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

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

Issue 1333383002: Move some of the adding stencil attachment logic of Gpu and into Render Target. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: spelling Created 5 years, 3 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/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 "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; 488 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig;
489 489
490 GrSurfaceDesc desc; 490 GrSurfaceDesc desc;
491 desc.fConfig = wrapDesc.fConfig; 491 desc.fConfig = wrapDesc.fConfig;
492 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; 492 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
493 desc.fWidth = wrapDesc.fWidth; 493 desc.fWidth = wrapDesc.fWidth;
494 desc.fHeight = wrapDesc.fHeight; 494 desc.fHeight = wrapDesc.fHeight;
495 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() ); 495 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() );
496 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); 496 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
497 497
498 GrRenderTarget* tgt = new GrGLRenderTarget(this, desc, idDesc); 498 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil Bits);
499 if (wrapDesc.fStencilBits) {
500 GrGLStencilAttachment::IDDesc sbDesc;
501 GrGLStencilAttachment::Format format;
502 format.fInternalFormat = GrGLStencilAttachment::kUnknownInternalFormat;
503 format.fPacked = false;
504 format.fStencilBits = wrapDesc.fStencilBits;
505 format.fTotalBits = wrapDesc.fStencilBits;
506 GrGLStencilAttachment* sb = new GrGLStencilAttachment(
507 this, sbDesc, desc.fWidth, desc.fHeight, desc.fSampleCnt, format );
508 tgt->renderTargetPriv().didAttachStencilAttachment(sb);
509 sb->unref();
510 }
511 return tgt;
512 } 499 }
513 500
514 //////////////////////////////////////////////////////////////////////////////// 501 ////////////////////////////////////////////////////////////////////////////////
515 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 502 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
516 size_t rowBytes, GrPixelConfig srcConfig, 503 size_t rowBytes, GrPixelConfig srcConfig,
517 DrawPreference* drawPreference, 504 DrawPreference* drawPreference,
518 WritePixelTempDrawInfo* tempDrawInfo) { 505 WritePixelTempDrawInfo* tempDrawInfo) {
519 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { 506 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) {
520 return false; 507 return false;
521 } 508 }
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex; 1221 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex;
1235 return kUnsupportedStencilIndex; 1222 return kUnsupportedStencilIndex;
1236 } 1223 }
1237 1224
1238 // unbind the texture from the texture unit before binding it to the fra me buffer 1225 // unbind the texture from the texture unit before binding it to the fra me buffer
1239 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); 1226 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0));
1240 1227
1241 // Create Framebuffer 1228 // Create Framebuffer
1242 GrGLuint fb; 1229 GrGLuint fb;
1243 GL_CALL(GenFramebuffers(1, &fb)); 1230 GL_CALL(GenFramebuffers(1, &fb));
1244 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fb)); 1231 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fb));
1245 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 1232 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1246 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, 1233 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
1247 GR_GL_COLOR_ATTACHMENT0, 1234 GR_GL_COLOR_ATTACHMENT0,
1248 GR_GL_TEXTURE_2D, 1235 GR_GL_TEXTURE_2D,
1249 colorID, 1236 colorID,
1250 0)); 1237 0));
1251 1238
1252 // look over formats till I find a compatible one 1239 // look over formats till I find a compatible one
1253 int stencilFmtCnt = this->glCaps().stencilFormats().count(); 1240 int stencilFmtCnt = this->glCaps().stencilFormats().count();
1254 GrGLuint sbRBID = 0; 1241 GrGLuint sbRBID = 0;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 } 1284 }
1298 GL_CALL(DeleteTextures(1, &colorID)); 1285 GL_CALL(DeleteTextures(1, &colorID));
1299 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); 1286 GL_CALL(DeleteRenderbuffers(1, &sbRBID));
1300 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); 1287 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
1301 GL_CALL(DeleteFramebuffers(1, &fb)); 1288 GL_CALL(DeleteFramebuffers(1, &fb));
1302 } 1289 }
1303 SkASSERT(kUnknownStencilIndex != fPixelConfigToStencilIndex[config]); 1290 SkASSERT(kUnknownStencilIndex != fPixelConfigToStencilIndex[config]);
1304 return fPixelConfigToStencilIndex[config]; 1291 return fPixelConfigToStencilIndex[config];
1305 } 1292 }
1306 1293
1307 bool GrGLGpu::createStencilAttachmentForRenderTarget(GrRenderTarget* rt, int wid th, int height) { 1294 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt,
1295 int width,
1296 int height) {
1308 // All internally created RTs are also textures. We don't create 1297 // All internally created RTs are also textures. We don't create
1309 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . 1298 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1310 SkASSERT(rt->asTexture()); 1299 SkASSERT(rt->asTexture());
1311 SkASSERT(width >= rt->width()); 1300 SkASSERT(width >= rt->width());
1312 SkASSERT(height >= rt->height()); 1301 SkASSERT(height >= rt->height());
1313 1302
1314 int samples = rt->numStencilSamples(); 1303 int samples = rt->numStencilSamples();
1315 GrGLStencilAttachment::IDDesc sbDesc; 1304 GrGLStencilAttachment::IDDesc sbDesc;
1316 1305
1317 int sIdx = this->getCompatibleStencilIndex(rt->config()); 1306 int sIdx = this->getCompatibleStencilIndex(rt->config());
1318 if (sIdx == kUnsupportedStencilIndex) { 1307 if (sIdx == kUnsupportedStencilIndex) {
1319 return false; 1308 return nullptr;
1320 } 1309 }
1321 1310
1322 if (!sbDesc.fRenderbufferID) { 1311 if (!sbDesc.fRenderbufferID) {
1323 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); 1312 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID));
1324 } 1313 }
1325 if (!sbDesc.fRenderbufferID) { 1314 if (!sbDesc.fRenderbufferID) {
1326 return false; 1315 return nullptr;
1327 } 1316 }
1328 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); 1317 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID));
1329 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx]; 1318 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx];
1330 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); 1319 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
1331 // we do this "if" so that we don't call the multisample 1320 // we do this "if" so that we don't call the multisample
1332 // version on a GL that doesn't have an MSAA extension. 1321 // version on a GL that doesn't have an MSAA extension.
1333 if (samples > 0) { 1322 if (samples > 0) {
1334 SkAssertResult(renderbuffer_storage_msaa(*fGLContext, 1323 SkAssertResult(renderbuffer_storage_msaa(*fGLContext,
1335 samples, 1324 samples,
1336 sFmt.fInternalFormat, 1325 sFmt.fInternalFormat,
1337 width, height)); 1326 width, height));
1338 } else { 1327 } else {
1339 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFE R, 1328 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFE R,
1340 sFmt.fInternalFor mat, 1329 sFmt.fInternalFor mat,
1341 width, height)); 1330 width, height));
1342 SkASSERT(GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa ce())); 1331 SkASSERT(GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa ce()));
1343 } 1332 }
1344 fStats.incStencilAttachmentCreates(); 1333 fStats.incStencilAttachmentCreates();
1345 // After sized formats we attempt an unsized format and take 1334 // After sized formats we attempt an unsized format and take
1346 // whatever sizes GL gives us. In that case we query for the size. 1335 // whatever sizes GL gives us. In that case we query for the size.
1347 GrGLStencilAttachment::Format format = sFmt; 1336 GrGLStencilAttachment::Format format = sFmt;
1348 get_stencil_rb_sizes(this->glInterface(), &format); 1337 get_stencil_rb_sizes(this->glInterface(), &format);
1349 SkAutoTUnref<GrGLStencilAttachment> sb( 1338 GrGLStencilAttachment* stencil = new GrGLStencilAttachment(this,
1350 new GrGLStencilAttachment(this, sbDesc, width, height, samples, format)) ; 1339 sbDesc,
1351 SkAssertResult(this->attachStencilAttachmentToRenderTarget(sb, rt)); 1340 width,
1352 rt->renderTargetPriv().didAttachStencilAttachment(sb); 1341 height,
1353 // This work around is currently breaking on windows 7 hd2000 bot when we bi nd a color buffer 1342 samples,
1354 #if 0 1343 format);
1355 // Clear the stencil buffer. We use a special purpose FBO for this so that t he 1344 return stencil;
1356 // entire stencil buffer is cleared, even if it is attached to an FBO with a
1357 // smaller color target.
1358 if (0 == fStencilClearFBOID) {
1359 GL_CALL(GenFramebuffers(1, &fStencilClearFBOID));
1360 }
1361
1362 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID));
1363 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1364 fStats.incRenderTargetBinds();
1365 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1366 GR_GL_STENCIL_ATTACHMENT,
1367 GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)) ;
1368 if (sFmt.fPacked) {
1369 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1370 GR_GL_DEPTH_ATTACHMENT,
1371 GR_GL_RENDERBUFFER, sbDesc.fRenderbuffer ID));
1372 }
1373
1374 GL_CALL(ClearStencil(0));
1375 // Many GL implementations seem to have trouble with clearing an FBO with on ly
1376 // a stencil buffer.
1377 GrGLuint tempRB;
1378 GL_CALL(GenRenderbuffers(1, &tempRB));
1379 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, tempRB));
1380 if (samples > 0) {
1381 renderbuffer_storage_msaa(fGLContext, samples, GR_GL_RGBA8, width, heigh t);
1382 } else {
1383 GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, heig ht));
1384 }
1385 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1386 GR_GL_COLOR_ATTACHMENT0,
1387 GR_GL_RENDERBUFFER, tempRB));
1388
1389 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
1390
1391 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1392 GR_GL_COLOR_ATTACHMENT0,
1393 GR_GL_RENDERBUFFER, 0));
1394 GL_CALL(DeleteRenderbuffers(1, &tempRB));
1395
1396 // Unbind the SB from the FBO so that we don't keep it alive.
1397 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1398 GR_GL_STENCIL_ATTACHMENT,
1399 GR_GL_RENDERBUFFER, 0));
1400 if (sFmt.fPacked) {
1401 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1402 GR_GL_DEPTH_ATTACHMENT,
1403 GR_GL_RENDERBUFFER, 0));
1404 }
1405 #endif
1406 return true;
1407 }
1408
1409 bool GrGLGpu::attachStencilAttachmentToRenderTarget(GrStencilAttachment* sb, GrR enderTarget* rt) {
1410 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
1411
1412 GrGLuint fbo = glrt->renderFBOID();
1413
1414 if (nullptr == sb) {
1415 if (rt->renderTargetPriv().getStencilAttachment()) {
1416 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1417 GR_GL_STENCIL_ATTACHMENT,
1418 GR_GL_RENDERBUFFER, 0));
1419 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1420 GR_GL_DEPTH_ATTACHMENT,
1421 GR_GL_RENDERBUFFER, 0));
1422 #ifdef SK_DEBUG
1423 GrGLenum status;
1424 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1425 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
1426 #endif
1427 }
1428 return true;
1429 } else {
1430 GrGLStencilAttachment* glsb = static_cast<GrGLStencilAttachment*>(sb);
1431 GrGLuint rb = glsb->renderbufferID();
1432
1433 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
1434 fStats.incRenderTargetBinds();
1435 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
1436 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1437 GR_GL_STENCIL_ATTACHMENT,
1438 GR_GL_RENDERBUFFER, rb));
1439 if (glsb->format().fPacked) {
1440 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1441 GR_GL_DEPTH_ATTACHMENT,
1442 GR_GL_RENDERBUFFER, rb));
1443 } else {
1444 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1445 GR_GL_DEPTH_ATTACHMENT,
1446 GR_GL_RENDERBUFFER, 0));
1447 }
1448
1449 #ifdef SK_DEBUG
1450 GrGLenum status;
1451 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1452 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
1453 #endif
1454 return true;
1455 }
1456 } 1345 }
1457 1346
1458 //////////////////////////////////////////////////////////////////////////////// 1347 ////////////////////////////////////////////////////////////////////////////////
1459 1348
1460 GrVertexBuffer* GrGLGpu::onCreateVertexBuffer(size_t size, bool dynamic) { 1349 GrVertexBuffer* GrGLGpu::onCreateVertexBuffer(size_t size, bool dynamic) {
1461 GrGLVertexBuffer::Desc desc; 1350 GrGLVertexBuffer::Desc desc;
1462 desc.fDynamic = dynamic; 1351 desc.fDynamic = dynamic;
1463 desc.fSizeInBytes = size; 1352 desc.fSizeInBytes = size;
1464 1353
1465 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { 1354 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) {
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 this->setVertexArrayID(gpu, 0); 3160 this->setVertexArrayID(gpu, 0);
3272 } 3161 }
3273 int attrCount = gpu->glCaps().maxVertexAttributes(); 3162 int attrCount = gpu->glCaps().maxVertexAttributes();
3274 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3163 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3275 fDefaultVertexArrayAttribState.resize(attrCount); 3164 fDefaultVertexArrayAttribState.resize(attrCount);
3276 } 3165 }
3277 attribState = &fDefaultVertexArrayAttribState; 3166 attribState = &fDefaultVertexArrayAttribState;
3278 } 3167 }
3279 return attribState; 3168 return attribState;
3280 } 3169 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLRenderTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698