aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrResourceAllocator.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-07-21 11:38:13 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-21 16:18:53 +0000
commit57aa367aa3c5911cd4a21230799b147e44190282 (patch)
tree63b03042079833f226a26f734cc0229010f1429a /src/gpu/GrResourceAllocator.cpp
parent8825a09fc88f46dcec1d547dfbe7457ea224790b (diff)
Add initial version of GrResourceAllocator's free pool (take 2)
TBR=bsalomon@google.com Change-Id: I252d0d75f9ad3911abf97495f67d5178e924dd78 Reviewed-on: https://skia-review.googlesource.com/25560 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrResourceAllocator.cpp')
-rw-r--r--src/gpu/GrResourceAllocator.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index f57e088dd0..76abe1855c 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -75,16 +75,31 @@ void GrResourceAllocator::IntervalList::insertByIncreasingEnd(Interval* intvl) {
// 'surface' can be reused. Add it back to the free pool.
void GrResourceAllocator::freeUpSurface(GrSurface* surface) {
- // TODO: add free pool
+ const GrScratchKey &key = surface->resourcePriv().getScratchKey();
+
+ if (!key.isValid()) {
+ return; // can't do it w/o a valid scratch key
+ }
+
+ // TODO: fix this insertion so we get a more LRU-ish behavior
+ fFreePool.insert(key, surface);
}
// First try to reuse one of the recently allocated/used GrSurfaces in the free pool.
// If we can't find a useable one, create a new one.
// TODO: handle being overbudget
sk_sp<GrSurface> GrResourceAllocator::findSurfaceFor(GrSurfaceProxy* proxy) {
- // TODO: add free pool
+ // First look in the free pool
+ GrScratchKey key;
- // Try to grab one from the resource cache
+ proxy->priv().computeScratchKey(&key);
+
+ GrSurface* surface = fFreePool.find(key);
+ if (surface) {
+ return sk_ref_sp(surface);
+ }
+
+ // Failing that, try to grab a new one from the resource cache
return proxy->priv().createSurface(fResourceProvider);
}
@@ -104,6 +119,12 @@ void GrResourceAllocator::assign() {
while (Interval* cur = fIntvlList.popHead()) {
this->expire(cur->fStart);
+
+ if (cur->fProxy->priv().isInstantiated()) {
+ fActiveIntvls.insertByIncreasingEnd(cur);
+ continue;
+ }
+
// TODO: add over budget handling here?
sk_sp<GrSurface> surface = this->findSurfaceFor(cur->fProxy);
if (surface) {