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

Side by Side Diff: tools/PictureRenderer.cpp

Issue 1416913003: Clean up some dead code. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: kill dump-record Created 5 years, 2 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 | « tools/PictureRenderer.h ('k') | tools/PictureRenderingFlags.h » ('j') | no next file with comments »
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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return; 276 return;
277 } 277 }
278 278
279 // resetState should've already done this 279 // resetState should've already done this
280 fGrContext->flush(); 280 fGrContext->flush();
281 281
282 fGrContext->purgeAllUnlockedResources(); 282 fGrContext->purgeAllUnlockedResources();
283 #endif 283 #endif
284 } 284 }
285 285
286 /**
287 * Write the canvas to an image file and/or JSON summary.
288 *
289 * @param canvas Must be non-null. Canvas to be written to a file.
290 * @param writePath If nonempty, write the binary image to a file within this di rectory.
291 * @param mismatchPath If nonempty, write the binary image to a file within this directory,
292 * but only if the image does not match expectations.
293 * @param inputFilename If we are writing out a binary image, use this to build its filename.
294 * @param jsonSummaryPtr If not null, add image results (checksum) to this summa ry.
295 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w riting to disk.
296 * @param tileNumberPtr If not null, which tile number this image contains.
297 *
298 * @return bool True if the operation completed successfully.
299 */
300 static bool write(SkCanvas* canvas, const SkString& writePath, const SkString& m ismatchPath,
301 const SkString& inputFilename, ImageResultsAndExpectations *js onSummaryPtr,
302 bool useChecksumBasedFilenames, const int* tileNumberPtr=nullp tr) {
303 SkASSERT(canvas != nullptr);
304 if (nullptr == canvas) {
305 return false;
306 }
307
308 SkBitmap bitmap;
309 SkISize size = canvas->getDeviceSize();
310 setup_bitmap(&bitmap, size.width(), size.height());
311
312 canvas->readPixels(&bitmap, 0, 0);
313 force_all_opaque(bitmap);
314 BitmapAndDigest bitmapAndDigest(bitmap);
315
316 SkString escapedInputFilename(inputFilename);
317 replace_char(&escapedInputFilename, '.', '_');
318
319 // TODO(epoger): what about including the config type within outputFilename? That way,
320 // we could combine results of different config types without conflicting fi lenames.
321 SkString outputFilename;
322 const char *outputSubdirPtr = nullptr;
323 if (useChecksumBasedFilenames) {
324 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
325 outputSubdirPtr = escapedInputFilename.c_str();
326 outputFilename.set(imageDigestPtr->getHashType());
327 outputFilename.append("_");
328 outputFilename.appendU64(imageDigestPtr->getHashValue());
329 } else {
330 outputFilename.set(escapedInputFilename);
331 if (tileNumberPtr) {
332 outputFilename.append("-tile");
333 outputFilename.appendS32(*tileNumberPtr);
334 }
335 }
336 outputFilename.append(".png");
337
338 if (jsonSummaryPtr) {
339 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
340 SkString outputRelativePath;
341 if (outputSubdirPtr) {
342 outputRelativePath.set(outputSubdirPtr);
343 outputRelativePath.append("/"); // always use "/", even on Windows
344 outputRelativePath.append(outputFilename);
345 } else {
346 outputRelativePath.set(outputFilename);
347 }
348
349 jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(),
350 *imageDigestPtr, tileNumberPtr);
351 if (!mismatchPath.isEmpty() &&
352 !jsonSummaryPtr->getExpectation(inputFilename.c_str(),
353 tileNumberPtr).matches(*imageDigestP tr)) {
354 if (!write_bitmap_to_disk(bitmap, mismatchPath, outputSubdirPtr, out putFilename)) {
355 return false;
356 }
357 }
358 }
359
360 if (writePath.isEmpty()) {
361 return true;
362 } else {
363 return write_bitmap_to_disk(bitmap, writePath, outputSubdirPtr, outputFi lename);
364 }
365 }
366
367 //////////////////////////////////////////////////////////////////////////////// /////////////// 286 //////////////////////////////////////////////////////////////////////////////// ///////////////
368 287
369 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { 288 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) {
370 // defer the canvas setup until the render step 289 // defer the canvas setup until the render step
371 return nullptr; 290 return nullptr;
372 } 291 }
373 292
374 bool RecordPictureRenderer::render(SkBitmap** out) { 293 bool RecordPictureRenderer::render(SkBitmap** out) {
375 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); 294 SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
376 SkPictureRecorder recorder; 295 SkPictureRecorder recorder;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); 329 SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
411 pipeCanvas->drawPicture(fPicture); 330 pipeCanvas->drawPicture(fPicture);
412 writer.endRecording(); 331 writer.endRecording();
413 fCanvas->flush(); 332 fCanvas->flush();
414 if (out) { 333 if (out) {
415 *out = new SkBitmap; 334 *out = new SkBitmap;
416 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), 335 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
417 SkScalarCeilToInt(fPicture->cullRect().height())); 336 SkScalarCeilToInt(fPicture->cullRect().height()));
418 fCanvas->readPixels(*out, 0, 0); 337 fCanvas->readPixels(*out, 0, 0);
419 } 338 }
420 if (fEnableWrites) { 339 return true;
421 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr,
422 fUseChecksumBasedFilenames);
423 } else {
424 return true;
425 }
426 } 340 }
427 341
428 SkString PipePictureRenderer::getConfigNameInternal() { 342 SkString PipePictureRenderer::getConfigNameInternal() {
429 return SkString("pipe"); 343 return SkString("pipe");
430 } 344 }
431 345
432 //////////////////////////////////////////////////////////////////////////////// /////////////// 346 //////////////////////////////////////////////////////////////////////////////// ///////////////
433 347
434 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write Path, 348 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write Path,
435 const SkString* mismatchPath, const SkString* i nputFilename, 349 const SkString* mismatchPath, const SkString* i nputFilename,
(...skipping 19 matching lines...) Expand all
455 } else { 369 } else {
456 fCanvas->drawPicture(fPicture); 370 fCanvas->drawPicture(fPicture);
457 } 371 }
458 fCanvas->flush(); 372 fCanvas->flush();
459 if (out) { 373 if (out) {
460 *out = new SkBitmap; 374 *out = new SkBitmap;
461 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), 375 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
462 SkScalarCeilToInt(fPicture->cullRect().height())); 376 SkScalarCeilToInt(fPicture->cullRect().height()));
463 fCanvas->readPixels(*out, 0, 0); 377 fCanvas->readPixels(*out, 0, 0);
464 } 378 }
465 if (fEnableWrites) { 379 return true;
466 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr,
467 fUseChecksumBasedFilenames);
468 } else {
469 return true;
470 }
471 } 380 }
472 381
473 SkString SimplePictureRenderer::getConfigNameInternal() { 382 SkString SimplePictureRenderer::getConfigNameInternal() {
474 return SkString("simple"); 383 return SkString("simple");
475 } 384 }
476 385
477 //////////////////////////////////////////////////////////////////////////////// /////////////// 386 //////////////////////////////////////////////////////////////////////////////// ///////////////
478 387
479 #if SK_SUPPORT_GPU 388 #if SK_SUPPORT_GPU
480 TiledPictureRenderer::TiledPictureRenderer(const GrContextOptions& opts) 389 TiledPictureRenderer::TiledPictureRenderer(const GrContextOptions& opts)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 void TiledPictureRenderer::drawCurrentTile() { 576 void TiledPictureRenderer::drawCurrentTile() {
668 SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count()) ; 577 SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count()) ;
669 draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture); 578 draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture);
670 } 579 }
671 580
672 bool TiledPictureRenderer::postRender(SkCanvas* canvas, const SkIRect& tileRect, 581 bool TiledPictureRenderer::postRender(SkCanvas* canvas, const SkIRect& tileRect,
673 SkBitmap* tempBM, SkBitmap** out, 582 SkBitmap* tempBM, SkBitmap** out,
674 int tileNumber) { 583 int tileNumber) {
675 bool success = true; 584 bool success = true;
676 585
677 if (fEnableWrites) {
678 success &= write(canvas, fWritePath, fMismatchPath, fInputFilename, fJso nSummaryPtr,
679 fUseChecksumBasedFilenames, &tileNumber);
680 }
681 if (out) { 586 if (out) {
682 if (canvas->readPixels(tempBM, 0, 0)) { 587 if (canvas->readPixels(tempBM, 0, 0)) {
683 // Add this tile to the entire bitmap. 588 // Add this tile to the entire bitmap.
684 bitmapCopyAtOffset(*tempBM, *out, tileRect.left(), tileRect.top()); 589 bitmapCopyAtOffset(*tempBM, *out, tileRect.left(), tileRect.top());
685 } else { 590 } else {
686 success = false; 591 success = false;
687 } 592 }
688 } 593 }
689 594
690 return success; 595 return success;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 case kNone_BBoxHierarchyType: 730 case kNone_BBoxHierarchyType:
826 return nullptr; 731 return nullptr;
827 case kRTree_BBoxHierarchyType: 732 case kRTree_BBoxHierarchyType:
828 return new SkRTreeFactory; 733 return new SkRTreeFactory;
829 } 734 }
830 SkASSERT(0); // invalid bbhType 735 SkASSERT(0); // invalid bbhType
831 return nullptr; 736 return nullptr;
832 } 737 }
833 738
834 } // namespace sk_tools 739 } // namespace sk_tools
OLDNEW
« no previous file with comments | « tools/PictureRenderer.h ('k') | tools/PictureRenderingFlags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698