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

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

Issue 2541683004: Add/remove surface references via MojoCompositorFrameSink. (Closed)
Patch Set: 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/surfaces/surface.h" 10 #include "cc/surfaces/surface.h"
(...skipping 11 matching lines...) Expand all
22 gpu::ImageFactory* image_factory, 22 gpu::ImageFactory* image_factory,
23 cc::mojom::DisplayCompositorRequest request, 23 cc::mojom::DisplayCompositorRequest request,
24 cc::mojom::DisplayCompositorClientPtr client) 24 cc::mojom::DisplayCompositorClientPtr client)
25 : gpu_service_(std::move(gpu_service)), 25 : gpu_service_(std::move(gpu_service)),
26 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), 26 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)),
27 image_factory_(image_factory), 27 image_factory_(image_factory),
28 client_(std::move(client)), 28 client_(std::move(client)),
29 reference_manager_(&manager_), 29 reference_manager_(&manager_),
30 binding_(this, std::move(request)) { 30 binding_(this, std::move(request)) {
31 manager_.AddObserver(this); 31 manager_.AddObserver(this);
32 if (client_)
33 client_->OnRootSurfaceId(GetRootSurfaceId());
32 } 34 }
33 35
34 void DisplayCompositor::CreateCompositorFrameSink( 36 void DisplayCompositor::CreateCompositorFrameSink(
35 const cc::FrameSinkId& frame_sink_id, 37 const cc::FrameSinkId& frame_sink_id,
36 gpu::SurfaceHandle surface_handle, 38 gpu::SurfaceHandle surface_handle,
37 cc::mojom::MojoCompositorFrameSinkRequest request, 39 cc::mojom::MojoCompositorFrameSinkRequest request,
38 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, 40 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
39 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 41 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
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 AddSurfaceReference(GetRootSurfaceId(), child_id); 60 const cc::SurfaceId& parent_id = ref.parent_id();
59 } 61 const cc::SurfaceId& child_id = ref.child_id();
60 62
61 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
62 const cc::SurfaceId& child_id) {
63 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); 63 auto vector_iter = temp_references_.find(child_id.frame_sink_id());
64 64
65 // If there are no temporary references for the FrameSinkId then we can just 65 // If there are no temporary references for the FrameSinkId then we can just
66 // add reference and return. 66 // add reference and return.
67 if (vector_iter == temp_references_.end()) { 67 if (vector_iter == temp_references_.end()) {
68 reference_manager_->AddSurfaceReference(parent_id, child_id); 68 CHECK(reference_manager_->AddSurfaceReference(parent_id, child_id));
69 return; 69 return;
70 } 70 }
71 71
72 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for 72 // 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 73 // |child_id.local_frame_id| in that vector. If found, there is a temporary
74 // reference to |child_id|. 74 // reference to |child_id|.
75 std::vector<cc::LocalFrameId>& refs = vector_iter->second; 75 std::vector<cc::LocalFrameId>& refs = vector_iter->second;
76 auto temp_ref_iter = 76 auto temp_ref_iter =
77 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); 77 std::find(refs.begin(), refs.end(), child_id.local_frame_id());
78 78
79 if (temp_ref_iter == refs.end()) { 79 if (temp_ref_iter == refs.end()) {
80 reference_manager_->AddSurfaceReference(parent_id, child_id); 80 CHECK(reference_manager_->AddSurfaceReference(parent_id, child_id));
81 return; 81 return;
82 } 82 }
83 83
84 // All surfaces get a temporary reference to the top level root. If the parent 84 // 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. 85 // wants to add a reference to the top level root then we do nothing.
86 // Otherwise remove the temporary reference and add the reference. 86 // Otherwise remove the temporary reference and add the reference.
87 if (parent_id != GetRootSurfaceId()) { 87 if (parent_id != GetRootSurfaceId()) {
88 reference_manager_->AddSurfaceReference(parent_id, child_id); 88 CHECK(reference_manager_->AddSurfaceReference(parent_id, child_id));
89 reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), child_id); 89 CHECK(reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(),
90 child_id));
90 } 91 }
91 92
92 // Remove temporary references for surfaces with the same FrameSinkId that 93 // Remove temporary references for surfaces with the same FrameSinkId that
93 // were created before |child_id|. The earlier surfaces were never embedded in 94 // 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 95 // the parent and the parent is embedding a later surface, so we know the
95 // parent doesn't need them anymore. 96 // parent doesn't need them anymore.
96 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) { 97 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) {
97 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); 98 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter);
98 reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), id); 99 CHECK(reference_manager_->RemoveSurfaceReference(GetRootSurfaceId(), id));
99 } 100 }
100 101
101 // 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
102 // 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
103 // 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
104 // FrameSinkId and can remove the map entry entirely. 105 // FrameSinkId and can remove the map entry entirely.
105 if (++temp_ref_iter == refs.end()) 106 if (++temp_ref_iter == refs.end())
106 temp_references_.erase(child_id.frame_sink_id()); 107 temp_references_.erase(child_id.frame_sink_id());
107 else 108 else
108 refs.erase(refs.begin(), ++temp_ref_iter); 109 refs.erase(refs.begin(), ++temp_ref_iter);
109 } 110 }
110 111
111 void DisplayCompositor::RemoveRootSurfaceReference( 112 void DisplayCompositor::RemoveSurfaceReference(
112 const cc::SurfaceId& child_id) { 113 const cc::SurfaceReference& ref) {
113 RemoveSurfaceReference(GetRootSurfaceId(), child_id);
114 }
115
116 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id,
117 const cc::SurfaceId& child_id) {
118 // 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
119 // we GC only once if removing multiple references. 115 // we GC only once if removing multiple references.
120 reference_manager_->RemoveSurfaceReference(parent_id, child_id); 116 CHECK(reference_manager_->RemoveSurfaceReference(ref.parent_id(),
117 ref.child_id()));
121 } 118 }
122 119
123 DisplayCompositor::~DisplayCompositor() { 120 DisplayCompositor::~DisplayCompositor() {
124 // Remove all temporary references on shutdown. 121 // Remove all temporary references on shutdown.
125 for (auto& map_entry : temp_references_) { 122 for (auto& map_entry : temp_references_) {
126 const cc::FrameSinkId& frame_sink_id = map_entry.first; 123 const cc::FrameSinkId& frame_sink_id = map_entry.first;
127 for (auto& local_frame_id : map_entry.second) { 124 for (auto& local_frame_id : map_entry.second) {
128 reference_manager_->RemoveSurfaceReference( 125 reference_manager_->RemoveSurfaceReference(
129 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id)); 126 GetRootSurfaceId(), cc::SurfaceId(frame_sink_id, local_frame_id));
130 } 127 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 surface_id.local_frame_id()); 164 surface_id.local_frame_id());
168 165
169 if (client_) 166 if (client_)
170 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 167 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
171 } 168 }
172 169
173 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 170 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
174 bool* changed) {} 171 bool* changed) {}
175 172
176 } // namespace ui 173 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698