OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/dri_gpu_platform_support.h" | 5 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
8 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
9 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
10 #include "ui/display/types/display_mode.h" | 11 #include "ui/display/types/display_mode.h" |
11 #include "ui/display/types/display_snapshot.h" | 12 #include "ui/display/types/display_snapshot.h" |
12 #include "ui/ozone/common/display_util.h" | 13 #include "ui/ozone/common/display_util.h" |
13 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h" | 14 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h" |
14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 15 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
| 16 #include "ui/ozone/platform/dri/dri_helper_thread.h" |
15 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" | 17 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
16 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 18 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
| 19 #include "ui/ozone/platform/dri/dri_wrapper.h" |
17 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" | 20 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" |
| 21 #include "ui/ozone/public/ozone_switches.h" |
18 | 22 |
19 namespace ui { | 23 namespace ui { |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 void MessageProcessedOnMain( | 27 void MessageProcessedOnMain( |
24 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 28 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
25 const base::Closure& io_thread_task) { | 29 const base::Closure& io_thread_task) { |
26 io_thread_task_runner->PostTask(FROM_HERE, io_thread_task); | 30 io_thread_task_runner->PostTask(FROM_HERE, io_thread_task); |
27 } | 31 } |
28 | 32 |
29 class DriGpuPlatformSupportMessageFilter : public IPC::MessageFilter { | 33 class DriGpuPlatformSupportMessageFilter : public IPC::MessageFilter { |
30 public: | 34 public: |
31 DriGpuPlatformSupportMessageFilter(DriWindowDelegateManager* window_manager, | 35 DriGpuPlatformSupportMessageFilter( |
32 IPC::Listener* main_thread_listener) | 36 DriWindowDelegateManager* window_manager, |
| 37 const base::Closure& on_filter_added_callback, |
| 38 IPC::Listener* main_thread_listener) |
33 : window_manager_(window_manager), | 39 : window_manager_(window_manager), |
| 40 on_filter_added_callback_(on_filter_added_callback), |
34 main_thread_listener_(main_thread_listener), | 41 main_thread_listener_(main_thread_listener), |
35 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 42 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
36 pending_main_thread_operations_(0), | 43 pending_main_thread_operations_(0), |
37 cursor_animating_(false) {} | 44 cursor_animating_(false) {} |
38 | 45 |
39 void OnFilterAdded(IPC::Sender* sender) override { | 46 void OnFilterAdded(IPC::Sender* sender) override { |
40 io_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 47 io_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 48 main_thread_task_runner_->PostTask(FROM_HERE, on_filter_added_callback_); |
41 } | 49 } |
42 | 50 |
43 // This code is meant to be very temporary and only as a special case to fix | 51 // This code is meant to be very temporary and only as a special case to fix |
44 // cursor movement jank resulting from slowdowns on the gpu main thread. | 52 // cursor movement jank resulting from slowdowns on the gpu main thread. |
45 // It handles cursor movement on IO thread when display config is stable | 53 // It handles cursor movement on IO thread when display config is stable |
46 // and returns it to main thread during transitions. | 54 // and returns it to main thread during transitions. |
47 bool OnMessageReceived(const IPC::Message& message) override { | 55 bool OnMessageReceived(const IPC::Message& message) override { |
48 // If this message affects the state needed to set cursor, handle it on | 56 // If this message affects the state needed to set cursor, handle it on |
49 // the main thread. If a cursor move message arrives but we haven't | 57 // the main thread. If a cursor move message arrives but we haven't |
50 // processed the previous main thread message, keep processing on main | 58 // processed the previous main thread message, keep processing on main |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 147 |
140 OzoneGpuMsg_CursorSet::Param param; | 148 OzoneGpuMsg_CursorSet::Param param; |
141 if (!OzoneGpuMsg_CursorSet::Read(&message, ¶m)) | 149 if (!OzoneGpuMsg_CursorSet::Read(&message, ¶m)) |
142 return; | 150 return; |
143 | 151 |
144 int frame_delay_ms = get<3>(param); | 152 int frame_delay_ms = get<3>(param); |
145 cursor_animating_ = frame_delay_ms != 0; | 153 cursor_animating_ = frame_delay_ms != 0; |
146 } | 154 } |
147 | 155 |
148 DriWindowDelegateManager* window_manager_; | 156 DriWindowDelegateManager* window_manager_; |
| 157 base::Closure on_filter_added_callback_; |
149 IPC::Listener* main_thread_listener_; | 158 IPC::Listener* main_thread_listener_; |
150 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
151 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
152 int32 pending_main_thread_operations_; | 161 int32 pending_main_thread_operations_; |
153 bool cursor_animating_; | 162 bool cursor_animating_; |
154 }; | 163 }; |
155 } | 164 } |
156 | 165 |
157 DriGpuPlatformSupport::DriGpuPlatformSupport( | 166 DriGpuPlatformSupport::DriGpuPlatformSupport( |
158 DriWrapper* drm, | 167 DriWrapper* drm, |
159 DriWindowDelegateManager* window_manager, | 168 DriWindowDelegateManager* window_manager, |
160 ScreenManager* screen_manager, | 169 ScreenManager* screen_manager, |
161 scoped_ptr<NativeDisplayDelegateDri> ndd) | 170 scoped_ptr<NativeDisplayDelegateDri> ndd) |
162 : sender_(NULL), | 171 : sender_(NULL), |
163 drm_(drm), | 172 drm_(drm), |
164 window_manager_(window_manager), | 173 window_manager_(window_manager), |
165 screen_manager_(screen_manager), | 174 screen_manager_(screen_manager), |
166 ndd_(ndd.Pass()) { | 175 ndd_(ndd.Pass()) { |
167 filter_ = new DriGpuPlatformSupportMessageFilter(window_manager, this); | 176 filter_ = new DriGpuPlatformSupportMessageFilter( |
| 177 window_manager, |
| 178 base::Bind(&DriGpuPlatformSupport::OnFilterAdded, base::Unretained(this)), |
| 179 this); |
168 } | 180 } |
169 | 181 |
170 DriGpuPlatformSupport::~DriGpuPlatformSupport() { | 182 DriGpuPlatformSupport::~DriGpuPlatformSupport() { |
171 } | 183 } |
172 | 184 |
173 void DriGpuPlatformSupport::AddHandler(scoped_ptr<GpuPlatformSupport> handler) { | 185 void DriGpuPlatformSupport::AddHandler(scoped_ptr<GpuPlatformSupport> handler) { |
174 handlers_.push_back(handler.release()); | 186 handlers_.push_back(handler.release()); |
175 } | 187 } |
176 | 188 |
177 void DriGpuPlatformSupport::OnChannelEstablished(IPC::Sender* sender) { | 189 void DriGpuPlatformSupport::OnChannelEstablished(IPC::Sender* sender) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 351 |
340 void DriGpuPlatformSupport::OnRemoveGraphicsDevice(const base::FilePath& path) { | 352 void DriGpuPlatformSupport::OnRemoveGraphicsDevice(const base::FilePath& path) { |
341 NOTIMPLEMENTED(); | 353 NOTIMPLEMENTED(); |
342 } | 354 } |
343 | 355 |
344 void DriGpuPlatformSupport::RelinquishGpuResources( | 356 void DriGpuPlatformSupport::RelinquishGpuResources( |
345 const base::Closure& callback) { | 357 const base::Closure& callback) { |
346 callback.Run(); | 358 callback.Run(); |
347 } | 359 } |
348 | 360 |
| 361 void DriGpuPlatformSupport::OnFilterAdded() { |
| 362 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 363 // Only surfaceless path supports async page flips. So we only initialize the |
| 364 // helper thread if we're using async page flips. |
| 365 if (!helper_thread_.IsRunning() && |
| 366 cmd->HasSwitch(switches::kOzoneUseSurfaceless)) { |
| 367 helper_thread_.Initialize(); |
| 368 drm_->InitializeTaskRunner(helper_thread_.task_runner()); |
| 369 } |
| 370 } |
| 371 |
349 IPC::MessageFilter* DriGpuPlatformSupport::GetMessageFilter() { | 372 IPC::MessageFilter* DriGpuPlatformSupport::GetMessageFilter() { |
350 return filter_.get(); | 373 return filter_.get(); |
351 } | 374 } |
352 | 375 |
353 } // namespace ui | 376 } // namespace ui |
OLD | NEW |