| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 { | 383 { |
| 384 SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; | 384 SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; |
| 385 TestArraySerialization(data, reporter); | 385 TestArraySerialization(data, reporter); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // Test invalid deserializations | 388 // Test invalid deserializations |
| 389 { | 389 { |
| 390 SkImageInfo info = SkImageInfo::MakeN32Premul(kBitmapSize, kBitmapSize); | 390 SkImageInfo info = SkImageInfo::MakeN32Premul(kBitmapSize, kBitmapSize); |
| 391 | 391 |
| 392 SkBitmap validBitmap; | 392 SkBitmap validBitmap; |
| 393 validBitmap.setInfo(info); | 393 validBitmap.setConfig(info); |
| 394 | 394 |
| 395 // Create a bitmap with a really large height | 395 // Create a bitmap with a really large height |
| 396 info.fHeight = 1000000000; | 396 info.fHeight = 1000000000; |
| 397 SkBitmap invalidBitmap; | 397 SkBitmap invalidBitmap; |
| 398 invalidBitmap.setInfo(info); | 398 invalidBitmap.setConfig(info); |
| 399 | 399 |
| 400 // The deserialization should succeed, and the rendering shouldn't crash
, | 400 // The deserialization should succeed, and the rendering shouldn't crash
, |
| 401 // even when the device fails to initialize, due to its size | 401 // even when the device fails to initialize, due to its size |
| 402 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); | 402 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
| 403 } | 403 } |
| 404 | 404 |
| 405 // Test simple SkPicture serialization | 405 // Test simple SkPicture serialization |
| 406 { | 406 { |
| 407 SkPictureRecorder recorder; | 407 SkPictureRecorder recorder; |
| 408 bool didDraw = drawSomething(recorder.beginRecording(kBitmapSize, kBitma
pSize, NULL, 0)); | 408 bool didDraw = drawSomething(recorder.beginRecording(kBitmapSize, kBitma
pSize, NULL, 0)); |
| 409 REPORTER_ASSERT(reporter, didDraw); | 409 REPORTER_ASSERT(reporter, didDraw); |
| 410 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); | 410 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
| 411 | 411 |
| 412 // Serialize picture | 412 // Serialize picture |
| 413 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); | 413 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
| 414 pict->flatten(writer); | 414 pict->flatten(writer); |
| 415 size_t size = writer.bytesWritten(); | 415 size_t size = writer.bytesWritten(); |
| 416 SkAutoTMalloc<unsigned char> data(size); | 416 SkAutoTMalloc<unsigned char> data(size); |
| 417 writer.writeToMemory(static_cast<void*>(data.get())); | 417 writer.writeToMemory(static_cast<void*>(data.get())); |
| 418 | 418 |
| 419 // Deserialize picture | 419 // Deserialize picture |
| 420 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); | 420 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
| 421 SkAutoTUnref<SkPicture> readPict( | 421 SkAutoTUnref<SkPicture> readPict( |
| 422 SkPicture::CreateFromBuffer(reader)); | 422 SkPicture::CreateFromBuffer(reader)); |
| 423 REPORTER_ASSERT(reporter, NULL != readPict.get()); | 423 REPORTER_ASSERT(reporter, NULL != readPict.get()); |
| 424 } | 424 } |
| 425 } | 425 } |
| OLD | NEW |