OLD | NEW |
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 "content/renderer/android/synchronous_compositor_proxy.h" | 5 #include "content/renderer/android/synchronous_compositor_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "cc/ipc/cc_param_traits.h" | 10 #include "cc/ipc/cc_param_traits.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 : routing_id_(routing_id), | 28 : routing_id_(routing_id), |
29 sender_(sender), | 29 sender_(sender), |
30 input_handler_proxy_(input_handler_proxy), | 30 input_handler_proxy_(input_handler_proxy), |
31 use_in_process_zero_copy_software_draw_( | 31 use_in_process_zero_copy_software_draw_( |
32 base::CommandLine::ForCurrentProcess()->HasSwitch( | 32 base::CommandLine::ForCurrentProcess()->HasSwitch( |
33 switches::kSingleProcess)), | 33 switches::kSingleProcess)), |
34 output_surface_(nullptr), | 34 output_surface_(nullptr), |
35 inside_receive_(false), | 35 inside_receive_(false), |
36 hardware_draw_reply_(nullptr), | 36 hardware_draw_reply_(nullptr), |
37 software_draw_reply_(nullptr), | 37 software_draw_reply_(nullptr), |
| 38 hardware_draw_reply_async_(false), |
38 version_(0u), | 39 version_(0u), |
39 page_scale_factor_(0.f), | 40 page_scale_factor_(0.f), |
40 min_page_scale_factor_(0.f), | 41 min_page_scale_factor_(0.f), |
41 max_page_scale_factor_(0.f), | 42 max_page_scale_factor_(0.f), |
42 need_animate_scroll_(false), | 43 need_animate_scroll_(false), |
43 need_invalidate_count_(0u), | 44 need_invalidate_count_(0u), |
44 did_activate_pending_tree_count_(0u) { | 45 did_activate_pending_tree_count_(0u) { |
45 DCHECK(input_handler_proxy_); | 46 DCHECK(input_handler_proxy_); |
46 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); | 47 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); |
47 } | 48 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 129 |
129 void SynchronousCompositorProxy::OnMessageReceived( | 130 void SynchronousCompositorProxy::OnMessageReceived( |
130 const IPC::Message& message) { | 131 const IPC::Message& message) { |
131 if (output_surface_ && output_surface_->OnMessageReceived(message)) | 132 if (output_surface_ && output_surface_->OnMessageReceived(message)) |
132 return; | 133 return; |
133 | 134 |
134 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorProxy, message) | 135 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorProxy, message) |
135 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ComputeScroll, OnComputeScroll) | 136 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ComputeScroll, OnComputeScroll) |
136 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawHw, | 137 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawHw, |
137 DemandDrawHw) | 138 DemandDrawHw) |
| 139 IPC_MESSAGE_HANDLER(SyncCompositorMsg_DemandDrawHwAsync, DemandDrawHwAsync) |
138 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetSharedMemory, SetSharedMemory) | 140 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetSharedMemory, SetSharedMemory) |
139 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZeroSharedMemory, ZeroSharedMemory) | 141 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZeroSharedMemory, ZeroSharedMemory) |
140 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawSw, | 142 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawSw, |
141 DemandDrawSw) | 143 DemandDrawSw) |
142 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZoomBy, SynchronouslyZoomBy) | 144 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZoomBy, SynchronouslyZoomBy) |
143 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetScroll, SetScroll) | 145 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetScroll, SetScroll) |
144 IPC_END_MESSAGE_MAP() | 146 IPC_END_MESSAGE_MAP() |
145 } | 147 } |
146 | 148 |
147 bool SynchronousCompositorProxy::Send(IPC::Message* message) { | 149 bool SynchronousCompositorProxy::Send(IPC::Message* message) { |
148 return sender_->Send(message); | 150 return sender_->Send(message); |
149 } | 151 } |
150 | 152 |
| 153 void SynchronousCompositorProxy::DemandDrawHwAsync( |
| 154 const SyncCompositorDemandDrawHwParams& params) { |
| 155 DoDemandDrawHw(params, nullptr); |
| 156 } |
| 157 |
151 void SynchronousCompositorProxy::DemandDrawHw( | 158 void SynchronousCompositorProxy::DemandDrawHw( |
152 const SyncCompositorDemandDrawHwParams& params, | 159 const SyncCompositorDemandDrawHwParams& params, |
153 IPC::Message* reply_message) { | 160 IPC::Message* reply_message) { |
| 161 DCHECK(reply_message); |
| 162 DoDemandDrawHw(params, reply_message); |
| 163 } |
| 164 |
| 165 void SynchronousCompositorProxy::DoDemandDrawHw( |
| 166 const SyncCompositorDemandDrawHwParams& params, |
| 167 IPC::Message* reply_message) { |
154 DCHECK(!inside_receive_); | 168 DCHECK(!inside_receive_); |
155 DCHECK(reply_message); | |
156 | |
157 inside_receive_ = true; | 169 inside_receive_ = true; |
158 | 170 |
159 if (output_surface_) { | 171 if (output_surface_) { |
160 base::AutoReset<IPC::Message*> scoped_hardware_draw_reply( | 172 if (!reply_message) { |
161 &hardware_draw_reply_, reply_message); | 173 base::AutoReset<bool> scoped_hardware_draw_reply_async( |
162 output_surface_->DemandDrawHw(params.viewport_size, | 174 &hardware_draw_reply_async_, true); |
163 params.viewport_rect_for_tile_priority, | 175 output_surface_->DemandDrawHw(params.viewport_size, |
164 params.transform_for_tile_priority); | 176 params.viewport_rect_for_tile_priority, |
| 177 params.transform_for_tile_priority); |
| 178 } else { |
| 179 base::AutoReset<IPC::Message*> scoped_hardware_draw_reply( |
| 180 &hardware_draw_reply_, reply_message); |
| 181 output_surface_->DemandDrawHw(params.viewport_size, |
| 182 params.viewport_rect_for_tile_priority, |
| 183 params.transform_for_tile_priority); |
| 184 } |
165 } | 185 } |
166 | 186 |
167 if (inside_receive_) { | 187 if (inside_receive_) { |
168 // Did not swap. | 188 // Did not swap. |
169 SendDemandDrawHwReply(cc::CompositorFrame(), 0u, reply_message); | 189 if (!reply_message) { |
| 190 SendDemandDrawHwReplyAsync(cc::CompositorFrame(), 0u); |
| 191 } else { |
| 192 SendDemandDrawHwReply(cc::CompositorFrame(), 0u, reply_message); |
| 193 } |
170 inside_receive_ = false; | 194 inside_receive_ = false; |
171 } | 195 } |
172 } | 196 } |
173 | 197 |
| 198 void SynchronousCompositorProxy::SwapBuffersHwAsync(uint32_t output_surface_id, |
| 199 cc::CompositorFrame frame) { |
| 200 DCHECK(inside_receive_); |
| 201 DCHECK(hardware_draw_reply_async_); |
| 202 SendDemandDrawHwReplyAsync(std::move(frame), output_surface_id); |
| 203 inside_receive_ = false; |
| 204 } |
| 205 |
174 void SynchronousCompositorProxy::SwapBuffersHw(uint32_t output_surface_id, | 206 void SynchronousCompositorProxy::SwapBuffersHw(uint32_t output_surface_id, |
175 cc::CompositorFrame frame) { | 207 cc::CompositorFrame frame) { |
176 DCHECK(inside_receive_); | 208 DCHECK(inside_receive_); |
177 DCHECK(hardware_draw_reply_); | 209 DCHECK(hardware_draw_reply_); |
178 SendDemandDrawHwReply(std::move(frame), output_surface_id, | 210 SendDemandDrawHwReply(std::move(frame), output_surface_id, |
179 hardware_draw_reply_); | 211 hardware_draw_reply_); |
180 inside_receive_ = false; | 212 inside_receive_ = false; |
181 } | 213 } |
182 | 214 |
| 215 void SynchronousCompositorProxy::SendDemandDrawHwReplyAsync( |
| 216 cc::CompositorFrame frame, |
| 217 uint32_t output_surface_id) { |
| 218 Send(new SyncCompositorHostMsg_ReturnFrame(routing_id_, output_surface_id, |
| 219 frame)); |
| 220 } |
| 221 |
183 void SynchronousCompositorProxy::SendDemandDrawHwReply( | 222 void SynchronousCompositorProxy::SendDemandDrawHwReply( |
184 cc::CompositorFrame frame, | 223 cc::CompositorFrame frame, |
185 uint32_t output_surface_id, | 224 uint32_t output_surface_id, |
186 IPC::Message* reply_message) { | 225 IPC::Message* reply_message) { |
187 SyncCompositorCommonRendererParams common_renderer_params; | 226 SyncCompositorCommonRendererParams common_renderer_params; |
188 PopulateCommonParams(&common_renderer_params); | 227 PopulateCommonParams(&common_renderer_params); |
189 SyncCompositorMsg_DemandDrawHw::WriteReplyParams( | 228 SyncCompositorMsg_DemandDrawHw::WriteReplyParams( |
190 reply_message, common_renderer_params, output_surface_id, frame); | 229 reply_message, common_renderer_params, output_surface_id, frame); |
191 Send(reply_message); | 230 Send(reply_message); |
192 } | 231 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 IPC::Message* reply_message) { | 329 IPC::Message* reply_message) { |
291 SyncCompositorCommonRendererParams common_renderer_params; | 330 SyncCompositorCommonRendererParams common_renderer_params; |
292 PopulateCommonParams(&common_renderer_params); | 331 PopulateCommonParams(&common_renderer_params); |
293 SyncCompositorMsg_DemandDrawSw::WriteReplyParams( | 332 SyncCompositorMsg_DemandDrawSw::WriteReplyParams( |
294 reply_message, success, common_renderer_params, frame); | 333 reply_message, success, common_renderer_params, frame); |
295 Send(reply_message); | 334 Send(reply_message); |
296 } | 335 } |
297 | 336 |
298 void SynchronousCompositorProxy::SwapBuffers(uint32_t output_surface_id, | 337 void SynchronousCompositorProxy::SwapBuffers(uint32_t output_surface_id, |
299 cc::CompositorFrame frame) { | 338 cc::CompositorFrame frame) { |
300 DCHECK(hardware_draw_reply_ || software_draw_reply_); | 339 // Verify that exactly one of these is true. |
301 DCHECK(!(hardware_draw_reply_ && software_draw_reply_)); | 340 DCHECK(hardware_draw_reply_async_ || hardware_draw_reply_ || |
302 if (hardware_draw_reply_) { | 341 software_draw_reply_); |
| 342 DCHECK(!((hardware_draw_reply_ && software_draw_reply_) || |
| 343 (hardware_draw_reply_ && hardware_draw_reply_async_) || |
| 344 (software_draw_reply_ && hardware_draw_reply_async_))); |
| 345 if (hardware_draw_reply_async_) { |
| 346 SwapBuffersHwAsync(output_surface_id, std::move(frame)); |
| 347 } else if (hardware_draw_reply_) { |
303 SwapBuffersHw(output_surface_id, std::move(frame)); | 348 SwapBuffersHw(output_surface_id, std::move(frame)); |
304 } else if (software_draw_reply_) { | 349 } else if (software_draw_reply_) { |
305 SwapBuffersSw(std::move(frame)); | 350 SwapBuffersSw(std::move(frame)); |
306 } | 351 } |
307 } | 352 } |
308 | 353 |
309 void SynchronousCompositorProxy::OnComputeScroll( | 354 void SynchronousCompositorProxy::OnComputeScroll( |
310 base::TimeTicks animation_time) { | 355 base::TimeTicks animation_time) { |
311 if (need_animate_scroll_) { | 356 if (need_animate_scroll_) { |
312 need_animate_scroll_ = false; | 357 need_animate_scroll_ = false; |
(...skipping 13 matching lines...) Expand all Loading... |
326 | 371 |
327 void SynchronousCompositorProxy::SetScroll( | 372 void SynchronousCompositorProxy::SetScroll( |
328 const gfx::ScrollOffset& new_total_scroll_offset) { | 373 const gfx::ScrollOffset& new_total_scroll_offset) { |
329 if (total_scroll_offset_ == new_total_scroll_offset) | 374 if (total_scroll_offset_ == new_total_scroll_offset) |
330 return; | 375 return; |
331 total_scroll_offset_ = new_total_scroll_offset; | 376 total_scroll_offset_ = new_total_scroll_offset; |
332 input_handler_proxy_->SynchronouslySetRootScrollOffset(total_scroll_offset_); | 377 input_handler_proxy_->SynchronouslySetRootScrollOffset(total_scroll_offset_); |
333 } | 378 } |
334 | 379 |
335 } // namespace content | 380 } // namespace content |
OLD | NEW |