aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-30 07:32:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-30 07:32:28 -0700
commit372177ee115d46dfb5bfb881a408e6c37ae83678 (patch)
tree674a01098b007017b989cf8d350398a0c794a345 /src
parent2e77ddbb5e7274a83724ceaa5680f367e54163d4 (diff)
Switch SkLocalMatrixImageFilter and SkPaintImageFilter over to sk_sp
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp3
-rw-r--r--src/core/SkImageFilter.cpp24
-rw-r--r--src/core/SkLocalMatrixImageFilter.cpp21
-rw-r--r--src/core/SkLocalMatrixImageFilter.h21
-rw-r--r--src/effects/SkPaintImageFilter.cpp11
-rw-r--r--src/effects/SkPictureImageFilter.cpp4
6 files changed, 51 insertions, 33 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f1777441d6..2f6477c41d 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1161,9 +1161,8 @@ static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt
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 06076c6891..e999d3aebb 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -158,6 +158,22 @@ bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) {
///////////////////////////////////////////////////////////////////////////////////////////////////
+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 @@ SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
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 @@ SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix,
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 15f2f0ef00..d1b5715b7f 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 @@ SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
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 412b391e18..eb112b0f0d 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 @@ protected:
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;
diff --git a/src/effects/SkPaintImageFilter.cpp b/src/effects/SkPaintImageFilter.cpp
index 7056f26863..cbd793a692 100644
--- a/src/effects/SkPaintImageFilter.cpp
+++ b/src/effects/SkPaintImageFilter.cpp
@@ -12,20 +12,16 @@
#include "SkSpecialSurface.h"
#include "SkWriteBuffer.h"
-SkImageFilter* SkPaintImageFilter::Create(const SkPaint& paint, const CropRect* cropRect) {
- return new SkPaintImageFilter(paint, cropRect);
-}
-
SkPaintImageFilter::SkPaintImageFilter(const SkPaint& paint, const CropRect* cropRect)
- : INHERITED(0, nullptr, cropRect)
- , fPaint(paint) {
+ : INHERITED(nullptr, 0, cropRect)
+ , fPaint(paint) {
}
SkFlattenable* SkPaintImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
SkPaint paint;
buffer.readPaint(&paint);
- return Create(paint, &common.cropRect());
+ return SkPaintImageFilter::Make(paint, &common.cropRect()).release();
}
void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const {
@@ -80,6 +76,7 @@ bool SkPaintImageFilter::canComputeFastBounds() const {
#ifndef SK_IGNORE_TO_STRING
void SkPaintImageFilter::toString(SkString* str) const {
str->appendf("SkPaintImageFilter: (");
+ fPaint.toString(str);
str->append(")");
}
#endif
diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp
index f5e3d4680b..2005463bd4 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -14,7 +14,7 @@
#include "SkValidationUtils.h"
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
- : INHERITED(0, 0, nullptr)
+ : INHERITED(nullptr, 0, nullptr)
, fPicture(std::move(picture))
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty())
, fPictureResolution(kDeviceSpace_PictureResolution)
@@ -24,7 +24,7 @@ SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
PictureResolution pictureResolution,
SkFilterQuality filterQuality)
- : INHERITED(0, 0, nullptr)
+ : INHERITED(nullptr, 0, nullptr)
, fPicture(std::move(picture))
, fCropRect(cropRect)
, fPictureResolution(pictureResolution)