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.
|
|
|
|
*/
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#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"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
// This is designed to emulate about 4 screens of textual content
|
|
|
|
|
|
|
|
|
|
|
|
class PicturePlaybackBench : public SkBenchmark {
|
|
|
|
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-04-13 19:09:42 +00:00
|
|
|
picture->draw(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:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2014-04-13 19:09:42 +00:00
|
|
|
virtual void recordCanvas(SkCanvas* canvas) SK_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:
|
2014-04-13 19:09:42 +00:00
|
|
|
virtual void recordCanvas(SkCanvas* canvas) SK_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); )
|