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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 setShaderOpacity(quad->opacity(), shaderAlphaLocation); | 671 setShaderOpacity(quad->opacity(), shaderAlphaLocation); |
| 672 setShaderQuadF(surfaceQuad, shaderQuadLocation); | 672 setShaderQuadF(surfaceQuad, shaderQuadLocation); |
| 673 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); | 673 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); |
| 674 | 674 |
| 675 // Flush the compositor context before the filter bitmap goes out of | 675 // Flush the compositor context before the filter bitmap goes out of |
| 676 // scope, so the draw gets processed before the filter texture gets deleted. | 676 // scope, so the draw gets processed before the filter texture gets deleted. |
| 677 if (filterBitmap.getTexture()) | 677 if (filterBitmap.getTexture()) |
| 678 m_context->flush(); | 678 m_context->flush(); |
| 679 } | 679 } |
| 680 | 680 |
| 681 struct SolidColorProgramUniforms { | |
| 682 unsigned program; | |
| 683 unsigned matrixLocation; | |
| 684 unsigned colorLocation; | |
| 685 unsigned pointLocation; | |
| 686 unsigned texScaleLocation; | |
| 687 unsigned edgeLocation; | |
| 688 }; | |
| 689 | |
| 690 template<class T> | |
| 691 static void solidColorUniformLocation(T program, SolidColorProgramUniforms& unif orms) | |
| 692 { | |
| 693 uniforms.program = program->program(); | |
| 694 uniforms.matrixLocation = program->vertexShader().matrixLocation(); | |
| 695 uniforms.colorLocation = program->fragmentShader().colorLocation(); | |
| 696 uniforms.pointLocation = program->vertexShader().pointLocation(); | |
| 697 uniforms.texScaleLocation = program->vertexShader().texScaleLocation(); | |
| 698 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); | |
| 699 } | |
| 700 | |
| 681 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) | 701 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) |
| 682 { | 702 { |
| 683 const SolidColorProgram* program = solidColorProgram(); | 703 gfx::Rect tileRect = quad->visible_rect; |
| 684 setUseProgram(program->program()); | 704 |
| 705 gfx::QuadF localQuad; | |
| 706 gfx::Transform deviceTransform = MathUtil::to2dTransform(frame.windowMatrix * frame.projectionMatrix * quad->quadTransform()); | |
| 707 if (!deviceTransform.IsInvertible()) | |
| 708 return; | |
| 709 | |
| 710 bool clipped = false; | |
| 711 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped); | |
| 712 DCHECK(!clipped); | |
| 713 | |
| 714 SolidColorProgramUniforms uniforms; | |
| 715 // For now, we simply skip anti-aliasing with the quad is clipped. This only happens | |
| 716 // on perspective transformed layers that go partially behind the camera. | |
| 717 if (quad->IsAntialiased() && !clipped) | |
| 718 solidColorUniformLocation(solidColorProgramAA(), uniforms); | |
| 719 else | |
| 720 solidColorUniformLocation(solidColorProgram(), uniforms); | |
| 721 | |
| 722 setUseProgram(uniforms.program); | |
| 685 | 723 |
| 686 SkColor color = quad->color; | 724 SkColor color = quad->color; |
| 687 float opacity = quad->opacity(); | 725 float opacity = quad->opacity(); |
| 688 float alpha = (SkColorGetA(color) / 255.0) * opacity; | 726 float alpha = (SkColorGetA(color) / 255.0) * opacity; |
| 689 | 727 |
| 690 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); | 728 GLC(context(), context()->uniform4f(uniforms.colorLocation, (SkColorGetR(col or) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (SkColorGetB(color) / 255.0) * alpha, alpha)); |
| 691 | 729 |
| 692 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 730 GLC(context(), context()->uniform2f(uniforms.texScaleLocation, 1.0f, 1.0f)); |
| 731 | |
| 732 bool useAA = !clipped && quad->IsAntialiased(); | |
| 733 if (useAA) { | |
| 734 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); | |
| 735 deviceLayerBounds.inflateAntiAliasingDistance(); | |
| 736 | |
| 737 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); | |
| 738 deviceLayerEdges.inflateAntiAliasingDistance(); | |
| 739 | |
| 740 float edge[24]; | |
| 741 deviceLayerEdges.toFloatArray(edge); | |
| 742 deviceLayerBounds.toFloatArray(&edge[12]); | |
| 743 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); | |
| 744 | |
| 745 gfx::PointF bottomRight = tileRect.bottom_right(); | |
| 746 gfx::PointF bottomLeft = tileRect.bottom_left(); | |
| 747 gfx::PointF topLeft = tileRect.origin(); | |
| 748 gfx::PointF topRight = tileRect.top_right(); | |
| 749 | |
| 750 // Map points to device space. | |
| 751 bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped); | |
| 752 DCHECK(!clipped); | |
| 753 bottomLeft = MathUtil::mapPoint(deviceTransform, bottomLeft, clipped); | |
| 754 DCHECK(!clipped); | |
| 755 topLeft = MathUtil::mapPoint(deviceTransform, topLeft, clipped); | |
| 756 DCHECK(!clipped); | |
| 757 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); | |
| 758 DCHECK(!clipped); | |
| 759 | |
| 760 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); | |
| 761 LayerQuad::Edge leftEdge(bottomLeft, topLeft); | |
| 762 LayerQuad::Edge topEdge(topLeft, topRight); | |
| 763 LayerQuad::Edge rightEdge(topRight, bottomRight); | |
|
jamesr
2013/01/08 22:29:26
Tons of this code is copy-pasted from drawTileQuad
reveman
2013/01/09 14:20:05
Definitely. I'm saving this until the rest of the
| |
| 764 | |
| 765 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. | |
| 766 if (quad->anti_aliasing.top_edge && tileRect.y() == quad->rect.y()) | |
| 767 topEdge = deviceLayerEdges.top(); | |
| 768 if (quad->anti_aliasing.left_edge && tileRect.x() == quad->rect.x()) | |
| 769 leftEdge = deviceLayerEdges.left(); | |
| 770 if (quad->anti_aliasing.right_edge && tileRect.right() == quad->rect.rig ht()) | |
| 771 rightEdge = deviceLayerEdges.right(); | |
| 772 if (quad->anti_aliasing.bottom_edge && tileRect.bottom() == quad->rect.b ottom()) | |
| 773 bottomEdge = deviceLayerEdges.bottom(); | |
| 774 | |
| 775 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; | |
| 776 bottomEdge.scale(sign); | |
| 777 leftEdge.scale(sign); | |
| 778 topEdge.scale(sign); | |
| 779 rightEdge.scale(sign); | |
| 780 | |
| 781 // Create device space quad. | |
| 782 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | |
| 783 | |
| 784 // Map device space quad to local space. deviceTransform has no 3d compo nent since it was generated with to2dTransform() so we don't need to project. | |
| 785 // We should have already checked that the transform was uninvertible ab ove. | |
| 786 gfx::Transform inverseDeviceTransform(gfx::Transform::kSkipInitializatio n); | |
| 787 bool didInvert = deviceTransform.GetInverse(&inverseDeviceTransform); | |
| 788 DCHECK(didInvert); | |
| 789 localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.ToQuadF (), clipped); | |
| 790 | |
| 791 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may cause deviceQuad to become | |
| 792 // clipped. To our knowledge this scenario does not need to be handled d ifferently than the unclipped case. | |
| 793 } else { | |
| 794 localQuad = gfx::RectF(tileRect); | |
| 795 } | |
| 796 | |
| 797 // Normalize to tileRect. | |
| 798 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); | |
| 799 | |
| 800 setShaderQuadF(localQuad, uniforms.pointLocation); | |
| 801 | |
| 802 // The tile quad shader behaves differently compared to all other shaders. | |
| 803 // The transform and vertex data are used to figure out the extents that the | |
| 804 // un-antialiased quad should have and which vertex this is and the float | |
| 805 // quad passed in via uniform is the actual geometry that gets used to draw | |
| 806 // it. This is why this centered rect is used and not the original quadRect. | |
| 807 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size()); | |
| 808 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location); | |
| 693 } | 809 } |
| 694 | 810 |
| 695 struct TileProgramUniforms { | 811 struct TileProgramUniforms { |
| 696 unsigned program; | 812 unsigned program; |
| 697 unsigned samplerLocation; | 813 unsigned samplerLocation; |
| 698 unsigned vertexTexTransformLocation; | 814 unsigned vertexTexTransformLocation; |
| 699 unsigned fragmentTexTransformLocation; | 815 unsigned fragmentTexTransformLocation; |
| 700 unsigned edgeLocation; | 816 unsigned edgeLocation; |
| 701 unsigned matrixLocation; | 817 unsigned matrixLocation; |
| 702 unsigned alphaLocation; | 818 unsigned alphaLocation; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 DCHECK(!clipped); | 951 DCHECK(!clipped); |
| 836 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); | 952 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); |
| 837 DCHECK(!clipped); | 953 DCHECK(!clipped); |
| 838 | 954 |
| 839 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); | 955 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); |
| 840 LayerQuad::Edge leftEdge(bottomLeft, topLeft); | 956 LayerQuad::Edge leftEdge(bottomLeft, topLeft); |
| 841 LayerQuad::Edge topEdge(topLeft, topRight); | 957 LayerQuad::Edge topEdge(topLeft, topRight); |
| 842 LayerQuad::Edge rightEdge(topRight, bottomRight); | 958 LayerQuad::Edge rightEdge(topRight, bottomRight); |
| 843 | 959 |
| 844 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. | 960 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. |
| 845 if (quad->top_edge_aa && tileRect.y() == quad->rect.y()) | 961 if (quad->anti_aliasing.top_edge && tileRect.y() == quad->rect.y()) |
| 846 topEdge = deviceLayerEdges.top(); | 962 topEdge = deviceLayerEdges.top(); |
| 847 if (quad->left_edge_aa && tileRect.x() == quad->rect.x()) | 963 if (quad->anti_aliasing.left_edge && tileRect.x() == quad->rect.x()) |
| 848 leftEdge = deviceLayerEdges.left(); | 964 leftEdge = deviceLayerEdges.left(); |
| 849 if (quad->right_edge_aa && tileRect.right() == quad->rect.right()) | 965 if (quad->anti_aliasing.right_edge && tileRect.right() == quad->rect.rig ht()) |
| 850 rightEdge = deviceLayerEdges.right(); | 966 rightEdge = deviceLayerEdges.right(); |
| 851 if (quad->bottom_edge_aa && tileRect.bottom() == quad->rect.bottom()) | 967 if (quad->anti_aliasing.bottom_edge && tileRect.bottom() == quad->rect.b ottom()) |
| 852 bottomEdge = deviceLayerEdges.bottom(); | 968 bottomEdge = deviceLayerEdges.bottom(); |
| 853 | 969 |
| 854 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; | 970 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; |
| 855 bottomEdge.scale(sign); | 971 bottomEdge.scale(sign); |
| 856 leftEdge.scale(sign); | 972 leftEdge.scale(sign); |
| 857 topEdge.scale(sign); | 973 topEdge.scale(sign); |
| 858 rightEdge.scale(sign); | 974 rightEdge.scale(sign); |
| 859 | 975 |
| 860 // Create device space quad. | 976 // Create device space quad. |
| 861 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | 977 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 { | 1691 { |
| 1576 if (!m_solidColorProgram) | 1692 if (!m_solidColorProgram) |
| 1577 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); | 1693 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); |
| 1578 if (!m_solidColorProgram->initialized()) { | 1694 if (!m_solidColorProgram->initialized()) { |
| 1579 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); | 1695 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
| 1580 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); | 1696 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); |
| 1581 } | 1697 } |
| 1582 return m_solidColorProgram.get(); | 1698 return m_solidColorProgram.get(); |
| 1583 } | 1699 } |
| 1584 | 1700 |
| 1701 const GLRenderer::SolidColorProgramAA* GLRenderer::solidColorProgramAA() | |
| 1702 { | |
| 1703 if (!m_solidColorProgramAA) | |
| 1704 m_solidColorProgramAA = make_scoped_ptr(new SolidColorProgramAA(m_contex t)); | |
| 1705 if (!m_solidColorProgramAA->initialized()) { | |
| 1706 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); | |
| 1707 m_solidColorProgramAA->initialize(m_context, m_isUsingBindUniform); | |
| 1708 } | |
| 1709 return m_solidColorProgramAA.get(); | |
| 1710 } | |
| 1711 | |
| 1585 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() | 1712 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() |
| 1586 { | 1713 { |
| 1587 DCHECK(m_renderPassProgram); | 1714 DCHECK(m_renderPassProgram); |
| 1588 if (!m_renderPassProgram->initialized()) { | 1715 if (!m_renderPassProgram->initialized()) { |
| 1589 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | 1716 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| 1590 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); | 1717 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); |
| 1591 } | 1718 } |
| 1592 return m_renderPassProgram.get(); | 1719 return m_renderPassProgram.get(); |
| 1593 } | 1720 } |
| 1594 | 1721 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1781 if (m_textureIOSurfaceProgram) | 1908 if (m_textureIOSurfaceProgram) |
| 1782 m_textureIOSurfaceProgram->cleanup(m_context); | 1909 m_textureIOSurfaceProgram->cleanup(m_context); |
| 1783 | 1910 |
| 1784 if (m_videoYUVProgram) | 1911 if (m_videoYUVProgram) |
| 1785 m_videoYUVProgram->cleanup(m_context); | 1912 m_videoYUVProgram->cleanup(m_context); |
| 1786 if (m_videoStreamTextureProgram) | 1913 if (m_videoStreamTextureProgram) |
| 1787 m_videoStreamTextureProgram->cleanup(m_context); | 1914 m_videoStreamTextureProgram->cleanup(m_context); |
| 1788 | 1915 |
| 1789 if (m_solidColorProgram) | 1916 if (m_solidColorProgram) |
| 1790 m_solidColorProgram->cleanup(m_context); | 1917 m_solidColorProgram->cleanup(m_context); |
| 1918 if (m_solidColorProgramAA) | |
| 1919 m_solidColorProgramAA->cleanup(m_context); | |
| 1791 | 1920 |
| 1792 if (m_offscreenFramebufferId) | 1921 if (m_offscreenFramebufferId) |
| 1793 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); | 1922 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); |
| 1794 | 1923 |
| 1795 releaseRenderPassTextures(); | 1924 releaseRenderPassTextures(); |
| 1796 } | 1925 } |
| 1797 | 1926 |
| 1798 bool GLRenderer::isContextLost() | 1927 bool GLRenderer::isContextLost() |
| 1799 { | 1928 { |
| 1800 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1929 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1801 } | 1930 } |
| 1802 | 1931 |
| 1803 } // namespace cc | 1932 } // namespace cc |
| OLD | NEW |