Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: bench/CmapBench.cpp

Issue 18083023: add charsToGlyphs to SkTypeface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/CmapBench.cpp
diff --git a/bench/CmapBench.cpp b/bench/CmapBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9697477850e81a96586338c74eb4b295e6be4830
--- /dev/null
+++ b/bench/CmapBench.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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 "SkPaint.h"
+#include "SkTypeface.h"
+
+enum {
+ LOOP = SkBENCHLOOP(1000),
+ NGLYPHS = 100
+};
+
+static SkTypeface::Encoding paint2Encoding(const SkPaint& paint) {
+ SkPaint::TextEncoding enc = paint.getTextEncoding();
+ SkASSERT(SkPaint::kGlyphID_TextEncoding != enc);
+ return (SkTypeface::Encoding)enc;
+}
+
+typedef void (*TypefaceProc)(const SkPaint&, const void* text, size_t len,
+ int glyphCount);
+
+static void containsText_proc(const SkPaint& paint, const void* text, size_t len,
+ int glyphCount) {
+ for (int i = 0; i < LOOP; ++i) {
+ paint.containsText(text, len);
+ }
+}
+
+static void textToGlyphs_proc(const SkPaint& paint, const void* text, size_t len,
+ int glyphCount) {
+ uint16_t glyphs[NGLYPHS];
+ SkASSERT(glyphCount <= NGLYPHS);
+
+ for (int i = 0; i < LOOP; ++i) {
+ paint.textToGlyphs(text, len, glyphs);
+ }
+}
+
+static void charsToGlyphs_proc(const SkPaint& paint, const void* text,
+ size_t len, int glyphCount) {
+ SkTypeface::Encoding encoding = paint2Encoding(paint);
+ uint16_t glyphs[NGLYPHS];
+ SkASSERT(glyphCount <= NGLYPHS);
+
+ SkTypeface* face = paint.getTypeface();
+ for (int i = 0; i < LOOP; ++i) {
+ face->charsToGlyphs(text, encoding, glyphs, glyphCount);
+ }
+}
+
+class CMAPBench : public SkBenchmark {
+ TypefaceProc fProc;
+ SkString fName;
+ char fText[NGLYPHS];
+ SkPaint fPaint;
+
+public:
+ CMAPBench(void* param, TypefaceProc proc, const char name[]) : SkBenchmark(param) {
+ fProc = proc;
+ fName.printf("cmap_%s", name);
+
+ for (int i = 0; i < NGLYPHS; ++i) {
+ // we're just jamming values into utf8, so we must keep it legal
+ fText[i] = i;
+ }
+ fPaint.setTypeface(SkTypeface::RefDefault())->unref();
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return fName.c_str();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ fProc(fPaint, fText, sizeof(fText), NGLYPHS);
+ }
+
+private:
+
+ typedef SkBenchmark INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_BENCH( return new CMAPBench(p, containsText_proc, "paint_containsText"); )
+DEF_BENCH( return new CMAPBench(p, textToGlyphs_proc, "paint_textToGlyphs"); )
+DEF_BENCH( return new CMAPBench(p, charsToGlyphs_proc, "face_charsToGlyphs"); )
+
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698