aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-09 18:12:23 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-09 18:12:23 +0000
commit338a49fc55be8555e171419d079a1b6317060a38 (patch)
treec30c2b998e5feca1948da6068d4b0ad7da89c4f9
parent9fb6c8ac9ce7dd5d3319b4e3affd5f1e051162a2 (diff)
Add new GM to stress test the GPU font cache for cases similar to
Chromium issue 303803. BUG=303803 Committed: http://code.google.com/p/skia/source/detail?r=11673 R=robertphillips@google.com Author: jvanverth@google.com Review URL: https://codereview.chromium.org/26699002 git-svn-id: http://skia.googlecode.com/svn/trunk@11680 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gm/fontcache.cpp121
-rw-r--r--gyp/gmslides.gypi1
2 files changed, 122 insertions, 0 deletions
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
new file mode 100644
index 0000000000..1e01de0641
--- /dev/null
+++ b/gm/fontcache.cpp
@@ -0,0 +1,121 @@
+/*
+ * 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 "gm.h"
+#include "SkCanvas.h"
+#include "SkGraphics.h"
+#include "SkTypeface.h"
+
+// GM to stress the GPU font cache
+
+const char* gFamilyNames[] = {
+ "sans-serif", "serif", "monospace"
+};
+
+const SkTypeface::Style gStyles[] = {
+ SkTypeface::kNormal, SkTypeface::kItalic
+};
+
+const SkScalar gTextSizes[] = {
+ 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
+};
+
+#define TYPEFACE_COUNT (SK_ARRAY_COUNT(gFamilyNames)*SK_ARRAY_COUNT(gStyles))
+
+static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
+ SkScalar y, const SkPaint& paint) {
+ canvas->drawText(text.c_str(), text.size(), x, y, paint);
+ return x + paint.measureText(text.c_str(), text.size());
+}
+
+class FontCacheGM : public skiagm::GM {
+public:
+ FontCacheGM() {
+ for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
+ fTypefaces[i] = NULL;
+ }
+ }
+
+ virtual ~FontCacheGM() {
+ for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
+ SkSafeUnref(fTypefaces[i]);
+ }
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return fName;
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(640, 320);
+ }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ int typefaceCount = 0;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) {
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) {
+ fTypefaces[typefaceCount++] = SkTypeface::CreateFromName(gFamilyNames[i],
+ gStyles[j]);
+ }
+ }
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkScalar y = 32;
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setLCDRenderText(true);
+ paint.setSubpixelText(true);
+
+ SkString text("Ham");
+
+ // draw some initial text to partially fill the GPU cache
+ for (size_t i = 0; i < 2; ++i) {
+ paint.setTypeface(fTypefaces[i]);
+ SkScalar x = 20;
+
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
+ paint.setTextSize(gTextSizes[j]);
+ x = draw_string(canvas, text, x, y, paint) + 19;
+ }
+ y += 32;
+ }
+
+ // force a flush
+ canvas->flush();
+
+ // draw again, and more to overflow the cache
+ for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
+ paint.setTypeface(fTypefaces[i]);
+ SkScalar x = 20;
+
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
+ paint.setTextSize(gTextSizes[j]);
+ x = draw_string(canvas, text, x, y, paint) + 19;
+ }
+ y += 32;
+ }
+
+ }
+
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ // this GM is meant only for the GPU
+ return kGPUOnly_Flag;
+ }
+
+private:
+ SkTypeface* fTypefaces[TYPEFACE_COUNT];
+ SkString fName;
+ typedef GM INHERITED;
+};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return SkNEW(FontCacheGM); )
+
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index 9307388850..a9d2234823 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -54,6 +54,7 @@
'../gm/filltypes.cpp',
'../gm/filltypespersp.cpp',
'../gm/filterbitmap.cpp',
+ '../gm/fontcache.cpp',
'../gm/fontmgr.cpp',
'../gm/fontscaler.cpp',
'../gm/gammatext.cpp',