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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/private/GrTypesPriv.h" |
| 15 | #include "src/image/SkImage_Base.h" |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 16 | |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 17 | class GrColorSpaceXform; |
Robert Phillips | 1a57857 | 2020-07-13 13:17:09 -0400 | [diff] [blame] | 18 | class GrDirectContext; |
Adlai Holler | 302e8fb | 2020-09-14 11:58:06 -0400 | [diff] [blame] | 19 | class GrImageContext; |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 20 | class GrSurfaceFillContext; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 21 | class SkColorSpace; |
| 22 | |
| 23 | class SkImage_GpuBase : public SkImage_Base { |
| 24 | public: |
Adlai Holler | 302e8fb | 2020-09-14 11:58:06 -0400 | [diff] [blame] | 25 | GrImageContext* context() const final { return fContext.get(); } |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 26 | |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 27 | bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final; |
Adlai Holler | 872a32c | 2020-07-10 14:33:22 -0400 | [diff] [blame] | 28 | sk_sp<SkImage> onMakeSubset(const SkIRect& subset, GrDirectContext*) const final; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 29 | |
Adlai Holler | bcfc554 | 2020-08-27 12:44:07 -0400 | [diff] [blame] | 30 | bool onReadPixels(GrDirectContext *dContext, |
| 31 | const SkImageInfo& dstInfo, |
| 32 | void* dstPixels, |
| 33 | size_t dstRB, |
| 34 | int srcX, |
| 35 | int srcY, |
| 36 | CachingHint) const override; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 37 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 38 | GrSurfaceProxyView refView(GrRecordingContext*, GrMipmapped) const final; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 39 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 40 | GrSurfaceProxyView refPinnedView(GrRecordingContext* context, uint32_t* uniqueID) const final { |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 41 | *uniqueID = this->uniqueID(); |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 42 | SkASSERT(this->view(context)); |
| 43 | return *this->view(context); |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, |
| 47 | GrSurfaceOrigin* origin) const final; |
| 48 | |
Greg Daniel | 7c90211 | 2020-03-06 13:07:10 -0500 | [diff] [blame] | 49 | GrTexture* getTexture() const; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 50 | |
Robert Phillips | 4a3ebc2 | 2020-07-10 11:27:43 -0400 | [diff] [blame] | 51 | bool onIsValid(GrRecordingContext*) const final; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 52 | |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 53 | #if GR_TEST_UTILS |
Adlai Holler | 302e8fb | 2020-09-14 11:58:06 -0400 | [diff] [blame] | 54 | void resetContext(sk_sp<GrImageContext> newContext); |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 55 | #endif |
| 56 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 57 | static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex, |
| 58 | GrColorType grCT, SkColorType ct, SkAlphaType at, |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 59 | sk_sp<SkColorSpace> cs); |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 60 | static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex, |
| 61 | SkAlphaType); |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 62 | |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 63 | static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) { |
| 64 | return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType |
| 65 | : kOpaque_SkAlphaType; |
| 66 | } |
| 67 | |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 68 | using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext; |
| 69 | using PromiseImageTextureFulfillProc = |
| 70 | SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc; |
| 71 | using PromiseImageTextureReleaseProc = |
| 72 | SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc; |
Jim Van Verth | 8bbce0e | 2018-10-08 14:34:52 -0400 | [diff] [blame] | 73 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 74 | protected: |
Adlai Holler | 302e8fb | 2020-09-14 11:58:06 -0400 | [diff] [blame] | 75 | SkImage_GpuBase(sk_sp<GrImageContext>, SkISize size, uint32_t uniqueID, SkColorType, |
| 76 | SkAlphaType, sk_sp<SkColorSpace>); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 77 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 78 | // Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called, |
| 79 | // if not null, immediately if this function fails. Othwerwise, it is installed in the |
| 80 | // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not |
| 81 | // be null. |
Brian Salomon | f143274 | 2020-11-09 15:40:27 -0500 | [diff] [blame] | 82 | static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(GrRecordingContext*, |
| 83 | SkISize dimensions, |
| 84 | GrBackendFormat, |
| 85 | GrMipmapped, |
| 86 | PromiseImageTextureFulfillProc, |
| 87 | sk_sp<GrRefCntedCallback> releaseHelper); |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 88 | |
Adlai Holler | 302e8fb | 2020-09-14 11:58:06 -0400 | [diff] [blame] | 89 | sk_sp<GrImageContext> fContext; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 90 | |
| 91 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 92 | using INHERITED = SkImage_Base; |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
Jim Van Verth | 8026ccc | 2018-10-04 13:10:39 -0400 | [diff] [blame] | 95 | #endif |