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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests: cc, skcanvas_video_renderer, wrtcrecorder... Fake capture supports Y16. Created 4 years, 2 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), 610 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad),
611 clip_region); 611 clip_region);
612 break; 612 break;
613 case DrawQuad::TILED_CONTENT: 613 case DrawQuad::TILED_CONTENT:
614 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); 614 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region);
615 break; 615 break;
616 case DrawQuad::YUV_VIDEO_CONTENT: 616 case DrawQuad::YUV_VIDEO_CONTENT:
617 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), 617 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad),
618 clip_region); 618 clip_region);
619 break; 619 break;
620 case DrawQuad::Y_VIDEO_CONTENT:
621 DrawYVideoQuad(frame, YVideoDrawQuad::MaterialCast(quad), clip_region);
622 break;
620 } 623 }
621 } 624 }
622 625
623 // This function does not handle 3D sorting right now, since the debug border 626 // This function does not handle 3D sorting right now, since the debug border
624 // quads are just drawn as their original quads and not in split pieces. This 627 // quads are just drawn as their original quads and not in split pieces. This
625 // results in some debug border quads drawing over foreground quads. 628 // results in some debug border quads drawing over foreground quads.
626 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, 629 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame,
627 const DebugBorderDrawQuad* quad) { 630 const DebugBorderDrawQuad* quad) {
628 SetBlendEnabled(quad->ShouldDrawWithBlending()); 631 SetBlendEnabled(quad->ShouldDrawWithBlending());
629 632
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 GetScaledUVs(quad->visible_rect, clip_region, uvs); 2454 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2452 gfx::QuadF region_quad = *clip_region; 2455 gfx::QuadF region_quad = *clip_region;
2453 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 2456 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
2454 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2457 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2455 DrawQuadGeometryClippedByQuadF( 2458 DrawQuadGeometryClippedByQuadF(
2456 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, 2459 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect,
2457 region_quad, matrix_location, uvs); 2460 region_quad, matrix_location, uvs);
2458 } 2461 }
2459 } 2462 }
2460 2463
2464 void GLRenderer::DrawYVideoQuad(const DrawingFrame* frame,
2465 const YVideoDrawQuad* quad,
2466 const gfx::QuadF* clip_region) {
2467 SetBlendEnabled(quad->ShouldDrawWithBlending());
2468 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2469 gl_, &highp_threshold_cache_, highp_threshold_min_,
2470 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2471
2472 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
2473 quad->resource_id());
2474 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
2475 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2476 gl_->BindTexture(lock.target(), lock.texture_id());
2477
2478 const VideoYProgram* program = GetVideoYProgram(tex_coord_precision, sampler);
2479 DCHECK(program && (program->initialized() || IsContextLost()));
2480 SetUseProgram(program->program());
2481
2482 // Set the uv-transform.
2483 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}};
2484 if (!clip_region) {
2485 gfx::PointF uv0 = quad->uv_top_left;
2486 gfx::PointF uv1 = quad->uv_bottom_right;
2487 uv_transform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}};
2488 }
2489 gfx::Size texture_size = lock.size();
2490 if (sampler == SAMPLER_TYPE_2D_RECT) {
2491 // Un-normalize the texture coordiantes for rectangle targets.
2492 uv_transform.data[0] *= texture_size.width();
2493 uv_transform.data[2] *= texture_size.width();
2494 uv_transform.data[1] *= texture_size.height();
2495 uv_transform.data[3] *= texture_size.height();
2496 }
2497 gl_->Uniform4fv(program->vertex_shader().tex_transform_location(), 1,
2498 uv_transform.data);
2499 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0);
2500 gl_->Uniform1f(program->fragment_shader().x_derivative_location(),
2501 1.f / (float)texture_size.width());
2502 gl_->Uniform1f(program->fragment_shader().y_derivative_location(),
2503 1.f / (float)texture_size.height());
2504
2505 if (!clip_region) {
2506 DrawQuadGeometry(frame->projection_matrix,
2507 quad->shared_quad_state->quad_to_target_transform,
2508 gfx::RectF(quad->rect),
2509 program->vertex_shader().matrix_location());
2510 } else {
2511 gfx::QuadF region_quad(*clip_region);
2512 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2513 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2514 float uvs[8] = {0};
2515 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2516 DrawQuadGeometryClippedByQuadF(
2517 frame, quad->shared_quad_state->quad_to_target_transform,
2518 gfx::RectF(quad->rect), region_quad,
2519 program->vertex_shader().matrix_location(), uvs);
2520 }
2521 }
2522
2461 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, 2523 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
2462 const StreamVideoDrawQuad* quad, 2524 const StreamVideoDrawQuad* quad,
2463 const gfx::QuadF* clip_region) { 2525 const gfx::QuadF* clip_region) {
2464 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2526 SetBlendEnabled(quad->ShouldDrawWithBlending());
2465 2527
2466 static float gl_matrix[16]; 2528 static float gl_matrix[16];
2467 2529
2468 DCHECK(capabilities_.using_egl_image); 2530 DCHECK(capabilities_.using_egl_image);
2469 2531
2470 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2532 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3677 if (!program->initialized()) { 3739 if (!program->initialized()) {
3678 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 3740 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
3679 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, 3741 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12,
3680 use_color_lut); 3742 use_color_lut);
3681 program->Initialize(output_surface_->context_provider(), precision, 3743 program->Initialize(output_surface_->context_provider(), precision,
3682 sampler); 3744 sampler);
3683 } 3745 }
3684 return program; 3746 return program;
3685 } 3747 }
3686 3748
3749 const GLRenderer::VideoYProgram* GLRenderer::GetVideoYProgram(
3750 TexCoordPrecision precision,
3751 SamplerType sampler) {
3752 DCHECK_GE(precision, 0);
3753 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3754 DCHECK_GE(sampler, 0);
3755 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3756 VideoYProgram* program = &video_y_program_[precision][sampler];
3757 if (!program->initialized()) {
3758 TRACE_EVENT0("cc", "GLRenderer::videoYProgram::initialize");
3759 program->Initialize(output_surface_->context_provider(), precision,
3760 sampler);
3761 }
3762 return program;
3763 }
3764
3687 const GLRenderer::VideoStreamTextureProgram* 3765 const GLRenderer::VideoStreamTextureProgram*
3688 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { 3766 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) {
3689 DCHECK_GE(precision, 0); 3767 DCHECK_GE(precision, 0);
3690 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3768 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3691 VideoStreamTextureProgram* program = 3769 VideoStreamTextureProgram* program =
3692 &video_stream_texture_program_[precision]; 3770 &video_stream_texture_program_[precision];
3693 if (!program->initialized()) { 3771 if (!program->initialized()) {
3694 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); 3772 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize");
3695 program->Initialize(output_surface_->context_provider(), precision, 3773 program->Initialize(output_surface_->context_provider(), precision,
3696 SAMPLER_TYPE_EXTERNAL_OES); 3774 SAMPLER_TYPE_EXTERNAL_OES);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3732 render_pass_program_aa_[i][j].Cleanup(gl_); 3810 render_pass_program_aa_[i][j].Cleanup(gl_);
3733 render_pass_color_matrix_program_[i][j].Cleanup(gl_); 3811 render_pass_color_matrix_program_[i][j].Cleanup(gl_);
3734 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); 3812 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_);
3735 } 3813 }
3736 3814
3737 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { 3815 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) {
3738 texture_program_[i][j].Cleanup(gl_); 3816 texture_program_[i][j].Cleanup(gl_);
3739 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); 3817 nonpremultiplied_texture_program_[i][j].Cleanup(gl_);
3740 texture_background_program_[i][j].Cleanup(gl_); 3818 texture_background_program_[i][j].Cleanup(gl_);
3741 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); 3819 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_);
3820 video_y_program_[i][j].Cleanup(gl_);
3742 } 3821 }
3743 3822
3744 video_stream_texture_program_[i].Cleanup(gl_); 3823 video_stream_texture_program_[i].Cleanup(gl_);
3745 } 3824 }
3746 3825
3747 debug_border_program_.Cleanup(gl_); 3826 debug_border_program_.Cleanup(gl_);
3748 solid_color_program_.Cleanup(gl_); 3827 solid_color_program_.Cleanup(gl_);
3749 solid_color_program_aa_.Cleanup(gl_); 3828 solid_color_program_aa_.Cleanup(gl_);
3750 3829
3751 if (offscreen_framebuffer_id_) 3830 if (offscreen_framebuffer_id_)
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
4073 4152
4074 gl_->ScheduleCALayerSharedStateCHROMIUM( 4153 gl_->ScheduleCALayerSharedStateCHROMIUM(
4075 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, 4154 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect,
4076 sorting_context_id, gl_transform); 4155 sorting_context_id, gl_transform);
4077 gl_->ScheduleCALayerCHROMIUM( 4156 gl_->ScheduleCALayerCHROMIUM(
4078 texture_id, contents_rect, ca_layer_overlay->background_color, 4157 texture_id, contents_rect, ca_layer_overlay->background_color,
4079 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4158 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4080 } 4159 }
4081 4160
4082 } // namespace cc 4161 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698