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 
6 
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 {
55 }
56 
58  return desc_;
59 }
60 
61 bool Texture::IsSliceValid(size_t slice) const {
62  switch (desc_.type) {
66  return slice == 0;
68  return slice <= 5;
69  }
70  FML_UNREACHABLE();
71 }
72 
74  coordinate_system_ = coordinate_system;
75 }
76 
78  return coordinate_system_;
79 }
80 
82  return 1.0;
83 }
84 
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:18
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:42
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:39
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureCoordinateSystem
TextureCoordinateSystem
Definition: formats.h:328
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:64
impeller::TextureType::kTexture2D
@ kTexture2D
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
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:37
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_blur_unittests.cc:20
impeller::Texture::SetContents
bool SetContents(const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
Definition: texture.cc:15