| 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 SkIntToScalar(fTileHeigh
t)); | 563 SkIntToScalar(fTileHeigh
t)); |
| 564 tile_x_start += current_width; | 564 tile_x_start += current_width; |
| 565 } | 565 } |
| 566 | 566 |
| 567 current_width >>= 1; | 567 current_width >>= 1; |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 | 571 |
| 572 /** | 572 /** |
| 573 * Draw the specified playback to the canvas translated to rectangle provided, s
o that this mini | 573 * Draw the specified picture to the canvas translated to rectangle provided, so
that this mini |
| 574 * canvas represents the rectangle's portion of the overall picture. | 574 * canvas represents the rectangle's portion of the overall picture. |
| 575 * Saves and restores so that the initial clip and matrix return to their state
before this function | 575 * Saves and restores so that the initial clip and matrix return to their state
before this function |
| 576 * is called. | 576 * is called. |
| 577 */ | 577 */ |
| 578 template<class T> | 578 static void draw_tile_to_canvas(SkCanvas* canvas, const SkRect& tileRect, SkPict
ure* picture) { |
| 579 static void DrawTileToCanvas(SkCanvas* canvas, const SkRect& tileRect, T* playba
ck) { | |
| 580 int saveCount = canvas->save(); | 579 int saveCount = canvas->save(); |
| 581 // Translate so that we draw the correct portion of the picture. | 580 // Translate so that we draw the correct portion of the picture. |
| 582 // Perform a postTranslate so that the scaleFactor does not interfere with t
he positioning. | 581 // Perform a postTranslate so that the scaleFactor does not interfere with t
he positioning. |
| 583 SkMatrix mat(canvas->getTotalMatrix()); | 582 SkMatrix mat(canvas->getTotalMatrix()); |
| 584 mat.postTranslate(-tileRect.fLeft, -tileRect.fTop); | 583 mat.postTranslate(-tileRect.fLeft, -tileRect.fTop); |
| 585 canvas->setMatrix(mat); | 584 canvas->setMatrix(mat); |
| 586 playback->draw(canvas); | 585 canvas->drawPicture(*picture); |
| 587 canvas->restoreToCount(saveCount); | 586 canvas->restoreToCount(saveCount); |
| 588 canvas->flush(); | 587 canvas->flush(); |
| 589 } | 588 } |
| 590 | 589 |
| 591 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 590 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 592 | 591 |
| 593 /** | 592 /** |
| 594 * Copies the entirety of the src bitmap (typically a tile) into a portion of th
e dst bitmap. | 593 * Copies the entirety of the src bitmap (typically a tile) into a portion of th
e dst bitmap. |
| 595 * If the src bitmap is too large to fit within the dst bitmap after the x and y | 594 * If the src bitmap is too large to fit within the dst bitmap after the x and y |
| 596 * offsets have been applied, any excess will be ignored (so only the top-left p
ortion of the | 595 * offsets have been applied, any excess will be ignored (so only the top-left p
ortion of the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 614 if (++fCurrentTileOffset < fTileRects.count()) { | 613 if (++fCurrentTileOffset < fTileRects.count()) { |
| 615 i = fCurrentTileOffset % fTilesX; | 614 i = fCurrentTileOffset % fTilesX; |
| 616 j = fCurrentTileOffset / fTilesX; | 615 j = fCurrentTileOffset / fTilesX; |
| 617 return true; | 616 return true; |
| 618 } | 617 } |
| 619 return false; | 618 return false; |
| 620 } | 619 } |
| 621 | 620 |
| 622 void TiledPictureRenderer::drawCurrentTile() { | 621 void TiledPictureRenderer::drawCurrentTile() { |
| 623 SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count())
; | 622 SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count())
; |
| 624 DrawTileToCanvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture); | 623 draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture); |
| 625 } | 624 } |
| 626 | 625 |
| 627 bool TiledPictureRenderer::render(const SkString* path, SkBitmap** out) { | 626 bool TiledPictureRenderer::render(const SkString* path, SkBitmap** out) { |
| 628 SkASSERT(fPicture != NULL); | 627 SkASSERT(fPicture != NULL); |
| 629 if (NULL == fPicture) { | 628 if (NULL == fPicture) { |
| 630 return false; | 629 return false; |
| 631 } | 630 } |
| 632 | 631 |
| 633 SkBitmap bitmap; | 632 SkBitmap bitmap; |
| 634 if (out){ | 633 if (out){ |
| 635 *out = SkNEW(SkBitmap); | 634 *out = SkNEW(SkBitmap); |
| 636 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 635 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
| 637 setup_bitmap(&bitmap, fTileWidth, fTileHeight); | 636 setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
| 638 } | 637 } |
| 639 bool success = true; | 638 bool success = true; |
| 640 for (int i = 0; i < fTileRects.count(); ++i) { | 639 for (int i = 0; i < fTileRects.count(); ++i) { |
| 641 DrawTileToCanvas(fCanvas, fTileRects[i], fPicture); | 640 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); |
| 642 if (NULL != path) { | 641 if (NULL != path) { |
| 643 success &= writeAppendNumber(fCanvas, path, i, fJsonSummaryPtr); | 642 success &= writeAppendNumber(fCanvas, path, i, fJsonSummaryPtr); |
| 644 } | 643 } |
| 645 if (NULL != out) { | 644 if (NULL != out) { |
| 646 if (fCanvas->readPixels(&bitmap, 0, 0)) { | 645 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
| 647 // Add this tile to the entire bitmap. | 646 // Add this tile to the entire bitmap. |
| 648 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i
].left()), | 647 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i
].left()), |
| 649 SkScalarFloorToInt(fTileRects[i].top())); | 648 SkScalarFloorToInt(fTileRects[i].top())); |
| 650 } else { | 649 } else { |
| 651 success = false; | 650 success = false; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 virtual void run() SK_OVERRIDE { | 714 virtual void run() SK_OVERRIDE { |
| 716 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); | 715 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); |
| 717 | 716 |
| 718 SkBitmap bitmap; | 717 SkBitmap bitmap; |
| 719 if (fBitmap != NULL) { | 718 if (fBitmap != NULL) { |
| 720 // All tiles are the same size. | 719 // All tiles are the same size. |
| 721 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); | 720 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); |
| 722 } | 721 } |
| 723 | 722 |
| 724 for (int i = fStart; i < fEnd; i++) { | 723 for (int i = fStart; i < fEnd; i++) { |
| 725 DrawTileToCanvas(fCanvas, fRects[i], fClone); | 724 draw_tile_to_canvas(fCanvas, fRects[i], fClone); |
| 726 if ((fPath != NULL) && !writeAppendNumber(fCanvas, fPath, i, fJsonSu
mmaryPtr) | 725 if ((fPath != NULL) && !writeAppendNumber(fCanvas, fPath, i, fJsonSu
mmaryPtr) |
| 727 && fSuccess != NULL) { | 726 && fSuccess != NULL) { |
| 728 *fSuccess = false; | 727 *fSuccess = false; |
| 729 // If one tile fails to write to a file, do not continue drawing
the rest. | 728 // If one tile fails to write to a file, do not continue drawing
the rest. |
| 730 break; | 729 break; |
| 731 } | 730 } |
| 732 if (fBitmap != NULL) { | 731 if (fBitmap != NULL) { |
| 733 if (fCanvas->readPixels(&bitmap, 0, 0)) { | 732 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
| 734 SkAutoLockPixels alp(*fBitmap); | 733 SkAutoLockPixels alp(*fBitmap); |
| 735 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect
s[i].left()), | 734 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect
s[i].left()), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 953 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
| 955 return SkString("picture_clone"); | 954 return SkString("picture_clone"); |
| 956 } | 955 } |
| 957 }; | 956 }; |
| 958 | 957 |
| 959 PictureRenderer* CreatePictureCloneRenderer() { | 958 PictureRenderer* CreatePictureCloneRenderer() { |
| 960 return SkNEW(PictureCloneRenderer); | 959 return SkNEW(PictureCloneRenderer); |
| 961 } | 960 } |
| 962 | 961 |
| 963 } // namespace sk_tools | 962 } // namespace sk_tools |
| OLD | NEW |