Flutter Engine
 
Loading...
Searching...
No Matches
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>
11
12namespace 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.
19enum class CompressionType {
21 kLossy,
22};
23
25 switch (type) {
27 return "Lossless";
29 return "Lossy";
30 }
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 +=
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 = default;
84
85 constexpr bool IsValid() const {
86 return format != PixelFormat::kUnknown && //
87 !size.IsEmpty() && //
88 mip_count >= 1u && //
90 }
91};
92
93std::string TextureDescriptorToString(const TextureDescriptor& desc);
94
95} // namespace impeller
96
97#endif // FLUTTER_IMPELLER_CORE_TEXTURE_DESCRIPTOR_H_
GLenum type
#define FML_UNREACHABLE()
Definition logging.h:128
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
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)
int32_t height
int32_t width
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 IsValid() const
constexpr bool operator==(const TextureDescriptor &other) const =default