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/GrGpu.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.h ('k') | src/gpu/GrGpuResource.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 2010 Google Inc. 3 * Copyright 2010 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 "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #ifdef SK_DEBUG 43 #ifdef SK_DEBUG
44 GeometryPoolState& poolState = fGeomPoolStateStack.back(); 44 GeometryPoolState& poolState = fGeomPoolStateStack.back();
45 poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; 45 poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
46 poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX; 46 poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
47 poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; 47 poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
48 poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX; 48 poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
49 #endif 49 #endif
50 } 50 }
51 51
52 GrGpu::~GrGpu() { 52 GrGpu::~GrGpu() {
53 this->releaseResources();
54 }
55
56 void GrGpu::abandonResources() {
57
58 fClipMaskManager.releaseResources();
59
60 while (NULL != fObjectList.head()) {
61 fObjectList.head()->abandon();
62 }
63
64 SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
65 SkSafeSetNull(fQuadIndexBuffer); 53 SkSafeSetNull(fQuadIndexBuffer);
66 delete fVertexPool; 54 delete fVertexPool;
67 fVertexPool = NULL; 55 fVertexPool = NULL;
68 delete fIndexPool; 56 delete fIndexPool;
69 fIndexPool = NULL; 57 fIndexPool = NULL;
70 } 58 }
71 59
72 void GrGpu::releaseResources() { 60 void GrGpu::contextAbandonded() {}
73
74 fClipMaskManager.releaseResources();
75
76 while (NULL != fObjectList.head()) {
77 fObjectList.head()->release();
78 }
79
80 SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
81 SkSafeSetNull(fQuadIndexBuffer);
82 delete fVertexPool;
83 fVertexPool = NULL;
84 delete fIndexPool;
85 fIndexPool = NULL;
86 }
87
88 void GrGpu::insertObject(GrGpuResource* object) {
89 SkASSERT(NULL != object);
90 SkASSERT(this == object->getGpu());
91
92 fObjectList.addToHead(object);
93 }
94
95 void GrGpu::removeObject(GrGpuResource* object) {
96 SkASSERT(NULL != object);
97 SkASSERT(this == object->getGpu());
98
99 fObjectList.remove(object);
100 }
101
102
103 void GrGpu::unimpl(const char msg[]) {
104 #ifdef SK_DEBUG
105 GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
106 #endif
107 }
108 61
109 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
110 63
111 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc, 64 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
112 const void* srcData, size_t rowBytes) { 65 const void* srcData, size_t rowBytes) {
113 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 66 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
114 return NULL; 67 return NULL;
115 } 68 }
116 69
117 if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) && 70 if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) &&
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 indices[6 * i + 0] = 4 * i + 0; 264 indices[6 * i + 0] = 4 * i + 0;
312 indices[6 * i + 1] = 4 * i + 1; 265 indices[6 * i + 1] = 4 * i + 1;
313 indices[6 * i + 2] = 4 * i + 2; 266 indices[6 * i + 2] = 4 * i + 2;
314 indices[6 * i + 3] = 4 * i + 0; 267 indices[6 * i + 3] = 4 * i + 0;
315 indices[6 * i + 4] = 4 * i + 2; 268 indices[6 * i + 4] = 4 * i + 2;
316 indices[6 * i + 5] = 4 * i + 3; 269 indices[6 * i + 5] = 4 * i + 3;
317 } 270 }
318 } 271 }
319 272
320 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { 273 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
321 if (NULL == fQuadIndexBuffer) { 274 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
275 SkSafeUnref(fQuadIndexBuffer);
322 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; 276 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
323 GrGpu* me = const_cast<GrGpu*>(this); 277 GrGpu* me = const_cast<GrGpu*>(this);
324 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); 278 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
325 if (NULL != fQuadIndexBuffer) { 279 if (NULL != fQuadIndexBuffer) {
326 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map(); 280 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map();
327 if (NULL != indices) { 281 if (NULL != indices) {
328 fill_indices(indices, MAX_QUADS); 282 fill_indices(indices, MAX_QUADS);
329 fQuadIndexBuffer->unmap(); 283 fQuadIndexBuffer->unmap();
330 } else { 284 } else {
331 indices = (uint16_t*)sk_malloc_throw(SIZE); 285 indices = (uint16_t*)sk_malloc_throw(SIZE);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 524 }
571 525
572 void GrGpu::releaseIndexArray() { 526 void GrGpu::releaseIndexArray() {
573 // if index source was array, we stowed data in the pool 527 // if index source was array, we stowed data in the pool
574 const GeometrySrcState& geoSrc = this->getGeomSrc(); 528 const GeometrySrcState& geoSrc = this->getGeomSrc();
575 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); 529 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc);
576 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); 530 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
577 fIndexPool->putBack(bytes); 531 fIndexPool->putBack(bytes);
578 --fIndexPoolUseCnt; 532 --fIndexPoolUseCnt;
579 } 533 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrGpuResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698