OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBlurMask.h" | 8 #include "SkBlurMask.h" |
9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
10 #include "SkLayerDrawLooper.h" | 10 #include "SkLayerDrawLooper.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 static int find_first_zero(const uint16_t glyphs[], int count) { | 53 static int find_first_zero(const uint16_t glyphs[], int count) { |
54 for (int i = 0; i < count; ++i) { | 54 for (int i = 0; i < count; ++i) { |
55 if (0 == glyphs[i]) { | 55 if (0 == glyphs[i]) { |
56 return i; | 56 return i; |
57 } | 57 } |
58 } | 58 } |
59 return count; | 59 return count; |
60 } | 60 } |
61 | 61 |
62 DEF_TEST(Paint_cmap, reporter) { | 62 static void test_cmap(skiatest::Reporter* reporter) { |
63 // need to implement charsToGlyphs on other backends (e.g. linux, win) | |
64 // before we can run this tests everywhere | |
65 return; | |
66 | |
67 static const int NGLYPHS = 64; | 63 static const int NGLYPHS = 64; |
68 | 64 |
69 SkUnichar src[NGLYPHS]; | 65 SkUnichar src[NGLYPHS]; |
70 SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage | 66 SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage |
71 | 67 |
72 static const struct { | 68 static const struct { |
73 size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count); | 69 size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count); |
74 SkPaint::TextEncoding fEncoding; | 70 SkPaint::TextEncoding fEncoding; |
75 } gRec[] = { | 71 } gRec[] = { |
76 { uni_to_utf8, SkPaint::kUTF8_TextEncoding }, | 72 { uni_to_utf8, SkPaint::kUTF8_TextEncoding }, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (contains) { | 106 if (contains) { |
111 REPORTER_ASSERT(reporter, NGLYPHS == first); | 107 REPORTER_ASSERT(reporter, NGLYPHS == first); |
112 } else { | 108 } else { |
113 REPORTER_ASSERT(reporter, NGLYPHS > first); | 109 REPORTER_ASSERT(reporter, NGLYPHS > first); |
114 } | 110 } |
115 } | 111 } |
116 } | 112 } |
117 } | 113 } |
118 | 114 |
119 // temparary api for bicubic, just be sure we can set/clear it | 115 // temparary api for bicubic, just be sure we can set/clear it |
120 DEF_TEST(Paint_filterlevel, reporter) { | 116 static void test_filterlevel(skiatest::Reporter* reporter) { |
121 SkPaint p0, p1; | 117 SkPaint p0, p1; |
122 | 118 |
123 REPORTER_ASSERT(reporter, | 119 REPORTER_ASSERT(reporter, |
124 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); | 120 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); |
125 | 121 |
126 static const SkPaint::FilterLevel gLevels[] = { | 122 static const SkPaint::FilterLevel gLevels[] = { |
127 SkPaint::kNone_FilterLevel, | 123 SkPaint::kNone_FilterLevel, |
128 SkPaint::kLow_FilterLevel, | 124 SkPaint::kLow_FilterLevel, |
129 SkPaint::kMedium_FilterLevel, | 125 SkPaint::kMedium_FilterLevel, |
130 SkPaint::kHigh_FilterLevel | 126 SkPaint::kHigh_FilterLevel |
131 }; | 127 }; |
132 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) { | 128 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) { |
133 p0.setFilterLevel(gLevels[i]); | 129 p0.setFilterLevel(gLevels[i]); |
134 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); | 130 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); |
135 p1 = p0; | 131 p1 = p0; |
136 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); | 132 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); |
137 | 133 |
138 p0.reset(); | 134 p0.reset(); |
139 REPORTER_ASSERT(reporter, | 135 REPORTER_ASSERT(reporter, |
140 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); | 136 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); |
141 } | 137 } |
142 } | 138 } |
143 | 139 |
144 DEF_TEST(Paint_copy, reporter) { | 140 static void test_copy(skiatest::Reporter* reporter) { |
145 SkPaint paint; | 141 SkPaint paint; |
146 // set a few member variables | 142 // set a few member variables |
147 paint.setStyle(SkPaint::kStrokeAndFill_Style); | 143 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
148 paint.setTextAlign(SkPaint::kLeft_Align); | 144 paint.setTextAlign(SkPaint::kLeft_Align); |
149 paint.setStrokeWidth(SkIntToScalar(2)); | 145 paint.setStrokeWidth(SkIntToScalar(2)); |
150 // set a few pointers | 146 // set a few pointers |
151 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); | 147 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); |
152 paint.setLooper(looper)->unref(); | 148 paint.setLooper(looper)->unref(); |
153 SkMaskFilter* mask = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Blur
Style, | 149 SkMaskFilter* mask = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Blur
Style, |
154 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(1))); | 150 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(1))); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // the reset function should increment the Generation ID | 185 // the reset function should increment the Generation ID |
190 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); | 186 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); |
191 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID)
; | 187 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID)
; |
192 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); | 188 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); |
193 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain
t))); | 189 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain
t))); |
194 #endif | 190 #endif |
195 } | 191 } |
196 | 192 |
197 // found and fixed for webkit: mishandling when we hit recursion limit on | 193 // found and fixed for webkit: mishandling when we hit recursion limit on |
198 // mostly degenerate cubic flatness test | 194 // mostly degenerate cubic flatness test |
199 DEF_TEST(Paint_regression_cubic, reporter) { | 195 static void regression_cubic(skiatest::Reporter* reporter) { |
200 SkPath path, stroke; | 196 SkPath path, stroke; |
201 SkPaint paint; | 197 SkPaint paint; |
202 | 198 |
203 path.moveTo(460.2881309415525f, | 199 path.moveTo(460.2881309415525f, |
204 303.250847066498f); | 200 303.250847066498f); |
205 path.cubicTo(463.36378422175284f, | 201 path.cubicTo(463.36378422175284f, |
206 302.1169735073363f, | 202 302.1169735073363f, |
207 456.32239330810046f, | 203 456.32239330810046f, |
208 304.720354932878f, | 204 304.720354932878f, |
209 453.15255460013304f, | 205 453.15255460013304f, |
(...skipping 12 matching lines...) Expand all Loading... |
222 SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ? | 218 SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ? |
223 SkScalarMul(paint.getStrokeWidth(), miter) : | 219 SkScalarMul(paint.getStrokeWidth(), miter) : |
224 paint.getStrokeWidth(); | 220 paint.getStrokeWidth(); |
225 maxR.inset(-inset, -inset); | 221 maxR.inset(-inset, -inset); |
226 | 222 |
227 // test that our stroke didn't explode | 223 // test that our stroke didn't explode |
228 REPORTER_ASSERT(reporter, maxR.contains(strokeR)); | 224 REPORTER_ASSERT(reporter, maxR.contains(strokeR)); |
229 } | 225 } |
230 | 226 |
231 // found and fixed for android: not initializing rect for string's of length 0 | 227 // found and fixed for android: not initializing rect for string's of length 0 |
232 DEF_TEST(Paint_regression_measureText, reporter) { | 228 static void regression_measureText(skiatest::Reporter* reporter) { |
233 | 229 |
234 SkPaint paint; | 230 SkPaint paint; |
235 paint.setTextSize(12.0f); | 231 paint.setTextSize(12.0f); |
236 | 232 |
237 SkRect r; | 233 SkRect r; |
238 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); | 234 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); |
239 | 235 |
240 // test that the rect was reset | 236 // test that the rect was reset |
241 paint.measureText("", 0, &r, 1.0f); | 237 paint.measureText("", 0, &r, 1.0f); |
242 REPORTER_ASSERT(reporter, r.isEmpty()); | 238 REPORTER_ASSERT(reporter, r.isEmpty()); |
243 } | 239 } |
244 | 240 |
| 241 DEF_TEST(Paint, reporter) { |
| 242 // TODO add general paint tests |
| 243 test_copy(reporter); |
| 244 |
| 245 // regression tests |
| 246 regression_cubic(reporter); |
| 247 regression_measureText(reporter); |
| 248 |
| 249 test_filterlevel(reporter); |
| 250 |
| 251 // need to implement charsToGlyphs on other backends (e.g. linux, win) |
| 252 // before we can run this tests everywhere |
| 253 if (false) { |
| 254 test_cmap(reporter); |
| 255 } |
| 256 } |
| 257 |
245 #define ASSERT(expr) REPORTER_ASSERT(r, expr) | 258 #define ASSERT(expr) REPORTER_ASSERT(r, expr) |
246 | 259 |
247 DEF_TEST(Paint_FlatteningTraits, r) { | 260 DEF_TEST(Paint_FlatteningTraits, r) { |
248 SkPaint paint; | 261 SkPaint paint; |
249 paint.setColor(0x00AABBCC); | 262 paint.setColor(0x00AABBCC); |
250 paint.setTextScaleX(1.0f); // Encoded despite being the default value. | 263 paint.setTextScaleX(1.0f); // Encoded despite being the default value. |
251 paint.setTextSize(19); | 264 paint.setTextSize(19); |
252 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref(); | 265 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref(); |
253 paint.setLooper(NULL); // Ignored. | 266 paint.setLooper(NULL); // Ignored. |
254 | 267 |
(...skipping 16 matching lines...) Expand all Loading... |
271 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); | 284 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); |
272 ASSERT(other.getTextSize() == paint.getTextSize()); | 285 ASSERT(other.getTextSize() == paint.getTextSize()); |
273 ASSERT(other.getLooper() == paint.getLooper()); | 286 ASSERT(other.getLooper() == paint.getLooper()); |
274 | 287 |
275 // We have to be a little looser and compare just the modes. Pointers might
not be the same. | 288 // We have to be a little looser and compare just the modes. Pointers might
not be the same. |
276 SkXfermode::Mode otherMode, paintMode; | 289 SkXfermode::Mode otherMode, paintMode; |
277 ASSERT(other.getXfermode()->asMode(&otherMode)); | 290 ASSERT(other.getXfermode()->asMode(&otherMode)); |
278 ASSERT(paint.getXfermode()->asMode(&paintMode)); | 291 ASSERT(paint.getXfermode()->asMode(&paintMode)); |
279 ASSERT(otherMode == paintMode); | 292 ASSERT(otherMode == paintMode); |
280 } | 293 } |
OLD | NEW |