diff options
author | djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-30 16:50:11 +0000 |
---|---|---|
committer | djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-30 16:50:11 +0000 |
commit | dde718c558b118e2a918d14046770a8c37d75040 (patch) | |
tree | 0e79cfbfdde6eb1d92ab58710a21b1f66c898feb | |
parent | 00bf06a142e49f2d6f398127d7e3cf747559a461 (diff) |
Add bench to test the performance of creating a picture.
Review URL: https://codereview.appspot.com/6258062
git-svn-id: http://skia.googlecode.com/svn/trunk@4076 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/PictureRecordBench.cpp | 130 | ||||
-rw-r--r-- | gyp/bench.gypi | 1 |
2 files changed, 131 insertions, 0 deletions
diff --git a/bench/PictureRecordBench.cpp b/bench/PictureRecordBench.cpp new file mode 100644 index 0000000000..e42e5346e1 --- /dev/null +++ b/bench/PictureRecordBench.cpp @@ -0,0 +1,130 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkBenchmark.h" +#include "SkCanvas.h" +#include "SkColor.h" +#include "SkPaint.h" +#include "SkPicture.h" +#include "SkPoint.h" +#include "SkRect.h" +#include "SkString.h" + +class PictureRecordBench : public SkBenchmark { +public: + PictureRecordBench(void* param, const char name[]) : INHERITED(param) { + fName.printf("picture_record_%s", name); + fPictureWidth = SkIntToScalar(PICTURE_WIDTH); + fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); + } + + enum { + N = SkBENCHLOOP(25), // number of times to create the picture + PICTURE_WIDTH = 1000, + PICTURE_HEIGHT = 4000, + }; +protected: + virtual const char* onGetName() { + return fName.c_str(); + } + + virtual void onDraw(SkCanvas* canvas) { + + for (int i = 0; i < N; i++) { + + SkPicture picture; + + SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); + recordCanvas(pCanvas); + + // we don't need to draw the picture as the endRecording step will + // do the work of transferring the recorded content into a playback + // object. + picture.endRecording(); + } + } + + virtual void recordCanvas(SkCanvas* canvas) = 0; + + SkString fName; + SkScalar fPictureWidth; + SkScalar fPictureHeight; + SkScalar fTextSize; +private: + typedef SkBenchmark INHERITED; +}; + +/* + * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, + * and regions. This bench populates those dictionaries to test the speed of + * reading and writing to those particular dictionary data structures. + */ +class DictionaryRecordBench : public PictureRecordBench { +public: + DictionaryRecordBench(void* param) + : INHERITED(param, "dictionaries") { } + + enum { + M = SkBENCHLOOP(100), // number of elements in each dictionary + }; +protected: + virtual void recordCanvas(SkCanvas* canvas) { + + const SkPoint translateDelta = getTranslateDelta(); + + for (int i = 0; i < M; i++) { + + SkColor color = SK_ColorYELLOW + (i % 255); + SkIRect rect = SkIRect::MakeWH(i,i); + + canvas->save(); + + // set the clip to the given region + SkRegion region; + region.setRect(rect); + canvas->clipRegion(region); + + // fill the clip with a color + SkPaint paint; + paint.setColor(color); + canvas->drawPaint(paint); + + // set a matrix on the canvas + SkMatrix matrix; + matrix.setRotate(SkIntToScalar(i % 360)); + canvas->setMatrix(matrix); + + // create a simple bitmap + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kRGB_565_Config, 10, 10); + bitmap.allocPixels(); + + // draw a single color into the bitmap + SkCanvas bitmapCanvas(bitmap); + bitmapCanvas.drawColor(SkColorSetA(color, i % 255)); + + // draw the bitmap onto the canvas + canvas->drawBitmapMatrix(bitmap, matrix); + + canvas->restore(); + canvas->translate(translateDelta.fX, translateDelta.fY); + } + } + + SkPoint getTranslateDelta() { + SkIPoint canvasSize = onGetSize(); + return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/M), + SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/M)); + } +private: + typedef PictureRecordBench INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } + +static BenchRegistry gReg0(Fact0); diff --git a/gyp/bench.gypi b/gyp/bench.gypi index 0489ac655d..ce089d66ac 100644 --- a/gyp/bench.gypi +++ b/gyp/bench.gypi @@ -33,6 +33,7 @@ '../bench/PathBench.cpp', '../bench/PathIterBench.cpp', '../bench/PicturePlaybackBench.cpp', + '../bench/PictureRecordBench.cpp', '../bench/RectBench.cpp', '../bench/RefCntBench.cpp', '../bench/RegionBench.cpp', |