From b93ba45b58ad24e0e2cb75b842e24ff711c368b0 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 10 Mar 2014 19:47:58 +0000 Subject: [PATCH] flag to make kClipToLayer_SaveFlag the default behavior #define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG to get the old behavior The goal is to remove the feature of saveLayer that allows the canvas to draw outside of the top-most layer. R=robertphillips@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/190723004 git-svn-id: http://skia.googlecode.com/svn/trunk@13730 2bbb7eff-a529-9590-31e7-b0007b416f81 --- expectations/gm/ignored-tests.txt | 6 ++++++ gm/canvasstate.cpp | 2 ++ include/core/SkCanvas.h | 12 +++++++++++- src/core/SkCanvas.cpp | 8 ++++++++ tests/CanvasStateTest.cpp | 7 ++++++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index 7abbf10..31f90fc 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -46,3 +46,9 @@ rrect_effect bezier_quad_effects bezier_conic_effects bezier_cubic_effects + +# reed: https://codereview.chromium.org/190723004/ +# This change removes an API that this GM was testing. If/when it lands and sticks, +# I will likely just delete the GM. +canvas-layer-state + diff --git a/gm/canvasstate.cpp b/gm/canvasstate.cpp index f2761da..b61ee72 100644 --- a/gm/canvasstate.cpp +++ b/gm/canvasstate.cpp @@ -132,6 +132,7 @@ protected: // clear the canvas to red canvas->drawColor(SK_ColorRED); +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG // both rects should appear drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag); @@ -144,6 +145,7 @@ protected: // only the bottom rect should appear drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag); +#endif } virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; } diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 093185c..773df89 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -18,6 +18,10 @@ #include "SkRegion.h" #include "SkXfermode.h" +// if not defined, we always assume ClipToLayer for saveLayer() +//#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG + + //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG //#define SK_SUPPORT_LEGACY_GETCLIPTYPE //#define SK_SUPPORT_LEGACY_GETTOTALCLIP @@ -325,12 +329,18 @@ public: kHasAlphaLayer_SaveFlag = 0x04, /** the layer needs to support 8-bits per color component */ kFullColorLayer_SaveFlag = 0x08, - /** the layer should clip against the bounds argument */ + /** + * the layer should clip against the bounds argument + * + * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on. + */ kClipToLayer_SaveFlag = 0x10, // helper masks for common choices kMatrixClip_SaveFlag = 0x03, +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG kARGB_NoClipLayer_SaveFlag = 0x0F, +#endif kARGB_ClipLayer_SaveFlag = 0x1F }; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 9dcbfdb..0888a01 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -812,7 +812,11 @@ int SkCanvas::save(SaveFlags flags) { } static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; +#else + return true; +#endif } bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, @@ -872,6 +876,10 @@ static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags, bool justForImageFilter) { +#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG + flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); +#endif + // do this before we create the layer. We don't call the public save() since // that would invoke a possibly overridden virtual int count = this->internalSave(flags); diff --git a/tests/CanvasStateTest.cpp b/tests/CanvasStateTest.cpp index 3c7552f..212b14a 100644 --- a/tests/CanvasStateTest.cpp +++ b/tests/CanvasStateTest.cpp @@ -16,6 +16,7 @@ #include "Test.h" static void test_complex_layers(skiatest::Reporter* reporter) { +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG const int WIDTH = 400; const int HEIGHT = 400; const int SPACER = 10; @@ -87,12 +88,13 @@ static void test_complex_layers(skiatest::Reporter* reporter) { bitmaps[1].getPixels(), bitmaps[0].getSize())); } +#endif } //////////////////////////////////////////////////////////////////////////////// static void test_complex_clips(skiatest::Reporter* reporter) { - +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG const int WIDTH = 400; const int HEIGHT = 400; const int SPACER = 10; @@ -175,6 +177,7 @@ static void test_complex_clips(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), bitmaps[1].getPixels(), bitmaps[0].getSize())); +#endif } //////////////////////////////////////////////////////////////////////////////// @@ -229,6 +232,7 @@ static void test_soft_clips(skiatest::Reporter* reporter) { } static void test_saveLayer_clip(skiatest::Reporter* reporter) { +#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG const int WIDTH = 100; const int HEIGHT = 100; const int LAYER_WIDTH = 50; @@ -259,6 +263,7 @@ static void test_saveLayer_clip(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); canvas.restore(); +#endif } DEF_TEST(CanvasState, reporter) { -- 2.7.4