Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/compositor/gpu_process_transport_factory.cc

Issue 1916923004: Request context sharing via content::ContextProviderCommandBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sharegroup: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 using cc::ContextProvider; 87 using cc::ContextProvider;
88 using gpu::gles2::GLES2Interface; 88 using gpu::gles2::GLES2Interface;
89 89
90 namespace { 90 namespace {
91 91
92 const int kNumRetriesBeforeSoftwareFallback = 4; 92 const int kNumRetriesBeforeSoftwareFallback = 4;
93 93
94 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl> 94 std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl>
95 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, 95 CreateContextCommon(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
96 gpu::SurfaceHandle surface_handle, 96 gpu::SurfaceHandle surface_handle) {
97 bool share_resources) {
98 DCHECK( 97 DCHECK(
99 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); 98 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor());
100 DCHECK(gpu_channel_host); 99 DCHECK(gpu_channel_host);
101 100
102 // This is called from a few places to create different contexts: 101 // This is called from a few places to create different contexts:
103 // - The shared main thread context (offscreen). 102 // - The shared main thread context (offscreen).
104 // - The compositor context, which is used by the browser compositor 103 // - The compositor context, which is used by the browser compositor
105 // (offscreen) for synchronization mostly, and by the display compositor 104 // (offscreen) for synchronization mostly, and by the display compositor
106 // (onscreen) for actual GL drawing. 105 // (onscreen) for actual GL drawing.
107 // - The compositor worker context (offscreen) used for GPU raster. 106 // - The compositor worker context (offscreen) used for GPU raster.
(...skipping 10 matching lines...) Expand all
118 attributes.samples = 0; 117 attributes.samples = 0;
119 attributes.sample_buffers = 0; 118 attributes.sample_buffers = 0;
120 attributes.bind_generates_resource = false; 119 attributes.bind_generates_resource = false;
121 attributes.lose_context_when_out_of_memory = true; 120 attributes.lose_context_when_out_of_memory = true;
122 121
123 bool automatic_flushes = false; 122 bool automatic_flushes = false;
124 123
125 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); 124 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon");
126 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( 125 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl(
127 surface_handle, url, gpu_channel_host.get(), attributes, 126 surface_handle, url, gpu_channel_host.get(), attributes,
128 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, 127 gfx::PreferIntegratedGpu, automatic_flushes));
129 nullptr));
130 } 128 }
131 129
132 } // namespace 130 } // namespace
133 131
134 namespace content { 132 namespace content {
135 133
136 struct GpuProcessTransportFactory::PerCompositorData { 134 struct GpuProcessTransportFactory::PerCompositorData {
137 int surface_id; 135 int surface_id;
138 BrowserCompositorOutputSurface* surface; 136 BrowserCompositorOutputSurface* surface;
139 ReflectorImpl* reflector; 137 ReflectorImpl* reflector;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 332 }
335 333
336 if (!gpu_channel_host) { 334 if (!gpu_channel_host) {
337 shared_worker_context_provider_ = nullptr; 335 shared_worker_context_provider_ = nullptr;
338 } else { 336 } else {
339 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); 337 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
340 gpu::SurfaceHandle surface_handle = 338 gpu::SurfaceHandle surface_handle =
341 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id) 339 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id)
342 : gpu::kNullSurfaceHandle; 340 : gpu::kNullSurfaceHandle;
343 341
344 // This context is used for both the browser compositor and the display
345 // compositor.
346 constexpr bool share_resources = true;
347 context_provider = new ContextProviderCommandBuffer(
348 CreateContextCommon(gpu_channel_host, surface_handle,
349 share_resources),
350 gpu::SharedMemoryLimits(), DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
351 if (!context_provider->BindToCurrentThread())
352 context_provider = nullptr;
353
354 if (!shared_worker_context_provider_) { 342 if (!shared_worker_context_provider_) {
355 shared_worker_context_provider_ = new ContextProviderCommandBuffer( 343 shared_worker_context_provider_ = new ContextProviderCommandBuffer(
356 CreateContextCommon(std::move(gpu_channel_host), 344 CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle),
357 gpu::kNullSurfaceHandle, share_resources), 345 gpu::SharedMemoryLimits(), nullptr, BROWSER_WORKER_CONTEXT);
358 gpu::SharedMemoryLimits(), BROWSER_WORKER_CONTEXT);
359 if (shared_worker_context_provider_->BindToCurrentThread()) 346 if (shared_worker_context_provider_->BindToCurrentThread())
360 shared_worker_context_provider_->SetupLock(); 347 shared_worker_context_provider_->SetupLock();
361 else 348 else
362 shared_worker_context_provider_ = nullptr; 349 shared_worker_context_provider_ = nullptr;
363 } 350 }
351
352 // This context is used for both the browser compositor and the display
353 // compositor. It shares resources with the worker context.
piman 2016/04/27 22:09:33 Should we do this only if shared_worker_context_pr
danakj 2016/04/28 00:25:58 Good point, will match RenderWidget and go back to
354 context_provider = new ContextProviderCommandBuffer(
355 CreateContextCommon(std::move(gpu_channel_host), surface_handle),
356 gpu::SharedMemoryLimits(), shared_worker_context_provider_.get(),
357 DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
358 if (!context_provider->BindToCurrentThread())
359 context_provider = nullptr;
364 } 360 }
365 361
366 bool created_gpu_browser_compositor = 362 bool created_gpu_browser_compositor =
367 !!context_provider && !!shared_worker_context_provider_; 363 !!context_provider && !!shared_worker_context_provider_;
368 364
369 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", 365 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor",
370 created_gpu_browser_compositor); 366 created_gpu_browser_compositor);
371 367
372 if (!created_gpu_browser_compositor) { 368 if (!created_gpu_browser_compositor) {
373 // Try again. 369 // Try again.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return nullptr; 649 return nullptr;
654 CauseForGpuLaunch cause = 650 CauseForGpuLaunch cause =
655 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; 651 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
656 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( 652 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
657 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); 653 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
658 if (!gpu_channel_host) 654 if (!gpu_channel_host)
659 return nullptr; 655 return nullptr;
660 656
661 // We need a separate context from the compositor's so that skia and gl_helper 657 // We need a separate context from the compositor's so that skia and gl_helper
662 // don't step on each other. 658 // don't step on each other.
663 bool share_resources = false;
664 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( 659 shared_main_thread_contexts_ = new ContextProviderCommandBuffer(
665 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle, 660 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle),
666 share_resources), 661 gpu::SharedMemoryLimits(), nullptr, BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
667 gpu::SharedMemoryLimits(), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
668 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( 662 shared_main_thread_contexts_->SetLostContextCallback(base::Bind(
669 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, 663 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback,
670 callback_factory_.GetWeakPtr())); 664 callback_factory_.GetWeakPtr()));
671 if (!shared_main_thread_contexts_->BindToCurrentThread()) 665 if (!shared_main_thread_contexts_->BindToCurrentThread())
672 shared_main_thread_contexts_ = nullptr; 666 shared_main_thread_contexts_ = nullptr;
673 return shared_main_thread_contexts_; 667 return shared_main_thread_contexts_;
674 } 668 }
675 669
676 GpuProcessTransportFactory::PerCompositorData* 670 GpuProcessTransportFactory::PerCompositorData*
677 GpuProcessTransportFactory::CreatePerCompositorData( 671 GpuProcessTransportFactory::CreatePerCompositorData(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 shared_vulkan_context_provider_ = 725 shared_vulkan_context_provider_ =
732 cc::VulkanInProcessContextProvider::Create(); 726 cc::VulkanInProcessContextProvider::Create();
733 } 727 }
734 728
735 shared_vulkan_context_provider_initialized_ = true; 729 shared_vulkan_context_provider_initialized_ = true;
736 } 730 }
737 return shared_vulkan_context_provider_; 731 return shared_vulkan_context_provider_;
738 } 732 }
739 733
740 } // namespace content 734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698