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 // If there are no temporary references then we can just add and return. |
| 24 if (temp_references_.count(child_id.frame_sink_id()) == 0) { | |
|
Fady Samuel
2016/11/18 03:46:06
nit: store temp_references_.find(child_id.frame_si
kylechar
2016/11/18 17:24:10
Done.
| |
| 25 manager_.AddSurfaceReference(parent_id, child_id); | |
| 24 return; | 26 return; |
| 25 } | 27 } |
| 26 surface->AddDestructionDependency(surface_sequence); | 28 |
| 29 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for | |
| 30 // child_id.local_frame_id() in that vector. If found, there is a temporary | |
| 31 // reference to |child_id|. | |
| 32 auto& refs = temp_references_[child_id.frame_sink_id()]; | |
| 33 auto ref_iter = | |
| 34 std::find(refs.begin(), refs.end(), child_id.local_frame_id()); | |
|
Fady Samuel
2016/11/18 03:46:06
This looks expensive but in practice I think the s
kylechar
2016/11/18 17:24:10
I can add one if you really want, but I'm not sure
| |
| 35 | |
| 36 if (ref_iter == refs.end()) { | |
| 37 manager_.AddSurfaceReference(parent_id, child_id); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 // If the real reference is from the top level root then we don't want to add | |
| 42 // new reference then remove temporary reference, since they're the same. | |
| 43 if (parent_id != manager_.GetRootSurfaceId()) { | |
| 44 manager_.AddSurfaceReference(parent_id, child_id); | |
| 45 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); | |
| 46 } | |
| 47 | |
| 48 // Remove temporary references for earlier frames. | |
|
Fady Samuel
2016/11/18 03:46:06
Add a comment about the reasoning for why this is
kylechar
2016/11/18 17:24:11
Done.
| |
| 49 for (auto iter = refs.begin(); iter != ref_iter; ++iter) { | |
| 50 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); | |
| 51 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), id); | |
| 52 } | |
| 53 | |
| 54 refs.erase(refs.begin(), ++ref_iter); | |
|
Fady Samuel
2016/11/18 03:46:06
This is removing the temp ref up to the |child_id|
kylechar
2016/11/18 17:24:11
Done.
| |
| 55 if (refs.empty()) | |
| 56 temp_references_.erase(child_id.frame_sink_id()); | |
| 27 } | 57 } |
| 28 | 58 |
| 29 void DisplayCompositor::ReturnSurfaceReferences( | 59 void DisplayCompositor::RemoveRootSurfaceReference( |
| 30 const cc::FrameSinkId& frame_sink_id, | 60 const cc::SurfaceId& child_id) { |
| 31 const std::vector<uint32_t>& sequences) { | 61 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); |
| 32 std::vector<uint32_t> sequences_copy(sequences); | 62 } |
| 33 manager_.DidSatisfySequences(frame_sink_id, &sequences_copy); | 63 |
| 64 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, | |
| 65 const cc::SurfaceId& child_id) { | |
| 66 manager_.RemoveSurfaceReference(parent_id, child_id); | |
| 34 } | 67 } |
| 35 | 68 |
| 36 DisplayCompositor::~DisplayCompositor() { | 69 DisplayCompositor::~DisplayCompositor() { |
| 70 // Remove all temporary references on shutdown. | |
| 71 for (auto& map_entry : temp_references_) { | |
| 72 const cc::FrameSinkId& frame_sink_id = map_entry.first; | |
| 73 for (auto& local_frame_id : map_entry.second) { | |
| 74 manager_.RemoveSurfaceReference( | |
|
Fady Samuel
2016/11/18 03:46:06
So this can cause multiple GCes right? I guess tha
kylechar
2016/11/18 17:24:10
Done.
| |
| 75 manager_.GetRootSurfaceId(), | |
| 76 cc::SurfaceId(frame_sink_id, local_frame_id)); | |
| 77 } | |
| 78 } | |
| 37 manager_.RemoveObserver(this); | 79 manager_.RemoveObserver(this); |
| 38 } | 80 } |
| 39 | 81 |
| 40 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 82 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
| 41 const gfx::Size& frame_size, | 83 const gfx::Size& frame_size, |
| 42 float device_scale_factor) { | 84 float device_scale_factor) { |
| 85 // We can get into a situation where multiple CompositorFrames arrive for a | |
| 86 // CompositorFrameSink before the DisplayCompositorClient can add any | |
| 87 // references for the frame. When the second frame with a new size arrives, | |
| 88 // the first will be destroyed and then if there are no references it will be | |
| 89 // deleted during surface GC. A temporary reference, removed when a real | |
| 90 // reference is received, is added to prevent this from happening. | |
| 91 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id); | |
| 92 temp_references_[surface_id.frame_sink_id()].push_back( | |
| 93 surface_id.local_frame_id()); | |
| 94 | |
| 43 if (client_) | 95 if (client_) |
| 44 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 96 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| 45 } | 97 } |
| 46 | 98 |
| 47 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 99 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 48 bool* changed) {} | 100 bool* changed) {} |
| 49 | 101 |
| 50 } // namespace ui | 102 } // namespace ui |
| OLD | NEW |