Chromium Code Reviews| Index: services/ui/surfaces/display_compositor.cc |
| diff --git a/services/ui/surfaces/display_compositor.cc b/services/ui/surfaces/display_compositor.cc |
| index f8126c0e681c3edbb2958125bf80a217a0bff3bc..19655cfb05383db49383bb5b6925883b59616cb6 100644 |
| --- a/services/ui/surfaces/display_compositor.cc |
| +++ b/services/ui/surfaces/display_compositor.cc |
| @@ -8,38 +8,76 @@ |
| namespace ui { |
| +namespace {} // namespace |
|
Fady Samuel
2016/11/10 13:53:02
delete?
kylechar
2016/11/14 19:05:38
Done.
|
| + |
| DisplayCompositor::DisplayCompositor( |
| cc::mojom::DisplayCompositorClientPtr client) |
| : client_(std::move(client)) { |
| manager_.AddObserver(this); |
| } |
| -void DisplayCompositor::AddSurfaceReference( |
| - const cc::SurfaceId& surface_id, |
| - const cc::SurfaceSequence& surface_sequence) { |
| - cc::Surface* surface = manager_.GetSurfaceForId(surface_id); |
| - if (!surface) { |
| - LOG(ERROR) << "Attempting to add dependency to nonexistent surface " |
| - << surface_id.ToString(); |
| +void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, |
| + const cc::SurfaceId& child_id) { |
| + // If there are no temporary references then we can just add. |
| + if (temp_references_.count(child_id.frame_sink_id()) == 0) { |
| + manager_.AddSurfaceReference(parent_id, child_id); |
| return; |
| } |
| - surface->AddDestructionDependency(surface_sequence); |
| + |
| + auto& refs = temp_references_[child_id.frame_sink_id()]; |
| + auto ref_iter = |
| + std::find(refs.begin(), refs.end(), child_id.local_frame_id()); |
|
Fady Samuel
2016/11/10 13:53:02
I was initially confused about what this is doing.
kylechar
2016/11/14 19:05:38
Done.
|
| + |
| + // Make sure not to double add reference here. |
| + if (parent_id != cc::SurfaceManager::kRootSurfaceId || ref_iter == refs.end()) |
| + manager_.AddSurfaceReference(parent_id, child_id); |
| + |
| + if (ref_iter == refs.end()) |
| + return; |
| + |
| + // Don't remove temporary reference if it was the same as real reference. |
| + if (parent_id != cc::SurfaceManager::kRootSurfaceId) |
|
Fady Samuel
2016/11/10 13:53:02
nit: Braces.
kylechar
2016/11/14 19:05:38
Done.
|
| + manager_.RemoveSurfaceReference(cc::SurfaceManager::kRootSurfaceId, |
| + child_id); |
| + |
| + // Remove temporary references for earlier frames. |
| + for (auto iter = refs.begin(); iter != ref_iter; ++iter) { |
| + cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter); |
| + manager_.RemoveSurfaceReference(cc::SurfaceManager::kRootSurfaceId, id); |
| + } |
| + |
| + refs.erase(refs.begin(), ++ref_iter); |
| + if (refs.empty()) |
| + temp_references_.erase(child_id.frame_sink_id()); |
| } |
| -void DisplayCompositor::ReturnSurfaceReferences( |
| - const cc::FrameSinkId& frame_sink_id, |
| - const std::vector<uint32_t>& sequences) { |
| - std::vector<uint32_t> sequences_copy(sequences); |
| - manager_.DidSatisfySequences(frame_sink_id, &sequences_copy); |
| +void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, |
| + const cc::SurfaceId& child_id) { |
| + manager_.RemoveSurfaceReference(parent_id, child_id); |
| } |
| DisplayCompositor::~DisplayCompositor() { |
| + // Remove all temporary references on shutdown. |
| + for (auto& map_entry : temp_references_) { |
| + const cc::FrameSinkId& frame_sink_id = map_entry.first; |
| + for (auto& local_frame_id : map_entry.second) { |
| + manager_.RemoveSurfaceReference( |
| + cc::SurfaceManager::kRootSurfaceId, |
| + cc::SurfaceId(frame_sink_id, local_frame_id)); |
| + } |
| + } |
| + temp_references_.clear(); |
| manager_.RemoveObserver(this); |
| } |
| void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
| const gfx::Size& frame_size, |
| float device_scale_factor) { |
| + // Add a temporary reference from the top level root to this surface. |
|
Fady Samuel
2016/11/10 13:53:02
A short description of why this temporary referenc
kylechar
2016/11/14 19:05:38
Done.
|
| + manager_.AddSurfaceReference(cc::SurfaceManager::kRootSurfaceId, surface_id); |
| + temp_references_[surface_id.frame_sink_id()].push_back( |
| + surface_id.local_frame_id()); |
| + |
| if (client_) |
| client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| } |