OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #ifndef PictureRenderer_DEFINED | 8 #ifndef PictureRenderer_DEFINED |
9 #define PictureRenderer_DEFINED | 9 #define PictureRenderer_DEFINED |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 namespace sk_tools { | 37 namespace sk_tools { |
38 | 38 |
39 class TiledPictureRenderer; | 39 class TiledPictureRenderer; |
40 | 40 |
41 /** | 41 /** |
42 * Class for collecting image results (checksums) as we go. | 42 * Class for collecting image results (checksums) as we go. |
43 */ | 43 */ |
44 class ImageResultsSummary { | 44 class ImageResultsSummary { |
45 public: | 45 public: |
46 /** | 46 /** |
| 47 * Adds this bitmap hash to the summary of results. |
| 48 * |
| 49 * @param testName name of the test |
| 50 * @param hash hash to store |
| 51 */ |
| 52 void add(const char *testName, uint64_t hash); |
| 53 |
| 54 /** |
47 * Adds this bitmap's hash to the summary of results. | 55 * Adds this bitmap's hash to the summary of results. |
48 * | 56 * |
49 * @param testName name of the test | 57 * @param testName name of the test |
50 * @param bitmap bitmap to store the hash of | 58 * @param bitmap bitmap to store the hash of |
51 */ | 59 */ |
52 void add(const char *testName, const SkBitmap& bitmap); | 60 void add(const char *testName, const SkBitmap& bitmap); |
53 | 61 |
54 /** | 62 /** |
55 * Writes the summary (as constructed so far) to a file. | 63 * Writes the summary (as constructed so far) to a file. |
56 * | 64 * |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 106 }; |
99 | 107 |
100 SK_COMPILE_ASSERT(!(kMaskFilter_DrawFilterFlag & SkPaint::kAllFlags), maskfi
lter_flag_must_be_greater); | 108 SK_COMPILE_ASSERT(!(kMaskFilter_DrawFilterFlag & SkPaint::kAllFlags), maskfi
lter_flag_must_be_greater); |
101 SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags), | 109 SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags), |
102 hinting_flag_must_be_greater); | 110 hinting_flag_must_be_greater); |
103 SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags), | 111 SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags), |
104 slight_hinting_flag_must_be_greater); | 112 slight_hinting_flag_must_be_greater); |
105 | 113 |
106 /** | 114 /** |
107 * Called with each new SkPicture to render. | 115 * Called with each new SkPicture to render. |
| 116 * |
| 117 * @param pict The SkPicture to render. |
| 118 * @param outputDir The output directory within which this renderer should w
rite files, |
| 119 * or NULL if this renderer should not write files at all. |
| 120 * @param inputFilename The name of the input file we are rendering. |
| 121 * @param useChecksumBasedFilenames Whether to use checksum-based filenames
when writing |
| 122 * bitmap images to disk. |
108 */ | 123 */ |
109 virtual void init(SkPicture* pict); | 124 virtual void init(SkPicture* pict, const SkString* outputDir, |
| 125 const SkString* inputFilename, bool useChecksumBasedFilena
mes); |
110 | 126 |
111 /** | 127 /** |
112 * Set the viewport so that only the portion listed gets drawn. | 128 * Set the viewport so that only the portion listed gets drawn. |
113 */ | 129 */ |
114 void setViewport(SkISize size) { fViewport = size; } | 130 void setViewport(SkISize size) { fViewport = size; } |
115 | 131 |
116 /** | 132 /** |
117 * Set the scale factor at which draw the picture. | 133 * Set the scale factor at which draw the picture. |
118 */ | 134 */ |
119 void setScaleFactor(SkScalar scale) { fScaleFactor = scale; } | 135 void setScaleFactor(SkScalar scale) { fScaleFactor = scale; } |
120 | 136 |
121 /** | 137 /** |
122 * Perform any setup that should done prior to each iteration of render() wh
ich should not be | 138 * Perform any setup that should done prior to each iteration of render() wh
ich should not be |
123 * timed. | 139 * timed. |
124 */ | 140 */ |
125 virtual void setup() {} | 141 virtual void setup() {} |
126 | 142 |
127 /** | 143 /** |
128 * Perform work that is to be timed. Typically this is rendering, but is als
o used for recording | 144 * Perform the work. If this is being called within the context of bench_pi
ctures, |
129 * and preparing picture for playback by the subclasses which do those. | 145 * this is the step that will be timed. |
130 * If path is non-null, subclass implementations should call write(). | 146 * |
131 * @param path If non-null, also write the output to the file specified by p
ath. path should | 147 * Typically "the work" is rendering an SkPicture into a bitmap, but in some
subclasses |
132 * have no extension; it will be added by write(). | 148 * it is recording the source SkPicture into another SkPicture. |
133 * @return bool True if rendering succeeded and, if path is non-null, the ou
tput was | 149 * |
134 * successfully written to a file. | 150 * If fOutputDir has been specified, the result of the work will be written
to that dir. |
| 151 * |
| 152 * @param out If non-null, the implementing subclass MAY allocate an SkBitma
p, copy the |
| 153 * output image into it, and return it here. (Some subclasses ig
nore this parameter) |
| 154 * @return bool True if rendering succeeded and, if fOutputDir had been spec
ified, the output |
| 155 * was successfully written to a file. |
135 */ | 156 */ |
136 virtual bool render(const SkString* path, SkBitmap** out = NULL) = 0; | 157 virtual bool render(SkBitmap** out = NULL) = 0; |
137 | 158 |
138 /** | 159 /** |
139 * Called once finished with a particular SkPicture, before calling init aga
in, and before | 160 * Called once finished with a particular SkPicture, before calling init aga
in, and before |
140 * being done with this Renderer. | 161 * being done with this Renderer. |
141 */ | 162 */ |
142 virtual void end(); | 163 virtual void end(); |
143 | 164 |
144 /** | 165 /** |
145 * If this PictureRenderer is actually a TiledPictureRender, return a pointe
r to this as a | 166 * If this PictureRenderer is actually a TiledPictureRender, return a pointe
r to this as a |
146 * TiledPictureRender so its methods can be called. | 167 * TiledPictureRender so its methods can be called. |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 385 |
365 #if SK_SUPPORT_GPU | 386 #if SK_SUPPORT_GPU |
366 virtual ~PictureRenderer() { | 387 virtual ~PictureRenderer() { |
367 SkSafeUnref(fGrContext); | 388 SkSafeUnref(fGrContext); |
368 } | 389 } |
369 #endif | 390 #endif |
370 | 391 |
371 protected: | 392 protected: |
372 SkAutoTUnref<SkCanvas> fCanvas; | 393 SkAutoTUnref<SkCanvas> fCanvas; |
373 SkPicture* fPicture; | 394 SkPicture* fPicture; |
| 395 bool fUseChecksumBasedFilenames; |
374 ImageResultsSummary* fJsonSummaryPtr; | 396 ImageResultsSummary* fJsonSummaryPtr; |
375 SkDeviceTypes fDeviceType; | 397 SkDeviceTypes fDeviceType; |
376 BBoxHierarchyType fBBoxHierarchyType; | 398 BBoxHierarchyType fBBoxHierarchyType; |
377 DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; | 399 DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; |
378 SkString fDrawFiltersConfig; | 400 SkString fDrawFiltersConfig; |
| 401 SkString fOutputDir; |
| 402 SkString fInputFilename; |
379 SkTileGridPicture::TileGridInfo fGridInfo; // used when fBBoxHierarchyType i
s TileGrid | 403 SkTileGridPicture::TileGridInfo fGridInfo; // used when fBBoxHierarchyType i
s TileGrid |
380 | 404 |
381 void buildBBoxHierarchy(); | 405 void buildBBoxHierarchy(); |
382 | 406 |
383 /** | 407 /** |
384 * Return the total width that should be drawn. If the viewport width has be
en set greater than | 408 * Return the total width that should be drawn. If the viewport width has be
en set greater than |
385 * 0, this will be the minimum of the current SkPicture's width and the view
port's width. | 409 * 0, this will be the minimum of the current SkPicture's width and the view
port's width. |
386 */ | 410 */ |
387 int getViewWidth(); | 411 int getViewWidth(); |
388 | 412 |
389 /** | 413 /** |
390 * Return the total height that should be drawn. If the viewport height has
been set greater | 414 * Return the total height that should be drawn. If the viewport height has
been set greater |
391 * than 0, this will be the minimum of the current SkPicture's height and th
e viewport's height. | 415 * than 0, this will be the minimum of the current SkPicture's height and th
e viewport's height. |
392 */ | 416 */ |
393 int getViewHeight(); | 417 int getViewHeight(); |
394 | 418 |
395 /** | 419 /** |
396 * Scales the provided canvas to the scale factor set by setScaleFactor. | 420 * Scales the provided canvas to the scale factor set by setScaleFactor. |
397 */ | 421 */ |
398 void scaleToScaleFactor(SkCanvas*); | 422 void scaleToScaleFactor(SkCanvas*); |
399 | 423 |
400 SkPicture* createPicture(); | 424 SkPicture* createPicture(); |
401 uint32_t recordFlags(); | 425 uint32_t recordFlags(); |
402 SkCanvas* setupCanvas(); | 426 SkCanvas* setupCanvas(); |
403 virtual SkCanvas* setupCanvas(int width, int height); | 427 virtual SkCanvas* setupCanvas(int width, int height); |
404 | 428 |
| 429 /** |
| 430 * Copy src to dest; if src==NULL, set dest to empty string. |
| 431 */ |
| 432 static void CopyString(SkString* dest, const SkString* src); |
| 433 |
405 private: | 434 private: |
406 SkISize fViewport; | 435 SkISize fViewport; |
407 SkScalar fScaleFactor; | 436 SkScalar fScaleFactor; |
408 #if SK_SUPPORT_GPU | 437 #if SK_SUPPORT_GPU |
409 GrContextFactory fGrContextFactory; | 438 GrContextFactory fGrContextFactory; |
410 GrContext* fGrContext; | 439 GrContext* fGrContext; |
411 int fSampleCount; | 440 int fSampleCount; |
412 #endif | 441 #endif |
413 | 442 |
414 virtual SkString getConfigNameInternal() = 0; | 443 virtual SkString getConfigNameInternal() = 0; |
415 | 444 |
416 typedef SkRefCnt INHERITED; | 445 typedef SkRefCnt INHERITED; |
417 }; | 446 }; |
418 | 447 |
419 /** | 448 /** |
420 * This class does not do any rendering, but its render function executes record
ing, which we want | 449 * This class does not do any rendering, but its render function executes record
ing, which we want |
421 * to time. | 450 * to time. |
422 */ | 451 */ |
423 class RecordPictureRenderer : public PictureRenderer { | 452 class RecordPictureRenderer : public PictureRenderer { |
424 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 453 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
425 | 454 |
426 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } | 455 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } |
427 | 456 |
428 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } | 457 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } |
429 | 458 |
430 protected: | 459 protected: |
431 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; | 460 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
432 | 461 |
433 private: | 462 private: |
434 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 463 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
435 }; | 464 }; |
436 | 465 |
437 class PipePictureRenderer : public PictureRenderer { | 466 class PipePictureRenderer : public PictureRenderer { |
438 public: | 467 public: |
439 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 468 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
440 | 469 |
441 private: | 470 private: |
442 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 471 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
443 | 472 |
444 typedef PictureRenderer INHERITED; | 473 typedef PictureRenderer INHERITED; |
445 }; | 474 }; |
446 | 475 |
447 class SimplePictureRenderer : public PictureRenderer { | 476 class SimplePictureRenderer : public PictureRenderer { |
448 public: | 477 public: |
449 virtual void init(SkPicture* pict) SK_OVERRIDE; | 478 virtual void init(SkPicture* pict, const SkString* outputDir, |
| 479 const SkString* inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
450 | 480 |
451 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 481 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
452 | 482 |
453 private: | 483 private: |
454 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 484 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
455 | 485 |
456 typedef PictureRenderer INHERITED; | 486 typedef PictureRenderer INHERITED; |
457 }; | 487 }; |
458 | 488 |
459 class TiledPictureRenderer : public PictureRenderer { | 489 class TiledPictureRenderer : public PictureRenderer { |
460 public: | 490 public: |
461 TiledPictureRenderer(); | 491 TiledPictureRenderer(); |
462 | 492 |
463 virtual void init(SkPicture* pict) SK_OVERRIDE; | 493 virtual void init(SkPicture* pict, const SkString* outputDir, |
| 494 const SkString* inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
464 | 495 |
465 /** | 496 /** |
466 * Renders to tiles, rather than a single canvas. If a path is provided, a s
eparate file is | 497 * Renders to tiles, rather than a single canvas. |
| 498 * If fOutputDir was provided, a separate file is |
467 * created for each tile, named "path0.png", "path1.png", etc. | 499 * created for each tile, named "path0.png", "path1.png", etc. |
468 * Multithreaded mode currently does not support writing to a file. | 500 * Multithreaded mode currently does not support writing to a file. |
469 */ | 501 */ |
470 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE
; | 502 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
471 | 503 |
472 virtual void end() SK_OVERRIDE; | 504 virtual void end() SK_OVERRIDE; |
473 | 505 |
474 void setTileWidth(int width) { | 506 void setTileWidth(int width) { |
475 fTileWidth = width; | 507 fTileWidth = width; |
476 } | 508 } |
477 | 509 |
478 int getTileWidth() const { | 510 int getTileWidth() const { |
479 return fTileWidth; | 511 return fTileWidth; |
480 } | 512 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 }; | 608 }; |
577 | 609 |
578 class CloneData; | 610 class CloneData; |
579 | 611 |
580 class MultiCorePictureRenderer : public TiledPictureRenderer { | 612 class MultiCorePictureRenderer : public TiledPictureRenderer { |
581 public: | 613 public: |
582 explicit MultiCorePictureRenderer(int threadCount); | 614 explicit MultiCorePictureRenderer(int threadCount); |
583 | 615 |
584 ~MultiCorePictureRenderer(); | 616 ~MultiCorePictureRenderer(); |
585 | 617 |
586 virtual void init(SkPicture* pict) SK_OVERRIDE; | 618 virtual void init(SkPicture* pict, const SkString* outputDir, |
| 619 const SkString* inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
587 | 620 |
588 /** | 621 /** |
589 * Behaves like TiledPictureRenderer::render(), only using multiple threads. | 622 * Behaves like TiledPictureRenderer::render(), only using multiple threads. |
590 */ | 623 */ |
591 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE
; | 624 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
592 | 625 |
593 virtual void end() SK_OVERRIDE; | 626 virtual void end() SK_OVERRIDE; |
594 | 627 |
595 virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } | 628 virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } |
596 | 629 |
597 private: | 630 private: |
598 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 631 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
599 | 632 |
600 const int fNumThreads; | 633 const int fNumThreads; |
601 SkTDArray<SkCanvas*> fCanvasPool; | 634 SkTDArray<SkCanvas*> fCanvasPool; |
602 SkThreadPool fThreadPool; | 635 SkThreadPool fThreadPool; |
603 SkPicture* fPictureClones; | 636 SkPicture* fPictureClones; |
604 CloneData** fCloneData; | 637 CloneData** fCloneData; |
605 SkCountdown fCountdown; | 638 SkCountdown fCountdown; |
606 | 639 |
607 typedef TiledPictureRenderer INHERITED; | 640 typedef TiledPictureRenderer INHERITED; |
608 }; | 641 }; |
609 | 642 |
610 /** | 643 /** |
611 * This class does not do any rendering, but its render function executes turnin
g an SkPictureRecord | 644 * This class does not do any rendering, but its render function executes turnin
g an SkPictureRecord |
612 * into an SkPicturePlayback, which we want to time. | 645 * into an SkPicturePlayback, which we want to time. |
613 */ | 646 */ |
614 class PlaybackCreationRenderer : public PictureRenderer { | 647 class PlaybackCreationRenderer : public PictureRenderer { |
615 public: | 648 public: |
616 virtual void setup() SK_OVERRIDE; | 649 virtual void setup() SK_OVERRIDE; |
617 | 650 |
618 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 651 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
619 | 652 |
620 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } | 653 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } |
621 | 654 |
622 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } | 655 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } |
623 | 656 |
624 private: | 657 private: |
625 SkAutoTUnref<SkPicture> fReplayer; | 658 SkAutoTUnref<SkPicture> fReplayer; |
626 | 659 |
627 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 660 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
628 | 661 |
629 typedef PictureRenderer INHERITED; | 662 typedef PictureRenderer INHERITED; |
630 }; | 663 }; |
631 | 664 |
632 extern PictureRenderer* CreateGatherPixelRefsRenderer(); | 665 extern PictureRenderer* CreateGatherPixelRefsRenderer(); |
633 extern PictureRenderer* CreatePictureCloneRenderer(); | 666 extern PictureRenderer* CreatePictureCloneRenderer(); |
634 | 667 |
635 } | 668 } |
636 | 669 |
637 #endif // PictureRenderer_DEFINED | 670 #endif // PictureRenderer_DEFINED |
OLD | NEW |