Commit 31bb95c1 authored by penghuang's avatar penghuang Committed by Commit bot

cc: Render TextureLayer which texture target is not GL_TEXTURE_2D correctly.

BUG=483203

Review URL: https://codereview.chromium.org/1124203006

Cr-Commit-Position: refs/heads/master@{#329403}
parent 6a4a569b
...@@ -2160,7 +2160,7 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { ...@@ -2160,7 +2160,7 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
draw_cache_.resource_id, draw_cache_.resource_id,
draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR); draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR);
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id()); gl_->BindTexture(locked_quad.target(), locked_quad.texture_id());
static_assert(sizeof(Float4) == 4 * sizeof(float), static_assert(sizeof(Float4) == 4 * sizeof(float),
"Float4 struct should be densely packed"); "Float4 struct should be densely packed");
...@@ -2222,20 +2222,24 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, ...@@ -2222,20 +2222,24 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
highp_threshold_min_, highp_threshold_min_,
quad->shared_quad_state->visible_content_rect.bottom_right()); quad->shared_quad_state->visible_content_rect.bottom_right());
ResourceProvider::ScopedReadLockGL lock(resource_provider_,
quad->resource_id);
const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
// Choose the correct texture program binding // Choose the correct texture program binding
TexTransformTextureProgramBinding binding; TexTransformTextureProgramBinding binding;
if (quad->premultiplied_alpha) { if (quad->premultiplied_alpha) {
if (quad->background_color == SK_ColorTRANSPARENT) { if (quad->background_color == SK_ColorTRANSPARENT) {
binding.Set(GetTextureProgram(tex_coord_precision)); binding.Set(GetTextureProgram(tex_coord_precision, sampler));
} else { } else {
binding.Set(GetTextureBackgroundProgram(tex_coord_precision)); binding.Set(GetTextureBackgroundProgram(tex_coord_precision, sampler));
} }
} else { } else {
if (quad->background_color == SK_ColorTRANSPARENT) { if (quad->background_color == SK_ColorTRANSPARENT) {
binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision));
} else {
binding.Set( binding.Set(
GetNonPremultipliedTextureBackgroundProgram(tex_coord_precision)); GetNonPremultipliedTextureProgram(tex_coord_precision, sampler));
} else {
binding.Set(GetNonPremultipliedTextureBackgroundProgram(
tex_coord_precision, sampler));
} }
} }
...@@ -3197,58 +3201,71 @@ const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( ...@@ -3197,58 +3201,71 @@ const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA(
} }
const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram(
TexCoordPrecision precision) { TexCoordPrecision precision,
SamplerType sampler) {
DCHECK_GE(precision, 0); DCHECK_GE(precision, 0);
DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
TextureProgram* program = &texture_program_[precision]; DCHECK_GE(sampler, 0);
DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
TextureProgram* program = &texture_program_[precision][sampler];
if (!program->initialized()) { if (!program->initialized()) {
TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize");
program->Initialize(output_surface_->context_provider(), precision, program->Initialize(output_surface_->context_provider(), precision,
SAMPLER_TYPE_2D); sampler);
} }
return program; return program;
} }
const GLRenderer::NonPremultipliedTextureProgram* const GLRenderer::NonPremultipliedTextureProgram*
GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision) { GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision,
SamplerType sampler) {
DCHECK_GE(precision, 0); DCHECK_GE(precision, 0);
DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
DCHECK_GE(sampler, 0);
DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
NonPremultipliedTextureProgram* program = NonPremultipliedTextureProgram* program =
&nonpremultiplied_texture_program_[precision]; &nonpremultiplied_texture_program_[precision][sampler];
if (!program->initialized()) { if (!program->initialized()) {
TRACE_EVENT0("cc", TRACE_EVENT0("cc",
"GLRenderer::NonPremultipliedTextureProgram::Initialize"); "GLRenderer::NonPremultipliedTextureProgram::Initialize");
program->Initialize(output_surface_->context_provider(), precision, program->Initialize(output_surface_->context_provider(), precision,
SAMPLER_TYPE_2D); sampler);
} }
return program; return program;
} }
const GLRenderer::TextureBackgroundProgram* const GLRenderer::TextureBackgroundProgram*
GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision) { GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision,
SamplerType sampler) {
DCHECK_GE(precision, 0); DCHECK_GE(precision, 0);
DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
TextureBackgroundProgram* program = &texture_background_program_[precision]; DCHECK_GE(sampler, 0);
DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
TextureBackgroundProgram* program =
&texture_background_program_[precision][sampler];
if (!program->initialized()) { if (!program->initialized()) {
TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize");
program->Initialize(output_surface_->context_provider(), precision, program->Initialize(output_surface_->context_provider(), precision,
SAMPLER_TYPE_2D); sampler);
} }
return program; return program;
} }
const GLRenderer::NonPremultipliedTextureBackgroundProgram* const GLRenderer::NonPremultipliedTextureBackgroundProgram*
GLRenderer::GetNonPremultipliedTextureBackgroundProgram( GLRenderer::GetNonPremultipliedTextureBackgroundProgram(
TexCoordPrecision precision) { TexCoordPrecision precision,
SamplerType sampler) {
DCHECK_GE(precision, 0); DCHECK_GE(precision, 0);
DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
DCHECK_GE(sampler, 0);
DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
NonPremultipliedTextureBackgroundProgram* program = NonPremultipliedTextureBackgroundProgram* program =
&nonpremultiplied_texture_background_program_[precision]; &nonpremultiplied_texture_background_program_[precision][sampler];
if (!program->initialized()) { if (!program->initialized()) {
TRACE_EVENT0("cc", TRACE_EVENT0("cc",
"GLRenderer::NonPremultipliedTextureProgram::Initialize"); "GLRenderer::NonPremultipliedTextureProgram::Initialize");
program->Initialize(output_surface_->context_provider(), precision, program->Initialize(output_surface_->context_provider(), precision,
SAMPLER_TYPE_2D); sampler);
} }
return program; return program;
} }
...@@ -3336,10 +3353,12 @@ void GLRenderer::CleanupSharedObjects() { ...@@ -3336,10 +3353,12 @@ void GLRenderer::CleanupSharedObjects() {
render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_);
} }
texture_program_[i].Cleanup(gl_); for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) {
nonpremultiplied_texture_program_[i].Cleanup(gl_); texture_program_[i][j].Cleanup(gl_);
texture_background_program_[i].Cleanup(gl_); nonpremultiplied_texture_program_[i][j].Cleanup(gl_);
nonpremultiplied_texture_background_program_[i].Cleanup(gl_); texture_background_program_[i][j].Cleanup(gl_);
nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_);
}
texture_io_surface_program_[i].Cleanup(gl_); texture_io_surface_program_[i].Cleanup(gl_);
video_yuv_program_[i].Cleanup(gl_); video_yuv_program_[i].Cleanup(gl_);
......
...@@ -387,14 +387,17 @@ class CC_EXPORT GLRenderer : public DirectRenderer { ...@@ -387,14 +387,17 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
BlendMode blend_mode, BlendMode blend_mode,
bool mask_for_background); bool mask_for_background);
const TextureProgram* GetTextureProgram( const TextureProgram* GetTextureProgram(TexCoordPrecision precision,
TexCoordPrecision precision); SamplerType sampler);
const NonPremultipliedTextureProgram* GetNonPremultipliedTextureProgram( const NonPremultipliedTextureProgram* GetNonPremultipliedTextureProgram(
TexCoordPrecision precision); TexCoordPrecision precision,
SamplerType sampler);
const TextureBackgroundProgram* GetTextureBackgroundProgram( const TextureBackgroundProgram* GetTextureBackgroundProgram(
TexCoordPrecision precision); TexCoordPrecision precision,
SamplerType sampler);
const NonPremultipliedTextureBackgroundProgram* const NonPremultipliedTextureBackgroundProgram*
GetNonPremultipliedTextureBackgroundProgram(TexCoordPrecision precision); GetNonPremultipliedTextureBackgroundProgram(TexCoordPrecision precision,
SamplerType sampler);
const TextureProgram* GetTextureIOSurfaceProgram( const TextureProgram* GetTextureIOSurfaceProgram(
TexCoordPrecision precision); TexCoordPrecision precision);
...@@ -425,14 +428,17 @@ class CC_EXPORT GLRenderer : public DirectRenderer { ...@@ -425,14 +428,17 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
TileCheckerboardProgram tile_checkerboard_program_; TileCheckerboardProgram tile_checkerboard_program_;
TextureProgram texture_program_[LAST_TEX_COORD_PRECISION + 1]; TextureProgram
texture_program_[LAST_TEX_COORD_PRECISION + 1][LAST_SAMPLER_TYPE + 1];
NonPremultipliedTextureProgram NonPremultipliedTextureProgram
nonpremultiplied_texture_program_[LAST_TEX_COORD_PRECISION + 1]; nonpremultiplied_texture_program_[LAST_TEX_COORD_PRECISION +
1][LAST_SAMPLER_TYPE + 1];
TextureBackgroundProgram TextureBackgroundProgram
texture_background_program_[LAST_TEX_COORD_PRECISION + 1]; texture_background_program_[LAST_TEX_COORD_PRECISION +
1][LAST_SAMPLER_TYPE + 1];
NonPremultipliedTextureBackgroundProgram NonPremultipliedTextureBackgroundProgram
nonpremultiplied_texture_background_program_[LAST_TEX_COORD_PRECISION + nonpremultiplied_texture_background_program_[LAST_TEX_COORD_PRECISION +
1]; 1][LAST_SAMPLER_TYPE + 1];
TextureProgram texture_io_surface_program_[LAST_TEX_COORD_PRECISION + 1]; TextureProgram texture_io_surface_program_[LAST_TEX_COORD_PRECISION + 1];
RenderPassProgram RenderPassProgram
......
...@@ -123,12 +123,6 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { ...@@ -123,12 +123,6 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest {
} }
void TestShadersWithPrecision(TexCoordPrecision precision) { void TestShadersWithPrecision(TexCoordPrecision precision) {
EXPECT_PROGRAM_VALID(renderer()->GetTextureProgram(precision));
EXPECT_PROGRAM_VALID(
renderer()->GetNonPremultipliedTextureProgram(precision));
EXPECT_PROGRAM_VALID(renderer()->GetTextureBackgroundProgram(precision));
EXPECT_PROGRAM_VALID(
renderer()->GetNonPremultipliedTextureBackgroundProgram(precision));
EXPECT_PROGRAM_VALID(renderer()->GetTextureIOSurfaceProgram(precision)); EXPECT_PROGRAM_VALID(renderer()->GetTextureIOSurfaceProgram(precision));
EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision)); EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision));
EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision)); EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision));
...@@ -154,6 +148,15 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest { ...@@ -154,6 +148,15 @@ class GLRendererShaderPixelTest : public GLRendererPixelTest {
return; return;
} }
EXPECT_PROGRAM_VALID(renderer()->GetTextureProgram(precision, sampler));
EXPECT_PROGRAM_VALID(
renderer()->GetNonPremultipliedTextureProgram(precision, sampler));
EXPECT_PROGRAM_VALID(
renderer()->GetTextureBackgroundProgram(precision, sampler));
EXPECT_PROGRAM_VALID(
renderer()->GetNonPremultipliedTextureBackgroundProgram(precision,
sampler));
EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision, sampler)); EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision, sampler));
EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision, sampler)); EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision, sampler));
EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision, sampler)); EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision, sampler));
......
...@@ -966,8 +966,8 @@ ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( ...@@ -966,8 +966,8 @@ ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(
ResourceProvider::ResourceId resource_id) ResourceProvider::ResourceId resource_id)
: resource_provider_(resource_provider), : resource_provider_(resource_provider),
resource_id_(resource_id), resource_id_(resource_id),
texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { resource_(resource_provider->LockForRead(resource_id)) {
DCHECK(texture_id_); DCHECK(resource_);
} }
ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() {
......
...@@ -223,14 +223,15 @@ class CC_EXPORT ResourceProvider { ...@@ -223,14 +223,15 @@ class CC_EXPORT ResourceProvider {
ResourceProvider::ResourceId resource_id); ResourceProvider::ResourceId resource_id);
virtual ~ScopedReadLockGL(); virtual ~ScopedReadLockGL();
unsigned texture_id() const { return texture_id_; } unsigned texture_id() const { return resource_->gl_id; }
GLenum target() const { return resource_->target; }
protected: protected:
ResourceProvider* resource_provider_; ResourceProvider* resource_provider_;
ResourceProvider::ResourceId resource_id_; ResourceProvider::ResourceId resource_id_;
private: private:
unsigned texture_id_; const ResourceProvider::Resource* resource_;
DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment