OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/gpu_process_host_ui_shim.h" | 5 #include "chrome/browser/gpu_process_host_ui_shim.h" |
6 | 6 |
7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
8 #include "chrome/browser/gpu_process_host.h" | 8 #include "chrome/browser/gpu_process_host.h" |
9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
10 #include "chrome/common/child_process_logging.h" | 11 #include "chrome/common/child_process_logging.h" |
11 #include "chrome/common/gpu_messages.h" | 12 #include "chrome/common/gpu_messages.h" |
12 | 13 |
| 14 #if defined(OS_LINUX) |
| 15 // These two #includes need to come after gpu_messages.h. |
| 16 #include <gdk/gdkwindow.h> // NOLINT |
| 17 #include <gdk/gdkx.h> // NOLINT |
| 18 #include "ui/base/x/x11_util.h" |
| 19 #include "gfx/gtk_native_view_id_manager.h" |
| 20 #include "gfx/size.h" |
| 21 #endif // defined(OS_LINUX) |
| 22 |
13 // Tasks used by this file | 23 // Tasks used by this file |
14 namespace { | 24 namespace { |
15 | 25 |
16 class SendOnIOThreadTask : public Task { | 26 class SendOnIOThreadTask : public Task { |
17 public: | 27 public: |
18 explicit SendOnIOThreadTask(IPC::Message* msg) : msg_(msg) { | 28 explicit SendOnIOThreadTask(IPC::Message* msg) : msg_(msg) { |
19 } | 29 } |
20 | 30 |
21 private: | 31 private: |
22 void Run() { | 32 void Run() { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 113 |
104 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 114 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
105 gpu_info_ = gpu_info; | 115 gpu_info_ = gpu_info; |
106 child_process_logging::SetGpuInfo(gpu_info); | 116 child_process_logging::SetGpuInfo(gpu_info); |
107 | 117 |
108 // Used only in testing. | 118 // Used only in testing. |
109 if (gpu_info_collected_callback_.get()) | 119 if (gpu_info_collected_callback_.get()) |
110 gpu_info_collected_callback_->Run(); | 120 gpu_info_collected_callback_->Run(); |
111 } | 121 } |
112 | 122 |
| 123 namespace { |
| 124 |
| 125 void SendDelayedReply(IPC::Message* reply_msg) { |
| 126 BrowserThread::PostTask( |
| 127 BrowserThread::IO, |
| 128 FROM_HERE, |
| 129 new SendOnIOThreadTask(reply_msg)); |
| 130 } |
| 131 |
| 132 } // namespace |
| 133 |
| 134 #if defined(OS_LINUX) |
| 135 |
| 136 void GpuProcessHostUIShim::OnGetViewXID(gfx::NativeViewId id, |
| 137 IPC::Message* reply_msg) { |
| 138 XID xid; |
| 139 |
| 140 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 141 if (!manager->GetPermanentXIDForId(&xid, id)) { |
| 142 DLOG(ERROR) << "Can't find XID for view id " << id; |
| 143 xid = 0; |
| 144 } |
| 145 |
| 146 GpuHostMsg_GetViewXID::WriteReplyParams(reply_msg, xid); |
| 147 SendDelayedReply(reply_msg); |
| 148 } |
| 149 |
| 150 void GpuProcessHostUIShim::OnReleaseXID(unsigned long xid) { |
| 151 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 152 manager->ReleasePermanentXID(xid); |
| 153 } |
| 154 |
| 155 void GpuProcessHostUIShim::OnResizeXID(unsigned long xid, gfx::Size size, |
| 156 IPC::Message *reply_msg) { |
| 157 GdkWindow* window = reinterpret_cast<GdkWindow*>(gdk_xid_table_lookup(xid)); |
| 158 if (window) { |
| 159 Display* display = GDK_WINDOW_XDISPLAY(window); |
| 160 gdk_window_resize(window, size.width(), size.height()); |
| 161 XSync(display, False); |
| 162 } |
| 163 |
| 164 GpuHostMsg_ResizeXID::WriteReplyParams(reply_msg, (window != NULL)); |
| 165 SendDelayedReply(reply_msg); |
| 166 } |
| 167 |
| 168 #elif defined(OS_MACOSX) |
| 169 |
| 170 void GpuProcessHostUIShim::OnAcceleratedSurfaceSetIOSurface( |
| 171 const GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params& params) { |
| 172 RenderViewHost* host = RenderViewHost::FromID(params.renderer_id, |
| 173 params.render_view_id); |
| 174 if (!host) |
| 175 return; |
| 176 RenderWidgetHostView* view = host->view(); |
| 177 if (!view) |
| 178 return; |
| 179 view->AcceleratedSurfaceSetIOSurface(params.window, |
| 180 params.width, |
| 181 params.height, |
| 182 params.identifier); |
| 183 } |
| 184 |
| 185 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( |
| 186 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 187 RenderViewHost* host = RenderViewHost::FromID(params.renderer_id, |
| 188 params.render_view_id); |
| 189 if (!host) |
| 190 return; |
| 191 RenderWidgetHostView* view = host->view(); |
| 192 if (!view) |
| 193 return; |
| 194 view->AcceleratedSurfaceBuffersSwapped( |
| 195 // Parameters needed to swap the IOSurface. |
| 196 params.window, |
| 197 params.surface_id, |
| 198 // Parameters needed to formulate an acknowledgment. |
| 199 params.renderer_id, |
| 200 params.route_id, |
| 201 params.swap_buffers_count); |
| 202 } |
| 203 |
| 204 #elif defined(OS_WIN) |
| 205 |
| 206 void GpuProcessHostUIShim::OnGetCompositorHostWindow( |
| 207 int renderer_id, |
| 208 int render_view_id, |
| 209 IPC::Message* reply_msg) { |
| 210 RenderViewHost* host = RenderViewHost::FromID(renderer_id, |
| 211 render_view_id); |
| 212 if (!host) { |
| 213 GpuHostMsg_GetCompositorHostWindow::WriteReplyParams(reply_msg, |
| 214 gfx::kNullPluginWindow); |
| 215 SendDelayedReply(reply_msg); |
| 216 return; |
| 217 } |
| 218 |
| 219 RenderWidgetHostView* view = host->view(); |
| 220 gfx::PluginWindowHandle id = view->GetCompositorHostWindow(); |
| 221 |
| 222 GpuHostMsg_GetCompositorHostWindow::WriteReplyParams(reply_msg, id); |
| 223 SendDelayedReply(reply_msg); |
| 224 } |
| 225 |
113 void GpuProcessHostUIShim::OnScheduleComposite(int renderer_id, | 226 void GpuProcessHostUIShim::OnScheduleComposite(int renderer_id, |
114 int render_view_id) { | 227 int render_view_id) { |
115 RenderViewHost* host = RenderViewHost::FromID(renderer_id, | 228 RenderViewHost* host = RenderViewHost::FromID(renderer_id, |
116 render_view_id); | 229 render_view_id); |
117 if (!host) { | 230 if (!host) { |
118 return; | 231 return; |
119 } | 232 } |
120 host->ScheduleComposite(); | 233 host->ScheduleComposite(); |
121 } | 234 } |
| 235 #endif |
122 | 236 |
123 bool GpuProcessHostUIShim::OnControlMessageReceived( | 237 bool GpuProcessHostUIShim::OnControlMessageReceived( |
124 const IPC::Message& message) { | 238 const IPC::Message& message) { |
125 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
126 | 240 |
127 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 241 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
128 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | 242 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
129 OnGraphicsInfoCollected) | 243 OnGraphicsInfoCollected) |
130 #if defined(OS_WIN) | 244 #if defined(OS_LINUX) |
| 245 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_GetViewXID, OnGetViewXID) |
| 246 IPC_MESSAGE_HANDLER(GpuHostMsg_ReleaseXID, OnReleaseXID) |
| 247 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_ResizeXID, OnResizeXID) |
| 248 #elif defined(OS_MACOSX) |
| 249 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSetIOSurface, |
| 250 OnAcceleratedSurfaceSetIOSurface) |
| 251 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 252 OnAcceleratedSurfaceBuffersSwapped) |
| 253 #elif defined(OS_WIN) |
| 254 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_GetCompositorHostWindow, |
| 255 OnGetCompositorHostWindow) |
131 IPC_MESSAGE_HANDLER(GpuHostMsg_ScheduleComposite, OnScheduleComposite); | 256 IPC_MESSAGE_HANDLER(GpuHostMsg_ScheduleComposite, OnScheduleComposite); |
132 #endif | 257 #endif |
133 IPC_MESSAGE_UNHANDLED_ERROR() | 258 IPC_MESSAGE_UNHANDLED_ERROR() |
134 IPC_END_MESSAGE_MAP() | 259 IPC_END_MESSAGE_MAP() |
135 | 260 |
136 return true; | 261 return true; |
137 } | 262 } |
OLD | NEW |