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)); | |
153 writer.writeToMemory(dataWritten); | 152 writer.writeToMemory(dataWritten); |
154 | 153 |
155 // Make sure this fails when it should (test with smaller size, but still mu
ltiple of 4) | 154 // Make sure this fails when it should (test with smaller size, but still mu
ltiple of 4) |
156 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); | 155 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); |
157 T* obj = NULL; | 156 T* obj = NULL; |
158 SerializationUtils<T>::Read(buffer, &obj); | 157 SerializationUtils<T>::Read(buffer, &obj); |
159 REPORTER_ASSERT(reporter, !buffer.isValid()); | 158 REPORTER_ASSERT(reporter, !buffer.isValid()); |
160 REPORTER_ASSERT(reporter, NULL == obj); | 159 REPORTER_ASSERT(reporter, NULL == obj); |
161 | 160 |
162 // Make sure this succeeds when it should | 161 // Make sure this succeeds when it should |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 301 |
303 // Create a bitmap with a really large height | 302 // Create a bitmap with a really large height |
304 SkBitmap invalidBitmap; | 303 SkBitmap invalidBitmap; |
305 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); | 304 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); |
306 | 305 |
307 // The deserialization should succeed, and the rendering shouldn't crash
, | 306 // The deserialization should succeed, and the rendering shouldn't crash
, |
308 // even when the device fails to initialize, due to its size | 307 // even when the device fails to initialize, due to its size |
309 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); | 308 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
310 | 309 |
311 // Create a bitmap with a pixel ref too small | 310 // 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 | |
318 SkBitmap invalidBitmap2; | 311 SkBitmap invalidBitmap2; |
319 invalidBitmap2.setConfig(info); | 312 invalidBitmap2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); |
320 | 313 invalidBitmap2.setPixelRef(SkNEW_ARGS(SkMallocPixelRef, |
321 // Hack to force invalid, by making the pixelref smaller than its | 314 (NULL, 256, NULL)))->unref(); |
322 // owning bitmap. | |
323 info.fWidth = 32; | |
324 info.fHeight = 1; | |
325 | |
326 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate( | |
327 info, invalidBitmap2.rowBytes(), NULL))->unref(); | |
328 | 315 |
329 // The deserialization should detect the pixel ref being too small and f
ail | 316 // The deserialization should detect the pixel ref being too small and f
ail |
330 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); | 317 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); |
331 } | 318 } |
332 } | 319 } |
OLD | NEW |