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" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
14 #include "SkReadBuffer.h" | |
15 #include "SkTypeface.h" | 14 #include "SkTypeface.h" |
16 #include "SkUtils.h" | 15 #include "SkUtils.h" |
17 #include "SkWriteBuffer.h" | |
18 #include "SkXfermode.h" | |
19 #include "Test.h" | 16 #include "Test.h" |
20 | 17 |
21 static size_t uni_to_utf8(const SkUnichar src[], void* dst, int count) { | 18 static size_t uni_to_utf8(const SkUnichar src[], void* dst, int count) { |
22 char* u8 = (char*)dst; | 19 char* u8 = (char*)dst; |
23 for (int i = 0; i < count; ++i) { | 20 for (int i = 0; i < count; ++i) { |
24 int n = SkUTF8_FromUnichar(src[i], u8); | 21 int n = SkUTF8_FromUnichar(src[i], u8); |
25 u8 += n; | 22 u8 += n; |
26 } | 23 } |
27 return u8 - (char*)dst; | 24 return u8 - (char*)dst; |
28 } | 25 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 regression_measureText(reporter); | 244 regression_measureText(reporter); |
248 | 245 |
249 test_filterlevel(reporter); | 246 test_filterlevel(reporter); |
250 | 247 |
251 // need to implement charsToGlyphs on other backends (e.g. linux, win) | 248 // need to implement charsToGlyphs on other backends (e.g. linux, win) |
252 // before we can run this tests everywhere | 249 // before we can run this tests everywhere |
253 if (false) { | 250 if (false) { |
254 test_cmap(reporter); | 251 test_cmap(reporter); |
255 } | 252 } |
256 } | 253 } |
257 | |
258 #define ASSERT(expr) REPORTER_ASSERT(r, expr) | |
259 | |
260 DEF_TEST(Paint_FlatteningTraits, r) { | |
261 SkPaint paint; | |
262 paint.setColor(0x00AABBCC); | |
263 paint.setTextScaleX(1.0f); // Encoded despite being the default value. | |
264 paint.setTextSize(19); | |
265 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode)); | |
266 paint.setLooper(NULL); // Ignored. | |
267 | |
268 SkWriteBuffer writer; | |
269 SkPaint::FlatteningTraits::Flatten(writer, paint); | |
270 ASSERT(writer.bytesWritten() == 48); | |
271 | |
272 const uint32_t* written = writer.getWriter32()->contiguousArray(); | |
273 SkASSERT(written != NULL); | |
274 ASSERT(*written == ((1<<0) | (1<<2) | (1<<3) | (1<<9))); // Dirty bits for
our 4. | |
275 | |
276 SkReadBuffer reader(written, writer.bytesWritten()); | |
277 SkPaint other; | |
278 SkPaint::FlatteningTraits::Unflatten(reader, &other); | |
279 ASSERT(reader.offset() == writer.bytesWritten()); | |
280 | |
281 // No matter the encoding, these must always hold. | |
282 ASSERT(other.getColor() == paint.getColor()); | |
283 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); | |
284 ASSERT(other.getTextSize() == paint.getTextSize()); | |
285 ASSERT(other.getLooper() == paint.getLooper()); | |
286 | |
287 // We have to be a little looser and compare just the modes. Pointers might
not be the same. | |
288 SkXfermode::Mode otherMode, paintMode; | |
289 ASSERT(other.getXfermode()->asMode(&otherMode)); | |
290 ASSERT(paint.getXfermode()->asMode(&paintMode)); | |
291 ASSERT(otherMode == paintMode); | |
292 } | |
OLD | NEW |