• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_YUVATextureProxies_DEFINED
9 #define skgpu_graphite_YUVATextureProxies_DEFINED
10 
11 #include "include/core/SkYUVAInfo.h"
12 #include "src/core/SkYUVAInfoLocation.h"
13 #include "src/gpu/graphite/TextureProxyView.h"
14 
15 namespace skgpu::graphite {
16 
17 class YUVATextureProxies {
18 public:
19     YUVATextureProxies() = default;
20 
21     /**
22      * When uploading pixmaps to textures it is important that we account for how the original
23      * pixmaps' channels are swizzled into the texture during upload. This will compute a swizzle
24      * for each texture based on the original color types and the views' swizzles.
25      */
26     YUVATextureProxies(const SkYUVAInfo&,
27                        TextureProxyView[SkYUVAInfo::kMaxPlanes],
28                        SkColorType[SkYUVAInfo::kMaxPlanes]);
29 
30     YUVATextureProxies(const YUVATextureProxies&) = default;
31     YUVATextureProxies(YUVATextureProxies&&) = default;
32 
33     YUVATextureProxies& operator=(const YUVATextureProxies&) = default;
34     YUVATextureProxies& operator=(YUVATextureProxies&&) = default;
35 
yuvaInfo()36     const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
37 
numPlanes()38     int numPlanes() const { return fYUVAInfo.numPlanes(); }
39 
40     // Overall set of YUVA proxies is mip mapped if each plane is mip mapped.
mipmapped()41     Mipmapped mipmapped() const { return fMipmapped; }
42 
proxy(int i)43     TextureProxy* proxy(int i) const { return fProxies[i].get(); }
44 
proxies()45     const std::array<sk_sp<TextureProxy>, SkYUVAInfo::kMaxPlanes>& proxies() const {
46         return fProxies;
47     }
48 
refProxy(int i)49     sk_sp<TextureProxy> refProxy(int i) const { return fProxies[i]; }
50 
makeView(int i)51     TextureProxyView makeView(int i) const {
52         return {fProxies[i], skgpu::Swizzle::RGBA()};
53     }
54 
isValid()55     bool isValid() const { return fYUVAInfo.isValid(); }
56 
yuvaLocations()57     const SkYUVAInfo::YUVALocations& yuvaLocations() const { return fYUVALocations; }
58 
59 private:
60     std::array<sk_sp<TextureProxy>, SkYUVAInfo::kMaxPlanes> fProxies;
61     SkYUVAInfo fYUVAInfo;
62     Mipmapped fMipmapped = Mipmapped::kNo;
63     SkYUVAInfo::YUVALocations fYUVALocations = {};
64 };
65 
66 }  // namespace skgpu::graphite
67 
68 #endif // skgpu_graphite_Image_YUVA_DEFINED
69