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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #elif defined(USE_X11) | 72 #elif defined(USE_X11) |
72 #include "content/browser/compositor/software_output_device_x11.h" | 73 #include "content/browser/compositor/software_output_device_x11.h" |
73 #elif defined(OS_MACOSX) | 74 #elif defined(OS_MACOSX) |
74 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_mac.h" | 75 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_mac.h" |
75 #include "content/browser/compositor/software_output_device_mac.h" | 76 #include "content/browser/compositor/software_output_device_mac.h" |
76 #include "ui/base/cocoa/remote_layer_api.h" | 77 #include "ui/base/cocoa/remote_layer_api.h" |
77 #elif defined(OS_ANDROID) | 78 #elif defined(OS_ANDROID) |
78 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_android.h" | 79 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_android.h" |
79 #endif | 80 #endif |
80 | 81 |
82 #if defined(ENABLE_VULKAN) | |
83 #include "content/browser/compositor/vulkan_browser_compositor_output_surface.h" | |
84 #endif | |
85 | |
81 using cc::ContextProvider; | 86 using cc::ContextProvider; |
82 using gpu::gles2::GLES2Interface; | 87 using gpu::gles2::GLES2Interface; |
83 | 88 |
84 namespace { | 89 namespace { |
85 | 90 |
86 const int kNumRetriesBeforeSoftwareFallback = 4; | 91 const int kNumRetriesBeforeSoftwareFallback = 4; |
87 | 92 |
88 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> | 93 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> |
89 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 94 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
90 gpu::SurfaceHandle surface_handle) { | 95 gpu::SurfaceHandle surface_handle) { |
(...skipping 158 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) |
384 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | |
385 if (vulkan_context_provider) { | |
386 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | |
387 vulkan_context_provider, compositor->vsync_manager())); | |
388 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | |
389 vulkan_surface->Destroy(); | |
390 vulkan_surface.reset(); | |
391 } | |
392 } | |
393 | |
394 if (vulkan_surface) { | |
395 surface = std::move(vulkan_surface); | |
396 } else | |
397 #endif | |
piman
2016/04/19 23:42:02
I would really prefer not to interleave compile-ti
David Yen
2016/04/20 17:37:38
Done.
| |
398 if (!create_gpu_output_surface) { | |
374 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( | 399 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( |
375 CreateSoftwareOutputDevice(compositor.get()), | 400 CreateSoftwareOutputDevice(compositor.get()), |
376 compositor->vsync_manager(), compositor->task_runner().get())); | 401 compositor->vsync_manager(), compositor->task_runner().get())); |
377 } else { | 402 } else { |
378 DCHECK(context_provider); | 403 DCHECK(context_provider); |
379 ContextProvider::Capabilities capabilities = | 404 ContextProvider::Capabilities capabilities = |
380 context_provider->ContextCapabilities(); | 405 context_provider->ContextCapabilities(); |
381 if (!data->surface_id) { | 406 if (!data->surface_id) { |
382 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( | 407 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( |
383 context_provider, shared_worker_context_provider_, | 408 context_provider, shared_worker_context_provider_, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 453 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
429 cc::SurfaceManager* manager = surface_manager_.get(); | 454 cc::SurfaceManager* manager = surface_manager_.get(); |
430 std::unique_ptr<cc::OnscreenDisplayClient> display_client( | 455 std::unique_ptr<cc::OnscreenDisplayClient> display_client( |
431 new cc::OnscreenDisplayClient( | 456 new cc::OnscreenDisplayClient( |
432 std::move(surface), manager, HostSharedBitmapManager::current(), | 457 std::move(surface), manager, HostSharedBitmapManager::current(), |
433 BrowserGpuMemoryBufferManager::current(), | 458 BrowserGpuMemoryBufferManager::current(), |
434 compositor->GetRendererSettings(), compositor->task_runner(), | 459 compositor->GetRendererSettings(), compositor->task_runner(), |
435 compositor->surface_id_allocator()->id_namespace())); | 460 compositor->surface_id_allocator()->id_namespace())); |
436 | 461 |
437 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 462 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
438 new cc::SurfaceDisplayOutputSurface( | 463 #if defined(ENABLE_VULKAN) |
439 manager, compositor->surface_id_allocator(), context_provider, | 464 vulkan_context_provider |
440 shared_worker_context_provider_)); | 465 ? new cc::SurfaceDisplayOutputSurface( |
466 manager, compositor->surface_id_allocator(), | |
467 static_cast<scoped_refptr<cc::VulkanContextProvider>>( | |
468 vulkan_context_provider)) | |
469 : | |
470 #endif | |
piman
2016/04/19 23:42:02
Ditto. If we remove the #ifdef for the SurfaceDisp
David Yen
2016/04/20 17:37:38
Done.
| |
471 new cc::SurfaceDisplayOutputSurface( | |
472 manager, compositor->surface_id_allocator(), context_provider, | |
473 shared_worker_context_provider_)); | |
441 display_client->set_surface_output_surface(output_surface.get()); | 474 display_client->set_surface_output_surface(output_surface.get()); |
442 output_surface->set_display_client(display_client.get()); | 475 output_surface->set_display_client(display_client.get()); |
443 display_client->display()->Resize(compositor->size()); | 476 display_client->display()->Resize(compositor->size()); |
444 data->display_client = std::move(display_client); | 477 data->display_client = std::move(display_client); |
445 compositor->SetOutputSurface(std::move(output_surface)); | 478 compositor->SetOutputSurface(std::move(output_surface)); |
446 } | 479 } |
447 | 480 |
448 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 481 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
449 ui::Compositor* source_compositor, | 482 ui::Compositor* source_compositor, |
450 ui::Layer* target_layer) { | 483 ui::Layer* target_layer) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 | 712 |
680 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 713 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
681 observer_list_, | 714 observer_list_, |
682 OnLostResources()); | 715 OnLostResources()); |
683 | 716 |
684 // Kill things that use the shared context before killing the shared context. | 717 // Kill things that use the shared context before killing the shared context. |
685 lost_gl_helper.reset(); | 718 lost_gl_helper.reset(); |
686 lost_shared_main_thread_contexts = NULL; | 719 lost_shared_main_thread_contexts = NULL; |
687 } | 720 } |
688 | 721 |
722 scoped_refptr<cc::VulkanInProcessContextProvider> | |
723 GpuProcessTransportFactory::SharedVulkanContextProvider() { | |
724 if (!shared_vulkan_context_provider_initialized_) { | |
725 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
726 switches::kEnableVulkan)) { | |
727 shared_vulkan_context_provider_ = | |
728 cc::VulkanInProcessContextProvider::Create(); | |
729 } | |
730 | |
731 shared_vulkan_context_provider_initialized_ = true; | |
732 } | |
733 return shared_vulkan_context_provider_; | |
734 } | |
735 | |
689 } // namespace content | 736 } // namespace content |
OLD | NEW |