| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 using testing::_; | 104 using testing::_; |
| 105 | 105 |
| 106 using blink::WebGestureEvent; | 106 using blink::WebGestureEvent; |
| 107 using blink::WebInputEvent; | 107 using blink::WebInputEvent; |
| 108 using blink::WebMouseEvent; | 108 using blink::WebMouseEvent; |
| 109 using blink::WebMouseWheelEvent; | 109 using blink::WebMouseWheelEvent; |
| 110 using blink::WebTouchEvent; | 110 using blink::WebTouchEvent; |
| 111 using blink::WebTouchPoint; | 111 using blink::WebTouchPoint; |
| 112 using ui::WebInputEventTraits; | 112 using ui::WebInputEventTraits; |
| 113 using viz::FrameEvictionManager; |
| 113 | 114 |
| 114 namespace content { | 115 namespace content { |
| 115 | 116 |
| 116 void InstallDelegatedFrameHostClient( | 117 void InstallDelegatedFrameHostClient( |
| 117 RenderWidgetHostViewAura* render_widget_host_view, | 118 RenderWidgetHostViewAura* render_widget_host_view, |
| 118 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client); | 119 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client); |
| 119 | 120 |
| 120 namespace { | 121 namespace { |
| 121 | 122 |
| 122 const cc::LocalSurfaceId kArbitraryLocalSurfaceId( | 123 const cc::LocalSurfaceId kArbitraryLocalSurfaceId( |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 648 |
| 648 void TearDown() override { TearDownEnvironment(); } | 649 void TearDown() override { TearDownEnvironment(); } |
| 649 | 650 |
| 650 void set_widget_host_uses_shutdown_to_destroy(bool use) { | 651 void set_widget_host_uses_shutdown_to_destroy(bool use) { |
| 651 widget_host_uses_shutdown_to_destroy_ = use; | 652 widget_host_uses_shutdown_to_destroy_ = use; |
| 652 } | 653 } |
| 653 | 654 |
| 654 void SimulateMemoryPressure( | 655 void SimulateMemoryPressure( |
| 655 base::MemoryPressureListener::MemoryPressureLevel level) { | 656 base::MemoryPressureListener::MemoryPressureLevel level) { |
| 656 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but | 657 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but |
| 657 // since the RendererFrameManager is installing a MemoryPressureListener | 658 // since the FrameEvictionManager is installing a MemoryPressureListener |
| 658 // which uses base::ObserverListThreadSafe, which furthermore remembers the | 659 // which uses base::ObserverListThreadSafe, which furthermore remembers the |
| 659 // message loop for the thread it was created in. Between tests, the | 660 // message loop for the thread it was created in. Between tests, the |
| 660 // RendererFrameManager singleton survives and and the MessageLoop gets | 661 // FrameEvictionManager singleton survives and and the MessageLoop gets |
| 661 // destroyed. The correct fix would be to have base::ObserverListThreadSafe | 662 // destroyed. The correct fix would be to have base::ObserverListThreadSafe |
| 662 // look | 663 // look |
| 663 // up the proper message loop every time (see crbug.com/443824.) | 664 // up the proper message loop every time (see crbug.com/443824.) |
| 664 RendererFrameManager::GetInstance()->OnMemoryPressure(level); | 665 FrameEvictionManager::GetInstance()->OnMemoryPressure(level); |
| 665 } | 666 } |
| 666 | 667 |
| 667 void SendInputEventACK(WebInputEvent::Type type, | 668 void SendInputEventACK(WebInputEvent::Type type, |
| 668 InputEventAckState ack_result) { | 669 InputEventAckState ack_result) { |
| 669 DCHECK(!WebInputEvent::IsTouchEventType(type)); | 670 DCHECK(!WebInputEvent::IsTouchEventType(type)); |
| 670 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, type, ack_result); | 671 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, type, ack_result); |
| 671 InputHostMsg_HandleInputEvent_ACK response(0, ack); | 672 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 672 widget_host_->OnMessageReceived(response); | 673 widget_host_->OnMessageReceived(response); |
| 673 } | 674 } |
| 674 | 675 |
| (...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2652 testing::Mock::VerifyAndClearExpectations(&observer); | 2653 testing::Mock::VerifyAndClearExpectations(&observer); |
| 2653 view_->RunOnCompositingDidCommit(); | 2654 view_->RunOnCompositingDidCommit(); |
| 2654 | 2655 |
| 2655 view_->window_->RemoveObserver(&observer); | 2656 view_->window_->RemoveObserver(&observer); |
| 2656 } | 2657 } |
| 2657 | 2658 |
| 2658 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { | 2659 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { |
| 2659 view_->InitAsChild(nullptr); | 2660 view_->InitAsChild(nullptr); |
| 2660 | 2661 |
| 2661 size_t max_renderer_frames = | 2662 size_t max_renderer_frames = |
| 2662 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames(); | 2663 FrameEvictionManager::GetInstance()->GetMaxNumberOfSavedFrames(); |
| 2663 ASSERT_LE(2u, max_renderer_frames); | 2664 ASSERT_LE(2u, max_renderer_frames); |
| 2664 size_t renderer_count = max_renderer_frames + 1; | 2665 size_t renderer_count = max_renderer_frames + 1; |
| 2665 gfx::Rect view_rect(100, 100); | 2666 gfx::Rect view_rect(100, 100); |
| 2666 gfx::Size frame_size = view_rect.size(); | 2667 gfx::Size frame_size = view_rect.size(); |
| 2667 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2668 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2668 ->AllocatedBitmapCount()); | 2669 ->AllocatedBitmapCount()); |
| 2669 | 2670 |
| 2670 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2671 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2671 new RenderWidgetHostImpl*[renderer_count]); | 2672 new RenderWidgetHostImpl*[renderer_count]); |
| 2672 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( | 2673 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2795 kArbitraryLocalSurfaceId, | 2796 kArbitraryLocalSurfaceId, |
| 2796 MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); | 2797 MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); |
| 2797 EXPECT_FALSE(views[1]->released_front_lock_active()); | 2798 EXPECT_FALSE(views[1]->released_front_lock_active()); |
| 2798 | 2799 |
| 2799 for (size_t i = 0; i < renderer_count - 1; ++i) | 2800 for (size_t i = 0; i < renderer_count - 1; ++i) |
| 2800 views[i]->Hide(); | 2801 views[i]->Hide(); |
| 2801 | 2802 |
| 2802 // Allocate enough bitmaps so that two frames (proportionally) would be | 2803 // Allocate enough bitmaps so that two frames (proportionally) would be |
| 2803 // enough hit the handle limit. | 2804 // enough hit the handle limit. |
| 2804 int handles_per_frame = 5; | 2805 int handles_per_frame = 5; |
| 2805 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame * 2); | 2806 FrameEvictionManager::GetInstance()->set_max_handles(handles_per_frame * 2); |
| 2806 | 2807 |
| 2807 display_compositor::HostSharedBitmapManagerClient bitmap_client( | 2808 display_compositor::HostSharedBitmapManagerClient bitmap_client( |
| 2808 display_compositor::HostSharedBitmapManager::current()); | 2809 display_compositor::HostSharedBitmapManager::current()); |
| 2809 | 2810 |
| 2810 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) { | 2811 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) { |
| 2811 bitmap_client.ChildAllocatedSharedBitmap( | 2812 bitmap_client.ChildAllocatedSharedBitmap( |
| 2812 1, base::SharedMemory::NULLHandle(), cc::SharedBitmap::GenerateId()); | 2813 1, base::SharedMemory::NULLHandle(), cc::SharedBitmap::GenerateId()); |
| 2813 } | 2814 } |
| 2814 | 2815 |
| 2815 // Hiding this last bitmap should evict all but two frames. | 2816 // Hiding this last bitmap should evict all but two frames. |
| 2816 views[renderer_count - 1]->Hide(); | 2817 views[renderer_count - 1]->Hide(); |
| 2817 for (size_t i = 0; i < renderer_count; ++i) { | 2818 for (size_t i = 0; i < renderer_count; ++i) { |
| 2818 if (i + 2 < renderer_count) | 2819 if (i + 2 < renderer_count) |
| 2819 EXPECT_FALSE(views[i]->HasFrameData()); | 2820 EXPECT_FALSE(views[i]->HasFrameData()); |
| 2820 else | 2821 else |
| 2821 EXPECT_TRUE(views[i]->HasFrameData()); | 2822 EXPECT_TRUE(views[i]->HasFrameData()); |
| 2822 } | 2823 } |
| 2823 RendererFrameManager::GetInstance()->set_max_handles( | 2824 FrameEvictionManager::GetInstance()->set_max_handles( |
| 2824 base::SharedMemory::GetHandleLimit()); | 2825 base::SharedMemory::GetHandleLimit()); |
| 2825 | 2826 |
| 2826 for (size_t i = 0; i < renderer_count; ++i) { | 2827 for (size_t i = 0; i < renderer_count; ++i) { |
| 2827 views[i]->Destroy(); | 2828 views[i]->Destroy(); |
| 2828 delete hosts[i]; | 2829 delete hosts[i]; |
| 2829 } | 2830 } |
| 2830 } | 2831 } |
| 2831 | 2832 |
| 2832 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { | 2833 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { |
| 2833 view_->InitAsChild(nullptr); | 2834 view_->InitAsChild(nullptr); |
| 2834 | 2835 |
| 2835 size_t max_renderer_frames = | 2836 size_t max_renderer_frames = |
| 2836 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames(); | 2837 FrameEvictionManager::GetInstance()->GetMaxNumberOfSavedFrames(); |
| 2837 ASSERT_LE(2u, max_renderer_frames); | 2838 ASSERT_LE(2u, max_renderer_frames); |
| 2838 size_t renderer_count = max_renderer_frames + 1; | 2839 size_t renderer_count = max_renderer_frames + 1; |
| 2839 gfx::Rect view_rect(100, 100); | 2840 gfx::Rect view_rect(100, 100); |
| 2840 gfx::Size frame_size = view_rect.size(); | 2841 gfx::Size frame_size = view_rect.size(); |
| 2841 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2842 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2842 ->AllocatedBitmapCount()); | 2843 ->AllocatedBitmapCount()); |
| 2843 | 2844 |
| 2844 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2845 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2845 new RenderWidgetHostImpl*[renderer_count]); | 2846 new RenderWidgetHostImpl*[renderer_count]); |
| 2846 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( | 2847 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2898 | 2899 |
| 2899 // Test that changing the memory pressure should delete saved frames. This test | 2900 // Test that changing the memory pressure should delete saved frames. This test |
| 2900 // only applies to ChromeOS. | 2901 // only applies to ChromeOS. |
| 2901 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) { | 2902 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) { |
| 2902 view_->InitAsChild(nullptr); | 2903 view_->InitAsChild(nullptr); |
| 2903 | 2904 |
| 2904 // The test logic below relies on having max_renderer_frames > 2. By default, | 2905 // The test logic below relies on having max_renderer_frames > 2. By default, |
| 2905 // this value is calculated from total physical memory and causes the test to | 2906 // this value is calculated from total physical memory and causes the test to |
| 2906 // fail when run on hardware with < 256MB of RAM. | 2907 // fail when run on hardware with < 256MB of RAM. |
| 2907 const size_t kMaxRendererFrames = 5; | 2908 const size_t kMaxRendererFrames = 5; |
| 2908 RendererFrameManager::GetInstance()->set_max_number_of_saved_frames( | 2909 FrameEvictionManager::GetInstance()->set_max_number_of_saved_frames( |
| 2909 kMaxRendererFrames); | 2910 kMaxRendererFrames); |
| 2910 | 2911 |
| 2911 size_t renderer_count = kMaxRendererFrames; | 2912 size_t renderer_count = kMaxRendererFrames; |
| 2912 gfx::Rect view_rect(100, 100); | 2913 gfx::Rect view_rect(100, 100); |
| 2913 gfx::Size frame_size = view_rect.size(); | 2914 gfx::Size frame_size = view_rect.size(); |
| 2914 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2915 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2915 ->AllocatedBitmapCount()); | 2916 ->AllocatedBitmapCount()); |
| 2916 | 2917 |
| 2917 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2918 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2918 new RenderWidgetHostImpl*[renderer_count]); | 2919 new RenderWidgetHostImpl*[renderer_count]); |
| (...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5432 // There is no composition in the beginning. | 5433 // There is no composition in the beginning. |
| 5433 EXPECT_FALSE(has_composition_text()); | 5434 EXPECT_FALSE(has_composition_text()); |
| 5434 SetHasCompositionTextToTrue(); | 5435 SetHasCompositionTextToTrue(); |
| 5435 view->ImeCancelComposition(); | 5436 view->ImeCancelComposition(); |
| 5436 // The composition must have been canceled. | 5437 // The composition must have been canceled. |
| 5437 EXPECT_FALSE(has_composition_text()); | 5438 EXPECT_FALSE(has_composition_text()); |
| 5438 } | 5439 } |
| 5439 } | 5440 } |
| 5440 | 5441 |
| 5441 } // namespace content | 5442 } // namespace content |
| OLD | NEW |