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

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

Issue 1302663003: Sample for GPU memory dumping using new SkTraceMemoryDump. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 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/GrContext.cpp ('k') | src/gpu/GrResourceCache.h » ('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 #include "GrGpuResource.h" 9 #include "GrGpuResource.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrResourceCache.h" 11 #include "GrResourceCache.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrGpuResourcePriv.h" 13 #include "GrGpuResourcePriv.h"
14 #include "SkTraceMemoryDump.h"
14 15
15 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { 16 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
16 SkASSERT(gpu); 17 SkASSERT(gpu);
17 SkASSERT(gpu->getContext()); 18 SkASSERT(gpu->getContext());
18 SkASSERT(gpu->getContext()->getResourceCache()); 19 SkASSERT(gpu->getContext()->getResourceCache());
19 return gpu->getContext()->getResourceCache(); 20 return gpu->getContext()->getResourceCache();
20 } 21 }
21 22
22 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) 23 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle)
23 : fGpu(gpu) 24 : fGpu(gpu)
24 , fGpuMemorySize(kInvalidGpuMemorySize) 25 , fGpuMemorySize(kInvalidGpuMemorySize)
25 , fLifeCycle(lifeCycle) 26 , fLifeCycle(lifeCycle)
26 , fUniqueID(CreateUniqueID()) { 27 , fUniqueID(CreateUniqueID()) {
27 SkDEBUGCODE(fCacheArrayIndex = -1); 28 SkDEBUGCODE(fCacheArrayIndex = -1);
28 } 29 }
29 30
30 void GrGpuResource::registerWithCache() { 31 void GrGpuResource::registerWithCache() {
31 get_resource_cache(fGpu)->resourceAccess().insertResource(this); 32 get_resource_cache(fGpu)->resourceAccess().insertResource(this);
32 } 33 }
33 34
34 GrGpuResource::~GrGpuResource() { 35 GrGpuResource::~GrGpuResource() {
35 // The cache should have released or destroyed this resource. 36 // The cache should have released or destroyed this resource.
36 SkASSERT(this->wasDestroyed()); 37 SkASSERT(this->wasDestroyed());
37 } 38 }
38 39
39 void GrGpuResource::release() { 40 void GrGpuResource::release() {
40 SkASSERT(fGpu); 41 SkASSERT(fGpu);
41 this->onRelease(); 42 this->onRelease();
42 get_resource_cache(fGpu)->resourceAccess().removeResource(this); 43 get_resource_cache(fGpu)->resourceAccess().removeResource(this);
43 fGpu = NULL; 44 fGpu = NULL;
44 fGpuMemorySize = 0; 45 fGpuMemorySize = 0;
45 } 46 }
46 47
47 void GrGpuResource::abandon() { 48 void GrGpuResource::abandon() {
48 SkASSERT(fGpu); 49 SkASSERT(fGpu);
49 this->onAbandon(); 50 this->onAbandon();
50 get_resource_cache(fGpu)->resourceAccess().removeResource(this); 51 get_resource_cache(fGpu)->resourceAccess().removeResource(this);
51 fGpu = NULL; 52 fGpu = NULL;
52 fGpuMemorySize = 0; 53 fGpuMemorySize = 0;
53 } 54 }
54 55
56 void GrGpuResource::onMemoryDump(SkTraceMemoryDump* traceMemoryDump) const {
57 SkString dump_name("skia/gpu_resources/resource_");
58 dump_name.appendS32(getUniqueID());
59 traceMemoryDump->DumpScalarValue(dump_name, "size", "bytes", onGpuMemorySize() );
60 }
61
55 const SkData* GrGpuResource::setCustomData(const SkData* data) { 62 const SkData* GrGpuResource::setCustomData(const SkData* data) {
56 SkSafeRef(data); 63 SkSafeRef(data);
57 fData.reset(data); 64 fData.reset(data);
58 return data; 65 return data;
59 } 66 }
60 67
61 const GrContext* GrGpuResource::getContext() const { 68 const GrContext* GrGpuResource::getContext() const {
62 if (fGpu) { 69 if (fGpu) {
63 return fGpu->getContext(); 70 return fGpu->getContext();
64 } else { 71 } else {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 180 }
174 181
175 uint32_t GrGpuResource::CreateUniqueID() { 182 uint32_t GrGpuResource::CreateUniqueID() {
176 static int32_t gUniqueID = SK_InvalidUniqueID; 183 static int32_t gUniqueID = SK_InvalidUniqueID;
177 uint32_t id; 184 uint32_t id;
178 do { 185 do {
179 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 186 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
180 } while (id == SK_InvalidUniqueID); 187 } while (id == SK_InvalidUniqueID);
181 return id; 188 return id;
182 } 189 }
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698