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" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 using cc::ContextProvider; | 91 using cc::ContextProvider; |
92 using gpu::gles2::GLES2Interface; | 92 using gpu::gles2::GLES2Interface; |
93 | 93 |
94 namespace { | 94 namespace { |
95 | 95 |
96 const int kNumRetriesBeforeSoftwareFallback = 4; | 96 const int kNumRetriesBeforeSoftwareFallback = 4; |
97 | 97 |
98 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> | 98 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> |
99 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 99 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
100 gpu::SurfaceHandle surface_handle, | 100 gpu::SurfaceHandle surface_handle) { |
101 bool share_resources) { | |
102 DCHECK( | 101 DCHECK( |
103 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); | 102 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); |
104 DCHECK(gpu_channel_host); | 103 DCHECK(gpu_channel_host); |
105 | 104 |
106 // This is called from a few places to create different contexts: | 105 // This is called from a few places to create different contexts: |
107 // - The shared main thread context (offscreen). | 106 // - The shared main thread context (offscreen). |
108 // - The compositor context, which is used by the browser compositor | 107 // - The compositor context, which is used by the browser compositor |
109 // (offscreen) for synchronization mostly, and by the display compositor | 108 // (offscreen) for synchronization mostly, and by the display compositor |
110 // (onscreen) for actual GL drawing. | 109 // (onscreen) for actual GL drawing. |
111 // - The compositor worker context (offscreen) used for GPU raster. | 110 // - The compositor worker context (offscreen) used for GPU raster. |
(...skipping 10 matching lines...) Expand all Loading... |
122 attributes.samples = 0; | 121 attributes.samples = 0; |
123 attributes.sample_buffers = 0; | 122 attributes.sample_buffers = 0; |
124 attributes.bind_generates_resource = false; | 123 attributes.bind_generates_resource = false; |
125 attributes.lose_context_when_out_of_memory = true; | 124 attributes.lose_context_when_out_of_memory = true; |
126 | 125 |
127 bool automatic_flushes = false; | 126 bool automatic_flushes = false; |
128 | 127 |
129 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); | 128 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); |
130 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( | 129 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( |
131 surface_handle, url, gpu_channel_host.get(), attributes, | 130 surface_handle, url, gpu_channel_host.get(), attributes, |
132 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, | 131 gfx::PreferIntegratedGpu, automatic_flushes)); |
133 nullptr)); | |
134 } | 132 } |
135 | 133 |
136 #if defined(OS_MACOSX) | 134 #if defined(OS_MACOSX) |
137 bool IsCALayersDisabledFromCommandLine() { | 135 bool IsCALayersDisabledFromCommandLine() { |
138 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 136 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
139 return command_line->HasSwitch(switches::kDisableMacOverlays); | 137 return command_line->HasSwitch(switches::kDisableMacOverlays); |
140 } | 138 } |
141 #endif | 139 #endif |
142 | 140 |
143 } // namespace | 141 } // namespace |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { | 350 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { |
353 // We attempted to do EstablishGpuChannel already, so we just use | 351 // We attempted to do EstablishGpuChannel already, so we just use |
354 // GetGpuChannel() instead of EstablishGpuChannelSync(). | 352 // GetGpuChannel() instead of EstablishGpuChannelSync(). |
355 gpu_channel_host = | 353 gpu_channel_host = |
356 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); | 354 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); |
357 } | 355 } |
358 | 356 |
359 if (!gpu_channel_host) { | 357 if (!gpu_channel_host) { |
360 shared_worker_context_provider_ = nullptr; | 358 shared_worker_context_provider_ = nullptr; |
361 } else { | 359 } else { |
362 // This context is used for both the browser compositor and the display | |
363 // compositor. | |
364 constexpr bool share_resources = true; | |
365 context_provider = new ContextProviderCommandBuffer( | |
366 CreateContextCommon(gpu_channel_host, data->surface_handle, | |
367 share_resources), | |
368 gpu::SharedMemoryLimits(), DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | |
369 if (!context_provider->BindToCurrentThread()) | |
370 context_provider = nullptr; | |
371 | |
372 if (!shared_worker_context_provider_) { | 360 if (!shared_worker_context_provider_) { |
373 shared_worker_context_provider_ = new ContextProviderCommandBuffer( | 361 shared_worker_context_provider_ = new ContextProviderCommandBuffer( |
374 CreateContextCommon(std::move(gpu_channel_host), | 362 CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle), |
375 gpu::kNullSurfaceHandle, share_resources), | 363 gpu::SharedMemoryLimits(), nullptr, BROWSER_WORKER_CONTEXT); |
376 gpu::SharedMemoryLimits(), BROWSER_WORKER_CONTEXT); | |
377 if (shared_worker_context_provider_->BindToCurrentThread()) | 364 if (shared_worker_context_provider_->BindToCurrentThread()) |
378 shared_worker_context_provider_->SetupLock(); | 365 shared_worker_context_provider_->SetupLock(); |
379 else | 366 else |
380 shared_worker_context_provider_ = nullptr; | 367 shared_worker_context_provider_ = nullptr; |
381 } | 368 } |
| 369 |
| 370 // The |context_provider| is used for both the browser compositor and the |
| 371 // display compositor. It shares resources with the worker context, so if |
| 372 // we failed to make a worker context, just start over and try again. |
| 373 if (shared_worker_context_provider_) { |
| 374 context_provider = new ContextProviderCommandBuffer( |
| 375 CreateContextCommon(std::move(gpu_channel_host), |
| 376 data->surface_handle), |
| 377 gpu::SharedMemoryLimits(), shared_worker_context_provider_.get(), |
| 378 DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| 379 if (!context_provider->BindToCurrentThread()) |
| 380 context_provider = nullptr; |
| 381 } |
382 } | 382 } |
383 | 383 |
384 bool created_gpu_browser_compositor = | 384 bool created_gpu_browser_compositor = |
385 !!context_provider && !!shared_worker_context_provider_; | 385 !!context_provider && !!shared_worker_context_provider_; |
386 | 386 |
387 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", | 387 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", |
388 created_gpu_browser_compositor); | 388 created_gpu_browser_compositor); |
389 | 389 |
390 if (!created_gpu_browser_compositor) { | 390 if (!created_gpu_browser_compositor) { |
391 // Try again. | 391 // Try again. |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 return nullptr; | 676 return nullptr; |
677 CauseForGpuLaunch cause = | 677 CauseForGpuLaunch cause = |
678 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 678 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
679 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 679 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
680 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); | 680 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); |
681 if (!gpu_channel_host) | 681 if (!gpu_channel_host) |
682 return nullptr; | 682 return nullptr; |
683 | 683 |
684 // We need a separate context from the compositor's so that skia and gl_helper | 684 // We need a separate context from the compositor's so that skia and gl_helper |
685 // don't step on each other. | 685 // don't step on each other. |
686 bool share_resources = false; | |
687 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( | 686 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( |
688 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle, | 687 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle), |
689 share_resources), | 688 gpu::SharedMemoryLimits(), nullptr, BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
690 gpu::SharedMemoryLimits(), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); | |
691 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( | 689 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( |
692 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, | 690 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, |
693 callback_factory_.GetWeakPtr())); | 691 callback_factory_.GetWeakPtr())); |
694 if (!shared_main_thread_contexts_->BindToCurrentThread()) | 692 if (!shared_main_thread_contexts_->BindToCurrentThread()) |
695 shared_main_thread_contexts_ = nullptr; | 693 shared_main_thread_contexts_ = nullptr; |
696 return shared_main_thread_contexts_; | 694 return shared_main_thread_contexts_; |
697 } | 695 } |
698 | 696 |
699 GpuProcessTransportFactory::PerCompositorData* | 697 GpuProcessTransportFactory::PerCompositorData* |
700 GpuProcessTransportFactory::CreatePerCompositorData( | 698 GpuProcessTransportFactory::CreatePerCompositorData( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 shared_vulkan_context_provider_ = | 756 shared_vulkan_context_provider_ = |
759 cc::VulkanInProcessContextProvider::Create(); | 757 cc::VulkanInProcessContextProvider::Create(); |
760 } | 758 } |
761 | 759 |
762 shared_vulkan_context_provider_initialized_ = true; | 760 shared_vulkan_context_provider_initialized_ = true; |
763 } | 761 } |
764 return shared_vulkan_context_provider_; | 762 return shared_vulkan_context_provider_; |
765 } | 763 } |
766 | 764 |
767 } // namespace content | 765 } // namespace content |
OLD | NEW |