| 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 "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 intptr_t fValue; | 25 intptr_t fValue; |
| 26 | 26 |
| 27 const Key& getKey() const override { return fKey; } | 27 const Key& getKey() const override { return fKey; } |
| 28 size_t bytesUsed() const override { return sizeof(fKey) + sizeof(fValue); } | 28 size_t bytesUsed() const override { return sizeof(fKey) + sizeof(fValue); } |
| 29 const char* getCategory() const override { return "test_cache"; } | 29 const char* getCategory() const override { return "test_cache"; } |
| 30 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur
n nullptr; } | 30 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur
n nullptr; } |
| 31 | 31 |
| 32 static bool Visitor(const SkResourceCache::Rec& baseRec, void* context) { | 32 static bool Visitor(const SkResourceCache::Rec& baseRec, void* context) { |
| 33 const TestingRec& rec = static_cast<const TestingRec&>(baseRec); | 33 const TestingRec& rec = static_cast<const TestingRec&>(baseRec); |
| 34 intptr_t* result = (intptr_t*)context; | 34 intptr_t* result = (intptr_t*)context; |
| 35 | 35 |
| 36 *result = rec.fValue; | 36 *result = rec.fValue; |
| 37 return true; | 37 return true; |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 } | 40 } |
| 41 | 41 |
| 42 static const int COUNT = 10; | 42 static const int COUNT = 10; |
| 43 static const int DIM = 256; | 43 static const int DIM = 256; |
| 44 | 44 |
| 45 static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache, boo
l testPurge) { | 45 static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache, boo
l testPurge) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 TestingKey key(1); | 144 TestingKey key(1); |
| 145 | 145 |
| 146 cache.add(new TestingRec(key, 2)); | 146 cache.add(new TestingRec(key, 2)); |
| 147 cache.add(new TestingRec(key, 3)); | 147 cache.add(new TestingRec(key, 3)); |
| 148 | 148 |
| 149 // Lookup can return either value. | 149 // Lookup can return either value. |
| 150 intptr_t value = -1; | 150 intptr_t value = -1; |
| 151 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); | 151 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); |
| 152 REPORTER_ASSERT(r, 2 == value || 3 == value); | 152 REPORTER_ASSERT(r, 2 == value || 3 == value); |
| 153 } | 153 } |
| OLD | NEW |