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  is_opaque_ = is_opaque;
27  return true;
28 }
29 
30 bool Texture::SetContents(std::shared_ptr<const fml::Mapping> mapping,
31  size_t slice,
32  bool is_opaque) {
33  if (!IsSliceValid(slice)) {
34  VALIDATION_LOG << "Invalid slice for texture.";
35  return false;
36  }
37  if (!mapping) {
38  return false;
39  }
40  if (!OnSetContents(std::move(mapping), slice)) {
41  return false;
42  }
43  is_opaque_ = is_opaque;
44  return true;
45 }
46 
47 bool Texture::IsOpaque() const {
48  return is_opaque_;
49 }
50 
51 size_t Texture::GetMipCount() const {
53 }
54 
56  return desc_;
57 }
58 
59 bool Texture::IsSliceValid(size_t slice) const {
60  switch (desc_.type) {
64  return slice == 0;
66  return slice <= 5;
67  }
68  FML_UNREACHABLE();
69 }
70 
72  return !mipmap_generated_ && desc_.mip_count > 1;
73 }
74 
75 } // namespace impeller
size_t GetMipCount() const
Definition: texture.cc:51
bool IsOpaque() const
Definition: texture.cc:47
virtual ~Texture()
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:55
bool NeedsMipmapGeneration() const
Definition: texture.cc:71
Texture(TextureDescriptor desc)
Definition: texture.cc:11
bool mipmap_generated_
Definition: texture.h:69
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_
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