2012-02-23 20:57:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-02-23 20:57:09 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-02-23 20:57:09 +00:00
|
|
|
#include "SkPoint.h"
|
2014-11-11 18:39:27 +00:00
|
|
|
#include "SkRandom.h"
|
2012-02-23 20:57:09 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
// This is designed to emulate about 4 screens of textual content
|
|
|
|
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class PicturePlaybackBench : public Benchmark {
|
2012-02-23 20:57:09 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PicturePlaybackBench(const char name[]) {
|
2012-02-23 20:57:09 +00:00
|
|
|
fName.printf("picture_playback_%s", name);
|
|
|
|
fPictureWidth = SkIntToScalar(PICTURE_WIDTH);
|
|
|
|
fPictureHeight = SkIntToScalar(PICTURE_HEIGHT);
|
|
|
|
fTextSize = SkIntToScalar(TEXT_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PICTURE_WIDTH = 1000,
|
|
|
|
PICTURE_HEIGHT = 4000,
|
|
|
|
TEXT_SIZE = 10
|
|
|
|
};
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
2012-02-23 20:57:09 +00:00
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-04-17 23:35:06 +00:00
|
|
|
SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, NULL, 0);
|
2014-04-13 19:09:42 +00:00
|
|
|
this->recordCanvas(pCanvas);
|
|
|
|
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
|
2012-02-23 20:57:09 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
const SkPoint translateDelta = getTranslateDelta(loops);
|
2012-02-23 20:57:09 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2014-09-04 15:42:50 +00:00
|
|
|
picture->playback(canvas);
|
2012-02-23 20:57:09 +00:00
|
|
|
canvas->translate(translateDelta.fX, translateDelta.fY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void recordCanvas(SkCanvas* canvas) = 0;
|
2013-09-10 19:23:38 +00:00
|
|
|
virtual SkPoint getTranslateDelta(int N) {
|
2012-02-23 20:57:09 +00:00
|
|
|
SkIPoint canvasSize = onGetSize();
|
|
|
|
return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N),
|
|
|
|
SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N));
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString fName;
|
|
|
|
SkScalar fPictureWidth;
|
|
|
|
SkScalar fPictureHeight;
|
|
|
|
SkScalar fTextSize;
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-02-23 20:57:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TextPlaybackBench : public PicturePlaybackBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
TextPlaybackBench() : INHERITED("drawText") { }
|
2012-02-23 20:57:09 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void recordCanvas(SkCanvas* canvas) override {
|
2012-02-23 20:57:09 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(fTextSize);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
size_t len = strlen(text);
|
|
|
|
const SkScalar textWidth = paint.measureText(text, len);
|
|
|
|
|
|
|
|
for (SkScalar x = 0; x < fPictureWidth; x += textWidth) {
|
|
|
|
for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) {
|
|
|
|
canvas->drawText(text, len, x, y, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PicturePlaybackBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PosTextPlaybackBench : public PicturePlaybackBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PosTextPlaybackBench(bool drawPosH)
|
|
|
|
: INHERITED(drawPosH ? "drawPosTextH" : "drawPosText")
|
2012-02-27 16:22:48 +00:00
|
|
|
, fDrawPosH(drawPosH) { }
|
2012-02-23 20:57:09 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void recordCanvas(SkCanvas* canvas) override {
|
2012-02-23 20:57:09 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(fTextSize);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
size_t len = strlen(text);
|
|
|
|
const SkScalar textWidth = paint.measureText(text, len);
|
|
|
|
|
|
|
|
SkScalar* adv = new SkScalar[len];
|
|
|
|
paint.getTextWidths(text, len, adv);
|
|
|
|
|
|
|
|
for (SkScalar x = 0; x < fPictureWidth; x += textWidth) {
|
|
|
|
for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) {
|
|
|
|
|
|
|
|
SkPoint* pos = new SkPoint[len];
|
|
|
|
SkScalar advX = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
if (fDrawPosH)
|
|
|
|
pos[i].set(x + advX, y);
|
|
|
|
else
|
2012-08-20 18:58:26 +00:00
|
|
|
pos[i].set(x + advX, y + i);
|
2012-02-23 20:57:09 +00:00
|
|
|
advX += adv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawPosText(text, len, pos, paint);
|
|
|
|
delete[] pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] adv;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool fDrawPosH;
|
|
|
|
typedef PicturePlaybackBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new TextPlaybackBench(); )
|
|
|
|
DEF_BENCH( return new PosTextPlaybackBench(true); )
|
|
|
|
DEF_BENCH( return new PosTextPlaybackBench(false); )
|
2014-11-11 18:39:27 +00:00
|
|
|
|
|
|
|
// Chrome draws into small tiles with impl-side painting.
|
|
|
|
// This benchmark measures the relative performance of our bounding-box hierarchies,
|
|
|
|
// both when querying tiles perfectly and when not.
|
2015-01-09 14:41:48 +00:00
|
|
|
enum BBH { kNone, kRTree };
|
2014-11-11 18:39:27 +00:00
|
|
|
enum Mode { kTiled, kRandom };
|
|
|
|
class TiledPlaybackBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tiled_playback") {
|
|
|
|
switch (fBBH) {
|
|
|
|
case kNone: fName.append("_none" ); break;
|
|
|
|
case kRTree: fName.append("_rtree" ); break;
|
|
|
|
}
|
|
|
|
switch (fMode) {
|
|
|
|
case kTiled: fName.append("_tiled" ); break;
|
|
|
|
case kRandom: fName.append("_random"); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
|
|
|
SkIPoint onGetSize() override { return SkIPoint::Make(1024,1024); }
|
2014-11-11 18:39:27 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2014-11-11 18:39:27 +00:00
|
|
|
SkAutoTDelete<SkBBHFactory> factory;
|
|
|
|
switch (fBBH) {
|
|
|
|
case kNone: break;
|
|
|
|
case kRTree: factory.reset(new SkRTreeFactory); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory);
|
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < 10000; i++) {
|
|
|
|
SkScalar x = rand.nextRangeScalar(0, 1024),
|
|
|
|
y = rand.nextRangeScalar(0, 1024),
|
|
|
|
w = rand.nextRangeScalar(0, 128),
|
|
|
|
h = rand.nextRangeScalar(0, 128);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(rand.nextU());
|
|
|
|
paint.setAlpha(0xFF);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
|
|
|
|
}
|
|
|
|
fPic.reset(recorder.endRecording());
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2014-11-11 18:39:27 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
// This inner loop guarantees we make the same choices for all bench variants.
|
|
|
|
SkRandom rand;
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
SkScalar x = 0, y = 0;
|
|
|
|
switch (fMode) {
|
|
|
|
case kTiled: x = SkScalar(256 * rand.nextULessThan(4));
|
|
|
|
y = SkScalar(256 * rand.nextULessThan(4));
|
|
|
|
break;
|
|
|
|
case kRandom: x = rand.nextRangeScalar(0, 768);
|
|
|
|
y = rand.nextRangeScalar(0, 768);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkAutoCanvasRestore ar(canvas, true/*save now*/);
|
|
|
|
canvas->clipRect(SkRect::MakeXYWH(x,y,256,256));
|
|
|
|
fPic->playback(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-11-24 20:02:31 +00:00
|
|
|
BBH fBBH;
|
|
|
|
Mode fMode;
|
|
|
|
SkString fName;
|
|
|
|
SkAutoTUnref<SkPicture> fPic;
|
2014-11-11 18:39:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); )
|