Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: cc/output/gl_renderer.cc

Issue 12157002: Adding YUVA support for enabling Alpha Playback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/output/gl_renderer.cc
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 13e6d8a5efa8936e78d519cf52f1a2e893341f26..9bb248680f3d8f48e9f1230abff51e07743b552d 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.
+// 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,
@@ -326,6 +342,9 @@ void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) {
case DrawQuad::YUV_VIDEO_CONTENT:
DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
break;
+ case DrawQuad::YUVA_VIDEO_CONTENT:
+ DrawYUVAVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
+ break;
}
}
@@ -1229,25 +1248,65 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
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));
+ GLC(Context(),
+ Context()->uniform3fv(program->fragment_shader().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());
+
+ // Reset active texture back to texture 0.
+ GLC(Context(), Context()->activeTexture(GL_TEXTURE0));
+}
+
+void GLRenderer::DrawYUVAVideoQuad(const DrawingFrame* frame,
danakj 2013/03/28 20:59:24 Can you merge this function with DrawYUVVideoQuad?
vignesh 2013/04/02 20:56:15 Which enum value are you referring to ? Also, what
danakj 2013/04/03 00:41:12 Sorry, I am referring to the DrawQuad::Material en
vignesh 2013/04/04 00:37:33 I have eliminated the enum type and included both
+ const YUVVideoDrawQuad* quad)
+{
+ SetBlendEnabled(quad->ShouldDrawWithBlending());
+
+ const VideoYUVAProgram* program = GetVideoYUVAProgram();
+ 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(
+ resource_provider_, y_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
+ GLC(Context(), Context()->activeTexture(GL_TEXTURE2));
+ ResourceProvider::ScopedSamplerGL u_plane_lock(
+ resource_provider_, u_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
+ GLC(Context(), Context()->activeTexture(GL_TEXTURE3));
+ ResourceProvider::ScopedSamplerGL v_plane_lock(
+ resource_provider_, v_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
+ ResourceProvider::ScopedSamplerGL A_plane_lock(
+ resource_provider_, a_plane.resource_id, GL_TEXTURE_2D, GL_LINEAR);
+
+ SetUseProgram(program->program());
+
+ GLC(Context(),
+ Context()->uniform2f(program->vertex_shader().tex_scale_location(),
+ quad->tex_scale.width(),
+ quad->tex_scale.height()));
+ 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));
+ GLC(Context(),
+ Context()->uniform1i(program->fragment_shader().a_texture_location(), 4));
+
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));
@@ -2209,6 +2268,17 @@ 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 +2331,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_);
« cc/output/gl_renderer.h ('K') | « cc/output/gl_renderer.h ('k') | cc/output/shader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698