| 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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 SetShaderQuadF(surface_quad, shader_quad_location); | 839 SetShaderQuadF(surface_quad, shader_quad_location); |
| 840 DrawQuadGeometry( | 840 DrawQuadGeometry( |
| 841 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 841 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
| 842 | 842 |
| 843 // Flush the compositor context before the filter bitmap goes out of | 843 // Flush the compositor context before the filter bitmap goes out of |
| 844 // scope, so the draw gets processed before the filter texture gets deleted. | 844 // scope, so the draw gets processed before the filter texture gets deleted. |
| 845 if (filter_bitmap.getTexture()) | 845 if (filter_bitmap.getTexture()) |
| 846 context_->flush(); | 846 context_->flush(); |
| 847 } | 847 } |
| 848 | 848 |
| 849 struct SolidColorProgramUniforms { |
| 850 unsigned program; |
| 851 unsigned matrix_location; |
| 852 unsigned color_location; |
| 853 unsigned point_location; |
| 854 unsigned tex_scale_location; |
| 855 unsigned edge_location; |
| 856 }; |
| 857 |
| 858 template<class T> |
| 859 static void SolidColorUniformLocation(T program, |
| 860 SolidColorProgramUniforms* uniforms) { |
| 861 uniforms->program = program->program(); |
| 862 uniforms->matrix_location = program->vertexShader().matrixLocation(); |
| 863 uniforms->color_location = program->fragmentShader().colorLocation(); |
| 864 uniforms->point_location = program->vertexShader().pointLocation(); |
| 865 uniforms->tex_scale_location = program->vertexShader().texScaleLocation(); |
| 866 uniforms->edge_location = program->fragmentShader().edgeLocation(); |
| 867 } |
| 868 |
| 869 bool GLRenderer::SetupQuadForAntialiasing( |
| 870 const gfx::Transform& device_transform, |
| 871 const DrawQuad* quad, |
| 872 gfx::QuadF* local_quad, |
| 873 float edge[24]) const { |
| 874 gfx::Rect tile_rect = quad->visible_rect; |
| 875 |
| 876 bool clipped = false; |
| 877 gfx::QuadF device_layer_quad = MathUtil::mapQuad( |
| 878 device_transform, gfx::QuadF(quad->visibleContentRect()), clipped); |
| 879 DCHECK(!clipped); |
| 880 |
| 881 // TODO(reveman): Axis-aligned is not enough to avoid anti-aliasing. |
| 882 // Bounding rectangle for quad also needs to be expressible as an integer |
| 883 // rectangle. crbug.com/169374 |
| 884 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear(); |
| 885 bool use_aa = !clipped && !is_axis_aligned_in_target && quad->IsEdge(); |
| 886 |
| 887 if (!use_aa) |
| 888 return false; |
| 889 |
| 890 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); |
| 891 device_layer_bounds.InflateAntiAliasingDistance(); |
| 892 |
| 893 LayerQuad device_layer_edges(device_layer_quad); |
| 894 device_layer_edges.InflateAntiAliasingDistance(); |
| 895 |
| 896 device_layer_edges.ToFloatArray(edge); |
| 897 device_layer_bounds.ToFloatArray(&edge[12]); |
| 898 |
| 899 gfx::PointF bottom_right = tile_rect.bottom_right(); |
| 900 gfx::PointF bottom_left = tile_rect.bottom_left(); |
| 901 gfx::PointF top_left = tile_rect.origin(); |
| 902 gfx::PointF top_right = tile_rect.top_right(); |
| 903 |
| 904 // Map points to device space. |
| 905 bottom_right = MathUtil::mapPoint(device_transform, bottom_right, clipped); |
| 906 DCHECK(!clipped); |
| 907 bottom_left = MathUtil::mapPoint(device_transform, bottom_left, clipped); |
| 908 DCHECK(!clipped); |
| 909 top_left = MathUtil::mapPoint(device_transform, top_left, clipped); |
| 910 DCHECK(!clipped); |
| 911 top_right = MathUtil::mapPoint(device_transform, top_right, clipped); |
| 912 DCHECK(!clipped); |
| 913 |
| 914 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); |
| 915 LayerQuad::Edge left_edge(bottom_left, top_left); |
| 916 LayerQuad::Edge top_edge(top_left, top_right); |
| 917 LayerQuad::Edge right_edge(top_right, bottom_right); |
| 918 |
| 919 // Only apply anti-aliasing to edges not clipped by culling or scissoring. |
| 920 if (quad->IsTopEdge() && tile_rect.y() == quad->rect.y()) |
| 921 top_edge = device_layer_edges.top(); |
| 922 if (quad->IsLeftEdge() && tile_rect.x() == quad->rect.x()) |
| 923 left_edge = device_layer_edges.left(); |
| 924 if (quad->IsRightEdge() && tile_rect.right() == quad->rect.right()) |
| 925 right_edge = device_layer_edges.right(); |
| 926 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) |
| 927 bottom_edge = device_layer_edges.bottom(); |
| 928 |
| 929 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; |
| 930 bottom_edge.scale(sign); |
| 931 left_edge.scale(sign); |
| 932 top_edge.scale(sign); |
| 933 right_edge.scale(sign); |
| 934 |
| 935 // Create device space quad. |
| 936 LayerQuad device_quad(left_edge, top_edge, right_edge, bottom_edge); |
| 937 |
| 938 // Map device space quad to local space. deviceTransform has no 3d |
| 939 // component since it was flattened, so we don't need to project. We should |
| 940 // have already checked that the transform was uninvertible above. |
| 941 gfx::Transform inverse_device_transform( |
| 942 gfx::Transform::kSkipInitialization); |
| 943 bool did_invert = device_transform.GetInverse(&inverse_device_transform); |
| 944 DCHECK(did_invert); |
| 945 *local_quad = MathUtil::mapQuad( |
| 946 inverse_device_transform, device_quad.ToQuadF(), clipped); |
| 947 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
| 948 // cause deviceQuad to become clipped. To our knowledge this scenario does |
| 949 // not need to be handled differently than the unclipped case. |
| 950 |
| 951 return true; |
| 952 } |
| 953 |
| 849 void GLRenderer::DrawSolidColorQuad(const DrawingFrame& frame, | 954 void GLRenderer::DrawSolidColorQuad(const DrawingFrame& frame, |
| 850 const SolidColorDrawQuad* quad) { | 955 const SolidColorDrawQuad* quad) { |
| 851 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 956 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 957 gfx::Rect tile_rect = quad->visible_rect; |
| 852 | 958 |
| 853 const SolidColorProgram* program = GetSolidColorProgram(); | 959 gfx::Transform device_transform = |
| 854 SetUseProgram(program->program()); | 960 frame.window_matrix * frame.projection_matrix * quad->quadTransform(); |
| 961 device_transform.FlattenTo2d(); |
| 962 if (!device_transform.IsInvertible()) |
| 963 return; |
| 964 |
| 965 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 966 float edge[24]; |
| 967 bool use_aa = SetupQuadForAntialiasing( |
| 968 device_transform, quad, &local_quad, edge); |
| 969 |
| 970 SolidColorProgramUniforms uniforms; |
| 971 if (use_aa) |
| 972 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); |
| 973 else |
| 974 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); |
| 975 SetUseProgram(uniforms.program); |
| 855 | 976 |
| 856 SkColor color = quad->color; | 977 SkColor color = quad->color; |
| 857 float opacity = quad->opacity(); | 978 float opacity = quad->opacity(); |
| 858 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 979 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
| 859 | 980 |
| 860 GLC(Context(), | 981 GLC(Context(), |
| 861 Context()->uniform4f(program->fragmentShader().colorLocation(), | 982 Context()->uniform4f(uniforms.color_location, |
| 862 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 983 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| 863 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 984 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
| 864 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, | 985 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, |
| 865 alpha)); | 986 alpha)); |
| 866 | 987 |
| 867 DrawQuadGeometry(frame, | 988 GLC(Context(), Context()->uniform2f(uniforms.tex_scale_location, 1.0f, 1.0f)); |
| 868 quad->quadTransform(), | 989 |
| 869 quad->rect, | 990 if (use_aa) |
| 870 program->vertexShader().matrixLocation()); | 991 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); |
| 992 |
| 993 // Enable blending when the quad properties require it or if we decided |
| 994 // to use antialiasing. |
| 995 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); |
| 996 |
| 997 // Normalize to tileRect. |
| 998 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 999 |
| 1000 SetShaderQuadF(local_quad, uniforms.point_location); |
| 1001 |
| 1002 // The transform and vertex data are used to figure out the extents that the |
| 1003 // un-antialiased quad should have and which vertex this is and the float |
| 1004 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1005 // it. This is why this centered rect is used and not the original quadRect. |
| 1006 gfx::RectF centered_rect(gfx::PointF(-0.5f * tile_rect.width(), |
| 1007 -0.5f * tile_rect.height()), |
| 1008 tile_rect.size()); |
| 1009 DrawQuadGeometry(frame, quad->quadTransform(), |
| 1010 centered_rect, uniforms.matrix_location); |
| 871 } | 1011 } |
| 872 | 1012 |
| 873 struct TileProgramUniforms { | 1013 struct TileProgramUniforms { |
| 874 unsigned program; | 1014 unsigned program; |
| 875 unsigned sampler_location; | 1015 unsigned sampler_location; |
| 876 unsigned vertex_tex_transform_location; | 1016 unsigned vertex_tex_transform_location; |
| 877 unsigned fragment_tex_transform_location; | 1017 unsigned fragment_tex_transform_location; |
| 878 unsigned edge_location; | 1018 unsigned edge_location; |
| 879 unsigned matrix_location; | 1019 unsigned matrix_location; |
| 880 unsigned alpha_location; | 1020 unsigned alpha_location; |
| 881 unsigned point_location; | 1021 unsigned point_location; |
| 882 }; | 1022 }; |
| 883 | 1023 |
| 884 template <class T> | 1024 template <class T> |
| 885 static void TileUniformLocation(T program, TileProgramUniforms& uniforms) { | 1025 static void TileUniformLocation(T program, TileProgramUniforms* uniforms) { |
| 886 uniforms.program = program->program(); | 1026 uniforms->program = program->program(); |
| 887 uniforms.vertex_tex_transform_location = | 1027 uniforms->vertex_tex_transform_location = |
| 888 program->vertexShader().vertexTexTransformLocation(); | 1028 program->vertexShader().vertexTexTransformLocation(); |
| 889 uniforms.matrix_location = program->vertexShader().matrixLocation(); | 1029 uniforms->matrix_location = program->vertexShader().matrixLocation(); |
| 890 uniforms.point_location = program->vertexShader().pointLocation(); | 1030 uniforms->point_location = program->vertexShader().pointLocation(); |
| 891 | 1031 |
| 892 uniforms.sampler_location = program->fragmentShader().samplerLocation(); | 1032 uniforms->sampler_location = program->fragmentShader().samplerLocation(); |
| 893 uniforms.alpha_location = program->fragmentShader().alphaLocation(); | 1033 uniforms->alpha_location = program->fragmentShader().alphaLocation(); |
| 894 uniforms.fragment_tex_transform_location = | 1034 uniforms->fragment_tex_transform_location = |
| 895 program->fragmentShader().fragmentTexTransformLocation(); | 1035 program->fragmentShader().fragmentTexTransformLocation(); |
| 896 uniforms.edge_location = program->fragmentShader().edgeLocation(); | 1036 uniforms->edge_location = program->fragmentShader().edgeLocation(); |
| 897 } | 1037 } |
| 898 | 1038 |
| 899 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, | 1039 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, |
| 900 const TileDrawQuad* quad) { | 1040 const TileDrawQuad* quad) { |
| 901 gfx::Rect tile_rect = quad->visible_rect; | 1041 gfx::Rect tile_rect = quad->visible_rect; |
| 902 | 1042 |
| 903 gfx::RectF tex_coord_rect = quad->tex_coord_rect; | 1043 gfx::RectF tex_coord_rect = quad->tex_coord_rect; |
| 904 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); | 1044 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); |
| 905 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); | 1045 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); |
| 906 | 1046 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); | 1080 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); |
| 941 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); | 1081 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); |
| 942 | 1082 |
| 943 // Map to normalized texture coordinates. | 1083 // Map to normalized texture coordinates. |
| 944 gfx::Size texture_size = quad->texture_size; | 1084 gfx::Size texture_size = quad->texture_size; |
| 945 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); | 1085 float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); |
| 946 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); | 1086 float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); |
| 947 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); | 1087 float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); |
| 948 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); | 1088 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); |
| 949 | 1089 |
| 950 gfx::QuadF local_quad; | |
| 951 gfx::Transform device_transform = | 1090 gfx::Transform device_transform = |
| 952 frame.window_matrix * frame.projection_matrix * quad->quadTransform(); | 1091 frame.window_matrix * frame.projection_matrix * quad->quadTransform(); |
| 953 device_transform.FlattenTo2d(); | 1092 device_transform.FlattenTo2d(); |
| 954 if (!device_transform.IsInvertible()) | 1093 if (!device_transform.IsInvertible()) |
| 955 return; | 1094 return; |
| 956 | 1095 |
| 957 bool clipped = false; | 1096 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 958 gfx::QuadF device_layer_quad = MathUtil::mapQuad( | 1097 float edge[24]; |
| 959 device_transform, gfx::QuadF(quad->visibleContentRect()), clipped); | 1098 bool use_aa = SetupQuadForAntialiasing( |
| 960 DCHECK(!clipped); | 1099 device_transform, quad, &local_quad, edge); |
| 961 | |
| 962 // TODO(reveman): Axis-aligned is not enough to avoid anti-aliasing. | |
| 963 // Bounding rectangle for quad also needs to be expressible as | |
| 964 // an integer rectangle. crbug.com/169374 | |
| 965 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear(); | |
| 966 bool use_aa = !clipped && !is_axis_aligned_in_target && quad->IsEdge(); | |
| 967 | 1100 |
| 968 TileProgramUniforms uniforms; | 1101 TileProgramUniforms uniforms; |
| 969 if (use_aa) { | 1102 if (use_aa) { |
| 970 if (quad->swizzle_contents) | 1103 if (quad->swizzle_contents) |
| 971 TileUniformLocation(GetTileProgramSwizzleAA(), uniforms); | 1104 TileUniformLocation(GetTileProgramSwizzleAA(), &uniforms); |
| 972 else | 1105 else |
| 973 TileUniformLocation(GetTileProgramAA(), uniforms); | 1106 TileUniformLocation(GetTileProgramAA(), &uniforms); |
| 974 } else { | 1107 } else { |
| 975 if (quad->ShouldDrawWithBlending()) { | 1108 if (quad->ShouldDrawWithBlending()) { |
| 976 if (quad->swizzle_contents) | 1109 if (quad->swizzle_contents) |
| 977 TileUniformLocation(GetTileProgramSwizzle(), uniforms); | 1110 TileUniformLocation(GetTileProgramSwizzle(), &uniforms); |
| 978 else | 1111 else |
| 979 TileUniformLocation(GetTileProgram(), uniforms); | 1112 TileUniformLocation(GetTileProgram(), &uniforms); |
| 980 } else { | 1113 } else { |
| 981 if (quad->swizzle_contents) | 1114 if (quad->swizzle_contents) |
| 982 TileUniformLocation(GetTileProgramSwizzleOpaque(), uniforms); | 1115 TileUniformLocation(GetTileProgramSwizzleOpaque(), &uniforms); |
| 983 else | 1116 else |
| 984 TileUniformLocation(GetTileProgramOpaque(), uniforms); | 1117 TileUniformLocation(GetTileProgramOpaque(), &uniforms); |
| 985 } | 1118 } |
| 986 } | 1119 } |
| 987 | 1120 |
| 988 SetUseProgram(uniforms.program); | 1121 SetUseProgram(uniforms.program); |
| 989 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); | 1122 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); |
| 990 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1123 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
| 991 GLenum filter = (use_aa || scaled || | 1124 GLenum filter = (use_aa || scaled || |
| 992 !quad->quadTransform().IsIdentityOrIntegerTranslation()) | 1125 !quad->quadTransform().IsIdentityOrIntegerTranslation()) |
| 993 ? GL_LINEAR | 1126 ? GL_LINEAR |
| 994 : GL_NEAREST; | 1127 : GL_NEAREST; |
| 995 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1128 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
| 996 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); | 1129 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); |
| 997 | 1130 |
| 998 if (use_aa) { | 1131 if (use_aa) { |
| 999 LayerQuad deviceLayerBounds(gfx::QuadF(device_layer_quad.BoundingBox())); | |
| 1000 deviceLayerBounds.InflateAntiAliasingDistance(); | |
| 1001 | |
| 1002 LayerQuad device_layer_edges(device_layer_quad); | |
| 1003 device_layer_edges.InflateAntiAliasingDistance(); | |
| 1004 | |
| 1005 float edge[24]; | |
| 1006 device_layer_edges.ToFloatArray(edge); | |
| 1007 deviceLayerBounds.ToFloatArray(&edge[12]); | |
| 1008 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); | 1132 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); |
| 1009 | 1133 |
| 1010 GLC(Context(), | 1134 GLC(Context(), |
| 1011 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1135 Context()->uniform4f(uniforms.vertex_tex_transform_location, |
| 1012 vertex_tex_translate_x, | 1136 vertex_tex_translate_x, |
| 1013 vertex_tex_translate_y, | 1137 vertex_tex_translate_y, |
| 1014 vertex_tex_scale_x, | 1138 vertex_tex_scale_x, |
| 1015 vertex_tex_scale_y)); | 1139 vertex_tex_scale_y)); |
| 1016 GLC(Context(), | 1140 GLC(Context(), |
| 1017 Context()->uniform4f(uniforms.fragment_tex_transform_location, | 1141 Context()->uniform4f(uniforms.fragment_tex_transform_location, |
| 1018 fragment_tex_translate_x, | 1142 fragment_tex_translate_x, |
| 1019 fragment_tex_translate_y, | 1143 fragment_tex_translate_y, |
| 1020 fragment_tex_scale_x, | 1144 fragment_tex_scale_x, |
| 1021 fragment_tex_scale_y)); | 1145 fragment_tex_scale_y)); |
| 1022 | |
| 1023 gfx::PointF bottom_right = tile_rect.bottom_right(); | |
| 1024 gfx::PointF bottom_left = tile_rect.bottom_left(); | |
| 1025 gfx::PointF top_left = tile_rect.origin(); | |
| 1026 gfx::PointF top_right = tile_rect.top_right(); | |
| 1027 | |
| 1028 // Map points to device space. | |
| 1029 bottom_right = MathUtil::mapPoint(device_transform, bottom_right, clipped); | |
| 1030 DCHECK(!clipped); | |
| 1031 bottom_left = MathUtil::mapPoint(device_transform, bottom_left, clipped); | |
| 1032 DCHECK(!clipped); | |
| 1033 top_left = MathUtil::mapPoint(device_transform, top_left, clipped); | |
| 1034 DCHECK(!clipped); | |
| 1035 top_right = MathUtil::mapPoint(device_transform, top_right, clipped); | |
| 1036 DCHECK(!clipped); | |
| 1037 | |
| 1038 LayerQuad::Edge bottom_edge(bottom_right, bottom_left); | |
| 1039 LayerQuad::Edge left_edge(bottom_left, top_left); | |
| 1040 LayerQuad::Edge top_edge(top_left, top_right); | |
| 1041 LayerQuad::Edge right_edge(top_right, bottom_right); | |
| 1042 | |
| 1043 // Only apply anti-aliasing to edges not clipped by culling or scissoring. | |
| 1044 if (quad->IsTopEdge() && tile_rect.y() == quad->rect.y()) | |
| 1045 top_edge = device_layer_edges.top(); | |
| 1046 if (quad->IsLeftEdge() && tile_rect.x() == quad->rect.x()) | |
| 1047 left_edge = device_layer_edges.left(); | |
| 1048 if (quad->IsRightEdge() && tile_rect.right() == quad->rect.right()) | |
| 1049 right_edge = device_layer_edges.right(); | |
| 1050 if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) | |
| 1051 bottom_edge = device_layer_edges.bottom(); | |
| 1052 | |
| 1053 float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; | |
| 1054 bottom_edge.scale(sign); | |
| 1055 left_edge.scale(sign); | |
| 1056 top_edge.scale(sign); | |
| 1057 right_edge.scale(sign); | |
| 1058 | |
| 1059 // Create device space quad. | |
| 1060 LayerQuad device_quad(left_edge, top_edge, right_edge, bottom_edge); | |
| 1061 | |
| 1062 // Map device space quad to local space. device_transform has no 3d | |
| 1063 // component since it was flattened, so we don't need to project. We should | |
| 1064 // have already checked that the transform was uninvertible above. | |
| 1065 gfx::Transform inverse_device_transform( | |
| 1066 gfx::Transform::kSkipInitialization); | |
| 1067 bool did_invert = device_transform.GetInverse(&inverse_device_transform); | |
| 1068 DCHECK(did_invert); | |
| 1069 local_quad = MathUtil::mapQuad( | |
| 1070 inverse_device_transform, device_quad.ToQuadF(), clipped); | |
| 1071 | |
| 1072 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | |
| 1073 // cause device_quad to become clipped. To our knowledge this scenario does | |
| 1074 // not need to be handled differently than the unclipped case. | |
| 1075 } else { | 1146 } else { |
| 1076 // Move fragment shader transform to vertex shader. We can do this while | 1147 // Move fragment shader transform to vertex shader. We can do this while |
| 1077 // still producing correct results as fragment_tex_transform_location | 1148 // still producing correct results as fragment_tex_transform_location |
| 1078 // should always be non-negative when tiles are transformed in a way | 1149 // should always be non-negative when tiles are transformed in a way |
| 1079 // that could result in sampling outside the layer. | 1150 // that could result in sampling outside the layer. |
| 1080 vertex_tex_scale_x *= fragment_tex_scale_x; | 1151 vertex_tex_scale_x *= fragment_tex_scale_x; |
| 1081 vertex_tex_scale_y *= fragment_tex_scale_y; | 1152 vertex_tex_scale_y *= fragment_tex_scale_y; |
| 1082 vertex_tex_translate_x *= fragment_tex_scale_x; | 1153 vertex_tex_translate_x *= fragment_tex_scale_x; |
| 1083 vertex_tex_translate_y *= fragment_tex_scale_y; | 1154 vertex_tex_translate_y *= fragment_tex_scale_y; |
| 1084 vertex_tex_translate_x += fragment_tex_translate_x; | 1155 vertex_tex_translate_x += fragment_tex_translate_x; |
| 1085 vertex_tex_translate_y += fragment_tex_translate_y; | 1156 vertex_tex_translate_y += fragment_tex_translate_y; |
| 1086 | 1157 |
| 1087 GLC(Context(), | 1158 GLC(Context(), |
| 1088 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1159 Context()->uniform4f(uniforms.vertex_tex_transform_location, |
| 1089 vertex_tex_translate_x, | 1160 vertex_tex_translate_x, |
| 1090 vertex_tex_translate_y, | 1161 vertex_tex_translate_y, |
| 1091 vertex_tex_scale_x, | 1162 vertex_tex_scale_x, |
| 1092 vertex_tex_scale_y)); | 1163 vertex_tex_scale_y)); |
| 1093 | |
| 1094 local_quad = gfx::RectF(tile_rect); | |
| 1095 } | 1164 } |
| 1096 | 1165 |
| 1097 // Enable blending when the quad properties require it or if we decided | 1166 // Enable blending when the quad properties require it or if we decided |
| 1098 // to use antialiasing. | 1167 // to use antialiasing. |
| 1099 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); | 1168 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); |
| 1100 | 1169 |
| 1101 // Normalize to tile_rect. | 1170 // Normalize to tile_rect. |
| 1102 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 1171 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 1103 | 1172 |
| 1104 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); | 1173 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); |
| 1105 SetShaderQuadF(local_quad, uniforms.point_location); | 1174 SetShaderQuadF(local_quad, uniforms.point_location); |
| 1106 | 1175 |
| 1107 // The tile quad shader behaves differently compared to all other shaders. | |
| 1108 // The transform and vertex data are used to figure out the extents that the | 1176 // The transform and vertex data are used to figure out the extents that the |
| 1109 // un-antialiased quad should have and which vertex this is and the float | 1177 // un-antialiased quad should have and which vertex this is and the float |
| 1110 // quad passed in via uniform is the actual geometry that gets used to draw | 1178 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1111 // it. This is why this centered rect is used and not the original quad_rect. | 1179 // it. This is why this centered rect is used and not the original quad_rect. |
| 1112 gfx::RectF centeredRect( | 1180 gfx::RectF centeredRect( |
| 1113 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1181 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1114 tile_rect.size()); | 1182 tile_rect.size()); |
| 1115 DrawQuadGeometry( | 1183 DrawQuadGeometry( |
| 1116 frame, quad->quadTransform(), centeredRect, uniforms.matrix_location); | 1184 frame, quad->quadTransform(), centeredRect, uniforms.matrix_location); |
| 1117 } | 1185 } |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 tile_program_ = make_scoped_ptr(new TileProgram(context_)); | 1963 tile_program_ = make_scoped_ptr(new TileProgram(context_)); |
| 1896 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_)); | 1964 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_)); |
| 1897 | 1965 |
| 1898 GLC(context_, context_->flush()); | 1966 GLC(context_, context_->flush()); |
| 1899 | 1967 |
| 1900 return true; | 1968 return true; |
| 1901 } | 1969 } |
| 1902 | 1970 |
| 1903 const GLRenderer::TileCheckerboardProgram* | 1971 const GLRenderer::TileCheckerboardProgram* |
| 1904 GLRenderer::GetTileCheckerboardProgram() { | 1972 GLRenderer::GetTileCheckerboardProgram() { |
| 1905 if (!tile_checkerboard_program_) | 1973 if (!tile_checkerboard_program_) { |
| 1906 tile_checkerboard_program_ = | 1974 tile_checkerboard_program_ = |
| 1907 make_scoped_ptr(new TileCheckerboardProgram(context_)); | 1975 make_scoped_ptr(new TileCheckerboardProgram(context_)); |
| 1976 } |
| 1908 if (!tile_checkerboard_program_->initialized()) { | 1977 if (!tile_checkerboard_program_->initialized()) { |
| 1909 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); | 1978 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); |
| 1910 tile_checkerboard_program_->initialize(context_, is_using_bind_uniform_); | 1979 tile_checkerboard_program_->initialize(context_, is_using_bind_uniform_); |
| 1911 } | 1980 } |
| 1912 return tile_checkerboard_program_.get(); | 1981 return tile_checkerboard_program_.get(); |
| 1913 } | 1982 } |
| 1914 | 1983 |
| 1915 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { | 1984 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { |
| 1916 if (!solid_color_program_) | 1985 if (!solid_color_program_) |
| 1917 solid_color_program_ = make_scoped_ptr(new SolidColorProgram(context_)); | 1986 solid_color_program_ = make_scoped_ptr(new SolidColorProgram(context_)); |
| 1918 if (!solid_color_program_->initialized()) { | 1987 if (!solid_color_program_->initialized()) { |
| 1919 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); | 1988 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
| 1920 solid_color_program_->initialize(context_, is_using_bind_uniform_); | 1989 solid_color_program_->initialize(context_, is_using_bind_uniform_); |
| 1921 } | 1990 } |
| 1922 return solid_color_program_.get(); | 1991 return solid_color_program_.get(); |
| 1923 } | 1992 } |
| 1924 | 1993 |
| 1994 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() |
| 1995 { |
| 1996 if (!solid_color_program_aa_) { |
| 1997 solid_color_program_aa_ = |
| 1998 make_scoped_ptr(new SolidColorProgramAA(context_)); |
| 1999 } |
| 2000 if (!solid_color_program_aa_->initialized()) { |
| 2001 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); |
| 2002 solid_color_program_aa_->initialize(context_, is_using_bind_uniform_); |
| 2003 } |
| 2004 return solid_color_program_aa_.get(); |
| 2005 } |
| 2006 |
| 1925 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram() { | 2007 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram() { |
| 1926 DCHECK(render_pass_program_); | 2008 DCHECK(render_pass_program_); |
| 1927 if (!render_pass_program_->initialized()) { | 2009 if (!render_pass_program_->initialized()) { |
| 1928 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | 2010 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| 1929 render_pass_program_->initialize(context_, is_using_bind_uniform_); | 2011 render_pass_program_->initialize(context_, is_using_bind_uniform_); |
| 1930 } | 2012 } |
| 1931 return render_pass_program_.get(); | 2013 return render_pass_program_.get(); |
| 1932 } | 2014 } |
| 1933 | 2015 |
| 1934 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA() { | 2016 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA() { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2117 if (texture_io_surface_program_) | 2199 if (texture_io_surface_program_) |
| 2118 texture_io_surface_program_->cleanup(context_); | 2200 texture_io_surface_program_->cleanup(context_); |
| 2119 | 2201 |
| 2120 if (video_yuv_program_) | 2202 if (video_yuv_program_) |
| 2121 video_yuv_program_->cleanup(context_); | 2203 video_yuv_program_->cleanup(context_); |
| 2122 if (video_stream_texture_program_) | 2204 if (video_stream_texture_program_) |
| 2123 video_stream_texture_program_->cleanup(context_); | 2205 video_stream_texture_program_->cleanup(context_); |
| 2124 | 2206 |
| 2125 if (solid_color_program_) | 2207 if (solid_color_program_) |
| 2126 solid_color_program_->cleanup(context_); | 2208 solid_color_program_->cleanup(context_); |
| 2209 if (solid_color_program_aa_) |
| 2210 solid_color_program_aa_->cleanup(context_); |
| 2127 | 2211 |
| 2128 if (offscreen_framebuffer_id_) | 2212 if (offscreen_framebuffer_id_) |
| 2129 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2213 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2130 | 2214 |
| 2131 ReleaseRenderPassTextures(); | 2215 ReleaseRenderPassTextures(); |
| 2132 } | 2216 } |
| 2133 | 2217 |
| 2134 bool GLRenderer::IsContextLost() { | 2218 bool GLRenderer::IsContextLost() { |
| 2135 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2219 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2136 } | 2220 } |
| 2137 | 2221 |
| 2138 } // namespace cc | 2222 } // namespace cc |
| OLD | NEW |