OLD | NEW |
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 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
12 | 12 |
13 #define WARN(msg) \ | 13 #define WARN(msg) \ |
14 SkDebugf("%s:%d: %s\n", __FILE__, __LINE__, msg); | 14 SkDebugf("%s:%d: %s\n", __FILE__, __LINE__, msg); |
15 | 15 |
16 // Do the commands in 'input' match the supplied pattern? Note: this is a pretty | 16 // Do the commands in 'input' match the supplied pattern? Note: this is a pretty |
17 // heavy-weight operation since we are drawing the picture into a debug canvas | 17 // heavy-weight operation since we are drawing the picture into a debug canvas |
18 // to extract the commands. | 18 // to extract the commands. |
19 static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern)
{ | 19 static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern)
{ |
20 SkDebugCanvas debugCanvas(SkScalarCeilToInt(input.cullRect().width()), | 20 SkDebugCanvas debugCanvas(SkScalarCeilToInt(input.cullRect().width()), |
21 SkScalarCeilToInt(input.cullRect().height())); | 21 SkScalarCeilToInt(input.cullRect().height())); |
22 input.draw(&debugCanvas); | 22 input.playback(&debugCanvas); |
23 | 23 |
24 if (pattern.count() != debugCanvas.getSize()) { | 24 if (pattern.count() != debugCanvas.getSize()) { |
25 return false; | 25 return false; |
26 } | 26 } |
27 | 27 |
28 for (int i = 0; i < pattern.count(); ++i) { | 28 for (int i = 0; i < pattern.count(); ++i) { |
29 if (pattern[i] != debugCanvas.getDrawCommandAt(i)->getType()) { | 29 if (pattern[i] != debugCanvas.getDrawCommandAt(i)->getType()) { |
30 return false; | 30 return false; |
31 } | 31 } |
32 } | 32 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 for (size_t i = 0; i < SK_ARRAY_COUNT(gOpts); ++i) { | 345 for (size_t i = 0; i < SK_ARRAY_COUNT(gOpts); ++i) { |
346 SkAutoTUnref<SkPicture> pre((*gOpts[i])(&prePattern, &postPattern, f
Checkerboard)); | 346 SkAutoTUnref<SkPicture> pre((*gOpts[i])(&prePattern, &postPattern, f
Checkerboard)); |
347 | 347 |
348 if (!(check_pattern(*pre, prePattern))) { | 348 if (!(check_pattern(*pre, prePattern))) { |
349 WARN("Pre optimization pattern mismatch"); | 349 WARN("Pre optimization pattern mismatch"); |
350 SkASSERT(0); | 350 SkASSERT(0); |
351 } | 351 } |
352 | 352 |
353 canvas->save(); | 353 canvas->save(); |
354 canvas->translate(xPos, yPos); | 354 canvas->translate(xPos, yPos); |
355 pre->draw(canvas); | 355 pre->playback(canvas); |
356 xPos += pre->cullRect().width(); | 356 xPos += pre->cullRect().width(); |
357 canvas->restore(); | 357 canvas->restore(); |
358 | 358 |
359 // re-render the 'pre' picture and thus 'apply' the optimization | 359 // re-render the 'pre' picture and thus 'apply' the optimization |
360 SkPictureRecorder recorder; | 360 SkPictureRecorder recorder; |
361 | 361 |
362 SkCanvas* recordCanvas = | 362 SkCanvas* recordCanvas = |
363 recorder.DEPRECATED_beginRecording(pre->cullRect().width(), | 363 recorder.DEPRECATED_beginRecording(pre->cullRect().width(), |
364 pre->cullRect().height(), | 364 pre->cullRect().height(), |
365 NULL, 0); | 365 NULL, 0); |
366 | 366 |
367 pre->draw(recordCanvas); | 367 pre->playback(recordCanvas); |
368 | 368 |
369 SkAutoTUnref<SkPicture> post(recorder.endRecording()); | 369 SkAutoTUnref<SkPicture> post(recorder.endRecording()); |
370 | 370 |
371 if (!(check_pattern(*post, postPattern))) { | 371 if (!(check_pattern(*post, postPattern))) { |
372 WARN("Post optimization pattern mismatch"); | 372 WARN("Post optimization pattern mismatch"); |
373 SkASSERT(0); | 373 SkASSERT(0); |
374 } | 374 } |
375 | 375 |
376 canvas->save(); | 376 canvas->save(); |
377 canvas->translate(xPos, yPos); | 377 canvas->translate(xPos, yPos); |
378 post->draw(canvas); | 378 post->playback(canvas); |
379 xPos += post->cullRect().width(); | 379 xPos += post->cullRect().width(); |
380 canvas->restore(); | 380 canvas->restore(); |
381 | 381 |
382 if (xPos >= kWidth) { | 382 if (xPos >= kWidth) { |
383 // start a new line | 383 // start a new line |
384 xPos = 0; | 384 xPos = 0; |
385 yPos += post->cullRect().height(); | 385 yPos += post->cullRect().height(); |
386 } | 386 } |
387 | 387 |
388 // TODO: we could also render the pre and post pictures to bitmaps | 388 // TODO: we could also render the pre and post pictures to bitmaps |
(...skipping 22 matching lines...) Expand all Loading... |
411 } | 411 } |
412 | 412 |
413 SkBitmap fCheckerboard; | 413 SkBitmap fCheckerboard; |
414 | 414 |
415 typedef skiagm::GM INHERITED; | 415 typedef skiagm::GM INHERITED; |
416 }; | 416 }; |
417 | 417 |
418 ////////////////////////////////////////////////////////////////////////////// | 418 ////////////////////////////////////////////////////////////////////////////// |
419 | 419 |
420 DEF_GM( return new OptimizationsGM; ) | 420 DEF_GM( return new OptimizationsGM; ) |
OLD | NEW |