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

Side by Side Diff: services/ui/ws/embedded_surface_tracker.cc

Issue 2610063007: Separate client surface reference tracking from FrameGenerator. (Closed)
Patch Set: Cleanup tests. Created 3 years, 11 months 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/ui/ws/embedded_surface_tracker.h"
6
7 #include "base/logging.h"
8
9 namespace ui {
10
11 EmbeddedSurfaceTracker::EmbeddedSurfaceTracker() {}
12
13 EmbeddedSurfaceTracker::~EmbeddedSurfaceTracker() {}
14
15 void EmbeddedSurfaceTracker::SetCurrentSurfaceId(
16 const cc::SurfaceId& surface_id) {
17 DCHECK(surface_id.is_valid());
18
19 // The last submitted CompositorFrame for |current_surface_id_| still embeds
20 // the surfaces in |references_to_remove_| and hasn't embedded the surfaces in
21 // |references_to_add_| yet.
22 references_to_remove_.clear();
23 references_to_add_.clear();
24
25 current_surface_id_ = surface_id;
26
27 // Add references from updated |current_surface_id_| to all embedded surfaces.
28 for (auto& map_entry : embedded_surfaces_)
29 AddReference(current_surface_id_, map_entry.second);
30 }
31
32 void EmbeddedSurfaceTracker::EmbedSurface(const cc::SurfaceId& embedded_id) {
33 auto iter = embedded_surfaces_.find(embedded_id.frame_sink_id());
34
35 // This is the first surface for the FrameSinkId.
36 if (iter == embedded_surfaces_.end()) {
37 if (HasValidSurfaceId())
38 AddReference(current_surface_id_, embedded_id);
39
40 embedded_surfaces_[embedded_id.frame_sink_id()] = embedded_id;
41 return;
42 }
43
44 // This is not the first surface for the FrameSinkId, we are unembedding the
45 // old surface and embedding a new Surface.
46 cc::SurfaceId& stored_surface_id = iter->second;
47 DCHECK_NE(stored_surface_id, embedded_id);
48
49 if (HasValidSurfaceId()) {
50 RemoveReference(current_surface_id_, stored_surface_id);
51 AddReference(current_surface_id_, embedded_id);
52 }
53
54 stored_surface_id = embedded_id;
55 }
56
57 void EmbeddedSurfaceTracker::UnembedSurface(
58 const cc::FrameSinkId& frame_sink_id) {
59 auto iter = embedded_surfaces_.find(frame_sink_id);
60 if (iter == embedded_surfaces_.end())
61 return;
62
63 if (HasValidSurfaceId())
64 RemoveReference(current_surface_id_, iter->second);
65
66 embedded_surfaces_.erase(iter);
67 }
68
69 void EmbeddedSurfaceTracker::SendAddSurfaceReferences(
70 cc::mojom::MojoCompositorFrameSink* compositor_frame_sink) {
71 DCHECK(compositor_frame_sink);
72
73 if (references_to_add_.empty())
74 return;
75
76 compositor_frame_sink->AddSurfaceReferences(references_to_add_);
77 references_to_add_.clear();
78 }
79
80 void EmbeddedSurfaceTracker::SendRemoveSurfaceReferences(
81 cc::mojom::MojoCompositorFrameSink* compositor_frame_sink) {
82 DCHECK(compositor_frame_sink);
83
84 if (references_to_remove_.empty())
85 return;
86
87 compositor_frame_sink->RemoveSurfaceReferences(references_to_remove_);
88 references_to_remove_.clear();
89 }
90
91 void EmbeddedSurfaceTracker::AddReference(const cc::SurfaceId& parent_id,
92 const cc::SurfaceId& child_id) {
93 references_to_add_.push_back(cc::SurfaceReference(parent_id, child_id));
94 }
95
96 void EmbeddedSurfaceTracker::RemoveReference(const cc::SurfaceId& parent_id,
97 const cc::SurfaceId& child_id) {
98 references_to_remove_.push_back(cc::SurfaceReference(parent_id, child_id));
99 }
100
101 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698