| 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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 setShaderOpacity(quad->opacity(), shaderAlphaLocation); | 718 setShaderOpacity(quad->opacity(), shaderAlphaLocation); |
| 719 setShaderQuadF(surfaceQuad, shaderQuadLocation); | 719 setShaderQuadF(surfaceQuad, shaderQuadLocation); |
| 720 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat
ion); | 720 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat
ion); |
| 721 | 721 |
| 722 // Flush the compositor context before the filter bitmap goes out of | 722 // Flush the compositor context before the filter bitmap goes out of |
| 723 // scope, so the draw gets processed before the filter texture gets deleted. | 723 // scope, so the draw gets processed before the filter texture gets deleted. |
| 724 if (filterBitmap.getTexture()) | 724 if (filterBitmap.getTexture()) |
| 725 m_context->flush(); | 725 m_context->flush(); |
| 726 } | 726 } |
| 727 | 727 |
| 728 struct SolidColorProgramUniforms { |
| 729 unsigned program; |
| 730 unsigned matrixLocation; |
| 731 unsigned colorLocation; |
| 732 unsigned pointLocation; |
| 733 unsigned texScaleLocation; |
| 734 unsigned edgeLocation; |
| 735 }; |
| 736 |
| 737 template<class T> |
| 738 static void solidColorUniformLocation(T program, SolidColorProgramUniforms& unif
orms) |
| 739 { |
| 740 uniforms.program = program->program(); |
| 741 uniforms.matrixLocation = program->vertexShader().matrixLocation(); |
| 742 uniforms.colorLocation = program->fragmentShader().colorLocation(); |
| 743 uniforms.pointLocation = program->vertexShader().pointLocation(); |
| 744 uniforms.texScaleLocation = program->vertexShader().texScaleLocation(); |
| 745 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); |
| 746 } |
| 747 |
| 748 bool GLRenderer::setupQuadForAntialiasing(const gfx::Transform& deviceTransform,
const DrawQuad* quad, |
| 749 gfx::QuadF* localQuad, float edge[24])
const |
| 750 { |
| 751 gfx::Rect tileRect = quad->visible_rect; |
| 752 |
| 753 bool clipped = false; |
| 754 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q
uad->visibleContentRect()), clipped); |
| 755 DCHECK(!clipped); |
| 756 |
| 757 // TODO(reveman): Axis-aligned is not enough to avoid anti-aliasing. |
| 758 // Bounding rectangle for quad also needs to be expressible as |
| 759 // an integer rectangle. crbug.com/169374 |
| 760 bool isAxisAlignedInTarget = deviceLayerQuad.IsRectilinear(); |
| 761 bool useAA = !clipped && !isAxisAlignedInTarget && quad->IsEdge(); |
| 762 |
| 763 if (!useAA) |
| 764 return false; |
| 765 |
| 766 LayerQuad deviceLayerBounds(gfx::QuadF(deviceLayerQuad.BoundingBox())); |
| 767 deviceLayerBounds.InflateAntiAliasingDistance(); |
| 768 |
| 769 LayerQuad deviceLayerEdges(deviceLayerQuad); |
| 770 deviceLayerEdges.InflateAntiAliasingDistance(); |
| 771 |
| 772 deviceLayerEdges.ToFloatArray(edge); |
| 773 deviceLayerBounds.ToFloatArray(&edge[12]); |
| 774 |
| 775 gfx::PointF bottomRight = tileRect.bottom_right(); |
| 776 gfx::PointF bottomLeft = tileRect.bottom_left(); |
| 777 gfx::PointF topLeft = tileRect.origin(); |
| 778 gfx::PointF topRight = tileRect.top_right(); |
| 779 |
| 780 // Map points to device space. |
| 781 bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped); |
| 782 DCHECK(!clipped); |
| 783 bottomLeft = MathUtil::mapPoint(deviceTransform, bottomLeft, clipped); |
| 784 DCHECK(!clipped); |
| 785 topLeft = MathUtil::mapPoint(deviceTransform, topLeft, clipped); |
| 786 DCHECK(!clipped); |
| 787 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); |
| 788 DCHECK(!clipped); |
| 789 |
| 790 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); |
| 791 LayerQuad::Edge leftEdge(bottomLeft, topLeft); |
| 792 LayerQuad::Edge topEdge(topLeft, topRight); |
| 793 LayerQuad::Edge rightEdge(topRight, bottomRight); |
| 794 |
| 795 // Only apply anti-aliasing to edges not clipped by culling or scissoring. |
| 796 if (quad->IsTopEdge() && tileRect.y() == quad->rect.y()) |
| 797 topEdge = deviceLayerEdges.top(); |
| 798 if (quad->IsLeftEdge() && tileRect.x() == quad->rect.x()) |
| 799 leftEdge = deviceLayerEdges.left(); |
| 800 if (quad->IsRightEdge() && tileRect.right() == quad->rect.right()) |
| 801 rightEdge = deviceLayerEdges.right(); |
| 802 if (quad->IsBottomEdge() && tileRect.bottom() == quad->rect.bottom()) |
| 803 bottomEdge = deviceLayerEdges.bottom(); |
| 804 |
| 805 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; |
| 806 bottomEdge.scale(sign); |
| 807 leftEdge.scale(sign); |
| 808 topEdge.scale(sign); |
| 809 rightEdge.scale(sign); |
| 810 |
| 811 // Create device space quad. |
| 812 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); |
| 813 |
| 814 // Map device space quad to local space. deviceTransform has no 3d component
since it was flattened, so we don't need to project. |
| 815 // We should have already checked that the transform was uninvertible above. |
| 816 gfx::Transform inverseDeviceTransform(gfx::Transform::kSkipInitialization); |
| 817 bool didInvert = deviceTransform.GetInverse(&inverseDeviceTransform); |
| 818 DCHECK(didInvert); |
| 819 *localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.ToQuadF(),
clipped); |
| 820 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may
cause deviceQuad to become |
| 821 // clipped. To our knowledge this scenario does not need to be handled diffe
rently than the unclipped case. |
| 822 |
| 823 return true; |
| 824 } |
| 825 |
| 728 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD
rawQuad* quad) | 826 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD
rawQuad* quad) |
| 729 { | 827 { |
| 730 setBlendEnabled(quad->ShouldDrawWithBlending()); | 828 gfx::Rect tileRect = quad->visible_rect; |
| 731 | 829 |
| 732 const SolidColorProgram* program = solidColorProgram(); | 830 gfx::Transform deviceTransform = frame.window_matrix * frame.projection_matr
ix * quad->quadTransform(); |
| 733 setUseProgram(program->program()); | 831 deviceTransform.FlattenTo2d(); |
| 832 if (!deviceTransform.IsInvertible()) |
| 833 return; |
| 834 |
| 835 gfx::QuadF localQuad = gfx::QuadF(gfx::RectF(tileRect)); |
| 836 float edge[24]; |
| 837 bool useAA = setupQuadForAntialiasing(deviceTransform, quad, &localQuad, edg
e); |
| 838 |
| 839 SolidColorProgramUniforms uniforms; |
| 840 if (useAA) |
| 841 solidColorUniformLocation(solidColorProgramAA(), uniforms); |
| 842 else |
| 843 solidColorUniformLocation(solidColorProgram(), uniforms); |
| 844 setUseProgram(uniforms.program); |
| 734 | 845 |
| 735 SkColor color = quad->color; | 846 SkColor color = quad->color; |
| 736 float opacity = quad->opacity(); | 847 float opacity = quad->opacity(); |
| 737 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 848 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
| 738 | 849 |
| 739 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, (SkColorGetG(color) * (1.0f /
255.0f)) * alpha, (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, alpha)); | 850 GLC(context(), context()->uniform4f(uniforms.colorLocation, |
| 851 (SkColorGetR(color) * (1.0f / 255.0f)) *
alpha, |
| 852 (SkColorGetG(color) * (1.0f / 255.0f)) *
alpha, |
| 853 (SkColorGetB(color) * (1.0f / 255.0f)) *
alpha, |
| 854 alpha)); |
| 740 | 855 |
| 741 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh
ader().matrixLocation()); | 856 GLC(context(), context()->uniform2f(uniforms.texScaleLocation, 1.0f, 1.0f)); |
| 857 |
| 858 if (useAA) { |
| 859 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); |
| 860 } |
| 861 |
| 862 // Enable blending when the quad properties require it or if we decided |
| 863 // to use antialiasing. |
| 864 setBlendEnabled(quad->ShouldDrawWithBlending() || useAA); |
| 865 |
| 866 // Normalize to tileRect. |
| 867 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); |
| 868 |
| 869 setShaderQuadF(localQuad, uniforms.pointLocation); |
| 870 |
| 871 // The transform and vertex data are used to figure out the extents that the |
| 872 // un-antialiased quad should have and which vertex this is and the float |
| 873 // quad passed in via uniform is the actual geometry that gets used to draw |
| 874 // it. This is why this centered rect is used and not the original quadRect. |
| 875 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect
.height()), tileRect.size()); |
| 876 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); |
| 742 } | 877 } |
| 743 | 878 |
| 744 struct TileProgramUniforms { | 879 struct TileProgramUniforms { |
| 745 unsigned program; | 880 unsigned program; |
| 746 unsigned samplerLocation; | 881 unsigned samplerLocation; |
| 747 unsigned vertexTexTransformLocation; | 882 unsigned vertexTexTransformLocation; |
| 748 unsigned fragmentTexTransformLocation; | 883 unsigned fragmentTexTransformLocation; |
| 749 unsigned edgeLocation; | 884 unsigned edgeLocation; |
| 750 unsigned matrixLocation; | 885 unsigned matrixLocation; |
| 751 unsigned alphaLocation; | 886 unsigned alphaLocation; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); | 944 float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); |
| 810 float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); | 945 float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); |
| 811 | 946 |
| 812 // Map to normalized texture coordinates. | 947 // Map to normalized texture coordinates. |
| 813 const gfx::Size& textureSize = quad->texture_size; | 948 const gfx::Size& textureSize = quad->texture_size; |
| 814 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); | 949 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); |
| 815 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); | 950 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); |
| 816 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); | 951 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); |
| 817 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); | 952 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); |
| 818 | 953 |
| 819 gfx::QuadF localQuad; | |
| 820 gfx::Transform deviceTransform = frame.window_matrix * frame.projection_matr
ix * quad->quadTransform(); | 954 gfx::Transform deviceTransform = frame.window_matrix * frame.projection_matr
ix * quad->quadTransform(); |
| 821 deviceTransform.FlattenTo2d(); | 955 deviceTransform.FlattenTo2d(); |
| 822 if (!deviceTransform.IsInvertible()) | 956 if (!deviceTransform.IsInvertible()) |
| 823 return; | 957 return; |
| 824 | 958 |
| 825 bool clipped = false; | 959 gfx::QuadF localQuad = gfx::QuadF(gfx::RectF(tileRect)); |
| 826 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q
uad->visibleContentRect()), clipped); | 960 float edge[24]; |
| 827 DCHECK(!clipped); | 961 bool useAA = setupQuadForAntialiasing(deviceTransform, quad, &localQuad, edg
e); |
| 828 | |
| 829 // TODO(reveman): Axis-aligned is not enough to avoid anti-aliasing. | |
| 830 // Bounding rectangle for quad also needs to be expressible as | |
| 831 // an integer rectangle. crbug.com/169374 | |
| 832 bool isAxisAlignedInTarget = deviceLayerQuad.IsRectilinear(); | |
| 833 bool useAA = !clipped && !isAxisAlignedInTarget && quad->IsEdge(); | |
| 834 | 962 |
| 835 TileProgramUniforms uniforms; | 963 TileProgramUniforms uniforms; |
| 836 if (useAA) { | 964 if (useAA) { |
| 837 if (quad->swizzle_contents) | 965 if (quad->swizzle_contents) |
| 838 tileUniformLocation(tileProgramSwizzleAA(), uniforms); | 966 tileUniformLocation(tileProgramSwizzleAA(), uniforms); |
| 839 else | 967 else |
| 840 tileUniformLocation(tileProgramAA(), uniforms); | 968 tileUniformLocation(tileProgramAA(), uniforms); |
| 841 } else { | 969 } else { |
| 842 if (quad->ShouldDrawWithBlending()) { | 970 if (quad->ShouldDrawWithBlending()) { |
| 843 if (quad->swizzle_contents) | 971 if (quad->swizzle_contents) |
| 844 tileUniformLocation(tileProgramSwizzle(), uniforms); | 972 tileUniformLocation(tileProgramSwizzle(), uniforms); |
| 845 else | 973 else |
| 846 tileUniformLocation(tileProgram(), uniforms); | 974 tileUniformLocation(tileProgram(), uniforms); |
| 847 } else { | 975 } else { |
| 848 if (quad->swizzle_contents) | 976 if (quad->swizzle_contents) |
| 849 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); | 977 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); |
| 850 else | 978 else |
| 851 tileUniformLocation(tileProgramOpaque(), uniforms); | 979 tileUniformLocation(tileProgramOpaque(), uniforms); |
| 852 } | 980 } |
| 853 } | 981 } |
| 854 | 982 |
| 855 setUseProgram(uniforms.program); | 983 setUseProgram(uniforms.program); |
| 856 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); | 984 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); |
| 857 bool scaled = (texToGeomScaleX != 1 || texToGeomScaleY != 1); | 985 bool scaled = (texToGeomScaleX != 1 || texToGeomScaleY != 1); |
| 858 GLenum filter = (useAA || scaled || !quad->quadTransform().IsIdentityOrInteg
erTranslation()) ? GL_LINEAR : GL_NEAREST; | 986 GLenum filter = (useAA || scaled || !quad->quadTransform().IsIdentityOrInteg
erTranslation()) ? GL_LINEAR : GL_NEAREST; |
| 859 ResourceProvider::ScopedSamplerGL quadResourceLock(resource_provider_, quad-
>resource_id, GL_TEXTURE_2D, filter); | 987 ResourceProvider::ScopedSamplerGL quadResourceLock(resource_provider_, quad-
>resource_id, GL_TEXTURE_2D, filter); |
| 860 | 988 |
| 861 if (useAA) { | 989 if (useAA) { |
| 862 LayerQuad deviceLayerBounds(gfx::QuadF(deviceLayerQuad.BoundingBox())); | |
| 863 deviceLayerBounds.InflateAntiAliasingDistance(); | |
| 864 | |
| 865 LayerQuad deviceLayerEdges(deviceLayerQuad); | |
| 866 deviceLayerEdges.InflateAntiAliasingDistance(); | |
| 867 | |
| 868 float edge[24]; | |
| 869 deviceLayerEdges.ToFloatArray(edge); | |
| 870 deviceLayerBounds.ToFloatArray(&edge[12]); | |
| 871 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); | 990 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); |
| 872 | |
| 873 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); | 991 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
| 874 GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocatio
n, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexS
caleY)); | 992 GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocatio
n, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexS
caleY)); |
| 875 | |
| 876 gfx::PointF bottomRight = tileRect.bottom_right(); | |
| 877 gfx::PointF bottomLeft = tileRect.bottom_left(); | |
| 878 gfx::PointF topLeft = tileRect.origin(); | |
| 879 gfx::PointF topRight = tileRect.top_right(); | |
| 880 | |
| 881 // Map points to device space. | |
| 882 bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped); | |
| 883 DCHECK(!clipped); | |
| 884 bottomLeft = MathUtil::mapPoint(deviceTransform, bottomLeft, clipped); | |
| 885 DCHECK(!clipped); | |
| 886 topLeft = MathUtil::mapPoint(deviceTransform, topLeft, clipped); | |
| 887 DCHECK(!clipped); | |
| 888 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); | |
| 889 DCHECK(!clipped); | |
| 890 | |
| 891 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); | |
| 892 LayerQuad::Edge leftEdge(bottomLeft, topLeft); | |
| 893 LayerQuad::Edge topEdge(topLeft, topRight); | |
| 894 LayerQuad::Edge rightEdge(topRight, bottomRight); | |
| 895 | |
| 896 // Only apply anti-aliasing to edges not clipped by culling or scissorin
g. | |
| 897 if (quad->IsTopEdge() && tileRect.y() == quad->rect.y()) | |
| 898 topEdge = deviceLayerEdges.top(); | |
| 899 if (quad->IsLeftEdge() && tileRect.x() == quad->rect.x()) | |
| 900 leftEdge = deviceLayerEdges.left(); | |
| 901 if (quad->IsRightEdge() && tileRect.right() == quad->rect.right()) | |
| 902 rightEdge = deviceLayerEdges.right(); | |
| 903 if (quad->IsBottomEdge() && tileRect.bottom() == quad->rect.bottom()) | |
| 904 bottomEdge = deviceLayerEdges.bottom(); | |
| 905 | |
| 906 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; | |
| 907 bottomEdge.scale(sign); | |
| 908 leftEdge.scale(sign); | |
| 909 topEdge.scale(sign); | |
| 910 rightEdge.scale(sign); | |
| 911 | |
| 912 // Create device space quad. | |
| 913 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | |
| 914 | |
| 915 // Map device space quad to local space. deviceTransform has no 3d compo
nent since it was flattened, so we don't need to project. | |
| 916 // We should have already checked that the transform was uninvertible ab
ove. | |
| 917 gfx::Transform inverseDeviceTransform(gfx::Transform::kSkipInitializatio
n); | |
| 918 bool didInvert = deviceTransform.GetInverse(&inverseDeviceTransform); | |
| 919 DCHECK(didInvert); | |
| 920 localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.ToQuadF
(), clipped); | |
| 921 | |
| 922 // We should not DCHECK(!clipped) here, because anti-aliasing inflation
may cause deviceQuad to become | |
| 923 // clipped. To our knowledge this scenario does not need to be handled d
ifferently than the unclipped case. | |
| 924 } else { | 993 } else { |
| 925 // Move fragment shader transform to vertex shader. We can do this while | 994 // Move fragment shader transform to vertex shader. We can do this while |
| 926 // still producing correct results as fragmentTexTransformLocation | 995 // still producing correct results as fragmentTexTransformLocation |
| 927 // should always be non-negative when tiles are transformed in a way | 996 // should always be non-negative when tiles are transformed in a way |
| 928 // that could result in sampling outside the layer. | 997 // that could result in sampling outside the layer. |
| 929 vertexTexScaleX *= fragmentTexScaleX; | 998 vertexTexScaleX *= fragmentTexScaleX; |
| 930 vertexTexScaleY *= fragmentTexScaleY; | 999 vertexTexScaleY *= fragmentTexScaleY; |
| 931 vertexTexTranslateX *= fragmentTexScaleX; | 1000 vertexTexTranslateX *= fragmentTexScaleX; |
| 932 vertexTexTranslateY *= fragmentTexScaleY; | 1001 vertexTexTranslateY *= fragmentTexScaleY; |
| 933 vertexTexTranslateX += fragmentTexTranslateX; | 1002 vertexTexTranslateX += fragmentTexTranslateX; |
| 934 vertexTexTranslateY += fragmentTexTranslateY; | 1003 vertexTexTranslateY += fragmentTexTranslateY; |
| 935 | 1004 |
| 936 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); | 1005 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
| 937 | |
| 938 localQuad = gfx::RectF(tileRect); | |
| 939 } | 1006 } |
| 940 | 1007 |
| 941 // Enable blending when the quad properties require it or if we decided | 1008 // Enable blending when the quad properties require it or if we decided |
| 942 // to use antialiasing. | 1009 // to use antialiasing. |
| 943 setBlendEnabled(quad->ShouldDrawWithBlending() || useAA); | 1010 setBlendEnabled(quad->ShouldDrawWithBlending() || useAA); |
| 944 | 1011 |
| 945 // Normalize to tileRect. | 1012 // Normalize to tileRect. |
| 946 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); | 1013 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); |
| 947 | 1014 |
| 948 setShaderOpacity(quad->opacity(), uniforms.alphaLocation); | 1015 setShaderOpacity(quad->opacity(), uniforms.alphaLocation); |
| 949 setShaderQuadF(localQuad, uniforms.pointLocation); | 1016 setShaderQuadF(localQuad, uniforms.pointLocation); |
| 950 | 1017 |
| 951 // The tile quad shader behaves differently compared to all other shaders. | |
| 952 // The transform and vertex data are used to figure out the extents that the | 1018 // The transform and vertex data are used to figure out the extents that the |
| 953 // un-antialiased quad should have and which vertex this is and the float | 1019 // un-antialiased quad should have and which vertex this is and the float |
| 954 // quad passed in via uniform is the actual geometry that gets used to draw | 1020 // quad passed in via uniform is the actual geometry that gets used to draw |
| 955 // it. This is why this centered rect is used and not the original quadRect. | 1021 // it. This is why this centered rect is used and not the original quadRect. |
| 956 gfx::RectF centeredRect(gfx::PointF(-0.5f * tileRect.width(), -0.5f * tileRe
ct.height()), tileRect.size()); | 1022 gfx::RectF centeredRect(gfx::PointF(-0.5f * tileRect.width(), -0.5f * tileRe
ct.height()), tileRect.size()); |
| 957 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); | 1023 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); |
| 958 } | 1024 } |
| 959 | 1025 |
| 960 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ
uad* quad) | 1026 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ
uad* quad) |
| 961 { | 1027 { |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 { | 1709 { |
| 1644 if (!m_solidColorProgram) | 1710 if (!m_solidColorProgram) |
| 1645 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); | 1711 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); |
| 1646 if (!m_solidColorProgram->initialized()) { | 1712 if (!m_solidColorProgram->initialized()) { |
| 1647 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); | 1713 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
| 1648 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); | 1714 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); |
| 1649 } | 1715 } |
| 1650 return m_solidColorProgram.get(); | 1716 return m_solidColorProgram.get(); |
| 1651 } | 1717 } |
| 1652 | 1718 |
| 1719 const GLRenderer::SolidColorProgramAA* GLRenderer::solidColorProgramAA() |
| 1720 { |
| 1721 if (!m_solidColorProgramAA) |
| 1722 m_solidColorProgramAA = make_scoped_ptr(new SolidColorProgramAA(m_conte
xt)); |
| 1723 if (!m_solidColorProgramAA->initialized()) { |
| 1724 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); |
| 1725 m_solidColorProgramAA->initialize(m_context, m_isUsingBindUniform); |
| 1726 } |
| 1727 return m_solidColorProgramAA.get(); |
| 1728 } |
| 1729 |
| 1653 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() | 1730 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() |
| 1654 { | 1731 { |
| 1655 DCHECK(m_renderPassProgram); | 1732 DCHECK(m_renderPassProgram); |
| 1656 if (!m_renderPassProgram->initialized()) { | 1733 if (!m_renderPassProgram->initialized()) { |
| 1657 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | 1734 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| 1658 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); | 1735 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); |
| 1659 } | 1736 } |
| 1660 return m_renderPassProgram.get(); | 1737 return m_renderPassProgram.get(); |
| 1661 } | 1738 } |
| 1662 | 1739 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 if (m_textureIOSurfaceProgram) | 1926 if (m_textureIOSurfaceProgram) |
| 1850 m_textureIOSurfaceProgram->cleanup(m_context); | 1927 m_textureIOSurfaceProgram->cleanup(m_context); |
| 1851 | 1928 |
| 1852 if (m_videoYUVProgram) | 1929 if (m_videoYUVProgram) |
| 1853 m_videoYUVProgram->cleanup(m_context); | 1930 m_videoYUVProgram->cleanup(m_context); |
| 1854 if (m_videoStreamTextureProgram) | 1931 if (m_videoStreamTextureProgram) |
| 1855 m_videoStreamTextureProgram->cleanup(m_context); | 1932 m_videoStreamTextureProgram->cleanup(m_context); |
| 1856 | 1933 |
| 1857 if (m_solidColorProgram) | 1934 if (m_solidColorProgram) |
| 1858 m_solidColorProgram->cleanup(m_context); | 1935 m_solidColorProgram->cleanup(m_context); |
| 1936 if (m_solidColorProgramAA) |
| 1937 m_solidColorProgramAA->cleanup(m_context); |
| 1859 | 1938 |
| 1860 if (m_offscreenFramebufferId) | 1939 if (m_offscreenFramebufferId) |
| 1861 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); | 1940 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); |
| 1862 | 1941 |
| 1863 releaseRenderPassTextures(); | 1942 releaseRenderPassTextures(); |
| 1864 } | 1943 } |
| 1865 | 1944 |
| 1866 bool GLRenderer::IsContextLost() | 1945 bool GLRenderer::IsContextLost() |
| 1867 { | 1946 { |
| 1868 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1947 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1869 } | 1948 } |
| 1870 | 1949 |
| 1871 } // namespace cc | 1950 } // namespace cc |
| OLD | NEW |