diff options
author | Michael Ludwig <michaelludwig@google.com> | 2023-12-11 09:32:44 -0500 |
---|---|---|
committer | SkCQ <skcq-be@skia-corp.google.com.iam.gserviceaccount.com> | 2023-12-12 17:34:55 +0000 |
commit | f82251f0091c52eee7125c06786d3c7e72c15327 (patch) | |
tree | df798fcc4b09b75ef1880b790adfabd85da66e84 | |
parent | 16298087c2772faf97e4ee0198bb9532288d5445 (diff) | |
download | skia-f82251f0091c52eee7125c06786d3c7e72c15327.tar.gz |
[skif] SkSpecialImage::draw() no longer virtual, can use fast constraint
All onDraw() implementations were essentially the same except that they
inlined their overload of the non-subsett'ed asImage(). This combines
them into a non-virtual function on SkSpecialImage and adds a
parameter switch between strict and fast constraints.
No callers use the fast constraint yet, but will be used in
skif::FilterResult to avoid shader-based tiling when possible.
This consolidation helps move SkSpecialImage and subclasses towards
just a wrapper around SkImage.
Bug: b/299474380
Bug: b/315351386
Change-Id: Icdf34b657a6cc59f0885e4d0b2dde4b85acb10ff
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/787917
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: James Godfrey-Kittle <jamesgk@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
-rw-r--r-- | src/core/SkSpecialImage.cpp | 19 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 10 | ||||
-rw-r--r-- | src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp | 28 | ||||
-rw-r--r-- | src/gpu/graphite/SpecialImage_Graphite.cpp | 15 |
4 files changed, 13 insertions, 59 deletions
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 10e2e9edcf..d28ed9ed24 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -35,6 +35,17 @@ SkSpecialImage::SkSpecialImage(const SkIRect& subset, , fProps(props) { } +void SkSpecialImage::draw(SkCanvas* canvas, + SkScalar x, SkScalar y, + const SkSamplingOptions& sampling, + const SkPaint* paint, bool strict) const { + SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); + + canvas->drawImageRect(this->asImage(), SkRect::Make(this->subset()), dst, + sampling, paint, strict ? SkCanvas::kStrict_SrcRectConstraint + : SkCanvas::kFast_SrcRectConstraint); +} + sk_sp<SkImage> SkSpecialImage::asImage(const SkIRect* subset) const { if (subset) { SkIRect absolute = subset->makeOffset(this->subset().topLeft()); @@ -74,14 +85,6 @@ public: size_t getSize() const override { return fBitmap.computeByteSize(); } - void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling, - const SkPaint* paint) const override { - SkRect dst = SkRect::MakeXYWH(x, y, - this->subset().width(), this->subset().height()); - - canvas->drawImageRect(fBitmap.asImage(), SkRect::Make(this->subset()), dst, - sampling, paint, SkCanvas::kStrict_SrcRectConstraint); - } sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { // No need to extract subset, onGetROPixels handles that when needed diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index 1e63c69e48..04b7e56699 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -73,9 +73,8 @@ public: void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling, - const SkPaint* paint) const { - return this->onDraw(canvas, x, y, sampling, paint); - } + const SkPaint* paint, + bool strict = true) const; void draw(SkCanvas* canvas, SkScalar x, SkScalar y) const { this->draw(canvas, x, y, SkSamplingOptions(), nullptr); } @@ -129,11 +128,6 @@ protected: const SkColorInfo&, const SkSurfaceProps&); - virtual void onDraw(SkCanvas*, - SkScalar x, SkScalar y, - const SkSamplingOptions&, - const SkPaint*) const = 0; - // This subset is relative to the backing store's coordinate frame, it has already been mapped // from the content rect by the non-virtual makeSubset(). virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; diff --git a/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp b/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp index 5ad28fab58..db4a592008 100644 --- a/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp +++ b/src/gpu/ganesh/image/SkSpecialImage_Ganesh.cpp @@ -7,18 +7,15 @@ #include "src/gpu/ganesh/image/SkSpecialImage_Ganesh.h" -#include "include/core/SkCanvas.h" #include "include/core/SkColorSpace.h" // IWYU pragma: keep #include "include/core/SkImage.h" #include "include/core/SkImageInfo.h" #include "include/core/SkMatrix.h" #include "include/core/SkRect.h" -#include "include/core/SkScalar.h" #include "include/gpu/GpuTypes.h" #include "include/gpu/GrRecordingContext.h" #include "include/private/base/SkAssert.h" #include "include/private/base/SkPoint_impl.h" -#include "include/private/gpu/ganesh/GrImageContext.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" #include "src/core/SkSpecialImage.h" #include "src/gpu/SkBackingFit.h" @@ -33,7 +30,6 @@ #include <cstddef> #include <utility> -class SkPaint; class SkShader; struct SkSamplingOptions; enum SkColorType : int; @@ -62,30 +58,6 @@ public: bool isGaneshBacked() const override { return true; } - void onDraw(SkCanvas* canvas, - SkScalar x, - SkScalar y, - const SkSamplingOptions& sampling, - const SkPaint* paint) const override { - SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); - - // TODO: In this instance we know we're going to draw a sub-portion of the backing - // texture into the canvas so it is okay to wrap it in an SkImage. This poses - // some problems for full deferral however in that when the deferred SkImage_Ganesh - // instantiates itself it is going to have to either be okay with having a larger - // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs - // to be tightened (if it is deferred). - sk_sp<SkImage> img = sk_sp<SkImage>(new SkImage_Ganesh( - sk_ref_sp(canvas->recordingContext()), this->uniqueID(), fView, this->colorInfo())); - - canvas->drawImageRect(img, - SkRect::Make(this->subset()), - dst, - sampling, - paint, - SkCanvas::kStrict_SrcRectConstraint); - } - GrRecordingContext* getContext() const override { return fContext; } GrSurfaceProxyView view(GrRecordingContext*) const { return fView; } diff --git a/src/gpu/graphite/SpecialImage_Graphite.cpp b/src/gpu/graphite/SpecialImage_Graphite.cpp index ba9e57dde4..73e37c10d4 100644 --- a/src/gpu/graphite/SpecialImage_Graphite.cpp +++ b/src/gpu/graphite/SpecialImage_Graphite.cpp @@ -38,21 +38,6 @@ public: TextureProxyView textureProxyView() const { return fTextureProxyView; } - void onDraw(SkCanvas* canvas, - SkScalar x, SkScalar y, - const SkSamplingOptions& sampling, - const SkPaint* paint) const override { - SkRect dst = SkRect::MakeXYWH(x, y, - this->subset().width(), this->subset().height()); - - sk_sp<SkImage> img = sk_sp<SkImage>(new skgpu::graphite::Image(this->uniqueID(), - fTextureProxyView, - this->colorInfo())); - - canvas->drawImageRect(img, SkRect::Make(this->subset()), dst, - sampling, paint, SkCanvas::kStrict_SrcRectConstraint); - } - sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { return SkSpecialImages::MakeGraphite(subset, this->uniqueID(), |