• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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 
~GrResourceCache2()13 GrResourceCache2::~GrResourceCache2() {
14     this->releaseAll();
15 }
16 
insertResource(GrGpuResource * resource)17 void GrResourceCache2::insertResource(GrGpuResource* resource) {
18     SkASSERT(resource);
19     SkASSERT(!resource->wasDestroyed());
20     SkASSERT(!this->isInCache(resource));
21     fResources.addToHead(resource);
22     ++fCount;
23     if (!resource->getScratchKey().isNullScratch()) {
24         fScratchMap.insert(resource->getScratchKey(), resource);
25     }
26 }
27 
removeResource(GrGpuResource * 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);
33     }
34     --fCount;
35 }
36 
abandonAll()37 void 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     }
44     SkASSERT(!fScratchMap.count());
45     SkASSERT(!fCount);
46 }
47 
releaseAll()48 void 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     }
55     SkASSERT(!fScratchMap.count());
56     SkASSERT(!fCount);
57 }
58