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

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

Issue 2520513002: Add DisplayCompositorTest. (Closed)
Patch Set: Created 4 years, 1 month 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 "cc/surfaces/surface.h" 7 #include "cc/surfaces/surface.h"
8 8
9 namespace ui { 9 namespace ui {
10 10
11 DisplayCompositor::DisplayCompositor( 11 DisplayCompositor::DisplayCompositor(
12 cc::mojom::DisplayCompositorClientPtr client) 12 cc::mojom::DisplayCompositorClientPtr client)
13 : client_(std::move(client)) { 13 : client_(std::move(client)),
14 reference_manager_(&manager_),
15 root_surface_id_(reference_manager_->GetRootSurfaceId()) {
14 manager_.AddObserver(this); 16 manager_.AddObserver(this);
15 } 17 }
16 18
17 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { 19 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) {
18 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id); 20 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id);
19 } 21 }
20 22
21 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, 23 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
22 const cc::SurfaceId& child_id) { 24 const cc::SurfaceId& child_id) {
23 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); 25 auto vector_iter = temp_references_.find(child_id.frame_sink_id());
24 26
25 // If there are no temporary references for the FrameSinkId then we can just 27 // If there are no temporary references for the FrameSinkId then we can just
26 // add reference and return. 28 // add reference and return.
27 if (vector_iter == temp_references_.end()) { 29 if (vector_iter == temp_references_.end()) {
28 manager_.AddSurfaceReference(parent_id, child_id); 30 reference_manager_->AddSurfaceReference(parent_id, child_id);
29 return; 31 return;
30 } 32 }
31 33
32 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for 34 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for
33 // |child_id.local_frame_id| in that vector. If found, there is a temporary 35 // |child_id.local_frame_id| in that vector. If found, there is a temporary
34 // reference to |child_id|. 36 // reference to |child_id|.
35 std::vector<cc::LocalFrameId>& refs = vector_iter->second; 37 std::vector<cc::LocalFrameId>& refs = vector_iter->second;
36 auto temp_ref_iter = 38 auto temp_ref_iter =
37 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); 39 std::find(refs.begin(), refs.end(), child_id.local_frame_id());
38 40
39 if (temp_ref_iter == refs.end()) { 41 if (temp_ref_iter == refs.end()) {
40 manager_.AddSurfaceReference(parent_id, child_id); 42 reference_manager_->AddSurfaceReference(parent_id, child_id);
41 return; 43 return;
42 } 44 }
43 45
44 // All surfaces get a temporary reference to the top level root. If we want to 46 // All surfaces get a temporary reference to the top level root. If we want to
45 // add a real reference to the top level root then we do nothing. Otherwise 47 // add a real reference to the top level root then we do nothing. Otherwise
46 // remove the temporary reference and add the real reference. 48 // remove the temporary reference and add the real reference.
47 if (parent_id != manager_.GetRootSurfaceId()) { 49 if (parent_id != root_surface_id_) {
48 manager_.AddSurfaceReference(parent_id, child_id); 50 reference_manager_->AddSurfaceReference(parent_id, child_id);
49 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); 51 reference_manager_->RemoveSurfaceReference(root_surface_id_, child_id);
50 } 52 }
51 53
52 // Remove temporary references for surfaces with the same FrameSinkId that 54 // Remove temporary references for surfaces with the same FrameSinkId that
53 // were created before |child_id|. The earlier surfaces were never embedded in 55 // were created before |child_id|. The earlier surfaces were never embedded in
54 // the parent and the parent is embedding a later surface, so we know the 56 // the parent and the parent is embedding a later surface, so we know the
55 // parent doesn't need them anymore. 57 // parent doesn't need them anymore.
56 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) { 58 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) {
57 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); 59 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter);
58 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), id); 60 reference_manager_->RemoveSurfaceReference(root_surface_id_, id);
59 } 61 }
60 62
61 // Remove markers for temporary references up to |child_id|, as the temporary 63 // Remove markers for temporary references up to |child_id|, as the temporary
62 // references they correspond to were removed above. If |ref_iter| is the last 64 // references they correspond to were removed above. If |ref_iter| is the last
63 // element in |refs| then we are removing all temporary references for the 65 // element in |refs| then we are removing all temporary references for the
64 // FrameSinkId and can remove the map entry entirely. 66 // FrameSinkId and can remove the map entry entirely.
65 if (++temp_ref_iter == refs.end()) 67 if (++temp_ref_iter == refs.end())
66 temp_references_.erase(child_id.frame_sink_id()); 68 temp_references_.erase(child_id.frame_sink_id());
67 else 69 else
68 refs.erase(refs.begin(), ++temp_ref_iter); 70 refs.erase(refs.begin(), ++temp_ref_iter);
69 } 71 }
70 72
71 void DisplayCompositor::RemoveRootSurfaceReference( 73 void DisplayCompositor::RemoveRootSurfaceReference(
72 const cc::SurfaceId& child_id) { 74 const cc::SurfaceId& child_id) {
73 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); 75 RemoveSurfaceReference(root_surface_id_, child_id);
74 } 76 }
75 77
76 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, 78 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id,
77 const cc::SurfaceId& child_id) { 79 const cc::SurfaceId& child_id) {
78 // TODO(kylechar): Each remove reference can trigger GC, it would be better if 80 // TODO(kylechar): Each remove reference can trigger GC, it would be better if
79 // we GC only once if removing multiple references. 81 // we GC only once if removing multiple references.
80 manager_.RemoveSurfaceReference(parent_id, child_id); 82 reference_manager_->RemoveSurfaceReference(parent_id, child_id);
81 } 83 }
82 84
83 DisplayCompositor::~DisplayCompositor() { 85 DisplayCompositor::~DisplayCompositor() {
84 // Remove all temporary references on shutdown. 86 // Remove all temporary references on shutdown.
85 for (auto& map_entry : temp_references_) { 87 for (auto& map_entry : temp_references_) {
86 const cc::FrameSinkId& frame_sink_id = map_entry.first; 88 const cc::FrameSinkId& frame_sink_id = map_entry.first;
87 for (auto& local_frame_id : map_entry.second) { 89 for (auto& local_frame_id : map_entry.second) {
88 manager_.RemoveSurfaceReference( 90 reference_manager_->RemoveSurfaceReference(
89 manager_.GetRootSurfaceId(), 91 root_surface_id_, cc::SurfaceId(frame_sink_id, local_frame_id));
90 cc::SurfaceId(frame_sink_id, local_frame_id));
91 } 92 }
92 } 93 }
93 manager_.RemoveObserver(this); 94 manager_.RemoveObserver(this);
94 } 95 }
95 96
96 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, 97 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id,
97 const gfx::Size& frame_size, 98 const gfx::Size& frame_size,
98 float device_scale_factor) { 99 float device_scale_factor) {
99 // We can get into a situation where multiple CompositorFrames arrive for a 100 // We can get into a situation where multiple CompositorFrames arrive for a
100 // CompositorFrameSink before the DisplayCompositorClient can add any 101 // CompositorFrameSink before the DisplayCompositorClient can add any
101 // references for the frame. When the second frame with a new size arrives, 102 // references for the frame. When the second frame with a new size arrives,
102 // the first will be destroyed and then if there are no references it will be 103 // the first will be destroyed and then if there are no references it will be
103 // deleted during surface GC. A temporary reference, removed when a real 104 // deleted during surface GC. A temporary reference, removed when a real
104 // reference is received, is added to prevent this from happening. 105 // reference is received, is added to prevent this from happening.
105 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id); 106 reference_manager_->AddSurfaceReference(root_surface_id_, surface_id);
106 temp_references_[surface_id.frame_sink_id()].push_back( 107 temp_references_[surface_id.frame_sink_id()].push_back(
107 surface_id.local_frame_id()); 108 surface_id.local_frame_id());
108 109
109 if (client_) 110 if (client_)
110 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 111 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
111 } 112 }
112 113
113 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 114 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
114 bool* changed) {} 115 bool* changed) {}
115 116
116 } // namespace ui 117 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698