Rename SkPaintImageFilter to SkShaderImageFilter
Bug: skia:11230
Change-Id: I4a90191d858265e60a817aa04c3e1aacf345a7f2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371965
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/gn/effects_imagefilters.gni b/gn/effects_imagefilters.gni
index d541aa0..223dc34 100644
--- a/gn/effects_imagefilters.gni
+++ b/gn/effects_imagefilters.gni
@@ -26,10 +26,9 @@
"$_src/effects/imagefilters/SkMergeImageFilter.cpp",
"$_src/effects/imagefilters/SkMorphologyImageFilter.cpp",
"$_src/effects/imagefilters/SkOffsetImageFilter.cpp",
- "$_src/effects/imagefilters/SkPaintImageFilter.cpp",
- "$_src/effects/imagefilters/SkPaintImageFilter.h",
"$_src/effects/imagefilters/SkPictureImageFilter.cpp",
"$_src/effects/imagefilters/SkPictureImageFilter.h",
+ "$_src/effects/imagefilters/SkShaderImageFilter.cpp",
"$_src/effects/imagefilters/SkTileImageFilter.cpp",
"$_src/effects/imagefilters/SkTileImageFilter.h",
]
diff --git a/src/core/SkImageFilter_Base.h b/src/core/SkImageFilter_Base.h
index 4ad3760..ca74e63 100644
--- a/src/core/SkImageFilter_Base.h
+++ b/src/core/SkImageFilter_Base.h
@@ -498,5 +498,6 @@
void SkRegisterMergeImageFilterFlattenable();
void SkRegisterMorphologyImageFilterFlattenables();
void SkRegisterOffsetImageFilterFlattenable();
+void SkRegisterShaderImageFilterFlattenable();
#endif // SkImageFilter_Base_DEFINED
diff --git a/src/effects/imagefilters/SkImageFilters.cpp b/src/effects/imagefilters/SkImageFilters.cpp
index 6e1c091..e078251 100644
--- a/src/effects/imagefilters/SkImageFilters.cpp
+++ b/src/effects/imagefilters/SkImageFilters.cpp
@@ -9,7 +9,6 @@
#include "include/core/SkPaint.h"
-#include "src/effects/imagefilters/SkPaintImageFilter.h"
#include "src/effects/imagefilters/SkPictureImageFilter.h"
#include "src/effects/imagefilters/SkTileImageFilter.h"
@@ -18,7 +17,6 @@
#include "src/core/SkMatrixImageFilter.h"
void SkImageFilters::RegisterFlattenables() {
- SkPaintImageFilter::RegisterFlattenables();
SkPictureImageFilter::RegisterFlattenables();
SkTileImageFilter::RegisterFlattenables();
}
@@ -39,36 +37,10 @@
}
#endif
-
-sk_sp<SkImageFilter> SkImageFilters::Paint(const SkPaint& paint, const CropRect& cropRect) {
- return SkPaintImageFilter::Make(paint, cropRect);
-}
-
sk_sp<SkImageFilter> SkImageFilters::Picture(sk_sp<SkPicture> pic, const SkRect& targetRect) {
return SkPictureImageFilter::Make(std::move(pic), targetRect);
}
-sk_sp<SkImageFilter> SkImageFilters::Shader(sk_sp<SkShader> shader, Dither dither,
- const CropRect& cropRect) {
- SkPaint paint;
- paint.setShader(std::move(shader));
- paint.setDither((bool) dither);
- return SkPaintImageFilter::Make(paint, cropRect);
-}
-
-#ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
-sk_sp<SkImageFilter> SkImageFilters::Shader(sk_sp<SkShader> shader, Dither dither,
- SkFilterQuality filterQuality,
- const CropRect& cropRect) {
- SkPaint paint;
- paint.setShader(std::move(shader));
- paint.setDither((bool) dither);
- // For SkImage::makeShader() shaders using SkImageShader::kInheritFromPaint sampling options
- paint.setFilterQuality(filterQuality);
- return SkPaintImageFilter::Make(paint, cropRect);
-}
-#endif
-
sk_sp<SkImageFilter> SkImageFilters::Tile(
const SkRect& src, const SkRect& dst, sk_sp<SkImageFilter> input) {
return SkTileImageFilter::Make(src, dst, std::move(input));
diff --git a/src/effects/imagefilters/SkPaintImageFilter.cpp b/src/effects/imagefilters/SkPaintImageFilter.cpp
deleted file mode 100644
index 74591d4..0000000
--- a/src/effects/imagefilters/SkPaintImageFilter.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "src/effects/imagefilters/SkPaintImageFilter.h"
-
-#include "include/core/SkCanvas.h"
-#include "include/core/SkPaint.h"
-#include "src/core/SkImageFilter_Base.h"
-#include "src/core/SkReadBuffer.h"
-#include "src/core/SkSpecialImage.h"
-#include "src/core/SkSpecialSurface.h"
-#include "src/core/SkWriteBuffer.h"
-
-namespace {
-
-class SkPaintImageFilterImpl final : public SkImageFilter_Base {
-public:
- SkPaintImageFilterImpl(const SkPaint& paint, const SkRect* rect)
- : INHERITED(nullptr, 0, rect)
- , fPaint(paint) {}
-
- bool affectsTransparentBlack() const override;
-
-protected:
- void flatten(SkWriteBuffer&) const override;
- sk_sp<SkSpecialImage> onFilterImage(const Context&, SkIPoint* offset) const override;
-
-private:
- friend void SkPaintImageFilter::RegisterFlattenables();
- SK_FLATTENABLE_HOOKS(SkPaintImageFilterImpl)
-
- SkPaint fPaint;
-
- using INHERITED = SkImageFilter_Base;
-};
-
-} // end namespace
-
-sk_sp<SkImageFilter> SkPaintImageFilter::Make(const SkPaint& paint,
- const SkRect* cropRect) {
- return sk_sp<SkImageFilter>(new SkPaintImageFilterImpl(paint, cropRect));
-}
-
-void SkPaintImageFilter::RegisterFlattenables() {
- SK_REGISTER_FLATTENABLE(SkPaintImageFilterImpl);
- // TODO (michaelludwig) - Remove after grace period for SKPs to stop using old name
- SkFlattenable::Register("SkPaintImageFilter", SkPaintImageFilterImpl::CreateProc);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-sk_sp<SkFlattenable> SkPaintImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
- SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
- SkPaint paint;
- buffer.readPaint(&paint, nullptr);
- return SkPaintImageFilter::Make(paint, common.cropRect());
-}
-
-void SkPaintImageFilterImpl::flatten(SkWriteBuffer& buffer) const {
- this->INHERITED::flatten(buffer);
- buffer.writePaint(fPaint);
-}
-
-sk_sp<SkSpecialImage> SkPaintImageFilterImpl::onFilterImage(const Context& ctx,
- SkIPoint* offset) const {
- SkIRect bounds;
- const SkIRect srcBounds = SkIRect::MakeWH(ctx.sourceImage()->width(),
- ctx.sourceImage()->height());
- if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
- return nullptr;
- }
-
- sk_sp<SkSpecialSurface> surf(ctx.makeSurface(bounds.size()));
- if (!surf) {
- return nullptr;
- }
-
- SkCanvas* canvas = surf->getCanvas();
- SkASSERT(canvas);
-
- canvas->clear(0x0);
-
- SkMatrix matrix(ctx.ctm());
- matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
- SkRect rect = SkRect::MakeIWH(bounds.width(), bounds.height());
- SkMatrix inverse;
- if (matrix.invert(&inverse)) {
- inverse.mapRect(&rect);
- }
- canvas->setMatrix(matrix);
- if (rect.isFinite()) {
- canvas->drawRect(rect, fPaint);
- }
-
- offset->fX = bounds.fLeft;
- offset->fY = bounds.fTop;
- return surf->makeImageSnapshot();
-}
-
-bool SkPaintImageFilterImpl::affectsTransparentBlack() const {
- return true;
-}
diff --git a/src/effects/imagefilters/SkPaintImageFilter.h b/src/effects/imagefilters/SkPaintImageFilter.h
deleted file mode 100644
index 6e9f381..0000000
--- a/src/effects/imagefilters/SkPaintImageFilter.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkPaintImageFilter_DEFINED
-#define SkPaintImageFilter_DEFINED
-
-#include "include/core/SkImageFilter.h"
-
-class SkPaint;
-
-// DEPRECATED: Use include/effects/SkImageFilters::Paint
-class SK_API SkPaintImageFilter {
-public:
- /** Create a new image filter which fills the given rectangle using the
- * given paint. If no rectangle is specified, an output is produced with
- * the same bounds as the input primitive (even though the input
- * primitive's pixels are not used for processing).
- * @param paint Paint to use when filling the rect.
- * @param rect Rectangle of output pixels. If NULL or a given crop edge is
- * not specified, the source primitive's bounds are used
- * instead.
- */
- static sk_sp<SkImageFilter> Make(const SkPaint& paint,
- const SkRect* cropRect = nullptr);
-
- static void RegisterFlattenables();
-
-private:
- SkPaintImageFilter() = delete;
-};
-
-#endif
diff --git a/src/effects/imagefilters/SkShaderImageFilter.cpp b/src/effects/imagefilters/SkShaderImageFilter.cpp
new file mode 100644
index 0000000..477c714
--- /dev/null
+++ b/src/effects/imagefilters/SkShaderImageFilter.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "include/core/SkCanvas.h"
+#include "include/core/SkPaint.h"
+#include "include/effects/SkImageFilters.h"
+#include "src/core/SkImageFilter_Base.h"
+#include "src/core/SkReadBuffer.h"
+#include "src/core/SkSpecialImage.h"
+#include "src/core/SkSpecialSurface.h"
+#include "src/core/SkWriteBuffer.h"
+
+namespace {
+
+class SkShaderImageFilter final : public SkImageFilter_Base {
+public:
+ SkShaderImageFilter(const SkPaint& paint, const SkRect* rect)
+ : INHERITED(nullptr, 0, rect)
+ , fPaint(paint) {}
+
+ static sk_sp<SkImageFilter> Make(const SkPaint& paint, const SkRect* rect) {
+ return sk_sp<SkImageFilter>(new SkShaderImageFilter(paint, rect));
+ }
+
+ bool affectsTransparentBlack() const override;
+
+protected:
+ void flatten(SkWriteBuffer&) const override;
+ sk_sp<SkSpecialImage> onFilterImage(const Context&, SkIPoint* offset) const override;
+
+private:
+ friend void ::SkRegisterShaderImageFilterFlattenable();
+ SK_FLATTENABLE_HOOKS(SkShaderImageFilter)
+
+ // This filter only applies the shader and dithering policy of the paint.
+ SkPaint fPaint;
+
+ using INHERITED = SkImageFilter_Base;
+};
+
+} // end namespace
+
+// TODO(michaelludwig) - Remove this deprecated factory once modules/svg is updated
+sk_sp<SkImageFilter> SkImageFilters::Paint(const SkPaint& paint, const CropRect& cropRect) {
+ return SkShaderImageFilter::Make(paint, cropRect);
+}
+
+sk_sp<SkImageFilter> SkImageFilters::Shader(sk_sp<SkShader> shader, Dither dither,
+ const CropRect& cropRect) {
+ SkPaint paint;
+ paint.setShader(std::move(shader));
+ paint.setDither((bool) dither);
+ return SkShaderImageFilter::Make(paint, cropRect);
+}
+
+#ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
+sk_sp<SkImageFilter> SkImageFilters::Shader(sk_sp<SkShader> shader, Dither dither,
+ SkFilterQuality filterQuality,
+ const CropRect& cropRect) {
+ SkPaint paint;
+ paint.setShader(std::move(shader));
+ paint.setDither((bool) dither);
+ // For SkImage::makeShader() shaders using SkImageShader::kInheritFromPaint sampling options
+ paint.setFilterQuality(filterQuality);
+ return SkShaderImageFilter::Make(paint, cropRect);
+}
+#endif
+
+void SkRegisterShaderImageFilterFlattenable() {
+ SK_REGISTER_FLATTENABLE(SkShaderImageFilter);
+ // TODO (michaelludwig) - Remove after grace period for SKPs to stop using old name
+ SkFlattenable::Register("SkPaintImageFilter", SkShaderImageFilter::CreateProc);
+ SkFlattenable::Register("SkPaintImageFilterImpl", SkShaderImageFilter::CreateProc);
+}
+
+sk_sp<SkFlattenable> SkShaderImageFilter::CreateProc(SkReadBuffer& buffer) {
+ SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
+ SkPaint paint;
+ buffer.readPaint(&paint, nullptr);
+ return SkShaderImageFilter::Make(paint, common.cropRect());
+}
+
+void SkShaderImageFilter::flatten(SkWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writePaint(fPaint);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+sk_sp<SkSpecialImage> SkShaderImageFilter::onFilterImage(const Context& ctx,
+ SkIPoint* offset) const {
+ SkIRect bounds;
+ const SkIRect srcBounds = SkIRect::MakeWH(ctx.sourceImage()->width(),
+ ctx.sourceImage()->height());
+ if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
+ return nullptr;
+ }
+
+ sk_sp<SkSpecialSurface> surf(ctx.makeSurface(bounds.size()));
+ if (!surf) {
+ return nullptr;
+ }
+
+ SkCanvas* canvas = surf->getCanvas();
+ SkASSERT(canvas);
+
+ canvas->clear(0x0);
+
+ SkMatrix matrix(ctx.ctm());
+ matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
+ SkRect rect = SkRect::MakeIWH(bounds.width(), bounds.height());
+ SkMatrix inverse;
+ if (matrix.invert(&inverse)) {
+ inverse.mapRect(&rect);
+ }
+ canvas->setMatrix(matrix);
+ if (rect.isFinite()) {
+ canvas->drawRect(rect, fPaint);
+ }
+
+ offset->fX = bounds.fLeft;
+ offset->fY = bounds.fTop;
+ return surf->makeImageSnapshot();
+}
+
+bool SkShaderImageFilter::affectsTransparentBlack() const {
+ return true;
+}
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index 5856c0c5..7b4a697 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -131,6 +131,7 @@
SkRegisterMergeImageFilterFlattenable();
SkRegisterMorphologyImageFilterFlattenables();
SkRegisterOffsetImageFilterFlattenable();
+ SkRegisterShaderImageFilterFlattenable();
SK_REGISTER_FLATTENABLE(SkLocalMatrixImageFilter);
SK_REGISTER_FLATTENABLE(SkMatrixImageFilter);
}