diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index b15b4a798..5128782d4 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -398,8 +398,12 @@ bool PipePictureRenderer::render(SkBitmap** out) { setup_bitmap(*out, fPicture->width(), fPicture->height()); fCanvas->readPixels(*out, 0, 0); } - return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, - fUseChecksumBasedFilenames); + if (fEnableWrites) { + return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, + fUseChecksumBasedFilenames); + } else { + return true; + } } SkString PipePictureRenderer::getConfigNameInternal() { @@ -429,8 +433,12 @@ bool SimplePictureRenderer::render(SkBitmap** out) { setup_bitmap(*out, fPicture->width(), fPicture->height()); fCanvas->readPixels(*out, 0, 0); } - return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, - fUseChecksumBasedFilenames); + if (fEnableWrites) { + return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, + fUseChecksumBasedFilenames); + } else { + return true; + } } SkString SimplePictureRenderer::getConfigNameInternal() { @@ -640,8 +648,10 @@ bool TiledPictureRenderer::render(SkBitmap** out) { bool success = true; for (int i = 0; i < fTileRects.count(); ++i) { draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); - success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, - fUseChecksumBasedFilenames, &i); + if (fEnableWrites) { + success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, + fUseChecksumBasedFilenames, &i); + } if (NULL != out) { if (fCanvas->readPixels(&bitmap, 0, 0)) { // Add this tile to the entire bitmap. @@ -700,9 +710,10 @@ class CloneData : public SkRunnable { public: CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray& rects, int start, int end, SkRunnable* done, ImageResultsAndExpectations* jsonSummaryPtr, - bool useChecksumBasedFilenames) + bool useChecksumBasedFilenames, bool enableWrites) : fClone(clone) , fCanvas(canvas) + , fEnableWrites(enableWrites) , fRects(rects) , fStart(start) , fEnd(end) @@ -724,23 +735,25 @@ public: for (int i = fStart; i < fEnd; i++) { draw_tile_to_canvas(fCanvas, fRects[i], fClone); - if (!write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, - fUseChecksumBasedFilenames, &i) - && fSuccess != NULL) { - *fSuccess = false; - // If one tile fails to write to a file, do not continue drawing the rest. - break; - } - if (fBitmap != NULL) { - if (fCanvas->readPixels(&bitmap, 0, 0)) { - SkAutoLockPixels alp(*fBitmap); - bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRects[i].left()), - SkScalarFloorToInt(fRects[i].top())); - } else { + if (fEnableWrites) { + if (!write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, + fUseChecksumBasedFilenames, &i) + && fSuccess != NULL) { *fSuccess = false; - // If one tile fails to read pixels, do not continue drawing the rest. + // If one tile fails to write to a file, do not continue drawing the rest. break; } + if (fBitmap != NULL) { + if (fCanvas->readPixels(&bitmap, 0, 0)) { + SkAutoLockPixels alp(*fBitmap); + bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRects[i].left()), + SkScalarFloorToInt(fRects[i].top())); + } else { + *fSuccess = false; + // If one tile fails to read pixels, do not continue drawing the rest. + break; + } + } } } fDone->run(); @@ -763,6 +776,8 @@ private: SkPicture* fClone; // Picture to draw from. Each CloneData has a unique one which // is threadsafe. SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. + bool fEnableWrites; // TODO(epoger): Temporary hack; see declaration of + // fEnableWrites in PictureRenderer.h. SkString fWritePath; // If not empty, write all results into this directory. SkString fMismatchPath; // If not empty, write all unexpected results into this dir. SkString fInputFilename; // Filename of input SkPicture file. @@ -813,7 +828,7 @@ void MultiCorePictureRenderer::init(SkPicture *pict, const SkString* writePath, const int end = SkMin32(start + chunkSize, fTileRects.count()); fCloneData[i] = SkNEW_ARGS(CloneData, (pic, fCanvasPool[i], fTileRects, start, end, &fCountdown, - fJsonSummaryPtr, useChecksumBasedFilenames)); + fJsonSummaryPtr, useChecksumBasedFilenames, fEnableWrites)); } } diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 468c567b1..109073bca 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -95,6 +95,14 @@ public: virtual void init(SkPicture* pict, const SkString* writePath, const SkString* mismatchPath, const SkString* inputFilename, bool useChecksumBasedFilenames); + /** + * TODO(epoger): Temporary hack, while we work on http://skbug.com/2584 ('bench_pictures is + * timing reading pixels and writing json files'), such that: + * - render_pictures can call this method and continue to work + * - any other callers (bench_pictures) will skip calls to write() by default + */ + void enableWrites() { fEnableWrites = true; } + /** * Set the viewport so that only the portion listed gets drawn. */ @@ -345,6 +353,7 @@ public: PictureRenderer() : fJsonSummaryPtr(NULL) , fDeviceType(kBitmap_DeviceType) + , fEnableWrites(false) , fBBoxHierarchyType(kNone_BBoxHierarchyType) , fScaleFactor(SK_Scalar1) #if SK_SUPPORT_GPU @@ -371,6 +380,7 @@ protected: bool fUseChecksumBasedFilenames; ImageResultsAndExpectations* fJsonSummaryPtr; SkDeviceTypes fDeviceType; + bool fEnableWrites; BBoxHierarchyType fBBoxHierarchyType; DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; SkString fDrawFiltersConfig; diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index cbbca7ab2..e054acf67 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -206,6 +206,7 @@ static bool render_picture_internal(const SkString& inputPath, const SkString* w } renderer.setup(); + renderer.enableWrites(); bool success = renderer.render(out); if (!success) {