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

Side by Side Diff: gm/optimizations.cpp

Issue 79173002: Remove unnamed namespace usage from 'gm'. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | « gm/imagefiltersgraph.cpp ('k') | 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 "SkDebugCanvas.h" 9 #include "SkDebugCanvas.h"
10 #include "SkPictureFlat.h" 10 #include "SkPictureFlat.h"
11 11
12 #define WARN(msg) \ 12 #define WARN(msg) \
13 SkDebugf("%s:%d: %s\n", __FILE__, __LINE__, msg); 13 SkDebugf("%s:%d: %s\n", __FILE__, __LINE__, msg);
14 14
15 namespace {
16
17 // Do the commands in 'input' match the supplied pattern? Note: this is a pretty 15 // Do the commands in 'input' match the supplied pattern? Note: this is a pretty
18 // heavy-weight operation since we are drawing the picture into a debug canvas 16 // heavy-weight operation since we are drawing the picture into a debug canvas
19 // to extract the commands. 17 // to extract the commands.
20 bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern) { 18 static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern) {
21 SkDebugCanvas debugCanvas(input.width(), input.height()); 19 SkDebugCanvas debugCanvas(input.width(), input.height());
22 debugCanvas.setBounds(input.width(), input.height()); 20 debugCanvas.setBounds(input.width(), input.height());
23 input.draw(&debugCanvas); 21 input.draw(&debugCanvas);
24 22
25 if (pattern.count() != debugCanvas.getSize()) { 23 if (pattern.count() != debugCanvas.getSize()) {
26 return false; 24 return false;
27 } 25 }
28 26
29 for (int i = 0; i < pattern.count(); ++i) { 27 for (int i = 0; i < pattern.count(); ++i) {
30 if (pattern[i] != debugCanvas.getDrawCommandAt(i)->getType()) { 28 if (pattern[i] != debugCanvas.getDrawCommandAt(i)->getType()) {
31 return false; 29 return false;
32 } 30 }
33 } 31 }
34 32
35 return true; 33 return true;
36 } 34 }
37 35
38 // construct the pattern removed by the SkPictureRecord::remove_save_layer1 36 // construct the pattern removed by the SkPictureRecord::remove_save_layer1
39 // optimization, i.e.: 37 // optimization, i.e.:
40 // SAVE_LAYER 38 // SAVE_LAYER
41 // DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_REC T 39 // DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_REC T
42 // RESTORE 40 // RESTORE
43 // 41 //
44 // saveLayerHasPaint - control if the saveLayer has a paint (the optimization 42 // saveLayerHasPaint - control if the saveLayer has a paint (the optimization
45 // takes a different path if this is false) 43 // takes a different path if this is false)
46 // dbmr2rHasPaint - control if the dbmr2r has a paint (the optimization 44 // dbmr2rHasPaint - control if the dbmr2r has a paint (the optimization
47 // takes a different path if this is false) 45 // takes a different path if this is false)
48 // colorsMatch - control if the saveLayer and dbmr2r paint colors 46 // colorsMatch - control if the saveLayer and dbmr2r paint colors
49 // match (the optimization will fail if they do not) 47 // match (the optimization will fail if they do not)
50 SkPicture* create_save_layer_opt_1(SkTDArray<DrawType> *preOptPattern, 48 static SkPicture* create_save_layer_opt_1(SkTDArray<DrawType>* preOptPattern,
51 SkTDArray<DrawType> *postOptPattern, 49 SkTDArray<DrawType>* postOptPattern,
52 const SkBitmap& checkerBoard, 50 const SkBitmap& checkerBoard,
53 bool saveLayerHasPaint, 51 bool saveLayerHasPaint,
54 bool dbmr2rHasPaint, 52 bool dbmr2rHasPaint,
55 bool colorsMatch) { 53 bool colorsMatch) {
56 // Create the pattern that should trigger the optimization 54 // Create the pattern that should trigger the optimization
57 preOptPattern->setCount(5); 55 preOptPattern->setCount(5);
58 (*preOptPattern)[0] = SAVE; 56 (*preOptPattern)[0] = SAVE;
59 (*preOptPattern)[1] = SAVE_LAYER; 57 (*preOptPattern)[1] = SAVE_LAYER;
60 (*preOptPattern)[2] = DRAW_BITMAP_RECT_TO_RECT; 58 (*preOptPattern)[2] = DRAW_BITMAP_RECT_TO_RECT;
61 (*preOptPattern)[3] = RESTORE; 59 (*preOptPattern)[3] = RESTORE;
62 (*preOptPattern)[4] = RESTORE; 60 (*preOptPattern)[4] = RESTORE;
63 61
64 if (colorsMatch) { 62 if (colorsMatch) {
65 // Create the pattern that should appear after the optimization 63 // Create the pattern that should appear after the optimization
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL); 111 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL);
114 } 112 }
115 canvas->restore(); 113 canvas->restore();
116 114
117 result->endRecording(); 115 result->endRecording();
118 116
119 return result; 117 return result;
120 } 118 }
121 119
122 // straight-ahead version that is seen in the skps 120 // straight-ahead version that is seen in the skps
123 SkPicture* create_save_layer_opt_1_v1(SkTDArray<DrawType> *preOptPattern, 121 static SkPicture* create_save_layer_opt_1_v1(SkTDArray<DrawType>* preOptPattern,
124 SkTDArray<DrawType> *postOptPattern, 122 SkTDArray<DrawType>* postOptPattern ,
125 const SkBitmap& checkerBoard) { 123 const SkBitmap& checkerBoard) {
126 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard, 124 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard,
127 true, // saveLayer has a paint 125 true, // saveLayer has a paint
128 true, // dbmr2r has a paint 126 true, // dbmr2r has a paint
129 true); // and the colors match 127 true); // and the colors match
130 } 128 }
131 129
132 // alternate version that should still succeed 130 // alternate version that should still succeed
133 SkPicture* create_save_layer_opt_1_v2(SkTDArray<DrawType> *preOptPattern, 131 static SkPicture* create_save_layer_opt_1_v2(SkTDArray<DrawType>* preOptPattern,
134 SkTDArray<DrawType> *postOptPattern, 132 SkTDArray<DrawType>* postOptPattern ,
135 const SkBitmap& checkerBoard) { 133 const SkBitmap& checkerBoard) {
136 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard, 134 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard,
137 false, // saveLayer doesn't have a paint! 135 false, // saveLayer doesn't have a paint!
138 true, // dbmr2r has a paint 136 true, // dbmr2r has a paint
139 true); // color matching not really applicab le 137 true); // color matching not really applicab le
140 } 138 }
141 139
142 // alternate version that should still succeed 140 // alternate version that should still succeed
143 SkPicture* create_save_layer_opt_1_v3(SkTDArray<DrawType> *preOptPattern, 141 static SkPicture* create_save_layer_opt_1_v3(SkTDArray<DrawType>* preOptPattern,
144 SkTDArray<DrawType> *postOptPattern, 142 SkTDArray<DrawType>* postOptPattern ,
145 const SkBitmap& checkerBoard) { 143 const SkBitmap& checkerBoard) {
146 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard, 144 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard,
147 true, // saveLayer has a paint 145 true, // saveLayer has a paint
148 false, // dbmr2r doesn't have a paint! 146 false, // dbmr2r doesn't have a paint!
149 true); // color matching not really applicab le 147 true); // color matching not really applicab le
150 } 148 }
151 149
152 // version in which the optimization fails b.c. the colors don't match 150 // version in which the optimization fails b.c. the colors don't match
153 SkPicture* create_save_layer_opt_1_v4(SkTDArray<DrawType> *preOptPattern, 151 static SkPicture* create_save_layer_opt_1_v4(SkTDArray<DrawType>* preOptPattern,
154 SkTDArray<DrawType> *postOptPattern, 152 SkTDArray<DrawType>* postOptPattern ,
155 const SkBitmap& checkerBoard) { 153 const SkBitmap& checkerBoard) {
156 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard, 154 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard,
157 true, // saveLayer has a paint 155 true, // saveLayer has a paint
158 true, // dbmr2r has a paint 156 true, // dbmr2r has a paint
159 false); // and the colors don't match! 157 false); // and the colors don't match!
160 } 158 }
161 159
162 // construct the pattern removed by the SkPictureRecord::remove_save_layer2 160 // construct the pattern removed by the SkPictureRecord::remove_save_layer2
163 // optimization, i.e.: 161 // optimization, i.e.:
164 // SAVE_LAYER (with NULL == bounds) 162 // SAVE_LAYER (with NULL == bounds)
165 // SAVE 163 // SAVE
166 // CLIP_RECT 164 // CLIP_RECT
167 // DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_R ECT 165 // DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_R ECT
168 // RESTORE 166 // RESTORE
169 // RESTORE 167 // RESTORE
170 // 168 //
171 // saveLayerHasPaint - control if the saveLayer has a paint (the optimization 169 // saveLayerHasPaint - control if the saveLayer has a paint (the optimization
172 // takes a different path if this is false) 170 // takes a different path if this is false)
173 // dbmr2rHasPaint - control if the dbmr2r has a paint (the optimization 171 // dbmr2rHasPaint - control if the dbmr2r has a paint (the optimization
174 // takes a different path if this is false) 172 // takes a different path if this is false)
175 // colorsMatch - control if the saveLayer and dbmr2r paint colors 173 // colorsMatch - control if the saveLayer and dbmr2r paint colors
176 // match (the optimization will fail if they do not) 174 // match (the optimization will fail if they do not)
177 SkPicture* create_save_layer_opt_2(SkTDArray<DrawType> *preOptPattern, 175 static SkPicture* create_save_layer_opt_2(SkTDArray<DrawType>* preOptPattern,
178 SkTDArray<DrawType> *postOptPattern, 176 SkTDArray<DrawType>* postOptPattern,
179 const SkBitmap& checkerBoard, 177 const SkBitmap& checkerBoard,
180 bool saveLayerHasPaint, 178 bool saveLayerHasPaint,
181 bool dbmr2rHasPaint, 179 bool dbmr2rHasPaint,
182 bool colorsMatch) { 180 bool colorsMatch) {
183 // Create the pattern that should trigger the optimization 181 // Create the pattern that should trigger the optimization
184 preOptPattern->setCount(8); 182 preOptPattern->setCount(8);
185 (*preOptPattern)[0] = SAVE; 183 (*preOptPattern)[0] = SAVE;
186 (*preOptPattern)[1] = SAVE_LAYER; 184 (*preOptPattern)[1] = SAVE_LAYER;
187 (*preOptPattern)[2] = SAVE; 185 (*preOptPattern)[2] = SAVE;
188 (*preOptPattern)[3] = CLIP_RECT; 186 (*preOptPattern)[3] = CLIP_RECT;
189 (*preOptPattern)[4] = DRAW_BITMAP_RECT_TO_RECT; 187 (*preOptPattern)[4] = DRAW_BITMAP_RECT_TO_RECT;
190 (*preOptPattern)[5] = RESTORE; 188 (*preOptPattern)[5] = RESTORE;
191 (*preOptPattern)[6] = RESTORE; 189 (*preOptPattern)[6] = RESTORE;
192 (*preOptPattern)[7] = RESTORE; 190 (*preOptPattern)[7] = RESTORE;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 251 }
254 canvas->restore(); 252 canvas->restore();
255 canvas->restore(); 253 canvas->restore();
256 254
257 result->endRecording(); 255 result->endRecording();
258 256
259 return result; 257 return result;
260 } 258 }
261 259
262 // straight-ahead version that is seen in the skps 260 // straight-ahead version that is seen in the skps
263 SkPicture* create_save_layer_opt_2_v1(SkTDArray<DrawType> *preOptPattern, 261 static SkPicture* create_save_layer_opt_2_v1(SkTDArray<DrawType>* preOptPattern,
264 SkTDArray<DrawType> *postOptPattern, 262 SkTDArray<DrawType>* postOptPattern ,
265 const SkBitmap& checkerBoard) { 263 const SkBitmap& checkerBoard) {
266 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard, 264 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard,
267 true, // saveLayer has a paint 265 true, // saveLayer has a paint
268 true, // dbmr2r has a paint 266 true, // dbmr2r has a paint
269 true); // and the colors match 267 true); // and the colors match
270 } 268 }
271 269
272 // alternate version that should still succeed 270 // alternate version that should still succeed
273 SkPicture* create_save_layer_opt_2_v2(SkTDArray<DrawType> *preOptPattern, 271 static SkPicture* create_save_layer_opt_2_v2(SkTDArray<DrawType>* preOptPattern,
274 SkTDArray<DrawType> *postOptPattern, 272 SkTDArray<DrawType>* postOptPattern ,
275 const SkBitmap& checkerBoard) { 273 const SkBitmap& checkerBoard) {
276 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard, 274 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard,
277 false, // saveLayer doesn't have a paint! 275 false, // saveLayer doesn't have a paint!
278 true, // dbmr2r has a paint 276 true, // dbmr2r has a paint
279 true); // color matching not really applicab le 277 true); // color matching not really applicab le
280 } 278 }
281 279
282 // alternate version that should still succeed 280 // alternate version that should still succeed
283 SkPicture* create_save_layer_opt_2_v3(SkTDArray<DrawType> *preOptPattern, 281 static SkPicture* create_save_layer_opt_2_v3(SkTDArray<DrawType>* preOptPattern,
284 SkTDArray<DrawType> *postOptPattern, 282 SkTDArray<DrawType>* postOptPattern ,
285 const SkBitmap& checkerBoard) { 283 const SkBitmap& checkerBoard) {
286 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard, 284 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard,
287 true, // saveLayer has a paint 285 true, // saveLayer has a paint
288 false, // dbmr2r doesn't have a paint! 286 false, // dbmr2r doesn't have a paint!
289 true); // color matching not really applicab le 287 true); // color matching not really applicab le
290 } 288 }
291 289
292 // version in which the optimization fails b.c. the colors don't match 290 // version in which the optimization fails b.c. the colors don't match
293 SkPicture* create_save_layer_opt_2_v4(SkTDArray<DrawType> *preOptPattern, 291 static SkPicture* create_save_layer_opt_2_v4(SkTDArray<DrawType>* preOptPattern,
294 SkTDArray<DrawType> *postOptPattern, 292 SkTDArray<DrawType>* postOptPattern ,
295 const SkBitmap& checkerBoard) { 293 const SkBitmap& checkerBoard) {
296 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard, 294 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard,
297 true, // saveLayer has a paint 295 true, // saveLayer has a paint
298 true, // dbmr2r has a paint 296 true, // dbmr2r has a paint
299 false); // and the colors don't match! 297 false); // and the colors don't match!
300 } 298 }
301 299
302 };
303
304
305 // As our .skp optimizations get folded into the captured skps our code will 300 // As our .skp optimizations get folded into the captured skps our code will
306 // no longer be locally exercised. This GM manually constructs the patterns 301 // no longer be locally exercised. This GM manually constructs the patterns
307 // our optimizations will remove to test them. It acts as both a GM and a unit 302 // our optimizations will remove to test them. It acts as both a GM and a unit
308 // test 303 // test
309 class OptimizationsGM : public skiagm::GM { 304 class OptimizationsGM : public skiagm::GM {
310 public: 305 public:
311 OptimizationsGM() { 306 OptimizationsGM() {
312 this->makeCheckerboard(); 307 this->makeCheckerboard();
313 } 308 }
314 309
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 406 }
412 407
413 SkBitmap fCheckerboard; 408 SkBitmap fCheckerboard;
414 409
415 typedef skiagm::GM INHERITED; 410 typedef skiagm::GM INHERITED;
416 }; 411 };
417 412
418 ////////////////////////////////////////////////////////////////////////////// 413 //////////////////////////////////////////////////////////////////////////////
419 414
420 DEF_GM( return new OptimizationsGM; ) 415 DEF_GM( return new OptimizationsGM; )
OLDNEW
« no previous file with comments | « gm/imagefiltersgraph.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698