| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 renderer_id, cause); | 90 renderer_id, cause); |
| 91 if (host) { | 91 if (host) { |
| 92 host->Send(message); | 92 host->Send(message); |
| 93 } else { | 93 } else { |
| 94 delete message; | 94 delete message; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // anonymous namespace | 98 } // anonymous namespace |
| 99 | 99 |
| 100 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 100 #if defined(TOOLKIT_USES_GTK) |
| 101 // Used to put a lock on surfaces so that the window to which the GPU | 101 // Used to put a lock on surfaces so that the window to which the GPU |
| 102 // process is drawing to doesn't disappear while it is drawing when | 102 // process is drawing to doesn't disappear while it is drawing when |
| 103 // a tab is closed. | 103 // a tab is closed. |
| 104 class GpuProcessHost::SurfaceRef { | 104 class GpuProcessHost::SurfaceRef { |
| 105 public: | 105 public: |
| 106 explicit SurfaceRef(gfx::PluginWindowHandle surface); | 106 explicit SurfaceRef(gfx::PluginWindowHandle surface); |
| 107 ~SurfaceRef(); | 107 ~SurfaceRef(); |
| 108 private: | 108 private: |
| 109 gfx::PluginWindowHandle surface_; | 109 gfx::PluginWindowHandle surface_; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) | 112 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) |
| 113 : surface_(surface) { | 113 : surface_(surface) { |
| 114 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | 114 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 115 if (!manager->AddRefPermanentXID(surface_)) { | 115 if (!manager->AddRefPermanentXID(surface_)) { |
| 116 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; | 116 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 GpuProcessHost::SurfaceRef::~SurfaceRef() { | 120 GpuProcessHost::SurfaceRef::~SurfaceRef() { |
| 121 BrowserThread::PostTask(BrowserThread::UI, | 121 BrowserThread::PostTask(BrowserThread::UI, |
| 122 FROM_HERE, | 122 FROM_HERE, |
| 123 new ReleasePermanentXIDDispatcher(surface_)); | 123 new ReleasePermanentXIDDispatcher(surface_)); |
| 124 } | 124 } |
| 125 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 125 #endif // defined(TOOLKIT_USES_GTK) |
| 126 | 126 |
| 127 // This class creates a GPU thread (instead of a GPU process), when running | 127 // This class creates a GPU thread (instead of a GPU process), when running |
| 128 // with --in-process-gpu or --single-process. | 128 // with --in-process-gpu or --single-process. |
| 129 class GpuMainThread : public base::Thread { | 129 class GpuMainThread : public base::Thread { |
| 130 public: | 130 public: |
| 131 explicit GpuMainThread(const std::string& channel_id) | 131 explicit GpuMainThread(const std::string& channel_id) |
| 132 : base::Thread("Chrome_InProcGpuThread"), | 132 : base::Thread("Chrome_InProcGpuThread"), |
| 133 channel_id_(channel_id), | 133 channel_id_(channel_id), |
| 134 gpu_process_(NULL), | 134 gpu_process_(NULL), |
| 135 child_thread_(NULL) { | 135 child_thread_(NULL) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 393 |
| 394 void GpuProcessHost::CreateViewCommandBuffer( | 394 void GpuProcessHost::CreateViewCommandBuffer( |
| 395 gfx::PluginWindowHandle compositing_surface, | 395 gfx::PluginWindowHandle compositing_surface, |
| 396 int32 render_view_id, | 396 int32 render_view_id, |
| 397 int32 renderer_id, | 397 int32 renderer_id, |
| 398 const GPUCreateCommandBufferConfig& init_params, | 398 const GPUCreateCommandBufferConfig& init_params, |
| 399 CreateCommandBufferCallback* callback) { | 399 CreateCommandBufferCallback* callback) { |
| 400 DCHECK(CalledOnValidThread()); | 400 DCHECK(CalledOnValidThread()); |
| 401 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); | 401 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
| 402 | 402 |
| 403 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 403 #if defined(TOOLKIT_USES_GTK) |
| 404 ViewID view_id(renderer_id, render_view_id); | 404 ViewID view_id(renderer_id, render_view_id); |
| 405 | 405 |
| 406 // There should only be one such command buffer (for the compositor). In | 406 // There should only be one such command buffer (for the compositor). In |
| 407 // practice, if the GPU process lost a context, GraphicsContext3D with | 407 // practice, if the GPU process lost a context, GraphicsContext3D with |
| 408 // associated command buffer and view surface will not be gone until new | 408 // associated command buffer and view surface will not be gone until new |
| 409 // one is in place and all layers are reattached. | 409 // one is in place and all layers are reattached. |
| 410 linked_ptr<SurfaceRef> surface_ref; | 410 linked_ptr<SurfaceRef> surface_ref; |
| 411 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 411 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 412 if (it != surface_refs_.end()) | 412 if (it != surface_refs_.end()) |
| 413 surface_ref = (*it).second; | 413 surface_ref = (*it).second; |
| 414 else | 414 else |
| 415 surface_ref.reset(new SurfaceRef(compositing_surface)); | 415 surface_ref.reset(new SurfaceRef(compositing_surface)); |
| 416 #endif // defined(TOOLKIT_USES_GTK) && defined(TOUCH_UI) | 416 #endif // defined(TOOLKIT_USES_GTK) |
| 417 | 417 |
| 418 if (compositing_surface != gfx::kNullPluginWindow && | 418 if (compositing_surface != gfx::kNullPluginWindow && |
| 419 Send(new GpuMsg_CreateViewCommandBuffer( | 419 Send(new GpuMsg_CreateViewCommandBuffer( |
| 420 compositing_surface, render_view_id, renderer_id, init_params))) { | 420 compositing_surface, render_view_id, renderer_id, init_params))) { |
| 421 create_command_buffer_requests_.push(wrapped_callback); | 421 create_command_buffer_requests_.push(wrapped_callback); |
| 422 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 422 #if defined(TOOLKIT_USES_GTK) |
| 423 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( | 423 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( |
| 424 view_id, surface_ref)); | 424 view_id, surface_ref)); |
| 425 #endif | 425 #endif |
| 426 } else { | 426 } else { |
| 427 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); | 427 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 void GpuProcessHost::OnChannelEstablished( | 431 void GpuProcessHost::OnChannelEstablished( |
| 432 const IPC::ChannelHandle& channel_handle) { | 432 const IPC::ChannelHandle& channel_handle) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 if (route_id == MSG_ROUTING_NONE) | 465 if (route_id == MSG_ROUTING_NONE) |
| 466 CreateCommandBufferError(callback.release(), route_id); | 466 CreateCommandBufferError(callback.release(), route_id); |
| 467 else | 467 else |
| 468 callback->Run(route_id); | 468 callback->Run(route_id); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 void GpuProcessHost::OnDestroyCommandBuffer( | 472 void GpuProcessHost::OnDestroyCommandBuffer( |
| 473 gfx::PluginWindowHandle window, int32 renderer_id, | 473 gfx::PluginWindowHandle window, int32 renderer_id, |
| 474 int32 render_view_id) { | 474 int32 render_view_id) { |
| 475 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 475 #if defined(TOOLKIT_USES_GTK) |
| 476 ViewID view_id(renderer_id, render_view_id); | 476 ViewID view_id(renderer_id, render_view_id); |
| 477 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 477 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 478 if (it != surface_refs_.end()) | 478 if (it != surface_refs_.end()) |
| 479 surface_refs_.erase(it); | 479 surface_refs_.erase(it); |
| 480 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 480 #endif // defined(TOOLKIT_USES_GTK) |
| 481 } | 481 } |
| 482 | 482 |
| 483 void GpuProcessHost::OnGraphicsInfoCollected(const content::GPUInfo& gpu_info) { | 483 void GpuProcessHost::OnGraphicsInfoCollected(const content::GPUInfo& gpu_info) { |
| 484 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); | 484 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); |
| 485 } | 485 } |
| 486 | 486 |
| 487 bool GpuProcessHost::CanShutdown() { | 487 bool GpuProcessHost::CanShutdown() { |
| 488 return true; | 488 return true; |
| 489 } | 489 } |
| 490 | 490 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 scoped_ptr<EstablishChannelCallback> wrapped_callback(callback); | 647 scoped_ptr<EstablishChannelCallback> wrapped_callback(callback); |
| 648 wrapped_callback->Run(channel_handle, renderer_process_for_gpu, gpu_info); | 648 wrapped_callback->Run(channel_handle, renderer_process_for_gpu, gpu_info); |
| 649 } | 649 } |
| 650 | 650 |
| 651 void GpuProcessHost::CreateCommandBufferError( | 651 void GpuProcessHost::CreateCommandBufferError( |
| 652 CreateCommandBufferCallback* callback, int32 route_id) { | 652 CreateCommandBufferCallback* callback, int32 route_id) { |
| 653 scoped_ptr<GpuProcessHost::CreateCommandBufferCallback> | 653 scoped_ptr<GpuProcessHost::CreateCommandBufferCallback> |
| 654 wrapped_callback(callback); | 654 wrapped_callback(callback); |
| 655 callback->Run(route_id); | 655 callback->Run(route_id); |
| 656 } | 656 } |
| OLD | NEW |