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

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

Issue 938383004: Dynamically create stencil buffer when needed. (Closed) Base URL: https://skia.googlesource.com/skia.git@bigstencil
Patch Set: Actually save file before uploading Created 5 years, 10 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/effects/GrConfigConversionEffect.cpp ('k') | src/gpu/gl/GrGLRenderTarget.h » ('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 * 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 "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLStencilBuffer.h" 10 #include "GrGLStencilBuffer.h"
11 #include "GrGLTextureRenderTarget.h" 11 #include "GrGLTextureRenderTarget.h"
12 #include "GrGpuResourcePriv.h" 12 #include "GrGpuResourcePriv.h"
13 #include "GrPipeline.h" 13 #include "GrPipeline.h"
14 #include "GrRenderTargetPriv.h"
14 #include "GrSurfacePriv.h" 15 #include "GrSurfacePriv.h"
15 #include "GrTemplates.h" 16 #include "GrTemplates.h"
16 #include "GrTexturePriv.h" 17 #include "GrTexturePriv.h"
17 #include "GrTypes.h" 18 #include "GrTypes.h"
18 #include "SkStrokeRec.h" 19 #include "SkStrokeRec.h"
19 #include "SkTemplates.h" 20 #include "SkTemplates.h"
20 21
21 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) 22 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
22 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) 23 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
23 24
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 format.fPacked = false; 448 format.fPacked = false;
448 format.fStencilBits = wrapDesc.fStencilBits; 449 format.fStencilBits = wrapDesc.fStencilBits;
449 format.fTotalBits = wrapDesc.fStencilBits; 450 format.fTotalBits = wrapDesc.fStencilBits;
450 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, 451 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer,
451 (this, 452 (this,
452 sbDesc, 453 sbDesc,
453 desc.fWidth, 454 desc.fWidth,
454 desc.fHeight, 455 desc.fHeight,
455 desc.fSampleCnt, 456 desc.fSampleCnt,
456 format)); 457 format));
457 tgt->setStencilBuffer(sb); 458 tgt->renderTargetPriv().didAttachStencilBuffer(sb);
458 sb->unref(); 459 sb->unref();
459 } 460 }
460 return tgt; 461 return tgt;
461 } 462 }
462 463
463 //////////////////////////////////////////////////////////////////////////////// 464 ////////////////////////////////////////////////////////////////////////////////
464 465
465 bool GrGLGpu::onWriteTexturePixels(GrTexture* texture, 466 bool GrGLGpu::onWriteTexturePixels(GrTexture* texture,
466 int left, int top, int width, int height, 467 int left, int top, int width, int height,
467 GrPixelConfig config, const void* buffer, 468 GrPixelConfig config, const void* buffer,
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 if (created) { 1169 if (created) {
1169 1170
1170 // After sized formats we attempt an unsized format and take 1171 // After sized formats we attempt an unsized format and take
1171 // whatever sizes GL gives us. In that case we query for the size. 1172 // whatever sizes GL gives us. In that case we query for the size.
1172 GrGLStencilBuffer::Format format = sFmt; 1173 GrGLStencilBuffer::Format format = sFmt;
1173 get_stencil_rb_sizes(this->glInterface(), &format); 1174 get_stencil_rb_sizes(this->glInterface(), &format);
1174 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, 1175 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer,
1175 (this, sbDesc, width, height, samples, format))); 1176 (this, sbDesc, width, height, samples, format)));
1176 if (this->attachStencilBufferToRenderTarget(sb, rt)) { 1177 if (this->attachStencilBufferToRenderTarget(sb, rt)) {
1177 fLastSuccessfulStencilFmtIdx = sIdx; 1178 fLastSuccessfulStencilFmtIdx = sIdx;
1178 rt->setStencilBuffer(sb); 1179 rt->renderTargetPriv().didAttachStencilBuffer(sb);
1179 return true; 1180 return true;
1180 } 1181 }
1181 // Remove the scratch key from this resource so we don't grab it fro m the cache ever 1182 // Remove the scratch key from this resource so we don't grab it fro m the cache ever
1182 // again. 1183 // again.
1183 sb->resourcePriv().removeScratchKey(); 1184 sb->resourcePriv().removeScratchKey();
1184 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource. 1185 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource.
1185 sbDesc.fRenderbufferID = 0; 1186 sbDesc.fRenderbufferID = 0;
1186 } 1187 }
1187 } 1188 }
1188 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); 1189 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID));
1189 return false; 1190 return false;
1190 } 1191 }
1191 1192
1192 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) { 1193 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) {
1193 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); 1194 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
1194 1195
1195 GrGLuint fbo = glrt->renderFBOID(); 1196 GrGLuint fbo = glrt->renderFBOID();
1196 1197
1197 if (NULL == sb) { 1198 if (NULL == sb) {
1198 if (rt->getStencilBuffer()) { 1199 if (rt->renderTargetPriv().getStencilBuffer()) {
1199 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1200 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1200 GR_GL_STENCIL_ATTACHMENT, 1201 GR_GL_STENCIL_ATTACHMENT,
1201 GR_GL_RENDERBUFFER, 0)); 1202 GR_GL_RENDERBUFFER, 0));
1202 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1203 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1203 GR_GL_DEPTH_ATTACHMENT, 1204 GR_GL_DEPTH_ATTACHMENT,
1204 GR_GL_RENDERBUFFER, 0)); 1205 GR_GL_RENDERBUFFER, 0));
1205 #ifdef SK_DEBUG 1206 #ifdef SK_DEBUG
1206 GrGLenum status; 1207 GrGLenum status;
1207 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1208 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1208 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); 1209 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1564
1564 GL_CALL(StencilMask(0xffffffff)); 1565 GL_CALL(StencilMask(0xffffffff));
1565 GL_CALL(ClearStencil(0)); 1566 GL_CALL(ClearStencil(0));
1566 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); 1567 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1567 fHWStencilSettings.invalidate(); 1568 fHWStencilSettings.invalidate();
1568 } 1569 }
1569 1570
1570 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo ol insideClip) { 1571 void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bo ol insideClip) {
1571 SkASSERT(target); 1572 SkASSERT(target);
1572 1573
1574 GrStencilBuffer* sb = target->renderTargetPriv().getStencilBuffer();
1573 // this should only be called internally when we know we have a 1575 // this should only be called internally when we know we have a
1574 // stencil buffer. 1576 // stencil buffer.
1575 SkASSERT(target->getStencilBuffer()); 1577 SkASSERT(sb);
1576 GrGLint stencilBitCount = target->getStencilBuffer()->bits(); 1578 GrGLint stencilBitCount = sb->bits();
1577 #if 0 1579 #if 0
1578 SkASSERT(stencilBitCount > 0); 1580 SkASSERT(stencilBitCount > 0);
1579 GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); 1581 GrGLint clipStencilMask = (1 << (stencilBitCount - 1));
1580 #else 1582 #else
1581 // we could just clear the clip bit but when we go through 1583 // we could just clear the clip bit but when we go through
1582 // ANGLE a partial stencil mask will cause clears to be 1584 // ANGLE a partial stencil mask will cause clears to be
1583 // turned into draws. Our contract on GrDrawTarget says that 1585 // turned into draws. Our contract on GrDrawTarget says that
1584 // changing the clip between stencil passes may or may not 1586 // changing the clip between stencil passes may or may not
1585 // zero the client's clip bits. So we just clear the whole thing. 1587 // zero the client's clip bits. So we just clear the whole thing.
1586 static const GrGLint clipStencilMask = ~0; 1588 static const GrGLint clipStencilMask = ~0;
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger ing temporary fbo 2555 // texture. This code prefers CopyTexSubImage to fbo blit and avoids trigger ing temporary fbo
2554 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal. 2556 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
2555 2557
2556 // Check for format issues with glCopyTexSubImage2D 2558 // Check for format issues with glCopyTexSubImage2D
2557 if (kGLES_GrGLStandard == this->glStandard() && this->glCaps().bgraIsInterna lFormat() && 2559 if (kGLES_GrGLStandard == this->glStandard() && this->glCaps().bgraIsInterna lFormat() &&
2558 kBGRA_8888_GrPixelConfig == src->config()) { 2560 kBGRA_8888_GrPixelConfig == src->config()) {
2559 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit 2561 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2560 // then we set up for that, otherwise fail. 2562 // then we set up for that, otherwise fail.
2561 if (this->caps()->isConfigRenderable(kBGRA_8888_GrPixelConfig, false)) { 2563 if (this->caps()->isConfigRenderable(kBGRA_8888_GrPixelConfig, false)) {
2562 desc->fOrigin = kDefault_GrSurfaceOrigin; 2564 desc->fOrigin = kDefault_GrSurfaceOrigin;
2563 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFla g; 2565 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2564 desc->fConfig = kBGRA_8888_GrPixelConfig; 2566 desc->fConfig = kBGRA_8888_GrPixelConfig;
2565 return true; 2567 return true;
2566 } 2568 }
2567 return false; 2569 return false;
2568 } else if (NULL == src->asRenderTarget()) { 2570 } else if (NULL == src->asRenderTarget()) {
2569 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t he src. 2571 // CopyTexSubImage2D or fbo blit would require creating a temp fbo for t he src.
2570 return false; 2572 return false;
2571 } 2573 }
2572 2574
2573 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget()); 2575 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as RenderTarget());
2574 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { 2576 if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
2575 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or 2577 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or
2576 // fail. 2578 // fail.
2577 if (this->caps()->isConfigRenderable(src->config(), false)) { 2579 if (this->caps()->isConfigRenderable(src->config(), false)) {
2578 desc->fOrigin = kDefault_GrSurfaceOrigin; 2580 desc->fOrigin = kDefault_GrSurfaceOrigin;
2579 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFla g; 2581 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2580 desc->fConfig = src->config(); 2582 desc->fConfig = src->config();
2581 return true; 2583 return true;
2582 } 2584 }
2583 return false; 2585 return false;
2584 } 2586 }
2585 2587
2586 // We'll do a CopyTexSubImage. Make the dst a plain old texture. 2588 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2587 desc->fConfig = src->config(); 2589 desc->fConfig = src->config();
2588 desc->fOrigin = src->origin(); 2590 desc->fOrigin = src->origin();
2589 desc->fFlags = kNone_GrSurfaceFlags; 2591 desc->fFlags = kNone_GrSurfaceFlags;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2757 this->setVertexArrayID(gpu, 0); 2759 this->setVertexArrayID(gpu, 0);
2758 } 2760 }
2759 int attrCount = gpu->glCaps().maxVertexAttributes(); 2761 int attrCount = gpu->glCaps().maxVertexAttributes();
2760 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2762 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2761 fDefaultVertexArrayAttribState.resize(attrCount); 2763 fDefaultVertexArrayAttribState.resize(attrCount);
2762 } 2764 }
2763 attribState = &fDefaultVertexArrayAttribState; 2765 attribState = &fDefaultVertexArrayAttribState;
2764 } 2766 }
2765 return attribState; 2767 return attribState;
2766 } 2768 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConfigConversionEffect.cpp ('k') | src/gpu/gl/GrGLRenderTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698