OLD | NEW |
---|---|
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1310 void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params) { | 1310 void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params) { |
1311 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1311 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1312 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1312 gl_, &highp_threshold_cache_, highp_threshold_min_, |
1313 params->quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 1313 params->quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
1314 | 1314 |
1315 BlendMode shader_blend_mode = | 1315 BlendMode shader_blend_mode = |
1316 params->use_shaders_for_blending | 1316 params->use_shaders_for_blending |
1317 ? BlendModeFromSkXfermode(params->quad->shared_quad_state->blend_mode) | 1317 ? BlendModeFromSkXfermode(params->quad->shared_quad_state->blend_mode) |
1318 : BLEND_MODE_NONE; | 1318 : BLEND_MODE_NONE; |
1319 | 1319 |
1320 unsigned mask_texture_id = 0; | 1320 SamplerType sampler_type = SAMPLER_TYPE_2D; |
1321 SamplerType mask_sampler = SAMPLER_TYPE_NA; | 1321 MaskMode mask_mode = NO_MASK; |
1322 bool mask_for_background = params->mask_for_background; | |
1322 if (params->mask_resource_lock) { | 1323 if (params->mask_resource_lock) { |
1323 mask_texture_id = params->mask_resource_lock->texture_id(); | 1324 mask_mode = HAS_MASK; |
1324 mask_sampler = | 1325 sampler_type = |
1325 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); | 1326 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); |
1326 } | 1327 } |
1327 bool mask_for_background = params->mask_for_background; | |
1328 | 1328 |
1329 if (params->use_aa && mask_texture_id && !params->use_color_matrix) { | 1329 const Program* program = GetProgram(ProgramKey::RenderPass( |
enne (OOO)
2017/01/09 19:46:48
This cleanup is great.
| |
1330 const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA( | 1330 tex_coord_precision, sampler_type, shader_blend_mode, |
1331 tex_coord_precision, mask_sampler, | 1331 params->use_aa ? USE_AA : NO_AA, mask_mode, mask_for_background, |
1332 shader_blend_mode, mask_for_background); | 1332 params->use_color_matrix)); |
1333 SetUseProgram(program->program()); | 1333 SetUseProgram(program->program()); |
1334 program->vertex_shader().FillLocations(¶ms->locations); | 1334 program->vertex_shader().FillLocations(¶ms->locations); |
1335 program->fragment_shader().FillLocations(¶ms->locations); | 1335 program->fragment_shader().FillLocations(¶ms->locations); |
1336 gl_->Uniform1i(params->locations.sampler, 0); | 1336 gl_->Uniform1i(params->locations.sampler, 0); |
1337 } else if (!params->use_aa && mask_texture_id && !params->use_color_matrix) { | |
1338 const RenderPassMaskProgram* program = GetRenderPassMaskProgram( | |
1339 tex_coord_precision, mask_sampler, | |
1340 shader_blend_mode, mask_for_background); | |
1341 SetUseProgram(program->program()); | |
1342 program->vertex_shader().FillLocations(¶ms->locations); | |
1343 program->fragment_shader().FillLocations(¶ms->locations); | |
1344 gl_->Uniform1i(params->locations.sampler, 0); | |
1345 } else if (params->use_aa && !mask_texture_id && !params->use_color_matrix) { | |
1346 const RenderPassProgramAA* program = | |
1347 GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode); | |
1348 SetUseProgram(program->program()); | |
1349 program->vertex_shader().FillLocations(¶ms->locations); | |
1350 program->fragment_shader().FillLocations(¶ms->locations); | |
1351 gl_->Uniform1i(params->locations.sampler, 0); | |
1352 } else if (params->use_aa && mask_texture_id && params->use_color_matrix) { | |
1353 const RenderPassMaskColorMatrixProgramAA* program = | |
1354 GetRenderPassMaskColorMatrixProgramAA( | |
1355 tex_coord_precision, mask_sampler, | |
1356 shader_blend_mode, mask_for_background); | |
1357 SetUseProgram(program->program()); | |
1358 program->vertex_shader().FillLocations(¶ms->locations); | |
1359 program->fragment_shader().FillLocations(¶ms->locations); | |
1360 gl_->Uniform1i(params->locations.sampler, 0); | |
1361 } else if (params->use_aa && !mask_texture_id && params->use_color_matrix) { | |
1362 const RenderPassColorMatrixProgramAA* program = | |
1363 GetRenderPassColorMatrixProgramAA(tex_coord_precision, | |
1364 shader_blend_mode); | |
1365 SetUseProgram(program->program()); | |
1366 program->vertex_shader().FillLocations(¶ms->locations); | |
1367 program->fragment_shader().FillLocations(¶ms->locations); | |
1368 gl_->Uniform1i(params->locations.sampler, 0); | |
1369 } else if (!params->use_aa && mask_texture_id && params->use_color_matrix) { | |
1370 const RenderPassMaskColorMatrixProgram* program = | |
1371 GetRenderPassMaskColorMatrixProgram( | |
1372 tex_coord_precision, mask_sampler, | |
1373 shader_blend_mode, mask_for_background); | |
1374 SetUseProgram(program->program()); | |
1375 program->vertex_shader().FillLocations(¶ms->locations); | |
1376 program->fragment_shader().FillLocations(¶ms->locations); | |
1377 gl_->Uniform1i(params->locations.sampler, 0); | |
1378 } else if (!params->use_aa && !mask_texture_id && params->use_color_matrix) { | |
1379 const RenderPassColorMatrixProgram* program = | |
1380 GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode); | |
1381 SetUseProgram(program->program()); | |
1382 program->vertex_shader().FillLocations(¶ms->locations); | |
1383 program->fragment_shader().FillLocations(¶ms->locations); | |
1384 gl_->Uniform1i(params->locations.sampler, 0); | |
1385 } else { | |
1386 const RenderPassProgram* program = | |
1387 GetRenderPassProgram(tex_coord_precision, shader_blend_mode); | |
1388 SetUseProgram(program->program()); | |
1389 program->vertex_shader().FillLocations(¶ms->locations); | |
1390 program->fragment_shader().FillLocations(¶ms->locations); | |
1391 gl_->Uniform1i(params->locations.sampler, 0); | |
1392 } | |
1393 } | 1337 } |
1394 | 1338 |
1395 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { | 1339 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { |
1396 ShaderLocations& locations = params->locations; | 1340 ShaderLocations& locations = params->locations; |
1397 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(), | 1341 gfx::RectF tex_rect(params->src_offset.x(), params->src_offset.y(), |
1398 params->dst_rect.width(), params->dst_rect.height()); | 1342 params->dst_rect.width(), params->dst_rect.height()); |
1399 gfx::Size texture_size; | 1343 gfx::Size texture_size; |
1400 if (params->filter_image) { | 1344 if (params->filter_image) { |
1401 texture_size.set_width(params->filter_image->width()); | 1345 texture_size.set_width(params->filter_image->width()); |
1402 texture_size.set_height(params->filter_image->height()); | 1346 texture_size.set_height(params->filter_image->height()); |
(...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3279 case CLIPPED_BINDING: | 3223 case CLIPPED_BINDING: |
3280 clipped_geometry_->PrepareForDraw(); | 3224 clipped_geometry_->PrepareForDraw(); |
3281 break; | 3225 break; |
3282 case NO_BINDING: | 3226 case NO_BINDING: |
3283 break; | 3227 break; |
3284 } | 3228 } |
3285 bound_geometry_ = binding; | 3229 bound_geometry_ = binding; |
3286 } | 3230 } |
3287 | 3231 |
3288 const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { | 3232 const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { |
3289 if (!debug_border_program_.initialized()) { | 3233 return GetProgram(ProgramKey::DebugBorder()); |
3290 TRACE_EVENT0("cc", "GLRenderer::debugBorderProgram::initialize"); | |
3291 debug_border_program_.InitializeDebugBorderProgram( | |
3292 output_surface_->context_provider()); | |
3293 } | |
3294 return &debug_border_program_; | |
3295 } | 3234 } |
3296 | 3235 |
3297 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { | 3236 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { |
3298 if (!solid_color_program_.initialized()) { | 3237 return GetProgram(ProgramKey::SolidColor(NO_AA)); |
3299 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); | |
3300 solid_color_program_.InitializeSolidColorProgram( | |
3301 output_surface_->context_provider(), false); | |
3302 } | |
3303 return &solid_color_program_; | |
3304 } | 3238 } |
3305 | 3239 |
3306 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { | 3240 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { |
3307 if (!solid_color_program_aa_.initialized()) { | 3241 return GetProgram(ProgramKey::SolidColor(USE_AA)); |
3308 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); | |
3309 solid_color_program_aa_.InitializeSolidColorProgram( | |
3310 output_surface_->context_provider(), true); | |
3311 } | |
3312 return &solid_color_program_aa_; | |
3313 } | 3242 } |
3314 | 3243 |
3315 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( | 3244 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( |
3316 TexCoordPrecision precision, | 3245 TexCoordPrecision precision, |
3317 BlendMode blend_mode) { | 3246 BlendMode blend_mode) { |
3318 DCHECK_GE(precision, 0); | 3247 return GetProgram(ProgramKey::RenderPass( |
3319 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3248 precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, false)); |
3320 DCHECK_GE(blend_mode, 0); | |
3321 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3322 RenderPassProgram* program = &render_pass_program_[precision][blend_mode]; | |
3323 if (!program->initialized()) { | |
3324 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | |
3325 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3326 precision, SAMPLER_TYPE_2D, blend_mode, | |
3327 NO_AA, NO_MASK, false, false); | |
3328 } | |
3329 return program; | |
3330 } | 3249 } |
3331 | 3250 |
3332 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( | 3251 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( |
3333 TexCoordPrecision precision, | 3252 TexCoordPrecision precision, |
3334 BlendMode blend_mode) { | 3253 BlendMode blend_mode) { |
3335 DCHECK_GE(precision, 0); | 3254 return GetProgram(ProgramKey::RenderPass( |
3336 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3255 precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, false)); |
3337 DCHECK_GE(blend_mode, 0); | |
3338 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3339 RenderPassProgramAA* program = | |
3340 &render_pass_program_aa_[precision][blend_mode]; | |
3341 if (!program->initialized()) { | |
3342 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); | |
3343 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3344 precision, SAMPLER_TYPE_2D, blend_mode, | |
3345 USE_AA, NO_MASK, false, false); | |
3346 } | |
3347 return program; | |
3348 } | 3256 } |
3349 | 3257 |
3350 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( | 3258 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( |
3351 TexCoordPrecision precision, | 3259 TexCoordPrecision precision, |
3352 SamplerType sampler, | 3260 SamplerType sampler, |
3353 BlendMode blend_mode, | 3261 BlendMode blend_mode, |
3354 bool mask_for_background) { | 3262 bool mask_for_background) { |
3355 DCHECK_GE(precision, 0); | 3263 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
3356 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3264 NO_AA, HAS_MASK, mask_for_background, |
3357 DCHECK_GE(sampler, 0); | 3265 false)); |
3358 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3359 DCHECK_GE(blend_mode, 0); | |
3360 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3361 RenderPassMaskProgram* program = | |
3362 &render_pass_mask_program_[precision][sampler][blend_mode] | |
3363 [mask_for_background ? HAS_MASK : NO_MASK]; | |
3364 if (!program->initialized()) { | |
3365 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); | |
3366 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3367 precision, sampler, blend_mode, NO_AA, | |
3368 HAS_MASK, mask_for_background, false); | |
3369 } | |
3370 return program; | |
3371 } | 3266 } |
3372 | 3267 |
3373 const GLRenderer::RenderPassMaskProgramAA* | 3268 const GLRenderer::RenderPassMaskProgramAA* |
3374 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision, | 3269 GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision, |
3375 SamplerType sampler, | 3270 SamplerType sampler, |
3376 BlendMode blend_mode, | 3271 BlendMode blend_mode, |
3377 bool mask_for_background) { | 3272 bool mask_for_background) { |
3378 DCHECK_GE(precision, 0); | 3273 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
3379 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3274 USE_AA, HAS_MASK, |
3380 DCHECK_GE(sampler, 0); | 3275 mask_for_background, false)); |
3381 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3382 DCHECK_GE(blend_mode, 0); | |
3383 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3384 RenderPassMaskProgramAA* program = | |
3385 &render_pass_mask_program_aa_[precision][sampler][blend_mode] | |
3386 [mask_for_background ? HAS_MASK : NO_MASK]; | |
3387 if (!program->initialized()) { | |
3388 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); | |
3389 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3390 precision, sampler, blend_mode, USE_AA, | |
3391 HAS_MASK, mask_for_background, false); | |
3392 } | |
3393 return program; | |
3394 } | 3276 } |
3395 | 3277 |
3396 const GLRenderer::RenderPassColorMatrixProgram* | 3278 const GLRenderer::RenderPassColorMatrixProgram* |
3397 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision, | 3279 GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision, |
3398 BlendMode blend_mode) { | 3280 BlendMode blend_mode) { |
3399 DCHECK_GE(precision, 0); | 3281 return GetProgram(ProgramKey::RenderPass( |
3400 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3282 precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, true)); |
3401 DCHECK_GE(blend_mode, 0); | |
3402 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3403 RenderPassColorMatrixProgram* program = | |
3404 &render_pass_color_matrix_program_[precision][blend_mode]; | |
3405 if (!program->initialized()) { | |
3406 TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgram::initialize"); | |
3407 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3408 precision, SAMPLER_TYPE_2D, blend_mode, | |
3409 NO_AA, NO_MASK, false, true); | |
3410 } | |
3411 return program; | |
3412 } | 3283 } |
3413 | 3284 |
3414 const GLRenderer::RenderPassColorMatrixProgramAA* | 3285 const GLRenderer::RenderPassColorMatrixProgramAA* |
3415 GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision, | 3286 GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision, |
3416 BlendMode blend_mode) { | 3287 BlendMode blend_mode) { |
3417 DCHECK_GE(precision, 0); | 3288 return GetProgram(ProgramKey::RenderPass( |
3418 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3289 precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, true)); |
3419 DCHECK_GE(blend_mode, 0); | 3290 } |
3420 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | 3291 |
3421 RenderPassColorMatrixProgramAA* program = | 3292 const GLRenderer::RenderPassMaskColorMatrixProgram* |
3422 &render_pass_color_matrix_program_aa_[precision][blend_mode]; | 3293 GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision, |
3423 if (!program->initialized()) { | 3294 SamplerType sampler, |
3424 TRACE_EVENT0("cc", | 3295 BlendMode blend_mode, |
3425 "GLRenderer::renderPassColorMatrixProgramAA::initialize"); | 3296 bool mask_for_background) { |
3426 program->InitializeRenderPassProgram(output_surface_->context_provider(), | 3297 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
3427 precision, SAMPLER_TYPE_2D, blend_mode, | 3298 NO_AA, HAS_MASK, mask_for_background, |
3428 USE_AA, NO_MASK, false, true); | 3299 true)); |
3300 } | |
3301 | |
3302 const GLRenderer::RenderPassMaskColorMatrixProgramAA* | |
3303 GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision, | |
3304 SamplerType sampler, | |
3305 BlendMode blend_mode, | |
3306 bool mask_for_background) { | |
3307 return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, | |
3308 USE_AA, HAS_MASK, | |
3309 mask_for_background, true)); | |
3310 } | |
3311 | |
3312 const GLRenderer::Program* GLRenderer::GetProgram(const ProgramKey& desc) { | |
3313 Program*& program = program_cache_[desc]; | |
3314 if (!program) { | |
3315 program = new Program; | |
3316 program->Initialize(output_surface_->context_provider(), desc); | |
3429 } | 3317 } |
3430 return program; | 3318 return program; |
3431 } | 3319 } |
3432 | 3320 |
3433 const GLRenderer::RenderPassMaskColorMatrixProgram* | 3321 const GLRenderer::Program* GLRenderer::GetProgramForTesting( |
3434 GLRenderer::GetRenderPassMaskColorMatrixProgram( | 3322 const ProgramKey& desc) const { |
3435 TexCoordPrecision precision, | 3323 const auto found = program_cache_.find(desc); |
3436 SamplerType sampler, | 3324 if (found == program_cache_.end()) |
3437 BlendMode blend_mode, | 3325 return nullptr; |
3438 bool mask_for_background) { | 3326 return found->second; |
3439 DCHECK_GE(precision, 0); | |
3440 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | |
3441 DCHECK_GE(sampler, 0); | |
3442 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3443 DCHECK_GE(blend_mode, 0); | |
3444 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3445 RenderPassMaskColorMatrixProgram* program = | |
3446 &render_pass_mask_color_matrix_program_[precision][sampler][blend_mode] | |
3447 [mask_for_background ? HAS_MASK : NO_MASK]; | |
3448 if (!program->initialized()) { | |
3449 TRACE_EVENT0("cc", | |
3450 "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); | |
3451 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3452 precision, sampler, blend_mode, NO_AA, | |
3453 HAS_MASK, mask_for_background, true); | |
3454 } | |
3455 return program; | |
3456 } | |
3457 | |
3458 const GLRenderer::RenderPassMaskColorMatrixProgramAA* | |
3459 GLRenderer::GetRenderPassMaskColorMatrixProgramAA( | |
3460 TexCoordPrecision precision, | |
3461 SamplerType sampler, | |
3462 BlendMode blend_mode, | |
3463 bool mask_for_background) { | |
3464 DCHECK_GE(precision, 0); | |
3465 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | |
3466 DCHECK_GE(sampler, 0); | |
3467 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3468 DCHECK_GE(blend_mode, 0); | |
3469 DCHECK_LE(blend_mode, LAST_BLEND_MODE); | |
3470 RenderPassMaskColorMatrixProgramAA* program = | |
3471 &render_pass_mask_color_matrix_program_aa_[precision][sampler][blend_mode] | |
3472 [mask_for_background ? HAS_MASK : NO_MASK]; | |
3473 if (!program->initialized()) { | |
3474 TRACE_EVENT0("cc", | |
3475 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); | |
3476 program->InitializeRenderPassProgram(output_surface_->context_provider(), | |
3477 precision, sampler, blend_mode, USE_AA, | |
3478 HAS_MASK, mask_for_background, true); | |
3479 } | |
3480 return program; | |
3481 } | 3327 } |
3482 | 3328 |
3483 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( | 3329 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( |
3484 TexCoordPrecision precision, | 3330 TexCoordPrecision precision, |
3485 SamplerType sampler) { | 3331 SamplerType sampler) { |
3486 DCHECK_GE(precision, 0); | 3332 return GetProgram( |
3487 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3333 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, NOT_OPAQUE)); |
3488 DCHECK_GE(sampler, 0); | |
3489 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3490 TileProgram* program = &tile_program_[precision][sampler]; | |
3491 if (!program->initialized()) { | |
3492 TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); | |
3493 program->InitializeTileProgram(output_surface_->context_provider(), | |
3494 precision, sampler, NO_AA, NO_SWIZZLE, | |
3495 NOT_OPAQUE); | |
3496 } | |
3497 return program; | |
3498 } | 3334 } |
3499 | 3335 |
3500 const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( | 3336 const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( |
3501 TexCoordPrecision precision, | 3337 TexCoordPrecision precision, |
3502 SamplerType sampler) { | 3338 SamplerType sampler) { |
3503 DCHECK_GE(precision, 0); | 3339 return GetProgram( |
3504 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3340 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, IS_OPAQUE)); |
3505 DCHECK_GE(sampler, 0); | |
3506 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3507 TileProgramOpaque* program = &tile_program_opaque_[precision][sampler]; | |
3508 if (!program->initialized()) { | |
3509 TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); | |
3510 program->InitializeTileProgram(output_surface_->context_provider(), | |
3511 precision, sampler, NO_AA, NO_SWIZZLE, | |
3512 IS_OPAQUE); | |
3513 } | |
3514 return program; | |
3515 } | 3341 } |
3516 | 3342 |
3517 const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( | 3343 const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( |
3518 TexCoordPrecision precision, | 3344 TexCoordPrecision precision, |
3519 SamplerType sampler) { | 3345 SamplerType sampler) { |
3520 DCHECK_GE(precision, 0); | 3346 return GetProgram( |
3521 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3347 ProgramKey::Tile(precision, sampler, USE_AA, NO_SWIZZLE, NOT_OPAQUE)); |
3522 DCHECK_GE(sampler, 0); | |
3523 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3524 TileProgramAA* program = &tile_program_aa_[precision][sampler]; | |
3525 if (!program->initialized()) { | |
3526 TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); | |
3527 program->InitializeTileProgram(output_surface_->context_provider(), | |
3528 precision, sampler, USE_AA, NO_SWIZZLE, | |
3529 NOT_OPAQUE); | |
3530 } | |
3531 return program; | |
3532 } | 3348 } |
3533 | 3349 |
3534 const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( | 3350 const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( |
3535 TexCoordPrecision precision, | 3351 TexCoordPrecision precision, |
3536 SamplerType sampler) { | 3352 SamplerType sampler) { |
3537 DCHECK_GE(precision, 0); | 3353 return GetProgram( |
3538 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3354 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, NOT_OPAQUE)); |
3539 DCHECK_GE(sampler, 0); | |
3540 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3541 TileProgramSwizzle* program = &tile_program_swizzle_[precision][sampler]; | |
3542 if (!program->initialized()) { | |
3543 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); | |
3544 program->InitializeTileProgram(output_surface_->context_provider(), | |
3545 precision, sampler, NO_AA, DO_SWIZZLE, | |
3546 NOT_OPAQUE); | |
3547 } | |
3548 return program; | |
3549 } | 3355 } |
3550 | 3356 |
3551 const GLRenderer::TileProgramSwizzleOpaque* | 3357 const GLRenderer::TileProgramSwizzleOpaque* |
3552 GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision, | 3358 GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision, |
3553 SamplerType sampler) { | 3359 SamplerType sampler) { |
3554 DCHECK_GE(precision, 0); | 3360 return GetProgram( |
3555 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3361 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, IS_OPAQUE)); |
3556 DCHECK_GE(sampler, 0); | |
3557 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3558 TileProgramSwizzleOpaque* program = | |
3559 &tile_program_swizzle_opaque_[precision][sampler]; | |
3560 if (!program->initialized()) { | |
3561 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); | |
3562 program->InitializeTileProgram(output_surface_->context_provider(), | |
3563 precision, sampler, NO_AA, DO_SWIZZLE, | |
3564 IS_OPAQUE); | |
3565 } | |
3566 return program; | |
3567 } | 3362 } |
3568 | 3363 |
3569 const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( | 3364 const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( |
3570 TexCoordPrecision precision, | 3365 TexCoordPrecision precision, |
3571 SamplerType sampler) { | 3366 SamplerType sampler) { |
3572 DCHECK_GE(precision, 0); | 3367 return GetProgram( |
3573 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3368 ProgramKey::Tile(precision, sampler, USE_AA, DO_SWIZZLE, NOT_OPAQUE)); |
3574 DCHECK_GE(sampler, 0); | |
3575 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3576 TileProgramSwizzleAA* program = &tile_program_swizzle_aa_[precision][sampler]; | |
3577 if (!program->initialized()) { | |
3578 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); | |
3579 program->InitializeTileProgram(output_surface_->context_provider(), | |
3580 precision, sampler, USE_AA, DO_SWIZZLE, | |
3581 NOT_OPAQUE); | |
3582 } | |
3583 return program; | |
3584 } | 3369 } |
3585 | 3370 |
3586 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( | 3371 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( |
3587 TexCoordPrecision precision, | 3372 TexCoordPrecision precision, |
3588 SamplerType sampler) { | 3373 SamplerType sampler) { |
3589 DCHECK_GE(precision, 0); | 3374 return GetProgram( |
3590 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3375 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, false)); |
3591 DCHECK_GE(sampler, 0); | |
3592 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3593 TextureProgram* program = &texture_program_[precision][sampler]; | |
3594 if (!program->initialized()) { | |
3595 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | |
3596 program->InitializeTextureProgram(output_surface_->context_provider(), | |
3597 precision, sampler, PREMULTIPLIED_ALPHA, | |
3598 false); | |
3599 } | |
3600 return program; | |
3601 } | 3376 } |
3602 | 3377 |
3603 const GLRenderer::NonPremultipliedTextureProgram* | 3378 const GLRenderer::NonPremultipliedTextureProgram* |
3604 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision, | 3379 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision, |
3605 SamplerType sampler) { | 3380 SamplerType sampler) { |
3606 DCHECK_GE(precision, 0); | 3381 return GetProgram( |
3607 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3382 ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, false)); |
3608 DCHECK_GE(sampler, 0); | |
3609 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3610 NonPremultipliedTextureProgram* program = | |
3611 &nonpremultiplied_texture_program_[precision][sampler]; | |
3612 if (!program->initialized()) { | |
3613 TRACE_EVENT0("cc", | |
3614 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | |
3615 program->InitializeTextureProgram(output_surface_->context_provider(), | |
3616 precision, sampler, | |
3617 NON_PREMULTIPLIED_ALPHA, false); | |
3618 } | |
3619 return program; | |
3620 } | 3383 } |
3621 | 3384 |
3622 const GLRenderer::TextureBackgroundProgram* | 3385 const GLRenderer::TextureBackgroundProgram* |
3623 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision, | 3386 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision, |
3624 SamplerType sampler) { | 3387 SamplerType sampler) { |
3625 DCHECK_GE(precision, 0); | 3388 return GetProgram( |
3626 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3389 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, true)); |
3627 DCHECK_GE(sampler, 0); | |
3628 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3629 TextureBackgroundProgram* program = | |
3630 &texture_background_program_[precision][sampler]; | |
3631 if (!program->initialized()) { | |
3632 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | |
3633 program->InitializeTextureProgram(output_surface_->context_provider(), | |
3634 precision, sampler, PREMULTIPLIED_ALPHA, | |
3635 true); | |
3636 } | |
3637 return program; | |
3638 } | 3390 } |
3639 | 3391 |
3640 const GLRenderer::NonPremultipliedTextureBackgroundProgram* | 3392 const GLRenderer::NonPremultipliedTextureBackgroundProgram* |
3641 GLRenderer::GetNonPremultipliedTextureBackgroundProgram( | 3393 GLRenderer::GetNonPremultipliedTextureBackgroundProgram( |
3642 TexCoordPrecision precision, | 3394 TexCoordPrecision precision, |
3643 SamplerType sampler) { | 3395 SamplerType sampler) { |
3644 DCHECK_GE(precision, 0); | 3396 return GetProgram( |
3645 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3397 ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, true)); |
3646 DCHECK_GE(sampler, 0); | |
3647 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
3648 NonPremultipliedTextureBackgroundProgram* program = | |
3649 &nonpremultiplied_texture_background_program_[precision][sampler]; | |
3650 if (!program->initialized()) { | |
3651 TRACE_EVENT0("cc", | |
3652 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | |
3653 program->InitializeTextureProgram(output_surface_->context_provider(), | |
3654 precision, sampler, | |
3655 NON_PREMULTIPLIED_ALPHA, true); | |
3656 } | |
3657 return program; | |
3658 } | 3398 } |
3659 | 3399 |
3660 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( | 3400 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( |
3661 TexCoordPrecision precision, | 3401 TexCoordPrecision precision, |
3662 SamplerType sampler, | 3402 SamplerType sampler, |
3663 bool use_alpha_plane, | 3403 bool use_alpha_plane, |
3664 bool use_nv12, | 3404 bool use_nv12, |
3665 bool use_color_lut) { | 3405 bool use_color_lut) { |
3666 DCHECK_GE(precision, 0); | 3406 DCHECK_GE(precision, 0); |
3667 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3407 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3668 DCHECK_GE(sampler, 0); | 3408 DCHECK_GE(sampler, 0); |
3669 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | 3409 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
3670 VideoYUVProgram* program = | 3410 VideoYUVProgram* program = |
3671 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12] | 3411 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12] |
3672 [use_color_lut]; | 3412 [use_color_lut]; |
3673 if (!program->initialized()) { | 3413 if (!program->initialized()) { |
3674 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3414 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
3675 program->InitializeVideoYUVProgram(output_surface_->context_provider(), | 3415 program->InitializeVideoYUVProgram(output_surface_->context_provider(), |
3676 precision, sampler, use_alpha_plane, | 3416 precision, sampler, use_alpha_plane, |
3677 use_nv12, use_color_lut); | 3417 use_nv12, use_color_lut); |
3678 } | 3418 } |
3679 return program; | 3419 return program; |
3680 } | 3420 } |
3681 | 3421 |
3682 const GLRenderer::VideoStreamTextureProgram* | 3422 const GLRenderer::VideoStreamTextureProgram* |
3683 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { | 3423 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
3684 DCHECK_GE(precision, 0); | 3424 return GetProgram(ProgramKey::VideoStream(precision)); |
3685 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | |
3686 VideoStreamTextureProgram* program = | |
3687 &video_stream_texture_program_[precision]; | |
3688 if (!program->initialized()) { | |
3689 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | |
3690 program->InitializeVideoStreamProgram(output_surface_->context_provider(), | |
3691 precision); | |
3692 } | |
3693 return program; | |
3694 } | 3425 } |
3695 | 3426 |
3696 void GLRenderer::CleanupSharedObjects() { | 3427 void GLRenderer::CleanupSharedObjects() { |
3697 shared_geometry_ = nullptr; | 3428 shared_geometry_ = nullptr; |
3698 | 3429 |
3699 for (int i = 0; i <= LAST_TEX_COORD_PRECISION; ++i) { | 3430 for (int i = 0; i <= LAST_TEX_COORD_PRECISION; ++i) { |
3700 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3431 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
3701 tile_program_[i][j].Cleanup(gl_); | |
3702 tile_program_opaque_[i][j].Cleanup(gl_); | |
3703 tile_program_swizzle_[i][j].Cleanup(gl_); | |
3704 tile_program_swizzle_opaque_[i][j].Cleanup(gl_); | |
3705 tile_program_aa_[i][j].Cleanup(gl_); | |
3706 tile_program_swizzle_aa_[i][j].Cleanup(gl_); | |
3707 | |
3708 for (int k = 0; k <= LAST_BLEND_MODE; k++) { | |
3709 for (int l = 0; l <= LAST_MASK_VALUE; ++l) { | |
3710 render_pass_mask_program_[i][j][k][l].Cleanup(gl_); | |
3711 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_); | |
3712 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_); | |
3713 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); | |
3714 } | |
3715 } | |
3716 | |
3717 for (int k = 0; k < 2; k++) { | 3432 for (int k = 0; k < 2; k++) { |
3718 for (int l = 0; l < 2; l++) { | 3433 for (int l = 0; l < 2; l++) { |
3719 for (int m = 0; m < 2; m++) { | 3434 for (int m = 0; m < 2; m++) { |
3720 video_yuv_program_[i][j][k][l][m].Cleanup(gl_); | 3435 video_yuv_program_[i][j][k][l][m].Cleanup(gl_); |
3721 } | 3436 } |
3722 } | 3437 } |
3723 } | 3438 } |
3724 } | 3439 } |
3725 for (int j = 0; j <= LAST_BLEND_MODE; j++) { | |
3726 render_pass_program_[i][j].Cleanup(gl_); | |
3727 render_pass_program_aa_[i][j].Cleanup(gl_); | |
3728 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | |
3729 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | |
3730 } | |
3731 | |
3732 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | |
3733 texture_program_[i][j].Cleanup(gl_); | |
3734 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); | |
3735 texture_background_program_[i][j].Cleanup(gl_); | |
3736 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); | |
3737 } | |
3738 | |
3739 video_stream_texture_program_[i].Cleanup(gl_); | |
3740 } | 3440 } |
3741 | 3441 for (auto iter : program_cache_) { |
3742 debug_border_program_.Cleanup(gl_); | 3442 Program* program = iter.second; |
3743 solid_color_program_.Cleanup(gl_); | 3443 program->Cleanup(gl_); |
3744 solid_color_program_aa_.Cleanup(gl_); | 3444 delete program; |
3445 } | |
3446 program_cache_.clear(); | |
3745 | 3447 |
3746 if (offscreen_framebuffer_id_) | 3448 if (offscreen_framebuffer_id_) |
3747 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); | 3449 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); |
3748 | 3450 |
3749 ReleaseRenderPassTextures(); | 3451 ReleaseRenderPassTextures(); |
3750 } | 3452 } |
3751 | 3453 |
3752 void GLRenderer::ReinitializeGLState() { | 3454 void GLRenderer::ReinitializeGLState() { |
3753 is_scissor_enabled_ = false; | 3455 is_scissor_enabled_ = false; |
3754 scissor_rect_ = gfx::Rect(); | 3456 scissor_rect_ = gfx::Rect(); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4072 // The alpha has already been applied when copying the RPDQ to an IOSurface. | 3774 // The alpha has already been applied when copying the RPDQ to an IOSurface. |
4073 GLfloat alpha = 1; | 3775 GLfloat alpha = 1; |
4074 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, | 3776 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, |
4075 sorting_context_id, gl_transform); | 3777 sorting_context_id, gl_transform); |
4076 gl_->ScheduleCALayerCHROMIUM( | 3778 gl_->ScheduleCALayerCHROMIUM( |
4077 texture_id, contents_rect, ca_layer_overlay->background_color, | 3779 texture_id, contents_rect, ca_layer_overlay->background_color, |
4078 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 3780 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
4079 } | 3781 } |
4080 | 3782 |
4081 } // namespace cc | 3783 } // namespace cc |
OLD | NEW |