f168b86d7f
This idea came while commenting on https://codereview.chromium.org/343583005/ Since SkBenchmark, SkBenchLogger and SkGMBench are not part of the Skia library, they should not have the Sk prefix. BUG=None TEST=make all R=mtklein@google.com Author: tfarina@chromium.org Review URL: https://codereview.chromium.org/347823004
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
* 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 "Benchmark.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkGraphics.h"
|
|
#include "SkPaint.h"
|
|
#include "SkRandom.h"
|
|
#include "SkString.h"
|
|
|
|
class FontScalerBench : public Benchmark {
|
|
SkString fName;
|
|
SkString fText;
|
|
bool fDoLCD;
|
|
public:
|
|
FontScalerBench(bool doLCD) {
|
|
fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
|
|
fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
|
|
fDoLCD = doLCD;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
|
SkPaint paint;
|
|
this->setupPaint(&paint);
|
|
paint.setLCDRenderText(fDoLCD);
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
// 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));
|
|
canvas->drawText(fText.c_str(), fText.size(),
|
|
0, SkIntToScalar(20), paint);
|
|
}
|
|
}
|
|
}
|
|
private:
|
|
typedef Benchmark INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); )
|
|
DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); )
|