| 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_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "third_party/WebKit/public/web/WebInputEvent.h" | 36 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 37 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
| 38 #include "ui/gfx/geometry/size_f.h" | 38 #include "ui/gfx/geometry/size_f.h" |
| 39 | 39 |
| 40 namespace content { | 40 namespace content { |
| 41 | 41 |
| 42 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( | 42 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( |
| 43 RenderWidgetHost* widget_host) | 43 RenderWidgetHost* widget_host) |
| 44 : host_(RenderWidgetHostImpl::From(widget_host)), | 44 : host_(RenderWidgetHostImpl::From(widget_host)), |
| 45 next_surface_sequence_(1u), | 45 next_surface_sequence_(1u), |
| 46 last_output_surface_id_(0), | 46 last_compositor_frame_sink_id_(0), |
| 47 current_surface_scale_factor_(1.f), | 47 current_surface_scale_factor_(1.f), |
| 48 ack_pending_count_(0), | 48 ack_pending_count_(0), |
| 49 frame_connector_(nullptr), | 49 frame_connector_(nullptr), |
| 50 begin_frame_source_(nullptr), | 50 begin_frame_source_(nullptr), |
| 51 parent_surface_client_id_(0), | 51 parent_surface_client_id_(0), |
| 52 weak_factory_(this) { | 52 weak_factory_(this) { |
| 53 id_allocator_.reset(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())); | 53 id_allocator_.reset(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())); |
| 54 GetSurfaceManager()->RegisterSurfaceClientId(id_allocator_->client_id()); | 54 GetSurfaceManager()->RegisterSurfaceClientId(id_allocator_->client_id()); |
| 55 RegisterSurfaceNamespaceId(); | 55 RegisterSurfaceNamespaceId(); |
| 56 | 56 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // always forwarded and handled according to current scroll state in the | 333 // always forwarded and handled according to current scroll state in the |
| 334 // RenderWidgetHostInputEventRouter. | 334 // RenderWidgetHostInputEventRouter. |
| 335 if (!frame_connector_) | 335 if (!frame_connector_) |
| 336 return; | 336 return; |
| 337 if ((event.type == blink::WebInputEvent::GestureScrollUpdate && | 337 if ((event.type == blink::WebInputEvent::GestureScrollUpdate && |
| 338 not_consumed) || | 338 not_consumed) || |
| 339 event.type == blink::WebInputEvent::GestureScrollEnd) | 339 event.type == blink::WebInputEvent::GestureScrollEnd) |
| 340 frame_connector_->BubbleScrollEvent(event); | 340 frame_connector_->BubbleScrollEvent(event); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void RenderWidgetHostViewChildFrame::SurfaceDrawn(uint32_t output_surface_id) { | 343 void RenderWidgetHostViewChildFrame::SurfaceDrawn( |
| 344 uint32_t compositor_frame_sink_id) { |
| 344 DCHECK_GT(ack_pending_count_, 0U); | 345 DCHECK_GT(ack_pending_count_, 0U); |
| 345 if (host_) { | 346 if (host_) { |
| 346 host_->Send(new ViewMsg_ReclaimCompositorResources( | 347 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 347 host_->GetRoutingID(), output_surface_id, true /* is_swap_ack */, | 348 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */, |
| 348 surface_returned_resources_)); | 349 surface_returned_resources_)); |
| 349 surface_returned_resources_.clear(); | 350 surface_returned_resources_.clear(); |
| 350 } | 351 } |
| 351 ack_pending_count_--; | 352 ack_pending_count_--; |
| 352 } | 353 } |
| 353 | 354 |
| 354 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( | 355 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( |
| 355 uint32_t output_surface_id, | 356 uint32_t compositor_frame_sink_id, |
| 356 cc::CompositorFrame frame) { | 357 cc::CompositorFrame frame) { |
| 357 TRACE_EVENT0("content", | 358 TRACE_EVENT0("content", |
| 358 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); | 359 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); |
| 359 | 360 |
| 360 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 361 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 361 | 362 |
| 362 if (!frame_connector_) | 363 if (!frame_connector_) |
| 363 return; | 364 return; |
| 364 | 365 |
| 365 cc::RenderPass* root_pass = | 366 cc::RenderPass* root_pass = |
| 366 frame.delegated_frame_data->render_pass_list.back().get(); | 367 frame.delegated_frame_data->render_pass_list.back().get(); |
| 367 | 368 |
| 368 gfx::Size frame_size = root_pass->output_rect.size(); | 369 gfx::Size frame_size = root_pass->output_rect.size(); |
| 369 float scale_factor = frame.metadata.device_scale_factor; | 370 float scale_factor = frame.metadata.device_scale_factor; |
| 370 | 371 |
| 371 // Check whether we need to recreate the cc::Surface, which means the child | 372 // Check whether we need to recreate the cc::Surface, which means the child |
| 372 // frame renderer has changed its output surface, or size, or scale factor. | 373 // frame renderer has changed its output surface, or size, or scale factor. |
| 373 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | 374 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ && |
| 375 surface_factory_) { |
| 374 surface_factory_->Destroy(surface_id_); | 376 surface_factory_->Destroy(surface_id_); |
| 375 surface_factory_.reset(); | 377 surface_factory_.reset(); |
| 376 } | 378 } |
| 377 if (output_surface_id != last_output_surface_id_ || | 379 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ || |
| 378 frame_size != current_surface_size_ || | 380 frame_size != current_surface_size_ || |
| 379 scale_factor != current_surface_scale_factor_) { | 381 scale_factor != current_surface_scale_factor_) { |
| 380 ClearCompositorSurfaceIfNecessary(); | 382 ClearCompositorSurfaceIfNecessary(); |
| 381 last_output_surface_id_ = output_surface_id; | 383 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 382 current_surface_size_ = frame_size; | 384 current_surface_size_ = frame_size; |
| 383 current_surface_scale_factor_ = scale_factor; | 385 current_surface_scale_factor_ = scale_factor; |
| 384 } | 386 } |
| 385 | 387 |
| 386 if (!surface_factory_) { | 388 if (!surface_factory_) { |
| 387 cc::SurfaceManager* manager = GetSurfaceManager(); | 389 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 388 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); | 390 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); |
| 389 } | 391 } |
| 390 | 392 |
| 391 if (surface_id_.is_null()) { | 393 if (surface_id_.is_null()) { |
| 392 surface_id_ = id_allocator_->GenerateId(); | 394 surface_id_ = id_allocator_->GenerateId(); |
| 393 surface_factory_->Create(surface_id_); | 395 surface_factory_->Create(surface_id_); |
| 394 | 396 |
| 395 cc::SurfaceSequence sequence = cc::SurfaceSequence( | 397 cc::SurfaceSequence sequence = cc::SurfaceSequence( |
| 396 id_allocator_->client_id(), next_surface_sequence_++); | 398 id_allocator_->client_id(), next_surface_sequence_++); |
| 397 // The renderer process will satisfy this dependency when it creates a | 399 // The renderer process will satisfy this dependency when it creates a |
| 398 // SurfaceLayer. | 400 // SurfaceLayer. |
| 399 cc::SurfaceManager* manager = GetSurfaceManager(); | 401 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 400 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); | 402 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); |
| 401 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, | 403 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, |
| 402 scale_factor, sequence); | 404 scale_factor, sequence); |
| 403 } | 405 } |
| 404 | 406 |
| 405 cc::SurfaceFactory::DrawCallback ack_callback = | 407 cc::SurfaceFactory::DrawCallback ack_callback = |
| 406 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | 408 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
| 407 output_surface_id); | 409 compositor_frame_sink_id); |
| 408 ack_pending_count_++; | 410 ack_pending_count_++; |
| 409 // If this value grows very large, something is going wrong. | 411 // If this value grows very large, something is going wrong. |
| 410 DCHECK_LT(ack_pending_count_, 1000U); | 412 DCHECK_LT(ack_pending_count_, 1000U); |
| 411 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 413 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 412 ack_callback); | 414 ack_callback); |
| 413 | 415 |
| 414 ProcessFrameSwappedCallbacks(); | 416 ProcessFrameSwappedCallbacks(); |
| 415 } | 417 } |
| 416 | 418 |
| 417 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { | 419 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 } | 618 } |
| 617 | 619 |
| 618 // cc::SurfaceFactoryClient implementation. | 620 // cc::SurfaceFactoryClient implementation. |
| 619 void RenderWidgetHostViewChildFrame::ReturnResources( | 621 void RenderWidgetHostViewChildFrame::ReturnResources( |
| 620 const cc::ReturnedResourceArray& resources) { | 622 const cc::ReturnedResourceArray& resources) { |
| 621 if (resources.empty()) | 623 if (resources.empty()) |
| 622 return; | 624 return; |
| 623 | 625 |
| 624 if (!ack_pending_count_ && host_) { | 626 if (!ack_pending_count_ && host_) { |
| 625 host_->Send(new ViewMsg_ReclaimCompositorResources( | 627 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 626 host_->GetRoutingID(), last_output_surface_id_, false /* is_swap_ack */, | 628 host_->GetRoutingID(), last_compositor_frame_sink_id_, |
| 627 resources)); | 629 false /* is_swap_ack */, resources)); |
| 628 return; | 630 return; |
| 629 } | 631 } |
| 630 | 632 |
| 631 std::copy(resources.begin(), resources.end(), | 633 std::copy(resources.begin(), resources.end(), |
| 632 std::back_inserter(surface_returned_resources_)); | 634 std::back_inserter(surface_returned_resources_)); |
| 633 } | 635 } |
| 634 | 636 |
| 635 void RenderWidgetHostViewChildFrame::SetBeginFrameSource( | 637 void RenderWidgetHostViewChildFrame::SetBeginFrameSource( |
| 636 cc::BeginFrameSource* source) { | 638 cc::BeginFrameSource* source) { |
| 637 bool needs_begin_frames = host_->needs_begin_frames(); | 639 bool needs_begin_frames = host_->needs_begin_frames(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 711 |
| 710 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 712 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 711 return true; | 713 return true; |
| 712 } | 714 } |
| 713 | 715 |
| 714 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 716 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 715 return surface_id_; | 717 return surface_id_; |
| 716 }; | 718 }; |
| 717 | 719 |
| 718 } // namespace content | 720 } // namespace content |
| OLD | NEW |