Index: gm/canvasstate.cpp |
diff --git a/gm/canvasstate.cpp b/gm/canvasstate.cpp |
index 1da8a140396bafbeabd48a3ecec214cadcbb21c9..f9dd8396a4a0a885df87798e0ec7a4f4369e8a12 100644 |
--- a/gm/canvasstate.cpp |
+++ b/gm/canvasstate.cpp |
@@ -109,6 +109,72 @@ 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); |
+ } |
+ |
+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 |