2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkGraphics.h"
11 #include "SkTypeface.h"
13 // GM to stress the GPU font cache
15 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
16 SkScalar y, const SkPaint& paint) {
17 canvas->drawText(text.c_str(), text.size(), x, y, paint);
18 return x + paint.measureText(text.c_str(), text.size());
21 class FontCacheGM : public skiagm::GM {
28 virtual ~FontCacheGM() {
29 SkSafeUnref(fTypefaces[0]);
30 SkSafeUnref(fTypefaces[1]);
34 SkString onShortName() override {
35 return SkString("fontcache");
38 SkISize onISize() override {
39 return SkISize::Make(1280, 640);
42 void onOnceBeforeDraw() override {
43 fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic);
44 fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic);
47 void onDraw(SkCanvas* canvas) override {
49 paint.setAntiAlias(true);
50 paint.setLCDRenderText(true);
51 paint.setSubpixelText(true);
52 paint.setTypeface(fTypefaces[0]);
53 paint.setTextSize(192);
55 // Make sure the nul character does not cause problems.
56 paint.measureText("\0", 1);
60 SkString text("ABCDEFGHIJ");
61 draw_string(canvas, text, x, y, paint);
63 SkString text2("KLMNOPQRS");
64 draw_string(canvas, text2, x, y, paint);
66 SkString text3("TUVWXYZ012");
67 draw_string(canvas, text3, x, y, paint);
69 paint.setTypeface(fTypefaces[1]);
70 draw_string(canvas, text, x, y, paint);
72 draw_string(canvas, text2, x, y, paint);
74 draw_string(canvas, text3, x, y, paint);
79 SkTypeface* fTypefaces[2];
84 //////////////////////////////////////////////////////////////////////////////
86 DEF_GM( return SkNEW(FontCacheGM); )