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

Side by Side Diff: src/gpu/gl/GrGpuGL.cpp

Issue 695813003: Add class GrGLTextureRenderTarget for GL texture/rendertarget objects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 6 years, 1 month 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
« src/gpu/gl/GrGLTextureRenderTarget.h ('K') | « src/gpu/gl/GrGpuGL.h ('k') | no next file » | 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 * 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
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
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 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", 1026 GrPrintf("--- 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
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
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); 1978 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode);
1985 return gWrapModes[tm]; 1979 return gWrapModes[tm];
1986 } 1980 }
1987 1981
1988 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { 1982 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) {
1989 SkASSERT(texture); 1983 SkASSERT(texture);
1990 1984
1991 // If we created a rt/tex and rendered to it without using a texture and now we're texturing 1985 // If we created a rt/tex and rendered to it without using a texture and now we're texturing
1992 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this 1986 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this
1993 // out of the "last != next" check. 1987 // out of the "last != next" check.
1994 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT arget()); 1988 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa rget());
1995 if (texRT) { 1989 if (texRT) {
1996 this->onResolveRenderTarget(texRT); 1990 this->onResolveRenderTarget(texRT);
1997 } 1991 }
1998 1992
1999 uint32_t textureID = texture->getUniqueID(); 1993 uint32_t textureID = texture->getUniqueID();
2000 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { 1994 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) {
2001 this->setTextureUnit(unitIdx); 1995 this->setTextureUnit(unitIdx);
2002 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); 1996 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID()));
2003 fHWBoundTextureUniqueIDs[unitIdx] = textureID; 1997 fHWBoundTextureUniqueIDs[unitIdx] = textureID;
2004 } 1998 }
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2574 this->setVertexArrayID(gpu, 0); 2568 this->setVertexArrayID(gpu, 0);
2575 } 2569 }
2576 int attrCount = gpu->glCaps().maxVertexAttributes(); 2570 int attrCount = gpu->glCaps().maxVertexAttributes();
2577 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2571 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2578 fDefaultVertexArrayAttribState.resize(attrCount); 2572 fDefaultVertexArrayAttribState.resize(attrCount);
2579 } 2573 }
2580 attribState = &fDefaultVertexArrayAttribState; 2574 attribState = &fDefaultVertexArrayAttribState;
2581 } 2575 }
2582 return attribState; 2576 return attribState;
2583 } 2577 }
OLDNEW
« src/gpu/gl/GrGLTextureRenderTarget.h ('K') | « src/gpu/gl/GrGpuGL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698