Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: services/ui/surfaces/display_compositor.cc

Issue 2541683004: Add/remove surface references via MojoCompositorFrameSink. (Closed)
Patch Set: Cleanup. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/output/texture_mailbox_deleter.h" 10 #include "cc/output/texture_mailbox_deleter.h"
(...skipping 21 matching lines...) Expand all
32 cc::mojom::DisplayCompositorClientPtr client) 32 cc::mojom::DisplayCompositorClientPtr client)
33 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), 33 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES),
34 reference_manager_(&manager_), 34 reference_manager_(&manager_),
35 gpu_service_(std::move(gpu_service)), 35 gpu_service_(std::move(gpu_service)),
36 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), 36 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)),
37 image_factory_(image_factory), 37 image_factory_(image_factory),
38 task_runner_(base::ThreadTaskRunnerHandle::Get()), 38 task_runner_(base::ThreadTaskRunnerHandle::Get()),
39 client_(std::move(client)), 39 client_(std::move(client)),
40 binding_(this, std::move(request)) { 40 binding_(this, std::move(request)) {
41 manager_.AddObserver(this); 41 manager_.AddObserver(this);
42 if (client_)
43 client_->OnDisplayCompositorCreated(GetRootSurfaceId());
44 }
45
46 void DisplayCompositor::AddSurfaceReferences(
47 const std::vector<cc::SurfaceReference>& references) {
48 DCHECK(thread_checker_.CalledOnValidThread());
49 for (auto& reference : references)
50 AddSurfaceReference(reference);
51 }
52
53 void DisplayCompositor::RemoveSurfaceReferences(
54 const std::vector<cc::SurfaceReference>& references) {
55 DCHECK(thread_checker_.CalledOnValidThread());
56
57 // TODO(kylechar): Each remove reference can trigger GC, it would be better if
58 // we GC only once if removing multiple references.
59 for (auto& reference : references)
60 RemoveSurfaceReference(reference);
61 }
62
63 DisplayCompositor::~DisplayCompositor() {
64 DCHECK(thread_checker_.CalledOnValidThread());
65 // Remove all temporary references on shutdown.
66 for (auto& map_entry : temp_references_) {
67 const cc::FrameSinkId& frame_sink_id = map_entry.first;
68 for (auto& local_frame_id : map_entry.second) {
69 reference_manager_->RemoveSurfaceReference(
70 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id));
71 }
72 }
73 manager_.RemoveObserver(this);
74 }
75
76 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost(
77 const cc::FrameSinkId& frame_sink_id,
78 bool destroy_compositor_frame_sink) {
79 DCHECK(thread_checker_.CalledOnValidThread());
80 if (destroy_compositor_frame_sink)
81 compositor_frame_sinks_.erase(frame_sink_id);
82 // TODO(fsamuel): Tell the display compositor host that the client connection
83 // has been lost so that it can drop its private connection and allow a new
84 // client instance to create a new CompositorFrameSink.
85 }
86
87 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost(
88 const cc::FrameSinkId& frame_sink_id,
89 bool destroy_compositor_frame_sink) {
90 DCHECK(thread_checker_.CalledOnValidThread());
91 if (destroy_compositor_frame_sink)
92 compositor_frame_sinks_.erase(frame_sink_id);
42 } 93 }
43 94
44 void DisplayCompositor::CreateCompositorFrameSink( 95 void DisplayCompositor::CreateCompositorFrameSink(
45 const cc::FrameSinkId& frame_sink_id, 96 const cc::FrameSinkId& frame_sink_id,
46 gpu::SurfaceHandle surface_handle, 97 gpu::SurfaceHandle surface_handle,
47 cc::mojom::MojoCompositorFrameSinkRequest request, 98 cc::mojom::MojoCompositorFrameSinkRequest request,
48 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, 99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
49 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 100 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
50 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
51 // We cannot create more than one CompositorFrameSink with a given 102 // We cannot create more than one CompositorFrameSink with a given
52 // |frame_sink_id|. 103 // |frame_sink_id|.
53 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); 104 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
54 105
55 std::unique_ptr<cc::Display> display; 106 std::unique_ptr<cc::Display> display;
56 if (surface_handle != gpu::kNullSurfaceHandle) 107 if (surface_handle != gpu::kNullSurfaceHandle)
57 display = CreateDisplay(frame_sink_id, surface_handle); 108 display = CreateDisplay(frame_sink_id, surface_handle);
58 109
59 compositor_frame_sinks_[frame_sink_id] = 110 compositor_frame_sinks_[frame_sink_id] =
60 base::MakeUnique<GpuCompositorFrameSink>( 111 base::MakeUnique<GpuCompositorFrameSink>(
61 this, frame_sink_id, std::move(display), std::move(request), 112 this, frame_sink_id, std::move(display), std::move(request),
62 std::move(private_request), std::move(client)); 113 std::move(private_request), std::move(client));
63 } 114 }
64 115
65 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { 116 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) {
66 DCHECK(thread_checker_.CalledOnValidThread()); 117 const cc::SurfaceId& parent_id = ref.parent_id();
67 AddSurfaceReference(GetRootSurfaceId(), child_id); 118 const cc::SurfaceId& child_id = ref.child_id();
68 }
69 119
70 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
71 const cc::SurfaceId& child_id) {
72 DCHECK(thread_checker_.CalledOnValidThread());
73 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); 120 auto vector_iter = temp_references_.find(child_id.frame_sink_id());
74 121
75 // If there are no temporary references for the FrameSinkId then we can just 122 // If there are no temporary references for the FrameSinkId then we can just
76 // add reference and return. 123 // add reference and return.
77 if (vector_iter == temp_references_.end()) { 124 if (vector_iter == temp_references_.end()) {
78 reference_manager_->AddSurfaceReference(parent_id, child_id); 125 reference_manager_->AddSurfaceReference(parent_id, child_id);
79 return; 126 return;
80 } 127 }
81 128
82 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for 129 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for
(...skipping 28 matching lines...) Expand all
111 // Remove markers for temporary references up to |child_id|, as the temporary 158 // Remove markers for temporary references up to |child_id|, as the temporary
112 // references they correspond to were removed above. If |ref_iter| is the last 159 // references they correspond to were removed above. If |ref_iter| is the last
113 // element in |refs| then we are removing all temporary references for the 160 // element in |refs| then we are removing all temporary references for the
114 // FrameSinkId and can remove the map entry entirely. 161 // FrameSinkId and can remove the map entry entirely.
115 if (++temp_ref_iter == refs.end()) 162 if (++temp_ref_iter == refs.end())
116 temp_references_.erase(child_id.frame_sink_id()); 163 temp_references_.erase(child_id.frame_sink_id());
117 else 164 else
118 refs.erase(refs.begin(), ++temp_ref_iter); 165 refs.erase(refs.begin(), ++temp_ref_iter);
119 } 166 }
120 167
121 void DisplayCompositor::RemoveRootSurfaceReference( 168 void DisplayCompositor::RemoveSurfaceReference(
122 const cc::SurfaceId& child_id) { 169 const cc::SurfaceReference& ref) {
123 DCHECK(thread_checker_.CalledOnValidThread()); 170 reference_manager_->RemoveSurfaceReference(ref.parent_id(), ref.child_id());
124 RemoveSurfaceReference(GetRootSurfaceId(), child_id);
125 }
126
127 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id,
128 const cc::SurfaceId& child_id) {
129 DCHECK(thread_checker_.CalledOnValidThread());
130 // TODO(kylechar): Each remove reference can trigger GC, it would be better if
131 // we GC only once if removing multiple references.
132 reference_manager_->RemoveSurfaceReference(parent_id, child_id);
133 }
134
135 DisplayCompositor::~DisplayCompositor() {
136 DCHECK(thread_checker_.CalledOnValidThread());
137 // Remove all temporary references on shutdown.
138 for (auto& map_entry : temp_references_) {
139 const cc::FrameSinkId& frame_sink_id = map_entry.first;
140 for (auto& local_frame_id : map_entry.second) {
141 reference_manager_->RemoveSurfaceReference(
142 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id));
143 }
144 }
145 manager_.RemoveObserver(this);
146 }
147
148 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost(
149 const cc::FrameSinkId& frame_sink_id,
150 bool destroy_compositor_frame_sink) {
151 DCHECK(thread_checker_.CalledOnValidThread());
152 if (destroy_compositor_frame_sink)
153 compositor_frame_sinks_.erase(frame_sink_id);
154 // TODO(fsamuel): Tell the display compositor host that the client connection
155 // has been lost so that it can drop its private connection and allow a new
156 // client instance to create a new CompositorFrameSink.
157 }
158
159 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost(
160 const cc::FrameSinkId& frame_sink_id,
161 bool destroy_compositor_frame_sink) {
162 DCHECK(thread_checker_.CalledOnValidThread());
163 if (destroy_compositor_frame_sink)
164 compositor_frame_sinks_.erase(frame_sink_id);
165 } 171 }
166 172
167 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay( 173 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay(
168 const cc::FrameSinkId& frame_sink_id, 174 const cc::FrameSinkId& frame_sink_id,
169 gpu::SurfaceHandle surface_handle) { 175 gpu::SurfaceHandle surface_handle) {
170 scoped_refptr<cc::InProcessContextProvider> context_provider = 176 scoped_refptr<cc::InProcessContextProvider> context_provider =
171 new cc::InProcessContextProvider( 177 new cc::InProcessContextProvider(
172 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), 178 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(),
173 image_factory_, gpu::SharedMemoryLimits(), 179 image_factory_, gpu::SharedMemoryLimits(),
174 nullptr /* shared_context */); 180 nullptr /* shared_context */);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 surface_id.local_frame_id()); 236 surface_id.local_frame_id());
231 237
232 if (client_) 238 if (client_)
233 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 239 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
234 } 240 }
235 241
236 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 242 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
237 bool* changed) {} 243 bool* changed) {}
238 244
239 } // namespace ui 245 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/surfaces/display_compositor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698