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