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 #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 | 10 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 344 |
345 std::string VertexShaderPosTexTransform::GetShaderHead() { | 345 std::string VertexShaderPosTexTransform::GetShaderHead() { |
346 return SHADER0([]() { | 346 return SHADER0([]() { |
347 attribute vec4 a_position; | 347 attribute vec4 a_position; |
348 attribute TexCoordPrecision vec2 a_texCoord; | 348 attribute TexCoordPrecision vec2 a_texCoord; |
349 attribute float a_index; | 349 attribute float a_index; |
350 uniform mat4 matrix[NUM_STATIC_QUADS]; | 350 uniform mat4 matrix[NUM_STATIC_QUADS]; |
351 uniform TexCoordPrecision vec4 texTransform[NUM_STATIC_QUADS]; | 351 uniform TexCoordPrecision vec4 texTransform[NUM_STATIC_QUADS]; |
352 uniform float opacity[NUM_STATIC_QUADS * 4]; | 352 uniform float opacity[NUM_STATIC_QUADS * 4]; |
353 varying TexCoordPrecision vec2 v_texCoord; | 353 varying TexCoordPrecision vec2 v_texCoord; |
354 varying float v_index; | |
354 varying float v_alpha; | 355 varying float v_alpha; |
355 }); | 356 }); |
356 } | 357 } |
357 | 358 |
358 std::string VertexShaderPosTexTransform::GetShaderBody() { | 359 std::string VertexShaderPosTexTransform::GetShaderBody() { |
359 return SHADER0([]() { | 360 return SHADER0([]() { |
360 void main() { | 361 void main() { |
361 int quad_index = int(a_index * 0.25); // NOLINT | 362 int quad_index = int(a_index * 0.25); // NOLINT |
363 v_index = float(quad_index); | |
362 gl_Position = matrix[quad_index] * a_position; | 364 gl_Position = matrix[quad_index] * a_position; |
363 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; | 365 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; |
364 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 366 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
365 v_alpha = opacity[int(a_index)]; // NOLINT | 367 v_alpha = opacity[int(a_index)]; // NOLINT |
366 } | 368 } |
367 }); | 369 }); |
368 } | 370 } |
369 | 371 |
370 void VertexShaderPosTexTransform::FillLocations( | 372 void VertexShaderPosTexTransform::FillLocations( |
371 ShaderLocations* locations) const { | 373 ShaderLocations* locations) const { |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( | 1211 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
1210 ShaderLocations* locations) const { | 1212 ShaderLocations* locations) const { |
1211 locations->sampler = sampler_location(); | 1213 locations->sampler = sampler_location(); |
1212 locations->alpha = alpha_location(); | 1214 locations->alpha = alpha_location(); |
1213 locations->color_matrix = color_matrix_location(); | 1215 locations->color_matrix = color_matrix_location(); |
1214 locations->color_offset = color_offset_location(); | 1216 locations->color_offset = color_offset_location(); |
1215 locations->backdrop = backdrop_location(); | 1217 locations->backdrop = backdrop_location(); |
1216 locations->backdrop_rect = backdrop_rect_location(); | 1218 locations->backdrop_rect = backdrop_rect_location(); |
1217 } | 1219 } |
1218 | 1220 |
1219 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1221 int FragmentTexQuadBase::background_color_location() const { |
1222 return -1; | |
1223 } | |
1224 | |
1225 int FragmentTexQuadBase::tex_clamp_rect_location() const { | |
dshwang
2016/10/21 13:26:21
When TextureQuad has background color, this locati
| |
1226 return -1; | |
1227 } | |
1228 | |
1229 void FragmentTexClampBinding::Init(GLES2Interface* context, | |
1230 unsigned program, | |
1231 int* base_uniform_index) { | |
1232 static const char* uniforms[] = { | |
1233 "s_texture", "tex_clamp_rect", | |
1234 }; | |
1235 int locations[arraysize(uniforms)]; | |
1236 | |
1237 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms, | |
1238 locations, base_uniform_index); | |
1239 | |
1240 sampler_location_ = locations[0]; | |
1241 DCHECK_NE(sampler_location_, -1); | |
1242 | |
1243 tex_clamp_rect_location_ = locations[1]; | |
1244 DCHECK_NE(tex_clamp_rect_location_, -1); | |
1245 } | |
1246 | |
1247 int FragmentTexClampBinding::tex_clamp_rect_location() const { | |
1248 return tex_clamp_rect_location_; | |
1249 } | |
1250 | |
1251 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderString( | |
1220 TexCoordPrecision precision, | 1252 TexCoordPrecision precision, |
1221 SamplerType sampler) const { | 1253 SamplerType sampler) const { |
1222 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1254 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1223 } | 1255 } |
1224 | 1256 |
1225 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { | 1257 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderHead() { |
1226 return SHADER0([]() { | 1258 return base::StringPrintf("#define NUM_STATIC_QUADS %d\n", |
1227 precision mediump float; | 1259 StaticGeometryBinding::NUM_QUADS) + |
1228 varying TexCoordPrecision vec2 v_texCoord; | 1260 SHADER0([]() { |
1229 varying float v_alpha; | 1261 precision mediump float; |
1230 uniform SamplerType s_texture; | 1262 varying TexCoordPrecision vec2 v_texCoord; |
1231 }); | 1263 varying float v_index; |
1264 varying float v_alpha; | |
1265 uniform SamplerType s_texture; | |
1266 uniform vec4 tex_clamp_rect[NUM_STATIC_QUADS]; | |
1267 }); | |
1232 } | 1268 } |
1233 | 1269 |
1234 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderBody() { | 1270 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderBody() { |
1235 return SHADER0([]() { | 1271 return SHADER0([]() { |
1236 void main() { | 1272 void main() { |
1237 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1273 vec2 tex_clamped = max(tex_clamp_rect[int(v_index)].xy, |
1274 min(tex_clamp_rect[int(v_index)].zw, v_texCoord)); | |
1275 vec4 texColor = TextureLookup(s_texture, tex_clamped); | |
1238 gl_FragColor = texColor * v_alpha; | 1276 gl_FragColor = texColor * v_alpha; |
1239 } | 1277 } |
1240 }); | 1278 }); |
1241 } | 1279 } |
1242 | 1280 |
1243 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 1281 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderString( |
1244 TexCoordPrecision precision, | 1282 TexCoordPrecision precision, |
1245 SamplerType sampler) const { | 1283 SamplerType sampler) const { |
1246 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1284 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1247 } | 1285 } |
1248 | 1286 |
1249 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderHead() { | 1287 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderHead() { |
1250 return SHADER0([]() { | 1288 return base::StringPrintf("#define NUM_STATIC_QUADS %d\n", |
1251 precision mediump float; | 1289 StaticGeometryBinding::NUM_QUADS) + |
1252 varying TexCoordPrecision vec2 v_texCoord; | 1290 SHADER0([]() { |
1253 varying float v_alpha; | 1291 precision mediump float; |
1254 uniform SamplerType s_texture; | 1292 varying TexCoordPrecision vec2 v_texCoord; |
1255 }); | 1293 varying float v_index; |
1294 varying float v_alpha; | |
1295 uniform SamplerType s_texture; | |
1296 uniform vec4 tex_clamp_rect[NUM_STATIC_QUADS]; | |
1297 }); | |
1256 } | 1298 } |
1257 | 1299 |
1258 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderBody() { | 1300 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderBody() { |
1259 return SHADER0([]() { | 1301 return SHADER0([]() { |
1260 void main() { | 1302 void main() { |
1261 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1303 vec2 tex_clamped = max(tex_clamp_rect[int(v_index)].xy, |
1304 min(tex_clamp_rect[int(v_index)].zw, v_texCoord)); | |
1305 vec4 texColor = TextureLookup(s_texture, tex_clamped); | |
1262 texColor.rgb *= texColor.a; | 1306 texColor.rgb *= texColor.a; |
1263 gl_FragColor = texColor * v_alpha; | 1307 gl_FragColor = texColor * v_alpha; |
1264 } | 1308 } |
1265 }); | 1309 }); |
1266 } | 1310 } |
1267 | 1311 |
1312 std::string FragmentShaderRGBATexClamp::GetShaderString( | |
1313 TexCoordPrecision precision, | |
1314 SamplerType sampler) const { | |
1315 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1316 } | |
1317 | |
1318 std::string FragmentShaderRGBATexClamp::GetShaderHead() { | |
1319 return SHADER0([]() { | |
1320 precision mediump float; | |
1321 varying TexCoordPrecision vec2 v_texCoord; | |
1322 uniform SamplerType s_texture; | |
1323 uniform vec4 tex_clamp_rect; | |
1324 }); | |
1325 } | |
1326 | |
1327 std::string FragmentShaderRGBATexClamp::GetShaderBody() { | |
1328 return SHADER0([]() { | |
1329 void main() { | |
1330 vec2 tex_clamped = | |
1331 max(tex_clamp_rect.xy, min(tex_clamp_rect.zw, v_texCoord)); | |
1332 gl_FragColor = TextureLookup(s_texture, tex_clamped); | |
1333 } | |
1334 }); | |
1335 } | |
1336 | |
1268 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | 1337 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
1269 : background_color_location_(-1), sampler_location_(-1) { | 1338 : background_color_location_(-1) {} |
1270 } | |
1271 | 1339 |
1272 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, | 1340 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, |
1273 unsigned program, | 1341 unsigned program, |
1274 int* base_uniform_index) { | 1342 int* base_uniform_index) { |
1275 static const char* uniforms[] = { | 1343 static const char* uniforms[] = { |
1276 "s_texture", "background_color", | 1344 "s_texture", "background_color", |
1277 }; | 1345 }; |
1278 int locations[arraysize(uniforms)]; | 1346 int locations[arraysize(uniforms)]; |
1279 | 1347 |
1280 GetProgramUniformLocations(context, | 1348 GetProgramUniformLocations(context, |
1281 program, | 1349 program, |
1282 arraysize(uniforms), | 1350 arraysize(uniforms), |
1283 uniforms, | 1351 uniforms, |
1284 locations, | 1352 locations, |
1285 base_uniform_index); | 1353 base_uniform_index); |
1286 | 1354 |
1287 sampler_location_ = locations[0]; | 1355 sampler_location_ = locations[0]; |
1288 DCHECK_NE(sampler_location_, -1); | 1356 DCHECK_NE(sampler_location_, -1); |
1289 | 1357 |
1290 background_color_location_ = locations[1]; | 1358 background_color_location_ = locations[1]; |
1291 DCHECK_NE(background_color_location_, -1); | 1359 DCHECK_NE(background_color_location_, -1); |
1292 } | 1360 } |
1293 | 1361 |
1362 int FragmentTexBackgroundBinding::background_color_location() const { | |
1363 return background_color_location_; | |
1364 } | |
1365 | |
1294 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 1366 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( |
1295 TexCoordPrecision precision, | 1367 TexCoordPrecision precision, |
1296 SamplerType sampler) const { | 1368 SamplerType sampler) const { |
1297 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1369 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1298 } | 1370 } |
1299 | 1371 |
1300 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { | 1372 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { |
1301 return SHADER0([]() { | 1373 return SHADER0([]() { |
1302 precision mediump float; | 1374 precision mediump float; |
1303 varying TexCoordPrecision vec2 v_texCoord; | 1375 varying TexCoordPrecision vec2 v_texCoord; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1360 | 1432 |
1361 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { | 1433 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { |
1362 return SHADER0([]() { | 1434 return SHADER0([]() { |
1363 void main() { | 1435 void main() { |
1364 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1436 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1365 gl_FragColor = vec4(texColor.rgb, 1.0); | 1437 gl_FragColor = vec4(texColor.rgb, 1.0); |
1366 } | 1438 } |
1367 }); | 1439 }); |
1368 } | 1440 } |
1369 | 1441 |
1370 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, | |
1371 SamplerType sampler) const { | |
1372 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1373 } | |
1374 | |
1375 std::string FragmentShaderRGBATex::GetShaderHead() { | |
1376 return SHADER0([]() { | |
1377 precision mediump float; | |
1378 varying TexCoordPrecision vec2 v_texCoord; | |
1379 uniform SamplerType s_texture; | |
1380 }); | |
1381 } | |
1382 | |
1383 std::string FragmentShaderRGBATex::GetShaderBody() { | |
1384 return SHADER0([]() { | |
1385 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } | |
1386 }); | |
1387 } | |
1388 | |
1389 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 1442 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
1390 TexCoordPrecision precision, | 1443 TexCoordPrecision precision, |
1391 SamplerType sampler) const { | 1444 SamplerType sampler) const { |
1392 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1445 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1393 } | 1446 } |
1394 | 1447 |
1395 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { | 1448 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { |
1396 return SHADER0([]() { | 1449 return SHADER0([]() { |
1397 precision mediump float; | 1450 precision mediump float; |
1398 varying TexCoordPrecision vec2 v_texCoord; | 1451 varying TexCoordPrecision vec2 v_texCoord; |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2252 void main() { | 2305 void main() { |
2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2306 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
2254 vec2 d2 = min(d4.xz, d4.yw); | 2307 vec2 d2 = min(d4.xz, d4.yw); |
2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2308 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
2256 gl_FragColor = color * aa; | 2309 gl_FragColor = color * aa; |
2257 } | 2310 } |
2258 }); | 2311 }); |
2259 } | 2312 } |
2260 | 2313 |
2261 } // namespace cc | 2314 } // namespace cc |
OLD | NEW |