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 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1786 } | 1786 } |
1787 | 1787 |
1788 return true; | 1788 return true; |
1789 } | 1789 } |
1790 | 1790 |
1791 bool GrGLGpu::onReadPixels(GrSurface* surface, | 1791 bool GrGLGpu::onReadPixels(GrSurface* surface, |
1792 int left, int top, | 1792 int left, int top, |
1793 int width, int height, | 1793 int width, int height, |
1794 GrPixelConfig config, | 1794 GrPixelConfig config, |
1795 void* buffer, | 1795 void* buffer, |
1796 size_t rowBytes) { | 1796 size_t rowBytes, |
1797 size_t tightRowBytes) { | |
bsalomon
2015/07/30 18:27:22
Personally I find the tightRowBytes param is more
egdaniel
2015/07/30 18:47:34
Done.
| |
1797 SkASSERT(surface); | 1798 SkASSERT(surface); |
1798 | 1799 |
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()); | 1800 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg et()); |
1805 if (!tgt) { | 1801 if (!tgt) { |
1806 return false; | 1802 return false; |
1807 } | 1803 } |
1808 | 1804 |
1809 GrGLenum format = 0; | 1805 GrGLenum format = 0; |
1810 GrGLenum type = 0; | 1806 GrGLenum type = 0; |
1811 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); | 1807 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); |
1812 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { | 1808 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
1813 return false; | 1809 return false; |
1814 } | 1810 } |
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 | 1811 |
1823 // resolve the render target if necessary | 1812 // resolve the render target if necessary |
egdaniel
2015/07/30 18:00:49
I also wouldn't be against a virtual on Gpu that i
bsalomon
2015/07/30 18:27:22
This is doing more than just resolving (that is ha
egdaniel
2015/07/30 18:47:34
Sounds good
| |
1824 switch (tgt->getResolveType()) { | 1813 switch (tgt->getResolveType()) { |
1825 case GrGLRenderTarget::kCantResolve_ResolveType: | 1814 case GrGLRenderTarget::kCantResolve_ResolveType: |
1826 return false; | 1815 return false; |
1827 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1816 case GrGLRenderTarget::kAutoResolves_ResolveType: |
1828 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); | 1817 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); |
1829 break; | 1818 break; |
1830 case GrGLRenderTarget::kCanResolve_ResolveType: | 1819 case GrGLRenderTarget::kCanResolve_ResolveType: |
1831 this->onResolveRenderTarget(tgt); | 1820 this->onResolveRenderTarget(tgt); |
1832 // we don't track the state of the READ FBO ID. | 1821 // we don't track the state of the READ FBO ID. |
1833 fStats.incRenderTargetBinds(); | 1822 fStats.incRenderTargetBinds(); |
1834 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 1823 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
1835 tgt->textureFBOID())); | 1824 tgt->textureFBOID())); |
1836 break; | 1825 break; |
1837 default: | 1826 default: |
1838 SkFAIL("Unknown resolve type"); | 1827 SkFAIL("Unknown resolve type"); |
1839 } | 1828 } |
1840 | 1829 |
1841 const GrGLIRect& glvp = tgt->getViewport(); | 1830 const GrGLIRect& glvp = tgt->getViewport(); |
1842 | 1831 |
1843 // the read rect is viewport-relative | 1832 // the read rect is viewport-relative |
1844 GrGLIRect readRect; | 1833 GrGLIRect readRect; |
1845 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); | 1834 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); |
1846 | 1835 |
1847 size_t tightRowBytes = bpp * width; | |
1848 if (0 == rowBytes) { | |
1849 rowBytes = tightRowBytes; | |
1850 } | |
1851 size_t readDstRowBytes = tightRowBytes; | 1836 size_t readDstRowBytes = tightRowBytes; |
1852 void* readDst = buffer; | 1837 void* readDst = buffer; |
1853 | 1838 |
1854 // determine if GL can read using the passed rowBytes or if we need | 1839 // determine if GL can read using the passed rowBytes or if we need |
1855 // a scratch buffer. | 1840 // a scratch buffer. |
1856 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; | 1841 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
1857 if (rowBytes != tightRowBytes) { | 1842 if (rowBytes != tightRowBytes) { |
1858 if (this->glCaps().packRowLengthSupport()) { | 1843 if (this->glCaps().packRowLengthSupport()) { |
1859 SkASSERT(!(rowBytes % sizeof(GrColor))); | 1844 SkASSERT(!(rowBytes % sizeof(GrColor))); |
1860 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, | 1845 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); | 3172 this->setVertexArrayID(gpu, 0); |
3188 } | 3173 } |
3189 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3174 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3190 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3175 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3191 fDefaultVertexArrayAttribState.resize(attrCount); | 3176 fDefaultVertexArrayAttribState.resize(attrCount); |
3192 } | 3177 } |
3193 attribState = &fDefaultVertexArrayAttribState; | 3178 attribState = &fDefaultVertexArrayAttribState; |
3194 } | 3179 } |
3195 return attribState; | 3180 return attribState; |
3196 } | 3181 } |
OLD | NEW |