OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 pending_delegated_ack_count_(0), | 568 pending_delegated_ack_count_(0), |
569 skipped_frames_(false), | 569 skipped_frames_(false), |
570 last_swapped_surface_scale_factor_(1.f), | 570 last_swapped_surface_scale_factor_(1.f), |
571 paint_canvas_(NULL), | 571 paint_canvas_(NULL), |
572 synthetic_move_sent_(false), | 572 synthetic_move_sent_(false), |
573 accelerated_compositing_state_changed_(false), | 573 accelerated_compositing_state_changed_(false), |
574 can_lock_compositor_(YES), | 574 can_lock_compositor_(YES), |
575 cursor_visibility_state_in_renderer_(UNKNOWN), | 575 cursor_visibility_state_in_renderer_(UNKNOWN), |
576 paint_observer_(NULL), | 576 paint_observer_(NULL), |
577 touch_editing_client_(NULL), | 577 touch_editing_client_(NULL), |
| 578 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
578 weak_ptr_factory_(this) { | 579 weak_ptr_factory_(this) { |
579 host_->SetView(this); | 580 host_->SetView(this); |
580 window_observer_.reset(new WindowObserver(this)); | 581 window_observer_.reset(new WindowObserver(this)); |
581 aura::client::SetTooltipText(window_, &tooltip_); | 582 aura::client::SetTooltipText(window_, &tooltip_); |
582 aura::client::SetActivationDelegate(window_, this); | 583 aura::client::SetActivationDelegate(window_, this); |
583 aura::client::SetActivationChangeObserver(window_, this); | 584 aura::client::SetActivationChangeObserver(window_, this); |
584 aura::client::SetFocusChangeObserver(window_, this); | 585 aura::client::SetFocusChangeObserver(window_, this); |
585 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 586 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
586 #if defined(OS_WIN) | 587 #if defined(OS_WIN) |
587 transient_observer_.reset(new TransientWindowObserver(this)); | 588 transient_observer_.reset(new TransientWindowObserver(this)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { | 667 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { |
667 return host_; | 668 return host_; |
668 } | 669 } |
669 | 670 |
670 void RenderWidgetHostViewAura::WasShown() { | 671 void RenderWidgetHostViewAura::WasShown() { |
671 DCHECK(host_); | 672 DCHECK(host_); |
672 if (!host_->is_hidden()) | 673 if (!host_->is_hidden()) |
673 return; | 674 return; |
674 host_->WasShown(); | 675 host_->WasShown(); |
675 software_frame_manager_->SetVisibility(true); | 676 software_frame_manager_->SetVisibility(true); |
| 677 delegated_frame_evictor_->SetVisible(true); |
676 | 678 |
677 aura::Window* root = window_->GetRootWindow(); | 679 aura::Window* root = window_->GetRootWindow(); |
678 if (root) { | 680 if (root) { |
679 aura::client::CursorClient* cursor_client = | 681 aura::client::CursorClient* cursor_client = |
680 aura::client::GetCursorClient(root); | 682 aura::client::GetCursorClient(root); |
681 if (cursor_client) | 683 if (cursor_client) |
682 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 684 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
683 } | 685 } |
684 | 686 |
685 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && | 687 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && |
686 !released_front_lock_.get()) { | 688 !released_front_lock_.get()) { |
687 ui::Compositor* compositor = GetCompositor(); | 689 ui::Compositor* compositor = GetCompositor(); |
688 if (compositor) | 690 if (compositor) |
689 released_front_lock_ = compositor->GetCompositorLock(); | 691 released_front_lock_ = compositor->GetCompositorLock(); |
690 } | 692 } |
691 | 693 |
692 #if defined(OS_WIN) | 694 #if defined(OS_WIN) |
693 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 695 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
694 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 696 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
695 transient_observer_->SendPluginCutoutRects(); | 697 transient_observer_->SendPluginCutoutRects(); |
696 #endif | 698 #endif |
697 } | 699 } |
698 | 700 |
699 void RenderWidgetHostViewAura::WasHidden() { | 701 void RenderWidgetHostViewAura::WasHidden() { |
700 if (!host_ || host_->is_hidden()) | 702 if (!host_ || host_->is_hidden()) |
701 return; | 703 return; |
702 host_->WasHidden(); | 704 host_->WasHidden(); |
703 software_frame_manager_->SetVisibility(false); | 705 software_frame_manager_->SetVisibility(false); |
| 706 delegated_frame_evictor_->SetVisible(false); |
704 released_front_lock_ = NULL; | 707 released_front_lock_ = NULL; |
705 | 708 |
706 #if defined(OS_WIN) | 709 #if defined(OS_WIN) |
707 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); | 710 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
708 if (dispatcher) { | 711 if (dispatcher) { |
709 HWND parent = dispatcher->GetAcceleratedWidget(); | 712 HWND parent = dispatcher->GetAcceleratedWidget(); |
710 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 713 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
711 | 714 |
712 EnumChildWindows(parent, HideWindowsCallback, lparam); | 715 EnumChildWindows(parent, HideWindowsCallback, lparam); |
713 } | 716 } |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 } | 1437 } |
1435 | 1438 |
1436 if (output_surface_id != last_output_surface_id_) { | 1439 if (output_surface_id != last_output_surface_id_) { |
1437 // Resource ids are scoped by the output surface. | 1440 // Resource ids are scoped by the output surface. |
1438 // If the originating output surface doesn't match the last one, it | 1441 // If the originating output surface doesn't match the last one, it |
1439 // indicates the renderer's output surface may have been recreated, in which | 1442 // indicates the renderer's output surface may have been recreated, in which |
1440 // case we should recreate the DelegatedRendererLayer, to avoid matching | 1443 // case we should recreate the DelegatedRendererLayer, to avoid matching |
1441 // resources from the old one with resources from the new one which would | 1444 // resources from the old one with resources from the new one which would |
1442 // have the same id. Changing the layer to showing painted content destroys | 1445 // have the same id. Changing the layer to showing painted content destroys |
1443 // the DelegatedRendererLayer. | 1446 // the DelegatedRendererLayer. |
1444 window_->layer()->SetShowPaintedContent(); | 1447 EvictDelegatedFrame(); |
1445 frame_provider_ = NULL; | |
1446 | 1448 |
1447 // Drop the cc::DelegatedFrameResourceCollection so that we will not return | 1449 // Drop the cc::DelegatedFrameResourceCollection so that we will not return |
1448 // any resources from the old output surface with the new output surface id. | 1450 // any resources from the old output surface with the new output surface id. |
1449 if (resource_collection_.get()) { | 1451 if (resource_collection_.get()) { |
1450 resource_collection_->SetClient(NULL); | 1452 resource_collection_->SetClient(NULL); |
1451 | 1453 |
1452 if (resource_collection_->LoseAllResources()) | 1454 if (resource_collection_->LoseAllResources()) |
1453 SendReturnedDelegatedResources(last_output_surface_id_); | 1455 SendReturnedDelegatedResources(last_output_surface_id_); |
1454 | 1456 |
1455 resource_collection_ = NULL; | 1457 resource_collection_ = NULL; |
1456 } | 1458 } |
1457 last_output_surface_id_ = output_surface_id; | 1459 last_output_surface_id_ = output_surface_id; |
1458 } | 1460 } |
1459 if (frame_size.IsEmpty()) { | 1461 if (frame_size.IsEmpty()) { |
1460 DCHECK_EQ(0u, frame_data->resource_list.size()); | 1462 DCHECK_EQ(0u, frame_data->resource_list.size()); |
1461 window_->layer()->SetShowPaintedContent(); | 1463 EvictDelegatedFrame(); |
1462 frame_provider_ = NULL; | |
1463 } else { | 1464 } else { |
1464 if (!resource_collection_) { | 1465 if (!resource_collection_) { |
1465 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 1466 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
1466 resource_collection_->SetClient(this); | 1467 resource_collection_->SetClient(this); |
1467 } | 1468 } |
1468 if (!frame_provider_.get() || frame_size != frame_provider_->frame_size()) { | 1469 if (!frame_provider_.get() || frame_size != frame_provider_->frame_size()) { |
1469 frame_provider_ = new cc::DelegatedFrameProvider( | 1470 frame_provider_ = new cc::DelegatedFrameProvider( |
1470 resource_collection_.get(), frame_data.Pass()); | 1471 resource_collection_.get(), frame_data.Pass()); |
1471 window_->layer()->SetShowDelegatedContent(frame_provider_.get(), | 1472 window_->layer()->SetShowDelegatedContent(frame_provider_.get(), |
1472 frame_size_in_dip); | 1473 frame_size_in_dip); |
(...skipping 15 matching lines...) Expand all Loading... |
1488 if (!compositor) { | 1489 if (!compositor) { |
1489 SendDelegatedFrameAck(output_surface_id); | 1490 SendDelegatedFrameAck(output_surface_id); |
1490 } else { | 1491 } else { |
1491 compositor->SetLatencyInfo(latency_info); | 1492 compositor->SetLatencyInfo(latency_info); |
1492 AddOnCommitCallbackAndDisableLocks( | 1493 AddOnCommitCallbackAndDisableLocks( |
1493 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, | 1494 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, |
1494 AsWeakPtr(), | 1495 AsWeakPtr(), |
1495 output_surface_id)); | 1496 output_surface_id)); |
1496 } | 1497 } |
1497 DidReceiveFrameFromRenderer(); | 1498 DidReceiveFrameFromRenderer(); |
| 1499 if (frame_provider_.get()) |
| 1500 delegated_frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 1501 // Note: the frame may have been evicted immediately. |
1498 } | 1502 } |
1499 | 1503 |
1500 void RenderWidgetHostViewAura::SendDelegatedFrameAck(uint32 output_surface_id) { | 1504 void RenderWidgetHostViewAura::SendDelegatedFrameAck(uint32 output_surface_id) { |
1501 cc::CompositorFrameAck ack; | 1505 cc::CompositorFrameAck ack; |
1502 if (resource_collection_) | 1506 if (resource_collection_) |
1503 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 1507 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
1504 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host_->GetRoutingID(), | 1508 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host_->GetRoutingID(), |
1505 output_surface_id, | 1509 output_surface_id, |
1506 host_->GetProcess()->GetID(), | 1510 host_->GetProcess()->GetID(), |
1507 ack); | 1511 ack); |
(...skipping 14 matching lines...) Expand all Loading... |
1522 if (resource_collection_) | 1526 if (resource_collection_) |
1523 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 1527 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
1524 DCHECK(!ack.resources.empty()); | 1528 DCHECK(!ack.resources.empty()); |
1525 RenderWidgetHostImpl::SendReclaimCompositorResources( | 1529 RenderWidgetHostImpl::SendReclaimCompositorResources( |
1526 host_->GetRoutingID(), | 1530 host_->GetRoutingID(), |
1527 output_surface_id, | 1531 output_surface_id, |
1528 host_->GetProcess()->GetID(), | 1532 host_->GetProcess()->GetID(), |
1529 ack); | 1533 ack); |
1530 } | 1534 } |
1531 | 1535 |
| 1536 void RenderWidgetHostViewAura::EvictDelegatedFrame() { |
| 1537 window_->layer()->SetShowPaintedContent(); |
| 1538 frame_provider_ = NULL; |
| 1539 delegated_frame_evictor_->DiscardedFrame(); |
| 1540 } |
| 1541 |
1532 void RenderWidgetHostViewAura::SwapSoftwareFrame( | 1542 void RenderWidgetHostViewAura::SwapSoftwareFrame( |
1533 uint32 output_surface_id, | 1543 uint32 output_surface_id, |
1534 scoped_ptr<cc::SoftwareFrameData> frame_data, | 1544 scoped_ptr<cc::SoftwareFrameData> frame_data, |
1535 float frame_device_scale_factor, | 1545 float frame_device_scale_factor, |
1536 const ui::LatencyInfo& latency_info) { | 1546 const ui::LatencyInfo& latency_info) { |
1537 const gfx::Size& frame_size = frame_data->size; | 1547 const gfx::Size& frame_size = frame_data->size; |
1538 const gfx::Rect& damage_rect = frame_data->damage_rect; | 1548 const gfx::Rect& damage_rect = frame_data->damage_rect; |
1539 gfx::Size frame_size_in_dip = | 1549 gfx::Size frame_size_in_dip = |
1540 ConvertSizeToDIP(frame_device_scale_factor, frame_size); | 1550 ConvertSizeToDIP(frame_device_scale_factor, frame_size); |
1541 if (ShouldSkipFrame(frame_size_in_dip)) { | 1551 if (ShouldSkipFrame(frame_size_in_dip)) { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 } | 1791 } |
1782 | 1792 |
1783 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { | 1793 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { |
1784 // This really tells us to release the frontbuffer. | 1794 // This really tells us to release the frontbuffer. |
1785 if (current_surface_.get()) { | 1795 if (current_surface_.get()) { |
1786 ui::Compositor* compositor = GetCompositor(); | 1796 ui::Compositor* compositor = GetCompositor(); |
1787 if (compositor) { | 1797 if (compositor) { |
1788 // We need to wait for a commit to clear to guarantee that all we | 1798 // We need to wait for a commit to clear to guarantee that all we |
1789 // will not issue any more GL referencing the previous surface. | 1799 // will not issue any more GL referencing the previous surface. |
1790 AddOnCommitCallbackAndDisableLocks( | 1800 AddOnCommitCallbackAndDisableLocks( |
1791 base::Bind(&RenderWidgetHostViewAura:: | 1801 base::Bind(&RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor, |
1792 SetSurfaceNotInUseByCompositor, | |
1793 AsWeakPtr(), | 1802 AsWeakPtr(), |
1794 current_surface_)); // Hold a ref so the texture will not | 1803 current_surface_)); // Hold a ref so the texture will not |
1795 // get deleted until after commit. | 1804 // get deleted until after commit. |
1796 } | 1805 } |
1797 current_surface_ = NULL; | 1806 current_surface_ = NULL; |
1798 UpdateExternalTexture(); | 1807 UpdateExternalTexture(); |
1799 } | 1808 } |
1800 } | 1809 } |
1801 | 1810 |
1802 bool RenderWidgetHostViewAura::HasAcceleratedSurface( | 1811 bool RenderWidgetHostViewAura::HasAcceleratedSurface( |
(...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3405 RenderWidgetHost* widget) { | 3414 RenderWidgetHost* widget) { |
3406 return new RenderWidgetHostViewAura(widget); | 3415 return new RenderWidgetHostViewAura(widget); |
3407 } | 3416 } |
3408 | 3417 |
3409 // static | 3418 // static |
3410 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3419 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3411 GetScreenInfoForWindow(results, NULL); | 3420 GetScreenInfoForWindow(results, NULL); |
3412 } | 3421 } |
3413 | 3422 |
3414 } // namespace content | 3423 } // namespace content |
OLD | NEW |