blob: 4f0bd07c416016fd9321fc81236804c802a1c45b [file] [log] [blame]
reed@google.com8af03712013-06-11 19:18:44 +00001/*
2 * Copyright 2013 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 "SkFontHost.h"
11#include "SkPaint.h"
12#include "SkString.h"
13#include "SkTemplates.h"
14
reed@google.com664621a2013-06-11 19:24:08 +000015#include "gUniqueGlyphIDs.h"
reed@google.com8af03712013-06-11 19:18:44 +000016
17class FontCacheBench : public SkBenchmark {
reed@google.com2fef6d22013-06-11 20:25:53 +000018 enum { N = SkBENCHLOOP(50) };
reed@google.com8af03712013-06-11 19:18:44 +000019public:
20 FontCacheBench(void* param) : INHERITED(param) {
21 }
22
23protected:
24 virtual const char* onGetName() SK_OVERRIDE {
25 return "fontcache";
26 }
27
28 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
29 SkPaint paint;
30 this->setupPaint(&paint);
31 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
32
reed@google.com2fef6d22013-06-11 20:25:53 +000033 const uint16_t* array = gUniqueGlyphIDs;
34 while (*array != 0xFFFF) {
35 const uint16_t* end = array + 1;
36 while (*end != 0xFFFF) {
37 end += 1;
reed@google.com8af03712013-06-11 19:18:44 +000038 }
reed@google.com2fef6d22013-06-11 20:25:53 +000039 for (int i = 0; i < N; ++i) {
reed@google.com5872e002013-06-11 21:42:54 +000040 size_t len = (end - array) * sizeof(uint16_t);
41 paint.measureText(array, len);
reed@google.com2fef6d22013-06-11 20:25:53 +000042 }
43 array = end + 1; // skip the sentinel
reed@google.com8af03712013-06-11 19:18:44 +000044 }
45 }
46
47private:
48 typedef SkBenchmark INHERITED;
49};
50
51///////////////////////////////////////////////////////////////////////////////
52
53DEF_BENCH( return new FontCacheBench(p); )