bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 1 | |
| 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 | |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 12 | #include "GrGpuResource.h" |
| 13 | #include "GrResourceKey.h" |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 14 | #include "SkTInternalLList.h" |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 15 | #include "SkTMultiMap.h" |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 16 | |
| 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 | */ |
| 22 | class GrResourceCache2 { |
| 23 | public: |
| 24 | GrResourceCache2() : fCount(0) {}; |
| 25 | ~GrResourceCache2(); |
| 26 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 27 | void insertResource(GrGpuResource*); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 28 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 29 | void removeResource(GrGpuResource*); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 30 | |
| 31 | void abandonAll(); |
| 32 | |
| 33 | void releaseAll(); |
| 34 | |
bsalomon | 000f829 | 2014-10-15 19:04:14 -0700 | [diff] [blame] | 35 | enum { |
| 36 | /** Preferentially returns scratch resources with no pending IO. */ |
| 37 | kPreferNoPendingIO_ScratchFlag = 0x1, |
| 38 | /** Will not return any resources that match but have pending IO. */ |
| 39 | kRequireNoPendingIO_ScratchFlag = 0x2, |
| 40 | }; |
| 41 | GrGpuResource* findAndRefScratchResource(const GrResourceKey& scratchKey, uint32_t flags = 0); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 42 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 43 | private: |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 44 | #ifdef SK_DEBUG |
| 45 | bool isInCache(const GrGpuResource* r) const { |
| 46 | return fResources.isInList(r); |
| 47 | } |
| 48 | #endif |
| 49 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 50 | class AvailableForScratchUse; |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 51 | |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 52 | struct ScratchMapTraits { |
| 53 | static const GrResourceKey& GetKey(const GrGpuResource& r) { |
| 54 | return r.getScratchKey(); |
| 55 | } |
| 56 | |
| 57 | static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } |
| 58 | }; |
| 59 | typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchMap; |
| 60 | |
| 61 | int fCount; |
| 62 | SkTInternalLList<GrGpuResource> fResources; |
| 63 | // This map holds all resources that can be used as scratch resources. |
| 64 | ScratchMap fScratchMap; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |