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

Unified Diff: tools/PictureRenderer.cpp

Issue 338633011: Deprecate SkPicture::clone(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add define for chrome Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: tools/PictureRenderer.cpp
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index d337a5ebb7df295c0828ed3bf2f6bcc0d8c36b34..acc787823018924daf0f62d897de18041be6d0e3 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -698,188 +698,6 @@ SkString TiledPictureRenderer::getConfigNameInternal() {
///////////////////////////////////////////////////////////////////////////////////////////////
-// Holds all of the information needed to draw a set of tiles.
-class CloneData : public SkRunnable {
-
-public:
- CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int start, int end,
- SkRunnable* done, ImageResultsAndExpectations* jsonSummaryPtr,
- bool useChecksumBasedFilenames, bool enableWrites)
- : fClone(clone)
- , fCanvas(canvas)
- , fEnableWrites(enableWrites)
- , fRects(rects)
- , fStart(start)
- , fEnd(end)
- , fSuccess(NULL)
- , fDone(done)
- , fJsonSummaryPtr(jsonSummaryPtr)
- , fUseChecksumBasedFilenames(useChecksumBasedFilenames) {
- SkASSERT(fDone != NULL);
- }
-
- virtual void run() SK_OVERRIDE {
- SkGraphics::SetTLSFontCacheLimit(1024 * 1024);
-
- SkBitmap bitmap;
- if (fBitmap != NULL) {
- // All tiles are the same size.
- setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScalarFloorToInt(fRects[0].height()));
- }
-
- for (int i = fStart; i < fEnd; i++) {
- draw_tile_to_canvas(fCanvas, fRects[i], fClone);
- if (fEnableWrites) {
- 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 {
- *fSuccess = false;
- // If one tile fails to read pixels, do not continue drawing the rest.
- break;
- }
- }
- }
- }
- fDone->run();
- }
-
- void setPathsAndSuccess(const SkString& writePath, const SkString& mismatchPath,
- const SkString& inputFilename, bool* success) {
- fWritePath.set(writePath);
- fMismatchPath.set(mismatchPath);
- fInputFilename.set(inputFilename);
- fSuccess = success;
- }
-
- void setBitmap(SkBitmap* bitmap) {
- fBitmap = bitmap;
- }
-
-private:
- // All pointers unowned.
- 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.
- SkTDArray<SkRect>& fRects; // All tiles of the picture.
- const int fStart; // Range of tiles drawn by this thread.
- const int fEnd;
- bool* fSuccess; // Only meaningful if path is non-null. Shared by all threads,
- // and only set to false upon failure to write to a PNG.
- SkRunnable* fDone;
- SkBitmap* fBitmap;
- ImageResultsAndExpectations* fJsonSummaryPtr;
- bool fUseChecksumBasedFilenames;
-};
-
-MultiCorePictureRenderer::MultiCorePictureRenderer(int threadCount)
-: fNumThreads(threadCount)
-, fThreadPool(threadCount)
-, fCountdown(threadCount) {
- // Only need to create fNumThreads - 1 clones, since one thread will use the base
- // picture.
- fPictureClones = SkNEW_ARRAY(SkPicture, fNumThreads - 1);
- fCloneData = SkNEW_ARRAY(CloneData*, fNumThreads);
-}
-
-void MultiCorePictureRenderer::init(SkPicture *pict, const SkString* writePath,
- const SkString* mismatchPath, const SkString* inputFilename,
- bool useChecksumBasedFilenames) {
- // Set fPicture and the tiles.
- this->INHERITED::init(pict, writePath, mismatchPath, inputFilename, useChecksumBasedFilenames);
- for (int i = 0; i < fNumThreads; ++i) {
- *fCanvasPool.append() = this->setupCanvas(this->getTileWidth(), this->getTileHeight());
- }
- // Only need to create fNumThreads - 1 clones, since one thread will use the base picture.
- fPicture->clone(fPictureClones, fNumThreads - 1);
- // Populate each thread with the appropriate data.
- // Group the tiles into nearly equal size chunks, rounding up so we're sure to cover them all.
- const int chunkSize = (fTileRects.count() + fNumThreads - 1) / fNumThreads;
-
- for (int i = 0; i < fNumThreads; i++) {
- SkPicture* pic;
- if (i == fNumThreads-1) {
- // The last set will use the original SkPicture.
- pic = fPicture;
- } else {
- pic = &fPictureClones[i];
- }
- const int start = i * chunkSize;
- const int end = SkMin32(start + chunkSize, fTileRects.count());
- fCloneData[i] = SkNEW_ARGS(CloneData,
- (pic, fCanvasPool[i], fTileRects, start, end, &fCountdown,
- fJsonSummaryPtr, useChecksumBasedFilenames, fEnableWrites));
- }
-}
-
-bool MultiCorePictureRenderer::render(SkBitmap** out) {
- bool success = true;
- if (!fWritePath.isEmpty() || !fMismatchPath.isEmpty()) {
- for (int i = 0; i < fNumThreads-1; i++) {
- fCloneData[i]->setPathsAndSuccess(fWritePath, fMismatchPath, fInputFilename, &success);
- }
- }
-
- if (NULL != out) {
- *out = SkNEW(SkBitmap);
- setup_bitmap(*out, fPicture->width(), fPicture->height());
- for (int i = 0; i < fNumThreads; i++) {
- fCloneData[i]->setBitmap(*out);
- }
- } else {
- for (int i = 0; i < fNumThreads; i++) {
- fCloneData[i]->setBitmap(NULL);
- }
- }
-
- fCountdown.reset(fNumThreads);
- for (int i = 0; i < fNumThreads; i++) {
- fThreadPool.add(fCloneData[i]);
- }
- fCountdown.wait();
-
- return success;
-}
-
-void MultiCorePictureRenderer::end() {
- for (int i = 0; i < fNumThreads - 1; i++) {
- SkDELETE(fCloneData[i]);
- fCloneData[i] = NULL;
- }
-
- fCanvasPool.unrefAll();
-
- this->INHERITED::end();
-}
-
-MultiCorePictureRenderer::~MultiCorePictureRenderer() {
- // Each individual CloneData was deleted in end.
- SkDELETE_ARRAY(fCloneData);
- SkDELETE_ARRAY(fPictureClones);
-}
-
-SkString MultiCorePictureRenderer::getConfigNameInternal() {
- SkString name = this->INHERITED::getConfigNameInternal();
- name.appendf("_multi_%i_threads", fNumThreads);
- return name;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-
void PlaybackCreationRenderer::setup() {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
fRecorder.reset(SkNEW(SkPictureRecorder));
@@ -941,27 +759,4 @@ PictureRenderer* CreateGatherPixelRefsRenderer() {
return SkNEW(GatherRenderer);
}
-///////////////////////////////////////////////////////////////////////////////
-
-class PictureCloneRenderer : public PictureRenderer {
-public:
- virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE {
- for (int i = 0; i < 100; ++i) {
- SkPicture* clone = fPicture->clone();
- SkSafeUnref(clone);
- }
-
- return (fWritePath.isEmpty()); // we don't have anything to write
- }
-
-private:
- virtual SkString getConfigNameInternal() SK_OVERRIDE {
- return SkString("picture_clone");
- }
-};
-
-PictureRenderer* CreatePictureCloneRenderer() {
- return SkNEW(PictureCloneRenderer);
-}
-
} // namespace sk_tools

Powered by Google App Engine
This is Rietveld 408576698