19static void* gGlobalAddress;
23 TestingKey(intptr_t value, uint64_t sharedID = 0) : fValue(
value) {
24 this->
init(&gGlobalAddress, sharedID,
sizeof(fValue));
28 TestingRec(
const TestingKey&
key, uint32_t value) : fKey(
key), fValue(
value) {}
33 const Key&
getKey()
const override {
return fKey; }
34 size_t bytesUsed()
const override {
return sizeof(fKey) +
sizeof(fValue); }
35 const char*
getCategory()
const override {
return "test_cache"; }
39 const TestingRec& rec =
static_cast<const TestingRec&
>(baseRec);
40 intptr_t*
result = (intptr_t*)context;
49static const int DIM = 256;
52 for (
int i = 0; i <
COUNT; ++i) {
59 cache.add(
new TestingRec(
key, i));
67 for (
int i = 0; i <
COUNT * 100; ++i) {
69 cache.add(
new TestingRec(
key, i));
74 for (
int i = 0; i <
COUNT; ++i) {
76 (void)cache.find(TestingKey(i), TestingRec::Visitor, &
value);
79 cache.setTotalByteLimit(0);
83 for (
int i = 0; i <
COUNT; ++i) {
84 TestingKey
key(i, i & 1);
85 cache.add(
new TestingRec(
key, i));
89 for (
int i = 0; i <
COUNT; ++i) {
90 TestingKey
key(i, i & 1);
98 cache.purgeSharedID(1);
101 for (
int i = 0; i <
COUNT; ++i) {
102 TestingKey
key(i, i & 1);
121 static const size_t defLimit =
DIM *
DIM * 4 *
COUNT + 1024;
149 cache.add(
new TestingRec(
key, 2));
150 cache.add(
new TestingRec(
key, 3));
static void test_cache_purge_shared_id(skiatest::Reporter *reporter, SkResourceCache &cache)
static SkDiscardableMemory * pool_factory(size_t bytes)
static SkDiscardableMemoryPool * gPool
static void test_cache(skiatest::Reporter *reporter, SkResourceCache &cache, bool testPurge)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
static sk_sp< SkDiscardableMemoryPool > Make(size_t size)
virtual SkDiscardableMemory * create(size_t bytes)=0
static SkDiscardableMemory * Create(size_t bytes)
void(* Visitor)(const Rec &, void *context)
virtual const char * getCategory() const =0
virtual SkDiscardableMemory * diagnostic_only_getDiscardable() const
virtual size_t bytesUsed() const =0
virtual const Key & getKey() const =0