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

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

Issue 2250473005: content: Fix Context creation logic in ContextProviderFactoryImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/renderer_host/context_provider_factory_impl_android.h" 5 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 21 matching lines...) Expand all
32 case ui::ContextProviderFactory::ContextType:: 32 case ui::ContextProviderFactory::ContextType::
33 BLIMP_RENDER_COMPOSITOR_CONTEXT: 33 BLIMP_RENDER_COMPOSITOR_CONTEXT:
34 return command_buffer_metrics::BLIMP_RENDER_COMPOSITOR_CONTEXT; 34 return command_buffer_metrics::BLIMP_RENDER_COMPOSITOR_CONTEXT;
35 case ui::ContextProviderFactory::ContextType::BLIMP_RENDER_WORKER_CONTEXT: 35 case ui::ContextProviderFactory::ContextType::BLIMP_RENDER_WORKER_CONTEXT:
36 return command_buffer_metrics::BLIMP_RENDER_WORKER_CONTEXT; 36 return command_buffer_metrics::BLIMP_RENDER_WORKER_CONTEXT;
37 } 37 }
38 NOTREACHED(); 38 NOTREACHED();
39 return command_buffer_metrics::CONTEXT_TYPE_UNKNOWN; 39 return command_buffer_metrics::CONTEXT_TYPE_UNKNOWN;
40 } 40 }
41 41
42 bool IsGpuChannelHostFactoryAvailable() {
43 return BrowserGpuChannelHostFactory::instance() != nullptr;
44 }
45
46 gpu::GpuChannelHost* IsGpuChannelAvailable() {
47 BrowserGpuChannelHostFactory* factory =
48 BrowserGpuChannelHostFactory::instance();
49 DCHECK(factory);
50
51 if (factory->GetGpuChannel())
52 return factory->GetGpuChannel();
53 else
54 return nullptr;
55 }
56
42 } // namespace 57 } // namespace
43 58
44 // static 59 // static
45 ContextProviderFactoryImpl* ContextProviderFactoryImpl::GetInstance() { 60 ContextProviderFactoryImpl* ContextProviderFactoryImpl::GetInstance() {
46 return base::Singleton<ContextProviderFactoryImpl>::get(); 61 return base::Singleton<ContextProviderFactoryImpl>::get();
47 } 62 }
48 63
49 ContextProviderFactoryImpl::ContextProviderFactoryImpl() 64 ContextProviderFactoryImpl::ContextProviderFactoryImpl()
50 : in_handle_pending_requests_(false), 65 : in_handle_pending_requests_(false),
51 surface_client_id_(0), 66 surface_client_id_(0),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 context_request.context_type = context_type; 153 context_request.context_type = context_type;
139 context_request.surface_handle = surface_handle; 154 context_request.surface_handle = surface_handle;
140 context_request.shared_memory_limits = shared_memory_limits; 155 context_request.shared_memory_limits = shared_memory_limits;
141 context_request.attributes = attributes; 156 context_request.attributes = attributes;
142 context_request.support_locking = support_locking; 157 context_request.support_locking = support_locking;
143 context_request.automatic_flushes = automatic_flushes; 158 context_request.automatic_flushes = automatic_flushes;
144 context_request.shared_context_provider = shared_context_provider; 159 context_request.shared_context_provider = shared_context_provider;
145 context_request.result_callback = result_callback; 160 context_request.result_callback = result_callback;
146 161
147 context_provider_requests_.push_back(context_request); 162 context_provider_requests_.push_back(context_request);
148 HandlePendingRequests(); 163 CheckCanHandlePendingRequests();
149 } 164 }
150 165
151 void ContextProviderFactoryImpl::HandlePendingRequests() { 166 void ContextProviderFactoryImpl::CheckCanHandlePendingRequests() {
167 DCHECK(!context_provider_requests_.empty())
168 << "We don't have any pending requests?";
169 if (!IsGpuChannelHostFactoryAvailable()) {
170 HandlePendingRequests(nullptr,
171 ContextCreationFailureReason::BROWSER_SHUTDOWN);
172 return;
173 }
174
175 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(IsGpuChannelAvailable());
176 if (gpu_channel_host) {
177 HandlePendingRequests(gpu_channel_host,
178 ContextCreationFailureReason::FAILURE_NONE);
179 } else {
180 EstablishGpuChannel();
181 }
182 }
183
184 void ContextProviderFactoryImpl::HandlePendingRequests(
185 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
186 ContextCreationFailureReason reason) {
152 DCHECK(!context_provider_requests_.empty()) 187 DCHECK(!context_provider_requests_.empty())
153 << "We don't have any pending requests?"; 188 << "We don't have any pending requests?";
154 189
155 // Failure to initialize the context could result in new requests. Handle 190 // Failure to initialize the context could result in new requests. Handle
156 // them after going through the current list. 191 // them after going through the current list.
157 if (in_handle_pending_requests_) 192 if (in_handle_pending_requests_)
158 return; 193 return;
159 194
160 { 195 {
161 base::AutoReset<bool> auto_reset_in_handle_requests( 196 base::AutoReset<bool> auto_reset_in_handle_requests(
162 &in_handle_pending_requests_, true); 197 &in_handle_pending_requests_, true);
163 198
164 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
165 EnsureGpuChannelEstablished());
166
167 // If we don't have a Gpu Channel Host, we will come back here when the Gpu
168 // channel is established, since OnGpuChannelEstablished triggers handling
169 // of the requests we couldn't process right now.
170 if (!gpu_channel_host)
171 return;
172
173 std::list<ContextProvidersRequest> context_requests = 199 std::list<ContextProvidersRequest> context_requests =
174 context_provider_requests_; 200 context_provider_requests_;
175 context_provider_requests_.clear(); 201 context_provider_requests_.clear();
176 202
177 for (ContextProvidersRequest& context_request : context_requests) { 203 for (ContextProvidersRequest& context_request : context_requests) {
178 scoped_refptr<cc::ContextProvider> context_provider; 204 scoped_refptr<cc::ContextProvider> context_provider;
179 205
180 const bool create_onscreen_context = 206 const bool create_onscreen_context =
181 context_request.surface_handle != gpu::kNullSurfaceHandle; 207 context_request.surface_handle != gpu::kNullSurfaceHandle;
182 208
183 // Is the request for an onscreen context? Make sure the surface is 209 // Is the request for an onscreen context? Make sure the surface is
184 // still valid in that case. DO NOT run the callback if we don't have a 210 // still valid in that case. DO NOT run the callback if we don't have a
185 // valid surface. 211 // valid surface.
186 if (create_onscreen_context && 212 if (create_onscreen_context &&
187 !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle( 213 !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle(
188 context_request.surface_handle)) { 214 context_request.surface_handle)) {
189 continue; 215 // GPU Surface handle loss trumps other context creation failure
216 // reasons.
217 context_request.result_callback.Run(
218 nullptr, ContextCreationFailureReason::GPU_SURFACE_HANDLE_LOST);
190 } 219 }
191 220
221 if (!gpu_channel_host)
222 context_request.result_callback.Run(nullptr, reason);
223
224 DCHECK_EQ(ContextCreationFailureReason::FAILURE_NONE, reason);
225
192 context_provider = new ContextProviderCommandBuffer( 226 context_provider = new ContextProviderCommandBuffer(
193 gpu_channel_host, gpu::GPU_STREAM_DEFAULT, 227 gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
194 gpu::GpuStreamPriority::NORMAL, context_request.surface_handle, 228 gpu::GpuStreamPriority::NORMAL, context_request.surface_handle,
195 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") + 229 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") +
196 std::string("CompositorContextProvider")), 230 std::string("CompositorContextProvider")),
197 context_request.automatic_flushes, context_request.support_locking, 231 context_request.automatic_flushes, context_request.support_locking,
198 context_request.shared_memory_limits, context_request.attributes, 232 context_request.shared_memory_limits, context_request.attributes,
199 static_cast<ContextProviderCommandBuffer*>( 233 static_cast<ContextProviderCommandBuffer*>(
200 context_request.shared_context_provider), 234 context_request.shared_context_provider),
201 context_request.context_type); 235 context_request.context_type);
202 context_request.result_callback.Run(context_provider); 236 context_request.result_callback.Run(context_provider, reason);
203 } 237 }
204 } 238 }
205 239
206 if (!context_provider_requests_.empty()) 240 if (!context_provider_requests_.empty())
207 HandlePendingRequests(); 241 CheckCanHandlePendingRequests();
208 } 242 }
209 243
210 gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() { 244 void ContextProviderFactoryImpl::EstablishGpuChannel() {
211 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ 245 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
212 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) 246 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
213 const int64_t kGpuChannelTimeoutInSeconds = 40; 247 const int64_t kGpuChannelTimeoutInSeconds = 40;
214 #else 248 #else
215 const int64_t kGpuChannelTimeoutInSeconds = 10; 249 const int64_t kGpuChannelTimeoutInSeconds = 10;
216 #endif 250 #endif
217 251
218 BrowserGpuChannelHostFactory* factory = 252 BrowserGpuChannelHostFactory* factory =
219 BrowserGpuChannelHostFactory::instance(); 253 BrowserGpuChannelHostFactory::instance();
220 254 DCHECK(factory);
221 if (factory->GetGpuChannel())
222 return factory->GetGpuChannel();
223 255
224 factory->EstablishGpuChannel( 256 factory->EstablishGpuChannel(
225 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, 257 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
226 weak_factory_.GetWeakPtr())); 258 weak_factory_.GetWeakPtr()));
227 establish_gpu_channel_timeout_.Start( 259 establish_gpu_channel_timeout_.Start(
228 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), 260 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
229 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout); 261 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout);
230
231 return nullptr;
232 } 262 }
233 263
234 void ContextProviderFactoryImpl::OnGpuChannelEstablished( 264 void ContextProviderFactoryImpl::OnGpuChannelEstablished(
235 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { 265 scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
236 establish_gpu_channel_timeout_.Stop(); 266 establish_gpu_channel_timeout_.Stop();
237 267
238 // This should happen only during shutdown. So early out instead of queuing
239 // more requests with the factory.
240 if (!gpu_channel)
241 return;
242
243 // We can queue the Gpu Channel initialization requests multiple times as 268 // We can queue the Gpu Channel initialization requests multiple times as
244 // we get context requests. So we might have already handled any pending 269 // we get context requests. So we might have already handled any pending
245 // requests when this callback runs. 270 // requests when this callback runs.
246 if (!context_provider_requests_.empty()) 271 if (context_provider_requests_.empty())
247 HandlePendingRequests(); 272 return;
273
274 if (gpu_channel) {
275 HandlePendingRequests(std::move(gpu_channel),
276 ContextCreationFailureReason::FAILURE_NONE);
277 } else if (IsGpuChannelHostFactoryAvailable()) {
278 HandlePendingRequests(
279 nullptr,
280 ContextCreationFailureReason::GPU_PROCESS_INITIALIZATION_FAILURE);
281 } else {
282 HandlePendingRequests(nullptr,
283 ContextCreationFailureReason::BROWSER_SHUTDOWN);
284 }
248 } 285 }
249 286
250 void ContextProviderFactoryImpl::OnGpuChannelTimeout() { 287 void ContextProviderFactoryImpl::OnGpuChannelTimeout() {
251 LOG(FATAL) << "Timed out waiting for GPU channel."; 288 LOG(FATAL) << "Timed out waiting for GPU channel.";
252 } 289 }
253 290
254 } // namespace content 291 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698