xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrYUVATextureProxies.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 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 GrYUVATextureProxies_DEFINED
9 #define GrYUVATextureProxies_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkYUVAInfo.h"
13 #include "include/gpu/GpuTypes.h"
14 #include "include/gpu/ganesh/GrTypes.h"
15 #include "src/core/SkYUVAInfoLocation.h"  // IWYU pragma: keep
16 #include "src/gpu/Swizzle.h"
17 #include "src/gpu/ganesh/GrSurfaceProxy.h"
18 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
19 
20 #include <array>
21 
22 enum class GrColorType;
23 
24 class GrYUVATextureProxies {
25 public:
26     GrYUVATextureProxies() = default;
27 
28     /** Assumes all planes are sampled with a default "rgba" swizzle. */
29     GrYUVATextureProxies(const SkYUVAInfo&,
30                          sk_sp<GrSurfaceProxy>[SkYUVAInfo::kMaxPlanes],
31                          GrSurfaceOrigin textureOrigin);
32 
33     /**
34      * When uploading pixmaps to textures it is important that we account for how the original
35      * pixmaps' channels are swizzled into the texture during upload. This will compute a swizzle
36      * for each texture based on the original color types and the views' swizzles. The views must
37      * all have the same origin or the result will be an invalid GrYUVATextureProxies.
38      */
39     GrYUVATextureProxies(const SkYUVAInfo&,
40                          GrSurfaceProxyView[SkYUVAInfo::kMaxPlanes],
41                          GrColorType[SkYUVAInfo::kMaxPlanes]);
42 
43     GrYUVATextureProxies(const GrYUVATextureProxies&) = default;
44     GrYUVATextureProxies(GrYUVATextureProxies&&) = default;
45 
46     GrYUVATextureProxies& operator=(const GrYUVATextureProxies&) = default;
47     GrYUVATextureProxies& operator=(GrYUVATextureProxies&&) = default;
48 
yuvaInfo()49     const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
50 
numPlanes()51     int numPlanes() const { return fYUVAInfo.numPlanes(); }
52 
textureOrigin()53     GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; }
54 
55     // Overall set of YUVA proxies is mip mapped if each plane is mip mapped.
mipmapped()56     skgpu::Mipmapped mipmapped() const { return fMipmapped; }
57 
proxy(int i)58     GrSurfaceProxy* proxy(int i) const { return fProxies[i].get(); }
59 
proxies()60     const std::array<sk_sp<GrSurfaceProxy>, SkYUVAInfo::kMaxPlanes>& proxies() const {
61         return fProxies;
62     }
63 
refProxy(int i)64     sk_sp<GrSurfaceProxy> refProxy(int i) const { return fProxies[i]; }
65 
makeView(int i)66     GrSurfaceProxyView makeView(int i) const {
67         return {fProxies[i], fTextureOrigin, skgpu::Swizzle::RGBA()};
68     }
69 
isValid()70     bool isValid() const { return fYUVAInfo.isValid(); }
71 
yuvaLocations()72     const SkYUVAInfo::YUVALocations& yuvaLocations() const { return fYUVALocations; }
73 
74 private:
75     std::array<sk_sp<GrSurfaceProxy>, SkYUVAInfo::kMaxPlanes> fProxies;
76     SkYUVAInfo fYUVAInfo;
77     GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin;
78     skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo;
79     SkYUVAInfo::YUVALocations fYUVALocations = {};
80 };
81 
82 #endif
83