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 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 31 | GrSurfaceProxyView refView(GrRecordingContext*, GrMipMapped) const final; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 32 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 33 | GrSurfaceProxyView refPinnedView(GrRecordingContext* context, uint32_t* uniqueID) const final { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 34 | *uniqueID = this->uniqueID(); |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 35 | SkASSERT(this->view(context)); |
| 36 | return *this->view(context); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, |
| 40 | GrSurfaceOrigin* origin) const final; |
| 41 | |
Greg Daniel | 7c90211 | 2020-03-06 13:07:10 -0500 | [diff] [blame^] | 42 | GrTexture* getTexture() const; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 43 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 44 | bool onIsValid(GrContext*) const final; |
| 45 | |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 46 | #if GR_TEST_UTILS |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 47 | void resetContext(sk_sp<GrContext> newContext); |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 48 | #endif |
| 49 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 50 | static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex, |
| 51 | GrColorType grCT, SkColorType ct, SkAlphaType at, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 52 | sk_sp<SkColorSpace> cs); |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 53 | static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex, |
| 54 | SkAlphaType); |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 55 | static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[], |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 56 | int numTextures, const SkYUVAIndex [4], |
| 57 | GrSurfaceOrigin imageOrigin, |
Greg Daniel | c767209 | 2020-02-06 14:32:54 -0500 | [diff] [blame] | 58 | GrSurfaceProxyView tempViews[4]); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 59 | |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 60 | static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) { |
| 61 | return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType |
| 62 | : kOpaque_SkAlphaType; |
| 63 | } |
| 64 | |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 65 | using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext; |
| 66 | using PromiseImageTextureFulfillProc = |
| 67 | SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc; |
| 68 | using PromiseImageTextureReleaseProc = |
| 69 | SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc; |
| 70 | using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 71 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 72 | protected: |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 73 | SkImage_GpuBase(sk_sp<GrContext>, SkISize size, uint32_t uniqueID, SkColorType, SkAlphaType, |
| 74 | sk_sp<SkColorSpace>); |
| 75 | |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 76 | using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion; |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 77 | // Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called, |
| 78 | // if not null, immediately if this function fails. Othwerwise, it is installed in the |
| 79 | // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not |
| 80 | // be null. |
| 81 | static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy( |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 82 | GrContext*, int width, int height, GrColorType, GrBackendFormat, GrMipMapped, |
| 83 | PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 84 | PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 85 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 86 | static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext, |
| 87 | const SkRect& rect, SkYUVColorSpace yuvColorSpace, |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 88 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Greg Daniel | c767209 | 2020-02-06 14:32:54 -0500 | [diff] [blame] | 89 | GrSurfaceProxyView views[4], |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 90 | const SkYUVAIndex yuvaIndices[4]); |
| 91 | |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 92 | sk_sp<GrContext> fContext; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | typedef SkImage_Base INHERITED; |
| 96 | }; |
| 97 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 98 | #endif |