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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { | 230 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { |
231 #if defined(OS_CHROMEOS) | 231 #if defined(OS_CHROMEOS) |
232 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use " | 232 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use " |
233 << "software compositing on ChromeOS."; | 233 << "software compositing on ChromeOS."; |
234 #endif | 234 #endif |
235 create_gpu_output_surface = false; | 235 create_gpu_output_surface = false; |
236 } | 236 } |
237 | 237 |
238 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 238 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
239 if (create_gpu_output_surface) { | 239 if (create_gpu_output_surface) { |
240 // Try to reuse existing worker context provider. | |
241 if (shared_worker_context_provider_) { | |
242 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); | |
243 if (shared_worker_context_provider_->ContextGL() | |
244 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | |
245 shared_worker_context_provider_ = nullptr; | |
246 } | |
247 scoped_refptr<GpuChannelHost> gpu_channel_host = | 240 scoped_refptr<GpuChannelHost> gpu_channel_host = |
248 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); | 241 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); |
249 if (gpu_channel_host.get()) { | 242 if (gpu_channel_host.get()) { |
250 context_provider = ContextProviderCommandBuffer::Create( | 243 context_provider = ContextProviderCommandBuffer::Create( |
251 GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host, | 244 GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host, |
252 data->surface_id), | 245 data->surface_id), |
253 BROWSER_COMPOSITOR_ONSCREEN_CONTEXT); | 246 BROWSER_COMPOSITOR_ONSCREEN_CONTEXT); |
254 if (context_provider && !context_provider->BindToCurrentThread()) | 247 if (context_provider && !context_provider->BindToCurrentThread()) |
255 context_provider = nullptr; | 248 context_provider = nullptr; |
256 if (!shared_worker_context_provider_) { | |
257 shared_worker_context_provider_ = ContextProviderCommandBuffer::Create( | |
258 GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host, | |
259 0), | |
260 BROWSER_WORKER_CONTEXT); | |
261 if (shared_worker_context_provider_ && | |
262 !shared_worker_context_provider_->BindToCurrentThread()) | |
263 shared_worker_context_provider_ = nullptr; | |
264 } | |
265 } | 249 } |
266 | 250 |
267 bool created_gpu_browser_compositor = | 251 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", |
268 !!context_provider && !!shared_worker_context_provider_; | 252 !!context_provider.get()); |
269 | 253 |
270 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", | 254 if (!context_provider) { |
271 created_gpu_browser_compositor); | |
272 | |
273 if (!created_gpu_browser_compositor) { | |
274 // Try again. | 255 // Try again. |
275 CauseForGpuLaunch cause = | 256 CauseForGpuLaunch cause = |
276 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 257 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
277 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 258 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
278 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 259 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
279 callback_factory_.GetWeakPtr(), compositor, | 260 callback_factory_.GetWeakPtr(), compositor, |
280 create_gpu_output_surface, num_attempts + 1)); | 261 create_gpu_output_surface, num_attempts + 1)); |
281 return; | 262 return; |
282 } | 263 } |
283 } | 264 } |
284 | 265 |
285 scoped_ptr<BrowserCompositorOutputSurface> surface; | 266 scoped_ptr<BrowserCompositorOutputSurface> surface; |
286 if (!create_gpu_output_surface) { | 267 if (!create_gpu_output_surface) { |
287 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( | 268 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( |
288 CreateSoftwareOutputDevice(compositor.get()), | 269 CreateSoftwareOutputDevice(compositor.get()), |
289 compositor->vsync_manager())); | 270 compositor->vsync_manager())); |
290 } else { | 271 } else { |
291 DCHECK(context_provider); | 272 DCHECK(context_provider); |
292 ContextProvider::Capabilities capabilities = | 273 ContextProvider::Capabilities capabilities = |
293 context_provider->ContextCapabilities(); | 274 context_provider->ContextCapabilities(); |
294 if (!data->surface_id) { | 275 if (!data->surface_id) { |
295 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface( | 276 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface( |
296 context_provider, shared_worker_context_provider_, | 277 context_provider, compositor->vsync_manager(), |
297 compositor->vsync_manager(), | |
298 scoped_ptr<BrowserCompositorOverlayCandidateValidator>())); | 278 scoped_ptr<BrowserCompositorOverlayCandidateValidator>())); |
299 } else if (capabilities.gpu.surfaceless) { | 279 } else if (capabilities.gpu.surfaceless) { |
300 GLenum target = GL_TEXTURE_2D; | 280 GLenum target = GL_TEXTURE_2D; |
301 GLenum format = GL_RGB; | 281 GLenum format = GL_RGB; |
302 #if defined(OS_MACOSX) | 282 #if defined(OS_MACOSX) |
303 target = GL_TEXTURE_RECTANGLE_ARB; | 283 target = GL_TEXTURE_RECTANGLE_ARB; |
304 format = GL_BGRA_EXT; | 284 format = GL_BGRA_EXT; |
305 #endif | 285 #endif |
306 surface = | 286 surface = |
307 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface( | 287 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface( |
308 context_provider, shared_worker_context_provider_, | 288 context_provider, data->surface_id, compositor->vsync_manager(), |
309 data->surface_id, compositor->vsync_manager(), | |
310 CreateOverlayCandidateValidator(compositor->widget()), target, | 289 CreateOverlayCandidateValidator(compositor->widget()), target, |
311 format, BrowserGpuMemoryBufferManager::current())); | 290 format, BrowserGpuMemoryBufferManager::current())); |
312 } else { | 291 } else { |
313 if (!surface) { | 292 if (!surface) { |
314 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( | 293 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( |
315 context_provider, shared_worker_context_provider_, | 294 context_provider, compositor->vsync_manager(), |
316 compositor->vsync_manager(), | |
317 CreateOverlayCandidateValidator(compositor->widget()))); | 295 CreateOverlayCandidateValidator(compositor->widget()))); |
318 } | 296 } |
319 } | 297 } |
320 } | 298 } |
321 | 299 |
322 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 300 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
323 // output_surface_map_ here. | 301 // output_surface_map_ here. |
324 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 302 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
325 data->surface = surface.get(); | 303 data->surface = surface.get(); |
326 if (data->reflector) | 304 if (data->reflector) |
(...skipping 10 matching lines...) Expand all Loading... |
337 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 315 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
338 cc::SurfaceManager* manager = surface_manager_.get(); | 316 cc::SurfaceManager* manager = surface_manager_.get(); |
339 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 317 scoped_ptr<cc::OnscreenDisplayClient> display_client( |
340 new cc::OnscreenDisplayClient( | 318 new cc::OnscreenDisplayClient( |
341 surface.Pass(), manager, HostSharedBitmapManager::current(), | 319 surface.Pass(), manager, HostSharedBitmapManager::current(), |
342 BrowserGpuMemoryBufferManager::current(), | 320 BrowserGpuMemoryBufferManager::current(), |
343 compositor->GetRendererSettings(), compositor->task_runner())); | 321 compositor->GetRendererSettings(), compositor->task_runner())); |
344 | 322 |
345 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 323 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
346 new cc::SurfaceDisplayOutputSurface( | 324 new cc::SurfaceDisplayOutputSurface( |
347 manager, compositor->surface_id_allocator(), context_provider, | 325 manager, compositor->surface_id_allocator(), context_provider)); |
348 shared_worker_context_provider_)); | |
349 display_client->set_surface_output_surface(output_surface.get()); | 326 display_client->set_surface_output_surface(output_surface.get()); |
350 output_surface->set_display_client(display_client.get()); | 327 output_surface->set_display_client(display_client.get()); |
351 display_client->display()->Resize(compositor->size()); | 328 display_client->display()->Resize(compositor->size()); |
352 data->display_client = display_client.Pass(); | 329 data->display_client = display_client.Pass(); |
353 compositor->SetOutputSurface(output_surface.Pass()); | 330 compositor->SetOutputSurface(output_surface.Pass()); |
354 } | 331 } |
355 | 332 |
356 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 333 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
357 ui::Compositor* source_compositor, | 334 ui::Compositor* source_compositor, |
358 ui::Layer* target_layer) { | 335 ui::Layer* target_layer) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 595 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
619 observer_list_, | 596 observer_list_, |
620 OnLostResources()); | 597 OnLostResources()); |
621 | 598 |
622 // Kill things that use the shared context before killing the shared context. | 599 // Kill things that use the shared context before killing the shared context. |
623 lost_gl_helper.reset(); | 600 lost_gl_helper.reset(); |
624 lost_shared_main_thread_contexts = NULL; | 601 lost_shared_main_thread_contexts = NULL; |
625 } | 602 } |
626 | 603 |
627 } // namespace content | 604 } // namespace content |
OLD | NEW |