1 /* 2 * Copyright 2021 Google LLC 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 skgpu_graphite_Image_Graphite_DEFINED 9 #define skgpu_graphite_Image_Graphite_DEFINED 10 11 #include "src/gpu/graphite/Image_Base_Graphite.h" 12 13 #include "src/gpu/graphite/TextureProxyView.h" 14 15 namespace skgpu { 16 class RefCntedCallback; 17 } 18 19 namespace skgpu::graphite { 20 21 class Context; 22 class Device; 23 class Recorder; 24 25 class Image final : public Image_Base { 26 public: 27 Image(TextureProxyView, const SkColorInfo&); 28 ~Image() override; 29 30 // Create an Image that wraps the Device and automatically flushes or references the Device's 31 // pending tasks when the Image is used in a draw to another canvas. 32 static sk_sp<Image> WrapDevice(sk_sp<Device> device); 33 34 // Create an Image by copying the provided texture proxy view into a new texturable proxy. 35 // The source texture does not have to be texturable if it is blittable. 36 static sk_sp<Image> Copy(Recorder*, 37 const TextureProxyView& srcView, 38 const SkColorInfo&, 39 const SkIRect& subset, 40 Budgeted, 41 Mipmapped, 42 SkBackingFit, 43 std::string_view label); 44 textureProxyView()45 const TextureProxyView& textureProxyView() const { return fTextureProxyView; } 46 type()47 SkImage_Base::Type type() const override { return SkImage_Base::Type::kGraphite; } 48 onHasMipmaps()49 bool onHasMipmaps() const override { 50 return fTextureProxyView.proxy()->mipmapped() == Mipmapped::kYes; 51 } 52 onIsProtected()53 bool onIsProtected() const override { 54 return fTextureProxyView.proxy()->isProtected(); 55 } 56 57 size_t textureSize() const override; 58 59 sk_sp<Image> copyImage(Recorder*, 60 const SkIRect& subset, 61 Budgeted, 62 Mipmapped, 63 SkBackingFit, 64 std::string_view label) const override; 65 66 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const override; 67 68 #if defined(GPU_TEST_UTILS) 69 bool readPixelsGraphite(Recorder*, const SkPixmap& dst, int srcX, int srcY) const override; 70 #endif 71 72 private: 73 74 TextureProxyView fTextureProxyView; 75 }; 76 77 } // namespace skgpu::graphite 78 79 #endif // skgpu_graphite_Image_Graphite_DEFINED 80