| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 using cc::ContextProvider; | 82 using cc::ContextProvider; |
| 83 using gpu::gles2::GLES2Interface; | 83 using gpu::gles2::GLES2Interface; |
| 84 | 84 |
| 85 namespace { | 85 namespace { |
| 86 | 86 |
| 87 const int kNumRetriesBeforeSoftwareFallback = 4; | 87 const int kNumRetriesBeforeSoftwareFallback = 4; |
| 88 | 88 |
| 89 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> | 89 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> |
| 90 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 90 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 91 gpu::SurfaceHandle surface_handle) { | 91 gpu::SurfaceHandle surface_handle, |
| 92 bool share_resources) { |
| 92 DCHECK( | 93 DCHECK( |
| 93 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); | 94 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); |
| 94 DCHECK(gpu_channel_host); | 95 DCHECK(gpu_channel_host); |
| 95 | 96 |
| 96 // This is called from a few places to create different contexts: | 97 // This is called from a few places to create different contexts: |
| 97 // - The shared main thread context (offscreen). | 98 // - The shared main thread context (offscreen). |
| 98 // - The compositor context, which is used by the browser compositor | 99 // - The compositor context, which is used by the browser compositor |
| 99 // (offscreen) for synchronization mostly, and by the display compositor | 100 // (offscreen) for synchronization mostly, and by the display compositor |
| 100 // (onscreen) for actual GL drawing. | 101 // (onscreen) for actual GL drawing. |
| 101 // - The compositor worker context (offscreen) used for GPU raster. | 102 // - The compositor worker context (offscreen) used for GPU raster. |
| 102 // So ask for capabilities needed by any of these cases (we can optimize by | 103 // So ask for capabilities needed by any of these cases (we can optimize by |
| 103 // branching on |surface_handle| being null if these needs diverge). | 104 // branching on |surface_handle| being null if these needs diverge). |
| 104 // | 105 // |
| 105 // The default framebuffer for an offscreen context is not used, so it does | 106 // The default framebuffer for an offscreen context is not used, so it does |
| 106 // not need alpha, stencil, depth, antialiasing. The display compositor does | 107 // not need alpha, stencil, depth, antialiasing. The display compositor does |
| 107 // not use these things either, so we can request nothing here. | 108 // not use these things either, so we can request nothing here. |
| 108 gpu::gles2::ContextCreationAttribHelper attributes; | 109 gpu::gles2::ContextCreationAttribHelper attributes; |
| 109 attributes.alpha_size = -1; | 110 attributes.alpha_size = -1; |
| 110 attributes.depth_size = 0; | 111 attributes.depth_size = 0; |
| 111 attributes.stencil_size = 0; | 112 attributes.stencil_size = 0; |
| 112 attributes.samples = 0; | 113 attributes.samples = 0; |
| 113 attributes.sample_buffers = 0; | 114 attributes.sample_buffers = 0; |
| 114 attributes.bind_generates_resource = false; | 115 attributes.bind_generates_resource = false; |
| 115 attributes.lose_context_when_out_of_memory = true; | 116 attributes.lose_context_when_out_of_memory = true; |
| 116 | 117 |
| 117 bool share_resources = true; | |
| 118 bool automatic_flushes = false; | 118 bool automatic_flushes = false; |
| 119 | 119 |
| 120 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); | 120 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); |
| 121 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( | 121 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( |
| 122 surface_handle, url, gpu_channel_host.get(), attributes, | 122 surface_handle, url, gpu_channel_host.get(), attributes, |
| 123 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, | 123 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, |
| 124 nullptr)); | 124 nullptr)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace | 127 } // namespace |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (!gpu_channel_host) { | 326 if (!gpu_channel_host) { |
| 327 shared_worker_context_provider_ = nullptr; | 327 shared_worker_context_provider_ = nullptr; |
| 328 } else { | 328 } else { |
| 329 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 329 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 330 gpu::SurfaceHandle surface_handle = | 330 gpu::SurfaceHandle surface_handle = |
| 331 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id) | 331 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id) |
| 332 : gpu::kNullSurfaceHandle; | 332 : gpu::kNullSurfaceHandle; |
| 333 | 333 |
| 334 // This context is used for both the browser compositor and the display | 334 // This context is used for both the browser compositor and the display |
| 335 // compositor. | 335 // compositor. |
| 336 constexpr bool share_resources = true; |
| 336 context_provider = new ContextProviderCommandBuffer( | 337 context_provider = new ContextProviderCommandBuffer( |
| 337 CreateContextCommon(gpu_channel_host, surface_handle), | 338 CreateContextCommon(gpu_channel_host, surface_handle, |
| 339 share_resources), |
| 338 gpu::SharedMemoryLimits(), DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | 340 gpu::SharedMemoryLimits(), DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| 339 if (!context_provider->BindToCurrentThread()) | 341 if (!context_provider->BindToCurrentThread()) |
| 340 context_provider = nullptr; | 342 context_provider = nullptr; |
| 341 | 343 |
| 342 if (!shared_worker_context_provider_) { | 344 if (!shared_worker_context_provider_) { |
| 343 shared_worker_context_provider_ = new ContextProviderCommandBuffer( | 345 shared_worker_context_provider_ = new ContextProviderCommandBuffer( |
| 344 CreateContextCommon(std::move(gpu_channel_host), | 346 CreateContextCommon(std::move(gpu_channel_host), |
| 345 gpu::kNullSurfaceHandle), | 347 gpu::kNullSurfaceHandle, share_resources), |
| 346 gpu::SharedMemoryLimits(), BROWSER_WORKER_CONTEXT); | 348 gpu::SharedMemoryLimits(), BROWSER_WORKER_CONTEXT); |
| 347 if (shared_worker_context_provider_->BindToCurrentThread()) | 349 if (shared_worker_context_provider_->BindToCurrentThread()) |
| 348 shared_worker_context_provider_->SetupLock(); | 350 shared_worker_context_provider_->SetupLock(); |
| 349 else | 351 else |
| 350 shared_worker_context_provider_ = nullptr; | 352 shared_worker_context_provider_ = nullptr; |
| 351 } | 353 } |
| 352 } | 354 } |
| 353 | 355 |
| 354 bool created_gpu_browser_compositor = | 356 bool created_gpu_browser_compositor = |
| 355 !!context_provider && !!shared_worker_context_provider_; | 357 !!context_provider && !!shared_worker_context_provider_; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 return nullptr; | 620 return nullptr; |
| 619 CauseForGpuLaunch cause = | 621 CauseForGpuLaunch cause = |
| 620 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 622 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 621 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 623 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 622 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); | 624 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); |
| 623 if (!gpu_channel_host) | 625 if (!gpu_channel_host) |
| 624 return nullptr; | 626 return nullptr; |
| 625 | 627 |
| 626 // We need a separate context from the compositor's so that skia and gl_helper | 628 // We need a separate context from the compositor's so that skia and gl_helper |
| 627 // don't step on each other. | 629 // don't step on each other. |
| 630 bool share_resources = false; |
| 628 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( | 631 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( |
| 629 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle), | 632 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle, |
| 633 share_resources), |
| 630 gpu::SharedMemoryLimits(), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); | 634 gpu::SharedMemoryLimits(), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
| 631 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( | 635 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( |
| 632 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, | 636 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, |
| 633 callback_factory_.GetWeakPtr())); | 637 callback_factory_.GetWeakPtr())); |
| 634 if (!shared_main_thread_contexts_->BindToCurrentThread()) | 638 if (!shared_main_thread_contexts_->BindToCurrentThread()) |
| 635 shared_main_thread_contexts_ = nullptr; | 639 shared_main_thread_contexts_ = nullptr; |
| 636 return shared_main_thread_contexts_; | 640 return shared_main_thread_contexts_; |
| 637 } | 641 } |
| 638 | 642 |
| 639 GpuProcessTransportFactory::PerCompositorData* | 643 GpuProcessTransportFactory::PerCompositorData* |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 683 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 680 observer_list_, | 684 observer_list_, |
| 681 OnLostResources()); | 685 OnLostResources()); |
| 682 | 686 |
| 683 // Kill things that use the shared context before killing the shared context. | 687 // Kill things that use the shared context before killing the shared context. |
| 684 lost_gl_helper.reset(); | 688 lost_gl_helper.reset(); |
| 685 lost_shared_main_thread_contexts = NULL; | 689 lost_shared_main_thread_contexts = NULL; |
| 686 } | 690 } |
| 687 | 691 |
| 688 } // namespace content | 692 } // namespace content |
| OLD | NEW |