aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-05-08 11:16:39 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-08 15:48:44 +0000
commit0562eb9c6c98f07732ca96a1dd4e986f1ca089b8 (patch)
treeb2df127ae523cc032e8e89d45c62258747c8d43d /src
parentaf6522adc17b06d82ec60afbfd41e9e4c48bfc9e (diff)
Allow wrapped resources to have unique keys
Previously, wrapped resources were never budgeted. Now we explicitly allow wrapped, unbudgeted resources with unique keys. This allows code that wraps (and re-wraps) external resources with a deterministic key to find the same wrapped resource - saving time and ensuring a single wrapped copy, to preserve state on the resource (like texture sampler state). Bug: skia: Change-Id: I1dd7642f1ed8bb6c620029d46203cf5cb6b3c160 Reviewed-on: https://skia-review.googlesource.com/15241 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrGpuResource.cpp7
-rw-r--r--src/gpu/GrGpuResourcePriv.h2
-rw-r--r--src/gpu/GrResourceCache.cpp4
3 files changed, 8 insertions, 5 deletions
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index dcc4e62282..c7df6632b3 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -134,8 +134,11 @@ void GrGpuResource::setUniqueKey(const GrUniqueKey& key) {
SkASSERT(this->internalHasRef());
SkASSERT(key.isValid());
- // Wrapped and uncached resources can never have a unique key.
- if (SkBudgeted::kNo == this->resourcePriv().isBudgeted()) {
+ // Uncached resources can never have a unique key, unless they're wrapped resources. Wrapped
+ // resources are a special case: the unique keys give us a weak ref so that we can reuse the
+ // same resource (rather than re-wrapping). When a wrapped resource is no longer referenced,
+ // it will always be released - it is never converted to a scratch resource.
+ if (SkBudgeted::kNo == this->resourcePriv().isBudgeted() && !this->fRefsWrappedObjects) {
return;
}
diff --git a/src/gpu/GrGpuResourcePriv.h b/src/gpu/GrGpuResourcePriv.h
index 82bf072db4..a1e207d77c 100644
--- a/src/gpu/GrGpuResourcePriv.h
+++ b/src/gpu/GrGpuResourcePriv.h
@@ -45,7 +45,7 @@ public:
*/
SkBudgeted isBudgeted() const {
bool ret = SkBudgeted::kYes == fResource->fBudgeted;
- SkASSERT(ret || !fResource->getUniqueKey().isValid());
+ SkASSERT(ret || !fResource->getUniqueKey().isValid() || fResource->fRefsWrappedObjects);
return SkBudgeted(ret);
}
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 596af6d623..e3373b27f9 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -697,8 +697,8 @@ void GrResourceCache::validate() const {
if (uniqueKey.isValid()) {
++fContent;
SkASSERT(fUniqueHash->find(uniqueKey) == resource);
- SkASSERT(!resource->resourcePriv().refsWrappedObjects());
- SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
+ SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted() ||
+ resource->resourcePriv().refsWrappedObjects());
if (scratchKey.isValid()) {
SkASSERT(!fScratchMap->has(resource, scratchKey));