diff options
author | Michael Ludwig <michaelludwig@google.com> | 2023-12-11 09:33:26 -0500 |
---|---|---|
committer | SkCQ <skcq-be@skia-corp.google.com.iam.gserviceaccount.com> | 2023-12-12 17:46:15 +0000 |
commit | 3678212a85b83854fc24fbf9d9090686c48acdce (patch) | |
tree | 20b484f7a672ff330e4dc7afa34b25ef0c483d02 | |
parent | f82251f0091c52eee7125c06786d3c7e72c15327 (diff) | |
download | skia-3678212a85b83854fc24fbf9d9090686c48acdce.tar.gz |
[skif] Remove subset parameter from SkSpecialImage::asImage()
asImage() is now a very simple wrapping operation from one type to
an SkImage of the same backing.
Bug: b/299474380
Change-Id: Ifa180bdcb7ff49cca6d70b6fade4a0628aaf5049
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/787937
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: James Godfrey-Kittle <jamesgk@google.com>
-rw-r--r-- | src/core/SkSpecialImage.cpp | 24 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 22 | ||||
-rw-r--r-- | src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp | 43 | ||||
-rw-r--r-- | src/gpu/graphite/SpecialImage_Graphite.cpp | 7 |
4 files changed, 13 insertions, 83 deletions
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index d28ed9ed24..bedb563d83 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -46,15 +46,6 @@ void SkSpecialImage::draw(SkCanvas* canvas, : SkCanvas::kFast_SrcRectConstraint); } -sk_sp<SkImage> SkSpecialImage::asImage(const SkIRect* subset) const { - if (subset) { - SkIRect absolute = subset->makeOffset(this->subset().topLeft()); - return this->onAsImage(&absolute); - } else { - return this->onAsImage(nullptr); - } -} - sk_sp<SkShader> SkSpecialImage::asShader(SkTileMode tileMode, const SkSamplingOptions& sampling, const SkMatrix& lm) const { @@ -85,26 +76,13 @@ public: size_t getSize() const override { return fBitmap.computeByteSize(); } + sk_sp<SkImage> asImage() const override { return fBitmap.asImage(); } sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { // No need to extract subset, onGetROPixels handles that when needed return SkSpecialImages::MakeFromRaster(subset, fBitmap, this->props()); } - sk_sp<SkImage> onAsImage(const SkIRect* subset) const override { - if (subset) { - SkBitmap subsetBM; - - if (!fBitmap.extractSubset(&subsetBM, *subset)) { - return nullptr; - } - - return subsetBM.asImage(); - } - - return fBitmap.asImage(); - } - sk_sp<SkShader> onAsShader(SkTileMode tileMode, const SkSamplingOptions& sampling, const SkMatrix& lm) const override { diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index 04b7e56699..89c82bbb91 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -90,18 +90,14 @@ public: } /** - * Create an SkImage from the contents of this special image optionally extracting a subset. - * It may or may not point to the same backing memory. - * Note: when no 'subset' parameter is specified the the entire SkSpecialImage will be - * returned - including whatever extra padding may have resulted from a loose fit! - * When the 'subset' parameter is specified the returned image will be tight even if that - * entails a copy! The 'subset' is relative to this special image's content rect. + * Create an SkImage view of the contents of this special image, pointing to the same + * underlying memory. + * + * TODO: If SkImages::MakeFiltered were to return an SkShader that accounted for the subset + * constraint and offset, then this could move to a private virtual for use in draw() and + * asShader(). */ - // TODO: The only version that uses the subset is the tile image filter, and that doesn't need - // to if it can be rewritten to use asShader() and SkTileModes. Similarly, the only use case of - // asImage() w/o a subset is SkImage::makeFiltered() and that could/should return an SkShader so - // that users don't need to worry about correctly applying the subset, etc. - sk_sp<SkImage> asImage(const SkIRect* subset = nullptr) const; + virtual sk_sp<SkImage> asImage() const = 0; /** * Create an SkShader that samples the contents of this special image, applying tile mode for @@ -132,10 +128,6 @@ protected: // from the content rect by the non-virtual makeSubset(). virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; - // This subset (when not null) is relative to the backing store's coordinate frame, it has - // already been mapped from the content rect by the non-virtual asImage(). - virtual sk_sp<SkImage> onAsImage(const SkIRect* subset) const = 0; - virtual sk_sp<SkShader> onAsShader(SkTileMode, const SkSamplingOptions&, const SkMatrix&) const = 0; diff --git a/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp b/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp index db4a592008..2b61fe2510 100644 --- a/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp +++ b/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp @@ -18,13 +18,11 @@ #include "include/private/base/SkPoint_impl.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" #include "src/core/SkSpecialImage.h" -#include "src/gpu/SkBackingFit.h" #include "src/gpu/ganesh/GrSurfaceProxy.h" #include "src/gpu/ganesh/GrSurfaceProxyPriv.h" #include "src/gpu/ganesh/GrSurfaceProxyView.h" #include "src/gpu/ganesh/image/GrImageUtils.h" #include "src/gpu/ganesh/image/SkImage_Ganesh.h" -#include "src/image/SkImage_Base.h" #include "src/shaders/SkImageShader.h" #include <cstddef> @@ -35,13 +33,6 @@ struct SkSamplingOptions; enum SkColorType : int; enum class SkTileMode; -static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, - GrSurfaceProxyView view, - const SkColorInfo& colorInfo) { - return sk_make_sp<SkImage_Ganesh>( - sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view), colorInfo); -} - class SkSpecialImage_Gpu final : public SkSpecialImage { public: SkSpecialImage_Gpu(GrRecordingContext* context, @@ -67,36 +58,10 @@ public: fContext, subset, this->uniqueID(), fView, this->colorInfo(), this->props()); } - sk_sp<SkImage> onAsImage(const SkIRect* subset) const override { - GrSurfaceProxy* proxy = fView.proxy(); - if (subset) { - if (proxy->isFunctionallyExact() && *subset == SkIRect::MakeSize(proxy->dimensions())) { - proxy->priv().exactify(false); - // The existing GrTexture is already tight so reuse it in the SkImage - return wrap_proxy_in_image(fContext, fView, this->colorInfo()); - } - - auto subsetView = GrSurfaceProxyView::Copy(fContext, - fView, - skgpu::Mipmapped::kNo, - *subset, - SkBackingFit::kExact, - skgpu::Budgeted::kYes, - /*label=*/"SkSpecialImage_AsImage"); - if (!subsetView) { - return nullptr; - } - SkASSERT(subsetView.asTextureProxy()); - SkASSERT(subsetView.proxy()->priv().isExact()); - - // MDB: this is acceptable (wrapping subsetProxy in an SkImage) bc Copy will - // return a kExact-backed proxy - return wrap_proxy_in_image(fContext, std::move(subsetView), this->colorInfo()); - } - - proxy->priv().exactify(true); - - return wrap_proxy_in_image(fContext, fView, this->colorInfo()); + sk_sp<SkImage> asImage() const override { + fView.proxy()->priv().exactify(true); + return sk_make_sp<SkImage_Ganesh>( + sk_ref_sp(fContext), this->uniqueID(), fView, this->colorInfo()); } sk_sp<SkShader> onAsShader(SkTileMode tileMode, diff --git a/src/gpu/graphite/SpecialImage_Graphite.cpp b/src/gpu/graphite/SpecialImage_Graphite.cpp index 73e37c10d4..c44438e3b8 100644 --- a/src/gpu/graphite/SpecialImage_Graphite.cpp +++ b/src/gpu/graphite/SpecialImage_Graphite.cpp @@ -46,12 +46,7 @@ public: this->props()); } - sk_sp<SkImage> onAsImage(const SkIRect* subset) const override { - if (subset) { - // TODO: fill this in - return nullptr; - } - + sk_sp<SkImage> asImage() const override { return sk_make_sp<Image>(this->uniqueID(), fTextureProxyView, this->colorInfo()); } |