2 * Copyright 2020 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrYUVABackendTextures_DEFINED
9 #define GrYUVABackendTextures_DEFINED
11 #include "include/core/SkYUVAInfo.h"
12 #include "include/gpu/GrBackendSurface.h"
17 * A description of a set GrBackendTextures that hold the planar data described by a SkYUVAInfo.
19 class SK_API GrYUVABackendTextureInfo {
21 static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes;
23 /** Default GrYUVABackendTextureInfo is invalid. */
24 GrYUVABackendTextureInfo() = default;
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.
34 GrYUVABackendTextureInfo(const SkYUVAInfo&,
35 const GrBackendFormat[kMaxPlanes],
39 GrYUVABackendTextureInfo(const GrYUVABackendTextureInfo&) = default;
41 GrYUVABackendTextureInfo& operator=(const GrYUVABackendTextureInfo&) = default;
43 bool operator==(const GrYUVABackendTextureInfo&) const;
44 bool operator!=(const GrYUVABackendTextureInfo& that) const { return !(*this == that); }
46 const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
48 SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); }
50 GrMipmapped mipmapped() const { return fMipmapped; }
52 GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; }
54 /** The number of SkPixmap planes, 0 if this GrYUVABackendTextureInfo is invalid. */
55 int numPlanes() const { return fYUVAInfo.numPlanes(); }
57 /** Format of the ith plane, or invalid format if i >= numPlanes() */
58 const GrBackendFormat& planeFormat(int i) const { return fPlaneFormats[i]; }
61 * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture
64 bool isValid() const { return fYUVAInfo.isValid(); }
67 * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be
68 * valid if this->isValid().
70 SkYUVAInfo::YUVALocations toYUVALocations() const;
74 GrBackendFormat fPlaneFormats[kMaxPlanes];
75 GrMipmapped fMipmapped = GrMipmapped::kNo;
76 GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin;
80 * A set of GrBackendTextures that hold the planar data for an image described a SkYUVAInfo.
82 class SK_API GrYUVABackendTextures {
84 GrYUVABackendTextures() = default;
85 GrYUVABackendTextures(const GrYUVABackendTextures&) = delete;
86 GrYUVABackendTextures(GrYUVABackendTextures&&) = default;
88 GrYUVABackendTextures& operator=(const GrYUVABackendTextures&) = delete;
89 GrYUVABackendTextures& operator=(GrYUVABackendTextures&&) = default;
91 GrYUVABackendTextures(const SkYUVAInfo&,
92 const GrBackendTexture[SkYUVAInfo::kMaxPlanes],
93 GrSurfaceOrigin textureOrigin);
95 const std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes>& textures() const {
99 GrBackendTexture texture(int i) const {
100 SkASSERT(i >= 0 && i < SkYUVAInfo::kMaxPlanes);
101 return fTextures[static_cast<size_t>(i)];
104 const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
106 int numPlanes() const { return fYUVAInfo.numPlanes(); }
108 GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; }
110 bool isValid() const { return fYUVAInfo.isValid(); }
113 * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be
114 * valid if this->isValid().
116 SkYUVAInfo::YUVALocations toYUVALocations() const;
119 SkYUVAInfo fYUVAInfo;
120 std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes> fTextures;
121 GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin;