| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "content/browser/gpu/gpu_data_manager.h" | 14 #include "content/browser/gpu/gpu_data_manager.h" |
| 15 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
| 16 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 16 #include "content/browser/renderer_host/render_process_host_impl.h" | 17 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
| 18 #include "content/browser/renderer_host/render_widget_host_view.h" | 19 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 19 #include "content/common/gpu/gpu_messages.h" | 20 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 | 22 |
| 22 #if defined(TOOLKIT_USES_GTK) | 23 #if defined(TOOLKIT_USES_GTK) |
| 23 // These two #includes need to come after gpu_messages.h. | 24 // These two #includes need to come after gpu_messages.h. |
| 24 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 25 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 67 } |
| 67 | 68 |
| 68 void Cancel() { cancelled_ = true; } | 69 void Cancel() { cancelled_ = true; } |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 int host_id_; | 72 int host_id_; |
| 72 scoped_ptr<IPC::Message> msg_; | 73 scoped_ptr<IPC::Message> msg_; |
| 73 bool cancelled_; | 74 bool cancelled_; |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 RenderWidgetHostView* GetRenderWidgetHostViewFromID(int render_process_id, | 77 RenderWidgetHostView* GetRenderWidgetHostViewFromSurfaceID(int surface_id) { |
| 77 int render_widget_id) { | 78 int render_process_id = 0; |
| 79 int render_widget_id = 0; |
| 80 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( |
| 81 surface_id, &render_process_id, &render_widget_id)) |
| 82 return NULL; |
| 83 |
| 78 content::RenderProcessHost* process = | 84 content::RenderProcessHost* process = |
| 79 content::RenderProcessHost::FromID(render_process_id); | 85 content::RenderProcessHost::FromID(render_process_id); |
| 80 if (!process) | 86 if (!process) |
| 81 return NULL; | 87 return NULL; |
| 82 | 88 |
| 83 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( | 89 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( |
| 84 process->GetListenerByID(render_widget_id)); | 90 process->GetListenerByID(render_widget_id)); |
| 85 return host ? host->view() : NULL; | 91 return host ? host->view() : NULL; |
| 86 } | 92 } |
| 87 | 93 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 const content::GPUInfo& gpu_info) { | 225 const content::GPUInfo& gpu_info) { |
| 220 // OnGraphicsInfoCollected is sent back after the GPU process successfully | 226 // OnGraphicsInfoCollected is sent back after the GPU process successfully |
| 221 // initializes GL. | 227 // initializes GL. |
| 222 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); | 228 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); |
| 223 | 229 |
| 224 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); | 230 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); |
| 225 } | 231 } |
| 226 | 232 |
| 227 #if defined(TOOLKIT_USES_GTK) || defined(OS_WIN) | 233 #if defined(TOOLKIT_USES_GTK) || defined(OS_WIN) |
| 228 | 234 |
| 229 void GpuProcessHostUIShim::OnResizeView(int32 client_id, | 235 void GpuProcessHostUIShim::OnResizeView(int32 surface_id, |
| 230 int32 render_view_id, | |
| 231 int32 route_id, | 236 int32 route_id, |
| 232 gfx::Size size) { | 237 gfx::Size size) { |
| 233 // Always respond even if the window no longer exists. The GPU process cannot | 238 // Always respond even if the window no longer exists. The GPU process cannot |
| 234 // make progress on the resizing command buffer until it receives the | 239 // make progress on the resizing command buffer until it receives the |
| 235 // response. | 240 // response. |
| 236 ScopedSendOnIOThread delayed_send( | 241 ScopedSendOnIOThread delayed_send( |
| 237 host_id_, | 242 host_id_, |
| 238 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); | 243 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); |
| 239 | 244 |
| 240 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID(client_id, | 245 RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID(surface_id); |
| 241 render_view_id); | |
| 242 if (!view) | 246 if (!view) |
| 243 return; | 247 return; |
| 244 | 248 |
| 245 gfx::PluginWindowHandle handle = view->GetCompositingSurface(); | 249 gfx::PluginWindowHandle handle = view->GetCompositingSurface(); |
| 246 | 250 |
| 247 // Resize the window synchronously. The GPU process must not issue GL | 251 // Resize the window synchronously. The GPU process must not issue GL |
| 248 // calls on the command buffer until the window is the size it expects it | 252 // calls on the command buffer until the window is the size it expects it |
| 249 // to be. | 253 // to be. |
| 250 #if defined(TOOLKIT_USES_GTK) | 254 #if defined(TOOLKIT_USES_GTK) |
| 251 GdkWindow* window = reinterpret_cast<GdkWindow*>( | 255 GdkWindow* window = reinterpret_cast<GdkWindow*>( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 271 #endif | 275 #endif |
| 272 | 276 |
| 273 #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 277 #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 274 | 278 |
| 275 void GpuProcessHostUIShim::OnAcceleratedSurfaceNew( | 279 void GpuProcessHostUIShim::OnAcceleratedSurfaceNew( |
| 276 const GpuHostMsg_AcceleratedSurfaceNew_Params& params) { | 280 const GpuHostMsg_AcceleratedSurfaceNew_Params& params) { |
| 277 ScopedSendOnIOThread delayed_send( | 281 ScopedSendOnIOThread delayed_send( |
| 278 host_id_, | 282 host_id_, |
| 279 new AcceleratedSurfaceMsg_NewACK( | 283 new AcceleratedSurfaceMsg_NewACK( |
| 280 params.route_id, | 284 params.route_id, |
| 281 params.surface_id, | 285 params.surface_handle, |
| 282 TransportDIB::DefaultHandleValue())); | 286 TransportDIB::DefaultHandleValue())); |
| 283 | 287 |
| 284 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( | 288 RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID( |
| 285 params.client_id, params.render_view_id); | 289 params.surface_id); |
| 286 if (!view) | 290 if (!view) |
| 287 return; | 291 return; |
| 288 | 292 |
| 289 uint64 surface_id = params.surface_id; | 293 uint64 surface_handle = params.surface_handle; |
| 290 TransportDIB::Handle surface_handle = TransportDIB::DefaultHandleValue(); | 294 TransportDIB::Handle shm_handle = TransportDIB::DefaultHandleValue(); |
| 291 | 295 |
| 292 #if defined(OS_MACOSX) | 296 #if defined(OS_MACOSX) |
| 293 if (params.create_transport_dib) { | 297 if (params.create_transport_dib) { |
| 294 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 298 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| 295 if (shared_memory->CreateAnonymous(params.width * params.height * 4)) { | 299 if (shared_memory->CreateAnonymous(params.width * params.height * 4)) { |
| 296 // Create a local handle for RWHVMac to map the SHM. | 300 // Create a local handle for RWHVMac to map the SHM. |
| 297 TransportDIB::Handle local_handle; | 301 TransportDIB::Handle local_handle; |
| 298 if (!shared_memory->ShareToProcess(0 /* pid, not needed */, | 302 if (!shared_memory->ShareToProcess(0 /* pid, not needed */, |
| 299 &local_handle)) { | 303 &local_handle)) { |
| 300 return; | 304 return; |
| 301 } else { | 305 } else { |
| 302 view->AcceleratedSurfaceSetTransportDIB(params.window, | 306 view->AcceleratedSurfaceSetTransportDIB(params.window, |
| 303 params.width, | 307 params.width, |
| 304 params.height, | 308 params.height, |
| 305 local_handle); | 309 local_handle); |
| 306 // Create a remote handle for the GPU process to map the SHM. | 310 // Create a remote handle for the GPU process to map the SHM. |
| 307 if (!shared_memory->ShareToProcess(0 /* pid, not needed */, | 311 if (!shared_memory->ShareToProcess(0 /* pid, not needed */, |
| 308 &surface_handle)) { | 312 &shm_handle)) { |
| 309 return; | 313 return; |
| 310 } | 314 } |
| 311 } | 315 } |
| 312 } | 316 } |
| 313 } else { | 317 } else { |
| 314 view->AcceleratedSurfaceSetIOSurface(params.window, | 318 view->AcceleratedSurfaceSetIOSurface(params.window, |
| 315 params.width, | 319 params.width, |
| 316 params.height, | 320 params.height, |
| 317 surface_id); | 321 surface_handle); |
| 318 } | 322 } |
| 319 #else // defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 323 #else // defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 320 view->AcceleratedSurfaceNew( | 324 view->AcceleratedSurfaceNew( |
| 321 params.width, params.height, &surface_id, &surface_handle); | 325 params.width, params.height, &surface_handle, &shm_handle); |
| 322 #endif | 326 #endif |
| 323 delayed_send.Cancel(); | 327 delayed_send.Cancel(); |
| 324 Send(new AcceleratedSurfaceMsg_NewACK( | 328 Send(new AcceleratedSurfaceMsg_NewACK( |
| 325 params.route_id, surface_id, surface_handle)); | 329 params.route_id, surface_handle, shm_handle)); |
| 326 } | 330 } |
| 327 | 331 |
| 328 #endif | 332 #endif |
| 329 | 333 |
| 330 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( | 334 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( |
| 331 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 335 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 332 TRACE_EVENT0("renderer", | 336 TRACE_EVENT0("renderer", |
| 333 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); | 337 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); |
| 334 | 338 |
| 335 ScopedSendOnIOThread delayed_send( | 339 ScopedSendOnIOThread delayed_send( |
| 336 host_id_, | 340 host_id_, |
| 337 new AcceleratedSurfaceMsg_BuffersSwappedACK(params.route_id)); | 341 new AcceleratedSurfaceMsg_BuffersSwappedACK(params.route_id)); |
| 338 | 342 |
| 339 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( | 343 RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID( |
| 340 params.client_id, params.render_view_id); | 344 params.surface_id); |
| 341 if (!view) | 345 if (!view) |
| 342 return; | 346 return; |
| 343 | 347 |
| 344 delayed_send.Cancel(); | 348 delayed_send.Cancel(); |
| 345 | 349 |
| 346 // View must send ACK message after next composite. | 350 // View must send ACK message after next composite. |
| 347 view->AcceleratedSurfaceBuffersSwapped(params, host_id_); | 351 view->AcceleratedSurfaceBuffersSwapped(params, host_id_); |
| 348 } | 352 } |
| 349 | 353 |
| 350 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( | 354 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( |
| 351 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { | 355 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { |
| 352 TRACE_EVENT0("renderer", | 356 TRACE_EVENT0("renderer", |
| 353 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); | 357 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); |
| 354 | 358 |
| 355 ScopedSendOnIOThread delayed_send( | 359 ScopedSendOnIOThread delayed_send( |
| 356 host_id_, | 360 host_id_, |
| 357 new AcceleratedSurfaceMsg_PostSubBufferACK(params.route_id)); | 361 new AcceleratedSurfaceMsg_PostSubBufferACK(params.route_id)); |
| 358 | 362 |
| 359 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( | 363 RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID( |
| 360 params.client_id, params.render_view_id); | 364 params.surface_id); |
| 361 if (!view) | 365 if (!view) |
| 362 return; | 366 return; |
| 363 | 367 |
| 364 delayed_send.Cancel(); | 368 delayed_send.Cancel(); |
| 365 | 369 |
| 366 // View must send ACK message after next composite. | 370 // View must send ACK message after next composite. |
| 367 view->AcceleratedSurfacePostSubBuffer(params, host_id_); | 371 view->AcceleratedSurfacePostSubBuffer(params, host_id_); |
| 368 } | 372 } |
| 369 | 373 |
| 370 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 374 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 371 | 375 |
| 372 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( | 376 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( |
| 373 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { | 377 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { |
| 374 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( | 378 RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID( |
| 375 params.client_id, params.render_view_id); | 379 params.surface_id); |
| 376 if (!view) | 380 if (!view) |
| 377 return; | 381 return; |
| 378 view->AcceleratedSurfaceRelease(params.identifier); | 382 view->AcceleratedSurfaceRelease(params.identifier); |
| 379 } | 383 } |
| 380 | 384 |
| 381 #endif | 385 #endif |
| OLD | NEW |