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 #include "cc/test/test_compositor_frame_sink.h" | 5 #include "cc/test/test_compositor_frame_sink.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "cc/output/begin_frame_args.h" | 10 #include "cc/output/begin_frame_args.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( | 104 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( |
105 enlarge_pass_texture_amount_); | 105 enlarge_pass_texture_amount_); |
106 display_->SetVisible(true); | 106 display_->SetVisible(true); |
107 bound_ = true; | 107 bound_ = true; |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 void TestCompositorFrameSink::DetachFromClient() { | 111 void TestCompositorFrameSink::DetachFromClient() { |
112 // Some tests make BindToClient fail on purpose. ^__^ | 112 // Some tests make BindToClient fail on purpose. ^__^ |
113 if (bound_) { | 113 if (bound_) { |
114 if (delegated_local_frame_id_.is_valid()) | 114 surface_factory_->EvictSurface(); |
115 surface_factory_->Destroy(delegated_local_frame_id_); | |
116 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 115 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
117 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 116 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
118 display_ = nullptr; | 117 display_ = nullptr; |
119 bound_ = false; | 118 bound_ = false; |
120 } | 119 } |
121 surface_factory_ = nullptr; | 120 surface_factory_ = nullptr; |
122 surface_id_allocator_ = nullptr; | 121 surface_id_allocator_ = nullptr; |
123 surface_manager_ = nullptr; | 122 surface_manager_ = nullptr; |
124 test_client_ = nullptr; | 123 test_client_ = nullptr; |
125 CompositorFrameSink::DetachFromClient(); | 124 CompositorFrameSink::DetachFromClient(); |
126 } | 125 } |
127 | 126 |
128 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 127 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
129 test_client_->DisplayReceivedCompositorFrame(frame); | 128 test_client_->DisplayReceivedCompositorFrame(frame); |
130 | 129 |
131 if (!delegated_local_frame_id_.is_valid()) { | 130 if (!delegated_local_frame_id_.is_valid()) { |
132 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); | 131 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); |
133 surface_factory_->Create(delegated_local_frame_id_); | |
134 } | 132 } |
135 display_->SetLocalFrameId(delegated_local_frame_id_, | 133 display_->SetLocalFrameId(delegated_local_frame_id_, |
136 frame.metadata.device_scale_factor); | 134 frame.metadata.device_scale_factor); |
137 | 135 |
138 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
139 display_->Resize(frame_size); | 137 display_->Resize(frame_size); |
140 | 138 |
141 bool synchronous = !display_->has_scheduler(); | 139 bool synchronous = !display_->has_scheduler(); |
142 | 140 |
143 SurfaceFactory::DrawCallback draw_callback; | 141 SurfaceFactory::DrawCallback draw_callback; |
144 if (!synchronous) { | 142 if (!synchronous) { |
145 // For async draws, we use a callback tell when it is done, but for sync | 143 // For async draws, we use a callback tell when it is done, but for sync |
146 // draws we don't need one. Unretained is safe here because the callback | 144 // draws we don't need one. Unretained is safe here because the callback |
147 // will be run when |surface_factory_| is destroyed which is owned by this | 145 // will be run when |surface_factory_| is destroyed which is owned by this |
148 // class. | 146 // class. |
149 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 147 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
150 base::Unretained(this)); | 148 base::Unretained(this)); |
151 } | 149 } |
152 | 150 |
153 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_, | 151 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_, |
154 std::move(frame), draw_callback); | 152 std::move(frame), draw_callback); |
155 | 153 |
156 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { | 154 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { |
157 surface_factory_->RequestCopyOfSurface(delegated_local_frame_id_, | 155 surface_factory_->RequestCopyOfSurface(std::move(copy_request)); |
158 std::move(copy_request)); | |
159 } | 156 } |
160 copy_requests_.clear(); | 157 copy_requests_.clear(); |
161 | 158 |
162 if (synchronous) { | 159 if (synchronous) { |
163 display_->DrawAndSwap(); | 160 display_->DrawAndSwap(); |
164 // Post this to get a new stack frame so that we exit this function before | 161 // Post this to get a new stack frame so that we exit this function before |
165 // calling the client to tell it that it is done. | 162 // calling the client to tell it that it is done. |
166 task_runner_->PostTask(FROM_HERE, | 163 task_runner_->PostTask(FROM_HERE, |
167 base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 164 base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
168 weak_ptr_factory_.GetWeakPtr())); | 165 weak_ptr_factory_.GetWeakPtr())); |
169 } | 166 } |
170 } | 167 } |
171 | 168 |
172 void TestCompositorFrameSink::DidDrawCallback() { | 169 void TestCompositorFrameSink::DidDrawCallback() { |
173 // This is to unthrottle the next frame, not actually a notice that drawing is | 170 // This is to unthrottle the next frame, not actually a notice that drawing is |
174 // done. | 171 // done. |
175 client_->DidReceiveCompositorFrameAck(); | 172 client_->DidReceiveCompositorFrameAck(); |
176 } | 173 } |
177 | 174 |
178 void TestCompositorFrameSink::ForceReclaimResources() { | 175 void TestCompositorFrameSink::ForceReclaimResources() { |
179 if (capabilities_.can_force_reclaim_resources && | 176 if (capabilities_.can_force_reclaim_resources && |
180 delegated_local_frame_id_.is_valid()) { | 177 delegated_local_frame_id_.is_valid()) { |
181 surface_factory_->ClearSurface(delegated_local_frame_id_); | 178 surface_factory_->ClearSurface(); |
182 } | 179 } |
183 } | 180 } |
184 | 181 |
185 void TestCompositorFrameSink::ReturnResources( | 182 void TestCompositorFrameSink::ReturnResources( |
186 const ReturnedResourceArray& resources) { | 183 const ReturnedResourceArray& resources) { |
187 client_->ReclaimResources(resources); | 184 client_->ReclaimResources(resources); |
188 } | 185 } |
189 | 186 |
190 void TestCompositorFrameSink::SetBeginFrameSource( | 187 void TestCompositorFrameSink::SetBeginFrameSource( |
191 BeginFrameSource* begin_frame_source) { | 188 BeginFrameSource* begin_frame_source) { |
192 client_->SetBeginFrameSource(begin_frame_source); | 189 client_->SetBeginFrameSource(begin_frame_source); |
193 } | 190 } |
194 | 191 |
195 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { | 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { |
196 client_->DidLoseCompositorFrameSink(); | 193 client_->DidLoseCompositorFrameSink(); |
197 } | 194 } |
198 | 195 |
199 void TestCompositorFrameSink::DisplayWillDrawAndSwap( | 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap( |
200 bool will_draw_and_swap, | 197 bool will_draw_and_swap, |
201 const RenderPassList& render_passes) { | 198 const RenderPassList& render_passes) { |
202 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
203 } | 200 } |
204 | 201 |
205 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
206 test_client_->DisplayDidDrawAndSwap(); | 203 test_client_->DisplayDidDrawAndSwap(); |
207 } | 204 } |
208 | 205 |
209 } // namespace cc | 206 } // namespace cc |
OLD | NEW |