From e43d00a219721c9413ab0686c5ed6a7124ae0d3d Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Wed, 2 Mar 2022 16:46:01 -0500 Subject: [PATCH] [graphite] Add isGaneshBacked and isGraphiteBacked Bug: skia:12845 Change-Id: Ib0b87966b1559b368759ce69c48f0fd27597503a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/514836 Reviewed-by: Greg Daniel Commit-Queue: Jim Van Verth --- experimental/graphite/src/Image_Graphite.cpp | 2 +- experimental/graphite/src/Image_Graphite.h | 2 ++ include/core/SkImage.h | 2 +- src/image/SkImage.cpp | 4 +++- src/image/SkImage_Base.h | 7 +++++-- src/image/SkImage_Gpu.cpp | 4 ++-- src/image/SkImage_Gpu.h | 2 +- src/image/SkImage_GpuYUVA.h | 2 +- tools/gpu/ProxyUtils.cpp | 2 +- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/experimental/graphite/src/Image_Graphite.cpp b/experimental/graphite/src/Image_Graphite.cpp index e8a34f1ad2..8a531a8588 100644 --- a/experimental/graphite/src/Image_Graphite.cpp +++ b/experimental/graphite/src/Image_Graphite.cpp @@ -43,7 +43,7 @@ sk_sp SkImage::makeTextureImage(skgpu::Recorder* recorder, mipmapped = skgpu::Mipmapped::kNo; } - if (this->isTextureBacked()) { + if (as_IB(this)->isGraphiteBacked()) { if (mipmapped == skgpu::Mipmapped::kNo || this->hasMipmaps()) { const SkImage* image = this; return sk_ref_sp(const_cast(image)); diff --git a/experimental/graphite/src/Image_Graphite.h b/experimental/graphite/src/Image_Graphite.h index 5a4b81d105..d1952da8e1 100644 --- a/experimental/graphite/src/Image_Graphite.h +++ b/experimental/graphite/src/Image_Graphite.h @@ -29,6 +29,8 @@ public: bool onHasMipmaps() const override { return false; } + bool isGraphiteBacked() const override { return true; } + bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint = kAllow_CachingHint) const override { return false; } diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 1b2e75113c..28d9d5c6f5 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -731,7 +731,7 @@ public: */ bool peekPixels(SkPixmap* pixmap) const; - /** Returns true the contents of SkImage was created on or uploaded to GPU memory, + /** Returns true if the contents of SkImage was created on or uploaded to GPU memory, and is available as a GPU texture. @return true if SkImage is a GPU texture diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 0ca2d90fa2..19d35364e8 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -216,7 +216,9 @@ sk_sp SkImage::makeSubset(const SkIRect& subset, GrDirectContext* direc #if SK_SUPPORT_GPU -bool SkImage::isTextureBacked() const { return as_IB(this)->onIsTextureBacked(); } +bool SkImage::isTextureBacked() const { + return as_IB(this)->isGaneshBacked() || as_IB(this)->isGraphiteBacked(); +} size_t SkImage::textureSize() const { return as_IB(this)->onTextureSize(); } diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 197faf1360..3d3ad0f107 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -153,8 +153,11 @@ public: // True for picture-backed and codec-backed virtual bool onIsLazyGenerated() const { return false; } - // True for images instantiated in GPU memory - virtual bool onIsTextureBacked() const { return false; } + // True for images instantiated by Ganesh in GPU memory + virtual bool isGaneshBacked() const { return false; } + + // True for images instantiated by Graphite in GPU memory + virtual bool isGraphiteBacked() const { return false; } // Amount of texture memory used by texture-backed images. virtual size_t onTextureSize() const { return 0; } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index eb4084a114..cb50980d18 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -540,12 +540,12 @@ sk_sp SkImage::makeTextureImage(GrDirectContext* dContext, mipmapped = GrMipmapped::kNo; } - if (this->isTextureBacked()) { + if (as_IB(this)->isGaneshBacked()) { if (!as_IB(this)->context()->priv().matches(dContext)) { return nullptr; } - if (this->isTextureBacked() && (mipmapped == GrMipmapped::kNo || this->hasMipmaps())) { + if (mipmapped == GrMipmapped::kNo || this->hasMipmaps()) { return sk_ref_sp(const_cast(this)); } } diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 0d2427ea52..b17ce4b03c 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -46,7 +46,7 @@ public: GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const final; - bool onIsTextureBacked() const override { return true; } + bool isGaneshBacked() const override { return true; } size_t onTextureSize() const override; diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h index b82c774199..375c28ff10 100644 --- a/src/image/SkImage_GpuYUVA.h +++ b/src/image/SkImage_GpuYUVA.h @@ -32,7 +32,7 @@ public: GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) const override; - bool onIsTextureBacked() const override { return true; } + bool isGaneshBacked() const override { return true; } size_t onTextureSize() const override; diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index 85450a51a8..10f387a14a 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -29,7 +29,7 @@ namespace sk_gpu_test { GrTextureProxy* GetTextureImageProxy(SkImage* image, GrRecordingContext* rContext) { - if (!image->isTextureBacked() || as_IB(image)->isYUVA()) { + if (!as_IB(image)->isGaneshBacked() || as_IB(image)->isYUVA()) { return nullptr; } if (!rContext) {