/src/skia/include/gpu/graphite/YUVABackendTextures.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2023 Google LLC |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #ifndef skgpu_graphite_YUVABackendTextures_DEFINED |
9 | | #define skgpu_graphite_YUVABackendTextures_DEFINED |
10 | | |
11 | | #include "include/core/SkSpan.h" |
12 | | #include "include/core/SkYUVAInfo.h" |
13 | | #include "include/gpu/graphite/BackendTexture.h" |
14 | | |
15 | | #include <tuple> |
16 | | |
17 | | namespace skgpu::graphite { |
18 | | class Recorder; |
19 | | |
20 | | /** |
21 | | * A description of a set of BackendTextures that hold the planar data described by a SkYUVAInfo. |
22 | | */ |
23 | | class SK_API YUVABackendTextureInfo { |
24 | | public: |
25 | | static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; |
26 | | |
27 | | /** Default YUVABackendTextureInfo is invalid. */ |
28 | 0 | YUVABackendTextureInfo() = default; |
29 | | YUVABackendTextureInfo(const YUVABackendTextureInfo&) = default; |
30 | 0 | YUVABackendTextureInfo& operator=(const YUVABackendTextureInfo&) = default; |
31 | | |
32 | | /** |
33 | | * Initializes a YUVABackendTextureInfo to describe a set of textures that can store the |
34 | | * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's |
35 | | * plane dimensions. All the described textures share a common origin. The planar image this |
36 | | * describes will be mip mapped if all the textures are individually mip mapped as indicated |
37 | | * by Mipmapped. This will produce an invalid result (return false from isValid()) if the |
38 | | * passed formats' channels don't agree with SkYUVAInfo. |
39 | | */ |
40 | | YUVABackendTextureInfo(const Recorder*, |
41 | | const SkYUVAInfo&, |
42 | | SkSpan<const TextureInfo>, |
43 | | Mipmapped); |
44 | | |
45 | | bool operator==(const YUVABackendTextureInfo&) const; |
46 | 0 | bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); } |
47 | | |
48 | | /** TextureInfo for the ith plane, or invalid if i >= numPlanes() */ |
49 | 0 | const TextureInfo& planeTextureInfo(int i) const { |
50 | 0 | SkASSERT(i >= 0); |
51 | 0 | return fPlaneTextureInfos[static_cast<size_t>(i)]; |
52 | 0 | } Unexecuted instantiation: skgpu::graphite::YUVABackendTextureInfo::planeTextureInfo(int) const Unexecuted instantiation: skgpu::graphite::YUVABackendTextureInfo::planeTextureInfo(int) const |
53 | | |
54 | 0 | const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } |
55 | | |
56 | 0 | SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } |
57 | | |
58 | 0 | Mipmapped mipmapped() const { return fMipmapped; } |
59 | | |
60 | | /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ |
61 | 0 | int numPlanes() const { return fYUVAInfo.numPlanes(); } |
62 | | |
63 | | /** |
64 | | * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture |
65 | | * formats. |
66 | | */ |
67 | 0 | bool isValid() const { return fYUVAInfo.isValid(); } |
68 | | |
69 | | /** |
70 | | * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be |
71 | | * valid if this->isValid(). |
72 | | */ |
73 | | SkYUVAInfo::YUVALocations toYUVALocations() const; |
74 | | |
75 | | private: |
76 | | SkYUVAInfo fYUVAInfo; |
77 | | std::array<TextureInfo, kMaxPlanes> fPlaneTextureInfos; |
78 | | std::array<uint32_t, kMaxPlanes> fPlaneChannelMasks; |
79 | | Mipmapped fMipmapped = Mipmapped::kNo; |
80 | | }; |
81 | | |
82 | | /** |
83 | | * A set of BackendTextures that hold the planar data for an image described a SkYUVAInfo. |
84 | | */ |
85 | | class SK_API YUVABackendTextures { |
86 | | public: |
87 | | static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; |
88 | | |
89 | | YUVABackendTextures() = default; |
90 | | YUVABackendTextures(const YUVABackendTextures&) = delete; |
91 | | YUVABackendTextures& operator=(const YUVABackendTextures&) = delete; |
92 | | |
93 | | /** |
94 | | * Initializes a YUVABackendTextures object from a set of textures that store the planes |
95 | | * indicated by the SkYUVAInfo. This will produce an invalid result (return false from |
96 | | * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo. |
97 | | */ |
98 | | YUVABackendTextures(const Recorder*, |
99 | | const SkYUVAInfo&, |
100 | | SkSpan<const BackendTexture>); |
101 | | |
102 | 0 | SkSpan<const BackendTexture> planeTextures() const { |
103 | 0 | return SkSpan<const BackendTexture>(fPlaneTextures); |
104 | 0 | } |
105 | | |
106 | | /** BackendTexture for the ith plane, or invalid if i >= numPlanes() */ |
107 | 0 | BackendTexture planeTexture(int i) const { |
108 | 0 | SkASSERT(i >= 0); |
109 | 0 | return fPlaneTextures[static_cast<size_t>(i)]; |
110 | 0 | } Unexecuted instantiation: skgpu::graphite::YUVABackendTextures::planeTexture(int) const Unexecuted instantiation: skgpu::graphite::YUVABackendTextures::planeTexture(int) const |
111 | | |
112 | 0 | const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } |
113 | | |
114 | 0 | SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } |
115 | | |
116 | | /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ |
117 | 0 | int numPlanes() const { return fYUVAInfo.numPlanes(); } |
118 | | |
119 | | /** |
120 | | * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture |
121 | | * formats. |
122 | | */ |
123 | 0 | bool isValid() const { return fYUVAInfo.isValid(); } |
124 | | |
125 | | /** |
126 | | * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be |
127 | | * valid if this->isValid(). |
128 | | */ |
129 | | SkYUVAInfo::YUVALocations toYUVALocations() const; |
130 | | |
131 | | private: |
132 | | SkYUVAInfo fYUVAInfo; |
133 | | std::array<BackendTexture, kMaxPlanes> fPlaneTextures; |
134 | | std::array<uint32_t, kMaxPlanes> fPlaneChannelMasks; |
135 | | }; |
136 | | |
137 | | } // End of namespace skgpu::graphite |
138 | | |
139 | | #endif // skgpu_graphite_YUVABackendTextures_DEFINED |