blob: a5732f786ea48b39bc8f8431c7755609e02e2c8d [file] [log] [blame]
bsalomonc8dc1f72014-08-21 13:02:13 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#include "GrResourceCache2.h"
11#include "GrGpuResource.h"
12
13GrResourceCache2::~GrResourceCache2() {
14 this->releaseAll();
15}
16
17void GrResourceCache2::insertResource(GrGpuResource* resource) {
18 SkASSERT(NULL != resource);
19 SkASSERT(!resource->wasDestroyed());
bsalomon16961262014-08-26 14:01:07 -070020 SkASSERT(!this->isInCache(resource));
bsalomonc8dc1f72014-08-21 13:02:13 -070021 fResources.addToHead(resource);
22 ++fCount;
bsalomon744998e2014-08-28 09:54:34 -070023 if (!resource->getScratchKey().isNullScratch()) {
24 fScratchMap.insert(resource->getScratchKey(), resource);
25 }
bsalomonc8dc1f72014-08-21 13:02:13 -070026}
27
28void GrResourceCache2::removeResource(GrGpuResource* resource) {
bsalomon16961262014-08-26 14:01:07 -070029 SkASSERT(this->isInCache(resource));
bsalomon744998e2014-08-28 09:54:34 -070030 fResources.remove(resource);
31 if (!resource->getScratchKey().isNullScratch()) {
32 fScratchMap.remove(resource->getScratchKey(), resource);
33 }
bsalomonc8dc1f72014-08-21 13:02:13 -070034 --fCount;
35}
36
37void GrResourceCache2::abandonAll() {
38 while (GrGpuResource* head = fResources.head()) {
39 SkASSERT(!head->wasDestroyed());
40 head->abandon();
41 // abandon should have already removed this from the list.
42 SkASSERT(head != fResources.head());
43 }
bsalomon744998e2014-08-28 09:54:34 -070044 SkASSERT(!fScratchMap.count());
bsalomonc8dc1f72014-08-21 13:02:13 -070045 SkASSERT(!fCount);
46}
47
48void GrResourceCache2::releaseAll() {
49 while (GrGpuResource* head = fResources.head()) {
50 SkASSERT(!head->wasDestroyed());
51 head->release();
52 // release should have already removed this from the list.
53 SkASSERT(head != fResources.head());
54 }
bsalomon744998e2014-08-28 09:54:34 -070055 SkASSERT(!fScratchMap.count());
bsalomonc8dc1f72014-08-21 13:02:13 -070056 SkASSERT(!fCount);
57}