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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

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