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

Side by Side Diff: content/browser/renderer_host/context_provider_factory_impl_android.cc

Issue 2190033002: content: Add ContextProviderFactory to create a render ContextProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
6
7 #include "base/auto_reset.h"
8 #include "base/command_line.h"
9 #include "base/lazy_instance.h"
10 #include "base/memory/singleton.h"
11 #include "cc/output/context_provider.h"
12 #include "cc/output/vulkan_in_process_context_provider.h"
13 #include "cc/surfaces/surface_manager.h"
14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
16 #include "content/browser/gpu/compositor_util.h"
17 #include "content/browser/gpu/gpu_surface_tracker.h"
18 #include "content/common/gpu/client/context_provider_command_buffer.h"
19 #include "content/common/host_shared_bitmap_manager.h"
20 #include "content/public/common/content_switches.h"
21 #include "gpu/command_buffer/client/gles2_interface.h"
22 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
23 #include "gpu/ipc/client/gpu_channel_host.h"
24
25 namespace content {
26
27 // static
28 ContextProviderFactoryImpl* ContextProviderFactoryImpl::GetInstance() {
29 return base::Singleton<ContextProviderFactoryImpl>::get();
30 }
31
32 ContextProviderFactoryImpl::ContextProviderFactoryImpl()
33 : in_handle_pending_requests_(false),
34 surface_client_id_(0),
35 weak_factory_(this) {}
36
37 ContextProviderFactoryImpl::~ContextProviderFactoryImpl() {}
38
39 ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest()
40 : widget(gfx::kNullAcceleratedWidget),
41 support_locking(false),
42 automatic_flushes(false),
43 shared_context_provider(nullptr) {}
44
45 ContextProviderFactoryImpl::ContextProvidersRequest::
46 ~ContextProvidersRequest() = default;
47
48 scoped_refptr<cc::VulkanContextProvider>
49 ContextProviderFactoryImpl::GetSharedVulkanContextProvider() {
50 if (!shared_vulkan_context_provider_)
51 shared_vulkan_context_provider_ =
52 cc::VulkanInProcessContextProvider::Create();
53
54 return shared_vulkan_context_provider_.get();
55 }
56
57 void ContextProviderFactoryImpl::CreateDisplayContextProvider(
58 gfx::AcceleratedWidget widget,
59 gpu::SharedMemoryLimits shared_memory_limits,
60 gpu::gles2::ContextCreationAttribHelper attributes,
61 bool support_locking,
62 bool automatic_flushes,
63 ContextProviderCallback result_callback) {
64 DCHECK(widget != gfx::kNullAcceleratedWidget);
65 CreateContextProviderInternal(widget, shared_memory_limits, attributes,
66 support_locking, automatic_flushes, nullptr,
67 result_callback);
68 }
69
70 void ContextProviderFactoryImpl::CreateOffscreenContextProvider(
71 gpu::SharedMemoryLimits shared_memory_limits,
72 gpu::gles2::ContextCreationAttribHelper attributes,
73 bool support_locking,
74 bool automatic_flushes,
75 cc::ContextProvider* shared_context_provider,
76 ContextProviderCallback result_callback) {
77 CreateContextProviderInternal(gfx::kNullAcceleratedWidget,
78 shared_memory_limits, attributes,
79 support_locking, automatic_flushes,
80 shared_context_provider, result_callback);
81 }
82
83 cc::SurfaceManager* ContextProviderFactoryImpl::GetSurfaceManager() {
84 if (!surface_manager_)
85 surface_manager_ = base::WrapUnique(new cc::SurfaceManager);
86
87 return surface_manager_.get();
88 }
89
90 uint32_t ContextProviderFactoryImpl::AllocateSurfaceClientId() {
91 return ++surface_client_id_;
92 }
93
94 cc::SharedBitmapManager* ContextProviderFactoryImpl::GetSharedBitmapManager() {
95 return HostSharedBitmapManager::current();
96 }
97
98 gpu::GpuMemoryBufferManager*
99 ContextProviderFactoryImpl::GetGpuMemoryBufferManager() {
100 return BrowserGpuMemoryBufferManager::current();
101 }
102
103 void ContextProviderFactoryImpl::CreateContextProviderInternal(
104 gfx::AcceleratedWidget widget,
105 gpu::SharedMemoryLimits shared_memory_limits,
106 gpu::gles2::ContextCreationAttribHelper attributes,
107 bool support_locking,
108 bool automatic_flushes,
109 cc::ContextProvider* shared_context_provider,
110 ContextProviderCallback result_callback) {
111 DCHECK(!result_callback.is_null());
112
113 ContextProvidersRequest context_request;
114 context_request.widget = widget;
115 context_request.shared_memory_limits = shared_memory_limits;
116 context_request.attributes = attributes;
117 context_request.support_locking = support_locking;
118 context_request.automatic_flushes = automatic_flushes;
119 context_request.shared_context_provider = shared_context_provider;
120 context_request.result_callback = result_callback;
121
122 context_provider_requests_.push_back(context_request);
123 HandlePendingRequests();
124 }
125
126 void ContextProviderFactoryImpl::HandlePendingRequests() {
127 // Failure to initialize the context could result in new requests. Handle
128 // them after going through the current list.
129 if (in_handle_pending_requests_)
130 return;
131
132 {
133 base::AutoReset<bool> auto_reset_in_handle_requests(
134 &in_handle_pending_requests_, true);
135
136 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
137 EnsureGpuChannelEstablished());
138 if (!gpu_channel_host)
139 return;
140
141 if (!context_provider_requests_.empty()) {
142 std::list<ContextProvidersRequest> context_requests =
143 context_provider_requests_;
144 context_provider_requests_.clear();
145
146 for (ContextProvidersRequest& context_request : context_requests) {
147 scoped_refptr<cc::ContextProvider> context_provider;
148
149 const bool create_onscreen_context =
150 context_request.widget != gfx::kNullAcceleratedWidget;
151 gpu::SurfaceHandle surface_handle =
152 create_onscreen_context
153 ? GpuSurfaceTracker::GetInstance()->GetSurfaceForNativeWidget(
154 context_request.widget)
155 : gpu::kNullSurfaceHandle;
156
157 // Is the request for an onscreen context? Make sure the surface is
158 // still valid in that case.
159 if (create_onscreen_context &&
160 surface_handle == gpu::kNullSurfaceHandle) {
161 context_request.result_callback.Run(context_provider);
162 continue;
163 }
164
165 context_provider = new ContextProviderCommandBuffer(
166 gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
167 gpu::GpuStreamPriority::NORMAL, surface_handle,
168 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") +
169 std::string("CompositorContextProvider")),
170 context_request.automatic_flushes, context_request.support_locking,
171 context_request.shared_memory_limits, context_request.attributes,
172 static_cast<ContextProviderCommandBuffer*>(
173 context_request.shared_context_provider),
174 create_onscreen_context
175 ? command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT
Khushal 2016/08/04 20:49:33 Btw, is this okay? Or do we need something else fo
no sievers 2016/08/04 21:02:34 You can add a type if you don't want it tracked as
Khushal 2016/08/04 22:04:25 Thanks, added another type. I figured it shouldn't
176 : command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT);
177 context_request.result_callback.Run(context_provider);
178 }
179 }
180 }
181
182 if (!context_provider_requests_.empty())
183 HandlePendingRequests();
184 }
185
186 gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
187 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
188 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
189 const int64_t kGpuChannelTimeoutInSeconds = 40;
190 #else
191 const int64_t kGpuChannelTimeoutInSeconds = 10;
192 #endif
193
194 BrowserGpuChannelHostFactory* factory =
195 BrowserGpuChannelHostFactory::instance();
196
197 if (factory->GetGpuChannel())
198 return factory->GetGpuChannel();
199
200 factory->EstablishGpuChannel(
201 CAUSE_FOR_GPU_LAUNCH_DISPLAY_COMPOSITOR_CONTEXT,
202 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
203 weak_factory_.GetWeakPtr()));
204 establish_gpu_channel_timeout_.Start(
205 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
206 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout);
207
208 return nullptr;
209 }
210
211 void ContextProviderFactoryImpl::OnGpuChannelEstablished() {
212 establish_gpu_channel_timeout_.Stop();
213 HandlePendingRequests();
214 }
215
216 void ContextProviderFactoryImpl::OnGpuChannelTimeout() {
217 LOG(FATAL) << "Timed out waiting for GPU channel.";
218 }
219
220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698