blob: e05efd744e44d9e75b157e8c67f9e53648f39fd1 [file] [log] [blame]
bsalomonc8dc1f72014-08-21 13:02:13 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef GrResourceCache2_DEFINED
10#define GrResourceCache2_DEFINED
11
bsalomon744998e2014-08-28 09:54:34 -070012#include "GrGpuResource.h"
13#include "GrResourceKey.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070014#include "SkTInternalLList.h"
bsalomon744998e2014-08-28 09:54:34 -070015#include "SkTMultiMap.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070016
17/**
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.
21 */
22class GrResourceCache2 {
23public:
24 GrResourceCache2() : fCount(0) {};
25 ~GrResourceCache2();
26
27 void insertResource(GrGpuResource* resource);
28
29 void removeResource(GrGpuResource* resource);
30
31 void abandonAll();
32
33 void releaseAll();
34
35private:
bsalomon16961262014-08-26 14:01:07 -070036#ifdef SK_DEBUG
37 bool isInCache(const GrGpuResource* r) const {
38 return fResources.isInList(r);
39 }
40#endif
41
bsalomon744998e2014-08-28 09:54:34 -070042
43 void removeScratch(const GrGpuResource* resource);
44 struct ScratchMapTraits {
45 static const GrResourceKey& GetKey(const GrGpuResource& r) {
46 return r.getScratchKey();
47 }
48
49 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
50 };
51 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchMap;
52
53 int fCount;
54 SkTInternalLList<GrGpuResource> fResources;
55 // This map holds all resources that can be used as scratch resources.
56 ScratchMap fScratchMap;
bsalomonc8dc1f72014-08-21 13:02:13 -070057};
58
59#endif