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

Side by Side 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 and calming down the try bots Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } 1379 }
1380 1380
1381 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, 1381 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
1382 const YUVVideoDrawQuad* quad) { 1382 const YUVVideoDrawQuad* quad) {
1383 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1383 SetBlendEnabled(quad->ShouldDrawWithBlending());
1384 1384
1385 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1385 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1386 context_, &highp_threshold_cache_, highp_threshold_min_, 1386 context_, &highp_threshold_cache_, highp_threshold_min_,
1387 quad->shared_quad_state->visible_content_rect.bottom_right()); 1387 quad->shared_quad_state->visible_content_rect.bottom_right());
1388 1388
1389 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision); 1389 bool use_alpha_plane = quad->a_plane_resource_id != 0;
1390 DCHECK(program && (program->initialized() || IsContextLost()));
1391 1390
1392 GLC(Context(), Context()->activeTexture(GL_TEXTURE1)); 1391 GLC(Context(), Context()->activeTexture(GL_TEXTURE1));
1393 ResourceProvider::ScopedSamplerGL y_plane_lock( 1392 ResourceProvider::ScopedSamplerGL y_plane_lock(
1394 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); 1393 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
1395 GLC(Context(), Context()->activeTexture(GL_TEXTURE2)); 1394 GLC(Context(), Context()->activeTexture(GL_TEXTURE2));
1396 ResourceProvider::ScopedSamplerGL u_plane_lock( 1395 ResourceProvider::ScopedSamplerGL u_plane_lock(
1397 resource_provider_, quad->u_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); 1396 resource_provider_, quad->u_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
1398 GLC(Context(), Context()->activeTexture(GL_TEXTURE3)); 1397 GLC(Context(), Context()->activeTexture(GL_TEXTURE3));
1399 ResourceProvider::ScopedSamplerGL v_plane_lock( 1398 ResourceProvider::ScopedSamplerGL v_plane_lock(
1400 resource_provider_, quad->v_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR); 1399 resource_provider_, quad->v_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
1400 scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock;
1401 if (use_alpha_plane) {
1402 GLC(Context(), Context()->activeTexture(GL_TEXTURE4));
1403 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
1404 resource_provider_,
1405 quad->a_plane_resource_id,
1406 GL_TEXTURE_2D,
1407 GL_LINEAR));
1408 }
1401 1409
1402 SetUseProgram(program->program()); 1410 int tex_scale_location = -1;
1411 int matrix_location = -1;
1412 int y_texture_location = -1;
1413 int u_texture_location = -1;
1414 int v_texture_location = -1;
1415 int a_texture_location = -1;
1416 int yuv_matrix_location = -1;
1417 int yuv_adj_location = -1;
1418 int alpha_location = -1;
1419 if (use_alpha_plane) {
1420 const VideoYUVAProgram* program = GetVideoYUVAProgram(tex_coord_precision);
1421 DCHECK(program && (program->initialized() || IsContextLost()));
1422 SetUseProgram(program->program());
1423 tex_scale_location = program->vertex_shader().tex_scale_location();
1424 matrix_location = program->vertex_shader().matrix_location();
1425 y_texture_location = program->fragment_shader().y_texture_location();
1426 u_texture_location = program->fragment_shader().u_texture_location();
1427 v_texture_location = program->fragment_shader().v_texture_location();
1428 a_texture_location = program->fragment_shader().a_texture_location();
1429 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
1430 yuv_adj_location = program->fragment_shader().yuv_adj_location();
1431 alpha_location = program->fragment_shader().alpha_location();
1432 } else {
1433 const VideoYUVProgram* program = GetVideoYUVProgram(tex_coord_precision);
1434 DCHECK(program && (program->initialized() || IsContextLost()));
1435 SetUseProgram(program->program());
1436 tex_scale_location = program->vertex_shader().tex_scale_location();
1437 matrix_location = program->vertex_shader().matrix_location();
1438 y_texture_location = program->fragment_shader().y_texture_location();
1439 u_texture_location = program->fragment_shader().u_texture_location();
1440 v_texture_location = program->fragment_shader().v_texture_location();
1441 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
1442 yuv_adj_location = program->fragment_shader().yuv_adj_location();
1443 alpha_location = program->fragment_shader().alpha_location();
1444 }
1403 1445
1404 GLC(Context(), 1446 GLC(Context(),
1405 Context()->uniform2f(program->vertex_shader().tex_scale_location(), 1447 Context()->uniform2f(tex_scale_location,
1406 quad->tex_scale.width(), 1448 quad->tex_scale.width(),
1407 quad->tex_scale.height())); 1449 quad->tex_scale.height()));
1408 GLC(Context(), 1450 GLC(Context(), Context()->uniform1i(y_texture_location, 1));
1409 Context()->uniform1i(program->fragment_shader().y_texture_location(), 1)); 1451 GLC(Context(), Context()->uniform1i(u_texture_location, 2));
1410 GLC(Context(), 1452 GLC(Context(), Context()->uniform1i(v_texture_location, 3));
1411 Context()->uniform1i(program->fragment_shader().u_texture_location(), 2)); 1453 if (use_alpha_plane)
1412 GLC(Context(), 1454 GLC(Context(), Context()->uniform1i(a_texture_location, 4));
1413 Context()->uniform1i(program->fragment_shader().v_texture_location(), 3));
1414 1455
1415 // These values are magic numbers that are used in the transformation from YUV 1456 // These values are magic numbers that are used in the transformation from YUV
1416 // to RGB color values. They are taken from the following webpage: 1457 // to RGB color values. They are taken from the following webpage:
1417 // http://www.fourcc.org/fccyvrgb.php 1458 // http://www.fourcc.org/fccyvrgb.php
1418 float yuv_to_rgb[9] = { 1459 float yuv_to_rgb[9] = {
1419 1.164f, 1.164f, 1.164f, 1460 1.164f, 1.164f, 1.164f,
1420 0.0f, -.391f, 2.018f, 1461 0.0f, -.391f, 2.018f,
1421 1.596f, -.813f, 0.0f, 1462 1.596f, -.813f, 0.0f,
1422 }; 1463 };
1423 GLC(Context(), 1464 GLC(Context(),
1424 Context()->uniformMatrix3fv( 1465 Context()->uniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb));
1425 program->fragment_shader().yuv_matrix_location(), 1, 0, yuv_to_rgb));
1426 1466
1427 // These values map to 16, 128, and 128 respectively, and are computed 1467 // These values map to 16, 128, and 128 respectively, and are computed
1428 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). 1468 // as a fraction over 256 (e.g. 16 / 256 = 0.0625).
1429 // They are used in the YUV to RGBA conversion formula: 1469 // They are used in the YUV to RGBA conversion formula:
1430 // Y - 16 : Gives 16 values of head and footroom for overshooting 1470 // Y - 16 : Gives 16 values of head and footroom for overshooting
1431 // U - 128 : Turns unsigned U into signed U [-128,127] 1471 // U - 128 : Turns unsigned U into signed U [-128,127]
1432 // V - 128 : Turns unsigned V into signed V [-128,127] 1472 // V - 128 : Turns unsigned V into signed V [-128,127]
1433 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; 1473 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, };
1434 GLC(Context(), 1474 GLC(Context(), Context()->uniform3fv(yuv_adj_location, 1, yuv_adjust));
1435 Context()->uniform3fv(
1436 program->fragment_shader().yuv_adj_location(), 1, yuv_adjust));
1437 1475
1438 SetShaderOpacity(quad->opacity(), 1476
1439 program->fragment_shader().alpha_location()); 1477 SetShaderOpacity(quad->opacity(), alpha_location);
1440 DrawQuadGeometry(frame, 1478 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location);
1441 quad->quadTransform(),
1442 quad->rect,
1443 program->vertex_shader().matrix_location());
1444 1479
1445 // Reset active texture back to texture 0. 1480 // Reset active texture back to texture 0.
1446 GLC(Context(), Context()->activeTexture(GL_TEXTURE0)); 1481 GLC(Context(), Context()->activeTexture(GL_TEXTURE0));
1447 } 1482 }
1448 1483
1449 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, 1484 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
1450 const StreamVideoDrawQuad* quad) { 1485 const StreamVideoDrawQuad* quad) {
1451 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1486 SetBlendEnabled(quad->ShouldDrawWithBlending());
1452 1487
1453 static float gl_matrix[16]; 1488 static float gl_matrix[16];
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 : video_yuv_program_; 2765 : video_yuv_program_;
2731 if (!program) 2766 if (!program)
2732 program = make_scoped_ptr(new VideoYUVProgram(context_, precision)); 2767 program = make_scoped_ptr(new VideoYUVProgram(context_, precision));
2733 if (!program->initialized()) { 2768 if (!program->initialized()) {
2734 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 2769 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
2735 program->Initialize(context_, is_using_bind_uniform_); 2770 program->Initialize(context_, is_using_bind_uniform_);
2736 } 2771 }
2737 return program.get(); 2772 return program.get();
2738 } 2773 }
2739 2774
2775 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram(
2776 TexCoordPrecision precision) {
2777 scoped_ptr<VideoYUVAProgram>& program =
2778 (precision == TexCoordPrecisionHigh) ? video_yuva_program_highp_
2779 : video_yuva_program_;
2780 if (!program)
2781 program = make_scoped_ptr(new VideoYUVAProgram(context_, precision));
2782 if (!program->initialized()) {
2783 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize");
2784 program->Initialize(context_, is_using_bind_uniform_);
2785 }
2786 return program.get();
2787 }
2788
2740 const GLRenderer::VideoStreamTextureProgram* 2789 const GLRenderer::VideoStreamTextureProgram*
2741 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { 2790 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) {
2742 if (!Capabilities().using_egl_image) 2791 if (!Capabilities().using_egl_image)
2743 return NULL; 2792 return NULL;
2744 scoped_ptr<VideoStreamTextureProgram>& program = 2793 scoped_ptr<VideoStreamTextureProgram>& program =
2745 (precision == TexCoordPrecisionHigh) ? video_stream_texture_program_highp_ 2794 (precision == TexCoordPrecisionHigh) ? video_stream_texture_program_highp_
2746 : video_stream_texture_program_; 2795 : video_stream_texture_program_;
2747 if (!program) 2796 if (!program)
2748 program = 2797 program =
2749 make_scoped_ptr(new VideoStreamTextureProgram(context_, precision)); 2798 make_scoped_ptr(new VideoStreamTextureProgram(context_, precision));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 2879
2831 if (texture_program_highp_) 2880 if (texture_program_highp_)
2832 texture_program_highp_->Cleanup(context_); 2881 texture_program_highp_->Cleanup(context_);
2833 if (texture_program_flip_highp_) 2882 if (texture_program_flip_highp_)
2834 texture_program_flip_highp_->Cleanup(context_); 2883 texture_program_flip_highp_->Cleanup(context_);
2835 if (texture_io_surface_program_highp_) 2884 if (texture_io_surface_program_highp_)
2836 texture_io_surface_program_highp_->Cleanup(context_); 2885 texture_io_surface_program_highp_->Cleanup(context_);
2837 2886
2838 if (video_yuv_program_) 2887 if (video_yuv_program_)
2839 video_yuv_program_->Cleanup(context_); 2888 video_yuv_program_->Cleanup(context_);
2889 if (video_yuva_program_)
2890 video_yuva_program_->Cleanup(context_);
2840 if (video_stream_texture_program_) 2891 if (video_stream_texture_program_)
2841 video_stream_texture_program_->Cleanup(context_); 2892 video_stream_texture_program_->Cleanup(context_);
2842 2893
2843 if (video_yuv_program_highp_) 2894 if (video_yuv_program_highp_)
2844 video_yuv_program_highp_->Cleanup(context_); 2895 video_yuv_program_highp_->Cleanup(context_);
2896 if (video_yuva_program_highp_)
2897 video_yuva_program_highp_->Cleanup(context_);
2845 if (video_stream_texture_program_highp_) 2898 if (video_stream_texture_program_highp_)
2846 video_stream_texture_program_highp_->Cleanup(context_); 2899 video_stream_texture_program_highp_->Cleanup(context_);
2847 2900
2848 if (debug_border_program_) 2901 if (debug_border_program_)
2849 debug_border_program_->Cleanup(context_); 2902 debug_border_program_->Cleanup(context_);
2850 if (solid_color_program_) 2903 if (solid_color_program_)
2851 solid_color_program_->Cleanup(context_); 2904 solid_color_program_->Cleanup(context_);
2852 if (solid_color_program_aa_) 2905 if (solid_color_program_aa_)
2853 solid_color_program_aa_->Cleanup(context_); 2906 solid_color_program_aa_->Cleanup(context_);
2854 2907
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas 2957 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas
2905 // implementation. 2958 // implementation.
2906 return gr_context_ && context_->getContextAttributes().stencil; 2959 return gr_context_ && context_->getContextAttributes().stencil;
2907 } 2960 }
2908 2961
2909 bool GLRenderer::IsContextLost() { 2962 bool GLRenderer::IsContextLost() {
2910 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 2963 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
2911 } 2964 }
2912 2965
2913 } // namespace cc 2966 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698