| 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 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 // If we have to do memcpy to handle non-trim rowBytes then we | 1724 // If we have to do memcpy to handle non-trim rowBytes then we |
| 1725 // get the flip for free. Otherwise it costs. | 1725 // get the flip for free. Otherwise it costs. |
| 1726 // Note that we're assuming that 0 rowBytes has already been handled and tha
t the width has been | 1726 // Note that we're assuming that 0 rowBytes has already been handled and tha
t the width has been |
| 1727 // clipped. | 1727 // clipped. |
| 1728 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; | 1728 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; |
| 1729 } | 1729 } |
| 1730 | 1730 |
| 1731 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, |
| 1732 GrPixelConfig readConfig, DrawPreference* draw
Preference, | 1732 GrPixelConfig readConfig, DrawPreference* draw
Preference, |
| 1733 ReadPixelTempDrawInfo* tempDrawInfo) { | 1733 ReadPixelTempDrawInfo* tempDrawInfo) { |
| 1734 if (GrPixelConfigIsCompressed(readConfig)) { | |
| 1735 return false; | |
| 1736 } | |
| 1737 | |
| 1738 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on | 1734 // 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. | 1735 // GL versions that support it but we don't today. |
| 1740 if (!srcSurface->asRenderTarget()) { | 1736 if (!srcSurface->asRenderTarget()) { |
| 1741 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 1737 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1742 } | 1738 } |
| 1743 | 1739 |
| 1744 tempDrawInfo->fSwapRAndB = false; | 1740 tempDrawInfo->fSwapRAndB = false; |
| 1745 | 1741 |
| 1746 // These settings we will always want if a temp draw is performed. The confi
g is set below | 1742 // These settings we will always want if a temp draw is performed. The confi
g is set below |
| 1747 // depending on whether we want to do a R/B swap or not. | 1743 // depending on whether we want to do a R/B swap or not. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 } | 1785 } |
| 1790 | 1786 |
| 1791 bool GrGLGpu::onReadPixels(GrSurface* surface, | 1787 bool GrGLGpu::onReadPixels(GrSurface* surface, |
| 1792 int left, int top, | 1788 int left, int top, |
| 1793 int width, int height, | 1789 int width, int height, |
| 1794 GrPixelConfig config, | 1790 GrPixelConfig config, |
| 1795 void* buffer, | 1791 void* buffer, |
| 1796 size_t rowBytes) { | 1792 size_t rowBytes) { |
| 1797 SkASSERT(surface); | 1793 SkASSERT(surface); |
| 1798 | 1794 |
| 1799 // We cannot read pixels into a compressed buffer | |
| 1800 if (GrPixelConfigIsCompressed(config)) { | |
| 1801 return false; | |
| 1802 } | |
| 1803 | |
| 1804 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg
et()); | 1795 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg
et()); |
| 1805 if (!tgt) { | 1796 if (!tgt) { |
| 1806 return false; | 1797 return false; |
| 1807 } | 1798 } |
| 1808 | 1799 |
| 1809 GrGLenum format = 0; | 1800 GrGLenum format = 0; |
| 1810 GrGLenum type = 0; | 1801 GrGLenum type = 0; |
| 1811 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); | 1802 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); |
| 1812 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { | 1803 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
| 1813 return false; | 1804 return false; |
| 1814 } | 1805 } |
| 1815 size_t bpp = GrBytesPerPixel(config); | |
| 1816 if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(
), bpp, | |
| 1817 &left, &top, &width, &height, | |
| 1818 &buffer, | |
| 1819 &rowBytes)) { | |
| 1820 return false; | |
| 1821 } | |
| 1822 | 1806 |
| 1823 // resolve the render target if necessary | 1807 // resolve the render target if necessary |
| 1824 switch (tgt->getResolveType()) { | 1808 switch (tgt->getResolveType()) { |
| 1825 case GrGLRenderTarget::kCantResolve_ResolveType: | 1809 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1826 return false; | 1810 return false; |
| 1827 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1811 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1828 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); | 1812 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); |
| 1829 break; | 1813 break; |
| 1830 case GrGLRenderTarget::kCanResolve_ResolveType: | 1814 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1831 this->onResolveRenderTarget(tgt); | 1815 this->onResolveRenderTarget(tgt); |
| 1832 // we don't track the state of the READ FBO ID. | 1816 // we don't track the state of the READ FBO ID. |
| 1833 fStats.incRenderTargetBinds(); | 1817 fStats.incRenderTargetBinds(); |
| 1834 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1818 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1835 tgt->textureFBOID())); | 1819 tgt->textureFBOID())); |
| 1836 break; | 1820 break; |
| 1837 default: | 1821 default: |
| 1838 SkFAIL("Unknown resolve type"); | 1822 SkFAIL("Unknown resolve type"); |
| 1839 } | 1823 } |
| 1840 | 1824 |
| 1841 const GrGLIRect& glvp = tgt->getViewport(); | 1825 const GrGLIRect& glvp = tgt->getViewport(); |
| 1842 | 1826 |
| 1843 // the read rect is viewport-relative | 1827 // the read rect is viewport-relative |
| 1844 GrGLIRect readRect; | 1828 GrGLIRect readRect; |
| 1845 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); | 1829 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); |
| 1846 | 1830 |
| 1847 size_t tightRowBytes = bpp * width; | 1831 size_t tightRowBytes = GrBytesPerPixel(config) * width; |
| 1848 if (0 == rowBytes) { | 1832 |
| 1849 rowBytes = tightRowBytes; | |
| 1850 } | |
| 1851 size_t readDstRowBytes = tightRowBytes; | 1833 size_t readDstRowBytes = tightRowBytes; |
| 1852 void* readDst = buffer; | 1834 void* readDst = buffer; |
| 1853 | 1835 |
| 1854 // determine if GL can read using the passed rowBytes or if we need | 1836 // determine if GL can read using the passed rowBytes or if we need |
| 1855 // a scratch buffer. | 1837 // a scratch buffer. |
| 1856 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; | 1838 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
| 1857 if (rowBytes != tightRowBytes) { | 1839 if (rowBytes != tightRowBytes) { |
| 1858 if (this->glCaps().packRowLengthSupport()) { | 1840 if (this->glCaps().packRowLengthSupport()) { |
| 1859 SkASSERT(!(rowBytes % sizeof(GrColor))); | 1841 SkASSERT(!(rowBytes % sizeof(GrColor))); |
| 1860 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, | 1842 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3187 this->setVertexArrayID(gpu, 0); | 3169 this->setVertexArrayID(gpu, 0); |
| 3188 } | 3170 } |
| 3189 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3171 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3190 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3172 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3191 fDefaultVertexArrayAttribState.resize(attrCount); | 3173 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3192 } | 3174 } |
| 3193 attribState = &fDefaultVertexArrayAttribState; | 3175 attribState = &fDefaultVertexArrayAttribState; |
| 3194 } | 3176 } |
| 3195 return attribState; | 3177 return attribState; |
| 3196 } | 3178 } |
| OLD | NEW |