| OLD | NEW |
| 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 #ifndef CC_OUTPUT_SHADER_H_ | 5 #ifndef CC_OUTPUT_SHADER_H_ |
| 6 #define CC_OUTPUT_SHADER_H_ | 6 #define CC_OUTPUT_SHADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| 25 | 25 |
| 26 enum TexCoordPrecision { | 26 enum TexCoordPrecision { |
| 27 TEX_COORD_PRECISION_NA = 0, | 27 TEX_COORD_PRECISION_NA = 0, |
| 28 TEX_COORD_PRECISION_MEDIUM = 1, | 28 TEX_COORD_PRECISION_MEDIUM = 1, |
| 29 TEX_COORD_PRECISION_HIGH = 2, | 29 TEX_COORD_PRECISION_HIGH = 2, |
| 30 LAST_TEX_COORD_PRECISION = 2 | 30 LAST_TEX_COORD_PRECISION = 2 |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // Texture coordinate sources for the vertex shader. |
| 34 enum TexCoordSource { |
| 35 // Vertex shader does not populate a texture coordinate. |
| 36 TEX_COORD_SOURCE_NONE, |
| 37 // Texture coordinate is set to the untransformed position. |
| 38 TEX_COORD_SOURCE_POSITION, |
| 39 // Texture coordinate has its own attribute. |
| 40 TEX_COORD_SOURCE_ATTRIBUTE, |
| 41 }; |
| 42 |
| 43 // Texture coordinate transformation modes for the vertex shader. |
| 44 enum TexCoordTransform { |
| 45 // Texture coordinates are not transformed. |
| 46 TEX_COORD_TRANSFORM_NONE, |
| 47 // Texture coordinates are transformed by a uniform vec4, scaling by zw and |
| 48 // then translating by xy. |
| 49 TEX_COORD_TRANSFORM_VEC4, |
| 50 // Same as the above, but add vec2(0.5) to the texture coordinate first. |
| 51 TEX_COORD_TRANSFORM_TRANSLATED_VEC4, |
| 52 // Texture coordiantes are transformed by a uniform mat4. |
| 53 TEX_COORD_TRANSFORM_MATRIX, |
| 54 }; |
| 55 |
| 56 // Position source for the vertex shader. |
| 57 enum PositionSource { |
| 58 // The position is read directly from the position attribute. |
| 59 POSITION_SOURCE_ATTRIBUTE, |
| 60 // The position is read by attribute index into a uniform array for xy, and |
| 61 // getting zw from the attribute. |
| 62 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM, |
| 63 }; |
| 64 |
| 33 enum SamplerType { | 65 enum SamplerType { |
| 34 SAMPLER_TYPE_NA = 0, | 66 SAMPLER_TYPE_NA = 0, |
| 35 SAMPLER_TYPE_2D = 1, | 67 SAMPLER_TYPE_2D = 1, |
| 36 SAMPLER_TYPE_2D_RECT = 2, | 68 SAMPLER_TYPE_2D_RECT = 2, |
| 37 SAMPLER_TYPE_EXTERNAL_OES = 3, | 69 SAMPLER_TYPE_EXTERNAL_OES = 3, |
| 38 LAST_SAMPLER_TYPE = 3 | 70 LAST_SAMPLER_TYPE = 3 |
| 39 }; | 71 }; |
| 40 | 72 |
| 41 enum BlendMode { | 73 enum BlendMode { |
| 42 BLEND_MODE_NONE, | 74 BLEND_MODE_NONE, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 int quad = -1; | 116 int quad = -1; |
| 85 int edge = -1; | 117 int edge = -1; |
| 86 int viewport = -1; | 118 int viewport = -1; |
| 87 int mask_sampler = -1; | 119 int mask_sampler = -1; |
| 88 int mask_tex_coord_scale = -1; | 120 int mask_tex_coord_scale = -1; |
| 89 int mask_tex_coord_offset = -1; | 121 int mask_tex_coord_offset = -1; |
| 90 int matrix = -1; | 122 int matrix = -1; |
| 91 int alpha = -1; | 123 int alpha = -1; |
| 92 int color_matrix = -1; | 124 int color_matrix = -1; |
| 93 int color_offset = -1; | 125 int color_offset = -1; |
| 94 int tex_transform = -1; | 126 int vertex_tex_transform = -1; |
| 95 int backdrop = -1; | 127 int backdrop = -1; |
| 96 int backdrop_rect = -1; | 128 int backdrop_rect = -1; |
| 97 int original_backdrop = -1; | 129 int original_backdrop = -1; |
| 98 }; | 130 }; |
| 99 | 131 |
| 100 // Note: The highp_threshold_cache must be provided by the caller to make | 132 // Note: The highp_threshold_cache must be provided by the caller to make |
| 101 // the caching multi-thread/context safe in an easy low-overhead manner. | 133 // the caching multi-thread/context safe in an easy low-overhead manner. |
| 102 // The caller must make sure to clear highp_threshold_cache to 0, so it can be | 134 // The caller must make sure to clear highp_threshold_cache to 0, so it can be |
| 103 // reinitialized, if a new or different context is used. | 135 // reinitialized, if a new or different context is used. |
| 104 CC_EXPORT TexCoordPrecision | 136 CC_EXPORT TexCoordPrecision |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 | 147 |
| 116 class VertexShaderBase { | 148 class VertexShaderBase { |
| 117 public: | 149 public: |
| 118 VertexShaderBase(); | 150 VertexShaderBase(); |
| 119 void Init(gpu::gles2::GLES2Interface* context, | 151 void Init(gpu::gles2::GLES2Interface* context, |
| 120 unsigned program, | 152 unsigned program, |
| 121 int* base_uniform_index); | 153 int* base_uniform_index); |
| 122 std::string GetShaderString() const; | 154 std::string GetShaderString() const; |
| 123 void FillLocations(ShaderLocations* locations) const; | 155 void FillLocations(ShaderLocations* locations) const; |
| 124 | 156 |
| 125 int tex_transform_location() const { return tex_transform_location_; } | |
| 126 | |
| 127 int vertex_tex_transform_location() const { | 157 int vertex_tex_transform_location() const { |
| 128 return vertex_tex_transform_location_; | 158 return vertex_tex_transform_location_; |
| 129 } | 159 } |
| 130 | 160 |
| 131 int tex_matrix_location() const { return tex_matrix_location_; } | 161 int tex_matrix_location() const { return tex_matrix_location_; } |
| 132 | 162 |
| 133 int ya_tex_scale_location() const { return ya_tex_scale_location_; } | 163 int ya_tex_scale_location() const { return ya_tex_scale_location_; } |
| 134 int ya_tex_offset_location() const { return ya_tex_offset_location_; } | 164 int ya_tex_offset_location() const { return ya_tex_offset_location_; } |
| 135 int uv_tex_scale_location() const { return uv_tex_scale_location_; } | 165 int uv_tex_scale_location() const { return uv_tex_scale_location_; } |
| 136 int uv_tex_offset_location() const { return uv_tex_offset_location_; } | 166 int uv_tex_offset_location() const { return uv_tex_offset_location_; } |
| 137 | 167 |
| 138 int matrix_location() const { return matrix_location_; } | 168 int matrix_location() const { return matrix_location_; } |
| 139 | 169 |
| 140 int vertex_opacity_location() const { return vertex_opacity_location_; } | 170 int vertex_opacity_location() const { return vertex_opacity_location_; } |
| 141 | 171 |
| 142 int viewport_location() const { return viewport_location_; } | 172 int viewport_location() const { return viewport_location_; } |
| 143 int edge_location() const { return edge_location_; } | 173 int edge_location() const { return edge_location_; } |
| 144 | 174 |
| 145 int quad_location() const { return quad_location_; } | 175 int quad_location() const { return quad_location_; } |
| 146 | 176 |
| 147 protected: | 177 protected: |
| 148 virtual std::string GetShaderSource() const = 0; | 178 // Use arrays of uniforms for matrix, texTransform, and opacity. |
| 179 bool use_uniform_arrays_ = false; |
| 149 | 180 |
| 150 bool has_tex_transform_ = false; | 181 PositionSource position_source_ = POSITION_SOURCE_ATTRIBUTE; |
| 151 int tex_transform_location_ = -1; | 182 TexCoordSource tex_coord_source_ = TEX_COORD_SOURCE_NONE; |
| 183 TexCoordTransform tex_coord_transform_ = TEX_COORD_TRANSFORM_NONE; |
| 152 | 184 |
| 153 bool has_vertex_tex_transform_ = false; | 185 // Used only with TEX_COORD_TRANSFORM_VEC4. |
| 154 int vertex_tex_transform_location_ = -1; | 186 int vertex_tex_transform_location_ = -1; |
| 155 | 187 |
| 156 bool has_tex_matrix_ = false; | 188 // Used only with TEX_COORD_TRANSFORM_MATRIX. |
| 157 int tex_matrix_location_ = -1; | 189 int tex_matrix_location_ = -1; |
| 158 | 190 |
| 159 bool has_ya_uv_tex_scale_offset_ = false; | 191 // Uniforms for YUV textures. |
| 192 bool is_ya_uv_ = false; |
| 160 int ya_tex_scale_location_ = -1; | 193 int ya_tex_scale_location_ = -1; |
| 161 int ya_tex_offset_location_ = -1; | 194 int ya_tex_offset_location_ = -1; |
| 162 int uv_tex_scale_location_ = -1; | 195 int uv_tex_scale_location_ = -1; |
| 163 int uv_tex_offset_location_ = -1; | 196 int uv_tex_offset_location_ = -1; |
| 164 | 197 |
| 198 // Matrix to transform the position. |
| 165 bool has_matrix_ = false; | 199 bool has_matrix_ = false; |
| 166 int matrix_location_ = -1; | 200 int matrix_location_ = -1; |
| 167 | 201 |
| 202 // Used only with POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM. |
| 203 int quad_location_ = -1; |
| 204 |
| 205 // Extra dummy variables to work around bugs on Android. |
| 206 // TODO(ccameron): This is likley unneeded cargo-culting. |
| 207 // http://crbug.com/240602 |
| 208 bool has_dummy_variables_ = false; |
| 209 |
| 168 bool has_vertex_opacity_ = false; | 210 bool has_vertex_opacity_ = false; |
| 169 int vertex_opacity_location_ = -1; | 211 int vertex_opacity_location_ = -1; |
| 170 | 212 |
| 171 bool has_aa_ = false; | 213 bool has_aa_ = false; |
| 172 int viewport_location_ = -1; | 214 int viewport_location_ = -1; |
| 173 int edge_location_ = -1; | 215 int edge_location_ = -1; |
| 174 | |
| 175 bool has_quad_ = false; | |
| 176 int quad_location_ = -1; | |
| 177 }; | 216 }; |
| 178 | 217 |
| 179 class VertexShaderPosTex : public VertexShaderBase { | 218 class VertexShaderPosTex : public VertexShaderBase { |
| 180 public: | 219 public: |
| 181 VertexShaderPosTex() { has_matrix_ = true; } | 220 VertexShaderPosTex() { |
| 182 std::string GetShaderSource() const override; | 221 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
| 222 has_matrix_ = true; |
| 223 } |
| 183 }; | 224 }; |
| 184 | 225 |
| 185 class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase { | 226 class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase { |
| 186 public: | 227 public: |
| 187 VertexShaderPosTexYUVStretchOffset() { | 228 VertexShaderPosTexYUVStretchOffset() { |
| 229 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
| 188 has_matrix_ = true; | 230 has_matrix_ = true; |
| 189 has_ya_uv_tex_scale_offset_ = true; | 231 is_ya_uv_ = true; |
| 190 } | 232 } |
| 191 std::string GetShaderSource() const override; | |
| 192 }; | 233 }; |
| 193 | 234 |
| 194 class VertexShaderPos : public VertexShaderBase { | 235 class VertexShaderPos : public VertexShaderBase { |
| 195 public: | 236 public: |
| 196 VertexShaderPos() { has_matrix_ = true; } | 237 VertexShaderPos() { has_matrix_ = true; } |
| 197 std::string GetShaderSource() const override; | |
| 198 }; | |
| 199 | |
| 200 class VertexShaderPosTexIdentity : public VertexShaderBase { | |
| 201 public: | |
| 202 std::string GetShaderSource() const override; | |
| 203 }; | 238 }; |
| 204 | 239 |
| 205 class VertexShaderPosTexTransform : public VertexShaderBase { | 240 class VertexShaderPosTexTransform : public VertexShaderBase { |
| 206 public: | 241 public: |
| 207 VertexShaderPosTexTransform() { | 242 VertexShaderPosTexTransform() { |
| 243 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
| 244 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
| 208 has_matrix_ = true; | 245 has_matrix_ = true; |
| 209 has_tex_transform_ = true; | |
| 210 has_vertex_opacity_ = true; | 246 has_vertex_opacity_ = true; |
| 247 use_uniform_arrays_ = true; |
| 211 } | 248 } |
| 212 std::string GetShaderSource() const override; | |
| 213 }; | 249 }; |
| 214 | 250 |
| 215 class VertexShaderQuad : public VertexShaderBase { | 251 class VertexShaderQuad : public VertexShaderBase { |
| 216 public: | 252 public: |
| 217 VertexShaderQuad() { | 253 VertexShaderQuad() { |
| 254 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
| 218 has_matrix_ = true; | 255 has_matrix_ = true; |
| 219 has_quad_ = true; | 256 #if defined(OS_ANDROID) |
| 257 has_dummy_variables_ = true; |
| 258 #endif |
| 220 } | 259 } |
| 221 std::string GetShaderSource() const override; | |
| 222 }; | 260 }; |
| 223 | 261 |
| 224 class VertexShaderQuadAA : public VertexShaderBase { | 262 class VertexShaderQuadAA : public VertexShaderBase { |
| 225 public: | 263 public: |
| 226 VertexShaderQuadAA() { | 264 VertexShaderQuadAA() { |
| 265 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
| 227 has_matrix_ = true; | 266 has_matrix_ = true; |
| 228 has_aa_ = true; | 267 has_aa_ = true; |
| 229 has_quad_ = true; | |
| 230 } | 268 } |
| 231 std::string GetShaderSource() const override; | |
| 232 }; | 269 }; |
| 233 | 270 |
| 234 class VertexShaderQuadTexTransformAA : public VertexShaderBase { | 271 class VertexShaderQuadTexTransformAA : public VertexShaderBase { |
| 235 public: | 272 public: |
| 236 VertexShaderQuadTexTransformAA() { | 273 VertexShaderQuadTexTransformAA() { |
| 274 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
| 275 tex_coord_source_ = TEX_COORD_SOURCE_POSITION; |
| 276 tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; |
| 237 has_matrix_ = true; | 277 has_matrix_ = true; |
| 238 has_aa_ = true; | 278 has_aa_ = true; |
| 239 has_quad_ = true; | |
| 240 has_tex_transform_ = true; | |
| 241 } | 279 } |
| 242 std::string GetShaderSource() const override; | |
| 243 }; | 280 }; |
| 244 | 281 |
| 245 class VertexShaderTile : public VertexShaderBase { | 282 class VertexShaderTile : public VertexShaderBase { |
| 246 public: | 283 public: |
| 247 VertexShaderTile() { | 284 VertexShaderTile() { |
| 285 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
| 286 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
| 287 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
| 248 has_matrix_ = true; | 288 has_matrix_ = true; |
| 249 has_quad_ = true; | |
| 250 has_vertex_tex_transform_ = true; | |
| 251 } | 289 } |
| 252 std::string GetShaderSource() const override; | |
| 253 }; | 290 }; |
| 254 | 291 |
| 255 class VertexShaderTileAA : public VertexShaderBase { | 292 class VertexShaderTileAA : public VertexShaderBase { |
| 256 public: | 293 public: |
| 257 VertexShaderTileAA() { | 294 VertexShaderTileAA() { |
| 295 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
| 296 tex_coord_source_ = TEX_COORD_SOURCE_POSITION; |
| 297 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
| 258 has_matrix_ = true; | 298 has_matrix_ = true; |
| 259 has_quad_ = true; | |
| 260 has_vertex_tex_transform_ = true; | |
| 261 has_aa_ = true; | 299 has_aa_ = true; |
| 262 } | 300 } |
| 263 std::string GetShaderSource() const override; | |
| 264 }; | 301 }; |
| 265 | 302 |
| 266 class VertexShaderVideoTransform : public VertexShaderBase { | 303 class VertexShaderVideoTransform : public VertexShaderBase { |
| 267 public: | 304 public: |
| 268 VertexShaderVideoTransform() { | 305 VertexShaderVideoTransform() { |
| 306 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
| 307 tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; |
| 269 has_matrix_ = true; | 308 has_matrix_ = true; |
| 270 has_tex_matrix_ = true; | |
| 271 } | 309 } |
| 272 std::string GetShaderSource() const override; | |
| 273 }; | 310 }; |
| 274 | 311 |
| 275 class FragmentShaderBase { | 312 class FragmentShaderBase { |
| 276 public: | 313 public: |
| 277 virtual void Init(gpu::gles2::GLES2Interface* context, | 314 virtual void Init(gpu::gles2::GLES2Interface* context, |
| 278 unsigned program, | 315 unsigned program, |
| 279 int* base_uniform_index); | 316 int* base_uniform_index); |
| 280 std::string GetShaderString(TexCoordPrecision precision, | 317 std::string GetShaderString(TexCoordPrecision precision, |
| 281 SamplerType sampler) const; | 318 SamplerType sampler) const; |
| 282 void FillLocations(ShaderLocations* locations) const; | 319 void FillLocations(ShaderLocations* locations) const; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 FragmentShaderColorAA() { | 619 FragmentShaderColorAA() { |
| 583 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; | 620 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; |
| 584 has_aa_ = true; | 621 has_aa_ = true; |
| 585 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 622 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| 586 } | 623 } |
| 587 }; | 624 }; |
| 588 | 625 |
| 589 } // namespace cc | 626 } // namespace cc |
| 590 | 627 |
| 591 #endif // CC_OUTPUT_SHADER_H_ | 628 #endif // CC_OUTPUT_SHADER_H_ |
| OLD | NEW |