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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 SkXfermodeImageFilter xfermodeImageFilter(mode, &invalidBitmapSource, &valid
BitmapSource); | 211 SkXfermodeImageFilter xfermodeImageFilter(mode, &invalidBitmapSource, &valid
BitmapSource); |
212 | 212 |
213 SkAutoTUnref<SkImageFilter> deserializedFilter( | 213 SkAutoTUnref<SkImageFilter> deserializedFilter( |
214 TestFlattenableSerialization<SkImageFilter>( | 214 TestFlattenableSerialization<SkImageFilter>( |
215 &xfermodeImageFilter, shouldSucceed, reporter)); | 215 &xfermodeImageFilter, shouldSucceed, reporter)); |
216 | 216 |
217 // Try to render a small bitmap using the invalid deserialized filter | 217 // Try to render a small bitmap using the invalid deserialized filter |
218 // to make sure we don't crash while trying to render it | 218 // to make sure we don't crash while trying to render it |
219 if (shouldSucceed) { | 219 if (shouldSucceed) { |
220 SkBitmap bitmap; | 220 SkBitmap bitmap; |
221 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 24, 24); | 221 bitmap.allocN32Pixels(24, 24); |
222 bitmap.allocPixels(); | 222 SkCanvas canvas(bitmap); |
223 SkBitmapDevice device(bitmap); | |
224 SkCanvas canvas(&device); | |
225 canvas.clear(0x00000000); | 223 canvas.clear(0x00000000); |
226 SkPaint paint; | 224 SkPaint paint; |
227 paint.setImageFilter(deserializedFilter); | 225 paint.setImageFilter(deserializedFilter); |
228 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar(
24))); | 226 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar(
24))); |
229 canvas.drawBitmap(bitmap, 0, 0, &paint); | 227 canvas.drawBitmap(bitmap, 0, 0, &paint); |
230 } | 228 } |
231 } | 229 } |
232 | 230 |
233 DEF_TEST(Serialization, reporter) { | 231 DEF_TEST(Serialization, reporter) { |
234 // Test matrix serialization | 232 // Test matrix serialization |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 284 } |
287 | 285 |
288 // Test readScalarArray | 286 // Test readScalarArray |
289 { | 287 { |
290 SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; | 288 SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; |
291 TestArraySerialization(data, reporter); | 289 TestArraySerialization(data, reporter); |
292 } | 290 } |
293 | 291 |
294 // Test invalid deserializations | 292 // Test invalid deserializations |
295 { | 293 { |
| 294 SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); |
| 295 |
296 SkBitmap validBitmap; | 296 SkBitmap validBitmap; |
297 validBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 297 validBitmap.setConfig(info); |
298 | 298 |
299 // Create a bitmap with a really large height | 299 // Create a bitmap with a really large height |
| 300 info.fHeight = 1000000000; |
300 SkBitmap invalidBitmap; | 301 SkBitmap invalidBitmap; |
301 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); | 302 invalidBitmap.setConfig(info); |
302 | 303 |
303 // The deserialization should succeed, and the rendering shouldn't crash
, | 304 // The deserialization should succeed, and the rendering shouldn't crash
, |
304 // even when the device fails to initialize, due to its size | 305 // even when the device fails to initialize, due to its size |
305 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); | 306 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
306 | |
307 // we assert if the pixelref doesn't agree with the config, so skip this | |
308 // test (at least for now) | |
309 #if 0 | |
310 // Create a bitmap with a pixel ref too small | |
311 SkImageInfo info; | |
312 info.fWidth = 256; | |
313 info.fHeight = 256; | |
314 info.fColorType = kPMColor_SkColorType; | |
315 info.fAlphaType = kPremul_SkAlphaType; | |
316 | |
317 SkBitmap invalidBitmap2; | |
318 invalidBitmap2.setConfig(info); | |
319 | |
320 // Hack to force invalid, by making the pixelref smaller than its | |
321 // owning bitmap. | |
322 info.fWidth = 32; | |
323 info.fHeight = 1; | |
324 | |
325 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate( | |
326 info, invalidBitmap2.rowBytes(), NULL))->unref(); | |
327 | |
328 // The deserialization should detect the pixel ref being too small and f
ail | |
329 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); | |
330 #endif | |
331 } | 307 } |
332 } | 308 } |
OLD | NEW |