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

Side by Side Diff: tests/ImageCacheTest.cpp

Issue 1271033002: private iterator to visit all resource cache entries (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add iter for fontcache Created 5 years, 4 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
« src/core/SkGlyphCache.cpp ('K') | « src/lazy/SkDiscardablePixelRef.h ('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 "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 intptr_t fValue; 15 intptr_t fValue;
16 16
17 TestingKey(intptr_t value, uint64_t sharedID = 0) : fValue(value) { 17 TestingKey(intptr_t value, uint64_t sharedID = 0) : fValue(value) {
18 this->init(&gGlobalAddress, sharedID, sizeof(fValue)); 18 this->init(&gGlobalAddress, sharedID, sizeof(fValue));
19 } 19 }
20 }; 20 };
21 struct TestingRec : public SkResourceCache::Rec { 21 struct TestingRec : public SkResourceCache::Rec {
22 TestingRec(const TestingKey& key, uint32_t value) : fKey(key), fValue(value) {} 22 TestingRec(const TestingKey& key, uint32_t value) : fKey(key), fValue(value) {}
23 23
24 TestingKey fKey; 24 TestingKey fKey;
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"; }
30 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur n NULL; }
29 31
30 static bool Visitor(const SkResourceCache::Rec& baseRec, void* context) { 32 static bool Visitor(const SkResourceCache::Rec& baseRec, void* context) {
31 const TestingRec& rec = static_cast<const TestingRec&>(baseRec); 33 const TestingRec& rec = static_cast<const TestingRec&>(baseRec);
32 intptr_t* result = (intptr_t*)context; 34 intptr_t* result = (intptr_t*)context;
33 35
34 *result = rec.fValue; 36 *result = rec.fValue;
35 return true; 37 return true;
36 } 38 }
37 }; 39 };
38 } 40 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 TestingKey key(1); 144 TestingKey key(1);
143 145
144 cache.add(SkNEW_ARGS(TestingRec, (key, 2))); 146 cache.add(SkNEW_ARGS(TestingRec, (key, 2)));
145 cache.add(SkNEW_ARGS(TestingRec, (key, 3))); 147 cache.add(SkNEW_ARGS(TestingRec, (key, 3)));
146 148
147 // Lookup can return either value. 149 // Lookup can return either value.
148 intptr_t value = -1; 150 intptr_t value = -1;
149 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); 151 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value));
150 REPORTER_ASSERT(r, 2 == value || 3 == value); 152 REPORTER_ASSERT(r, 2 == value || 3 == value);
151 } 153 }
OLDNEW
« src/core/SkGlyphCache.cpp ('K') | « src/lazy/SkDiscardablePixelRef.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698