OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmapSource.h" | |
10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
11 #include "SkFixed.h" | 10 #include "SkFixed.h" |
12 #include "SkFontDescriptor.h" | 11 #include "SkFontDescriptor.h" |
| 12 #include "SkImage.h" |
| 13 #include "SkImageSource.h" |
13 #include "SkMallocPixelRef.h" | 14 #include "SkMallocPixelRef.h" |
14 #include "SkOSFile.h" | 15 #include "SkOSFile.h" |
15 #include "SkPictureRecorder.h" | 16 #include "SkPictureRecorder.h" |
16 #include "SkTableColorFilter.h" | 17 #include "SkTableColorFilter.h" |
17 #include "SkTemplates.h" | 18 #include "SkTemplates.h" |
18 #include "SkTypeface.h" | 19 #include "SkTypeface.h" |
19 #include "SkWriteBuffer.h" | 20 #include "SkWriteBuffer.h" |
20 #include "SkValidatingReadBuffer.h" | 21 #include "SkValidatingReadBuffer.h" |
21 #include "SkXfermodeImageFilter.h" | 22 #include "SkXfermodeImageFilter.h" |
22 #include "Test.h" | 23 #include "Test.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); | 234 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
234 success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize); | 235 success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize); |
235 // This should have succeeded, since there are enough bytes to read this | 236 // This should have succeeded, since there are enough bytes to read this |
236 REPORTER_ASSERT(reporter, success); | 237 REPORTER_ASSERT(reporter, success); |
237 } | 238 } |
238 | 239 |
239 static void TestBitmapSerialization(const SkBitmap& validBitmap, | 240 static void TestBitmapSerialization(const SkBitmap& validBitmap, |
240 const SkBitmap& invalidBitmap, | 241 const SkBitmap& invalidBitmap, |
241 bool shouldSucceed, | 242 bool shouldSucceed, |
242 skiatest::Reporter* reporter) { | 243 skiatest::Reporter* reporter) { |
243 SkAutoTUnref<SkBitmapSource> validBitmapSource(SkBitmapSource::Create(validB
itmap)); | 244 SkAutoTUnref<SkImage> validImage(SkImage::NewFromBitmap(validBitmap)); |
244 SkAutoTUnref<SkBitmapSource> invalidBitmapSource(SkBitmapSource::Create(inva
lidBitmap)); | 245 SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validIma
ge)); |
| 246 SkAutoTUnref<SkImage> invalidImage(SkImage::NewFromBitmap(invalidBitmap)); |
| 247 SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invali
dImage)); |
245 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode))
; | 248 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode))
; |
246 SkAutoTUnref<SkXfermodeImageFilter> xfermodeImageFilter( | 249 SkAutoTUnref<SkXfermodeImageFilter> xfermodeImageFilter( |
247 SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSour
ce)); | 250 SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSour
ce)); |
248 | 251 |
249 SkAutoTUnref<SkImageFilter> deserializedFilter( | 252 SkAutoTUnref<SkImageFilter> deserializedFilter( |
250 TestFlattenableSerialization<SkImageFilter>( | 253 TestFlattenableSerialization<SkImageFilter>( |
251 xfermodeImageFilter, shouldSucceed, reporter)); | 254 xfermodeImageFilter, shouldSucceed, reporter)); |
252 | 255 |
253 // Try to render a small bitmap using the invalid deserialized filter | 256 // Try to render a small bitmap using the invalid deserialized filter |
254 // to make sure we don't crash while trying to render it | 257 // to make sure we don't crash while trying to render it |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 539 |
537 // Deserialize picture | 540 // Deserialize picture |
538 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); | 541 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
539 SkAutoTUnref<SkPicture> readPict( | 542 SkAutoTUnref<SkPicture> readPict( |
540 SkPicture::CreateFromBuffer(reader)); | 543 SkPicture::CreateFromBuffer(reader)); |
541 REPORTER_ASSERT(reporter, readPict.get()); | 544 REPORTER_ASSERT(reporter, readPict.get()); |
542 } | 545 } |
543 | 546 |
544 TestPictureTypefaceSerialization(reporter); | 547 TestPictureTypefaceSerialization(reporter); |
545 } | 548 } |
OLD | NEW |