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" |
| 8 #include "base/thread_task_runner_handle.h" |
7 #include "ipc/ipc_message_macros.h" | 9 #include "ipc/ipc_message_macros.h" |
8 #include "ui/display/types/display_mode.h" | 10 #include "ui/display/types/display_mode.h" |
9 #include "ui/display/types/display_snapshot.h" | 11 #include "ui/display/types/display_snapshot.h" |
10 #include "ui/ozone/common/display_util.h" | 12 #include "ui/ozone/common/display_util.h" |
11 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h" | 13 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h" |
12 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
13 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" | 15 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 16 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
15 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" | 17 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" |
16 | 18 |
17 namespace ui { | 19 namespace ui { |
18 | 20 |
| 21 namespace { |
| 22 |
| 23 void MessageProcessedOnMain( |
| 24 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 25 const base::Closure& io_thread_task) { |
| 26 io_thread_task_runner->PostTask(FROM_HERE, io_thread_task); |
| 27 } |
| 28 |
| 29 class DriGpuPlatformSupportMessageFilter : public IPC::MessageFilter { |
| 30 public: |
| 31 DriGpuPlatformSupportMessageFilter(DriWindowDelegateManager* window_manager, |
| 32 IPC::Listener* main_thread_listener) |
| 33 : window_manager_(window_manager), |
| 34 main_thread_listener_(main_thread_listener), |
| 35 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 36 pending_main_thread_operations_(0) {} |
| 37 |
| 38 void OnFilterAdded(IPC::Sender* sender) override { |
| 39 io_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 40 } |
| 41 |
| 42 // This code is meant to be very temporary and only as a special case to fix |
| 43 // cursor movement jank resulting from slowdowns on the gpu main thread. |
| 44 // It handles cursor movement on IO thread when display config is stable |
| 45 // and returns it to main thread during transitions. |
| 46 bool OnMessageReceived(const IPC::Message& message) override { |
| 47 // If this message affects the state needed to set cursor, handle it on |
| 48 // the main thread. If a cursor move message arrives but we haven't |
| 49 // processed the previous main thread message, keep processing on main |
| 50 // until nothing is pending. |
| 51 bool process_move_on_main = pending_main_thread_operations_ && |
| 52 MessageAffectsCursorPosition(message.type()); |
| 53 if (MessageAffectsCursorState(message.type()) || process_move_on_main) { |
| 54 pending_main_thread_operations_++; |
| 55 |
| 56 base::Closure main_thread_message_handler = |
| 57 base::Bind(base::IgnoreResult(&IPC::Listener::OnMessageReceived), |
| 58 base::Unretained(main_thread_listener_), message); |
| 59 main_thread_task_runner_->PostTask(FROM_HERE, |
| 60 main_thread_message_handler); |
| 61 |
| 62 // This is an echo from the main thread to decrement pending ops. |
| 63 // When the main thread is done with the task, it posts back to IO to |
| 64 // signal completion. |
| 65 base::Closure io_thread_task = base::Bind( |
| 66 &DriGpuPlatformSupportMessageFilter::DecrementPendingOperationsOnIO, |
| 67 this); |
| 68 |
| 69 base::Closure message_processed_callback = base::Bind( |
| 70 &MessageProcessedOnMain, io_thread_task_runner_, io_thread_task); |
| 71 main_thread_task_runner_->PostTask(FROM_HERE, message_processed_callback); |
| 72 |
| 73 return true; |
| 74 } |
| 75 |
| 76 // Otherwise, we are in a steady state and it's safe to move cursor on IO. |
| 77 bool handled = true; |
| 78 IPC_BEGIN_MESSAGE_MAP(DriGpuPlatformSupportMessageFilter, message) |
| 79 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorMove, OnCursorMove) |
| 80 IPC_MESSAGE_UNHANDLED(handled = false); |
| 81 IPC_END_MESSAGE_MAP() |
| 82 |
| 83 return handled; |
| 84 } |
| 85 |
| 86 protected: |
| 87 ~DriGpuPlatformSupportMessageFilter() override {} |
| 88 |
| 89 void OnCursorMove(gfx::AcceleratedWidget widget, const gfx::Point& location) { |
| 90 window_manager_->GetWindowDelegate(widget)->MoveCursor(location); |
| 91 } |
| 92 |
| 93 void DecrementPendingOperationsOnIO() { pending_main_thread_operations_--; } |
| 94 |
| 95 bool MessageAffectsCursorState(uint32 message_type) { |
| 96 switch (message_type) { |
| 97 case OzoneGpuMsg_CreateWindowDelegate::ID: |
| 98 case OzoneGpuMsg_DestroyWindowDelegate::ID: |
| 99 case OzoneGpuMsg_WindowBoundsChanged::ID: |
| 100 case OzoneGpuMsg_ConfigureNativeDisplay::ID: |
| 101 case OzoneGpuMsg_DisableNativeDisplay::ID: |
| 102 case OzoneGpuMsg_CursorSet::ID: |
| 103 return true; |
| 104 default: |
| 105 return false; |
| 106 } |
| 107 } |
| 108 |
| 109 bool MessageAffectsCursorPosition(uint32 message_type) { |
| 110 switch (message_type) { |
| 111 case OzoneGpuMsg_CursorMove::ID: |
| 112 return true; |
| 113 default: |
| 114 return false; |
| 115 } |
| 116 } |
| 117 |
| 118 DriWindowDelegateManager* window_manager_; |
| 119 IPC::Listener* main_thread_listener_; |
| 120 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 121 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 122 int32 pending_main_thread_operations_; |
| 123 }; |
| 124 } |
| 125 |
19 DriGpuPlatformSupport::DriGpuPlatformSupport( | 126 DriGpuPlatformSupport::DriGpuPlatformSupport( |
20 DriWrapper* drm, | 127 DriWrapper* drm, |
21 DriWindowDelegateManager* window_manager, | 128 DriWindowDelegateManager* window_manager, |
22 ScreenManager* screen_manager, | 129 ScreenManager* screen_manager, |
23 scoped_ptr<NativeDisplayDelegateDri> ndd) | 130 scoped_ptr<NativeDisplayDelegateDri> ndd) |
24 : sender_(NULL), | 131 : sender_(NULL), |
25 drm_(drm), | 132 drm_(drm), |
26 window_manager_(window_manager), | 133 window_manager_(window_manager), |
27 screen_manager_(screen_manager), | 134 screen_manager_(screen_manager), |
28 ndd_(ndd.Pass()) { | 135 ndd_(ndd.Pass()) { |
| 136 filter_ = new DriGpuPlatformSupportMessageFilter(window_manager, this); |
29 } | 137 } |
30 | 138 |
31 DriGpuPlatformSupport::~DriGpuPlatformSupport() { | 139 DriGpuPlatformSupport::~DriGpuPlatformSupport() { |
32 } | 140 } |
33 | 141 |
34 void DriGpuPlatformSupport::AddHandler(scoped_ptr<GpuPlatformSupport> handler) { | 142 void DriGpuPlatformSupport::AddHandler(scoped_ptr<GpuPlatformSupport> handler) { |
35 handlers_.push_back(handler.release()); | 143 handlers_.push_back(handler.release()); |
36 } | 144 } |
37 | 145 |
38 void DriGpuPlatformSupport::OnChannelEstablished(IPC::Sender* sender) { | 146 void DriGpuPlatformSupport::OnChannelEstablished(IPC::Sender* sender) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 void DriGpuPlatformSupport::OnRemoveGraphicsDevice(const base::FilePath& path) { | 304 void DriGpuPlatformSupport::OnRemoveGraphicsDevice(const base::FilePath& path) { |
197 NOTIMPLEMENTED(); | 305 NOTIMPLEMENTED(); |
198 } | 306 } |
199 | 307 |
200 void DriGpuPlatformSupport::RelinquishGpuResources( | 308 void DriGpuPlatformSupport::RelinquishGpuResources( |
201 const base::Closure& callback) { | 309 const base::Closure& callback) { |
202 callback.Run(); | 310 callback.Run(); |
203 } | 311 } |
204 | 312 |
205 IPC::MessageFilter* DriGpuPlatformSupport::GetMessageFilter() { | 313 IPC::MessageFilter* DriGpuPlatformSupport::GetMessageFilter() { |
206 return nullptr; | 314 return filter_.get(); |
207 } | 315 } |
208 | 316 |
209 } // namespace ui | 317 } // namespace ui |
OLD | NEW |