• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
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 SkImage_GpuYUVA_DEFINED
9 #define SkImage_GpuYUVA_DEFINED
10 
11 #include "GrBackendSurface.h"
12 #include "GrContext.h"
13 #include "SkCachedData.h"
14 #include "SkImage_GpuBase.h"
15 
16 class GrTexture;
17 struct SkYUVASizeInfo;
18 
19 // Wraps the 3 or 4 planes of a YUVA image for consumption by the GPU.
20 // Initially any direct rendering will be done by passing the individual planes to a shader.
21 // Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB
22 // proxy will be stored and used for any future rendering.
23 class SkImage_GpuYUVA : public SkImage_GpuBase {
24 public:
25     friend class GrYUVAImageTextureMaker;
26 
27     SkImage_GpuYUVA(sk_sp<GrContext>, int width, int height, uint32_t uniqueID, SkYUVColorSpace,
28                     sk_sp<GrTextureProxy> proxies[], int numProxies, const SkYUVAIndex[4],
29                     GrSurfaceOrigin, sk_sp<SkColorSpace>);
30     ~SkImage_GpuYUVA() override;
31 
32     SkImageInfo onImageInfo() const override;
33 
peekProxy()34     GrTextureProxy* peekProxy() const override { return this->asTextureProxyRef().get(); }
35     sk_sp<GrTextureProxy> asTextureProxyRef() const override;
36 
onIsTextureBacked()37     virtual bool onIsTextureBacked() const override { return SkToBool(fProxies[0].get()); }
38 
39     sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const final;
40 
isYUVA()41     virtual bool isYUVA() const override { return true; }
asYUVATextureProxiesRef(sk_sp<GrTextureProxy> proxies[4],SkYUVAIndex yuvaIndices[4],SkYUVColorSpace * yuvColorSpace)42     virtual bool asYUVATextureProxiesRef(sk_sp<GrTextureProxy> proxies[4],
43                                          SkYUVAIndex yuvaIndices[4],
44                                          SkYUVColorSpace* yuvColorSpace) const override {
45         for (int i = 0; i < 4; ++i) {
46             proxies[i] = fProxies[i];
47             yuvaIndices[i] = fYUVAIndices[i];
48         }
49         *yuvColorSpace = fYUVColorSpace;
50         return true;
51     }
52 
53     bool setupMipmapsForPlanes() const;
54 
55     // Returns a ref-ed texture proxy with miplevels
56     sk_sp<GrTextureProxy> asMippedTextureProxyRef() const;
57 
targetColorSpace()58     SkColorSpace* targetColorSpace() const { return fTargetColorSpace.get(); }
59 
60     /**
61      * This is the implementation of SkDeferredDisplayListRecorder::makeYUVAPromiseTexture.
62      */
63     static sk_sp<SkImage> MakePromiseYUVATexture(GrContext* context,
64                                                  SkYUVColorSpace yuvColorSpace,
65                                                  const GrBackendFormat yuvaFormats[],
66                                                  const SkISize yuvaSizes[],
67                                                  const SkYUVAIndex yuvaIndices[4],
68                                                  int width,
69                                                  int height,
70                                                  GrSurfaceOrigin imageOrigin,
71                                                  sk_sp<SkColorSpace> imageColorSpace,
72                                                  PromiseImageTextureFulfillProc textureFulfillProc,
73                                                  PromiseImageTextureReleaseProc textureReleaseProc,
74                                                  PromiseImageTextureDoneProc textureDoneProc,
75                                                  PromiseImageTextureContext textureContexts[],
76                                                  DelayReleaseCallback delayReleaseCallback);
77 
78 private:
79     SkImage_GpuYUVA(const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);
80 
81     // This array will usually only be sparsely populated.
82     // The actual non-null fields are dictated by the 'fYUVAIndices' indices
83     mutable sk_sp<GrTextureProxy>    fProxies[4];
84     int                              fNumProxies;
85     SkYUVAIndex                      fYUVAIndices[4];
86     const SkYUVColorSpace            fYUVColorSpace;
87     GrSurfaceOrigin                  fOrigin;
88     const sk_sp<SkColorSpace>        fTargetColorSpace;
89 
90     // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
91     // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call.
92     mutable sk_sp<SkColorSpace>      fOnMakeColorSpaceTarget;
93     mutable sk_sp<SkImage>           fOnMakeColorSpaceResult;
94 
95     // This is only allocated when the image needs to be flattened rather than
96     // using the separate YUVA planes. From thence forth we will only use the
97     // the RGBProxy.
98     mutable sk_sp<GrTextureProxy>    fRGBProxy;
99     typedef SkImage_GpuBase INHERITED;
100 };
101 
102 #endif
103