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

Side by Side Diff: tools/PictureRenderer.cpp

Issue 544233002: "NULL !=" = NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@are
Patch Set: rebase Created 6 years, 3 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/PictureBenchmark.cpp ('k') | tools/filtermain.cpp » ('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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const SkString* mismatchPath, 53 const SkString* mismatchPath,
54 const SkString* inputFilename, 54 const SkString* inputFilename,
55 bool useChecksumBasedFilenames) { 55 bool useChecksumBasedFilenames) {
56 this->CopyString(&fWritePath, writePath); 56 this->CopyString(&fWritePath, writePath);
57 this->CopyString(&fMismatchPath, mismatchPath); 57 this->CopyString(&fMismatchPath, mismatchPath);
58 this->CopyString(&fInputFilename, inputFilename); 58 this->CopyString(&fInputFilename, inputFilename);
59 fUseChecksumBasedFilenames = useChecksumBasedFilenames; 59 fUseChecksumBasedFilenames = useChecksumBasedFilenames;
60 60
61 SkASSERT(NULL == fPicture); 61 SkASSERT(NULL == fPicture);
62 SkASSERT(NULL == fCanvas.get()); 62 SkASSERT(NULL == fCanvas.get());
63 if (NULL != fPicture || NULL != fCanvas.get()) { 63 if (fPicture || fCanvas.get()) {
64 return; 64 return;
65 } 65 }
66 66
67 SkASSERT(pict != NULL); 67 SkASSERT(pict != NULL);
68 if (NULL == pict) { 68 if (NULL == pict) {
69 return; 69 return;
70 } 70 }
71 71
72 fPicture.reset(pict)->ref(); 72 fPicture.reset(pict)->ref();
73 fCanvas.reset(this->setupCanvas()); 73 fCanvas.reset(this->setupCanvas());
74 } 74 }
75 75
76 void PictureRenderer::CopyString(SkString* dest, const SkString* src) { 76 void PictureRenderer::CopyString(SkString* dest, const SkString* src) {
77 if (NULL != src) { 77 if (src) {
78 dest->set(*src); 78 dest->set(*src);
79 } else { 79 } else {
80 dest->reset(); 80 dest->reset();
81 } 81 }
82 } 82 }
83 83
84 class FlagsDrawFilter : public SkDrawFilter { 84 class FlagsDrawFilter : public SkDrawFilter {
85 public: 85 public:
86 FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) : 86 FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) :
87 fFlags(flags) {} 87 fFlags(flags) {}
88 88
89 virtual bool filter(SkPaint* paint, Type t) { 89 virtual bool filter(SkPaint* paint, Type t) {
90 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); 90 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags);
91 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { 91 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) {
92 SkMaskFilter* maskFilter = paint->getMaskFilter(); 92 SkMaskFilter* maskFilter = paint->getMaskFilter();
93 if (NULL != maskFilter) { 93 if (maskFilter) {
94 paint->setMaskFilter(NULL); 94 paint->setMaskFilter(NULL);
95 } 95 }
96 } 96 }
97 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { 97 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) {
98 paint->setHinting(SkPaint::kNo_Hinting); 98 paint->setHinting(SkPaint::kNo_Hinting);
99 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { 99 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) {
100 paint->setHinting(SkPaint::kSlight_Hinting); 100 paint->setHinting(SkPaint::kSlight_Hinting);
101 } 101 }
102 return true; 102 return true;
103 } 103 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(fPicture);
216 if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) { 216 if (kNone_BBoxHierarchyType != fBBoxHierarchyType && 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->cullRect().width(), 219 SkCanvas* canvas = recorder.beginRecording(fPicture->cullRect().width(),
220 fPicture->cullRect().height() , 220 fPicture->cullRect().height() ,
221 factory.get(), 221 factory.get(),
222 this->recordFlags()); 222 this->recordFlags());
223 fPicture->playback(canvas); 223 fPicture->playback(canvas);
224 fPicture.reset(recorder.endRecording()); 224 fPicture.reset(recorder.endRecording());
225 } 225 }
226 } 226 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 SkString outputFilename; 298 SkString outputFilename;
299 const char *outputSubdirPtr = NULL; 299 const char *outputSubdirPtr = NULL;
300 if (useChecksumBasedFilenames) { 300 if (useChecksumBasedFilenames) {
301 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); 301 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
302 outputSubdirPtr = escapedInputFilename.c_str(); 302 outputSubdirPtr = escapedInputFilename.c_str();
303 outputFilename.set(imageDigestPtr->getHashType()); 303 outputFilename.set(imageDigestPtr->getHashType());
304 outputFilename.append("_"); 304 outputFilename.append("_");
305 outputFilename.appendU64(imageDigestPtr->getHashValue()); 305 outputFilename.appendU64(imageDigestPtr->getHashValue());
306 } else { 306 } else {
307 outputFilename.set(escapedInputFilename); 307 outputFilename.set(escapedInputFilename);
308 if (NULL != tileNumberPtr) { 308 if (tileNumberPtr) {
309 outputFilename.append("-tile"); 309 outputFilename.append("-tile");
310 outputFilename.appendS32(*tileNumberPtr); 310 outputFilename.appendS32(*tileNumberPtr);
311 } 311 }
312 } 312 }
313 outputFilename.append(".png"); 313 outputFilename.append(".png");
314 314
315 if (NULL != jsonSummaryPtr) { 315 if (jsonSummaryPtr) {
316 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); 316 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
317 SkString outputRelativePath; 317 SkString outputRelativePath;
318 if (outputSubdirPtr) { 318 if (outputSubdirPtr) {
319 outputRelativePath.set(outputSubdirPtr); 319 outputRelativePath.set(outputSubdirPtr);
320 outputRelativePath.append("/"); // always use "/", even on Windows 320 outputRelativePath.append("/"); // always use "/", even on Windows
321 outputRelativePath.append(outputFilename); 321 outputRelativePath.append(outputFilename);
322 } else { 322 } else {
323 outputRelativePath.set(outputFilename); 323 outputRelativePath.set(outputFilename);
324 } 324 }
325 325
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (NULL == fCanvas.get() || NULL == fPicture) { 385 if (NULL == fCanvas.get() || NULL == fPicture) {
386 return false; 386 return false;
387 } 387 }
388 388
389 PipeController pipeController(fCanvas.get()); 389 PipeController pipeController(fCanvas.get());
390 SkGPipeWriter writer; 390 SkGPipeWriter writer;
391 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); 391 SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
392 pipeCanvas->drawPicture(fPicture); 392 pipeCanvas->drawPicture(fPicture);
393 writer.endRecording(); 393 writer.endRecording();
394 fCanvas->flush(); 394 fCanvas->flush();
395 if (NULL != out) { 395 if (out) {
396 *out = SkNEW(SkBitmap); 396 *out = SkNEW(SkBitmap);
397 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), 397 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
398 SkScalarCeilToInt(fPicture->cullRect().height())); 398 SkScalarCeilToInt(fPicture->cullRect().height()));
399 fCanvas->readPixels(*out, 0, 0); 399 fCanvas->readPixels(*out, 0, 0);
400 } 400 }
401 if (fEnableWrites) { 401 if (fEnableWrites) {
402 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr, 402 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr,
403 fUseChecksumBasedFilenames); 403 fUseChecksumBasedFilenames);
404 } else { 404 } else {
405 return true; 405 return true;
406 } 406 }
407 } 407 }
408 408
409 SkString PipePictureRenderer::getConfigNameInternal() { 409 SkString PipePictureRenderer::getConfigNameInternal() {
410 return SkString("pipe"); 410 return SkString("pipe");
411 } 411 }
412 412
413 //////////////////////////////////////////////////////////////////////////////// /////////////// 413 //////////////////////////////////////////////////////////////////////////////// ///////////////
414 414
415 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write Path, 415 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write Path,
416 const SkString* mismatchPath, const SkString* i nputFilename, 416 const SkString* mismatchPath, const SkString* i nputFilename,
417 bool useChecksumBasedFilenames) { 417 bool useChecksumBasedFilenames) {
418 INHERITED::init(picture, writePath, mismatchPath, inputFilename, useChecksum BasedFilenames); 418 INHERITED::init(picture, writePath, mismatchPath, inputFilename, useChecksum BasedFilenames);
419 this->buildBBoxHierarchy(); 419 this->buildBBoxHierarchy();
420 } 420 }
421 421
422 bool SimplePictureRenderer::render(SkBitmap** out) { 422 bool SimplePictureRenderer::render(SkBitmap** out) {
423 SkASSERT(fCanvas.get() != NULL); 423 SkASSERT(fCanvas.get() != NULL);
424 SkASSERT(NULL != fPicture); 424 SkASSERT(fPicture);
425 if (NULL == fCanvas.get() || NULL == fPicture) { 425 if (NULL == fCanvas.get() || NULL == fPicture) {
426 return false; 426 return false;
427 } 427 }
428 428
429 fCanvas->drawPicture(fPicture); 429 fCanvas->drawPicture(fPicture);
430 fCanvas->flush(); 430 fCanvas->flush();
431 if (NULL != out) { 431 if (out) {
432 *out = SkNEW(SkBitmap); 432 *out = SkNEW(SkBitmap);
433 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), 433 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
434 SkScalarCeilToInt(fPicture->cullRect().height())); 434 SkScalarCeilToInt(fPicture->cullRect().height()));
435 fCanvas->readPixels(*out, 0, 0); 435 fCanvas->readPixels(*out, 0, 0);
436 } 436 }
437 if (fEnableWrites) { 437 if (fEnableWrites) {
438 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr, 438 return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSu mmaryPtr,
439 fUseChecksumBasedFilenames); 439 fUseChecksumBasedFilenames);
440 } else { 440 } else {
441 return true; 441 return true;
(...skipping 18 matching lines...) Expand all
460 , fTileWidthPercentage(0.0) 460 , fTileWidthPercentage(0.0)
461 , fTileHeightPercentage(0.0) 461 , fTileHeightPercentage(0.0)
462 , fTileMinPowerOf2Width(0) 462 , fTileMinPowerOf2Width(0)
463 , fCurrentTileOffset(-1) 463 , fCurrentTileOffset(-1)
464 , fTilesX(0) 464 , fTilesX(0)
465 , fTilesY(0) { } 465 , fTilesY(0) { }
466 466
467 void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath , 467 void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath ,
468 const SkString* mismatchPath, const SkString* in putFilename, 468 const SkString* mismatchPath, const SkString* in putFilename,
469 bool useChecksumBasedFilenames) { 469 bool useChecksumBasedFilenames) {
470 SkASSERT(NULL != pict); 470 SkASSERT(pict);
471 SkASSERT(0 == fTileRects.count()); 471 SkASSERT(0 == fTileRects.count());
472 if (NULL == pict || fTileRects.count() != 0) { 472 if (NULL == pict || fTileRects.count() != 0) {
473 return; 473 return;
474 } 474 }
475 475
476 // 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
477 // used by bench_pictures. 477 // used by bench_pictures.
478 fPicture.reset(pict)->ref(); 478 fPicture.reset(pict)->ref();
479 this->CopyString(&fWritePath, writePath); 479 this->CopyString(&fWritePath, writePath);
480 this->CopyString(&fMismatchPath, mismatchPath); 480 this->CopyString(&fMismatchPath, mismatchPath);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 SkScalarCeilToInt(fPicture->cullRect().height())); 655 SkScalarCeilToInt(fPicture->cullRect().height()));
656 setup_bitmap(&bitmap, fTileWidth, fTileHeight); 656 setup_bitmap(&bitmap, fTileWidth, fTileHeight);
657 } 657 }
658 bool success = true; 658 bool success = true;
659 for (int i = 0; i < fTileRects.count(); ++i) { 659 for (int i = 0; i < fTileRects.count(); ++i) {
660 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); 660 draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture);
661 if (fEnableWrites) { 661 if (fEnableWrites) {
662 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, 662 success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr,
663 fUseChecksumBasedFilenames, &i); 663 fUseChecksumBasedFilenames, &i);
664 } 664 }
665 if (NULL != out) { 665 if (out) {
666 if (fCanvas->readPixels(&bitmap, 0, 0)) { 666 if (fCanvas->readPixels(&bitmap, 0, 0)) {
667 // Add this tile to the entire bitmap. 667 // Add this tile to the entire bitmap.
668 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i ].left()), 668 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i ].left()),
669 SkScalarFloorToInt(fTileRects[i].top())); 669 SkScalarFloorToInt(fTileRects[i].top()));
670 } else { 670 } else {
671 success = false; 671 success = false;
672 } 672 }
673 } 673 }
674 } 674 }
675 return success; 675 return success;
676 } 676 }
677 677
678 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { 678 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) {
679 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); 679 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height);
680 SkASSERT(NULL != fPicture); 680 SkASSERT(fPicture);
681 // Clip the tile to an area that is completely inside both the SkPicture and the viewport. This 681 // Clip the tile to an area that is completely inside both the SkPicture and the viewport. This
682 // is mostly important for tiles on the right and bottom edges as they may g o over this area and 682 // is mostly important for tiles on the right and bottom edges as they may g o over this area and
683 // the picture may have some commands that draw outside of this area and so should not actually 683 // the picture may have some commands that draw outside of this area and so should not actually
684 // be written. 684 // be written.
685 // Uses a clipRegion so that it will be unaffected by the scale factor, whic h may have been set 685 // Uses a clipRegion so that it will be unaffected by the scale factor, whic h may have been set
686 // by INHERITED::setupCanvas. 686 // by INHERITED::setupCanvas.
687 SkRegion clipRegion; 687 SkRegion clipRegion;
688 clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight()); 688 clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight());
689 canvas->clipRegion(clipRegion); 689 canvas->clipRegion(clipRegion);
690 return canvas; 690 return canvas;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { 780 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) {
781 return SkNEW_ARGS(GatherRenderer, (opts)); 781 return SkNEW_ARGS(GatherRenderer, (opts));
782 } 782 }
783 #else 783 #else
784 PictureRenderer* CreateGatherPixelRefsRenderer() { 784 PictureRenderer* CreateGatherPixelRefsRenderer() {
785 return SkNEW(GatherRenderer); 785 return SkNEW(GatherRenderer);
786 } 786 }
787 #endif 787 #endif
788 788
789 } // namespace sk_tools 789 } // namespace sk_tools
OLDNEW
« no previous file with comments | « tools/PictureBenchmark.cpp ('k') | tools/filtermain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698