blob: f64633c5109b2b1737b92526fe0b93ed26bcca45 [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
Robert Phillips6603a172019-03-05 12:35:44 -050031 sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext* context) const override {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040032 // we shouldn't end up calling this
33 SkASSERT(false);
Robert Phillips6603a172019-03-05 12:35:44 -050034 return this->INHERITED::asTextureProxyRef(context);
Jim Van Verth8026ccc2018-10-04 13:10:39 -040035 }
Robert Phillips9338c602019-02-19 12:52:29 -050036 sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&,
Jim Van Verth8026ccc2018-10-04 13:10:39 -040037 SkScalar scaleAdjust[2]) const final;
38
Robert Phillips6603a172019-03-05 12:35:44 -050039 sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext* context,
40 uint32_t* uniqueID) const final {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040041 *uniqueID = this->uniqueID();
Robert Phillips6603a172019-03-05 12:35:44 -050042 return this->asTextureProxyRef(context);
Jim Van Verth8026ccc2018-10-04 13:10:39 -040043 }
44
45 GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
46 GrSurfaceOrigin* origin) const final;
47
48 GrTexture* onGetTexture() const final;
49
Jim Van Verth8026ccc2018-10-04 13:10:39 -040050 bool onIsValid(GrContext*) const final;
51
Jim Van Verth21bd60d2018-10-12 15:00:20 -040052#if GR_TEST_UTILS
Robert Phillipsfd0d9702019-02-01 10:19:42 -050053 void resetContext(sk_sp<GrContext> newContext);
Jim Van Verth21bd60d2018-10-12 15:00:20 -040054#endif
55
Robert Phillips62221e72019-07-24 15:07:38 -040056 static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex,
57 GrColorType grCT, SkColorType ct, SkAlphaType at,
Jim Van Verth8026ccc2018-10-04 13:10:39 -040058 sk_sp<SkColorSpace> cs);
Jim Van Verth0e671942018-11-09 12:03:57 -050059 static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
Jim Van Verth53275362018-11-09 15:42:35 -050060 int numTextures, const SkYUVAIndex [4],
61 GrSurfaceOrigin imageOrigin,
Jim Van Verth0e671942018-11-09 12:03:57 -050062 sk_sp<GrTextureProxy> tempTextureProxies[4]);
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040063
Jim Van Verth53275362018-11-09 15:42:35 -050064 static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
65 return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
66 : kOpaque_SkAlphaType;
67 }
68
Brian Salomoncdd8a0a2019-01-10 12:09:52 -050069 using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext;
70 using PromiseImageTextureFulfillProc =
71 SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc;
72 using PromiseImageTextureReleaseProc =
73 SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc;
74 using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040075
Jim Van Verth8026ccc2018-10-04 13:10:39 -040076protected:
Brian Salomon9f2b86c2019-10-22 10:37:46 -040077 SkImage_GpuBase(sk_sp<GrContext>, SkISize size, uint32_t uniqueID, SkColorType, SkAlphaType,
78 sk_sp<SkColorSpace>);
79
Brian Salomon0cc57542019-03-08 13:28:46 -050080 using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion;
Brian Salomonbe5a0932018-12-10 10:03:26 -050081 // 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 Phillipsc80b0e92019-07-23 10:27:09 -040086 GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat,
Brian Salomoncdd8a0a2019-01-10 12:09:52 -050087 GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
Brian Salomon0cc57542019-03-08 13:28:46 -050088 PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
Brian Salomonbe5a0932018-12-10 10:03:26 -050089
Jim Van Verth0e671942018-11-09 12:03:57 -050090 static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
91 const SkRect& rect, SkYUVColorSpace yuvColorSpace,
Brian Osmane9560492019-02-05 17:00:03 -050092 sk_sp<GrColorSpaceXform> colorSpaceXform,
Jim Van Verth0e671942018-11-09 12:03:57 -050093 const sk_sp<GrTextureProxy> proxies[4],
94 const SkYUVAIndex yuvaIndices[4]);
95
Brian Salomon5ad6fd32019-03-21 15:30:08 -040096 sk_sp<GrContext> fContext;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040097
98private:
99 typedef SkImage_Base INHERITED;
100};
101
Jim Van Verth8026ccc2018-10-04 13:10:39 -0400102#endif