| 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 "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 this->notifyIndexBufferDelete(desc.fID); | 1472 this->notifyIndexBufferDelete(desc.fID); |
| 1473 return nullptr; | 1473 return nullptr; |
| 1474 } | 1474 } |
| 1475 GrIndexBuffer* indexBuffer = new GrGLIndexBuffer(this, desc); | 1475 GrIndexBuffer* indexBuffer = new GrGLIndexBuffer(this, desc); |
| 1476 return indexBuffer; | 1476 return indexBuffer; |
| 1477 } | 1477 } |
| 1478 return nullptr; | 1478 return nullptr; |
| 1479 } | 1479 } |
| 1480 } | 1480 } |
| 1481 | 1481 |
| 1482 GrTransferBuffer* GrGLGpu::onCreateTransferBuffer(size_t size, TransferType type
) { | 1482 GrTransferBuffer* GrGLGpu::onCreateTransferBuffer(size_t size, TransferType xfer
Type) { |
| 1483 GrGLCaps::TransferBufferType xferBufferType = this->ctxInfo().caps()->transf
erBufferType(); |
| 1484 if (GrGLCaps::kNone_TransferBufferType == xferBufferType) { |
| 1485 return nullptr; |
| 1486 } |
| 1487 |
| 1483 GrGLTransferBuffer::Desc desc; | 1488 GrGLTransferBuffer::Desc desc; |
| 1484 bool toGpu = (kCpuToGpu_TransferType == type); | 1489 bool toGpu = (kCpuToGpu_TransferType == xferType); |
| 1485 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS
treamRead_Usage; | 1490 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS
treamRead_Usage; |
| 1486 | 1491 |
| 1487 desc.fSizeInBytes = size; | 1492 desc.fSizeInBytes = size; |
| 1488 | 1493 |
| 1489 // TODO: check caps to see if we can create a PBO, and which kind | |
| 1490 GL_CALL(GenBuffers(1, &desc.fID)); | 1494 GL_CALL(GenBuffers(1, &desc.fID)); |
| 1491 if (desc.fID) { | 1495 if (desc.fID) { |
| 1492 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1496 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1493 // make sure driver can allocate memory for this buffer | 1497 // make sure driver can allocate memory for this bmapuffer |
| 1494 GrGLenum type = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUF
FER; | 1498 GrGLenum type; |
| 1499 if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) { |
| 1500 type = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM |
| 1501 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; |
| 1502 } else { |
| 1503 SkASSERT(GrGLCaps::kPBO_TransferBufferType == xferBufferType); |
| 1504 type = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER; |
| 1505 } |
| 1495 GL_ALLOC_CALL(this->glInterface(), | 1506 GL_ALLOC_CALL(this->glInterface(), |
| 1496 BufferData(type, | 1507 BufferData(type, |
| 1497 (GrGLsizeiptr) desc.fSizeInBytes, | 1508 (GrGLsizeiptr) desc.fSizeInBytes, |
| 1498 nullptr, // data ptr | 1509 nullptr, // data ptr |
| 1499 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ)
)); | 1510 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ)
)); |
| 1500 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { | 1511 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1501 GL_CALL(DeleteBuffers(1, &desc.fID)); | 1512 GL_CALL(DeleteBuffers(1, &desc.fID)); |
| 1502 return nullptr; | 1513 return nullptr; |
| 1503 } | 1514 } |
| 1504 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty
pe); | 1515 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty
pe); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 1654 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
| 1644 } | 1655 } |
| 1645 } | 1656 } |
| 1646 | 1657 |
| 1647 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { | 1658 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { |
| 1648 this->handleDirtyContext(); | 1659 this->handleDirtyContext(); |
| 1649 if (GR_GL_ARRAY_BUFFER == type) { | 1660 if (GR_GL_ARRAY_BUFFER == type) { |
| 1650 this->bindVertexBuffer(id); | 1661 this->bindVertexBuffer(id); |
| 1651 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { | 1662 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { |
| 1652 this->bindIndexBufferAndDefaultVertexArray(id); | 1663 this->bindIndexBufferAndDefaultVertexArray(id); |
| 1664 } else { |
| 1665 GR_GL_CALL(this->glInterface(), BindBuffer(type, id)); |
| 1653 } | 1666 } |
| 1654 } | 1667 } |
| 1655 | 1668 |
| 1656 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) { | 1669 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) { |
| 1657 this->handleDirtyContext(); | 1670 this->handleDirtyContext(); |
| 1658 GL_CALL(DeleteBuffers(1, &id)); | 1671 GL_CALL(DeleteBuffers(1, &id)); |
| 1659 if (GR_GL_ARRAY_BUFFER == type) { | 1672 if (GR_GL_ARRAY_BUFFER == type) { |
| 1660 this->notifyVertexBufferDelete(id); | 1673 this->notifyVertexBufferDelete(id); |
| 1661 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { | 1674 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { |
| 1662 this->notifyIndexBufferDelete(id); | 1675 this->notifyIndexBufferDelete(id); |
| 1663 } | 1676 } |
| 1664 } | 1677 } |
| 1665 | 1678 |
| 1666 static GrGLenum get_gl_usage(GrGLBufferImpl::Usage usage) { | 1679 static GrGLenum get_gl_usage(GrGLBufferImpl::Usage usage) { |
| 1667 static const GrGLenum grToGL[] = { | 1680 static const GrGLenum grToGL[] = { |
| 1668 GR_GL_STATIC_DRAW, // GrGLBufferImpl::kStaticDraw_Usage | 1681 GR_GL_STATIC_DRAW, // GrGLBufferImpl::kStaticDraw_Usage |
| 1669 DYNAMIC_USAGE_PARAM, // GrGLBufferImpl::kDynamicDraw_Usage | 1682 DYNAMIC_USAGE_PARAM, // GrGLBufferImpl::kDynamicDraw_Usage |
| 1670 GR_GL_STREAM_DRAW, // GrGLBufferImpl::kStreamDraw_Usage | 1683 GR_GL_STREAM_DRAW, // GrGLBufferImpl::kStreamDraw_Usage |
| 1671 GR_GL_STREAM_READ, // GrGLBufferImpl::kStreamRead_Usage | 1684 GR_GL_STREAM_READ, // GrGLBufferImpl::kStreamRead_Usage |
| 1672 }; | 1685 }; |
| 1673 static_assert(SK_ARRAY_COUNT(grToGL) == GrGLBufferImpl::kUsageCount, "array_
size_mismatch"); | 1686 static_assert(SK_ARRAY_COUNT(grToGL) == GrGLBufferImpl::kUsageCount, "array_
size_mismatch"); |
| 1674 | 1687 |
| 1675 return grToGL[usage]; | 1688 return grToGL[usage]; |
| 1676 } | 1689 } |
| 1677 | 1690 |
| 1678 void* GrGLGpu::mapBuffer(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage
, | 1691 void* GrGLGpu::mapBuffer(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage
, |
| 1679 size_t currentSize, size_t requestedSize) { | 1692 size_t currentSize, size_t requestedSize) { |
| 1680 void* mapPtr = nullptr; | 1693 void* mapPtr = nullptr; |
| 1681 GrGLenum glUsage = get_gl_usage(usage); | 1694 GrGLenum glUsage = get_gl_usage(usage); |
| 1695 bool readOnly = (GrGLBufferImpl::kStreamRead_Usage == usage); |
| 1696 |
| 1682 // Handling dirty context is done in the bindBuffer call | 1697 // Handling dirty context is done in the bindBuffer call |
| 1683 switch (this->glCaps().mapBufferType()) { | 1698 switch (this->glCaps().mapBufferType()) { |
| 1684 case GrGLCaps::kNone_MapBufferType: | 1699 case GrGLCaps::kNone_MapBufferType: |
| 1685 break; | 1700 break; |
| 1686 case GrGLCaps::kMapBuffer_MapBufferType: | 1701 case GrGLCaps::kMapBuffer_MapBufferType: |
| 1687 this->bindBuffer(id, type); | 1702 this->bindBuffer(id, type); |
| 1688 // Let driver know it can discard the old data | 1703 // Let driver know it can discard the old data |
| 1689 if (GR_GL_USE_BUFFER_DATA_NULL_HINT || currentSize != requestedSize)
{ | 1704 if (GR_GL_USE_BUFFER_DATA_NULL_HINT || currentSize != requestedSize)
{ |
| 1690 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1705 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1691 } | 1706 } |
| 1692 GL_CALL_RET(mapPtr, MapBuffer(type, GR_GL_WRITE_ONLY)); | 1707 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_
GL_WRITE_ONLY)); |
| 1693 break; | 1708 break; |
| 1694 case GrGLCaps::kMapBufferRange_MapBufferType: { | 1709 case GrGLCaps::kMapBufferRange_MapBufferType: { |
| 1695 this->bindBuffer(id, type); | 1710 this->bindBuffer(id, type); |
| 1696 // Make sure the GL buffer size agrees with fDesc before mapping. | 1711 // Make sure the GL buffer size agrees with fDesc before mapping. |
| 1697 if (currentSize != requestedSize) { | 1712 if (currentSize != requestedSize) { |
| 1698 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1713 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1699 } | 1714 } |
| 1700 static const GrGLbitfield kAccess = GR_GL_MAP_INVALIDATE_BUFFER_BIT
| | 1715 static const GrGLbitfield kWriteAccess = GR_GL_MAP_INVALIDATE_BUFFER
_BIT | |
| 1701 GR_GL_MAP_WRITE_BIT; | 1716 GR_GL_MAP_WRITE_BIT; |
| 1702 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, kAccess))
; | 1717 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly
? |
| 1718 GR_GL_MAP
_READ_BIT : |
| 1719 kWriteAcc
ess)); |
| 1703 break; | 1720 break; |
| 1704 } | 1721 } |
| 1705 case GrGLCaps::kChromium_MapBufferType: | 1722 case GrGLCaps::kChromium_MapBufferType: |
| 1706 this->bindBuffer(id, type); | 1723 this->bindBuffer(id, type); |
| 1707 // Make sure the GL buffer size agrees with fDesc before mapping. | 1724 // Make sure the GL buffer size agrees with fDesc before mapping. |
| 1708 if (currentSize != requestedSize) { | 1725 if (currentSize != requestedSize) { |
| 1709 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1726 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1710 } | 1727 } |
| 1711 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, GR_GL_W
RITE_ONLY)); | 1728 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl
y ? |
| 1729 GR_GL_R
EAD_ONLY : |
| 1730 GR_GL_W
RITE_ONLY)); |
| 1712 break; | 1731 break; |
| 1713 } | 1732 } |
| 1714 return mapPtr; | 1733 return mapPtr; |
| 1715 } | 1734 } |
| 1716 | 1735 |
| 1717 void GrGLGpu::bufferData(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage
, | 1736 void GrGLGpu::bufferData(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage
, |
| 1718 size_t currentSize, const void* src, size_t srcSizeInBy
tes) { | 1737 size_t currentSize, const void* src, size_t srcSizeInBy
tes) { |
| 1719 SkASSERT(srcSizeInBytes <= currentSize); | 1738 SkASSERT(srcSizeInBytes <= currentSize); |
| 1720 // bindbuffer handles dirty context | 1739 // bindbuffer handles dirty context |
| 1721 this->bindBuffer(id, type); | 1740 this->bindBuffer(id, type); |
| (...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3603 this->setVertexArrayID(gpu, 0); | 3622 this->setVertexArrayID(gpu, 0); |
| 3604 } | 3623 } |
| 3605 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3624 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3606 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3625 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3607 fDefaultVertexArrayAttribState.resize(attrCount); | 3626 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3608 } | 3627 } |
| 3609 attribState = &fDefaultVertexArrayAttribState; | 3628 attribState = &fDefaultVertexArrayAttribState; |
| 3610 } | 3629 } |
| 3611 return attribState; | 3630 return attribState; |
| 3612 } | 3631 } |
| OLD | NEW |