diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-23 21:19:12 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-23 21:19:12 +0000 |
commit | 8d7aa0159fc1c19e0a82a3366e5354de356a2831 (patch) | |
tree | d62be4cd48c8aa7a17fb4a80ae43c8f1fa836f7a /cc | |
parent | 7c762647e3744c83f1d08f58e199a0b0d29709dc (diff) | |
download | chromium_src-8d7aa0159fc1c19e0a82a3366e5354de356a2831.zip chromium_src-8d7aa0159fc1c19e0a82a3366e5354de356a2831.tar.gz chromium_src-8d7aa0159fc1c19e0a82a3366e5354de356a2831.tar.bz2 |
cc: Allow TEXTURE_RECTANGLE_ARB to be used for tile textures.
Refactor shader framework to support different texture targets and
use TEXTURE_RECTANGLE_ARB by default when initializing tile textures
using ImageRasterWorkerPool.
BUG=322571
TEST=cc_unittests --gtest_filter=GLRendererShaderPixelTest.AllShadersCompile
Review URL: https://codereview.chromium.org/83883002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236981 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
23 files changed, 664 insertions, 515 deletions
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc index 10014f8..c0cf138 100644 --- a/cc/output/gl_renderer.cc +++ b/cc/output/gl_renderer.cc @@ -111,6 +111,20 @@ Float4 PremultipliedColor(SkColor color) { return result; } +SamplerType SamplerTypeFromTextureTarget(GLenum target) { + switch (target) { + case GL_TEXTURE_2D: + return SamplerType2D; + case GL_TEXTURE_RECTANGLE_ARB: + return SamplerType2DRect; + case GL_TEXTURE_EXTERNAL_OES: + return SamplerTypeExternalOES; + default: + NOTREACHED(); + return SamplerType2D; + } +} + // Smallest unit that impact anti-aliasing output. We use this to // determine when anti-aliasing is unnecessary. const float kAntiAliasingEpsilon = 1.0f / 1024.0f; @@ -813,7 +827,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, // TODO(danakj): use the background_texture and blend the background in with // this draw instead of having a separate copy of the background texture. - scoped_ptr<ResourceProvider::ScopedReadLockGL> contents_resource_lock; + scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; if (filter_bitmap.getTexture()) { GrTexture* texture = reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); @@ -823,8 +837,9 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, contents_resource_lock = make_scoped_ptr( new ResourceProvider::ScopedSamplerGL(resource_provider_, contents_texture->id(), - GL_TEXTURE_2D, GL_LINEAR)); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + contents_resource_lock->target()); } TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( @@ -1001,7 +1016,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, tex_scale_x, -tex_scale_y)); - scoped_ptr<ResourceProvider::ScopedReadLockGL> shader_mask_sampler_lock; + scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_mask_sampler_lock; if (shader_mask_sampler_location != -1) { DCHECK_NE(shader_mask_tex_coord_scale_location, 1); DCHECK_NE(shader_mask_tex_coord_offset_location, 1); @@ -1025,9 +1040,10 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, shader_mask_sampler_lock = make_scoped_ptr( new ResourceProvider::ScopedSamplerGL(resource_provider_, quad->mask_resource_id, - GL_TEXTURE_2D, GL_TEXTURE1, GL_LINEAR)); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), + shader_mask_sampler_lock->target()); } if (shader_edge_location != -1) { @@ -1336,13 +1352,6 @@ void GLRenderer::DrawContentQuad(const DrawingFrame* frame, context_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); - // Map to normalized texture coordinates. - gfx::Size texture_size = quad->texture_size; - float fragment_tex_translate_x = clamp_tex_rect.x() / texture_size.width(); - float fragment_tex_translate_y = clamp_tex_rect.y() / texture_size.height(); - float fragment_tex_scale_x = clamp_tex_rect.width() / texture_size.width(); - float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); - gfx::Transform device_transform = frame->window_matrix * frame->projection_matrix * quad->quadTransform(); device_transform.FlattenTo2d(); @@ -1354,28 +1363,58 @@ void GLRenderer::DrawContentQuad(const DrawingFrame* frame, bool use_aa = settings_->allow_antialiasing && SetupQuadForAntialiasing( device_transform, quad, &local_quad, edge); + bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); + GLenum filter = (use_aa || scaled || + !quad->quadTransform().IsIdentityOrIntegerTranslation()) + ? GL_LINEAR + : GL_NEAREST; + ResourceProvider::ScopedSamplerGL quad_resource_lock( + resource_provider_, resource_id, filter); + SamplerType sampler = SamplerTypeFromTextureTarget( + quad_resource_lock.target()); + + float fragment_tex_translate_x = clamp_tex_rect.x(); + float fragment_tex_translate_y = clamp_tex_rect.y(); + float fragment_tex_scale_x = clamp_tex_rect.width(); + float fragment_tex_scale_y = clamp_tex_rect.height(); + + // Map to normalized texture coordinates. + if (sampler != SamplerType2DRect) { + gfx::Size texture_size = quad->texture_size; + DCHECK(!texture_size.IsEmpty()); + fragment_tex_translate_x /= texture_size.width(); + fragment_tex_translate_y /= texture_size.height(); + fragment_tex_scale_x /= texture_size.width(); + fragment_tex_scale_y /= texture_size.height(); + } + TileProgramUniforms uniforms; if (use_aa) { if (quad->swizzle_contents) { - TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision), - &uniforms); + TileUniformLocation( + GetTileProgramSwizzleAA(tex_coord_precision, sampler), + &uniforms); } else { - TileUniformLocation(GetTileProgramAA(tex_coord_precision), &uniforms); + TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler), + &uniforms); } } else { if (quad->ShouldDrawWithBlending()) { if (quad->swizzle_contents) { - TileUniformLocation(GetTileProgramSwizzle(tex_coord_precision), - &uniforms); + TileUniformLocation( + GetTileProgramSwizzle(tex_coord_precision, sampler), + &uniforms); } else { - TileUniformLocation(GetTileProgram(tex_coord_precision), &uniforms); + TileUniformLocation(GetTileProgram(tex_coord_precision, sampler), + &uniforms); } } else { if (quad->swizzle_contents) { - TileUniformLocation(GetTileProgramSwizzleOpaque(tex_coord_precision), - &uniforms); + TileUniformLocation( + GetTileProgramSwizzleOpaque(tex_coord_precision, sampler), + &uniforms); } else { - TileUniformLocation(GetTileProgramOpaque(tex_coord_precision), + TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler), &uniforms); } } @@ -1383,13 +1422,6 @@ void GLRenderer::DrawContentQuad(const DrawingFrame* frame, SetUseProgram(uniforms.program); GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); - bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); - GLenum filter = (use_aa || scaled || - !quad->quadTransform().IsIdentityOrIntegerTranslation()) - ? GL_LINEAR - : GL_NEAREST; - ResourceProvider::ScopedSamplerGL quad_resource_lock( - resource_provider_, resource_id, GL_TEXTURE_2D, filter); if (use_aa) { float viewport[4] = { @@ -1468,29 +1500,29 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, ResourceProvider::ScopedSamplerGL y_plane_lock( resource_provider_, quad->y_plane_resource_id, - GL_TEXTURE_2D, GL_TEXTURE1, GL_LINEAR); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), y_plane_lock.target()); ResourceProvider::ScopedSamplerGL u_plane_lock( resource_provider_, quad->u_plane_resource_id, - GL_TEXTURE_2D, GL_TEXTURE2, GL_LINEAR); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), u_plane_lock.target()); ResourceProvider::ScopedSamplerGL v_plane_lock( resource_provider_, quad->v_plane_resource_id, - GL_TEXTURE_2D, GL_TEXTURE3, GL_LINEAR); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), v_plane_lock.target()); scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; if (use_alpha_plane) { a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( resource_provider_, quad->a_plane_resource_id, - GL_TEXTURE_2D, GL_TEXTURE4, GL_LINEAR)); + DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), a_plane_lock->target()); } int tex_scale_location = -1; @@ -1666,6 +1698,7 @@ void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( quad->texture_size, + GL_TEXTURE_2D, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, @@ -2526,7 +2559,9 @@ GLRenderer::GetTileCheckerboardProgram() { if (!tile_checkerboard_program_.initialized()) { TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); tile_checkerboard_program_.Initialize( - output_surface_->context_provider(), TexCoordPrecisionNA); + output_surface_->context_provider(), + TexCoordPrecisionNA, + SamplerTypeNA); } return &tile_checkerboard_program_; } @@ -2535,7 +2570,9 @@ const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { if (!debug_border_program_.initialized()) { TRACE_EVENT0("cc", "GLRenderer::debugBorderProgram::initialize"); debug_border_program_.Initialize( - output_surface_->context_provider(), TexCoordPrecisionNA); + output_surface_->context_provider(), + TexCoordPrecisionNA, + SamplerTypeNA); } return &debug_border_program_; } @@ -2544,7 +2581,9 @@ const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { if (!solid_color_program_.initialized()) { TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); solid_color_program_.Initialize( - output_surface_->context_provider(), TexCoordPrecisionNA); + output_surface_->context_provider(), + TexCoordPrecisionNA, + SamplerTypeNA); } return &solid_color_program_; } @@ -2553,221 +2592,254 @@ const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { if (!solid_color_program_aa_.initialized()) { TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); solid_color_program_aa_.Initialize( - output_surface_->context_provider(), TexCoordPrecisionNA); + output_surface_->context_provider(), + TexCoordPrecisionNA, + SamplerTypeNA); } return &solid_color_program_aa_; } const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( TexCoordPrecision precision) { - RenderPassProgram* program = - (precision == TexCoordPrecisionHigh) ? &render_pass_program_highp_ - : &render_pass_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + RenderPassProgram* program = &render_pass_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( TexCoordPrecision precision) { - RenderPassProgramAA* program = - (precision == TexCoordPrecisionHigh) ? &render_pass_program_aa_highp_ - : &render_pass_program_aa_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + RenderPassProgramAA* program = &render_pass_program_aa_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram(TexCoordPrecision precision) { - RenderPassMaskProgram* program = - (precision == TexCoordPrecisionHigh) ? &render_pass_mask_program_highp_ - : &render_pass_mask_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + RenderPassMaskProgram* program = &render_pass_mask_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassMaskProgramAA* GLRenderer::GetRenderPassMaskProgramAA(TexCoordPrecision precision) { - RenderPassMaskProgramAA* program = - (precision == TexCoordPrecisionHigh) ? &render_pass_mask_program_aa_highp_ - : &render_pass_mask_program_aa_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + RenderPassMaskProgramAA* program = &render_pass_mask_program_aa_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassColorMatrixProgram* GLRenderer::GetRenderPassColorMatrixProgram(TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); RenderPassColorMatrixProgram* program = - (precision == TexCoordPrecisionHigh) ? - &render_pass_color_matrix_program_highp_ : - &render_pass_color_matrix_program_; + &render_pass_color_matrix_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassColorMatrixProgramAA* GLRenderer::GetRenderPassColorMatrixProgramAA(TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); RenderPassColorMatrixProgramAA* program = - (precision == TexCoordPrecisionHigh) ? - &render_pass_color_matrix_program_aa_highp_ : - &render_pass_color_matrix_program_aa_; + &render_pass_color_matrix_program_aa_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassColorMatrixProgramAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassMaskColorMatrixProgram* GLRenderer::GetRenderPassMaskColorMatrixProgram(TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); RenderPassMaskColorMatrixProgram* program = - (precision == TexCoordPrecisionHigh) ? - &render_pass_mask_color_matrix_program_highp_ : - &render_pass_mask_color_matrix_program_; + &render_pass_mask_color_matrix_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassMaskColorMatrixProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::RenderPassMaskColorMatrixProgramAA* GLRenderer::GetRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); RenderPassMaskColorMatrixProgramAA* program = - (precision == TexCoordPrecisionHigh) ? - &render_pass_mask_color_matrix_program_aa_highp_ : - &render_pass_mask_color_matrix_program_aa_; + &render_pass_mask_color_matrix_program_aa_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::TileProgram* GLRenderer::GetTileProgram( - TexCoordPrecision precision) { - TileProgram* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_highp_ - : &tile_program_; + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); + TileProgram* program = &tile_program_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( - TexCoordPrecision precision) { - TileProgramOpaque* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_opaque_highp_ - : &tile_program_opaque_; - DCHECK(program); + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); + TileProgramOpaque* program = &tile_program_opaque_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( - TexCoordPrecision precision) { - TileProgramAA* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_aa_highp_ - : &tile_program_aa_; + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); + TileProgramAA* program = &tile_program_aa_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( - TexCoordPrecision precision) { - TileProgramSwizzle* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_swizzle_highp_ - : &tile_program_swizzle_; + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); + TileProgramSwizzle* program = &tile_program_swizzle_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TileProgramSwizzleOpaque* -GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision) { +GLRenderer::GetTileProgramSwizzleOpaque( + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); TileProgramSwizzleOpaque* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_swizzle_opaque_highp_ - : &tile_program_swizzle_opaque_; + &tile_program_swizzle_opaque_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( - TexCoordPrecision precision) { + TexCoordPrecision precision, SamplerType sampler) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + DCHECK_GE(sampler, 0); + DCHECK_LT(sampler, NumSamplerTypes); TileProgramSwizzleAA* program = - (precision == TexCoordPrecisionHigh) ? &tile_program_swizzle_aa_highp_ - : &tile_program_swizzle_aa_; + &tile_program_swizzle_aa_[precision][sampler]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, sampler); } return program; } const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( TexCoordPrecision precision) { - TextureProgram* program = - (precision == TexCoordPrecisionHigh) ? &texture_program_highp_ - : &texture_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + TextureProgram* program = &texture_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::NonPremultipliedTextureProgram* GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); NonPremultipliedTextureProgram* program = - (precision == TexCoordPrecisionHigh) ? - &nonpremultiplied_texture_program_highp_ : - &nonpremultiplied_texture_program_; + &nonpremultiplied_texture_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::NonPremultipliedTextureProgram::Initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::TextureBackgroundProgram* GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision) { - TextureBackgroundProgram* program = - (precision == TexCoordPrecisionHigh) ? &texture_background_program_highp_ - : &texture_background_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + TextureBackgroundProgram* program = &texture_background_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } @@ -2775,50 +2847,54 @@ GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision) { const GLRenderer::NonPremultipliedTextureBackgroundProgram* GLRenderer::GetNonPremultipliedTextureBackgroundProgram( TexCoordPrecision precision) { + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); NonPremultipliedTextureBackgroundProgram* program = - (precision == TexCoordPrecisionHigh) ? - &nonpremultiplied_texture_background_program_highp_ : - &nonpremultiplied_texture_background_program_; + &nonpremultiplied_texture_background_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::NonPremultipliedTextureProgram::Initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } -const GLRenderer::TextureIOSurfaceProgram* +const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram(TexCoordPrecision precision) { - TextureIOSurfaceProgram* program = - (precision == TexCoordPrecisionHigh) ? &texture_io_surface_program_highp_ - : &texture_io_surface_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + TextureProgram* program = &texture_io_surface_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2DRect); } return program; } const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( TexCoordPrecision precision) { - VideoYUVProgram* program = - (precision == TexCoordPrecisionHigh) ? &video_yuv_program_highp_ - : &video_yuv_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + VideoYUVProgram* program = &video_yuv_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram( TexCoordPrecision precision) { - VideoYUVAProgram* program = - (precision == TexCoordPrecisionHigh) ? &video_yuva_program_highp_ - : &video_yuva_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + VideoYUVAProgram* program = &video_yuva_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), precision, SamplerType2D); } return program; } @@ -2827,12 +2903,16 @@ const GLRenderer::VideoStreamTextureProgram* GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { if (!Capabilities().using_egl_image) return NULL; - VideoStreamTextureProgram* program = (precision == TexCoordPrecisionHigh) - ? &video_stream_texture_program_highp_ - : &video_stream_texture_program_; + DCHECK_GE(precision, 0); + DCHECK_LT(precision, NumTexCoordPrecisions); + VideoStreamTextureProgram* program = + &video_stream_texture_program_[precision]; if (!program->initialized()) { TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); - program->Initialize(output_surface_->context_provider(), precision); + program->Initialize( + output_surface_->context_provider(), + precision, + SamplerTypeExternalOES); } return program; } @@ -2842,58 +2922,37 @@ void GLRenderer::CleanupSharedObjects() { shared_geometry_.reset(); - tile_program_.Cleanup(context_); - tile_program_opaque_.Cleanup(context_); - tile_program_swizzle_.Cleanup(context_); - tile_program_swizzle_opaque_.Cleanup(context_); - tile_program_aa_.Cleanup(context_); - tile_program_swizzle_aa_.Cleanup(context_); - tile_checkerboard_program_.Cleanup(context_); + for (int i = 0; i < NumTexCoordPrecisions; ++i) { + for (int j = 0; j < NumSamplerTypes; ++j) { + tile_program_[i][j].Cleanup(context_); + tile_program_opaque_[i][j].Cleanup(context_); + tile_program_swizzle_[i][j].Cleanup(context_); + tile_program_swizzle_opaque_[i][j].Cleanup(context_); + tile_program_aa_[i][j].Cleanup(context_); + tile_program_swizzle_aa_[i][j].Cleanup(context_); + } - tile_program_highp_.Cleanup(context_); - tile_program_opaque_highp_.Cleanup(context_); - tile_program_swizzle_highp_.Cleanup(context_); - tile_program_swizzle_opaque_highp_.Cleanup(context_); - tile_program_aa_highp_.Cleanup(context_); - tile_program_swizzle_aa_highp_.Cleanup(context_); - - render_pass_mask_program_.Cleanup(context_); - render_pass_program_.Cleanup(context_); - render_pass_mask_program_aa_.Cleanup(context_); - render_pass_program_aa_.Cleanup(context_); - render_pass_color_matrix_program_.Cleanup(context_); - render_pass_mask_color_matrix_program_aa_.Cleanup(context_); - render_pass_color_matrix_program_aa_.Cleanup(context_); - render_pass_mask_color_matrix_program_.Cleanup(context_); - - render_pass_mask_program_highp_.Cleanup(context_); - render_pass_program_highp_.Cleanup(context_); - render_pass_mask_program_aa_highp_.Cleanup(context_); - render_pass_program_aa_highp_.Cleanup(context_); - render_pass_color_matrix_program_highp_.Cleanup(context_); - render_pass_mask_color_matrix_program_aa_highp_.Cleanup(context_); - render_pass_color_matrix_program_aa_highp_.Cleanup(context_); - render_pass_mask_color_matrix_program_highp_.Cleanup(context_); - - texture_program_.Cleanup(context_); - nonpremultiplied_texture_program_.Cleanup(context_); - texture_background_program_.Cleanup(context_); - nonpremultiplied_texture_background_program_.Cleanup(context_); - texture_io_surface_program_.Cleanup(context_); - - texture_program_highp_.Cleanup(context_); - nonpremultiplied_texture_program_highp_.Cleanup(context_); - texture_background_program_highp_.Cleanup(context_); - nonpremultiplied_texture_background_program_highp_.Cleanup(context_); - texture_io_surface_program_highp_.Cleanup(context_); - - video_yuv_program_.Cleanup(context_); - video_yuva_program_.Cleanup(context_); - video_stream_texture_program_.Cleanup(context_); - - video_yuv_program_highp_.Cleanup(context_); - video_yuva_program_highp_.Cleanup(context_); - video_stream_texture_program_highp_.Cleanup(context_); + render_pass_mask_program_[i].Cleanup(context_); + render_pass_program_[i].Cleanup(context_); + render_pass_mask_program_aa_[i].Cleanup(context_); + render_pass_program_aa_[i].Cleanup(context_); + render_pass_color_matrix_program_[i].Cleanup(context_); + render_pass_mask_color_matrix_program_aa_[i].Cleanup(context_); + render_pass_color_matrix_program_aa_[i].Cleanup(context_); + render_pass_mask_color_matrix_program_[i].Cleanup(context_); + + texture_program_[i].Cleanup(context_); + nonpremultiplied_texture_program_[i].Cleanup(context_); + texture_background_program_[i].Cleanup(context_); + nonpremultiplied_texture_background_program_[i].Cleanup(context_); + texture_io_surface_program_[i].Cleanup(context_); + + video_yuv_program_[i].Cleanup(context_); + video_yuva_program_[i].Cleanup(context_); + video_stream_texture_program_[i].Cleanup(context_); + } + + tile_checkerboard_program_.Cleanup(context_); debug_border_program_.Cleanup(context_); solid_color_program_.Cleanup(context_); diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h index 956644b..def9a25 100644 --- a/cc/output/gl_renderer.h +++ b/cc/output/gl_renderer.h @@ -264,9 +264,6 @@ class CC_EXPORT GLRenderer : public DirectRenderer { typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderTexBackgroundPremultiplyAlpha> NonPremultipliedTextureBackgroundProgram; - typedef ProgramBinding<VertexShaderPosTexTransform, - FragmentShaderRGBATexRectVaryingAlpha> - TextureIOSurfaceProgram; // Render surface shaders. typedef ProgramBinding<VertexShaderPosTexTransform, @@ -292,8 +289,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer { RenderPassMaskColorMatrixProgram; // Video shaders. - typedef ProgramBinding<VertexShaderVideoTransform, - FragmentShaderOESImageExternal> + typedef ProgramBinding<VertexShaderVideoTransform, FragmentShaderRGBATex> VideoStreamTextureProgram; typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo> VideoYUVProgram; @@ -308,14 +304,19 @@ class CC_EXPORT GLRenderer : public DirectRenderer { typedef ProgramBinding<VertexShaderQuadAA, FragmentShaderColorAA> SolidColorProgramAA; - const TileProgram* GetTileProgram(TexCoordPrecision precision); - const TileProgramOpaque* GetTileProgramOpaque(TexCoordPrecision precision); - const TileProgramAA* GetTileProgramAA(TexCoordPrecision precision); - const TileProgramSwizzle* GetTileProgramSwizzle(TexCoordPrecision precision); + const TileProgram* GetTileProgram( + TexCoordPrecision precision, SamplerType sampler); + const TileProgramOpaque* GetTileProgramOpaque( + TexCoordPrecision precision, SamplerType sampler); + const TileProgramAA* GetTileProgramAA( + TexCoordPrecision precision, SamplerType sampler); + const TileProgramSwizzle* GetTileProgramSwizzle( + TexCoordPrecision precision, SamplerType sampler); const TileProgramSwizzleOpaque* GetTileProgramSwizzleOpaque( - TexCoordPrecision precision); + TexCoordPrecision precision, SamplerType sampler); const TileProgramSwizzleAA* GetTileProgramSwizzleAA( - TexCoordPrecision precision); + TexCoordPrecision precision, SamplerType sampler); + const TileCheckerboardProgram* GetTileCheckerboardProgram(); const RenderPassProgram* GetRenderPassProgram( @@ -343,7 +344,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer { TexCoordPrecision precision); const NonPremultipliedTextureBackgroundProgram* GetNonPremultipliedTextureBackgroundProgram(TexCoordPrecision precision); - const TextureIOSurfaceProgram* GetTextureIOSurfaceProgram( + const TextureProgram* GetTextureIOSurfaceProgram( TexCoordPrecision precision); const VideoYUVProgram* GetVideoYUVProgram( @@ -357,61 +358,44 @@ class CC_EXPORT GLRenderer : public DirectRenderer { const SolidColorProgram* GetSolidColorProgram(); const SolidColorProgramAA* GetSolidColorProgramAA(); - TileProgram tile_program_; - TileProgramOpaque tile_program_opaque_; - TileProgramAA tile_program_aa_; - TileProgramSwizzle tile_program_swizzle_; - TileProgramSwizzleOpaque tile_program_swizzle_opaque_; - TileProgramSwizzleAA tile_program_swizzle_aa_; - TileCheckerboardProgram tile_checkerboard_program_; + TileProgram tile_program_[NumTexCoordPrecisions][NumSamplerTypes]; + TileProgramOpaque + tile_program_opaque_[NumTexCoordPrecisions][NumSamplerTypes]; + TileProgramAA tile_program_aa_[NumTexCoordPrecisions][NumSamplerTypes]; + TileProgramSwizzle + tile_program_swizzle_[NumTexCoordPrecisions][NumSamplerTypes]; + TileProgramSwizzleOpaque + tile_program_swizzle_opaque_[NumTexCoordPrecisions][NumSamplerTypes]; + TileProgramSwizzleAA + tile_program_swizzle_aa_[NumTexCoordPrecisions][NumSamplerTypes]; - TileProgram tile_program_highp_; - TileProgramOpaque tile_program_opaque_highp_; - TileProgramAA tile_program_aa_highp_; - TileProgramSwizzle tile_program_swizzle_highp_; - TileProgramSwizzleOpaque tile_program_swizzle_opaque_highp_; - TileProgramSwizzleAA tile_program_swizzle_aa_highp_; - - TextureProgram texture_program_; - NonPremultipliedTextureProgram nonpremultiplied_texture_program_; - TextureBackgroundProgram texture_background_program_; - NonPremultipliedTextureBackgroundProgram - nonpremultiplied_texture_background_program_; - TextureIOSurfaceProgram texture_io_surface_program_; + TileCheckerboardProgram tile_checkerboard_program_; - TextureProgram texture_program_highp_; - NonPremultipliedTextureProgram nonpremultiplied_texture_program_highp_; - TextureBackgroundProgram texture_background_program_highp_; + TextureProgram texture_program_[NumTexCoordPrecisions]; + NonPremultipliedTextureProgram + nonpremultiplied_texture_program_[NumTexCoordPrecisions]; + TextureBackgroundProgram texture_background_program_[NumTexCoordPrecisions]; NonPremultipliedTextureBackgroundProgram - nonpremultiplied_texture_background_program_highp_; - TextureIOSurfaceProgram texture_io_surface_program_highp_; - - RenderPassProgram render_pass_program_; - RenderPassProgramAA render_pass_program_aa_; - RenderPassMaskProgram render_pass_mask_program_; - RenderPassMaskProgramAA render_pass_mask_program_aa_; - RenderPassColorMatrixProgram render_pass_color_matrix_program_; - RenderPassColorMatrixProgramAA render_pass_color_matrix_program_aa_; - RenderPassMaskColorMatrixProgram render_pass_mask_color_matrix_program_; - RenderPassMaskColorMatrixProgramAA render_pass_mask_color_matrix_program_aa_; - - RenderPassProgram render_pass_program_highp_; - RenderPassProgramAA render_pass_program_aa_highp_; - RenderPassMaskProgram render_pass_mask_program_highp_; - RenderPassMaskProgramAA render_pass_mask_program_aa_highp_; - RenderPassColorMatrixProgram render_pass_color_matrix_program_highp_; - RenderPassColorMatrixProgramAA render_pass_color_matrix_program_aa_highp_; - RenderPassMaskColorMatrixProgram render_pass_mask_color_matrix_program_highp_; + nonpremultiplied_texture_background_program_[NumTexCoordPrecisions]; + TextureProgram texture_io_surface_program_[NumTexCoordPrecisions]; + + RenderPassProgram render_pass_program_[NumTexCoordPrecisions]; + RenderPassProgramAA render_pass_program_aa_[NumTexCoordPrecisions]; + RenderPassMaskProgram render_pass_mask_program_[NumTexCoordPrecisions]; + RenderPassMaskProgramAA render_pass_mask_program_aa_[NumTexCoordPrecisions]; + RenderPassColorMatrixProgram + render_pass_color_matrix_program_[NumTexCoordPrecisions]; + RenderPassColorMatrixProgramAA + render_pass_color_matrix_program_aa_[NumTexCoordPrecisions]; + RenderPassMaskColorMatrixProgram + render_pass_mask_color_matrix_program_[NumTexCoordPrecisions]; RenderPassMaskColorMatrixProgramAA - render_pass_mask_color_matrix_program_aa_highp_; - - VideoYUVProgram video_yuv_program_; - VideoYUVAProgram video_yuva_program_; - VideoStreamTextureProgram video_stream_texture_program_; + render_pass_mask_color_matrix_program_aa_[NumTexCoordPrecisions]; - VideoYUVProgram video_yuv_program_highp_; - VideoYUVAProgram video_yuva_program_highp_; - VideoStreamTextureProgram video_stream_texture_program_highp_; + VideoYUVProgram video_yuv_program_[NumTexCoordPrecisions]; + VideoYUVAProgram video_yuva_program_[NumTexCoordPrecisions]; + VideoStreamTextureProgram + video_stream_texture_program_[NumTexCoordPrecisions]; DebugBorderProgram debug_border_program_; SolidColorProgram solid_color_program_; diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc index 8254bb2..93905fd 100644 --- a/cc/output/gl_renderer_unittest.cc +++ b/cc/output/gl_renderer_unittest.cc @@ -76,12 +76,6 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { } void TestShadersWithTexCoordPrecision(TexCoordPrecision precision) { - EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetTileProgramSwizzle(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetTileProgramSwizzleOpaque(precision)); - EXPECT_PROGRAM_VALID(renderer()->GetTileProgramSwizzleAA(precision)); EXPECT_PROGRAM_VALID(renderer()->GetRenderPassProgram(precision)); EXPECT_PROGRAM_VALID(renderer()->GetRenderPassProgramAA(precision)); EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskProgram(precision)); @@ -108,6 +102,24 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { EXPECT_PROGRAM_VALID(renderer()->GetVideoStreamTextureProgram(precision)); else EXPECT_FALSE(renderer()->GetVideoStreamTextureProgram(precision)); + TestShadersWithSamplerType(precision, SamplerType2D); + TestShadersWithSamplerType(precision, SamplerType2DRect); + // This is unlikely to be ever true in tests due to usage of osmesa. + if (renderer()->Capabilities().using_egl_image) + TestShadersWithSamplerType(precision, SamplerTypeExternalOES); + } + + void TestShadersWithSamplerType( + TexCoordPrecision precision, SamplerType sampler) { + EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision, sampler)); + EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision, sampler)); + EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision, sampler)); + EXPECT_PROGRAM_VALID( + renderer()->GetTileProgramSwizzle(precision, sampler)); + EXPECT_PROGRAM_VALID( + renderer()->GetTileProgramSwizzleOpaque(precision, sampler)); + EXPECT_PROGRAM_VALID( + renderer()->GetTileProgramSwizzleAA(precision, sampler)); } }; @@ -261,51 +273,59 @@ class GLRendererShaderTest : public testing::Test { renderer_->Initialize(); } - void TestRenderPassProgram() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_program_); - EXPECT_EQ(renderer_->render_pass_program_.program(), + void TestRenderPassProgram(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID(&renderer_->render_pass_program_[precision]); + EXPECT_EQ(renderer_->render_pass_program_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassColorMatrixProgram() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_color_matrix_program_); - EXPECT_EQ(renderer_->render_pass_color_matrix_program_.program(), - renderer_->program_shadow_); + void TestRenderPassColorMatrixProgram(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID( + &renderer_->render_pass_color_matrix_program_[precision]); + EXPECT_EQ( + renderer_->render_pass_color_matrix_program_[precision].program(), + renderer_->program_shadow_); } - void TestRenderPassMaskProgram() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_program_); - EXPECT_EQ(renderer_->render_pass_mask_program_.program(), + void TestRenderPassMaskProgram(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_program_[precision]); + EXPECT_EQ(renderer_->render_pass_mask_program_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassMaskColorMatrixProgram() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_color_matrix_program_); - EXPECT_EQ(renderer_->render_pass_mask_color_matrix_program_.program(), + void TestRenderPassMaskColorMatrixProgram(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID( + &renderer_->render_pass_mask_color_matrix_program_[precision]); + EXPECT_EQ(renderer_-> + render_pass_mask_color_matrix_program_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassProgramAA() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_program_aa_); - EXPECT_EQ(renderer_->render_pass_program_aa_.program(), + void TestRenderPassProgramAA(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID(&renderer_->render_pass_program_aa_[precision]); + EXPECT_EQ(renderer_->render_pass_program_aa_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassColorMatrixProgramAA() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_color_matrix_program_aa_); - EXPECT_EQ(renderer_->render_pass_color_matrix_program_aa_.program(), + void TestRenderPassColorMatrixProgramAA(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID( + &renderer_->render_pass_color_matrix_program_aa_[precision]); + EXPECT_EQ(renderer_-> + render_pass_color_matrix_program_aa_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassMaskProgramAA() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_program_aa_); - EXPECT_EQ(renderer_->render_pass_mask_program_aa_.program(), + void TestRenderPassMaskProgramAA(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_program_aa_[precision]); + EXPECT_EQ(renderer_->render_pass_mask_program_aa_[precision].program(), renderer_->program_shadow_); } - void TestRenderPassMaskColorMatrixProgramAA() { - EXPECT_PROGRAM_VALID(&renderer_->render_pass_mask_color_matrix_program_aa_); - EXPECT_EQ(renderer_->render_pass_mask_color_matrix_program_aa_.program(), + void TestRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision) { + EXPECT_PROGRAM_VALID( + &renderer_->render_pass_mask_color_matrix_program_aa_[precision]); + EXPECT_EQ(renderer_-> + render_pass_mask_color_matrix_program_aa_[precision].program(), renderer_->program_shadow_); } @@ -1367,7 +1387,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassProgram(); + TestRenderPassProgram(TexCoordPrecisionMedium); // RenderPassColorMatrixProgram render_passes->clear(); @@ -1384,7 +1404,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassColorMatrixProgram(); + TestRenderPassColorMatrixProgram(TexCoordPrecisionMedium); // RenderPassMaskProgram render_passes->clear(); @@ -1405,7 +1425,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassMaskProgram(); + TestRenderPassMaskProgram(TexCoordPrecisionMedium); // RenderPassMaskColorMatrixProgram render_passes->clear(); @@ -1422,7 +1442,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassMaskColorMatrixProgram(); + TestRenderPassMaskColorMatrixProgram(TexCoordPrecisionMedium); // RenderPassProgramAA render_passes->clear(); @@ -1443,7 +1463,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassProgramAA(); + TestRenderPassProgramAA(TexCoordPrecisionMedium); // RenderPassColorMatrixProgramAA render_passes->clear(); @@ -1460,7 +1480,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassColorMatrixProgramAA(); + TestRenderPassColorMatrixProgramAA(TexCoordPrecisionMedium); // RenderPassMaskProgramAA render_passes->clear(); @@ -1478,7 +1498,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassMaskProgramAA(); + TestRenderPassMaskProgramAA(TexCoordPrecisionMedium); // RenderPassMaskColorMatrixProgramAA render_passes->clear(); @@ -1495,7 +1515,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { *renderer_client_.render_passes_in_draw_order()); renderer_->DrawFrame( renderer_client_.render_passes_in_draw_order(), NULL, 1.f, true, false); - TestRenderPassMaskColorMatrixProgramAA(); + TestRenderPassMaskColorMatrixProgramAA(TexCoordPrecisionMedium); } // At this time, the AA code path cannot be taken if the surface's rect would @@ -1547,7 +1567,7 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) { // If use_aa incorrectly ignores clipping, it will use the // RenderPassProgramAA shader instead of the RenderPassProgram. - TestRenderPassProgram(); + TestRenderPassProgram(TexCoordPrecisionMedium); } TEST_F(GLRendererShaderTest, DrawSolidColorShader) { diff --git a/cc/output/program_binding.h b/cc/output/program_binding.h index 4c11902..4a75a01 100644 --- a/cc/output/program_binding.h +++ b/cc/output/program_binding.h @@ -53,7 +53,8 @@ class ProgramBinding : public ProgramBindingBase { ProgramBinding() {} void Initialize(ContextProvider* context_provider, - TexCoordPrecision precision) { + TexCoordPrecision precision, + SamplerType sampler) { DCHECK(context_provider); DCHECK(!initialized_); @@ -63,7 +64,7 @@ class ProgramBinding : public ProgramBindingBase { if (!ProgramBindingBase::Init( context_provider->Context3d(), vertex_shader_.GetShaderString(), - fragment_shader_.GetShaderString(precision))) { + fragment_shader_.GetShaderString(precision, sampler))) { DCHECK(context_provider->IsContextLost()); return; } diff --git a/cc/output/shader.cc b/cc/output/shader.cc index 0aae3ec..501c00d 100644 --- a/cc/output/shader.cc +++ b/cc/output/shader.cc @@ -14,7 +14,8 @@ #define SHADER0(Src) #Src #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) -#define FRAGMENT_SHADER(Src) SetFragTexCoordPrecision(precision, SHADER0(Src)) +#define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \ + precision, SetFragmentSamplerType(sampler, SHADER0(Src))) using blink::WebGraphicsContext3D; @@ -34,7 +35,7 @@ static void GetProgramUniformLocations(WebGraphicsContext3D* context, } } -static std::string SetFragTexCoordPrecision( +static std::string SetFragmentTexCoordPrecision( TexCoordPrecision requested_precision, std::string shader_string) { switch (requested_precision) { case TexCoordPrecisionHigh: @@ -53,7 +54,11 @@ static std::string SetFragTexCoordPrecision( case TexCoordPrecisionNA: DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); + DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); return shader_string; + default: + NOTREACHED(); + break; } return shader_string; } @@ -90,6 +95,43 @@ TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, return TexCoordPrecisionMedium; } +static std::string SetFragmentSamplerType( + SamplerType requested_type, std::string shader_string) { + switch (requested_type) { + case SamplerType2D: + DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); + DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); + return + "#define SamplerType sampler2D\n" + "#define TextureLookup texture2D\n" + + shader_string; + case SamplerType2DRect: + DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); + DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); + return + "#extension GL_ARB_texture_rectangle : require\n" + "#define SamplerType sampler2DRect\n" + "#define TextureLookup texture2DRect\n" + + shader_string; + case SamplerTypeExternalOES: + DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); + DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); + return + "#extension GL_OES_EGL_image_external : require\n" + "#define SamplerType samplerExternalOES\n" + "#define TextureLookup texture2D\n" + + shader_string; + case SamplerTypeNA: + DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); + DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); + return shader_string; + default: + NOTREACHED(); + break; + } + return shader_string; +} + } // namespace TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, @@ -655,66 +697,31 @@ void FragmentTexOpaqueBinding::Init(WebGraphicsContext3D* context, sampler_location_ = locations[0]; } -FragmentShaderOESImageExternal::FragmentShaderOESImageExternal() - : sampler_location_(-1) {} - -void FragmentShaderOESImageExternal::Init(WebGraphicsContext3D* context, - unsigned program, - int* base_uniform_index) { - static const char* uniforms[] = { - "s_texture", - }; - int locations[arraysize(uniforms)]; - - GetProgramUniformLocations(context, - program, - arraysize(uniforms), - uniforms, - locations, - base_uniform_index); - sampler_location_ = locations[0]; -} - -std::string FragmentShaderOESImageExternal::GetShaderString( - TexCoordPrecision precision) const { - // Cannot use the SHADER() macro because of the '#' char - return "#extension GL_OES_EGL_image_external : require\n" + - FRAGMENT_SHADER( - precision mediump float; - varying TexCoordPrecision vec2 v_texCoord; - uniform samplerExternalOES s_texture; - void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); - gl_FragColor = texColor; - } - ); // NOLINT(whitespace/parens) -} - std::string FragmentShaderRGBATexAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); gl_FragColor = texColor * alpha; } ); // NOLINT(whitespace/parens) } std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; uniform mat4 colorMatrix; uniform vec4 colorOffset; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); float nonZeroAlpha = max(texColor.a, 0.00001); texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); texColor = colorMatrix * texColor + colorOffset; @@ -726,28 +733,28 @@ std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( } std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; varying float v_alpha; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); gl_FragColor = texColor * v_alpha; } ); // NOLINT(whitespace/parens) } std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; varying float v_alpha; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); texColor.rgb *= texColor.a; gl_FragColor = texColor * v_alpha; } @@ -783,15 +790,15 @@ void FragmentTexBackgroundBinding::Init(WebGraphicsContext3D* context, } std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; varying float v_alpha; uniform vec4 background_color; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); texColor += background_color * (1.0 - texColor.a); gl_FragColor = texColor * v_alpha; } @@ -799,15 +806,15 @@ std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( } std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; varying float v_alpha; uniform vec4 background_color; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); texColor.rgb *= texColor.a; texColor += background_color * (1.0 - texColor.a); gl_FragColor = texColor * v_alpha; @@ -815,55 +822,40 @@ std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( ); // NOLINT(whitespace/parens) } -std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( - TexCoordPrecision precision) const { - return "#extension GL_ARB_texture_rectangle : require\n" + - FRAGMENT_SHADER( - precision mediump float; - varying TexCoordPrecision vec2 v_texCoord; - varying float v_alpha; - uniform sampler2DRect s_texture; - void main() { - vec4 texColor = texture2DRect(s_texture, v_texCoord); - gl_FragColor = texColor * v_alpha; - } - ); // NOLINT(whitespace/parens) -} - std::string FragmentShaderRGBATexOpaque::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); gl_FragColor = vec4(texColor.rgb, 1.0); } ); // NOLINT(whitespace/parens) } std::string FragmentShaderRGBATex::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - gl_FragColor = texture2D(s_texture, v_texCoord); + gl_FragColor = TextureLookup(s_texture, v_texCoord); } ); // NOLINT(whitespace/parens) } std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; } @@ -871,13 +863,13 @@ std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( } std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; + uniform SamplerType s_texture; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); } ); // NOLINT(whitespace/parens) @@ -907,16 +899,16 @@ void FragmentShaderRGBATexAlphaAA::Init(WebGraphicsContext3D* context, } std::string FragmentShaderRGBATexAlphaAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; varying TexCoordPrecision vec2 v_texCoord; varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); vec4 d4 = min(edge_dist[0], edge_dist[1]); vec2 d2 = min(d4.xz, d4.yw); float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); @@ -952,10 +944,10 @@ void FragmentTexClampAlphaAABinding::Init(WebGraphicsContext3D* context, } std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; uniform TexCoordPrecision vec4 fragmentTexTransform; varying TexCoordPrecision vec2 v_texCoord; @@ -965,7 +957,7 @@ std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy; - vec4 texColor = texture2D(s_texture, texCoord); + vec4 texColor = TextureLookup(s_texture, texCoord); vec4 d4 = min(edge_dist[0], edge_dist[1]); vec2 d2 = min(d4.xz, d4.yw); float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); @@ -975,10 +967,10 @@ std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( } std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; uniform TexCoordPrecision vec4 fragmentTexTransform; varying TexCoordPrecision vec2 v_texCoord; @@ -988,7 +980,7 @@ std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy; - vec4 texColor = texture2D(s_texture, texCoord); + vec4 texColor = TextureLookup(s_texture, texCoord); vec4 d4 = min(edge_dist[0], edge_dist[1]); vec2 d2 = min(d4.xz, d4.yw); float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); @@ -1030,21 +1022,21 @@ void FragmentShaderRGBATexAlphaMask::Init(WebGraphicsContext3D* context, } std::string FragmentShaderRGBATexAlphaMask::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; - uniform sampler2D s_mask; + uniform SamplerType s_texture; + uniform SamplerType s_mask; uniform TexCoordPrecision vec2 maskTexCoordScale; uniform TexCoordPrecision vec2 maskTexCoordOffset; uniform float alpha; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); - vec4 maskColor = texture2D(s_mask, maskTexCoord); + vec4 maskColor = TextureLookup(s_mask, maskTexCoord); gl_FragColor = texColor * alpha * maskColor.w; } ); // NOLINT(whitespace/parens) @@ -1083,11 +1075,11 @@ void FragmentShaderRGBATexAlphaMaskAA::Init(WebGraphicsContext3D* context, } std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; - uniform sampler2D s_mask; + uniform SamplerType s_texture; + uniform SamplerType s_mask; uniform TexCoordPrecision vec2 maskTexCoordScale; uniform TexCoordPrecision vec2 maskTexCoordOffset; uniform float alpha; @@ -1095,11 +1087,11 @@ std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); - vec4 maskColor = texture2D(s_mask, maskTexCoord); + vec4 maskColor = TextureLookup(s_mask, maskTexCoord); vec4 d4 = min(edge_dist[0], edge_dist[1]); vec2 d2 = min(d4.xz, d4.yw); float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); @@ -1148,11 +1140,11 @@ void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( } std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; - uniform sampler2D s_mask; + uniform SamplerType s_texture; + uniform SamplerType s_mask; uniform vec2 maskTexCoordScale; uniform vec2 maskTexCoordOffset; uniform mat4 colorMatrix; @@ -1162,7 +1154,7 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); float nonZeroAlpha = max(texColor.a, 0.00001); texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); texColor = colorMatrix * texColor + colorOffset; @@ -1171,7 +1163,7 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); - vec4 maskColor = texture2D(s_mask, maskTexCoord); + vec4 maskColor = TextureLookup(s_mask, maskTexCoord); vec4 d4 = min(edge_dist[0], edge_dist[1]); vec2 d2 = min(d4.xz, d4.yw); float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); @@ -1212,10 +1204,10 @@ void FragmentShaderRGBATexAlphaColorMatrixAA::Init( } std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; - uniform sampler2D s_texture; + uniform SamplerType s_texture; uniform float alpha; uniform mat4 colorMatrix; uniform vec4 colorOffset; @@ -1223,7 +1215,7 @@ std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); float nonZeroAlpha = max(texColor.a, 0.00001); texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); texColor = colorMatrix * texColor + colorOffset; @@ -1275,19 +1267,19 @@ void FragmentShaderRGBATexAlphaMaskColorMatrix::Init( } std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D s_texture; - uniform sampler2D s_mask; + uniform SamplerType s_texture; + uniform SamplerType s_mask; uniform vec2 maskTexCoordScale; uniform vec2 maskTexCoordOffset; uniform mat4 colorMatrix; uniform vec4 colorOffset; uniform float alpha; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec4 texColor = TextureLookup(s_texture, v_texCoord); float nonZeroAlpha = max(texColor.a, 0.00001); texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); texColor = colorMatrix * texColor + colorOffset; @@ -1296,7 +1288,7 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); - vec4 maskColor = texture2D(s_mask, maskTexCoord); + vec4 maskColor = TextureLookup(s_mask, maskTexCoord); gl_FragColor = texColor * alpha * maskColor.w; } ); // NOLINT(whitespace/parens) @@ -1338,21 +1330,21 @@ void FragmentShaderYUVVideo::Init(WebGraphicsContext3D* context, } std::string FragmentShaderYUVVideo::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; precision mediump int; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D y_texture; - uniform sampler2D u_texture; - uniform sampler2D v_texture; + uniform SamplerType y_texture; + uniform SamplerType u_texture; + uniform SamplerType v_texture; uniform float alpha; uniform vec3 yuv_adj; uniform mat3 yuv_matrix; void main() { - float y_raw = texture2D(y_texture, v_texCoord).x; - float u_unsigned = texture2D(u_texture, v_texCoord).x; - float v_unsigned = texture2D(v_texture, v_texCoord).x; + float y_raw = TextureLookup(y_texture, v_texCoord).x; + float u_unsigned = TextureLookup(u_texture, v_texCoord).x; + float v_unsigned = TextureLookup(v_texture, v_texCoord).x; vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; vec3 rgb = yuv_matrix * yuv; gl_FragColor = vec4(rgb, 1.0) * alpha; @@ -1400,23 +1392,23 @@ void FragmentShaderYUVAVideo::Init(WebGraphicsContext3D* context, } std::string FragmentShaderYUVAVideo::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; precision mediump int; varying TexCoordPrecision vec2 v_texCoord; - uniform sampler2D y_texture; - uniform sampler2D u_texture; - uniform sampler2D v_texture; - uniform sampler2D a_texture; + uniform SamplerType y_texture; + uniform SamplerType u_texture; + uniform SamplerType v_texture; + uniform SamplerType a_texture; uniform float alpha; uniform vec3 yuv_adj; uniform mat3 yuv_matrix; void main() { - float y_raw = texture2D(y_texture, v_texCoord).x; - float u_unsigned = texture2D(u_texture, v_texCoord).x; - float v_unsigned = texture2D(v_texture, v_texCoord).x; - float a_raw = texture2D(a_texture, v_texCoord).x; + float y_raw = TextureLookup(y_texture, v_texCoord).x; + float u_unsigned = TextureLookup(u_texture, v_texCoord).x; + float v_unsigned = TextureLookup(v_texture, v_texCoord).x; + float a_raw = TextureLookup(a_texture, v_texCoord).x; vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; vec3 rgb = yuv_matrix * yuv; gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); @@ -1445,7 +1437,7 @@ void FragmentShaderColor::Init(WebGraphicsContext3D* context, } std::string FragmentShaderColor::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; uniform vec4 color; @@ -1476,7 +1468,7 @@ void FragmentShaderColorAA::Init(WebGraphicsContext3D* context, } std::string FragmentShaderColorAA::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { return FRAGMENT_SHADER( precision mediump float; uniform vec4 color; @@ -1520,7 +1512,7 @@ void FragmentShaderCheckerboard::Init(WebGraphicsContext3D* context, } std::string FragmentShaderCheckerboard::GetShaderString( - TexCoordPrecision precision) const { + TexCoordPrecision precision, SamplerType sampler) const { // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" // by Munshi, Ginsburg, Shreiner. return FRAGMENT_SHADER( diff --git a/cc/output/shader.h b/cc/output/shader.h index eb89d65..986e6d9 100644 --- a/cc/output/shader.h +++ b/cc/output/shader.h @@ -21,9 +21,18 @@ namespace blink { class WebGraphicsContext3D; } namespace cc { enum TexCoordPrecision { - TexCoordPrecisionNA, - TexCoordPrecisionMedium, - TexCoordPrecisionHigh, + TexCoordPrecisionNA = 0, + TexCoordPrecisionMedium = 1, + TexCoordPrecisionHigh = 2, + NumTexCoordPrecisions = 3 +}; + +enum SamplerType { + SamplerTypeNA = 0, + SamplerType2D = 1, + SamplerType2DRect = 2, + SamplerTypeExternalOES = 3, + NumSamplerTypes = 4 }; // Note: The highp_threshold_cache must be provided by the caller to make @@ -340,77 +349,67 @@ class FragmentTexBackgroundBinding { class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderTexBackgroundVaryingAlpha : public FragmentTexBackgroundBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentTexBackgroundBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexColorMatrixAlpha : public FragmentTexColorMatrixAlphaBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; -}; - -class FragmentShaderRGBATexRectVaryingAlpha : public FragmentTexOpaqueBinding { - public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATex : public FragmentTexOpaqueBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; // Swizzles the red and blue component of sampled texel with alpha. class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; // Swizzles the red and blue component of sampled texel without alpha. class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; -}; - -// Fragment shader for external textures. -class FragmentShaderOESImageExternal : public FragmentTexAlphaBinding { - public: - FragmentShaderOESImageExternal(); - - std::string GetShaderString(TexCoordPrecision precision) const; - void Init(blink::WebGraphicsContext3D* context, - unsigned program, - int* base_uniform_index); - private: - int sampler_location_; - - DISALLOW_COPY_AND_ASSIGN(FragmentShaderOESImageExternal); + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexAlphaAA { @@ -420,7 +419,8 @@ class FragmentShaderRGBATexAlphaAA { void Init(blink::WebGraphicsContext3D* context, unsigned program, int* base_uniform_index); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; int alpha_location() const { return alpha_location_; } int sampler_location() const { return sampler_location_; } @@ -456,20 +456,23 @@ class FragmentTexClampAlphaAABinding { class FragmentShaderRGBATexClampAlphaAA : public FragmentTexClampAlphaAABinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; // Swizzles the red and blue component of sampled texel. class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentTexClampAlphaAABinding { public: - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; }; class FragmentShaderRGBATexAlphaMask { public: FragmentShaderRGBATexAlphaMask(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -497,7 +500,8 @@ class FragmentShaderRGBATexAlphaMask { class FragmentShaderRGBATexAlphaMaskAA { public: FragmentShaderRGBATexAlphaMaskAA(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -525,7 +529,8 @@ class FragmentShaderRGBATexAlphaMaskAA { class FragmentShaderRGBATexAlphaMaskColorMatrixAA { public: FragmentShaderRGBATexAlphaMaskColorMatrixAA(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -555,7 +560,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrixAA { class FragmentShaderRGBATexAlphaColorMatrixAA { public: FragmentShaderRGBATexAlphaColorMatrixAA(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -575,7 +581,8 @@ class FragmentShaderRGBATexAlphaColorMatrixAA { class FragmentShaderRGBATexAlphaMaskColorMatrix { public: FragmentShaderRGBATexAlphaMaskColorMatrix(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -605,7 +612,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrix { class FragmentShaderYUVVideo { public: FragmentShaderYUVVideo(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -632,7 +640,8 @@ class FragmentShaderYUVVideo { class FragmentShaderYUVAVideo { public: FragmentShaderYUVAVideo(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -661,7 +670,8 @@ class FragmentShaderYUVAVideo { class FragmentShaderColor { public: FragmentShaderColor(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -677,7 +687,8 @@ class FragmentShaderColor { class FragmentShaderColorAA { public: FragmentShaderColorAA(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, @@ -693,7 +704,8 @@ class FragmentShaderColorAA { class FragmentShaderCheckerboard { public: FragmentShaderCheckerboard(); - std::string GetShaderString(TexCoordPrecision precision) const; + std::string GetShaderString( + TexCoordPrecision precision, SamplerType sampler) const; void Init(blink::WebGraphicsContext3D* context, unsigned program, diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc index 8c3a06b..90572ab 100644 --- a/cc/resources/image_raster_worker_pool.cc +++ b/cc/resources/image_raster_worker_pool.cc @@ -57,8 +57,11 @@ class ImageWorkerPoolTaskImpl : public internal::WorkerPoolTask { } // namespace ImageRasterWorkerPool::ImageRasterWorkerPool( - ResourceProvider* resource_provider, size_t num_threads) + ResourceProvider* resource_provider, + size_t num_threads, + GLenum texture_target) : RasterWorkerPool(resource_provider, num_threads), + texture_target_(texture_target), raster_tasks_pending_(false), raster_tasks_required_for_activation_pending_(false) { } @@ -154,6 +157,10 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) { "state", TracedValue::FromValue(StateAsValue().release())); } +GLenum ImageRasterWorkerPool::GetResourceTarget() const { + return texture_target_; +} + ResourceFormat ImageRasterWorkerPool::GetResourceFormat() const { return resource_provider()->best_texture_format(); } diff --git a/cc/resources/image_raster_worker_pool.h b/cc/resources/image_raster_worker_pool.h index 63526493..38fe042 100644 --- a/cc/resources/image_raster_worker_pool.h +++ b/cc/resources/image_raster_worker_pool.h @@ -14,20 +14,26 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { virtual ~ImageRasterWorkerPool(); static scoped_ptr<RasterWorkerPool> Create( - ResourceProvider* resource_provider, size_t num_threads) { + ResourceProvider* resource_provider, + size_t num_threads, + GLenum texture_target) { return make_scoped_ptr<RasterWorkerPool>( - new ImageRasterWorkerPool(resource_provider, num_threads)); + new ImageRasterWorkerPool(resource_provider, + num_threads, + texture_target)); } // Overridden from RasterWorkerPool: virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE; + virtual GLenum GetResourceTarget() const OVERRIDE; virtual ResourceFormat GetResourceFormat() const OVERRIDE; virtual void OnRasterTasksFinished() OVERRIDE; virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE; private: ImageRasterWorkerPool(ResourceProvider* resource_provider, - size_t num_threads); + size_t num_threads, + GLenum texture_target); void OnRasterTaskCompleted( scoped_refptr<internal::RasterWorkerPoolTask> task, bool was_canceled); @@ -43,6 +49,8 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { internal::GraphNode* raster_finished_node, TaskGraph* graph); + const GLenum texture_target_; + TaskMap image_tasks_; bool raster_tasks_pending_; diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc index edd7d6c..011e514 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.cc +++ b/cc/resources/pixel_buffer_raster_worker_pool.cc @@ -217,6 +217,10 @@ void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) { "state", TracedValue::FromValue(StateAsValue().release())); } +GLenum PixelBufferRasterWorkerPool::GetResourceTarget() const { + return GL_TEXTURE_2D; +} + ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { return resource_provider()->memory_efficient_texture_format(); } diff --git a/cc/resources/pixel_buffer_raster_worker_pool.h b/cc/resources/pixel_buffer_raster_worker_pool.h index a856d8a..88be2c0 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.h +++ b/cc/resources/pixel_buffer_raster_worker_pool.h @@ -34,6 +34,7 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { // Overridden from RasterWorkerPool: virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE; + virtual GLenum GetResourceTarget() const OVERRIDE; virtual ResourceFormat GetResourceFormat() const OVERRIDE; virtual void OnRasterTasksFinished() OVERRIDE; virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE; diff --git a/cc/resources/prioritized_resource_manager.cc b/cc/resources/prioritized_resource_manager.cc index ece04b1..8efe143 100644 --- a/cc/resources/prioritized_resource_manager.cc +++ b/cc/resources/prioritized_resource_manager.cc @@ -447,6 +447,7 @@ PrioritizedResource::Backing* PrioritizedResourceManager::CreateBacking( ResourceProvider::ResourceId resource_id = resource_provider->CreateManagedResource( size, + GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h index e7c7a5c..a334f65 100644 --- a/cc/resources/raster_worker_pool.h +++ b/cc/resources/raster_worker_pool.h @@ -186,6 +186,9 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool { // even if they later get canceled by another call to ScheduleTasks(). virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; + // Returns the target that needs to be used for raster task resources. + virtual GLenum GetResourceTarget() const = 0; + // Returns the format that needs to be used for raster task resources. virtual ResourceFormat GetResourceFormat() const = 0; diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc index e08dffc..8b9c8e0 100644 --- a/cc/resources/raster_worker_pool_perftest.cc +++ b/cc/resources/raster_worker_pool_perftest.cc @@ -40,6 +40,10 @@ class PerfRasterWorkerPool : public RasterWorkerPool { virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE { NOTREACHED(); } + virtual GLenum GetResourceTarget() const OVERRIDE { + NOTREACHED(); + return GL_TEXTURE_2D; + } virtual ResourceFormat GetResourceFormat() const OVERRIDE { NOTREACHED(); return RGBA_8888; diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc index f64419e..255f41c 100644 --- a/cc/resources/raster_worker_pool_unittest.cc +++ b/cc/resources/raster_worker_pool_unittest.cc @@ -104,7 +104,7 @@ class RasterWorkerPoolTest : public testing::Test, void RunTest(bool use_map_image) { if (use_map_image) { raster_worker_pool_ = ImageRasterWorkerPool::Create( - resource_provider(), 1); + resource_provider(), 1, GL_TEXTURE_2D); } else { raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc index 5281023..254837f 100644 --- a/cc/resources/resource_pool.cc +++ b/cc/resources/resource_pool.cc @@ -10,9 +10,11 @@ namespace cc { ResourcePool::Resource::Resource(cc::ResourceProvider* resource_provider, gfx::Size size, + GLenum target, ResourceFormat format) : cc::Resource(resource_provider->CreateManagedResource( size, + target, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format), @@ -28,8 +30,12 @@ ResourcePool::Resource::~Resource() { resource_provider_->DeleteResource(id()); } -ResourcePool::ResourcePool(ResourceProvider* resource_provider) +ResourcePool::ResourcePool(ResourceProvider* resource_provider, + GLenum target, + ResourceFormat format) : resource_provider_(resource_provider), + target_(target), + format_(format), max_memory_usage_bytes_(0), max_unused_memory_usage_bytes_(0), max_resource_count_(0), @@ -52,7 +58,7 @@ ResourcePool::~ResourcePool() { } scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( - gfx::Size size, ResourceFormat format) { + gfx::Size size) { for (ResourceList::iterator it = unused_resources_.begin(); it != unused_resources_.end(); ++it) { Resource* resource = *it; @@ -60,8 +66,6 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( if (resource->size() != size) continue; - if (resource->format() != format) - continue; unused_resources_.erase(it); unused_memory_usage_bytes_ -= resource->bytes(); @@ -69,7 +73,8 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( } // Create new resource. - Resource* resource = new Resource(resource_provider_, size, format); + Resource* resource = new Resource( + resource_provider_, size, target_, format_); // Extend all read locks on all resources until the resource is // finished being used, such that we know when resources are diff --git a/cc/resources/resource_pool.h b/cc/resources/resource_pool.h index de63d97..74175ed 100644 --- a/cc/resources/resource_pool.h +++ b/cc/resources/resource_pool.h @@ -21,6 +21,7 @@ class CC_EXPORT ResourcePool { public: Resource(ResourceProvider* resource_provider, gfx::Size size, + GLenum target, ResourceFormat format); ~Resource(); @@ -30,14 +31,17 @@ class CC_EXPORT ResourcePool { DISALLOW_COPY_AND_ASSIGN(Resource); }; - static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider) { - return make_scoped_ptr(new ResourcePool(resource_provider)); + static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider, + GLenum target, + ResourceFormat format) { + return make_scoped_ptr(new ResourcePool(resource_provider, + target, + format)); } virtual ~ResourcePool(); - scoped_ptr<ResourcePool::Resource> AcquireResource( - gfx::Size size, ResourceFormat format); + scoped_ptr<ResourcePool::Resource> AcquireResource(gfx::Size size); void ReleaseResource(scoped_ptr<ResourcePool::Resource>); void SetResourceUsageLimits(size_t max_memory_usage_bytes, @@ -58,7 +62,9 @@ class CC_EXPORT ResourcePool { } protected: - explicit ResourcePool(ResourceProvider* resource_provider); + ResourcePool(ResourceProvider* resource_provider, + GLenum target, + ResourceFormat format); bool ResourceUsageTooHigh(); @@ -66,6 +72,8 @@ class CC_EXPORT ResourcePool { void DidFinishUsingResource(ResourcePool::Resource* resource); ResourceProvider* resource_provider_; + const GLenum target_; + const ResourceFormat format_; size_t max_memory_usage_bytes_; size_t max_unused_memory_usage_bytes_; size_t max_resource_count_; diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index c0d56ef..6696840 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -339,8 +339,12 @@ ResourceProvider::ResourceId ResourceProvider::CreateResource( DCHECK(!size.IsEmpty()); switch (default_resource_type_) { case GLTexture: - return CreateGLTexture( - size, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, wrap_mode, hint, format); + return CreateGLTexture(size, + GL_TEXTURE_2D, + GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, + wrap_mode, + hint, + format); case Bitmap: DCHECK_EQ(RGBA_8888, format); return CreateBitmap(size, wrap_mode); @@ -354,14 +358,19 @@ ResourceProvider::ResourceId ResourceProvider::CreateResource( ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( gfx::Size size, + GLenum target, GLint wrap_mode, TextureUsageHint hint, ResourceFormat format) { DCHECK(!size.IsEmpty()); switch (default_resource_type_) { case GLTexture: - return CreateGLTexture( - size, GL_TEXTURE_POOL_MANAGED_CHROMIUM, wrap_mode, hint, format); + return CreateGLTexture(size, + target, + GL_TEXTURE_POOL_MANAGED_CHROMIUM, + wrap_mode, + hint, + format); case Bitmap: DCHECK_EQ(RGBA_8888, format); return CreateBitmap(size, wrap_mode); @@ -375,6 +384,7 @@ ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( gfx::Size size, + GLenum target, GLenum texture_pool, GLint wrap_mode, TextureUsageHint hint, @@ -385,7 +395,7 @@ ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( ResourceId id = next_id_++; Resource resource( - 0, size, GL_TEXTURE_2D, GL_LINEAR, texture_pool, wrap_mode, hint, format); + 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); resource.allocated = false; resources_[id] = resource; return id; @@ -789,24 +799,20 @@ ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( ResourceProvider* resource_provider, ResourceProvider::ResourceId resource_id, - GLenum target, GLenum filter) : ScopedReadLockGL(resource_provider, resource_id), - target_(target), - unit_(GL_TEXTURE0) { - resource_provider->BindForSampling(resource_id, target, unit_, filter); + unit_(GL_TEXTURE0), + target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { } ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( ResourceProvider* resource_provider, ResourceProvider::ResourceId resource_id, - GLenum target, GLenum unit, GLenum filter) : ScopedReadLockGL(resource_provider, resource_id), - target_(target), - unit_(unit) { - resource_provider->BindForSampling(resource_id, target, unit, filter); + unit_(unit), + target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { } ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { @@ -1487,10 +1493,10 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) { } } -void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, - GLenum target, - GLenum unit, - GLenum filter) { +GLenum ResourceProvider::BindForSampling( + ResourceProvider::ResourceId resource_id, + GLenum unit, + GLenum filter) { DCHECK(thread_checker_.CalledOnValidThread()); WebGraphicsContext3D* context3d = Context3d(); ResourceMap::iterator it = resources_.find(resource_id); @@ -1500,9 +1506,9 @@ void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); ScopedSetActiveTexture scoped_active_tex(context3d, unit); + GLenum target = resource->target; GLC(context3d, context3d->bindTexture(target, resource->gl_id)); if (filter != resource->filter) { - DCHECK_EQ(resource->target, target); GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); GLC(context3d, @@ -1518,6 +1524,8 @@ void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, resource->bound_image_id = resource->image_id; resource->dirty_image = false; } + + return target; } void ResourceProvider::BeginSetPixels(ResourceId id) { diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h index fccb70c..6cd4270 100644 --- a/cc/resources/resource_provider.h +++ b/cc/resources/resource_provider.h @@ -101,12 +101,14 @@ class CC_EXPORT ResourceProvider { // Creates a resource which is tagged as being managed for GPU memory // accounting purposes. ResourceId CreateManagedResource(gfx::Size size, + GLenum target, GLint wrap_mode, TextureUsageHint hint, ResourceFormat format); // You can also explicitly create a specific resource type. ResourceId CreateGLTexture(gfx::Size size, + GLenum target, GLenum texture_pool, GLint wrap_mode, TextureUsageHint hint, @@ -221,18 +223,18 @@ class CC_EXPORT ResourceProvider { public: ScopedSamplerGL(ResourceProvider* resource_provider, ResourceProvider::ResourceId resource_id, - GLenum target, GLenum filter); ScopedSamplerGL(ResourceProvider* resource_provider, ResourceProvider::ResourceId resource_id, - GLenum target, GLenum unit, GLenum filter); virtual ~ScopedSamplerGL(); + GLenum target() const { return target_; } + private: - GLenum target_; GLenum unit_; + GLenum target_; DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); }; @@ -465,12 +467,11 @@ class CC_EXPORT ResourceProvider { void LazyAllocate(Resource* resource); // Binds the given GL resource to a texture target for sampling using the - // specified filter for both minification and magnification. The resource - // must be locked for reading. - void BindForSampling(ResourceProvider::ResourceId resource_id, - GLenum target, - GLenum unit, - GLenum filter); + // specified filter for both minification and magnification. Returns the + // texture target used. The resource must be locked for reading. + GLenum BindForSampling(ResourceProvider::ResourceId resource_id, + GLenum unit, + GLenum filter); // Returns NULL if the output_surface_ does not have a ContextProvider. blink::WebGraphicsContext3D* Context3d() const; diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index 5bf9fc9..a34aee6 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -2132,7 +2132,11 @@ TEST_P(ResourceProviderTest, ManagedResource) { // Check that the texture gets created with the right sampler settings. ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( - size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); + size, + GL_TEXTURE_2D, + GL_CLAMP_TO_EDGE, + ResourceProvider::TextureUsageAny, + format); EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); @@ -2180,6 +2184,7 @@ TEST_P(ResourceProviderTest, TextureWrapMode) { // Check that the texture gets created with the right sampler settings. ResourceProvider::ResourceId id = resource_provider->CreateGLTexture(size, + GL_TEXTURE_2D, texture_pool, wrap_mode, ResourceProvider::TextureUsageAny, diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc index 84842fe..b443516 100644 --- a/cc/resources/tile_manager.cc +++ b/cc/resources/tile_manager.cc @@ -172,13 +172,16 @@ scoped_ptr<TileManager> TileManager::Create( RenderingStatsInstrumentation* rendering_stats_instrumentation, bool use_map_image, size_t max_transfer_buffer_usage_bytes, - size_t max_raster_usage_bytes) { + size_t max_raster_usage_bytes, + GLenum map_image_texture_target) { return make_scoped_ptr( new TileManager(client, resource_provider, use_map_image ? ImageRasterWorkerPool::Create( - resource_provider, num_raster_threads) : + resource_provider, + num_raster_threads, + map_image_texture_target) : PixelBufferRasterWorkerPool::Create( resource_provider, num_raster_threads, @@ -196,7 +199,10 @@ TileManager::TileManager( size_t max_raster_usage_bytes, RenderingStatsInstrumentation* rendering_stats_instrumentation) : client_(client), - resource_pool_(ResourcePool::Create(resource_provider)), + resource_pool_(ResourcePool::Create( + resource_provider, + raster_worker_pool->GetResourceTarget(), + raster_worker_pool->GetResourceFormat())), raster_worker_pool_(raster_worker_pool.Pass()), prioritized_tiles_dirty_(false), all_tiles_that_need_to_be_rasterized_have_memory_(true), @@ -844,9 +850,7 @@ RasterWorkerPool::RasterTask TileManager::CreateRasterTask(Tile* tile) { ManagedTileState& mts = tile->managed_state(); scoped_ptr<ResourcePool::Resource> resource = - resource_pool_->AcquireResource( - tile->tile_size_.size(), - raster_worker_pool_->GetResourceFormat()); + resource_pool_->AcquireResource(tile->tile_size_.size()); const Resource* const_resource = resource.get(); // Create and queue all image decode tasks that this tile depends on. diff --git a/cc/resources/tile_manager.h b/cc/resources/tile_manager.h index ce9b280..0aa89d7 100644 --- a/cc/resources/tile_manager.h +++ b/cc/resources/tile_manager.h @@ -56,7 +56,8 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, RenderingStatsInstrumentation* rendering_stats_instrumentation, bool use_map_image, size_t max_transfer_buffer_usage_bytes, - size_t max_raster_usage_bytes); + size_t max_raster_usage_bytes, + GLenum map_image_texture_target); virtual ~TileManager(); void ManageTiles(const GlobalStateThatImpactsTilePriority& state); @@ -93,7 +94,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, mts.tile_versions[HIGH_QUALITY_NO_LCD_RASTER_MODE]; tile_version.resource_ = resource_pool_->AcquireResource( - gfx::Size(1, 1), resource_provider->best_texture_format()); + gfx::Size(1, 1)); bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); ++resources_releasable_; diff --git a/cc/test/fake_tile_manager.cc b/cc/test/fake_tile_manager.cc index 0ca699f..6523060 100644 --- a/cc/test/fake_tile_manager.cc +++ b/cc/test/fake_tile_manager.cc @@ -33,6 +33,9 @@ class FakeRasterWorkerPool : public RasterWorkerPool { completed_tasks_.pop_front(); } } + virtual GLenum GetResourceTarget() const OVERRIDE { + return GL_TEXTURE_2D; + } virtual ResourceFormat GetResourceFormat() const OVERRIDE { return RGBA_8888; } diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 6f267cc..9485c72 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -56,6 +56,7 @@ #include "cc/trees/quad_culler.h" #include "cc/trees/single_thread_proxy.h" #include "cc/trees/tree_synchronizer.h" +#include "gpu/GLES2/gl2extchromium.h" #include "ui/gfx/frame_time.h" #include "ui/gfx/size_conversions.h" #include "ui/gfx/vector2d_conversions.h" @@ -103,6 +104,22 @@ size_t GetMaxRasterTasksUsageBytes(cc::ContextProvider* context_provider) { return GetMaxTransferBufferUsageBytes(context_provider); } +GLenum GetMapImageTextureTarget(cc::ContextProvider* context_provider) { + if (!context_provider) + return GL_TEXTURE_2D; + + // TODO(reveman): Determine if GL_TEXTURE_EXTERNAL_OES works well on + // Android before we enable this. crbug.com/322780 +#if !defined(OS_ANDROID) + if (context_provider->ContextCapabilities().egl_image_external) + return GL_TEXTURE_EXTERNAL_OES; + if (context_provider->ContextCapabilities().texture_rectangle) + return GL_TEXTURE_RECTANGLE_ARB; +#endif + + return GL_TEXTURE_2D; +} + } // namespace namespace cc { @@ -1660,7 +1677,8 @@ void LayerTreeHostImpl::CreateAndSetTileManager( rendering_stats_instrumentation_, using_map_image, GetMaxTransferBufferUsageBytes(context_provider), - GetMaxRasterTasksUsageBytes(context_provider)); + GetMaxRasterTasksUsageBytes(context_provider), + GetMapImageTextureTarget(context_provider)); UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); need_to_update_visible_tiles_before_draw_ = false; |