OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ozone/platform/drm/gpu/drm_thread_message_proxy.h" |
| 6 |
| 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "ipc/ipc_message.h" |
| 9 #include "ipc/ipc_sender.h" |
| 10 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
| 11 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" |
| 12 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 DrmThreadMessageProxy::DrmThreadMessageProxy(DrmThread* drm_thread) |
| 17 : drm_thread_(drm_thread), weak_ptr_factory_(this) {} |
| 18 |
| 19 DrmThreadMessageProxy::~DrmThreadMessageProxy() {} |
| 20 |
| 21 void DrmThreadMessageProxy::OnFilterAdded(IPC::Sender* sender) { |
| 22 sender_ = sender; |
| 23 |
| 24 // The DRM thread needs to be started late since we need to wait for the |
| 25 // sandbox to start. |
| 26 drm_thread_->Start(); |
| 27 } |
| 28 |
| 29 bool DrmThreadMessageProxy::OnMessageReceived(const IPC::Message& message) { |
| 30 bool handled = true; |
| 31 |
| 32 IPC_BEGIN_MESSAGE_MAP(DrmThreadMessageProxy, message) |
| 33 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CreateWindow, OnCreateWindow) |
| 34 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DestroyWindow, OnDestroyWindow) |
| 35 IPC_MESSAGE_HANDLER(OzoneGpuMsg_WindowBoundsChanged, OnWindowBoundsChanged) |
| 36 |
| 37 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorSet, OnCursorSet) |
| 38 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorMove, OnCursorMove) |
| 39 |
| 40 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RefreshNativeDisplays, |
| 41 OnRefreshNativeDisplays) |
| 42 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ConfigureNativeDisplay, |
| 43 OnConfigureNativeDisplay) |
| 44 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DisableNativeDisplay, |
| 45 OnDisableNativeDisplay) |
| 46 IPC_MESSAGE_HANDLER(OzoneGpuMsg_TakeDisplayControl, OnTakeDisplayControl) |
| 47 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RelinquishDisplayControl, |
| 48 OnRelinquishDisplayControl) |
| 49 IPC_MESSAGE_HANDLER(OzoneGpuMsg_AddGraphicsDevice, OnAddGraphicsDevice) |
| 50 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RemoveGraphicsDevice, |
| 51 OnRemoveGraphicsDevice) |
| 52 IPC_MESSAGE_HANDLER(OzoneGpuMsg_GetHDCPState, OnGetHDCPState) |
| 53 IPC_MESSAGE_HANDLER(OzoneGpuMsg_SetHDCPState, OnSetHDCPState) |
| 54 IPC_MESSAGE_HANDLER(OzoneGpuMsg_SetGammaRamp, OnSetGammaRamp); |
| 55 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CheckOverlayCapabilities, |
| 56 OnCheckOverlayCapabilities) |
| 57 IPC_MESSAGE_UNHANDLED(handled = false); |
| 58 IPC_END_MESSAGE_MAP() |
| 59 |
| 60 return handled; |
| 61 } |
| 62 |
| 63 void DrmThreadMessageProxy::OnCreateWindow(gfx::AcceleratedWidget widget) { |
| 64 DCHECK(drm_thread_->IsRunning()); |
| 65 drm_thread_->task_runner()->PostTask( |
| 66 FROM_HERE, base::Bind(&DrmThread::CreateWindow, |
| 67 base::Unretained(drm_thread_), widget)); |
| 68 } |
| 69 |
| 70 void DrmThreadMessageProxy::OnDestroyWindow(gfx::AcceleratedWidget widget) { |
| 71 DCHECK(drm_thread_->IsRunning()); |
| 72 drm_thread_->task_runner()->PostTask( |
| 73 FROM_HERE, base::Bind(&DrmThread::DestroyWindow, |
| 74 base::Unretained(drm_thread_), widget)); |
| 75 } |
| 76 |
| 77 void DrmThreadMessageProxy::OnWindowBoundsChanged(gfx::AcceleratedWidget widget, |
| 78 const gfx::Rect& bounds) { |
| 79 DCHECK(drm_thread_->IsRunning()); |
| 80 drm_thread_->task_runner()->PostTask( |
| 81 FROM_HERE, base::Bind(&DrmThread::SetWindowBounds, |
| 82 base::Unretained(drm_thread_), widget, bounds)); |
| 83 } |
| 84 |
| 85 void DrmThreadMessageProxy::OnCursorSet(gfx::AcceleratedWidget widget, |
| 86 const std::vector<SkBitmap>& bitmaps, |
| 87 const gfx::Point& location, |
| 88 int frame_delay_ms) { |
| 89 DCHECK(drm_thread_->IsRunning()); |
| 90 drm_thread_->task_runner()->PostTask( |
| 91 FROM_HERE, |
| 92 base::Bind(&DrmThread::SetCursor, base::Unretained(drm_thread_), widget, |
| 93 bitmaps, location, frame_delay_ms)); |
| 94 } |
| 95 |
| 96 void DrmThreadMessageProxy::OnCursorMove(gfx::AcceleratedWidget widget, |
| 97 const gfx::Point& location) { |
| 98 DCHECK(drm_thread_->IsRunning()); |
| 99 drm_thread_->task_runner()->PostTask( |
| 100 FROM_HERE, base::Bind(&DrmThread::MoveCursor, |
| 101 base::Unretained(drm_thread_), widget, location)); |
| 102 } |
| 103 |
| 104 void DrmThreadMessageProxy::OnCheckOverlayCapabilities( |
| 105 gfx::AcceleratedWidget widget, |
| 106 const std::vector<OverlayCheck_Params>& overlays) { |
| 107 DCHECK(drm_thread_->IsRunning()); |
| 108 auto callback = |
| 109 base::Bind(&DrmThreadMessageProxy::OnCheckOverlayCapabilitiesCallback, |
| 110 weak_ptr_factory_.GetWeakPtr()); |
| 111 drm_thread_->task_runner()->PostTask( |
| 112 FROM_HERE, base::Bind(&DrmThread::CheckOverlayCapabilities, |
| 113 base::Unretained(drm_thread_), widget, overlays, |
| 114 CreateSafeCallback(callback))); |
| 115 } |
| 116 |
| 117 void DrmThreadMessageProxy::OnRefreshNativeDisplays() { |
| 118 DCHECK(drm_thread_->IsRunning()); |
| 119 auto callback = |
| 120 base::Bind(&DrmThreadMessageProxy::OnRefreshNativeDisplaysCallback, |
| 121 weak_ptr_factory_.GetWeakPtr()); |
| 122 drm_thread_->task_runner()->PostTask( |
| 123 FROM_HERE, |
| 124 base::Bind(&DrmThread::RefreshNativeDisplays, |
| 125 base::Unretained(drm_thread_), CreateSafeCallback(callback))); |
| 126 } |
| 127 |
| 128 void DrmThreadMessageProxy::OnConfigureNativeDisplay( |
| 129 int64_t id, |
| 130 const DisplayMode_Params& mode, |
| 131 const gfx::Point& origin) { |
| 132 DCHECK(drm_thread_->IsRunning()); |
| 133 auto callback = |
| 134 base::Bind(&DrmThreadMessageProxy::OnConfigureNativeDisplayCallback, |
| 135 weak_ptr_factory_.GetWeakPtr()); |
| 136 drm_thread_->task_runner()->PostTask( |
| 137 FROM_HERE, base::Bind(&DrmThread::ConfigureNativeDisplay, |
| 138 base::Unretained(drm_thread_), id, mode, origin, |
| 139 CreateSafeCallback(callback))); |
| 140 } |
| 141 |
| 142 void DrmThreadMessageProxy::OnDisableNativeDisplay(int64_t id) { |
| 143 DCHECK(drm_thread_->IsRunning()); |
| 144 auto callback = |
| 145 base::Bind(&DrmThreadMessageProxy::OnDisableNativeDisplayCallback, |
| 146 weak_ptr_factory_.GetWeakPtr()); |
| 147 drm_thread_->task_runner()->PostTask( |
| 148 FROM_HERE, base::Bind(&DrmThread::DisableNativeDisplay, |
| 149 base::Unretained(drm_thread_), id, |
| 150 CreateSafeCallback(callback))); |
| 151 } |
| 152 |
| 153 void DrmThreadMessageProxy::OnTakeDisplayControl() { |
| 154 DCHECK(drm_thread_->IsRunning()); |
| 155 auto callback = |
| 156 base::Bind(&DrmThreadMessageProxy::OnTakeDisplayControlCallback, |
| 157 weak_ptr_factory_.GetWeakPtr()); |
| 158 drm_thread_->task_runner()->PostTask( |
| 159 FROM_HERE, |
| 160 base::Bind(&DrmThread::TakeDisplayControl, base::Unretained(drm_thread_), |
| 161 CreateSafeCallback(callback))); |
| 162 } |
| 163 |
| 164 void DrmThreadMessageProxy::OnRelinquishDisplayControl() { |
| 165 DCHECK(drm_thread_->IsRunning()); |
| 166 auto callback = |
| 167 base::Bind(&DrmThreadMessageProxy::OnRelinquishDisplayControlCallback, |
| 168 weak_ptr_factory_.GetWeakPtr()); |
| 169 drm_thread_->task_runner()->PostTask( |
| 170 FROM_HERE, |
| 171 base::Bind(&DrmThread::RelinquishDisplayControl, |
| 172 base::Unretained(drm_thread_), CreateSafeCallback(callback))); |
| 173 } |
| 174 |
| 175 void DrmThreadMessageProxy::OnAddGraphicsDevice( |
| 176 const base::FilePath& path, |
| 177 const base::FileDescriptor& fd) { |
| 178 DCHECK(drm_thread_->IsRunning()); |
| 179 drm_thread_->task_runner()->PostTask( |
| 180 FROM_HERE, base::Bind(&DrmThread::AddGraphicsDevice, |
| 181 base::Unretained(drm_thread_), path, fd)); |
| 182 } |
| 183 |
| 184 void DrmThreadMessageProxy::OnRemoveGraphicsDevice(const base::FilePath& path) { |
| 185 DCHECK(drm_thread_->IsRunning()); |
| 186 drm_thread_->task_runner()->PostTask( |
| 187 FROM_HERE, base::Bind(&DrmThread::RemoveGraphicsDevice, |
| 188 base::Unretained(drm_thread_), path)); |
| 189 } |
| 190 |
| 191 void DrmThreadMessageProxy::OnGetHDCPState(int64_t display_id) { |
| 192 DCHECK(drm_thread_->IsRunning()); |
| 193 auto callback = base::Bind(&DrmThreadMessageProxy::OnGetHDCPStateCallback, |
| 194 weak_ptr_factory_.GetWeakPtr()); |
| 195 drm_thread_->task_runner()->PostTask( |
| 196 FROM_HERE, |
| 197 base::Bind(&DrmThread::GetHDCPState, base::Unretained(drm_thread_), |
| 198 display_id, CreateSafeCallback(callback))); |
| 199 } |
| 200 |
| 201 void DrmThreadMessageProxy::OnSetHDCPState(int64_t display_id, |
| 202 HDCPState state) { |
| 203 DCHECK(drm_thread_->IsRunning()); |
| 204 auto callback = base::Bind(&DrmThreadMessageProxy::OnSetHDCPStateCallback, |
| 205 weak_ptr_factory_.GetWeakPtr()); |
| 206 drm_thread_->task_runner()->PostTask( |
| 207 FROM_HERE, |
| 208 base::Bind(&DrmThread::SetHDCPState, base::Unretained(drm_thread_), |
| 209 display_id, state, CreateSafeCallback(callback))); |
| 210 } |
| 211 |
| 212 void DrmThreadMessageProxy::OnSetGammaRamp( |
| 213 int64_t id, |
| 214 const std::vector<GammaRampRGBEntry>& lut) { |
| 215 DCHECK(drm_thread_->IsRunning()); |
| 216 drm_thread_->task_runner()->PostTask( |
| 217 FROM_HERE, base::Bind(&DrmThread::SetGammaRamp, |
| 218 base::Unretained(drm_thread_), id, lut)); |
| 219 } |
| 220 |
| 221 void DrmThreadMessageProxy::OnCheckOverlayCapabilitiesCallback( |
| 222 gfx::AcceleratedWidget widget, |
| 223 const std::vector<OverlayCheck_Params>& overlays) const { |
| 224 sender_->Send(new OzoneHostMsg_OverlayCapabilitiesReceived(widget, overlays)); |
| 225 } |
| 226 |
| 227 void DrmThreadMessageProxy::OnRefreshNativeDisplaysCallback( |
| 228 const std::vector<DisplaySnapshot_Params>& displays) const { |
| 229 sender_->Send(new OzoneHostMsg_UpdateNativeDisplays(displays)); |
| 230 } |
| 231 |
| 232 void DrmThreadMessageProxy::OnConfigureNativeDisplayCallback( |
| 233 int64_t display_id, |
| 234 bool success) const { |
| 235 sender_->Send(new OzoneHostMsg_DisplayConfigured(display_id, success)); |
| 236 } |
| 237 |
| 238 void DrmThreadMessageProxy::OnDisableNativeDisplayCallback(int64_t display_id, |
| 239 bool success) const { |
| 240 sender_->Send(new OzoneHostMsg_DisplayConfigured(display_id, success)); |
| 241 } |
| 242 |
| 243 void DrmThreadMessageProxy::OnTakeDisplayControlCallback(bool success) const { |
| 244 sender_->Send(new OzoneHostMsg_DisplayControlTaken(success)); |
| 245 } |
| 246 |
| 247 void DrmThreadMessageProxy::OnRelinquishDisplayControlCallback( |
| 248 bool success) const { |
| 249 sender_->Send(new OzoneHostMsg_DisplayControlRelinquished(success)); |
| 250 } |
| 251 |
| 252 void DrmThreadMessageProxy::OnGetHDCPStateCallback(int64_t display_id, |
| 253 bool success, |
| 254 HDCPState state) const { |
| 255 sender_->Send(new OzoneHostMsg_HDCPStateReceived(display_id, success, state)); |
| 256 } |
| 257 |
| 258 void DrmThreadMessageProxy::OnSetHDCPStateCallback(int64_t display_id, |
| 259 bool success) const { |
| 260 sender_->Send(new OzoneHostMsg_HDCPStateUpdated(display_id, success)); |
| 261 } |
| 262 |
| 263 } // namespace ui |
OLD | NEW |