• 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_GpuBase_DEFINED
9 #define SkImage_GpuBase_DEFINED
10 
11 #include "include/core/SkDeferredDisplayListRecorder.h"
12 #include "include/core/SkYUVAIndex.h"
13 #include "include/gpu/GrBackendSurface.h"
14 #include "include/gpu/GrContext.h"
15 #include "include/private/GrTypesPriv.h"
16 #include "src/image/SkImage_Base.h"
17 
18 class GrColorSpaceXform;
19 class SkColorSpace;
20 
21 class SkImage_GpuBase : public SkImage_Base {
22 public:
23     SkImage_GpuBase(sk_sp<GrContext>, int width, int height, uint32_t uniqueID, SkColorType,
24                     SkAlphaType, sk_sp<SkColorSpace>);
25     ~SkImage_GpuBase() override;
26 
context()27     GrContext* context() const final { return fContext.get(); }
28 
29     bool getROPixels(SkBitmap*, CachingHint) const final;
30     sk_sp<SkImage> onMakeSubset(GrRecordingContext*, const SkIRect& subset) const final;
31 
32     bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
33                       int srcX, int srcY, CachingHint) const override;
34 
asTextureProxyRef(GrRecordingContext * context)35     sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext* context) const override {
36         // we shouldn't end up calling this
37         SkASSERT(false);
38         return this->INHERITED::asTextureProxyRef(context);
39     }
40     sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&,
41                                             SkScalar scaleAdjust[2]) const final;
42 
refPinnedTextureProxy(GrRecordingContext * context,uint32_t * uniqueID)43     sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext* context,
44                                                 uint32_t* uniqueID) const final {
45         *uniqueID = this->uniqueID();
46         return this->asTextureProxyRef(context);
47     }
48 
49     GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
50                                          GrSurfaceOrigin* origin) const final;
51 
52     GrTexture* onGetTexture() const final;
53 
54     bool onIsValid(GrContext*) const final;
55 
56 #if GR_TEST_UTILS
57     void resetContext(sk_sp<GrContext> newContext);
58 #endif
59 
60     static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex,
61                                        GrColorType grCT, SkColorType ct, SkAlphaType at,
62                                        sk_sp<SkColorSpace> cs);
63     static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
64                                        int numTextures, const SkYUVAIndex [4],
65                                        GrSurfaceOrigin imageOrigin,
66                                        sk_sp<GrTextureProxy> tempTextureProxies[4]);
67 
GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4])68     static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
69         return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
70                                                                : kOpaque_SkAlphaType;
71     }
72 
73     using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext;
74     using PromiseImageTextureFulfillProc =
75             SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc;
76     using PromiseImageTextureReleaseProc =
77             SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc;
78     using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc;
79 
80 protected:
81     using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion;
82     // Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called,
83     // if not null, immediately if this function fails. Othwerwise, it is installed in the
84     // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not
85     // be null.
86     static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
87             GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat,
88             GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
89             PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
90 
91     static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
92                                  const SkRect& rect, SkYUVColorSpace yuvColorSpace,
93                                  sk_sp<GrColorSpaceXform> colorSpaceXform,
94                                  const sk_sp<GrTextureProxy> proxies[4],
95                                  const SkYUVAIndex yuvaIndices[4]);
96 
97     sk_sp<GrContext> fContext;
98 
99 private:
100     typedef SkImage_Base INHERITED;
101 };
102 
103 #endif
104