2011-11-15 15:29:45 +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.
|
|
|
|
*/
|
2016-03-25 16:08:00 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2011-11-15 15:29:45 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
|
|
|
|
#define STR "Hamburgefons"
|
|
|
|
|
|
|
|
enum FontQuality {
|
|
|
|
kBW,
|
|
|
|
kAA,
|
|
|
|
kLCD
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* fontQualityName(const SkPaint& paint) {
|
|
|
|
if (!paint.isAntiAlias()) {
|
|
|
|
return "BW";
|
|
|
|
}
|
|
|
|
if (paint.isLCDRenderText()) {
|
|
|
|
return "LCD";
|
|
|
|
}
|
|
|
|
return "AA";
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ShaderMaskBench : public Benchmark {
|
2011-11-15 15:29:45 +00:00
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fText;
|
|
|
|
SkString fName;
|
|
|
|
FontQuality fFQ;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ShaderMaskBench(bool isOpaque, FontQuality fq) {
|
2011-11-15 15:29:45 +00:00
|
|
|
fFQ = fq;
|
|
|
|
fText.set(STR);
|
|
|
|
|
|
|
|
fPaint.setAntiAlias(kBW != fq);
|
|
|
|
fPaint.setLCDRenderText(kLCD == fq);
|
2016-03-25 16:08:00 +00:00
|
|
|
fPaint.setShader(SkShader::MakeColorShader(isOpaque ? 0xFFFFFFFF : 0x80808080));
|
2011-11-15 15:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
2012-08-14 15:03:35 +00:00
|
|
|
fName.printf("shadermask");
|
2011-11-15 15:29:45 +00:00
|
|
|
fName.appendf("_%s", fontQualityName(fPaint));
|
|
|
|
fName.appendf("_%02X", fPaint.getAlpha());
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas* canvas) {
|
2011-11-15 15:29:45 +00:00
|
|
|
const SkIPoint dim = this->getSize();
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-11-15 15:29:45 +00:00
|
|
|
|
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
// explicitly need these
|
|
|
|
paint.setAlpha(fPaint.getAlpha());
|
|
|
|
paint.setAntiAlias(kBW != fFQ);
|
|
|
|
paint.setLCDRenderText(kLCD == fFQ);
|
|
|
|
|
|
|
|
const SkScalar x0 = SkIntToScalar(-10);
|
|
|
|
const SkScalar y0 = SkIntToScalar(-10);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-11-15 15:29:45 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(12));
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2011-11-15 15:29:45 +00:00
|
|
|
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
|
|
|
|
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
|
|
|
|
canvas->drawText(fText.c_str(), fText.size(), x, y, paint);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-11-15 15:29:45 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(48));
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops / 4 ; i++) {
|
2011-11-15 15:29:45 +00:00
|
|
|
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
|
|
|
|
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
|
|
|
|
canvas->drawText(fText.c_str(), fText.size(), x, y, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-11-15 15:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ShaderMaskBench(true, kBW); )
|
|
|
|
DEF_BENCH( return new ShaderMaskBench(false, kBW); )
|
|
|
|
DEF_BENCH( return new ShaderMaskBench(true, kAA); )
|
|
|
|
DEF_BENCH( return new ShaderMaskBench(false, kAA); )
|
|
|
|
DEF_BENCH( return new ShaderMaskBench(true, kLCD); )
|
|
|
|
DEF_BENCH( return new ShaderMaskBench(false, kLCD); )
|