Chromium Code Reviews| Index: cc/output/gl_renderer.cc |
| diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc |
| index 13e6d8a5efa8936e78d519cf52f1a2e893341f26..844050e2f15a8c6ff9975f09fbd680d8d3aeab00 100644 |
| --- a/cc/output/gl_renderer.cc |
| +++ b/cc/output/gl_renderer.cc |
| @@ -79,6 +79,22 @@ bool NeedsIOSurfaceReadbackWorkaround() { |
| #endif |
| } |
| +// These values are magic numbers that are used in the transformation from YUV to RGB color values. |
|
danakj
2013/04/04 15:01:55
nit: 80 columns
upload should complain about this
vignesh
2013/04/04 22:06:14
Done.
|
| +// They are taken from the following webpage: http://www.fourcc.org/fccyvrgb.php |
| +float yuv_to_rgb[9] = { |
| + 1.164f, 1.164f, 1.164f, |
| + 0.f, -.391f, 2.018f, |
| + 1.596f, -.813f, 0.f, |
| +}; |
| + |
| +// These values map to 16, 128, and 128 respectively, and are computed |
| +// as a fraction over 256 (e.g. 16 / 256 = 0.0625). |
| +// They are used in the YUV to RGBA conversion formula: |
| +// Y - 16 : Gives 16 values of head and footroom for overshooting |
| +// U - 128 : Turns unsigned U into signed U [-128,127] |
| +// V - 128 : Turns unsigned V into signed V [-128,127] |
| +float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; |
| + |
| } // anonymous namespace |
| scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client, |
| @@ -1199,12 +1215,10 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| const YUVVideoDrawQuad* quad) { |
| SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| - const VideoYUVProgram* program = GetVideoYUVProgram(); |
| - DCHECK(program && (program->initialized() || IsContextLost())); |
| - |
| const VideoLayerImpl::FramePlane& y_plane = quad->y_plane; |
| const VideoLayerImpl::FramePlane& u_plane = quad->u_plane; |
| const VideoLayerImpl::FramePlane& v_plane = quad->v_plane; |
| + const VideoLayerImpl::FramePlane& a_plane = quad->a_plane; |
| GLC(Context(), Context()->activeTexture(GL_TEXTURE1)); |
| ResourceProvider::ScopedSamplerGL y_plane_lock( |
| @@ -1215,49 +1229,64 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| GLC(Context(), Context()->activeTexture(GL_TEXTURE3)); |
| ResourceProvider::ScopedSamplerGL v_plane_lock( |
| resource_provider_, v_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| + if (a_plane.resource_id) { |
|
danakj
2013/04/04 15:01:55
how about "bool use_alpha_plane = a_plane.resource
vignesh
2013/04/04 22:06:14
Done.
|
| + ResourceProvider::ScopedSamplerGL a_plane_lock( |
|
danakj
2013/04/04 15:01:55
this seems like it works at the moment, but its na
vignesh
2013/04/04 22:06:14
Done.
|
| + resource_provider_, a_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR); |
| + } |
| - SetUseProgram(program->program()); |
| + int tex_scale_location; |
| + int matrix_location; |
| + int y_texture_location; |
| + int u_texture_location; |
| + int v_texture_location; |
| + int a_texture_location; |
| + int yuv_matrix_location; |
|
danakj
2013/04/04 15:01:55
nothing seems to set this.
can you initialize all
vignesh
2013/04/04 22:06:14
Done.
|
| + int yuv_adj_location; |
| + int alpha_location; |
| + if (!a_plane.resource_id) { |
| + const VideoYUVProgram* program = GetVideoYUVProgram(); |
| + DCHECK(program && (program->initialized() || IsContextLost())); |
| + SetUseProgram(program->program()); |
| + tex_scale_location = program->vertex_shader().tex_scale_location(); |
| + matrix_location = program->vertex_shader().matrix_location(); |
| + y_texture_location = program->fragment_shader().y_texture_location(); |
| + u_texture_location = program->fragment_shader().u_texture_location(); |
| + v_texture_location = program->fragment_shader().v_texture_location(); |
| + a_texture_location = program->fragment_shader().yuv_matrix_location(); |
|
danakj
2013/04/04 15:01:55
why is this yuv_matrix_location and not just -1?
vignesh
2013/04/04 22:06:14
Done.
|
| + yuv_adj_location = program->fragment_shader().yuv_adj_location(); |
| + alpha_location = program->fragment_shader().alpha_location(); |
| + } else { |
| + const VideoYUVAProgram* program = GetVideoYUVAProgram(); |
| + DCHECK(program && (program->initialized() || IsContextLost())); |
| + SetUseProgram(program->program()); |
| + tex_scale_location = program->vertex_shader().tex_scale_location(); |
| + matrix_location = program->vertex_shader().matrix_location(); |
| + y_texture_location = program->fragment_shader().y_texture_location(); |
| + u_texture_location = program->fragment_shader().u_texture_location(); |
| + v_texture_location = program->fragment_shader().v_texture_location(); |
| + a_texture_location = program->fragment_shader().yuv_matrix_location(); |
|
danakj
2013/04/04 15:01:55
why is this yuv_matrix_location and not a_texture_
vignesh
2013/04/04 22:06:14
Done.
|
| + yuv_adj_location = program->fragment_shader().yuv_adj_location(); |
| + alpha_location = program->fragment_shader().alpha_location(); |
| + } |
| GLC(Context(), |
| - Context()->uniform2f(program->vertex_shader().tex_scale_location(), |
| + Context()->uniform2f(tex_scale_location, |
| quad->tex_scale.width(), |
| quad->tex_scale.height())); |
| + GLC(Context(), Context()->uniform1i(y_texture_location, 1)); |
| + GLC(Context(), Context()->uniform1i(u_texture_location, 2)); |
| + GLC(Context(), Context()->uniform1i(v_texture_location, 3)); |
| + if (a_plane.resource_id) { |
| + GLC(Context(), Context()->uniform1i(a_texture_location, 4)); |
| + } |
| + |
| GLC(Context(), |
| - Context()->uniform1i(program->fragment_shader().y_texture_location(), 1)); |
| - GLC(Context(), |
| - Context()->uniform1i(program->fragment_shader().u_texture_location(), 2)); |
| - GLC(Context(), |
| - Context()->uniform1i(program->fragment_shader().v_texture_location(), 3)); |
| - |
| - // These values are magic numbers that are used in the transformation from YUV |
| - // to RGB color values. They are taken from the following webpage: |
| - // http://www.fourcc.org/fccyvrgb.php |
| - float yuv_to_rgb[9] = { |
| - 1.164f, 1.164f, 1.164f, |
| - 0.0f, -.391f, 2.018f, |
| - 1.596f, -.813f, 0.0f, |
| - }; |
| - GLC(Context(), |
| - Context()->uniformMatrix3fv( |
| - program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb)); |
| - |
| - // These values map to 16, 128, and 128 respectively, and are computed |
| - // as a fraction over 256 (e.g. 16 / 256 = 0.0625). |
| - // They are used in the YUV to RGBA conversion formula: |
| - // Y - 16 : Gives 16 values of head and footroom for overshooting |
| - // U - 128 : Turns unsigned U into signed U [-128,127] |
| - // V - 128 : Turns unsigned V into signed V [-128,127] |
| - float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; |
| - GLC(Context(), |
| - Context()->uniform3fv( |
| - program->fragment_shader().yuv_adj_location(), 1, yuv_adjust)); |
| + Context()->uniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); |
| + GLC(Context(), Context()->uniform3fv(yuv_adj_location, 1, yuv_adjust)); |
| - SetShaderOpacity(quad->opacity(), |
| - program->fragment_shader().alpha_location()); |
| - DrawQuadGeometry(frame, |
| - quad->quadTransform(), |
| - quad->rect, |
| - program->vertex_shader().matrix_location()); |
| + |
| + SetShaderOpacity(quad->opacity(), alpha_location); |
| + DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); |
| // Reset active texture back to texture 0. |
| GLC(Context(), Context()->activeTexture(GL_TEXTURE0)); |
| @@ -2209,6 +2238,16 @@ const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram() { |
| return video_yuv_program_.get(); |
| } |
| +const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram() { |
| + if (!video_yuva_program_) |
| + video_yuva_program_ = make_scoped_ptr(new VideoYUVAProgram(context_)); |
| + if (!video_yuva_program_->initialized()) { |
| + TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); |
| + video_yuva_program_->Initialize(context_, is_using_bind_uniform_); |
| + } |
| + return video_yuva_program_.get(); |
| +} |
| + |
| const GLRenderer::VideoStreamTextureProgram* |
| GLRenderer::GetVideoStreamTextureProgram() { |
| if (!Capabilities().using_egl_image) |
| @@ -2261,6 +2300,8 @@ void GLRenderer::CleanupSharedObjects() { |
| if (video_yuv_program_) |
| video_yuv_program_->Cleanup(context_); |
| + if (video_yuva_program_) |
| + video_yuva_program_->Cleanup(context_); |
| if (video_stream_texture_program_) |
| video_stream_texture_program_->Cleanup(context_); |