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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 SkRect r; | 308 SkRect r; |
309 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); | 309 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); |
310 | 310 |
311 // test that the rect was reset | 311 // test that the rect was reset |
312 paint.measureText("", 0, &r); | 312 paint.measureText("", 0, &r); |
313 REPORTER_ASSERT(reporter, r.isEmpty()); | 313 REPORTER_ASSERT(reporter, r.isEmpty()); |
314 } | 314 } |
315 | 315 |
316 #define ASSERT(expr) REPORTER_ASSERT(r, expr) | 316 #define ASSERT(expr) REPORTER_ASSERT(r, expr) |
317 | 317 |
318 DEF_TEST(Paint_FlatteningTraits, r) { | 318 DEF_TEST(Paint_MoreFlattening, r) { |
319 SkPaint paint; | 319 SkPaint paint; |
320 paint.setColor(0x00AABBCC); | 320 paint.setColor(0x00AABBCC); |
321 paint.setTextScaleX(1.0f); // Default value, ignored. | 321 paint.setTextScaleX(1.0f); // Default value, ignored. |
322 paint.setTextSize(19); | 322 paint.setTextSize(19); |
323 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref(); | 323 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref(); |
324 paint.setLooper(NULL); // Default value, ignored. | 324 paint.setLooper(NULL); // Default value, ignored. |
325 | 325 |
326 SkWriteBuffer writer; | 326 SkWriteBuffer writer; |
327 SkPaint::FlatteningTraits::Flatten(writer, paint); | 327 paint.flatten(writer); |
328 | 328 |
329 // BEGIN white box asserts: if the impl changes, these asserts may change | 329 SkReadBuffer reader(writer.getWriter32()->contiguousArray(), writer.bytesWri
tten()); |
330 const size_t expectedBytesWritten = sizeof(void*) == 8 ? 32 : 28; | |
331 ASSERT(expectedBytesWritten == writer.bytesWritten()); | |
332 | |
333 const uint32_t* written = writer.getWriter32()->contiguousArray(); | |
334 SkASSERT(written != NULL); | |
335 ASSERT(*written == ((1<<0) | (1<<1) | (1<<8))); // Dirty bits for our 3
. | |
336 // END white box asserts | |
337 | |
338 SkReadBuffer reader(written, writer.bytesWritten()); | |
339 SkPaint other; | 330 SkPaint other; |
340 SkPaint::FlatteningTraits::Unflatten(reader, &other); | 331 other.unflatten(reader); |
341 ASSERT(reader.offset() == writer.bytesWritten()); | 332 ASSERT(reader.offset() == writer.bytesWritten()); |
342 | 333 |
343 // No matter the encoding, these must always hold. | 334 // No matter the encoding, these must always hold. |
344 ASSERT(other.getColor() == paint.getColor()); | 335 ASSERT(other.getColor() == paint.getColor()); |
345 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); | 336 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); |
346 ASSERT(other.getTextSize() == paint.getTextSize()); | 337 ASSERT(other.getTextSize() == paint.getTextSize()); |
347 ASSERT(other.getLooper() == paint.getLooper()); | 338 ASSERT(other.getLooper() == paint.getLooper()); |
348 | 339 |
349 // We have to be a little looser and compare just the modes. Pointers might
not be the same. | 340 // We have to be a little looser and compare just the modes. Pointers might
not be the same. |
350 SkXfermode::Mode otherMode, paintMode; | 341 SkXfermode::Mode otherMode, paintMode; |
351 ASSERT(other.getXfermode()->asMode(&otherMode)); | 342 ASSERT(other.getXfermode()->asMode(&otherMode)); |
352 ASSERT(paint.getXfermode()->asMode(&paintMode)); | 343 ASSERT(paint.getXfermode()->asMode(&paintMode)); |
353 ASSERT(otherMode == paintMode); | 344 ASSERT(otherMode == paintMode); |
354 } | 345 } |
OLD | NEW |