blob: f4f763e53469cbca9f943eec587cbca789e7d8a4 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/private/GrTypesPriv.h"
15#include "src/image/SkImage_Base.h"
Jim Van Verth8026ccc2018-10-04 13:10:39 -040016
Brian Osmane9560492019-02-05 17:00:03 -050017class GrColorSpaceXform;
Robert Phillips1a578572020-07-13 13:17:09 -040018class GrDirectContext;
Adlai Holler302e8fb2020-09-14 11:58:06 -040019class GrImageContext;
Brian Salomon590f5672020-12-16 11:44:47 -050020class GrSurfaceFillContext;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040021class SkColorSpace;
22
23class SkImage_GpuBase : public SkImage_Base {
24public:
Adlai Holler302e8fb2020-09-14 11:58:06 -040025 GrImageContext* context() const final { return fContext.get(); }
Jim Van Verth8026ccc2018-10-04 13:10:39 -040026
Adlai Hollerbcfc5542020-08-27 12:44:07 -040027 bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final;
Adlai Holler872a32c2020-07-10 14:33:22 -040028 sk_sp<SkImage> onMakeSubset(const SkIRect& subset, GrDirectContext*) const final;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040029
Adlai Hollerbcfc5542020-08-27 12:44:07 -040030 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 Verth8bbce0e2018-10-08 14:34:52 -040037
Brian Salomon7e67dca2020-07-21 09:27:25 -040038 GrSurfaceProxyView refView(GrRecordingContext*, GrMipmapped) const final;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040039
Greg Danielcc21d0c2020-02-05 16:58:40 -050040 GrSurfaceProxyView refPinnedView(GrRecordingContext* context, uint32_t* uniqueID) const final {
Jim Van Verth8026ccc2018-10-04 13:10:39 -040041 *uniqueID = this->uniqueID();
Greg Danielcc21d0c2020-02-05 16:58:40 -050042 SkASSERT(this->view(context));
43 return *this->view(context);
Jim Van Verth8026ccc2018-10-04 13:10:39 -040044 }
45
46 GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
47 GrSurfaceOrigin* origin) const final;
48
Greg Daniel7c902112020-03-06 13:07:10 -050049 GrTexture* getTexture() const;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040050
Robert Phillips4a3ebc22020-07-10 11:27:43 -040051 bool onIsValid(GrRecordingContext*) const final;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040052
Jim Van Verth21bd60d2018-10-12 15:00:20 -040053#if GR_TEST_UTILS
Adlai Holler302e8fb2020-09-14 11:58:06 -040054 void resetContext(sk_sp<GrImageContext> newContext);
Jim Van Verth21bd60d2018-10-12 15:00:20 -040055#endif
56
Robert Phillips62221e72019-07-24 15:07:38 -040057 static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex,
58 GrColorType grCT, SkColorType ct, SkAlphaType at,
Jim Van Verth8026ccc2018-10-04 13:10:39 -040059 sk_sp<SkColorSpace> cs);
Robert Phillipsead321b2019-12-19 10:16:32 -050060 static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex,
61 SkAlphaType);
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040062
Jim Van Verth53275362018-11-09 15:42:35 -050063 static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
64 return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
65 : kOpaque_SkAlphaType;
66 }
67
Brian Salomoncdd8a0a2019-01-10 12:09:52 -050068 using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext;
69 using PromiseImageTextureFulfillProc =
70 SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc;
71 using PromiseImageTextureReleaseProc =
72 SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc;
Jim Van Verth8bbce0e2018-10-08 14:34:52 -040073
Jim Van Verth8026ccc2018-10-04 13:10:39 -040074protected:
Adlai Holler302e8fb2020-09-14 11:58:06 -040075 SkImage_GpuBase(sk_sp<GrImageContext>, SkISize size, uint32_t uniqueID, SkColorType,
76 SkAlphaType, sk_sp<SkColorSpace>);
Brian Salomon9f2b86c2019-10-22 10:37:46 -040077
Brian Salomonbe5a0932018-12-10 10:03:26 -050078 // 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 Salomonf1432742020-11-09 15:40:27 -050082 static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(GrRecordingContext*,
83 SkISize dimensions,
84 GrBackendFormat,
85 GrMipmapped,
86 PromiseImageTextureFulfillProc,
87 sk_sp<GrRefCntedCallback> releaseHelper);
Brian Salomonbe5a0932018-12-10 10:03:26 -050088
Adlai Holler302e8fb2020-09-14 11:58:06 -040089 sk_sp<GrImageContext> fContext;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040090
91private:
John Stiles7571f9e2020-09-02 22:42:33 -040092 using INHERITED = SkImage_Base;
Jim Van Verth8026ccc2018-10-04 13:10:39 -040093};
94
Jim Van Verth8026ccc2018-10-04 13:10:39 -040095#endif