| 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> |
| 8 |
| 7 #include "cc/output/in_process_context_provider.h" | 9 #include "cc/output/in_process_context_provider.h" |
| 8 #include "cc/surfaces/surface.h" | 10 #include "cc/surfaces/surface.h" |
| 9 #include "gpu/command_buffer/client/shared_memory_limits.h" | 11 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 10 #include "gpu/ipc/gpu_in_process_thread_service.h" | 12 #include "gpu/ipc/gpu_in_process_thread_service.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" | 14 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" |
| 13 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" | 15 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 | 18 |
| 17 DisplayCompositor::DisplayCompositor( | 19 DisplayCompositor::DisplayCompositor( |
| 18 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, | 20 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, |
| 19 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, | 21 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, |
| 20 gpu::ImageFactory* image_factory, | 22 gpu::ImageFactory* image_factory, |
| 21 cc::mojom::DisplayCompositorRequest request, | 23 cc::mojom::DisplayCompositorRequest request, |
| 22 cc::mojom::DisplayCompositorClientPtr client) | 24 cc::mojom::DisplayCompositorClientPtr client) |
| 23 : gpu_service_(std::move(gpu_service)), | 25 : gpu_service_(std::move(gpu_service)), |
| 24 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), | 26 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), |
| 25 image_factory_(image_factory), | 27 image_factory_(image_factory), |
| 26 client_(std::move(client)), | 28 client_(std::move(client)), |
| 29 reference_manager_(&manager_), |
| 27 binding_(this, std::move(request)) { | 30 binding_(this, std::move(request)) { |
| 28 manager_.AddObserver(this); | 31 manager_.AddObserver(this); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void DisplayCompositor::CreateCompositorFrameSink( | 34 void DisplayCompositor::CreateCompositorFrameSink( |
| 32 const cc::FrameSinkId& frame_sink_id, | 35 const cc::FrameSinkId& frame_sink_id, |
| 33 gpu::SurfaceHandle surface_handle, | 36 gpu::SurfaceHandle surface_handle, |
| 34 cc::mojom::MojoCompositorFrameSinkRequest request, | 37 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 38 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 36 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 39 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 } | 50 } |
| 48 compositor_frame_sinks_[frame_sink_id] = | 51 compositor_frame_sinks_[frame_sink_id] = |
| 49 base::MakeUnique<GpuCompositorFrameSink>( | 52 base::MakeUnique<GpuCompositorFrameSink>( |
| 50 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), | 53 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), |
| 51 std::move(context_provider), std::move(request), | 54 std::move(context_provider), std::move(request), |
| 52 std::move(private_request), std::move(client)); | 55 std::move(private_request), std::move(client)); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { | 58 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id); | 60 AddSurfaceReference(GetRootSurfaceId(), child_id); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, | 63 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, |
| 61 const cc::SurfaceId& child_id) { | 64 const cc::SurfaceId& child_id) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 65 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); | 66 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); |
| 64 | 67 |
| 65 // If there are no temporary references for the FrameSinkId then we can just | 68 // If there are no temporary references for the FrameSinkId then we can just |
| 66 // add reference and return. | 69 // add reference and return. |
| 67 if (vector_iter == temp_references_.end()) { | 70 if (vector_iter == temp_references_.end()) { |
| 68 manager_.AddSurfaceReference(parent_id, child_id); | 71 reference_manager_->AddSurfaceReference(parent_id, child_id); |
| 69 return; | 72 return; |
| 70 } | 73 } |
| 71 | 74 |
| 72 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for | 75 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for |
| 73 // |child_id.local_frame_id| in that vector. If found, there is a temporary | 76 // |child_id.local_frame_id| in that vector. If found, there is a temporary |
| 74 // reference to |child_id|. | 77 // reference to |child_id|. |
| 75 std::vector<cc::LocalFrameId>& refs = vector_iter->second; | 78 std::vector<cc::LocalFrameId>& refs = vector_iter->second; |
| 76 auto temp_ref_iter = | 79 auto temp_ref_iter = |
| 77 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); | 80 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); |
| 78 | 81 |
| 79 if (temp_ref_iter == refs.end()) { | 82 if (temp_ref_iter == refs.end()) { |
| 80 manager_.AddSurfaceReference(parent_id, child_id); | 83 reference_manager_->AddSurfaceReference(parent_id, child_id); |
| 81 return; | 84 return; |
| 82 } | 85 } |
| 83 | 86 |
| 84 // All surfaces get a temporary reference to the top level root. If the parent | 87 // All surfaces get a temporary reference to the top level root. If the parent |
| 85 // wants to add a reference to the top level root then we do nothing. | 88 // wants to add a reference to the top level root then we do nothing. |
| 86 // Otherwise remove the temporary reference and add the reference. | 89 // Otherwise remove the temporary reference and add the reference. |
| 87 if (parent_id != manager_.GetRootSurfaceId()) { | 90 if (parent_id != GetRootSurfaceId()) { |
| 88 manager_.AddSurfaceReference(parent_id, child_id); | 91 reference_manager_->AddSurfaceReference(parent_id, child_id); |
| 89 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); | 92 reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), child_id); |
| 90 } | 93 } |
| 91 | 94 |
| 92 // Remove temporary references for surfaces with the same FrameSinkId that | 95 // Remove temporary references for surfaces with the same FrameSinkId that |
| 93 // were created before |child_id|. The earlier surfaces were never embedded in | 96 // were created before |child_id|. The earlier surfaces were never embedded in |
| 94 // the parent and the parent is embedding a later surface, so we know the | 97 // the parent and the parent is embedding a later surface, so we know the |
| 95 // parent doesn't need them anymore. | 98 // parent doesn't need them anymore. |
| 96 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) { | 99 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) { |
| 97 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); | 100 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); |
| 98 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), id); | 101 reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), id); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // Remove markers for temporary references up to |child_id|, as the temporary | 104 // Remove markers for temporary references up to |child_id|, as the temporary |
| 102 // references they correspond to were removed above. If |ref_iter| is the last | 105 // references they correspond to were removed above. If |ref_iter| is the last |
| 103 // element in |refs| then we are removing all temporary references for the | 106 // element in |refs| then we are removing all temporary references for the |
| 104 // FrameSinkId and can remove the map entry entirely. | 107 // FrameSinkId and can remove the map entry entirely. |
| 105 if (++temp_ref_iter == refs.end()) | 108 if (++temp_ref_iter == refs.end()) |
| 106 temp_references_.erase(child_id.frame_sink_id()); | 109 temp_references_.erase(child_id.frame_sink_id()); |
| 107 else | 110 else |
| 108 refs.erase(refs.begin(), ++temp_ref_iter); | 111 refs.erase(refs.begin(), ++temp_ref_iter); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void DisplayCompositor::RemoveRootSurfaceReference( | 114 void DisplayCompositor::RemoveRootSurfaceReference( |
| 112 const cc::SurfaceId& child_id) { | 115 const cc::SurfaceId& child_id) { |
| 113 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); | 117 RemoveSurfaceReference(GetRootSurfaceId(), child_id); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, | 120 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, |
| 118 const cc::SurfaceId& child_id) { | 121 const cc::SurfaceId& child_id) { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 // TODO(kylechar): Each remove reference can trigger GC, it would be better if | 123 // TODO(kylechar): Each remove reference can trigger GC, it would be better if |
| 121 // we GC only once if removing multiple references. | 124 // we GC only once if removing multiple references. |
| 122 manager_.RemoveSurfaceReference(parent_id, child_id); | 125 reference_manager_->RemoveSurfaceReference(parent_id, child_id); |
| 123 } | 126 } |
| 124 | 127 |
| 125 DisplayCompositor::~DisplayCompositor() { | 128 DisplayCompositor::~DisplayCompositor() { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 // Remove all temporary references on shutdown. | 130 // Remove all temporary references on shutdown. |
| 128 for (auto& map_entry : temp_references_) { | 131 for (auto& map_entry : temp_references_) { |
| 129 const cc::FrameSinkId& frame_sink_id = map_entry.first; | 132 const cc::FrameSinkId& frame_sink_id = map_entry.first; |
| 130 for (auto& local_frame_id : map_entry.second) { | 133 for (auto& local_frame_id : map_entry.second) { |
| 131 manager_.RemoveSurfaceReference( | 134 reference_manager_->RemoveSurfaceReference( |
| 132 manager_.GetRootSurfaceId(), | 135 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id)); |
| 133 cc::SurfaceId(frame_sink_id, local_frame_id)); | |
| 134 } | 136 } |
| 135 } | 137 } |
| 136 manager_.RemoveObserver(this); | 138 manager_.RemoveObserver(this); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost( | 141 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost( |
| 140 const cc::FrameSinkId& frame_sink_id, | 142 const cc::FrameSinkId& frame_sink_id, |
| 141 bool destroy_compositor_frame_sink) { | 143 bool destroy_compositor_frame_sink) { |
| 142 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
| 143 if (destroy_compositor_frame_sink) | 145 if (destroy_compositor_frame_sink) |
| 144 compositor_frame_sinks_.erase(frame_sink_id); | 146 compositor_frame_sinks_.erase(frame_sink_id); |
| 145 // TODO(fsamuel): Tell the display compositor host that the client connection | 147 // TODO(fsamuel): Tell the display compositor host that the client connection |
| 146 // has been lost so that it can drop its private connection and allow a new | 148 // has been lost so that it can drop its private connection and allow a new |
| 147 // client instance to create a new CompositorFrameSink. | 149 // client instance to create a new CompositorFrameSink. |
| 148 } | 150 } |
| 149 | 151 |
| 150 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( | 152 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( |
| 151 const cc::FrameSinkId& frame_sink_id, | 153 const cc::FrameSinkId& frame_sink_id, |
| 152 bool destroy_compositor_frame_sink) { | 154 bool destroy_compositor_frame_sink) { |
| 153 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 if (destroy_compositor_frame_sink) | 156 if (destroy_compositor_frame_sink) |
| 155 compositor_frame_sinks_.erase(frame_sink_id); | 157 compositor_frame_sinks_.erase(frame_sink_id); |
| 156 } | 158 } |
| 157 | 159 |
| 160 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { |
| 161 return reference_manager_->GetRootSurfaceId(); |
| 162 } |
| 163 |
| 158 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 164 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
| 159 const gfx::Size& frame_size, | 165 const gfx::Size& frame_size, |
| 160 float device_scale_factor) { | 166 float device_scale_factor) { |
| 161 DCHECK(thread_checker_.CalledOnValidThread()); | 167 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 // We can get into a situation where multiple CompositorFrames arrive for a | 168 // We can get into a situation where multiple CompositorFrames arrive for a |
| 163 // CompositorFrameSink before the DisplayCompositorClient can add any | 169 // CompositorFrameSink before the DisplayCompositorClient can add any |
| 164 // references for the frame. When the second frame with a new size arrives, | 170 // references for the frame. When the second frame with a new size arrives, |
| 165 // the first will be destroyed and then if there are no references it will be | 171 // the first will be destroyed and then if there are no references it will be |
| 166 // deleted during surface GC. A temporary reference, removed when a real | 172 // deleted during surface GC. A temporary reference, removed when a real |
| 167 // reference is received, is added to prevent this from happening. | 173 // reference is received, is added to prevent this from happening. |
| 168 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id); | 174 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); |
| 169 temp_references_[surface_id.frame_sink_id()].push_back( | 175 temp_references_[surface_id.frame_sink_id()].push_back( |
| 170 surface_id.local_frame_id()); | 176 surface_id.local_frame_id()); |
| 171 | 177 |
| 172 if (client_) | 178 if (client_) |
| 173 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 179 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| 174 } | 180 } |
| 175 | 181 |
| 176 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 182 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 177 bool* changed) {} | 183 bool* changed) {} |
| 178 | 184 |
| 179 } // namespace ui | 185 } // namespace ui |
| OLD | NEW |