2011-11-02 21:02:57 +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"
|
2011-11-02 21:02:57 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class FontScalerBench : public Benchmark {
|
2011-11-02 21:02:57 +00:00
|
|
|
SkString fName;
|
|
|
|
SkString fText;
|
2011-11-03 13:45:38 +00:00
|
|
|
bool fDoLCD;
|
2011-11-02 21:02:57 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
FontScalerBench(bool doLCD) {
|
2011-11-03 13:45:38 +00:00
|
|
|
fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
|
2011-11-02 21:02:57 +00:00
|
|
|
fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
|
2011-11-03 13:45:38 +00:00
|
|
|
fDoLCD = doLCD;
|
2011-11-02 21:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas* canvas) {
|
2011-11-02 21:02:57 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
2011-11-03 13:45:38 +00:00
|
|
|
paint.setLCDRenderText(fDoLCD);
|
2011-11-02 21:02:57 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
// this is critical - we want to time the creation process, so we
|
|
|
|
// explicitly flush our cache before each run
|
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
|
|
|
|
for (int ps = 9; ps <= 24; ps += 2) {
|
|
|
|
paint.setTextSize(SkIntToScalar(ps));
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(fText,
|
2013-09-10 19:23:38 +00:00
|
|
|
0, SkIntToScalar(20), paint);
|
|
|
|
}
|
2011-11-02 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-11-02 21:02:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new FontScalerBench(false);)
|
|
|
|
DEF_BENCH(return new FontScalerBench(true);)
|