Call write() within render_pictures but not bench_pictures

BUG=skia:2584
R=bsalomon@google.com, robertphillips@google.com, bensong@google.com

Author: epoger@google.com

Review URL: https://codereview.chromium.org/291843010

git-svn-id: http://skia.googlecode.com/svn/trunk@14837 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-22 00:36:05 +00:00
parent 336df8fd34
commit 8991c67f0c
3 changed files with 48 additions and 22 deletions

View File

@ -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<SkRect>& 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));
}
}

View File

@ -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;

View File

@ -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) {