OLD | NEW |
---|---|
(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 #ifndef SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ | |
6 #define SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ | |
7 | |
8 #include <unordered_map> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "cc/ipc/mojo_compositor_frame_sink.mojom.h" | |
13 #include "cc/surfaces/frame_sink_id.h" | |
14 #include "cc/surfaces/surface_id.h" | |
15 #include "cc/surfaces/surface_reference.h" | |
16 | |
17 namespace ui { | |
18 | |
19 namespace test { | |
20 class EmbeddedSurfaceTrackerTest; | |
21 } | |
22 | |
23 // Tracks surface references from a client surface to all surfaces embedded in | |
24 // the client surface. Handles updating the references when the client surface | |
25 // resizes. | |
26 // TODO(kylechar): This class should move somewhere else, cc/surfaces maybe? | |
27 class EmbeddedSurfaceTracker { | |
Fady Samuel
2017/01/05 19:36:19
Can we move this to cc/surfaces.
kylechar
2017/01/06 17:58:40
Done.
| |
28 public: | |
29 EmbeddedSurfaceTracker(); | |
30 ~EmbeddedSurfaceTracker(); | |
31 | |
32 const cc::SurfaceId& current_surface_id() const { | |
33 return current_surface_id_; | |
34 } | |
35 | |
36 // Checks if the client has a valid SurfaceId. This will become true after | |
37 // SetCurrentSurfaceId() is called for the first time. No references will be | |
38 // added or removed until this is true. | |
39 bool HasValidSurfaceId() const { return current_surface_id_.is_valid(); } | |
40 | |
41 // Sets |current_surface_id_| when the client switches surfaces. Clears all | |
42 // references waiting to be added or removed, since no CompositorFrame will be | |
43 // submitted for the previous surface now. Generates new references from the | |
44 // new surface to all embedded surfaces. Does not send IPC. | |
45 void SetCurrentSurfaceId(const cc::SurfaceId& surface_id); | |
46 | |
47 // Adds a reference from |current_surface_id_| to |embedded_id| and records | |
48 // |embedded_id|. If an existing surface with the same FrameSinkId is embedded | |
49 // removes the reference to it. Does not send IPC. | |
50 void EmbedSurface(const cc::SurfaceId& embedded_id); | |
51 | |
52 // Removes reference from |current_surface_id_| to latest embedded surface for | |
53 // |frame_sink_id|. Does not send IPC. | |
54 void UnembedSurface(const cc::FrameSinkId& frame_sink_id); | |
55 | |
56 // Sends IPC to add references in |references_to_add_|. This should be called | |
57 // *before* the next CompositorFrame is submitted. Does nothing if there are | |
58 // no references to add. | |
59 void SendAddSurfaceReferences( | |
60 cc::mojom::MojoCompositorFrameSink* compositor_frame_sink); | |
Fady Samuel
2017/01/05 19:36:19
Don't depend on mojo.
kylechar
2017/01/06 17:58:40
Done.
| |
61 | |
62 // Sends IPC to remove all references in |references_to_remove_|. This should | |
63 // be called *after* the next CompositorFrame is submitted. Does nothing if | |
64 // there are no references to remove. | |
65 void SendRemoveSurfaceReferences( | |
66 cc::mojom::MojoCompositorFrameSink* compositor_frame_sink); | |
67 | |
68 private: | |
69 friend class test::EmbeddedSurfaceTrackerTest; | |
70 | |
71 // Records adding a reference from |parent_id| to |child_id|. References are | |
72 // not actually added until SendAddSurfaceReferences() is called. | |
73 void AddReference(const cc::SurfaceId& parent_id, | |
74 const cc::SurfaceId& child_id); | |
75 | |
76 // Records removing a reference from |parent_id| to |child_id|. References | |
77 // are not actually removed until SendRemoveSurfaceReferences() is called. | |
78 void RemoveReference(const cc::SurfaceId& parent_id, | |
79 const cc::SurfaceId& child_id); | |
80 | |
81 // The SurfaceId of the client surface that is embedding other surfaces. | |
82 cc::SurfaceId current_surface_id_; | |
83 | |
84 // Surfaces that are embedded by the client surface. A reference from | |
85 // |current_surface_id_| will be added if it's valid. | |
86 std::unordered_map<cc::FrameSinkId, cc::SurfaceId, cc::FrameSinkIdHash> | |
87 embedded_surfaces_; | |
88 | |
89 // References to surfaces that should be removed after the next | |
90 // CompositorFrame has been submitted and the surfaces are no longer embedded. | |
91 std::vector<cc::SurfaceReference> references_to_remove_; | |
92 | |
93 // References that should be added before the next CompositorFrame is | |
94 // submitted. | |
95 std::vector<cc::SurfaceReference> references_to_add_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(EmbeddedSurfaceTracker); | |
98 }; | |
99 | |
100 } // namespace ui | |
101 | |
102 #endif // SERVICES_UI_WS_EMBEDDED_SURFACE_TRACKER_H_ | |
OLD | NEW |