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" |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 bool adjust_pixel_ops_params(int surfaceWidth, | 535 bool adjust_pixel_ops_params(int surfaceWidth, |
536 int surfaceHeight, | 536 int surfaceHeight, |
537 size_t bpp, | 537 size_t bpp, |
538 int* left, int* top, int* width, int* height, | 538 int* left, int* top, int* width, int* height, |
539 const void** data, | 539 const void** data, |
540 size_t* rowBytes) { | 540 size_t* rowBytes) { |
541 if (!*rowBytes) { | 541 if (!*rowBytes) { |
542 *rowBytes = *width * bpp; | 542 *rowBytes = *width * bpp; |
543 } | 543 } |
544 | 544 |
545 GrIRect subRect = GrIRect::MakeXYWH(*left, *top, *width, *height); | 545 SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height); |
546 GrIRect bounds = GrIRect::MakeWH(surfaceWidth, surfaceHeight); | 546 SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight); |
547 | 547 |
548 if (!subRect.intersect(bounds)) { | 548 if (!subRect.intersect(bounds)) { |
549 return false; | 549 return false; |
550 } | 550 } |
551 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + | 551 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
552 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); | 552 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
553 | 553 |
554 *left = subRect.fLeft; | 554 *left = subRect.fLeft; |
555 *top = subRect.fTop; | 555 *top = subRect.fTop; |
556 *width = subRect.width(); | 556 *width = subRect.width(); |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 return; | 1262 return; |
1263 } | 1263 } |
1264 } | 1264 } |
1265 if (kNo_TriState != fHWScissorSettings.fEnabled) { | 1265 if (kNo_TriState != fHWScissorSettings.fEnabled) { |
1266 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); | 1266 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
1267 fHWScissorSettings.fEnabled = kNo_TriState; | 1267 fHWScissorSettings.fEnabled = kNo_TriState; |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 } | 1270 } |
1271 | 1271 |
1272 void GrGpuGL::onClear(const GrIRect* rect, GrColor color) { | 1272 void GrGpuGL::onClear(const SkIRect* rect, GrColor color) { |
1273 const GrDrawState& drawState = this->getDrawState(); | 1273 const GrDrawState& drawState = this->getDrawState(); |
1274 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1274 const GrRenderTarget* rt = drawState.getRenderTarget(); |
1275 // parent class should never let us get here with no RT | 1275 // parent class should never let us get here with no RT |
1276 GrAssert(NULL != rt); | 1276 GrAssert(NULL != rt); |
1277 | 1277 |
1278 GrIRect clippedRect; | 1278 SkIRect clippedRect; |
1279 if (NULL != rect) { | 1279 if (NULL != rect) { |
1280 // flushScissor expects rect to be clipped to the target. | 1280 // flushScissor expects rect to be clipped to the target. |
1281 clippedRect = *rect; | 1281 clippedRect = *rect; |
1282 GrIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); | 1282 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
1283 if (clippedRect.intersect(rtRect)) { | 1283 if (clippedRect.intersect(rtRect)) { |
1284 rect = &clippedRect; | 1284 rect = &clippedRect; |
1285 } else { | 1285 } else { |
1286 return; | 1286 return; |
1287 } | 1287 } |
1288 } | 1288 } |
1289 this->flushRenderTarget(rect); | 1289 this->flushRenderTarget(rect); |
1290 GrAutoTRestore<ScissorState> asr(&fScissorState); | 1290 GrAutoTRestore<ScissorState> asr(&fScissorState); |
1291 fScissorState.fEnabled = (NULL != rect); | 1291 fScissorState.fEnabled = (NULL != rect); |
1292 if (fScissorState.fEnabled) { | 1292 if (fScissorState.fEnabled) { |
(...skipping 13 matching lines...) Expand all Loading... |
1306 fHWWriteToColor = kYes_TriState; | 1306 fHWWriteToColor = kYes_TriState; |
1307 GL_CALL(ClearColor(r, g, b, a)); | 1307 GL_CALL(ClearColor(r, g, b, a)); |
1308 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); | 1308 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
1309 } | 1309 } |
1310 | 1310 |
1311 void GrGpuGL::clearStencil() { | 1311 void GrGpuGL::clearStencil() { |
1312 if (NULL == this->getDrawState().getRenderTarget()) { | 1312 if (NULL == this->getDrawState().getRenderTarget()) { |
1313 return; | 1313 return; |
1314 } | 1314 } |
1315 | 1315 |
1316 this->flushRenderTarget(&GrIRect::EmptyIRect()); | 1316 this->flushRenderTarget(&SkIRect::EmptyIRect()); |
1317 | 1317 |
1318 GrAutoTRestore<ScissorState> asr(&fScissorState); | 1318 GrAutoTRestore<ScissorState> asr(&fScissorState); |
1319 fScissorState.fEnabled = false; | 1319 fScissorState.fEnabled = false; |
1320 this->flushScissor(); | 1320 this->flushScissor(); |
1321 | 1321 |
1322 GL_CALL(StencilMask(0xffffffff)); | 1322 GL_CALL(StencilMask(0xffffffff)); |
1323 GL_CALL(ClearStencil(0)); | 1323 GL_CALL(ClearStencil(0)); |
1324 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1324 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1325 fHWStencilSettings.invalidate(); | 1325 fHWStencilSettings.invalidate(); |
1326 } | 1326 } |
1327 | 1327 |
1328 void GrGpuGL::clearStencilClip(const GrIRect& rect, bool insideClip) { | 1328 void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) { |
1329 const GrDrawState& drawState = this->getDrawState(); | 1329 const GrDrawState& drawState = this->getDrawState(); |
1330 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1330 const GrRenderTarget* rt = drawState.getRenderTarget(); |
1331 GrAssert(NULL != rt); | 1331 GrAssert(NULL != rt); |
1332 | 1332 |
1333 // this should only be called internally when we know we have a | 1333 // this should only be called internally when we know we have a |
1334 // stencil buffer. | 1334 // stencil buffer. |
1335 GrAssert(NULL != rt->getStencilBuffer()); | 1335 GrAssert(NULL != rt->getStencilBuffer()); |
1336 GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); | 1336 GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); |
1337 #if 0 | 1337 #if 0 |
1338 GrAssert(stencilBitCount > 0); | 1338 GrAssert(stencilBitCount > 0); |
1339 GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); | 1339 GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
1340 #else | 1340 #else |
1341 // we could just clear the clip bit but when we go through | 1341 // we could just clear the clip bit but when we go through |
1342 // ANGLE a partial stencil mask will cause clears to be | 1342 // ANGLE a partial stencil mask will cause clears to be |
1343 // turned into draws. Our contract on GrDrawTarget says that | 1343 // turned into draws. Our contract on GrDrawTarget says that |
1344 // changing the clip between stencil passes may or may not | 1344 // changing the clip between stencil passes may or may not |
1345 // zero the client's clip bits. So we just clear the whole thing. | 1345 // zero the client's clip bits. So we just clear the whole thing. |
1346 static const GrGLint clipStencilMask = ~0; | 1346 static const GrGLint clipStencilMask = ~0; |
1347 #endif | 1347 #endif |
1348 GrGLint value; | 1348 GrGLint value; |
1349 if (insideClip) { | 1349 if (insideClip) { |
1350 value = (1 << (stencilBitCount - 1)); | 1350 value = (1 << (stencilBitCount - 1)); |
1351 } else { | 1351 } else { |
1352 value = 0; | 1352 value = 0; |
1353 } | 1353 } |
1354 this->flushRenderTarget(&GrIRect::EmptyIRect()); | 1354 this->flushRenderTarget(&SkIRect::EmptyIRect()); |
1355 | 1355 |
1356 GrAutoTRestore<ScissorState> asr(&fScissorState); | 1356 GrAutoTRestore<ScissorState> asr(&fScissorState); |
1357 fScissorState.fEnabled = true; | 1357 fScissorState.fEnabled = true; |
1358 fScissorState.fRect = rect; | 1358 fScissorState.fRect = rect; |
1359 this->flushScissor(); | 1359 this->flushScissor(); |
1360 | 1360 |
1361 GL_CALL(StencilMask((uint32_t) clipStencilMask)); | 1361 GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
1362 GL_CALL(ClearStencil(value)); | 1362 GL_CALL(ClearStencil(value)); |
1363 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1363 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1364 fHWStencilSettings.invalidate(); | 1364 fHWStencilSettings.invalidate(); |
1365 } | 1365 } |
1366 | 1366 |
1367 void GrGpuGL::onForceRenderTargetFlush() { | 1367 void GrGpuGL::onForceRenderTargetFlush() { |
1368 this->flushRenderTarget(&GrIRect::EmptyIRect()); | 1368 this->flushRenderTarget(&SkIRect::EmptyIRect()); |
1369 } | 1369 } |
1370 | 1370 |
1371 bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, | 1371 bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
1372 int left, int top, | 1372 int left, int top, |
1373 int width, int height, | 1373 int width, int height, |
1374 GrPixelConfig config, | 1374 GrPixelConfig config, |
1375 size_t rowBytes) const { | 1375 size_t rowBytes) const { |
1376 // If this rendertarget is aready TopLeft, we don't need to flip. | 1376 // If this rendertarget is aready TopLeft, we don't need to flip. |
1377 if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) { | 1377 if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) { |
1378 return false; | 1378 return false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 } | 1420 } |
1421 | 1421 |
1422 // resolve the render target if necessary | 1422 // resolve the render target if necessary |
1423 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | 1423 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
1424 GrDrawState::AutoRenderTargetRestore artr; | 1424 GrDrawState::AutoRenderTargetRestore artr; |
1425 switch (tgt->getResolveType()) { | 1425 switch (tgt->getResolveType()) { |
1426 case GrGLRenderTarget::kCantResolve_ResolveType: | 1426 case GrGLRenderTarget::kCantResolve_ResolveType: |
1427 return false; | 1427 return false; |
1428 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1428 case GrGLRenderTarget::kAutoResolves_ResolveType: |
1429 artr.set(this->drawState(), target); | 1429 artr.set(this->drawState(), target); |
1430 this->flushRenderTarget(&GrIRect::EmptyIRect()); | 1430 this->flushRenderTarget(&SkIRect::EmptyIRect()); |
1431 break; | 1431 break; |
1432 case GrGLRenderTarget::kCanResolve_ResolveType: | 1432 case GrGLRenderTarget::kCanResolve_ResolveType: |
1433 this->onResolveRenderTarget(tgt); | 1433 this->onResolveRenderTarget(tgt); |
1434 // we don't track the state of the READ FBO ID. | 1434 // we don't track the state of the READ FBO ID. |
1435 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1435 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
1436 tgt->textureFBOID())); | 1436 tgt->textureFBOID())); |
1437 break; | 1437 break; |
1438 default: | 1438 default: |
1439 GrCrash("Unknown resolve type"); | 1439 GrCrash("Unknown resolve type"); |
1440 } | 1440 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 if (!flipY) { | 1515 if (!flipY) { |
1516 dst += rowBytes; | 1516 dst += rowBytes; |
1517 } else { | 1517 } else { |
1518 dst -= rowBytes; | 1518 dst -= rowBytes; |
1519 } | 1519 } |
1520 } | 1520 } |
1521 } | 1521 } |
1522 return true; | 1522 return true; |
1523 } | 1523 } |
1524 | 1524 |
1525 void GrGpuGL::flushRenderTarget(const GrIRect* bound) { | 1525 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { |
1526 | 1526 |
1527 GrGLRenderTarget* rt = | 1527 GrGLRenderTarget* rt = |
1528 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); | 1528 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
1529 GrAssert(NULL != rt); | 1529 GrAssert(NULL != rt); |
1530 | 1530 |
1531 if (fHWBoundRenderTarget != rt) { | 1531 if (fHWBoundRenderTarget != rt) { |
1532 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); | 1532 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
1533 #if GR_DEBUG | 1533 #if GR_DEBUG |
1534 GrGLenum status; | 1534 GrGLenum status; |
1535 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1535 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 if (rt->needsResolve()) { | 1694 if (rt->needsResolve()) { |
1695 // Some extensions automatically resolves the texture when it is read. | 1695 // Some extensions automatically resolves the texture when it is read. |
1696 if (this->glCaps().usesMSAARenderBuffers()) { | 1696 if (this->glCaps().usesMSAARenderBuffers()) { |
1697 GrAssert(rt->textureFBOID() != rt->renderFBOID()); | 1697 GrAssert(rt->textureFBOID() != rt->renderFBOID()); |
1698 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1698 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
1699 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1699 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
1700 // make sure we go through flushRenderTarget() since we've modified | 1700 // make sure we go through flushRenderTarget() since we've modified |
1701 // the bound DRAW FBO ID. | 1701 // the bound DRAW FBO ID. |
1702 fHWBoundRenderTarget = NULL; | 1702 fHWBoundRenderTarget = NULL; |
1703 const GrGLIRect& vp = rt->getViewport(); | 1703 const GrGLIRect& vp = rt->getViewport(); |
1704 const GrIRect dirtyRect = rt->getResolveRect(); | 1704 const SkIRect dirtyRect = rt->getResolveRect(); |
1705 GrGLIRect r; | 1705 GrGLIRect r; |
1706 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, | 1706 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
1707 dirtyRect.width(), dirtyRect.height(), target->origi
n()); | 1707 dirtyRect.width(), dirtyRect.height(), target->origi
n()); |
1708 | 1708 |
1709 GrAutoTRestore<ScissorState> asr; | 1709 GrAutoTRestore<ScissorState> asr; |
1710 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { | 1710 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
1711 // Apple's extension uses the scissor as the blit bounds. | 1711 // Apple's extension uses the scissor as the blit bounds. |
1712 asr.reset(&fScissorState); | 1712 asr.reset(&fScissorState); |
1713 fScissorState.fEnabled = true; | 1713 fScissorState.fEnabled = true; |
1714 fScissorState.fRect = dirtyRect; | 1714 fScissorState.fRect = dirtyRect; |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 this->setVertexArrayID(gpu, 0); | 2515 this->setVertexArrayID(gpu, 0); |
2516 } | 2516 } |
2517 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2517 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2518 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2518 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2519 fDefaultVertexArrayAttribState.resize(attrCount); | 2519 fDefaultVertexArrayAttribState.resize(attrCount); |
2520 } | 2520 } |
2521 attribState = &fDefaultVertexArrayAttribState; | 2521 attribState = &fDefaultVertexArrayAttribState; |
2522 } | 2522 } |
2523 return attribState; | 2523 return attribState; |
2524 } | 2524 } |
OLD | NEW |