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 <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-02-06 15:04:45 -05:00 committed by Skia Commit-Bot
parent c19d81acc0
commit c877ea2657
18 changed files with 61 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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<SkDrawLooper> drawLooper);
#endif
/** Returns true if SkPaint prevents all drawing;
otherwise, the SkPaint may or may not allow drawing.

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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));

View File

@ -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);

View File

@ -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<SkDrawLooper> 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);
}

View File

@ -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);

View File

@ -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<TestLooper>());
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