Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 { | 55 { |
| 56 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
| 57 return true; | 57 return true; |
| 58 #else | 58 #else |
| 59 return false; | 59 return false; |
| 60 #endif | 60 #endif |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // anonymous namespace | 63 } // anonymous namespace |
| 64 | 64 |
| 65 // These values are magic numbers that are used in the transformation from YUV t o RGB color values. | |
|
jzern
2013/02/13 19:56:14
these are actually ITU-R BT.601
| |
| 66 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb.php | |
| 67 float yuv2RGB[9] = { | |
|
jzern
2013/02/13 19:56:14
these should be moved into the anonymous namespace
vigneshv
2013/02/15 18:05:02
Done.
| |
| 68 1.164f, 1.164f, 1.164f, | |
| 69 0.f, -.391f, 2.018f, | |
| 70 1.596f, -.813f, 0.f, | |
| 71 }; | |
| 72 | |
| 73 // These values map to 16, 128, and 128 respectively, and are computed | |
| 74 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | |
| 75 // They are used in the YUV to RGBA conversion formula: | |
| 76 // Y - 16 : Gives 16 values of head and footroom for overshooting | |
| 77 // U - 128 : Turns unsigned U into signed U [-128,127] | |
| 78 // V - 128 : Turns unsigned V into signed V [-128,127] | |
| 79 float yuvAdjust[3] = { | |
| 80 -0.0625f, | |
| 81 -0.5f, | |
| 82 -0.5f, | |
| 83 }; | |
| 84 | |
| 65 scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, OutputSurface* outputSurface, ResourceProvider* resourceProvider) | 85 scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, OutputSurface* outputSurface, ResourceProvider* resourceProvider) |
| 66 { | 86 { |
| 67 scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, outpu tSurface, resourceProvider))); | 87 scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, outpu tSurface, resourceProvider))); |
| 68 if (!renderer->initialize()) | 88 if (!renderer->initialize()) |
| 69 return scoped_ptr<GLRenderer>(); | 89 return scoped_ptr<GLRenderer>(); |
| 70 | 90 |
| 71 return renderer.Pass(); | 91 return renderer.Pass(); |
| 72 } | 92 } |
| 73 | 93 |
| 74 GLRenderer::GLRenderer(RendererClient* client, OutputSurface* outputSurface, Res ourceProvider* resourceProvider) | 94 GLRenderer::GLRenderer(RendererClient* client, OutputSurface* outputSurface, Res ourceProvider* resourceProvider) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 break; | 309 break; |
| 290 case DrawQuad::TEXTURE_CONTENT: | 310 case DrawQuad::TEXTURE_CONTENT: |
| 291 enqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); | 311 enqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); |
| 292 break; | 312 break; |
| 293 case DrawQuad::TILED_CONTENT: | 313 case DrawQuad::TILED_CONTENT: |
| 294 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 314 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); |
| 295 break; | 315 break; |
| 296 case DrawQuad::YUV_VIDEO_CONTENT: | 316 case DrawQuad::YUV_VIDEO_CONTENT: |
| 297 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); | 317 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); |
| 298 break; | 318 break; |
| 319 case DrawQuad::YUVA_VIDEO_CONTENT: | |
| 320 drawYUVAVideoQuad(frame, YUVAVideoDrawQuad::MaterialCast(quad)); | |
| 321 break; | |
| 299 } | 322 } |
| 300 } | 323 } |
| 301 | 324 |
| 302 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) | 325 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) |
| 303 { | 326 { |
| 304 const TileCheckerboardProgram* program = tileCheckerboardProgram(); | 327 const TileCheckerboardProgram* program = tileCheckerboardProgram(); |
| 305 DCHECK(program && (program->initialized() || isContextLost())); | 328 DCHECK(program && (program->initialized() || isContextLost())); |
| 306 setUseProgram(program->program()); | 329 setUseProgram(program->program()); |
| 307 | 330 |
| 308 SkColor color = quad->color; | 331 SkColor color = quad->color; |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 GLC(context(), context()->activeTexture(GL_TEXTURE3)); | 933 GLC(context(), context()->activeTexture(GL_TEXTURE3)); |
| 911 ResourceProvider::ScopedSamplerGL vPlaneLock(m_resourceProvider, vPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR); | 934 ResourceProvider::ScopedSamplerGL vPlaneLock(m_resourceProvider, vPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR); |
| 912 | 935 |
| 913 setUseProgram(program->program()); | 936 setUseProgram(program->program()); |
| 914 | 937 |
| 915 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); | 938 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); |
| 916 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); | 939 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); |
| 917 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); | 940 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); |
| 918 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); | 941 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); |
| 919 | 942 |
| 920 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. | 943 |
|
jzern
2013/02/13 19:56:14
drop this line
vigneshv
2013/02/15 18:05:02
Done.
| |
| 921 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php | |
| 922 float yuv2RGB[9] = { | |
| 923 1.164f, 1.164f, 1.164f, | |
| 924 0.f, -.391f, 2.018f, | |
| 925 1.596f, -.813f, 0.f, | |
| 926 }; | |
| 927 GLC(context(), context()->uniformMatrix3fv(program->fragmentShader().yuvMatr ixLocation(), 1, 0, yuv2RGB)); | 944 GLC(context(), context()->uniformMatrix3fv(program->fragmentShader().yuvMatr ixLocation(), 1, 0, yuv2RGB)); |
| 928 | 945 |
| 929 // These values map to 16, 128, and 128 respectively, and are computed | |
| 930 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | |
| 931 // They are used in the YUV to RGBA conversion formula: | |
| 932 // Y - 16 : Gives 16 values of head and footroom for overshooting | |
| 933 // U - 128 : Turns unsigned U into signed U [-128,127] | |
| 934 // V - 128 : Turns unsigned V into signed V [-128,127] | |
| 935 float yuvAdjust[3] = { | |
| 936 -0.0625f, | |
| 937 -0.5f, | |
| 938 -0.5f, | |
| 939 }; | |
| 940 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio n(), 1, yuvAdjust)); | 946 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio n(), 1, yuvAdjust)); |
| 941 | 947 |
| 942 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | 948 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; |
| 943 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 949 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
| 944 | 950 |
| 945 // Reset active texture back to texture 0. | 951 // Reset active texture back to texture 0. |
| 946 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 952 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
| 947 } | 953 } |
| 948 | 954 |
| 955 void GLRenderer::drawYUVAVideoQuad(const DrawingFrame& frame, const YUVAVideoDra wQuad* quad) | |
| 956 { | |
| 957 const VideoYUVAProgram* program = videoYUVAProgram(); | |
| 958 DCHECK(program && program->initialized()); | |
| 959 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane; | |
| 960 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane; | |
| 961 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane; | |
| 962 const VideoLayerImpl::FramePlane& aPlane = quad->a_plane; | |
| 963 | |
| 964 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId); | |
| 965 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId); | |
| 966 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId); | |
| 967 ResourceProvider::ScopedReadLockGL aPlaneLock(m_resourceProvider, aPlane.res ourceId); | |
| 968 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | |
| 969 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); | |
| 970 GLC(context(), context()->activeTexture(GL_TEXTURE2)); | |
| 971 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); | |
| 972 GLC(context(), context()->activeTexture(GL_TEXTURE3)); | |
| 973 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); | |
| 974 GLC(context(), context()->activeTexture(GL_TEXTURE4)); | |
| 975 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, aPlaneLock.textureId()) ); | |
|
jamesr
2013/02/14 01:55:19
it looks like you could use some for loops here.
| |
| 976 | |
| 977 GLC(context(), context()->useProgram(program->program())); | |
| 978 | |
| 979 // Arbitrarily take the y sizes because y and a dimensions are identical. | |
| 980 float yWidthScaleFactor = static_cast<float>(yPlane.size.width()) / yPlane.s ize.width(); | |
| 981 // Arbitrarily take the u sizes because u and v dimensions are identical. | |
| 982 float uvWidthScaleFactor = static_cast<float>(uPlane.size.width()) / uPlane. size.width(); | |
| 983 //GLC(context(), context()->uniform1f(program->vertexShader().yWidthScaleFac torLocation(), yWidthScaleFactor)); | |
|
jzern
2013/02/13 19:56:14
dead code
vigneshv
2013/02/15 18:05:02
Done.
| |
| 984 //GLC(context(), context()->uniform1f(program->vertexShader().uvWidthScaleFa ctorLocation(), uvWidthScaleFactor)); | |
| 985 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); | |
| 986 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); | |
| 987 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); | |
| 988 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); | |
| 989 GLC(context(), context()->uniform1i(program->fragmentShader().aTextureLocati on(), 4)); | |
| 990 GLC(context(), context()->uniformMatrix3fv(program->fragmentShader().yuvMatr ixLocation(), 1, 0, yuv2RGB)); | |
| 991 | |
| 992 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio n(), 1, yuvAdjust)); | |
| 993 | |
| 994 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | |
| 995 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | |
| 996 | |
| 997 // Reset active texture back to texture 0. | |
| 998 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
| 999 | |
| 1000 } | |
| 1001 | |
| 949 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) | 1002 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) |
| 950 { | 1003 { |
| 951 static float glMatrix[16]; | 1004 static float glMatrix[16]; |
| 952 | 1005 |
| 953 DCHECK(m_capabilities.usingEglImage); | 1006 DCHECK(m_capabilities.usingEglImage); |
| 954 | 1007 |
| 955 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); | 1008 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); |
| 956 setUseProgram(program->program()); | 1009 setUseProgram(program->program()); |
| 957 | 1010 |
| 958 toGLMatrix(&glMatrix[0], quad->matrix); | 1011 toGLMatrix(&glMatrix[0], quad->matrix); |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 { | 1774 { |
| 1722 if (!m_videoYUVProgram) | 1775 if (!m_videoYUVProgram) |
| 1723 m_videoYUVProgram = make_scoped_ptr(new VideoYUVProgram(m_context)); | 1776 m_videoYUVProgram = make_scoped_ptr(new VideoYUVProgram(m_context)); |
| 1724 if (!m_videoYUVProgram->initialized()) { | 1777 if (!m_videoYUVProgram->initialized()) { |
| 1725 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 1778 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
| 1726 m_videoYUVProgram->initialize(m_context, m_isUsingBindUniform); | 1779 m_videoYUVProgram->initialize(m_context, m_isUsingBindUniform); |
| 1727 } | 1780 } |
| 1728 return m_videoYUVProgram.get(); | 1781 return m_videoYUVProgram.get(); |
| 1729 } | 1782 } |
| 1730 | 1783 |
| 1784 const GLRenderer::VideoYUVAProgram* GLRenderer::videoYUVAProgram() | |
| 1785 { | |
| 1786 if (!m_videoYUVAProgram) | |
| 1787 m_videoYUVAProgram = make_scoped_ptr(new VideoYUVAProgram(m_context)); | |
| 1788 if (!m_videoYUVAProgram->initialized()) { | |
| 1789 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); | |
| 1790 m_videoYUVAProgram->initialize(m_context, m_isUsingBindUniform); | |
| 1791 } | |
| 1792 return m_videoYUVAProgram.get(); | |
| 1793 } | |
| 1794 | |
| 1795 | |
| 1731 const GLRenderer::VideoStreamTextureProgram* GLRenderer::videoStreamTextureProgr am() | 1796 const GLRenderer::VideoStreamTextureProgram* GLRenderer::videoStreamTextureProgr am() |
| 1732 { | 1797 { |
| 1733 if (!m_videoStreamTextureProgram) | 1798 if (!m_videoStreamTextureProgram) |
| 1734 m_videoStreamTextureProgram = make_scoped_ptr(new VideoStreamTextureProg ram(m_context)); | 1799 m_videoStreamTextureProgram = make_scoped_ptr(new VideoStreamTextureProg ram(m_context)); |
| 1735 if (!m_videoStreamTextureProgram->initialized()) { | 1800 if (!m_videoStreamTextureProgram->initialized()) { |
| 1736 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | 1801 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
| 1737 m_videoStreamTextureProgram->initialize(m_context, m_isUsingBindUniform) ; | 1802 m_videoStreamTextureProgram->initialize(m_context, m_isUsingBindUniform) ; |
| 1738 } | 1803 } |
| 1739 return m_videoStreamTextureProgram.get(); | 1804 return m_videoStreamTextureProgram.get(); |
| 1740 } | 1805 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1771 | 1836 |
| 1772 if (m_textureProgram) | 1837 if (m_textureProgram) |
| 1773 m_textureProgram->cleanup(m_context); | 1838 m_textureProgram->cleanup(m_context); |
| 1774 if (m_textureProgramFlip) | 1839 if (m_textureProgramFlip) |
| 1775 m_textureProgramFlip->cleanup(m_context); | 1840 m_textureProgramFlip->cleanup(m_context); |
| 1776 if (m_textureIOSurfaceProgram) | 1841 if (m_textureIOSurfaceProgram) |
| 1777 m_textureIOSurfaceProgram->cleanup(m_context); | 1842 m_textureIOSurfaceProgram->cleanup(m_context); |
| 1778 | 1843 |
| 1779 if (m_videoYUVProgram) | 1844 if (m_videoYUVProgram) |
| 1780 m_videoYUVProgram->cleanup(m_context); | 1845 m_videoYUVProgram->cleanup(m_context); |
| 1846 if (m_videoYUVAProgram) | |
| 1847 m_videoYUVAProgram->cleanup(m_context); | |
| 1781 if (m_videoStreamTextureProgram) | 1848 if (m_videoStreamTextureProgram) |
| 1782 m_videoStreamTextureProgram->cleanup(m_context); | 1849 m_videoStreamTextureProgram->cleanup(m_context); |
| 1783 | 1850 |
| 1784 if (m_solidColorProgram) | 1851 if (m_solidColorProgram) |
| 1785 m_solidColorProgram->cleanup(m_context); | 1852 m_solidColorProgram->cleanup(m_context); |
| 1786 | 1853 |
| 1787 if (m_offscreenFramebufferId) | 1854 if (m_offscreenFramebufferId) |
| 1788 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); | 1855 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); |
| 1789 | 1856 |
| 1790 releaseRenderPassTextures(); | 1857 releaseRenderPassTextures(); |
| 1791 } | 1858 } |
| 1792 | 1859 |
| 1793 bool GLRenderer::isContextLost() | 1860 bool GLRenderer::isContextLost() |
| 1794 { | 1861 { |
| 1795 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1862 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1796 } | 1863 } |
| 1797 | 1864 |
| 1798 } // namespace cc | 1865 } // namespace cc |
| OLD | NEW |