aboutsummaryrefslogtreecommitdiffstats
path: root/bench/FontScalerBench.cpp
blob: 4ac6a35e081577a83ed0f49f87769aa807620b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * 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;
    bool     fDoLCD;
public:
    FontScalerBench(void* param, bool doLCD) : INHERITED(param) {
        fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
        fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
        fDoLCD = doLCD;
    }

protected:
    virtual const char* onGetName() { return fName.c_str(); }
    virtual void onDraw(SkCanvas* canvas) {
        SkPaint paint;
        this->setupPaint(&paint);
        paint.setLCDRenderText(fDoLCD);

        bool prev = gSkSuppressFontCachePurgeSpew;
        gSkSuppressFontCachePurgeSpew = true;

        // 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);
        }

        gSkSuppressFontCachePurgeSpew = prev;
    }
private:
    typedef SkBenchmark INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(FontScalerBench, (p, false)); }
static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(FontScalerBench, (p, true)); }

static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1);