| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
| 10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
| 11 #include "GrGLTextureRenderTarget.h" |
| 11 #include "GrOptDrawState.h" | 12 #include "GrOptDrawState.h" |
| 12 #include "GrSurfacePriv.h" | 13 #include "GrSurfacePriv.h" |
| 13 #include "GrTemplates.h" | 14 #include "GrTemplates.h" |
| 14 #include "GrTexturePriv.h" | 15 #include "GrTexturePriv.h" |
| 15 #include "GrTypes.h" | 16 #include "GrTypes.h" |
| 16 #include "SkStrokeRec.h" | 17 #include "SkStrokeRec.h" |
| 17 #include "SkTemplates.h" | 18 #include "SkTemplates.h" |
| 18 | 19 |
| 19 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 20 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 20 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) | 21 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } else { | 397 } else { |
| 397 surfDesc.fOrigin = desc.fOrigin; | 398 surfDesc.fOrigin = desc.fOrigin; |
| 398 } | 399 } |
| 399 | 400 |
| 400 GrGLTexture* texture = NULL; | 401 GrGLTexture* texture = NULL; |
| 401 if (renderTarget) { | 402 if (renderTarget) { |
| 402 GrGLRenderTarget::IDDesc rtIDDesc; | 403 GrGLRenderTarget::IDDesc rtIDDesc; |
| 403 if (!this->createRenderTargetObjects(surfDesc, idDesc.fTextureID, &rtIDD
esc)) { | 404 if (!this->createRenderTargetObjects(surfDesc, idDesc.fTextureID, &rtIDD
esc)) { |
| 404 return NULL; | 405 return NULL; |
| 405 } | 406 } |
| 406 texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc, rtIDDesc)); | 407 texture = SkNEW_ARGS(GrGLTextureRenderTarget, (this, surfDesc, idDesc, r
tIDDesc)); |
| 407 } else { | 408 } else { |
| 408 texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc)); | 409 texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc)); |
| 409 } | 410 } |
| 410 if (NULL == texture) { | 411 if (NULL == texture) { |
| 411 return NULL; | 412 return NULL; |
| 412 } | 413 } |
| 413 | 414 |
| 414 return texture; | 415 return texture; |
| 415 } | 416 } |
| 416 | 417 |
| 417 GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc) { | 418 GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc) { |
| 418 GrGLRenderTarget::IDDesc idDesc; | 419 GrGLRenderTarget::IDDesc idDesc; |
| 419 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); | 420 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
| 420 idDesc.fMSColorRenderbufferID = 0; | 421 idDesc.fMSColorRenderbufferID = 0; |
| 421 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; | 422 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 422 | 423 |
| 423 GrSurfaceDesc desc; | 424 GrSurfaceDesc desc; |
| 424 desc.fConfig = wrapDesc.fConfig; | 425 desc.fConfig = wrapDesc.fConfig; |
| 425 desc.fFlags = kCheckAllocation_GrSurfaceFlag; | 426 desc.fFlags = kCheckAllocation_GrSurfaceFlag; |
| 426 desc.fWidth = wrapDesc.fWidth; | 427 desc.fWidth = wrapDesc.fWidth; |
| 427 desc.fHeight = wrapDesc.fHeight; | 428 desc.fHeight = wrapDesc.fHeight; |
| 428 desc.fSampleCnt = wrapDesc.fSampleCnt; | 429 desc.fSampleCnt = wrapDesc.fSampleCnt; |
| 429 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); | 430 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
| 430 | 431 |
| 431 GrGLIRect viewport; | 432 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc)); |
| 432 viewport.fLeft = 0; | |
| 433 viewport.fBottom = 0; | |
| 434 viewport.fWidth = desc.fWidth; | |
| 435 viewport.fHeight = desc.fHeight; | |
| 436 | |
| 437 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc, view
port)); | |
| 438 if (wrapDesc.fStencilBits) { | 433 if (wrapDesc.fStencilBits) { |
| 439 GrGLStencilBuffer::Format format; | 434 GrGLStencilBuffer::Format format; |
| 440 format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; | 435 format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; |
| 441 format.fPacked = false; | 436 format.fPacked = false; |
| 442 format.fStencilBits = wrapDesc.fStencilBits; | 437 format.fStencilBits = wrapDesc.fStencilBits; |
| 443 format.fTotalBits = wrapDesc.fStencilBits; | 438 format.fTotalBits = wrapDesc.fStencilBits; |
| 444 static const bool kIsSBWrapped = false; | 439 static const bool kIsSBWrapped = false; |
| 445 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, | 440 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, |
| 446 (this, | 441 (this, |
| 447 kIsSBWrapped, | 442 kIsSBWrapped, |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 1010 |
| 1016 GrGLTexture* tex; | 1011 GrGLTexture* tex; |
| 1017 if (renderTarget) { | 1012 if (renderTarget) { |
| 1018 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1013 // unbind the texture from the texture unit before binding it to the fra
me buffer |
| 1019 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); | 1014 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 1020 | 1015 |
| 1021 if (!this->createRenderTargetObjects(desc, idDesc.fTextureID, &rtIDDesc
)) { | 1016 if (!this->createRenderTargetObjects(desc, idDesc.fTextureID, &rtIDDesc
)) { |
| 1022 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1017 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
| 1023 return return_null_texture(); | 1018 return return_null_texture(); |
| 1024 } | 1019 } |
| 1025 tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc, rtIDDesc)); | 1020 tex = SkNEW_ARGS(GrGLTextureRenderTarget, (this, desc, idDesc, rtIDDesc)
); |
| 1026 } else { | 1021 } else { |
| 1027 tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc)); | 1022 tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc)); |
| 1028 } | 1023 } |
| 1029 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1024 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1030 #ifdef TRACE_TEXTURE_CREATION | 1025 #ifdef TRACE_TEXTURE_CREATION |
| 1031 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", | 1026 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 1032 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1027 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1033 #endif | 1028 #endif |
| 1034 return tex; | 1029 return tex; |
| 1035 } | 1030 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 return true; | 1181 return true; |
| 1187 } | 1182 } |
| 1188 sb->abandon(); // otherwise we lose sbID | 1183 sb->abandon(); // otherwise we lose sbID |
| 1189 } | 1184 } |
| 1190 } | 1185 } |
| 1191 GL_CALL(DeleteRenderbuffers(1, &sbID)); | 1186 GL_CALL(DeleteRenderbuffers(1, &sbID)); |
| 1192 return false; | 1187 return false; |
| 1193 } | 1188 } |
| 1194 | 1189 |
| 1195 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { | 1190 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { |
| 1196 GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; | 1191 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
| 1197 | 1192 |
| 1198 GrGLuint fbo = glrt->renderFBOID(); | 1193 GrGLuint fbo = glrt->renderFBOID(); |
| 1199 | 1194 |
| 1200 if (NULL == sb) { | 1195 if (NULL == sb) { |
| 1201 if (rt->getStencilBuffer()) { | 1196 if (rt->getStencilBuffer()) { |
| 1202 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1197 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1203 GR_GL_STENCIL_ATTACHMENT, | 1198 GR_GL_STENCIL_ATTACHMENT, |
| 1204 GR_GL_RENDERBUFFER, 0)); | 1199 GR_GL_RENDERBUFFER, 0)); |
| 1205 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1206 GR_GL_DEPTH_ATTACHMENT, | 1201 GR_GL_DEPTH_ATTACHMENT, |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 &rowBytes)) { | 1563 &rowBytes)) { |
| 1569 return false; | 1564 return false; |
| 1570 } | 1565 } |
| 1571 | 1566 |
| 1572 // resolve the render target if necessary | 1567 // resolve the render target if necessary |
| 1573 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | 1568 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
| 1574 switch (tgt->getResolveType()) { | 1569 switch (tgt->getResolveType()) { |
| 1575 case GrGLRenderTarget::kCantResolve_ResolveType: | 1570 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1576 return false; | 1571 return false; |
| 1577 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1572 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1578 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), | 1573 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); |
| 1579 &SkIRect::EmptyIRect()); | |
| 1580 break; | 1574 break; |
| 1581 case GrGLRenderTarget::kCanResolve_ResolveType: | 1575 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1582 this->onResolveRenderTarget(tgt); | 1576 this->onResolveRenderTarget(tgt); |
| 1583 // we don't track the state of the READ FBO ID. | 1577 // we don't track the state of the READ FBO ID. |
| 1584 fGPUStats.incRenderTargetBinds(); | 1578 fGPUStats.incRenderTargetBinds(); |
| 1585 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1579 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1586 tgt->textureFBOID())); | 1580 tgt->textureFBOID())); |
| 1587 break; | 1581 break; |
| 1588 default: | 1582 default: |
| 1589 SkFAIL("Unknown resolve type"); | 1583 SkFAIL("Unknown resolve type"); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); | 1976 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 1983 return gWrapModes[tm]; | 1977 return gWrapModes[tm]; |
| 1984 } | 1978 } |
| 1985 | 1979 |
| 1986 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { | 1980 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { |
| 1987 SkASSERT(texture); | 1981 SkASSERT(texture); |
| 1988 | 1982 |
| 1989 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing | 1983 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing |
| 1990 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this | 1984 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this |
| 1991 // out of the "last != next" check. | 1985 // out of the "last != next" check. |
| 1992 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); | 1986 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa
rget()); |
| 1993 if (texRT) { | 1987 if (texRT) { |
| 1994 this->onResolveRenderTarget(texRT); | 1988 this->onResolveRenderTarget(texRT); |
| 1995 } | 1989 } |
| 1996 | 1990 |
| 1997 uint32_t textureID = texture->getUniqueID(); | 1991 uint32_t textureID = texture->getUniqueID(); |
| 1998 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { | 1992 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { |
| 1999 this->setTextureUnit(unitIdx); | 1993 this->setTextureUnit(unitIdx); |
| 2000 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); | 1994 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); |
| 2001 fHWBoundTextureUniqueIDs[unitIdx] = textureID; | 1995 fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
| 2002 } | 1996 } |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2572 this->setVertexArrayID(gpu, 0); | 2566 this->setVertexArrayID(gpu, 0); |
| 2573 } | 2567 } |
| 2574 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2568 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2575 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2569 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2576 fDefaultVertexArrayAttribState.resize(attrCount); | 2570 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2577 } | 2571 } |
| 2578 attribState = &fDefaultVertexArrayAttribState; | 2572 attribState = &fDefaultVertexArrayAttribState; |
| 2579 } | 2573 } |
| 2580 return attribState; | 2574 return attribState; |
| 2581 } | 2575 } |
| OLD | NEW |