diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-13 19:09:42 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-13 19:09:42 +0000 |
commit | 84b18c7e3e042bf206e1ace3d1b6ea5bb929fe51 (patch) | |
tree | 7b46e74e6212283d9efe62a7b6feaad2c009972b /tools | |
parent | c202ea7cc69476a20ad898d6c76bcdbcb18adf74 (diff) |
split SkPictureRecorder out of SkPicture
https://codereview.chromium.org/214953003/
git-svn-id: http://skia.googlecode.com/svn/trunk@14171 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CopyTilesRenderer.cpp | 3 | ||||
-rw-r--r-- | tools/PictureRenderer.cpp | 79 | ||||
-rw-r--r-- | tools/PictureRenderer.h | 9 | ||||
-rw-r--r-- | tools/bench_record.cpp | 41 | ||||
-rw-r--r-- | tools/filtermain.cpp | 9 | ||||
-rw-r--r-- | tools/render_pictures_main.cpp | 6 | ||||
-rw-r--r-- | tools/skpmaker.cpp | 8 |
7 files changed, 84 insertions, 71 deletions
diff --git a/tools/CopyTilesRenderer.cpp b/tools/CopyTilesRenderer.cpp index 341d93edae..9e919e0a4f 100644 --- a/tools/CopyTilesRenderer.cpp +++ b/tools/CopyTilesRenderer.cpp @@ -27,11 +27,10 @@ namespace sk_tools { SkASSERT(pict != NULL); // Only work with absolute widths (as opposed to percentages). SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); - fPicture = pict; + fPicture.reset(pict)->ref(); this->CopyString(&fOutputDir, outputDir); this->CopyString(&fInputFilename, inputFilename); fUseChecksumBasedFilenames = useChecksumBasedFilenames; - fPicture->ref(); this->buildBBoxHierarchy(); // In order to avoid allocating a large canvas (particularly important for GPU), create one // canvas that is a multiple of the tile size, and draw portions of the picture. diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index f71b9544e0..a1098d9c16 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -120,7 +120,7 @@ void PictureRenderer::init(SkPicture* pict, const SkString* outputDir, SkASSERT(NULL == fPicture); SkASSERT(NULL == fCanvas.get()); - if (fPicture != NULL || NULL != fCanvas.get()) { + if (NULL != fPicture || NULL != fCanvas.get()) { return; } @@ -129,8 +129,7 @@ void PictureRenderer::init(SkPicture* pict, const SkString* outputDir, return; } - fPicture = pict; - fPicture->ref(); + fPicture.reset(pict)->ref(); fCanvas.reset(this->setupCanvas()); } @@ -246,8 +245,7 @@ void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { void PictureRenderer::end() { this->resetState(true); - SkSafeUnref(fPicture); - fPicture = NULL; + fPicture.reset(NULL); fCanvas.reset(NULL); } @@ -276,13 +274,12 @@ int PictureRenderer::getViewHeight() { void PictureRenderer::buildBBoxHierarchy() { SkASSERT(NULL != fPicture); if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) { - SkPicture* newPicture = this->createPicture(); - SkCanvas* recorder = newPicture->beginRecording(fPicture->width(), fPicture->height(), - this->recordFlags()); - fPicture->draw(recorder); - newPicture->endRecording(); - fPicture->unref(); - fPicture = newPicture; + SkAutoTUnref<SkPictureFactory> factory(this->getFactory()); + SkPictureRecorder recorder(factory); + SkCanvas* canvas = recorder.beginRecording(fPicture->width(), fPicture->height(), + this->recordFlags()); + fPicture->draw(canvas); + fPicture.reset(recorder.endRecording()); } } @@ -438,17 +435,18 @@ static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { } bool RecordPictureRenderer::render(SkBitmap** out) { - SkAutoTUnref<SkPicture> replayer(this->createPicture()); - SkCanvas* recorder = replayer->beginRecording(this->getViewWidth(), this->getViewHeight(), - this->recordFlags()); - this->scaleToScaleFactor(recorder); - fPicture->draw(recorder); - replayer->endRecording(); + SkAutoTUnref<SkPictureFactory> factory(this->getFactory()); + SkPictureRecorder recorder(factory); + SkCanvas* canvas = recorder.beginRecording(this->getViewWidth(), this->getViewHeight(), + this->recordFlags()); + this->scaleToScaleFactor(canvas); + fPicture->draw(canvas); + SkAutoTUnref<SkPicture> picture(recorder.endRecording()); if (!fOutputDir.isEmpty()) { // Record the new picture as a new SKP with PNG encoded bitmaps. SkString skpPath = SkOSPath::SkPathJoin(fOutputDir.c_str(), fInputFilename.c_str()); SkFILEWStream stream(skpPath.c_str()); - replayer->serialize(&stream, &encode_bitmap_to_data); + picture->serialize(&stream, &encode_bitmap_to_data); return true; } return false; @@ -499,7 +497,7 @@ void SimplePictureRenderer::init(SkPicture* picture, const SkString* outputDir, bool SimplePictureRenderer::render(SkBitmap** out) { SkASSERT(fCanvas.get() != NULL); - SkASSERT(fPicture != NULL); + SkASSERT(NULL != fPicture); if (NULL == fCanvas.get() || NULL == fPicture) { return false; } @@ -538,7 +536,7 @@ TiledPictureRenderer::TiledPictureRenderer() void TiledPictureRenderer::init(SkPicture* pict, const SkString* outputDir, const SkString* inputFilename, bool useChecksumBasedFilenames) { - SkASSERT(pict != NULL); + SkASSERT(NULL != pict); SkASSERT(0 == fTileRects.count()); if (NULL == pict || fTileRects.count() != 0) { return; @@ -546,7 +544,7 @@ void TiledPictureRenderer::init(SkPicture* pict, const SkString* outputDir, // Do not call INHERITED::init(), which would create a (potentially large) canvas which is not // used by bench_pictures. - fPicture = SkRef(pict); + fPicture.reset(pict)->ref(); this->CopyString(&fOutputDir, outputDir); this->CopyString(&fInputFilename, inputFilename); fUseChecksumBasedFilenames = useChecksumBasedFilenames; @@ -956,15 +954,16 @@ SkString MultiCorePictureRenderer::getConfigNameInternal() { /////////////////////////////////////////////////////////////////////////////////////////////// void PlaybackCreationRenderer::setup() { - fReplayer.reset(this->createPicture()); - SkCanvas* recorder = fReplayer->beginRecording(this->getViewWidth(), this->getViewHeight(), - this->recordFlags()); - this->scaleToScaleFactor(recorder); - recorder->drawPicture(*fPicture); + SkAutoTUnref<SkPictureFactory> factory(this->getFactory()); + fRecorder.reset(SkNEW_ARGS(SkPictureRecorder, (factory))); + SkCanvas* canvas = fRecorder->beginRecording(this->getViewWidth(), this->getViewHeight(), + this->recordFlags()); + this->scaleToScaleFactor(canvas); + canvas->drawPicture(*fPicture); } bool PlaybackCreationRenderer::render(SkBitmap** out) { - fReplayer->endRecording(); + fPicture.reset(fRecorder->endRecording()); // Since this class does not actually render, return false. return false; } @@ -978,7 +977,7 @@ SkString PlaybackCreationRenderer::getConfigNameInternal() { class RTreePicture : public SkPicture { public: - virtual SkBBoxHierarchy* createBBoxHierarchy() const SK_OVERRIDE{ + virtual SkBBoxHierarchy* createBBoxHierarchy() const SK_OVERRIDE { static const int kRTreeMinChildren = 6; static const int kRTreeMaxChildren = 11; SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(fWidth), @@ -989,18 +988,26 @@ public: } }; -SkPicture* PictureRenderer::createPicture() { +class SkRTreePictureFactory : public SkPictureFactory { +private: + virtual SkPicture* create(int width, int height) SK_OVERRIDE { + return SkNEW(RTreePicture); + } + +private: + typedef SkPictureFactory INHERITED; +}; + +SkPictureFactory* PictureRenderer::getFactory() { switch (fBBoxHierarchyType) { case kNone_BBoxHierarchyType: - return SkNEW(SkPicture); + return NULL; case kQuadTree_BBoxHierarchyType: - return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(fPicture->width(), - fPicture->height()))); + return SkNEW(SkQuadTreePictureFactory); case kRTree_BBoxHierarchyType: - return SkNEW(RTreePicture); + return SkNEW(SkRTreePictureFactory); case kTileGrid_BBoxHierarchyType: - return SkNEW_ARGS(SkTileGridPicture, (fPicture->width(), - fPicture->height(), fGridInfo)); + return new SkTileGridPictureFactory(fGridInfo); } SkASSERT(0); // invalid bbhType return NULL; diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 26bdb7790f..4c5b426887 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -376,8 +376,7 @@ public: } PictureRenderer() - : fPicture(NULL) - , fJsonSummaryPtr(NULL) + : fJsonSummaryPtr(NULL) , fDeviceType(kBitmap_DeviceType) , fBBoxHierarchyType(kNone_BBoxHierarchyType) , fScaleFactor(SK_Scalar1) @@ -401,7 +400,7 @@ public: protected: SkAutoTUnref<SkCanvas> fCanvas; - SkPicture* fPicture; + SkAutoTUnref<SkPicture> fPicture; bool fUseChecksumBasedFilenames; ImageResultsSummary* fJsonSummaryPtr; SkDeviceTypes fDeviceType; @@ -431,7 +430,7 @@ protected: */ void scaleToScaleFactor(SkCanvas*); - SkPicture* createPicture(); + SkPictureFactory* getFactory(); uint32_t recordFlags(); SkCanvas* setupCanvas(); virtual SkCanvas* setupCanvas(int width, int height); @@ -665,7 +664,7 @@ public: virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } private: - SkAutoTUnref<SkPicture> fReplayer; + SkAutoTDelete<SkPictureRecorder> fRecorder; virtual SkString getConfigNameInternal() SK_OVERRIDE; diff --git a/tools/bench_record.cpp b/tools/bench_record.cpp index e59744b1dc..283ba6ca57 100644 --- a/tools/bench_record.cpp +++ b/tools/bench_record.cpp @@ -33,40 +33,48 @@ DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tilegrid, quadtree"); DEFINE_bool(skr, false, "Record SKR instead of SKP."); -typedef SkPicture* (*PictureFactory)(const int width, const int height, int* recordingFlags); +typedef SkPictureFactory* (*PictureFactory)(int* recordingFlags); -static SkPicture* vanilla_factory(const int width, const int height, int* recordingFlags) { - return SkNEW(SkPicture); +static SkPictureFactory* vanilla_factory(int* recordingFlags) { + return NULL; } -static SkPicture* rtree_factory(const int width, const int height, int* recordingFlags) { +static SkPictureFactory* rtree_factory(int* recordingFlags) { *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; - return SkNEW(SkPicture); + return NULL; } -static SkPicture* tilegrid_factory(const int width, const int height, int* recordingFlags) { +static SkPictureFactory* tilegrid_factory(int* recordingFlags) { *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; SkTileGridPicture::TileGridInfo info; info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); info.fMargin.setEmpty(); info.fOffset.setZero(); - return SkNEW_ARGS(SkTileGridPicture, (width, height, info)); + return SkNEW_ARGS(SkTileGridPictureFactory, (info)); } -static SkPicture* quadtree_factory(const int width, const int height, int* recordingFlags) { +static SkPictureFactory* quadtree_factory(int* recordingFlags) { *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; - return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(width, height))); + return SkNEW(SkQuadTreePictureFactory); } static PictureFactory parse_FLAGS_bbh() { - if (FLAGS_bbh.isEmpty()) { return &vanilla_factory; } + if (FLAGS_bbh.isEmpty()) { + return &vanilla_factory; + } if (FLAGS_bbh.count() != 1) { SkDebugf("Multiple bbh arguments supplied.\n"); return NULL; } - if (FLAGS_bbh.contains("rtree")) { return rtree_factory; } - if (FLAGS_bbh.contains("tilegrid")) { return tilegrid_factory; } - if (FLAGS_bbh.contains("quadtree")) { return quadtree_factory; } + if (FLAGS_bbh.contains("rtree")) { + return rtree_factory; + } + if (FLAGS_bbh.contains("tilegrid")) { + return tilegrid_factory; + } + if (FLAGS_bbh.contains("quadtree")) { + return quadtree_factory; + } SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n", FLAGS_bbh[0]); return NULL; } @@ -85,13 +93,14 @@ static void bench_record(SkPicture* src, const char* name, PictureFactory pictur } } else { int recordingFlags = FLAGS_flags; - SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recordingFlags)); - SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); + SkAutoTUnref<SkPictureFactory> factory(pictureFactory(&recordingFlags)); + SkPictureRecorder recorder(factory); + SkCanvas* canvas = recorder.beginRecording(width, height, recordingFlags); if (NULL != src) { src->draw(canvas); } if (FLAGS_endRecording) { - dst->endRecording(); + SkAutoTUnref<SkPicture> dst(recorder.endRecording()); } } } diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp index 39c484d724..b61e15d656 100644 --- a/tools/filtermain.cpp +++ b/tools/filtermain.cpp @@ -717,15 +717,14 @@ static int filter_picture(const SkString& inFile, const SkString& outFile) { int numAfter = debugCanvas.getSize(); if (!outFile.isEmpty()) { - SkPicture outPicture; - - SkCanvas* canvas = outPicture.beginRecording(inPicture->width(), inPicture->height()); + SkPictureRecorder recorder; + SkCanvas* canvas = recorder.beginRecording(inPicture->width(), inPicture->height()); debugCanvas.draw(canvas); - outPicture.endRecording(); + SkAutoTUnref<SkPicture> outPicture(recorder.endRecording()); SkFILEWStream outStream(outFile.c_str()); - outPicture.serialize(&outStream); + outPicture->serialize(&outStream); } bool someOptFired = false; diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index 7ebbdbd3aa..0e68117c72 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -174,9 +174,9 @@ static bool render_picture_internal(const SkString& inputPath, const SkString* o while (FLAGS_bench_record) { const int kRecordFlags = 0; - SkPicture other; - picture->draw(other.beginRecording(picture->width(), picture->height(), kRecordFlags)); - other.endRecording(); + SkPictureRecorder recorder; + picture->draw(recorder.beginRecording(picture->width(), picture->height(), kRecordFlags)); + SkAutoTUnref<SkPicture> other(recorder.endRecording()); } for (int i = 0; i < FLAGS_clone; ++i) { diff --git a/tools/skpmaker.cpp b/tools/skpmaker.cpp index 00082075c7..740d522366 100644 --- a/tools/skpmaker.cpp +++ b/tools/skpmaker.cpp @@ -26,8 +26,8 @@ DEFINE_string(writePath, "", "Filepath to write the SKP into."); static void skpmaker(int width, int height, int border, SkColor color, const char *writePath) { - SkPicture pict; - SkCanvas* canvas = pict.beginRecording(width, height); + SkPictureRecorder recorder; + SkCanvas* canvas = recorder.beginRecording(width, height); SkPaint paint; paint.setStyle(SkPaint::kFill_Style); paint.setColor(SK_ColorBLACK); @@ -36,9 +36,9 @@ static void skpmaker(int width, int height, int border, SkColor color, canvas->drawRectCoords(SkIntToScalar(border), SkIntToScalar(border), SkIntToScalar(width - border*2), SkIntToScalar(height - border*2), paint); - pict.endRecording(); + SkAutoTUnref<SkPicture> pict(recorder.endRecording()); SkFILEWStream stream(writePath); - pict.serialize(&stream); + pict->serialize(&stream); } int tool_main(int argc, char** argv); |