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

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

Issue 859013002: Make stencil buffers uncached for uncached render target textures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 11 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/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLStencilBuffer.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"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 GrSurfaceDesc desc; 423 GrSurfaceDesc desc;
424 desc.fConfig = wrapDesc.fConfig; 424 desc.fConfig = wrapDesc.fConfig;
425 desc.fFlags = kCheckAllocation_GrSurfaceFlag; 425 desc.fFlags = kCheckAllocation_GrSurfaceFlag;
426 desc.fWidth = wrapDesc.fWidth; 426 desc.fWidth = wrapDesc.fWidth;
427 desc.fHeight = wrapDesc.fHeight; 427 desc.fHeight = wrapDesc.fHeight;
428 desc.fSampleCnt = wrapDesc.fSampleCnt; 428 desc.fSampleCnt = wrapDesc.fSampleCnt;
429 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); 429 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
430 430
431 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc)); 431 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc));
432 if (wrapDesc.fStencilBits) { 432 if (wrapDesc.fStencilBits) {
433 GrGLStencilBuffer::IDDesc sbDesc;
434 sbDesc.fRenderbufferID = 0;
435 sbDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle;
433 GrGLStencilBuffer::Format format; 436 GrGLStencilBuffer::Format format;
434 format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; 437 format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat;
435 format.fPacked = false; 438 format.fPacked = false;
436 format.fStencilBits = wrapDesc.fStencilBits; 439 format.fStencilBits = wrapDesc.fStencilBits;
437 format.fTotalBits = wrapDesc.fStencilBits; 440 format.fTotalBits = wrapDesc.fStencilBits;
438 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, 441 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer,
439 (this, 442 (this,
440 0, 443 sbDesc,
441 desc.fWidth, 444 desc.fWidth,
442 desc.fHeight, 445 desc.fHeight,
443 desc.fSampleCnt, 446 desc.fSampleCnt,
444 format)); 447 format));
445 tgt->setStencilBuffer(sb); 448 tgt->setStencilBuffer(sb);
446 sb->unref(); 449 sb->unref();
447 } 450 }
448 return tgt; 451 return tgt;
449 } 452 }
450 453
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 GR_GL_RENDERBUFFER_DEPTH_SIZE, 1110 GR_GL_RENDERBUFFER_DEPTH_SIZE,
1108 (GrGLint*)&format->fTotalBits); 1111 (GrGLint*)&format->fTotalBits);
1109 format->fTotalBits += format->fStencilBits; 1112 format->fTotalBits += format->fStencilBits;
1110 } else { 1113 } else {
1111 format->fTotalBits = format->fStencilBits; 1114 format->fTotalBits = format->fStencilBits;
1112 } 1115 }
1113 } 1116 }
1114 } 1117 }
1115 } 1118 }
1116 1119
1117 bool GrGLGpu::createStencilBufferForRenderTarget(GrRenderTarget* rt, int width, int height) { 1120 bool GrGLGpu::createStencilBufferForRenderTarget(GrRenderTarget* rt, bool budget ed, int width,
1118 1121 int height) {
1119 // All internally created RTs are also textures. We don't create 1122 // All internally created RTs are also textures. We don't create
1120 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . 1123 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1121 SkASSERT(rt->asTexture()); 1124 SkASSERT(rt->asTexture());
1122 SkASSERT(width >= rt->width()); 1125 SkASSERT(width >= rt->width());
1123 SkASSERT(height >= rt->height()); 1126 SkASSERT(height >= rt->height());
1124 1127
1125 int samples = rt->numSamples(); 1128 int samples = rt->numSamples();
1126 GrGLuint sbID = 0; 1129 GrGLStencilBuffer::IDDesc sbDesc;
1130 sbDesc.fRenderbufferID = 0;
1131 sbDesc.fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle
1132 : GrGpuResource::kUncached_LifeCycle;
1127 1133
1128 int stencilFmtCnt = this->glCaps().stencilFormats().count(); 1134 int stencilFmtCnt = this->glCaps().stencilFormats().count();
1129 for (int i = 0; i < stencilFmtCnt; ++i) { 1135 for (int i = 0; i < stencilFmtCnt; ++i) {
1130 if (!sbID) { 1136 if (!sbDesc.fRenderbufferID) {
1131 GL_CALL(GenRenderbuffers(1, &sbID)); 1137 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID));
1132 } 1138 }
1133 if (!sbID) { 1139 if (!sbDesc.fRenderbufferID) {
1134 return false; 1140 return false;
1135 } 1141 }
1136 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); 1142 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID));
1137 // we start with the last stencil format that succeeded in hopes 1143 // we start with the last stencil format that succeeded in hopes
1138 // that we won't go through this loop more than once after the 1144 // that we won't go through this loop more than once after the
1139 // first (painful) stencil creation. 1145 // first (painful) stencil creation.
1140 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; 1146 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt;
1141 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sI dx]; 1147 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sI dx];
1142 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); 1148 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
1143 // we do this "if" so that we don't call the multisample 1149 // we do this "if" so that we don't call the multisample
1144 // version on a GL that doesn't have an MSAA extension. 1150 // version on a GL that doesn't have an MSAA extension.
1145 bool created; 1151 bool created;
1146 if (samples > 0) { 1152 if (samples > 0) {
1147 created = renderbuffer_storage_msaa(fGLContext, 1153 created = renderbuffer_storage_msaa(fGLContext,
1148 samples, 1154 samples,
1149 sFmt.fInternalFormat, 1155 sFmt.fInternalFormat,
1150 width, height); 1156 width, height);
1151 } else { 1157 } else {
1152 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERB UFFER, 1158 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERB UFFER,
1153 sFmt.fInterna lFormat, 1159 sFmt.fInterna lFormat,
1154 width, height )); 1160 width, height ));
1155 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI nterface())); 1161 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI nterface()));
1156 } 1162 }
1157 if (created) { 1163 if (created) {
1164
1158 // After sized formats we attempt an unsized format and take 1165 // After sized formats we attempt an unsized format and take
1159 // whatever sizes GL gives us. In that case we query for the size. 1166 // whatever sizes GL gives us. In that case we query for the size.
1160 GrGLStencilBuffer::Format format = sFmt; 1167 GrGLStencilBuffer::Format format = sFmt;
1161 get_stencil_rb_sizes(this->glInterface(), &format); 1168 get_stencil_rb_sizes(this->glInterface(), &format);
1162 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, 1169 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer,
1163 (this, sbID, width, height, sa mples, format))); 1170 (this, sbDesc, width, height, samples, format)));
1164 if (this->attachStencilBufferToRenderTarget(sb, rt)) { 1171 if (this->attachStencilBufferToRenderTarget(sb, rt)) {
1165 fLastSuccessfulStencilFmtIdx = sIdx; 1172 fLastSuccessfulStencilFmtIdx = sIdx;
1166 rt->setStencilBuffer(sb); 1173 rt->setStencilBuffer(sb);
1167 return true; 1174 return true;
1168 } 1175 }
1169 // Remove the scratch key from this resource so we don't grab it fro m the cache ever 1176 // Remove the scratch key from this resource so we don't grab it fro m the cache ever
1170 // again. 1177 // again.
1171 sb->cacheAccess().removeScratchKey(); 1178 sb->cacheAccess().removeScratchKey();
1172 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource. 1179 // Set this to 0 since we handed the valid ID off to the failed sten cil buffer resource.
1173 sbID = 0; 1180 sbDesc.fRenderbufferID = 0;
1174 } 1181 }
1175 } 1182 }
1176 GL_CALL(DeleteRenderbuffers(1, &sbID)); 1183 GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID));
1177 return false; 1184 return false;
1178 } 1185 }
1179 1186
1180 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) { 1187 bool GrGLGpu::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) {
1181 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); 1188 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
1182 1189
1183 GrGLuint fbo = glrt->renderFBOID(); 1190 GrGLuint fbo = glrt->renderFBOID();
1184 1191
1185 if (NULL == sb) { 1192 if (NULL == sb) {
1186 if (rt->getStencilBuffer()) { 1193 if (rt->getStencilBuffer()) {
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 this->setVertexArrayID(gpu, 0); 2750 this->setVertexArrayID(gpu, 0);
2744 } 2751 }
2745 int attrCount = gpu->glCaps().maxVertexAttributes(); 2752 int attrCount = gpu->glCaps().maxVertexAttributes();
2746 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2753 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2747 fDefaultVertexArrayAttribState.resize(attrCount); 2754 fDefaultVertexArrayAttribState.resize(attrCount);
2748 } 2755 }
2749 attribState = &fDefaultVertexArrayAttribState; 2756 attribState = &fDefaultVertexArrayAttribState;
2750 } 2757 }
2751 return attribState; 2758 return attribState;
2752 } 2759 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLStencilBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698