| 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/mojo_frame_sink_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/base/switches.h" | 11 #include "cc/base/switches.h" |
| 12 #include "cc/scheduler/begin_frame_source.h" | 12 #include "cc/scheduler/begin_frame_source.h" |
| 13 #include "cc/surfaces/display.h" | 13 #include "cc/surfaces/display.h" |
| 14 #include "cc/surfaces/surface_dependency_tracker.h" | 14 #include "cc/surfaces/surface_dependency_tracker.h" |
| 15 #include "components/display_compositor/gpu_compositor_frame_sink.h" | 15 #include "components/display_compositor/gpu_compositor_frame_sink.h" |
| 16 #include "components/display_compositor/gpu_root_compositor_frame_sink.h" | 16 #include "components/display_compositor/gpu_root_compositor_frame_sink.h" |
| 17 #include "services/ui/surfaces/display_provider.h" | 17 #include "services/ui/surfaces/display_provider.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 DisplayCompositor::DisplayCompositor( | 21 MojoFrameSinkManager::MojoFrameSinkManager( |
| 22 DisplayProvider* display_provider, | 22 DisplayProvider* display_provider, |
| 23 cc::mojom::DisplayCompositorRequest request, | 23 cc::mojom::FrameSinkManagerRequest request, |
| 24 cc::mojom::DisplayCompositorClientPtr client) | 24 cc::mojom::FrameSinkManagerClientPtr client) |
| 25 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), | 25 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), |
| 26 display_provider_(display_provider), | 26 display_provider_(display_provider), |
| 27 client_(std::move(client)), | 27 client_(std::move(client)), |
| 28 binding_(this, std::move(request)) { | 28 binding_(this, std::move(request)) { |
| 29 manager_.AddObserver(this); | 29 manager_.AddObserver(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 DisplayCompositor::~DisplayCompositor() { | 32 MojoFrameSinkManager::~MojoFrameSinkManager() { |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
| 34 manager_.RemoveObserver(this); | 34 manager_.RemoveObserver(this); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void DisplayCompositor::CreateRootCompositorFrameSink( | 37 void MojoFrameSinkManager::CreateRootCompositorFrameSink( |
| 38 const cc::FrameSinkId& frame_sink_id, | 38 const cc::FrameSinkId& frame_sink_id, |
| 39 gpu::SurfaceHandle surface_handle, | 39 gpu::SurfaceHandle surface_handle, |
| 40 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, | 40 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, |
| 41 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 41 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 42 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 42 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 43 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { | 43 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); | 45 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); |
| 46 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 46 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 47 DCHECK(display_provider_); | 47 DCHECK(display_provider_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 compositor_frame_sinks_[frame_sink_id] = | 63 compositor_frame_sinks_[frame_sink_id] = |
| 64 base::MakeUnique<display_compositor::GpuRootCompositorFrameSink>( | 64 base::MakeUnique<display_compositor::GpuRootCompositorFrameSink>( |
| 65 this, &manager_, frame_sink_id, std::move(display), | 65 this, &manager_, frame_sink_id, std::move(display), |
| 66 std::move(begin_frame_source), std::move(request), | 66 std::move(begin_frame_source), std::move(request), |
| 67 std::move(private_request), std::move(client), | 67 std::move(private_request), std::move(client), |
| 68 std::move(display_private_request)); | 68 std::move(display_private_request)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DisplayCompositor::CreateCompositorFrameSink( | 71 void MojoFrameSinkManager::CreateCompositorFrameSink( |
| 72 const cc::FrameSinkId& frame_sink_id, | 72 const cc::FrameSinkId& frame_sink_id, |
| 73 cc::mojom::MojoCompositorFrameSinkRequest request, | 73 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 74 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 74 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 75 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 75 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 77 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 78 | 78 |
| 79 compositor_frame_sinks_[frame_sink_id] = | 79 compositor_frame_sinks_[frame_sink_id] = |
| 80 base::MakeUnique<display_compositor::GpuCompositorFrameSink>( | 80 base::MakeUnique<display_compositor::GpuCompositorFrameSink>( |
| 81 this, &manager_, frame_sink_id, std::move(request), | 81 this, &manager_, frame_sink_id, std::move(request), |
| 82 std::move(private_request), std::move(client)); | 82 std::move(private_request), std::move(client)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void DisplayCompositor::RegisterFrameSinkHierarchy( | 85 void MojoFrameSinkManager::RegisterFrameSinkHierarchy( |
| 86 const cc::FrameSinkId& parent_frame_sink_id, | 86 const cc::FrameSinkId& parent_frame_sink_id, |
| 87 const cc::FrameSinkId& child_frame_sink_id) { | 87 const cc::FrameSinkId& child_frame_sink_id) { |
| 88 manager_.RegisterFrameSinkHierarchy(parent_frame_sink_id, | 88 manager_.RegisterFrameSinkHierarchy(parent_frame_sink_id, |
| 89 child_frame_sink_id); | 89 child_frame_sink_id); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DisplayCompositor::UnregisterFrameSinkHierarchy( | 92 void MojoFrameSinkManager::UnregisterFrameSinkHierarchy( |
| 93 const cc::FrameSinkId& parent_frame_sink_id, | 93 const cc::FrameSinkId& parent_frame_sink_id, |
| 94 const cc::FrameSinkId& child_frame_sink_id) { | 94 const cc::FrameSinkId& child_frame_sink_id) { |
| 95 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id, | 95 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id, |
| 96 child_frame_sink_id); | 96 child_frame_sink_id); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DisplayCompositor::DropTemporaryReference( | 99 void MojoFrameSinkManager::DropTemporaryReference( |
| 100 const cc::SurfaceId& surface_id) { | 100 const cc::SurfaceId& surface_id) { |
| 101 manager_.DropTemporaryReference(surface_id); | 101 manager_.DropTemporaryReference(surface_id); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void DisplayCompositor::DestroyCompositorFrameSink(cc::FrameSinkId sink_id) { | 104 void MojoFrameSinkManager::DestroyCompositorFrameSink(cc::FrameSinkId sink_id) { |
| 105 compositor_frame_sinks_.erase(sink_id); | 105 compositor_frame_sinks_.erase(sink_id); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceInfo& surface_info) { | 108 void MojoFrameSinkManager::OnSurfaceCreated( |
| 109 const cc::SurfaceInfo& surface_info) { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); | 111 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); |
| 111 | 112 |
| 112 // TODO(kylechar): |client_| will try to find an owner for the temporary | 113 // TODO(kylechar): |client_| will try to find an owner for the temporary |
| 113 // reference to the new surface. With surface synchronization this might not | 114 // reference to the new surface. With surface synchronization this might not |
| 114 // be necessary, because a surface reference might already exist and no | 115 // be necessary, because a surface reference might already exist and no |
| 115 // temporary reference was created. It could be useful to let |client_| know | 116 // temporary reference was created. It could be useful to let |client_| know |
| 116 // if it should find an owner. | 117 // if it should find an owner. |
| 117 if (client_) | 118 if (client_) |
| 118 client_->OnSurfaceCreated(surface_info); | 119 client_->OnSurfaceCreated(surface_info); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 122 void MojoFrameSinkManager::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 122 bool* changed) {} | 123 bool* changed) {} |
| 123 | 124 |
| 124 void DisplayCompositor::OnClientConnectionLost( | 125 void MojoFrameSinkManager::OnClientConnectionLost( |
| 125 const cc::FrameSinkId& frame_sink_id, | 126 const cc::FrameSinkId& frame_sink_id, |
| 126 bool destroy_compositor_frame_sink) { | 127 bool destroy_compositor_frame_sink) { |
| 127 DCHECK(thread_checker_.CalledOnValidThread()); | 128 DCHECK(thread_checker_.CalledOnValidThread()); |
| 128 if (destroy_compositor_frame_sink) | 129 if (destroy_compositor_frame_sink) |
| 129 DestroyCompositorFrameSink(frame_sink_id); | 130 DestroyCompositorFrameSink(frame_sink_id); |
| 130 // TODO(fsamuel): Tell the display compositor host that the client connection | 131 // TODO(fsamuel): Tell the frame sink manager host that the client connection |
| 131 // has been lost so that it can drop its private connection and allow a new | 132 // has been lost so that it can drop its private connection and allow a new |
| 132 // client instance to create a new CompositorFrameSink. | 133 // client instance to create a new CompositorFrameSink. |
| 133 } | 134 } |
| 134 | 135 |
| 135 void DisplayCompositor::OnPrivateConnectionLost( | 136 void MojoFrameSinkManager::OnPrivateConnectionLost( |
| 136 const cc::FrameSinkId& frame_sink_id, | 137 const cc::FrameSinkId& frame_sink_id, |
| 137 bool destroy_compositor_frame_sink) { | 138 bool destroy_compositor_frame_sink) { |
| 138 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
| 139 if (destroy_compositor_frame_sink) | 140 if (destroy_compositor_frame_sink) |
| 140 DestroyCompositorFrameSink(frame_sink_id); | 141 DestroyCompositorFrameSink(frame_sink_id); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace ui | 144 } // namespace ui |
| OLD | NEW |