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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 virtual ~FontCacheGM() { | 43 virtual ~FontCacheGM() { |
44 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) { | 44 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) { |
45 SkSafeUnref(fTypefaces[i]); | 45 SkSafeUnref(fTypefaces[i]); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 protected: | 49 protected: |
50 virtual SkString onShortName() SK_OVERRIDE { | 50 SkString onShortName() SK_OVERRIDE { |
51 return SkString("fontcache"); | 51 return SkString("fontcache"); |
52 } | 52 } |
53 | 53 |
54 virtual SkISize onISize() SK_OVERRIDE { | 54 SkISize onISize() SK_OVERRIDE { |
55 return SkISize::Make(1280, 640); | 55 return SkISize::Make(1280, 640); |
56 } | 56 } |
57 | 57 |
58 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 58 void onOnceBeforeDraw() SK_OVERRIDE { |
59 int typefaceCount = 0; | 59 int typefaceCount = 0; |
60 for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) { | 60 for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) { |
61 for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) { | 61 for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) { |
62 fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typ
eface(gFamilyNames[i], | 62 fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typ
eface(gFamilyNames[i], |
63 g
Styles[j]); | 63 g
Styles[j]); |
64 } | 64 } |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 68 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
69 SkScalar y = 32; | 69 SkScalar y = 32; |
70 SkPaint paint; | 70 SkPaint paint; |
71 paint.setAntiAlias(true); | 71 paint.setAntiAlias(true); |
72 paint.setLCDRenderText(true); | 72 paint.setLCDRenderText(true); |
73 paint.setSubpixelText(true); | 73 paint.setSubpixelText(true); |
74 | 74 |
75 SkString text("H"); | 75 SkString text("H"); |
76 | 76 |
77 // draw enough to overflow the cache | 77 // draw enough to overflow the cache |
78 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) { | 78 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) { |
79 paint.setTypeface(fTypefaces[i]); | 79 paint.setTypeface(fTypefaces[i]); |
80 SkScalar x = 20; | 80 SkScalar x = 20; |
81 | 81 |
82 for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) { | 82 for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) { |
83 paint.setTextSize(gTextSizes[j]); | 83 paint.setTextSize(gTextSizes[j]); |
84 x = draw_string(canvas, text, x, y, paint) + 10; | 84 x = draw_string(canvas, text, x, y, paint) + 10; |
85 } | 85 } |
86 y += 128; | 86 y += 128; |
87 } | 87 } |
88 | 88 |
89 } | 89 } |
90 | 90 |
91 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 91 uint32_t onGetFlags() const SK_OVERRIDE { |
92 // this GM is meant only for the GPU | 92 // this GM is meant only for the GPU |
93 return kGPUOnly_Flag; | 93 return kGPUOnly_Flag; |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 SkTypeface* fTypefaces[TYPEFACE_COUNT]; | 97 SkTypeface* fTypefaces[TYPEFACE_COUNT]; |
98 typedef GM INHERITED; | 98 typedef GM INHERITED; |
99 }; | 99 }; |
100 | 100 |
101 | 101 |
102 ////////////////////////////////////////////////////////////////////////////// | 102 ////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
104 DEF_GM( return SkNEW(FontCacheGM); ) | 104 DEF_GM( return SkNEW(FontCacheGM); ) |
OLD | NEW |