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

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

Issue 2622243003: The great shader refactor: Clean up GLRenderer (Closed)
Patch Set: Rebase Created 3 years, 11 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/shader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/shader.h" 5 #include "cc/output/shader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return shader_string; 137 return shader_string;
138 default: 138 default:
139 NOTREACHED(); 139 NOTREACHED();
140 break; 140 break;
141 } 141 }
142 return shader_string; 142 return shader_string;
143 } 143 }
144 144
145 } // namespace 145 } // namespace
146 146
147 ShaderLocations::ShaderLocations() {
148 }
149
150 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, 147 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
151 int* highp_threshold_cache, 148 int* highp_threshold_cache,
152 int highp_threshold_min, 149 int highp_threshold_min,
153 const gfx::Point& max_coordinate) { 150 const gfx::Point& max_coordinate) {
154 return TexCoordPrecisionRequired(context, 151 return TexCoordPrecisionRequired(context,
155 highp_threshold_cache, 152 highp_threshold_cache,
156 highp_threshold_min, 153 highp_threshold_min,
157 max_coordinate.x(), 154 max_coordinate.x(),
158 max_coordinate.y()); 155 max_coordinate.y());
159 } 156 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 if (has_vertex_opacity_) 230 if (has_vertex_opacity_)
234 vertex_opacity_location_ = locations[index++]; 231 vertex_opacity_location_ = locations[index++];
235 if (aa_mode_ == USE_AA) { 232 if (aa_mode_ == USE_AA) {
236 viewport_location_ = locations[index++]; 233 viewport_location_ = locations[index++];
237 edge_location_ = locations[index++]; 234 edge_location_ = locations[index++];
238 } 235 }
239 if (position_source_ == POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM) 236 if (position_source_ == POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM)
240 quad_location_ = locations[index++]; 237 quad_location_ = locations[index++];
241 } 238 }
242 239
243 void VertexShaderBase::FillLocations(ShaderLocations* locations) const {
244 locations->quad = quad_location();
245 locations->edge = edge_location();
246 locations->viewport = viewport_location();
247 locations->matrix = matrix_location();
248 locations->vertex_tex_transform = vertex_tex_transform_location();
249 }
250
251 std::string VertexShaderBase::GetShaderString() const { 240 std::string VertexShaderBase::GetShaderString() const {
252 // We unconditionally use highp in the vertex shader since 241 // We unconditionally use highp in the vertex shader since
253 // we are unlikely to be vertex shader bound when drawing large quads. 242 // we are unlikely to be vertex shader bound when drawing large quads.
254 // Also, some vertex shaders mutate the texture coordinate in such a 243 // Also, some vertex shaders mutate the texture coordinate in such a
255 // way that the effective precision might be lower than expected. 244 // way that the effective precision might be lower than expected.
256 std::string header = "#define TexCoordPrecision highp\n"; 245 std::string header = "#define TexCoordPrecision highp\n";
257 std::string source = "void main() {\n"; 246 std::string source = "void main() {\n";
258 247
259 // Define the size of quads for attribute indexed uniform arrays. 248 // Define the size of quads for attribute indexed uniform arrays.
260 if (use_uniform_arrays_) { 249 if (use_uniform_arrays_) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (has_rgba_fragment_tex_transform_) 458 if (has_rgba_fragment_tex_transform_)
470 fragment_tex_transform_location_ = locations[index++]; 459 fragment_tex_transform_location_ = locations[index++];
471 break; 460 break;
472 case INPUT_COLOR_SOURCE_UNIFORM: 461 case INPUT_COLOR_SOURCE_UNIFORM:
473 color_location_ = locations[index++]; 462 color_location_ = locations[index++];
474 break; 463 break;
475 } 464 }
476 DCHECK_EQ(index, locations.size()); 465 DCHECK_EQ(index, locations.size());
477 } 466 }
478 467
479 void FragmentShaderBase::FillLocations(ShaderLocations* locations) const {
480 if (has_blend_mode()) {
481 locations->backdrop = backdrop_location_;
482 locations->backdrop_rect = backdrop_rect_location_;
483 }
484 if (mask_for_background_)
485 locations->original_backdrop = original_backdrop_location_;
486 if (mask_mode_ != NO_MASK) {
487 locations->mask_sampler = mask_sampler_location_;
488 locations->mask_tex_coord_scale = mask_tex_coord_scale_location_;
489 locations->mask_tex_coord_offset = mask_tex_coord_offset_location_;
490 }
491 if (has_color_matrix_) {
492 locations->color_matrix = color_matrix_location_;
493 locations->color_offset = color_offset_location_;
494 }
495 if (has_uniform_alpha_)
496 locations->alpha = alpha_location_;
497 switch (input_color_type_) {
498 case INPUT_COLOR_SOURCE_RGBA_TEXTURE:
499 locations->sampler = sampler_location_;
500 break;
501 case INPUT_COLOR_SOURCE_UNIFORM:
502 break;
503 }
504 }
505
506 std::string FragmentShaderBase::SetBlendModeFunctions( 468 std::string FragmentShaderBase::SetBlendModeFunctions(
507 const std::string& shader_string) const { 469 const std::string& shader_string) const {
508 if (shader_string.find("ApplyBlendMode") == std::string::npos) 470 if (shader_string.find("ApplyBlendMode") == std::string::npos)
509 return shader_string; 471 return shader_string;
510 472
511 if (!has_blend_mode()) { 473 if (!has_blend_mode()) {
512 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; 474 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string;
513 } 475 }
514 476
515 static const std::string kUniforms = SHADER0([]() { 477 static const std::string kUniforms = SHADER0([]() {
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); 1031 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
1070 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); 1032 vec3 yuv = vec3(y_raw, GetUV(uv_clamped));
1071 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); 1033 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped);
1072 } 1034 }
1073 }); 1035 });
1074 1036
1075 return head + functions; 1037 return head + functions;
1076 } 1038 }
1077 1039
1078 } // namespace cc 1040 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698