Chromium Code Reviews| Index: cc/output/gl_renderer.cc |
| diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc |
| index e79f3b26e4dfdc7fde3d510c97c2f2d01afd7bf4..10f88d7e2b2e320ac01afb008787183cb778215b 100644 |
| --- a/cc/output/gl_renderer.cc |
| +++ b/cc/output/gl_renderer.cc |
| @@ -1317,79 +1317,23 @@ void GLRenderer::ChooseRPDQProgram(DrawRenderPassDrawQuadParams* params) { |
| ? BlendModeFromSkXfermode(params->quad->shared_quad_state->blend_mode) |
| : BLEND_MODE_NONE; |
| - unsigned mask_texture_id = 0; |
| - SamplerType mask_sampler = SAMPLER_TYPE_NA; |
| + SamplerType sampler_type = SAMPLER_TYPE_2D; |
| + MaskMode mask_mode = NO_MASK; |
| + bool mask_for_background = params->mask_for_background; |
| if (params->mask_resource_lock) { |
| - mask_texture_id = params->mask_resource_lock->texture_id(); |
| - mask_sampler = |
| + mask_mode = HAS_MASK; |
| + sampler_type = |
| SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); |
| } |
| - bool mask_for_background = params->mask_for_background; |
| - if (params->use_aa && mask_texture_id && !params->use_color_matrix) { |
| - const RenderPassMaskProgramAA* program = GetRenderPassMaskProgramAA( |
| - tex_coord_precision, mask_sampler, |
| - shader_blend_mode, mask_for_background); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (!params->use_aa && mask_texture_id && !params->use_color_matrix) { |
| - const RenderPassMaskProgram* program = GetRenderPassMaskProgram( |
| - tex_coord_precision, mask_sampler, |
| - shader_blend_mode, mask_for_background); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (params->use_aa && !mask_texture_id && !params->use_color_matrix) { |
| - const RenderPassProgramAA* program = |
| - GetRenderPassProgramAA(tex_coord_precision, shader_blend_mode); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (params->use_aa && mask_texture_id && params->use_color_matrix) { |
| - const RenderPassMaskColorMatrixProgramAA* program = |
| - GetRenderPassMaskColorMatrixProgramAA( |
| - tex_coord_precision, mask_sampler, |
| - shader_blend_mode, mask_for_background); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (params->use_aa && !mask_texture_id && params->use_color_matrix) { |
| - const RenderPassColorMatrixProgramAA* program = |
| - GetRenderPassColorMatrixProgramAA(tex_coord_precision, |
| - shader_blend_mode); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (!params->use_aa && mask_texture_id && params->use_color_matrix) { |
| - const RenderPassMaskColorMatrixProgram* program = |
| - GetRenderPassMaskColorMatrixProgram( |
| - tex_coord_precision, mask_sampler, |
| - shader_blend_mode, mask_for_background); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else if (!params->use_aa && !mask_texture_id && params->use_color_matrix) { |
| - const RenderPassColorMatrixProgram* program = |
| - GetRenderPassColorMatrixProgram(tex_coord_precision, shader_blend_mode); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } else { |
| - const RenderPassProgram* program = |
| - GetRenderPassProgram(tex_coord_precision, shader_blend_mode); |
| - SetUseProgram(program->program()); |
| - program->vertex_shader().FillLocations(¶ms->locations); |
| - program->fragment_shader().FillLocations(¶ms->locations); |
| - gl_->Uniform1i(params->locations.sampler, 0); |
| - } |
| + const Program* program = GetProgram(ProgramKey::RenderPass( |
|
enne (OOO)
2017/01/09 19:46:48
This cleanup is great.
|
| + tex_coord_precision, sampler_type, shader_blend_mode, |
| + params->use_aa ? USE_AA : NO_AA, mask_mode, mask_for_background, |
| + params->use_color_matrix)); |
| + SetUseProgram(program->program()); |
| + program->vertex_shader().FillLocations(¶ms->locations); |
| + program->fragment_shader().FillLocations(¶ms->locations); |
| + gl_->Uniform1i(params->locations.sampler, 0); |
| } |
| void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { |
| @@ -3286,65 +3230,29 @@ void GLRenderer::PrepareGeometry(BoundGeometry binding) { |
| } |
| const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { |
| - if (!debug_border_program_.initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::debugBorderProgram::initialize"); |
| - debug_border_program_.InitializeDebugBorderProgram( |
| - output_surface_->context_provider()); |
| - } |
| - return &debug_border_program_; |
| + return GetProgram(ProgramKey::DebugBorder()); |
| } |
| const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { |
| - if (!solid_color_program_.initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
| - solid_color_program_.InitializeSolidColorProgram( |
| - output_surface_->context_provider(), false); |
| - } |
| - return &solid_color_program_; |
| + return GetProgram(ProgramKey::SolidColor(NO_AA)); |
| } |
| const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { |
| - if (!solid_color_program_aa_.initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); |
| - solid_color_program_aa_.InitializeSolidColorProgram( |
| - output_surface_->context_provider(), true); |
| - } |
| - return &solid_color_program_aa_; |
| + return GetProgram(ProgramKey::SolidColor(USE_AA)); |
| } |
| const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( |
| TexCoordPrecision precision, |
| BlendMode blend_mode) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassProgram* program = &render_pass_program_[precision][blend_mode]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, SAMPLER_TYPE_2D, blend_mode, |
| - NO_AA, NO_MASK, false, false); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass( |
| + precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, false)); |
| } |
| const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( |
| TexCoordPrecision precision, |
| BlendMode blend_mode) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassProgramAA* program = |
| - &render_pass_program_aa_[precision][blend_mode]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, SAMPLER_TYPE_2D, blend_mode, |
| - USE_AA, NO_MASK, false, false); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass( |
| + precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, false)); |
| } |
| const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( |
| @@ -3352,22 +3260,9 @@ const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( |
| SamplerType sampler, |
| BlendMode blend_mode, |
| bool mask_for_background) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassMaskProgram* program = |
| - &render_pass_mask_program_[precision][sampler][blend_mode] |
| - [mask_for_background ? HAS_MASK : NO_MASK]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, sampler, blend_mode, NO_AA, |
| - HAS_MASK, mask_for_background, false); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
| + NO_AA, HAS_MASK, mask_for_background, |
| + false)); |
| } |
| const GLRenderer::RenderPassMaskProgramAA* |
| @@ -3375,286 +3270,131 @@ GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision, |
| SamplerType sampler, |
| BlendMode blend_mode, |
| bool mask_for_background) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassMaskProgramAA* program = |
| - &render_pass_mask_program_aa_[precision][sampler][blend_mode] |
| - [mask_for_background ? HAS_MASK : NO_MASK]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, sampler, blend_mode, USE_AA, |
| - HAS_MASK, mask_for_background, false); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
| + USE_AA, HAS_MASK, |
| + mask_for_background, false)); |
| } |
| const GLRenderer::RenderPassColorMatrixProgram* |
| GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision, |
| BlendMode blend_mode) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassColorMatrixProgram* program = |
| - &render_pass_color_matrix_program_[precision][blend_mode]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgram::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, SAMPLER_TYPE_2D, blend_mode, |
| - NO_AA, NO_MASK, false, true); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass( |
| + precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, true)); |
| } |
| const GLRenderer::RenderPassColorMatrixProgramAA* |
| GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision, |
| BlendMode blend_mode) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassColorMatrixProgramAA* program = |
| - &render_pass_color_matrix_program_aa_[precision][blend_mode]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", |
| - "GLRenderer::renderPassColorMatrixProgramAA::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, SAMPLER_TYPE_2D, blend_mode, |
| - USE_AA, NO_MASK, false, true); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::RenderPass( |
| + precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, NO_MASK, false, true)); |
| } |
| const GLRenderer::RenderPassMaskColorMatrixProgram* |
| -GLRenderer::GetRenderPassMaskColorMatrixProgram( |
| - TexCoordPrecision precision, |
| - SamplerType sampler, |
| - BlendMode blend_mode, |
| - bool mask_for_background) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassMaskColorMatrixProgram* program = |
| - &render_pass_mask_color_matrix_program_[precision][sampler][blend_mode] |
| - [mask_for_background ? HAS_MASK : NO_MASK]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", |
| - "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, sampler, blend_mode, NO_AA, |
| - HAS_MASK, mask_for_background, true); |
| - } |
| - return program; |
| +GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision, |
| + SamplerType sampler, |
| + BlendMode blend_mode, |
| + bool mask_for_background) { |
| + return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
| + NO_AA, HAS_MASK, mask_for_background, |
| + true)); |
| } |
| const GLRenderer::RenderPassMaskColorMatrixProgramAA* |
| -GLRenderer::GetRenderPassMaskColorMatrixProgramAA( |
| - TexCoordPrecision precision, |
| - SamplerType sampler, |
| - BlendMode blend_mode, |
| - bool mask_for_background) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - DCHECK_GE(blend_mode, 0); |
| - DCHECK_LE(blend_mode, LAST_BLEND_MODE); |
| - RenderPassMaskColorMatrixProgramAA* program = |
| - &render_pass_mask_color_matrix_program_aa_[precision][sampler][blend_mode] |
| - [mask_for_background ? HAS_MASK : NO_MASK]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", |
| - "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); |
| - program->InitializeRenderPassProgram(output_surface_->context_provider(), |
| - precision, sampler, blend_mode, USE_AA, |
| - HAS_MASK, mask_for_background, true); |
| +GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision, |
| + SamplerType sampler, |
| + BlendMode blend_mode, |
| + bool mask_for_background) { |
| + return GetProgram(ProgramKey::RenderPass(precision, sampler, blend_mode, |
| + USE_AA, HAS_MASK, |
| + mask_for_background, true)); |
| +} |
| + |
| +const GLRenderer::Program* GLRenderer::GetProgram(const ProgramKey& desc) { |
| + Program*& program = program_cache_[desc]; |
| + if (!program) { |
| + program = new Program; |
| + program->Initialize(output_surface_->context_provider(), desc); |
| } |
| return program; |
| } |
| +const GLRenderer::Program* GLRenderer::GetProgramForTesting( |
| + const ProgramKey& desc) const { |
| + const auto found = program_cache_.find(desc); |
| + if (found == program_cache_.end()) |
| + return nullptr; |
| + return found->second; |
| +} |
| + |
| const GLRenderer::TileProgram* GLRenderer::GetTileProgram( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgram* program = &tile_program_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, NO_AA, NO_SWIZZLE, |
| - NOT_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, NOT_OPAQUE)); |
| } |
| const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgramOpaque* program = &tile_program_opaque_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, NO_AA, NO_SWIZZLE, |
| - IS_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, IS_OPAQUE)); |
| } |
| const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgramAA* program = &tile_program_aa_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, USE_AA, NO_SWIZZLE, |
| - NOT_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, USE_AA, NO_SWIZZLE, NOT_OPAQUE)); |
| } |
| const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgramSwizzle* program = &tile_program_swizzle_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, NO_AA, DO_SWIZZLE, |
| - NOT_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, NOT_OPAQUE)); |
| } |
| const GLRenderer::TileProgramSwizzleOpaque* |
| GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgramSwizzleOpaque* program = |
| - &tile_program_swizzle_opaque_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, NO_AA, DO_SWIZZLE, |
| - IS_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, IS_OPAQUE)); |
| } |
| const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TileProgramSwizzleAA* program = &tile_program_swizzle_aa_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); |
| - program->InitializeTileProgram(output_surface_->context_provider(), |
| - precision, sampler, USE_AA, DO_SWIZZLE, |
| - NOT_OPAQUE); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Tile(precision, sampler, USE_AA, DO_SWIZZLE, NOT_OPAQUE)); |
| } |
| const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TextureProgram* program = &texture_program_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
| - program->InitializeTextureProgram(output_surface_->context_provider(), |
| - precision, sampler, PREMULTIPLIED_ALPHA, |
| - false); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, false)); |
| } |
| const GLRenderer::NonPremultipliedTextureProgram* |
| GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - NonPremultipliedTextureProgram* program = |
| - &nonpremultiplied_texture_program_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", |
| - "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| - program->InitializeTextureProgram(output_surface_->context_provider(), |
| - precision, sampler, |
| - NON_PREMULTIPLIED_ALPHA, false); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, false)); |
| } |
| const GLRenderer::TextureBackgroundProgram* |
| GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - TextureBackgroundProgram* program = |
| - &texture_background_program_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
| - program->InitializeTextureProgram(output_surface_->context_provider(), |
| - precision, sampler, PREMULTIPLIED_ALPHA, |
| - true); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, true)); |
| } |
| const GLRenderer::NonPremultipliedTextureBackgroundProgram* |
| GLRenderer::GetNonPremultipliedTextureBackgroundProgram( |
| TexCoordPrecision precision, |
| SamplerType sampler) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - DCHECK_GE(sampler, 0); |
| - DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| - NonPremultipliedTextureBackgroundProgram* program = |
| - &nonpremultiplied_texture_background_program_[precision][sampler]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", |
| - "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| - program->InitializeTextureProgram(output_surface_->context_provider(), |
| - precision, sampler, |
| - NON_PREMULTIPLIED_ALPHA, true); |
| - } |
| - return program; |
| + return GetProgram( |
| + ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, true)); |
| } |
| const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( |
| @@ -3681,16 +3421,7 @@ const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( |
| const GLRenderer::VideoStreamTextureProgram* |
| GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
| - DCHECK_GE(precision, 0); |
| - DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| - VideoStreamTextureProgram* program = |
| - &video_stream_texture_program_[precision]; |
| - if (!program->initialized()) { |
| - TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
| - program->InitializeVideoStreamProgram(output_surface_->context_provider(), |
| - precision); |
| - } |
| - return program; |
| + return GetProgram(ProgramKey::VideoStream(precision)); |
| } |
| void GLRenderer::CleanupSharedObjects() { |
| @@ -3698,22 +3429,6 @@ void GLRenderer::CleanupSharedObjects() { |
| for (int i = 0; i <= LAST_TEX_COORD_PRECISION; ++i) { |
| for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
| - tile_program_[i][j].Cleanup(gl_); |
| - tile_program_opaque_[i][j].Cleanup(gl_); |
| - tile_program_swizzle_[i][j].Cleanup(gl_); |
| - tile_program_swizzle_opaque_[i][j].Cleanup(gl_); |
| - tile_program_aa_[i][j].Cleanup(gl_); |
| - tile_program_swizzle_aa_[i][j].Cleanup(gl_); |
| - |
| - for (int k = 0; k <= LAST_BLEND_MODE; k++) { |
| - for (int l = 0; l <= LAST_MASK_VALUE; ++l) { |
| - render_pass_mask_program_[i][j][k][l].Cleanup(gl_); |
| - render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_); |
| - render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_); |
| - render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); |
| - } |
| - } |
| - |
| for (int k = 0; k < 2; k++) { |
| for (int l = 0; l < 2; l++) { |
| for (int m = 0; m < 2; m++) { |
| @@ -3722,26 +3437,13 @@ void GLRenderer::CleanupSharedObjects() { |
| } |
| } |
| } |
| - for (int j = 0; j <= LAST_BLEND_MODE; j++) { |
| - render_pass_program_[i][j].Cleanup(gl_); |
| - render_pass_program_aa_[i][j].Cleanup(gl_); |
| - render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
| - render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
| - } |
| - |
| - for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
| - texture_program_[i][j].Cleanup(gl_); |
| - nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
| - texture_background_program_[i][j].Cleanup(gl_); |
| - nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
| - } |
| - |
| - video_stream_texture_program_[i].Cleanup(gl_); |
| } |
| - |
| - debug_border_program_.Cleanup(gl_); |
| - solid_color_program_.Cleanup(gl_); |
| - solid_color_program_aa_.Cleanup(gl_); |
| + for (auto iter : program_cache_) { |
| + Program* program = iter.second; |
| + program->Cleanup(gl_); |
| + delete program; |
| + } |
| + program_cache_.clear(); |
| if (offscreen_framebuffer_id_) |
| gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); |