OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "cc/base/histograms.h" | 19 #include "cc/base/histograms.h" |
20 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
21 #include "cc/output/output_surface.h" | 21 #include "cc/output/output_surface.h" |
| 22 #include "cc/output/vulkan_in_process_context_provider.h" |
22 #include "cc/raster/single_thread_task_graph_runner.h" | 23 #include "cc/raster/single_thread_task_graph_runner.h" |
23 #include "cc/raster/task_graph_runner.h" | 24 #include "cc/raster/task_graph_runner.h" |
24 #include "cc/surfaces/onscreen_display_client.h" | 25 #include "cc/surfaces/onscreen_display_client.h" |
25 #include "cc/surfaces/surface_display_output_surface.h" | 26 #include "cc/surfaces/surface_display_output_surface.h" |
26 #include "cc/surfaces/surface_manager.h" | 27 #include "cc/surfaces/surface_manager.h" |
27 #include "content/browser/compositor/browser_compositor_output_surface.h" | 28 #include "content/browser/compositor/browser_compositor_output_surface.h" |
28 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 29 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
29 #include "content/browser/compositor/gl_helper.h" | 30 #include "content/browser/compositor/gl_helper.h" |
30 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 31 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
31 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" | 32 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #elif defined(USE_X11) | 73 #elif defined(USE_X11) |
73 #include "content/browser/compositor/software_output_device_x11.h" | 74 #include "content/browser/compositor/software_output_device_x11.h" |
74 #elif defined(OS_MACOSX) | 75 #elif defined(OS_MACOSX) |
75 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_mac.h" | 76 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_mac.h" |
76 #include "content/browser/compositor/software_output_device_mac.h" | 77 #include "content/browser/compositor/software_output_device_mac.h" |
77 #include "ui/base/cocoa/remote_layer_api.h" | 78 #include "ui/base/cocoa/remote_layer_api.h" |
78 #elif defined(OS_ANDROID) | 79 #elif defined(OS_ANDROID) |
79 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_android.h" | 80 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_android.h" |
80 #endif | 81 #endif |
81 | 82 |
| 83 #if defined(ENABLE_VULKAN) |
| 84 #include "content/browser/compositor/vulkan_browser_compositor_output_surface.h" |
| 85 #endif |
| 86 |
82 using cc::ContextProvider; | 87 using cc::ContextProvider; |
83 using gpu::gles2::GLES2Interface; | 88 using gpu::gles2::GLES2Interface; |
84 | 89 |
85 namespace { | 90 namespace { |
86 | 91 |
87 const int kNumRetriesBeforeSoftwareFallback = 4; | 92 const int kNumRetriesBeforeSoftwareFallback = 4; |
88 | 93 |
89 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> | 94 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> |
90 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 95 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
91 gpu::SurfaceHandle surface_handle) { | 96 gpu::SurfaceHandle surface_handle) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // output_surface_map_ here. | 254 // output_surface_map_ here. |
250 output_surface_map_.Remove(data->surface_id); | 255 output_surface_map_.Remove(data->surface_id); |
251 data->surface = nullptr; | 256 data->surface = nullptr; |
252 } | 257 } |
253 | 258 |
254 #if defined(OS_WIN) | 259 #if defined(OS_WIN) |
255 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 260 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
256 compositor->widget()); | 261 compositor->widget()); |
257 #endif | 262 #endif |
258 | 263 |
259 bool create_gpu_output_surface = | 264 const bool use_vulkan = SharedVulkanContextProvider(); |
| 265 |
| 266 const bool create_gpu_output_surface = |
260 ShouldCreateGpuOutputSurface(compositor.get()); | 267 ShouldCreateGpuOutputSurface(compositor.get()); |
261 if (create_gpu_output_surface) { | 268 if (create_gpu_output_surface && !use_vulkan) { |
262 CauseForGpuLaunch cause = | 269 CauseForGpuLaunch cause = |
263 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 270 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
264 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 271 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
265 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 272 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
266 callback_factory_.GetWeakPtr(), compositor, | 273 callback_factory_.GetWeakPtr(), compositor, |
267 create_gpu_output_surface, 0)); | 274 create_gpu_output_surface, 0)); |
268 } else { | 275 } else { |
269 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0); | 276 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0); |
270 } | 277 } |
271 } | 278 } |
(...skipping 20 matching lines...) Expand all Loading... |
292 << "software compositing on ChromeOS."; | 299 << "software compositing on ChromeOS."; |
293 #endif | 300 #endif |
294 create_gpu_output_surface = false; | 301 create_gpu_output_surface = false; |
295 } | 302 } |
296 | 303 |
297 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
298 gfx::RenderingWindowManager::GetInstance()->RegisterParent( | 305 gfx::RenderingWindowManager::GetInstance()->RegisterParent( |
299 compositor->widget()); | 306 compositor->widget()); |
300 #endif | 307 #endif |
301 | 308 |
| 309 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
| 310 SharedVulkanContextProvider(); |
| 311 |
302 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 312 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
303 if (create_gpu_output_surface) { | 313 if (create_gpu_output_surface && !vulkan_context_provider) { |
304 // Try to reuse existing worker context provider. | 314 // Try to reuse existing worker context provider. |
305 if (shared_worker_context_provider_) { | 315 if (shared_worker_context_provider_) { |
306 bool lost; | 316 bool lost; |
307 { | 317 { |
308 // Note: If context is lost, we delete reference after releasing the | 318 // Note: If context is lost, we delete reference after releasing the |
309 // lock. | 319 // lock. |
310 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); | 320 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); |
311 lost = shared_worker_context_provider_->ContextGL() | 321 lost = shared_worker_context_provider_->ContextGL() |
312 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 322 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
313 } | 323 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 373 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
364 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 374 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
365 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 375 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
366 callback_factory_.GetWeakPtr(), compositor, | 376 callback_factory_.GetWeakPtr(), compositor, |
367 create_gpu_output_surface, num_attempts + 1)); | 377 create_gpu_output_surface, num_attempts + 1)); |
368 return; | 378 return; |
369 } | 379 } |
370 } | 380 } |
371 | 381 |
372 std::unique_ptr<BrowserCompositorOutputSurface> surface; | 382 std::unique_ptr<BrowserCompositorOutputSurface> surface; |
373 if (!create_gpu_output_surface) { | 383 #if defined(ENABLE_VULKAN) |
374 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( | 384 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
375 CreateSoftwareOutputDevice(compositor.get()), | 385 if (vulkan_context_provider) { |
376 compositor->vsync_manager(), compositor->task_runner().get())); | 386 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
377 } else { | 387 vulkan_context_provider, compositor->vsync_manager())); |
378 DCHECK(context_provider); | 388 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
379 const auto& capabilities = context_provider->ContextCapabilities(); | 389 vulkan_surface->Destroy(); |
380 if (!data->surface_id) { | 390 vulkan_surface.reset(); |
381 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( | 391 } else { |
382 context_provider, shared_worker_context_provider_, | 392 surface = std::move(vulkan_surface); |
383 compositor->vsync_manager(), compositor->task_runner().get(), | 393 } |
384 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); | 394 } |
385 } else if (capabilities.surfaceless) { | 395 #endif |
386 GLenum target = GL_TEXTURE_2D; | 396 |
387 GLenum format = GL_RGB; | 397 if (!surface) { |
| 398 if (!create_gpu_output_surface) { |
| 399 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( |
| 400 CreateSoftwareOutputDevice(compositor.get()), |
| 401 compositor->vsync_manager(), compositor->task_runner().get())); |
| 402 } else { |
| 403 DCHECK(context_provider); |
| 404 const auto& capabilities = context_provider->ContextCapabilities(); |
| 405 if (!data->surface_id) { |
| 406 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( |
| 407 context_provider, shared_worker_context_provider_, |
| 408 compositor->vsync_manager(), compositor->task_runner().get(), |
| 409 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); |
| 410 } else if (capabilities.surfaceless) { |
| 411 GLenum target = GL_TEXTURE_2D; |
| 412 GLenum format = GL_RGB; |
388 #if defined(OS_MACOSX) | 413 #if defined(OS_MACOSX) |
389 target = GL_TEXTURE_RECTANGLE_ARB; | 414 target = GL_TEXTURE_RECTANGLE_ARB; |
390 format = GL_RGBA; | 415 format = GL_RGBA; |
391 #endif | 416 #endif |
392 surface = | 417 surface = |
393 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( | 418 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( |
394 context_provider, shared_worker_context_provider_, | 419 context_provider, shared_worker_context_provider_, |
395 data->surface_id, compositor->vsync_manager(), | 420 data->surface_id, compositor->vsync_manager(), |
396 compositor->task_runner().get(), | 421 compositor->task_runner().get(), |
397 CreateOverlayCandidateValidator(compositor->widget()), target, | 422 CreateOverlayCandidateValidator(compositor->widget()), target, |
398 format, BrowserGpuMemoryBufferManager::current())); | 423 format, BrowserGpuMemoryBufferManager::current())); |
399 } else { | 424 } else { |
400 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; | 425 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; |
401 #if !defined(OS_MACOSX) | 426 #if !defined(OS_MACOSX) |
402 // Overlays are only supported on surfaceless output surfaces on Mac. | 427 // Overlays are only supported on surfaceless output surfaces on Mac. |
403 validator = CreateOverlayCandidateValidator(compositor->widget()); | 428 validator = CreateOverlayCandidateValidator(compositor->widget()); |
404 #endif | 429 #endif |
405 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( | 430 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( |
406 context_provider, shared_worker_context_provider_, | 431 context_provider, shared_worker_context_provider_, |
407 compositor->vsync_manager(), compositor->task_runner().get(), | 432 compositor->vsync_manager(), compositor->task_runner().get(), |
408 std::move(validator))); | 433 std::move(validator))); |
| 434 } |
409 } | 435 } |
410 } | 436 } |
411 | 437 |
412 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 438 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
413 // output_surface_map_ here. | 439 // output_surface_map_ here. |
414 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 440 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
415 data->surface = surface.get(); | 441 data->surface = surface.get(); |
416 if (data->reflector) | 442 if (data->reflector) |
417 data->reflector->OnSourceSurfaceReady(data->surface); | 443 data->reflector->OnSourceSurfaceReady(data->surface); |
418 | 444 |
419 #if defined(OS_WIN) | 445 #if defined(OS_WIN) |
420 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 446 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
421 compositor->widget()); | 447 compositor->widget()); |
422 #endif | 448 #endif |
423 | 449 |
424 // This gets a bit confusing. Here we have a ContextProvider in the |surface| | 450 // This gets a bit confusing. Here we have a ContextProvider in the |surface| |
425 // configured to render directly to this widget. We need to make an | 451 // configured to render directly to this widget. We need to make an |
426 // OnscreenDisplayClient associated with that context, then return a | 452 // OnscreenDisplayClient associated with that context, then return a |
427 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 453 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
428 cc::SurfaceManager* manager = surface_manager_.get(); | 454 cc::SurfaceManager* manager = surface_manager_.get(); |
429 std::unique_ptr<cc::OnscreenDisplayClient> display_client( | 455 std::unique_ptr<cc::OnscreenDisplayClient> display_client( |
430 new cc::OnscreenDisplayClient( | 456 new cc::OnscreenDisplayClient( |
431 std::move(surface), manager, HostSharedBitmapManager::current(), | 457 std::move(surface), manager, HostSharedBitmapManager::current(), |
432 BrowserGpuMemoryBufferManager::current(), | 458 BrowserGpuMemoryBufferManager::current(), |
433 compositor->GetRendererSettings(), compositor->task_runner(), | 459 compositor->GetRendererSettings(), compositor->task_runner(), |
434 compositor->surface_id_allocator()->id_namespace())); | 460 compositor->surface_id_allocator()->id_namespace())); |
435 | 461 |
436 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 462 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
437 new cc::SurfaceDisplayOutputSurface( | 463 vulkan_context_provider |
438 manager, compositor->surface_id_allocator(), context_provider, | 464 ? new cc::SurfaceDisplayOutputSurface( |
439 shared_worker_context_provider_)); | 465 manager, compositor->surface_id_allocator(), |
| 466 static_cast<scoped_refptr<cc::VulkanContextProvider>>( |
| 467 vulkan_context_provider)) |
| 468 : new cc::SurfaceDisplayOutputSurface( |
| 469 manager, compositor->surface_id_allocator(), context_provider, |
| 470 shared_worker_context_provider_)); |
440 display_client->set_surface_output_surface(output_surface.get()); | 471 display_client->set_surface_output_surface(output_surface.get()); |
441 output_surface->set_display_client(display_client.get()); | 472 output_surface->set_display_client(display_client.get()); |
442 display_client->display()->Resize(compositor->size()); | 473 display_client->display()->Resize(compositor->size()); |
443 data->display_client = std::move(display_client); | 474 data->display_client = std::move(display_client); |
444 compositor->SetOutputSurface(std::move(output_surface)); | 475 compositor->SetOutputSurface(std::move(output_surface)); |
445 } | 476 } |
446 | 477 |
447 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 478 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
448 ui::Compositor* source_compositor, | 479 ui::Compositor* source_compositor, |
449 ui::Layer* target_layer) { | 480 ui::Layer* target_layer) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 709 |
679 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 710 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
680 observer_list_, | 711 observer_list_, |
681 OnLostResources()); | 712 OnLostResources()); |
682 | 713 |
683 // Kill things that use the shared context before killing the shared context. | 714 // Kill things that use the shared context before killing the shared context. |
684 lost_gl_helper.reset(); | 715 lost_gl_helper.reset(); |
685 lost_shared_main_thread_contexts = NULL; | 716 lost_shared_main_thread_contexts = NULL; |
686 } | 717 } |
687 | 718 |
| 719 scoped_refptr<cc::VulkanInProcessContextProvider> |
| 720 GpuProcessTransportFactory::SharedVulkanContextProvider() { |
| 721 if (!shared_vulkan_context_provider_initialized_) { |
| 722 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 723 switches::kEnableVulkan)) { |
| 724 shared_vulkan_context_provider_ = |
| 725 cc::VulkanInProcessContextProvider::Create(); |
| 726 } |
| 727 |
| 728 shared_vulkan_context_provider_initialized_ = true; |
| 729 } |
| 730 return shared_vulkan_context_provider_; |
| 731 } |
| 732 |
688 } // namespace content | 733 } // namespace content |
OLD | NEW |