| Flutter Impeller |

texture.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/core/texture.h"
6
7 #include "impeller/base/validation.h"
8
9 namespace impeller {
10
11 Texture::Texture(TextureDescriptor desc) : desc_(desc) {}
12
13 Texture::~Texture() = default;
14
15 bool Texture::SetContents(const uint8_t* contents,
16 size_t length,
17 size_t slice,
18 bool is_opaque) {
19 if (!IsSliceValid(slice)) {
20 VALIDATION_LOG << "Invalid slice for texture.";
21 return false;
22 }
23 if (!OnSetContents(contents, length, slice)) {
24 return false;
25 }
26 coordinate_system_ = TextureCoordinateSystem::kUploadFromHost;
27 is_opaque_ = is_opaque;
28 return true;
29 }
30
31 bool Texture::SetContents(std::shared_ptr<const fml::Mapping> mapping,
32 size_t slice,
33 bool is_opaque) {
34 if (!IsSliceValid(slice)) {
35 VALIDATION_LOG << "Invalid slice for texture.";
36 return false;
37 }
38 if (!mapping) {
39 return false;
40 }
41 if (!OnSetContents(std::move(mapping), slice)) {
42 return false;
43 }
44 coordinate_system_ = TextureCoordinateSystem::kUploadFromHost;
45 is_opaque_ = is_opaque;
46 return true;
47 }
48
49 bool Texture::IsOpaque() const {
50 return is_opaque_;
51 }
52
53 size_t Texture::GetMipCount() const {
54 return GetTextureDescriptor().mip_count;
55 }
56
57 const TextureDescriptor& Texture::GetTextureDescriptor() const {
58 return desc_;
59 }
60
61 bool Texture::IsSliceValid(size_t slice) const {
62 switch (desc_.type) {
63 case TextureType::kTexture2D:
64 case TextureType::kTexture2DMultisample:
65 case TextureType::kTextureExternalOES:
66 return slice == 0;
67 case TextureType::kTextureCube:
68 return slice <= 5;
69 }
70 FML_UNREACHABLE();
71 }
72
73 void Texture::SetCoordinateSystem(TextureCoordinateSystem coordinate_system) {
74 coordinate_system_ = coordinate_system;
75 }
76
77 TextureCoordinateSystem Texture::GetCoordinateSystem() const {
78 return coordinate_system_;
79 }
80
81 Scalar Texture::GetYCoordScale() const {
82 return 1.0;
83 }
84
85 bool Texture::NeedsMipmapGeneration() const {
86 return !mipmap_generated_ && desc_.mip_count > 1;
87 }
88
89 } // namespace impeller
impeller::Texture::NeedsMipmapGeneration
bool NeedsMipmapGeneration() const
Definition: texture.cc:85
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::Texture::~Texture
virtual ~Texture()
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::Texture::GetMipCount
size_t GetMipCount() const
Definition: texture.cc:53
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:44
validation.h
impeller::Texture::GetYCoordScale
virtual Scalar GetYCoordScale() const
Definition: texture.cc:81
impeller::TextureCoordinateSystem::kUploadFromHost
@ kUploadFromHost
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:41
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureCoordinateSystem
TextureCoordinateSystem
Definition: formats.h:304
impeller::Texture::SetCoordinateSystem
void SetCoordinateSystem(TextureCoordinateSystem coordinate_system)
Definition: texture.cc:73
impeller::Texture::IsOpaque
bool IsOpaque() const
Definition: texture.cc:49
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::Texture::mipmap_generated_
bool mipmap_generated_
Definition: texture.h:61
impeller::TextureType::kTexture2D
@ kTexture2D
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
texture.h
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:39
impeller::Texture::OnSetContents
virtual bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)=0
impeller::Texture::Texture
Texture(TextureDescriptor desc)
Definition: texture.cc:11
impeller::Texture::GetCoordinateSystem
TextureCoordinateSystem GetCoordinateSystem() const
Definition: texture.cc:77
impeller
Definition: aiks_context.cc:10
impeller::Texture::SetContents
bool SetContents(const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
Definition: texture.cc:15