guard rasterizer and drawlooper setters
authorreed <reed@google.com>
Mon, 21 Mar 2016 20:25:16 +0000 (13:25 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 21 Mar 2016 20:25:16 +0000 (13:25 -0700)
Need to land https://codereview.chromium.org/1823513002/ first

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1821533002

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

36 files changed:
bench/BlurRoundRectBench.cpp
bench/RectoriBench.cpp
gm/blurroundrect.cpp
gm/circles.cpp
gm/drawlooper.cpp
gm/megalooper.cpp
gm/rects.cpp
gm/shadows.cpp
gm/textbloblooper.cpp
gm/texteffects.cpp
gyp/skia_for_android_framework_defines.gypi
include/core/SkPaint.h
include/effects/SkBlurDrawLooper.h
include/effects/SkLayerDrawLooper.h
include/effects/SkLayerRasterizer.h
public.bzl
samplecode/ClockFaceView.cpp
samplecode/SampleAll.cpp
samplecode/SampleFilterFuzz.cpp
samplecode/SamplePathEffects.cpp
samplecode/SampleSlides.cpp
samplecode/SampleTextOnPath.cpp
samplecode/SampleTiling.cpp
samplecode/SampleUnpremul.cpp
src/core/SkPaint.cpp
src/core/SkReadBuffer.h
src/effects/SkBlurDrawLooper.cpp
src/effects/SkLayerDrawLooper.cpp
src/effects/SkLayerRasterizer.cpp
tests/BlurTest.cpp
tests/LayerDrawLooperTest.cpp
tests/LayerRasterizerTest.cpp
tests/PaintTest.cpp
tests/QuickRejectTest.cpp
tools/android/SkAndroidSDKCanvas.cpp
tools/debugger/SkDrawCommand.cpp

index 5213276..85852d5 100644 (file)
@@ -67,7 +67,7 @@ public:
         dullPaint.setAntiAlias(true);
 
         SkPaint loopedPaint;
-        loopedPaint.setLooper(looperBuilder.detachLooper())->unref();
+        loopedPaint.setLooper(looperBuilder.detach());
         loopedPaint.setAntiAlias(true);
         loopedPaint.setColor(SK_ColorCYAN);
 
index 1f4da86..e2a44e3 100644 (file)
@@ -52,7 +52,7 @@ protected:
             SkScalar translate = 2.0f * size;
 
             SkPaint paint;
-            paint.setLooper(this->createLooper(-translate, blurSigma))->unref();
+            paint.setLooper(this->createLooper(-translate, blurSigma));
             paint.setColor(0xff000000 | Random.nextU());
             paint.setAntiAlias(true);
 
@@ -71,7 +71,7 @@ private:
         H = 480,
     };
 
-    SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar sigma) {
+    sk_sp<SkDrawLooper> createLooper(SkScalar xOff, SkScalar sigma) {
         SkLayerDrawLooper::Builder looperBuilder;
 
         //-----------------------------------------------
@@ -96,7 +96,7 @@ private:
         info.fOffset.set(0, 0);
 
         paint = looperBuilder.addLayer(info);
-        return looperBuilder.detachLooper();
+        return looperBuilder.detach();
     }
 
     typedef Benchmark INHERITED;
index ef20e25..fe4a939 100644 (file)
@@ -73,7 +73,7 @@ public:
         SkPaint paint;
         canvas->drawRect(fRRect.rect(), paint);
 
-        paint.setLooper(looperBuilder.detachLooper())->unref();
+        paint.setLooper(looperBuilder.detach());
         paint.setColor(SK_ColorCYAN);
         paint.setAntiAlias(true);
 
index 4d3e33d..d9b25c0 100644 (file)
@@ -76,15 +76,12 @@ protected:
         // AA with blur
         SkPaint p;
         p.setAntiAlias(true);
-        SkDrawLooper* shadowLooper =
-            SkBlurDrawLooper::Create(SK_ColorBLUE,
+        p.setLooper(SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
                                      SkIntToScalar(5), SkIntToScalar(10),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
                                      SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag);
-        SkAutoUnref aurL0(shadowLooper);
-        p.setLooper(shadowLooper);
+                                     SkBlurDrawLooper::kHighQuality_BlurFlag));
         fPaints.push_back(p);
         }
 
index 9f922a5..7ee7747 100644 (file)
@@ -22,10 +22,6 @@ public:
         this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
     }
 
-    virtual ~DrawLooperGM() {
-        SkSafeUnref(fLooper);
-    }
-
 protected:
     virtual SkISize onISize() override {
         return SkISize::Make(520, 160);
@@ -55,7 +51,7 @@ protected:
     }
 
 private:
-    SkLayerDrawLooper*   fLooper;
+    sk_sp<SkDrawLooper> fLooper;
 
     void init() {
         if (fLooper) return;
@@ -91,7 +87,7 @@ private:
                 paint->setMaskFilter(mf)->unref();
             }
         }
-        fLooper = looperBuilder.detachLooper();
+        fLooper = looperBuilder.detach();
     }
 
     typedef GM INHERITED;
index ae92971..5fe9af2 100644 (file)
@@ -131,7 +131,7 @@ private:
         for (int i = 0; i < 4; ++i) {
             SkPaint loopPaint;
 
-            loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]))->unref();
+            loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]));
             loopPaint.setAntiAlias(true);
 
             SkRect outerClip = {
@@ -161,7 +161,7 @@ private:
     }
 
     // Create a 1-tier drawlooper
-    SkLayerDrawLooper* create1Looper(SkScalar xOff, SkScalar yOff, SkColor color) {
+    sk_sp<SkDrawLooper> create1Looper(SkScalar xOff, SkScalar yOff, SkColor color) {
         SkLayerDrawLooper::Builder looperBuilder;
         SkLayerDrawLooper::LayerInfo info;
 
@@ -178,7 +178,7 @@ private:
         SkColorFilter* cf = SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcIn_Mode);
         paint->setColorFilter(cf)->unref();
 
-        return looperBuilder.detachLooper();
+        return looperBuilder.detach();
     }
 
     void draw1x4(SkCanvas* canvas, SkScalar x, SkScalar y) {
@@ -193,7 +193,7 @@ private:
 
         SkPaint paint;
         paint.setAntiAlias(true);
-        paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0))->unref();
+        paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0));
 
         canvas->save();
             canvas->clipRect(outerClip, SkRegion::kIntersect_Op);
@@ -205,7 +205,7 @@ private:
     }
 
     // Create a 4-tier draw looper
-    SkLayerDrawLooper* create4Looper(SkScalar xOff, SkScalar yOff) {
+    sk_sp<SkDrawLooper> create4Looper(SkScalar xOff, SkScalar yOff) {
         SkLayerDrawLooper::Builder looperBuilder;
         SkLayerDrawLooper::LayerInfo info;
 
@@ -226,7 +226,7 @@ private:
             paint->setColorFilter(cf)->unref();
         }
 
-        return looperBuilder.detachLooper();
+        return looperBuilder.detach();
     }
 
     typedef GM INHERITED;
index 6f4c75e..51eeff0 100644 (file)
@@ -91,15 +91,12 @@ protected:
             SkPaint p;
             p.setColor(SK_ColorWHITE);
             p.setAntiAlias(true);
-            SkDrawLooper* shadowLooper =
-                SkBlurDrawLooper::Create(SK_ColorWHITE,
+            p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
                                          SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
                                          SkIntToScalar(5), SkIntToScalar(10),
                                          SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
                                          SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                         SkBlurDrawLooper::kHighQuality_BlurFlag);
-            SkAutoUnref aurL0(shadowLooper);
-            p.setLooper(shadowLooper);
+                                         SkBlurDrawLooper::kHighQuality_BlurFlag));
             fPaints.push_back(p);
         }
 
index 5696240..6263af2 100644 (file)
@@ -54,45 +54,36 @@ protected:
     }
 
     void onDraw(SkCanvas* canvas) override {
-        SkDrawLooper* shadowLoopers[5];
-        shadowLoopers[0] =
-            SkBlurDrawLooper::Create(SK_ColorBLUE,
+        sk_sp<SkDrawLooper> shadowLoopers[] = {
+              SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
                                      SkIntToScalar(5), SkIntToScalar(10),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
                                      SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag);
-        SkAutoUnref aurL0(shadowLoopers[0]);
-        shadowLoopers[1] =
-            SkBlurDrawLooper::Create(SK_ColorBLUE,
+                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+              SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
                                      SkIntToScalar(5), SkIntToScalar(10),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag);
-        SkAutoUnref aurL1(shadowLoopers[1]);
-        shadowLoopers[2] =
-            SkBlurDrawLooper::Create(SK_ColorBLACK,
+                                     SkBlurDrawLooper::kOverrideColor_BlurFlag),
+              SkBlurDrawLooper::Make(SK_ColorBLACK,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
                                      SkIntToScalar(5),
                                      SkIntToScalar(10),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag);
-        SkAutoUnref aurL2(shadowLoopers[2]);
-        shadowLoopers[3] =
-            SkBlurDrawLooper::Create(0x7FFF0000,
+                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+              SkBlurDrawLooper::Make(0x7FFF0000,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
                                      SkIntToScalar(-5), SkIntToScalar(-10),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
                                      SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag);
-        SkAutoUnref aurL3(shadowLoopers[3]);
-        shadowLoopers[4] =
-            SkBlurDrawLooper::Create(SK_ColorBLACK, SkIntToScalar(0),
+                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+            SkBlurDrawLooper::Make(SK_ColorBLACK, SkIntToScalar(0),
                                      SkIntToScalar(5), SkIntToScalar(5),
                                      SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
                                      SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag);
-        SkAutoUnref aurL4(shadowLoopers[4]);
+                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+        };
 
         static const struct {
             SkColor fColor;
index d544902..d970113 100644 (file)
@@ -107,10 +107,10 @@ static void kitchen_sink(SkPaint* paint) {
 
 }
 
-static SkLayerDrawLooper* setupLooper(SkLayerDrawLooper::BitFlags bits,
-                                      LooperProc proc,
-                                      const LooperSettings settings[],
-                                      size_t size) {
+static sk_sp<SkDrawLooper> setupLooper(SkLayerDrawLooper::BitFlags bits,
+                                       LooperProc proc,
+                                       const LooperSettings settings[],
+                                       size_t size) {
     SkLayerDrawLooper::Builder looperBuilder;
 
     SkLayerDrawLooper::LayerInfo info;
@@ -129,7 +129,7 @@ static SkLayerDrawLooper* setupLooper(SkLayerDrawLooper::BitFlags bits,
             (*proc)(paint);
         }
     }
-    return looperBuilder.detachLooper();
+    return looperBuilder.detach();
 }
 
 class TextBlobLooperGM : public GM {
@@ -186,33 +186,33 @@ protected:
             { SkXfermode::kSrcOver_Mode, 0x50FF00FF, SkPaint::kFill_Style, 0, 20.f, 0, false },
         };
 
-        fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
-                                               SkLayerDrawLooper::kXfermode_Bit |
-                                               SkLayerDrawLooper::kStyle_Bit, &mask_filter,
-                                               compound, SK_ARRAY_COUNT(compound)));
-        fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kPathEffect_Bit |
-                                               SkLayerDrawLooper::kXfermode_Bit, &path_effect,
-                                               looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
-        fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit |
-                                               SkLayerDrawLooper::kColorFilter_Bit |
-                                               SkLayerDrawLooper::kXfermode_Bit, &color_filter,
-                                               looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
-        fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit |
-                                               SkLayerDrawLooper::kColorFilter_Bit |
-                                               SkLayerDrawLooper::kXfermode_Bit, &color_filter,
-                                               xfermode, SK_ARRAY_COUNT(xfermode)));
-        fLoopers.push_back().reset(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(skew)));
-        fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
-                                               SkLayerDrawLooper::kShader_Bit |
-                                               SkLayerDrawLooper::kColorFilter_Bit |
-                                               SkLayerDrawLooper::kPathEffect_Bit |
-                                               SkLayerDrawLooper::kStyle_Bit |
-                                               SkLayerDrawLooper::kXfermode_Bit, &kitchen_sink,
-                                               kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
+        fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
+                                       SkLayerDrawLooper::kXfermode_Bit |
+                                       SkLayerDrawLooper::kStyle_Bit, &mask_filter,
+                                       compound, SK_ARRAY_COUNT(compound)));
+        fLoopers.push_back(setupLooper(SkLayerDrawLooper::kPathEffect_Bit |
+                                       SkLayerDrawLooper::kXfermode_Bit, &path_effect,
+                                       looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
+        fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
+                                       SkLayerDrawLooper::kColorFilter_Bit |
+                                       SkLayerDrawLooper::kXfermode_Bit, &color_filter,
+                                       looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
+        fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
+                                       SkLayerDrawLooper::kColorFilter_Bit |
+                                       SkLayerDrawLooper::kXfermode_Bit, &color_filter,
+                                       xfermode, SK_ARRAY_COUNT(xfermode)));
+        fLoopers.push_back(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(skew)));
+        fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
+                                       SkLayerDrawLooper::kShader_Bit |
+                                       SkLayerDrawLooper::kColorFilter_Bit |
+                                       SkLayerDrawLooper::kPathEffect_Bit |
+                                       SkLayerDrawLooper::kStyle_Bit |
+                                       SkLayerDrawLooper::kXfermode_Bit, &kitchen_sink,
+                                       kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
 
         // Test we respect overrides
-        fLoopers.push_back().reset(setupLooper(0, &kitchen_sink,
-                                               kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
+        fLoopers.push_back(setupLooper(0, &kitchen_sink,
+                                       kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
     }
 
     SkString onShortName() override {
@@ -247,7 +247,7 @@ protected:
 
 private:
     SkAutoTUnref<const SkTextBlob> fBlob;
-    SkTArray<SkAutoTUnref<SkLayerDrawLooper>, true> fLoopers;
+    SkTArray<sk_sp<SkDrawLooper>, true> fLoopers;
 
     typedef GM INHERITED;
 };
index aa3d375..5962cd7 100644 (file)
@@ -88,7 +88,7 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
     p.setAntiAlias(false);
     SkLayerRasterizer::Builder rastBuilder2;
     r5(&rastBuilder2, p);
-    p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+    p.setRasterizer(rastBuilder2.detach());
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rastBuilder->addLayer(p);
 }
@@ -153,14 +153,13 @@ static const raster_proc gRastProcs[] = {
 
 static void apply_shader(SkPaint* paint, int index) {
     raster_proc proc = gRastProcs[index];
-    if (proc)
-    {
+    if (proc) {
         SkPaint p;
         SkLayerRasterizer::Builder rastBuilder;
 
         p.setAntiAlias(true);
         proc(&rastBuilder, p);
-        paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+        paint->setRasterizer(rastBuilder.detach());
     }
 
 #if 0
index d6324bd..8660475 100644 (file)
@@ -17,6 +17,7 @@
       # Needed until we fix https://bug.skia.org/2440 .
       'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
       'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
+      'SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR',
       'SK_SUPPORT_LEGACY_GRADIENT_DITHERING',
       'SK_SUPPORT_LEGACY_DRAWFILTER',
       'SK_SUPPORT_LEGACY_CREATESHADER_PTR',
index 8266eaa..f5c3bc3 100644 (file)
@@ -627,7 +627,9 @@ public:
                           the paint.
         @return           rasterizer
     */
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
     SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
+#endif
     void setRasterizer(sk_sp<SkRasterizer>);
 
     SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
@@ -651,7 +653,9 @@ public:
      *  @param looper May be NULL. The new looper to be installed in the paint.
      *  @return looper
      */
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
     SkDrawLooper* setLooper(SkDrawLooper* looper);
+#endif
     void setLooper(sk_sp<SkDrawLooper>);
 
     enum Align {
index 930af15..0371700 100644 (file)
@@ -35,10 +35,16 @@ public:
         kAll_BlurFlag               = 0x07
     };
 
+    static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
+                                    uint32_t flags = kNone_BlurFlag) {
+        return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
+    }
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
     static SkDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
                                 uint32_t flags = kNone_BlurFlag) {
-        return new SkBlurDrawLooper(color, sigma, dx, dy, flags);
+        return Make(color, sigma, dx, dy, flags).release();
     }
+#endif
 
     virtual ~SkBlurDrawLooper();
 
index 76172df..6ddde88 100644 (file)
@@ -142,7 +142,12 @@ public:
           * Pass list of layers on to newly built looper and return it. This will
           * also reset the builder, so it can be used to build another looper.
           */
-        SkLayerDrawLooper* detachLooper();
+        sk_sp<SkDrawLooper> detach();
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
+        SkLayerDrawLooper* detachLooper() {
+            return (SkLayerDrawLooper*)this->detach().release();
+        }
+#endif
 
     private:
         Rec* fRecs;
index c6ac1de..9ddcd4e 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #ifndef SkLayerRasterizer_DEFINED
 #define SkLayerRasterizer_DEFINED
 
@@ -44,7 +42,7 @@ public:
           *
           *  The caller is responsible for calling unref() on the returned object, if non NULL.
           */
-        SkLayerRasterizer* detachRasterizer();
+        sk_sp<SkLayerRasterizer> detach();
 
         /**
           *  Create and return a new immutable SkLayerRasterizer that contains a shapshot of the
@@ -58,7 +56,16 @@ public:
           *
           *  The caller is responsible for calling unref() on the returned object, if non NULL.
           */
-        SkLayerRasterizer* snapshotRasterizer() const;
+        sk_sp<SkLayerRasterizer> snapshot() const;
+    
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
+        SkLayerRasterizer* detachRasterizer() {
+            return this->detach().release();
+        }
+        SkLayerRasterizer* snapshotRasterizer() const {
+            return this->snapshot().release();
+        }
+#endif
 
     private:
         SkDeque* fLayers;
index 5729be8..11a7ca3 100644 (file)
@@ -523,6 +523,7 @@ DEFINES_ALL = [
     # Chrome DEFINES.
     "SK_USE_FLOATBITS",
     "SK_USE_FREETYPE_EMBOLDEN",
+    "SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR",
     "SK_SUPPORT_LEGACY_PATHEFFECT_PTR",
     # Turn on a few Google3-specific build fixes.
     "GOOGLE3",
index f5b43fb..80debeb 100644 (file)
@@ -163,7 +163,7 @@ static void apply_shader(SkPaint* paint, float scale)
 
     p.setAntiAlias(true);
     r7(&rastBuilder, p, scale);
-    paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+    paint->setRasterizer(rastBuilder.detach());
 
     paint->setColor(SK_ColorBLUE);
 }
index 2bbe29f..b8b0ee6 100644 (file)
@@ -152,7 +152,7 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
     p.setAntiAlias(false);
     SkLayerRasterizer::Builder rastBuilder2;
     r5(&rastBuilder2, p);
-    p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+    p.setRasterizer(rastBuilder2.detach());
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rastBuilder->addLayer(p);
 }
@@ -246,7 +246,7 @@ static void apply_shader(SkPaint* paint, int index) {
 
         p.setAntiAlias(true);
         proc(&rastBuilder, p);
-        paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+        paint->setRasterizer(rastBuilder.detach());
     }
 
 #if 1
index fe2fb0b..dd0fa40 100644 (file)
@@ -536,8 +536,7 @@ static SkPaint make_paint() {
         paintForRasterizer = make_paint();
     }
     rasterizerBuilder.addLayer(paintForRasterizer);
-    SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer());
-    paint.setRasterizer(rasterizer);
+    paint.setRasterizer(rasterizerBuilder.detach());
     paint.setImageFilter(make_image_filter());
     SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
     paint.setTextAlign(make_paint_align());
index 10715f3..1f9915d 100644 (file)
@@ -152,7 +152,7 @@ protected:
         paint.setARGB(0xFF, 0, 0, 0);
         paint.setPathEffect(make_warp_pe(fPhase));
         TestRastBuilder testRastBuilder;
-        paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
+        paint.setRasterizer(testRastBuilder.detach());
         canvas->drawPath(fPath, paint);
     }
 
index ca0d9df..9b054ad 100644 (file)
@@ -544,7 +544,7 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
     p.setAntiAlias(false);
     SkLayerRasterizer::Builder rastBuilder2;
     r5(&rastBuilder2, p);
-    p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+    p.setRasterizer(rastBuilder2.detach());
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rastBuilder->addLayer(p);
 }
@@ -615,7 +615,7 @@ static void apply_shader(SkPaint* paint, int index) {
 
     p.setAntiAlias(true);
     proc(&rastBuilder, p);
-    paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+    paint->setRasterizer(rastBuilder.detach());
     paint->setColor(SK_ColorBLUE);
 }
 
index ea2ae81..7c71084 100644 (file)
@@ -35,10 +35,8 @@ static void textStrokePath(SkCanvas* canvas) {
 
     canvas->drawPath(path, paint);
 
-    paint.setLooper(SkBlurDrawLooper::Create(SK_ColorBLACK,
-                                             SkBlurMask::ConvertRadiusToSigma(0.002f),
-                                             0.0f,
-                                             0.0f))->unref();
+    paint.setLooper(SkBlurDrawLooper::Make(SK_ColorBLACK, SkBlurMask::ConvertRadiusToSigma(0.002f),
+                                           0.0f, 0.0f));
 
     const char* text = "DRAWING STROKED TEXT WITH A BLUR ON A PATH";
     size_t      len = strlen(text);
index 62f055f..dbc7d09 100644 (file)
@@ -55,12 +55,12 @@ static const int gHeight = 32;
 
 class TilingView : public SampleView {
     sk_sp<SkPicture>     fTextPicture;
-    SkAutoTUnref<SkDrawLooper>  fLooper;
+    sk_sp<SkDrawLooper>  fLooper;
 public:
     TilingView()
-            : fLooper(SkBlurDrawLooper::Create(0x88000000,
-                                               SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
-                                               SkIntToScalar(2), SkIntToScalar(2))) {
+        : fLooper(SkBlurDrawLooper::Make(0x88000000,
+                                         SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
+                                         SkIntToScalar(2), SkIntToScalar(2))) {
         for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
             makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight);
         }
index fb9735c..919fb64 100644 (file)
@@ -80,10 +80,9 @@ protected:
         SkPaint paint;
         paint.setAntiAlias(true);
         paint.setTextSize(SkIntToScalar(24));
-        SkAutoTUnref<SkDrawLooper> looper(
-            SkBlurDrawLooper::Create(SK_ColorBLUE,
-                                     SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2)),
-                                     0, 0));
+        auto looper(
+            SkBlurDrawLooper::Make(SK_ColorBLUE, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2)),
+                                   0, 0));
         paint.setLooper(looper);
         SkScalar height = paint.getFontMetrics(nullptr);
         if (!fDecodeSucceeded) {
index 331f779..5baabd3 100644 (file)
@@ -370,7 +370,9 @@ void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fLooper = std::move(looper
         return f;                                   \
     }
 SET_PTR(Typeface)
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
 SET_PTR(Rasterizer)
+#endif
 SET_PTR(ImageFilter)
 SET_PTR(Shader)
 SET_PTR(ColorFilter)
@@ -381,10 +383,12 @@ SET_PTR(PathEffect)
 SET_PTR(MaskFilter)
 #undef SET_PTR
 
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
     fLooper.reset(SkSafeRef(looper));
     return looper;
 }
+#endif
 
 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
     fXfermode.reset(SkXfermode::Create(mode));
@@ -1937,8 +1941,8 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
         SkSafeUnref(this->setXfermode(buffer.readXfermode()));
         SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
         SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
-        SkSafeUnref(this->setRasterizer(buffer.readRasterizer()));
-        SkSafeUnref(this->setLooper(buffer.readDrawLooper()));
+        this->setRasterizer(buffer.readRasterizer());
+        this->setLooper(buffer.readDrawLooper());
         SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
 
         if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version)) {
index c7ac848..575375e 100644 (file)
@@ -131,13 +131,17 @@ public:
         return (T*) this->readFlattenable(T::GetFlattenableType());
     }
     SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
-    SkDrawLooper*  readDrawLooper()  { return this->readFlattenable<SkDrawLooper>(); }
+    sk_sp<SkDrawLooper> readDrawLooper() {
+        return sk_sp<SkDrawLooper>(this->readFlattenable<SkDrawLooper>());
+    }
     SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilter>(); }
     SkMaskFilter*  readMaskFilter()  { return this->readFlattenable<SkMaskFilter>(); }
     sk_sp<SkPathEffect> readPathEffect()  {
         return sk_sp<SkPathEffect>(this->readFlattenable<SkPathEffect>());
     }
-    SkRasterizer*  readRasterizer()  { return this->readFlattenable<SkRasterizer>(); }
+    sk_sp<SkRasterizer> readRasterizer() {
+        return sk_sp<SkRasterizer>(this->readFlattenable<SkRasterizer>());
+    }
     sk_sp<SkShader> readShader()     { return sk_sp<SkShader>(this->readFlattenable<SkShader>()); }
     SkXfermode*    readXfermode()    { return this->readFlattenable<SkXfermode>(); }
 
index 9f10ff5..d8127eb 100644 (file)
@@ -68,7 +68,7 @@ SkFlattenable* SkBlurDrawLooper::CreateProc(SkReadBuffer& buffer) {
     const SkScalar dx = buffer.readScalar();
     const SkScalar dy = buffer.readScalar();
     const uint32_t flags = buffer.read32();
-    return Create(color, sigma, dx, dy, flags);
+    return Make(color, sigma, dx, dy, flags).release();
 }
 
 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
index 83f21e5..ae31482 100644 (file)
@@ -230,7 +230,7 @@ SkFlattenable* SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) {
         info.fPostTranslate = buffer.readBool();
         buffer.readPaint(builder.addLayerOnTop(info));
     }
-    return builder.detachLooper();
+    return builder.detach().release();
 }
 
 #ifndef SK_IGNORE_TO_STRING
@@ -344,7 +344,7 @@ SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) {
     return &rec->fPaint;
 }
 
-SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
+sk_sp<SkDrawLooper> SkLayerDrawLooper::Builder::detach() {
     SkLayerDrawLooper* looper = new SkLayerDrawLooper;
     looper->fCount = fCount;
     looper->fRecs = fRecs;
@@ -353,5 +353,5 @@ SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
     fRecs = nullptr;
     fTopRec = nullptr;
 
-    return looper;
+    return sk_sp<SkDrawLooper>(looper);
 }
index 6c08afc..351265c 100644 (file)
@@ -196,7 +196,7 @@ void SkLayerRasterizer::Builder::addLayer(const SkPaint& paint, SkScalar dx,
     rec->fOffset.set(dx, dy);
 }
 
-SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() {
+sk_sp<SkLayerRasterizer> SkLayerRasterizer::Builder::detach() {
     SkLayerRasterizer* rasterizer;
     if (0 == fLayers->count()) {
         rasterizer = nullptr;
@@ -205,10 +205,10 @@ SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() {
         rasterizer = new SkLayerRasterizer(fLayers);
     }
     fLayers = nullptr;
-    return rasterizer;
+    return sk_sp<SkLayerRasterizer>(rasterizer);
 }
 
-SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const {
+sk_sp<SkLayerRasterizer> SkLayerRasterizer::Builder::snapshot() const {
     if (0 == fLayers->count()) {
         return nullptr;
     }
@@ -224,6 +224,5 @@ SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const {
     }
     SkASSERT(fLayers->count() == count);
     SkASSERT(layers->count() == count);
-    SkLayerRasterizer* rasterizer = new SkLayerRasterizer(layers);
-    return rasterizer;
+    return sk_sp<SkLayerRasterizer>(new SkLayerRasterizer(layers));
 }
index 30f218a..39ef738 100644 (file)
@@ -418,12 +418,12 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
     const SkBlurQuality quality = blurMaskFilterFlags_as_quality(blurMaskFilterFlags);
     uint32_t flags = blurMaskFilterFlags_to_blurDrawLooperFlags(blurMaskFilterFlags);
 
-    SkAutoTUnref<SkDrawLooper> lp(SkBlurDrawLooper::Create(color, sigma, dx, dy, flags));
+    sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy, flags));
 
     const bool expectSuccess = sigma > 0 &&
                                0 == (flags & SkBlurDrawLooper::kIgnoreTransform_BlurFlag);
 
-    if (nullptr == lp.get()) {
+    if (nullptr == lp) {
         REPORTER_ASSERT(reporter, sigma <= 0);
     } else {
         SkDrawLooper::BlurShadowRec rec;
@@ -440,8 +440,8 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
     }
 }
 
-static void test_delete_looper(skiatest::Reporter* reporter, SkDrawLooper* lp, SkScalar sigma,
-                               SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) {
+static void test_looper(skiatest::Reporter* reporter, sk_sp<SkDrawLooper> lp, SkScalar sigma,
+                        SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) {
     SkDrawLooper::BlurShadowRec rec;
     bool success = lp->asABlurShadow(&rec);
     REPORTER_ASSERT(reporter, success == expectSuccess);
@@ -453,7 +453,6 @@ static void test_delete_looper(skiatest::Reporter* reporter, SkDrawLooper* lp, S
         REPORTER_ASSERT(reporter, rec.fStyle == style);
         REPORTER_ASSERT(reporter, rec.fQuality == quality);
     }
-    lp->unref();
 }
 
 static void make_noop_layer(SkLayerDrawLooper::Builder* builder) {
@@ -481,23 +480,23 @@ static void test_layerDrawLooper(skiatest::Reporter* reporter, SkMaskFilter* mf,
 
     // 1 layer is too few
     make_noop_layer(&builder);
-    test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+    test_looper(reporter, builder.detach(), sigma, style, quality, false);
 
     // 2 layers is good, but need blur
     make_noop_layer(&builder);
     make_noop_layer(&builder);
-    test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+    test_looper(reporter, builder.detach(), sigma, style, quality, false);
 
     // 2 layers is just right
     make_noop_layer(&builder);
     make_blur_layer(&builder, mf);
-    test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, expectSuccess);
+    test_looper(reporter, builder.detach(), sigma, style, quality, expectSuccess);
 
     // 3 layers is too many
     make_noop_layer(&builder);
     make_blur_layer(&builder, mf);
     make_noop_layer(&builder);
-    test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+    test_looper(reporter, builder.detach(), sigma, style, quality, false);
 }
 
 DEF_TEST(BlurAsABlur, reporter) {
index 391db7c..8ba290f 100644 (file)
@@ -58,7 +58,7 @@ static void test_frontToBack(skiatest::Reporter* reporter) {
     FakeDevice device;
     SkCanvas canvas(&device);
     SkPaint paint;
-    SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+    auto looper(looperBuilder.detach());
     SkSmallAllocator<1, 32> allocator;
     void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
     SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
@@ -98,7 +98,7 @@ static void test_backToFront(skiatest::Reporter* reporter) {
     FakeDevice device;
     SkCanvas canvas(&device);
     SkPaint paint;
-    SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+    auto looper(looperBuilder.detach());
     SkSmallAllocator<1, 32> allocator;
     void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
     SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
@@ -138,7 +138,7 @@ static void test_mixed(skiatest::Reporter* reporter) {
     FakeDevice device;
     SkCanvas canvas(&device);
     SkPaint paint;
-    SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+    sk_sp<SkDrawLooper> looper(looperBuilder.detach());
     SkSmallAllocator<1, 32> allocator;
     void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
     SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
index a81cca4..b71c305 100644 (file)
@@ -49,7 +49,7 @@ SkFlattenable* DummyRasterizer::CreateProc(SkReadBuffer&) { return new DummyRast
 DEF_TEST(LayerRasterizer_destructor, reporter) {
     {
         SkPaint paint;
-        paint.setRasterizer(new DummyRasterizer)->unref();
+        paint.setRasterizer(sk_make_sp<DummyRasterizer>());
         REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 1);
 
         SkLayerRasterizer::Builder builder;
@@ -81,7 +81,7 @@ static bool equals(const SkLayerRasterizer_Rec& rec1, const SkLayerRasterizer_Re
 
 DEF_TEST(LayerRasterizer_copy, reporter) {
     SkLayerRasterizer::Builder builder;
-    REPORTER_ASSERT(reporter, nullptr == builder.snapshotRasterizer());
+    REPORTER_ASSERT(reporter, nullptr == builder.snapshot());
     SkPaint paint;
     // Create a bunch of paints with different flags.
     for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) {
@@ -90,14 +90,14 @@ DEF_TEST(LayerRasterizer_copy, reporter) {
     }
 
     // Create a layer rasterizer with all the existing layers.
-    SkAutoTUnref<SkLayerRasterizer> firstCopy(builder.snapshotRasterizer());
+    sk_sp<SkLayerRasterizer> firstCopy(builder.snapshot());
 
     // Add one more layer.
     paint.setFlags(SkPaint::kAllFlags);
     builder.addLayer(paint);
 
-    SkAutoTUnref<SkLayerRasterizer> oneLarger(builder.snapshotRasterizer());
-    SkAutoTUnref<SkLayerRasterizer> detached(builder.detachRasterizer());
+    sk_sp<SkLayerRasterizer> oneLarger(builder.snapshot());
+    sk_sp<SkLayerRasterizer> detached(builder.detach());
 
     // Check the counts for consistency.
     const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get());
@@ -140,5 +140,5 @@ DEF_TEST(LayerRasterizer_copy, reporter) {
 
 DEF_TEST(LayerRasterizer_detachEmpty, reporter) {
     SkLayerRasterizer::Builder builder;
-    REPORTER_ASSERT(reporter, nullptr == builder.detachRasterizer());
+    REPORTER_ASSERT(reporter, nullptr == builder.detach());
 }
index 7affa9e..a58bd86 100644 (file)
@@ -146,8 +146,7 @@ DEF_TEST(Paint_copy, reporter) {
     paint.setStrokeWidth(SkIntToScalar(2));
     // set a few pointers
     SkLayerDrawLooper::Builder looperBuilder;
-    SkLayerDrawLooper* looper = looperBuilder.detachLooper();
-    paint.setLooper(looper)->unref();
+    paint.setLooper(looperBuilder.detach());
     SkMaskFilter* mask = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
                                       SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)));
     paint.setMaskFilter(mask)->unref();
index 7eb80f1..582789a 100644 (file)
@@ -82,7 +82,7 @@ static void test_drawBitmap(skiatest::Reporter* reporter) {
     // to the left. The test is to ensure that canvas' quickReject machinary
     // allows us through, even though sans-looper we would look like we should
     // be clipped out.
-    paint.setLooper(new TestLooper)->unref();
+    paint.setLooper(sk_make_sp<TestLooper>());
     canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
     REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
 }
index 1deb97c..35b1581 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkAndroidSDKCanvas.h"
 
 #include "SkColorFilter.h"
+#include "SkDrawLooper.h"
 #include "SkPaint.h"
 #include "SkPathEffect.h"
 #include "SkShader.h"
index 5941a5d..5bacf02 100644 (file)
@@ -1184,10 +1184,9 @@ static void extract_json_paint_looper(Json::Value& jsonPaint, UrlDataManager& ur
                                       SkPaint* target) {
     if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LOOPER)) {
         Json::Value jsonLooper = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LOOPER];
-        SkDrawLooper* looper = (SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager);
+        sk_sp<SkDrawLooper> looper((SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager));
         if (looper != nullptr) {
-            target->setLooper(looper);
-            looper->unref();
+            target->setLooper(std::move(looper));
         }
     }
 }