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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 char text[kMaxLength]; | 65 char text[kMaxLength]; |
66 for (int j = 0; j < length; ++j) { | 66 for (int j = 0; j < length; ++j) { |
67 text[j] = (char)random.nextRangeU('!', 'z'); | 67 text[j] = (char)random.nextRangeU('!', 'z'); |
68 } | 68 } |
69 fStrings[i].set(text, length); | 69 fStrings[i].set(text, length); |
70 | 70 |
71 fColors[i] = random.nextU(); | 71 fColors[i] = random.nextU(); |
72 fColors[i] |= 0xFF000000; | 72 fColors[i] |= 0xFF000000; |
73 fColors[i] = sk_tool_utils::color_to_565(fColors[i]); | 73 fColors[i] = sk_tool_utils::color_to_565(fColors[i]); |
74 | 74 |
75 static const SkScalar kMinPtSize = 8.f; | 75 constexpr SkScalar kMinPtSize = 8.f; |
76 static const SkScalar kMaxPtSize = 32.f; | 76 constexpr SkScalar kMaxPtSize = 32.f; |
77 | 77 |
78 fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize); | 78 fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize); |
79 | 79 |
80 fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces
)); | 80 fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces
)); |
81 | 81 |
82 SkRect r; | 82 SkRect r; |
83 fPaint.setColor(fColors[i]); | 83 fPaint.setColor(fColors[i]); |
84 fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); | 84 fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); |
85 fPaint.setTextSize(fPtSizes[i]); | 85 fPaint.setTextSize(fPtSizes[i]); |
86 | 86 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 wirePaint.setStyle(SkPaint::kStroke_Style); | 127 wirePaint.setStyle(SkPaint::kStroke_Style); |
128 for (int i = 0; i < kCnt; ++i) { | 128 for (int i = 0; i < kCnt; ++i) { |
129 canvas->drawRect(fClipRects[i], wirePaint); | 129 canvas->drawRect(fClipRects[i], wirePaint); |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 bool runAsBench() const override { return true; } | 134 bool runAsBench() const override { return true; } |
135 | 135 |
136 private: | 136 private: |
137 static const int kCnt = 30; | 137 static constexpr int kCnt = 30; |
138 static const int kMinLength = 15; | 138 static constexpr int kMinLength = 15; |
139 static const int kMaxLength = 40; | 139 static constexpr int kMaxLength = 40; |
140 | 140 |
141 bool fEffectiveClip; | 141 bool fEffectiveClip; |
142 bool fLCD; | 142 bool fLCD; |
143 sk_sp<SkTypeface> fTypefaces[4]; | 143 sk_sp<SkTypeface> fTypefaces[4]; |
144 SkPaint fPaint; | 144 SkPaint fPaint; |
145 | 145 |
146 // precomputed for each text draw | 146 // precomputed for each text draw |
147 SkString fStrings[kCnt]; | 147 SkString fStrings[kCnt]; |
148 SkColor fColors[kCnt]; | 148 SkColor fColors[kCnt]; |
149 SkScalar fPtSizes[kCnt]; | 149 SkScalar fPtSizes[kCnt]; |
150 int fTypefaceIndices[kCnt]; | 150 int fTypefaceIndices[kCnt]; |
151 SkPoint fPositions[kCnt]; | 151 SkPoint fPositions[kCnt]; |
152 SkRect fClipRects[kCnt]; | 152 SkRect fClipRects[kCnt]; |
153 | 153 |
154 typedef skiagm::GM INHERITED; | 154 typedef skiagm::GM INHERITED; |
155 }; | 155 }; |
156 | 156 |
157 DEF_GM(return new VariedTextGM(false, false);) | 157 DEF_GM(return new VariedTextGM(false, false);) |
158 DEF_GM(return new VariedTextGM(true, false);) | 158 DEF_GM(return new VariedTextGM(true, false);) |
159 DEF_GM(return new VariedTextGM(false, true);) | 159 DEF_GM(return new VariedTextGM(false, true);) |
160 DEF_GM(return new VariedTextGM(true, true);) | 160 DEF_GM(return new VariedTextGM(true, true);) |
OLD | NEW |