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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 fHWScissorSettings.fEnabled = kYes_TriState; | 1329 fHWScissorSettings.fEnabled = kYes_TriState; |
1330 } | 1330 } |
1331 return; | 1331 return; |
1332 } | 1332 } |
1333 } | 1333 } |
1334 | 1334 |
1335 // See fall through note above | 1335 // See fall through note above |
1336 this->disableScissor(); | 1336 this->disableScissor(); |
1337 } | 1337 } |
1338 | 1338 |
1339 bool GrGLGpu::flushGLState(const GrOptDrawState& optState) { | 1339 bool GrGLGpu::flushGLState(const DrawArgs& args) { |
1340 GrXferProcessor::BlendInfo blendInfo; | 1340 GrXferProcessor::BlendInfo blendInfo; |
1341 optState.getXferProcessor()->getBlendInfo(&blendInfo); | 1341 const GrOptDrawState& optState = *args.fOptState; |
| 1342 args.fOptState->getXferProcessor()->getBlendInfo(&blendInfo); |
1342 | 1343 |
1343 this->flushDither(optState.isDitherState()); | 1344 this->flushDither(optState.isDitherState()); |
1344 this->flushColorWrite(blendInfo.fWriteColor); | 1345 this->flushColorWrite(blendInfo.fWriteColor); |
1345 this->flushDrawFace(optState.getDrawFace()); | 1346 this->flushDrawFace(optState.getDrawFace()); |
1346 | 1347 |
1347 fCurrentProgram.reset(fProgramCache->getProgram(optState)); | 1348 fCurrentProgram.reset(fProgramCache->getProgram(args)); |
1348 if (NULL == fCurrentProgram.get()) { | 1349 if (NULL == fCurrentProgram.get()) { |
1349 SkDEBUGFAIL("Failed to create program!"); | 1350 SkDEBUGFAIL("Failed to create program!"); |
1350 return false; | 1351 return false; |
1351 } | 1352 } |
1352 | 1353 |
1353 fCurrentProgram.get()->ref(); | 1354 fCurrentProgram.get()->ref(); |
1354 | 1355 |
1355 GrGLuint programID = fCurrentProgram->programID(); | 1356 GrGLuint programID = fCurrentProgram->programID(); |
1356 if (fHWProgramID != programID) { | 1357 if (fHWProgramID != programID) { |
1357 GL_CALL(UseProgram(programID)); | 1358 GL_CALL(UseProgram(programID)); |
1358 fHWProgramID = programID; | 1359 fHWProgramID = programID; |
1359 } | 1360 } |
1360 | 1361 |
1361 if (blendInfo.fWriteColor) { | 1362 if (blendInfo.fWriteColor) { |
1362 this->flushBlend(blendInfo); | 1363 this->flushBlend(blendInfo); |
1363 } | 1364 } |
1364 | 1365 |
1365 fCurrentProgram->setData(optState); | 1366 fCurrentProgram->setData(*args.fPrimitiveProcessor, optState, *args.fBatchTr
acker); |
1366 | 1367 |
1367 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa
rget()); | 1368 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa
rget()); |
1368 this->flushStencil(optState.getStencil()); | 1369 this->flushStencil(optState.getStencil()); |
1369 this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 1370 this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
1370 this->flushHWAAState(glRT, optState.isHWAntialiasState(), | 1371 this->flushHWAAState(glRT, optState.isHWAntialiasState(), |
1371 kDrawLines_DrawType == optState.drawType()); | 1372 kDrawLines_DrawType == optState.drawType()); |
1372 | 1373 |
1373 // This must come after textures are flushed because a texture may need | 1374 // This must come after textures are flushed because a texture may need |
1374 // to be msaa-resolved (which will modify bound FBO state). | 1375 // to be msaa-resolved (which will modify bound FBO state). |
1375 this->flushRenderTarget(glRT, NULL); | 1376 this->flushRenderTarget(glRT, NULL); |
1376 | 1377 |
1377 return true; | 1378 return true; |
1378 } | 1379 } |
1379 | 1380 |
1380 void GrGLGpu::setupGeometry(const GrOptDrawState& optState, | 1381 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
1381 const GrDrawTarget::DrawInfo& info, | 1382 const GrDrawTarget::DrawInfo& info, |
1382 size_t* indexOffsetInBytes) { | 1383 size_t* indexOffsetInBytes) { |
1383 GrGLVertexBuffer* vbuf; | 1384 GrGLVertexBuffer* vbuf; |
1384 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); | 1385 vbuf = (GrGLVertexBuffer*) info.vertexBuffer(); |
1385 | 1386 |
1386 SkASSERT(vbuf); | 1387 SkASSERT(vbuf); |
1387 SkASSERT(!vbuf->isMapped()); | 1388 SkASSERT(!vbuf->isMapped()); |
1388 | 1389 |
1389 GrGLIndexBuffer* ibuf = NULL; | 1390 GrGLIndexBuffer* ibuf = NULL; |
1390 if (info.isIndexed()) { | 1391 if (info.isIndexed()) { |
1391 SkASSERT(indexOffsetInBytes); | 1392 SkASSERT(indexOffsetInBytes); |
1392 | 1393 |
1393 *indexOffsetInBytes = 0; | 1394 *indexOffsetInBytes = 0; |
1394 ibuf = (GrGLIndexBuffer*)info.indexBuffer(); | 1395 ibuf = (GrGLIndexBuffer*)info.indexBuffer(); |
1395 | 1396 |
1396 SkASSERT(ibuf); | 1397 SkASSERT(ibuf); |
1397 SkASSERT(!ibuf->isMapped()); | 1398 SkASSERT(!ibuf->isMapped()); |
1398 *indexOffsetInBytes += ibuf->baseOffset(); | 1399 *indexOffsetInBytes += ibuf->baseOffset(); |
1399 } | 1400 } |
1400 GrGLAttribArrayState* attribState = | 1401 GrGLAttribArrayState* attribState = |
1401 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | 1402 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); |
1402 | 1403 |
1403 const GrPrimitiveProcessor* primProc = optState.getPrimitiveProcessor(); | 1404 int vaCount = primProc.numAttribs(); |
1404 int vaCount = primProc->numAttribs(); | |
1405 if (vaCount > 0) { | 1405 if (vaCount > 0) { |
1406 | 1406 |
1407 GrGLsizei stride = static_cast<GrGLsizei>(primProc->getVertexStride()); | 1407 GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride()); |
1408 | 1408 |
1409 size_t vertexOffsetInBytes = stride * info.startVertex(); | 1409 size_t vertexOffsetInBytes = stride * info.startVertex(); |
1410 | 1410 |
1411 vertexOffsetInBytes += vbuf->baseOffset(); | 1411 vertexOffsetInBytes += vbuf->baseOffset(); |
1412 | 1412 |
1413 uint32_t usedAttribArraysMask = 0; | 1413 uint32_t usedAttribArraysMask = 0; |
1414 size_t offset = 0; | 1414 size_t offset = 0; |
1415 | 1415 |
1416 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { | 1416 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
1417 const GrGeometryProcessor::Attribute& attrib = primProc->getAttrib(a
ttribIndex); | 1417 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at
tribIndex); |
1418 usedAttribArraysMask |= (1 << attribIndex); | 1418 usedAttribArraysMask |= (1 << attribIndex); |
1419 GrVertexAttribType attribType = attrib.fType; | 1419 GrVertexAttribType attribType = attrib.fType; |
1420 attribState->set(this, | 1420 attribState->set(this, |
1421 attribIndex, | 1421 attribIndex, |
1422 vbuf, | 1422 vbuf, |
1423 GrGLAttribTypeToLayout(attribType).fCount, | 1423 GrGLAttribTypeToLayout(attribType).fCount, |
1424 GrGLAttribTypeToLayout(attribType).fType, | 1424 GrGLAttribTypeToLayout(attribType).fType, |
1425 GrGLAttribTypeToLayout(attribType).fNormalized, | 1425 GrGLAttribTypeToLayout(attribType).fNormalized, |
1426 stride, | 1426 stride, |
1427 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o
ffset)); | 1427 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o
ffset)); |
1428 offset += attrib.fOffset; | 1428 offset += attrib.fOffset; |
1429 } | 1429 } |
1430 attribState->disableUnusedArrays(this, usedAttribArraysMask); | 1430 attribState->disableUnusedArrays(this, usedAttribArraysMask); |
1431 } | 1431 } |
1432 } | 1432 } |
1433 | 1433 |
1434 void GrGLGpu::buildProgramDesc(const GrOptDrawState& optState, | 1434 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc, |
| 1435 const GrPrimitiveProcessor& primProc, |
| 1436 const GrOptDrawState& optState, |
1435 const GrProgramDesc::DescInfo& descInfo, | 1437 const GrProgramDesc::DescInfo& descInfo, |
1436 GrGpu::DrawType drawType, | 1438 GrGpu::DrawType drawType, |
1437 GrProgramDesc* desc) { | 1439 const GrBatchTracker& batchTracker) const { |
1438 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { | 1440 if (!GrGLProgramDescBuilder::Build(desc, primProc, optState, descInfo, drawT
ype, this, |
| 1441 batchTracker)) { |
1439 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 1442 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
1440 } | 1443 } |
1441 } | 1444 } |
1442 | 1445 |
1443 void GrGLGpu::disableScissor() { | 1446 void GrGLGpu::disableScissor() { |
1444 if (kNo_TriState != fHWScissorSettings.fEnabled) { | 1447 if (kNo_TriState != fHWScissorSettings.fEnabled) { |
1445 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); | 1448 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
1446 fHWScissorSettings.fEnabled = kNo_TriState; | 1449 fHWScissorSettings.fEnabled = kNo_TriState; |
1447 return; | 1450 return; |
1448 } | 1451 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 GetWindowThreadProcessId(hwnd, &wndProcID); | 1819 GetWindowThreadProcessId(hwnd, &wndProcID); |
1817 if(wndProcID == procID) { | 1820 if(wndProcID == procID) { |
1818 SwapBuffers(GetDC(hwnd)); | 1821 SwapBuffers(GetDC(hwnd)); |
1819 } | 1822 } |
1820 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); | 1823 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
1821 } | 1824 } |
1822 } | 1825 } |
1823 #endif | 1826 #endif |
1824 #endif | 1827 #endif |
1825 | 1828 |
1826 void GrGLGpu::onDraw(const GrOptDrawState& ds, const GrDrawTarget::DrawInfo& inf
o) { | 1829 void GrGLGpu::onDraw(const DrawArgs& args, const GrDrawTarget::DrawInfo& info) { |
1827 if (!this->flushGLState(ds)) { | 1830 if (!this->flushGLState(args)) { |
1828 return; | 1831 return; |
1829 } | 1832 } |
1830 | 1833 |
1831 size_t indexOffsetInBytes; | 1834 size_t indexOffsetInBytes = 0; |
1832 this->setupGeometry(ds, info, &indexOffsetInBytes); | 1835 this->setupGeometry(*args.fPrimitiveProcessor, info, &indexOffsetInBytes); |
1833 | 1836 |
1834 SkASSERT((size_t)info.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GLMode
)); | 1837 SkASSERT((size_t)info.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GLMode
)); |
1835 | 1838 |
1836 if (info.isIndexed()) { | 1839 if (info.isIndexed()) { |
1837 GrGLvoid* indices = | 1840 GrGLvoid* indices = |
1838 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
info.startIndex()); | 1841 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
info.startIndex()); |
1839 // info.startVertex() was accounted for by setupGeometry. | 1842 // info.startVertex() was accounted for by setupGeometry. |
1840 GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], | 1843 GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], |
1841 info.indexCount(), | 1844 info.indexCount(), |
1842 GR_GL_UNSIGNED_SHORT, | 1845 GR_GL_UNSIGNED_SHORT, |
(...skipping 25 matching lines...) Expand all Loading... |
1868 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); | 1871 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); |
1869 SkISize size = SkISize::Make(rt->width(), rt->height()); | 1872 SkISize size = SkISize::Make(rt->width(), rt->height()); |
1870 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o
rigin()); | 1873 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o
rigin()); |
1871 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); | 1874 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); |
1872 this->flushHWAAState(rt, state.fUseHWAA, false); | 1875 this->flushHWAAState(rt, state.fUseHWAA, false); |
1873 this->flushRenderTarget(rt, NULL); | 1876 this->flushRenderTarget(rt, NULL); |
1874 | 1877 |
1875 fPathRendering->stencilPath(path, *state.fStencil); | 1878 fPathRendering->stencilPath(path, *state.fStencil); |
1876 } | 1879 } |
1877 | 1880 |
1878 void GrGLGpu::onDrawPath(const GrOptDrawState& ds, const GrPath* path, | 1881 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, |
1879 const GrStencilSettings& stencil) { | 1882 const GrStencilSettings& stencil) { |
1880 if (!this->flushGLState(ds)) { | 1883 if (!this->flushGLState(args)) { |
1881 return; | 1884 return; |
1882 } | 1885 } |
1883 fPathRendering->drawPath(path, stencil); | 1886 fPathRendering->drawPath(path, stencil); |
1884 } | 1887 } |
1885 | 1888 |
1886 void GrGLGpu::onDrawPaths(const GrOptDrawState& ds, | 1889 void GrGLGpu::onDrawPaths(const DrawArgs& args, |
1887 const GrPathRange* pathRange, | 1890 const GrPathRange* pathRange, |
1888 const void* indices, | 1891 const void* indices, |
1889 GrDrawTarget::PathIndexType indexType, | 1892 GrDrawTarget::PathIndexType indexType, |
1890 const float transformValues[], | 1893 const float transformValues[], |
1891 GrDrawTarget::PathTransformType transformType, | 1894 GrDrawTarget::PathTransformType transformType, |
1892 int count, | 1895 int count, |
1893 const GrStencilSettings& stencil) { | 1896 const GrStencilSettings& stencil) { |
1894 if (!this->flushGLState(ds)) { | 1897 if (!this->flushGLState(args)) { |
1895 return; | 1898 return; |
1896 } | 1899 } |
1897 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, | 1900 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, |
1898 transformType, count, stencil); | 1901 transformType, count, stencil); |
1899 } | 1902 } |
1900 | 1903 |
1901 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { | 1904 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
1902 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1905 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
1903 if (rt->needsResolve()) { | 1906 if (rt->needsResolve()) { |
1904 // Some extensions automatically resolves the texture when it is read. | 1907 // Some extensions automatically resolves the texture when it is read. |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2742 this->setVertexArrayID(gpu, 0); | 2745 this->setVertexArrayID(gpu, 0); |
2743 } | 2746 } |
2744 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2747 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2745 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2748 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2746 fDefaultVertexArrayAttribState.resize(attrCount); | 2749 fDefaultVertexArrayAttribState.resize(attrCount); |
2747 } | 2750 } |
2748 attribState = &fDefaultVertexArrayAttribState; | 2751 attribState = &fDefaultVertexArrayAttribState; |
2749 } | 2752 } |
2750 return attribState; | 2753 return attribState; |
2751 } | 2754 } |
OLD | NEW |