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

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

Issue 481443002: Add GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove removeHead 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 fGeomPoolStateStack.push_back(); 42 fGeomPoolStateStack.push_back();
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 53
56 void GrGpu::abandonResources() { 54 void GrGpu::contextAbandonded() {}
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);
66 delete fVertexPool;
67 fVertexPool = NULL;
68 delete fIndexPool;
69 fIndexPool = NULL;
70 }
71
72 void GrGpu::releaseResources() {
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 55
109 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
110 57
111 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc, 58 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
112 const void* srcData, size_t rowBytes) { 59 const void* srcData, size_t rowBytes) {
113 if (!this->caps()->isConfigTexturable(desc.fConfig)) { 60 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
114 return NULL; 61 return NULL;
115 } 62 }
116 63
117 if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) && 64 if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) &&
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 indices[6 * i + 0] = 4 * i + 0; 259 indices[6 * i + 0] = 4 * i + 0;
313 indices[6 * i + 1] = 4 * i + 1; 260 indices[6 * i + 1] = 4 * i + 1;
314 indices[6 * i + 2] = 4 * i + 2; 261 indices[6 * i + 2] = 4 * i + 2;
315 indices[6 * i + 3] = 4 * i + 0; 262 indices[6 * i + 3] = 4 * i + 0;
316 indices[6 * i + 4] = 4 * i + 2; 263 indices[6 * i + 4] = 4 * i + 2;
317 indices[6 * i + 5] = 4 * i + 3; 264 indices[6 * i + 5] = 4 * i + 3;
318 } 265 }
319 } 266 }
320 267
321 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { 268 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
322 if (NULL == fQuadIndexBuffer) { 269 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
270 SkSafeUnref(fQuadIndexBuffer);
323 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; 271 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
324 GrGpu* me = const_cast<GrGpu*>(this); 272 GrGpu* me = const_cast<GrGpu*>(this);
325 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); 273 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
326 if (NULL != fQuadIndexBuffer) { 274 if (NULL != fQuadIndexBuffer) {
327 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map(); 275 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map();
328 if (NULL != indices) { 276 if (NULL != indices) {
329 fill_indices(indices, MAX_QUADS); 277 fill_indices(indices, MAX_QUADS);
330 fQuadIndexBuffer->unmap(); 278 fQuadIndexBuffer->unmap();
331 } else { 279 } else {
332 indices = (uint16_t*)sk_malloc_throw(SIZE); 280 indices = (uint16_t*)sk_malloc_throw(SIZE);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 } 519 }
572 520
573 void GrGpu::releaseIndexArray() { 521 void GrGpu::releaseIndexArray() {
574 // if index source was array, we stowed data in the pool 522 // if index source was array, we stowed data in the pool
575 const GeometrySrcState& geoSrc = this->getGeomSrc(); 523 const GeometrySrcState& geoSrc = this->getGeomSrc();
576 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); 524 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc);
577 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); 525 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
578 fIndexPool->putBack(bytes); 526 fIndexPool->putBack(bytes);
579 --fIndexPoolUseCnt; 527 --fIndexPoolUseCnt;
580 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698