Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: src/gpu/GrResourceCache2.cpp

Issue 703303003: Add GrGpuResource::CacheAccess (Closed) Base URL: https://skia.googlesource.com/skia.git@nohash
Patch Set: update Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrResourceCache2.h" 10 #include "GrResourceCache2.h"
11 #include "GrGpuResource.h" 11 #include "GrGpuResource.h"
12 12
13 GrResourceCache2::~GrResourceCache2() { 13 GrResourceCache2::~GrResourceCache2() {
14 this->releaseAll(); 14 this->releaseAll();
15 } 15 }
16 16
17 void GrResourceCache2::insertResource(GrGpuResource* resource) { 17 void GrResourceCache2::insertResource(GrGpuResource* resource) {
18 SkASSERT(resource); 18 SkASSERT(resource);
19 SkASSERT(!resource->wasDestroyed()); 19 SkASSERT(!resource->wasDestroyed());
20 SkASSERT(!this->isInCache(resource)); 20 SkASSERT(!this->isInCache(resource));
21 fResources.addToHead(resource); 21 fResources.addToHead(resource);
22 ++fCount; 22 ++fCount;
23 if (!resource->getScratchKey().isNullScratch()) { 23 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
24 // TODO(bsalomon): Make this assertion possible. 24 // TODO(bsalomon): Make this assertion possible.
25 // SkASSERT(!resource->isWrapped()); 25 // SkASSERT(!resource->isWrapped());
26 fScratchMap.insert(resource->getScratchKey(), resource); 26 fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource);
27 } 27 }
28 } 28 }
29 29
30 void GrResourceCache2::removeResource(GrGpuResource* resource) { 30 void GrResourceCache2::removeResource(GrGpuResource* resource) {
31 SkASSERT(this->isInCache(resource)); 31 SkASSERT(this->isInCache(resource));
32 fResources.remove(resource); 32 fResources.remove(resource);
33 if (!resource->getScratchKey().isNullScratch()) { 33 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
34 fScratchMap.remove(resource->getScratchKey(), resource); 34 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource);
35 } 35 }
36 if (const GrResourceKey* contentKey = resource->getContentKey()) { 36 if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey( )) {
37 fContentHash.remove(*contentKey); 37 fContentHash.remove(*contentKey);
38 } 38 }
39 --fCount; 39 --fCount;
40 } 40 }
41 41
42 void GrResourceCache2::abandonAll() { 42 void GrResourceCache2::abandonAll() {
43 while (GrGpuResource* head = fResources.head()) { 43 while (GrGpuResource* head = fResources.head()) {
44 SkASSERT(!head->wasDestroyed()); 44 SkASSERT(!head->wasDestroyed());
45 head->abandon(); 45 head->abandon();
46 // abandon should have already removed this from the list. 46 // abandon should have already removed this from the list.
(...skipping 13 matching lines...) Expand all
60 } 60 }
61 SkASSERT(!fScratchMap.count()); 61 SkASSERT(!fScratchMap.count());
62 SkASSERT(!fCount); 62 SkASSERT(!fCount);
63 } 63 }
64 64
65 class GrResourceCache2::AvailableForScratchUse { 65 class GrResourceCache2::AvailableForScratchUse {
66 public: 66 public:
67 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { } 67 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { }
68 68
69 bool operator()(const GrGpuResource* resource) const { 69 bool operator()(const GrGpuResource* resource) const {
70 if (!resource->reffedOnlyByCache() || !resource->isScratch()) { 70 if (!resource->reffedOnlyByCache() || !resource->cacheAccess().isScratch ()) {
71 return false; 71 return false;
72 } 72 }
73 73
74 return !fRejectPendingIO || !resource->internalHasPendingIO(); 74 return !fRejectPendingIO || !resource->internalHasPendingIO();
75 } 75 }
76 76
77 private: 77 private:
78 bool fRejectPendingIO; 78 bool fRejectPendingIO;
79 }; 79 };
80 80
81 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey, 81 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey,
82 uint32_t flags) { 82 uint32_t flags) {
83 SkASSERT(scratchKey.isScratch()); 83 SkASSERT(scratchKey.isScratch());
84 84
85 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla g)) { 85 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla g)) {
86 GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScrat chUse(true)); 86 GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScrat chUse(true));
87 if (resource) { 87 if (resource) {
88 return SkRef(resource); 88 return SkRef(resource);
89 } else if (flags & kRequireNoPendingIO_ScratchFlag) { 89 } else if (flags & kRequireNoPendingIO_ScratchFlag) {
90 return NULL; 90 return NULL;
91 } 91 }
92 // TODO: fail here when kPrefer is specified, we didn't find a resource without pending io, 92 // TODO: fail here when kPrefer is specified, we didn't find a resource without pending io,
93 // but there is still space in our budget for the resource. 93 // but there is still space in our budget for the resource.
94 } 94 }
95 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(false)) ); 95 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(false)) );
96 } 96 }
97 97
98 #if 0
99 void GrResourceCache2::willRemoveContentKey(const GrGpuResource* resource) {
100 SkASSERT(resource);
101 SkASSERT(resource->getContentKey());
102 SkDEBUGCODE(GrGpuResource* res = fContentHash.find(*resource->getContentKey( )));
103 SkASSERT(res == resource);
104
105 fContentHash.remove(*resource->getContentKey());
106 }
107 #endif
108
109 bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) { 98 bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) {
110 SkASSERT(resource); 99 SkASSERT(resource);
111 SkASSERT(resource->getContentKey()); 100 SkASSERT(resource->cacheAccess().getContentKey());
112 SkASSERT(!resource->getContentKey()->isScratch()); 101 SkASSERT(!resource->cacheAccess().getContentKey()->isScratch());
113 102
114 GrGpuResource* res = fContentHash.find(*resource->getContentKey()); 103 GrGpuResource* res = fContentHash.find(*resource->cacheAccess().getContentKe y());
115 if (NULL != res) { 104 if (NULL != res) {
116 return false; 105 return false;
117 } 106 }
118 107
119 fContentHash.add(resource); 108 fContentHash.add(resource);
120 return true; 109 return true;
121 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698