OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/gpu/media/rendering_helper.h" | 5 #include "content/common/gpu/media/rendering_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this))); | 307 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this))); |
308 | 308 |
309 frame_duration_ = params.rendering_fps > 0 | 309 frame_duration_ = params.rendering_fps > 0 |
310 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps | 310 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps |
311 : base::TimeDelta(); | 311 : base::TimeDelta(); |
312 | 312 |
313 render_as_thumbnails_ = params.render_as_thumbnails; | 313 render_as_thumbnails_ = params.render_as_thumbnails; |
314 message_loop_ = base::MessageLoop::current(); | 314 message_loop_ = base::MessageLoop::current(); |
315 | 315 |
316 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); | 316 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); |
| 317 #if defined(USE_OZONE) |
| 318 gl_surface_->Resize(platform_window_delegate_->GetSize()); |
| 319 #endif // defined(USE_OZONE) |
317 screen_size_ = gl_surface_->GetSize(); | 320 screen_size_ = gl_surface_->GetSize(); |
318 | 321 |
319 gl_context_ = gfx::GLContext::CreateGLContext( | 322 gl_context_ = gfx::GLContext::CreateGLContext( |
320 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); | 323 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); |
321 CHECK(gl_context_->MakeCurrent(gl_surface_.get())); | 324 CHECK(gl_context_->MakeCurrent(gl_surface_.get())); |
322 | 325 |
323 CHECK_GT(params.window_sizes.size(), 0U); | 326 CHECK_GT(params.window_sizes.size(), 0U); |
324 videos_.resize(params.window_sizes.size()); | 327 videos_.resize(params.window_sizes.size()); |
325 LayoutRenderingAreas(params.window_sizes); | 328 LayoutRenderingAreas(params.window_sizes); |
326 | 329 |
(...skipping 30 matching lines...) Expand all Loading... |
357 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 360 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
358 GL_COLOR_ATTACHMENT0, | 361 GL_COLOR_ATTACHMENT0, |
359 GL_TEXTURE_2D, | 362 GL_TEXTURE_2D, |
360 thumbnails_texture_id_, | 363 thumbnails_texture_id_, |
361 0); | 364 0); |
362 | 365 |
363 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 366 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
364 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status; | 367 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status; |
365 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | 368 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
366 glClear(GL_COLOR_BUFFER_BIT); | 369 glClear(GL_COLOR_BUFFER_BIT); |
367 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 370 glBindFramebufferEXT(GL_FRAMEBUFFER, |
| 371 gl_surface_->GetBackingFrameBufferObject()); |
368 } | 372 } |
369 | 373 |
370 // These vertices and texture coords. map (0,0) in the texture to the | 374 // These vertices and texture coords. map (0,0) in the texture to the |
371 // bottom left of the viewport. Since we get the video frames with the | 375 // bottom left of the viewport. Since we get the video frames with the |
372 // the top left at (0,0) we need to flip the texture y coordinate | 376 // the top left at (0,0) we need to flip the texture y coordinate |
373 // in the vertex shader for this to be rendered the right way up. | 377 // in the vertex shader for this to be rendered the right way up. |
374 // In the case of thumbnail rendering we use the same vertex shader | 378 // In the case of thumbnail rendering we use the same vertex shader |
375 // to render the FBO the screen, where we do not want this flipping. | 379 // to render the FBO the screen, where we do not want this flipping. |
376 static const float kVertices[] = | 380 static const float kVertices[] = |
377 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; | 381 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { | 501 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { |
498 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 502 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
499 | 503 |
500 render_task_.Cancel(); | 504 render_task_.Cancel(); |
501 | 505 |
502 if (render_as_thumbnails_) { | 506 if (render_as_thumbnails_) { |
503 glDeleteTextures(1, &thumbnails_texture_id_); | 507 glDeleteTextures(1, &thumbnails_texture_id_); |
504 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); | 508 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); |
505 } | 509 } |
506 | 510 |
| 511 gl_surface_->Destroy(); |
507 gl_context_->ReleaseCurrent(gl_surface_.get()); | 512 gl_context_->ReleaseCurrent(gl_surface_.get()); |
508 gl_context_ = NULL; | 513 gl_context_ = NULL; |
509 gl_surface_ = NULL; | 514 gl_surface_ = NULL; |
510 | 515 |
511 Clear(); | 516 Clear(); |
512 done->Signal(); | 517 done->Signal(); |
513 } | 518 } |
514 | 519 |
515 void RenderingHelper::CreateTexture(uint32 texture_target, | 520 void RenderingHelper::CreateTexture(uint32 texture_target, |
516 uint32* texture_id, | 521 uint32* texture_id, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 const int thumbnails_in_column = thumbnails_fbo_size_.height() / height; | 568 const int thumbnails_in_column = thumbnails_fbo_size_.height() / height; |
564 const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column; | 569 const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column; |
565 const int col = frame_count_ % thumbnails_in_row; | 570 const int col = frame_count_ % thumbnails_in_row; |
566 | 571 |
567 gfx::Rect area(col * width, row * height, width, height); | 572 gfx::Rect area(col * width, row * height, width, height); |
568 | 573 |
569 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); | 574 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); |
570 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 575 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
571 GLSetViewPort(area); | 576 GLSetViewPort(area); |
572 RenderTexture(texture_target, texture_id); | 577 RenderTexture(texture_target, texture_id); |
573 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 578 glBindFramebufferEXT(GL_FRAMEBUFFER, |
| 579 gl_surface_->GetBackingFrameBufferObject()); |
574 | 580 |
575 // Need to flush the GL commands before we return the tnumbnail texture to | 581 // Need to flush the GL commands before we return the tnumbnail texture to |
576 // the decoder. | 582 // the decoder. |
577 glFlush(); | 583 glFlush(); |
578 ++frame_count_; | 584 ++frame_count_; |
579 } | 585 } |
580 | 586 |
581 void RenderingHelper::QueueVideoFrame( | 587 void RenderingHelper::QueueVideoFrame( |
582 size_t window_id, | 588 size_t window_id, |
583 scoped_refptr<VideoFrameTexture> video_frame) { | 589 scoped_refptr<VideoFrameTexture> video_frame) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 660 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
655 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 661 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
656 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. | 662 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. |
657 glReadPixels(0, | 663 glReadPixels(0, |
658 0, | 664 0, |
659 thumbnails_fbo_size_.width(), | 665 thumbnails_fbo_size_.width(), |
660 thumbnails_fbo_size_.height(), | 666 thumbnails_fbo_size_.height(), |
661 GL_RGBA, | 667 GL_RGBA, |
662 GL_UNSIGNED_BYTE, | 668 GL_UNSIGNED_BYTE, |
663 &rgba[0]); | 669 &rgba[0]); |
664 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 670 glBindFramebufferEXT(GL_FRAMEBUFFER, |
| 671 gl_surface_->GetBackingFrameBufferObject()); |
665 rgb->resize(num_pixels * 3); | 672 rgb->resize(num_pixels * 3); |
666 // Drop the alpha channel, but check as we go that it is all 0xff. | 673 // Drop the alpha channel, but check as we go that it is all 0xff. |
667 bool solid = true; | 674 bool solid = true; |
668 unsigned char* rgb_ptr = &((*rgb)[0]); | 675 unsigned char* rgb_ptr = &((*rgb)[0]); |
669 unsigned char* rgba_ptr = &rgba[0]; | 676 unsigned char* rgba_ptr = &rgba[0]; |
670 for (size_t i = 0; i < num_pixels; ++i) { | 677 for (size_t i = 0; i < num_pixels; ++i) { |
671 *rgb_ptr++ = *rgba_ptr++; | 678 *rgb_ptr++ = *rgba_ptr++; |
672 *rgb_ptr++ = *rgba_ptr++; | 679 *rgb_ptr++ = *rgba_ptr++; |
673 *rgb_ptr++ = *rgba_ptr++; | 680 *rgb_ptr++ = *rgba_ptr++; |
674 solid = solid && (*rgba_ptr == 0xff); | 681 solid = solid && (*rgba_ptr == 0xff); |
(...skipping 16 matching lines...) Expand all Loading... |
691 // It's safe to use Unretained here since |rendering_thread_| will be stopped | 698 // It's safe to use Unretained here since |rendering_thread_| will be stopped |
692 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is | 699 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is |
693 // a member of that class. (See video_decode_accelerator_unittest.cc.) | 700 // a member of that class. (See video_decode_accelerator_unittest.cc.) |
694 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); | 701 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); |
695 if (vsync_provider) { | 702 if (vsync_provider) { |
696 vsync_provider->GetVSyncParameters(base::Bind( | 703 vsync_provider->GetVSyncParameters(base::Bind( |
697 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), | 704 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), |
698 static_cast<base::WaitableEvent*>(NULL))); | 705 static_cast<base::WaitableEvent*>(NULL))); |
699 } | 706 } |
700 | 707 |
701 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); | 708 int tex_flip = 1; |
| 709 #if defined(USE_OZONE) |
| 710 // Ozone surfaceless renders flipped from normal GL, so there's no need to |
| 711 // do an extra flip. |
| 712 tex_flip = 0; |
| 713 #endif // defined(USE_OZONE) |
| 714 glUniform1i(glGetUniformLocation(program_, "tex_flip"), tex_flip); |
702 | 715 |
703 // Frames that will be returned to the client (via the no_longer_needed_cb) | 716 // Frames that will be returned to the client (via the no_longer_needed_cb) |
704 // after this vector falls out of scope at the end of this method. We need | 717 // after this vector falls out of scope at the end of this method. We need |
705 // to keep references to them until after SwapBuffers() call below. | 718 // to keep references to them until after SwapBuffers() call below. |
706 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; | 719 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; |
707 bool need_swap_buffer = false; | 720 bool need_swap_buffer = false; |
708 if (render_as_thumbnails_) { | 721 if (render_as_thumbnails_) { |
709 // In render_as_thumbnails_ mode, we render the FBO content on the | 722 // In render_as_thumbnails_ mode, we render the FBO content on the |
710 // screen instead of the decoded textures. | 723 // screen instead of the decoded textures. |
711 GLSetViewPort(videos_[0].render_area); | 724 GLSetViewPort(videos_[0].render_area); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // When the rendering falls behind, drops frames. | 844 // When the rendering falls behind, drops frames. |
832 while (scheduled_render_time_ < target) { | 845 while (scheduled_render_time_ < target) { |
833 scheduled_render_time_ += frame_duration_; | 846 scheduled_render_time_ += frame_duration_; |
834 DropOneFrameForAllVideos(); | 847 DropOneFrameForAllVideos(); |
835 } | 848 } |
836 | 849 |
837 message_loop_->PostDelayedTask( | 850 message_loop_->PostDelayedTask( |
838 FROM_HERE, render_task_.callback(), target - now); | 851 FROM_HERE, render_task_.callback(), target - now); |
839 } | 852 } |
840 } // namespace content | 853 } // namespace content |
OLD | NEW |