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.
9 #include "sk_tool_utils.h"
11 #include "SkGraphics.h"
12 #include "SkTypeface.h"
14 // GM to stress the GPU font cache
16 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
17 SkScalar y, const SkPaint& paint) {
18 canvas->drawString(text, x, y, paint);
19 return x + paint.measureText(text.c_str(), text.size());
22 class FontCacheGM : public skiagm::GM {
27 SkString onShortName() override {
28 return SkString("fontcache");
31 SkISize onISize() override {
32 return SkISize::Make(1280, 640);
35 void onOnceBeforeDraw() override {
36 fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif",
37 SkFontStyle::FromOldStyle(SkTypeface::kItalic));
38 fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
39 SkFontStyle::FromOldStyle(SkTypeface::kItalic));
42 void onDraw(SkCanvas* canvas) override {
44 paint.setAntiAlias(true);
45 paint.setLCDRenderText(true);
46 paint.setSubpixelText(true);
47 paint.setTypeface(fTypefaces[0]);
48 paint.setTextSize(192);
50 // Make sure the nul character does not cause problems.
51 paint.measureText("\0", 1);
55 SkString text("ABCDEFGHIJ");
56 draw_string(canvas, text, x, y, paint);
58 SkString text2("KLMNOPQRS");
59 draw_string(canvas, text2, x, y, paint);
61 SkString text3("TUVWXYZ012");
62 draw_string(canvas, text3, x, y, paint);
64 paint.setTypeface(fTypefaces[1]);
65 draw_string(canvas, text, x, y, paint);
67 draw_string(canvas, text2, x, y, paint);
69 draw_string(canvas, text3, x, y, paint);
74 sk_sp<SkTypeface> fTypefaces[2];
79 //////////////////////////////////////////////////////////////////////////////
81 DEF_GM(return new FontCacheGM;)