Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: cc/gl_renderer.cc

Issue 11649005: cc: Support anti-aliasing for solid color layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: per edge anti-aliasing Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 setShaderOpacity(quad->opacity(), shaderAlphaLocation); 678 setShaderOpacity(quad->opacity(), shaderAlphaLocation);
679 setShaderQuadF(surfaceQuad, shaderQuadLocation); 679 setShaderQuadF(surfaceQuad, shaderQuadLocation);
680 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); 680 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion);
681 681
682 // Flush the compositor context before the filter bitmap goes out of 682 // Flush the compositor context before the filter bitmap goes out of
683 // scope, so the draw gets processed before the filter texture gets deleted. 683 // scope, so the draw gets processed before the filter texture gets deleted.
684 if (filterBitmap.getTexture()) 684 if (filterBitmap.getTexture())
685 m_context->flush(); 685 m_context->flush();
686 } 686 }
687 687
688 struct SolidColorProgramUniforms {
689 unsigned program;
690 unsigned matrixLocation;
691 unsigned colorLocation;
692 unsigned pointLocation;
693 unsigned texScaleLocation;
694 unsigned edgeLocation;
695 };
696
697 template<class T>
698 static void solidColorUniformLocation(T program, SolidColorProgramUniforms& unif orms)
699 {
700 uniforms.program = program->program();
701 uniforms.matrixLocation = program->vertexShader().matrixLocation();
702 uniforms.colorLocation = program->fragmentShader().colorLocation();
703 uniforms.pointLocation = program->vertexShader().pointLocation();
704 uniforms.texScaleLocation = program->vertexShader().texScaleLocation();
705 uniforms.edgeLocation = program->fragmentShader().edgeLocation();
706 }
707
688 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) 708 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad)
689 { 709 {
690 const SolidColorProgram* program = solidColorProgram(); 710 gfx::Rect tileRect = quad->visible_rect;
691 setUseProgram(program->program()); 711
712 gfx::QuadF localQuad;
713 gfx::Transform deviceTransform = MathUtil::to2dTransform(frame.windowMatrix * frame.projectionMatrix * quad->quadTransform());
714 if (!deviceTransform.IsInvertible())
715 return;
716
717 bool clipped = false;
718 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped);
719 DCHECK(!clipped);
720
721 SolidColorProgramUniforms uniforms;
722 // For now, we simply skip anti-aliasing with the quad is clipped. This only happens
723 // on perspective transformed layers that go partially behind the camera.
724 if (quad->IsAntialiased() && !clipped)
725 solidColorUniformLocation(solidColorProgramAA(), uniforms);
726 else
727 solidColorUniformLocation(solidColorProgram(), uniforms);
728
729 setUseProgram(uniforms.program);
692 730
693 SkColor color = quad->color; 731 SkColor color = quad->color;
694 float opacity = quad->opacity(); 732 float opacity = quad->opacity();
695 float alpha = (SkColorGetA(color) / 255.0) * opacity; 733 float alpha = (SkColorGetA(color) / 255.0) * opacity;
696 734
697 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); 735 GLC(context(), context()->uniform4f(uniforms.colorLocation, (SkColorGetR(col or) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (SkColorGetB(color) / 255.0) * alpha, alpha));
698 736
699 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); 737 GLC(context(), context()->uniform2f(uniforms.texScaleLocation, 1.0f, 1.0f));
738
739 bool useAA = !clipped && quad->IsAntialiased();
740 if (useAA) {
741 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox()));
742 deviceLayerBounds.inflateAntiAliasingDistance();
743
744 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad);
745 deviceLayerEdges.inflateAntiAliasingDistance();
746
747 float edge[24];
748 deviceLayerEdges.toFloatArray(edge);
749 deviceLayerBounds.toFloatArray(&edge[12]);
750 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge));
751
752 gfx::PointF bottomRight = tileRect.bottom_right();
753 gfx::PointF bottomLeft = tileRect.bottom_left();
754 gfx::PointF topLeft = tileRect.origin();
755 gfx::PointF topRight = tileRect.top_right();
756
757 // Map points to device space.
758 bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped);
759 DCHECK(!clipped);
760 bottomLeft = MathUtil::mapPoint(deviceTransform, bottomLeft, clipped);
761 DCHECK(!clipped);
762 topLeft = MathUtil::mapPoint(deviceTransform, topLeft, clipped);
763 DCHECK(!clipped);
764 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped);
765 DCHECK(!clipped);
766
767 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft);
768 LayerQuad::Edge leftEdge(bottomLeft, topLeft);
769 LayerQuad::Edge topEdge(topLeft, topRight);
770 LayerQuad::Edge rightEdge(topRight, bottomRight);
771
772 // Only apply anti-aliasing to edges not clipped by culling or scissorin g.
773 if (quad->top_edge_aa && tileRect.y() == quad->rect.y())
774 topEdge = deviceLayerEdges.top();
775 if (quad->left_edge_aa && tileRect.x() == quad->rect.x())
776 leftEdge = deviceLayerEdges.left();
777 if (quad->right_edge_aa && tileRect.right() == quad->rect.right())
778 rightEdge = deviceLayerEdges.right();
779 if (quad->bottom_edge_aa && tileRect.bottom() == quad->rect.bottom())
780 bottomEdge = deviceLayerEdges.bottom();
781
782 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1;
783 bottomEdge.scale(sign);
784 leftEdge.scale(sign);
785 topEdge.scale(sign);
786 rightEdge.scale(sign);
787
788 // Create device space quad.
789 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge);
790
791 // 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.
792 gfx::Transform deviceTransformInverse = MathUtil::inverse(deviceTransfor m);
793 localQuad = MathUtil::mapQuad(deviceTransformInverse, deviceQuad.ToQuadF (), clipped);
794
795 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may cause deviceQuad to become
796 // clipped. To our knowledge this scenario does not need to be handled d ifferently than the unclipped case.
797 } else {
798 localQuad = gfx::RectF(tileRect);
799 }
800
801 // Normalize to tileRect.
802 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height());
803
804 setShaderQuadF(localQuad, uniforms.pointLocation);
805
806 // The tile quad shader behaves differently compared to all other shaders.
807 // The transform and vertex data are used to figure out the extents that the
808 // un-antialiased quad should have and which vertex this is and the float
809 // quad passed in via uniform is the actual geometry that gets used to draw
810 // it. This is why this centered rect is used and not the original quadRect.
811 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size());
812 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location);
700 } 813 }
701 814
702 struct TileProgramUniforms { 815 struct TileProgramUniforms {
703 unsigned program; 816 unsigned program;
704 unsigned samplerLocation; 817 unsigned samplerLocation;
705 unsigned vertexTexTransformLocation; 818 unsigned vertexTexTransformLocation;
706 unsigned fragmentTexTransformLocation; 819 unsigned fragmentTexTransformLocation;
707 unsigned edgeLocation; 820 unsigned edgeLocation;
708 unsigned matrixLocation; 821 unsigned matrixLocation;
709 unsigned alphaLocation; 822 unsigned alphaLocation;
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 { 1691 {
1579 if (!m_solidColorProgram) 1692 if (!m_solidColorProgram)
1580 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); 1693 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context));
1581 if (!m_solidColorProgram->initialized()) { 1694 if (!m_solidColorProgram->initialized()) {
1582 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); 1695 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize");
1583 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); 1696 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform);
1584 } 1697 }
1585 return m_solidColorProgram.get(); 1698 return m_solidColorProgram.get();
1586 } 1699 }
1587 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
1588 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() 1712 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram()
1589 { 1713 {
1590 DCHECK(m_renderPassProgram); 1714 DCHECK(m_renderPassProgram);
1591 if (!m_renderPassProgram->initialized()) { 1715 if (!m_renderPassProgram->initialized()) {
1592 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); 1716 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize");
1593 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); 1717 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform);
1594 } 1718 }
1595 return m_renderPassProgram.get(); 1719 return m_renderPassProgram.get();
1596 } 1720 }
1597 1721
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 if (m_textureIOSurfaceProgram) 1908 if (m_textureIOSurfaceProgram)
1785 m_textureIOSurfaceProgram->cleanup(m_context); 1909 m_textureIOSurfaceProgram->cleanup(m_context);
1786 1910
1787 if (m_videoYUVProgram) 1911 if (m_videoYUVProgram)
1788 m_videoYUVProgram->cleanup(m_context); 1912 m_videoYUVProgram->cleanup(m_context);
1789 if (m_videoStreamTextureProgram) 1913 if (m_videoStreamTextureProgram)
1790 m_videoStreamTextureProgram->cleanup(m_context); 1914 m_videoStreamTextureProgram->cleanup(m_context);
1791 1915
1792 if (m_solidColorProgram) 1916 if (m_solidColorProgram)
1793 m_solidColorProgram->cleanup(m_context); 1917 m_solidColorProgram->cleanup(m_context);
1918 if (m_solidColorProgramAA)
1919 m_solidColorProgramAA->cleanup(m_context);
1794 1920
1795 if (m_offscreenFramebufferId) 1921 if (m_offscreenFramebufferId)
1796 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); 1922 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId));
1797 1923
1798 releaseRenderPassTextures(); 1924 releaseRenderPassTextures();
1799 } 1925 }
1800 1926
1801 bool GLRenderer::isContextLost() 1927 bool GLRenderer::isContextLost()
1802 { 1928 {
1803 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1929 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1804 } 1930 }
1805 1931
1806 } // namespace cc 1932 } // namespace cc
OLDNEW
« no previous file with comments | « cc/gl_renderer.h ('k') | cc/gl_renderer_pixeltest.cc » ('j') | cc/solid_color_draw_quad.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698