OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref)); | 24 memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref)); |
25 } | 25 } |
26 | 26 |
27 ~VariedTextGM() { | 27 ~VariedTextGM() { |
28 for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) { | 28 for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) { |
29 SkSafeUnref(fTypefacesToUnref[i]); | 29 SkSafeUnref(fTypefacesToUnref[i]); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 SkString onShortName() SK_OVERRIDE { | 34 SkString onShortName() override { |
35 SkString name("varied_text"); | 35 SkString name("varied_text"); |
36 if (fEffectiveClip) { | 36 if (fEffectiveClip) { |
37 name.append("_clipped"); | 37 name.append("_clipped"); |
38 } else { | 38 } else { |
39 name.append("_ignorable_clip"); | 39 name.append("_ignorable_clip"); |
40 } | 40 } |
41 if (fLCD) { | 41 if (fLCD) { |
42 name.append("_lcd"); | 42 name.append("_lcd"); |
43 } else { | 43 } else { |
44 name.append("_no_lcd"); | 44 name.append("_no_lcd"); |
45 } | 45 } |
46 return name; | 46 return name; |
47 } | 47 } |
48 | 48 |
49 SkISize onISize() SK_OVERRIDE { | 49 SkISize onISize() override { |
50 return SkISize::Make(640, 480); | 50 return SkISize::Make(640, 480); |
51 } | 51 } |
52 | 52 |
53 void onOnceBeforeDraw() SK_OVERRIDE { | 53 void onOnceBeforeDraw() override { |
54 fPaint.setAntiAlias(true); | 54 fPaint.setAntiAlias(true); |
55 fPaint.setLCDRenderText(fLCD); | 55 fPaint.setLCDRenderText(fLCD); |
56 | 56 |
57 SkISize size = this->getISize(); | 57 SkISize size = this->getISize(); |
58 SkScalar w = SkIntToScalar(size.fWidth); | 58 SkScalar w = SkIntToScalar(size.fWidth); |
59 SkScalar h = SkIntToScalar(size.fHeight); | 59 SkScalar h = SkIntToScalar(size.fHeight); |
60 | 60 |
61 SK_COMPILE_ASSERT(4 == SK_ARRAY_COUNT(fTypefacesToUnref), typeface_cnt); | 61 SK_COMPILE_ASSERT(4 == SK_ARRAY_COUNT(fTypefacesToUnref), typeface_cnt); |
62 fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kNormal); | 62 fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kNormal); |
63 fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kBold); | 63 fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-ser
if", SkTypeface::kBold); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 fClipRects[i] = r; | 104 fClipRects[i] = r; |
105 fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY); | 105 fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY); |
106 fClipRects[i].outset(2.f, 2.f); | 106 fClipRects[i].outset(2.f, 2.f); |
107 | 107 |
108 if (fEffectiveClip) { | 108 if (fEffectiveClip) { |
109 fClipRects[i].fRight -= 0.25f * fClipRects[i].width(); | 109 fClipRects[i].fRight -= 0.25f * fClipRects[i].width(); |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 114 void onDraw(SkCanvas* canvas) override { |
115 for (int i = 0; i < kCnt; ++i) { | 115 for (int i = 0; i < kCnt; ++i) { |
116 fPaint.setColor(fColors[i]); | 116 fPaint.setColor(fColors[i]); |
117 fPaint.setTextSize(fPtSizes[i]); | 117 fPaint.setTextSize(fPtSizes[i]); |
118 fPaint.setTypeface(fTypefaces[i]); | 118 fPaint.setTypeface(fTypefaces[i]); |
119 | 119 |
120 canvas->save(); | 120 canvas->save(); |
121 canvas->clipRect(fClipRects[i]); | 121 canvas->clipRect(fClipRects[i]); |
122 canvas->translate(fPositions[i].fX, fPositions[i].fY); | 122 canvas->translate(fPositions[i].fX, fPositions[i].fY); |
123 canvas->drawText(fStrings[i].c_str(), fStrings[i].size(), 0, 0,
fPaint); | 123 canvas->drawText(fStrings[i].c_str(), fStrings[i].size(), 0, 0,
fPaint); |
124 canvas->restore(); | 124 canvas->restore(); |
125 } | 125 } |
126 | 126 |
127 // Visualize the clips, but not in bench mode. | 127 // Visualize the clips, but not in bench mode. |
128 if (kBench_Mode != this->getMode()) { | 128 if (kBench_Mode != this->getMode()) { |
129 SkPaint wirePaint; | 129 SkPaint wirePaint; |
130 wirePaint.setAntiAlias(true); | 130 wirePaint.setAntiAlias(true); |
131 wirePaint.setStrokeWidth(0); | 131 wirePaint.setStrokeWidth(0); |
132 wirePaint.setStyle(SkPaint::kStroke_Style); | 132 wirePaint.setStyle(SkPaint::kStroke_Style); |
133 for (int i = 0; i < kCnt; ++i) { | 133 for (int i = 0; i < kCnt; ++i) { |
134 canvas->drawRect(fClipRects[i], wirePaint); | 134 canvas->drawRect(fClipRects[i], wirePaint); |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 bool runAsBench() const SK_OVERRIDE { return true; } | 139 bool runAsBench() const override { return true; } |
140 | 140 |
141 private: | 141 private: |
142 static const int kCnt = 30; | 142 static const int kCnt = 30; |
143 static const int kMinLength = 15; | 143 static const int kMinLength = 15; |
144 static const int kMaxLength = 40; | 144 static const int kMaxLength = 40; |
145 | 145 |
146 bool fEffectiveClip; | 146 bool fEffectiveClip; |
147 bool fLCD; | 147 bool fLCD; |
148 SkTypeface* fTypefacesToUnref[4]; | 148 SkTypeface* fTypefacesToUnref[4]; |
149 SkPaint fPaint; | 149 SkPaint fPaint; |
150 | 150 |
151 // precomputed for each text draw | 151 // precomputed for each text draw |
152 SkString fStrings[kCnt]; | 152 SkString fStrings[kCnt]; |
153 SkColor fColors[kCnt]; | 153 SkColor fColors[kCnt]; |
154 SkScalar fPtSizes[kCnt]; | 154 SkScalar fPtSizes[kCnt]; |
155 SkTypeface* fTypefaces[kCnt]; | 155 SkTypeface* fTypefaces[kCnt]; |
156 SkPoint fPositions[kCnt]; | 156 SkPoint fPositions[kCnt]; |
157 SkRect fClipRects[kCnt]; | 157 SkRect fClipRects[kCnt]; |
158 | 158 |
159 typedef skiagm::GM INHERITED; | 159 typedef skiagm::GM INHERITED; |
160 }; | 160 }; |
161 | 161 |
162 DEF_GM( return SkNEW(VariedTextGM(false, false)); ) | 162 DEF_GM( return SkNEW(VariedTextGM(false, false)); ) |
163 DEF_GM( return SkNEW(VariedTextGM(true, false)); ) | 163 DEF_GM( return SkNEW(VariedTextGM(true, false)); ) |
164 DEF_GM( return SkNEW(VariedTextGM(false, true)); ) | 164 DEF_GM( return SkNEW(VariedTextGM(false, true)); ) |
165 DEF_GM( return SkNEW(VariedTextGM(true, true)); ) | 165 DEF_GM( return SkNEW(VariedTextGM(true, true)); ) |
OLD | NEW |