| 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 "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "app/gfx/gl/gl_implementation.h" | 8 #include "app/gfx/gl/gl_implementation.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 void Run() { | 41 void Run() { |
| 42 GpuProcessHost::Get()->Send(msg_); | 42 GpuProcessHost::Get()->Send(msg_); |
| 43 } | 43 } |
| 44 IPC::Message* msg_; | 44 IPC::Message* msg_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 class GpuProcessHostUIShim::ViewSurface { |
| 50 public: |
| 51 explicit ViewSurface(ViewID view_id); |
| 52 ~ViewSurface(); |
| 53 gfx::PluginWindowHandle surface() { return surface_; } |
| 54 private: |
| 55 RenderWidgetHostView* GetRenderWidgetHostView(); |
| 56 ViewID view_id_; |
| 57 gfx::PluginWindowHandle surface_; |
| 58 }; |
| 59 |
| 60 GpuProcessHostUIShim::ViewSurface::ViewSurface(ViewID view_id) |
| 61 : view_id_(view_id), surface_(gfx::kNullPluginWindow) { |
| 62 RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 63 if (view) |
| 64 surface_ = view->AcquireCompositingSurface(); |
| 65 } |
| 66 |
| 67 GpuProcessHostUIShim::ViewSurface::~ViewSurface() { |
| 68 if (!surface_) |
| 69 return; |
| 70 |
| 71 RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 72 if (view) |
| 73 view->ReleaseCompositingSurface(surface_); |
| 74 } |
| 75 |
| 76 // We do separate lookups for the RenderWidgetHostView when acquiring |
| 77 // and releasing surfaces (rather than caching) because the |
| 78 // RenderWidgetHostView could die without warning. In such a case, |
| 79 // it's the RenderWidgetHostView's responsibility to cleanup. |
| 80 RenderWidgetHostView* GpuProcessHostUIShim::ViewSurface:: |
| 81 GetRenderWidgetHostView() { |
| 82 RenderProcessHost* process = RenderProcessHost::FromID(view_id_.first); |
| 83 RenderWidgetHost* host = NULL; |
| 84 if (process) { |
| 85 host = static_cast<RenderWidgetHost*>( |
| 86 process->GetListenerByID(view_id_.second)); |
| 87 } |
| 88 |
| 89 RenderWidgetHostView* view = NULL; |
| 90 if (host) |
| 91 view = host->view(); |
| 92 |
| 93 return view; |
| 94 } |
| 95 |
| 49 GpuProcessHostUIShim::GpuProcessHostUIShim() | 96 GpuProcessHostUIShim::GpuProcessHostUIShim() |
| 50 : last_routing_id_(1), | 97 : last_routing_id_(1), |
| 51 initialized_(false), | 98 initialized_(false), |
| 52 initialized_successfully_(false), | 99 initialized_successfully_(false), |
| 53 gpu_feature_flags_set_(false) { | 100 gpu_feature_flags_set_(false) { |
| 54 } | 101 } |
| 55 | 102 |
| 56 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 103 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 57 } | 104 } |
| 58 | 105 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 253 } |
| 207 } | 254 } |
| 208 | 255 |
| 209 void GpuProcessHostUIShim::CreateViewCommandBuffer( | 256 void GpuProcessHostUIShim::CreateViewCommandBuffer( |
| 210 int32 render_view_id, | 257 int32 render_view_id, |
| 211 int32 renderer_id, | 258 int32 renderer_id, |
| 212 const GPUCreateCommandBufferConfig& init_params, | 259 const GPUCreateCommandBufferConfig& init_params, |
| 213 CreateCommandBufferCallback* callback) { | 260 CreateCommandBufferCallback* callback) { |
| 214 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
| 215 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); | 262 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
| 263 ViewID view_id(renderer_id, render_view_id); |
| 216 | 264 |
| 217 gfx::PluginWindowHandle window = gfx::kNullPluginWindow; | 265 // We assume that there can only be one such command buffer (for the |
| 218 RenderProcessHost* process = RenderProcessHost::FromID(renderer_id); | 266 // compositor). |
| 219 RenderWidgetHost* host = NULL; | 267 if (acquired_surfaces_.count(view_id) != 0) { |
| 220 if (process) { | 268 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
| 221 host = static_cast<RenderWidgetHost*>( | 269 return; |
| 222 process->GetListenerByID(render_view_id)); | |
| 223 } | 270 } |
| 224 | 271 |
| 225 RenderWidgetHostView* view = NULL; | 272 linked_ptr<ViewSurface> view_surface(new ViewSurface(view_id)); |
| 226 if (host) | |
| 227 view = host->view(); | |
| 228 | 273 |
| 229 if (view) { | 274 if (view_surface->surface() != gfx::kNullPluginWindow && |
| 230 #if defined(OS_LINUX) | |
| 231 gfx::NativeViewId view_id = NULL; | |
| 232 view_id = gfx::IdFromNativeView(view->GetNativeView()); | |
| 233 | |
| 234 // Lock the window that we will draw into. | |
| 235 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | |
| 236 if (!manager->GetPermanentXIDForId(&window, view_id)) { | |
| 237 DLOG(ERROR) << "Can't find XID for view id " << view_id; | |
| 238 } | |
| 239 #elif defined(OS_MACOSX) | |
| 240 // On Mac OS X we currently pass a (fake) PluginWindowHandle for the | |
| 241 // window that we draw to. | |
| 242 window = view->AllocateFakePluginWindowHandle( | |
| 243 /*opaque=*/true, /*root=*/true); | |
| 244 #elif defined(OS_WIN) | |
| 245 // Create a window that we will overlay. | |
| 246 window = view->GetCompositorHostWindow(); | |
| 247 #endif | |
| 248 } | |
| 249 | |
| 250 if (window != gfx::kNullPluginWindow && | |
| 251 Send(new GpuMsg_CreateViewCommandBuffer( | 275 Send(new GpuMsg_CreateViewCommandBuffer( |
| 252 window, render_view_id, renderer_id, init_params))) { | 276 view_surface->surface(), render_view_id, renderer_id, init_params))) { |
| 253 create_command_buffer_requests_.push(wrapped_callback); | 277 create_command_buffer_requests_.push(wrapped_callback); |
| 278 acquired_surfaces_[view_id] = view_surface; |
| 254 } else { | 279 } else { |
| 255 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); | 280 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
| 256 } | 281 } |
| 257 } | 282 } |
| 258 | 283 |
| 259 void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously( | 284 void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously( |
| 260 GPUInfo::Level level) { | 285 GPUInfo::Level level) { |
| 261 DCHECK(CalledOnValidThread()); | 286 DCHECK(CalledOnValidThread()); |
| 262 Send(new GpuMsg_CollectGraphicsInfo(level)); | 287 Send(new GpuMsg_CollectGraphicsInfo(level)); |
| 263 } | 288 } |
| 264 | 289 |
| 265 void GpuProcessHostUIShim::SendAboutGpuCrash() { | 290 void GpuProcessHostUIShim::SendAboutGpuCrash() { |
| 266 DCHECK(CalledOnValidThread()); | 291 DCHECK(CalledOnValidThread()); |
| 267 Send(new GpuMsg_Crash()); | 292 Send(new GpuMsg_Crash()); |
| 268 } | 293 } |
| 269 | 294 |
| 270 void GpuProcessHostUIShim::SendAboutGpuHang() { | 295 void GpuProcessHostUIShim::SendAboutGpuHang() { |
| 271 DCHECK(CalledOnValidThread()); | 296 DCHECK(CalledOnValidThread()); |
| 272 Send(new GpuMsg_Hang()); | 297 Send(new GpuMsg_Hang()); |
| 273 } | 298 } |
| 274 | 299 |
| 275 const GPUInfo& GpuProcessHostUIShim::gpu_info() const { | 300 const GPUInfo& GpuProcessHostUIShim::gpu_info() const { |
| 276 DCHECK(CalledOnValidThread()); | 301 DCHECK(CalledOnValidThread()); |
| 277 return gpu_info_; | 302 return gpu_info_; |
| 278 } | 303 } |
| 279 | 304 |
| 280 void GpuProcessHostUIShim::AddCustomLogMessage(int level, | 305 void GpuProcessHostUIShim::AddCustomLogMessage(int level, |
| 281 const std::string& header, | 306 const std::string& header, |
| 282 const std::string& message) { | 307 const std::string& message) { |
| 283 OnLogMessage(level, header, message); | 308 OnLogMessage(level, header, message); |
| 284 } | 309 } |
| 285 | 310 |
| 286 bool GpuProcessHostUIShim::OnControlMessageReceived( | 311 bool GpuProcessHostUIShim::OnControlMessageReceived( |
| 287 const IPC::Message& message) { | 312 const IPC::Message& message) { |
| 288 DCHECK(CalledOnValidThread()); | 313 DCHECK(CalledOnValidThread()); |
| 289 | 314 |
| 290 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 315 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
| 291 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, | 316 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, |
| 292 OnChannelEstablished) | 317 OnChannelEstablished) |
| 293 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, | 318 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 if (route_id == MSG_ROUTING_NONE) | 407 if (route_id == MSG_ROUTING_NONE) |
| 383 CreateCommandBufferError(callback.release(), route_id); | 408 CreateCommandBufferError(callback.release(), route_id); |
| 384 else | 409 else |
| 385 callback->Run(route_id); | 410 callback->Run(route_id); |
| 386 } | 411 } |
| 387 } | 412 } |
| 388 | 413 |
| 389 void GpuProcessHostUIShim::OnDestroyCommandBuffer( | 414 void GpuProcessHostUIShim::OnDestroyCommandBuffer( |
| 390 gfx::PluginWindowHandle window, int32 renderer_id, | 415 gfx::PluginWindowHandle window, int32 renderer_id, |
| 391 int32 render_view_id) { | 416 int32 render_view_id) { |
| 392 if (!window) | 417 ViewID view_id(renderer_id, render_view_id); |
| 393 return; | 418 acquired_surfaces_.erase(view_id); |
| 394 | |
| 395 #if defined(OS_LINUX) | |
| 396 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | |
| 397 manager->ReleasePermanentXID(window); | |
| 398 #elif defined(OS_MACOSX) || defined(OS_WIN) | |
| 399 RenderProcessHost* process = RenderProcessHost::FromID(renderer_id); | |
| 400 RenderWidgetHost* host = NULL; | |
| 401 if (process) { | |
| 402 host = static_cast<RenderWidgetHost*>( | |
| 403 process->GetListenerByID(render_view_id)); | |
| 404 } | |
| 405 RenderWidgetHostView* view = NULL; | |
| 406 if (host) | |
| 407 view = host->view(); | |
| 408 | |
| 409 if (view) { | |
| 410 #if defined(OS_MACOSX) | |
| 411 view->DestroyFakePluginWindowHandle(window); | |
| 412 #elif defined(OS_WIN) | |
| 413 view->ShowCompositorHostWindow(false); | |
| 414 #endif | |
| 415 } | |
| 416 #endif // defined(OS_MACOSX) || defined(OS_WIN) | |
| 417 } | 419 } |
| 418 | 420 |
| 419 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 421 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
| 420 gpu_info_ = gpu_info; | 422 gpu_info_ = gpu_info; |
| 421 child_process_logging::SetGpuInfo(gpu_info); | 423 child_process_logging::SetGpuInfo(gpu_info); |
| 422 | 424 |
| 423 // Used only in testing. | 425 // Used only in testing. |
| 424 if (gpu_info_collected_callback_.get()) | 426 if (gpu_info_collected_callback_.get()) |
| 425 gpu_info_collected_callback_->Run(); | 427 gpu_info_collected_callback_->Run(); |
| 426 } | 428 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 return true; | 507 return true; |
| 506 static const base::StringPiece gpu_blacklist_json( | 508 static const base::StringPiece gpu_blacklist_json( |
| 507 ResourceBundle::GetSharedInstance().GetRawDataResource( | 509 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 508 IDR_GPU_BLACKLIST)); | 510 IDR_GPU_BLACKLIST)); |
| 509 gpu_blacklist_.reset(new GpuBlacklist()); | 511 gpu_blacklist_.reset(new GpuBlacklist()); |
| 510 if (gpu_blacklist_->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) | 512 if (gpu_blacklist_->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) |
| 511 return true; | 513 return true; |
| 512 gpu_blacklist_.reset(NULL); | 514 gpu_blacklist_.reset(NULL); |
| 513 return false; | 515 return false; |
| 514 } | 516 } |
| 517 |
| OLD | NEW |