aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrResourceAllocator.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-07-20 15:09:23 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-21 11:37:23 +0000
commit6ec9a4ffe43910551d15ddc95150472aabbc8b74 (patch)
treeeb7322a0bda17d800ec0df84f9df9b560ef52aea /src/gpu/GrResourceAllocator.cpp
parent8b8b2244c3056cb4ee4f2ea30ff7876f0b4d2b99 (diff)
Add initial version of GrResourceAllocator's free pool
Change-Id: Ibd60303ffb1d3ea814dad0cee3a521f94da63ca8 Reviewed-on: https://skia-review.googlesource.com/24262 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@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) {