From c877ea265759f38929a03cd28fb3d6de033d5b39 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Wed, 6 Feb 2019 15:04:45 -0500 Subject: [PATCH] Hide setDrawLooper -- deprecate loopers Guarded with SK_SUPPORT_LEGACY_DRAWLOOPER Bug: skia:4783 Change-Id: I4a47513624bc5c09816f44e107917dc8028adb94 Reviewed-on: https://skia-review.googlesource.com/c/189871 Reviewed-by: Mike Reed Commit-Queue: Mike Reed Auto-Submit: Mike Reed --- bench/BlurRoundRectBench.cpp | 2 ++ bench/RectoriBench.cpp | 2 ++ gm/blurroundrect.cpp | 2 ++ gm/circles.cpp | 2 ++ gm/drawlooper.cpp | 2 ++ gm/megalooper.cpp | 4 ++++ gm/rects.cpp | 2 ++ gm/shadows.cpp | 2 ++ gm/textbloblooper.cpp | 2 ++ include/core/SkPaint.h | 2 ++ samplecode/SampleTiling.cpp | 4 ++++ samplecode/SampleUnpremul.cpp | 2 ++ src/core/SkCanvas.cpp | 2 ++ src/core/SkColorSpaceXformer.cpp | 2 ++ src/core/SkDrawLooper.cpp | 4 ++++ src/core/SkPaint.cpp | 17 +++++++++++++++++ tests/PaintTest.cpp | 4 ++++ tests/QuickRejectTest.cpp | 4 ++++ 18 files changed, 61 insertions(+) diff --git a/bench/BlurRoundRectBench.cpp b/bench/BlurRoundRectBench.cpp index 085a8eb0e6..5b7bcd8b1e 100644 --- a/bench/BlurRoundRectBench.cpp +++ b/bench/BlurRoundRectBench.cpp @@ -62,7 +62,9 @@ public: dullPaint.setAntiAlias(true); SkPaint loopedPaint; +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER loopedPaint.setLooper(looperBuilder.detach()); +#endif loopedPaint.setAntiAlias(true); loopedPaint.setColor(SK_ColorCYAN); diff --git a/bench/RectoriBench.cpp b/bench/RectoriBench.cpp index c0d21552f9..990a8a90ab 100644 --- a/bench/RectoriBench.cpp +++ b/bench/RectoriBench.cpp @@ -52,7 +52,9 @@ protected: SkScalar translate = 2.0f * size; SkPaint paint; +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(this->createLooper(-translate, blurSigma)); +#endif paint.setColor(0xff000000 | Random.nextU()); paint.setAntiAlias(true); diff --git a/gm/blurroundrect.cpp b/gm/blurroundrect.cpp index b7d0800a86..411663828e 100644 --- a/gm/blurroundrect.cpp +++ b/gm/blurroundrect.cpp @@ -69,7 +69,9 @@ public: SkPaint paint; canvas->drawRect(fRRect.rect(), paint); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(looperBuilder.detach()); +#endif paint.setColor(SK_ColorCYAN); paint.setAntiAlias(true); diff --git a/gm/circles.cpp b/gm/circles.cpp index 9127c0a8fe..0c874691ff 100644 --- a/gm/circles.cpp +++ b/gm/circles.cpp @@ -70,6 +70,7 @@ protected: fPaints.push_back(p); } +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER { // AA with blur SkPaint p; @@ -79,6 +80,7 @@ protected: SkIntToScalar(5), SkIntToScalar(10))); fPaints.push_back(p); } +#endif { // AA with stroke style diff --git a/gm/drawlooper.cpp b/gm/drawlooper.cpp index a9fe09f32e..017ec26b90 100644 --- a/gm/drawlooper.cpp +++ b/gm/drawlooper.cpp @@ -37,7 +37,9 @@ protected: SkPaint paint; paint.setAntiAlias(true); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(fLooper); +#endif SkFont font(sk_tool_utils::create_portable_typeface(), 72); diff --git a/gm/megalooper.cpp b/gm/megalooper.cpp index e2e53e75fa..16c07ae948 100644 --- a/gm/megalooper.cpp +++ b/gm/megalooper.cpp @@ -130,7 +130,9 @@ private: for (int i = 0; i < 4; ++i) { SkPaint loopPaint; +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i])); +#endif loopPaint.setAntiAlias(true); SkRect outerClip = { @@ -191,7 +193,9 @@ private: SkPaint paint; paint.setAntiAlias(true); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0)); +#endif canvas->save(); canvas->clipRect(outerClip, kIntersect_SkClipOp); diff --git a/gm/rects.cpp b/gm/rects.cpp index 2786be74ad..1da6878954 100644 --- a/gm/rects.cpp +++ b/gm/rects.cpp @@ -85,6 +85,7 @@ protected: fPaints.push_back(p); } +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER { // AA with blur SkPaint p; @@ -95,6 +96,7 @@ protected: SkIntToScalar(5), SkIntToScalar(10))); fPaints.push_back(p); } +#endif { // AA with stroke style diff --git a/gm/shadows.cpp b/gm/shadows.cpp index 1160e498f9..e0a2d0167d 100644 --- a/gm/shadows.cpp +++ b/gm/shadows.cpp @@ -88,7 +88,9 @@ protected: for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) { SkAutoCanvasRestore acr(canvas, true); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(shadowLoopers[i]); +#endif canvas->translate(SkIntToScalar((unsigned int)i*40), SkIntToScalar(0)); setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth); diff --git a/gm/textbloblooper.cpp b/gm/textbloblooper.cpp index 51e815524f..b2764fa708 100644 --- a/gm/textbloblooper.cpp +++ b/gm/textbloblooper.cpp @@ -230,7 +230,9 @@ protected: int y = 0; for (int looper = 0; looper < fLoopers.count(); looper++) { +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(fLoopers[looper]); +#endif canvas->save(); canvas->translate(0, SkIntToScalar(y)); canvas->drawTextBlob(fBlob, 0, 0, paint); diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 3d6a93890c..babed4ba2e 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -561,6 +561,7 @@ public: */ SkDrawLooper* getLooper() const { return fDrawLooper.get(); } +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on drawing unaltered. @@ -575,6 +576,7 @@ public: (see skbug.com/6259) */ void setLooper(sk_sp drawLooper); +#endif /** Returns true if SkPaint prevents all drawing; otherwise, the SkPaint may or may not allow drawing. diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp index 14e40c4529..21d3cb6208 100644 --- a/samplecode/SampleTiling.cpp +++ b/samplecode/SampleTiling.cpp @@ -107,7 +107,9 @@ protected: SkPaint p; SkString str; p.setDither(true); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER p.setLooper(fLooper); +#endif str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); SkTextUtils::DrawString(textCanvas, str.c_str(), x + r.width()/2, y, SkFont(), p, @@ -139,7 +141,9 @@ protected: } if (textCanvas) { SkPaint p; +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER p.setLooper(fLooper); +#endif textCanvas->drawString( SkStringPrintf("%s, %s", gConfigNames[i], gFilterNames[j]), x, y + r.height() * 2 / 3, SkFont(), p); diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp index da7e42dbbe..e2b34da5e4 100644 --- a/samplecode/SampleUnpremul.cpp +++ b/samplecode/SampleUnpremul.cpp @@ -81,7 +81,9 @@ protected: auto looper( SkBlurDrawLooper::Make(SK_ColorBLUE, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2)), 0, 0)); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(looper); +#endif SkScalar height = font.getMetrics(nullptr); if (!fDecodeSucceeded) { SkString failure; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index bf9b690854..12f0ea3c45 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -472,8 +472,10 @@ bool AutoDrawLooper::doNext() { SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? *fLazyPaintInit.get() : fOrigPaint); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER // never want our downstream clients (i.e. devices) to see loopers paint->setDrawLooper(nullptr); +#endif if (fTempLayerForImageFilter) { paint->setImageFilter(nullptr); diff --git a/src/core/SkColorSpaceXformer.cpp b/src/core/SkColorSpaceXformer.cpp index 09f399cfa5..d31b0c5e3a 100644 --- a/src/core/SkColorSpaceXformer.cpp +++ b/src/core/SkColorSpaceXformer.cpp @@ -169,9 +169,11 @@ SkPaint SkColorSpaceXformer::apply(const SkPaint& src) { dst.setColorFilter(this->apply(cf)); } +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER if (auto looper = src.getDrawLooper()) { dst.setDrawLooper(looper->makeColorSpace(this)); } +#endif if (auto imageFilter = src.getImageFilter()) { dst.setImageFilter(this->apply(imageFilter)); diff --git a/src/core/SkDrawLooper.cpp b/src/core/SkDrawLooper.cpp index db6bd5433a..8b1a3b59f5 100644 --- a/src/core/SkDrawLooper.cpp +++ b/src/core/SkDrawLooper.cpp @@ -20,7 +20,9 @@ bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const { for (;;) { SkPaint p(paint); if (context->next(&canvas, &p)) { +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER p.setLooper(nullptr); +#endif if (!p.canComputeFastBounds()) { return false; } @@ -47,7 +49,9 @@ void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& s, if (context->next(&canvas, &p)) { SkRect r(src); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER p.setLooper(nullptr); +#endif p.computeFastBounds(r, &r); canvas.getTotalMatrix().mapRect(&r); diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 150fcceefa..85dc6ca5fe 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -243,9 +243,14 @@ MOVE_FIELD(Shader) MOVE_FIELD(ColorFilter) MOVE_FIELD(PathEffect) MOVE_FIELD(MaskFilter) +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER MOVE_FIELD(DrawLooper) +#endif #undef MOVE_FIELD + +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER void SkPaint::setLooper(sk_sp looper) { fDrawLooper = std::move(looper); } +#endif /////////////////////////////////////////////////////////////////////////////// @@ -449,14 +454,20 @@ SkReadPaintResult SkPaintPriv::Unflatten_PreV68(SkPaint* paint, SkReadBuffer& bu paint->setMaskFilter(buffer.readMaskFilter()); paint->setColorFilter(buffer.readColorFilter()); (void)buffer.read32(); // use to be SkRasterizer +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint->setLooper(buffer.readDrawLooper()); +#else + (void)buffer.readDrawLooper(); +#endif paint->setImageFilter(buffer.readImageFilter()); } else { paint->setPathEffect(nullptr); paint->setShader(nullptr); paint->setMaskFilter(nullptr); paint->setColorFilter(nullptr); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint->setLooper(nullptr); +#endif paint->setImageFilter(nullptr); } @@ -489,14 +500,20 @@ SkReadPaintResult SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer, S paint->setShader(buffer.readShader()); paint->setMaskFilter(buffer.readMaskFilter()); paint->setColorFilter(buffer.readColorFilter()); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint->setLooper(buffer.readDrawLooper()); +#else + (void)buffer.readDrawLooper(); +#endif paint->setImageFilter(buffer.readImageFilter()); } else { paint->setPathEffect(nullptr); paint->setShader(nullptr); paint->setMaskFilter(nullptr); paint->setColorFilter(nullptr); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint->setLooper(nullptr); +#endif paint->setImageFilter(nullptr); } diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index 762cf1f7c2..20187ec91e 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -135,7 +135,9 @@ DEF_TEST(Paint_copy, reporter) { paint.setStrokeWidth(SkIntToScalar(2)); // set a few pointers SkLayerDrawLooper::Builder looperBuilder; +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(looperBuilder.detach()); +#endif paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(1))); @@ -263,7 +265,9 @@ DEF_TEST(Paint_MoreFlattening, r) { SkPaint paint; paint.setColor(0x00AABBCC); paint.setBlendMode(SkBlendMode::kModulate); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER paint.setLooper(nullptr); // Default value, ignored. +#endif SkBinaryWriteBuffer writer; SkPaintPriv::Flatten(paint, writer); diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp index 4bffe1356b..02752bf086 100644 --- a/tests/QuickRejectTest.cpp +++ b/tests/QuickRejectTest.cpp @@ -80,6 +80,7 @@ static void test_drawBitmap(skiatest::Reporter* reporter) { canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5)); +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER // now install our looper, which will draw, since it internally translates // 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 @@ -87,6 +88,7 @@ static void test_drawBitmap(skiatest::Reporter* reporter) { paint.setLooper(sk_make_sp()); canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint); REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5)); +#endif } static void test_layers(skiatest::Reporter* reporter) { @@ -171,6 +173,7 @@ DEF_TEST(QuickReject_MatrixState, reporter) { canvas.quickReject(SkRect::MakeWH(100.0f, 100.0f)); } +#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER #include "SkLayerDrawLooper.h" #include "SkSurface.h" DEF_TEST(looper_nothingtodraw, reporter) { @@ -196,3 +199,4 @@ DEF_TEST(looper_nothingtodraw, reporter) { // See https://skia-review.googlesource.com/c/skia/+/121220 surf->getCanvas()->drawRect({1, 1, 10, 10}, paint); } +#endif