Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: gm/canvasstate.cpp

Issue 22815012: Add a GM to test the clipping of canvas layers. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698