| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_FlatteningTraits, r) { |
| 319 SkPaint paint; | 319 SkPaint paint; |
| 320 paint.setColor(0x00AABBCC); | 320 paint.setColor(0x00AABBCC); |
| 321 paint.setTextScaleX(1.0f); // Encoded despite being the default value. | 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); // Ignored. | 324 paint.setLooper(NULL); // Default value, ignored. |
| 325 | 325 |
| 326 SkWriteBuffer writer; | 326 SkWriteBuffer writer; |
| 327 SkPaint::FlatteningTraits::Flatten(writer, paint); | 327 SkPaint::FlatteningTraits::Flatten(writer, paint); |
| 328 const size_t expectedBytesWritten = sizeof(void*) == 8 ? 36 : 32; | |
| 329 ASSERT(expectedBytesWritten == writer.bytesWritten()); | |
| 330 | 328 |
| 331 const uint32_t* written = writer.getWriter32()->contiguousArray(); | 329 // BEGIN white box asserts: if the impl changes, these asserts may change |
| 332 SkASSERT(written != NULL); | 330 const size_t expectedBytesWritten = sizeof(void*) == 8 ? 32 : 28; |
| 333 ASSERT(*written == ((1<<0) | (1<<1) | (1<<2) | (1<<8))); // Dirty bits for
our 4. | 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 |
| 334 | 337 |
| 335 SkReadBuffer reader(written, writer.bytesWritten()); | 338 SkReadBuffer reader(written, writer.bytesWritten()); |
| 336 SkPaint other; | 339 SkPaint other; |
| 337 SkPaint::FlatteningTraits::Unflatten(reader, &other); | 340 SkPaint::FlatteningTraits::Unflatten(reader, &other); |
| 338 ASSERT(reader.offset() == writer.bytesWritten()); | 341 ASSERT(reader.offset() == writer.bytesWritten()); |
| 339 | 342 |
| 340 // No matter the encoding, these must always hold. | 343 // No matter the encoding, these must always hold. |
| 341 ASSERT(other.getColor() == paint.getColor()); | 344 ASSERT(other.getColor() == paint.getColor()); |
| 342 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); | 345 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); |
| 343 ASSERT(other.getTextSize() == paint.getTextSize()); | 346 ASSERT(other.getTextSize() == paint.getTextSize()); |
| 344 ASSERT(other.getLooper() == paint.getLooper()); | 347 ASSERT(other.getLooper() == paint.getLooper()); |
| 345 | 348 |
| 346 // We have to be a little looser and compare just the modes. Pointers might
not be the same. | 349 // We have to be a little looser and compare just the modes. Pointers might
not be the same. |
| 347 SkXfermode::Mode otherMode, paintMode; | 350 SkXfermode::Mode otherMode, paintMode; |
| 348 ASSERT(other.getXfermode()->asMode(&otherMode)); | 351 ASSERT(other.getXfermode()->asMode(&otherMode)); |
| 349 ASSERT(paint.getXfermode()->asMode(&paintMode)); | 352 ASSERT(paint.getXfermode()->asMode(&paintMode)); |
| 350 ASSERT(otherMode == paintMode); | 353 ASSERT(otherMode == paintMode); |
| 351 } | 354 } |
| OLD | NEW |