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 <cstdint>
10 #include "impeller/geometry/size.h"
11 
12 namespace impeller {
13 
14 //------------------------------------------------------------------------------
15 /// @brief Additional compression to apply to a texture. This value is
16 /// ignored on platforms which do not support it.
17 ///
18 /// Lossy compression is only supported on iOS 15+ on A15 chips.
19 enum class CompressionType {
20  kLossless,
21  kLossy,
22 };
23 
25  switch (type) {
27  return "Lossless";
29  return "Lossy";
30  }
31  FML_UNREACHABLE();
32 }
33 
34 //------------------------------------------------------------------------------
35 /// @brief A lightweight object that describes the attributes of a texture
36 /// that can then used an allocator to create that texture.
37 ///
43  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 GetByteSizeOfAllMipLevels() const {
56  if (!IsValid()) {
57  return 0u;
58  }
59  size_t result = 0u;
60  int64_t width = size.width;
61  int64_t height = size.height;
62  for (auto i = 0u; i < mip_count; i++) {
63  result +=
64  ISize(width, height).Area() * BytesPerPixelForPixelFormat(format);
65  width /= 2;
66  height /= 2;
67  }
68  return result;
69  }
70 
71  constexpr size_t GetBytesPerRow() const {
72  if (!IsValid()) {
73  return 0u;
74  }
76  }
77 
78  constexpr bool SamplingOptionsAreValid() const {
79  const auto count = static_cast<uint64_t>(sample_count);
80  return IsMultisampleCapable(type) ? count > 1 : count == 1;
81  }
82 
83  constexpr bool operator==(const TextureDescriptor& other) const {
84  return size == other.size && //
85  storage_mode == other.storage_mode && //
86  format == other.format && //
87  usage == other.usage && //
88  sample_count == other.sample_count && //
89  type == other.type && //
90  compression_type == other.compression_type && //
91  mip_count == other.mip_count;
92  }
93 
94  constexpr bool operator!=(const TextureDescriptor& other) const {
95  return !(*this == other);
96  }
97 
98  constexpr bool IsValid() const {
99  return format != PixelFormat::kUnknown && //
100  !size.IsEmpty() && //
101  mip_count >= 1u && //
103  }
104 };
105 
106 std::string TextureDescriptorToString(const TextureDescriptor& desc);
107 
108 } // namespace impeller
109 
110 #endif // FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
GLenum type
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:466
std::string TextureDescriptorToString(const TextureDescriptor &desc)
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:32
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
TextureType
Definition: formats.h:262
CompressionType
Additional compression to apply to a texture. This value is ignored on platforms which do not support...
ISize64 ISize
Definition: size.h:162
constexpr bool IsMultisampleCapable(TextureType type)
Definition: formats.h:283
constexpr const char * CompressionTypeToString(CompressionType type)
SampleCount
Definition: formats.h:295
constexpr Type Area() const
Definition: size.h:120
Type height
Definition: size.h:29
Type width
Definition: size.h:28
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:123
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
constexpr size_t GetByteSizeOfBaseMipLevel() const
constexpr size_t GetBytesPerRow() const
constexpr size_t GetByteSizeOfAllMipLevels() const
constexpr bool SamplingOptionsAreValid() const
constexpr bool operator==(const TextureDescriptor &other) const
constexpr bool IsValid() const
constexpr bool operator!=(const TextureDescriptor &other) const