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

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

Issue 481443002: Add GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix leaks Created 6 years, 4 months 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
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrLayerCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 "GrGpuResource.h" 10 #include "GrGpuResource.h"
11 #include "GrResourceCache2.h"
11 #include "GrGpu.h" 12 #include "GrGpu.h"
12 13
14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) {
15 SkASSERT(NULL != gpu);
16 SkASSERT(NULL != gpu->getContext());
17 SkASSERT(NULL != gpu->getContext()->getResourceCache2());
18 return gpu->getContext()->getResourceCache2();
19 }
20
13 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) 21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
14 : fRefCnt(1) 22 : fGpu(gpu)
23 , fRefCnt(1)
15 , fCacheEntry(NULL) 24 , fCacheEntry(NULL)
16 , fUniqueID(CreateUniqueID()) { 25 , fUniqueID(CreateUniqueID()) {
17 fGpu = gpu;
18 if (isWrapped) { 26 if (isWrapped) {
19 fFlags = kWrapped_FlagBit; 27 fFlags = kWrapped_FlagBit;
20 } else { 28 } else {
21 fFlags = 0; 29 fFlags = 0;
22 } 30 }
23 fGpu->insertObject(this); 31 get_resource_cache2(fGpu)->insertResource(this);
24 } 32 }
25 33
26 GrGpuResource::~GrGpuResource() { 34 GrGpuResource::~GrGpuResource() {
27 SkASSERT(0 == fRefCnt); 35 SkASSERT(0 == fRefCnt);
28 // subclass should have released this. 36 // subclass should have released this.
29 SkASSERT(this->wasDestroyed()); 37 SkASSERT(this->wasDestroyed());
30 } 38 }
31 39
32 void GrGpuResource::release() { 40 void GrGpuResource::release() {
33 if (NULL != fGpu) { 41 if (NULL != fGpu) {
34 this->onRelease(); 42 this->onRelease();
35 fGpu->removeObject(this); 43 get_resource_cache2(fGpu)->removeResource(this);
36 fGpu = NULL; 44 fGpu = NULL;
37 } 45 }
38 } 46 }
39 47
40 void GrGpuResource::abandon() { 48 void GrGpuResource::abandon() {
41 if (NULL != fGpu) { 49 if (NULL != fGpu) {
42 this->onAbandon(); 50 this->onAbandon();
43 fGpu->removeObject(this); 51 get_resource_cache2(fGpu)->removeResource(this);
44 fGpu = NULL; 52 fGpu = NULL;
45 } 53 }
46 } 54 }
47 55
48 const GrContext* GrGpuResource::getContext() const { 56 const GrContext* GrGpuResource::getContext() const {
49 if (NULL != fGpu) { 57 if (NULL != fGpu) {
50 return fGpu->getContext(); 58 return fGpu->getContext();
51 } else { 59 } else {
52 return NULL; 60 return NULL;
53 } 61 }
54 } 62 }
55 63
56 GrContext* GrGpuResource::getContext() { 64 GrContext* GrGpuResource::getContext() {
57 if (NULL != fGpu) { 65 if (NULL != fGpu) {
58 return fGpu->getContext(); 66 return fGpu->getContext();
59 } else { 67 } else {
60 return NULL; 68 return NULL;
61 } 69 }
62 } 70 }
63 71
64 uint32_t GrGpuResource::CreateUniqueID() { 72 uint32_t GrGpuResource::CreateUniqueID() {
65 static int32_t gUniqueID = SK_InvalidUniqueID; 73 static int32_t gUniqueID = SK_InvalidUniqueID;
66 uint32_t id; 74 uint32_t id;
67 do { 75 do {
68 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 76 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
69 } while (id == SK_InvalidUniqueID); 77 } while (id == SK_InvalidUniqueID);
70 return id; 78 return id;
71 } 79 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrLayerCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698