blob: 250a9c7c031af35f911063c44e2bfea16ee90852 [file] [log] [blame]
Jim Van Verth8026ccc2018-10-04 13:10:39 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#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 Verth8026ccc2018-10-04 13:10:39 -040017
Brian Osmane9560492019-02-05 17:00:03 -050018class GrColorSpaceXform;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040019class SkColorSpace;
20
21class SkImage_GpuBase : public SkImage_Base {
22public:
Jim Van Verth8026ccc2018-10-04 13:10:39 -040023 GrContext* context() const final { return fContext.get(); }
24
Brian Osmane50cdf02018-10-19 13:02:14 -040025 bool getROPixels(SkBitmap*, CachingHint) const final;
Robert Phillips6603a172019-03-05 12:35:44 -050026 sk_sp<SkImage> onMakeSubset(GrRecordingContext*, const SkIRect& subset) const final;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040027
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040028 bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
29 int srcX, int srcY, CachingHint) const override;
30
Brian Salomonecbb0fb2020-02-28 18:07:32 -050031 GrSurfaceProxyView refView(GrRecordingContext*, GrMipMapped) const final;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040032
Greg Danielcc21d0c2020-02-05 16:58:40 -050033 GrSurfaceProxyView refPinnedView(GrRecordingContext* context, uint32_t* uniqueID) const final {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040034 *uniqueID = this->uniqueID();
Greg Danielcc21d0c2020-02-05 16:58:40 -050035 SkASSERT(this->view(context));
36 return *this->view(context);
Jim Van Verth8026ccc2018-10-04 13:10:39 -040037 }
38
39 GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
40 GrSurfaceOrigin* origin) const final;
41
Greg Daniel7c902112020-03-06 13:07:10 -050042 GrTexture* getTexture() const;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040043
Jim Van Verth8026ccc2018-10-04 13:10:39 -040044 bool onIsValid(GrContext*) const final;
45
Jim Van Verth21bd60d2018-10-12 15:00:20 -040046#if GR_TEST_UTILS
Robert Phillipsfd0d9702019-02-01 10:19:42 -050047 void resetContext(sk_sp<GrContext> newContext);
Jim Van Verth21bd60d2018-10-12 15:00:20 -040048#endif
49
Robert Phillips62221e72019-07-24 15:07:38 -040050 static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex,
51 GrColorType grCT, SkColorType ct, SkAlphaType at,
Jim Van Verth8026ccc2018-10-04 13:10:39 -040052 sk_sp<SkColorSpace> cs);
Robert Phillipsead321b2019-12-19 10:16:32 -050053 static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex,
54 SkAlphaType);
Jim Van Verth0e671942018-11-09 12:03:57 -050055 static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
Jim Van Verth53275362018-11-09 15:42:35 -050056 int numTextures, const SkYUVAIndex [4],
57 GrSurfaceOrigin imageOrigin,
Greg Danielc7672092020-02-06 14:32:54 -050058 GrSurfaceProxyView tempViews[4]);
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040059
Jim Van Verth53275362018-11-09 15:42:35 -050060 static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
61 return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
62 : kOpaque_SkAlphaType;
63 }
64
Brian Salomoncdd8a0a2019-01-10 12:09:52 -050065 using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext;
66 using PromiseImageTextureFulfillProc =
67 SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc;
68 using PromiseImageTextureReleaseProc =
69 SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc;
70 using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040071
Jim Van Verth8026ccc2018-10-04 13:10:39 -040072protected:
Brian Salomon9f2b86c2019-10-22 10:37:46 -040073 SkImage_GpuBase(sk_sp<GrContext>, SkISize size, uint32_t uniqueID, SkColorType, SkAlphaType,
74 sk_sp<SkColorSpace>);
75
Brian Salomon0cc57542019-03-08 13:28:46 -050076 using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion;
Brian Salomonbe5a0932018-12-10 10:03:26 -050077 // 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 Daniel3a365112020-02-14 10:47:18 -050082 GrContext*, int width, int height, GrColorType, GrBackendFormat, GrMipMapped,
83 PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
Brian Salomon0cc57542019-03-08 13:28:46 -050084 PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
Brian Salomonbe5a0932018-12-10 10:03:26 -050085
Jim Van Verth0e671942018-11-09 12:03:57 -050086 static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
87 const SkRect& rect, SkYUVColorSpace yuvColorSpace,
Brian Osmane9560492019-02-05 17:00:03 -050088 sk_sp<GrColorSpaceXform> colorSpaceXform,
Greg Danielc7672092020-02-06 14:32:54 -050089 GrSurfaceProxyView views[4],
Jim Van Verth0e671942018-11-09 12:03:57 -050090 const SkYUVAIndex yuvaIndices[4]);
91
Brian Salomon5ad6fd32019-03-21 15:30:08 -040092 sk_sp<GrContext> fContext;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040093
94private:
95 typedef SkImage_Base INHERITED;
96};
97
Jim Van Verth8026ccc2018-10-04 13:10:39 -040098#endif