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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 74793011: Add SkImageGenerator Interface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: protected destructor Created 7 years, 1 month 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 | Annotate | Revision Log
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkDecodingImageGenerator.h"
11 #include "SkForceLinking.h" 12 #include "SkForceLinking.h"
12 #include "SkImageDecoder.h" 13 #include "SkImageDecoder.h"
13 #include "SkImagePriv.h" 14 #include "SkImagePriv.h"
14 #include "SkLazyCachingPixelRef.h" 15 #include "SkLazyCachingPixelRef.h"
15 #include "SkLazyPixelRef.h" 16 #include "SkLazyPixelRef.h"
16 #include "SkScaledImageCache.h" 17 #include "SkScaledImageCache.h"
17 #include "SkStream.h" 18 #include "SkStream.h"
18 19
19 #include "Test.h" 20 #include "Test.h"
20 #include "TestClassDef.h" 21 #include "TestClassDef.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 DEF_TEST(CachingPixelRef, reporter) { 238 DEF_TEST(CachingPixelRef, reporter) {
238 SkBitmap lazy; 239 SkBitmap lazy;
239 // test the error handling 240 // test the error handling
240 REPORTER_ASSERT(reporter, !TestPixelRef::Install(&lazy, 0)); 241 REPORTER_ASSERT(reporter, !TestPixelRef::Install(&lazy, 0));
241 // onDecodeInfo should succeed, allowing installation 242 // onDecodeInfo should succeed, allowing installation
242 REPORTER_ASSERT(reporter, TestPixelRef::Install(&lazy, 1)); 243 REPORTER_ASSERT(reporter, TestPixelRef::Install(&lazy, 1));
243 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. 244 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
244 // onDecodePixels should fail, so getting pixels will fail. 245 // onDecodePixels should fail, so getting pixels will fail.
245 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); 246 REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
246 } 247 }
248
249 static void compare_with_SkDecodingImageGenerator(skiatest::Reporter* reporter,
250 SkData* encoded,
251 const SkBitmap& original,
252 bool comparePixels) {
253
254 SkBitmap lazy;
255 bool success = SkDecodingImageGenerator::Install(encoded, &lazy);
256 REPORTER_ASSERT(reporter, success);
scroggo 2013/11/19 22:19:27 If success is false, should we return false?
hal.canary 2013/11/20 00:07:10 We should return early, at least.
257
258 bool getPixelsSuccess;
259 REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
260 {
261 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
262 REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
263 getPixelsSuccess = (NULL != lazy.getPixels());
264 }
265 if (!getPixelsSuccess) {
266 return;
267 }
268 // pixels should be gone!
269 REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
270 {
271 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
272 REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
273 }
274 if (getPixelsSuccess) {
275 compare_bitmaps(reporter, original, lazy, comparePixels);
276 }
277 }
278 DEF_TEST(DecodingImageGenerator, reporter) {
279 test_three_encodings(reporter, compare_with_SkDecodingImageGenerator);
280 }
OLDNEW
« src/ports/SkDiscardableMemory_none.cpp ('K') | « src/ports/SkDiscardableMemory_none.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698