| 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
8 #include "impeller/core/formats.h"
9 #include "impeller/geometry/size.h"
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) {
25 case CompressionType::kLossless:
26 return "Lossless";
27 case CompressionType::kLossy:
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 ///
37 struct TextureDescriptor {
38 StorageMode storage_mode = StorageMode::kDeviceTransient;
39 TextureType type = TextureType::kTexture2D;
40 PixelFormat format = PixelFormat::kUnknown;
41 ISize size;
42 size_t mip_count = 1u; // Size::MipCount is usually appropriate.
43 TextureUsageMask usage = TextureUsage::kShaderRead;
44 SampleCount sample_count = SampleCount::kCount1;
45 CompressionType compression_type = CompressionType::kLossless;
46
47 constexpr size_t GetByteSizeOfBaseMipLevel() const {
48 if (!IsValid()) {
49 return 0u;
50 }
51 return size.Area() * BytesPerPixelForPixelFormat(format);
52 }
53
54 constexpr size_t GetBytesPerRow() const {
55 if (!IsValid()) {
56 return 0u;
57 }
58 return size.width * BytesPerPixelForPixelFormat(format);
59 }
60
61 constexpr bool SamplingOptionsAreValid() const {
62 const auto count = static_cast<uint64_t>(sample_count);
63 return IsMultisampleCapable(type) ? count > 1 : count == 1;
64 }
65
66 constexpr bool operator==(const TextureDescriptor& other) const {
67 return size == other.size && //
68 storage_mode == other.storage_mode && //
69 format == other.format && //
70 usage == other.usage && //
71 sample_count == other.sample_count && //
72 type == other.type && //
73 compression_type == other.compression_type && //
74 mip_count == other.mip_count;
75 }
76
77 constexpr bool operator!=(const TextureDescriptor& other) const {
78 return !(*this == other);
79 }
80
81 constexpr bool IsValid() const {
82 return format != PixelFormat::kUnknown && //
83 !size.IsEmpty() && //
84 mip_count >= 1u && //
85 SamplingOptionsAreValid();
86 }
87 };
88
89 std::string TextureDescriptorToString(const TextureDescriptor& desc);
90
91 } // namespace impeller
92
93 #endif // FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::TextureType
TextureType
Definition: formats.h:263
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:44
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:43
impeller::TextureDescriptor::operator!=
constexpr bool operator!=(const TextureDescriptor &other) const
Definition: texture_descriptor.h:77
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:100
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:39
impeller::Mask< TextureUsage >
impeller::TextureDescriptor::IsValid
constexpr bool IsValid() const
Definition: texture_descriptor.h:81
impeller::TSize< int64_t >
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:33
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:448
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:66
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:284
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:47
impeller::TextureDescriptor::SamplingOptionsAreValid
constexpr bool SamplingOptionsAreValid() const
Definition: texture_descriptor.h:61
impeller::SampleCount
SampleCount
Definition: formats.h:296
impeller::TextureUsage::kShaderRead
@ kShaderRead
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:45
impeller
Definition: aiks_blur_unittests.cc:20
size.h
impeller::TextureDescriptor::GetBytesPerRow
constexpr size_t GetBytesPerRow() const
Definition: texture_descriptor.h:54