| 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/browser/renderer_host/render_widget_host_view.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 BrowserThread::IO, | 104 BrowserThread::IO, |
| 105 FROM_HERE, | 105 FROM_HERE, |
| 106 new SendOnIOThreadTask(new GpuMsg_Hang())); | 106 new SendOnIOThreadTask(new GpuMsg_Hang())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 const GPUInfo& GpuProcessHostUIShim::gpu_info() const { | 109 const GPUInfo& GpuProcessHostUIShim::gpu_info() const { |
| 110 DCHECK(CalledOnValidThread()); | 110 DCHECK(CalledOnValidThread()); |
| 111 return gpu_info_; | 111 return gpu_info_; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void GpuProcessHostUIShim::OnDestroyCommandBuffer( |
| 115 gfx::PluginWindowHandle window, int32 renderer_id, |
| 116 int32 render_view_id) { |
| 117 if (!window) |
| 118 return; |
| 119 |
| 120 #if defined(OS_LINUX) |
| 121 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 122 manager->ReleasePermanentXID(window); |
| 123 #elif defined(OS_MACOSX) || defined(OS_WIN) |
| 124 RenderViewHost* host = RenderViewHost::FromID(renderer_id, |
| 125 render_view_id); |
| 126 if (!host) |
| 127 return; |
| 128 RenderWidgetHostView* view = host->view(); |
| 129 if (!view) |
| 130 return; |
| 131 #if defined(OS_MACOSX) |
| 132 view->DestroyFakePluginWindowHandle(window); |
| 133 #elif defined(OS_WIN) |
| 134 view->ShowCompositorHostWindow(false); |
| 135 #endif |
| 136 |
| 137 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
| 138 } |
| 139 |
| 114 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 140 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
| 115 gpu_info_ = gpu_info; | 141 gpu_info_ = gpu_info; |
| 116 child_process_logging::SetGpuInfo(gpu_info); | 142 child_process_logging::SetGpuInfo(gpu_info); |
| 117 | 143 |
| 118 // Used only in testing. | 144 // Used only in testing. |
| 119 if (gpu_info_collected_callback_.get()) | 145 if (gpu_info_collected_callback_.get()) |
| 120 gpu_info_collected_callback_->Run(); | 146 gpu_info_collected_callback_->Run(); |
| 121 } | 147 } |
| 122 | 148 |
| 149 bool GpuProcessHostUIShim::OnControlMessageReceived( |
| 150 const IPC::Message& message) { |
| 151 DCHECK(CalledOnValidThread()); |
| 152 |
| 153 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
| 154 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, |
| 155 OnDestroyCommandBuffer) |
| 156 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
| 157 OnGraphicsInfoCollected) |
| 158 #if defined(OS_LINUX) |
| 159 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_ResizeXID, OnResizeXID) |
| 160 #elif defined(OS_MACOSX) |
| 161 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSetIOSurface, |
| 162 OnAcceleratedSurfaceSetIOSurface) |
| 163 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 164 OnAcceleratedSurfaceBuffersSwapped) |
| 165 #elif defined(OS_WIN) |
| 166 IPC_MESSAGE_HANDLER(GpuHostMsg_ScheduleComposite, OnScheduleComposite); |
| 167 #endif |
| 168 IPC_MESSAGE_UNHANDLED_ERROR() |
| 169 IPC_END_MESSAGE_MAP() |
| 170 |
| 171 return true; |
| 172 } |
| 173 |
| 123 namespace { | 174 namespace { |
| 124 | 175 |
| 125 void SendDelayedReply(IPC::Message* reply_msg) { | 176 void SendDelayedReply(IPC::Message* reply_msg) { |
| 126 BrowserThread::PostTask( | 177 BrowserThread::PostTask( |
| 127 BrowserThread::IO, | 178 BrowserThread::IO, |
| 128 FROM_HERE, | 179 FROM_HERE, |
| 129 new SendOnIOThreadTask(reply_msg)); | 180 new SendOnIOThreadTask(reply_msg)); |
| 130 } | 181 } |
| 131 | 182 |
| 132 } // namespace | 183 } // namespace |
| 133 | 184 |
| 134 #if defined(OS_LINUX) | 185 #if defined(OS_LINUX) |
| 135 | 186 |
| 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, | 187 void GpuProcessHostUIShim::OnResizeXID(unsigned long xid, gfx::Size size, |
| 156 IPC::Message *reply_msg) { | 188 IPC::Message *reply_msg) { |
| 157 GdkWindow* window = reinterpret_cast<GdkWindow*>(gdk_xid_table_lookup(xid)); | 189 GdkWindow* window = reinterpret_cast<GdkWindow*>(gdk_xid_table_lookup(xid)); |
| 158 if (window) { | 190 if (window) { |
| 159 Display* display = GDK_WINDOW_XDISPLAY(window); | 191 Display* display = GDK_WINDOW_XDISPLAY(window); |
| 160 gdk_window_resize(window, size.width(), size.height()); | 192 gdk_window_resize(window, size.width(), size.height()); |
| 161 XSync(display, False); | 193 XSync(display, False); |
| 162 } | 194 } |
| 163 | 195 |
| 164 GpuHostMsg_ResizeXID::WriteReplyParams(reply_msg, (window != NULL)); | 196 GpuHostMsg_ResizeXID::WriteReplyParams(reply_msg, (window != NULL)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 params.window, | 228 params.window, |
| 197 params.surface_id, | 229 params.surface_id, |
| 198 // Parameters needed to formulate an acknowledgment. | 230 // Parameters needed to formulate an acknowledgment. |
| 199 params.renderer_id, | 231 params.renderer_id, |
| 200 params.route_id, | 232 params.route_id, |
| 201 params.swap_buffers_count); | 233 params.swap_buffers_count); |
| 202 } | 234 } |
| 203 | 235 |
| 204 #elif defined(OS_WIN) | 236 #elif defined(OS_WIN) |
| 205 | 237 |
| 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 | |
| 226 void GpuProcessHostUIShim::OnScheduleComposite(int renderer_id, | 238 void GpuProcessHostUIShim::OnScheduleComposite(int renderer_id, |
| 227 int render_view_id) { | 239 int render_view_id) { |
| 228 RenderViewHost* host = RenderViewHost::FromID(renderer_id, | 240 RenderViewHost* host = RenderViewHost::FromID(renderer_id, |
| 229 render_view_id); | 241 render_view_id); |
| 230 if (!host) { | 242 if (!host) { |
| 231 return; | 243 return; |
| 232 } | 244 } |
| 233 host->ScheduleComposite(); | 245 host->ScheduleComposite(); |
| 234 } | 246 } |
| 247 |
| 235 #endif | 248 #endif |
| 236 | |
| 237 bool GpuProcessHostUIShim::OnControlMessageReceived( | |
| 238 const IPC::Message& message) { | |
| 239 DCHECK(CalledOnValidThread()); | |
| 240 | |
| 241 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | |
| 242 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | |
| 243 OnGraphicsInfoCollected) | |
| 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) | |
| 256 IPC_MESSAGE_HANDLER(GpuHostMsg_ScheduleComposite, OnScheduleComposite); | |
| 257 #endif | |
| 258 IPC_MESSAGE_UNHANDLED_ERROR() | |
| 259 IPC_END_MESSAGE_MAP() | |
| 260 | |
| 261 return true; | |
| 262 } | |
| OLD | NEW |