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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 gfx::kGLImplementationDesktopName); | 174 gfx::kGLImplementationDesktopName); |
175 #else | 175 #else |
176 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); | 176 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); |
177 #endif | 177 #endif |
178 | 178 |
179 if (!gfx::GLSurface::InitializeOneOff()) | 179 if (!gfx::GLSurface::InitializeOneOff()) |
180 LOG(FATAL) << "Could not initialize GL"; | 180 LOG(FATAL) << "Could not initialize GL"; |
181 done->Signal(); | 181 done->Signal(); |
182 } | 182 } |
183 | 183 |
184 RenderingHelper::RenderingHelper() { | 184 RenderingHelper::RenderingHelper() : ignore_vsync_(false) { |
185 window_ = gfx::kNullAcceleratedWidget; | 185 window_ = gfx::kNullAcceleratedWidget; |
186 Clear(); | 186 Clear(); |
187 } | 187 } |
188 | 188 |
189 RenderingHelper::~RenderingHelper() { | 189 RenderingHelper::~RenderingHelper() { |
190 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; | 190 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; |
191 Clear(); | 191 Clear(); |
192 } | 192 } |
193 | 193 |
194 void RenderingHelper::Setup() { | 194 void RenderingHelper::Setup() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 XSelectInput(display, window_, ExposureMask); | 234 XSelectInput(display, window_, ExposureMask); |
235 XMapWindow(display, window_); | 235 XMapWindow(display, window_); |
236 #elif defined(USE_OZONE) | 236 #elif defined(USE_OZONE) |
237 base::MessageLoop::ScopedNestableTaskAllower nest_loop( | 237 base::MessageLoop::ScopedNestableTaskAllower nest_loop( |
238 base::MessageLoop::current()); | 238 base::MessageLoop::current()); |
239 base::RunLoop wait_window_resize; | 239 base::RunLoop wait_window_resize; |
240 | 240 |
241 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); | 241 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); |
242 window_ = platform_window_delegate_->accelerated_widget(); | 242 window_ = platform_window_delegate_->accelerated_widget(); |
243 gfx::Size window_size(800, 600); | 243 gfx::Size window_size(800, 600); |
244 // Assume headless mode by default. On ChromeOS this will be set accordingly | |
Pawel Osciak
2015/04/24 01:08:56
Please update comment.
dnicoara
2015/04/24 13:21:12
Done.
| |
245 // based on the display configuration. | |
246 ignore_vsync_ = true; | |
244 #if defined(OS_CHROMEOS) | 247 #if defined(OS_CHROMEOS) |
245 // We hold onto the main loop here to wait for the DisplayController | 248 // We hold onto the main loop here to wait for the DisplayController |
246 // to give us the size of the display so we can create a window of | 249 // to give us the size of the display so we can create a window of |
247 // the same size. | 250 // the same size. |
248 base::RunLoop wait_display_setup; | 251 base::RunLoop wait_display_setup; |
249 DisplayConfiguratorObserver display_setup_observer(&wait_display_setup); | 252 DisplayConfiguratorObserver display_setup_observer(&wait_display_setup); |
250 display_configurator_.reset(new ui::DisplayConfigurator()); | 253 display_configurator_.reset(new ui::DisplayConfigurator()); |
251 display_configurator_->SetDelegateForTesting(0); | 254 display_configurator_->SetDelegateForTesting(0); |
252 display_configurator_->AddObserver(&display_setup_observer); | 255 display_configurator_->AddObserver(&display_setup_observer); |
253 display_configurator_->Init(true); | 256 display_configurator_->Init(true); |
254 display_configurator_->ForceInitialConfigure(0); | 257 display_configurator_->ForceInitialConfigure(0); |
255 // Make sure all the display configuration is applied. | 258 // Make sure all the display configuration is applied. |
256 wait_display_setup.Run(); | 259 wait_display_setup.Run(); |
257 display_configurator_->RemoveObserver(&display_setup_observer); | 260 display_configurator_->RemoveObserver(&display_setup_observer); |
258 | 261 |
259 gfx::Size framebuffer_size = display_configurator_->framebuffer_size(); | 262 gfx::Size framebuffer_size = display_configurator_->framebuffer_size(); |
260 if (!framebuffer_size.IsEmpty()) | 263 if (!framebuffer_size.IsEmpty()) { |
261 window_size = framebuffer_size; | 264 window_size = framebuffer_size; |
265 ignore_vsync_ = false; | |
266 } | |
262 #endif | 267 #endif |
268 if (ignore_vsync_) | |
269 DVLOG(1) << "Ignoring vsync provider"; | |
270 | |
263 platform_window_delegate_->platform_window()->SetBounds( | 271 platform_window_delegate_->platform_window()->SetBounds( |
264 gfx::Rect(window_size)); | 272 gfx::Rect(window_size)); |
265 | 273 |
266 // On Ozone/DRI, platform windows are associated with the physical | 274 // On Ozone/DRI, platform windows are associated with the physical |
267 // outputs. Association is achieved by matching the bounds of the | 275 // outputs. Association is achieved by matching the bounds of the |
268 // window with the origin & modeset of the display output. Until a | 276 // window with the origin & modeset of the display output. Until a |
269 // window is associated with a display output, we cannot get vsync | 277 // window is associated with a display output, we cannot get vsync |
270 // events, because there is no hardware to get events from. Here we | 278 // events, because there is no hardware to get events from. Here we |
271 // wait for the window to resized and therefore associated with | 279 // wait for the window to resized and therefore associated with |
272 // display output to be sure that we will get such events. | 280 // display output to be sure that we will get such events. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 // the front and back buffers. | 472 // the front and back buffers. |
465 warm_up_iterations = std::max(2, warm_up_iterations); | 473 warm_up_iterations = std::max(2, warm_up_iterations); |
466 #endif | 474 #endif |
467 WarmUpRendering(warm_up_iterations); | 475 WarmUpRendering(warm_up_iterations); |
468 } | 476 } |
469 | 477 |
470 // It's safe to use Unretained here since |rendering_thread_| will be stopped | 478 // It's safe to use Unretained here since |rendering_thread_| will be stopped |
471 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is | 479 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is |
472 // a member of that class. (See video_decode_accelerator_unittest.cc.) | 480 // a member of that class. (See video_decode_accelerator_unittest.cc.) |
473 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); | 481 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); |
474 if (vsync_provider && frame_duration_ != base::TimeDelta()) | 482 |
483 // VSync providers rely on the underlying CRTC to get the timing. In headless | |
484 // mode the surface isn't associated with a CRTC so the vsync provider can not | |
485 // get the timing, meaning it will not call UpdateVsyncParameters() ever. | |
486 if (!ignore_vsync_ && vsync_provider && frame_duration_ != base::TimeDelta()) | |
475 vsync_provider->GetVSyncParameters(base::Bind( | 487 vsync_provider->GetVSyncParameters(base::Bind( |
476 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); | 488 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); |
477 else | 489 else |
478 done->Signal(); | 490 done->Signal(); |
479 } | 491 } |
480 | 492 |
481 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). | 493 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). |
482 // This affects the numbers measured in the performance test. We try to render | 494 // This affects the numbers measured in the performance test. We try to render |
483 // several frames here to warm up the rendering. | 495 // several frames here to warm up the rendering. |
484 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { | 496 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 | 708 |
697 void RenderingHelper::RenderContent() { | 709 void RenderingHelper::RenderContent() { |
698 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 710 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
699 | 711 |
700 // Update the VSync params. | 712 // Update the VSync params. |
701 // | 713 // |
702 // It's safe to use Unretained here since |rendering_thread_| will be stopped | 714 // It's safe to use Unretained here since |rendering_thread_| will be stopped |
703 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is | 715 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is |
704 // a member of that class. (See video_decode_accelerator_unittest.cc.) | 716 // a member of that class. (See video_decode_accelerator_unittest.cc.) |
705 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); | 717 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); |
706 if (vsync_provider) { | 718 if (vsync_provider && !ignore_vsync_) { |
707 vsync_provider->GetVSyncParameters(base::Bind( | 719 vsync_provider->GetVSyncParameters(base::Bind( |
708 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), | 720 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), |
709 static_cast<base::WaitableEvent*>(NULL))); | 721 static_cast<base::WaitableEvent*>(NULL))); |
710 } | 722 } |
711 | 723 |
712 int tex_flip = 1; | 724 int tex_flip = 1; |
713 #if defined(USE_OZONE) | 725 #if defined(USE_OZONE) |
714 // Ozone surfaceless renders flipped from normal GL, so there's no need to | 726 // Ozone surfaceless renders flipped from normal GL, so there's no need to |
715 // do an extra flip. | 727 // do an extra flip. |
716 tex_flip = 0; | 728 tex_flip = 0; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 // When the rendering falls behind, drops frames. | 860 // When the rendering falls behind, drops frames. |
849 while (scheduled_render_time_ < target) { | 861 while (scheduled_render_time_ < target) { |
850 scheduled_render_time_ += frame_duration_; | 862 scheduled_render_time_ += frame_duration_; |
851 DropOneFrameForAllVideos(); | 863 DropOneFrameForAllVideos(); |
852 } | 864 } |
853 | 865 |
854 message_loop_->PostDelayedTask( | 866 message_loop_->PostDelayedTask( |
855 FROM_HERE, render_task_.callback(), target - now); | 867 FROM_HERE, render_task_.callback(), target - now); |
856 } | 868 } |
857 } // namespace content | 869 } // namespace content |
OLD | NEW |