Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: tools/PictureRenderer.cpp

Issue 259703002: fix contents of render_pictures JSON summary (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add more comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/render_pictures_main.cpp » ('j') | tools/tests/render_pictures_test.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 #endif 316 #endif
317 } 317 }
318 318
319 uint32_t PictureRenderer::recordFlags() { 319 uint32_t PictureRenderer::recordFlags() {
320 return (kNone_BBoxHierarchyType == fBBoxHierarchyType) 320 return (kNone_BBoxHierarchyType == fBBoxHierarchyType)
321 ? 0 321 ? 0
322 : SkPicture::kUsePathBoundsForClip_RecordingFlag; 322 : SkPicture::kUsePathBoundsForClip_RecordingFlag;
323 } 323 }
324 324
325 /** 325 /**
326 * Write the canvas to the specified path. 326 * Write the canvas to the specified path.
scroggo 2014/04/24 21:15:08 Since this function does a lot more than this (and
epoger 2014/04/25 15:26:43 Done.
327 * 327 *
328 * @param canvas Must be non-null. Canvas to be written to a file. 328 * @param canvas Must be non-null. Canvas to be written to a file.
329 * @param outputDir If nonempty, write the binary image to a file within this di rectory. 329 * @param outputDir If nonempty, write the binary image to a file within this di rectory.
330 * @param inputFilename If we are writing out a binary image, use this to build its filename. 330 * @param inputFilename If we are writing out a binary image, use this to build its filename.
331 * @param jsonSummaryPtr If not null, add image results to this summary. 331 * @param jsonSummaryPtr If not null, add image results to this summary.
332 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w riting to disk. 332 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w riting to disk.
333 * @param tileNumberPtr If not null, which tile number this image contains. 333 * @param tileNumberPtr If not null, which tile number this image contains.
334 * @return bool True if the Canvas is written to a file. 334 * @return bool True if the Canvas is written to a file.
scroggo 2014/04/24 21:15:08 or if outputDir is NULL but we still wrote a summa
epoger 2014/04/25 15:26:43 It's slightly different than that... updated.
335 *
336 * TODO(epoger): Right now, all canvases must pass through this function in orde r to be appended
337 * to the ImageResultsSummary. We need some way to add bitmaps to the ImageResu ltsSummary
338 * even if --writePath has not been specified (and thus this function is not cal led).
339 *
340 * One fix would be to pass in these path elements separately, and allow this fu nction to be
341 * called even if --writePath was not specified...
342 * const char *outputDir // NULL if we don't want to write image files to dis k
343 * const char *filename // name we use within JSON summary, and as the filen ame within outputDir
344 *
345 * UPDATE: Now that outputDir and inputFilename are passed separately, we should be able to do that.
346 */ 335 */
347 static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i nputFilename, 336 static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i nputFilename,
348 ImageResultsSummary *jsonSummaryPtr, bool useChecksumBasedFile names, 337 ImageResultsSummary *jsonSummaryPtr, bool useChecksumBasedFile names,
349 const int* tileNumberPtr=NULL) { 338 const int* tileNumberPtr=NULL) {
350 SkASSERT(canvas != NULL); 339 SkASSERT(canvas != NULL);
351 if (NULL == canvas) { 340 if (NULL == canvas) {
352 return false; 341 return false;
353 } 342 }
354 343
355 SkBitmap bitmap; 344 SkBitmap bitmap;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 outputRelativePath.append("/"); // always use "/", even on Windows 389 outputRelativePath.append("/"); // always use "/", even on Windows
401 outputRelativePath.append(outputFilename); 390 outputRelativePath.append(outputFilename);
402 } else { 391 } else {
403 outputRelativePath.set(outputFilename); 392 outputRelativePath.set(outputFilename);
404 } 393 }
405 394
406 jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(), 395 jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(),
407 hash, tileNumberPtr); 396 hash, tileNumberPtr);
408 } 397 }
409 398
410 SkASSERT(!outputDir.isEmpty()); // TODO(epoger): we want to remove this cons traint, 399 if (outputDir.isEmpty()) {
411 // as noted above 400 return true;
401 }
402
412 SkString dirPath; 403 SkString dirPath;
413 if (outputSubdirPtr) { 404 if (outputSubdirPtr) {
414 dirPath = SkOSPath::SkPathJoin(outputDir.c_str(), outputSubdirPtr); 405 dirPath = SkOSPath::SkPathJoin(outputDir.c_str(), outputSubdirPtr);
415 sk_mkdir(dirPath.c_str()); 406 sk_mkdir(dirPath.c_str());
416 } else { 407 } else {
417 dirPath.set(outputDir); 408 dirPath.set(outputDir);
418 } 409 }
419 SkString fullPath = SkOSPath::SkPathJoin(dirPath.c_str(), outputFilename.c_s tr()); 410 SkString fullPath = SkOSPath::SkPathJoin(dirPath.c_str(), outputFilename.c_s tr());
420 return SkImageEncoder::EncodeFile(fullPath.c_str(), bitmap, SkImageEncoder:: kPNG_Type, 100); 411 return SkImageEncoder::EncodeFile(fullPath.c_str(), bitmap, SkImageEncoder:: kPNG_Type, 100);
421 } 412 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (NULL == fCanvas.get() || NULL == fPicture) { 454 if (NULL == fCanvas.get() || NULL == fPicture) {
464 return false; 455 return false;
465 } 456 }
466 457
467 PipeController pipeController(fCanvas.get()); 458 PipeController pipeController(fCanvas.get());
468 SkGPipeWriter writer; 459 SkGPipeWriter writer;
469 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); 460 SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
470 pipeCanvas->drawPicture(*fPicture); 461 pipeCanvas->drawPicture(*fPicture);
471 writer.endRecording(); 462 writer.endRecording();
472 fCanvas->flush(); 463 fCanvas->flush();
473 if (!fOutputDir.isEmpty()) {
474 return write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
475 fUseChecksumBasedFilenames);
476 }
477 if (NULL != out) { 464 if (NULL != out) {
478 *out = SkNEW(SkBitmap); 465 *out = SkNEW(SkBitmap);
479 setup_bitmap(*out, fPicture->width(), fPicture->height()); 466 setup_bitmap(*out, fPicture->width(), fPicture->height());
480 fCanvas->readPixels(*out, 0, 0); 467 fCanvas->readPixels(*out, 0, 0);
481 } 468 }
482 return true; 469 return write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
470 fUseChecksumBasedFilenames);
483 } 471 }
484 472
485 SkString PipePictureRenderer::getConfigNameInternal() { 473 SkString PipePictureRenderer::getConfigNameInternal() {
486 return SkString("pipe"); 474 return SkString("pipe");
487 } 475 }
488 476
489 //////////////////////////////////////////////////////////////////////////////// /////////////// 477 //////////////////////////////////////////////////////////////////////////////// ///////////////
490 478
491 void SimplePictureRenderer::init(SkPicture* picture, const SkString* outputDir, 479 void SimplePictureRenderer::init(SkPicture* picture, const SkString* outputDir,
492 const SkString* inputFilename, bool useChecksum BasedFilenames) { 480 const SkString* inputFilename, bool useChecksum BasedFilenames) {
493 INHERITED::init(picture, outputDir, inputFilename, useChecksumBasedFilenames ); 481 INHERITED::init(picture, outputDir, inputFilename, useChecksumBasedFilenames );
494 this->buildBBoxHierarchy(); 482 this->buildBBoxHierarchy();
495 } 483 }
496 484
497 bool SimplePictureRenderer::render(SkBitmap** out) { 485 bool SimplePictureRenderer::render(SkBitmap** out) {
498 SkASSERT(fCanvas.get() != NULL); 486 SkASSERT(fCanvas.get() != NULL);
499 SkASSERT(NULL != fPicture); 487 SkASSERT(NULL != fPicture);
500 if (NULL == fCanvas.get() || NULL == fPicture) { 488 if (NULL == fCanvas.get() || NULL == fPicture) {
501 return false; 489 return false;
502 } 490 }
503 491
504 fCanvas->drawPicture(*fPicture); 492 fCanvas->drawPicture(*fPicture);
505 fCanvas->flush(); 493 fCanvas->flush();
506 if (!fOutputDir.isEmpty()) {
507 return write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
508 fUseChecksumBasedFilenames);
509 }
510
511 if (NULL != out) { 494 if (NULL != out) {
512 *out = SkNEW(SkBitmap); 495 *out = SkNEW(SkBitmap);
513 setup_bitmap(*out, fPicture->width(), fPicture->height()); 496 setup_bitmap(*out, fPicture->width(), fPicture->height());
514 fCanvas->readPixels(*out, 0, 0); 497 fCanvas->readPixels(*out, 0, 0);
515 } 498 }
516 499 return write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
517 return true; 500 fUseChecksumBasedFilenames);
518 } 501 }
519 502
520 SkString SimplePictureRenderer::getConfigNameInternal() { 503 SkString SimplePictureRenderer::getConfigNameInternal() {
521 return SkString("simple"); 504 return SkString("simple");
522 } 505 }
523 506
524 //////////////////////////////////////////////////////////////////////////////// /////////////// 507 //////////////////////////////////////////////////////////////////////////////// ///////////////
525 508
526 TiledPictureRenderer::TiledPictureRenderer() 509 TiledPictureRenderer::TiledPictureRenderer()
527 : fTileWidth(kDefaultTileWidth) 510 : fTileWidth(kDefaultTileWidth)
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 698
716 SkBitmap bitmap; 699 SkBitmap bitmap;
717 if (out){ 700 if (out){
718 *out = SkNEW(SkBitmap); 701 *out = SkNEW(SkBitmap);
719 setup_bitmap(*out, fPicture->width(), fPicture->height()); 702 setup_bitmap(*out, fPicture->width(), fPicture->height());
720 setup_bitmap(&bitmap, fTileWidth, fTileHeight); 703 setup_bitmap(&bitmap, fTileWidth, fTileHeight);
721 } 704 }
722 bool success = true; 705 bool success = true;
723 for (int i = 0; i < fTileRects.count(); ++i) { 706 for (int i = 0; i < fTileRects.count(); ++i) {
724 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); 707 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture);
725 if (!fOutputDir.isEmpty()) { 708 success &= write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
726 success &= write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPt r, 709 fUseChecksumBasedFilenames, &i);
727 fUseChecksumBasedFilenames, &i);
728 }
729 if (NULL != out) { 710 if (NULL != out) {
730 if (fCanvas->readPixels(&bitmap, 0, 0)) { 711 if (fCanvas->readPixels(&bitmap, 0, 0)) {
731 // Add this tile to the entire bitmap. 712 // Add this tile to the entire bitmap.
732 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i ].left()), 713 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i ].left()),
733 SkScalarFloorToInt(fTileRects[i].top())); 714 SkScalarFloorToInt(fTileRects[i].top()));
734 } else { 715 } else {
735 success = false; 716 success = false;
736 } 717 }
737 } 718 }
738 } 719 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); 781 SkGraphics::SetTLSFontCacheLimit(1024 * 1024);
801 782
802 SkBitmap bitmap; 783 SkBitmap bitmap;
803 if (fBitmap != NULL) { 784 if (fBitmap != NULL) {
804 // All tiles are the same size. 785 // All tiles are the same size.
805 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala rFloorToInt(fRects[0].height())); 786 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala rFloorToInt(fRects[0].height()));
806 } 787 }
807 788
808 for (int i = fStart; i < fEnd; i++) { 789 for (int i = fStart; i < fEnd; i++) {
809 draw_tile_to_canvas(fCanvas, fRects[i], fClone); 790 draw_tile_to_canvas(fCanvas, fRects[i], fClone);
810 if ((!fOutputDir.isEmpty()) 791 if (!write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr,
811 && !write(fCanvas, fOutputDir, fInputFilename, fJsonSummaryPtr, 792 fUseChecksumBasedFilenames, &i)
812 fUseChecksumBasedFilenames, &i)
813 && fSuccess != NULL) { 793 && fSuccess != NULL) {
814 *fSuccess = false; 794 *fSuccess = false;
815 // If one tile fails to write to a file, do not continue drawing the rest. 795 // If one tile fails to write to a file, do not continue drawing the rest.
816 break; 796 break;
817 } 797 }
818 if (fBitmap != NULL) { 798 if (fBitmap != NULL) {
819 if (fCanvas->readPixels(&bitmap, 0, 0)) { 799 if (fCanvas->readPixels(&bitmap, 0, 0)) {
820 SkAutoLockPixels alp(*fBitmap); 800 SkAutoLockPixels alp(*fBitmap);
821 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect s[i].left()), 801 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect s[i].left()),
822 SkScalarFloorToInt(fRects[i].top())); 802 SkScalarFloorToInt(fRects[i].top()));
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 virtual SkString getConfigNameInternal() SK_OVERRIDE { 1010 virtual SkString getConfigNameInternal() SK_OVERRIDE {
1031 return SkString("picture_clone"); 1011 return SkString("picture_clone");
1032 } 1012 }
1033 }; 1013 };
1034 1014
1035 PictureRenderer* CreatePictureCloneRenderer() { 1015 PictureRenderer* CreatePictureCloneRenderer() {
1036 return SkNEW(PictureCloneRenderer); 1016 return SkNEW(PictureCloneRenderer);
1037 } 1017 }
1038 1018
1039 } // namespace sk_tools 1019 } // namespace sk_tools
OLDNEW
« no previous file with comments | « no previous file | tools/render_pictures_main.cpp » ('j') | tools/tests/render_pictures_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698