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 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 180 } |
180 #elif defined(OS_MACOSX) | 181 #elif defined(OS_MACOSX) |
181 // Overlays are only supported through the remote layer API. | 182 // Overlays are only supported through the remote layer API. |
182 if (ui::RemoteLayerAPISupported()) { | 183 if (ui::RemoteLayerAPISupported()) { |
183 validator.reset(new BrowserCompositorOverlayCandidateValidatorMac(widget)); | 184 validator.reset(new BrowserCompositorOverlayCandidateValidatorMac(widget)); |
184 } | 185 } |
185 #elif defined(OS_ANDROID) | 186 #elif defined(OS_ANDROID) |
186 validator.reset(new BrowserCompositorOverlayCandidateValidatorAndroid()); | 187 validator.reset(new BrowserCompositorOverlayCandidateValidatorAndroid()); |
187 #endif | 188 #endif |
188 | 189 |
189 return validator.Pass(); | 190 return validator; |
190 } | 191 } |
191 | 192 |
192 static bool ShouldCreateGpuOutputSurface(ui::Compositor* compositor) { | 193 static bool ShouldCreateGpuOutputSurface(ui::Compositor* compositor) { |
193 #if defined(MOJO_RUNNER_CLIENT) | 194 #if defined(MOJO_RUNNER_CLIENT) |
194 // Chrome running as a mojo app currently can only use software compositing. | 195 // Chrome running as a mojo app currently can only use software compositing. |
195 // TODO(rjkroege): http://crbug.com/548451 | 196 // TODO(rjkroege): http://crbug.com/548451 |
196 if (IsRunningInMojoShell()) { | 197 if (IsRunningInMojoShell()) { |
197 return false; | 198 return false; |
198 } | 199 } |
199 #endif | 200 #endif |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 CreateOverlayCandidateValidator(compositor->widget()), target, | 345 CreateOverlayCandidateValidator(compositor->widget()), target, |
345 format, BrowserGpuMemoryBufferManager::current())); | 346 format, BrowserGpuMemoryBufferManager::current())); |
346 } else { | 347 } else { |
347 scoped_ptr<BrowserCompositorOverlayCandidateValidator> validator; | 348 scoped_ptr<BrowserCompositorOverlayCandidateValidator> validator; |
348 #if !defined(OS_MACOSX) | 349 #if !defined(OS_MACOSX) |
349 // Overlays are only supported on surfaceless output surfaces on Mac. | 350 // Overlays are only supported on surfaceless output surfaces on Mac. |
350 validator = CreateOverlayCandidateValidator(compositor->widget()); | 351 validator = CreateOverlayCandidateValidator(compositor->widget()); |
351 #endif | 352 #endif |
352 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( | 353 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( |
353 context_provider, shared_worker_context_provider_, | 354 context_provider, shared_worker_context_provider_, |
354 compositor->vsync_manager(), validator.Pass())); | 355 compositor->vsync_manager(), std::move(validator))); |
355 } | 356 } |
356 } | 357 } |
357 | 358 |
358 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 359 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
359 // output_surface_map_ here. | 360 // output_surface_map_ here. |
360 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 361 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
361 data->surface = surface.get(); | 362 data->surface = surface.get(); |
362 if (data->reflector) | 363 if (data->reflector) |
363 data->reflector->OnSourceSurfaceReady(data->surface); | 364 data->reflector->OnSourceSurfaceReady(data->surface); |
364 | 365 |
365 if (!UseSurfacesEnabled()) { | 366 if (!UseSurfacesEnabled()) { |
366 compositor->SetOutputSurface(surface.Pass()); | 367 compositor->SetOutputSurface(std::move(surface)); |
367 return; | 368 return; |
368 } | 369 } |
369 | 370 |
370 // This gets a bit confusing. Here we have a ContextProvider in the |surface| | 371 // This gets a bit confusing. Here we have a ContextProvider in the |surface| |
371 // configured to render directly to this widget. We need to make an | 372 // configured to render directly to this widget. We need to make an |
372 // OnscreenDisplayClient associated with that context, then return a | 373 // OnscreenDisplayClient associated with that context, then return a |
373 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 374 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
374 cc::SurfaceManager* manager = surface_manager_.get(); | 375 cc::SurfaceManager* manager = surface_manager_.get(); |
375 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 376 scoped_ptr<cc::OnscreenDisplayClient> display_client( |
376 new cc::OnscreenDisplayClient( | 377 new cc::OnscreenDisplayClient( |
377 surface.Pass(), manager, HostSharedBitmapManager::current(), | 378 std::move(surface), manager, HostSharedBitmapManager::current(), |
378 BrowserGpuMemoryBufferManager::current(), | 379 BrowserGpuMemoryBufferManager::current(), |
379 compositor->GetRendererSettings(), compositor->task_runner())); | 380 compositor->GetRendererSettings(), compositor->task_runner())); |
380 | 381 |
381 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 382 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
382 new cc::SurfaceDisplayOutputSurface( | 383 new cc::SurfaceDisplayOutputSurface( |
383 manager, compositor->surface_id_allocator(), context_provider, | 384 manager, compositor->surface_id_allocator(), context_provider, |
384 shared_worker_context_provider_)); | 385 shared_worker_context_provider_)); |
385 display_client->set_surface_output_surface(output_surface.get()); | 386 display_client->set_surface_output_surface(output_surface.get()); |
386 output_surface->set_display_client(display_client.get()); | 387 output_surface->set_display_client(display_client.get()); |
387 display_client->display()->Resize(compositor->size()); | 388 display_client->display()->Resize(compositor->size()); |
388 data->display_client = display_client.Pass(); | 389 data->display_client = std::move(display_client); |
389 compositor->SetOutputSurface(output_surface.Pass()); | 390 compositor->SetOutputSurface(std::move(output_surface)); |
390 } | 391 } |
391 | 392 |
392 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 393 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
393 ui::Compositor* source_compositor, | 394 ui::Compositor* source_compositor, |
394 ui::Layer* target_layer) { | 395 ui::Layer* target_layer) { |
395 PerCompositorData* source_data = per_compositor_data_[source_compositor]; | 396 PerCompositorData* source_data = per_compositor_data_[source_compositor]; |
396 DCHECK(source_data); | 397 DCHECK(source_data); |
397 | 398 |
398 scoped_ptr<ReflectorImpl> reflector( | 399 scoped_ptr<ReflectorImpl> reflector( |
399 new ReflectorImpl(source_compositor, target_layer)); | 400 new ReflectorImpl(source_compositor, target_layer)); |
400 source_data->reflector = reflector.get(); | 401 source_data->reflector = reflector.get(); |
401 if (BrowserCompositorOutputSurface* source_surface = source_data->surface) | 402 if (BrowserCompositorOutputSurface* source_surface = source_data->surface) |
402 reflector->OnSourceSurfaceReady(source_surface); | 403 reflector->OnSourceSurfaceReady(source_surface); |
403 return reflector.Pass(); | 404 return std::move(reflector); |
404 } | 405 } |
405 | 406 |
406 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { | 407 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { |
407 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); | 408 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); |
408 PerCompositorData* data = | 409 PerCompositorData* data = |
409 per_compositor_data_[reflector_impl->mirrored_compositor()]; | 410 per_compositor_data_[reflector_impl->mirrored_compositor()]; |
410 DCHECK(data); | 411 DCHECK(data); |
411 data->reflector->Shutdown(); | 412 data->reflector->Shutdown(); |
412 data->reflector = nullptr; | 413 data->reflector = nullptr; |
413 } | 414 } |
(...skipping 11 matching lines...) Expand all Loading... |
425 if (data->surface_id) | 426 if (data->surface_id) |
426 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 427 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
427 delete data; | 428 delete data; |
428 per_compositor_data_.erase(it); | 429 per_compositor_data_.erase(it); |
429 if (per_compositor_data_.empty()) { | 430 if (per_compositor_data_.empty()) { |
430 // Destroying the GLHelper may cause some async actions to be cancelled, | 431 // Destroying the GLHelper may cause some async actions to be cancelled, |
431 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 432 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
432 // GLHelper created in this case would be lost/leaked if we just reset() | 433 // GLHelper created in this case would be lost/leaked if we just reset() |
433 // on the |gl_helper_| variable directly. So instead we call reset() on a | 434 // on the |gl_helper_| variable directly. So instead we call reset() on a |
434 // local scoped_ptr. | 435 // local scoped_ptr. |
435 scoped_ptr<GLHelper> helper = gl_helper_.Pass(); | 436 scoped_ptr<GLHelper> helper = std::move(gl_helper_); |
436 | 437 |
437 // If there are any observer left at this point, make sure they clean up | 438 // If there are any observer left at this point, make sure they clean up |
438 // before we destroy the GLHelper. | 439 // before we destroy the GLHelper. |
439 FOR_EACH_OBSERVER( | 440 FOR_EACH_OBSERVER( |
440 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 441 ImageTransportFactoryObserver, observer_list_, OnLostResources()); |
441 | 442 |
442 helper.reset(); | 443 helper.reset(); |
443 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 444 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
444 "GLHelper to be created."; | 445 "GLHelper to be created."; |
445 } | 446 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); | 626 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); |
626 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 627 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
627 new WebGraphicsContext3DCommandBufferImpl( | 628 new WebGraphicsContext3DCommandBufferImpl( |
628 surface_id, | 629 surface_id, |
629 url, | 630 url, |
630 gpu_channel_host.get(), | 631 gpu_channel_host.get(), |
631 attrs, | 632 attrs, |
632 lose_context_when_out_of_memory, | 633 lose_context_when_out_of_memory, |
633 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(), | 634 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(), |
634 NULL)); | 635 NULL)); |
635 return context.Pass(); | 636 return context; |
636 } | 637 } |
637 | 638 |
638 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { | 639 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { |
639 base::ThreadTaskRunnerHandle::Get()->PostTask( | 640 base::ThreadTaskRunnerHandle::Get()->PostTask( |
640 FROM_HERE, | 641 FROM_HERE, |
641 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, | 642 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, |
642 callback_factory_.GetWeakPtr())); | 643 callback_factory_.GetWeakPtr())); |
643 } | 644 } |
644 | 645 |
645 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { | 646 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { |
646 LOG(ERROR) << "Lost UI shared context."; | 647 LOG(ERROR) << "Lost UI shared context."; |
647 | 648 |
648 // Keep old resources around while we call the observers, but ensure that | 649 // Keep old resources around while we call the observers, but ensure that |
649 // new resources are created if needed. | 650 // new resources are created if needed. |
650 // Kill shared contexts for both threads in tandem so they are always in | 651 // Kill shared contexts for both threads in tandem so they are always in |
651 // the same share group. | 652 // the same share group. |
652 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = | 653 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = |
653 shared_main_thread_contexts_; | 654 shared_main_thread_contexts_; |
654 shared_main_thread_contexts_ = NULL; | 655 shared_main_thread_contexts_ = NULL; |
655 | 656 |
656 scoped_ptr<GLHelper> lost_gl_helper = gl_helper_.Pass(); | 657 scoped_ptr<GLHelper> lost_gl_helper = std::move(gl_helper_); |
657 | 658 |
658 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 659 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
659 observer_list_, | 660 observer_list_, |
660 OnLostResources()); | 661 OnLostResources()); |
661 | 662 |
662 // Kill things that use the shared context before killing the shared context. | 663 // Kill things that use the shared context before killing the shared context. |
663 lost_gl_helper.reset(); | 664 lost_gl_helper.reset(); |
664 lost_shared_main_thread_contexts = NULL; | 665 lost_shared_main_thread_contexts = NULL; |
665 } | 666 } |
666 | 667 |
667 } // namespace content | 668 } // namespace content |
OLD | NEW |