Chromium Code Reviews| 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 "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 manager_.AddObserver(this); | 14 manager_.AddObserver(this); |
| 15 } | 15 } |
| 16 | 16 |
| 17 void DisplayCompositor::AddSurfaceReference( | 17 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { |
| 18 const cc::SurfaceId& surface_id, | 18 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id); |
| 19 const cc::SurfaceSequence& surface_sequence) { | 19 } |
| 20 cc::Surface* surface = manager_.GetSurfaceForId(surface_id); | 20 |
| 21 if (!surface) { | 21 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, |
| 22 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " | 22 const cc::SurfaceId& child_id) { |
| 23 << surface_id.ToString(); | 23 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); |
| 24 | |
| 25 // If there are no temporary references for the FrameSinkId then we can just | |
| 26 // add reference and return. | |
| 27 if (vector_iter == temp_references_.end()) { | |
| 28 manager_.AddSurfaceReference(parent_id, child_id); | |
| 24 return; | 29 return; |
| 25 } | 30 } |
| 26 surface->AddDestructionDependency(surface_sequence); | 31 |
| 32 // 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 | |
| 34 // reference to |child_id|. | |
| 35 std::vector<cc::LocalFrameId>& refs = vector_iter->second; | |
| 36 auto temp_ref_iter = | |
| 37 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); | |
| 38 | |
| 39 if (temp_ref_iter == refs.end()) { | |
| 40 manager_.AddSurfaceReference(parent_id, child_id); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 // 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 | |
|
Fady Samuel
2016/11/18 22:27:24
super nit: I don't like the word "real" here. I gu
kylechar
2016/11/21 14:48:22
I removed the word real and reworded a bit. Left t
| |
| 46 // remove the temporary reference and add the real reference. | |
| 47 if (parent_id != manager_.GetRootSurfaceId()) { | |
| 48 manager_.AddSurfaceReference(parent_id, child_id); | |
| 49 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); | |
| 50 } | |
| 51 | |
| 52 // Remove temporary references for surfaces with the same FrameSinkId that | |
| 53 // 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 | |
| 55 // parent doesn't need them anymore. | |
| 56 for (auto iter = refs.begin(); iter != temp_ref_iter; ++iter) { | |
| 57 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); | |
| 58 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), id); | |
| 59 } | |
| 60 | |
| 61 // 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 | |
| 63 // element in |refs| then we are removing all temporary references for the | |
| 64 // FrameSinkId and can remove the map entry entirely. | |
| 65 if (++temp_ref_iter == refs.end()) | |
| 66 temp_references_.erase(child_id.frame_sink_id()); | |
| 67 else | |
| 68 refs.erase(refs.begin(), ++temp_ref_iter); | |
| 27 } | 69 } |
| 28 | 70 |
| 29 void DisplayCompositor::ReturnSurfaceReferences( | 71 void DisplayCompositor::RemoveRootSurfaceReference( |
| 30 const cc::FrameSinkId& frame_sink_id, | 72 const cc::SurfaceId& child_id) { |
| 31 const std::vector<uint32_t>& sequences) { | 73 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); |
| 32 std::vector<uint32_t> sequences_copy(sequences); | 74 } |
| 33 manager_.DidSatisfySequences(frame_sink_id, &sequences_copy); | 75 |
| 76 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, | |
| 77 const cc::SurfaceId& child_id) { | |
| 78 // TODO(kylechar): Each remove reference can trigger GC, it would be better if | |
| 79 // we GC only once if removing multiple references. | |
| 80 manager_.RemoveSurfaceReference(parent_id, child_id); | |
| 34 } | 81 } |
| 35 | 82 |
| 36 DisplayCompositor::~DisplayCompositor() { | 83 DisplayCompositor::~DisplayCompositor() { |
| 84 // Remove all temporary references on shutdown. | |
| 85 for (auto& map_entry : temp_references_) { | |
| 86 const cc::FrameSinkId& frame_sink_id = map_entry.first; | |
| 87 for (auto& local_frame_id : map_entry.second) { | |
| 88 manager_.RemoveSurfaceReference( | |
| 89 manager_.GetRootSurfaceId(), | |
| 90 cc::SurfaceId(frame_sink_id, local_frame_id)); | |
| 91 } | |
| 92 } | |
| 37 manager_.RemoveObserver(this); | 93 manager_.RemoveObserver(this); |
| 38 } | 94 } |
| 39 | 95 |
| 40 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 96 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
| 41 const gfx::Size& frame_size, | 97 const gfx::Size& frame_size, |
| 42 float device_scale_factor) { | 98 float device_scale_factor) { |
| 99 // We can get into a situation where multiple CompositorFrames arrive for a | |
| 100 // CompositorFrameSink before the DisplayCompositorClient can add any | |
| 101 // 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 // deleted during surface GC. A temporary reference, removed when a real | |
| 104 // reference is received, is added to prevent this from happening. | |
| 105 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id); | |
| 106 temp_references_[surface_id.frame_sink_id()].push_back( | |
| 107 surface_id.local_frame_id()); | |
| 108 | |
| 43 if (client_) | 109 if (client_) |
| 44 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 110 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| 45 } | 111 } |
| 46 | 112 |
| 47 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 113 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 48 bool* changed) {} | 114 bool* changed) {} |
| 49 | 115 |
| 50 } // namespace ui | 116 } // namespace ui |
| OLD | NEW |