OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
11 #include "SkTypeface.h" | 11 #include "SkTypeface.h" |
12 | 12 |
13 // GM to stress the GPU font cache | 13 // GM to stress the GPU font cache |
14 | 14 |
15 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, | 15 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, |
16 SkScalar y, const SkPaint& paint) { | 16 SkScalar y, const SkPaint& paint) { |
17 canvas->drawText(text.c_str(), text.size(), x, y, paint); | 17 canvas->drawText(text.c_str(), text.size(), x, y, paint); |
18 return x + paint.measureText(text.c_str(), text.size()); | 18 return x + paint.measureText(text.c_str(), text.size()); |
19 } | 19 } |
20 | 20 |
21 class FontCacheGM : public skiagm::GM { | 21 class FontCacheGM : public skiagm::GM { |
22 public: | 22 public: |
23 FontCacheGM() {} | 23 FontCacheGM() { |
| 24 fTypefaces[0] = nullptr; |
| 25 fTypefaces[1] = nullptr; |
| 26 } |
| 27 |
| 28 virtual ~FontCacheGM() { |
| 29 SkSafeUnref(fTypefaces[0]); |
| 30 SkSafeUnref(fTypefaces[1]); |
| 31 } |
24 | 32 |
25 protected: | 33 protected: |
26 SkString onShortName() override { | 34 SkString onShortName() override { |
27 return SkString("fontcache"); | 35 return SkString("fontcache"); |
28 } | 36 } |
29 | 37 |
30 SkISize onISize() override { | 38 SkISize onISize() override { |
31 return SkISize::Make(1280, 640); | 39 return SkISize::Make(1280, 640); |
32 } | 40 } |
33 | 41 |
(...skipping 27 matching lines...) Expand all Loading... |
61 paint.setTypeface(fTypefaces[1]); | 69 paint.setTypeface(fTypefaces[1]); |
62 draw_string(canvas, text, x, y, paint); | 70 draw_string(canvas, text, x, y, paint); |
63 y += 100; | 71 y += 100; |
64 draw_string(canvas, text2, x, y, paint); | 72 draw_string(canvas, text2, x, y, paint); |
65 y += 100; | 73 y += 100; |
66 draw_string(canvas, text3, x, y, paint); | 74 draw_string(canvas, text3, x, y, paint); |
67 y += 100; | 75 y += 100; |
68 } | 76 } |
69 | 77 |
70 private: | 78 private: |
71 sk_sp<SkTypeface> fTypefaces[2]; | 79 SkTypeface* fTypefaces[2]; |
72 typedef GM INHERITED; | 80 typedef GM INHERITED; |
73 }; | 81 }; |
74 | 82 |
75 | 83 |
76 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
77 | 85 |
78 DEF_GM(return new FontCacheGM;) | 86 DEF_GM(return new FontCacheGM;) |
OLD | NEW |