robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrCacheID_DEFINED |
| 9 | #define GrCacheID_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
| 12 | |
| 13 | /////////////////////////////////////////////////////////////////////////////// |
| 14 | #define GR_DECLARE_RESOURCE_CACHE_TYPE() \ |
| 15 | static int8_t GetResourceType(); |
| 16 | |
| 17 | #define GR_DEFINE_RESOURCE_CACHE_TYPE(ClassName) \ |
| 18 | int8_t ClassName::GetResourceType() { \ |
| 19 | static int8_t kResourceTypeID = 0; \ |
| 20 | if (0 == kResourceTypeID) { \ |
| 21 | kResourceTypeID = GrCacheID::GetNextResourceType(); \ |
| 22 | } \ |
| 23 | return kResourceTypeID; \ |
| 24 | } |
| 25 | |
| 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | #define GR_DECLARE_RESOURCE_CACHE_DOMAIN(AccessorName) \ |
| 29 | static int8_t AccessorName(); |
| 30 | |
| 31 | #define GR_DEFINE_RESOURCE_CACHE_DOMAIN(ClassName, AccessorName) \ |
| 32 | int8_t ClassName::AccessorName() { \ |
| 33 | static int8_t kDomainID = 0; \ |
| 34 | if (0 == kDomainID) { \ |
| 35 | kDomainID = GrCacheID::GetNextDomain(); \ |
| 36 | } \ |
| 37 | return kDomainID; \ |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * The cache ID adds structure to the IDs used for caching GPU resources. It |
| 42 | * is broken into three portions: |
| 43 | * the public portion - which is filled in by Skia clients |
| 44 | * the private portion - which is used by the cache (domain & type) |
| 45 | * the resource-specific portion - which is filled in by each GrResource- |
| 46 | * derived class. |
| 47 | * |
| 48 | * For the public portion each client of the cache makes up its own |
| 49 | * unique-per-resource identifier (e.g., bitmap genID). A public ID of |
| 50 | * 'kScratch_CacheID' indicates that the resource is a "scratch" resource. |
| 51 | * When used to acquire a resource it indicates the cache user is |
| 52 | * looking for a resource that matches a resource-subclass-specific set of |
| 53 | * “dimensions” such as width, height, buffer size, or pixel config, but not |
| 54 | * for particular resource contents (e.g., texel or vertex values). The public |
| 55 | * IDs are unique within a private ID value but not necessarily across |
| 56 | * private IDs. |
| 57 | * |
| 58 | * The domain portion identifies the cache client while the type field |
| 59 | * indicates the resource type. When the public portion indicates that the |
| 60 | * resource is a scratch resource, the domain field should be kUnrestricted |
| 61 | * so that scratch resources can be recycled across domains. |
| 62 | */ |
| 63 | class GrCacheID { |
| 64 | public: |
| 65 | uint64_t fPublicID; |
| 66 | |
| 67 | uint32_t fResourceSpecific32; |
| 68 | |
| 69 | uint8_t fDomain; |
| 70 | private: |
| 71 | uint8_t fResourceType; |
| 72 | |
| 73 | public: |
| 74 | uint16_t fResourceSpecific16; |
| 75 | |
| 76 | GrCacheID(uint8_t resourceType) |
| 77 | : fPublicID(kDefaultPublicCacheID) |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 78 | , fDomain(GrCacheData::kScratch_ResourceDomain) |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 79 | , fResourceType(resourceType) { |
| 80 | } |
| 81 | |
| 82 | void toRaw(uint32_t v[4]); |
| 83 | |
| 84 | uint8_t getResourceType() const { return fResourceType; } |
| 85 | |
| 86 | /* |
| 87 | * Default value for public portion of GrCacheID |
| 88 | */ |
| 89 | static const uint64_t kDefaultPublicCacheID = 0; |
| 90 | |
| 91 | static const uint8_t kInvalid_ResourceType = 0; |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 92 | |
| 93 | static uint8_t GetNextDomain(); |
| 94 | static uint8_t GetNextResourceType(); |
| 95 | |
| 96 | |
| 97 | }; |
| 98 | |
| 99 | #endif // GrCacheID_DEFINED |