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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 canvas->drawRect(fFillRect, fFillPaint); 102 canvas->drawRect(fFillRect, fFillPaint);
103 103
104 canvas->restore(); 104 canvas->restore();
105 } 105 }
106 106
107 typedef GM INHERITED; 107 typedef GM INHERITED;
108 }; 108 };
109 109
110 ////////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////////
111 111
112 class CanvasLayerStateGM : public GM {
113 public:
114 CanvasLayerStateGM() {
115 fRedPaint.setColor(SK_ColorRED);
116 fRedPaint.setStyle(SkPaint::kFill_Style);
117
118 fBluePaint.setColor(SK_ColorBLUE);
119 fBluePaint.setStyle(SkPaint::kFill_Style);
120
121 fRect = SkRect::MakeXYWH(SPACER, SPACER, WIDTH-(2*SPACER), (HEIGHT-(2*SP ACER)) / 7);
122 }
123
124 protected:
125 virtual SkString onShortName() SK_OVERRIDE {
126 return SkString("canvas-layer-state");
127 }
128
129 virtual SkISize onISize() SK_OVERRIDE {
130 return SkISize::Make(WIDTH, HEIGHT);
131 }
132
133 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
134
135 // clear the canvas to red
136 canvas->drawColor(SK_ColorRED);
137
138 // both rects should appear
139 drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag);
140
141 canvas->translate(0, 2*(fRect.height() + 10));
142
143 // only the top rect should appear
144 drawTestPattern(canvas, 255, SkCanvas::kARGB_ClipLayer_SaveFlag);
145
146 canvas->translate(0, 2*(fRect.height() + 10));
147
148 // only the bottom rect should appear
149 drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag);
150 }
151
152 private:
153 // draw a rect within the layer's bounds and again outside the layer's bound s
154 void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags flags) {
155 canvas->saveLayerAlpha(&fRect, layerAlpha, flags);
156 canvas->drawRect(fRect, fBluePaint);
157 canvas->translate(0, fRect.height() + 10);
158 canvas->drawRect(fRect, fBluePaint);
159 canvas->restore();
160 }
161
162 enum {
163 WIDTH = 400,
164 HEIGHT = 400,
165 SPACER = 10,
166 };
167
168 SkPaint fRedPaint;
169 SkPaint fBluePaint;
170 SkRect fRect;
171
172 typedef GM INHERITED;
173 };
174
175 //////////////////////////////////////////////////////////////////////////////
176
112 DEF_GM( return SkNEW(CanvasStateGM); ) 177 DEF_GM( return SkNEW(CanvasStateGM); )
178 DEF_GM( return SkNEW(CanvasLayerStateGM); )
113 179
114 } // end namespace 180 } // end namespace
OLDNEW
« 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