Chromium Code Reviews| 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 } | 641 } |
| 642 | 642 |
| 643 if (success) { | 643 if (success) { |
| 644 glTex->texturePriv().dirtyMipMaps(true); | 644 glTex->texturePriv().dirtyMipMaps(true); |
| 645 return true; | 645 return true; |
| 646 } | 646 } |
| 647 | 647 |
| 648 return false; | 648 return false; |
| 649 } | 649 } |
| 650 | 650 |
| 651 bool GrGLGpu::onTransferPixels(GrSurface* surface, | |
| 652 int left, int top, int width, int height, | |
| 653 GrPixelConfig config, GrTransferBuffer* buffer, | |
| 654 size_t offset, size_t rowBytes) { | |
| 655 SkASSERT(!buffer->isMapped()); | |
| 656 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer) ; | |
| 657 // bind the transfer buffer | |
| 658 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || | |
| 659 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferT ype()); | |
|
bsalomon
2015/12/18 15:24:38
align?
jvanverth1
2016/01/04 21:24:09
Done.
| |
| 660 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); | |
| 661 | |
| 662 bool result = onWritePixels(surface, left, top, width, height, config, | |
|
bsalomon
2015/12/18 15:24:38
this->
jvanverth1
2016/01/04 21:24:09
Done.
| |
| 663 (void*) offset, rowBytes); | |
| 664 | |
| 665 // unbind | |
| 666 GL_CALL(BindBuffer(glBuffer->bufferType(), 0)); | |
|
bsalomon
2015/12/18 15:24:38
should we lazily unbind when we see a call to writ
jvanverth1
2016/01/04 21:24:09
I'm not sure we need an unbind -- removed.
| |
| 667 | |
| 668 return result; | |
| 669 } | |
| 670 | |
| 651 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 671 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
| 652 const GrGLInterface* interface) { | 672 const GrGLInterface* interface) { |
| 653 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 673 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
| 654 return GR_GL_GET_ERROR(interface); | 674 return GR_GL_GET_ERROR(interface); |
| 655 } else { | 675 } else { |
| 656 return CHECK_ALLOC_ERROR(interface); | 676 return CHECK_ALLOC_ERROR(interface); |
| 657 } | 677 } |
| 658 } | 678 } |
| 659 | 679 |
| 660 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 680 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
| 661 GrGLenum target, | 681 GrGLenum target, |
| 662 bool isNewTexture, | 682 bool isNewTexture, |
| 663 int left, int top, int width, int height, | 683 int left, int top, int width, int height, |
| 664 GrPixelConfig dataConfig, | 684 GrPixelConfig dataConfig, |
| 665 const void* data, | 685 const void* data, |
| 666 size_t rowBytes) { | 686 size_t rowBytes) { |
| 667 SkASSERT(data || isNewTexture); | 687 //*** for now SkASSERT(data || isNewTexture); |
|
bsalomon
2015/12/18 15:24:38
b/c data might be an offset? Maybe we should renam
jvanverth1
2016/01/04 21:24:09
Rewrote this to take an upload type -- some of the
| |
| 668 | 688 |
| 669 // If we're uploading compressed data then we should be using uploadCompress edTexData | 689 // If we're uploading compressed data then we should be using uploadCompress edTexData |
| 670 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 690 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 671 | 691 |
| 672 size_t bpp = GrBytesPerPixel(dataConfig); | 692 size_t bpp = GrBytesPerPixel(dataConfig); |
| 673 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top, | 693 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top, |
| 674 &width, &height, &data, &rowBytes )) { | 694 &width, &height, &data, &rowBytes )) { |
| 675 return false; | 695 return false; |
| 676 } | 696 } |
| 677 size_t trimRowBytes = width * bpp; | 697 size_t trimRowBytes = width * bpp; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 // TODO: This function is using a lot of wonky semantics like, if width == -1 | 852 // TODO: This function is using a lot of wonky semantics like, if width == -1 |
| 833 // then set width = desc.fWdith ... blah. A better way to do it might be to | 853 // then set width = desc.fWdith ... blah. A better way to do it might be to |
| 834 // create a CompressedTexData struct that takes a desc/ptr and figures out | 854 // create a CompressedTexData struct that takes a desc/ptr and figures out |
| 835 // the proper upload semantics. Then users can construct this function how they | 855 // the proper upload semantics. Then users can construct this function how they |
| 836 // see fit if they want to go against the "standard" way to do it. | 856 // see fit if they want to go against the "standard" way to do it. |
| 837 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, | 857 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, |
| 838 GrGLenum target, | 858 GrGLenum target, |
| 839 const void* data, | 859 const void* data, |
| 840 bool isNewTexture, | 860 bool isNewTexture, |
| 841 int left, int top, int width, int height) { | 861 int left, int top, int width, int height) { |
| 842 SkASSERT(data || isNewTexture); | 862 //*** for now SkASSERT(data || isNewTexture); |
| 843 | 863 |
| 844 // No support for software flip y, yet... | 864 // No support for software flip y, yet... |
| 845 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 865 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 846 | 866 |
| 847 if (-1 == width) { | 867 if (-1 == width) { |
| 848 width = desc.fWidth; | 868 width = desc.fWidth; |
| 849 } | 869 } |
| 850 #ifdef SK_DEBUG | 870 #ifdef SK_DEBUG |
| 851 else { | 871 else { |
| 852 SkASSERT(width <= desc.fWidth); | 872 SkASSERT(width <= desc.fWidth); |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1492 GrGLTransferBuffer::Desc desc; | 1512 GrGLTransferBuffer::Desc desc; |
| 1493 bool toGpu = (kCpuToGpu_TransferType == xferType); | 1513 bool toGpu = (kCpuToGpu_TransferType == xferType); |
| 1494 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS treamRead_Usage; | 1514 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS treamRead_Usage; |
| 1495 | 1515 |
| 1496 desc.fSizeInBytes = size; | 1516 desc.fSizeInBytes = size; |
| 1497 desc.fID = 0; | 1517 desc.fID = 0; |
| 1498 GL_CALL(GenBuffers(1, &desc.fID)); | 1518 GL_CALL(GenBuffers(1, &desc.fID)); |
| 1499 if (desc.fID) { | 1519 if (desc.fID) { |
| 1500 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1520 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1501 // make sure driver can allocate memory for this bmapuffer | 1521 // make sure driver can allocate memory for this bmapuffer |
| 1502 GrGLenum type; | 1522 GrGLenum target; |
| 1503 if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) { | 1523 if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) { |
| 1504 type = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM | 1524 target = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM |
| 1505 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; | 1525 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; |
| 1506 } else { | 1526 } else { |
| 1507 SkASSERT(GrGLCaps::kPBO_TransferBufferType == xferBufferType); | 1527 SkASSERT(GrGLCaps::kPBO_TransferBufferType == xferBufferType); |
| 1508 type = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER; | 1528 target = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER ; |
| 1509 } | 1529 } |
| 1510 GL_ALLOC_CALL(this->glInterface(), | 1530 GL_CALL(BindBuffer(target, desc.fID)); |
| 1511 BufferData(type, | 1531 GL_ALLOC_CALL(this->glInterface(), |
| 1532 BufferData(target, | |
| 1512 (GrGLsizeiptr) desc.fSizeInBytes, | 1533 (GrGLsizeiptr) desc.fSizeInBytes, |
| 1513 nullptr, // data ptr | 1534 nullptr, // data ptr |
| 1514 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) )); | 1535 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) )); |
| 1515 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { | 1536 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1516 GL_CALL(DeleteBuffers(1, &desc.fID)); | 1537 GL_CALL(DeleteBuffers(1, &desc.fID)); |
| 1517 return nullptr; | 1538 return nullptr; |
| 1518 } | 1539 } |
| 1519 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty pe); | 1540 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ta rget); |
| 1520 return transferBuffer; | 1541 return transferBuffer; |
| 1521 } | 1542 } |
| 1522 | 1543 |
| 1523 return nullptr; | 1544 return nullptr; |
| 1524 } | 1545 } |
| 1525 | 1546 |
| 1526 void GrGLGpu::flushScissor(const GrScissorState& scissorState, | 1547 void GrGLGpu::flushScissor(const GrScissorState& scissorState, |
| 1527 const GrGLIRect& rtViewport, | 1548 const GrGLIRect& rtViewport, |
| 1528 GrSurfaceOrigin rtOrigin) { | 1549 GrSurfaceOrigin rtOrigin) { |
| 1529 if (scissorState.enabled()) { | 1550 if (scissorState.enabled()) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1709 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1730 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1710 } | 1731 } |
| 1711 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_ GL_WRITE_ONLY)); | 1732 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_ GL_WRITE_ONLY)); |
| 1712 break; | 1733 break; |
| 1713 case GrGLCaps::kMapBufferRange_MapBufferType: { | 1734 case GrGLCaps::kMapBufferRange_MapBufferType: { |
| 1714 this->bindBuffer(id, type); | 1735 this->bindBuffer(id, type); |
| 1715 // Make sure the GL buffer size agrees with fDesc before mapping. | 1736 // Make sure the GL buffer size agrees with fDesc before mapping. |
| 1716 if (currentSize != requestedSize) { | 1737 if (currentSize != requestedSize) { |
| 1717 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1738 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1718 } | 1739 } |
| 1719 static const GrGLbitfield kWriteAccess = GR_GL_MAP_INVALIDATE_BUFFER _BIT | | 1740 GrGLbitfield writeAccess = GR_GL_MAP_WRITE_BIT; |
| 1720 GR_GL_MAP_WRITE_BIT; | 1741 // TODO: allow the client to specify invalidation in the stream draw case |
| 1742 if (GrGLBufferImpl::kStreamDraw_Usage != usage) { | |
| 1743 writeAccess |= GR_GL_MAP_INVALIDATE_BUFFER_BIT; | |
| 1744 } | |
| 1721 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly ? | 1745 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly ? |
| 1722 GR_GL_MAP _READ_BIT : | 1746 GR_GL_MAP _READ_BIT : |
| 1723 kWriteAcc ess)); | 1747 writeAcce ss)); |
| 1724 break; | 1748 break; |
| 1725 } | 1749 } |
| 1726 case GrGLCaps::kChromium_MapBufferType: | 1750 case GrGLCaps::kChromium_MapBufferType: |
| 1727 this->bindBuffer(id, type); | 1751 this->bindBuffer(id, type); |
| 1728 // Make sure the GL buffer size agrees with fDesc before mapping. | 1752 // Make sure the GL buffer size agrees with fDesc before mapping. |
| 1729 if (currentSize != requestedSize) { | 1753 if (currentSize != requestedSize) { |
| 1730 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1754 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
| 1731 } | 1755 } |
| 1732 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl y ? | 1756 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl y ? |
| 1733 GR_GL_R EAD_ONLY : | 1757 GR_GL_R EAD_ONLY : |
| (...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3627 this->setVertexArrayID(gpu, 0); | 3651 this->setVertexArrayID(gpu, 0); |
| 3628 } | 3652 } |
| 3629 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3653 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3630 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3654 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3631 fDefaultVertexArrayAttribState.resize(attrCount); | 3655 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3632 } | 3656 } |
| 3633 attribState = &fDefaultVertexArrayAttribState; | 3657 attribState = &fDefaultVertexArrayAttribState; |
| 3634 } | 3658 } |
| 3635 return attribState; | 3659 return attribState; |
| 3636 } | 3660 } |
| OLD | NEW |