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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 132803005: SkOnce: add option to call another cleanup function once at exit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add static Created 6 years, 11 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 | « src/core/SkScaledImageCache.cpp ('k') | tests/OnceTest.cpp » ('j') | 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); 135 REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
136 if (NULL == lazy.getPixels()) { 136 if (NULL == lazy.getPixels()) {
137 continue; 137 continue;
138 } 138 }
139 } 139 }
140 bool comparePixels = (SkImageEncoder::kPNG_Type == type); 140 bool comparePixels = (SkImageEncoder::kPNG_Type == type);
141 compare_bitmaps(reporter, original, lazy, comparePixels); 141 compare_bitmaps(reporter, original, lazy, comparePixels);
142 } 142 }
143 } 143 }
144 144
145 static void purge_global_scaled_image_cache() {
146 size_t byteLimit = SkScaledImageCache::GetByteLimit();
147 SkScaledImageCache::SetByteLimit(0);
148 SkScaledImageCache::SetByteLimit(byteLimit);
149 }
150
151 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
152 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { 146 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) {
153 return SkCachingPixelRef::Install( 147 return SkCachingPixelRef::Install(
154 SkDecodingImageGenerator::Create( 148 SkDecodingImageGenerator::Create(
155 encoded, SkDecodingImageGenerator::Options()), dst); 149 encoded, SkDecodingImageGenerator::Options()), dst);
156 } 150 }
157 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { 151 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
158 // Use system-default discardable memory. 152 // Use system-default discardable memory.
159 return SkInstallDiscardablePixelRef( 153 return SkInstallDiscardablePixelRef(
160 SkDecodingImageGenerator::Create( 154 SkDecodingImageGenerator::Create(
161 encoded, SkDecodingImageGenerator::Options()), dst, NULL); 155 encoded, SkDecodingImageGenerator::Options()), dst, NULL);
162 } 156 }
163 157
164 //////////////////////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////////////////
165 /** 159 /**
166 * This checks to see that a SkCachingPixelRef and a 160 * This checks to see that a SkCachingPixelRef and a
167 * SkDiscardablePixelRef works as advertised with a 161 * SkDiscardablePixelRef works as advertised with a
168 * SkDecodingImageGenerator. 162 * SkDecodingImageGenerator.
169 */ 163 */
170 DEF_TEST(DecodingImageGenerator, reporter) { 164 DEF_TEST(DecodingImageGenerator, reporter) {
171 test_three_encodings(reporter, install_skCachingPixelRef); 165 test_three_encodings(reporter, install_skCachingPixelRef);
172 purge_global_scaled_image_cache();
173 test_three_encodings(reporter, install_skDiscardablePixelRef); 166 test_three_encodings(reporter, install_skDiscardablePixelRef);
174 } 167 }
175 168
176 class TestImageGenerator : public SkImageGenerator { 169 class TestImageGenerator : public SkImageGenerator {
177 public: 170 public:
178 enum TestType { 171 enum TestType {
179 kFailGetInfo_TestType, 172 kFailGetInfo_TestType,
180 kFailGetPixels_TestType, 173 kFailGetPixels_TestType,
181 kSucceedGetPixels_TestType, 174 kSucceedGetPixels_TestType,
182 kLast_TestType = kSucceedGetPixels_TestType 175 kLast_TestType = kSucceedGetPixels_TestType
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { 288 DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
296 test_newlockdelete(reporter); 289 test_newlockdelete(reporter);
297 290
298 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, 291 check_pixelref(TestImageGenerator::kFailGetInfo_TestType,
299 reporter, kSkCaching_PixelRefType, NULL); 292 reporter, kSkCaching_PixelRefType, NULL);
300 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 293 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
301 reporter, kSkCaching_PixelRefType, NULL); 294 reporter, kSkCaching_PixelRefType, NULL);
302 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 295 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
303 reporter, kSkCaching_PixelRefType, NULL); 296 reporter, kSkCaching_PixelRefType, NULL);
304 297
305 purge_global_scaled_image_cache();
306
307 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, 298 check_pixelref(TestImageGenerator::kFailGetInfo_TestType,
308 reporter, kSkDiscardable_PixelRefType, NULL); 299 reporter, kSkDiscardable_PixelRefType, NULL);
309 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 300 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
310 reporter, kSkDiscardable_PixelRefType, NULL); 301 reporter, kSkDiscardable_PixelRefType, NULL);
311 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 302 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
312 reporter, kSkDiscardable_PixelRefType, NULL); 303 reporter, kSkDiscardable_PixelRefType, NULL);
313 304
314 SkAutoTUnref<SkDiscardableMemoryPool> pool( 305 SkAutoTUnref<SkDiscardableMemoryPool> pool(
315 SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL))); 306 SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL)));
316 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 307 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
317 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 308 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
318 reporter, kSkDiscardable_PixelRefType, pool); 309 reporter, kSkDiscardable_PixelRefType, pool);
319 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 310 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
320 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 311 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
321 reporter, kSkDiscardable_PixelRefType, pool); 312 reporter, kSkDiscardable_PixelRefType, pool);
322 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 313 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
323 314
324 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); 315 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool();
325 // Only acts differently from NULL on a platform that has a 316 // Only acts differently from NULL on a platform that has a
326 // default discardable memory implementation that differs from the 317 // default discardable memory implementation that differs from the
327 // global DM pool. 318 // global DM pool.
328 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 319 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
329 reporter, kSkDiscardable_PixelRefType, globalPool); 320 reporter, kSkDiscardable_PixelRefType, globalPool);
330 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 321 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
331 reporter, kSkDiscardable_PixelRefType, globalPool); 322 reporter, kSkDiscardable_PixelRefType, globalPool);
332 } 323 }
OLDNEW
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698