3 * Copyright 2014 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef GrResourceCache2_DEFINED
10 #define GrResourceCache2_DEFINED
12 #include "GrGpuResource.h"
13 #include "GrResourceKey.h"
14 #include "SkTInternalLList.h"
15 #include "SkTMultiMap.h"
18 * Eventual replacement for GrResourceCache. Currently it simply holds a list
19 * of all GrGpuResource objects for a GrContext. It is used to invalidate all
20 * the resources when necessary.
22 class GrResourceCache2 {
24 GrResourceCache2() : fCount(0) {};
27 void insertResource(GrGpuResource* resource);
29 void removeResource(GrGpuResource* resource);
37 bool isInCache(const GrGpuResource* r) const {
38 return fResources.isInList(r);
43 void removeScratch(const GrGpuResource* resource);
44 struct ScratchMapTraits {
45 static const GrResourceKey& GetKey(const GrGpuResource& r) {
46 return r.getScratchKey();
49 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
51 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchMap;
54 SkTInternalLList<GrGpuResource> fResources;
55 // This map holds all resources that can be used as scratch resources.
56 ScratchMap fScratchMap;