blob: 596b830809c81eefe8a4f84e59cc6a6a5335228b [file] [log] [blame]
reed@google.com6e5a45c2011-11-02 21:02:57 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBenchmark.h"
9#include "SkCanvas.h"
10#include "SkGraphics.h"
11#include "SkPaint.h"
12#include "SkRandom.h"
13#include "SkString.h"
14
15extern bool gSkSuppressFontCachePurgeSpew;
16
17class FontScalerBench : public SkBenchmark {
18 SkString fName;
19 SkString fText;
20public:
21 FontScalerBench(void* param) : INHERITED(param) {
22 fName.set("fontscaler");
23 fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
24 }
25
26protected:
27 virtual const char* onGetName() { return fName.c_str(); }
28 virtual void onDraw(SkCanvas* canvas) {
29 SkPaint paint;
30 this->setupPaint(&paint);
31
32 bool prev = gSkSuppressFontCachePurgeSpew;
33 gSkSuppressFontCachePurgeSpew = true;
34
35 // this is critical - we want to time the creation process, so we
36 // explicitly flush our cache before each run
37 SkGraphics::SetFontCacheUsed(0);
38 for (int ps = 9; ps <= 24; ps += 2) {
39 paint.setTextSize(SkIntToScalar(ps));
40 canvas->drawText(fText.c_str(), fText.size(),
41 0, SkIntToScalar(20), paint);
42 }
43
44 gSkSuppressFontCachePurgeSpew = prev;
45 }
46private:
47 typedef SkBenchmark INHERITED;
48};
49
50///////////////////////////////////////////////////////////////////////////////
51
52static SkBenchmark* Fact(void* p) { return SkNEW_ARGS(FontScalerBench, (p)); }
53
54static BenchRegistry gReg(Fact);