Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: tests/SerializationTest.cpp

Issue 182983003: Factory methods for heap-allocated SkImageFilter objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/ImageFilterTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); 198 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
199 success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize); 199 success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize);
200 // This should have succeeded, since there are enough bytes to read this 200 // This should have succeeded, since there are enough bytes to read this
201 REPORTER_ASSERT(reporter, success); 201 REPORTER_ASSERT(reporter, success);
202 } 202 }
203 203
204 static void TestBitmapSerialization(const SkBitmap& validBitmap, 204 static void TestBitmapSerialization(const SkBitmap& validBitmap,
205 const SkBitmap& invalidBitmap, 205 const SkBitmap& invalidBitmap,
206 bool shouldSucceed, 206 bool shouldSucceed,
207 skiatest::Reporter* reporter) { 207 skiatest::Reporter* reporter) {
208 SkBitmapSource validBitmapSource(validBitmap); 208 SkAutoTUnref<SkBitmapSource> validBitmapSource(SkBitmapSource::Create(validB itmap));
209 SkBitmapSource invalidBitmapSource(invalidBitmap); 209 SkAutoTUnref<SkBitmapSource> invalidBitmapSource(SkBitmapSource::Create(inva lidBitmap));
210 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)) ; 210 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)) ;
211 SkXfermodeImageFilter xfermodeImageFilter(mode, &invalidBitmapSource, &valid BitmapSource); 211 SkAutoTUnref<SkXfermodeImageFilter> xfermodeImageFilter(
212 SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSour ce));
212 213
213 SkAutoTUnref<SkImageFilter> deserializedFilter( 214 SkAutoTUnref<SkImageFilter> deserializedFilter(
214 TestFlattenableSerialization<SkImageFilter>( 215 TestFlattenableSerialization<SkImageFilter>(
215 &xfermodeImageFilter, shouldSucceed, reporter)); 216 xfermodeImageFilter, shouldSucceed, reporter));
216 217
217 // Try to render a small bitmap using the invalid deserialized filter 218 // Try to render a small bitmap using the invalid deserialized filter
218 // to make sure we don't crash while trying to render it 219 // to make sure we don't crash while trying to render it
219 if (shouldSucceed) { 220 if (shouldSucceed) {
220 SkBitmap bitmap; 221 SkBitmap bitmap;
221 bitmap.allocN32Pixels(24, 24); 222 bitmap.allocN32Pixels(24, 24);
222 SkCanvas canvas(bitmap); 223 SkCanvas canvas(bitmap);
223 canvas.clear(0x00000000); 224 canvas.clear(0x00000000);
224 SkPaint paint; 225 SkPaint paint;
225 paint.setImageFilter(deserializedFilter); 226 paint.setImageFilter(deserializedFilter);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // Create a bitmap with a really large height 300 // Create a bitmap with a really large height
300 info.fHeight = 1000000000; 301 info.fHeight = 1000000000;
301 SkBitmap invalidBitmap; 302 SkBitmap invalidBitmap;
302 invalidBitmap.setConfig(info); 303 invalidBitmap.setConfig(info);
303 304
304 // The deserialization should succeed, and the rendering shouldn't crash , 305 // The deserialization should succeed, and the rendering shouldn't crash ,
305 // even when the device fails to initialize, due to its size 306 // even when the device fails to initialize, due to its size
306 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); 307 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter);
307 } 308 }
308 } 309 }
OLDNEW
« no previous file with comments | « tests/ImageFilterTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698