blob: 0326a0cce6a20916a7b437fa49bb44342959bdce [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.com6e5a45c2011-11-02 21:02:57 +00009#include "SkCanvas.h"
10#include "SkGraphics.h"
11#include "SkPaint.h"
12#include "SkRandom.h"
13#include "SkString.h"
14
tfarinaf168b862014-06-19 12:32:29 -070015class FontScalerBench : public Benchmark {
reed@google.com6e5a45c2011-11-02 21:02:57 +000016 SkString fName;
17 SkString fText;
reed@google.com8e372c92011-11-03 13:45:38 +000018 bool fDoLCD;
reed@google.com6e5a45c2011-11-02 21:02:57 +000019public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000020 FontScalerBench(bool doLCD) {
reed@google.com8e372c92011-11-03 13:45:38 +000021 fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
reed@google.com6e5a45c2011-11-02 21:02:57 +000022 fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
reed@google.com8e372c92011-11-03 13:45:38 +000023 fDoLCD = doLCD;
reed@google.com6e5a45c2011-11-02 21:02:57 +000024 }
25
26protected:
27 virtual const char* onGetName() { return fName.c_str(); }
commit-bot@chromium.org33614712013-12-03 18:17:16 +000028 virtual void onDraw(const int loops, SkCanvas* canvas) {
reed@google.com6e5a45c2011-11-02 21:02:57 +000029 SkPaint paint;
30 this->setupPaint(&paint);
reed@google.com8e372c92011-11-03 13:45:38 +000031 paint.setLCDRenderText(fDoLCD);
reed@google.com6e5a45c2011-11-02 21:02:57 +000032
commit-bot@chromium.org33614712013-12-03 18:17:16 +000033 for (int i = 0; i < loops; i++) {
mtklein@google.comc2897432013-09-10 19:23:38 +000034 // this is critical - we want to time the creation process, so we
35 // explicitly flush our cache before each run
36 SkGraphics::PurgeFontCache();
reed@google.com073c9072011-11-08 20:03:48 +000037
mtklein@google.comc2897432013-09-10 19:23:38 +000038 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 }
reed@google.com6e5a45c2011-11-02 21:02:57 +000043 }
reed@google.com6e5a45c2011-11-02 21:02:57 +000044 }
45private:
tfarinaf168b862014-06-19 12:32:29 -070046 typedef Benchmark INHERITED;
reed@google.com6e5a45c2011-11-02 21:02:57 +000047};
48
49///////////////////////////////////////////////////////////////////////////////
50
mtklein@google.com410e6e82013-09-13 19:52:27 +000051DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); )
52DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); )