From d196cbe9c270799a6edb6e110ab647c5a4a850a2 Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Thu, 23 Feb 2017 10:28:33 -0500 Subject: [PATCH] Do not throw away the savelayer if kDontClipToLayer_PrivateSaveLayerFlag is set This affects the Android CTS test android.uirendering.cts.testclasses.LayerTests#testSaveLayerUnclippedWithAlpha BUG=skia: Change-Id: Idae150e7e4f7ed9a1a225c382ba0b40d3f840937 Reviewed-on: https://skia-review.googlesource.com/8892 Reviewed-by: Mike Klein Commit-Queue: Yuqian Li --- gm/savelayer.cpp | 27 +++++++++++++++++++++++---- src/core/SkRecordOpts.cpp | 5 +++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gm/savelayer.cpp b/gm/savelayer.cpp index e35ccc9..510fc2f 100644 --- a/gm/savelayer.cpp +++ b/gm/savelayer.cpp @@ -7,14 +7,16 @@ #include "gm.h" + +static const uint32_t SkCanvas_kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31; + // This GM tests out the deprecated Android-specific unclipped saveLayer "feature". // In particular, it attempts to compare the performance of unclipped saveLayers with alternatives. static void save_layer_unclipped(SkCanvas* canvas, SkScalar l, SkScalar t, SkScalar r, SkScalar b) { - static const uint32_t kSecretDeprecated_DontClipToLayerFlag = 1U << 31; SkRect rect = SkRect::MakeLTRB(l, t, r, b); - canvas->saveLayer({ &rect, nullptr, nullptr, kSecretDeprecated_DontClipToLayerFlag }); + canvas->saveLayer({ &rect, nullptr, nullptr, SkCanvas_kDontClipToLayer_PrivateSaveLayerFlag }); } static void do_draw(SkCanvas* canvas) { @@ -67,7 +69,7 @@ protected: } else { SkASSERT(Mode::kUnclipped == fMode); canvas->saveLayer({ L, T, R, B }, nullptr); - } + } do_draw(canvas); } @@ -79,9 +81,26 @@ private: typedef skiagm::GM INHERITED; }; +DEF_SIMPLE_GM(picture_savelayer, canvas, 320, 640) { + SkPaint paint1, paint2, paint3; + paint1.setAlpha(0x7f); + paint2.setAlpha(0x3f); + paint3.setColor(0xFFFF0000); + SkRect rect1{40, 5, 80, 70}, rect2{5, 40, 70, 80}, rect3{10, 10, 70, 70}; + // In the future, we might also test the clipped case by allowing i = 0 + for(int i = 1; i < 2; ++i) { + canvas->translate(100 * i, 0); + auto flag = i ? SkCanvas_kDontClipToLayer_PrivateSaveLayerFlag : 0; + canvas->saveLayer({ &rect1, &paint1, nullptr, flag}); + canvas->saveLayer({ &rect2, &paint2, nullptr, flag}); + canvas->drawRect(rect3, paint3); + canvas->restore(); + canvas->restore(); + } +}; + ////////////////////////////////////////////////////////////////////////////// DEF_GM(return new UnclippedSaveLayerGM(UnclippedSaveLayerGM::Mode::kClipped);) DEF_GM(return new UnclippedSaveLayerGM(UnclippedSaveLayerGM::Mode::kUnclipped);) - diff --git a/src/core/SkRecordOpts.cpp b/src/core/SkRecordOpts.cpp index 605caa3..bd8364f 100644 --- a/src/core/SkRecordOpts.cpp +++ b/src/core/SkRecordOpts.cpp @@ -192,6 +192,11 @@ struct SaveLayerDrawRestoreNooper { return false; } + if (match->first()->saveLayerFlags & (1U << 31)) { + // can't throw away the layer if the kDontClipToLayer_PrivateSaveLayerFlag is set + return false; + } + // A SaveLayer's bounds field is just a hint, so we should be free to ignore it. SkPaint* layerPaint = match->first()->paint; SkPaint* drawPaint = match->second(); -- 2.7.4