| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 void PictureRenderer::end() { | 186 void PictureRenderer::end() { |
| 187 this->resetState(true); | 187 this->resetState(true); |
| 188 fPicture.reset(NULL); | 188 fPicture.reset(NULL); |
| 189 fCanvas.reset(NULL); | 189 fCanvas.reset(NULL); |
| 190 } | 190 } |
| 191 | 191 |
| 192 int PictureRenderer::getViewWidth() { | 192 int PictureRenderer::getViewWidth() { |
| 193 SkASSERT(fPicture != NULL); | 193 SkASSERT(fPicture != NULL); |
| 194 int width = SkScalarCeilToInt(fPicture->width() * fScaleFactor); | 194 int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor); |
| 195 if (fViewport.width() > 0) { | 195 if (fViewport.width() > 0) { |
| 196 width = SkMin32(width, fViewport.width()); | 196 width = SkMin32(width, fViewport.width()); |
| 197 } | 197 } |
| 198 return width; | 198 return width; |
| 199 } | 199 } |
| 200 | 200 |
| 201 int PictureRenderer::getViewHeight() { | 201 int PictureRenderer::getViewHeight() { |
| 202 SkASSERT(fPicture != NULL); | 202 SkASSERT(fPicture != NULL); |
| 203 int height = SkScalarCeilToInt(fPicture->height() * fScaleFactor); | 203 int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor)
; |
| 204 if (fViewport.height() > 0) { | 204 if (fViewport.height() > 0) { |
| 205 height = SkMin32(height, fViewport.height()); | 205 height = SkMin32(height, fViewport.height()); |
| 206 } | 206 } |
| 207 return height; | 207 return height; |
| 208 } | 208 } |
| 209 | 209 |
| 210 /** Converts fPicture to a picture that uses a BBoxHierarchy. | 210 /** Converts fPicture to a picture that uses a BBoxHierarchy. |
| 211 * PictureRenderer subclasses that are used to test picture playback | 211 * PictureRenderer subclasses that are used to test picture playback |
| 212 * should call this method during init. | 212 * should call this method during init. |
| 213 */ | 213 */ |
| 214 void PictureRenderer::buildBBoxHierarchy() { | 214 void PictureRenderer::buildBBoxHierarchy() { |
| 215 SkASSERT(NULL != fPicture); | 215 SkASSERT(NULL != fPicture); |
| 216 if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) { | 216 if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) { |
| 217 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 217 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 218 SkPictureRecorder recorder; | 218 SkPictureRecorder recorder; |
| 219 SkCanvas* canvas = recorder.beginRecording(fPicture->width(), fPicture->
height(), | 219 SkCanvas* canvas = recorder.beginRecording(fPicture->cullRect().width(),
|
| 220 fPicture->cullRect().height()
, |
| 220 factory.get(), | 221 factory.get(), |
| 221 this->recordFlags()); | 222 this->recordFlags()); |
| 222 fPicture->draw(canvas); | 223 fPicture->draw(canvas); |
| 223 fPicture.reset(recorder.endRecording()); | 224 fPicture.reset(recorder.endRecording()); |
| 224 } | 225 } |
| 225 } | 226 } |
| 226 | 227 |
| 227 void PictureRenderer::resetState(bool callFinish) { | 228 void PictureRenderer::resetState(bool callFinish) { |
| 228 #if SK_SUPPORT_GPU | 229 #if SK_SUPPORT_GPU |
| 229 SkGLContextHelper* glContext = this->getGLContext(); | 230 SkGLContextHelper* glContext = this->getGLContext(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 349 } |
| 349 | 350 |
| 350 // the size_t* parameter is deprecated, so we ignore it | 351 // the size_t* parameter is deprecated, so we ignore it |
| 351 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 352 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
| 352 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 353 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
| 353 } | 354 } |
| 354 | 355 |
| 355 bool RecordPictureRenderer::render(SkBitmap** out) { | 356 bool RecordPictureRenderer::render(SkBitmap** out) { |
| 356 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 357 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 357 SkPictureRecorder recorder; | 358 SkPictureRecorder recorder; |
| 358 SkCanvas* canvas = recorder.beginRecording(this->getViewWidth(), this->getVi
ewHeight(), | 359 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), |
| 360 SkIntToScalar(this->getViewHeight
()), |
| 359 factory.get(), | 361 factory.get(), |
| 360 this->recordFlags()); | 362 this->recordFlags()); |
| 361 this->scaleToScaleFactor(canvas); | 363 this->scaleToScaleFactor(canvas); |
| 362 fPicture->draw(canvas); | 364 fPicture->draw(canvas); |
| 363 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 365 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 364 if (!fWritePath.isEmpty()) { | 366 if (!fWritePath.isEmpty()) { |
| 365 // Record the new picture as a new SKP with PNG encoded bitmaps. | 367 // Record the new picture as a new SKP with PNG encoded bitmaps. |
| 366 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); | 368 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); |
| 367 SkFILEWStream stream(skpPath.c_str()); | 369 SkFILEWStream stream(skpPath.c_str()); |
| 368 picture->serialize(&stream, &encode_bitmap_to_data); | 370 picture->serialize(&stream, &encode_bitmap_to_data); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 385 } | 387 } |
| 386 | 388 |
| 387 PipeController pipeController(fCanvas.get()); | 389 PipeController pipeController(fCanvas.get()); |
| 388 SkGPipeWriter writer; | 390 SkGPipeWriter writer; |
| 389 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 391 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
| 390 pipeCanvas->drawPicture(fPicture); | 392 pipeCanvas->drawPicture(fPicture); |
| 391 writer.endRecording(); | 393 writer.endRecording(); |
| 392 fCanvas->flush(); | 394 fCanvas->flush(); |
| 393 if (NULL != out) { | 395 if (NULL != out) { |
| 394 *out = SkNEW(SkBitmap); | 396 *out = SkNEW(SkBitmap); |
| 395 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 397 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 398 SkScalarCeilToInt(fPicture->cullRect().height())); |
| 396 fCanvas->readPixels(*out, 0, 0); | 399 fCanvas->readPixels(*out, 0, 0); |
| 397 } | 400 } |
| 398 if (fEnableWrites) { | 401 if (fEnableWrites) { |
| 399 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, | 402 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, |
| 400 fUseChecksumBasedFilenames); | 403 fUseChecksumBasedFilenames); |
| 401 } else { | 404 } else { |
| 402 return true; | 405 return true; |
| 403 } | 406 } |
| 404 } | 407 } |
| 405 | 408 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 420 SkASSERT(fCanvas.get() != NULL); | 423 SkASSERT(fCanvas.get() != NULL); |
| 421 SkASSERT(NULL != fPicture); | 424 SkASSERT(NULL != fPicture); |
| 422 if (NULL == fCanvas.get() || NULL == fPicture) { | 425 if (NULL == fCanvas.get() || NULL == fPicture) { |
| 423 return false; | 426 return false; |
| 424 } | 427 } |
| 425 | 428 |
| 426 fCanvas->drawPicture(fPicture); | 429 fCanvas->drawPicture(fPicture); |
| 427 fCanvas->flush(); | 430 fCanvas->flush(); |
| 428 if (NULL != out) { | 431 if (NULL != out) { |
| 429 *out = SkNEW(SkBitmap); | 432 *out = SkNEW(SkBitmap); |
| 430 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 433 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 434 SkScalarCeilToInt(fPicture->cullRect().height())); |
| 431 fCanvas->readPixels(*out, 0, 0); | 435 fCanvas->readPixels(*out, 0, 0); |
| 432 } | 436 } |
| 433 if (fEnableWrites) { | 437 if (fEnableWrites) { |
| 434 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, | 438 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu
mmaryPtr, |
| 435 fUseChecksumBasedFilenames); | 439 fUseChecksumBasedFilenames); |
| 436 } else { | 440 } else { |
| 437 return true; | 441 return true; |
| 438 } | 442 } |
| 439 } | 443 } |
| 440 | 444 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not | 476 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not |
| 473 // used by bench_pictures. | 477 // used by bench_pictures. |
| 474 fPicture.reset(pict)->ref(); | 478 fPicture.reset(pict)->ref(); |
| 475 this->CopyString(&fWritePath, writePath); | 479 this->CopyString(&fWritePath, writePath); |
| 476 this->CopyString(&fMismatchPath, mismatchPath); | 480 this->CopyString(&fMismatchPath, mismatchPath); |
| 477 this->CopyString(&fInputFilename, inputFilename); | 481 this->CopyString(&fInputFilename, inputFilename); |
| 478 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 482 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
| 479 this->buildBBoxHierarchy(); | 483 this->buildBBoxHierarchy(); |
| 480 | 484 |
| 481 if (fTileWidthPercentage > 0) { | 485 if (fTileWidthPercentage > 0) { |
| 482 fTileWidth = sk_float_ceil2int(float(fTileWidthPercentage * fPicture->wi
dth() / 100)); | 486 fTileWidth = SkScalarCeilToInt(float(fTileWidthPercentage * fPicture->cu
llRect().width() / 100)); |
| 483 } | 487 } |
| 484 if (fTileHeightPercentage > 0) { | 488 if (fTileHeightPercentage > 0) { |
| 485 fTileHeight = sk_float_ceil2int(float(fTileHeightPercentage * fPicture->
height() / 100)); | 489 fTileHeight = SkScalarCeilToInt(float(fTileHeightPercentage * fPicture->
cullRect().height() / 100)); |
| 486 } | 490 } |
| 487 | 491 |
| 488 if (fTileMinPowerOf2Width > 0) { | 492 if (fTileMinPowerOf2Width > 0) { |
| 489 this->setupPowerOf2Tiles(); | 493 this->setupPowerOf2Tiles(); |
| 490 } else { | 494 } else { |
| 491 this->setupTiles(); | 495 this->setupTiles(); |
| 492 } | 496 } |
| 493 fCanvas.reset(this->setupCanvas(fTileWidth, fTileHeight)); | 497 fCanvas.reset(this->setupCanvas(fTileWidth, fTileHeight)); |
| 494 // Initialize to -1 so that the first call to nextTile will set this up to d
raw tile 0 on the | 498 // Initialize to -1 so that the first call to nextTile will set this up to d
raw tile 0 on the |
| 495 // first call to drawCurrentTile. | 499 // first call to drawCurrentTile. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 644 |
| 641 bool TiledPictureRenderer::render(SkBitmap** out) { | 645 bool TiledPictureRenderer::render(SkBitmap** out) { |
| 642 SkASSERT(fPicture != NULL); | 646 SkASSERT(fPicture != NULL); |
| 643 if (NULL == fPicture) { | 647 if (NULL == fPicture) { |
| 644 return false; | 648 return false; |
| 645 } | 649 } |
| 646 | 650 |
| 647 SkBitmap bitmap; | 651 SkBitmap bitmap; |
| 648 if (out){ | 652 if (out){ |
| 649 *out = SkNEW(SkBitmap); | 653 *out = SkNEW(SkBitmap); |
| 650 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 654 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 655 SkScalarCeilToInt(fPicture->cullRect().height())); |
| 651 setup_bitmap(&bitmap, fTileWidth, fTileHeight); | 656 setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
| 652 } | 657 } |
| 653 bool success = true; | 658 bool success = true; |
| 654 for (int i = 0; i < fTileRects.count(); ++i) { | 659 for (int i = 0; i < fTileRects.count(); ++i) { |
| 655 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); | 660 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); |
| 656 if (fEnableWrites) { | 661 if (fEnableWrites) { |
| 657 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename,
fJsonSummaryPtr, | 662 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename,
fJsonSummaryPtr, |
| 658 fUseChecksumBasedFilenames, &i); | 663 fUseChecksumBasedFilenames, &i); |
| 659 } | 664 } |
| 660 if (NULL != out) { | 665 if (NULL != out) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 name.appendf("%i", fTileHeight); | 710 name.appendf("%i", fTileHeight); |
| 706 } | 711 } |
| 707 return name; | 712 return name; |
| 708 } | 713 } |
| 709 | 714 |
| 710 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 715 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 711 | 716 |
| 712 void PlaybackCreationRenderer::setup() { | 717 void PlaybackCreationRenderer::setup() { |
| 713 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 718 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 714 fRecorder.reset(SkNEW(SkPictureRecorder)); | 719 fRecorder.reset(SkNEW(SkPictureRecorder)); |
| 715 SkCanvas* canvas = fRecorder->beginRecording(this->getViewWidth(), this->get
ViewHeight(), | 720 SkCanvas* canvas = fRecorder->beginRecording(SkIntToScalar(this->getViewWidt
h()), |
| 721 SkIntToScalar(this->getViewHeig
ht()), |
| 716 factory.get(), | 722 factory.get(), |
| 717 this->recordFlags()); | 723 this->recordFlags()); |
| 718 this->scaleToScaleFactor(canvas); | 724 this->scaleToScaleFactor(canvas); |
| 719 canvas->drawPicture(fPicture); | 725 canvas->drawPicture(fPicture); |
| 720 } | 726 } |
| 721 | 727 |
| 722 bool PlaybackCreationRenderer::render(SkBitmap** out) { | 728 bool PlaybackCreationRenderer::render(SkBitmap** out) { |
| 723 fPicture.reset(fRecorder->endRecording()); | 729 fPicture.reset(fRecorder->endRecording()); |
| 724 // Since this class does not actually render, return false. | 730 // Since this class does not actually render, return false. |
| 725 return false; | 731 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 747 | 753 |
| 748 /////////////////////////////////////////////////////////////////////////////// | 754 /////////////////////////////////////////////////////////////////////////////// |
| 749 | 755 |
| 750 class GatherRenderer : public PictureRenderer { | 756 class GatherRenderer : public PictureRenderer { |
| 751 public: | 757 public: |
| 752 #if SK_SUPPORT_GPU | 758 #if SK_SUPPORT_GPU |
| 753 GatherRenderer(const GrContext::Options& opts) : INHERITED(opts) { } | 759 GatherRenderer(const GrContext::Options& opts) : INHERITED(opts) { } |
| 754 #endif | 760 #endif |
| 755 | 761 |
| 756 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { | 762 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { |
| 757 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()), | 763 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->cullRect().width(
)), |
| 758 SkIntToScalar(fPicture->height())); | 764 SkIntToScalar(fPicture->cullRect().height
())); |
| 759 SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds); | 765 SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds); |
| 760 SkSafeUnref(data); | 766 SkSafeUnref(data); |
| 761 | 767 |
| 762 return (fWritePath.isEmpty()); // we don't have anything to write | 768 return (fWritePath.isEmpty()); // we don't have anything to write |
| 763 } | 769 } |
| 764 | 770 |
| 765 private: | 771 private: |
| 766 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 772 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
| 767 return SkString("gather_pixelrefs"); | 773 return SkString("gather_pixelrefs"); |
| 768 } | 774 } |
| 769 | 775 |
| 770 typedef PictureRenderer INHERITED; | 776 typedef PictureRenderer INHERITED; |
| 771 }; | 777 }; |
| 772 | 778 |
| 773 #if SK_SUPPORT_GPU | 779 #if SK_SUPPORT_GPU |
| 774 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { | 780 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { |
| 775 return SkNEW_ARGS(GatherRenderer, (opts)); | 781 return SkNEW_ARGS(GatherRenderer, (opts)); |
| 776 } | 782 } |
| 777 #else | 783 #else |
| 778 PictureRenderer* CreateGatherPixelRefsRenderer() { | 784 PictureRenderer* CreateGatherPixelRefsRenderer() { |
| 779 return SkNEW(GatherRenderer); | 785 return SkNEW(GatherRenderer); |
| 780 } | 786 } |
| 781 #endif | 787 #endif |
| 782 | 788 |
| 783 } // namespace sk_tools | 789 } // namespace sk_tools |
| OLD | NEW |