OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef GrResourceCache2_DEFINED | 9 #ifndef GrResourceCache2_DEFINED |
10 #define GrResourceCache2_DEFINED | 10 #define GrResourceCache2_DEFINED |
11 | 11 |
12 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
13 #include "GrResourceKey.h" | 13 #include "GrResourceKey.h" |
14 #include "SkTInternalLList.h" | 14 #include "SkTInternalLList.h" |
15 #include "SkTMultiMap.h" | 15 #include "SkTMultiMap.h" |
16 | 16 |
17 /** | 17 /** |
18 * Eventual replacement for GrResourceCache. Currently it simply holds a list | 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 | 19 * of all GrGpuResource objects for a GrContext. It is used to invalidate all |
20 * the resources when necessary. | 20 * the resources when necessary. |
21 */ | 21 */ |
22 class GrResourceCache2 { | 22 class GrResourceCache2 { |
23 public: | 23 public: |
24 GrResourceCache2() : fCount(0) {}; | 24 GrResourceCache2() : fCount(0) {}; |
25 ~GrResourceCache2(); | 25 ~GrResourceCache2(); |
26 | 26 |
27 void insertResource(GrGpuResource* resource); | 27 void insertResource(GrGpuResource*); |
28 | 28 |
29 void removeResource(GrGpuResource* resource); | 29 void removeResource(GrGpuResource*); |
30 | 30 |
31 void abandonAll(); | 31 void abandonAll(); |
32 | 32 |
33 void releaseAll(); | 33 void releaseAll(); |
34 | 34 |
| 35 GrGpuResource* findAndRefScratchResource(const GrResourceKey& scratchKey, |
| 36 bool calledDuringFlush); |
| 37 |
35 private: | 38 private: |
36 #ifdef SK_DEBUG | 39 #ifdef SK_DEBUG |
37 bool isInCache(const GrGpuResource* r) const { | 40 bool isInCache(const GrGpuResource* r) const { |
38 return fResources.isInList(r); | 41 return fResources.isInList(r); |
39 } | 42 } |
40 #endif | 43 #endif |
41 | 44 |
| 45 class AvailableForScratchUse; |
42 | 46 |
43 void removeScratch(const GrGpuResource* resource); | |
44 struct ScratchMapTraits { | 47 struct ScratchMapTraits { |
45 static const GrResourceKey& GetKey(const GrGpuResource& r) { | 48 static const GrResourceKey& GetKey(const GrGpuResource& r) { |
46 return r.getScratchKey(); | 49 return r.getScratchKey(); |
47 } | 50 } |
48 | 51 |
49 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } | 52 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } |
50 }; | 53 }; |
51 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchM
ap; | 54 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchM
ap; |
52 | 55 |
53 int fCount; | 56 int fCount; |
54 SkTInternalLList<GrGpuResource> fResources; | 57 SkTInternalLList<GrGpuResource> fResources; |
55 // This map holds all resources that can be used as scratch resources. | 58 // This map holds all resources that can be used as scratch resources. |
56 ScratchMap fScratchMap; | 59 ScratchMap fScratchMap; |
57 }; | 60 }; |
58 | 61 |
59 #endif | 62 #endif |
OLD | NEW |