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 /bench | |
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 'bench')
-rw-r--r-- | bench/PicturePlaybackBench.cpp | 15 | ||||
-rw-r--r-- | bench/PictureRecordBench.cpp | 16 | ||||
-rw-r--r-- | bench/benchmain.cpp | 37 |
3 files changed, 38 insertions, 30 deletions
diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp index 815ef0b777..fa693c2468 100644 --- a/bench/PicturePlaybackBench.cpp +++ b/bench/PicturePlaybackBench.cpp @@ -37,16 +37,15 @@ protected: virtual void onDraw(const int loops, SkCanvas* canvas) { - SkPicture picture; - - SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); - recordCanvas(pCanvas); - picture.endRecording(); + SkPictureRecorder recorder; + SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); + this->recordCanvas(pCanvas); + SkAutoTUnref<SkPicture> picture(recorder.endRecording()); const SkPoint translateDelta = getTranslateDelta(loops); for (int i = 0; i < loops; i++) { - picture.draw(canvas); + picture->draw(canvas); canvas->translate(translateDelta.fX, translateDelta.fY); } } @@ -71,7 +70,7 @@ class TextPlaybackBench : public PicturePlaybackBench { public: TextPlaybackBench() : INHERITED("drawText") { } protected: - virtual void recordCanvas(SkCanvas* canvas) { + virtual void recordCanvas(SkCanvas* canvas) SK_OVERRIDE { SkPaint paint; paint.setTextSize(fTextSize); paint.setColor(SK_ColorBLACK); @@ -96,7 +95,7 @@ public: : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText") , fDrawPosH(drawPosH) { } protected: - virtual void recordCanvas(SkCanvas* canvas) { + virtual void recordCanvas(SkCanvas* canvas) SK_OVERRIDE { SkPaint paint; paint.setTextSize(fTextSize); paint.setColor(SK_ColorBLACK); diff --git a/bench/PictureRecordBench.cpp b/bench/PictureRecordBench.cpp index 4083f81af7..4c82fe2881 100644 --- a/bench/PictureRecordBench.cpp +++ b/bench/PictureRecordBench.cpp @@ -51,15 +51,15 @@ public: protected: virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { - SkAutoTDelete<SkPicture> picture; + SkPictureRecorder recorder; SkCanvas* canvas = NULL; const SkPoint translateDelta = getTranslateDelta(loops); for (int i = 0; i < loops; i++) { if (0 == i % kMaxLoopsPerCanvas) { - picture.reset(SkNEW(SkPicture)); - canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); + SkAutoTUnref<SkPicture> picture(recorder.endRecording()); + canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); } SkColor color = SK_ColorYELLOW + (i % 255); @@ -120,12 +120,12 @@ protected: virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { SkRandom rand; SkPaint paint; - SkAutoTDelete<SkPicture> picture; + SkPictureRecorder recorder; SkCanvas* canvas = NULL; for (int i = 0; i < loops; i++) { if (0 == i % kMaxLoopsPerCanvas) { - picture.reset(SkNEW(SkPicture)); - canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); + SkAutoTUnref<SkPicture> picture(recorder.endRecording()); + canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); } paint.setColor(rand.nextU()); canvas->drawPaint(paint); @@ -158,8 +158,8 @@ public: }; protected: virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { - SkPicture picture; - SkCanvas* canvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); + SkPictureRecorder recorder; + SkCanvas* canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); for (int i = 0; i < loops; i++) { canvas->drawPaint(fPaint[i % ObjCount]); } diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index cc55bb9f29..eb3947abad 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -122,7 +122,7 @@ static void saveFile(const char name[], const char config[], const char dir[], stream.write(data->data(), data->size()); } -static void performClip(SkCanvas* canvas, int w, int h) { +static void perform_clip(SkCanvas* canvas, int w, int h) { SkRect r; r.set(SkIntToScalar(10), SkIntToScalar(10), @@ -134,7 +134,7 @@ static void performClip(SkCanvas* canvas, int w, int h) { canvas->clipRect(r, SkRegion::kXOR_Op); } -static void performRotate(SkCanvas* canvas, int w, int h) { +static void perform_rotate(SkCanvas* canvas, int w, int h) { const SkScalar x = SkIntToScalar(w) / 2; const SkScalar y = SkIntToScalar(h) / 2; @@ -143,7 +143,7 @@ static void performRotate(SkCanvas* canvas, int w, int h) { canvas->translate(-x, -y); } -static void performScale(SkCanvas* canvas, int w, int h) { +static void perform_scale(SkCanvas* canvas, int w, int h) { const SkScalar x = SkIntToScalar(w) / 2; const SkScalar y = SkIntToScalar(h) / 2; @@ -480,7 +480,8 @@ int tool_main(int argc, char** argv) { #endif SkAutoTUnref<SkCanvas> canvas; - SkPicture recordFrom, recordTo; + SkAutoTUnref<SkPicture> recordFrom; + SkPictureRecorder recorderTo; const SkIPoint dim = bench->getSize(); const SkPicture::RecordingFlags kRecordFlags = @@ -505,13 +506,15 @@ int tool_main(int argc, char** argv) { canvas.reset(SkDeferredCanvas::Create(surface.get())); break; case kRecord_BenchMode: - canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); + canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); break; - case kPictureRecord_BenchMode: - bench->draw(1, recordFrom.beginRecording(dim.fX, dim.fY, kRecordFlags)); - recordFrom.endRecording(); - canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); + case kPictureRecord_BenchMode: { + SkPictureRecorder recorderFrom; + bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.fY, kRecordFlags)); + recordFrom.reset(recorderFrom.endRecording()); + canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); break; + } case kNormal_BenchMode: canvas.reset(SkRef(surface->getCanvas())); break; @@ -522,9 +525,15 @@ int tool_main(int argc, char** argv) { if (NULL != canvas) { canvas->clear(SK_ColorWHITE); - if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } - if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } - if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } + if (FLAGS_clip) { + perform_clip(canvas, dim.fX, dim.fY); + } + if (FLAGS_scale) { + perform_scale(canvas, dim.fX, dim.fY); + } + if (FLAGS_rotate) { + perform_rotate(canvas, dim.fX, dim.fY); + } } if (!loggedBenchName) { @@ -569,7 +578,7 @@ int tool_main(int argc, char** argv) { if ((benchMode == kRecord_BenchMode || benchMode == kPictureRecord_BenchMode)) { // Clear the recorded commands so that they do not accumulate. - canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); + canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); } timer.start(); @@ -591,7 +600,7 @@ int tool_main(int argc, char** argv) { } if (benchMode == kPictureRecord_BenchMode) { - recordFrom.draw(canvas); + recordFrom->draw(canvas); } else { bench->draw(loops, canvas); } |