blob: ac4f60ec3250b1f5dfca6312d61ee14eaccb5046 [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;
reed@google.com8e372c92011-11-03 13:45:38 +000020 bool fDoLCD;
reed@google.com6e5a45c2011-11-02 21:02:57 +000021public:
reed@google.com8e372c92011-11-03 13:45:38 +000022 FontScalerBench(void* param, bool doLCD) : INHERITED(param) {
23 fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
reed@google.com6e5a45c2011-11-02 21:02:57 +000024 fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
reed@google.com8e372c92011-11-03 13:45:38 +000025 fDoLCD = doLCD;
reed@google.com6e5a45c2011-11-02 21:02:57 +000026 }
27
28protected:
29 virtual const char* onGetName() { return fName.c_str(); }
30 virtual void onDraw(SkCanvas* canvas) {
31 SkPaint paint;
32 this->setupPaint(&paint);
reed@google.com8e372c92011-11-03 13:45:38 +000033 paint.setLCDRenderText(fDoLCD);
reed@google.com6e5a45c2011-11-02 21:02:57 +000034
35 bool prev = gSkSuppressFontCachePurgeSpew;
36 gSkSuppressFontCachePurgeSpew = true;
37
mtklein@google.comc2897432013-09-10 19:23:38 +000038 for (int i = 0; i < this->getLoops(); i++) {
39 // this is critical - we want to time the creation process, so we
40 // explicitly flush our cache before each run
41 SkGraphics::PurgeFontCache();
reed@google.com073c9072011-11-08 20:03:48 +000042
mtklein@google.comc2897432013-09-10 19:23:38 +000043 for (int ps = 9; ps <= 24; ps += 2) {
44 paint.setTextSize(SkIntToScalar(ps));
45 canvas->drawText(fText.c_str(), fText.size(),
46 0, SkIntToScalar(20), paint);
47 }
reed@google.com6e5a45c2011-11-02 21:02:57 +000048 }
49
50 gSkSuppressFontCachePurgeSpew = prev;
51 }
52private:
53 typedef SkBenchmark INHERITED;
54};
55
56///////////////////////////////////////////////////////////////////////////////
57
reed@google.com8e372c92011-11-03 13:45:38 +000058static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(FontScalerBench, (p, false)); }
59static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(FontScalerBench, (p, true)); }
reed@google.com6e5a45c2011-11-02 21:02:57 +000060
reed@google.com8e372c92011-11-03 13:45:38 +000061static BenchRegistry gReg0(Fact0);
62static BenchRegistry gReg1(Fact1);