Flutter Impeller
texture_descriptor.h
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 #ifndef FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
6 #define FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
7 
10 
11 namespace impeller {
12 
13 //------------------------------------------------------------------------------
14 /// @brief Additional compression to apply to a texture. This value is
15 /// ignored on platforms which do not support it.
16 ///
17 /// Lossy compression is only supported on iOS 15+ on A15 chips.
18 enum class CompressionType {
19  kLossless,
20  kLossy,
21 };
22 
23 constexpr const char* CompressionTypeToString(CompressionType type) {
24  switch (type) {
26  return "Lossless";
28  return "Lossy";
29  }
30  FML_UNREACHABLE();
31 }
32 
33 //------------------------------------------------------------------------------
34 /// @brief A lightweight object that describes the attributes of a texture
35 /// that can then used an allocator to create that texture.
36 ///
42  size_t mip_count = 1u; // Size::MipCount is usually appropriate.
47 
48  constexpr size_t GetByteSizeOfBaseMipLevel() const {
49  if (!IsValid()) {
50  return 0u;
51  }
53  }
54 
55  constexpr size_t GetBytesPerRow() const {
56  if (!IsValid()) {
57  return 0u;
58  }
60  }
61 
62  constexpr bool SamplingOptionsAreValid() const {
63  const auto count = static_cast<uint64_t>(sample_count);
64  return IsMultisampleCapable(type) ? count > 1 : count == 1;
65  }
66 
67  constexpr bool operator==(const TextureDescriptor& other) const {
68  return size == other.size && //
69  storage_mode == other.storage_mode && //
70  format == other.format && //
71  usage == other.usage && //
72  sample_count == other.sample_count && //
73  type == other.type && //
74  compression_type == other.compression_type && //
75  mip_count == other.mip_count;
76  }
77 
78  constexpr bool operator!=(const TextureDescriptor& other) const {
79  return !(*this == other);
80  }
81 
82  constexpr bool IsValid() const {
83  return format != PixelFormat::kUnknown && //
84  !size.IsEmpty() && //
85  mip_count >= 1u && //
87  }
88 };
89 
90 std::string TextureDescriptorToString(const TextureDescriptor& desc);
91 
92 } // namespace impeller
93 
94 #endif // FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
impeller::TextureUsageMask
uint64_t TextureUsageMask
Definition: formats.h:295
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::TextureType
TextureType
Definition: formats.h:257
formats.h
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:42
impeller::TextureDescriptorToString
std::string TextureDescriptorToString(const TextureDescriptor &desc)
Definition: texture_descriptor.cc:11
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:45
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:43
impeller::TextureDescriptor::operator!=
constexpr bool operator!=(const TextureDescriptor &other) const
Definition: texture_descriptor.h:78
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:39
impeller::TextureDescriptor::IsValid
constexpr bool IsValid() const
Definition: texture_descriptor.h:82
impeller::TSize< int64_t >
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:27
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:442
impeller::CompressionType
CompressionType
Additional compression to apply to a texture. This value is ignored on platforms which do not support...
Definition: texture_descriptor.h:18
impeller::CompressionType::kLossless
@ kLossless
impeller::TextureDescriptor::operator==
constexpr bool operator==(const TextureDescriptor &other) const
Definition: texture_descriptor.h:67
impeller::TextureUsage::kShaderRead
@ kShaderRead
impeller::CompressionTypeToString
constexpr const char * CompressionTypeToString(CompressionType type)
Definition: texture_descriptor.h:23
impeller::CompressionType::kLossy
@ kLossy
impeller::IsMultisampleCapable
constexpr bool IsMultisampleCapable(TextureType type)
Definition: formats.h:278
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TSize::width
Type width
Definition: size.h:22
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
impeller::TSize::Area
constexpr Type Area() const
Definition: size.h:102
impeller::TextureDescriptor::GetByteSizeOfBaseMipLevel
constexpr size_t GetByteSizeOfBaseMipLevel() const
Definition: texture_descriptor.h:48
impeller::TextureDescriptor::SamplingOptionsAreValid
constexpr bool SamplingOptionsAreValid() const
Definition: texture_descriptor.h:62
impeller::SampleCount
SampleCount
Definition: formats.h:290
impeller::SampleCount::kCount1
@ kCount1
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:38
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::TSize::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:105
impeller::TextureDescriptor::compression_type
CompressionType compression_type
Definition: texture_descriptor.h:46
impeller
Definition: aiks_context.cc:10
size.h
impeller::TextureDescriptor::GetBytesPerRow
constexpr size_t GetBytesPerRow() const
Definition: texture_descriptor.h:55