| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 frame_sink_id_( | 45 frame_sink_id_( |
| 46 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()), | 46 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()), |
| 47 base::checked_cast<uint32_t>(widget_host->GetRoutingID())), | 47 base::checked_cast<uint32_t>(widget_host->GetRoutingID())), |
| 48 next_surface_sequence_(1u), | 48 next_surface_sequence_(1u), |
| 49 last_compositor_frame_sink_id_(0), | 49 last_compositor_frame_sink_id_(0), |
| 50 current_surface_scale_factor_(1.f), | 50 current_surface_scale_factor_(1.f), |
| 51 ack_pending_count_(0), | 51 ack_pending_count_(0), |
| 52 frame_connector_(nullptr), | 52 frame_connector_(nullptr), |
| 53 begin_frame_source_(nullptr), | 53 begin_frame_source_(nullptr), |
| 54 weak_factory_(this) { | 54 weak_factory_(this) { |
| 55 id_allocator_.reset(new cc::SurfaceIdAllocator(frame_sink_id_)); | 55 id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 56 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); | 56 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |
| 57 RegisterFrameSinkId(); | 57 RegisterFrameSinkId(); |
| 58 | 58 |
| 59 host_->SetView(this); | 59 host_->SetView(this); |
| 60 GetTextInputManager(); | 60 GetTextInputManager(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { | 63 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { |
| 64 if (!surface_id_.is_null()) | 64 if (!local_frame_id_.is_null()) |
| 65 surface_factory_->Destroy(surface_id_); | 65 surface_factory_->Destroy(local_frame_id_); |
| 66 | 66 |
| 67 if (GetSurfaceManager()) | 67 if (GetSurfaceManager()) |
| 68 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 68 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( | 71 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| 72 CrossProcessFrameConnector* frame_connector) { | 72 CrossProcessFrameConnector* frame_connector) { |
| 73 if (frame_connector_ == frame_connector) | 73 if (frame_connector_ == frame_connector) |
| 74 return; | 74 return; |
| 75 | 75 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 void RenderWidgetHostViewChildFrame::Focus() { | 130 void RenderWidgetHostViewChildFrame::Focus() { |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool RenderWidgetHostViewChildFrame::HasFocus() const { | 133 bool RenderWidgetHostViewChildFrame::HasFocus() const { |
| 134 if (frame_connector_) | 134 if (frame_connector_) |
| 135 return frame_connector_->HasFocus(); | 135 return frame_connector_->HasFocus(); |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { | 139 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { |
| 140 return surface_factory_ && !surface_id_.is_null(); | 140 return surface_factory_ && !local_frame_id_.is_null(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void RenderWidgetHostViewChildFrame::Show() { | 143 void RenderWidgetHostViewChildFrame::Show() { |
| 144 if (!host_->is_hidden()) | 144 if (!host_->is_hidden()) |
| 145 return; | 145 return; |
| 146 host_->WasShown(ui::LatencyInfo()); | 146 host_->WasShown(ui::LatencyInfo()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void RenderWidgetHostViewChildFrame::Hide() { | 149 void RenderWidgetHostViewChildFrame::Hide() { |
| 150 if (host_->is_hidden()) | 150 if (host_->is_hidden()) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 cc::RenderPass* root_pass = | 369 cc::RenderPass* root_pass = |
| 370 frame.delegated_frame_data->render_pass_list.back().get(); | 370 frame.delegated_frame_data->render_pass_list.back().get(); |
| 371 | 371 |
| 372 gfx::Size frame_size = root_pass->output_rect.size(); | 372 gfx::Size frame_size = root_pass->output_rect.size(); |
| 373 float scale_factor = frame.metadata.device_scale_factor; | 373 float scale_factor = frame.metadata.device_scale_factor; |
| 374 | 374 |
| 375 // Check whether we need to recreate the cc::Surface, which means the child | 375 // Check whether we need to recreate the cc::Surface, which means the child |
| 376 // frame renderer has changed its output surface, or size, or scale factor. | 376 // frame renderer has changed its output surface, or size, or scale factor. |
| 377 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ && | 377 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ && |
| 378 surface_factory_) { | 378 surface_factory_) { |
| 379 surface_factory_->Destroy(surface_id_); | 379 surface_factory_->Destroy(local_frame_id_); |
| 380 surface_factory_.reset(); | 380 surface_factory_.reset(); |
| 381 } | 381 } |
| 382 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ || | 382 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ || |
| 383 frame_size != current_surface_size_ || | 383 frame_size != current_surface_size_ || |
| 384 scale_factor != current_surface_scale_factor_) { | 384 scale_factor != current_surface_scale_factor_) { |
| 385 ClearCompositorSurfaceIfNecessary(); | 385 ClearCompositorSurfaceIfNecessary(); |
| 386 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 386 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 387 current_surface_size_ = frame_size; | 387 current_surface_size_ = frame_size; |
| 388 current_surface_scale_factor_ = scale_factor; | 388 current_surface_scale_factor_ = scale_factor; |
| 389 } | 389 } |
| 390 | 390 |
| 391 if (!surface_factory_) { | 391 if (!surface_factory_) { |
| 392 cc::SurfaceManager* manager = GetSurfaceManager(); | 392 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 393 surface_factory_ = | 393 surface_factory_ = |
| 394 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); | 394 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); |
| 395 } | 395 } |
| 396 | 396 |
| 397 if (surface_id_.is_null()) { | 397 if (local_frame_id_.is_null()) { |
| 398 surface_id_ = id_allocator_->GenerateId(); | 398 local_frame_id_ = id_allocator_->GenerateId(); |
| 399 surface_factory_->Create(surface_id_); | 399 surface_factory_->Create(local_frame_id_); |
| 400 | 400 |
| 401 cc::SurfaceSequence sequence = | 401 cc::SurfaceSequence sequence = |
| 402 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 402 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 403 // The renderer process will satisfy this dependency when it creates a | 403 // The renderer process will satisfy this dependency when it creates a |
| 404 // SurfaceLayer. | 404 // SurfaceLayer. |
| 405 cc::SurfaceManager* manager = GetSurfaceManager(); | 405 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 406 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); | 406 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) |
| 407 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, | 407 ->AddDestructionDependency(sequence); |
| 408 scale_factor, sequence); | 408 frame_connector_->SetChildFrameSurface( |
| 409 cc::SurfaceId(frame_sink_id_, local_frame_id_), frame_size, |
| 410 scale_factor, sequence); |
| 409 } | 411 } |
| 410 | 412 |
| 411 cc::SurfaceFactory::DrawCallback ack_callback = | 413 cc::SurfaceFactory::DrawCallback ack_callback = |
| 412 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | 414 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
| 413 compositor_frame_sink_id); | 415 compositor_frame_sink_id); |
| 414 ack_pending_count_++; | 416 ack_pending_count_++; |
| 415 // If this value grows very large, something is going wrong. | 417 // If this value grows very large, something is going wrong. |
| 416 DCHECK_LT(ack_pending_count_, 1000U); | 418 DCHECK_LT(ack_pending_count_, 1000U); |
| 417 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 419 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 418 ack_callback); | 420 ack_callback); |
| 419 | 421 |
| 420 ProcessFrameSwappedCallbacks(); | 422 ProcessFrameSwappedCallbacks(); |
| 421 } | 423 } |
| 422 | 424 |
| 423 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { | 425 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { |
| 424 // We only use callbacks once, therefore we make a new list for registration | 426 // We only use callbacks once, therefore we make a new list for registration |
| 425 // before we start, and discard the old list entries when we are done. | 427 // before we start, and discard the old list entries when we are done. |
| 426 FrameSwappedCallbackList process_callbacks; | 428 FrameSwappedCallbackList process_callbacks; |
| 427 process_callbacks.swap(frame_swapped_callbacks_); | 429 process_callbacks.swap(frame_swapped_callbacks_); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 const blink::WebGestureEvent& event, | 509 const blink::WebGestureEvent& event, |
| 508 const ui::LatencyInfo& latency) { | 510 const ui::LatencyInfo& latency) { |
| 509 host_->ForwardGestureEventWithLatencyInfo(event, latency); | 511 host_->ForwardGestureEventWithLatencyInfo(event, latency); |
| 510 } | 512 } |
| 511 | 513 |
| 512 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToRootCoordSpace( | 514 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToRootCoordSpace( |
| 513 const gfx::Point& point) { | 515 const gfx::Point& point) { |
| 514 if (!frame_connector_) | 516 if (!frame_connector_) |
| 515 return point; | 517 return point; |
| 516 | 518 |
| 517 return frame_connector_->TransformPointToRootCoordSpace(point, surface_id_); | 519 return frame_connector_->TransformPointToRootCoordSpace( |
| 520 point, cc::SurfaceId(frame_sink_id_, local_frame_id_)); |
| 518 } | 521 } |
| 519 | 522 |
| 520 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToLocalCoordSpace( | 523 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToLocalCoordSpace( |
| 521 const gfx::Point& point, | 524 const gfx::Point& point, |
| 522 const cc::SurfaceId& original_surface) { | 525 const cc::SurfaceId& original_surface) { |
| 523 if (!frame_connector_ || surface_id_.is_null()) | 526 if (!frame_connector_ || local_frame_id_.is_null()) |
| 524 return point; | 527 return point; |
| 525 | 528 |
| 526 return frame_connector_->TransformPointToLocalCoordSpace( | 529 return frame_connector_->TransformPointToLocalCoordSpace( |
| 527 point, original_surface, surface_id_); | 530 point, original_surface, cc::SurfaceId(frame_sink_id_, local_frame_id_)); |
| 528 } | 531 } |
| 529 | 532 |
| 530 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToCoordSpaceForView( | 533 gfx::Point RenderWidgetHostViewChildFrame::TransformPointToCoordSpaceForView( |
| 531 const gfx::Point& point, | 534 const gfx::Point& point, |
| 532 RenderWidgetHostViewBase* target_view) { | 535 RenderWidgetHostViewBase* target_view) { |
| 533 if (!frame_connector_ || surface_id_.is_null() || target_view == this) | 536 if (!frame_connector_ || local_frame_id_.is_null() || target_view == this) |
| 534 return point; | 537 return point; |
| 535 | 538 |
| 536 return frame_connector_->TransformPointToCoordSpaceForView(point, target_view, | 539 return frame_connector_->TransformPointToCoordSpaceForView( |
| 537 surface_id_); | 540 point, target_view, cc::SurfaceId(frame_sink_id_, local_frame_id_)); |
| 538 } | 541 } |
| 539 | 542 |
| 540 #if defined(OS_MACOSX) | 543 #if defined(OS_MACOSX) |
| 541 ui::AcceleratedWidgetMac* | 544 ui::AcceleratedWidgetMac* |
| 542 RenderWidgetHostViewChildFrame::GetAcceleratedWidgetMac() const { | 545 RenderWidgetHostViewChildFrame::GetAcceleratedWidgetMac() const { |
| 543 return nullptr; | 546 return nullptr; |
| 544 } | 547 } |
| 545 | 548 |
| 546 void RenderWidgetHostViewChildFrame::SetActive(bool active) { | 549 void RenderWidgetHostViewChildFrame::SetActive(bool active) { |
| 547 } | 550 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 const SkColorType preferred_color_type) { | 597 const SkColorType preferred_color_type) { |
| 595 DCHECK(IsSurfaceAvailableForCopy()); | 598 DCHECK(IsSurfaceAvailableForCopy()); |
| 596 | 599 |
| 597 std::unique_ptr<cc::CopyOutputRequest> request = | 600 std::unique_ptr<cc::CopyOutputRequest> request = |
| 598 cc::CopyOutputRequest::CreateRequest( | 601 cc::CopyOutputRequest::CreateRequest( |
| 599 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, | 602 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, |
| 600 preferred_color_type, callback)); | 603 preferred_color_type, callback)); |
| 601 if (!src_subrect.IsEmpty()) | 604 if (!src_subrect.IsEmpty()) |
| 602 request->set_area(src_subrect); | 605 request->set_area(src_subrect); |
| 603 | 606 |
| 604 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 607 surface_factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| 605 } | 608 } |
| 606 | 609 |
| 607 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( | 610 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( |
| 608 const gfx::Rect& src_subrect, | 611 const gfx::Rect& src_subrect, |
| 609 const scoped_refptr<media::VideoFrame>& target, | 612 const scoped_refptr<media::VideoFrame>& target, |
| 610 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 613 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 611 NOTIMPLEMENTED(); | 614 NOTIMPLEMENTED(); |
| 612 callback.Run(gfx::Rect(), false); | 615 callback.Run(gfx::Rect(), false); |
| 613 } | 616 } |
| 614 | 617 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 } | 704 } |
| 702 | 705 |
| 703 BrowserAccessibilityManager* | 706 BrowserAccessibilityManager* |
| 704 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( | 707 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( |
| 705 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 708 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 706 return BrowserAccessibilityManager::Create( | 709 return BrowserAccessibilityManager::Create( |
| 707 BrowserAccessibilityManager::GetEmptyDocument(), delegate); | 710 BrowserAccessibilityManager::GetEmptyDocument(), delegate); |
| 708 } | 711 } |
| 709 | 712 |
| 710 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 713 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 711 if (surface_factory_ && !surface_id_.is_null()) | 714 if (surface_factory_ && !local_frame_id_.is_null()) |
| 712 surface_factory_->Destroy(surface_id_); | 715 surface_factory_->Destroy(local_frame_id_); |
| 713 surface_id_ = cc::SurfaceId(); | 716 local_frame_id_ = cc::LocalFrameId(); |
| 714 } | 717 } |
| 715 | 718 |
| 716 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 719 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 717 return true; | 720 return true; |
| 718 } | 721 } |
| 719 | 722 |
| 720 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 723 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 721 return surface_id_; | 724 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
| 722 }; | 725 }; |
| 723 | 726 |
| 724 } // namespace content | 727 } // namespace content |
| OLD | NEW |