| 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 #include "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
| 9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
| 10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 SkGPipeWriter writer; | 391 SkGPipeWriter writer; |
| 392 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 392 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
| 393 pipeCanvas->drawPicture(*fPicture); | 393 pipeCanvas->drawPicture(*fPicture); |
| 394 writer.endRecording(); | 394 writer.endRecording(); |
| 395 fCanvas->flush(); | 395 fCanvas->flush(); |
| 396 if (NULL != out) { | 396 if (NULL != out) { |
| 397 *out = SkNEW(SkBitmap); | 397 *out = SkNEW(SkBitmap); |
| 398 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 398 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
| 399 fCanvas->readPixels(*out, 0, 0); | 399 fCanvas->readPixels(*out, 0, 0); |
| 400 } | 400 } |
| 401 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummar
yPtr, | 401 if (fEnableWrites) { |
| 402 fUseChecksumBasedFilenames); | 402 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, |
| 403 fUseChecksumBasedFilenames); |
| 404 } else { |
| 405 return true; |
| 406 } |
| 403 } | 407 } |
| 404 | 408 |
| 405 SkString PipePictureRenderer::getConfigNameInternal() { | 409 SkString PipePictureRenderer::getConfigNameInternal() { |
| 406 return SkString("pipe"); | 410 return SkString("pipe"); |
| 407 } | 411 } |
| 408 | 412 |
| 409 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 413 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 410 | 414 |
| 411 void SimplePictureRenderer::init(SkPicture* picture, const SkString* writePath, | 415 void SimplePictureRenderer::init(SkPicture* picture, const SkString* writePath, |
| 412 const SkString* mismatchPath, const SkString* i
nputFilename, | 416 const SkString* mismatchPath, const SkString* i
nputFilename, |
| 413 bool useChecksumBasedFilenames) { | 417 bool useChecksumBasedFilenames) { |
| 414 INHERITED::init(picture, writePath, mismatchPath, inputFilename, useChecksum
BasedFilenames); | 418 INHERITED::init(picture, writePath, mismatchPath, inputFilename, useChecksum
BasedFilenames); |
| 415 this->buildBBoxHierarchy(); | 419 this->buildBBoxHierarchy(); |
| 416 } | 420 } |
| 417 | 421 |
| 418 bool SimplePictureRenderer::render(SkBitmap** out) { | 422 bool SimplePictureRenderer::render(SkBitmap** out) { |
| 419 SkASSERT(fCanvas.get() != NULL); | 423 SkASSERT(fCanvas.get() != NULL); |
| 420 SkASSERT(NULL != fPicture); | 424 SkASSERT(NULL != fPicture); |
| 421 if (NULL == fCanvas.get() || NULL == fPicture) { | 425 if (NULL == fCanvas.get() || NULL == fPicture) { |
| 422 return false; | 426 return false; |
| 423 } | 427 } |
| 424 | 428 |
| 425 fCanvas->drawPicture(*fPicture); | 429 fCanvas->drawPicture(*fPicture); |
| 426 fCanvas->flush(); | 430 fCanvas->flush(); |
| 427 if (NULL != out) { | 431 if (NULL != out) { |
| 428 *out = SkNEW(SkBitmap); | 432 *out = SkNEW(SkBitmap); |
| 429 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 433 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
| 430 fCanvas->readPixels(*out, 0, 0); | 434 fCanvas->readPixels(*out, 0, 0); |
| 431 } | 435 } |
| 432 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummar
yPtr, | 436 if (fEnableWrites) { |
| 433 fUseChecksumBasedFilenames); | 437 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, |
| 438 fUseChecksumBasedFilenames); |
| 439 } else { |
| 440 return true; |
| 441 } |
| 434 } | 442 } |
| 435 | 443 |
| 436 SkString SimplePictureRenderer::getConfigNameInternal() { | 444 SkString SimplePictureRenderer::getConfigNameInternal() { |
| 437 return SkString("simple"); | 445 return SkString("simple"); |
| 438 } | 446 } |
| 439 | 447 |
| 440 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 448 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 441 | 449 |
| 442 TiledPictureRenderer::TiledPictureRenderer() | 450 TiledPictureRenderer::TiledPictureRenderer() |
| 443 : fTileWidth(kDefaultTileWidth) | 451 : fTileWidth(kDefaultTileWidth) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 641 |
| 634 SkBitmap bitmap; | 642 SkBitmap bitmap; |
| 635 if (out){ | 643 if (out){ |
| 636 *out = SkNEW(SkBitmap); | 644 *out = SkNEW(SkBitmap); |
| 637 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 645 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
| 638 setup_bitmap(&bitmap, fTileWidth, fTileHeight); | 646 setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
| 639 } | 647 } |
| 640 bool success = true; | 648 bool success = true; |
| 641 for (int i = 0; i < fTileRects.count(); ++i) { | 649 for (int i = 0; i < fTileRects.count(); ++i) { |
| 642 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); | 650 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); |
| 643 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJs
onSummaryPtr, | 651 if (fEnableWrites) { |
| 644 fUseChecksumBasedFilenames, &i); | 652 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename,
fJsonSummaryPtr, |
| 653 fUseChecksumBasedFilenames, &i); |
| 654 } |
| 645 if (NULL != out) { | 655 if (NULL != out) { |
| 646 if (fCanvas->readPixels(&bitmap, 0, 0)) { | 656 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
| 647 // Add this tile to the entire bitmap. | 657 // Add this tile to the entire bitmap. |
| 648 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i
].left()), | 658 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i
].left()), |
| 649 SkScalarFloorToInt(fTileRects[i].top())); | 659 SkScalarFloorToInt(fTileRects[i].top())); |
| 650 } else { | 660 } else { |
| 651 success = false; | 661 success = false; |
| 652 } | 662 } |
| 653 } | 663 } |
| 654 } | 664 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 703 } |
| 694 | 704 |
| 695 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 705 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 696 | 706 |
| 697 // Holds all of the information needed to draw a set of tiles. | 707 // Holds all of the information needed to draw a set of tiles. |
| 698 class CloneData : public SkRunnable { | 708 class CloneData : public SkRunnable { |
| 699 | 709 |
| 700 public: | 710 public: |
| 701 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int
start, int end, | 711 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int
start, int end, |
| 702 SkRunnable* done, ImageResultsAndExpectations* jsonSummaryPtr, | 712 SkRunnable* done, ImageResultsAndExpectations* jsonSummaryPtr, |
| 703 bool useChecksumBasedFilenames) | 713 bool useChecksumBasedFilenames, bool enableWrites) |
| 704 : fClone(clone) | 714 : fClone(clone) |
| 705 , fCanvas(canvas) | 715 , fCanvas(canvas) |
| 716 , fEnableWrites(enableWrites) |
| 706 , fRects(rects) | 717 , fRects(rects) |
| 707 , fStart(start) | 718 , fStart(start) |
| 708 , fEnd(end) | 719 , fEnd(end) |
| 709 , fSuccess(NULL) | 720 , fSuccess(NULL) |
| 710 , fDone(done) | 721 , fDone(done) |
| 711 , fJsonSummaryPtr(jsonSummaryPtr) | 722 , fJsonSummaryPtr(jsonSummaryPtr) |
| 712 , fUseChecksumBasedFilenames(useChecksumBasedFilenames) { | 723 , fUseChecksumBasedFilenames(useChecksumBasedFilenames) { |
| 713 SkASSERT(fDone != NULL); | 724 SkASSERT(fDone != NULL); |
| 714 } | 725 } |
| 715 | 726 |
| 716 virtual void run() SK_OVERRIDE { | 727 virtual void run() SK_OVERRIDE { |
| 717 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); | 728 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); |
| 718 | 729 |
| 719 SkBitmap bitmap; | 730 SkBitmap bitmap; |
| 720 if (fBitmap != NULL) { | 731 if (fBitmap != NULL) { |
| 721 // All tiles are the same size. | 732 // All tiles are the same size. |
| 722 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); | 733 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); |
| 723 } | 734 } |
| 724 | 735 |
| 725 for (int i = fStart; i < fEnd; i++) { | 736 for (int i = fStart; i < fEnd; i++) { |
| 726 draw_tile_to_canvas(fCanvas, fRects[i], fClone); | 737 draw_tile_to_canvas(fCanvas, fRects[i], fClone); |
| 727 if (!write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJson
SummaryPtr, | 738 if (fEnableWrites) { |
| 728 fUseChecksumBasedFilenames, &i) | 739 if (!write(fCanvas, fWritePath, fMismatchPath, fInputFilename, f
JsonSummaryPtr, |
| 729 && fSuccess != NULL) { | 740 fUseChecksumBasedFilenames, &i) |
| 730 *fSuccess = false; | 741 && fSuccess != NULL) { |
| 731 // If one tile fails to write to a file, do not continue drawing
the rest. | |
| 732 break; | |
| 733 } | |
| 734 if (fBitmap != NULL) { | |
| 735 if (fCanvas->readPixels(&bitmap, 0, 0)) { | |
| 736 SkAutoLockPixels alp(*fBitmap); | |
| 737 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect
s[i].left()), | |
| 738 SkScalarFloorToInt(fRects[i].top())); | |
| 739 } else { | |
| 740 *fSuccess = false; | 742 *fSuccess = false; |
| 741 // If one tile fails to read pixels, do not continue drawing
the rest. | 743 // If one tile fails to write to a file, do not continue dra
wing the rest. |
| 742 break; | 744 break; |
| 743 } | 745 } |
| 746 if (fBitmap != NULL) { |
| 747 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
| 748 SkAutoLockPixels alp(*fBitmap); |
| 749 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(f
Rects[i].left()), |
| 750 SkScalarFloorToInt(fRects[i].top())); |
| 751 } else { |
| 752 *fSuccess = false; |
| 753 // If one tile fails to read pixels, do not continue dra
wing the rest. |
| 754 break; |
| 755 } |
| 756 } |
| 744 } | 757 } |
| 745 } | 758 } |
| 746 fDone->run(); | 759 fDone->run(); |
| 747 } | 760 } |
| 748 | 761 |
| 749 void setPathsAndSuccess(const SkString& writePath, const SkString& mismatchP
ath, | 762 void setPathsAndSuccess(const SkString& writePath, const SkString& mismatchP
ath, |
| 750 const SkString& inputFilename, bool* success) { | 763 const SkString& inputFilename, bool* success) { |
| 751 fWritePath.set(writePath); | 764 fWritePath.set(writePath); |
| 752 fMismatchPath.set(mismatchPath); | 765 fMismatchPath.set(mismatchPath); |
| 753 fInputFilename.set(inputFilename); | 766 fInputFilename.set(inputFilename); |
| 754 fSuccess = success; | 767 fSuccess = success; |
| 755 } | 768 } |
| 756 | 769 |
| 757 void setBitmap(SkBitmap* bitmap) { | 770 void setBitmap(SkBitmap* bitmap) { |
| 758 fBitmap = bitmap; | 771 fBitmap = bitmap; |
| 759 } | 772 } |
| 760 | 773 |
| 761 private: | 774 private: |
| 762 // All pointers unowned. | 775 // All pointers unowned. |
| 763 SkPicture* fClone; // Picture to draw from. Each CloneData has
a unique one which | 776 SkPicture* fClone; // Picture to draw from. Each CloneData has
a unique one which |
| 764 // is threadsafe. | 777 // is threadsafe. |
| 765 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. | 778 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. |
| 779 bool fEnableWrites; // TODO(epoger): Temporary hack; see decla
ration of |
| 780 // fEnableWrites in PictureRenderer.h. |
| 766 SkString fWritePath; // If not empty, write all results into this
directory. | 781 SkString fWritePath; // If not empty, write all results into this
directory. |
| 767 SkString fMismatchPath; // If not empty, write all unexpected res
ults into this dir. | 782 SkString fMismatchPath; // If not empty, write all unexpected res
ults into this dir. |
| 768 SkString fInputFilename; // Filename of input SkPicture file. | 783 SkString fInputFilename; // Filename of input SkPicture file. |
| 769 SkTDArray<SkRect>& fRects; // All tiles of the picture. | 784 SkTDArray<SkRect>& fRects; // All tiles of the picture. |
| 770 const int fStart; // Range of tiles drawn by this thread. | 785 const int fStart; // Range of tiles drawn by this thread. |
| 771 const int fEnd; | 786 const int fEnd; |
| 772 bool* fSuccess; // Only meaningful if path is non-null. Shar
ed by all threads, | 787 bool* fSuccess; // Only meaningful if path is non-null. Shar
ed by all threads, |
| 773 // and only set to false upon failure to wri
te to a PNG. | 788 // and only set to false upon failure to wri
te to a PNG. |
| 774 SkRunnable* fDone; | 789 SkRunnable* fDone; |
| 775 SkBitmap* fBitmap; | 790 SkBitmap* fBitmap; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 806 if (i == fNumThreads-1) { | 821 if (i == fNumThreads-1) { |
| 807 // The last set will use the original SkPicture. | 822 // The last set will use the original SkPicture. |
| 808 pic = fPicture; | 823 pic = fPicture; |
| 809 } else { | 824 } else { |
| 810 pic = &fPictureClones[i]; | 825 pic = &fPictureClones[i]; |
| 811 } | 826 } |
| 812 const int start = i * chunkSize; | 827 const int start = i * chunkSize; |
| 813 const int end = SkMin32(start + chunkSize, fTileRects.count()); | 828 const int end = SkMin32(start + chunkSize, fTileRects.count()); |
| 814 fCloneData[i] = SkNEW_ARGS(CloneData, | 829 fCloneData[i] = SkNEW_ARGS(CloneData, |
| 815 (pic, fCanvasPool[i], fTileRects, start, end,
&fCountdown, | 830 (pic, fCanvasPool[i], fTileRects, start, end,
&fCountdown, |
| 816 fJsonSummaryPtr, useChecksumBasedFilenames))
; | 831 fJsonSummaryPtr, useChecksumBasedFilenames,
fEnableWrites)); |
| 817 } | 832 } |
| 818 } | 833 } |
| 819 | 834 |
| 820 bool MultiCorePictureRenderer::render(SkBitmap** out) { | 835 bool MultiCorePictureRenderer::render(SkBitmap** out) { |
| 821 bool success = true; | 836 bool success = true; |
| 822 if (!fWritePath.isEmpty() || !fMismatchPath.isEmpty()) { | 837 if (!fWritePath.isEmpty() || !fMismatchPath.isEmpty()) { |
| 823 for (int i = 0; i < fNumThreads-1; i++) { | 838 for (int i = 0; i < fNumThreads-1; i++) { |
| 824 fCloneData[i]->setPathsAndSuccess(fWritePath, fMismatchPath, fInputF
ilename, &success); | 839 fCloneData[i]->setPathsAndSuccess(fWritePath, fMismatchPath, fInputF
ilename, &success); |
| 825 } | 840 } |
| 826 } | 841 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 964 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
| 950 return SkString("picture_clone"); | 965 return SkString("picture_clone"); |
| 951 } | 966 } |
| 952 }; | 967 }; |
| 953 | 968 |
| 954 PictureRenderer* CreatePictureCloneRenderer() { | 969 PictureRenderer* CreatePictureCloneRenderer() { |
| 955 return SkNEW(PictureCloneRenderer); | 970 return SkNEW(PictureCloneRenderer); |
| 956 } | 971 } |
| 957 | 972 |
| 958 } // namespace sk_tools | 973 } // namespace sk_tools |
| OLD | NEW |