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

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: run the callback once, fix 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
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();
no sievers 2016/08/17 18:30:10 nit: This is maybe a bit verbose vs. just returnin
Khushal 2016/08/17 21:24:55 Yeah, that's better. Done.
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() {
no sievers 2016/08/17 18:30:10 can this outer logic be merged into HandlePendingR
Khushal 2016/08/17 21:24:55 We call HandlePendingRequests from places where we
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.
185 // valid surface.
186 if (create_onscreen_context && 211 if (create_onscreen_context &&
187 !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle( 212 !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle(
188 context_request.surface_handle)) { 213 context_request.surface_handle)) {
189 continue; 214 // GPU Surface handle loss trumps other context creation failure
215 // reasons.
216 context_request.result_callback.Run(
217 nullptr, ContextCreationFailureReason::GPU_SURFACE_HANDLE_LOST);
218 } else if (!gpu_channel_host) {
219 context_request.result_callback.Run(nullptr, reason);
220 } else {
221 DCHECK_EQ(ContextCreationFailureReason::FAILURE_NONE, reason);
222
223 context_provider = new ContextProviderCommandBuffer(
224 gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
225 gpu::GpuStreamPriority::NORMAL, context_request.surface_handle,
226 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") +
227 std::string("CompositorContextProvider")),
228 context_request.automatic_flushes, context_request.support_locking,
229 context_request.shared_memory_limits, context_request.attributes,
230 static_cast<ContextProviderCommandBuffer*>(
231 context_request.shared_context_provider),
232 context_request.context_type);
233 context_request.result_callback.Run(context_provider, reason);
190 } 234 }
191
192 context_provider = new ContextProviderCommandBuffer(
193 gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
194 gpu::GpuStreamPriority::NORMAL, context_request.surface_handle,
195 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") +
196 std::string("CompositorContextProvider")),
197 context_request.automatic_flushes, context_request.support_locking,
198 context_request.shared_memory_limits, context_request.attributes,
199 static_cast<ContextProviderCommandBuffer*>(
200 context_request.shared_context_provider),
201 context_request.context_type);
202 context_request.result_callback.Run(context_provider);
203 } 235 }
204 } 236 }
205 237
206 if (!context_provider_requests_.empty()) 238 if (!context_provider_requests_.empty())
207 HandlePendingRequests(); 239 CheckCanHandlePendingRequests();
208 } 240 }
209 241
210 gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() { 242 void ContextProviderFactoryImpl::EstablishGpuChannel() {
211 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ 243 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
212 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) 244 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
213 const int64_t kGpuChannelTimeoutInSeconds = 40; 245 const int64_t kGpuChannelTimeoutInSeconds = 40;
214 #else 246 #else
215 const int64_t kGpuChannelTimeoutInSeconds = 10; 247 const int64_t kGpuChannelTimeoutInSeconds = 10;
216 #endif 248 #endif
217 249
218 BrowserGpuChannelHostFactory* factory = 250 BrowserGpuChannelHostFactory* factory =
219 BrowserGpuChannelHostFactory::instance(); 251 BrowserGpuChannelHostFactory::instance();
220 252 DCHECK(factory);
221 if (factory->GetGpuChannel())
222 return factory->GetGpuChannel();
223 253
224 factory->EstablishGpuChannel( 254 factory->EstablishGpuChannel(
225 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, 255 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
226 weak_factory_.GetWeakPtr())); 256 weak_factory_.GetWeakPtr()));
227 establish_gpu_channel_timeout_.Start( 257 establish_gpu_channel_timeout_.Start(
228 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), 258 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
229 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout); 259 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout);
230
231 return nullptr;
232 } 260 }
233 261
234 void ContextProviderFactoryImpl::OnGpuChannelEstablished( 262 void ContextProviderFactoryImpl::OnGpuChannelEstablished(
235 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { 263 scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
236 establish_gpu_channel_timeout_.Stop(); 264 establish_gpu_channel_timeout_.Stop();
237 265
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 266 // We can queue the Gpu Channel initialization requests multiple times as
244 // we get context requests. So we might have already handled any pending 267 // we get context requests. So we might have already handled any pending
245 // requests when this callback runs. 268 // requests when this callback runs.
246 if (!context_provider_requests_.empty()) 269 if (context_provider_requests_.empty())
247 HandlePendingRequests(); 270 return;
271
272 if (gpu_channel) {
273 HandlePendingRequests(std::move(gpu_channel),
274 ContextCreationFailureReason::FAILURE_NONE);
275 } else if (IsGpuChannelHostFactoryAvailable()) {
276 HandlePendingRequests(
277 nullptr,
278 ContextCreationFailureReason::GPU_PROCESS_INITIALIZATION_FAILURE);
279 } else {
280 HandlePendingRequests(nullptr,
281 ContextCreationFailureReason::BROWSER_SHUTDOWN);
282 }
248 } 283 }
249 284
250 void ContextProviderFactoryImpl::OnGpuChannelTimeout() { 285 void ContextProviderFactoryImpl::OnGpuChannelTimeout() {
251 LOG(FATAL) << "Timed out waiting for GPU channel."; 286 LOG(FATAL) << "Timed out waiting for GPU channel.";
252 } 287 }
253 288
254 } // namespace content 289 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698