| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // The two sizes may fall out of sync if we switch RenderWidgetHostViews, | 108 // The two sizes may fall out of sync if we switch RenderWidgetHostViews, |
| 109 // resize, and then switch page, as is the case with interstitial pages. | 109 // resize, and then switch page, as is the case with interstitial pages. |
| 110 // NOTE: |guest_| is NULL in unit tests. | 110 // NOTE: |guest_| is NULL in unit tests. |
| 111 if (guest_) { | 111 if (guest_) { |
| 112 SetSize(guest_->web_contents()->GetViewBounds().size()); | 112 SetSize(guest_->web_contents()->GetViewBounds().size()); |
| 113 // Since we were last shown, our renderer may have had a different surface | 113 // Since we were last shown, our renderer may have had a different surface |
| 114 // set (e.g. showing an interstitial), so we resend our current surface to | 114 // set (e.g. showing an interstitial), so we resend our current surface to |
| 115 // the renderer. | 115 // the renderer. |
| 116 if (!surface_id_.is_null()) { | 116 if (!surface_id_.is_null()) { |
| 117 cc::SurfaceSequence sequence = cc::SurfaceSequence( | 117 cc::SurfaceSequence sequence = cc::SurfaceSequence( |
| 118 id_allocator_->client_id(), next_surface_sequence_++); | 118 surface_id_.client_id(), next_surface_sequence_++); |
| 119 GetSurfaceManager() | 119 GetSurfaceManager() |
| 120 ->GetSurfaceForId(surface_id_) | 120 ->GetSurfaceForId(surface_id_) |
| 121 ->AddDestructionDependency(sequence); | 121 ->AddDestructionDependency(sequence); |
| 122 guest_->SetChildFrameSurface(surface_id_, current_surface_size_, | 122 guest_->SetChildFrameSurface(surface_id_, current_surface_size_, |
| 123 current_surface_scale_factor_, | 123 current_surface_scale_factor_, |
| 124 sequence); | 124 sequence); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 host_->WasShown(ui::LatencyInfo()); | 127 host_->WasShown(ui::LatencyInfo()); |
| 128 } | 128 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 void RenderWidgetHostViewGuest::SetTooltipText( | 253 void RenderWidgetHostViewGuest::SetTooltipText( |
| 254 const base::string16& tooltip_text) { | 254 const base::string16& tooltip_text) { |
| 255 if (guest_) | 255 if (guest_) |
| 256 guest_->SetTooltipText(tooltip_text); | 256 guest_->SetTooltipText(tooltip_text); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( | 259 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( |
| 260 uint32_t output_surface_id, | 260 uint32_t output_surface_id, |
| 261 const cc::SurfaceId& surface_id, |
| 261 cc::CompositorFrame frame) { | 262 cc::CompositorFrame frame) { |
| 262 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame"); | 263 TRACE_EVENT0("content", "RenderWidgetHostViewGuest::OnSwapCompositorFrame"); |
| 263 | 264 |
| 264 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 265 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 265 | 266 |
| 266 cc::RenderPass* root_pass = | 267 cc::RenderPass* root_pass = |
| 267 frame.delegated_frame_data->render_pass_list.back().get(); | 268 frame.delegated_frame_data->render_pass_list.back().get(); |
| 268 | 269 |
| 269 gfx::Size frame_size = root_pass->output_rect.size(); | 270 gfx::Size frame_size = root_pass->output_rect.size(); |
| 270 float scale_factor = frame.metadata.device_scale_factor; | 271 float scale_factor = frame.metadata.device_scale_factor; |
| 272 current_surface_scale_factor_ = scale_factor; |
| 273 current_surface_size_ = frame_size; |
| 271 | 274 |
| 272 // Check whether we need to recreate the cc::Surface, which means the child | 275 // Check whether we need to recreate the cc::Surface, which means the child |
| 273 // frame renderer has changed its output surface, or size, or scale factor. | 276 // frame renderer has changed its output surface, or size, or scale factor. |
| 274 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | |
| 275 surface_factory_->Destroy(surface_id_); | |
| 276 surface_factory_.reset(); | |
| 277 } | |
| 278 if (output_surface_id != last_output_surface_id_ || | 277 if (output_surface_id != last_output_surface_id_ || |
| 279 frame_size != current_surface_size_ || | |
| 280 scale_factor != current_surface_scale_factor_ || | |
| 281 guest_->has_attached_since_surface_set()) { | 278 guest_->has_attached_since_surface_set()) { |
| 282 ClearCompositorSurfaceIfNecessary(); | 279 if (surface_factory_) |
| 280 surface_factory_->DestroyAll(); |
| 283 last_output_surface_id_ = output_surface_id; | 281 last_output_surface_id_ = output_surface_id; |
| 284 current_surface_size_ = frame_size; | |
| 285 current_surface_scale_factor_ = scale_factor; | |
| 286 } | 282 } |
| 287 | 283 |
| 288 if (!surface_factory_) { | 284 if (!surface_factory_) { |
| 289 cc::SurfaceManager* manager = GetSurfaceManager(); | 285 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 290 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | 286 surface_factory_ = base::WrapUnique( |
| 287 new cc::SurfaceFactory(surface_id_.client_id(), manager, this)); |
| 291 } | 288 } |
| 292 | 289 |
| 293 if (surface_id_.is_null()) { | 290 if (surface_id_ != surface_id) { |
| 294 surface_id_ = id_allocator_->GenerateId(); | 291 if (!surface_id_.is_null()) |
| 295 surface_factory_->Create(surface_id_); | 292 surface_factory_->Destroy(surface_id_); |
| 296 | 293 |
| 297 cc::SurfaceSequence sequence = cc::SurfaceSequence( | 294 surface_id_ = surface_id; |
| 298 id_allocator_->client_id(), next_surface_sequence_++); | 295 if (!surface_id.is_null()) { |
| 299 // The renderer process will satisfy this dependency when it creates a | 296 surface_factory_->Create(surface_id); |
| 300 // SurfaceLayer. | 297 |
| 301 cc::SurfaceManager* manager = GetSurfaceManager(); | 298 cc::SurfaceSequence sequence = cc::SurfaceSequence( |
| 302 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); | 299 surface_id_.client_id(), next_surface_sequence_++); |
| 303 guest_->SetChildFrameSurface(surface_id_, frame_size, scale_factor, | 300 // The renderer process will satisfy this dependency when it creates a |
| 304 sequence); | 301 // SurfaceLayer. |
| 302 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 303 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); |
| 304 guest_->SetChildFrameSurface(surface_id_, frame_size, scale_factor, |
| 305 sequence); |
| 306 } |
| 305 } | 307 } |
| 306 | 308 |
| 307 cc::SurfaceFactory::DrawCallback ack_callback = base::Bind( | 309 cc::SurfaceFactory::DrawCallback ack_callback = base::Bind( |
| 308 &RenderWidgetHostViewChildFrame::SurfaceDrawn, | 310 &RenderWidgetHostViewChildFrame::SurfaceDrawn, |
| 309 RenderWidgetHostViewChildFrame::AsWeakPtr(), output_surface_id); | 311 RenderWidgetHostViewChildFrame::AsWeakPtr(), output_surface_id); |
| 310 ack_pending_count_++; | 312 ack_pending_count_++; |
| 311 // If this value grows very large, something is going wrong. | 313 // If this value grows very large, something is going wrong. |
| 312 DCHECK(ack_pending_count_ < 1000); | 314 DCHECK(ack_pending_count_ < 1000); |
| 313 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 315 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 314 ack_callback); | 316 ack_callback); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 gesture_event.data.scrollUpdate.inertialPhase == | 640 gesture_event.data.scrollUpdate.inertialPhase == |
| 639 blink::WebGestureEvent::MomentumPhase) { | 641 blink::WebGestureEvent::MomentumPhase) { |
| 640 return; | 642 return; |
| 641 } | 643 } |
| 642 host_->ForwardGestureEvent(gesture_event); | 644 host_->ForwardGestureEvent(gesture_event); |
| 643 return; | 645 return; |
| 644 } | 646 } |
| 645 } | 647 } |
| 646 | 648 |
| 647 } // namespace content | 649 } // namespace content |
| OLD | NEW |