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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
extern bool gSkSuppressFontCachePurgeSpew;
|
|
|
|
|
|
|
|
class FontScalerBench : public SkBenchmark {
|
|
|
|
SkString fName;
|
|
|
|
SkString fText;
|
2011-11-03 13:45:38 +00:00
|
|
|
bool fDoLCD;
|
2011-11-02 21:02:57 +00:00
|
|
|
public:
|
2011-11-03 13:45:38 +00:00
|
|
|
FontScalerBench(void* param, bool doLCD) : INHERITED(param) {
|
|
|
|
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(); }
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
2011-11-03 13:45:38 +00:00
|
|
|
paint.setLCDRenderText(fDoLCD);
|
2011-11-02 21:02:57 +00:00
|
|
|
|
|
|
|
bool prev = gSkSuppressFontCachePurgeSpew;
|
|
|
|
gSkSuppressFontCachePurgeSpew = true;
|
|
|
|
|
|
|
|
// this is critical - we want to time the creation process, so we
|
|
|
|
// explicitly flush our cache before each run
|
2011-11-08 20:03:48 +00:00
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
|
2011-11-02 21:02:57 +00:00
|
|
|
for (int ps = 9; ps <= 24; ps += 2) {
|
|
|
|
paint.setTextSize(SkIntToScalar(ps));
|
|
|
|
canvas->drawText(fText.c_str(), fText.size(),
|
|
|
|
0, SkIntToScalar(20), paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
gSkSuppressFontCachePurgeSpew = prev;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-11-03 13:45:38 +00:00
|
|
|
static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(FontScalerBench, (p, false)); }
|
|
|
|
static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(FontScalerBench, (p, true)); }
|
2011-11-02 21:02:57 +00:00
|
|
|
|
2011-11-03 13:45:38 +00:00
|
|
|
static BenchRegistry gReg0(Fact0);
|
|
|
|
static BenchRegistry gReg1(Fact1);
|