aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/FontCacheBench.cpp
blob: 4224e87093a93bedb096f1fab2d2635fff5bd914 (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
/*
 * Copyright 2013 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 "SkFontHost.h"
#include "SkPaint.h"
#include "SkString.h"
#include "SkTemplates.h"

#include "glyphs.h"

class FontCacheBench : public SkBenchmark {
    enum { N = SkBENCHLOOP(800) };
public:
    FontCacheBench(void* param) : INHERITED(param) {
    }

protected:
    virtual const char* onGetName() SK_OVERRIDE {
        return "fontcache";
    }

    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
        SkPaint paint;
        this->setupPaint(&paint);
        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

        for (int i = 0; i < N; ++i) {
            const int16_t* array = gUniqueGlyphIDs;
            while (*array >= 0) {
                const int16_t* end = array + 1;
                while (*end >= 0) {
                    end += 1;
                }
                paint.measureText(array, end - array);
                array = end + 1;    // skip the sentinel
            }
        }
    }

private:
    typedef SkBenchmark INHERITED;
};

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

DEF_BENCH( return new FontCacheBench(p); )