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 loop_->Quit(); | |
85 } | |
86 void OnDisplayModeChangeFailed( | |
87 ui::MultipleDisplayState failed_new_state) override {} | |
Owen Lin
2015/01/21 08:10:03
Crash the program here ?
LOG(FATAL)
llandwerlin-old
2015/01/21 08:44:19
Acknowledged.
| |
88 | |
89 base::RunLoop* loop_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorObserver); | |
92 }; | |
93 | |
73 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { | 94 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { |
74 public: | 95 public: |
75 StubOzoneDelegate() : accelerated_widget_(gfx::kNullAcceleratedWidget) { | 96 StubOzoneDelegate(base::RunLoop* loop) |
97 : accelerated_widget_(gfx::kNullAcceleratedWidget), loop_(loop) { | |
76 ui_thread_gpu_.Initialize(); | 98 ui_thread_gpu_.Initialize(); |
77 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | 99 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
78 this, gfx::Rect()); | 100 this, gfx::Rect()); |
79 } | 101 } |
80 virtual ~StubOzoneDelegate() {} | 102 virtual ~StubOzoneDelegate() {} |
81 | 103 |
82 void OnBoundsChanged(const gfx::Rect& new_bounds) override {} | 104 void OnBoundsChanged(const gfx::Rect& new_bounds) override { loop_->Quit(); } |
Pawel Osciak
2015/01/21 08:13:35
Does this pass git cl format?
llandwerlin-old
2015/01/21 08:44:19
Yes.
| |
83 | 105 |
84 void OnDamageRect(const gfx::Rect& damaged_region) override {} | 106 void OnDamageRect(const gfx::Rect& damaged_region) override {} |
85 | 107 |
86 void DispatchEvent(ui::Event* event) override {} | 108 void DispatchEvent(ui::Event* event) override {} |
87 | 109 |
88 void OnCloseRequest() override {} | 110 void OnCloseRequest() override {} |
89 void OnClosed() override {} | 111 void OnClosed() override {} |
90 | 112 |
91 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} | 113 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} |
92 | 114 |
(...skipping 10 matching lines...) Expand all Loading... | |
103 } | 125 } |
104 | 126 |
105 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } | 127 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } |
106 | 128 |
107 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } | 129 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } |
108 | 130 |
109 private: | 131 private: |
110 ui::UiThreadGpu ui_thread_gpu_; | 132 ui::UiThreadGpu ui_thread_gpu_; |
111 scoped_ptr<ui::PlatformWindow> platform_window_; | 133 scoped_ptr<ui::PlatformWindow> platform_window_; |
112 gfx::AcceleratedWidget accelerated_widget_; | 134 gfx::AcceleratedWidget accelerated_widget_; |
135 base::RunLoop* loop_; | |
113 | 136 |
114 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); | 137 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); |
115 }; | 138 }; |
116 | 139 |
117 #endif // defined(USE_OZONE) | 140 #endif // defined(USE_OZONE) |
118 | 141 |
119 RenderingHelperParams::RenderingHelperParams() | 142 RenderingHelperParams::RenderingHelperParams() |
120 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { | 143 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { |
121 } | 144 } |
122 | 145 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 0 /* border width */, | 245 0 /* border width */, |
223 depth, | 246 depth, |
224 CopyFromParent /* class */, | 247 CopyFromParent /* class */, |
225 CopyFromParent /* visual */, | 248 CopyFromParent /* visual */, |
226 (CWBackPixel | CWOverrideRedirect), | 249 (CWBackPixel | CWOverrideRedirect), |
227 &window_attributes); | 250 &window_attributes); |
228 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); | 251 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); |
229 XSelectInput(display, window_, ExposureMask); | 252 XSelectInput(display, window_, ExposureMask); |
230 XMapWindow(display, window_); | 253 XMapWindow(display, window_); |
231 #elif defined(USE_OZONE) | 254 #elif defined(USE_OZONE) |
232 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); | 255 scoped_ptr<base::RunLoop> window_loop(new base::RunLoop); |
Owen Lin
2015/01/21 08:10:03
Can we just use a local variable?
base::RunLoop wi
llandwerlin-old
2015/01/21 08:44:19
Acknowledged.
| |
256 | |
257 platform_window_delegate_.reset( | |
258 new RenderingHelper::StubOzoneDelegate(window_loop.get())); | |
Pawel Osciak
2015/01/21 08:13:35
Is it safe to pass a local variable pointer to the
llandwerlin-old
2015/01/21 08:44:19
Thanks, I should reset the class member after the
| |
233 window_ = platform_window_delegate_->accelerated_widget(); | 259 window_ = platform_window_delegate_->accelerated_widget(); |
234 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
235 display_configurator_.reset(new ui::DisplayConfigurator()); | 261 // We hold onto the main loop here to wait for the DisplayController |
262 // to give us the size of the display so we can create a window of | |
263 // the same size. | |
264 base::MessageLoop::ScopedNestableTaskAllower nest_loop( | |
265 base::MessageLoop::current()); | |
266 scoped_ptr<base::RunLoop> display_loop(new base::RunLoop); | |
Owen Lin
2015/01/21 08:10:03
Same. How about renaming it to wait_mode_change_lo
Pawel Osciak
2015/01/21 08:13:35
(new base::RunLoop());
| |
267 scoped_ptr<DisplayConfiguratorObserver> display_observer( | |
268 new DisplayConfiguratorObserver(display_loop.get())); | |
269 display_configurator_.reset(new ui::DisplayConfigurator); | |
270 display_configurator_->AddObserver(display_observer.get()); | |
236 display_configurator_->Init(true); | 271 display_configurator_->Init(true); |
237 display_configurator_->ForceInitialConfigure(0); | 272 display_configurator_->ForceInitialConfigure(0); |
273 display_configurator_->SetDisplayMode(ui::MULTIPLE_DISPLAY_STATE_SINGLE); | |
Owen Lin
2015/01/21 08:10:03
Are we sure the "OnDisplayModeChanged" would be ca
llandwerlin-old
2015/01/21 08:44:19
As far as I can tell the ForceInitialConfigure wil
| |
274 // Wait for the display to be give probe the screen's size. | |
275 display_loop->Run(); | |
276 display_configurator_->RemoveObserver(display_observer.get()); | |
238 platform_window_delegate_->platform_window()->SetBounds( | 277 platform_window_delegate_->platform_window()->SetBounds( |
239 gfx::Rect(display_configurator_->framebuffer_size())); | 278 gfx::Rect(display_configurator_->framebuffer_size())); |
240 #else | 279 #else |
241 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600)); | 280 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600)); |
242 #endif | 281 #endif |
282 // Wait for the window to be resized. | |
Owen Lin
2015/01/21 08:10:03
Here is even more vague. Why we are sure the windo
llandwerlin-old
2015/01/21 08:44:19
We initially create the window with a gfx::Rect()
| |
283 window_loop->Run(); | |
243 #else | 284 #else |
244 #error unknown platform | 285 #error unknown platform |
245 #endif | 286 #endif |
246 CHECK(window_ != gfx::kNullAcceleratedWidget); | 287 CHECK(window_ != gfx::kNullAcceleratedWidget); |
247 | 288 |
248 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); | 289 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); |
249 screen_size_ = gl_surface_->GetSize(); | 290 screen_size_ = gl_surface_->GetSize(); |
250 | 291 |
251 gl_context_ = gfx::GLContext::CreateGLContext( | 292 gl_context_ = gfx::GLContext::CreateGLContext( |
252 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); | 293 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. | 823 // When the rendering falls behind, drops frames. |
783 while (scheduled_render_time_ < target) { | 824 while (scheduled_render_time_ < target) { |
784 scheduled_render_time_ += frame_duration_; | 825 scheduled_render_time_ += frame_duration_; |
785 DropOneFrameForAllVideos(); | 826 DropOneFrameForAllVideos(); |
786 } | 827 } |
787 | 828 |
788 message_loop_->PostDelayedTask( | 829 message_loop_->PostDelayedTask( |
789 FROM_HERE, render_task_.callback(), target - now); | 830 FROM_HERE, render_task_.callback(), target - now); |
790 } | 831 } |
791 } // namespace content | 832 } // namespace content |
OLD | NEW |