Add a GM to test the clipping of canvas layers.
R=tomhudson@google.com Review URL: https://codereview.chromium.org/22815012 git-svn-id: http://skia.googlecode.com/svn/trunk@10831 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
3055b70018
commit
9615fed005
@ -109,6 +109,74 @@ private:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CanvasLayerStateGM : public GM {
|
||||
public:
|
||||
CanvasLayerStateGM() {
|
||||
fRedPaint.setColor(SK_ColorRED);
|
||||
fRedPaint.setStyle(SkPaint::kFill_Style);
|
||||
|
||||
fBluePaint.setColor(SK_ColorBLUE);
|
||||
fBluePaint.setStyle(SkPaint::kFill_Style);
|
||||
|
||||
fRect = SkRect::MakeXYWH(SPACER, SPACER, WIDTH-(2*SPACER), (HEIGHT-(2*SPACER)) / 7);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() SK_OVERRIDE {
|
||||
return SkString("canvas-layer-state");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() SK_OVERRIDE {
|
||||
return SkISize::Make(WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
|
||||
// clear the canvas to red
|
||||
canvas->drawColor(SK_ColorRED);
|
||||
|
||||
// both rects should appear
|
||||
drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag);
|
||||
|
||||
canvas->translate(0, 2*(fRect.height() + 10));
|
||||
|
||||
// only the top rect should appear
|
||||
drawTestPattern(canvas, 255, SkCanvas::kARGB_ClipLayer_SaveFlag);
|
||||
|
||||
canvas->translate(0, 2*(fRect.height() + 10));
|
||||
|
||||
// only the bottom rect should appear
|
||||
drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag);
|
||||
}
|
||||
|
||||
virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; }
|
||||
|
||||
private:
|
||||
// draw a rect within the layer's bounds and again outside the layer's bounds
|
||||
void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags flags) {
|
||||
canvas->saveLayerAlpha(&fRect, layerAlpha, flags);
|
||||
canvas->drawRect(fRect, fBluePaint);
|
||||
canvas->translate(0, fRect.height() + 10);
|
||||
canvas->drawRect(fRect, fBluePaint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
enum {
|
||||
WIDTH = 400,
|
||||
HEIGHT = 400,
|
||||
SPACER = 10,
|
||||
};
|
||||
|
||||
SkPaint fRedPaint;
|
||||
SkPaint fBluePaint;
|
||||
SkRect fRect;
|
||||
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_GM( return SkNEW(CanvasStateGM); )
|
||||
DEF_GM( return SkNEW(CanvasLayerStateGM); )
|
||||
|
||||
} // end namespace
|
||||
|
Loading…
Reference in New Issue
Block a user