OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ | 5 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ |
6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ | 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | |
10 #include <vector> | |
11 | 9 |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
14 #include "cc/ipc/display_compositor.mojom.h" | 12 #include "cc/ipc/display_compositor.mojom.h" |
| 13 #include "cc/surfaces/embedded_surface_tracker.h" |
15 #include "cc/surfaces/frame_sink_id.h" | 14 #include "cc/surfaces/frame_sink_id.h" |
16 #include "cc/surfaces/surface_id.h" | 15 #include "cc/surfaces/surface_id.h" |
17 #include "cc/surfaces/surface_id_allocator.h" | 16 #include "cc/surfaces/surface_id_allocator.h" |
18 #include "cc/surfaces/surface_reference.h" | 17 #include "cc/surfaces/surface_reference.h" |
19 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" | 18 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" |
20 #include "services/ui/ws/ids.h" | 19 #include "services/ui/ws/ids.h" |
21 #include "services/ui/ws/server_window_delegate.h" | 20 #include "services/ui/ws/server_window_delegate.h" |
22 #include "services/ui/ws/server_window_tracker.h" | 21 #include "services/ui/ws/server_window_tracker.h" |
23 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
24 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 69 |
71 private: | 70 private: |
72 friend class ui::ws::test::FrameGeneratorTest; | 71 friend class ui::ws::test::FrameGeneratorTest; |
73 | 72 |
74 // cc::mojom::MojoCompositorFrameSinkClient implementation: | 73 // cc::mojom::MojoCompositorFrameSinkClient implementation: |
75 void DidReceiveCompositorFrameAck() override; | 74 void DidReceiveCompositorFrameAck() override; |
76 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; | 75 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; |
77 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; | 76 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
78 void WillDrawSurface() override; | 77 void WillDrawSurface() override; |
79 | 78 |
| 79 // Updates the display surface SurfaceId using new value in |local_frame_id_|. |
| 80 void UpdateDisplaySurfaceId(); |
| 81 |
80 // Generates the CompositorFrame. | 82 // Generates the CompositorFrame. |
81 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); | 83 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); |
82 | 84 |
83 // DrawWindow creates SurfaceDrawQuad for the provided ServerWindow and | 85 // DrawWindow creates SurfaceDrawQuad for the provided ServerWindow and |
84 // appends it to the provided cc::RenderPass. | 86 // appends it to the provided cc::RenderPass. |
85 void DrawWindow(cc::RenderPass* pass, ServerWindow* window); | 87 void DrawWindow(cc::RenderPass* pass, ServerWindow* window); |
86 | 88 |
87 // Finds the parent surface id for |window|. | |
88 cc::SurfaceId FindParentSurfaceId(ServerWindow* window); | |
89 | |
90 // Adds surface reference to local cache and surface manager. | |
91 void AddSurfaceReference(const cc::SurfaceId& parent_id, | |
92 const cc::SurfaceId& child_id); | |
93 | |
94 // Does work necessary for adding the first surface reference. | |
95 void AddFirstReference(const cc::SurfaceId& surface_id, ServerWindow* window); | |
96 | |
97 // Finds all Surfaces with references from |old_surface_id| and adds a new | |
98 // reference from |new_surface_id|. The caller should remove any references | |
99 // to |old_surface_id| afterwards to finish cleanup. | |
100 void AddNewParentReferences(const cc::SurfaceId& old_surface_id, | |
101 const cc::SurfaceId& new_surface_id); | |
102 | |
103 // Sends IPC to add references in |references_to_add_|. | |
104 void PerformAddSurfaceReferences(); | |
105 | |
106 // Sends IPC to remove all references in |references_to_remove_|. | |
107 void PerformRemoveSurfaceReferences(); | |
108 | |
109 // Removes any retained references for |frame_sink_id_|. | |
110 void RemoveFrameSinkReference(const cc::FrameSinkId& frame_sink_id); | |
111 | |
112 // Removes all retained references to surfaces. | |
113 void RemoveAllSurfaceReferences(); | |
114 | |
115 cc::mojom::DisplayCompositor* GetDisplayCompositor(); | |
116 | |
117 // ServerWindowObserver implementation. | 89 // ServerWindowObserver implementation. |
118 void OnWindowDestroying(ServerWindow* window) override; | 90 void OnWindowDestroying(ServerWindow* window) override; |
119 | 91 |
120 FrameGeneratorDelegate* delegate_; | 92 FrameGeneratorDelegate* delegate_; |
121 ServerWindow* const root_window_; | 93 ServerWindow* const root_window_; |
122 float device_scale_factor_ = 1.f; | 94 float device_scale_factor_ = 1.f; |
123 | 95 |
124 gfx::Size last_submitted_frame_size_; | 96 gfx::Size last_submitted_frame_size_; |
125 cc::LocalFrameId local_frame_id_; | 97 cc::LocalFrameId local_frame_id_; |
126 cc::SurfaceIdAllocator id_allocator_; | 98 cc::SurfaceIdAllocator id_allocator_; |
127 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; | 99 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; |
128 cc::mojom::DisplayPrivatePtr display_private_; | 100 cc::mojom::DisplayPrivatePtr display_private_; |
129 | 101 |
130 // Active references held by this client to surfaces that could be embedded in | 102 // Tracks surface references for embedded surfaces. |
131 // a CompositorFrame submitted from FrameGenerator. | 103 cc::EmbeddedSurfaceTracker surface_tracker_; |
132 std::unordered_map<cc::FrameSinkId, cc::SurfaceReference, cc::FrameSinkIdHash> | |
133 active_references_; | |
134 | |
135 // References to surfaces that should be removed after a CompositorFrame has | |
136 // been submitted and the surfaces are not being used. | |
137 std::vector<cc::SurfaceReference> references_to_remove_; | |
138 | |
139 // References that should be added before the next CompositorFrame is | |
140 // submitted. | |
141 std::vector<cc::SurfaceReference> references_to_add_; | |
142 | |
143 // If a CompositorFrame for a child surface is submitted before the first | |
144 // display root CompositorFrame, we can't add a reference from the unknown | |
145 // display root SurfaceId. Track the child SurfaceId here and add a reference | |
146 // to it when the display root SurfaceId is available. | |
147 std::vector<cc::SurfaceId> waiting_for_references_; | |
148 | 104 |
149 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; | 105 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; |
150 | 106 |
151 base::WeakPtrFactory<FrameGenerator> weak_factory_; | 107 base::WeakPtrFactory<FrameGenerator> weak_factory_; |
152 | 108 |
153 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); | 109 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); |
154 }; | 110 }; |
155 | 111 |
156 } // namespace ws | 112 } // namespace ws |
157 | 113 |
158 } // namespace ui | 114 } // namespace ui |
159 | 115 |
160 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ | 116 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ |
OLD | NEW |