/src/skia/include/gpu/GrYUVABackendTextures.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2020 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 GrYUVABackendTextures_DEFINED |
9 | | #define GrYUVABackendTextures_DEFINED |
10 | | |
11 | | #include "include/core/SkYUVAInfo.h" |
12 | | #include "include/gpu/GrBackendSurface.h" |
13 | | |
14 | | #include <tuple> |
15 | | |
16 | | /** |
17 | | * A description of a set GrBackendTextures that hold the planar data described by a SkYUVAInfo. |
18 | | */ |
19 | | class SK_API GrYUVABackendTextureInfo { |
20 | | public: |
21 | | static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; |
22 | | |
23 | | /** Default GrYUVABackendTextureInfo is invalid. */ |
24 | 0 | GrYUVABackendTextureInfo() = default; |
25 | | |
26 | | /** |
27 | | * Initializes a GrYUVABackendTextureInfo to describe a set of textures that can store the |
28 | | * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's |
29 | | * plane dimensions. All the described textures share a common origin. The planar image this |
30 | | * describes will be mip mapped if all the textures are individually mip mapped as indicated |
31 | | * by GrMipmapped. This will produce an invalid result (return false from isValid()) if the |
32 | | * passed formats' channels don't agree with SkYUVAInfo. |
33 | | */ |
34 | | GrYUVABackendTextureInfo(const SkYUVAInfo&, |
35 | | const GrBackendFormat[kMaxPlanes], |
36 | | GrMipmapped, |
37 | | GrSurfaceOrigin); |
38 | | |
39 | | GrYUVABackendTextureInfo(const GrYUVABackendTextureInfo&) = default; |
40 | | |
41 | 0 | GrYUVABackendTextureInfo& operator=(const GrYUVABackendTextureInfo&) = default; |
42 | | |
43 | | bool operator==(const GrYUVABackendTextureInfo&) const; |
44 | 0 | bool operator!=(const GrYUVABackendTextureInfo& that) const { return !(*this == that); } |
45 | | |
46 | 0 | const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } |
47 | | |
48 | 0 | SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } |
49 | | |
50 | 0 | GrMipmapped mipmapped() const { return fMipmapped; } |
51 | | |
52 | 0 | GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; } |
53 | | |
54 | | /** The number of SkPixmap planes, 0 if this GrYUVABackendTextureInfo is invalid. */ |
55 | 0 | int numPlanes() const { return fYUVAInfo.numPlanes(); } |
56 | | |
57 | | /** Format of the ith plane, or invalid format if i >= numPlanes() */ |
58 | 0 | const GrBackendFormat& planeFormat(int i) const { return fPlaneFormats[i]; } |
59 | | |
60 | | /** |
61 | | * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture |
62 | | * formats. |
63 | | */ |
64 | 0 | bool isValid() const { return fYUVAInfo.isValid(); } |
65 | | |
66 | | /** |
67 | | * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be |
68 | | * valid if this->isValid(). |
69 | | */ |
70 | | SkYUVAInfo::YUVALocations toYUVALocations() const; |
71 | | |
72 | | private: |
73 | | SkYUVAInfo fYUVAInfo; |
74 | | GrBackendFormat fPlaneFormats[kMaxPlanes]; |
75 | | GrMipmapped fMipmapped = GrMipmapped::kNo; |
76 | | GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin; |
77 | | }; |
78 | | |
79 | | /** |
80 | | * A set of GrBackendTextures that hold the planar data for an image described a SkYUVAInfo. |
81 | | */ |
82 | | class SK_API GrYUVABackendTextures { |
83 | | public: |
84 | 0 | GrYUVABackendTextures() = default; |
85 | | GrYUVABackendTextures(const GrYUVABackendTextures&) = delete; |
86 | | GrYUVABackendTextures(GrYUVABackendTextures&&) = default; |
87 | | |
88 | | GrYUVABackendTextures& operator=(const GrYUVABackendTextures&) = delete; |
89 | 0 | GrYUVABackendTextures& operator=(GrYUVABackendTextures&&) = default; |
90 | | |
91 | | GrYUVABackendTextures(const SkYUVAInfo&, |
92 | | const GrBackendTexture[SkYUVAInfo::kMaxPlanes], |
93 | | GrSurfaceOrigin textureOrigin); |
94 | | |
95 | 0 | const std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes>& textures() const { |
96 | 0 | return fTextures; |
97 | 0 | } |
98 | | |
99 | 0 | GrBackendTexture texture(int i) const { |
100 | 0 | SkASSERT(i >= 0 && i < SkYUVAInfo::kMaxPlanes); |
101 | 0 | return fTextures[static_cast<size_t>(i)]; |
102 | 0 | } Unexecuted instantiation: GrYUVABackendTextures::texture(int) const Unexecuted instantiation: GrYUVABackendTextures::texture(int) const |
103 | | |
104 | 0 | const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } |
105 | | |
106 | 0 | int numPlanes() const { return fYUVAInfo.numPlanes(); } |
107 | | |
108 | 0 | GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; } |
109 | | |
110 | 0 | bool isValid() const { return fYUVAInfo.isValid(); } |
111 | | |
112 | | /** |
113 | | * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be |
114 | | * valid if this->isValid(). |
115 | | */ |
116 | | SkYUVAInfo::YUVALocations toYUVALocations() const; |
117 | | |
118 | | private: |
119 | | SkYUVAInfo fYUVAInfo; |
120 | | std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes> fTextures; |
121 | | GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin; |
122 | | }; |
123 | | |
124 | | #endif |