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 empty string if this renderer should not write files at all. |
| 120 * @param intputFilename 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 |
(...skipping 25 matching lines...) Expand all Loading... |
414 virtual SkString getConfigNameInternal() = 0; | 438 virtual SkString getConfigNameInternal() = 0; |
415 | 439 |
416 typedef SkRefCnt INHERITED; | 440 typedef SkRefCnt INHERITED; |
417 }; | 441 }; |
418 | 442 |
419 /** | 443 /** |
420 * This class does not do any rendering, but its render function executes record
ing, which we want | 444 * This class does not do any rendering, but its render function executes record
ing, which we want |
421 * to time. | 445 * to time. |
422 */ | 446 */ |
423 class RecordPictureRenderer : public PictureRenderer { | 447 class RecordPictureRenderer : public PictureRenderer { |
424 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 448 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
425 | 449 |
426 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } | 450 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } |
427 | 451 |
428 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } | 452 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } |
429 | 453 |
430 protected: | 454 protected: |
431 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; | 455 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
432 | 456 |
433 private: | 457 private: |
434 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 458 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
435 }; | 459 }; |
436 | 460 |
437 class PipePictureRenderer : public PictureRenderer { | 461 class PipePictureRenderer : public PictureRenderer { |
438 public: | 462 public: |
439 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 463 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
440 | 464 |
441 private: | 465 private: |
442 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 466 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
443 | 467 |
444 typedef PictureRenderer INHERITED; | 468 typedef PictureRenderer INHERITED; |
445 }; | 469 }; |
446 | 470 |
447 class SimplePictureRenderer : public PictureRenderer { | 471 class SimplePictureRenderer : public PictureRenderer { |
448 public: | 472 public: |
449 virtual void init(SkPicture* pict) SK_OVERRIDE; | 473 virtual void init(SkPicture* pict, const SkString& outputDir, |
| 474 const SkString& inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
450 | 475 |
451 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 476 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
452 | 477 |
453 private: | 478 private: |
454 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 479 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
455 | 480 |
456 typedef PictureRenderer INHERITED; | 481 typedef PictureRenderer INHERITED; |
457 }; | 482 }; |
458 | 483 |
459 class TiledPictureRenderer : public PictureRenderer { | 484 class TiledPictureRenderer : public PictureRenderer { |
460 public: | 485 public: |
461 TiledPictureRenderer(); | 486 TiledPictureRenderer(); |
462 | 487 |
463 virtual void init(SkPicture* pict) SK_OVERRIDE; | 488 virtual void init(SkPicture* pict, const SkString& outputDir, |
| 489 const SkString& inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
464 | 490 |
465 /** | 491 /** |
466 * Renders to tiles, rather than a single canvas. If a path is provided, a s
eparate file is | 492 * Renders to tiles, rather than a single canvas. |
| 493 * If fOutputDir was provided, a separate file is |
467 * created for each tile, named "path0.png", "path1.png", etc. | 494 * created for each tile, named "path0.png", "path1.png", etc. |
468 * Multithreaded mode currently does not support writing to a file. | 495 * Multithreaded mode currently does not support writing to a file. |
469 */ | 496 */ |
470 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE
; | 497 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
471 | 498 |
472 virtual void end() SK_OVERRIDE; | 499 virtual void end() SK_OVERRIDE; |
473 | 500 |
474 void setTileWidth(int width) { | 501 void setTileWidth(int width) { |
475 fTileWidth = width; | 502 fTileWidth = width; |
476 } | 503 } |
477 | 504 |
478 int getTileWidth() const { | 505 int getTileWidth() const { |
479 return fTileWidth; | 506 return fTileWidth; |
480 } | 507 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 }; | 603 }; |
577 | 604 |
578 class CloneData; | 605 class CloneData; |
579 | 606 |
580 class MultiCorePictureRenderer : public TiledPictureRenderer { | 607 class MultiCorePictureRenderer : public TiledPictureRenderer { |
581 public: | 608 public: |
582 explicit MultiCorePictureRenderer(int threadCount); | 609 explicit MultiCorePictureRenderer(int threadCount); |
583 | 610 |
584 ~MultiCorePictureRenderer(); | 611 ~MultiCorePictureRenderer(); |
585 | 612 |
586 virtual void init(SkPicture* pict) SK_OVERRIDE; | 613 virtual void init(SkPicture* pict, const SkString& outputDir, |
| 614 const SkString& inputFilename, bool useChecksumBasedFilena
mes) SK_OVERRIDE; |
587 | 615 |
588 /** | 616 /** |
589 * Behaves like TiledPictureRenderer::render(), only using multiple threads. | 617 * Behaves like TiledPictureRenderer::render(), only using multiple threads. |
590 */ | 618 */ |
591 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE
; | 619 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
592 | 620 |
593 virtual void end() SK_OVERRIDE; | 621 virtual void end() SK_OVERRIDE; |
594 | 622 |
595 virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } | 623 virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } |
596 | 624 |
597 private: | 625 private: |
598 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 626 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
599 | 627 |
600 const int fNumThreads; | 628 const int fNumThreads; |
601 SkTDArray<SkCanvas*> fCanvasPool; | 629 SkTDArray<SkCanvas*> fCanvasPool; |
602 SkThreadPool fThreadPool; | 630 SkThreadPool fThreadPool; |
603 SkPicture* fPictureClones; | 631 SkPicture* fPictureClones; |
604 CloneData** fCloneData; | 632 CloneData** fCloneData; |
605 SkCountdown fCountdown; | 633 SkCountdown fCountdown; |
606 | 634 |
607 typedef TiledPictureRenderer INHERITED; | 635 typedef TiledPictureRenderer INHERITED; |
608 }; | 636 }; |
609 | 637 |
610 /** | 638 /** |
611 * This class does not do any rendering, but its render function executes turnin
g an SkPictureRecord | 639 * 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. | 640 * into an SkPicturePlayback, which we want to time. |
613 */ | 641 */ |
614 class PlaybackCreationRenderer : public PictureRenderer { | 642 class PlaybackCreationRenderer : public PictureRenderer { |
615 public: | 643 public: |
616 virtual void setup() SK_OVERRIDE; | 644 virtual void setup() SK_OVERRIDE; |
617 | 645 |
618 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE; | 646 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
619 | 647 |
620 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } | 648 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"
); } |
621 | 649 |
622 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } | 650 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"
); } |
623 | 651 |
624 private: | 652 private: |
625 SkAutoTUnref<SkPicture> fReplayer; | 653 SkAutoTUnref<SkPicture> fReplayer; |
626 | 654 |
627 virtual SkString getConfigNameInternal() SK_OVERRIDE; | 655 virtual SkString getConfigNameInternal() SK_OVERRIDE; |
628 | 656 |
629 typedef PictureRenderer INHERITED; | 657 typedef PictureRenderer INHERITED; |
630 }; | 658 }; |
631 | 659 |
632 extern PictureRenderer* CreateGatherPixelRefsRenderer(); | 660 extern PictureRenderer* CreateGatherPixelRefsRenderer(); |
633 extern PictureRenderer* CreatePictureCloneRenderer(); | 661 extern PictureRenderer* CreatePictureCloneRenderer(); |
634 | 662 |
635 } | 663 } |
636 | 664 |
637 #endif // PictureRenderer_DEFINED | 665 #endif // PictureRenderer_DEFINED |
OLD | NEW |