test dont-clip-layer

depends on fix from https://codereview.chromium.org/2309623002/

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2296703003

Review-Url: https://codereview.chromium.org/2296703003
This commit is contained in:
reed 2016-09-06 09:06:18 -07:00 committed by Commit bot
parent ef7cee4bbc
commit 02f9ed74ea
2 changed files with 65 additions and 8 deletions

View File

@ -9,6 +9,47 @@
#include "SkCanvas.h"
#include "SkPath.h"
static void do_draw(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
paint.setColor(0x800000FF);
canvas->drawRect(r, paint);
}
/**
* Exercise kDontClipToLayer_Legacy_SaveLayerFlag flag, which does not limit the clip to the
* layer's bounds. Thus when a draw occurs, it can (depending on "where" it is) draw into the layer
* and/or draw onto the surrounding portions of the canvas, or both.
*
* This GM has a 100x100 rectangle (r), which its going to draw. However first it creates a layer
* with this flag covering 1/2 of the rectangle (upper half). Then it draws the rect in SRC mode.
*
* The portion of the draw that intersects the layer should see the SRC draw, apply it to the layer
* and then during restore, it will SRC_OVER that layer onto the canvas (SRC_OVER since the layer
* has no paint, so it gets the default xfermode during restore).
*
* The portion of the draw below the layer draws directly into the canvas. Since it is in SRC mode,
* it will wrote 0x80 to the canvas' alpha, making it appear darker when shown in the window.
* The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas, so
* they will appear lighter (since the canvas was erased to white initially).
*
* Thus the expected result is the upper half to be light-blue w/ 0xFF for its alpha, and
* the lower half to be darker blue with 0x80 for its alpha.
*/
DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) {
SkRect r { 10, 10, 110, 110 };
SkRect r0 = SkRect::MakeXYWH(r.left(), r.top(), r.width(), r.height()/2);
SkCanvas::SaveLayerRec rec;
rec.fPaint = nullptr;
rec.fBounds = &r0;
rec.fBackdrop = nullptr;
rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
canvas->saveLayer(rec);
do_draw(canvas, r);
canvas->restore();
}
/** Draw a 2px border around the target, then red behind the target;
set the clip to match the target, then draw >> the target in blue.
*/

View File

@ -314,6 +314,11 @@ public:
}
};
static SkIRect compute_device_bounds(SkBaseDevice* device) {
return SkIRect::MakeXYWH(device->getOrigin().x(), device->getOrigin().y(),
device->width(), device->height());
}
class SkDrawIter : public SkDraw {
public:
SkDrawIter(SkCanvas* canvas) {
@ -322,9 +327,27 @@ public:
fClipStack = canvas->fClipStack;
fCurrLayer = canvas->fMCRec->fTopLayer;
fMultiDeviceCS = nullptr;
if (fCurrLayer->fNext) {
fMultiDeviceCS = canvas->fClipStack;
fMultiDeviceCS->save();
}
}
~SkDrawIter() {
if (fMultiDeviceCS) {
fMultiDeviceCS->restore();
}
}
bool next() {
if (fMultiDeviceCS && fDevice) {
// remove the previous device's bounds
fMultiDeviceCS->clipDevRect(compute_device_bounds(fDevice),
SkRegion::kDifference_Op);
}
// skip over recs with empty clips
while (fCurrLayer && fCurrLayer->fClip.isEmpty()) {
fCurrLayer = fCurrLayer->fNext;
@ -360,6 +383,7 @@ public:
private:
const DeviceCM* fCurrLayer;
const SkPaint* fPaint; // May be null.
SkClipStack* fMultiDeviceCS;
typedef SkDraw INHERITED;
};
@ -1047,11 +1071,7 @@ void SkCanvas::internalSave() {
}
bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) {
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag);
#else
return true;
#endif
}
bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlags,
@ -1168,10 +1188,6 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
const SkPaint* paint = rec.fPaint;
SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags;
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag;
#endif
SkLazyPaint lazyP;
SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL;
SkMatrix stashedMatrix = fMCRec->fMatrix;