Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 17 | |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 18 | class GrColorSpaceXform; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 19 | class SkColorSpace; |
| 20 | |
| 21 | class SkImage_GpuBase : public SkImage_Base { |
| 22 | public: |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 23 | GrContext* context() const final { return fContext.get(); } |
| 24 | |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 25 | bool getROPixels(SkBitmap*, CachingHint) const final; |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 26 | sk_sp<SkImage> onMakeSubset(GrRecordingContext*, const SkIRect& subset) const final; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 27 | |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 28 | bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, |
| 29 | int srcX, int srcY, CachingHint) const override; |
| 30 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 31 | sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext* context) const override { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 32 | // we shouldn't end up calling this |
| 33 | SkASSERT(false); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 34 | return this->INHERITED::asTextureProxyRef(context); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 35 | } |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 36 | sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 37 | SkScalar scaleAdjust[2]) const final; |
| 38 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 39 | sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext* context, |
| 40 | uint32_t* uniqueID) const final { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 41 | *uniqueID = this->uniqueID(); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 42 | return this->asTextureProxyRef(context); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, |
| 46 | GrSurfaceOrigin* origin) const final; |
| 47 | |
| 48 | GrTexture* onGetTexture() const final; |
| 49 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 50 | bool onIsValid(GrContext*) const final; |
| 51 | |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 52 | #if GR_TEST_UTILS |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 53 | void resetContext(sk_sp<GrContext> newContext); |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 54 | #endif |
| 55 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 56 | static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex, |
| 57 | GrColorType grCT, SkColorType ct, SkAlphaType at, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 58 | sk_sp<SkColorSpace> cs); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 59 | static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[], |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 60 | int numTextures, const SkYUVAIndex [4], |
| 61 | GrSurfaceOrigin imageOrigin, |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 62 | sk_sp<GrTextureProxy> tempTextureProxies[4]); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 63 | |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 64 | static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) { |
| 65 | return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType |
| 66 | : kOpaque_SkAlphaType; |
| 67 | } |
| 68 | |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 69 | using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext; |
| 70 | using PromiseImageTextureFulfillProc = |
| 71 | SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc; |
| 72 | using PromiseImageTextureReleaseProc = |
| 73 | SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc; |
| 74 | using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 75 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 76 | protected: |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 77 | SkImage_GpuBase(sk_sp<GrContext>, SkISize size, uint32_t uniqueID, SkColorType, SkAlphaType, |
| 78 | sk_sp<SkColorSpace>); |
| 79 | |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 80 | using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion; |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 81 | // Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called, |
| 82 | // if not null, immediately if this function fails. Othwerwise, it is installed in the |
| 83 | // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not |
| 84 | // be null. |
| 85 | static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 86 | GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat, |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 87 | GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 88 | PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 89 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 90 | static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext, |
| 91 | const SkRect& rect, SkYUVColorSpace yuvColorSpace, |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 92 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 93 | const sk_sp<GrTextureProxy> proxies[4], |
| 94 | const SkYUVAIndex yuvaIndices[4]); |
| 95 | |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 96 | sk_sp<GrContext> fContext; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | typedef SkImage_Base INHERITED; |
| 100 | }; |
| 101 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 102 | #endif |