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
This commit is contained in:
reed@google.com 2014-03-10 19:47:58 +00:00
Родитель bf99824083
Коммит b93ba45b58
5 изменённых файлов: 33 добавлений и 2 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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