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

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

Issue 2489003002: Convert mustash use surface references. (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 namespace {} // namespace
Fady Samuel 2016/11/10 13:53:02 delete?
kylechar 2016/11/14 19:05:38 Done.
12
11 DisplayCompositor::DisplayCompositor( 13 DisplayCompositor::DisplayCompositor(
12 cc::mojom::DisplayCompositorClientPtr client) 14 cc::mojom::DisplayCompositorClientPtr client)
13 : client_(std::move(client)) { 15 : client_(std::move(client)) {
14 manager_.AddObserver(this); 16 manager_.AddObserver(this);
15 } 17 }
16 18
17 void DisplayCompositor::AddSurfaceReference( 19 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
18 const cc::SurfaceId& surface_id, 20 const cc::SurfaceId& child_id) {
19 const cc::SurfaceSequence& surface_sequence) { 21 // If there are no temporary references then we can just add.
20 cc::Surface* surface = manager_.GetSurfaceForId(surface_id); 22 if (temp_references_.count(child_id.frame_sink_id()) == 0) {
21 if (!surface) { 23 manager_.AddSurfaceReference(parent_id, child_id);
22 LOG(ERROR) << "Attempting to add dependency to nonexistent surface "
23 << surface_id.ToString();
24 return; 24 return;
25 } 25 }
26 surface->AddDestructionDependency(surface_sequence); 26
27 auto& refs = temp_references_[child_id.frame_sink_id()];
28 auto ref_iter =
29 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.
30
31 // Make sure not to double add reference here.
32 if (parent_id != cc::SurfaceManager::kRootSurfaceId || ref_iter == refs.end())
33 manager_.AddSurfaceReference(parent_id, child_id);
34
35 if (ref_iter == refs.end())
36 return;
37
38 // Don't remove temporary reference if it was the same as real reference.
39 if (parent_id != cc::SurfaceManager::kRootSurfaceId)
Fady Samuel 2016/11/10 13:53:02 nit: Braces.
kylechar 2016/11/14 19:05:38 Done.
40 manager_.RemoveSurfaceReference(cc::SurfaceManager::kRootSurfaceId,
41 child_id);
42
43 // Remove temporary references for earlier frames.
44 for (auto iter = refs.begin(); iter != ref_iter; ++iter) {
45 cc::SurfaceId id = cc::SurfaceId(child_id.frame_sink_id(), *iter);
46 manager_.RemoveSurfaceReference(cc::SurfaceManager::kRootSurfaceId, id);
47 }
48
49 refs.erase(refs.begin(), ++ref_iter);
50 if (refs.empty())
51 temp_references_.erase(child_id.frame_sink_id());
27 } 52 }
28 53
29 void DisplayCompositor::ReturnSurfaceReferences( 54 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id,
30 const cc::FrameSinkId& frame_sink_id, 55 const cc::SurfaceId& child_id) {
31 const std::vector<uint32_t>& sequences) { 56 manager_.RemoveSurfaceReference(parent_id, child_id);
32 std::vector<uint32_t> sequences_copy(sequences);
33 manager_.DidSatisfySequences(frame_sink_id, &sequences_copy);
34 } 57 }
35 58
36 DisplayCompositor::~DisplayCompositor() { 59 DisplayCompositor::~DisplayCompositor() {
60 // Remove all temporary references on shutdown.
61 for (auto& map_entry : temp_references_) {
62 const cc::FrameSinkId& frame_sink_id = map_entry.first;
63 for (auto& local_frame_id : map_entry.second) {
64 manager_.RemoveSurfaceReference(
65 cc::SurfaceManager::kRootSurfaceId,
66 cc::SurfaceId(frame_sink_id, local_frame_id));
67 }
68 }
69 temp_references_.clear();
37 manager_.RemoveObserver(this); 70 manager_.RemoveObserver(this);
38 } 71 }
39 72
40 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, 73 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id,
41 const gfx::Size& frame_size, 74 const gfx::Size& frame_size,
42 float device_scale_factor) { 75 float device_scale_factor) {
76 // 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.
77 manager_.AddSurfaceReference(cc::SurfaceManager::kRootSurfaceId, surface_id);
78 temp_references_[surface_id.frame_sink_id()].push_back(
79 surface_id.local_frame_id());
80
43 if (client_) 81 if (client_)
44 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 82 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
45 } 83 }
46 84
47 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 85 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
48 bool* changed) {} 86 bool* changed) {}
49 87
50 } // namespace ui 88 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698