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 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "cc/base/histograms.h" | 19 #include "cc/base/histograms.h" |
20 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
21 #include "cc/output/output_surface.h" | 21 #include "cc/output/output_surface.h" |
22 #include "cc/raster/single_thread_task_graph_runner.h" | 22 #include "cc/raster/single_thread_task_graph_runner.h" |
23 #include "cc/raster/task_graph_runner.h" | 23 #include "cc/raster/task_graph_runner.h" |
24 #include "cc/surfaces/onscreen_display_client.h" | 24 #include "cc/surfaces/onscreen_display_client.h" |
25 #include "cc/surfaces/surface_display_output_surface.h" | 25 #include "cc/surfaces/surface_display_output_surface.h" |
26 #include "cc/surfaces/surface_manager.h" | 26 #include "cc/surfaces/surface_manager.h" |
27 #include "components/display_compositor/gl_helper.h" | |
28 #include "content/browser/compositor/browser_compositor_output_surface.h" | 27 #include "content/browser/compositor/browser_compositor_output_surface.h" |
29 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 28 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
| 29 #include "content/browser/compositor/gl_helper.h" |
30 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 30 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
31 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" | 31 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" |
32 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" | 32 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" |
33 #include "content/browser/compositor/reflector_impl.h" | 33 #include "content/browser/compositor/reflector_impl.h" |
34 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" | 34 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
35 #include "content/browser/compositor/software_output_device_mus.h" | 35 #include "content/browser/compositor/software_output_device_mus.h" |
36 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 36 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
37 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 37 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
38 #include "content/browser/gpu/gpu_data_manager_impl.h" | 38 #include "content/browser/gpu/gpu_data_manager_impl.h" |
39 #include "content/browser/gpu/gpu_surface_tracker.h" | 39 #include "content/browser/gpu/gpu_surface_tracker.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 if (data->surface_id) | 481 if (data->surface_id) |
482 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 482 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
483 delete data; | 483 delete data; |
484 per_compositor_data_.erase(it); | 484 per_compositor_data_.erase(it); |
485 if (per_compositor_data_.empty()) { | 485 if (per_compositor_data_.empty()) { |
486 // Destroying the GLHelper may cause some async actions to be cancelled, | 486 // Destroying the GLHelper may cause some async actions to be cancelled, |
487 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 487 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
488 // GLHelper created in this case would be lost/leaked if we just reset() | 488 // GLHelper created in this case would be lost/leaked if we just reset() |
489 // on the |gl_helper_| variable directly. So instead we call reset() on a | 489 // on the |gl_helper_| variable directly. So instead we call reset() on a |
490 // local std::unique_ptr. | 490 // local std::unique_ptr. |
491 std::unique_ptr<display_compositor::GLHelper> helper = | 491 std::unique_ptr<GLHelper> helper = std::move(gl_helper_); |
492 std::move(gl_helper_); | |
493 | 492 |
494 // If there are any observer left at this point, make sure they clean up | 493 // If there are any observer left at this point, make sure they clean up |
495 // before we destroy the GLHelper. | 494 // before we destroy the GLHelper. |
496 FOR_EACH_OBSERVER( | 495 FOR_EACH_OBSERVER( |
497 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 496 ImageTransportFactoryObserver, observer_list_, OnLostResources()); |
498 | 497 |
499 helper.reset(); | 498 helper.reset(); |
500 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 499 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
501 "GLHelper to be created."; | 500 "GLHelper to be created."; |
502 } | 501 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 PerCompositorData* data = it->second; | 547 PerCompositorData* data = it->second; |
549 DCHECK(data); | 548 DCHECK(data); |
550 if (data->display_client) | 549 if (data->display_client) |
551 data->display_client->display()->Resize(size); | 550 data->display_client->display()->Resize(size); |
552 } | 551 } |
553 | 552 |
554 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { | 553 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { |
555 return surface_manager_.get(); | 554 return surface_manager_.get(); |
556 } | 555 } |
557 | 556 |
558 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 557 GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
559 if (!gl_helper_ && !per_compositor_data_.empty()) { | 558 if (!gl_helper_ && !per_compositor_data_.empty()) { |
560 scoped_refptr<cc::ContextProvider> provider = | 559 scoped_refptr<cc::ContextProvider> provider = |
561 SharedMainThreadContextProvider(); | 560 SharedMainThreadContextProvider(); |
562 if (provider.get()) | 561 if (provider.get()) |
563 gl_helper_.reset(new display_compositor::GLHelper( | 562 gl_helper_.reset(new GLHelper(provider->ContextGL(), |
564 provider->ContextGL(), provider->ContextSupport())); | 563 provider->ContextSupport())); |
565 } | 564 } |
566 return gl_helper_.get(); | 565 return gl_helper_.get(); |
567 } | 566 } |
568 | 567 |
569 void GpuProcessTransportFactory::AddObserver( | 568 void GpuProcessTransportFactory::AddObserver( |
570 ImageTransportFactoryObserver* observer) { | 569 ImageTransportFactoryObserver* observer) { |
571 observer_list_.AddObserver(observer); | 570 observer_list_.AddObserver(observer); |
572 } | 571 } |
573 | 572 |
574 void GpuProcessTransportFactory::RemoveObserver( | 573 void GpuProcessTransportFactory::RemoveObserver( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 LOG(ERROR) << "Lost UI shared context."; | 668 LOG(ERROR) << "Lost UI shared context."; |
670 | 669 |
671 // Keep old resources around while we call the observers, but ensure that | 670 // Keep old resources around while we call the observers, but ensure that |
672 // new resources are created if needed. | 671 // new resources are created if needed. |
673 // Kill shared contexts for both threads in tandem so they are always in | 672 // Kill shared contexts for both threads in tandem so they are always in |
674 // the same share group. | 673 // the same share group. |
675 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = | 674 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = |
676 shared_main_thread_contexts_; | 675 shared_main_thread_contexts_; |
677 shared_main_thread_contexts_ = NULL; | 676 shared_main_thread_contexts_ = NULL; |
678 | 677 |
679 std::unique_ptr<display_compositor::GLHelper> lost_gl_helper = | 678 std::unique_ptr<GLHelper> lost_gl_helper = std::move(gl_helper_); |
680 std::move(gl_helper_); | |
681 | 679 |
682 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 680 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
683 observer_list_, | 681 observer_list_, |
684 OnLostResources()); | 682 OnLostResources()); |
685 | 683 |
686 // Kill things that use the shared context before killing the shared context. | 684 // Kill things that use the shared context before killing the shared context. |
687 lost_gl_helper.reset(); | 685 lost_gl_helper.reset(); |
688 lost_shared_main_thread_contexts = NULL; | 686 lost_shared_main_thread_contexts = NULL; |
689 } | 687 } |
690 | 688 |
691 } // namespace content | 689 } // namespace content |
OLD | NEW |