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

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

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

Powered by Google App Engine
This is Rietveld 408576698