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

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: Created 4 years, 5 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), 538 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad),
539 clip_region); 539 clip_region);
540 break; 540 break;
541 case DrawQuad::TILED_CONTENT: 541 case DrawQuad::TILED_CONTENT:
542 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); 542 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region);
543 break; 543 break;
544 case DrawQuad::YUV_VIDEO_CONTENT: 544 case DrawQuad::YUV_VIDEO_CONTENT:
545 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), 545 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad),
546 clip_region); 546 clip_region);
547 break; 547 break;
548 case DrawQuad::Y_VIDEO_CONTENT:
549 DrawYVideoQuad(frame, YVideoDrawQuad::MaterialCast(quad), clip_region);
550 break;
548 } 551 }
549 } 552 }
550 553
551 // This function does not handle 3D sorting right now, since the debug border 554 // This function does not handle 3D sorting right now, since the debug border
552 // quads are just drawn as their original quads and not in split pieces. This 555 // quads are just drawn as their original quads and not in split pieces. This
553 // results in some debug border quads drawing over foreground quads. 556 // results in some debug border quads drawing over foreground quads.
554 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, 557 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame,
555 const DebugBorderDrawQuad* quad) { 558 const DebugBorderDrawQuad* quad) {
556 SetBlendEnabled(quad->ShouldDrawWithBlending()); 559 SetBlendEnabled(quad->ShouldDrawWithBlending());
557 560
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 GetScaledUVs(quad->visible_rect, clip_region, uvs); 2319 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2317 gfx::QuadF region_quad = *clip_region; 2320 gfx::QuadF region_quad = *clip_region;
2318 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 2321 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
2319 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2322 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2320 DrawQuadGeometryClippedByQuadF( 2323 DrawQuadGeometryClippedByQuadF(
2321 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, 2324 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect,
2322 region_quad, matrix_location, uvs); 2325 region_quad, matrix_location, uvs);
2323 } 2326 }
2324 } 2327 }
2325 2328
2329 void GLRenderer::DrawYVideoQuad(const DrawingFrame* frame,
2330 const YVideoDrawQuad* quad,
2331 const gfx::QuadF* clip_region) {
2332 SetBlendEnabled(quad->ShouldDrawWithBlending());
2333 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2334 gl_, &highp_threshold_cache_, highp_threshold_min_,
2335 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2336
2337 ResourceProvider::ScopedSamplerGL lock(resource_provider_,
2338 quad->resource_id(),
2339 GL_NEAREST);
2340 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
2341 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2342 gl_->BindTexture(lock.target(), lock.texture_id());
2343
2344 // TODO(astojilj) TextureProgram could also be used - just remember to set
2345 // varying v_alpha.
2346 const VideoYProgram* program =
2347 GetVideoYProgram(tex_coord_precision, sampler);
2348 DCHECK(program && (program->initialized() || IsContextLost()));
2349 SetUseProgram(program->program());
2350
2351 // Set the uv-transform.
2352 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}};
2353 if (!clip_region) {
2354 gfx::PointF uv0 = quad->uv_top_left;
2355 gfx::PointF uv1 = quad->uv_bottom_right;
2356 uv_transform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } };
2357 }
2358 if (sampler == SAMPLER_TYPE_2D_RECT) {
2359 // Un-normalize the texture coordiantes for rectangle targets.
2360 gfx::Size texture_size = lock.texture_size();
2361 uv_transform.data[0] *= texture_size.width();
2362 uv_transform.data[2] *= texture_size.width();
2363 uv_transform.data[1] *= texture_size.height();
2364 uv_transform.data[3] *= texture_size.height();
2365 }
2366 gl_->Uniform4fv(program->vertex_shader().tex_transform_location(), 1,
2367 uv_transform.data);
2368 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0);
2369
2370 if (!clip_region) {
2371 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform,
2372 gfx::RectF(quad->rect),
2373 program->vertex_shader().matrix_location());
2374 } else {
2375 gfx::QuadF region_quad(*clip_region);
2376 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2377 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2378 float uvs[8] = {0};
2379 GetScaledUVs(quad->visible_rect, clip_region, uvs);
2380 DrawQuadGeometryClippedByQuadF(
2381 frame, quad->shared_quad_state->quad_to_target_transform,
2382 gfx::RectF(quad->rect), region_quad,
2383 program->vertex_shader().matrix_location(), uvs);
2384 }
2385 }
2386
2326 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, 2387 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
2327 const StreamVideoDrawQuad* quad, 2388 const StreamVideoDrawQuad* quad,
2328 const gfx::QuadF* clip_region) { 2389 const gfx::QuadF* clip_region) {
2329 SetBlendEnabled(quad->ShouldDrawWithBlending()); 2390 SetBlendEnabled(quad->ShouldDrawWithBlending());
2330 2391
2331 static float gl_matrix[16]; 2392 static float gl_matrix[16];
2332 2393
2333 DCHECK(capabilities_.using_egl_image); 2394 DCHECK(capabilities_.using_egl_image);
2334 2395
2335 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2396 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3548 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 3609 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3549 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler]; 3610 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler];
3550 if (!program->initialized()) { 3611 if (!program->initialized()) {
3551 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); 3612 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize");
3552 program->Initialize(output_surface_->context_provider(), precision, 3613 program->Initialize(output_surface_->context_provider(), precision,
3553 sampler); 3614 sampler);
3554 } 3615 }
3555 return program; 3616 return program;
3556 } 3617 }
3557 3618
3619 const GLRenderer::VideoYProgram* GLRenderer::GetVideoYProgram(
3620 TexCoordPrecision precision,
3621 SamplerType sampler) {
3622 DCHECK_GE(precision, 0);
3623 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3624 DCHECK_GE(sampler, 0);
3625 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3626 VideoYProgram* program = &video_y_program_[precision][sampler];
3627 if (!program->initialized()) {
3628 TRACE_EVENT0("cc", "GLRenderer::videoYProgram::initialize");
3629 program->Initialize(output_surface_->context_provider(), precision,
3630 sampler);
3631 }
3632 return program;
3633 }
3634
3558 const GLRenderer::VideoStreamTextureProgram* 3635 const GLRenderer::VideoStreamTextureProgram*
3559 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { 3636 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) {
3560 DCHECK_GE(precision, 0); 3637 DCHECK_GE(precision, 0);
3561 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3638 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3562 VideoStreamTextureProgram* program = 3639 VideoStreamTextureProgram* program =
3563 &video_stream_texture_program_[precision]; 3640 &video_stream_texture_program_[precision];
3564 if (!program->initialized()) { 3641 if (!program->initialized()) {
3565 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); 3642 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize");
3566 program->Initialize(output_surface_->context_provider(), precision, 3643 program->Initialize(output_surface_->context_provider(), precision,
3567 SAMPLER_TYPE_EXTERNAL_OES); 3644 SAMPLER_TYPE_EXTERNAL_OES);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 render_pass_program_aa_[i][j].Cleanup(gl_); 3676 render_pass_program_aa_[i][j].Cleanup(gl_);
3600 render_pass_color_matrix_program_[i][j].Cleanup(gl_); 3677 render_pass_color_matrix_program_[i][j].Cleanup(gl_);
3601 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); 3678 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_);
3602 } 3679 }
3603 3680
3604 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { 3681 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) {
3605 texture_program_[i][j].Cleanup(gl_); 3682 texture_program_[i][j].Cleanup(gl_);
3606 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); 3683 nonpremultiplied_texture_program_[i][j].Cleanup(gl_);
3607 texture_background_program_[i][j].Cleanup(gl_); 3684 texture_background_program_[i][j].Cleanup(gl_);
3608 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); 3685 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_);
3686 video_y_program_[i][j].Cleanup(gl_);
3609 } 3687 }
3610 3688
3611 video_stream_texture_program_[i].Cleanup(gl_); 3689 video_stream_texture_program_[i].Cleanup(gl_);
3612 } 3690 }
3613 3691
3614 debug_border_program_.Cleanup(gl_); 3692 debug_border_program_.Cleanup(gl_);
3615 solid_color_program_.Cleanup(gl_); 3693 solid_color_program_.Cleanup(gl_);
3616 solid_color_program_aa_.Cleanup(gl_); 3694 solid_color_program_aa_.Cleanup(gl_);
3617 3695
3618 if (offscreen_framebuffer_id_) 3696 if (offscreen_framebuffer_id_)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 texture_id = pending_overlay_resources_.back()->texture_id(); 3811 texture_id = pending_overlay_resources_.back()->texture_id();
3734 } 3812 }
3735 3813
3736 context_support_->ScheduleOverlayPlane( 3814 context_support_->ScheduleOverlayPlane(
3737 overlay.plane_z_order, overlay.transform, texture_id, 3815 overlay.plane_z_order, overlay.transform, texture_id,
3738 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3816 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3739 } 3817 }
3740 } 3818 }
3741 3819
3742 } // namespace cc 3820 } // namespace cc
OLDNEW
« cc/layers/video_layer_impl.cc ('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