Switch SkLocalMatrixImageFilter and SkPaintImageFilter over to sk_sp
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1842793002
Committed: https://skia.googlesource.com/skia/+/a33cf07a2273315363c0b6fb5d3ce811742f5a85
Review URL: https://codereview.chromium.org/1842793002
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f177744..2f6477c 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1161,9 +1161,8 @@
SkCanvas c(dst);
- SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm));
SkPaint p;
- p.setImageFilter(localF);
+ p.setImageFilter(filter->makeWithLocalMatrix(ctm));
const SkScalar x = SkIntToScalar(src->getOrigin().x());
const SkScalar y = SkIntToScalar(src->getOrigin().y());
c.drawBitmap(srcBM, x, y, &p);
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 06076c6..e999d3a 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -158,6 +158,22 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
+SkImageFilter::SkImageFilter(sk_sp<SkImageFilter>* inputs,
+ int inputCount,
+ const CropRect* cropRect)
+ : fInputCount(inputCount),
+ fInputs(new SkImageFilter*[inputCount]),
+ fUsesSrcInput(false),
+ fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)),
+ fUniqueID(next_image_filter_unique_id()) {
+ for (int i = 0; i < inputCount; ++i) {
+ if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
+ fUsesSrcInput = true;
+ }
+ fInputs[i] = SkSafeRef(inputs[i].get());
+ }
+}
+
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
: fInputCount(inputCount),
fInputs(new SkImageFilter*[inputCount]),
@@ -168,8 +184,7 @@
if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
fUsesSrcInput = true;
}
- fInputs[i] = inputs[i];
- SkSafeRef(fInputs[i]);
+ fInputs[i] = SkSafeRef(inputs[i]);
}
}
@@ -556,11 +571,12 @@
return SkMatrixImageFilter::Create(matrix, filterQuality, input);
}
-SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const {
+sk_sp<SkImageFilter> SkImageFilter::makeWithLocalMatrix(const SkMatrix& matrix) const {
// SkLocalMatrixImageFilter takes SkImage* in its factory, but logically that parameter
// is *always* treated as a const ptr. Hence the const-cast here.
//
- return SkLocalMatrixImageFilter::Create(matrix, const_cast<SkImageFilter*>(this));
+ SkImageFilter* nonConstThis = const_cast<SkImageFilter*>(this);
+ return SkLocalMatrixImageFilter::Make(matrix, sk_ref_sp<SkImageFilter>(nonConstThis));
}
sk_sp<SkSpecialImage> SkImageFilter::filterInput(int index,
diff --git a/src/core/SkLocalMatrixImageFilter.cpp b/src/core/SkLocalMatrixImageFilter.cpp
index 15f2f0e..d1b5715 100644
--- a/src/core/SkLocalMatrixImageFilter.cpp
+++ b/src/core/SkLocalMatrixImageFilter.cpp
@@ -10,21 +10,9 @@
#include "SkSpecialImage.h"
#include "SkString.h"
-SkImageFilter* SkLocalMatrixImageFilter::Create(const SkMatrix& localM, SkImageFilter* input) {
- if (!input) {
- return nullptr;
- }
- if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
- return nullptr;
- }
- if (localM.isIdentity()) {
- return SkRef(input);
- }
- return new SkLocalMatrixImageFilter(localM, input);
-}
-
-SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input)
- : INHERITED(1, &input)
+SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM,
+ sk_sp<SkImageFilter> input)
+ : INHERITED(&input, 1, nullptr)
, fLocalM(localM) {
}
@@ -32,7 +20,8 @@
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkMatrix lm;
buffer.readMatrix(&lm);
- return SkLocalMatrixImageFilter::Create(lm, common.getInput(0));
+ return SkLocalMatrixImageFilter::Make(lm,
+ sk_ref_sp<SkImageFilter>(common.getInput(0))).release();
}
void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/core/SkLocalMatrixImageFilter.h b/src/core/SkLocalMatrixImageFilter.h
index 412b391..eb112b0 100644
--- a/src/core/SkLocalMatrixImageFilter.h
+++ b/src/core/SkLocalMatrixImageFilter.h
@@ -16,11 +16,28 @@
*/
class SkLocalMatrixImageFilter : public SkImageFilter {
public:
- static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input);
+ static sk_sp<SkImageFilter> Make(const SkMatrix& localM, sk_sp<SkImageFilter> input) {
+ if (!input) {
+ return nullptr;
+ }
+ if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
+ return nullptr;
+ }
+ if (localM.isIdentity()) {
+ return input;
+ }
+ return sk_sp<SkImageFilter>(new SkLocalMatrixImageFilter(localM, input));
+ }
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input) {
+ return Make(localM, sk_sp<SkImageFilter>(SkSafeRef(input))).release();
+ }
+#endif
+
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
@@ -28,7 +45,7 @@
SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
private:
- SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input);
+ SkLocalMatrixImageFilter(const SkMatrix& localM, sk_sp<SkImageFilter> input);
SkMatrix fLocalM;