| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/ui/surfaces/display_compositor.h" | 5 #include "services/ui/surfaces/display_compositor.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/output/in_process_context_provider.h" | 11 #include "cc/output/in_process_context_provider.h" |
| 12 #include "cc/output/texture_mailbox_deleter.h" | 12 #include "cc/output/texture_mailbox_deleter.h" |
| 13 #include "cc/surfaces/display.h" | 13 #include "cc/surfaces/display.h" |
| 14 #include "cc/surfaces/display_scheduler.h" | 14 #include "cc/surfaces/display_scheduler.h" |
| 15 #include "cc/surfaces/surface.h" | 15 #include "cc/surfaces/surface.h" |
| 16 #include "components/display_compositor/gpu_display_compositor_frame_sink.h" | |
| 17 #include "components/display_compositor/gpu_offscreen_compositor_frame_sink.h" | |
| 18 #include "gpu/command_buffer/client/shared_memory_limits.h" | 16 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 19 #include "gpu/ipc/gpu_in_process_thread_service.h" | 17 #include "gpu/ipc/gpu_in_process_thread_service.h" |
| 20 #include "mojo/public/cpp/bindings/strong_binding.h" | 18 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 21 #include "services/ui/surfaces/display_output_surface.h" | 19 #include "services/ui/surfaces/display_output_surface.h" |
| 20 #include "services/ui/surfaces/gpu_display_compositor_frame_sink.h" |
| 21 #include "services/ui/surfaces/gpu_offscreen_compositor_frame_sink.h" |
| 22 | 22 |
| 23 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
| 24 #include "gpu/command_buffer/client/gles2_interface.h" | 24 #include "gpu/command_buffer/client/gles2_interface.h" |
| 25 #include "services/ui/surfaces/display_output_surface_ozone.h" | 25 #include "services/ui/surfaces/display_output_surface_ozone.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 namespace ui { | 28 namespace ui { |
| 29 | 29 |
| 30 DisplayCompositor::DisplayCompositor( | 30 DisplayCompositor::DisplayCompositor( |
| 31 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, | 31 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, |
| 32 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, | 32 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, |
| 33 gpu::ImageFactory* image_factory, | 33 gpu::ImageFactory* image_factory, |
| 34 cc::mojom::DisplayCompositorRequest request, | 34 cc::mojom::DisplayCompositorRequest request, |
| 35 cc::mojom::DisplayCompositorClientPtr client) | 35 cc::mojom::DisplayCompositorClientPtr client) |
| 36 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), | 36 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), |
| 37 reference_manager_(&manager_), | 37 reference_manager_(&manager_), |
| 38 gpu_service_(std::move(gpu_service)), | 38 gpu_service_(std::move(gpu_service)), |
| 39 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), | 39 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), |
| 40 image_factory_(image_factory), | 40 image_factory_(image_factory), |
| 41 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 41 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 42 client_(std::move(client)), | 42 client_(std::move(client)), |
| 43 binding_(this, std::move(request)) { | 43 binding_(this, std::move(request)) { |
| 44 manager_.AddObserver(this); | 44 manager_.AddObserver(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void DisplayCompositor::AddSurfaceReferences( |
| 48 const std::vector<cc::SurfaceReference>& references) { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 for (const auto& reference : references) { |
| 51 reference_manager_->AddSurfaceReference(reference.parent_id(), |
| 52 reference.child_id()); |
| 53 } |
| 54 } |
| 55 |
| 56 void DisplayCompositor::RemoveSurfaceReferences( |
| 57 const std::vector<cc::SurfaceReference>& references) { |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 |
| 60 // TODO(kylechar): Each remove reference can trigger GC, it would be better if |
| 61 // we GC only once if removing multiple references. |
| 62 for (const auto& reference : references) { |
| 63 reference_manager_->RemoveSurfaceReference(reference.parent_id(), |
| 64 reference.child_id()); |
| 65 } |
| 66 } |
| 67 |
| 47 DisplayCompositor::~DisplayCompositor() { | 68 DisplayCompositor::~DisplayCompositor() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 69 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 manager_.RemoveObserver(this); | 70 manager_.RemoveObserver(this); |
| 50 } | 71 } |
| 51 | 72 |
| 52 void DisplayCompositor::OnClientConnectionLost( | 73 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost( |
| 53 const cc::FrameSinkId& frame_sink_id, | 74 const cc::FrameSinkId& frame_sink_id, |
| 54 bool destroy_compositor_frame_sink) { | 75 bool destroy_compositor_frame_sink) { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 if (destroy_compositor_frame_sink) | 77 if (destroy_compositor_frame_sink) |
| 57 compositor_frame_sinks_.erase(frame_sink_id); | 78 compositor_frame_sinks_.erase(frame_sink_id); |
| 58 // TODO(fsamuel): Tell the display compositor host that the client connection | 79 // TODO(fsamuel): Tell the display compositor host that the client connection |
| 59 // has been lost so that it can drop its private connection and allow a new | 80 // has been lost so that it can drop its private connection and allow a new |
| 60 // client instance to create a new CompositorFrameSink. | 81 // client instance to create a new CompositorFrameSink. |
| 61 } | 82 } |
| 62 | 83 |
| 63 void DisplayCompositor::OnPrivateConnectionLost( | 84 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( |
| 64 const cc::FrameSinkId& frame_sink_id, | 85 const cc::FrameSinkId& frame_sink_id, |
| 65 bool destroy_compositor_frame_sink) { | 86 bool destroy_compositor_frame_sink) { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 if (destroy_compositor_frame_sink) | 88 if (destroy_compositor_frame_sink) |
| 68 compositor_frame_sinks_.erase(frame_sink_id); | 89 compositor_frame_sinks_.erase(frame_sink_id); |
| 69 } | 90 } |
| 70 | 91 |
| 71 void DisplayCompositor::CreateDisplayCompositorFrameSink( | 92 void DisplayCompositor::CreateDisplayCompositorFrameSink( |
| 72 const cc::FrameSinkId& frame_sink_id, | 93 const cc::FrameSinkId& frame_sink_id, |
| 73 gpu::SurfaceHandle surface_handle, | 94 gpu::SurfaceHandle surface_handle, |
| 74 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, | 95 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, |
| 75 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 96 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 76 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 97 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 77 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { | 98 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { |
| 78 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); | 100 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); |
| 80 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 101 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 81 | 102 |
| 82 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( | 103 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
| 83 new cc::DelayBasedBeginFrameSource( | 104 new cc::DelayBasedBeginFrameSource( |
| 84 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | 105 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); |
| 85 std::unique_ptr<cc::Display> display = | 106 std::unique_ptr<cc::Display> display = |
| 86 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); | 107 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); |
| 87 | 108 |
| 88 compositor_frame_sinks_[frame_sink_id] = | 109 compositor_frame_sinks_[frame_sink_id] = |
| 89 base::MakeUnique<display_compositor::GpuDisplayCompositorFrameSink>( | 110 base::MakeUnique<GpuDisplayCompositorFrameSink>( |
| 90 this, &manager_, frame_sink_id, std::move(display), | 111 this, frame_sink_id, std::move(display), |
| 91 std::move(begin_frame_source), std::move(request), | 112 std::move(begin_frame_source), std::move(request), |
| 92 std::move(private_request), std::move(client), | 113 std::move(private_request), std::move(client), |
| 93 std::move(display_private_request)); | 114 std::move(display_private_request)); |
| 94 } | 115 } |
| 95 | 116 |
| 96 void DisplayCompositor::CreateOffscreenCompositorFrameSink( | 117 void DisplayCompositor::CreateOffscreenCompositorFrameSink( |
| 97 const cc::FrameSinkId& frame_sink_id, | 118 const cc::FrameSinkId& frame_sink_id, |
| 98 cc::mojom::MojoCompositorFrameSinkRequest request, | 119 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 120 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 121 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 123 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 103 | 124 |
| 104 compositor_frame_sinks_[frame_sink_id] = | 125 compositor_frame_sinks_[frame_sink_id] = |
| 105 base::MakeUnique<display_compositor::GpuOffscreenCompositorFrameSink>( | 126 base::MakeUnique<GpuOffscreenCompositorFrameSink>( |
| 106 this, &manager_, frame_sink_id, std::move(request), | 127 this, frame_sink_id, std::move(request), std::move(private_request), |
| 107 std::move(private_request), std::move(client)); | 128 std::move(client)); |
| 108 } | 129 } |
| 109 | 130 |
| 110 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay( | 131 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay( |
| 111 const cc::FrameSinkId& frame_sink_id, | 132 const cc::FrameSinkId& frame_sink_id, |
| 112 gpu::SurfaceHandle surface_handle, | 133 gpu::SurfaceHandle surface_handle, |
| 113 cc::SyntheticBeginFrameSource* begin_frame_source) { | 134 cc::SyntheticBeginFrameSource* begin_frame_source) { |
| 114 scoped_refptr<cc::InProcessContextProvider> context_provider = | 135 scoped_refptr<cc::InProcessContextProvider> context_provider = |
| 115 new cc::InProcessContextProvider( | 136 new cc::InProcessContextProvider( |
| 116 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), | 137 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), |
| 117 image_factory_, gpu::SharedMemoryLimits(), | 138 image_factory_, gpu::SharedMemoryLimits(), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); | 179 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); |
| 159 | 180 |
| 160 if (client_) | 181 if (client_) |
| 161 client_->OnSurfaceCreated(surface_info); | 182 client_->OnSurfaceCreated(surface_info); |
| 162 } | 183 } |
| 163 | 184 |
| 164 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 185 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 165 bool* changed) {} | 186 bool* changed) {} |
| 166 | 187 |
| 167 } // namespace ui | 188 } // namespace ui |
| OLD | NEW |