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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 959283004: Background filters are affected by masks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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
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/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 background_image = 931 background_image =
932 ApplyBackgroundFilters(frame, quad, background_texture.get()); 932 ApplyBackgroundFilters(frame, quad, background_texture.get());
933 } 933 }
934 } 934 }
935 935
936 if (!background_texture) { 936 if (!background_texture) {
937 // Something went wrong with reading the backdrop. 937 // Something went wrong with reading the backdrop.
938 DCHECK(!background_image); 938 DCHECK(!background_image);
939 use_shaders_for_blending = false; 939 use_shaders_for_blending = false;
940 } else if (background_image) { 940 } else if (background_image) {
941 background_texture.reset(); 941 // Reset original background texture if there is no any mask
942 if (!quad->mask_resource_id)
943 background_texture.reset();
942 } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) && 944 } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) &&
943 ShouldApplyBackgroundFilters(frame, quad)) { 945 ShouldApplyBackgroundFilters(frame, quad)) {
944 // Something went wrong with applying background filters to the backdrop. 946 // Something went wrong with applying background filters to the backdrop.
945 use_shaders_for_blending = false; 947 use_shaders_for_blending = false;
946 background_texture.reset(); 948 background_texture.reset();
947 } 949 }
948 } 950 }
949 951 // Need original background texture for mask?
952 bool mask_for_background =
953 background_texture && // Have original background texture
954 background_image && // Have filtered background texture
955 quad->mask_resource_id; // Have mask texture
950 SetBlendEnabled( 956 SetBlendEnabled(
951 !use_shaders_for_blending && 957 !use_shaders_for_blending &&
952 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode))); 958 (quad->ShouldDrawWithBlending() || !IsDefaultBlendMode(blend_mode)));
953 959
954 // TODO(senorblanco): Cache this value so that we don't have to do it for both 960 // TODO(senorblanco): Cache this value so that we don't have to do it for both
955 // the surface and its replica. Apply filters to the contents texture. 961 // the surface and its replica. Apply filters to the contents texture.
956 skia::RefPtr<SkImage> filter_image; 962 skia::RefPtr<SkImage> filter_image;
957 SkScalar color_matrix[20]; 963 SkScalar color_matrix[20];
958 bool use_color_matrix = false; 964 bool use_color_matrix = false;
959 if (!quad->filters.IsEmpty()) { 965 if (!quad->filters.IsEmpty()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1015
1010 ApplyBlendModeUsingBlendFunc(blend_mode); 1016 ApplyBlendModeUsingBlendFunc(blend_mode);
1011 } 1017 }
1012 1018
1013 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1019 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1014 gl_, 1020 gl_,
1015 &highp_threshold_cache_, 1021 &highp_threshold_cache_,
1016 highp_threshold_min_, 1022 highp_threshold_min_,
1017 quad->shared_quad_state->visible_content_rect.bottom_right()); 1023 quad->shared_quad_state->visible_content_rect.bottom_right());
1018 1024
1019 int shader_quad_location = -1; 1025 ShaderLocations locations;
1020 int shader_edge_location = -1;
1021 int shader_viewport_location = -1;
1022 int shader_mask_sampler_location = -1;
1023 int shader_mask_tex_coord_scale_location = -1;
1024 int shader_mask_tex_coord_offset_location = -1;
1025 int shader_matrix_location = -1;
1026 int shader_alpha_location = -1;
1027 int shader_color_matrix_location = -1;
1028 int shader_color_offset_location = -1;
1029 int shader_tex_transform_location = -1;
1030 int shader_backdrop_location = -1;
1031 int shader_backdrop_rect_location = -1;
1032 1026
1033 DCHECK_EQ(background_texture || background_image, use_shaders_for_blending); 1027 DCHECK_EQ(background_texture || background_image, use_shaders_for_blending);
1034 BlendMode shader_blend_mode = use_shaders_for_blending 1028 BlendMode shader_blend_mode = use_shaders_for_blending
1035 ? BlendModeFromSkXfermode(blend_mode) 1029 ? BlendModeFromSkXfermode(blend_mode)
1036 : BLEND_MODE_NONE; 1030 : BLEND_MODE_NONE;
1037 1031
1038 if (use_aa && mask_texture_id && !use_color_matrix) { 1032 if (use_aa && mask_texture_id && !use_color_matrix) {
1039 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA( 1033 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA(
1040 tex_coord_precision, mask_sampler, shader_blend_mode); 1034 tex_coord_precision, mask_sampler,
1035 shader_blend_mode, mask_for_background);
1041 SetUseProgram(program->program()); 1036 SetUseProgram(program->program());
1042 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1037 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1043 1038
1044 shader_quad_location = program->vertex_shader().quad_location(); 1039 program->vertex_shader().FillLocations(&locations);
1045 shader_edge_location = program->vertex_shader().edge_location(); 1040 program->fragment_shader().FillLocations(&locations);
1046 shader_viewport_location = program->vertex_shader().viewport_location();
1047 shader_mask_sampler_location =
1048 program->fragment_shader().mask_sampler_location();
1049 shader_mask_tex_coord_scale_location =
1050 program->fragment_shader().mask_tex_coord_scale_location();
1051 shader_mask_tex_coord_offset_location =
1052 program->fragment_shader().mask_tex_coord_offset_location();
1053 shader_matrix_location = program->vertex_shader().matrix_location();
1054 shader_alpha_location = program->fragment_shader().alpha_location();
1055 shader_tex_transform_location =
1056 program->vertex_shader().tex_transform_location();
1057 shader_backdrop_location = program->fragment_shader().backdrop_location();
1058 shader_backdrop_rect_location =
1059 program->fragment_shader().backdrop_rect_location();
1060 } else if (!use_aa && mask_texture_id && !use_color_matrix) { 1041 } else if (!use_aa && mask_texture_id && !use_color_matrix) {
1061 const RenderPassMaskProgram* program = GetRenderPassMaskProgram( 1042 const RenderPassMaskProgram* program = GetRenderPassMaskProgram(
1062 tex_coord_precision, mask_sampler, shader_blend_mode); 1043 tex_coord_precision, mask_sampler,
1044 shader_blend_mode, mask_for_background);
1063 SetUseProgram(program->program()); 1045 SetUseProgram(program->program());
1064 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1046 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1065 1047
1066 shader_mask_sampler_location = 1048 program->vertex_shader().FillLocations(&locations);
1067 program->fragment_shader().mask_sampler_location(); 1049 program->fragment_shader().FillLocations(&locations);
1068 shader_mask_tex_coord_scale_location =
1069 program->fragment_shader().mask_tex_coord_scale_location();
1070 shader_mask_tex_coord_offset_location =
1071 program->fragment_shader().mask_tex_coord_offset_location();
1072 shader_matrix_location = program->vertex_shader().matrix_location();
1073 shader_alpha_location = program->fragment_shader().alpha_location();
1074 shader_tex_transform_location =
1075 program->vertex_shader().tex_transform_location();
1076 shader_backdrop_location = program->fragment_shader().backdrop_location();
1077 shader_backdrop_rect_location =
1078 program->fragment_shader().backdrop_rect_location();
1079 } else if (use_aa && !mask_texture_id && !use_color_matrix) { 1050 } else if (use_aa && !mask_texture_id && !use_color_matrix) {
1080 const RenderPassProgramAA* program = 1051 const RenderPassProgramAA* program =
1081 GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode); 1052 GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode);
1082 SetUseProgram(program->program()); 1053 SetUseProgram(program->program());
1083 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1054 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1084 1055
1085 shader_quad_location = program->vertex_shader().quad_location(); 1056 program->vertex_shader().FillLocations(&locations);
1086 shader_edge_location = program->vertex_shader().edge_location(); 1057 program->fragment_shader().FillLocations(&locations);
1087 shader_viewport_location = program->vertex_shader().viewport_location();
1088 shader_matrix_location = program->vertex_shader().matrix_location();
1089 shader_alpha_location = program->fragment_shader().alpha_location();
1090 shader_tex_transform_location =
1091 program->vertex_shader().tex_transform_location();
1092 shader_backdrop_location = program->fragment_shader().backdrop_location();
1093 shader_backdrop_rect_location =
1094 program->fragment_shader().backdrop_rect_location();
1095 } else if (use_aa && mask_texture_id && use_color_matrix) { 1058 } else if (use_aa && mask_texture_id && use_color_matrix) {
1096 const RenderPassMaskColorMatrixProgramAA* program = 1059 const RenderPassMaskColorMatrixProgramAA* program =
1097 GetRenderPassMaskColorMatrixProgramAA( 1060 GetRenderPassMaskColorMatrixProgramAA(
1098 tex_coord_precision, mask_sampler, shader_blend_mode); 1061 tex_coord_precision, mask_sampler,
1062 shader_blend_mode, mask_for_background);
1099 SetUseProgram(program->program()); 1063 SetUseProgram(program->program());
1100 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1064 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1101 1065
1102 shader_matrix_location = program->vertex_shader().matrix_location(); 1066 program->vertex_shader().FillLocations(&locations);
1103 shader_quad_location = program->vertex_shader().quad_location(); 1067 program->fragment_shader().FillLocations(&locations);
1104 shader_tex_transform_location =
1105 program->vertex_shader().tex_transform_location();
1106 shader_edge_location = program->vertex_shader().edge_location();
1107 shader_viewport_location = program->vertex_shader().viewport_location();
1108 shader_alpha_location = program->fragment_shader().alpha_location();
1109 shader_mask_sampler_location =
1110 program->fragment_shader().mask_sampler_location();
1111 shader_mask_tex_coord_scale_location =
1112 program->fragment_shader().mask_tex_coord_scale_location();
1113 shader_mask_tex_coord_offset_location =
1114 program->fragment_shader().mask_tex_coord_offset_location();
1115 shader_color_matrix_location =
1116 program->fragment_shader().color_matrix_location();
1117 shader_color_offset_location =
1118 program->fragment_shader().color_offset_location();
1119 shader_backdrop_location = program->fragment_shader().backdrop_location();
1120 shader_backdrop_rect_location =
1121 program->fragment_shader().backdrop_rect_location();
1122 } else if (use_aa && !mask_texture_id && use_color_matrix) { 1068 } else if (use_aa && !mask_texture_id && use_color_matrix) {
1123 const RenderPassColorMatrixProgramAA* program = 1069 const RenderPassColorMatrixProgramAA* program =
1124 GetRenderPassColorMatrixProgramAA(tex_coord_precision, 1070 GetRenderPassColorMatrixProgramAA(tex_coord_precision,
1125 shader_blend_mode); 1071 shader_blend_mode);
1126 SetUseProgram(program->program()); 1072 SetUseProgram(program->program());
1127 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1073 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1128 1074
1129 shader_matrix_location = program->vertex_shader().matrix_location(); 1075 program->vertex_shader().FillLocations(&locations);
1130 shader_quad_location = program->vertex_shader().quad_location(); 1076 program->fragment_shader().FillLocations(&locations);
1131 shader_tex_transform_location =
1132 program->vertex_shader().tex_transform_location();
1133 shader_edge_location = program->vertex_shader().edge_location();
1134 shader_viewport_location = program->vertex_shader().viewport_location();
1135 shader_alpha_location = program->fragment_shader().alpha_location();
1136 shader_color_matrix_location =
1137 program->fragment_shader().color_matrix_location();
1138 shader_color_offset_location =
1139 program->fragment_shader().color_offset_location();
1140 shader_backdrop_location = program->fragment_shader().backdrop_location();
1141 shader_backdrop_rect_location =
1142 program->fragment_shader().backdrop_rect_location();
1143 } else if (!use_aa && mask_texture_id && use_color_matrix) { 1077 } else if (!use_aa && mask_texture_id && use_color_matrix) {
1144 const RenderPassMaskColorMatrixProgram* program = 1078 const RenderPassMaskColorMatrixProgram* program =
1145 GetRenderPassMaskColorMatrixProgram( 1079 GetRenderPassMaskColorMatrixProgram(
1146 tex_coord_precision, mask_sampler, shader_blend_mode); 1080 tex_coord_precision, mask_sampler,
1081 shader_blend_mode, mask_for_background);
1147 SetUseProgram(program->program()); 1082 SetUseProgram(program->program());
1148 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1083 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1149 1084
1150 shader_matrix_location = program->vertex_shader().matrix_location(); 1085 program->vertex_shader().FillLocations(&locations);
1151 shader_tex_transform_location = 1086 program->fragment_shader().FillLocations(&locations);
1152 program->vertex_shader().tex_transform_location();
1153 shader_mask_sampler_location =
1154 program->fragment_shader().mask_sampler_location();
1155 shader_mask_tex_coord_scale_location =
1156 program->fragment_shader().mask_tex_coord_scale_location();
1157 shader_mask_tex_coord_offset_location =
1158 program->fragment_shader().mask_tex_coord_offset_location();
1159 shader_alpha_location = program->fragment_shader().alpha_location();
1160 shader_color_matrix_location =
1161 program->fragment_shader().color_matrix_location();
1162 shader_color_offset_location =
1163 program->fragment_shader().color_offset_location();
1164 shader_backdrop_location = program->fragment_shader().backdrop_location();
1165 shader_backdrop_rect_location =
1166 program->fragment_shader().backdrop_rect_location();
1167 } else if (!use_aa && !mask_texture_id && use_color_matrix) { 1087 } else if (!use_aa && !mask_texture_id && use_color_matrix) {
1168 const RenderPassColorMatrixProgram* program = 1088 const RenderPassColorMatrixProgram* program =
1169 GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode); 1089 GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode);
1170 SetUseProgram(program->program()); 1090 SetUseProgram(program->program());
1171 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1091 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1172 1092
1173 shader_matrix_location = program->vertex_shader().matrix_location(); 1093 program->vertex_shader().FillLocations(&locations);
1174 shader_tex_transform_location = 1094 program->fragment_shader().FillLocations(&locations);
1175 program->vertex_shader().tex_transform_location();
1176 shader_alpha_location = program->fragment_shader().alpha_location();
1177 shader_color_matrix_location =
1178 program->fragment_shader().color_matrix_location();
1179 shader_color_offset_location =
1180 program->fragment_shader().color_offset_location();
1181 shader_backdrop_location = program->fragment_shader().backdrop_location();
1182 shader_backdrop_rect_location =
1183 program->fragment_shader().backdrop_rect_location();
1184 } else { 1095 } else {
1185 const RenderPassProgram* program = 1096 const RenderPassProgram* program =
1186 GetRenderPassProgram(tex_coord_precision, shader_blend_mode); 1097 GetRenderPassProgram(tex_coord_precision, shader_blend_mode);
1187 SetUseProgram(program->program()); 1098 SetUseProgram(program->program());
1188 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1099 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1189 1100
1190 shader_matrix_location = program->vertex_shader().matrix_location(); 1101 program->vertex_shader().FillLocations(&locations);
1191 shader_alpha_location = program->fragment_shader().alpha_location(); 1102 program->fragment_shader().FillLocations(&locations);
1192 shader_tex_transform_location =
1193 program->vertex_shader().tex_transform_location();
1194 shader_backdrop_location = program->fragment_shader().backdrop_location();
1195 shader_backdrop_rect_location =
1196 program->fragment_shader().backdrop_rect_location();
1197 } 1103 }
1198 float tex_scale_x = 1104 float tex_scale_x =
1199 quad->rect.width() / static_cast<float>(contents_texture->size().width()); 1105 quad->rect.width() / static_cast<float>(contents_texture->size().width());
1200 float tex_scale_y = quad->rect.height() / 1106 float tex_scale_y = quad->rect.height() /
1201 static_cast<float>(contents_texture->size().height()); 1107 static_cast<float>(contents_texture->size().height());
1202 DCHECK_LE(tex_scale_x, 1.0f); 1108 DCHECK_LE(tex_scale_x, 1.0f);
1203 DCHECK_LE(tex_scale_y, 1.0f); 1109 DCHECK_LE(tex_scale_y, 1.0f);
1204 1110
1205 DCHECK(shader_tex_transform_location != -1 || IsContextLost()); 1111 DCHECK(locations.tex_transform != -1 || IsContextLost());
1206 // Flip the content vertically in the shader, as the RenderPass input 1112 // Flip the content vertically in the shader, as the RenderPass input
1207 // texture is already oriented the same way as the framebuffer, but the 1113 // texture is already oriented the same way as the framebuffer, but the
1208 // projection transform does a flip. 1114 // projection transform does a flip.
1209 GLC(gl_, 1115 GLC(gl_,
1210 gl_->Uniform4f(shader_tex_transform_location, 1116 gl_->Uniform4f(locations.tex_transform,
1211 0.0f, 1117 0.0f,
1212 tex_scale_y, 1118 tex_scale_y,
1213 tex_scale_x, 1119 tex_scale_x,
1214 -tex_scale_y)); 1120 -tex_scale_y));
1215 1121
1216 GLint last_texture_unit = 0; 1122 GLint last_texture_unit = 0;
1217 if (shader_mask_sampler_location != -1) { 1123 if (locations.mask_sampler != -1) {
1218 DCHECK_NE(shader_mask_tex_coord_scale_location, 1); 1124 DCHECK_NE(locations.mask_tex_coord_scale, 1);
1219 DCHECK_NE(shader_mask_tex_coord_offset_location, 1); 1125 DCHECK_NE(locations.mask_tex_coord_offset, 1);
1220 GLC(gl_, gl_->Uniform1i(shader_mask_sampler_location, 1)); 1126 GLC(gl_, gl_->Uniform1i(locations.mask_sampler, 1));
1221 1127
1222 gfx::RectF mask_uv_rect = quad->MaskUVRect(); 1128 gfx::RectF mask_uv_rect = quad->MaskUVRect();
1223 if (mask_sampler != SAMPLER_TYPE_2D) { 1129 if (mask_sampler != SAMPLER_TYPE_2D) {
1224 mask_uv_rect.Scale(quad->mask_texture_size.width(), 1130 mask_uv_rect.Scale(quad->mask_texture_size.width(),
1225 quad->mask_texture_size.height()); 1131 quad->mask_texture_size.height());
1226 } 1132 }
1227 1133
1228 // Mask textures are oriented vertically flipped relative to the framebuffer 1134 // Mask textures are oriented vertically flipped relative to the framebuffer
1229 // and the RenderPass contents texture, so we flip the tex coords from the 1135 // and the RenderPass contents texture, so we flip the tex coords from the
1230 // RenderPass texture to find the mask texture coords. 1136 // RenderPass texture to find the mask texture coords.
1231 GLC(gl_, 1137 GLC(gl_,
1232 gl_->Uniform2f(shader_mask_tex_coord_offset_location, 1138 gl_->Uniform2f(locations.mask_tex_coord_offset,
1233 mask_uv_rect.x(), 1139 mask_uv_rect.x(),
1234 mask_uv_rect.bottom())); 1140 mask_uv_rect.bottom()));
1235 GLC(gl_, 1141 GLC(gl_,
1236 gl_->Uniform2f(shader_mask_tex_coord_scale_location, 1142 gl_->Uniform2f(locations.mask_tex_coord_scale,
1237 mask_uv_rect.width() / tex_scale_x, 1143 mask_uv_rect.width() / tex_scale_x,
1238 -mask_uv_rect.height() / tex_scale_y)); 1144 -mask_uv_rect.height() / tex_scale_y));
1239 1145
1240 last_texture_unit = 1; 1146 last_texture_unit = 1;
1241 } 1147 }
1242 1148
1243 if (shader_edge_location != -1) 1149 if (locations.edge != -1)
1244 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge)); 1150 GLC(gl_, gl_->Uniform3fv(locations.edge, 8, edge));
1245 1151
1246 if (shader_viewport_location != -1) { 1152 if (locations.viewport != -1) {
1247 float viewport[4] = {static_cast<float>(viewport_.x()), 1153 float viewport[4] = {static_cast<float>(viewport_.x()),
1248 static_cast<float>(viewport_.y()), 1154 static_cast<float>(viewport_.y()),
1249 static_cast<float>(viewport_.width()), 1155 static_cast<float>(viewport_.width()),
1250 static_cast<float>(viewport_.height()), }; 1156 static_cast<float>(viewport_.height()), };
1251 GLC(gl_, gl_->Uniform4fv(shader_viewport_location, 1, viewport)); 1157 GLC(gl_, gl_->Uniform4fv(locations.viewport, 1, viewport));
1252 } 1158 }
1253 1159
1254 if (shader_color_matrix_location != -1) { 1160 if (locations.color_matrix != -1) {
1255 float matrix[16]; 1161 float matrix[16];
1256 for (int i = 0; i < 4; ++i) { 1162 for (int i = 0; i < 4; ++i) {
1257 for (int j = 0; j < 4; ++j) 1163 for (int j = 0; j < 4; ++j)
1258 matrix[i * 4 + j] = SkScalarToFloat(color_matrix[j * 5 + i]); 1164 matrix[i * 4 + j] = SkScalarToFloat(color_matrix[j * 5 + i]);
1259 } 1165 }
1260 GLC(gl_, 1166 GLC(gl_,
1261 gl_->UniformMatrix4fv(shader_color_matrix_location, 1, false, matrix)); 1167 gl_->UniformMatrix4fv(locations.color_matrix, 1, false, matrix));
1262 } 1168 }
1263 static const float kScale = 1.0f / 255.0f; 1169 static const float kScale = 1.0f / 255.0f;
1264 if (shader_color_offset_location != -1) { 1170 if (locations.color_offset != -1) {
1265 float offset[4]; 1171 float offset[4];
1266 for (int i = 0; i < 4; ++i) 1172 for (int i = 0; i < 4; ++i)
1267 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale; 1173 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale;
1268 1174
1269 GLC(gl_, gl_->Uniform4fv(shader_color_offset_location, 1, offset)); 1175 GLC(gl_, gl_->Uniform4fv(locations.color_offset, 1, offset));
1270 } 1176 }
1271 1177
1272 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_background_sampler_lock; 1178 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_background_sampler_lock;
1273 if (shader_backdrop_location != -1) { 1179 if (locations.backdrop != -1) {
1274 DCHECK(background_texture || background_image); 1180 DCHECK(background_texture || background_image);
1275 DCHECK_NE(shader_backdrop_location, 0); 1181 DCHECK_NE(locations.backdrop, 0);
1276 DCHECK_NE(shader_backdrop_rect_location, 0); 1182 DCHECK_NE(locations.backdrop_rect, 0);
1277 1183
1278 GLC(gl_, gl_->Uniform1i(shader_backdrop_location, ++last_texture_unit)); 1184 GLC(gl_, gl_->Uniform1i(locations.backdrop, ++last_texture_unit));
1279 1185
1280 GLC(gl_, 1186 GLC(gl_,
1281 gl_->Uniform4f(shader_backdrop_rect_location, 1187 gl_->Uniform4f(locations.backdrop_rect,
1282 background_rect.x(), 1188 background_rect.x(),
1283 background_rect.y(), 1189 background_rect.y(),
1284 background_rect.width(), 1190 background_rect.width(),
1285 background_rect.height())); 1191 background_rect.height()));
1286 1192
1287 if (background_image) { 1193 if (background_image) {
1288 GrTexture* texture = background_image->getTexture(); 1194 GrTexture* texture = background_image->getTexture();
1289 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit)); 1195 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0 + last_texture_unit));
1290 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 1196 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
1291 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); 1197 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0));
1292 } else { 1198 if (mask_for_background)
1199 GLC(gl_, gl_->Uniform1i(locations.original_backdrop,
1200 ++last_texture_unit));
1201 }
1202 if (background_texture) {
1293 shader_background_sampler_lock = make_scoped_ptr( 1203 shader_background_sampler_lock = make_scoped_ptr(
1294 new ResourceProvider::ScopedSamplerGL(resource_provider_, 1204 new ResourceProvider::ScopedSamplerGL(resource_provider_,
1295 background_texture->id(), 1205 background_texture->id(),
1296 GL_TEXTURE0 + last_texture_unit, 1206 GL_TEXTURE0 + last_texture_unit,
1297 GL_LINEAR)); 1207 GL_LINEAR));
1298 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1208 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1299 shader_background_sampler_lock->target()); 1209 shader_background_sampler_lock->target());
1300 } 1210 }
1301 } 1211 }
1302 1212
1303 SetShaderOpacity(quad->opacity(), shader_alpha_location); 1213 SetShaderOpacity(quad->opacity(), locations.alpha);
1304 SetShaderQuadF(surface_quad, shader_quad_location); 1214 SetShaderQuadF(surface_quad, locations.quad);
1305 DrawQuadGeometry( 1215 DrawQuadGeometry(
1306 frame, quad->quadTransform(), quad->rect, shader_matrix_location); 1216 frame, quad->quadTransform(), quad->rect, locations.matrix);
1307 1217
1308 // Flush the compositor context before the filter bitmap goes out of 1218 // Flush the compositor context before the filter bitmap goes out of
1309 // scope, so the draw gets processed before the filter texture gets deleted. 1219 // scope, so the draw gets processed before the filter texture gets deleted.
1310 if (filter_image) 1220 if (filter_image)
1311 GLC(gl_, gl_->Flush()); 1221 GLC(gl_, gl_->Flush());
1312 1222
1313 if (!use_shaders_for_blending) 1223 if (!use_shaders_for_blending)
1314 RestoreBlendFuncToDefault(blend_mode); 1224 RestoreBlendFuncToDefault(blend_mode);
1315 } 1225 }
1316 1226
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); 2708 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize");
2799 program->Initialize(output_surface_->context_provider(), precision, 2709 program->Initialize(output_surface_->context_provider(), precision,
2800 SAMPLER_TYPE_2D, blend_mode); 2710 SAMPLER_TYPE_2D, blend_mode);
2801 } 2711 }
2802 return program; 2712 return program;
2803 } 2713 }
2804 2714
2805 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( 2715 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram(
2806 TexCoordPrecision precision, 2716 TexCoordPrecision precision,
2807 SamplerType sampler, 2717 SamplerType sampler,
2808 BlendMode blend_mode) { 2718 BlendMode blend_mode,
2719 bool mask_for_background) {
2809 DCHECK_GE(precision, 0); 2720 DCHECK_GE(precision, 0);
2810 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2721 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2811 DCHECK_GE(sampler, 0); 2722 DCHECK_GE(sampler, 0);
2812 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 2723 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
2813 DCHECK_GE(blend_mode, 0); 2724 DCHECK_GE(blend_mode, 0);
2814 DCHECK_LE(blend_mode, LAST_BLEND_MODE); 2725 DCHECK_LE(blend_mode, LAST_BLEND_MODE);
2815 RenderPassMaskProgram* program = 2726 RenderPassMaskProgram* program =
2816 &render_pass_mask_program_[precision][sampler][blend_mode]; 2727 &render_pass_mask_program_[precision][sampler][blend_mode]
2728 [mask_for_background ? 1 : 0];
2817 if (!program->initialized()) { 2729 if (!program->initialized()) {
2818 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); 2730 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize");
2819 program->Initialize( 2731 program->Initialize(
2820 output_surface_->context_provider(), precision, sampler, blend_mode); 2732 output_surface_->context_provider(), precision,
2733 sampler, blend_mode, mask_for_background);
2821 } 2734 }
2822 return program; 2735 return program;
2823 } 2736 }
2824 2737
2825 const GLRenderer::RenderPassMaskProgramAA* 2738 const GLRenderer::RenderPassMaskProgramAA*
2826 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision, 2739 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision,
2827 SamplerType sampler, 2740 SamplerType sampler,
2828 BlendMode blend_mode) { 2741 BlendMode blend_mode,
2742 bool mask_for_background) {
2829 DCHECK_GE(precision, 0); 2743 DCHECK_GE(precision, 0);
2830 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2744 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2831 DCHECK_GE(sampler, 0); 2745 DCHECK_GE(sampler, 0);
2832 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 2746 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
2833 DCHECK_GE(blend_mode, 0); 2747 DCHECK_GE(blend_mode, 0);
2834 DCHECK_LE(blend_mode, LAST_BLEND_MODE); 2748 DCHECK_LE(blend_mode, LAST_BLEND_MODE);
2835 RenderPassMaskProgramAA* program = 2749 RenderPassMaskProgramAA* program =
2836 &render_pass_mask_program_aa_[precision][sampler][blend_mode]; 2750 &render_pass_mask_program_aa_[precision][sampler][blend_mode]
2751 [mask_for_background ? 1 : 0];
2837 if (!program->initialized()) { 2752 if (!program->initialized()) {
2838 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); 2753 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize");
2839 program->Initialize( 2754 program->Initialize(
2840 output_surface_->context_provider(), precision, sampler, blend_mode); 2755 output_surface_->context_provider(), precision,
2756 sampler, blend_mode, mask_for_background);
2841 } 2757 }
2842 return program; 2758 return program;
2843 } 2759 }
2844 2760
2845 const GLRenderer::RenderPassColorMatrixProgram* 2761 const GLRenderer::RenderPassColorMatrixProgram*
2846 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision, 2762 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision,
2847 BlendMode blend_mode) { 2763 BlendMode blend_mode) {
2848 DCHECK_GE(precision, 0); 2764 DCHECK_GE(precision, 0);
2849 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2765 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2850 DCHECK_GE(blend_mode, 0); 2766 DCHECK_GE(blend_mode, 0);
(...skipping 20 matching lines...) Expand all
2871 if (!program->initialized()) { 2787 if (!program->initialized()) {
2872 TRACE_EVENT0("cc", 2788 TRACE_EVENT0("cc",
2873 "GLRenderer::renderPassColorMatrixProgramAA::initialize"); 2789 "GLRenderer::renderPassColorMatrixProgramAA::initialize");
2874 program->Initialize(output_surface_->context_provider(), precision, 2790 program->Initialize(output_surface_->context_provider(), precision,
2875 SAMPLER_TYPE_2D, blend_mode); 2791 SAMPLER_TYPE_2D, blend_mode);
2876 } 2792 }
2877 return program; 2793 return program;
2878 } 2794 }
2879 2795
2880 const GLRenderer::RenderPassMaskColorMatrixProgram* 2796 const GLRenderer::RenderPassMaskColorMatrixProgram*
2881 GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision, 2797 GLRenderer::GetRenderPassMaskColorMatrixProgram(
2882 SamplerType sampler, 2798 TexCoordPrecision precision,
2883 BlendMode blend_mode) { 2799 SamplerType sampler,
2800 BlendMode blend_mode,
2801 bool mask_for_background) {
2884 DCHECK_GE(precision, 0); 2802 DCHECK_GE(precision, 0);
2885 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2803 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2886 DCHECK_GE(sampler, 0); 2804 DCHECK_GE(sampler, 0);
2887 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 2805 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
2888 DCHECK_GE(blend_mode, 0); 2806 DCHECK_GE(blend_mode, 0);
2889 DCHECK_LE(blend_mode, LAST_BLEND_MODE); 2807 DCHECK_LE(blend_mode, LAST_BLEND_MODE);
2890 RenderPassMaskColorMatrixProgram* program = 2808 RenderPassMaskColorMatrixProgram* program =
2891 &render_pass_mask_color_matrix_program_[precision][sampler][blend_mode]; 2809 &render_pass_mask_color_matrix_program_[precision][sampler][blend_mode]
2810 [mask_for_background ? 1 : 0];
2892 if (!program->initialized()) { 2811 if (!program->initialized()) {
2893 TRACE_EVENT0("cc", 2812 TRACE_EVENT0("cc",
2894 "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); 2813 "GLRenderer::renderPassMaskColorMatrixProgram::initialize");
2895 program->Initialize( 2814 program->Initialize(
2896 output_surface_->context_provider(), precision, sampler, blend_mode); 2815 output_surface_->context_provider(), precision,
2816 sampler, blend_mode, mask_for_background);
2897 } 2817 }
2898 return program; 2818 return program;
2899 } 2819 }
2900 2820
2901 const GLRenderer::RenderPassMaskColorMatrixProgramAA* 2821 const GLRenderer::RenderPassMaskColorMatrixProgramAA*
2902 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision, 2822 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(
2903 SamplerType sampler, 2823 TexCoordPrecision precision,
2904 BlendMode blend_mode) { 2824 SamplerType sampler,
2825 BlendMode blend_mode,
2826 bool mask_for_background) {
2905 DCHECK_GE(precision, 0); 2827 DCHECK_GE(precision, 0);
2906 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2828 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2907 DCHECK_GE(sampler, 0); 2829 DCHECK_GE(sampler, 0);
2908 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 2830 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
2909 DCHECK_GE(blend_mode, 0); 2831 DCHECK_GE(blend_mode, 0);
2910 DCHECK_LE(blend_mode, LAST_BLEND_MODE); 2832 DCHECK_LE(blend_mode, LAST_BLEND_MODE);
2911 RenderPassMaskColorMatrixProgramAA* program = 2833 RenderPassMaskColorMatrixProgramAA* program =
2912 &render_pass_mask_color_matrix_program_aa_[precision][sampler] 2834 &render_pass_mask_color_matrix_program_aa_[precision][sampler][blend_mode]
2913 [blend_mode]; 2835 [mask_for_background ? 1 : 0];
2914 if (!program->initialized()) { 2836 if (!program->initialized()) {
2915 TRACE_EVENT0("cc", 2837 TRACE_EVENT0("cc",
2916 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); 2838 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize");
2917 program->Initialize( 2839 program->Initialize(
2918 output_surface_->context_provider(), precision, sampler, blend_mode); 2840 output_surface_->context_provider(), precision,
2841 sampler, blend_mode, mask_for_background);
2919 } 2842 }
2920 return program; 2843 return program;
2921 } 2844 }
2922 2845
2923 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( 2846 const GLRenderer::TileProgram* GLRenderer::GetTileProgram(
2924 TexCoordPrecision precision, 2847 TexCoordPrecision precision,
2925 SamplerType sampler) { 2848 SamplerType sampler) {
2926 DCHECK_GE(precision, 0); 2849 DCHECK_GE(precision, 0);
2927 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 2850 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
2928 DCHECK_GE(sampler, 0); 2851 DCHECK_GE(sampler, 0);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 for (int i = 0; i <= LAST_TEX_COORD_PRECISION; ++i) { 3058 for (int i = 0; i <= LAST_TEX_COORD_PRECISION; ++i) {
3136 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { 3059 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) {
3137 tile_program_[i][j].Cleanup(gl_); 3060 tile_program_[i][j].Cleanup(gl_);
3138 tile_program_opaque_[i][j].Cleanup(gl_); 3061 tile_program_opaque_[i][j].Cleanup(gl_);
3139 tile_program_swizzle_[i][j].Cleanup(gl_); 3062 tile_program_swizzle_[i][j].Cleanup(gl_);
3140 tile_program_swizzle_opaque_[i][j].Cleanup(gl_); 3063 tile_program_swizzle_opaque_[i][j].Cleanup(gl_);
3141 tile_program_aa_[i][j].Cleanup(gl_); 3064 tile_program_aa_[i][j].Cleanup(gl_);
3142 tile_program_swizzle_aa_[i][j].Cleanup(gl_); 3065 tile_program_swizzle_aa_[i][j].Cleanup(gl_);
3143 3066
3144 for (int k = 0; k <= LAST_BLEND_MODE; k++) { 3067 for (int k = 0; k <= LAST_BLEND_MODE; k++) {
3145 render_pass_mask_program_[i][j][k].Cleanup(gl_); 3068 for (int l = 0; l <= 1; ++l) {
3146 render_pass_mask_program_aa_[i][j][k].Cleanup(gl_); 3069 render_pass_mask_program_[i][j][k][l].Cleanup(gl_);
3147 render_pass_mask_color_matrix_program_aa_[i][j][k].Cleanup(gl_); 3070 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_);
3148 render_pass_mask_color_matrix_program_[i][j][k].Cleanup(gl_); 3071 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_);
3072 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_);
3073 }
3149 } 3074 }
3150 } 3075 }
3151 for (int j = 0; j <= LAST_BLEND_MODE; j++) { 3076 for (int j = 0; j <= LAST_BLEND_MODE; j++) {
3152 render_pass_program_[i][j].Cleanup(gl_); 3077 render_pass_program_[i][j].Cleanup(gl_);
3153 render_pass_program_aa_[i][j].Cleanup(gl_); 3078 render_pass_program_aa_[i][j].Cleanup(gl_);
3154 render_pass_color_matrix_program_[i][j].Cleanup(gl_); 3079 render_pass_color_matrix_program_[i][j].Cleanup(gl_);
3155 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); 3080 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_);
3156 } 3081 }
3157 3082
3158 texture_program_[i].Cleanup(gl_); 3083 texture_program_[i].Cleanup(gl_);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 context_support_->ScheduleOverlayPlane( 3180 context_support_->ScheduleOverlayPlane(
3256 overlay.plane_z_order, 3181 overlay.plane_z_order,
3257 overlay.transform, 3182 overlay.transform,
3258 pending_overlay_resources_.back()->texture_id(), 3183 pending_overlay_resources_.back()->texture_id(),
3259 overlay.display_rect, 3184 overlay.display_rect,
3260 overlay.uv_rect); 3185 overlay.uv_rect);
3261 } 3186 }
3262 } 3187 }
3263 3188
3264 } // namespace cc 3189 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | cc/output/shader.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698