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

Side by Side Diff: gm/canvasstate.cpp

Issue 23545017: Create a semi-stable API for capturing the state of an SkCanvas and reconstructing that state acros… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | gyp/utils.gyp » ('j') | include/utils/SkCanvasUtils.h » ('J')
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"
11 #include "SkPath.h" 11 #include "SkPath.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 13
14 #include "SkCanvasUtils.h"
djsollen 2013/08/28 15:45:12 need to move this inline with other includes.
15
14 namespace skiagm { 16 namespace skiagm {
15 17
16 /* 18 /*
17 * This GM exercises the flags to SkCanvas::save(). The canvas' save() and 19 * This GM exercises the flags to SkCanvas::save(). The canvas' save() and
18 * restore actions can be limited to only a portion of the canvas' state through 20 * restore actions can be limited to only a portion of the canvas' state through
19 * the use of flags when calling save. 21 * the use of flags when calling save.
20 */ 22 */
21 class CanvasStateGM : public GM { 23 class CanvasStateGM : public GM {
22 SkSize fSize; 24 SkSize fSize;
23 enum { 25 enum {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // only the bottom rect should appear 150 // only the bottom rect should appear
149 drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag); 151 drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag);
150 } 152 }
151 153
152 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; } 154 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; }
153 155
154 private: 156 private:
155 // draw a rect within the layer's bounds and again outside the layer's bound s 157 // draw a rect within the layer's bounds and again outside the layer's bound s
156 void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags flags) { 158 void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags flags) {
157 canvas->saveLayerAlpha(&fRect, layerAlpha, flags); 159 canvas->saveLayerAlpha(&fRect, layerAlpha, flags);
158 canvas->drawRect(fRect, fBluePaint); 160
159 canvas->translate(0, fRect.height() + 10); 161 SkCanvas* newCanvas = canvas;
djsollen 2013/08/28 15:45:12 need to add comment as to why we do this here.
mtklein 2013/08/28 18:20:46 Yeah, I'm confused. :) The name newCanvas makes m
160 canvas->drawRect(fRect, fBluePaint); 162 SkCanvasState* state = SkCanvasUtils::CaptureCanvasState(canvas);
163 if (state) {
164 newCanvas = SkCanvasUtils::CreateFromCanvasState(state);
165 SkCanvasUtils::ReleaseCanvasState(state);
166 }
167
168 newCanvas->drawRect(fRect, fBluePaint);
scroggo 2013/08/28 17:22:01 I know this is just a test, so if it is testing wh
djsollen 2013/08/29 15:09:19 This was really just jammed in here and I'm convin
169 newCanvas->translate(0, fRect.height() + 10);
170 newCanvas->drawRect(fRect, fBluePaint);
171
161 canvas->restore(); 172 canvas->restore();
162 } 173 }
163 174
164 enum { 175 enum {
165 WIDTH = 400, 176 WIDTH = 400,
166 HEIGHT = 400, 177 HEIGHT = 400,
167 SPACER = 10, 178 SPACER = 10,
168 }; 179 };
169 180
170 SkPaint fRedPaint; 181 SkPaint fRedPaint;
171 SkPaint fBluePaint; 182 SkPaint fBluePaint;
172 SkRect fRect; 183 SkRect fRect;
173 184
174 typedef GM INHERITED; 185 typedef GM INHERITED;
175 }; 186 };
176 187
177 ////////////////////////////////////////////////////////////////////////////// 188 //////////////////////////////////////////////////////////////////////////////
178 189
179 DEF_GM( return SkNEW(CanvasStateGM); ) 190 DEF_GM( return SkNEW(CanvasStateGM); )
180 DEF_GM( return SkNEW(CanvasLayerStateGM); ) 191 DEF_GM( return SkNEW(CanvasLayerStateGM); )
181 192
182 } // end namespace 193 } // end namespace
OLDNEW
« no previous file with comments | « no previous file | gyp/utils.gyp » ('j') | include/utils/SkCanvasUtils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698