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 
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
size_t GetMipCount() const
Definition: texture.cc:53
bool IsOpaque() const
Definition: texture.cc:49
virtual ~Texture()
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
TextureCoordinateSystem GetCoordinateSystem() const
Definition: texture.cc:77
bool NeedsMipmapGeneration() const
Definition: texture.cc:85
Texture(TextureDescriptor desc)
Definition: texture.cc:11
bool mipmap_generated_
Definition: texture.h:79
void SetCoordinateSystem(TextureCoordinateSystem coordinate_system)
Definition: texture.cc:73
virtual Scalar GetYCoordScale() const
Definition: texture.cc:81
virtual bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)=0
bool SetContents(const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
Definition: texture.cc:15
std::optional< PipelineDescriptor > desc_
float Scalar
Definition: scalar.h:19
TextureCoordinateSystem
Definition: formats.h:327
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define VALIDATION_LOG
Definition: validation.h:91