Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: content/browser/frame_host/render_widget_host_view_guest.cc

Issue 2633303003: Clean up RenderWidgetHostView(ChildFrame and Guest) compositing code (Closed)
Patch Set: c Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return; 117 return;
118 // Make sure the size of this view matches the size of the WebContentsView. 118 // Make sure the size of this view matches the size of the WebContentsView.
119 // The two sizes may fall out of sync if we switch RenderWidgetHostViews, 119 // The two sizes may fall out of sync if we switch RenderWidgetHostViews,
120 // resize, and then switch page, as is the case with interstitial pages. 120 // resize, and then switch page, as is the case with interstitial pages.
121 // NOTE: |guest_| is NULL in unit tests. 121 // NOTE: |guest_| is NULL in unit tests.
122 if (guest_) { 122 if (guest_) {
123 SetSize(guest_->web_contents()->GetViewBounds().size()); 123 SetSize(guest_->web_contents()->GetViewBounds().size());
124 // Since we were last shown, our renderer may have had a different surface 124 // Since we were last shown, our renderer may have had a different surface
125 // set (e.g. showing an interstitial), so we resend our current surface to 125 // set (e.g. showing an interstitial), so we resend our current surface to
126 // the renderer. 126 // the renderer.
127 if (local_frame_id_.is_valid()) { 127 if (local_frame_id_.is_valid())
128 cc::SurfaceSequence sequence = 128 SendSurfaceInfoToEmbedder();
129 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++);
130 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
131 GetSurfaceManager()
132 ->GetSurfaceForId(surface_id)
133 ->AddDestructionDependency(sequence);
134 guest_->SetChildFrameSurface(surface_id, current_surface_size_,
135 current_surface_scale_factor_, sequence);
136 }
137 } 129 }
138 host_->WasShown(ui::LatencyInfo()); 130 host_->WasShown(ui::LatencyInfo());
139 } 131 }
140 132
141 void RenderWidgetHostViewGuest::Hide() { 133 void RenderWidgetHostViewGuest::Hide() {
142 // |guest_| is NULL during test. 134 // |guest_| is NULL during test.
143 if ((guest_ && guest_->is_in_destruction()) || host_->is_hidden()) 135 if ((guest_ && guest_->is_in_destruction()) || host_->is_hidden())
144 return; 136 return;
145 host_->WasHidden(); 137 host_->WasHidden();
146 } 138 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (platform_view_) 264 if (platform_view_)
273 platform_view_->SetNeedsBeginFrames(needs_begin_frames); 265 platform_view_->SetNeedsBeginFrames(needs_begin_frames);
274 } 266 }
275 267
276 void RenderWidgetHostViewGuest::SetTooltipText( 268 void RenderWidgetHostViewGuest::SetTooltipText(
277 const base::string16& tooltip_text) { 269 const base::string16& tooltip_text) {
278 if (guest_) 270 if (guest_)
279 guest_->SetTooltipText(tooltip_text); 271 guest_->SetTooltipText(tooltip_text);
280 } 272 }
281 273
274 bool RenderWidgetHostViewGuest::ShouldCreateNewSurfaceId(
275 uint32_t compositor_frame_sink_id,
276 const cc::CompositorFrame& frame) {
277 return (guest_ && guest_->has_attached_since_surface_set()) ||
278 RenderWidgetHostViewChildFrame::ShouldCreateNewSurfaceId(
279 compositor_frame_sink_id, frame);
280 }
281
282 void RenderWidgetHostViewGuest::SendSurfaceInfoToEmbedderImpl(
283 const cc::SurfaceInfo& surface_info,
284 const cc::SurfaceSequence& sequence) {
285 if (guest_ && !guest_->is_in_destruction())
286 guest_->SetChildFrameSurface(surface_info, sequence);
287 }
288
282 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( 289 void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
283 uint32_t compositor_frame_sink_id, 290 uint32_t compositor_frame_sink_id,
284 cc::CompositorFrame frame) { 291 cc::CompositorFrame frame) {
285 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame"); 292 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame");
286 293
287 last_scroll_offset_ = frame.metadata.root_scroll_offset; 294 last_scroll_offset_ = frame.metadata.root_scroll_offset;
288 295 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 296
344 // If after detaching we are sent a frame, we should finish processing it, and 297 // 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 298 // then we should clear the surface so that we are not holding resources we
346 // no longer need. 299 // no longer need.
347 if (!guest_ || !guest_->attached()) 300 if (!guest_ || !guest_->attached())
348 ClearCompositorSurfaceIfNecessary(); 301 ClearCompositorSurfaceIfNecessary();
349 } 302 }
350 303
351 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) { 304 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
352 if (!platform_view_) { 305 if (!platform_view_) {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 gesture_event.data.scrollUpdate.inertialPhase == 647 gesture_event.data.scrollUpdate.inertialPhase ==
695 blink::WebGestureEvent::MomentumPhase) { 648 blink::WebGestureEvent::MomentumPhase) {
696 return; 649 return;
697 } 650 }
698 host_->ForwardGestureEvent(gesture_event); 651 host_->ForwardGestureEvent(gesture_event);
699 return; 652 return;
700 } 653 }
701 } 654 }
702 655
703 } // namespace content 656 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698