| 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_impl.h" | 14 #include "content/browser/gpu/gpu_data_manager_impl.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/gpu/gpu_surface_tracker.h" |
| 17 #include "content/browser/renderer_host/render_process_host_impl.h" | 17 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_view.h" | |
| 20 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/port/browser/render_widget_host_view_port.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 | 22 |
| 23 #if defined(TOOLKIT_USES_GTK) | 23 #if defined(TOOLKIT_USES_GTK) |
| 24 // These two #includes need to come after gpu_messages.h. | 24 // These two #includes need to come after gpu_messages.h. |
| 25 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 26 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
| 27 #include <gdk/gdk.h> // NOLINT | 27 #include <gdk/gdk.h> // NOLINT |
| 28 #include <gdk/gdkx.h> // NOLINT | 28 #include <gdk/gdkx.h> // NOLINT |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::RenderWidgetHostViewPort; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // One of the linux specific headers defines this as a macro. | 36 // One of the linux specific headers defines this as a macro. |
| 36 #ifdef DestroyAll | 37 #ifdef DestroyAll |
| 37 #undef DestroyAll | 38 #undef DestroyAll |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = | 41 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = |
| 41 LAZY_INSTANCE_INITIALIZER; | 42 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 } | 68 } |
| 68 | 69 |
| 69 void Cancel() { cancelled_ = true; } | 70 void Cancel() { cancelled_ = true; } |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 int host_id_; | 73 int host_id_; |
| 73 scoped_ptr<IPC::Message> msg_; | 74 scoped_ptr<IPC::Message> msg_; |
| 74 bool cancelled_; | 75 bool cancelled_; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 RenderWidgetHostViewBase* GetRenderWidgetHostViewFromSurfaceID( | 78 RenderWidgetHostViewPort* GetRenderWidgetHostViewFromSurfaceID( |
| 78 int surface_id) { | 79 int surface_id) { |
| 79 int render_process_id = 0; | 80 int render_process_id = 0; |
| 80 int render_widget_id = 0; | 81 int render_widget_id = 0; |
| 81 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | 82 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( |
| 82 surface_id, &render_process_id, &render_widget_id)) | 83 surface_id, &render_process_id, &render_widget_id)) |
| 83 return NULL; | 84 return NULL; |
| 84 | 85 |
| 85 content::RenderProcessHost* process = | 86 content::RenderProcessHost* process = |
| 86 content::RenderProcessHost::FromID(render_process_id); | 87 content::RenderProcessHost::FromID(render_process_id); |
| 87 if (!process) | 88 if (!process) |
| 88 return NULL; | 89 return NULL; |
| 89 | 90 |
| 90 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( | 91 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( |
| 91 process->GetListenerByID(render_widget_id)); | 92 process->GetListenerByID(render_widget_id)); |
| 92 return host ? RenderWidgetHostViewBase::FromRWHV(host->view()) : NULL; | 93 return host ? RenderWidgetHostViewPort::FromRWHV(host->view()) : NULL; |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace | 96 } // namespace |
| 96 | 97 |
| 97 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { | 98 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { |
| 98 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); | 99 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); |
| 99 if (ui_shim) | 100 if (ui_shim) |
| 100 ui_shim->OnMessageReceived(msg); | 101 ui_shim->OnMessageReceived(msg); |
| 101 } | 102 } |
| 102 | 103 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void GpuProcessHostUIShim::OnResizeView(int32 surface_id, | 239 void GpuProcessHostUIShim::OnResizeView(int32 surface_id, |
| 239 int32 route_id, | 240 int32 route_id, |
| 240 gfx::Size size) { | 241 gfx::Size size) { |
| 241 // Always respond even if the window no longer exists. The GPU process cannot | 242 // Always respond even if the window no longer exists. The GPU process cannot |
| 242 // make progress on the resizing command buffer until it receives the | 243 // make progress on the resizing command buffer until it receives the |
| 243 // response. | 244 // response. |
| 244 ScopedSendOnIOThread delayed_send( | 245 ScopedSendOnIOThread delayed_send( |
| 245 host_id_, | 246 host_id_, |
| 246 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); | 247 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); |
| 247 | 248 |
| 248 RenderWidgetHostViewBase* view = | 249 RenderWidgetHostViewPort* view = |
| 249 GetRenderWidgetHostViewFromSurfaceID(surface_id); | 250 GetRenderWidgetHostViewFromSurfaceID(surface_id); |
| 250 if (!view) | 251 if (!view) |
| 251 return; | 252 return; |
| 252 | 253 |
| 253 gfx::GLSurfaceHandle surface = view->GetCompositingSurface(); | 254 gfx::GLSurfaceHandle surface = view->GetCompositingSurface(); |
| 254 | 255 |
| 255 // Resize the window synchronously. The GPU process must not issue GL | 256 // Resize the window synchronously. The GPU process must not issue GL |
| 256 // calls on the command buffer until the window is the size it expects it | 257 // calls on the command buffer until the window is the size it expects it |
| 257 // to be. | 258 // to be. |
| 258 #if defined(TOOLKIT_USES_GTK) | 259 #if defined(TOOLKIT_USES_GTK) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 282 | 283 |
| 283 void GpuProcessHostUIShim::OnAcceleratedSurfaceNew( | 284 void GpuProcessHostUIShim::OnAcceleratedSurfaceNew( |
| 284 const GpuHostMsg_AcceleratedSurfaceNew_Params& params) { | 285 const GpuHostMsg_AcceleratedSurfaceNew_Params& params) { |
| 285 ScopedSendOnIOThread delayed_send( | 286 ScopedSendOnIOThread delayed_send( |
| 286 host_id_, | 287 host_id_, |
| 287 new AcceleratedSurfaceMsg_NewACK( | 288 new AcceleratedSurfaceMsg_NewACK( |
| 288 params.route_id, | 289 params.route_id, |
| 289 params.surface_handle, | 290 params.surface_handle, |
| 290 TransportDIB::DefaultHandleValue())); | 291 TransportDIB::DefaultHandleValue())); |
| 291 | 292 |
| 292 RenderWidgetHostViewBase* view = GetRenderWidgetHostViewFromSurfaceID( | 293 RenderWidgetHostViewPort* view = GetRenderWidgetHostViewFromSurfaceID( |
| 293 params.surface_id); | 294 params.surface_id); |
| 294 if (!view) | 295 if (!view) |
| 295 return; | 296 return; |
| 296 | 297 |
| 297 uint64 surface_handle = params.surface_handle; | 298 uint64 surface_handle = params.surface_handle; |
| 298 TransportDIB::Handle shm_handle = TransportDIB::DefaultHandleValue(); | 299 TransportDIB::Handle shm_handle = TransportDIB::DefaultHandleValue(); |
| 299 | 300 |
| 300 #if defined(OS_MACOSX) | 301 #if defined(OS_MACOSX) |
| 301 if (params.create_transport_dib) { | 302 if (params.create_transport_dib) { |
| 302 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 303 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 338 |
| 338 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( | 339 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( |
| 339 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 340 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 340 TRACE_EVENT0("renderer", | 341 TRACE_EVENT0("renderer", |
| 341 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); | 342 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); |
| 342 | 343 |
| 343 ScopedSendOnIOThread delayed_send( | 344 ScopedSendOnIOThread delayed_send( |
| 344 host_id_, | 345 host_id_, |
| 345 new AcceleratedSurfaceMsg_BuffersSwappedACK(params.route_id)); | 346 new AcceleratedSurfaceMsg_BuffersSwappedACK(params.route_id)); |
| 346 | 347 |
| 347 RenderWidgetHostViewBase* view = GetRenderWidgetHostViewFromSurfaceID( | 348 RenderWidgetHostViewPort* view = GetRenderWidgetHostViewFromSurfaceID( |
| 348 params.surface_id); | 349 params.surface_id); |
| 349 if (!view) | 350 if (!view) |
| 350 return; | 351 return; |
| 351 | 352 |
| 352 delayed_send.Cancel(); | 353 delayed_send.Cancel(); |
| 353 | 354 |
| 354 // View must send ACK message after next composite. | 355 // View must send ACK message after next composite. |
| 355 view->AcceleratedSurfaceBuffersSwapped(params, host_id_); | 356 view->AcceleratedSurfaceBuffersSwapped(params, host_id_); |
| 356 } | 357 } |
| 357 | 358 |
| 358 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( | 359 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( |
| 359 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { | 360 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { |
| 360 TRACE_EVENT0("renderer", | 361 TRACE_EVENT0("renderer", |
| 361 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); | 362 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); |
| 362 | 363 |
| 363 ScopedSendOnIOThread delayed_send( | 364 ScopedSendOnIOThread delayed_send( |
| 364 host_id_, | 365 host_id_, |
| 365 new AcceleratedSurfaceMsg_PostSubBufferACK(params.route_id)); | 366 new AcceleratedSurfaceMsg_PostSubBufferACK(params.route_id)); |
| 366 | 367 |
| 367 RenderWidgetHostViewBase* view = | 368 RenderWidgetHostViewPort* view = |
| 368 GetRenderWidgetHostViewFromSurfaceID(params.surface_id); | 369 GetRenderWidgetHostViewFromSurfaceID(params.surface_id); |
| 369 if (!view) | 370 if (!view) |
| 370 return; | 371 return; |
| 371 | 372 |
| 372 delayed_send.Cancel(); | 373 delayed_send.Cancel(); |
| 373 | 374 |
| 374 // View must send ACK message after next composite. | 375 // View must send ACK message after next composite. |
| 375 view->AcceleratedSurfacePostSubBuffer(params, host_id_); | 376 view->AcceleratedSurfacePostSubBuffer(params, host_id_); |
| 376 } | 377 } |
| 377 | 378 |
| 378 void GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend(int32 surface_id) { | 379 void GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend(int32 surface_id) { |
| 379 TRACE_EVENT0("renderer", | 380 TRACE_EVENT0("renderer", |
| 380 "GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend"); | 381 "GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend"); |
| 381 | 382 |
| 382 RenderWidgetHostViewBase* view = | 383 RenderWidgetHostViewPort* view = |
| 383 GetRenderWidgetHostViewFromSurfaceID(surface_id); | 384 GetRenderWidgetHostViewFromSurfaceID(surface_id); |
| 384 if (!view) | 385 if (!view) |
| 385 return; | 386 return; |
| 386 | 387 |
| 387 view->AcceleratedSurfaceSuspend(); | 388 view->AcceleratedSurfaceSuspend(); |
| 388 } | 389 } |
| 389 | 390 |
| 390 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 391 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 391 | 392 |
| 392 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( | 393 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( |
| 393 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { | 394 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { |
| 394 RenderWidgetHostViewBase* view = GetRenderWidgetHostViewFromSurfaceID( | 395 RenderWidgetHostViewPort* view = GetRenderWidgetHostViewFromSurfaceID( |
| 395 params.surface_id); | 396 params.surface_id); |
| 396 if (!view) | 397 if (!view) |
| 397 return; | 398 return; |
| 398 view->AcceleratedSurfaceRelease(params.identifier); | 399 view->AcceleratedSurfaceRelease(params.identifier); |
| 399 } | 400 } |
| 400 | 401 |
| 401 #endif | 402 #endif |
| OLD | NEW |