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

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

Issue 1503593002: Add transfer buffer to GLCaps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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/GrGLDefines.h ('k') | no next file » | 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 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 == type);
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::kPBO_TransferBufferType == xferBufferType) {
1500 type = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER;
1501 } else if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) {
1502 type = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM
1503 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM;
1504 } else {
1505 SkASSERT(false);
1506 }
1495 GL_ALLOC_CALL(this->glInterface(), 1507 GL_ALLOC_CALL(this->glInterface(),
1496 BufferData(type, 1508 BufferData(type,
1497 (GrGLsizeiptr) desc.fSizeInBytes, 1509 (GrGLsizeiptr) desc.fSizeInBytes,
1498 nullptr, // data ptr 1510 nullptr, // data ptr
1499 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) )); 1511 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) ));
1500 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { 1512 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) {
1501 GL_CALL(DeleteBuffers(1, &desc.fID)); 1513 GL_CALL(DeleteBuffers(1, &desc.fID));
1502 return nullptr; 1514 return nullptr;
1503 } 1515 }
1504 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty pe); 1516 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty pe);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 SkDEBUGFAIL("Failed to generate GL program descriptor"); 1655 SkDEBUGFAIL("Failed to generate GL program descriptor");
1644 } 1656 }
1645 } 1657 }
1646 1658
1647 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { 1659 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) {
1648 this->handleDirtyContext(); 1660 this->handleDirtyContext();
1649 if (GR_GL_ARRAY_BUFFER == type) { 1661 if (GR_GL_ARRAY_BUFFER == type) {
1650 this->bindVertexBuffer(id); 1662 this->bindVertexBuffer(id);
1651 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { 1663 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) {
1652 this->bindIndexBufferAndDefaultVertexArray(id); 1664 this->bindIndexBufferAndDefaultVertexArray(id);
1665 } else {
1666 GR_GL_CALL(this->glInterface(), BindBuffer(type, id));
1653 } 1667 }
1654 } 1668 }
1655 1669
1656 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) { 1670 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) {
1657 this->handleDirtyContext(); 1671 this->handleDirtyContext();
1658 GL_CALL(DeleteBuffers(1, &id)); 1672 GL_CALL(DeleteBuffers(1, &id));
1659 if (GR_GL_ARRAY_BUFFER == type) { 1673 if (GR_GL_ARRAY_BUFFER == type) {
1660 this->notifyVertexBufferDelete(id); 1674 this->notifyVertexBufferDelete(id);
1661 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { 1675 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) {
1662 this->notifyIndexBufferDelete(id); 1676 this->notifyIndexBufferDelete(id);
1663 } 1677 }
1664 } 1678 }
1665 1679
1666 static GrGLenum get_gl_usage(GrGLBufferImpl::Usage usage) { 1680 static GrGLenum get_gl_usage(GrGLBufferImpl::Usage usage) {
1667 static const GrGLenum grToGL[] = { 1681 static const GrGLenum grToGL[] = {
1668 GR_GL_STATIC_DRAW, // GrGLBufferImpl::kStaticDraw_Usage 1682 GR_GL_STATIC_DRAW, // GrGLBufferImpl::kStaticDraw_Usage
1669 DYNAMIC_USAGE_PARAM, // GrGLBufferImpl::kDynamicDraw_Usage 1683 DYNAMIC_USAGE_PARAM, // GrGLBufferImpl::kDynamicDraw_Usage
1670 GR_GL_STREAM_DRAW, // GrGLBufferImpl::kStreamDraw_Usage 1684 GR_GL_STREAM_DRAW, // GrGLBufferImpl::kStreamDraw_Usage
1671 GR_GL_STREAM_READ, // GrGLBufferImpl::kStreamRead_Usage 1685 GR_GL_STREAM_READ, // GrGLBufferImpl::kStreamRead_Usage
1672 }; 1686 };
1673 static_assert(SK_ARRAY_COUNT(grToGL) == GrGLBufferImpl::kUsageCount, "array_ size_mismatch"); 1687 static_assert(SK_ARRAY_COUNT(grToGL) == GrGLBufferImpl::kUsageCount, "array_ size_mismatch");
1674 1688
1675 return grToGL[usage]; 1689 return grToGL[usage];
1676 } 1690 }
1677 1691
1678 void* GrGLGpu::mapBuffer(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage , 1692 void* GrGLGpu::mapBuffer(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage ,
1679 size_t currentSize, size_t requestedSize) { 1693 size_t currentSize, size_t requestedSize) {
1680 void* mapPtr = nullptr; 1694 void* mapPtr = nullptr;
1681 GrGLenum glUsage = get_gl_usage(usage); 1695 GrGLenum glUsage = get_gl_usage(usage);
1696 bool readOnly = (GrGLBufferImpl::kStreamRead_Usage == usage);
1697
1682 // Handling dirty context is done in the bindBuffer call 1698 // Handling dirty context is done in the bindBuffer call
1683 switch (this->glCaps().mapBufferType()) { 1699 switch (this->glCaps().mapBufferType()) {
1684 case GrGLCaps::kNone_MapBufferType: 1700 case GrGLCaps::kNone_MapBufferType:
1685 break; 1701 break;
1686 case GrGLCaps::kMapBuffer_MapBufferType: 1702 case GrGLCaps::kMapBuffer_MapBufferType:
1687 this->bindBuffer(id, type); 1703 this->bindBuffer(id, type);
1688 // Let driver know it can discard the old data 1704 // Let driver know it can discard the old data
1689 if (GR_GL_USE_BUFFER_DATA_NULL_HINT || currentSize != requestedSize) { 1705 if (GR_GL_USE_BUFFER_DATA_NULL_HINT || currentSize != requestedSize) {
1690 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); 1706 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage));
1691 } 1707 }
1692 GL_CALL_RET(mapPtr, MapBuffer(type, GR_GL_WRITE_ONLY)); 1708 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_ GL_WRITE_ONLY));
1693 break; 1709 break;
1694 case GrGLCaps::kMapBufferRange_MapBufferType: { 1710 case GrGLCaps::kMapBufferRange_MapBufferType: {
1695 this->bindBuffer(id, type); 1711 this->bindBuffer(id, type);
1696 // Make sure the GL buffer size agrees with fDesc before mapping. 1712 // Make sure the GL buffer size agrees with fDesc before mapping.
1697 if (currentSize != requestedSize) { 1713 if (currentSize != requestedSize) {
1698 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); 1714 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage));
1699 } 1715 }
1700 static const GrGLbitfield kAccess = GR_GL_MAP_INVALIDATE_BUFFER_BIT | 1716 static const GrGLbitfield kWriteAccess = GR_GL_MAP_INVALIDATE_BUFFER _BIT |
jvanverth1 2015/12/07 14:27:04 I realized over the weekend that I need to fix thi
1701 GR_GL_MAP_WRITE_BIT; 1717 GR_GL_MAP_WRITE_BIT;
1702 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, kAccess)) ; 1718 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly ?
1719 GR_GL_MAP _READ_BIT :
1720 kWriteAcc ess));
1703 break; 1721 break;
1704 } 1722 }
1705 case GrGLCaps::kChromium_MapBufferType: 1723 case GrGLCaps::kChromium_MapBufferType:
1706 this->bindBuffer(id, type); 1724 this->bindBuffer(id, type);
1707 // Make sure the GL buffer size agrees with fDesc before mapping. 1725 // Make sure the GL buffer size agrees with fDesc before mapping.
1708 if (currentSize != requestedSize) { 1726 if (currentSize != requestedSize) {
1709 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); 1727 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage));
1710 } 1728 }
1711 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, GR_GL_W RITE_ONLY)); 1729 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl y ?
1730 GR_GL_R EAD_ONLY :
1731 GR_GL_W RITE_ONLY));
1712 break; 1732 break;
1713 } 1733 }
1714 return mapPtr; 1734 return mapPtr;
1715 } 1735 }
1716 1736
1717 void GrGLGpu::bufferData(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage , 1737 void GrGLGpu::bufferData(GrGLuint id, GrGLenum type, GrGLBufferImpl::Usage usage ,
1718 size_t currentSize, const void* src, size_t srcSizeInBy tes) { 1738 size_t currentSize, const void* src, size_t srcSizeInBy tes) {
1719 SkASSERT(srcSizeInBytes <= currentSize); 1739 SkASSERT(srcSizeInBytes <= currentSize);
1720 // bindbuffer handles dirty context 1740 // bindbuffer handles dirty context
1721 this->bindBuffer(id, type); 1741 this->bindBuffer(id, type);
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
3603 this->setVertexArrayID(gpu, 0); 3623 this->setVertexArrayID(gpu, 0);
3604 } 3624 }
3605 int attrCount = gpu->glCaps().maxVertexAttributes(); 3625 int attrCount = gpu->glCaps().maxVertexAttributes();
3606 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3626 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3607 fDefaultVertexArrayAttribState.resize(attrCount); 3627 fDefaultVertexArrayAttribState.resize(attrCount);
3608 } 3628 }
3609 attribState = &fDefaultVertexArrayAttribState; 3629 attribState = &fDefaultVertexArrayAttribState;
3610 } 3630 }
3611 return attribState; 3631 return attribState;
3612 } 3632 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLDefines.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698