Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: src/gpu/GrResourceCache2.cpp

Issue 815833004: Add a simpler key type for scratch resource keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrResourceCache2.cpp
diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp
index 39181554d23705bc863e5f0ad4c3d0b1dc88dd77..21d99e96833419db13aab6c4b749ad6146182513 100644
--- a/src/gpu/GrResourceCache2.cpp
+++ b/src/gpu/GrResourceCache2.cpp
@@ -10,6 +10,7 @@
#include "GrResourceCache2.h"
#include "GrGpuResource.h"
+#include "SkChecksum.h"
#include "SkGr.h"
#include "SkMessageBus.h"
@@ -17,32 +18,26 @@ DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
//////////////////////////////////////////////////////////////////////////////
-GrResourceKey& GrResourceKey::NullScratchKey() {
- static const GrCacheID::Key kBogusKey = { { {0} } };
- static GrCacheID kBogusID(ScratchDomain(), kBogusKey);
- static GrResourceKey kNullScratchKey(kBogusID, NoneResourceType(), 0);
- return kNullScratchKey;
-}
+GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() {
+ static int32_t gType = kInvalidResourceType + 1;
-GrResourceKey::ResourceType GrResourceKey::NoneResourceType() {
- static const ResourceType gNoneResourceType = GenerateResourceType();
- return gNoneResourceType;
-}
+ int32_t type = sk_atomic_inc(&gType);
robertphillips 2014/12/30 18:19:52 yoda-style ?
bsalomon 2014/12/30 18:37:09 Done.
+ if (type == kInvalidResourceType) {
+ SkFAIL("Too many Resource Types");
+ }
-GrCacheID::Domain GrResourceKey::ScratchDomain() {
- static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
- return gDomain;
+ return static_cast<ResourceType>(type);
}
-GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
- static int32_t gNextType = 0;
- int32_t type = sk_atomic_inc(&gNextType);
- if (type >= (1 << 8 * sizeof(ResourceType))) {
- SkFAIL("Too many Resource Types");
+void GrScratchKey::Builder::finish() {
+ if (NULL == fKey) {
+ return;
}
-
- return static_cast<ResourceType>(type);
+ GR_STATIC_ASSERT(0 == kHashIdx);
+ fKey->fKey[kHashIdx] =
+ SkChecksum::Compute(&fKey->fKey[kHashIdx + 1], fKey->size() - sizeof(uint32_t));
+ fKey = NULL;
}
//////////////////////////////////////////////////////////////////////////////
@@ -111,7 +106,7 @@ void GrResourceCache2::insertResource(GrGpuResource* resource) {
fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes);
#endif
}
- if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
+ if (resource->cacheAccess().getScratchKey().isValid()) {
SkASSERT(!resource->cacheAccess().isWrapped());
fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource);
}
@@ -131,7 +126,7 @@ void GrResourceCache2::removeResource(GrGpuResource* resource) {
}
fResources.remove(resource);
- if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
+ if (resource->cacheAccess().getScratchKey().isValid()) {
fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource);
}
if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey()) {
@@ -190,10 +185,10 @@ private:
bool fRejectPendingIO;
};
-GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey,
+GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrScratchKey& scratchKey,
uint32_t flags) {
SkASSERT(!fPurging);
- SkASSERT(scratchKey.isScratch());
+ SkASSERT(scratchKey.isValid());
GrGpuResource* resource;
if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFlag)) {
@@ -228,7 +223,6 @@ bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) {
SkASSERT(resource);
SkASSERT(this->isInCache(resource));
SkASSERT(resource->cacheAccess().getContentKey());
- SkASSERT(!resource->cacheAccess().getContentKey()->isScratch());
GrGpuResource* res = fContentHash.find(*resource->cacheAccess().getContentKey());
if (NULL != res) {
@@ -414,7 +408,7 @@ void GrResourceCache2::validate() const {
++scratch;
SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchKey()));
SkASSERT(!resource->cacheAccess().isWrapped());
- } else if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
+ } else if (resource->cacheAccess().getScratchKey().isValid()) {
SkASSERT(NULL != resource->cacheAccess().getContentKey());
++couldBeScratch;
SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchKey()));

Powered by Google App Engine
This is Rietveld 408576698