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

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

Issue 14301021: cc: Don't pass simple well-defined classes by reference. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/shared_quad_state.h » ('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 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "cc/output/gl_renderer.h" // For the GLC() macro. 11 #include "cc/output/gl_renderer.h" // For the GLC() macro.
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
13 #include "third_party/khronos/GLES2/gl2.h" 13 #include "third_party/khronos/GLES2/gl2.h"
14 14
15 #define SHADER0(Src) #Src 15 #define SHADER0(Src) #Src
16 #define VERTEX_SHADER(Src) setVertexTexCoordPrecision(SHADER0(Src)) 16 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src))
17 #define FRAGMENT_SHADER(Src) setFragTexCoordPrecision(precision, SHADER0(Src)) 17 #define FRAGMENT_SHADER(Src) SetFragTexCoordPrecision(precision, SHADER0(Src))
18 18
19 using WebKit::WebGraphicsContext3D; 19 using WebKit::WebGraphicsContext3D;
20 20
21 namespace cc { 21 namespace cc {
22 22
23 namespace { 23 namespace {
24 24
25 static void GetProgramUniformLocations(WebGraphicsContext3D* context, 25 static void GetProgramUniformLocations(WebGraphicsContext3D* context,
26 unsigned program, 26 unsigned program,
27 const char** shader_uniforms, 27 const char** shader_uniforms,
(...skipping 10 matching lines...) Expand all
38 context->bindUniformLocationCHROMIUM(program, 38 context->bindUniformLocationCHROMIUM(program,
39 locations[uniform_index], 39 locations[uniform_index],
40 shader_uniforms[uniform_index]); 40 shader_uniforms[uniform_index]);
41 } else { 41 } else {
42 locations[uniform_index] = 42 locations[uniform_index] =
43 context->getUniformLocation(program, shader_uniforms[uniform_index]); 43 context->getUniformLocation(program, shader_uniforms[uniform_index]);
44 } 44 }
45 } 45 }
46 } 46 }
47 47
48 static std::string setFragTexCoordPrecision( 48 static std::string SetFragTexCoordPrecision(
49 TexCoordPrecision requestedPrecision, std::string shaderString) 49 TexCoordPrecision requested_precision, std::string shader_string) {
50 { 50 switch (requested_precision) {
51 switch (requestedPrecision) {
52 case TexCoordPrecisionHigh: 51 case TexCoordPrecisionHigh:
53 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); 52 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
54 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" 53 return
55 " #define TexCoordPrecision highp\n" 54 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
56 "#else\n" 55 " #define TexCoordPrecision highp\n"
57 " #define TexCoordPrecision mediump\n" 56 "#else\n"
58 "#endif\n" + 57 " #define TexCoordPrecision mediump\n"
59 shaderString; 58 "#endif\n" +
59 shader_string;
60 case TexCoordPrecisionMedium: 60 case TexCoordPrecisionMedium:
61 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); 61 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
62 return "#define TexCoordPrecision mediump\n" + 62 return "#define TexCoordPrecision mediump\n" +
63 shaderString; 63 shader_string;
64 case TexCoordPrecisionNA: 64 case TexCoordPrecisionNA:
65 DCHECK_EQ(shaderString.find("TexCoordPrecision"), std::string::npos); 65 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos);
66 DCHECK_EQ(shaderString.find("texture2D"), std::string::npos); 66 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos);
67 return shaderString; 67 return shader_string;
68 } 68 }
69 return shaderString; 69 return shader_string;
70 } 70 }
71 71
72 static std::string setVertexTexCoordPrecision(const char* shaderString) 72 static std::string SetVertexTexCoordPrecision(const char* shader_string) {
73 { 73 // We unconditionally use highp in the vertex shader since
74 // We unconditionally use highp in the vertex shader since 74 // we are unlikely to be vertex shader bound when drawing large quads.
75 // we are unlikely to be vertex shader bound when drawing large quads. 75 // Also, some vertex shaders mutate the texture coordinate in such a
76 // Also, some vertex shaders mutate the texture coordinate in such a 76 // way that the effective precision might be lower than expected.
77 // way that the effective precision might be lower than expected. 77 return "#define TexCoordPrecision highp\n" +
78 return "#define TexCoordPrecision highp\n" + 78 std::string(shader_string);
79 std::string(shaderString);
80 } 79 }
81 80
82 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, 81 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context,
83 int highp_threshold_min, 82 int highp_threshold_min,
84 int x, int y) { 83 int x, int y) {
85 // Initialize range and precision with minimum spec values for when 84 // Initialize range and precision with minimum spec values for when
86 // getShaderPrecisionFormat is a test stub. 85 // GetShaderPrecisionFormat is a test stub.
87 // TODO: Implement better stubs of getShaderPrecisionFormat everywhere. 86 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat
87 // everywhere.
88 GLint range[2] = { 14, 14 }; 88 GLint range[2] = { 14, 14 };
89 GLint precision = 10; 89 GLint precision = 10;
90 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, 90 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER,
91 GL_MEDIUM_FLOAT, 91 GL_MEDIUM_FLOAT,
92 range, &precision)); 92 range, &precision));
93 int highp_threshold = std::max(1 << precision, highp_threshold_min); 93 int highp_threshold = std::max(1 << precision, highp_threshold_min);
94 if (x > highp_threshold || y > highp_threshold) 94 if (x > highp_threshold || y > highp_threshold)
95 return TexCoordPrecisionHigh; 95 return TexCoordPrecisionHigh;
96 return TexCoordPrecisionMedium; 96 return TexCoordPrecisionMedium;
97 } 97 }
98 98
99 } // namespace 99 } // namespace
100 100
101 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, 101 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context,
102 int highp_threshold_min, 102 int highp_threshold_min,
103 const gfx::Point& max_coordinate) { 103 gfx::Point max_coordinate) {
104 return TexCoordPrecisionRequired(context, highp_threshold_min, 104 return TexCoordPrecisionRequired(context, highp_threshold_min,
105 max_coordinate.x(), max_coordinate.y()); 105 max_coordinate.x(), max_coordinate.y());
106 } 106 }
107 107
108 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, 108 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context,
109 int highp_threshold_min, 109 int highp_threshold_min,
110 const gfx::Size& max_size) { 110 gfx::Size max_size) {
111 return TexCoordPrecisionRequired(context, highp_threshold_min, 111 return TexCoordPrecisionRequired(context, highp_threshold_min,
112 max_size.width(), max_size.height()); 112 max_size.width(), max_size.height());
113 } 113 }
114 114
115 VertexShaderPosTex::VertexShaderPosTex() 115 VertexShaderPosTex::VertexShaderPosTex()
116 : matrix_location_(-1) {} 116 : matrix_location_(-1) {}
117 117
118 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, 118 void VertexShaderPosTex::Init(WebGraphicsContext3D* context,
119 unsigned program, 119 unsigned program,
120 bool using_bind_uniform, 120 bool using_bind_uniform,
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 vec2 texCoord = 1425 vec2 texCoord =
1426 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 1426 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
1427 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1427 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1428 float picker = abs(coord.x - coord.y); 1428 float picker = abs(coord.x - coord.y);
1429 gl_FragColor = mix(color1, color2, picker) * alpha; 1429 gl_FragColor = mix(color1, color2, picker) * alpha;
1430 } 1430 }
1431 ); // NOLINT(whitespace/parens) 1431 ); // NOLINT(whitespace/parens)
1432 } 1432 }
1433 1433
1434 } // namespace cc 1434 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/shared_quad_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698