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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/mac/scoped_nsautorelease_pool.h" | 14 #include "base/mac/scoped_nsautorelease_pool.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | |
16 #include "base/strings/stringize_macros.h" | 17 #include "base/strings/stringize_macros.h" |
17 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
20 #include "ui/gl/gl_implementation.h" | 21 #include "ui/gl/gl_implementation.h" |
21 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
22 | 23 |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
24 #include <windows.h> | 25 #include <windows.h> |
25 #endif | 26 #endif |
26 | 27 |
27 #if defined(USE_X11) | 28 #if defined(USE_X11) |
28 #include "ui/gfx/x/x11_types.h" | 29 #include "ui/gfx/x/x11_types.h" |
29 #endif | 30 #endif |
30 | 31 |
31 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 32 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
32 #include "ui/gl/gl_surface_glx.h" | 33 #include "ui/gl/gl_surface_glx.h" |
33 #define GL_VARIANT_GLX 1 | 34 #define GL_VARIANT_GLX 1 |
34 #else | 35 #else |
35 #include "ui/gl/gl_surface_egl.h" | 36 #include "ui/gl/gl_surface_egl.h" |
36 #define GL_VARIANT_EGL 1 | 37 #define GL_VARIANT_EGL 1 |
37 #endif | 38 #endif |
38 | 39 |
39 #if defined(USE_OZONE) | 40 #if defined(USE_OZONE) |
40 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
41 #include "ui/display/chromeos/display_configurator.h" | 42 #include "ui/display/chromeos/display_configurator.h" |
43 #include "ui/display/types/display_constants.h" | |
42 #endif // defined(OS_CHROMEOS) | 44 #endif // defined(OS_CHROMEOS) |
43 #include "ui/ozone/public/ozone_platform.h" | 45 #include "ui/ozone/public/ozone_platform.h" |
44 #include "ui/ozone/public/ui_thread_gpu.h" | 46 #include "ui/ozone/public/ui_thread_gpu.h" |
45 #include "ui/platform_window/platform_window.h" | 47 #include "ui/platform_window/platform_window.h" |
46 #include "ui/platform_window/platform_window_delegate.h" | 48 #include "ui/platform_window/platform_window_delegate.h" |
47 #endif // defined(USE_OZONE) | 49 #endif // defined(USE_OZONE) |
48 | 50 |
49 // Helper for Shader creation. | 51 // Helper for Shader creation. |
50 static void CreateShader(GLuint program, | 52 static void CreateShader(GLuint program, |
51 GLenum type, | 53 GLenum type, |
(...skipping 11 matching lines...) Expand all Loading... | |
63 } | 65 } |
64 glAttachShader(program, shader); | 66 glAttachShader(program, shader); |
65 glDeleteShader(shader); | 67 glDeleteShader(shader); |
66 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 68 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
67 } | 69 } |
68 | 70 |
69 namespace content { | 71 namespace content { |
70 | 72 |
71 #if defined(USE_OZONE) | 73 #if defined(USE_OZONE) |
72 | 74 |
75 class DisplayConfiguratorObserver : public ui::DisplayConfigurator::Observer { | |
76 public: | |
77 DisplayConfiguratorObserver(base::RunLoop* loop) : loop_(loop) {} | |
78 ~DisplayConfiguratorObserver() override {} | |
79 | |
80 private: | |
81 // ui::DisplayConfigurator::Observer overrides: | |
82 void OnDisplayModeChanged( | |
83 const ui::DisplayConfigurator::DisplayStateList& outputs) override { | |
84 if (!loop_) | |
85 return; | |
86 loop_->Quit(); | |
87 loop_ = nullptr; | |
88 } | |
89 void OnDisplayModeChangeFailed( | |
90 ui::MultipleDisplayState failed_new_state) override { | |
91 LOG(FATAL) << "Could not setup display"; | |
92 } | |
93 | |
94 base::RunLoop* loop_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorObserver); | |
97 }; | |
98 | |
73 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { | 99 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { |
74 public: | 100 public: |
75 StubOzoneDelegate() : accelerated_widget_(gfx::kNullAcceleratedWidget) { | 101 StubOzoneDelegate(base::RunLoop* loop) |
102 : accelerated_widget_(gfx::kNullAcceleratedWidget), loop_(loop) { | |
76 ui_thread_gpu_.Initialize(); | 103 ui_thread_gpu_.Initialize(); |
77 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | 104 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
78 this, gfx::Rect()); | 105 this, gfx::Rect()); |
79 } | 106 } |
80 virtual ~StubOzoneDelegate() {} | 107 virtual ~StubOzoneDelegate() {} |
81 | 108 |
82 void OnBoundsChanged(const gfx::Rect& new_bounds) override {} | 109 void OnBoundsChanged(const gfx::Rect& new_bounds) override { |
110 if (!loop_) | |
111 return; | |
112 loop_->Quit(); | |
113 loop_ = nullptr; | |
114 } | |
83 | 115 |
84 void OnDamageRect(const gfx::Rect& damaged_region) override {} | 116 void OnDamageRect(const gfx::Rect& damaged_region) override {} |
85 | 117 |
86 void DispatchEvent(ui::Event* event) override {} | 118 void DispatchEvent(ui::Event* event) override {} |
87 | 119 |
88 void OnCloseRequest() override {} | 120 void OnCloseRequest() override {} |
89 void OnClosed() override {} | 121 void OnClosed() override {} |
90 | 122 |
91 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} | 123 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} |
92 | 124 |
(...skipping 10 matching lines...) Expand all Loading... | |
103 } | 135 } |
104 | 136 |
105 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } | 137 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } |
106 | 138 |
107 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } | 139 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } |
108 | 140 |
109 private: | 141 private: |
110 ui::UiThreadGpu ui_thread_gpu_; | 142 ui::UiThreadGpu ui_thread_gpu_; |
111 scoped_ptr<ui::PlatformWindow> platform_window_; | 143 scoped_ptr<ui::PlatformWindow> platform_window_; |
112 gfx::AcceleratedWidget accelerated_widget_; | 144 gfx::AcceleratedWidget accelerated_widget_; |
145 base::RunLoop* loop_; | |
113 | 146 |
114 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); | 147 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); |
115 }; | 148 }; |
116 | 149 |
117 #endif // defined(USE_OZONE) | 150 #endif // defined(USE_OZONE) |
118 | 151 |
119 RenderingHelperParams::RenderingHelperParams() | 152 RenderingHelperParams::RenderingHelperParams() |
120 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { | 153 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { |
121 } | 154 } |
122 | 155 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 0 /* border width */, | 255 0 /* border width */, |
223 depth, | 256 depth, |
224 CopyFromParent /* class */, | 257 CopyFromParent /* class */, |
225 CopyFromParent /* visual */, | 258 CopyFromParent /* visual */, |
226 (CWBackPixel | CWOverrideRedirect), | 259 (CWBackPixel | CWOverrideRedirect), |
227 &window_attributes); | 260 &window_attributes); |
228 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); | 261 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); |
229 XSelectInput(display, window_, ExposureMask); | 262 XSelectInput(display, window_, ExposureMask); |
230 XMapWindow(display, window_); | 263 XMapWindow(display, window_); |
231 #elif defined(USE_OZONE) | 264 #elif defined(USE_OZONE) |
232 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); | 265 base::RunLoop wait_resize_loop; |
266 | |
267 platform_window_delegate_.reset( | |
268 new RenderingHelper::StubOzoneDelegate(&wait_resize_loop)); | |
233 window_ = platform_window_delegate_->accelerated_widget(); | 269 window_ = platform_window_delegate_->accelerated_widget(); |
234 #if defined(OS_CHROMEOS) | 270 #if defined(OS_CHROMEOS) |
235 display_configurator_.reset(new ui::DisplayConfigurator()); | 271 // We hold onto the main loop here to wait for the DisplayController |
272 // to give us the size of the display so we can create a window of | |
273 // the same size. | |
274 base::MessageLoop::ScopedNestableTaskAllower nest_loop( | |
275 base::MessageLoop::current()); | |
276 base::RunLoop wait_mode_change_loop; | |
277 DisplayConfiguratorObserver display_observer(&wait_mode_change_loop); | |
278 display_configurator_.reset(new ui::DisplayConfigurator); | |
279 display_configurator_->AddObserver(&display_observer); | |
dnicoara
2015/01/21 16:23:57
You can remove all the nested message loops and th
llandwerlin-old
2015/01/21 18:45:51
Done.
| |
236 display_configurator_->Init(true); | 280 display_configurator_->Init(true); |
281 display_configurator_->SetDisplayMode(ui::MULTIPLE_DISPLAY_STATE_SINGLE); | |
Owen Lin
2015/01/23 08:57:38
Why this line is removed ?
dnicoara
2015/01/23 15:10:13
You don't need to set the display mode since Force
| |
237 display_configurator_->ForceInitialConfigure(0); | 282 display_configurator_->ForceInitialConfigure(0); |
283 // Wait for the display to probe the screen's size. | |
284 wait_mode_change_loop.Run(); | |
285 display_configurator_->RemoveObserver(&display_observer); | |
238 platform_window_delegate_->platform_window()->SetBounds( | 286 platform_window_delegate_->platform_window()->SetBounds( |
239 gfx::Rect(display_configurator_->framebuffer_size())); | 287 gfx::Rect(display_configurator_->framebuffer_size())); |
240 #else | 288 #else |
241 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600)); | 289 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600)); |
242 #endif | 290 #endif |
291 // Wait for the window to be resized. | |
292 wait_resize_loop.Run(); | |
dnicoara
2015/01/21 16:23:57
This also needs to be replaced by a "base::RunLoop
llandwerlin-old
2015/01/21 18:45:51
Done.
| |
243 #else | 293 #else |
244 #error unknown platform | 294 #error unknown platform |
245 #endif | 295 #endif |
246 CHECK(window_ != gfx::kNullAcceleratedWidget); | 296 CHECK(window_ != gfx::kNullAcceleratedWidget); |
247 | 297 |
248 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); | 298 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); |
249 screen_size_ = gl_surface_->GetSize(); | 299 screen_size_ = gl_surface_->GetSize(); |
250 | 300 |
251 gl_context_ = gfx::GLContext::CreateGLContext( | 301 gl_context_ = gfx::GLContext::CreateGLContext( |
252 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); | 302 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
782 // When the rendering falls behind, drops frames. | 832 // When the rendering falls behind, drops frames. |
783 while (scheduled_render_time_ < target) { | 833 while (scheduled_render_time_ < target) { |
784 scheduled_render_time_ += frame_duration_; | 834 scheduled_render_time_ += frame_duration_; |
785 DropOneFrameForAllVideos(); | 835 DropOneFrameForAllVideos(); |
786 } | 836 } |
787 | 837 |
788 message_loop_->PostDelayedTask( | 838 message_loop_->PostDelayedTask( |
789 FROM_HERE, render_task_.callback(), target - now); | 839 FROM_HERE, render_task_.callback(), target - now); |
790 } | 840 } |
791 } // namespace content | 841 } // namespace content |
OLD | NEW |