aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/FontScalerBench.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-02 21:02:57 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-02 21:02:57 +0000
commit6e5a45c038b1f3c0e4b119b0cd5091ac885ca764 (patch)
tree65201040a4e23fa516c65d8f545624a40587effc /bench/FontScalerBench.cpp
parent11b4d8a251f23e399180f60e7b0fc70e68246e03 (diff)
add bench for building the font cache
git-svn-id: http://skia.googlecode.com/svn/trunk@2590 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/FontScalerBench.cpp')
-rw-r--r--bench/FontScalerBench.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/bench/FontScalerBench.cpp b/bench/FontScalerBench.cpp
new file mode 100644
index 0000000000..596b830809
--- /dev/null
+++ b/bench/FontScalerBench.cpp
@@ -0,0 +1,54 @@
+/*
+ * 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;
+public:
+ FontScalerBench(void* param) : INHERITED(param) {
+ fName.set("fontscaler");
+ fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
+ }
+
+protected:
+ virtual const char* onGetName() { return fName.c_str(); }
+ virtual void onDraw(SkCanvas* canvas) {
+ SkPaint paint;
+ this->setupPaint(&paint);
+
+ 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::SetFontCacheUsed(0);
+ 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* Fact(void* p) { return SkNEW_ARGS(FontScalerBench, (p)); }
+
+static BenchRegistry gReg(Fact);