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

Side by Side Diff: gm/optimizations.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 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
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"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 postOptPattern->setCount(7); 72 postOptPattern->setCount(7);
73 (*postOptPattern)[0] = SAVE; // extra save/restore added by extra draw 73 (*postOptPattern)[0] = SAVE; // extra save/restore added by extra draw
74 (*postOptPattern)[1] = SAVE; 74 (*postOptPattern)[1] = SAVE;
75 (*postOptPattern)[2] = SAVE_LAYER; 75 (*postOptPattern)[2] = SAVE_LAYER;
76 (*postOptPattern)[3] = DRAW_BITMAP_RECT_TO_RECT; 76 (*postOptPattern)[3] = DRAW_BITMAP_RECT_TO_RECT;
77 (*postOptPattern)[4] = RESTORE; 77 (*postOptPattern)[4] = RESTORE;
78 (*postOptPattern)[5] = RESTORE; 78 (*postOptPattern)[5] = RESTORE;
79 (*postOptPattern)[6] = RESTORE; 79 (*postOptPattern)[6] = RESTORE;
80 } 80 }
81 81
82 SkPicture* result = new SkPicture; 82 SkPictureRecorder recorder;
83 83
84 SkCanvas* canvas = recorder.beginRecording(100, 100);
84 // have to disable the optimizations while generating the picture 85 // have to disable the optimizations while generating the picture
85 SkCanvas* canvas = result->beginRecording(100, 100); 86 recorder.internalOnly_EnableOpts(false);
86 result->internalOnly_EnableOpts(false);
87 87
88 SkPaint saveLayerPaint; 88 SkPaint saveLayerPaint;
89 saveLayerPaint.setColor(0xCC000000); 89 saveLayerPaint.setColor(0xCC000000);
90 90
91 // saveLayer's 'bounds' parameter must be NULL for this optimization 91 // saveLayer's 'bounds' parameter must be NULL for this optimization
92 if (saveLayerHasPaint) { 92 if (saveLayerHasPaint) {
93 canvas->saveLayer(NULL, &saveLayerPaint); 93 canvas->saveLayer(NULL, &saveLayerPaint);
94 } else { 94 } else {
95 canvas->saveLayer(NULL, NULL); 95 canvas->saveLayer(NULL, NULL);
96 } 96 }
97 97
98 SkRect rect = { 10, 10, 90, 90 }; 98 SkRect rect = { 10, 10, 90, 90 };
99 99
100 // The dbmr2r's paint must be opaque 100 // The dbmr2r's paint must be opaque
101 SkPaint dbmr2rPaint; 101 SkPaint dbmr2rPaint;
102 if (colorsMatch) { 102 if (colorsMatch) {
103 dbmr2rPaint.setColor(0xFF000000); 103 dbmr2rPaint.setColor(0xFF000000);
104 } else { 104 } else {
105 dbmr2rPaint.setColor(0xFFFF0000); 105 dbmr2rPaint.setColor(0xFFFF0000);
106 } 106 }
107 107
108 if (dbmr2rHasPaint) { 108 if (dbmr2rHasPaint) {
109 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, &dbmr2rPaint); 109 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, &dbmr2rPaint);
110 } else { 110 } else {
111 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL); 111 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL);
112 } 112 }
113 canvas->restore(); 113 canvas->restore();
114 114
115 result->endRecording(); 115 return recorder.endRecording();
116
117 return result;
118 } 116 }
119 117
120 // straight-ahead version that is seen in the skps 118 // straight-ahead version that is seen in the skps
121 static SkPicture* create_save_layer_opt_1_v1(SkTDArray<DrawType>* preOptPattern, 119 static SkPicture* create_save_layer_opt_1_v1(SkTDArray<DrawType>* preOptPattern,
122 SkTDArray<DrawType>* postOptPattern , 120 SkTDArray<DrawType>* postOptPattern ,
123 const SkBitmap& checkerBoard) { 121 const SkBitmap& checkerBoard) {
124 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard, 122 return create_save_layer_opt_1(preOptPattern, postOptPattern, checkerBoard,
125 true, // saveLayer has a paint 123 true, // saveLayer has a paint
126 true, // dbmr2r has a paint 124 true, // dbmr2r has a paint
127 true); // and the colors match 125 true); // and the colors match
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 (*postOptPattern)[2] = SAVE_LAYER; 206 (*postOptPattern)[2] = SAVE_LAYER;
209 (*postOptPattern)[3] = SAVE; 207 (*postOptPattern)[3] = SAVE;
210 (*postOptPattern)[4] = CLIP_RECT; 208 (*postOptPattern)[4] = CLIP_RECT;
211 (*postOptPattern)[5] = DRAW_BITMAP_RECT_TO_RECT; 209 (*postOptPattern)[5] = DRAW_BITMAP_RECT_TO_RECT;
212 (*postOptPattern)[6] = RESTORE; 210 (*postOptPattern)[6] = RESTORE;
213 (*postOptPattern)[7] = RESTORE; 211 (*postOptPattern)[7] = RESTORE;
214 (*postOptPattern)[8] = RESTORE; 212 (*postOptPattern)[8] = RESTORE;
215 (*postOptPattern)[9] = RESTORE; 213 (*postOptPattern)[9] = RESTORE;
216 } 214 }
217 215
218 SkPicture* result = new SkPicture; 216 SkPictureRecorder recorder;
219 217
218 SkCanvas* canvas = recorder.beginRecording(100, 100);
220 // have to disable the optimizations while generating the picture 219 // have to disable the optimizations while generating the picture
221 SkCanvas* canvas = result->beginRecording(100, 100); 220 recorder.internalOnly_EnableOpts(false);
222 result->internalOnly_EnableOpts(false);
223 221
224 SkPaint saveLayerPaint; 222 SkPaint saveLayerPaint;
225 saveLayerPaint.setColor(0xCC000000); 223 saveLayerPaint.setColor(0xCC000000);
226 224
227 // saveLayer's 'bounds' parameter must be NULL for this optimization 225 // saveLayer's 'bounds' parameter must be NULL for this optimization
228 if (saveLayerHasPaint) { 226 if (saveLayerHasPaint) {
229 canvas->saveLayer(NULL, &saveLayerPaint); 227 canvas->saveLayer(NULL, &saveLayerPaint);
230 } else { 228 } else {
231 canvas->saveLayer(NULL, NULL); 229 canvas->saveLayer(NULL, NULL);
232 } 230 }
(...skipping 12 matching lines...) Expand all
245 } 243 }
246 244
247 if (dbmr2rHasPaint) { 245 if (dbmr2rHasPaint) {
248 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, &dbmr2rPaint); 246 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, &dbmr2rPaint);
249 } else { 247 } else {
250 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL); 248 canvas->drawBitmapRectToRect(checkerBoard, NULL, rect, NULL);
251 } 249 }
252 canvas->restore(); 250 canvas->restore();
253 canvas->restore(); 251 canvas->restore();
254 252
255 result->endRecording(); 253 return recorder.endRecording();
256
257 return result;
258 } 254 }
259 255
260 // straight-ahead version that is seen in the skps 256 // straight-ahead version that is seen in the skps
261 static SkPicture* create_save_layer_opt_2_v1(SkTDArray<DrawType>* preOptPattern, 257 static SkPicture* create_save_layer_opt_2_v1(SkTDArray<DrawType>* preOptPattern,
262 SkTDArray<DrawType>* postOptPattern , 258 SkTDArray<DrawType>* postOptPattern ,
263 const SkBitmap& checkerBoard) { 259 const SkBitmap& checkerBoard) {
264 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard, 260 return create_save_layer_opt_2(preOptPattern, postOptPattern, checkerBoard,
265 true, // saveLayer has a paint 261 true, // saveLayer has a paint
266 true, // dbmr2r has a paint 262 true, // dbmr2r has a paint
267 true); // and the colors match 263 true); // and the colors match
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 SkASSERT(0); 349 SkASSERT(0);
354 } 350 }
355 351
356 canvas->save(); 352 canvas->save();
357 canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos)); 353 canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
358 pre->draw(canvas); 354 pre->draw(canvas);
359 xPos += pre->width(); 355 xPos += pre->width();
360 canvas->restore(); 356 canvas->restore();
361 357
362 // re-render the 'pre' picture and thus 'apply' the optimization 358 // re-render the 'pre' picture and thus 'apply' the optimization
363 SkAutoTUnref<SkPicture> post(new SkPicture); 359 SkPictureRecorder recorder;
364 360
365 SkCanvas* recordCanvas = post->beginRecording(pre->width(), pre->hei ght()); 361 SkCanvas* recordCanvas = recorder.beginRecording(pre->width(), pre-> height());
366 362
367 pre->draw(recordCanvas); 363 pre->draw(recordCanvas);
368 364
369 post->endRecording(); 365 SkAutoTUnref<SkPicture> post(recorder.endRecording());
370 366
371 if (!(check_pattern(*post, postPattern))) { 367 if (!(check_pattern(*post, postPattern))) {
372 WARN("Post optimization pattern mismatch"); 368 WARN("Post optimization pattern mismatch");
373 SkASSERT(0); 369 SkASSERT(0);
374 } 370 }
375 371
376 canvas->save(); 372 canvas->save();
377 canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos)); 373 canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
378 post->draw(canvas); 374 post->draw(canvas);
379 xPos += post->width(); 375 xPos += post->width();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 407 }
412 408
413 SkBitmap fCheckerboard; 409 SkBitmap fCheckerboard;
414 410
415 typedef skiagm::GM INHERITED; 411 typedef skiagm::GM INHERITED;
416 }; 412 };
417 413
418 ////////////////////////////////////////////////////////////////////////////// 414 //////////////////////////////////////////////////////////////////////////////
419 415
420 DEF_GM( return new OptimizationsGM; ) 416 DEF_GM( return new OptimizationsGM; )
OLDNEW
« no previous file with comments | « gm/gmmain.cpp ('k') | gm/pathopsskpclip.cpp » ('j') | samplecode/SampleTiling.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698