| OLD | NEW |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (!this->caps()->npotTextureTileSupport() && | 80 if (!this->caps()->npotTextureTileSupport() && |
| 81 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | 81 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
| 82 return NULL; | 82 return NULL; |
| 83 } | 83 } |
| 84 | 84 |
| 85 this->handleDirtyContext(); | 85 this->handleDirtyContext(); |
| 86 tex = this->onCreateCompressedTexture(desc, srcData); | 86 tex = this->onCreateCompressedTexture(desc, srcData); |
| 87 } else { | 87 } else { |
| 88 this->handleDirtyContext(); | 88 this->handleDirtyContext(); |
| 89 tex = this->onCreateTexture(desc, srcData, rowBytes); | 89 tex = this->onCreateTexture(desc, srcData, rowBytes); |
| 90 if (NULL != tex && | 90 if (tex && |
| 91 (kRenderTarget_GrTextureFlagBit & desc.fFlags) && | 91 (kRenderTarget_GrTextureFlagBit & desc.fFlags) && |
| 92 !(kNoStencil_GrTextureFlagBit & desc.fFlags)) { | 92 !(kNoStencil_GrTextureFlagBit & desc.fFlags)) { |
| 93 SkASSERT(NULL != tex->asRenderTarget()); | 93 SkASSERT(tex->asRenderTarget()); |
| 94 // TODO: defer this and attach dynamically | 94 // TODO: defer this and attach dynamically |
| 95 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget()))
{ | 95 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget()))
{ |
| 96 tex->unref(); | 96 tex->unref(); |
| 97 return NULL; | 97 return NULL; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return tex; | 101 return tex; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { | 104 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
| 105 SkASSERT(NULL == rt->getStencilBuffer()); | 105 SkASSERT(NULL == rt->getStencilBuffer()); |
| 106 GrStencilBuffer* sb = | 106 GrStencilBuffer* sb = |
| 107 this->getContext()->findStencilBuffer(rt->width(), | 107 this->getContext()->findStencilBuffer(rt->width(), |
| 108 rt->height(), | 108 rt->height(), |
| 109 rt->numSamples()); | 109 rt->numSamples()); |
| 110 if (NULL != sb) { | 110 if (sb) { |
| 111 rt->setStencilBuffer(sb); | 111 rt->setStencilBuffer(sb); |
| 112 bool attached = this->attachStencilBufferToRenderTarget(sb, rt); | 112 bool attached = this->attachStencilBufferToRenderTarget(sb, rt); |
| 113 if (!attached) { | 113 if (!attached) { |
| 114 rt->setStencilBuffer(NULL); | 114 rt->setStencilBuffer(NULL); |
| 115 } | 115 } |
| 116 return attached; | 116 return attached; |
| 117 } | 117 } |
| 118 if (this->createStencilBufferForRenderTarget(rt, | 118 if (this->createStencilBufferForRenderTarget(rt, |
| 119 rt->width(), rt->height())) { | 119 rt->width(), rt->height())) { |
| 120 // Right now we're clearing the stencil buffer here after it is | 120 // Right now we're clearing the stencil buffer here after it is |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { | 135 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
| 136 this->handleDirtyContext(); | 136 this->handleDirtyContext(); |
| 137 GrTexture* tex = this->onWrapBackendTexture(desc); | 137 GrTexture* tex = this->onWrapBackendTexture(desc); |
| 138 if (NULL == tex) { | 138 if (NULL == tex) { |
| 139 return NULL; | 139 return NULL; |
| 140 } | 140 } |
| 141 // TODO: defer this and attach dynamically | 141 // TODO: defer this and attach dynamically |
| 142 GrRenderTarget* tgt = tex->asRenderTarget(); | 142 GrRenderTarget* tgt = tex->asRenderTarget(); |
| 143 if (NULL != tgt && | 143 if (tgt && |
| 144 !this->attachStencilBufferToRenderTarget(tgt)) { | 144 !this->attachStencilBufferToRenderTarget(tgt)) { |
| 145 tex->unref(); | 145 tex->unref(); |
| 146 return NULL; | 146 return NULL; |
| 147 } else { | 147 } else { |
| 148 return tex; | 148 return tex; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc) { | 152 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc) { |
| 153 this->handleDirtyContext(); | 153 this->handleDirtyContext(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 indices[6 * i + 5] = 4 * i + 3; | 267 indices[6 * i + 5] = 4 * i + 3; |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { | 271 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
| 272 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { | 272 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { |
| 273 SkSafeUnref(fQuadIndexBuffer); | 273 SkSafeUnref(fQuadIndexBuffer); |
| 274 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; | 274 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; |
| 275 GrGpu* me = const_cast<GrGpu*>(this); | 275 GrGpu* me = const_cast<GrGpu*>(this); |
| 276 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); | 276 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); |
| 277 if (NULL != fQuadIndexBuffer) { | 277 if (fQuadIndexBuffer) { |
| 278 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map(); | 278 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map(); |
| 279 if (NULL != indices) { | 279 if (indices) { |
| 280 fill_indices(indices, MAX_QUADS); | 280 fill_indices(indices, MAX_QUADS); |
| 281 fQuadIndexBuffer->unmap(); | 281 fQuadIndexBuffer->unmap(); |
| 282 } else { | 282 } else { |
| 283 indices = (uint16_t*)sk_malloc_throw(SIZE); | 283 indices = (uint16_t*)sk_malloc_throw(SIZE); |
| 284 fill_indices(indices, MAX_QUADS); | 284 fill_indices(indices, MAX_QUADS); |
| 285 if (!fQuadIndexBuffer->updateData(indices, SIZE)) { | 285 if (!fQuadIndexBuffer->updateData(indices, SIZE)) { |
| 286 fQuadIndexBuffer->unref(); | 286 fQuadIndexBuffer->unref(); |
| 287 fQuadIndexBuffer = NULL; | 287 fQuadIndexBuffer = NULL; |
| 288 SkFAIL("Can't get indices into buffer!"); | 288 SkFAIL("Can't get indices into buffer!"); |
| 289 } | 289 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 386 |
| 387 GrDrawState::AutoRestoreEffects are; | 387 GrDrawState::AutoRestoreEffects are; |
| 388 if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, &are, NULL))
{ | 388 if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, &are, NULL))
{ |
| 389 return; | 389 return; |
| 390 } | 390 } |
| 391 | 391 |
| 392 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran
sformsType, fill); | 392 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran
sformsType, fill); |
| 393 } | 393 } |
| 394 | 394 |
| 395 void GrGpu::finalizeReservedVertices() { | 395 void GrGpu::finalizeReservedVertices() { |
| 396 SkASSERT(NULL != fVertexPool); | 396 SkASSERT(fVertexPool); |
| 397 fVertexPool->unmap(); | 397 fVertexPool->unmap(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void GrGpu::finalizeReservedIndices() { | 400 void GrGpu::finalizeReservedIndices() { |
| 401 SkASSERT(NULL != fIndexPool); | 401 SkASSERT(fIndexPool); |
| 402 fIndexPool->unmap(); | 402 fIndexPool->unmap(); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void GrGpu::prepareVertexPool() { | 405 void GrGpu::prepareVertexPool() { |
| 406 if (NULL == fVertexPool) { | 406 if (NULL == fVertexPool) { |
| 407 SkASSERT(0 == fVertexPoolUseCnt); | 407 SkASSERT(0 == fVertexPoolUseCnt); |
| 408 fVertexPool = SkNEW_ARGS(GrVertexBufferAllocPool, (this, true, | 408 fVertexPool = SkNEW_ARGS(GrVertexBufferAllocPool, (this, true, |
| 409 VERTEX_POOL_VB_SIZE, | 409 VERTEX_POOL_VB_SIZE, |
| 410 VERTEX_POOL_VB_COUNT)); | 410 VERTEX_POOL_VB_COUNT)); |
| 411 fVertexPool->releaseGpuRef(); | 411 fVertexPool->releaseGpuRef(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 427 fIndexPool->reset(); | 427 fIndexPool->reset(); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 bool GrGpu::onReserveVertexSpace(size_t vertexSize, | 431 bool GrGpu::onReserveVertexSpace(size_t vertexSize, |
| 432 int vertexCount, | 432 int vertexCount, |
| 433 void** vertices) { | 433 void** vertices) { |
| 434 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); | 434 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 435 | 435 |
| 436 SkASSERT(vertexCount > 0); | 436 SkASSERT(vertexCount > 0); |
| 437 SkASSERT(NULL != vertices); | 437 SkASSERT(vertices); |
| 438 | 438 |
| 439 this->prepareVertexPool(); | 439 this->prepareVertexPool(); |
| 440 | 440 |
| 441 *vertices = fVertexPool->makeSpace(vertexSize, | 441 *vertices = fVertexPool->makeSpace(vertexSize, |
| 442 vertexCount, | 442 vertexCount, |
| 443 &geomPoolState.fPoolVertexBuffer, | 443 &geomPoolState.fPoolVertexBuffer, |
| 444 &geomPoolState.fPoolStartVertex); | 444 &geomPoolState.fPoolStartVertex); |
| 445 if (NULL == *vertices) { | 445 if (NULL == *vertices) { |
| 446 return false; | 446 return false; |
| 447 } | 447 } |
| 448 ++fVertexPoolUseCnt; | 448 ++fVertexPoolUseCnt; |
| 449 return true; | 449 return true; |
| 450 } | 450 } |
| 451 | 451 |
| 452 bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) { | 452 bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) { |
| 453 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); | 453 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 454 | 454 |
| 455 SkASSERT(indexCount > 0); | 455 SkASSERT(indexCount > 0); |
| 456 SkASSERT(NULL != indices); | 456 SkASSERT(indices); |
| 457 | 457 |
| 458 this->prepareIndexPool(); | 458 this->prepareIndexPool(); |
| 459 | 459 |
| 460 *indices = fIndexPool->makeSpace(indexCount, | 460 *indices = fIndexPool->makeSpace(indexCount, |
| 461 &geomPoolState.fPoolIndexBuffer, | 461 &geomPoolState.fPoolIndexBuffer, |
| 462 &geomPoolState.fPoolStartIndex); | 462 &geomPoolState.fPoolStartIndex); |
| 463 if (NULL == *indices) { | 463 if (NULL == *indices) { |
| 464 return false; | 464 return false; |
| 465 } | 465 } |
| 466 ++fIndexPoolUseCnt; | 466 ++fIndexPoolUseCnt; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 522 } |
| 523 | 523 |
| 524 void GrGpu::releaseIndexArray() { | 524 void GrGpu::releaseIndexArray() { |
| 525 // if index source was array, we stowed data in the pool | 525 // if index source was array, we stowed data in the pool |
| 526 const GeometrySrcState& geoSrc = this->getGeomSrc(); | 526 const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 527 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); | 527 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); |
| 528 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); | 528 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 529 fIndexPool->putBack(bytes); | 529 fIndexPool->putBack(bytes); |
| 530 --fIndexPoolUseCnt; | 530 --fIndexPoolUseCnt; |
| 531 } | 531 } |
| OLD | NEW |