guard rasterizer and drawlooper setters
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
diff --git a/gm/blurroundrect.cpp b/gm/blurroundrect.cpp
index ef20e25..fe4a939 100644
--- a/gm/blurroundrect.cpp
+++ b/gm/blurroundrect.cpp
@@ -73,7 +73,7 @@
SkPaint paint;
canvas->drawRect(fRRect.rect(), paint);
- paint.setLooper(looperBuilder.detachLooper())->unref();
+ paint.setLooper(looperBuilder.detach());
paint.setColor(SK_ColorCYAN);
paint.setAntiAlias(true);
diff --git a/gm/circles.cpp b/gm/circles.cpp
index 4d3e33d..d9b25c0 100644
--- a/gm/circles.cpp
+++ b/gm/circles.cpp
@@ -76,15 +76,12 @@
// 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);
}
diff --git a/gm/drawlooper.cpp b/gm/drawlooper.cpp
index 9f922a5..7ee7747 100644
--- a/gm/drawlooper.cpp
+++ b/gm/drawlooper.cpp
@@ -22,10 +22,6 @@
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 @@
}
private:
- SkLayerDrawLooper* fLooper;
+ sk_sp<SkDrawLooper> fLooper;
void init() {
if (fLooper) return;
@@ -91,7 +87,7 @@
paint->setMaskFilter(mf)->unref();
}
}
- fLooper = looperBuilder.detachLooper();
+ fLooper = looperBuilder.detach();
}
typedef GM INHERITED;
diff --git a/gm/megalooper.cpp b/gm/megalooper.cpp
index ae92971..5fe9af2 100644
--- a/gm/megalooper.cpp
+++ b/gm/megalooper.cpp
@@ -131,7 +131,7 @@
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 @@
}
// 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 @@
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 @@
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 @@
}
// 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 @@
paint->setColorFilter(cf)->unref();
}
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
typedef GM INHERITED;
diff --git a/gm/rects.cpp b/gm/rects.cpp
index 6f4c75e..51eeff0 100644
--- a/gm/rects.cpp
+++ b/gm/rects.cpp
@@ -91,15 +91,12 @@
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);
}
diff --git a/gm/shadows.cpp b/gm/shadows.cpp
index 5696240..6263af2 100644
--- a/gm/shadows.cpp
+++ b/gm/shadows.cpp
@@ -54,45 +54,36 @@
}
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;
diff --git a/gm/textbloblooper.cpp b/gm/textbloblooper.cpp
index d544902..d970113 100644
--- a/gm/textbloblooper.cpp
+++ b/gm/textbloblooper.cpp
@@ -107,10 +107,10 @@
}
-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 @@
(*proc)(paint);
}
}
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
class TextBlobLooperGM : public GM {
@@ -186,33 +186,33 @@
{ 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 @@
private:
SkAutoTUnref<const SkTextBlob> fBlob;
- SkTArray<SkAutoTUnref<SkLayerDrawLooper>, true> fLoopers;
+ SkTArray<sk_sp<SkDrawLooper>, true> fLoopers;
typedef GM INHERITED;
};
diff --git a/gm/texteffects.cpp b/gm/texteffects.cpp
index aa3d375..5962cd7 100644
--- a/gm/texteffects.cpp
+++ b/gm/texteffects.cpp
@@ -88,7 +88,7 @@
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 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