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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/gpu_blacklist.h" | 10 #include "chrome/browser/gpu_blacklist.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void GpuProcessHostUIShim::CreateViewCommandBuffer( | 207 void GpuProcessHostUIShim::CreateViewCommandBuffer( |
208 int32 render_view_id, | 208 int32 render_view_id, |
209 int32 renderer_id, | 209 int32 renderer_id, |
210 const GPUCreateCommandBufferConfig& init_params, | 210 const GPUCreateCommandBufferConfig& init_params, |
211 CreateCommandBufferCallback* callback) { | 211 CreateCommandBufferCallback* callback) { |
212 DCHECK(CalledOnValidThread()); | 212 DCHECK(CalledOnValidThread()); |
213 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); | 213 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
214 ViewID view_id(renderer_id, render_view_id); | |
215 scoped_refptr<ViewSurface> view_surface(new ViewSurface(view_id)); | |
apatrick_chromium
2011/02/10 19:11:19
I can't see where reference counting is needed. Ca
jonathan.backer
2011/02/11 19:42:03
Done. I ref count to add to the map.
| |
214 | 216 |
215 gfx::PluginWindowHandle window = gfx::kNullPluginWindow; | 217 if (view_surface->surface() != gfx::kNullPluginWindow && |
216 RenderProcessHost* process = RenderProcessHost::FromID(renderer_id); | |
217 RenderWidgetHost* host = NULL; | |
218 if (process) { | |
219 host = static_cast<RenderWidgetHost*>( | |
220 process->GetListenerByID(render_view_id)); | |
221 } | |
222 | |
223 RenderWidgetHostView* view = NULL; | |
224 if (host) | |
225 view = host->view(); | |
226 | |
227 if (view) { | |
228 #if defined(OS_LINUX) | |
229 gfx::NativeViewId view_id = NULL; | |
230 view_id = gfx::IdFromNativeView(view->GetNativeView()); | |
231 | |
232 // Lock the window that we will draw into. | |
233 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | |
234 if (!manager->GetPermanentXIDForId(&window, view_id)) { | |
235 DLOG(ERROR) << "Can't find XID for view id " << view_id; | |
236 } | |
237 #elif defined(OS_MACOSX) | |
238 // On Mac OS X we currently pass a (fake) PluginWindowHandle for the | |
239 // window that we draw to. | |
240 window = view->AllocateFakePluginWindowHandle( | |
241 /*opaque=*/true, /*root=*/true); | |
242 #elif defined(OS_WIN) | |
243 // Create a window that we will overlay. | |
244 window = view->GetCompositorHostWindow(); | |
245 #endif | |
246 } | |
247 | |
248 if (window != gfx::kNullPluginWindow && | |
249 Send(new GpuMsg_CreateViewCommandBuffer( | 218 Send(new GpuMsg_CreateViewCommandBuffer( |
250 window, render_view_id, renderer_id, init_params))) { | 219 view_surface->surface(), render_view_id, renderer_id, init_params))) { |
251 create_command_buffer_requests_.push(wrapped_callback); | 220 create_command_buffer_requests_.push(wrapped_callback); |
221 acquired_surfaces_[view_id] = view_surface; | |
apatrick_chromium
2011/02/10 19:11:19
Is it safe to assume that there will be only one r
jonathan.backer
2011/02/11 19:42:03
To my knowledge, only the compositor creates a Vie
| |
252 } else { | 222 } else { |
253 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); | 223 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
254 } | 224 } |
255 } | 225 } |
256 | 226 |
257 void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously( | 227 void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously( |
258 GPUInfo::Level level) { | 228 GPUInfo::Level level) { |
259 DCHECK(CalledOnValidThread()); | 229 DCHECK(CalledOnValidThread()); |
260 Send(new GpuMsg_CollectGraphicsInfo(level)); | 230 Send(new GpuMsg_CollectGraphicsInfo(level)); |
261 } | 231 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 if (route_id == MSG_ROUTING_NONE) | 332 if (route_id == MSG_ROUTING_NONE) |
363 CreateCommandBufferError(callback.release(), route_id); | 333 CreateCommandBufferError(callback.release(), route_id); |
364 else | 334 else |
365 callback->Run(route_id); | 335 callback->Run(route_id); |
366 } | 336 } |
367 } | 337 } |
368 | 338 |
369 void GpuProcessHostUIShim::OnDestroyCommandBuffer( | 339 void GpuProcessHostUIShim::OnDestroyCommandBuffer( |
370 gfx::PluginWindowHandle window, int32 renderer_id, | 340 gfx::PluginWindowHandle window, int32 renderer_id, |
371 int32 render_view_id) { | 341 int32 render_view_id) { |
372 if (!window) | 342 ViewID view_id(renderer_id, render_view_id); |
373 return; | 343 acquired_surfaces_.erase(view_id); |
374 | |
375 #if defined(OS_LINUX) | |
376 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | |
377 manager->ReleasePermanentXID(window); | |
378 #elif defined(OS_MACOSX) || defined(OS_WIN) | |
379 RenderProcessHost* process = RenderProcessHost::FromID(renderer_id); | |
380 RenderWidgetHost* host = NULL; | |
381 if (process) { | |
382 host = static_cast<RenderWidgetHost*>( | |
383 process->GetListenerByID(render_view_id)); | |
384 } | |
385 RenderWidgetHostView* view = NULL; | |
386 if (host) | |
387 view = host->view(); | |
388 | |
389 if (view) { | |
390 #if defined(OS_MACOSX) | |
391 view->DestroyFakePluginWindowHandle(window); | |
392 #elif defined(OS_WIN) | |
393 view->ShowCompositorHostWindow(false); | |
394 #endif | |
395 } | |
396 #endif // defined(OS_MACOSX) || defined(OS_WIN) | |
397 } | 344 } |
398 | 345 |
399 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 346 void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
400 gpu_info_ = gpu_info; | 347 gpu_info_ = gpu_info; |
401 child_process_logging::SetGpuInfo(gpu_info); | 348 child_process_logging::SetGpuInfo(gpu_info); |
402 | 349 |
403 // Used only in testing. | 350 // Used only in testing. |
404 if (gpu_info_collected_callback_.get()) | 351 if (gpu_info_collected_callback_.get()) |
405 gpu_info_collected_callback_->Run(); | 352 gpu_info_collected_callback_->Run(); |
406 } | 353 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 IDR_GPU_BLACKLIST)); | 435 IDR_GPU_BLACKLIST)); |
489 gpu_blacklist_.reset(new GpuBlacklist()); | 436 gpu_blacklist_.reset(new GpuBlacklist()); |
490 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 437 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
491 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) || | 438 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) || |
492 gpu_blacklist_->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) { | 439 gpu_blacklist_->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) { |
493 return true; | 440 return true; |
494 } | 441 } |
495 gpu_blacklist_.reset(NULL); | 442 gpu_blacklist_.reset(NULL); |
496 return false; | 443 return false; |
497 } | 444 } |
445 | |
446 GpuProcessHostUIShim::ViewSurface::ViewSurface(ViewID view_id) | |
447 : view_id_(view_id), surface_(gfx::kNullPluginWindow) { | |
448 RenderWidgetHostView* view = GetRenderWidgetHostView(); | |
449 if (view) | |
450 surface_ = view->AcquireCompositingSurface(); | |
451 } | |
452 | |
453 GpuProcessHostUIShim::ViewSurface::~ViewSurface() { | |
454 if (!surface_) | |
455 return; | |
456 | |
457 RenderWidgetHostView* view = GetRenderWidgetHostView(); | |
458 if (view) | |
459 view->ReleaseCompositingSurface(surface_); | |
460 } | |
461 | |
462 // We do separate lookups for the RenderWidgetHostView when acquiring | |
463 // and releasing surfaces (rather than caching) because the | |
464 // RenderWidgetHostView could die without warning. In such a case, | |
465 // it's the RenderWidgetHostView's responsibility to cleanup. | |
466 RenderWidgetHostView* GpuProcessHostUIShim::ViewSurface:: | |
467 GetRenderWidgetHostView() { | |
468 RenderProcessHost* process = RenderProcessHost::FromID(view_id_.first); | |
469 RenderWidgetHost* host = NULL; | |
470 if (process) { | |
471 host = static_cast<RenderWidgetHost*>( | |
apatrick_chromium
2011/02/10 19:11:19
If the browser process does not trust the renderer
jonathan.backer
2011/02/11 19:42:03
I'm not disagreeing with you, but this is done els
| |
472 process->GetListenerByID(view_id_.second)); | |
473 } | |
474 | |
475 RenderWidgetHostView* view = NULL; | |
476 if (host) | |
477 view = host->view(); | |
478 | |
479 return view; | |
480 } | |
OLD | NEW |