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