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