3 * Copyright 2014 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #include "GrResourceCache2.h"
11 #include "GrGpuResource.h"
13 GrResourceCache2::~GrResourceCache2() {
17 void GrResourceCache2::insertResource(GrGpuResource* resource) {
19 SkASSERT(!resource->wasDestroyed());
20 SkASSERT(!this->isInCache(resource));
21 fResources.addToHead(resource);
23 if (!resource->getScratchKey().isNullScratch()) {
24 fScratchMap.insert(resource->getScratchKey(), resource);
28 void GrResourceCache2::removeResource(GrGpuResource* resource) {
29 SkASSERT(this->isInCache(resource));
30 fResources.remove(resource);
31 if (!resource->getScratchKey().isNullScratch()) {
32 fScratchMap.remove(resource->getScratchKey(), resource);
37 void GrResourceCache2::abandonAll() {
38 while (GrGpuResource* head = fResources.head()) {
39 SkASSERT(!head->wasDestroyed());
41 // abandon should have already removed this from the list.
42 SkASSERT(head != fResources.head());
44 SkASSERT(!fScratchMap.count());
48 void GrResourceCache2::releaseAll() {
49 while (GrGpuResource* head = fResources.head()) {
50 SkASSERT(!head->wasDestroyed());
52 // release should have already removed this from the list.
53 SkASSERT(head != fResources.head());
55 SkASSERT(!fScratchMap.count());