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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 1369443002: Revert "Revert of remove unused SkCachingPixelRef (patchset #1 id:1 of https://codereview.chromium.… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/lazy/SkCachingPixelRef.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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCachingPixelRef.h"
10 #include "SkCanvas.h" 9 #include "SkCanvas.h"
11 #include "SkData.h" 10 #include "SkData.h"
12 #include "SkDiscardableMemoryPool.h" 11 #include "SkDiscardableMemoryPool.h"
13 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
14 #include "SkImageGeneratorPriv.h" 13 #include "SkImageGeneratorPriv.h"
15 #include "SkResourceCache.h" 14 #include "SkResourceCache.h"
16 #include "SkStream.h" 15 #include "SkStream.h"
17 #include "SkUtils.h" 16 #include "SkUtils.h"
18 17
19 #include "Test.h" 18 #include "Test.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (nullptr == lazy.getPixels()) { 133 if (nullptr == lazy.getPixels()) {
135 continue; 134 continue;
136 } 135 }
137 } 136 }
138 bool comparePixels = (SkImageEncoder::kPNG_Type == type); 137 bool comparePixels = (SkImageEncoder::kPNG_Type == type);
139 compare_bitmaps(reporter, original, lazy, comparePixels); 138 compare_bitmaps(reporter, original, lazy, comparePixels);
140 } 139 }
141 } 140 }
142 141
143 //////////////////////////////////////////////////////////////////////////////// 142 ////////////////////////////////////////////////////////////////////////////////
144 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) {
145 return SkCachingPixelRef::Install(SkImageGenerator::NewFromEncoded(encoded), dst);
146 }
147 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { 143 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
148 // Use system-default discardable memory. 144 // Use system-default discardable memory.
149 return SkInstallDiscardablePixelRef(encoded, dst); 145 return SkInstallDiscardablePixelRef(encoded, dst);
150 } 146 }
151 147
152 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
153 /** 149 /**
154 * This checks to see that a SkCachingPixelRef and a 150 * This checks to see that SkDiscardablePixelRef works as advertised with a
155 * SkDiscardablePixelRef works as advertised with a
156 * SkDecodingImageGenerator. 151 * SkDecodingImageGenerator.
157 */ 152 */
158 DEF_TEST(DecodingImageGenerator, reporter) { 153 DEF_TEST(DecodingImageGenerator, reporter) {
159 test_three_encodings(reporter, install_skCachingPixelRef);
160 test_three_encodings(reporter, install_skDiscardablePixelRef); 154 test_three_encodings(reporter, install_skDiscardablePixelRef);
161 } 155 }
162 156
163 class TestImageGenerator : public SkImageGenerator { 157 class TestImageGenerator : public SkImageGenerator {
164 public: 158 public:
165 enum TestType { 159 enum TestType {
166 kFailGetPixels_TestType, 160 kFailGetPixels_TestType,
167 kSucceedGetPixels_TestType, 161 kSucceedGetPixels_TestType,
168 kLast_TestType = kSucceedGetPixels_TestType 162 kLast_TestType = kSucceedGetPixels_TestType
169 }; 163 };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 for (int y = 0; y < bm.height(); ++y) { 215 for (int y = 0; y < bm.height(); ++y) {
222 for (int x = 0; x < bm.width(); ++x) { 216 for (int x = 0; x < bm.width(); ++x) {
223 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) { 217 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) {
224 ++errors; 218 ++errors;
225 } 219 }
226 } 220 }
227 } 221 }
228 REPORTER_ASSERT(reporter, 0 == errors); 222 REPORTER_ASSERT(reporter, 0 == errors);
229 } 223 }
230 224
231 enum PixelRefType {
232 kSkCaching_PixelRefType,
233 kSkDiscardable_PixelRefType,
234 kLast_PixelRefType = kSkDiscardable_PixelRefType
235 };
236
237 static void check_pixelref(TestImageGenerator::TestType type, 225 static void check_pixelref(TestImageGenerator::TestType type,
238 skiatest::Reporter* reporter, 226 skiatest::Reporter* reporter,
239 PixelRefType pixelRefType,
240 SkDiscardableMemory::Factory* factory) { 227 SkDiscardableMemory::Factory* factory) {
241 SkASSERT((pixelRefType >= 0) && (pixelRefType <= kLast_PixelRefType));
242 SkAutoTDelete<SkImageGenerator> gen(new TestImageGenerator(type, reporter)); 228 SkAutoTDelete<SkImageGenerator> gen(new TestImageGenerator(type, reporter));
243 REPORTER_ASSERT(reporter, gen.get() != nullptr); 229 REPORTER_ASSERT(reporter, gen.get() != nullptr);
244 SkBitmap lazy; 230 SkBitmap lazy;
245 bool success; 231 bool success = SkInstallDiscardablePixelRef(gen.detach(), nullptr, &lazy, fa ctory);
246 if (kSkCaching_PixelRefType == pixelRefType) { 232
247 // Ignore factory; use global cache.
248 success = SkCachingPixelRef::Install(gen.detach(), &lazy);
249 } else {
250 success = SkInstallDiscardablePixelRef(gen.detach(), nullptr, &lazy, fac tory);
251 }
252 REPORTER_ASSERT(reporter, success); 233 REPORTER_ASSERT(reporter, success);
253 if (TestImageGenerator::kSucceedGetPixels_TestType == type) { 234 if (TestImageGenerator::kSucceedGetPixels_TestType == type) {
254 check_test_image_generator_bitmap(reporter, lazy); 235 check_test_image_generator_bitmap(reporter, lazy);
255 } else if (TestImageGenerator::kFailGetPixels_TestType == type) { 236 } else if (TestImageGenerator::kFailGetPixels_TestType == type) {
256 SkAutoLockPixels autoLockPixels(lazy); 237 SkAutoLockPixels autoLockPixels(lazy);
257 REPORTER_ASSERT(reporter, nullptr == lazy.getPixels()); 238 REPORTER_ASSERT(reporter, nullptr == lazy.getPixels());
258 } 239 }
259 } 240 }
260 241
261 // new/lock/delete is an odd pattern for a pixelref, but it needs to not assert
262 static void test_newlockdelete(skiatest::Reporter* reporter) {
263 #ifdef SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT
264 SkBitmap bm;
265 SkImageGenerator* ig = new TestImageGenerator(
266 TestImageGenerator::kSucceedGetPixels_TestType, reporter);
267 SkInstallDiscardablePixelRef(ig, &bm);
268 bm.pixelRef()->lockPixels();
269 #endif
270 }
271
272 /** 242 /**
273 * This tests the basic functionality of SkDiscardablePixelRef with a 243 * This tests the basic functionality of SkDiscardablePixelRef with a
274 * basic SkImageGenerator implementation and several 244 * basic SkImageGenerator implementation and several
275 * SkDiscardableMemory::Factory choices. 245 * SkDiscardableMemory::Factory choices.
276 */ 246 */
277 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { 247 DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
278 test_newlockdelete(reporter); 248 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, nullpt r);
279 249 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, nul lptr);
280 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
281 reporter, kSkCaching_PixelRefType, nullptr);
282 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
283 reporter, kSkCaching_PixelRefType, nullptr);
284
285 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
286 reporter, kSkDiscardable_PixelRefType, nullptr);
287 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
288 reporter, kSkDiscardable_PixelRefType, nullptr);
289 250
290 SkAutoTUnref<SkDiscardableMemoryPool> pool( 251 SkAutoTUnref<SkDiscardableMemoryPool> pool(
291 SkDiscardableMemoryPool::Create(1, nullptr)); 252 SkDiscardableMemoryPool::Create(1, nullptr));
292 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 253 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
293 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 254 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, pool);
294 reporter, kSkDiscardable_PixelRefType, pool);
295 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 255 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
296 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 256 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, poo l);
297 reporter, kSkDiscardable_PixelRefType, pool);
298 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 257 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
299 258
300 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); 259 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool();
301 // Only acts differently from nullptr on a platform that has a 260 // Only acts differently from nullptr on a platform that has a
302 // default discardable memory implementation that differs from the 261 // default discardable memory implementation that differs from the
303 // global DM pool. 262 // global DM pool.
304 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 263 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, global Pool);
305 reporter, kSkDiscardable_PixelRefType, globalPool); 264 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, glo balPool);
306 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
307 reporter, kSkDiscardable_PixelRefType, globalPool);
308 } 265 }
309 266
310 //////////////////////////////////////////////////////////////////////////////// 267 ////////////////////////////////////////////////////////////////////////////////
311 268
312 DEF_TEST(Image_NewFromGenerator, r) { 269 DEF_TEST(Image_NewFromGenerator, r) {
313 TestImageGenerator::TestType testTypes[] = { 270 TestImageGenerator::TestType testTypes[] = {
314 TestImageGenerator::kFailGetPixels_TestType, 271 TestImageGenerator::kFailGetPixels_TestType,
315 TestImageGenerator::kSucceedGetPixels_TestType, 272 TestImageGenerator::kSucceedGetPixels_TestType,
316 }; 273 };
317 for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) { 274 for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) {
(...skipping 16 matching lines...) Expand all
334 canvas.clear(kDefaultColor); 291 canvas.clear(kDefaultColor);
335 canvas.drawImage(image, 0, 0, nullptr); 292 canvas.drawImage(image, 0, 0, nullptr);
336 if (TestImageGenerator::kSucceedGetPixels_TestType == test) { 293 if (TestImageGenerator::kSucceedGetPixels_TestType == test) {
337 REPORTER_ASSERT( 294 REPORTER_ASSERT(
338 r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0)); 295 r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0));
339 } else { 296 } else {
340 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0)); 297 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0));
341 } 298 }
342 } 299 }
343 } 300 }
OLDNEW
« no previous file with comments | « src/lazy/SkCachingPixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698