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 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/gpu/ganesh/GrImageContext.h" 13 #include "src/image/SkImage_Base.h" 14 15 #include <cstddef> 16 #include <cstdint> 17 18 class GrBackendFormat; 19 class GrBackendTexture; 20 class GrCaps; 21 class GrContextThreadSafeProxy; 22 class GrDirectContext; 23 class GrRecordingContext; 24 class GrTextureProxy; 25 class SkBitmap; 26 class SkColorSpace; 27 class SkImage; 28 enum SkAlphaType : int; 29 enum SkColorType : int; 30 enum class GrColorType; 31 struct SkIRect; 32 struct SkISize; 33 struct SkImageInfo; 34 namespace skgpu { 35 enum class Mipmapped : bool; 36 class RefCntedCallback; 37 } 38 39 class SkImage_GpuBase : public SkImage_Base { 40 public: context()41 GrImageContext* context() const final { return fContext.get(); } 42 43 bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final; 44 sk_sp<SkImage> onMakeSubset(const SkIRect& subset, GrDirectContext*) const final; 45 46 bool onReadPixels(GrDirectContext *dContext, 47 const SkImageInfo& dstInfo, 48 void* dstPixels, 49 size_t dstRB, 50 int srcX, 51 int srcY, 52 CachingHint) const override; 53 54 bool onIsValid(GrRecordingContext*) const final; 55 56 static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex, 57 GrColorType grCT, SkColorType ct, SkAlphaType at, 58 sk_sp<SkColorSpace> cs); 59 static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex, 60 SkAlphaType); 61 62 // Helper for making a lazy proxy for a promise image. 63 // PromiseImageTextureFulfillProc must not be null. 64 static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy( 65 GrContextThreadSafeProxy*, 66 SkISize dimensions, 67 GrBackendFormat, 68 skgpu::Mipmapped, 69 PromiseImageTextureFulfillProc, 70 sk_sp<skgpu::RefCntedCallback> releaseHelper); 71 72 protected: 73 SkImage_GpuBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID); 74 75 sk_sp<GrImageContext> fContext; 76 77 #if defined(SK_GRAPHITE) 78 sk_sp<SkImage> onMakeTextureImage(skgpu::graphite::Recorder*, 79 RequiredImageProperties) const final; 80 sk_sp<SkImage> onMakeSubset(const SkIRect& subset, 81 skgpu::graphite::Recorder*, 82 RequiredImageProperties) const final; 83 sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, 84 sk_sp<SkColorSpace>, 85 skgpu::graphite::Recorder*, 86 RequiredImageProperties) const final; 87 #endif 88 }; 89 90 #endif 91