| 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 506 |
| 507 //////////////////////////////////////////////////////////////////////////////// | 507 //////////////////////////////////////////////////////////////////////////////// |
| 508 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 508 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 509 size_t rowBytes, GrPixelConfig srcConfig, | 509 size_t rowBytes, GrPixelConfig srcConfig, |
| 510 DrawPreference* drawPreference, | 510 DrawPreference* drawPreference, |
| 511 WritePixelTempDrawInfo* tempDrawInfo) { | 511 WritePixelTempDrawInfo* tempDrawInfo) { |
| 512 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { | 512 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { |
| 513 return false; | 513 return false; |
| 514 } | 514 } |
| 515 | 515 |
| 516 // This subclass only allows writes to textures. If the dst is not a texture
we have to draw |
| 517 // into it. We could use glDrawPixels on GLs that have it, but we don't toda
y. |
| 518 if (!dstSurface->asTexture()) { |
| 519 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 520 } |
| 521 |
| 516 tempDrawInfo->fSwapRAndB = false; | 522 tempDrawInfo->fSwapRAndB = false; |
| 517 | 523 |
| 518 // These settings we will always want if a temp draw is performed. Initially
set the config | 524 // These settings we will always want if a temp draw is performed. Initially
set the config |
| 519 // to srcConfig, though that may be modified if we decide to do a R/G swap. | 525 // to srcConfig, though that may be modified if we decide to do a R/G swap. |
| 520 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags; | 526 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags; |
| 521 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; | 527 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; |
| 522 tempDrawInfo->fTempSurfaceDesc.fWidth = width; | 528 tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 523 tempDrawInfo->fTempSurfaceDesc.fHeight = height; | 529 tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 524 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; | 530 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 525 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. | 531 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 546 } | 552 } |
| 547 | 553 |
| 548 if (!this->glCaps().unpackFlipYSupport() && | 554 if (!this->glCaps().unpackFlipYSupport() && |
| 549 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { | 555 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { |
| 550 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 556 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 551 } | 557 } |
| 552 | 558 |
| 553 return true; | 559 return true; |
| 554 } | 560 } |
| 555 | 561 |
| 556 bool GrGLGpu::onWriteTexturePixels(GrTexture* texture, | 562 bool GrGLGpu::onWritePixels(GrSurface* surface, |
| 557 int left, int top, int width, int height, | 563 int left, int top, int width, int height, |
| 558 GrPixelConfig config, const void* buffer, | 564 GrPixelConfig config, const void* buffer, |
| 559 size_t rowBytes) { | 565 size_t rowBytes) { |
| 560 if (NULL == buffer) { | 566 if (NULL == buffer) { |
| 561 return false; | 567 return false; |
| 562 } | 568 } |
| 563 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); | 569 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); |
| 570 if (!glTex) { |
| 571 return false; |
| 572 } |
| 564 | 573 |
| 565 this->setScratchTextureUnit(); | 574 this->setScratchTextureUnit(); |
| 566 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); | 575 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
| 567 | 576 |
| 568 bool success = false; | 577 bool success = false; |
| 569 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 578 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
| 570 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() | 579 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() |
| 571 SkASSERT(config == glTex->desc().fConfig); | 580 SkASSERT(config == glTex->desc().fConfig); |
| 572 success = this->uploadCompressedTexData(glTex->desc(), buffer, false, le
ft, top, width, | 581 success = this->uploadCompressedTexData(glTex->desc(), buffer, false, le
ft, top, width, |
| 573 height); | 582 height); |
| 574 } else { | 583 } else { |
| 575 success = this->uploadTexData(glTex->desc(), false, left, top, width, he
ight, config, | 584 success = this->uploadTexData(glTex->desc(), false, left, top, width, he
ight, config, |
| 576 buffer, rowBytes); | 585 buffer, rowBytes); |
| 577 } | 586 } |
| 578 | 587 |
| 579 if (success) { | 588 if (success) { |
| 580 texture->texturePriv().dirtyMipMaps(true); | 589 glTex->texturePriv().dirtyMipMaps(true); |
| 581 return true; | 590 return true; |
| 582 } | 591 } |
| 583 | 592 |
| 584 return false; | 593 return false; |
| 585 } | 594 } |
| 586 | 595 |
| 587 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 596 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
| 588 const GrGLInterface* interface) { | 597 const GrGLInterface* interface) { |
| 589 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 598 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
| 590 return GR_GL_GET_ERROR(interface); | 599 return GR_GL_GET_ERROR(interface); |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; | 1728 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; |
| 1720 } | 1729 } |
| 1721 | 1730 |
| 1722 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
size_t rowBytes, | 1731 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
size_t rowBytes, |
| 1723 GrPixelConfig readConfig, DrawPreference* draw
Preference, | 1732 GrPixelConfig readConfig, DrawPreference* draw
Preference, |
| 1724 ReadPixelTempDrawInfo* tempDrawInfo) { | 1733 ReadPixelTempDrawInfo* tempDrawInfo) { |
| 1725 if (GrPixelConfigIsCompressed(readConfig)) { | 1734 if (GrPixelConfigIsCompressed(readConfig)) { |
| 1726 return false; | 1735 return false; |
| 1727 } | 1736 } |
| 1728 | 1737 |
| 1738 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on |
| 1739 // GL versions that support it but we don't today. |
| 1740 if (!srcSurface->asRenderTarget()) { |
| 1741 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1742 } |
| 1743 |
| 1729 tempDrawInfo->fSwapRAndB = false; | 1744 tempDrawInfo->fSwapRAndB = false; |
| 1730 | 1745 |
| 1731 // These settings we will always want if a temp draw is performed. The confi
g is set below | 1746 // These settings we will always want if a temp draw is performed. The confi
g is set below |
| 1732 // depending on whether we want to do a R/B swap or not. | 1747 // depending on whether we want to do a R/B swap or not. |
| 1733 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 1748 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 1734 tempDrawInfo->fTempSurfaceDesc.fWidth = width; | 1749 tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 1735 tempDrawInfo->fTempSurfaceDesc.fHeight = height; | 1750 tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 1736 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; | 1751 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 1737 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. | 1752 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. |
| 1738 tempDrawInfo->fUseExactScratch = SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_
PARTIAL) && | 1753 tempDrawInfo->fUseExactScratch = SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_
PARTIAL) && |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1766 if (!srcAsRT) { | 1781 if (!srcAsRT) { |
| 1767 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 1782 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1768 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh
t, readConfig, | 1783 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh
t, readConfig, |
| 1769 rowBytes)) { | 1784 rowBytes)) { |
| 1770 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 1785 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 1771 } | 1786 } |
| 1772 | 1787 |
| 1773 return true; | 1788 return true; |
| 1774 } | 1789 } |
| 1775 | 1790 |
| 1776 bool GrGLGpu::onReadPixels(GrRenderTarget* target, | 1791 bool GrGLGpu::onReadPixels(GrSurface* surface, |
| 1777 int left, int top, | 1792 int left, int top, |
| 1778 int width, int height, | 1793 int width, int height, |
| 1779 GrPixelConfig config, | 1794 GrPixelConfig config, |
| 1780 void* buffer, | 1795 void* buffer, |
| 1781 size_t rowBytes) { | 1796 size_t rowBytes) { |
| 1782 SkASSERT(target); | 1797 SkASSERT(surface); |
| 1783 | 1798 |
| 1784 // We cannot read pixels into a compressed buffer | 1799 // We cannot read pixels into a compressed buffer |
| 1785 if (GrPixelConfigIsCompressed(config)) { | 1800 if (GrPixelConfigIsCompressed(config)) { |
| 1786 return false; | 1801 return false; |
| 1787 } | 1802 } |
| 1788 | 1803 |
| 1804 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg
et()); |
| 1805 if (!tgt) { |
| 1806 return false; |
| 1807 } |
| 1808 |
| 1789 GrGLenum format = 0; | 1809 GrGLenum format = 0; |
| 1790 GrGLenum type = 0; | 1810 GrGLenum type = 0; |
| 1791 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); | 1811 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); |
| 1792 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { | 1812 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
| 1793 return false; | 1813 return false; |
| 1794 } | 1814 } |
| 1795 size_t bpp = GrBytesPerPixel(config); | 1815 size_t bpp = GrBytesPerPixel(config); |
| 1796 if (!GrSurfacePriv::AdjustReadPixelParams(target->width(), target->height(),
bpp, | 1816 if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(
), bpp, |
| 1797 &left, &top, &width, &height, | 1817 &left, &top, &width, &height, |
| 1798 &buffer, | 1818 &buffer, |
| 1799 &rowBytes)) { | 1819 &rowBytes)) { |
| 1800 return false; | 1820 return false; |
| 1801 } | 1821 } |
| 1802 | 1822 |
| 1803 // resolve the render target if necessary | 1823 // resolve the render target if necessary |
| 1804 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | |
| 1805 switch (tgt->getResolveType()) { | 1824 switch (tgt->getResolveType()) { |
| 1806 case GrGLRenderTarget::kCantResolve_ResolveType: | 1825 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1807 return false; | 1826 return false; |
| 1808 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1827 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1809 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); | 1828 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); |
| 1810 break; | 1829 break; |
| 1811 case GrGLRenderTarget::kCanResolve_ResolveType: | 1830 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1812 this->onResolveRenderTarget(tgt); | 1831 this->onResolveRenderTarget(tgt); |
| 1813 // we don't track the state of the READ FBO ID. | 1832 // we don't track the state of the READ FBO ID. |
| 1814 fStats.incRenderTargetBinds(); | 1833 fStats.incRenderTargetBinds(); |
| 1815 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1834 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1816 tgt->textureFBOID())); | 1835 tgt->textureFBOID())); |
| 1817 break; | 1836 break; |
| 1818 default: | 1837 default: |
| 1819 SkFAIL("Unknown resolve type"); | 1838 SkFAIL("Unknown resolve type"); |
| 1820 } | 1839 } |
| 1821 | 1840 |
| 1822 const GrGLIRect& glvp = tgt->getViewport(); | 1841 const GrGLIRect& glvp = tgt->getViewport(); |
| 1823 | 1842 |
| 1824 // the read rect is viewport-relative | 1843 // the read rect is viewport-relative |
| 1825 GrGLIRect readRect; | 1844 GrGLIRect readRect; |
| 1826 readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); | 1845 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); |
| 1827 | 1846 |
| 1828 size_t tightRowBytes = bpp * width; | 1847 size_t tightRowBytes = bpp * width; |
| 1829 if (0 == rowBytes) { | 1848 if (0 == rowBytes) { |
| 1830 rowBytes = tightRowBytes; | 1849 rowBytes = tightRowBytes; |
| 1831 } | 1850 } |
| 1832 size_t readDstRowBytes = tightRowBytes; | 1851 size_t readDstRowBytes = tightRowBytes; |
| 1833 void* readDst = buffer; | 1852 void* readDst = buffer; |
| 1834 | 1853 |
| 1835 // determine if GL can read using the passed rowBytes or if we need | 1854 // determine if GL can read using the passed rowBytes or if we need |
| 1836 // a scratch buffer. | 1855 // a scratch buffer. |
| (...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3168 this->setVertexArrayID(gpu, 0); | 3187 this->setVertexArrayID(gpu, 0); |
| 3169 } | 3188 } |
| 3170 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3189 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3171 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3190 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3172 fDefaultVertexArrayAttribState.resize(attrCount); | 3191 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3173 } | 3192 } |
| 3174 attribState = &fDefaultVertexArrayAttribState; | 3193 attribState = &fDefaultVertexArrayAttribState; |
| 3175 } | 3194 } |
| 3176 return attribState; | 3195 return attribState; |
| 3177 } | 3196 } |
| OLD | NEW |