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

Unified Diff: bench/TextBlobBench.cpp

Issue 1031423002: Add mixedtextblob gm and a simple bench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: mac warnings Created 5 years, 9 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 | gm/mixedtextblobs.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/TextBlobBench.cpp
diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1f4b2b7120d5d7ca076da3f184f3d1665a11a784
--- /dev/null
+++ b/bench/TextBlobBench.cpp
@@ -0,0 +1,71 @@
+
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "Resources.h"
+#include "SkCanvas.h"
+#include "SkPaint.h"
+#include "SkRandom.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTemplates.h"
+#include "SkTextBlob.h"
+#include "SkTypeface.h"
+
+#include "sk_tool_utils.h"
+
+/*
+ * A trivial test which benchmarks the performance of a textblob with a single run.
+ */
+class TextBlobBench : public Benchmark {
+public:
+ TextBlobBench()
+ : fTypeface(sk_tool_utils::create_portable_typeface("Times", SkTypeface::kNormal)) {
+ // make textblob
+ SkPaint paint;
+ paint.setTypeface(fTypeface);
+ const char* text = "Hello blob!";
+ SkTDArray<uint16_t> glyphs;
+ size_t len = strlen(text);
+ glyphs.append(paint.textToGlyphs(text, len, NULL));
+ paint.textToGlyphs(text, len, glyphs.begin());
+
+ SkTextBlobBuilder builder;
+
+ paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs.count(), 10, 10,
+ NULL);
+ memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
+
+ fBlob.reset(builder.build());
+ }
+
+protected:
+ const char* onGetName() {
+ return "TextBlobBench";
+ }
+
+ void onDraw(const int loops, SkCanvas* canvas) {
+ SkPaint paint;
+
+ // To ensure maximum caching, we just redraw the blob at the same place everytime
+ for (int i = 0; i < loops; i++) {
+ canvas->drawTextBlob(fBlob, 0, 0, paint);
+ }
+ }
+
+private:
+
+ SkAutoTUnref<const SkTextBlob> fBlob;
+ SkTDArray<uint16_t> fGlyphs;
+ SkAutoTUnref<SkTypeface> fTypeface;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH( return new TextBlobBench(); )
« no previous file with comments | « no previous file | gm/mixedtextblobs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698