| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 begin_frame_source_(nullptr), | 62 begin_frame_source_(nullptr), |
| 63 weak_factory_(this) { | 63 weak_factory_(this) { |
| 64 id_allocator_.reset(new cc::SurfaceIdAllocator()); | 64 id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 65 auto* manager = GetSurfaceManager(); | 65 auto* manager = GetSurfaceManager(); |
| 66 manager->RegisterFrameSinkId(frame_sink_id_); | 66 manager->RegisterFrameSinkId(frame_sink_id_); |
| 67 surface_factory_ = | 67 surface_factory_ = |
| 68 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); | 68 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { | 71 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { |
| 72 surface_factory_->EvictSurface(); | 72 if (local_frame_id_.is_valid()) |
| 73 surface_factory_->Destroy(local_frame_id_); |
| 74 |
| 73 if (GetSurfaceManager()) | 75 if (GetSurfaceManager()) |
| 74 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 76 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void RenderWidgetHostViewChildFrame::Init() { | 79 void RenderWidgetHostViewChildFrame::Init() { |
| 78 RegisterFrameSinkId(); | 80 RegisterFrameSinkId(); |
| 79 host_->SetView(this); | 81 host_->SetView(this); |
| 80 GetTextInputManager(); | 82 GetTextInputManager(); |
| 81 } | 83 } |
| 82 | 84 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 ClearCompositorSurfaceIfNecessary(); | 393 ClearCompositorSurfaceIfNecessary(); |
| 392 // If the renderer changed its frame sink, reset the surface factory to | 394 // If the renderer changed its frame sink, reset the surface factory to |
| 393 // avoid returning stale resources. | 395 // avoid returning stale resources. |
| 394 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) | 396 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) |
| 395 surface_factory_->Reset(); | 397 surface_factory_->Reset(); |
| 396 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 398 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 397 current_surface_size_ = frame_size; | 399 current_surface_size_ = frame_size; |
| 398 current_surface_scale_factor_ = scale_factor; | 400 current_surface_scale_factor_ = scale_factor; |
| 399 } | 401 } |
| 400 | 402 |
| 401 bool allocated_new_local_frame_id = false; | |
| 402 if (!local_frame_id_.is_valid()) { | 403 if (!local_frame_id_.is_valid()) { |
| 403 local_frame_id_ = id_allocator_->GenerateId(); | 404 local_frame_id_ = id_allocator_->GenerateId(); |
| 404 allocated_new_local_frame_id = true; | 405 surface_factory_->Create(local_frame_id_); |
| 405 } | |
| 406 | 406 |
| 407 cc::SurfaceFactory::DrawCallback ack_callback = | |
| 408 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | |
| 409 compositor_frame_sink_id); | |
| 410 ack_pending_count_++; | |
| 411 // If this value grows very large, something is going wrong. | |
| 412 DCHECK_LT(ack_pending_count_, 1000U); | |
| 413 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | |
| 414 ack_callback); | |
| 415 | |
| 416 if (allocated_new_local_frame_id) { | |
| 417 cc::SurfaceSequence sequence = | 407 cc::SurfaceSequence sequence = |
| 418 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 408 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 419 // The renderer process will satisfy this dependency when it creates a | 409 // The renderer process will satisfy this dependency when it creates a |
| 420 // SurfaceLayer. | 410 // SurfaceLayer. |
| 421 cc::SurfaceManager* manager = GetSurfaceManager(); | 411 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 422 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) | 412 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) |
| 423 ->AddDestructionDependency(sequence); | 413 ->AddDestructionDependency(sequence); |
| 424 frame_connector_->SetChildFrameSurface( | 414 frame_connector_->SetChildFrameSurface( |
| 425 cc::SurfaceId(frame_sink_id_, local_frame_id_), frame_size, | 415 cc::SurfaceId(frame_sink_id_, local_frame_id_), frame_size, |
| 426 scale_factor, sequence); | 416 scale_factor, sequence); |
| 427 } | 417 } |
| 418 |
| 419 cc::SurfaceFactory::DrawCallback ack_callback = |
| 420 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
| 421 compositor_frame_sink_id); |
| 422 ack_pending_count_++; |
| 423 // If this value grows very large, something is going wrong. |
| 424 DCHECK_LT(ack_pending_count_, 1000U); |
| 425 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 426 ack_callback); |
| 427 |
| 428 ProcessFrameSwappedCallbacks(); | 428 ProcessFrameSwappedCallbacks(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { | 431 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { |
| 432 // We only use callbacks once, therefore we make a new list for registration | 432 // We only use callbacks once, therefore we make a new list for registration |
| 433 // before we start, and discard the old list entries when we are done. | 433 // before we start, and discard the old list entries when we are done. |
| 434 FrameSwappedCallbackList process_callbacks; | 434 FrameSwappedCallbackList process_callbacks; |
| 435 process_callbacks.swap(frame_swapped_callbacks_); | 435 process_callbacks.swap(frame_swapped_callbacks_); |
| 436 for (std::unique_ptr<base::Closure>& callback : process_callbacks) | 436 for (std::unique_ptr<base::Closure>& callback : process_callbacks) |
| 437 callback->Run(); | 437 callback->Run(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 const SkColorType preferred_color_type) { | 612 const SkColorType preferred_color_type) { |
| 613 DCHECK(IsSurfaceAvailableForCopy()); | 613 DCHECK(IsSurfaceAvailableForCopy()); |
| 614 | 614 |
| 615 std::unique_ptr<cc::CopyOutputRequest> request = | 615 std::unique_ptr<cc::CopyOutputRequest> request = |
| 616 cc::CopyOutputRequest::CreateRequest( | 616 cc::CopyOutputRequest::CreateRequest( |
| 617 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, | 617 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, |
| 618 preferred_color_type, callback)); | 618 preferred_color_type, callback)); |
| 619 if (!src_subrect.IsEmpty()) | 619 if (!src_subrect.IsEmpty()) |
| 620 request->set_area(src_subrect); | 620 request->set_area(src_subrect); |
| 621 | 621 |
| 622 surface_factory_->RequestCopyOfSurface(std::move(request)); | 622 surface_factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| 623 } | 623 } |
| 624 | 624 |
| 625 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( | 625 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( |
| 626 const gfx::Rect& src_subrect, | 626 const gfx::Rect& src_subrect, |
| 627 const scoped_refptr<media::VideoFrame>& target, | 627 const scoped_refptr<media::VideoFrame>& target, |
| 628 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 628 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 629 NOTIMPLEMENTED(); | 629 NOTIMPLEMENTED(); |
| 630 callback.Run(gfx::Rect(), false); | 630 callback.Run(gfx::Rect(), false); |
| 631 } | 631 } |
| 632 | 632 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 } | 719 } |
| 720 | 720 |
| 721 BrowserAccessibilityManager* | 721 BrowserAccessibilityManager* |
| 722 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( | 722 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( |
| 723 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 723 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 724 return BrowserAccessibilityManager::Create( | 724 return BrowserAccessibilityManager::Create( |
| 725 BrowserAccessibilityManager::GetEmptyDocument(), delegate); | 725 BrowserAccessibilityManager::GetEmptyDocument(), delegate); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 728 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 729 surface_factory_->EvictSurface(); | 729 if (local_frame_id_.is_valid()) |
| 730 surface_factory_->Destroy(local_frame_id_); |
| 730 local_frame_id_ = cc::LocalFrameId(); | 731 local_frame_id_ = cc::LocalFrameId(); |
| 731 } | 732 } |
| 732 | 733 |
| 733 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 734 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 734 return true; | 735 return true; |
| 735 } | 736 } |
| 736 | 737 |
| 737 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 738 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 738 return cc::SurfaceId(frame_sink_id_, local_frame_id_); | 739 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
| 739 }; | 740 }; |
| 740 | 741 |
| 741 } // namespace content | 742 } // namespace content |
| OLD | NEW |