| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 using testing::_; | 105 using testing::_; |
| 106 | 106 |
| 107 using blink::WebGestureEvent; | 107 using blink::WebGestureEvent; |
| 108 using blink::WebInputEvent; | 108 using blink::WebInputEvent; |
| 109 using blink::WebMouseEvent; | 109 using blink::WebMouseEvent; |
| 110 using blink::WebMouseWheelEvent; | 110 using blink::WebMouseWheelEvent; |
| 111 using blink::WebTouchEvent; | 111 using blink::WebTouchEvent; |
| 112 using blink::WebTouchPoint; | 112 using blink::WebTouchPoint; |
| 113 using ui::WebInputEventTraits; | 113 using ui::WebInputEventTraits; |
| 114 using viz::FrameEvictionManager; |
| 114 | 115 |
| 115 namespace content { | 116 namespace content { |
| 116 | 117 |
| 117 void InstallDelegatedFrameHostClient( | 118 void InstallDelegatedFrameHostClient( |
| 118 RenderWidgetHostViewAura* render_widget_host_view, | 119 RenderWidgetHostViewAura* render_widget_host_view, |
| 119 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client); | 120 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client); |
| 120 | 121 |
| 121 namespace { | 122 namespace { |
| 122 | 123 |
| 123 const cc::LocalSurfaceId kArbitraryLocalSurfaceId( | 124 const cc::LocalSurfaceId kArbitraryLocalSurfaceId( |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 667 |
| 667 void TearDown() override { TearDownEnvironment(); } | 668 void TearDown() override { TearDownEnvironment(); } |
| 668 | 669 |
| 669 void set_widget_host_uses_shutdown_to_destroy(bool use) { | 670 void set_widget_host_uses_shutdown_to_destroy(bool use) { |
| 670 widget_host_uses_shutdown_to_destroy_ = use; | 671 widget_host_uses_shutdown_to_destroy_ = use; |
| 671 } | 672 } |
| 672 | 673 |
| 673 void SimulateMemoryPressure( | 674 void SimulateMemoryPressure( |
| 674 base::MemoryPressureListener::MemoryPressureLevel level) { | 675 base::MemoryPressureListener::MemoryPressureLevel level) { |
| 675 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but | 676 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but |
| 676 // since the RendererFrameManager is installing a MemoryPressureListener | 677 // since the FrameEvictionManager is installing a MemoryPressureListener |
| 677 // which uses base::ObserverListThreadSafe, which furthermore remembers the | 678 // which uses base::ObserverListThreadSafe, which furthermore remembers the |
| 678 // message loop for the thread it was created in. Between tests, the | 679 // message loop for the thread it was created in. Between tests, the |
| 679 // RendererFrameManager singleton survives and and the MessageLoop gets | 680 // FrameEvictionManager singleton survives and and the MessageLoop gets |
| 680 // destroyed. The correct fix would be to have base::ObserverListThreadSafe | 681 // destroyed. The correct fix would be to have base::ObserverListThreadSafe |
| 681 // look | 682 // look |
| 682 // up the proper message loop every time (see crbug.com/443824.) | 683 // up the proper message loop every time (see crbug.com/443824.) |
| 683 RendererFrameManager::GetInstance()->OnMemoryPressure(level); | 684 FrameEvictionManager::GetInstance()->OnMemoryPressure(level); |
| 684 } | 685 } |
| 685 | 686 |
| 686 void SendInputEventACK(WebInputEvent::Type type, | 687 void SendInputEventACK(WebInputEvent::Type type, |
| 687 InputEventAckState ack_result) { | 688 InputEventAckState ack_result) { |
| 688 DCHECK(!WebInputEvent::IsTouchEventType(type)); | 689 DCHECK(!WebInputEvent::IsTouchEventType(type)); |
| 689 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, type, ack_result); | 690 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, type, ack_result); |
| 690 InputHostMsg_HandleInputEvent_ACK response(0, ack); | 691 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 691 widget_host_->OnMessageReceived(response); | 692 widget_host_->OnMessageReceived(response); |
| 692 } | 693 } |
| 693 | 694 |
| (...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2663 testing::Mock::VerifyAndClearExpectations(&observer); | 2664 testing::Mock::VerifyAndClearExpectations(&observer); |
| 2664 view_->RunOnCompositingDidCommit(); | 2665 view_->RunOnCompositingDidCommit(); |
| 2665 | 2666 |
| 2666 view_->window_->RemoveObserver(&observer); | 2667 view_->window_->RemoveObserver(&observer); |
| 2667 } | 2668 } |
| 2668 | 2669 |
| 2669 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { | 2670 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { |
| 2670 view_->InitAsChild(nullptr); | 2671 view_->InitAsChild(nullptr); |
| 2671 | 2672 |
| 2672 size_t max_renderer_frames = | 2673 size_t max_renderer_frames = |
| 2673 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames(); | 2674 FrameEvictionManager::GetInstance()->GetMaxNumberOfSavedFrames(); |
| 2674 ASSERT_LE(2u, max_renderer_frames); | 2675 ASSERT_LE(2u, max_renderer_frames); |
| 2675 size_t renderer_count = max_renderer_frames + 1; | 2676 size_t renderer_count = max_renderer_frames + 1; |
| 2676 gfx::Rect view_rect(100, 100); | 2677 gfx::Rect view_rect(100, 100); |
| 2677 gfx::Size frame_size = view_rect.size(); | 2678 gfx::Size frame_size = view_rect.size(); |
| 2678 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2679 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2679 ->AllocatedBitmapCount()); | 2680 ->AllocatedBitmapCount()); |
| 2680 | 2681 |
| 2681 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2682 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2682 new RenderWidgetHostImpl*[renderer_count]); | 2683 new RenderWidgetHostImpl*[renderer_count]); |
| 2683 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( | 2684 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2806 kArbitraryLocalSurfaceId, | 2807 kArbitraryLocalSurfaceId, |
| 2807 MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); | 2808 MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); |
| 2808 EXPECT_FALSE(views[1]->released_front_lock_active()); | 2809 EXPECT_FALSE(views[1]->released_front_lock_active()); |
| 2809 | 2810 |
| 2810 for (size_t i = 0; i < renderer_count - 1; ++i) | 2811 for (size_t i = 0; i < renderer_count - 1; ++i) |
| 2811 views[i]->Hide(); | 2812 views[i]->Hide(); |
| 2812 | 2813 |
| 2813 // Allocate enough bitmaps so that two frames (proportionally) would be | 2814 // Allocate enough bitmaps so that two frames (proportionally) would be |
| 2814 // enough hit the handle limit. | 2815 // enough hit the handle limit. |
| 2815 int handles_per_frame = 5; | 2816 int handles_per_frame = 5; |
| 2816 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame * 2); | 2817 FrameEvictionManager::GetInstance()->set_max_handles(handles_per_frame * 2); |
| 2817 | 2818 |
| 2818 display_compositor::HostSharedBitmapManagerClient bitmap_client( | 2819 display_compositor::HostSharedBitmapManagerClient bitmap_client( |
| 2819 display_compositor::HostSharedBitmapManager::current()); | 2820 display_compositor::HostSharedBitmapManager::current()); |
| 2820 | 2821 |
| 2821 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) { | 2822 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) { |
| 2822 bitmap_client.ChildAllocatedSharedBitmap( | 2823 bitmap_client.ChildAllocatedSharedBitmap( |
| 2823 1, base::SharedMemory::NULLHandle(), cc::SharedBitmap::GenerateId()); | 2824 1, base::SharedMemory::NULLHandle(), cc::SharedBitmap::GenerateId()); |
| 2824 } | 2825 } |
| 2825 | 2826 |
| 2826 // Hiding this last bitmap should evict all but two frames. | 2827 // Hiding this last bitmap should evict all but two frames. |
| 2827 views[renderer_count - 1]->Hide(); | 2828 views[renderer_count - 1]->Hide(); |
| 2828 for (size_t i = 0; i < renderer_count; ++i) { | 2829 for (size_t i = 0; i < renderer_count; ++i) { |
| 2829 if (i + 2 < renderer_count) | 2830 if (i + 2 < renderer_count) |
| 2830 EXPECT_FALSE(views[i]->HasFrameData()); | 2831 EXPECT_FALSE(views[i]->HasFrameData()); |
| 2831 else | 2832 else |
| 2832 EXPECT_TRUE(views[i]->HasFrameData()); | 2833 EXPECT_TRUE(views[i]->HasFrameData()); |
| 2833 } | 2834 } |
| 2834 RendererFrameManager::GetInstance()->set_max_handles( | 2835 FrameEvictionManager::GetInstance()->set_max_handles( |
| 2835 base::SharedMemory::GetHandleLimit()); | 2836 base::SharedMemory::GetHandleLimit()); |
| 2836 | 2837 |
| 2837 for (size_t i = 0; i < renderer_count; ++i) { | 2838 for (size_t i = 0; i < renderer_count; ++i) { |
| 2838 views[i]->Destroy(); | 2839 views[i]->Destroy(); |
| 2839 delete hosts[i]; | 2840 delete hosts[i]; |
| 2840 } | 2841 } |
| 2841 } | 2842 } |
| 2842 | 2843 |
| 2843 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { | 2844 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { |
| 2844 view_->InitAsChild(nullptr); | 2845 view_->InitAsChild(nullptr); |
| 2845 | 2846 |
| 2846 size_t max_renderer_frames = | 2847 size_t max_renderer_frames = |
| 2847 RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames(); | 2848 FrameEvictionManager::GetInstance()->GetMaxNumberOfSavedFrames(); |
| 2848 ASSERT_LE(2u, max_renderer_frames); | 2849 ASSERT_LE(2u, max_renderer_frames); |
| 2849 size_t renderer_count = max_renderer_frames + 1; | 2850 size_t renderer_count = max_renderer_frames + 1; |
| 2850 gfx::Rect view_rect(100, 100); | 2851 gfx::Rect view_rect(100, 100); |
| 2851 gfx::Size frame_size = view_rect.size(); | 2852 gfx::Size frame_size = view_rect.size(); |
| 2852 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2853 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2853 ->AllocatedBitmapCount()); | 2854 ->AllocatedBitmapCount()); |
| 2854 | 2855 |
| 2855 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2856 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2856 new RenderWidgetHostImpl*[renderer_count]); | 2857 new RenderWidgetHostImpl*[renderer_count]); |
| 2857 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( | 2858 std::unique_ptr<FakeRenderWidgetHostViewAura* []> views( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2909 | 2910 |
| 2910 // Test that changing the memory pressure should delete saved frames. This test | 2911 // Test that changing the memory pressure should delete saved frames. This test |
| 2911 // only applies to ChromeOS. | 2912 // only applies to ChromeOS. |
| 2912 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) { | 2913 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) { |
| 2913 view_->InitAsChild(nullptr); | 2914 view_->InitAsChild(nullptr); |
| 2914 | 2915 |
| 2915 // The test logic below relies on having max_renderer_frames > 2. By default, | 2916 // The test logic below relies on having max_renderer_frames > 2. By default, |
| 2916 // this value is calculated from total physical memory and causes the test to | 2917 // this value is calculated from total physical memory and causes the test to |
| 2917 // fail when run on hardware with < 256MB of RAM. | 2918 // fail when run on hardware with < 256MB of RAM. |
| 2918 const size_t kMaxRendererFrames = 5; | 2919 const size_t kMaxRendererFrames = 5; |
| 2919 RendererFrameManager::GetInstance()->set_max_number_of_saved_frames( | 2920 FrameEvictionManager::GetInstance()->set_max_number_of_saved_frames( |
| 2920 kMaxRendererFrames); | 2921 kMaxRendererFrames); |
| 2921 | 2922 |
| 2922 size_t renderer_count = kMaxRendererFrames; | 2923 size_t renderer_count = kMaxRendererFrames; |
| 2923 gfx::Rect view_rect(100, 100); | 2924 gfx::Rect view_rect(100, 100); |
| 2924 gfx::Size frame_size = view_rect.size(); | 2925 gfx::Size frame_size = view_rect.size(); |
| 2925 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() | 2926 DCHECK_EQ(0u, display_compositor::HostSharedBitmapManager::current() |
| 2926 ->AllocatedBitmapCount()); | 2927 ->AllocatedBitmapCount()); |
| 2927 | 2928 |
| 2928 std::unique_ptr<RenderWidgetHostImpl* []> hosts( | 2929 std::unique_ptr<RenderWidgetHostImpl* []> hosts( |
| 2929 new RenderWidgetHostImpl*[renderer_count]); | 2930 new RenderWidgetHostImpl*[renderer_count]); |
| (...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5443 // There is no composition in the beginning. | 5444 // There is no composition in the beginning. |
| 5444 EXPECT_FALSE(has_composition_text()); | 5445 EXPECT_FALSE(has_composition_text()); |
| 5445 SetHasCompositionTextToTrue(); | 5446 SetHasCompositionTextToTrue(); |
| 5446 view->ImeCancelComposition(); | 5447 view->ImeCancelComposition(); |
| 5447 // The composition must have been canceled. | 5448 // The composition must have been canceled. |
| 5448 EXPECT_FALSE(has_composition_text()); | 5449 EXPECT_FALSE(has_composition_text()); |
| 5449 } | 5450 } |
| 5450 } | 5451 } |
| 5451 | 5452 |
| 5452 } // namespace content | 5453 } // namespace content |
| OLD | NEW |