Reland of [2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https:...
authorreed <reed@google.com>
Tue, 22 Mar 2016 17:17:23 +0000 (10:17 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 22 Mar 2016 17:17:23 +0000 (10:17 -0700)
Reason for revert:
guard has now landed in chrome

Original issue's description:
> Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #3 id:40001 of https://codereview.chromium.org/1825073002/ )
>
> Reason for revert:
> CreateModeFilter not compiling
>
> Original issue's description:
> > Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
> >
> > Fixed legacy withColorFilter to call new(er) make method
> >
> > This reverts commit 1eb81db650d31f50be67b12d60c4f9e7dd08432f.
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
> >
> > TBR=
> >
> > Committed: https://skia.googlesource.com/skia/+/4c9776b046dd5e9e46e2d1ce35154855c8fcb381
>
> TBR=
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d6889293dd0942f27f9593f679722c956831f2c4

TBR=
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:

Review URL: https://codereview.chromium.org/1827433002

80 files changed:
bench/BlurRoundRectBench.cpp
bench/ColorCubeBench.cpp
bench/ColorFilterBench.cpp
bench/ImageFilterCollapse.cpp
gm/blurredclippedcircle.cpp
gm/blurroundrect.cpp
gm/color4f.cpp
gm/colorcube.cpp
gm/coloremoji.cpp
gm/colorfilterimagefilter.cpp
gm/colorfilters.cpp
gm/colormatrix.cpp
gm/dropshadowimagefilter.cpp
gm/emboss.cpp
gm/fadefilter.cpp
gm/imagefilters.cpp
gm/imagefiltersbase.cpp
gm/imagefilterscropexpand.cpp
gm/imagefilterscropped.cpp
gm/imagefiltersgraph.cpp
gm/lumafilter.cpp
gm/megalooper.cpp
gm/modecolorfilters.cpp
gm/multipicturedraw.cpp
gm/recordopts.cpp
gm/skbug1719.cpp
gm/tablecolorfilter.cpp
gm/testimagefilters.cpp
gm/textbloblooper.cpp
gm/tileimagefilter.cpp
gm/vertices.cpp
gyp/skia_for_android_framework_defines.gypi
include/core/SkColorFilter.h
include/core/SkPaint.h
include/core/SkShader.h
include/effects/SkBlurDrawLooper.h
include/effects/SkColorCubeFilter.h
include/effects/SkColorFilterImageFilter.h
include/effects/SkColorMatrixFilter.h
include/effects/SkLumaColorFilter.h
include/effects/SkTableColorFilter.h
public.bzl
samplecode/SampleAll.cpp
samplecode/SampleColorFilter.cpp
samplecode/SampleFilterFuzz.cpp
src/core/SkBlitter.cpp
src/core/SkCanvas.cpp
src/core/SkColorFilter.cpp
src/core/SkColorFilterShader.cpp
src/core/SkColorFilterShader.h
src/core/SkColorMatrixFilterRowMajor255.cpp
src/core/SkColorMatrixFilterRowMajor255.h
src/core/SkDevice.cpp
src/core/SkModeColorFilter.cpp
src/core/SkModeColorFilter.h
src/core/SkPaint.cpp
src/core/SkReadBuffer.h
src/core/SkShader.cpp
src/effects/SkBlurDrawLooper.cpp
src/effects/SkColorCubeFilter.cpp
src/effects/SkColorFilterImageFilter.cpp
src/effects/SkColorMatrixFilter.cpp
src/effects/SkDropShadowImageFilter.cpp
src/effects/SkLayerDrawLooper.cpp
src/effects/SkLumaColorFilter.cpp
src/effects/SkTableColorFilter.cpp
src/pdf/SkPDFDevice.cpp
src/utils/SkLua.cpp
src/utils/SkRGBAToYUV.cpp
tests/ColorFilterTest.cpp
tests/ColorMatrixTest.cpp
tests/GpuColorFilterTest.cpp
tests/ImageFilterTest.cpp
tests/PaintTest.cpp
tests/PictureTest.cpp
tests/RecordOptsTest.cpp
tests/SerializationTest.cpp
tests/SkColor4fTest.cpp
tools/android/SkAndroidSDKCanvas.cpp
tools/debugger/SkDrawCommand.cpp

index 85852d581e32317ec0955dd3b4e56274ce9e20a8..46f410d3b34c6a3cad9d11336e8b044ecb999e78 100644 (file)
@@ -54,9 +54,8 @@ public:
                     SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
                     SkBlurMaskFilter::kHighQuality_BlurFlag);
             paint->setMaskFilter(maskFilter)->unref();
-            SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY,
-                    SkXfermode::kSrcIn_Mode);
-            paint->setColorFilter(colorFilter)->unref();
+            paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
+                                                                SkXfermode::kSrcIn_Mode));
             paint->setColor(SK_ColorGRAY);
         }
         {
index 9f6bd001ff00b5b972dad83acce4d87f65ea7386..6a7774012dab3412e831e234afdaaa732bef8f65 100644 (file)
 class ColorCubeBench : public Benchmark {
     SkISize fSize;
     int fCubeDimension;
-    SkData* fCubeData;
+    sk_sp<SkData> fCubeData;
     SkBitmap fBitmap;
 
 public:
-    ColorCubeBench()
-     : fCubeDimension(0)
-     , fCubeData(nullptr) {
+    ColorCubeBench() : fCubeDimension(0) {
         fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution
     }
 
-    ~ColorCubeBench() {
-        SkSafeUnref(fCubeData);
-    }
-
 protected:
     const char* onGetName() override {
         return "colorcube";
@@ -71,7 +65,7 @@ private:
 
     void makeCubeData() {
         fCubeDimension = 32;
-        fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
+        fCubeData = SkData::MakeUninitialized(sizeof(SkColor) *
             fCubeDimension * fCubeDimension * fCubeDimension);
         SkColor* pixels = (SkColor*)(fCubeData->writable_data());
         SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension);
@@ -95,9 +89,7 @@ private:
     void test(int loops, SkCanvas* canvas) {
         SkPaint paint;
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkColorFilter> colorCube(
-                SkColorCubeFilter::Create(fCubeData, fCubeDimension));
-            paint.setColorFilter(colorCube);
+            paint.setColorFilter(SkColorCubeFilter::Make(fCubeData, fCubeDimension));
             canvas->drawBitmap(fBitmap, 0, 0, &paint);
         }
     }
index 5365a9c2ad52082c79de59f2a4ce07490694c3c5..c4ba1e5dcb435e709aa103a9a5d54479c8290dd1 100644 (file)
@@ -34,8 +34,8 @@ protected:
                                 0, 1, 0, 0, amount255,
                                 0, 0, 1, 0, amount255,
                                 0, 0, 0, 1, 0 };
-        SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
-        return SkColorFilterImageFilter::Create(filter, input);
+        auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+        return SkColorFilterImageFilter::Create(filter.get(), input);
     }
 
     static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
@@ -45,14 +45,13 @@ protected:
         matrix[1] = matrix[6] = matrix[11] = 0.7152f;
         matrix[2] = matrix[7] = matrix[12] = 0.0722f;
         matrix[18] = 1.0f;
-        SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
-        return SkColorFilterImageFilter::Create(filter, input);
+        auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+        return SkColorFilterImageFilter::Create(filter.get(), input);
     }
 
     static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
-        SkAutoTUnref<SkColorFilter> filter(
-            SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
-        return SkColorFilterImageFilter::Create(filter, input);
+        auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+        return SkColorFilterImageFilter::Create(filter.get(), input);
     }
 
     inline bool isSmall() const { return fIsSmall; }
index bd3f80fefb59a2b9f89b1f46c34ec8d54b0736f0..cafcd38c6e94cbf0054ea26fa5d6cd16f077e913 100644 (file)
@@ -28,12 +28,12 @@ public:
     }
 
 protected:
-    void doPreDraw(SkColorFilter* colorFilters[], int nFilters) {
+    void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
         // Create a chain of ImageFilters from colorFilters
         fImageFilter = nullptr;
         for(int i = nFilters; i --> 0;) {
             SkAutoTUnref<SkImageFilter> filter(
-                        SkColorFilterImageFilter::Create(colorFilters[i], fImageFilter, nullptr)
+                    SkColorFilterImageFilter::Create(colorFilters[i].get(), fImageFilter, nullptr)
             );
             SkRefCnt_SafeAssign(fImageFilter, filter.get());
         }
@@ -73,15 +73,12 @@ private:
 };
 
 class TableCollapseBench: public BaseImageFilterCollapseBench {
-public:
-    virtual ~TableCollapseBench() {}
-
 protected:
-    virtual const char* onGetName() override {
+    const char* onGetName() override {
         return "image_filter_collapse_table";
     }
 
-    virtual void onDelayedSetup() override {
+    void onDelayedSetup() override {
         for (int i = 0; i < 256; ++i) {
             int n = i >> 5;
             table1[i] = (n << 5) | (n << 2) | (n >> 1);
@@ -92,63 +89,52 @@ protected:
             table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255);
         }
 
-        SkColorFilter* colorFilters[] = {
-            SkTableColorFilter::Create(table1),
-            SkTableColorFilter::Create(table2),
-            SkTableColorFilter::Create(table3),
+        sk_sp<SkColorFilter> colorFilters[] = {
+            SkTableColorFilter::Make(table1),
+            SkTableColorFilter::Make(table2),
+            SkTableColorFilter::Make(table3),
         };
 
         doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
-
-        for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
-            colorFilters[i]->unref();
-        }
     }
 
 private:
     uint8_t table1[256], table2[256], table3[256];
 };
 
-static SkColorFilter* make_brightness(float amount) {
+static sk_sp<SkColorFilter> make_brightness(float amount) {
     SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
     SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
                             0, 1, 0, 0, amount255,
                             0, 0, 1, 0, amount255,
                             0, 0, 0, 1, 0 };
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
 
-static SkColorFilter* make_grayscale() {
+static sk_sp<SkColorFilter> make_grayscale() {
     SkScalar matrix[20];
     memset(matrix, 0, 20 * sizeof(SkScalar));
     matrix[0] = matrix[5] = matrix[10] = 0.2126f;
     matrix[1] = matrix[6] = matrix[11] = 0.7152f;
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
 
 class MatrixCollapseBench: public BaseImageFilterCollapseBench {
-public:
-    virtual ~MatrixCollapseBench() {}
-
 protected:
-    virtual const char* onGetName() override {
+    const char* onGetName() override {
         return "image_filter_collapse_matrix";
     }
 
-    virtual void onDelayedSetup() override {
-        SkColorFilter* colorFilters[] = {
+    void onDelayedSetup() override {
+        sk_sp<SkColorFilter> colorFilters[] = {
             make_brightness(0.1f),
             make_grayscale(),
             make_brightness(-0.1f),
         };
 
         doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
-
-        for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
-            colorFilters[i]->unref();
-        }
     }
 };
 
index d1d374c7d44a3a40cf00bbb0a2a51f07935d6acc..3bbff755e980494783961286fa370cb068b3e4ea 100644 (file)
@@ -67,9 +67,9 @@ protected:
                                             kNormal_SkBlurStyle,
                                             1.366025f,
                                             SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
-                    paint.setColorFilter(SkColorFilter::CreateModeFilter(
+                    paint.setColorFilter(SkColorFilter::MakeModeFilter(
                                              SK_ColorRED,
-                                             SkXfermode::kSrcIn_Mode))->unref();
+                                             SkXfermode::kSrcIn_Mode));
                     paint.setAntiAlias(true);
 
                     canvas->drawRRect(rr, paint);
index fe4a93994628d8401562f9a7321cde86add4017a..9135ba099f54733ac5f44f49420f4ad9e095ee76 100644 (file)
@@ -60,10 +60,9 @@ public:
                     SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
                     SkBlurMaskFilter::kHighQuality_BlurFlag);
             paint->setMaskFilter(maskFilter)->unref();
-            SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(
+            paint->setColorFilter(SkColorFilter::MakeModeFilter(
                     sk_tool_utils::color_to_565(SK_ColorLTGRAY),
-                    SkXfermode::kSrcIn_Mode);
-            paint->setColorFilter(colorFilter)->unref();
+                    SkXfermode::kSrcIn_Mode));
             paint->setColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
         }
         {
index 2d5b7d2c1ae09a31e4d1f704916828b4941126db..ec9bbcbfba9b3056fd7f4b672a27413091ab15f8 100644 (file)
@@ -22,43 +22,43 @@ static sk_sp<SkShader> make_alpha_color() {
     return SkShader::MakeColorShader(0x80FF0000);
 }
 
-static SkColorFilter* make_cf_null() {
+static sk_sp<SkColorFilter> make_cf_null() {
     return nullptr;
 }
 
-static SkColorFilter* make_cf0() {
+static sk_sp<SkColorFilter> make_cf0() {
     SkColorMatrix cm;
     cm.setSaturation(0.75f);
-    return SkColorMatrixFilter::Create(cm);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat);
 }
 
-static SkColorFilter* make_cf1() {
+static sk_sp<SkColorFilter> make_cf1() {
     SkColorMatrix cm;
     cm.setSaturation(0.75f);
-    SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm));
+    auto a(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
     // CreateComposedFilter will try to concat these two matrices, resulting in a single
     // filter (which is good for speed). For this test, we want to force a real compose of
     // these two, so our inner filter has a scale-up, which disables the optimization of
     // combining the two matrices.
     cm.setScale(1.1f, 0.9f, 1);
-    SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm));
-    return SkColorFilter::CreateComposeFilter(a, b);
+    auto b(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
+    return SkColorFilter::MakeComposeFilter(a, b);
 }
 
-static SkColorFilter* make_cf2() {
-    return SkColorFilter::CreateModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode);
+static sk_sp<SkColorFilter> make_cf2() {
+    return SkColorFilter::MakeModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode);
 }
 
 static void draw_into_canvas(SkCanvas* canvas) {
     const SkRect r = SkRect::MakeWH(50, 100);
     sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
-    SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
+    sk_sp<SkColorFilter> (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
     
     SkPaint paint;
     for (auto shProc : shaders) {
         paint.setShader(shProc());
         for (auto cfProc : filters) {
-            SkSafeUnref(paint.setColorFilter(cfProc()));
+            paint.setColorFilter(cfProc());
             canvas->drawRect(r, paint);
             canvas->translate(60, 0);
         }
index 01aaf156107968e1220681f6331317ae5ae95a04..54e0688c6ab279f0d55fc856e0bc5de25804bb91 100644 (file)
@@ -25,27 +25,12 @@ static sk_sp<SkShader> MakeLinear() {
 
 class ColorCubeGM : public GM {
 public:
-    ColorCubeGM()
-    : fInitialized(false)
-    , f3DLut4(nullptr)
-    , f3DLut8(nullptr)
-    , f3DLut16(nullptr)
-    , f3DLut32(nullptr)
-    , f3DLut64(nullptr)
-    {
+    ColorCubeGM() : fInitialized(false) {
         this->setBGColor(0xFF000000);
     }
 
-    ~ColorCubeGM() {
-        SkSafeUnref(f3DLut4);
-        SkSafeUnref(f3DLut8);
-        SkSafeUnref(f3DLut16);
-        SkSafeUnref(f3DLut32);
-        SkSafeUnref(f3DLut64);
-    }
-
 protected:
-    virtual SkString onShortName() {
+    SkString onShortName() override {
         return SkString("colorcube");
     }
 
@@ -67,8 +52,8 @@ protected:
         canvas.drawRect(SkRect::MakeWH(80, 80), paint);
     }
 
-    void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
-        *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
+    void make_3Dlut(sk_sp<SkData>* data, int size, bool invR, bool invG, bool invB) {
+        *data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size);
         SkColor* pixels = (SkColor*)((*data)->writable_data());
         SkAutoTMalloc<uint8_t> lutMemory(size);
         SkAutoTMalloc<uint8_t> invLutMemory(size);
@@ -92,11 +77,11 @@ protected:
         }
     }
 
-    virtual SkISize onISize() {
+    SkISize onISize() override {
         return SkISize::Make(500, 100);
     }
 
-    virtual void onDraw(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
         if (!fInitialized) {
             this->make_bitmap();
             this->make_3Dluts();
@@ -104,19 +89,19 @@ protected:
         }
         canvas->clear(0x00000000);
         SkPaint paint;
-        paint.setColorFilter(SkColorCubeFilter::Create(f3DLut4, 4))->unref();
+        paint.setColorFilter(SkColorCubeFilter::Make(f3DLut4, 4));
         canvas->drawBitmap(fBitmap, 10, 10, &paint);
 
-        paint.setColorFilter(SkColorCubeFilter::Create(f3DLut8, 8))->unref();
+        paint.setColorFilter(SkColorCubeFilter::Make(f3DLut8, 8));
         canvas->drawBitmap(fBitmap, 110, 10, &paint);
 
-        paint.setColorFilter(SkColorCubeFilter::Create(f3DLut16, 16))->unref();
+        paint.setColorFilter(SkColorCubeFilter::Make(f3DLut16, 16));
         canvas->drawBitmap(fBitmap, 210, 10, &paint);
 
-        paint.setColorFilter(SkColorCubeFilter::Create(f3DLut32, 32))->unref();
+        paint.setColorFilter(SkColorCubeFilter::Make(f3DLut32, 32));
         canvas->drawBitmap(fBitmap, 310, 10, &paint);
 
-        paint.setColorFilter(SkColorCubeFilter::Create(f3DLut64, 64))->unref();
+        paint.setColorFilter(SkColorCubeFilter::Make(f3DLut64, 64));
         canvas->drawBitmap(fBitmap, 410, 10, &paint);
     }
 
@@ -124,11 +109,11 @@ private:
     typedef GM INHERITED;
     bool fInitialized;
     SkBitmap fBitmap;
-    SkData* f3DLut4;
-    SkData* f3DLut8;
-    SkData* f3DLut16;
-    SkData* f3DLut32;
-    SkData* f3DLut64;
+    sk_sp<SkData> f3DLut4;
+    sk_sp<SkData> f3DLut8;
+    sk_sp<SkData> f3DLut16;
+    sk_sp<SkData> f3DLut32;
+    sk_sp<SkData> f3DLut64;
 };
 
 //////////////////////////////////////////////////////////////////////////////
index 78c347c079655442cafa65903fd6656fb24b5773..4be8202d1932fc3bf7c82444bef21a752db6e943 100644 (file)
@@ -34,8 +34,8 @@ static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
     matrix[1] = matrix[6] = matrix[11] = 0.7152f;
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
-    SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
-    return SkColorFilterImageFilter::Create(filter, input);
+    auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Create(filter.get(), input);
 }
 
 static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) {
index f72108f433a85a473df0052f4e44d396a52c8447..497757e128ac50a25fca2212773193d0f89e3d1b 100644 (file)
 #define FILTER_HEIGHT   SkIntToScalar(30)
 #define MARGIN          SkIntToScalar(10)
 
-static SkColorFilter* cf_make_brightness(float brightness) {
+static sk_sp<SkColorFilter> cf_make_brightness(float brightness) {
     SkScalar amount255 = SkScalarMul(brightness, SkIntToScalar(255));
     SkScalar matrix[20] = {
         1, 0, 0, 0, amount255,
         0, 1, 0, 0, amount255,
         0, 0, 1, 0, amount255,
         0, 0, 0, 1, 0 };
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
 
-static SkColorFilter* cf_make_grayscale() {
+static sk_sp<SkColorFilter> cf_make_grayscale() {
     SkScalar matrix[20];
     memset(matrix, 0, 20 * sizeof(SkScalar));
     matrix[0] = matrix[5] = matrix[10] = 0.2126f;
     matrix[1] = matrix[6] = matrix[11] = 0.7152f;
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
 
-static SkColorFilter* cf_make_colorize(SkColor color) {
-    return SkColorFilter::CreateModeFilter(color, SkXfermode::kSrc_Mode);
+static sk_sp<SkColorFilter> cf_make_colorize(SkColor color) {
+    return SkColorFilter::MakeModeFilter(color, SkXfermode::kSrc_Mode);
 }
 
-static void sk_gm_get_colorfilters(SkTDArray<SkColorFilter*>* array) {
-    *array->append() = cf_make_brightness(0.5f);
-    *array->append() = cf_make_grayscale();
-    *array->append() = cf_make_colorize(SK_ColorBLUE);
+static void sk_gm_get_colorfilters(SkTArray<sk_sp<SkColorFilter>>* array) {
+    array->push_back(cf_make_brightness(0.5f));
+    array->push_back(cf_make_grayscale());
+    array->push_back(cf_make_colorize(SK_ColorBLUE));
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -92,18 +92,15 @@ static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) {
 }
 
 static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) {
-    SkAutoTUnref<SkColorFilter> filter(cf_make_brightness(amount));
-    return SkColorFilterImageFilter::Create(filter, input);
+    return SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(), input);
 }
 
 static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
-    SkAutoTUnref<SkColorFilter> filter(cf_make_grayscale());
-    return SkColorFilterImageFilter::Create(filter, input);
+    return SkColorFilterImageFilter::Create(cf_make_grayscale().get(), input);
 }
 
 static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
-    SkAutoTUnref<SkColorFilter> filter(cf_make_colorize(SK_ColorBLUE));
-    return SkColorFilterImageFilter::Create(filter, input);
+    return SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(), input);
 }
 
 static void drawClippedRect(SkCanvas* canvas,
@@ -179,8 +176,8 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) {
     SkAutoCanvasRestore autoCanvasRestore(canvas, false);
     SkColorMatrix cm;
     cm.setSaturation(0.0f);
-    SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm));
-    SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf));
+    auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
+    SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf.get()));
     SkPaint p;
     p.setImageFilter(imf);
     canvas->saveLayer(NULL, &p);
@@ -195,7 +192,7 @@ public:
 };
 
 DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
-    SkTRefArray<SkColorFilter*> filters;
+    SkTArray<sk_sp<SkColorFilter>> filters;
     sk_gm_get_colorfilters(&filters);
 
     SkTRefArray<SkShader*> shaders;
@@ -210,7 +207,7 @@ DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
 
         canvas->save();
         for (int x = -1; x < filters.count(); ++x) {
-            SkColorFilter* filter = x >= 0 ? filters[x] : nullptr;
+            sk_sp<SkColorFilter> filter = x >= 0 ? filters[x] : nullptr;
 
             paint.setShader(shader->makeWithColorFilter(filter));
             canvas->drawRect(r, paint);
index eaee39dd55b729df124a2e7fc1b3f58a27059e2d..635298533b225a762dc92d9af69a5e90bbb5890b 100644 (file)
@@ -30,7 +30,7 @@ static void install_nothing(SkPaint* paint, uint32_t, uint32_t) {
 }
 
 static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) {
-    paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(mul, add))->unref();
+    paint->setColorFilter(SkColorMatrixFilter::MakeLightingFilter(mul, add));
 }
 
 class ColorFiltersGM : public skiagm::GM {
index de80ebb64b3b8cc9ffe43cbffe42ebc3affe1a95..8ac15dba8ea9073072232de6a3d6f940ae23bb0b 100644 (file)
 #define HEIGHT 500
 
 static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) {
-    paint->setColorFilter(SkColorMatrixFilter::Create(matrix))->unref();
+    paint->setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat));
 }
 
 static void set_array(SkPaint* paint, const SkScalar array[]) {
-    paint->setColorFilter(SkColorMatrixFilter::Create(array))->unref();
+    paint->setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(array));
 }
 
 class ColorMatrixGM : public skiagm::GM {
index 512c82de01da27f08ca436a99934927148c5dfcf..567ef803b59387b7dcd4547d9a6e9f1c384ce68b 100644 (file)
@@ -93,8 +93,7 @@ protected:
             draw_bitmap, draw_path, draw_paint, draw_text
         };
 
-        SkAutoTUnref<SkColorFilter> cf(
-            SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
+        auto cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
         SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
         SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
                                          SkImageFilter::CropRect::kHasAll_CropEdge);
index 20d3c918909e1faa12cddd57210703ba1fce6a84..5773577389ef7d5c25cc0bd1e63ebe9ea752547b 100644 (file)
@@ -49,7 +49,7 @@ protected:
 
         // this combination of emboss+colorfilter used to crash -- so we exercise it to
         // confirm that we have a fix.
-        paint.setColorFilter(SkColorFilter::CreateModeFilter(0xFFFF0000, SkXfermode::kSrcATop_Mode))->unref();
+        paint.setColorFilter(SkColorFilter::MakeModeFilter(0xFFFF0000, SkXfermode::kSrcATop_Mode));
         canvas->translate(bm.width() + SkIntToScalar(10), 0);
         canvas->drawBitmap(bm, 10, 10, &paint);
     }
index 6f64e1e30e3d1e54df1ee32e0972bb8c97ba00fc..386e32b098c6a351430917d0fef4942e68394b95 100644 (file)
@@ -15,10 +15,8 @@ DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) {
                             0, 1, 0, 0, 128.0f,
                             0, 0, 1, 0, 128.0f,
                             0, 0, 0, 1, 0 };
-    SkAutoTUnref<SkColorFilter> colorFilter(
-            SkColorMatrixFilter::Create(matrix));
-    SkAutoTUnref<SkImageFilter> filter(
-            SkColorFilterImageFilter::Create(colorFilter));
+    auto colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(colorFilter.get()));
     SkPaint layerPaint;
     layerPaint.setImageFilter(filter);
     canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint);
index 24a08ff865f8a44e7c638270b5fb8c6c33cd15d5..21ce0fef9709d25d678bcaf249b4700713dd6965 100644 (file)
@@ -140,7 +140,7 @@ static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) {
 DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
     SkColorMatrix cm;
     cm.setSaturation(10);
-    SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm));
+    auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
     const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 };
     SkImageFilter* filters[] = {
         SkBlurImageFilter::Create(10, 10),
@@ -148,7 +148,7 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
         SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
                                            SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
                                                true),
-        SkColorFilterImageFilter::Create(cf),
+        SkColorFilterImageFilter::Create(cf.get()),
     };
 
     const struct {
index a55328a999fd2489e9c463f0e03a2531ff8a6380..ca8a2d421a758342248e5d489875c6868fb64f51 100644 (file)
@@ -192,18 +192,16 @@ protected:
             draw_bitmap,
         };
 
-        SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
-                                                     SkXfermode::kSrcIn_Mode);
+        auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode);
         SkImageFilter* filters[] = {
             nullptr,
             IdentityImageFilter::Create(),
             FailImageFilter::Create(),
-            SkColorFilterImageFilter::Create(cf),
+            SkColorFilterImageFilter::Create(cf.get()),
             SkBlurImageFilter::Create(12.0f, 0.0f),
             SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
                 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
         };
-        cf->unref();
 
         SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
         SkScalar MARGIN = SkIntToScalar(16);
@@ -320,7 +318,7 @@ public:
     ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {}
 
     void installFilter(SkPaint* paint) override {
-        paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode))->unref();
+        paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
     }
 };
 DEF_GM( return new ImageFiltersText_CF; )
index f3ca4d32a6b872aeb24b6c6085322f9082860c72..ada206cea4b3ec7c84564c45d7012479bc4cd0f3 100644 (file)
@@ -40,8 +40,6 @@ protected:
     SkISize onISize() override { return SkISize::Make(730, 650); }
 
     void onDraw(SkCanvas* canvas) override {
-        SkAutoTUnref<SkColorFilter> cf(
-            SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
         SkImageFilter::CropRect cropRect(
             SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
             SkImageFilter::CropRect::kHasAll_CropEdge);
@@ -59,7 +57,7 @@ protected:
                                 0, 1, 0, 0, sk255,
                                 0, 0, 1, 0, 0,
                                 0, 0, 0, 0, sk255 };
-        SkAutoTUnref<SkColorFilter> cfAlphaTrans(SkColorMatrixFilter::Create(matrix));
+        auto cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
 
         SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
         SkScalar MARGIN = SkIntToScalar(12);
@@ -80,7 +78,7 @@ protected:
             SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
 
             Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create(
-                cfAlphaTrans, noopCropped.get(), &bigRect));
+                cfAlphaTrans.get(), noopCropped.get(), &bigRect));
 
             Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
                 0.3f, 0.3f, noopCropped.get(), &bigRect));
index d39e6b026a20fb557fd3bd290dfd70a356ecc043..b06761d80c835fb617984d48f642f59e37f1f800 100644 (file)
@@ -115,8 +115,7 @@ protected:
             draw_bitmap, draw_path, draw_paint, draw_text
         };
 
-        SkAutoTUnref<SkColorFilter> cf(
-            SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+        auto cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
         SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
         SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
 
index fa9c512591a06d9130b01bc0b4b3aabf922332cb..547a3bbbe229c8ce3a9fdfd2162c8ce730609afc 100644 (file)
@@ -119,11 +119,10 @@ protected:
         canvas->clear(SK_ColorBLACK);
         {
             SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImage.get()));
-            SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
-                                                         SkXfermode::kSrcIn_Mode));
+            auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
             SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0f, bitmapSource));
             SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, blur));
-            SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(cf, erode));
+            SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode));
             SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, color));
 
             SkPaint paint;
@@ -139,8 +138,8 @@ protected:
                                     0, 0, SK_Scalar1, 0, 0,
                                     0, 0, 0, 0.5f, 0 };
 
-            SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create(matrix));
-            SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter, morph));
+            auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+            SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(), morph));
             SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
             SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create(mode, colorMorph));
 
@@ -154,8 +153,8 @@ protected:
                                     0, SK_Scalar1, 0, 0, 0,
                                     0, 0, SK_Scalar1, 0, 0,
                                     0, 0, 0, 0.5f, 0 };
-            SkAutoTUnref<SkColorFilter> matrixCF(SkColorMatrixFilter::Create(matrix));
-            SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF));
+            auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+            SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
             SkAutoTUnref<SkImageFilter> offsetFilter(
                 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
 
@@ -218,16 +217,14 @@ protected:
         }
         {
             // Test that crop offsets are absolute, not relative to the parent's crop rect.
-            SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_ColorBLUE,
-                                                                            SkXfermode::kSrcIn_Mode));
-            SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_ColorGREEN,
-                                                                            SkXfermode::kSrcIn_Mode));
+            auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+            auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
             SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
                                                                SkIntToScalar(80), SkIntToScalar(80)));
             SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
                                                                SkIntToScalar(60), SkIntToScalar(60)));
-            SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1, nullptr, &outerRect));
-            SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2, color1, &innerRect));
+            SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(), nullptr, &outerRect));
+            SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(), color1, &innerRect));
 
             SkPaint paint;
             paint.setImageFilter(color2);
index adffd008c10bbe571d495d007e3ce827d8c95b61..10eefabd5642ddc7c382a7bfbfe48e8138120be5 100644 (file)
@@ -26,7 +26,7 @@ static void draw_label(SkCanvas* canvas, const char* label,
                      paint);
 }
 
-static void draw_scene(SkCanvas* canvas, SkColorFilter* filter, SkXfermode::Mode mode,
+static void draw_scene(SkCanvas* canvas, const sk_sp<SkColorFilter>& filter, SkXfermode::Mode mode,
                        const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) {
     SkPaint paint;
     paint.setAntiAlias(true);
@@ -83,7 +83,7 @@ public:
         SkPoint  g2Points[] = { { 0, 0 }, { kSize, 0   } };
         SkScalar pos[] = { 0.2f, 1.0f };
 
-        fFilter.reset(SkLumaColorFilter::Create());
+        fFilter = SkLumaColorFilter::Make();
         fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors),
                                             SkShader::kClamp_TileMode);
         fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_COUNT(g2Colors),
@@ -137,8 +137,8 @@ protected:
     }
 
 private:
-    SkAutoTUnref<SkColorFilter> fFilter;
-    sk_sp<SkShader>             fGr1, fGr2;
+    sk_sp<SkColorFilter>    fFilter;
+    sk_sp<SkShader>         fGr1, fGr2;
 
     typedef skiagm::GM INHERITED;
 };
index 5fe9af298b0d751eb7966b7ec9f3067ab12490a5..6f5640272fc068de9f84b80341c69c3c8c77b7c3 100644 (file)
@@ -175,8 +175,7 @@ private:
 
         paint->setMaskFilter(this->createBlur())->unref();
 
-        SkColorFilter* cf = SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcIn_Mode);
-        paint->setColorFilter(cf)->unref();
+        paint->setColorFilter(SkColorFilter::MakeModeFilter(color, SkXfermode::kSrcIn_Mode));
 
         return looperBuilder.detach();
     }
@@ -222,8 +221,8 @@ private:
 
             paint->setMaskFilter(this->createBlur())->unref();
 
-            SkColorFilter* cf = SkColorFilter::CreateModeFilter(gColors[i], SkXfermode::kSrcIn_Mode);
-            paint->setColorFilter(cf)->unref();
+            paint->setColorFilter(SkColorFilter::MakeModeFilter(gColors[i],
+                                                                SkXfermode::kSrcIn_Mode));
         }
 
         return looperBuilder.detach();
index de6a18a41c85e2320773743e82ee0d9fa92728b3..4e5d45cf96e5045ee6de71db739c2fc32927d4e7 100644 (file)
@@ -121,9 +121,7 @@ protected:
         static const int kRectsPerRow = SkMax32(this->getISize().fWidth / kRectWidth, 1);
         for (size_t cfm = 0; cfm < SK_ARRAY_COUNT(modes); ++cfm) {
             for (size_t cfc = 0; cfc < SK_ARRAY_COUNT(colors); ++cfc) {
-                SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[cfc],
-                                                                               modes[cfm]));
-                paint.setColorFilter(cf);
+                paint.setColorFilter(SkColorFilter::MakeModeFilter(colors[cfc], modes[cfm]));
                 for (size_t s = 0; s < SK_ARRAY_COUNT(shaders); ++s) {
                     paint.setShader(shaders[s]);
                     bool hasShader = nullptr == paint.getShader();
index 1f302ee57af608d3a206d78a35a7ca0bfd78a42b..a4b09b2c2fcc7bd7bd0b5b77c14d025fa98b8c9f 100644 (file)
@@ -420,7 +420,7 @@ static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
             step.fY = SkIntToScalar(y*kTileHeight);
             step.fPaint = new SkPaint;
             step.fPaint->setColorFilter(
-                SkColorFilter::CreateModeFilter(colors[x][y], SkXfermode::kModulate_Mode))->unref();
+                SkColorFilter::MakeModeFilter(colors[x][y], SkXfermode::kModulate_Mode));
 
             step.fSurf = create_compat_surface(finalCanvas, kTileWidth, kTileHeight);
 
index 97d13cb9c90836d616044b18c400f3e3ebcc0920..bac6d8858ce2ca8a8a9cf208d20c29a2ecdf865c 100644 (file)
@@ -22,26 +22,26 @@ static const int kDetectorGreenValue = 50;
 // kDetectorGreenValue and then the incorrect value is observable by some part of the drawing
 // pipeline, that pixel will remain empty.
 
-static SkColorFilter* make_detector_color_filter() {
+static sk_sp<SkColorFilter> make_detector_color_filter() {
     uint8_t tableA[256] = { 0, };
     uint8_t tableR[256] = { 0, };
     uint8_t tableG[256] = { 0, };
     uint8_t tableB[256] = { 0, };
     tableA[255] = 255;
     tableG[kDetectorGreenValue] = 255;
-    return SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
+    return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
 }
 
 // This detector detects that color filter phase of the pixel pipeline receives the correct value.
 static void install_detector_color_filter(SkPaint* drawPaint) {
-    drawPaint->setColorFilter(make_detector_color_filter())->unref();
+    drawPaint->setColorFilter(make_detector_color_filter());
 }
 
 // This detector detects that image filter phase of the pixel pipeline receives the correct value.
 static void install_detector_image_filter(SkPaint* drawPaint) {
-    SkAutoTUnref<SkColorFilter> colorFilter(make_detector_color_filter());
+    auto colorFilter(make_detector_color_filter());
     SkImageFilter* imageFilter =
-            SkColorFilterImageFilter::Create(colorFilter, drawPaint->getImageFilter());
+            SkColorFilterImageFilter::Create(colorFilter.get(), drawPaint->getImageFilter());
     drawPaint->setImageFilter(imageFilter)->unref();
 }
 
index 23c0c5fec06f7ba897863efeb185363025262cd6..3358de5525f9dca4247e899de503ec5d266ac6ae 100644 (file)
@@ -64,8 +64,7 @@ DEF_SIMPLE_GM_BG(skbug1719, canvas, 300, 100,
             SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
                                      0.78867501f,
                                      SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
-        paint.setColorFilter(
-            SkColorFilter::CreateModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode))->unref();
+        paint.setColorFilter(SkColorFilter::MakeModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode));
 
         canvas->clipPath(clipPath, SkRegion::kIntersect_Op, true);
         canvas->drawPath(drawPath, paint);
index dcc29f37cf3d8de45cb099f15a8f3aff0259c55a..c9ca474e764564a85359d6c4df174bfeef3b3875 100644 (file)
@@ -73,27 +73,27 @@ static void make_table2(uint8_t table[]) {
     }
 }
 
-static SkColorFilter* make_null_cf() {
+static sk_sp<SkColorFilter> make_null_cf() {
     return nullptr;
 }
 
-static SkColorFilter* make_cf0() {
+static sk_sp<SkColorFilter> make_cf0() {
     uint8_t table[256]; make_table0(table);
-    return SkTableColorFilter::Create(table);
+    return SkTableColorFilter::Make(table);
 }
-static SkColorFilter* make_cf1() {
+static sk_sp<SkColorFilter> make_cf1() {
     uint8_t table[256]; make_table1(table);
-    return SkTableColorFilter::Create(table);
+    return SkTableColorFilter::Make(table);
 }
-static SkColorFilter* make_cf2() {
+static sk_sp<SkColorFilter> make_cf2() {
     uint8_t table[256]; make_table2(table);
-    return SkTableColorFilter::Create(table);
+    return SkTableColorFilter::Make(table);
 }
-static SkColorFilter* make_cf3() {
+static sk_sp<SkColorFilter> make_cf3() {
     uint8_t table0[256]; make_table0(table0);
     uint8_t table1[256]; make_table1(table1);
     uint8_t table2[256]; make_table2(table2);
-    return SkTableColorFilter::CreateARGB(nullptr, table0, table1, table2);
+    return SkTableColorFilter::MakeARGB(nullptr, table0, table1, table2);
 }
 
 class TableColorFilterGM : public skiagm::GM {
@@ -114,8 +114,9 @@ protected:
         canvas->translate(20, 20);
 
 
-        static SkColorFilter* (*gColorFilterMakers[])() = { make_null_cf, make_cf0, make_cf1,
-                                                 make_cf2, make_cf3 };
+        static sk_sp<SkColorFilter> (*gColorFilterMakers[])() = {
+            make_null_cf, make_cf0, make_cf1, make_cf2, make_cf3
+        };
         static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 };
 
         // This test will be done once for each bitmap with the results stacked vertically.
@@ -155,25 +156,25 @@ protected:
             // each draw being at xOffset of the previous one
             for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
                 x += xOffset;
-                paint.setColorFilter(gColorFilterMakers[i]())->unref();
+                paint.setColorFilter(gColorFilterMakers[i]());
                 canvas->drawBitmap(bm, x, y, &paint);
             }
 
             paint.setColorFilter(nullptr);
 
             for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
-                SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]());
+                auto colorFilter1(gColorFilterMakers[i]());
                 SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create(
-                            colorFilter1, nullptr, nullptr));
+                            colorFilter1.get(), nullptr, nullptr));
 
                 // Move down to the next line and draw it
                 // each draw being at xOffset of the previous one
                 y += yOffset;
                 x = 0;
                 for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j) {
-                    SkAutoTUnref<SkColorFilter> colorFilter2(gColorFilterMakers[j]());
+                    auto colorFilter2(gColorFilterMakers[j]());
                     SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Create(
-                                colorFilter2, imageFilter1, nullptr));
+                                colorFilter2.get(), imageFilter1, nullptr));
                     paint.setImageFilter(imageFilter2);
                     canvas->drawBitmap(bm, x, y, &paint);
                     x += xOffset;
@@ -225,11 +226,11 @@ protected:
         canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
 
         const int MODES = MODE_COUNT * COLOR_COUNT;
-        SkAutoTUnref<SkColorFilter> filters[MODES];
+        sk_sp<SkColorFilter> filters[MODES];
         int index = 0;
         for (int i = 0; i < MODE_COUNT; ++i) {
             for (int j = 0; j < COLOR_COUNT; ++j) {
-                filters[index++].reset(SkColorFilter::CreateModeFilter(fColors[j], fModes[i]));
+                filters[index++] = SkColorFilter::MakeModeFilter(fColors[j], fModes[i]);
             }
         }
 
@@ -261,9 +262,7 @@ protected:
         for (int y = 0; y < MODES; ++y) {
             canvas->save();
             for (int x = 0; x < MODES; ++x) {
-                SkAutoTUnref<SkColorFilter> compose(SkColorFilter::CreateComposeFilter(filters[y],
-                                                                                       filters[x]));
-                paint.setColorFilter(compose);
+                paint.setColorFilter(SkColorFilter::MakeComposeFilter(filters[y], filters[x]));
                 canvas->drawRect(r, paint);
                 canvas->translate(r.width() + spacer, 0);
             }
index 1ea9575c7c9fa492b3a42d8e3eacded3a62675a8..465d606e2ba5315d72de6d2b1f5bb9cb89c0ac8b 100644 (file)
 static SkImageFilter* make0() { return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); }
 static SkImageFilter* make1() { return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); }
 static SkImageFilter* make2() {
-    SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorBLUE,
-                                                        SkXfermode::kSrcIn_Mode);
-    SkAutoUnref aur(cf);
-    return SkColorFilterImageFilter::Create(cf);
+    auto cf = SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode);
+    return SkColorFilterImageFilter::Create(cf.get());
 }
 static SkImageFilter* make3() {
     return SkBlurImageFilter::Create(8, 0);
@@ -56,10 +54,8 @@ static SkImageFilter* make6() {
     SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
     SkAutoUnref aur2(compose);
 
-    SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
-                                                        SkXfermode::kSrcIn_Mode);
-    SkAutoUnref aur3(cf);
-    SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
+    auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode);
+    SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get());
     SkAutoUnref aur4(blue);
 
     return SkMergeImageFilter::Create(compose, blue);
@@ -73,10 +69,8 @@ static SkImageFilter* make7() {
     SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
     SkAutoUnref aur2(compose);
 
-    SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
-                                                        SkXfermode::kSrcIn_Mode);
-    SkAutoUnref aur3(cf);
-    SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
+    auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode);
+    SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get());
     SkAutoUnref aur4(blue);
 
     return SkMergeImageFilter::Create(compose, blue);
index d9701131a407f2dae3766b777b3a37826758d77f..ac8b7c9759580070317b54cd81eb0f05fd20a586 100644 (file)
@@ -97,7 +97,7 @@ static void color_filter(SkPaint* paint) {
     SkRect r;
     r.setWH(SkIntToScalar(kWidth), 50);
     paint->setShader(make_shader(r));
-    paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(0xF0F0F0, 0))->unref();
+    paint->setColorFilter(SkColorMatrixFilter::MakeLightingFilter(0xF0F0F0, 0));
 }
 
 static void kitchen_sink(SkPaint* paint) {
index cf8825e5bb9d105600954edb96334ab1bfb7ae84..f75e7f97221553f2cd31b6cab14a46d0fd14d201 100644 (file)
@@ -93,9 +93,9 @@ protected:
         SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
                                         SkIntToScalar(fBitmap->height() * 2));
         SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
-        SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(matrix));
+        auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
 
-        SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf, tile.get()));
+        SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get()));
         SkPaint paint;
         paint.setImageFilter(cfif);
         canvas->save();
index 177dc43c2b7bc83b4d7838defc0cea3bc405cb52..9c4ccc16bb33d04b3bffb4c790f73fd67188b0bf 100644 (file)
@@ -26,17 +26,17 @@ static sk_sp<SkShader> make_shader2() {
     return SkShader::MakeColorShader(SK_ColorBLUE);
 }
 
-static SkColorFilter* make_color_filter() {
-    return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
+static sk_sp<SkColorFilter> make_color_filter() {
+    return SkColorFilter::MakeModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
 }
 
 class VerticesGM : public skiagm::GM {
-    SkPoint                     fPts[9];
-    SkPoint                     fTexs[9];
-    SkColor                     fColors[9];
-    sk_sp<SkShader>             fShader1;
-    sk_sp<SkShader>             fShader2;
-    SkAutoTUnref<SkColorFilter> fColorFilter;
+    SkPoint                 fPts[9];
+    SkPoint                 fTexs[9];
+    SkColor                 fColors[9];
+    sk_sp<SkShader>         fShader1;
+    sk_sp<SkShader>         fShader2;
+    sk_sp<SkColorFilter>    fColorFilter;
 
 public:
     VerticesGM() {}
@@ -60,7 +60,7 @@ protected:
 
         fShader1 = make_shader1(w, h);
         fShader2 = make_shader2();
-        fColorFilter.reset(make_color_filter());
+        fColorFilter = make_color_filter();
 
         SkRandom rand;
         for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
@@ -85,11 +85,11 @@ protected:
         };
 
         const struct {
-            const SkColor*          fColors;
-            const SkPoint*          fTexs;
-            const sk_sp<SkShader>&  fShader;
-            SkColorFilter*          fColorFilter;
-            uint8_t                 fAlpha;
+            const SkColor*              fColors;
+            const SkPoint*              fTexs;
+            const sk_sp<SkShader>&      fShader;
+            const sk_sp<SkColorFilter>& fColorFilter;
+            uint8_t                     fAlpha;
         } rec[] = {
             { fColors,  nullptr, fShader1, nullptr     , 0xFF },
             { nullptr,  fTexs  , fShader1, nullptr     , 0xFF },
index 8660475463ad34ed2a8abde7388dd14e7dc06316..a76108416bfa5d29f46f65ac8e633ac661b28fae 100644 (file)
@@ -16,6 +16,7 @@
       'SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT',
       # Needed until we fix https://bug.skia.org/2440 .
       'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
+      'SK_SUPPORT_LEGACY_COLORFILTER_PTR',
       'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
       'SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR',
       'SK_SUPPORT_LEGACY_GRADIENT_DITHERING',
index 4c9795c2711037b646ef876edc01beb0c8cdb037..7ac335fb103677fb50037915e67b99b9dbbcf177 100644 (file)
@@ -86,7 +86,7 @@ public:
      *
      *  e.g. result(color) == this_filter(inner(color))
      */
-    virtual SkColorFilter* newComposed(const SkColorFilter* /*inner*/) const { return NULL; }
+    virtual sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const { return nullptr; }
 
     /**
      *  Apply this colorfilter to the specified SkColor. This routine handles
@@ -110,7 +110,7 @@ public:
         @return colorfilter object that applies the src color and mode,
                     or NULL if the mode will have no effect.
     */
-    static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode);
+    static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkXfermode::Mode mode);
 
     /** Construct a colorfilter whose effect is to first apply the inner filter and then apply
      *  the outer filter to the result of the inner's.
@@ -119,12 +119,28 @@ public:
      *  Due to internal limits, it is possible that this will return NULL, so the caller must
      *  always check.
      */
-    static SkColorFilter* CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner);
+    static sk_sp<SkColorFilter> MakeComposeFilter(sk_sp<SkColorFilter> outer,
+                                                  sk_sp<SkColorFilter> inner);
 
     /** Construct a color filter that transforms a color by a 4x5 matrix. The matrix is in row-
      *  major order and the translation column is specified in unnormalized, 0...255, space.
      */
-    static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]);
+    static sk_sp<SkColorFilter> MakeMatrixFilterRowMajor255(const SkScalar array[20]);
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
+    static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode) {
+        return MakeModeFilter(c, mode).release();
+    }
+    static SkColorFilter* CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
+        return MakeComposeFilter(sk_ref_sp(outer), sk_ref_sp(inner)).release();
+    }
+    static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
+        return MakeMatrixFilterRowMajor255(array).release();
+    }
+    virtual SkColorFilter* newComposed(const SkColorFilter* inner) const {
+        return this->makeComposed(sk_ref_sp(const_cast<SkColorFilter*>(inner))).release();
+    }
+#endif
 
     /**
      *  A subclass may implement this factory function to work with the GPU backend. It returns
index f5c3bc3d4b009a39a308f7d097476519b3a7f185..21d7109cbb446ea4b077bc56c71062d8142c34bd 100644 (file)
@@ -515,7 +515,9 @@ public:
         @param filter   May be NULL. The filter to be installed in the paint
         @return         filter
     */
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
     SkColorFilter* setColorFilter(SkColorFilter* filter);
+#endif
     void setColorFilter(sk_sp<SkColorFilter>);
 
     /** Get the paint's xfermode object.
index c9c760d06d9ed01e897c41a4cb1e615f35f0a83d..e2ebda5f1018218806cd49f56d1c644e2c3101d2 100644 (file)
@@ -359,7 +359,7 @@ public:
      *  Create a new shader that produces the same colors as invoking this shader and then applying
      *  the colorfilter.
      */
-    sk_sp<SkShader> makeWithColorFilter(SkColorFilter*) const;
+    sk_sp<SkShader> makeWithColorFilter(sk_sp<SkColorFilter>) const;
 
     //////////////////////////////////////////////////////////////////////////
     //  Factory methods for stock shaders
@@ -393,9 +393,7 @@ public:
     SkShader* newWithLocalMatrix(const SkMatrix& matrix) const {
         return this->makeWithLocalMatrix(matrix).release();
     }
-    SkShader* newWithColorFilter(SkColorFilter* filter) const {
-        return this->makeWithColorFilter(filter).release();
-    }
+    SkShader* newWithColorFilter(SkColorFilter* filter) const;
 #endif
 
     /**
index 0371700ba4d2576cd5d4b4370ac1c33986f16976..49b0c51f251cd481fd9fa8e52a5b0bb7c50c93c4 100644 (file)
@@ -65,7 +65,7 @@ protected:
 
 private:
     SkMaskFilter*   fBlur;
-    SkColorFilter*  fColorFilter;
+    sk_sp<SkColorFilter> fColorFilter;
     SkScalar        fDx, fDy, fSigma;
     SkColor         fBlurColor;
     uint32_t        fBlurFlags;
index 8d63667c3232c295bf8c93b855cac0adbda716a5..8b621292b03bdba9eb1bead4e21ab25122ee392c 100644 (file)
@@ -20,7 +20,11 @@ public:
      *  This cube contains a transform where (x,y,z) maps to the (r,g,b).
      *  The alpha components of the colors must be 0xFF.
      */
+    static sk_sp<SkColorFilter> Make(sk_sp<SkData> cubeData, int cubeDimension);
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
     static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
+#endif
 
     void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
     uint32_t getFlags() const override;
@@ -33,7 +37,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
 
 protected:
-    SkColorCubeFilter(SkData* cubeData, int cubeDimension);
+    SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension);
     void flatten(SkWriteBuffer&) const override;
 
 private:
index 6dd9df2495ca28809a14ba43d19bb936a03137fd..c34e9ced5908e9f5febde9d9c259ef6673356ebb 100644 (file)
@@ -31,9 +31,8 @@ private:
     SkColorFilterImageFilter(SkColorFilter* cf,
                              SkImageFilter* input,
                              const CropRect* cropRect);
-    virtual ~SkColorFilterImageFilter();
 
-    SkColorFilter*  fColorFilter;
+    sk_sp<SkColorFilter> fColorFilter;
 
     typedef SkImageFilter INHERITED;
 };
index d71d2ed5332d1f08c822b18acee34c3e3f619106..6e74bee315c3d10bd1ca13638554d3d0f0cb8fb6 100644 (file)
 
 class SK_API SkColorMatrixFilter : public SkColorFilter {
 public:
-    static SkColorFilter* Create(const SkColorMatrix& cm) {
-        return SkColorFilter::CreateMatrixFilterRowMajor255(cm.fMat);
-    }
-    static SkColorFilter* Create(const SkScalar array[20]) {
-        return SkColorFilter::CreateMatrixFilterRowMajor255(array);
-    }
-
     /**
      *  Create a colorfilter that multiplies the RGB channels by one color, and
      *  then adds a second color, pinning the result for each component to
      *  [0..255]. The alpha components of the mul and add arguments
      *  are ignored.
      */
-    static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add);
+    static sk_sp<SkColorFilter> MakeLightingFilter(SkColor mul, SkColor add);
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
+    static SkColorFilter* Create(const SkColorMatrix& cm) {
+        return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat).release();
+    }
+    static SkColorFilter* Create(const SkScalar array[20]) {
+        return SkColorFilter::MakeMatrixFilterRowMajor255(array).release();
+    }
+    static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add) {
+        return MakeLightingFilter(mul, add).release();
+    }
+#endif
 };
 
 #endif
index 8dd519af4a77fe5ea142e9d8a15c4bfbc4c4a2e5..3a68607b1977dee04471ef958c3a71a5153c1c1c 100644 (file)
  */
 class SK_API SkLumaColorFilter : public SkColorFilter {
 public:
-    static SkColorFilter* Create();
+    static sk_sp<SkColorFilter> Make();
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
+    static SkColorFilter* Create() { return Make().release(); }
+#endif
 
     void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
 
index e4d42dc00cc4cd8a1c7a19f10601763844c24d03..fe31149464dc44170f8a5405559984a33cd05a2d 100644 (file)
@@ -23,7 +23,7 @@ public:
      *  colors are premultiplied, they are temporarily unpremultiplied, then
      *  the table is applied, and then the result is remultiplied.
      */
-    static SkColorFilter* Create(const uint8_t table[256]);
+    static sk_sp<SkColorFilter> Make(const uint8_t table[256]);
 
     /**
      *  Create a table colorfilter, with a different table for each
@@ -31,11 +31,23 @@ public:
      *  treated as identity, with the component left unchanged. If a table
      *  is not null, then its contents are copied into the filter.
      */
+    static sk_sp<SkColorFilter> MakeARGB(const uint8_t tableA[256],
+                                         const uint8_t tableR[256],
+                                         const uint8_t tableG[256],
+                                         const uint8_t tableB[256]);
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
+    static SkColorFilter* Create(const uint8_t table[256]) {
+        return Make(table).release();
+    }
     static SkColorFilter* CreateARGB(const uint8_t tableA[256],
                                      const uint8_t tableR[256],
                                      const uint8_t tableG[256],
-                                     const uint8_t tableB[256]);
-
+                                     const uint8_t tableB[256]) {
+        return MakeARGB(tableA, tableR, tableG, tableB).release();
+    }
+#endif
+    
     SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
 };
 
index 11a7ca3ab3cf3d350e8879664f5208a5c02624f0..20914ea69cc7694e33a861a2ba8bffe80df37e5f 100644 (file)
@@ -501,7 +501,6 @@ DEFINES_UNIX = [
     "SK_CODEC_DECODES_PNG",
     "SK_CODEC_DECODES_RAW",
     "SK_CODEC_DECODES_WEBP",
-    "SK_SUPPORT_LEGACY_CREATESHADER_PTR",
 ]
 
 DEFINES_ANDROID = [
@@ -527,6 +526,9 @@ DEFINES_ALL = [
     "SK_SUPPORT_LEGACY_PATHEFFECT_PTR",
     # Turn on a few Google3-specific build fixes.
     "GOOGLE3",
+    # Staging flags for API changes
+    "SK_SUPPORT_LEGACY_COLORFILTER_PTR",
+    "SK_SUPPORT_LEGACY_CREATESHADER_PTR",
 ]
 
 ################################################################################
index b8b0ee677d168dfc8d84b4b5a697879a5dc947a0..70ecd9fe7e57dea95258bccb8810c738b00a60f3 100644 (file)
@@ -384,7 +384,7 @@ protected:
         SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light);
 
         SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode);
-        SkColorFilter* lightingFilter = SkColorMatrixFilter::CreateLightingFilter(
+        auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter(
             0xff89bc45, 0xff112233);
 
         canvas->save();
@@ -406,7 +406,7 @@ protected:
         paint.setStrokeWidth(SkIntToScalar(10));
         paint.setStyle(SkPaint::kStroke_Style);
         paint.setXfermode(xfermode)->unref();
-        paint.setColorFilter(lightingFilter)->unref();
+        paint.setColorFilter(lightingFilter);
         canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green
         paint.setXfermode(nullptr);
         paint.setColorFilter(nullptr);
@@ -543,9 +543,9 @@ protected:
 
 #if 01
             int index = i % SK_ARRAY_COUNT(gLightingColors);
-            paint.setColorFilter(SkColorMatrixFilter::CreateLightingFilter(
+            paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter(
                                     gLightingColors[index].fMul,
-                                    gLightingColors[index].fAdd))->unref();
+                                    gLightingColors[index].fAdd));
 #endif
 
             canvas->drawText(str.c_str(), str.size(), x, y, paint);
index 4ee8949410e58f72b3b41ee3b962081774eca6f0..0b8acc32d71b7dc2680dd39a737fdf29d409b8e6 100644 (file)
@@ -184,8 +184,7 @@ protected:
 
         for (size_t y = 0; y < SK_ARRAY_COUNT(gColors); y++) {
             for (size_t x = 0; x < SK_ARRAY_COUNT(gModes); x++) {
-                SkColorFilter* cf = SkColorFilter::CreateModeFilter(gColors[y], gModes[x]);
-                SkSafeUnref(paint.setColorFilter(cf));
+                paint.setColorFilter(SkColorFilter::MakeModeFilter(gColors[y], gModes[x]));
                 canvas->drawBitmap(fBitmap, x * N * 1.25f, y * N * scale, &paint);
             }
         }
index dd0fa4044e6f5b9bbeaf776b4d454d7311ecea78..82934ea3cc774079e7bcef4f17cdf1cf6bfca582 100644 (file)
@@ -298,9 +298,9 @@ static const SkBitmap& make_bitmap() {
     return bitmap[R(2)];
 }
 
-static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
+static sk_sp<SkData> make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
     int size = 4 << R(5);
-    SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
+    auto data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size);
     SkColor* pixels = (SkColor*)(data->writable_data());
     SkAutoTMalloc<uint8_t> lutMemory(size);
     SkAutoTMalloc<uint8_t> invLutMemory(size);
@@ -350,20 +350,17 @@ static void rand_color_table(uint8_t* table) {
     }
 }
 
-static SkColorFilter* make_color_filter() {
-    SkColorFilter* colorFilter;
+static sk_sp<SkColorFilter> make_color_filter() {
     switch (R(6)) {
         case 0: {
             SkScalar array[20];
             for (int i = 0; i < 20; ++i) {
                 array[i] = make_scalar();
             }
-            colorFilter = SkColorMatrixFilter::Create(array);
-            break;
+            return SkColorFilter::MakeMatrixFilterRowMajor255(array);
         }
         case 1:
-            colorFilter = SkLumaColorFilter::Create();
-            break;
+            return SkLumaColorFilter::Make();
         case 2: {
             uint8_t tableA[256];
             uint8_t tableR[256];
@@ -373,21 +370,17 @@ static SkColorFilter* make_color_filter() {
             rand_color_table(tableR);
             rand_color_table(tableG);
             rand_color_table(tableB);
-            colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
-            break;
+            return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
         }
         case 3:
-            colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfermode());
-            break;
+            return SkColorFilter::MakeModeFilter(make_color(), make_xfermode());
         case 4:
-            colorFilter = SkColorMatrixFilter::CreateLightingFilter(make_color(), make_color());
-            break;
+            return SkColorMatrixFilter::MakeLightingFilter(make_color(), make_color());
         case 5:
         default:
-            colorFilter = nullptr;
             break;
     }
-    return colorFilter;
+    return nullptr;
 }
 
 static SkPath make_path() {
@@ -538,7 +531,7 @@ static SkPaint make_paint() {
     rasterizerBuilder.addLayer(paintForRasterizer);
     paint.setRasterizer(rasterizerBuilder.detach());
     paint.setImageFilter(make_image_filter());
-    SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
+    sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
     paint.setTextAlign(make_paint_align());
     paint.setTextSize(make_scalar());
     paint.setTextScaleX(make_scalar());
@@ -567,16 +560,16 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
         break;
     case COLOR:
     {
-        SkAutoTUnref<SkColorFilter> cf(make_color_filter());
-        filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0;
+        sk_sp<SkColorFilter> cf(make_color_filter());
+        filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
     }
         break;
     case LUT3D:
     {
         int cubeDimension;
-        SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
-        SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDimension));
-        filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0;
+        sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
+        sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
+        filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
     }
         break;
     case BLUR:
index 04897e3828af4ec077ec27102e88b279437969a8..15562168e990a5bbb5eb5fef9b1f1da4c03b8d8e 100644 (file)
@@ -844,7 +844,8 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
     if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) {
         SkPaint* p = paint.writable();
         shader = p->setShader(nullptr);
-        cf = p->setColorFilter(nullptr);
+        p->setColorFilter(nullptr);
+        cf = nullptr;
         mode = p->setXfermodeMode(SkXfermode::kSrc_Mode);
         p->setColor(0);
     }
@@ -867,7 +868,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
 
     if (cf) {
         SkASSERT(shader);
-        paint.writable()->setShader(shader->makeWithColorFilter(cf));
+        paint.writable()->setShader(shader->makeWithColorFilter(sk_ref_sp(cf)));
         shader = paint->getShader();
         // blitters should ignore the presence/absence of a filter, since
         // if there is one, the shader will take care of it.
index 3efb44cc548bed305cf0c18450e9b45f91b6711d..f7f870210d0844b6347030575ec159d210f15ea9 100644 (file)
@@ -391,16 +391,17 @@ static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) {
  *  If the paint has an imagefilter, but it can be simplified to just a colorfilter, return that
  *  colorfilter, else return nullptr.
  */
-static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
+static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) {
     SkImageFilter* imgf = paint.getImageFilter();
     if (!imgf) {
         return nullptr;
     }
 
-    SkColorFilter* imgCF;
-    if (!imgf->asAColorFilter(&imgCF)) {
+    SkColorFilter* imgCFPtr;
+    if (!imgf->asAColorFilter(&imgCFPtr)) {
         return nullptr;
     }
+    sk_sp<SkColorFilter> imgCF(imgCFPtr);
 
     SkColorFilter* paintCF = paint.getColorFilter();
     if (nullptr == paintCF) {
@@ -410,8 +411,7 @@ static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
 
     // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF)
     // and we need to combine them into a single colorfilter.
-    SkAutoTUnref<SkColorFilter> autoImgCF(imgCF);
-    return SkColorFilter::CreateComposeFilter(imgCF, paintCF);
+    return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF));
 }
 
 /**
@@ -455,10 +455,10 @@ public:
         fTempLayerForImageFilter = false;
         fDone = false;
 
-        SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint);
+        auto simplifiedCF = image_to_color_filter(fOrigPaint);
         if (simplifiedCF) {
             SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
-            paint->setColorFilter(simplifiedCF)->unref();
+            paint->setColorFilter(std::move(simplifiedCF));
             paint->setImageFilter(nullptr);
             fPaint = paint;
         }
index dab4ccf7b55d09f8aa791804c3bb5e1bb176cf33..59a625d0b6d4b0b7f54a3b0354d3f5992fe2d4e1 100644 (file)
@@ -114,14 +114,15 @@ public:
     
 protected:
     void flatten(SkWriteBuffer& buffer) const override {
-        buffer.writeFlattenable(fOuter);
-        buffer.writeFlattenable(fInner);
+        buffer.writeFlattenable(fOuter.get());
+        buffer.writeFlattenable(fInner.get());
     }
     
 private:
-    SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner, int composedFilterCount)
-        : fOuter(SkRef(outer))
-        , fInner(SkRef(inner))
+    SkComposeColorFilter(sk_sp<SkColorFilter> outer, sk_sp<SkColorFilter> inner,
+                         int composedFilterCount)
+        : fOuter(std::move(outer))
+        , fInner(std::move(inner))
         , fComposedFilterCount(composedFilterCount)
     {
         SkASSERT(composedFilterCount >= 2);
@@ -132,9 +133,9 @@ private:
         return fComposedFilterCount;
     }
 
-    SkAutoTUnref<SkColorFilter> fOuter;
-    SkAutoTUnref<SkColorFilter> fInner;
-    const int                   fComposedFilterCount;
+    sk_sp<SkColorFilter> fOuter;
+    sk_sp<SkColorFilter> fInner;
+    const int            fComposedFilterCount;
 
     friend class SkColorFilter;
 
@@ -142,23 +143,24 @@ private:
 };
 
 SkFlattenable* SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) {
-    SkAutoTUnref<SkColorFilter> outer(buffer.readColorFilter());
-    SkAutoTUnref<SkColorFilter> inner(buffer.readColorFilter());
-    return CreateComposeFilter(outer, inner);
+    sk_sp<SkColorFilter> outer(buffer.readColorFilter());
+    sk_sp<SkColorFilter> inner(buffer.readColorFilter());
+    return MakeComposeFilter(std::move(outer), std::move(inner)).release();
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
+sk_sp<SkColorFilter> SkColorFilter::MakeComposeFilter(sk_sp<SkColorFilter> outer,
+                                                      sk_sp<SkColorFilter> inner) {
     if (!outer) {
-        return SkSafeRef(inner);
+        return inner;
     }
     if (!inner) {
-        return SkSafeRef(outer);
+        return outer;
     }
 
     // Give the subclass a shot at a more optimal composition...
-    SkColorFilter* composition = outer->newComposed(inner);
+    auto composition = outer->makeComposed(inner);
     if (composition) {
         return composition;
     }
@@ -167,7 +169,7 @@ SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorF
     if (count > SK_MAX_COMPOSE_COLORFILTER_COUNT) {
         return nullptr;
     }
-    return new SkComposeColorFilter(outer, inner, count);
+    return sk_sp<SkColorFilter>(new SkComposeColorFilter(std::move(outer), std::move(inner),count));
 }
 
 #include "SkModeColorFilter.h"
index 2e426a17eded3255f99f12f562cda2b86f510691..8a175024def79963a4da350025f7209c7141a66f 100644 (file)
 #include "GrFragmentProcessor.h"
 #endif
 
-SkColorFilterShader::SkColorFilterShader(SkShader* shader, SkColorFilter* filter)
-    : fShader(SkRef(shader))
-    , fFilter(SkRef(filter))
+SkColorFilterShader::SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter)
+    : fShader(std::move(shader))
+    , fFilter(std::move(filter))
 {
-    SkASSERT(shader);
-    SkASSERT(filter);
+    SkASSERT(fShader);
+    SkASSERT(fFilter);
 }
 
 SkFlattenable* SkColorFilterShader::CreateProc(SkReadBuffer& buffer) {
     auto shader = buffer.readShader();
-    SkAutoTUnref<SkColorFilter> filter(buffer.readColorFilter());
-    if (!shader || !filter.get()) {
+    auto filter = buffer.readColorFilter();
+    if (!shader || !filter) {
         return nullptr;
     }
-    return new SkColorFilterShader(shader.get(), filter);
+    return new SkColorFilterShader(shader, filter);
 }
 
 void SkColorFilterShader::flatten(SkWriteBuffer& buffer) const {
-    buffer.writeFlattenable(fShader);
-    buffer.writeFlattenable(fFilter);
+    buffer.writeFlattenable(fShader.get());
+    buffer.writeFlattenable(fFilter.get());
 }
 
 uint32_t SkColorFilterShader::FilterShaderContext::getFlags() const {
@@ -137,10 +137,10 @@ void SkColorFilterShader::toString(SkString* str) const {
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-sk_sp<SkShader> SkShader::makeWithColorFilter(SkColorFilter* filter) const {
+sk_sp<SkShader> SkShader::makeWithColorFilter(sk_sp<SkColorFilter> filter) const {
     SkShader* base = const_cast<SkShader*>(this);
     if (!filter) {
         return sk_ref_sp(base);
     }
-    return sk_make_sp<SkColorFilterShader>(base, filter);
+    return sk_make_sp<SkColorFilterShader>(sk_ref_sp(base), filter);
 }
index 0f41a43c49d72890f59b2f1544bea0288621362b..167a272fa4e8ca6914a170040f8c17984900f6e4 100644 (file)
@@ -13,7 +13,7 @@
 
 class SkColorFilterShader : public SkShader {
 public:
-    SkColorFilterShader(SkShader* shader, SkColorFilter* filter);
+    SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter);
 
 #if SK_SUPPORT_GPU
     const GrFragmentProcessor* asFragmentProcessor(GrContext*,
@@ -53,8 +53,8 @@ protected:
     Context* onCreateContext(const ContextRec&, void* storage) const override;
     
 private:
-    SkAutoTUnref<SkShader>      fShader;
-    SkAutoTUnref<SkColorFilter> fFilter;
+    sk_sp<SkShader>      fShader;
+    sk_sp<SkColorFilter> fFilter;
     
     typedef SkShader INHERITED;
 };
index 09df61699d1e6dedde7ee2d83c623c1002ca405a..bd9a66a561a50f4744f07480c23d200658a4efc9 100644 (file)
@@ -226,12 +226,13 @@ static void set_concat(SkScalar result[20], const SkScalar outer[20], const SkSc
 //  End duplication
 //////
 
-SkColorFilter* SkColorMatrixFilterRowMajor255::newComposed(const SkColorFilter* innerFilter) const {
+sk_sp<SkColorFilter>
+SkColorMatrixFilterRowMajor255::makeComposed(sk_sp<SkColorFilter> innerFilter) const {
     SkScalar innerMatrix[20];
     if (innerFilter->asColorMatrix(innerMatrix) && !needs_clamping(innerMatrix)) {
         SkScalar concat[20];
         set_concat(concat, fMatrix, innerMatrix);
-        return new SkColorMatrixFilterRowMajor255(concat);
+        return sk_make_sp<SkColorMatrixFilterRowMajor255>(concat);
     }
     return nullptr;
 }
@@ -417,15 +418,16 @@ void SkColorMatrixFilterRowMajor255::toString(SkString* str) const {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
-    return new SkColorMatrixFilterRowMajor255(array);
+sk_sp<SkColorFilter> SkColorFilter::MakeMatrixFilterRowMajor255(const SkScalar array[20]) {
+    return sk_sp<SkColorFilter>(new SkColorMatrixFilterRowMajor255(array));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkColorFilter* SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(const SkScalar row[5]) {
+sk_sp<SkColorFilter>
+SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(const SkScalar row[5]) {
     SkASSERT(row);
-    SkColorMatrixFilterRowMajor255* cf = new SkColorMatrixFilterRowMajor255();
+    auto cf = sk_make_sp<SkColorMatrixFilterRowMajor255>();
     static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't match");
     for (int i = 0; i < 4; ++i) {
         memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5);
index 106d2bd882a798886824c050526a1ba70f7f0e48..0ad64fa2f0ed8e1a1f1f6c700d1fd173ade04d38 100644 (file)
 
 class SK_API SkColorMatrixFilterRowMajor255 : public SkColorFilter {
 public:
+    SkColorMatrixFilterRowMajor255() {};
     explicit SkColorMatrixFilterRowMajor255(const SkScalar array[20]);
 
     /** Creates a color matrix filter that returns the same value in all four channels. */
-    static SkColorFilter* CreateSingleChannelOutput(const SkScalar row[5]);
+    static sk_sp<SkColorFilter> MakeSingleChannelOutput(const SkScalar row[5]);
 
     void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
     void filterSpan4f(const SkPM4f src[], int count, SkPM4f[]) const override;
     uint32_t getFlags() const override;
     bool asColorMatrix(SkScalar matrix[20]) const override;
-    SkColorFilter* newComposed(const SkColorFilter*) const override;
+    sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const override;
 
 #if SK_SUPPORT_GPU
     const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override;
@@ -35,8 +36,6 @@ protected:
     void flatten(SkWriteBuffer&) const override;
 
 private:
-    SkColorMatrixFilterRowMajor255() {};
-
     SkScalar        fMatrix[20];
     float           fTranspose[20]; // for Sk4s
     uint32_t        fFlags;
index 90be52b403e4e5a40b161b8879afac1e169738dc..fb4b48fdbd4376614c937bb2e8246aeda9510cff 100644 (file)
@@ -207,8 +207,7 @@ void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR
         pnt.setShader(std::move(shader));
 
         if (colors) {
-            SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[i], mode));
-            pnt.setColorFilter(cf);
+            pnt.setColorFilter(SkColorFilter::MakeModeFilter(colors[i], mode));
         }
         
         path.rewind();
index 1e104d8dc77856b7ba07940769836e9a0e444025..3da51609a3a4dbadaef747332fe19d8f75ab9a10 100644 (file)
@@ -80,7 +80,7 @@ void SkModeColorFilter::updateCache() {
 SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) {
     SkColor color = buffer.readColor();
     SkXfermode::Mode mode = (SkXfermode::Mode)buffer.readUInt();
-    return SkColorFilter::CreateModeFilter(color, mode);
+    return SkColorFilter::MakeModeFilter(color, mode).release();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -148,7 +148,7 @@ private:
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode mode) {
+sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkXfermode::Mode mode) {
     if (!SkIsValidMode(mode)) {
         return nullptr;
     }
@@ -183,10 +183,10 @@ SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode m
 
     switch (mode) {
         case SkXfermode::kSrc_Mode:
-            return new Src_SkModeColorFilter(color);
+            return sk_make_sp<Src_SkModeColorFilter>(color);
         case SkXfermode::kSrcOver_Mode:
-            return new SrcOver_SkModeColorFilter(color);
+            return sk_make_sp<SrcOver_SkModeColorFilter>(color);
         default:
-            return SkModeColorFilter::Create(color, mode);
+            return SkModeColorFilter::Make(color, mode);
     }
 }
index 44e618a3ad27b6a7479690e080755db6f32c5d16..d73cab7932e9fc92a3b994ac5d3637d7828bee3b 100644 (file)
 
 class SkModeColorFilter : public SkColorFilter {
 public:
+    static sk_sp<SkColorFilter> Make(SkColor color, SkXfermode::Mode mode) {
+        return sk_sp<SkColorFilter>(new SkModeColorFilter(color, mode));
+    }
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
     static SkColorFilter* Create(SkColor color, SkXfermode::Mode mode) {
-        return new SkModeColorFilter(color, mode);
+        return Make(color, mode).release();
     }
+#endif
 
     SkColor getColor() const { return fColor; }
     SkXfermode::Mode getMode() const { return fMode; }
index 19bdcaf0aa97ccd199d86f820b682ec050f8d91f..6fe9d7599d30a7342fe0f3b93301453842f46eb3 100644 (file)
@@ -375,7 +375,9 @@ SET_PTR(Rasterizer)
 #endif
 SET_PTR(ImageFilter)
 SET_PTR(Shader)
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
 SET_PTR(ColorFilter)
+#endif
 SET_PTR(Xfermode)
 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
 SET_PTR(PathEffect)
@@ -1940,7 +1942,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
         this->setShader(buffer.readShader());
         SkSafeUnref(this->setXfermode(buffer.readXfermode()));
         SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
-        SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
+        this->setColorFilter(buffer.readColorFilter());
         this->setRasterizer(buffer.readRasterizer());
         this->setLooper(buffer.readDrawLooper());
         SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
index 575375edede670cbb56d4dd4d63cb2d2a6775755..46f6b818daf5b6149308c697d82cdbc9e6b9a762 100644 (file)
@@ -130,7 +130,9 @@ public:
     template <typename T> T* readFlattenable() {
         return (T*) this->readFlattenable(T::GetFlattenableType());
     }
-    SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
+    sk_sp<SkColorFilter> readColorFilter() {
+        return sk_sp<SkColorFilter>(this->readFlattenable<SkColorFilter>());
+    }
     sk_sp<SkDrawLooper> readDrawLooper() {
         return sk_sp<SkDrawLooper>(this->readFlattenable<SkDrawLooper>());
     }
index 52d0064eb1b16f7d6b4e0ccdc1d099a93d75fd5d..75fa6fc60cc72112d47ca16c3a2fa84172ef21b5 100644 (file)
@@ -449,4 +449,7 @@ SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, Tile
     return MakePictureShader(sk_ref_sp(const_cast<SkPicture*>(src)), tmx, tmy,
                              localMatrix, tile).release();
 }
+SkShader* SkShader::newWithColorFilter(SkColorFilter* filter) const {
+    return this->makeWithColorFilter(sk_ref_sp(filter)).release();
+}
 #endif
index d8127eba4ee4d03b1bec0d80c45888453c1e1b41..c8e20e1265be4858ffb687d0deac50ac89edfc21 100644 (file)
@@ -44,8 +44,7 @@ void SkBlurDrawLooper::initEffects() {
         // be baked into the blurred mask.
         SkColor opaqueColor = SkColorSetA(fBlurColor, 255);
         //The SrcIn xfer mode will multiply 'color' by the incoming alpha
-        fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor,
-                                                       SkXfermode::kSrcIn_Mode);
+        fColorFilter = SkColorFilter::MakeModeFilter(opaqueColor, SkXfermode::kSrcIn_Mode);
     } else {
         fColorFilter = nullptr;
     }
@@ -81,7 +80,6 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
 
 SkBlurDrawLooper::~SkBlurDrawLooper() {
     SkSafeUnref(fBlur);
-    SkSafeUnref(fColorFilter);
 }
 
 bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
index d59f123a80aaf0bfd2c37f6650571873a0f8f6c2..d80a02fef2424bb801407aaacdf95c35e75e6687 100644 (file)
@@ -48,19 +48,19 @@ static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) {
            (nullptr != cubeData) && (cubeData->size() >= minMemorySize);
 }
 
-SkColorFilter* SkColorCubeFilter::Create(SkData* cubeData, int cubeDimension) {
-    if (!is_valid_3D_lut(cubeData, cubeDimension)) {
+sk_sp<SkColorFilter> SkColorCubeFilter::Make(sk_sp<SkData> cubeData, int cubeDimension) {
+    if (!is_valid_3D_lut(cubeData.get(), cubeDimension)) {
         return nullptr;
     }
 
-    return new SkColorCubeFilter(cubeData, cubeDimension);
+    return sk_sp<SkColorFilter>(new SkColorCubeFilter(std::move(cubeData), cubeDimension));
 }
 
-SkColorCubeFilter::SkColorCubeFilter(SkData* cubeData, int cubeDimension)
-  : fCubeData(SkRef(cubeData))
-  , fUniqueID(SkNextColorCubeUniqueID())
-  , fCache(cubeDimension) {
-}
+SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension)
+    : fCubeData(std::move(cubeData))
+    , fUniqueID(SkNextColorCubeUniqueID())
+    , fCache(cubeDimension)
+{}
 
 uint32_t SkColorCubeFilter::getFlags() const {
     return this->INHERITED::getFlags() | kAlphaUnchanged_Flag;
@@ -142,7 +142,7 @@ SkFlattenable* SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) {
     if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) {
         return nullptr;
     }
-    return Create(cubeData.get(), cubeDimension);
+    return Make(std::move(cubeData), cubeDimension).release();
 }
 
 void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const {
index 96ce5d9690588867945886330a4dc723b4450fd9..6eb66533d90a96846610a9c7674d784b19e34a3e 100644 (file)
@@ -25,10 +25,10 @@ SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
     if (input && input->isColorFilterNode(&inputCF)) {
         // This is an optimization, as it collapses the hierarchy by just combining the two
         // colorfilters into a single one, which the new imagefilter will wrap.
-        SkAutoUnref autoUnref(inputCF);
-        SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf, inputCF));
+        sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf),
+                                                                    sk_sp<SkColorFilter>(inputCF)));
         if (newCF) {
-            return new SkColorFilterImageFilter(newCF, input->getInput(0), cropRect);
+            return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect);
         }
     }
 
@@ -42,17 +42,13 @@ SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
 
 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
-    SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter());
-    return Create(cf, common.getInput(0), &common.cropRect());
+    sk_sp<SkColorFilter> cf(buffer.readColorFilter());
+    return Create(cf.get(), common.getInput(0), &common.cropRect());
 }
 
 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    buffer.writeFlattenable(fColorFilter);
-}
-
-SkColorFilterImageFilter::~SkColorFilterImageFilter() {
-    fColorFilter->unref();
+    buffer.writeFlattenable(fColorFilter.get());
 }
 
 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source,
@@ -94,7 +90,7 @@ bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
     SkASSERT(1 == this->countInputs());
     if (!this->cropRectIsSet()) {
         if (filter) {
-            *filter = SkRef(fColorFilter);
+            *filter = SkRef(fColorFilter.get());
         }
         return true;
     }
index e122b6ac8e8aef1bed2171dac4173ac7f484c67b..82bd45b73ddd759bb0d19ec1bc56f9f4518a6bfa 100644 (file)
@@ -16,7 +16,7 @@ static SkScalar byte_to_scale(U8CPU byte) {
     }
 }
 
-SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor add) {
+sk_sp<SkColorFilter> SkColorMatrixFilter::MakeLightingFilter(SkColor mul, SkColor add) {
     SkColorMatrix matrix;
     matrix.setScale(byte_to_scale(SkColorGetR(mul)),
                     byte_to_scale(SkColorGetG(mul)),
@@ -26,5 +26,5 @@ SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor ad
                          SkIntToScalar(SkColorGetG(add)),
                          SkIntToScalar(SkColorGetB(add)),
                          0);
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat);
 }
index deece35b3883fe9255ba9f0f926a3e1602093da3..e32b89ee6df8d92cfd8ad1d8486e781a62fd4f49 100644 (file)
@@ -79,11 +79,9 @@ bool SkDropShadowImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitm
     sigma.fX = SkMaxScalar(0, sigma.fX);
     sigma.fY = SkMaxScalar(0, sigma.fY);
     SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY));
-    SkAutoTUnref<SkColorFilter> colorFilter(
-        SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode));
     SkPaint paint;
     paint.setImageFilter(blurFilter.get());
-    paint.setColorFilter(colorFilter.get());
+    paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcIn_Mode));
     paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
     SkVector offsetVec = SkVector::Make(fDx, fDy);
     ctx.ctm().mapVectors(&offsetVec, 1);
index ae31482ae7bdf5ff3747680b902286a9447660a5..8510767801c174a401cf28b0a3fb31b157ee1bc6 100644 (file)
@@ -102,7 +102,7 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
         dst->setShader(src.getShader());
     }
     if (bits & kColorFilter_Bit) {
-        dst->setColorFilter(src.getColorFilter());
+        dst->setColorFilter(sk_ref_sp(src.getColorFilter()));
     }
     if (bits & kXfermode_Bit) {
         dst->setXfermode(src.getXfermode());
index 0ca6342d563a6340a4f918bc17d8faa9aeea0293..18b2485a30ced845ad912109988cfdbe8458974c 100644 (file)
@@ -37,7 +37,9 @@ void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count,
     }
 }
 
-SkColorFilter* SkLumaColorFilter::Create() { return new SkLumaColorFilter; }
+sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
+    return sk_sp<SkColorFilter>(new SkLumaColorFilter);
+}
 
 SkLumaColorFilter::SkLumaColorFilter() : INHERITED() {}
 
index 5ae175ffca7822f43c40c83206d11465249950c5..4ce0b4bb0ee4fb0e4b4b0678a64269634176e520 100644 (file)
@@ -46,7 +46,7 @@ public:
     virtual ~SkTable_ColorFilter() { delete fBitmap; }
 
     bool asComponentTable(SkBitmap* table) const override;
-    SkColorFilter* newComposed(const SkColorFilter* inner) const override;
+    sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override;
 
 #if SK_SUPPORT_GPU
     const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override;
@@ -251,7 +251,7 @@ SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) {
         b = ptr;
         ptr += 256;
     }
-    return SkTableColorFilter::CreateARGB(a, r, g, b);
+    return SkTableColorFilter::MakeARGB(a, r, g, b).release();
 }
 
 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const {
@@ -287,7 +287,7 @@ static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin
     }
 }
 
-SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter) const {
+sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> innerFilter) const {
     SkBitmap innerBM;
     if (!innerFilter->asComponentTable(&innerBM)) {
         return nullptr;
@@ -326,7 +326,7 @@ SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter
     combine_tables(concatG, tableG, innerBM.getAddr8(0, 2));
     combine_tables(concatB, tableB, innerBM.getAddr8(0, 3));
 
-    return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB);
+    return SkTableColorFilter::MakeARGB(concatA, concatR, concatG, concatB);
 }
 
 #if SK_SUPPORT_GPU
@@ -554,7 +554,7 @@ const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d)
             }
         }
     }
-    SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB(
+    auto filter(SkTableColorFilter::MakeARGB(
         (flags & (1 << 0)) ? luts[0] : nullptr,
         (flags & (1 << 1)) ? luts[1] : nullptr,
         (flags & (1 << 2)) ? luts[2] : nullptr,
@@ -587,15 +587,15 @@ const GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* c
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) {
-    return new SkTable_ColorFilter(table, table, table, table);
+sk_sp<SkColorFilter> SkTableColorFilter::Make(const uint8_t table[256]) {
+    return sk_make_sp<SkTable_ColorFilter>(table, table, table, table);
 }
 
-SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256],
-                                              const uint8_t tableR[256],
-                                              const uint8_t tableG[256],
-                                              const uint8_t tableB[256]) {
-    return new SkTable_ColorFilter(tableA, tableR, tableG, tableB);
+sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256],
+                                                  const uint8_t tableR[256],
+                                                  const uint8_t tableG[256],
+                                                  const uint8_t tableB[256]) {
+    return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB);
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
index 514cd8840897c9a84312ce5c6da0186e9605ee06..66048ff751f0210418d411043d4a3f3b09326037 100644 (file)
@@ -2114,8 +2114,7 @@ static SkSize rect_to_size(const SkRect& r) {
     return SkSize::Make(r.width(), r.height());
 }
 
-static const SkImage* color_filter(const SkImage* image,
-                                   SkColorFilter* colorFilter) {
+static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFilter) {
     sk_sp<SkSurface> surface(SkSurface::NewRaster(
             SkImageInfo::MakeN32Premul(image->dimensions())));
     if (!surface) {
@@ -2124,7 +2123,7 @@ static const SkImage* color_filter(const SkImage* image,
     SkCanvas* canvas = surface->getCanvas();
     canvas->clear(SK_ColorTRANSPARENT);
     SkPaint paint;
-    paint.setColorFilter(colorFilter);
+    paint.setColorFilter(sk_ref_sp(colorFilter));
     canvas->drawImage(image, 0, 0, &paint);
     canvas->flush();
     return surface->makeImageSnapshot().release();
index 56e2b41a454e5f81b22c81be895e07155aa5f56a..d0b6a4b1ac27d3b665b512b873d4b26cbc4ff0eb 100644 (file)
@@ -1114,7 +1114,7 @@ static int lpaint_getColorFilter(lua_State* L) {
 
 static int lpaint_setColorFilter(lua_State* L) {
     SkPaint* paint = get_obj<SkPaint>(L, 1);
-    paint->setColorFilter(get_ref<SkColorFilter>(L, 2));
+    paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2)));
     return 0;
 }
 
index b7f78bac14c08cc8110b0ca2935156d77b7ca2a1..eebbda4869e4baa4ce5914f2798c3060548732f1 100644 (file)
@@ -49,7 +49,7 @@ bool SkRGBAToYUV(const SkImage* image, const SkISize sizes[3], void* const plane
         int rowStartIdx = 5 * i;
         const SkScalar* row = kYUVColorSpaceInvMatrices[colorSpace] + rowStartIdx;
         paint.setColorFilter(
-                SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(row))->unref();
+                SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(row));
         surface->getCanvas()->drawImageRect(image, SkIRect::MakeWH(image->width(), image->height()),
                                             SkRect::MakeIWH(surface->width(), surface->height()),
                                             &paint);
index ee8f12b2fbc9387658a719f0ffc6717d8a4cce0e..822fb0bd70f5a34eb8b3ca0516b79206269bf2de 100644 (file)
@@ -15,7 +15,7 @@
 #include "SkXfermode.h"
 #include "Test.h"
 
-static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
+static sk_sp<SkColorFilter> reincarnate_colorfilter(SkFlattenable* obj) {
     SkWriteBuffer wb;
     wb.writeFlattenable(obj);
 
@@ -30,18 +30,18 @@ static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static SkColorFilter* make_filter() {
+static sk_sp<SkColorFilter> make_filter() {
     // pick a filter that cannot compose with itself via newComposed()
-    return SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kColorBurn_Mode);
+    return SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kColorBurn_Mode);
 }
 
 static void test_composecolorfilter_limit(skiatest::Reporter* reporter) {
     // Test that CreateComposeFilter() has some finite limit (i.e. that the factory can return null)
     const int way_too_many = 100;
-    SkAutoTUnref<SkColorFilter> parent(make_filter());
+    auto parent(make_filter());
     for (int i = 2; i < way_too_many; ++i) {
-        SkAutoTUnref<SkColorFilter> filter(make_filter());
-        parent.reset(SkColorFilter::CreateComposeFilter(parent, filter));
+        auto filter(make_filter());
+        parent = SkColorFilter::MakeComposeFilter(parent, filter);
         if (nullptr == parent) {
             REPORTER_ASSERT(reporter, i > 2); // we need to have succeeded at least once!
             return;
@@ -62,15 +62,13 @@ DEF_TEST(ColorFilter, reporter) {
         // special case that would return nullptr (if color's alpha is 0 or 0xFF)
         color = SkColorSetA(color, 0x7F);
 
-        SkColorFilter* cf = SkColorFilter::CreateModeFilter(color,
-                                                        (SkXfermode::Mode)mode);
+        auto cf = SkColorFilter::MakeModeFilter(color, (SkXfermode::Mode)mode);
 
         // allow for no filter if we're in Dst mode (its a no op)
         if (SkXfermode::kDst_Mode == mode && nullptr == cf) {
             continue;
         }
 
-        SkAutoUnref aur(cf);
         REPORTER_ASSERT(reporter, cf);
 
         SkColor c = ~color;
@@ -98,8 +96,7 @@ DEF_TEST(ColorFilter, reporter) {
         REPORTER_ASSERT(reporter, m == expectedMode);
 
         {
-            SkColorFilter* cf2 = reincarnate_colorfilter(cf);
-            SkAutoUnref aur2(cf2);
+            auto cf2 = reincarnate_colorfilter(cf.get());
             REPORTER_ASSERT(reporter, cf2);
 
             SkColor c2 = ~color;
@@ -117,7 +114,7 @@ DEF_TEST(ColorFilter, reporter) {
 
 DEF_TEST(LumaColorFilter, reporter) {
     SkPMColor in, out;
-    SkAutoTUnref<SkColorFilter> lf(SkLumaColorFilter::Create());
+    auto lf(SkLumaColorFilter::Make());
 
     // Applying luma to white produces black with the same transparency.
     for (unsigned i = 0; i < 256; ++i) {
@@ -183,31 +180,31 @@ static void get_grayscale_matrix(float amount, float matrix[20]) {
     matrix[18] = 1.f;
 }
 
-static SkColorFilter* make_cf0() {
+static sk_sp<SkColorFilter> make_cf0() {
     SkScalar matrix[20];
     get_brightness_matrix(0.5f, matrix);
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
-static SkColorFilter* make_cf1() {
+static sk_sp<SkColorFilter> make_cf1() {
     SkScalar matrix[20];
     get_grayscale_matrix(1, matrix);
-    return SkColorMatrixFilter::Create(matrix);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
 }
-static SkColorFilter* make_cf2() {
+static sk_sp<SkColorFilter> make_cf2() {
     SkColorMatrix m0, m1;
     get_brightness_matrix(0.5f, m0.fMat);
     get_grayscale_matrix(1, m1.fMat);
     m0.preConcat(m1);
-    return SkColorMatrixFilter::Create(m0);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(m0.fMat);
 }
-static SkColorFilter* make_cf3() {
+static sk_sp<SkColorFilter> make_cf3() {
     SkColorMatrix m0, m1;
     get_brightness_matrix(0.5f, m0.fMat);
     get_grayscale_matrix(1, m1.fMat);
     m0.postConcat(m1);
-    return SkColorMatrixFilter::Create(m0);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(m0.fMat);
 }
-typedef SkColorFilter* (*CFProc)();
+typedef sk_sp<SkColorFilter> (*CFProc)();
 
 // Test that a colormatrix that "should" preserve opaquness actually does.
 DEF_TEST(ColorMatrixFilter, reporter) {
@@ -216,7 +213,7 @@ DEF_TEST(ColorMatrixFilter, reporter) {
     };
 
     for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
-        SkAutoTUnref<SkColorFilter> cf(procs[i]());
+        auto cf(procs[i]());
 
         // generate all possible r,g,b triples
         for (int r = 0; r < 256; ++r) {
index 1eea4f5a9de4c252a55a59f88f8bb3a773e369fc..7919b40242a1dd262e190c7999dcc92fc45f6eeb 100644 (file)
@@ -45,7 +45,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
             0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
             0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
             0.0f, 0.0f, 0.0f, 1.0f, 0.0f };
-    paint.setColorFilter(SkColorMatrixFilter::Create(blueToCyan))->unref();
+    paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(blueToCyan));
 
     paint.setColor(SK_ColorBLUE);
     canvas.drawPoint(0, 0, paint);
@@ -70,7 +70,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
             0.0f, 0.0f, 1.0f, 0.0f, 64.0f,
            -0.5f, 0.0f, 0.0f, 1.0f, 0.0f
     };
-    paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->unref();
+    paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
     bitmap.eraseColor(SK_ColorTRANSPARENT);
 
     paint.setColor(SK_ColorRED);
@@ -91,7 +91,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
     assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
 
     // create a new filter with the changed matrix
-    paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->unref();
+    paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
     canvas.drawPoint(0, 0, paint);
     assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0));
 }
index 830c7dfff3028f987dd8ea10e6ff0b4fed796579..714555a6260a890556d3844e50670b37bc8d13ad 100644 (file)
@@ -99,8 +99,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) {
     GrPaint paint;
     for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) {
         const GetConstantComponentTestCase& test = filterTests[i];
-        SkAutoTUnref<SkColorFilter> cf(
-            SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode));
+        auto cf(SkColorFilter::MakeModeFilter(test.filterColor, test.filterMode));
         SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(context));
         REPORTER_ASSERT(reporter, fp);
         GrInvariantOutput inout(test.inputColor,
index fd916cfeb3b9d494d7121cac63aad317ae31bb01..c2230b7cdb8733c9edae75a6cd983e8086a4abfa 100644 (file)
@@ -137,8 +137,8 @@ static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
                             0, s, 0, 0, 0,
                             0, 0, s, 0, 0,
                             0, 0, 0, s, 0 };
-    SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
-    return SkColorFilterImageFilter::Create(filter, input);
+    auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Create(filter.get(), input);
 }
 
 static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
@@ -148,14 +148,13 @@ static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::
     matrix[1] = matrix[6] = matrix[11] = 0.7152f;
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
-    SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
-    return SkColorFilterImageFilter::Create(filter, input, cropRect);
+    auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
 }
 
 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
-    SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorBLUE,
-                                                                       SkXfermode::kSrcIn_Mode));
-    return SkColorFilterImageFilter::Create(filter, input, cropRect);
+    auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+    return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
 }
 
 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
@@ -258,9 +257,9 @@ DEF_TEST(ImageFilter, reporter) {
         blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
         SkScalar redToGreenMatrix[20] = { 0 };
         redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
-        SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedMatrix));
+        auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
         SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blueToRed.get()));
-        SkAutoTUnref<SkColorFilter> redToGreen(SkColorMatrixFilter::Create(redToGreenMatrix));
+        auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
         SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get()));
 
         SkBitmap result;
@@ -320,7 +319,7 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
     SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
     SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
 
-    SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
+    auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
     SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
     SkScalar kernel[9] = {
         SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
@@ -564,7 +563,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
     // match the same filters drawn with a single full-canvas bitmap draw.
     // Tests pass by not asserting.
 
-    SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
+    auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
     SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
     SkScalar kernel[9] = {
         SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
@@ -693,7 +692,7 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
     SkMatrix matrix;
     matrix.setTranslate(SkIntToScalar(50), 0);
 
-    SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
+    auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
     SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
     SkAutoTUnref<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality, cfif.get()));
 
@@ -1122,14 +1121,13 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
     SkRTreeFactory factory;
     SkPictureRecorder recorder;
 
-    SkAutoTUnref<SkColorFilter> green(
-        SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
+    auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
     SkAutoTUnref<SkImageFilter> imageFilter(
         SkColorFilterImageFilter::Create(green.get()));
     SkPaint imageFilterPaint;
     imageFilterPaint.setImageFilter(imageFilter.get());
     SkPaint colorFilterPaint;
-    colorFilterPaint.setColorFilter(green.get());
+    colorFilterPaint.setColorFilter(green);
 
     SkRect bounds = SkRect::MakeWH(10, 10);
 
@@ -1245,8 +1243,7 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
     bitmap.allocN32Pixels(1, 1);
     bitmap.eraseARGB(255, 255, 255, 255);
 
-    SkAutoTUnref<SkColorFilter> green(
-        SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
+    auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
     SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get()));
     SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
     SkAutoTUnref<SkImageFilter> croppedOut(
@@ -1467,8 +1464,8 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
                                  0, 0, 0, 0, 1,
                                  0, 0, 0, 0, 0,
                                  0, 0, 0, 0, 1 };
-    SkAutoTUnref<SkColorFilter> greenCF(SkColorMatrixFilter::Create(greenMatrix));
-    SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF));
+    auto greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
+    SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get()));
 
     REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
     REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
@@ -1482,14 +1479,12 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
         allOne[i] = 255;
     }
 
-    SkAutoTUnref<SkColorFilter> identityCF(
-        SkTableColorFilter::CreateARGB(identity, identity, identity, allOne));
+    auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne));
     SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(identityCF.get()));
     REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
     REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
 
-    SkAutoTUnref<SkColorFilter> forceOpaqueCF(
-        SkTableColorFilter::CreateARGB(allOne, identity, identity, identity));
+    auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity));
     SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get()));
     REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
     REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
index a58bd864ece75c165d8fe0ff58b3cdcc08d14a68..0e92e65ba3ec500a16e4907cbfd2ccba88dad4cb 100644 (file)
@@ -360,11 +360,11 @@ DEF_TEST(Paint_nothingToDraw, r) {
 
     SkColorMatrix cm;
     cm.setIdentity();   // does not change alpha
-    paint.setColorFilter(SkColorMatrixFilter::Create(cm))->unref();
+    paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
     REPORTER_ASSERT(r, paint.nothingToDraw());
 
     cm.postTranslate(0, 0, 0, 1);    // wacks alpha
-    paint.setColorFilter(SkColorMatrixFilter::Create(cm))->unref();
+    paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
     REPORTER_ASSERT(r, !paint.nothingToDraw());
 }
 
index 58a08ecc348bf11dfaf9a2cd88c8d792fc5034b4..a57a1b2fb28b04e317e391ef219f3514ea2f5732 100644 (file)
@@ -278,7 +278,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
     // optimize away
     SkScalar blueToRedMatrix[20] = { 0 };
     blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
-    SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedMatrix));
+    auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
     SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRed.get()));
 
     SkPaint complexPaint;
index 597639e5432f2408f36d1ff521bb4d5e803e83ec..77eb76bc0288e6715ef754fa2a906a296962958b 100644 (file)
@@ -224,7 +224,7 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
     xfermodePaint.setXfermodeMode(SkXfermode::kDstIn_Mode);
     SkPaint colorFilterPaint;
     colorFilterPaint.setColorFilter(
-        SkColorFilter::CreateModeFilter(SK_ColorLTGRAY, SkXfermode::kSrcIn_Mode))->unref();
+        SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkXfermode::kSrcIn_Mode));
 
     SkPaint opaqueFilterLayerPaint;
     opaqueFilterLayerPaint.setColor(0xFF020202);  // Opaque.
index c58020724d2da9867884da1f0f0de800000f4ed5..f8d6ea4297da670f9116c14fc4a20c6d51af2107 100644 (file)
@@ -286,7 +286,7 @@ static void TestColorFilterSerialization(skiatest::Reporter* reporter) {
     for (int i = 0; i < 256; ++i) {
         table[i] = (i * 41) % 256;
     }
-    SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::Create(table));
+    auto colorFilter(SkTableColorFilter::Make(table));
     SkAutoTUnref<SkColorFilter> copy(
         TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, reporter));
 }
index 94e1b688165e67d3f6f6161d2ab945d6ee57c345..239004aacb35fed695eba2841f247a397244ea44 100644 (file)
@@ -78,24 +78,22 @@ DEF_TEST(Color4f_premul, reporter) {
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkColorFilter* make_mode_cf() {
-    return SkColorFilter::CreateModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
+static sk_sp<SkColorFilter> make_mode_cf() {
+    return SkColorFilter::MakeModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
 }
 
-static SkColorFilter* make_mx_cf() {
+static sk_sp<SkColorFilter> make_mx_cf() {
     const float mx[] = {
         0.5f, 0,    0, 0, 0.1f,
         0,    0.5f, 0, 0, 0.2f,
         0,    0,    1, 0, -0.1f,
         0,    0,    0, 1, 0,
     };
-    return SkColorMatrixFilter::Create(mx);
+    return SkColorFilter::MakeMatrixFilterRowMajor255(mx);
 }
 
-static SkColorFilter* make_compose_cf() {
-    SkAutoTUnref<SkColorFilter> cf0(make_mode_cf());
-    SkAutoTUnref<SkColorFilter> cf1(make_mx_cf());
-    return SkColorFilter::CreateComposeFilter(cf0, cf1);
+static sk_sp<SkColorFilter> make_compose_cf() {
+    return SkColorFilter::MakeComposeFilter(make_mode_cf(), make_mx_cf());
 }
 
 static sk_sp<SkShader> make_color_sh() { return SkShader::MakeColorShader(0xFFBB8855); }
@@ -124,8 +122,7 @@ static sk_sp<SkShader> make_grad_sh() {
 }
 
 static sk_sp<SkShader> make_cf_sh() {
-    SkAutoTUnref<SkColorFilter> filter(make_mx_cf());
-    return make_color_sh()->makeWithColorFilter(filter);
+    return make_color_sh()->makeWithColorFilter(make_mx_cf());
 }
 
 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int count,
@@ -178,9 +175,9 @@ DEF_TEST(Color4f_shader, reporter) {
 
 DEF_TEST(Color4f_colorfilter, reporter) {
     struct {
-        SkColorFilter* (*fFact)();
-        bool           fSupports4f;
-        const char*    fName;
+        sk_sp<SkColorFilter>    (*fFact)();
+        bool                    fSupports4f;
+        const char*             fName;
     } recs[] = {
         { make_mode_cf,     true, "mode" },
         { make_mx_cf,       true, "matrix" },
@@ -200,7 +197,7 @@ DEF_TEST(Color4f_colorfilter, reporter) {
     REPORTER_ASSERT(reporter, compare_spans(src4f, src4b, N));
 
     for (const auto& rec : recs) {
-        SkAutoTUnref<SkColorFilter> filter(rec.fFact());
+        auto filter(rec.fFact());
         SkPMColor dst4b[N];
         filter->filterSpan(src4b, N, dst4b);
         SkPM4f dst4f[N];
index 35b1581fdab2df6175120e9cc9991cab1f19336e..d7a76ca215f54889460b4a68edb29fc443752889 100644 (file)
@@ -69,7 +69,7 @@ void Filter(SkPaint* paint) {
         bool isMode = cf->asColorMode(&color, &mode);
         if (isMode && mode > SkXfermode::kLighten_Mode) {
             paint->setColorFilter(
-                SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode));
+                SkColorFilter::MakeModeFilter(color, SkXfermode::kSrcOver_Mode));
         } else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) {
             paint->setColorFilter(nullptr);
         }
index 5bacf02b1a2e0bfaf6f59923d14db80eee9cdbe8..5dc6079897c21bc6807c7181404650f1af72fb7b 100644 (file)
@@ -1159,11 +1159,10 @@ static void extract_json_paint_colorfilter(Json::Value& jsonPaint, UrlDataManage
                                            SkPaint* target) {
     if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER)) {
         Json::Value jsonColorFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER];
-        SkColorFilter* colorFilter = (SkColorFilter*) load_flattenable(jsonColorFilter, 
-                                                                       urlDataManager);
+        sk_sp<SkColorFilter> colorFilter((SkColorFilter*)load_flattenable(jsonColorFilter,
+                                                                          urlDataManager));
         if (colorFilter != nullptr) {
             target->setColorFilter(colorFilter);
-            colorFilter->unref();
         }
     }
 }