| 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" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 static void* gGlobalAddress; | 13 static void* gGlobalAddress; |
| 14 struct TestingKey : public SkResourceCache::Key { | 14 struct TestingKey : public SkResourceCache::Key { |
| 15 void* fPtr; | |
| 16 intptr_t fValue; | 15 intptr_t fValue; |
| 17 | 16 |
| 18 TestingKey(intptr_t value) : fPtr(&gGlobalAddress), fValue(value) { | 17 TestingKey(intptr_t value) : fValue(value) { |
| 19 this->init(sizeof(fPtr) + sizeof(fValue)); | 18 this->init(&gGlobalAddress, sizeof(fValue)); |
| 20 } | 19 } |
| 21 }; | 20 }; |
| 22 struct TestingRec : public SkResourceCache::Rec { | 21 struct TestingRec : public SkResourceCache::Rec { |
| 23 TestingRec(const TestingKey& key, uint32_t value) : fKey(key), fValue(value)
{} | 22 TestingRec(const TestingKey& key, uint32_t value) : fKey(key), fValue(value)
{} |
| 24 | 23 |
| 25 TestingKey fKey; | 24 TestingKey fKey; |
| 26 intptr_t fValue; | 25 intptr_t fValue; |
| 27 | 26 |
| 28 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } | 27 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } |
| 29 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(
fValue); } | 28 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(
fValue); } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 TestingKey key(1); | 106 TestingKey key(1); |
| 108 | 107 |
| 109 cache.add(SkNEW_ARGS(TestingRec, (key, 2))); | 108 cache.add(SkNEW_ARGS(TestingRec, (key, 2))); |
| 110 cache.add(SkNEW_ARGS(TestingRec, (key, 3))); | 109 cache.add(SkNEW_ARGS(TestingRec, (key, 3))); |
| 111 | 110 |
| 112 // Lookup can return either value. | 111 // Lookup can return either value. |
| 113 intptr_t value = -1; | 112 intptr_t value = -1; |
| 114 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); | 113 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); |
| 115 REPORTER_ASSERT(r, 2 == value || 3 == value); | 114 REPORTER_ASSERT(r, 2 == value || 3 == value); |
| 116 } | 115 } |
| OLD | NEW |