| 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 "cc/output/in_process_context_provider.h" | 9 #include "cc/output/in_process_context_provider.h" |
| 10 #include "cc/surfaces/surface.h" | 10 #include "cc/surfaces/surface.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 gpu::ImageFactory* image_factory, | 21 gpu::ImageFactory* image_factory, |
| 22 cc::mojom::DisplayCompositorRequest request, | 22 cc::mojom::DisplayCompositorRequest request, |
| 23 cc::mojom::DisplayCompositorClientPtr client) | 23 cc::mojom::DisplayCompositorClientPtr client) |
| 24 : gpu_service_(std::move(gpu_service)), | 24 : gpu_service_(std::move(gpu_service)), |
| 25 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), | 25 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), |
| 26 image_factory_(image_factory), | 26 image_factory_(image_factory), |
| 27 client_(std::move(client)), | 27 client_(std::move(client)), |
| 28 reference_manager_(&manager_), | 28 reference_manager_(&manager_), |
| 29 binding_(this, std::move(request)) { | 29 binding_(this, std::move(request)) { |
| 30 manager_.AddObserver(this); | 30 manager_.AddObserver(this); |
| 31 if (client_) |
| 32 client_->OnRootSurfaceId(GetRootSurfaceId()); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void DisplayCompositor::CreateCompositorFrameSink( | 35 void DisplayCompositor::CreateCompositorFrameSink( |
| 34 const cc::FrameSinkId& frame_sink_id, | 36 const cc::FrameSinkId& frame_sink_id, |
| 35 gpu::SurfaceHandle surface_handle, | 37 gpu::SurfaceHandle surface_handle, |
| 36 cc::mojom::MojoCompositorFrameSinkRequest request, | 38 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 37 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 39 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 38 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 40 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 39 DCHECK(thread_checker_.CalledOnValidThread()); | 41 DCHECK(thread_checker_.CalledOnValidThread()); |
| 40 // We cannot create more than one CompositorFrameSink with a given | 42 // We cannot create more than one CompositorFrameSink with a given |
| 41 // |frame_sink_id|. | 43 // |frame_sink_id|. |
| 42 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 44 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 43 scoped_refptr<cc::InProcessContextProvider> context_provider; | 45 scoped_refptr<cc::InProcessContextProvider> context_provider; |
| 44 if (surface_handle != gpu::kNullSurfaceHandle) { | 46 if (surface_handle != gpu::kNullSurfaceHandle) { |
| 45 context_provider = new cc::InProcessContextProvider( | 47 context_provider = new cc::InProcessContextProvider( |
| 46 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), | 48 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), |
| 47 image_factory_, gpu::SharedMemoryLimits(), | 49 image_factory_, gpu::SharedMemoryLimits(), |
| 48 nullptr /* shared_context */); | 50 nullptr /* shared_context */); |
| 49 } | 51 } |
| 50 compositor_frame_sinks_[frame_sink_id] = | 52 compositor_frame_sinks_[frame_sink_id] = |
| 51 base::MakeUnique<GpuCompositorFrameSink>( | 53 base::MakeUnique<GpuCompositorFrameSink>( |
| 52 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), | 54 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), |
| 53 std::move(context_provider), std::move(request), | 55 std::move(context_provider), std::move(request), |
| 54 std::move(private_request), std::move(client)); | 56 std::move(private_request), std::move(client)); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { | 59 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) { |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); | 60 DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 AddSurfaceReference(GetRootSurfaceId(), child_id); | 61 const cc::SurfaceId& parent_id = ref.parent_id(); |
| 60 } | 62 const cc::SurfaceId& child_id = ref.child_id(); |
| 61 | 63 |
| 62 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, | |
| 63 const cc::SurfaceId& child_id) { | |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 65 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); | 64 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); |
| 66 | 65 |
| 67 // If there are no temporary references for the FrameSinkId then we can just | 66 // If there are no temporary references for the FrameSinkId then we can just |
| 68 // add reference and return. | 67 // add reference and return. |
| 69 if (vector_iter == temp_references_.end()) { | 68 if (vector_iter == temp_references_.end()) { |
| 70 reference_manager_->AddSurfaceReference(parent_id, child_id); | 69 reference_manager_->AddSurfaceReference(parent_id, child_id); |
| 71 return; | 70 return; |
| 72 } | 71 } |
| 73 | 72 |
| 74 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for | 73 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for |
| (...skipping 28 matching lines...) Expand all Loading... |
| 103 // Remove markers for temporary references up to |child_id|, as the temporary | 102 // Remove markers for temporary references up to |child_id|, as the temporary |
| 104 // references they correspond to were removed above. If |ref_iter| is the last | 103 // references they correspond to were removed above. If |ref_iter| is the last |
| 105 // element in |refs| then we are removing all temporary references for the | 104 // element in |refs| then we are removing all temporary references for the |
| 106 // FrameSinkId and can remove the map entry entirely. | 105 // FrameSinkId and can remove the map entry entirely. |
| 107 if (++temp_ref_iter == refs.end()) | 106 if (++temp_ref_iter == refs.end()) |
| 108 temp_references_.erase(child_id.frame_sink_id()); | 107 temp_references_.erase(child_id.frame_sink_id()); |
| 109 else | 108 else |
| 110 refs.erase(refs.begin(), ++temp_ref_iter); | 109 refs.erase(refs.begin(), ++temp_ref_iter); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void DisplayCompositor::RemoveRootSurfaceReference( | 112 void DisplayCompositor::RemoveSurfaceReference( |
| 114 const cc::SurfaceId& child_id) { | 113 const cc::SurfaceReference& ref) { |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 116 RemoveSurfaceReference(GetRootSurfaceId(), child_id); | |
| 117 } | |
| 118 | |
| 119 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, | |
| 120 const cc::SurfaceId& child_id) { | |
| 121 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 122 // TODO(kylechar): Each remove reference can trigger GC, it would be better if | 114 // TODO(kylechar): Each remove reference can trigger GC, it would be better if |
| 123 // we GC only once if removing multiple references. | 115 // we GC only once if removing multiple references. |
| 124 reference_manager_->RemoveSurfaceReference(parent_id, child_id); | 116 reference_manager_->RemoveSurfaceReference(ref.parent_id(), ref.child_id()); |
| 125 } | 117 } |
| 126 | 118 |
| 127 DisplayCompositor::~DisplayCompositor() { | 119 DisplayCompositor::~DisplayCompositor() { |
| 128 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 129 // Remove all temporary references on shutdown. | 121 // Remove all temporary references on shutdown. |
| 130 for (auto& map_entry : temp_references_) { | 122 for (auto& map_entry : temp_references_) { |
| 131 const cc::FrameSinkId& frame_sink_id = map_entry.first; | 123 const cc::FrameSinkId& frame_sink_id = map_entry.first; |
| 132 for (auto& local_frame_id : map_entry.second) { | 124 for (auto& local_frame_id : map_entry.second) { |
| 133 reference_manager_->RemoveSurfaceReference( | 125 reference_manager_->RemoveSurfaceReference( |
| 134 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id)); | 126 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 surface_id.local_frame_id()); | 167 surface_id.local_frame_id()); |
| 176 | 168 |
| 177 if (client_) | 169 if (client_) |
| 178 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 170 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| 179 } | 171 } |
| 180 | 172 |
| 181 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 173 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 182 bool* changed) {} | 174 bool* changed) {} |
| 183 | 175 |
| 184 } // namespace ui | 176 } // namespace ui |
| OLD | NEW |