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 "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 template<typename T> | 142 template<typename T> |
143 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, | 143 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, |
144 skiatest::Reporter* reporter) { | 144 skiatest::Reporter* reporter) { |
145 SkOrderedWriteBuffer writer(1024); | 145 SkOrderedWriteBuffer writer(1024); |
146 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); | 146 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); |
147 SerializationUtils<T>::Write(writer, testObj); | 147 SerializationUtils<T>::Write(writer, testObj); |
148 size_t bytesWritten = writer.bytesWritten(); | 148 size_t bytesWritten = writer.bytesWritten(); |
149 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); | 149 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); |
150 | 150 |
151 unsigned char dataWritten[1024]; | 151 unsigned char dataWritten[1024]; |
| 152 SkASSERT(bytesWritten <= sizeof(dataWritten)); |
152 writer.writeToMemory(dataWritten); | 153 writer.writeToMemory(dataWritten); |
153 | 154 |
154 // Make sure this fails when it should (test with smaller size, but still mu
ltiple of 4) | 155 // Make sure this fails when it should (test with smaller size, but still mu
ltiple of 4) |
155 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); | 156 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); |
156 T* obj = NULL; | 157 T* obj = NULL; |
157 SerializationUtils<T>::Read(buffer, &obj); | 158 SerializationUtils<T>::Read(buffer, &obj); |
158 REPORTER_ASSERT(reporter, !buffer.isValid()); | 159 REPORTER_ASSERT(reporter, !buffer.isValid()); |
159 REPORTER_ASSERT(reporter, NULL == obj); | 160 REPORTER_ASSERT(reporter, NULL == obj); |
160 | 161 |
161 // Make sure this succeeds when it should | 162 // Make sure this succeeds when it should |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 302 |
302 // Create a bitmap with a really large height | 303 // Create a bitmap with a really large height |
303 SkBitmap invalidBitmap; | 304 SkBitmap invalidBitmap; |
304 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); | 305 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); |
305 | 306 |
306 // The deserialization should succeed, and the rendering shouldn't crash
, | 307 // The deserialization should succeed, and the rendering shouldn't crash
, |
307 // even when the device fails to initialize, due to its size | 308 // even when the device fails to initialize, due to its size |
308 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); | 309 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
309 | 310 |
310 // Create a bitmap with a pixel ref too small | 311 // Create a bitmap with a pixel ref too small |
| 312 SkImageInfo info; |
| 313 info.fWidth = 256; |
| 314 info.fHeight = 256; |
| 315 info.fColorType = kPMColor_SkColorType; |
| 316 info.fAlphaType = kPremul_SkAlphaType; |
| 317 |
311 SkBitmap invalidBitmap2; | 318 SkBitmap invalidBitmap2; |
312 invalidBitmap2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 319 invalidBitmap2.setConfig(info); |
313 invalidBitmap2.setPixelRef(SkNEW_ARGS(SkMallocPixelRef, | 320 |
314 (NULL, 256, NULL)))->unref(); | 321 // Hack to force invalid, by making the pixelref smaller than its |
| 322 // owning bitmap. |
| 323 info.fWidth = 32; |
| 324 info.fHeight = 1; |
| 325 |
| 326 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate( |
| 327 info, invalidBitmap2.rowBytes(), NULL))->unref(); |
315 | 328 |
316 // The deserialization should detect the pixel ref being too small and f
ail | 329 // The deserialization should detect the pixel ref being too small and f
ail |
317 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); | 330 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); |
318 } | 331 } |
319 } | 332 } |
OLD | NEW |