OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/frame_host/render_widget_host_view_guest.h" | 5 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 if (platform_view_) | 272 if (platform_view_) |
273 platform_view_->SetNeedsBeginFrames(needs_begin_frames); | 273 platform_view_->SetNeedsBeginFrames(needs_begin_frames); |
274 } | 274 } |
275 | 275 |
276 void RenderWidgetHostViewGuest::SetTooltipText( | 276 void RenderWidgetHostViewGuest::SetTooltipText( |
277 const base::string16& tooltip_text) { | 277 const base::string16& tooltip_text) { |
278 if (guest_) | 278 if (guest_) |
279 guest_->SetTooltipText(tooltip_text); | 279 guest_->SetTooltipText(tooltip_text); |
280 } | 280 } |
281 | 281 |
282 bool RenderWidgetHostViewGuest::ShouldRecreateSurface( | |
283 uint32_t compositor_frame_sink_id, | |
284 const cc::CompositorFrame& frame) { | |
285 return (guest_ && guest_->has_attached_since_surface_set()) || | |
286 RenderWidgetHostViewChildFrame::ShouldRecreateSurface( | |
287 compositor_frame_sink_id, frame); | |
288 } | |
289 | |
290 void RenderWidgetHostViewGuest::SendSurfaceInfoToChild( | |
Fady Samuel
2017/01/17 20:54:12
I'd rather this actually take in a SurfaceInfo ins
| |
291 const cc::SurfaceSequence& sequence) { | |
292 if (guest_ && !guest_->is_in_destruction()) { | |
293 guest_->SetChildFrameSurface(cc::SurfaceId(frame_sink_id_, local_frame_id_), | |
294 current_surface_size_, | |
295 current_surface_scale_factor_, sequence); | |
296 } | |
297 } | |
298 | |
282 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( | 299 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( |
283 uint32_t compositor_frame_sink_id, | 300 uint32_t compositor_frame_sink_id, |
284 cc::CompositorFrame frame) { | 301 cc::CompositorFrame frame) { |
285 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame"); | 302 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame"); |
286 | 303 |
287 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 304 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
288 | 305 ProcessCompositorFrame(compositor_frame_sink_id, std::move(frame)); |
289 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | |
290 | |
291 gfx::Size frame_size = root_pass->output_rect.size(); | |
292 float scale_factor = frame.metadata.device_scale_factor; | |
293 | |
294 // Check whether we need to recreate the cc::Surface, which means the child | |
295 // frame renderer has changed its output surface, or size, or scale factor. | |
296 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ || | |
297 frame_size != current_surface_size_ || | |
298 scale_factor != current_surface_scale_factor_ || | |
299 (guest_ && guest_->has_attached_since_surface_set())) { | |
300 ClearCompositorSurfaceIfNecessary(); | |
301 // If the renderer changed its frame sink, reset the surface factory to | |
302 // avoid returning stale resources. | |
303 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) | |
304 surface_factory_->Reset(); | |
305 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | |
306 current_surface_size_ = frame_size; | |
307 current_surface_scale_factor_ = scale_factor; | |
308 } | |
309 | |
310 bool allocated_new_local_frame_id = false; | |
311 if (!local_frame_id_.is_valid()) { | |
312 local_frame_id_ = id_allocator_->GenerateId(); | |
313 allocated_new_local_frame_id = true; | |
314 } | |
315 | |
316 cc::SurfaceFactory::DrawCallback ack_callback = base::Bind( | |
317 &RenderWidgetHostViewChildFrame::SurfaceDrawn, | |
318 RenderWidgetHostViewChildFrame::AsWeakPtr(), compositor_frame_sink_id); | |
319 ack_pending_count_++; | |
320 // If this value grows very large, something is going wrong. | |
321 DCHECK(ack_pending_count_ < 1000); | |
322 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | |
323 ack_callback); | |
324 | |
325 if (allocated_new_local_frame_id) { | |
326 cc::SurfaceSequence sequence = | |
327 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | |
328 // The renderer process will satisfy this dependency when it creates a | |
329 // SurfaceLayer. | |
330 cc::SurfaceManager* manager = GetSurfaceManager(); | |
331 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); | |
332 manager->GetSurfaceForId(surface_id)->AddDestructionDependency(sequence); | |
333 // TODO(wjmaclean): I'm not sure what it means to create a surface id | |
334 // without setting it on the child, though since we will in this case be | |
335 // guaranteed to call ClearCompositorSurfaceIfNecessary() below, I suspect | |
336 // skipping SetChildFrameSurface() here is irrelevant. | |
337 if (guest_ && !guest_->is_in_destruction()) { | |
338 guest_->SetChildFrameSurface(surface_id, frame_size, scale_factor, | |
339 sequence); | |
340 } | |
341 } | |
342 ProcessFrameSwappedCallbacks(); | |
343 | 306 |
344 // If after detaching we are sent a frame, we should finish processing it, and | 307 // If after detaching we are sent a frame, we should finish processing it, and |
345 // then we should clear the surface so that we are not holding resources we | 308 // then we should clear the surface so that we are not holding resources we |
346 // no longer need. | 309 // no longer need. |
347 if (!guest_ || !guest_->attached()) | 310 if (!guest_ || !guest_->attached()) |
348 ClearCompositorSurfaceIfNecessary(); | 311 ClearCompositorSurfaceIfNecessary(); |
349 } | 312 } |
350 | 313 |
351 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) { | 314 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) { |
352 if (!platform_view_) { | 315 if (!platform_view_) { |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 gesture_event.data.scrollUpdate.inertialPhase == | 657 gesture_event.data.scrollUpdate.inertialPhase == |
695 blink::WebGestureEvent::MomentumPhase) { | 658 blink::WebGestureEvent::MomentumPhase) { |
696 return; | 659 return; |
697 } | 660 } |
698 host_->ForwardGestureEvent(gesture_event); | 661 host_->ForwardGestureEvent(gesture_event); |
699 return; | 662 return; |
700 } | 663 } |
701 } | 664 } |
702 | 665 |
703 } // namespace content | 666 } // namespace content |
OLD | NEW |