OLD | NEW |
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 "SkDiscardableMemory.h" | 8 #include "SkDiscardableMemory.h" |
9 #include "SkScaledImageCache.h" | 9 #include "SkScaledImageCache.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 cache.setByteLimit(0); | 77 cache.setByteLimit(0); |
78 } | 78 } |
79 | 79 |
80 #include "SkDiscardableMemoryPool.h" | 80 #include "SkDiscardableMemoryPool.h" |
81 | 81 |
82 static SkDiscardableMemoryPool* gPool; | 82 static SkDiscardableMemoryPool* gPool; |
83 static SkDiscardableMemory* pool_factory(size_t bytes) { | 83 static SkDiscardableMemory* pool_factory(size_t bytes) { |
| 84 SkASSERT(gPool); |
84 return gPool->create(bytes); | 85 return gPool->create(bytes); |
85 } | 86 } |
86 | 87 |
87 DEF_TEST(ImageCache, reporter) { | 88 DEF_TEST(ImageCache, reporter) { |
88 static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop | 89 static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop |
89 | 90 |
90 { | 91 { |
91 SkScaledImageCache cache(defLimit); | 92 SkScaledImageCache cache(defLimit); |
92 test_cache(reporter, cache, true); | 93 test_cache(reporter, cache, true); |
93 } | 94 } |
94 { | 95 { |
95 SkDiscardableMemoryPool pool(defLimit); | 96 SkAutoTUnref<SkDiscardableMemoryPool> pool( |
96 gPool = &pool; | 97 SkDiscardableMemoryPool::Create(defLimit, NULL)); |
| 98 gPool = pool.get(); |
97 SkScaledImageCache cache(pool_factory); | 99 SkScaledImageCache cache(pool_factory); |
98 test_cache(reporter, cache, true); | 100 test_cache(reporter, cache, true); |
99 } | 101 } |
100 { | 102 { |
101 SkScaledImageCache cache(SkDiscardableMemory::Create); | 103 SkScaledImageCache cache(SkDiscardableMemory::Create); |
102 test_cache(reporter, cache, false); | 104 test_cache(reporter, cache, false); |
103 } | 105 } |
104 } | 106 } |
105 | 107 |
106 DEF_TEST(ImageCache_doubleAdd, r) { | 108 DEF_TEST(ImageCache_doubleAdd, r) { |
(...skipping 15 matching lines...) Expand all Loading... |
122 cache.unlock(id1); | 124 cache.unlock(id1); |
123 cache.unlock(id2); | 125 cache.unlock(id2); |
124 | 126 |
125 SkBitmap tmp; | 127 SkBitmap tmp; |
126 // Lookup should return the value that was added last. | 128 // Lookup should return the value that was added last. |
127 SkScaledImageCache::ID* id = cache.findAndLock(original, 0.5f, 0.5f, &tmp); | 129 SkScaledImageCache::ID* id = cache.findAndLock(original, 0.5f, 0.5f, &tmp); |
128 REPORTER_ASSERT(r, NULL != id); | 130 REPORTER_ASSERT(r, NULL != id); |
129 REPORTER_ASSERT(r, tmp.getGenerationID() == scaled2.getGenerationID()); | 131 REPORTER_ASSERT(r, tmp.getGenerationID() == scaled2.getGenerationID()); |
130 cache.unlock(id); | 132 cache.unlock(id); |
131 } | 133 } |
OLD | NEW |