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/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 149 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
150 public: | 150 public: |
151 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) | 151 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) |
152 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} | 152 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} |
153 | 153 |
154 virtual ~FakeRenderWidgetHostViewAura() {} | 154 virtual ~FakeRenderWidgetHostViewAura() {} |
155 | 155 |
156 virtual bool ShouldCreateResizeLock() OVERRIDE { | 156 virtual bool ShouldCreateResizeLock() OVERRIDE { |
157 gfx::Size desired_size = window()->bounds().size(); | 157 gfx::Size desired_size = window()->bounds().size(); |
158 return desired_size != current_frame_size(); | 158 return desired_size != current_frame_size_in_dip(); |
159 } | 159 } |
160 | 160 |
161 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) | 161 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) |
162 OVERRIDE { | 162 OVERRIDE { |
163 gfx::Size desired_size = window()->bounds().size(); | 163 gfx::Size desired_size = window()->bounds().size(); |
164 return scoped_ptr<ResizeLock>( | 164 return scoped_ptr<ResizeLock>( |
165 new FakeResizeLock(desired_size, defer_compositor_lock)); | 165 new FakeResizeLock(desired_size, defer_compositor_lock)); |
166 } | 166 } |
167 | 167 |
168 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) | 168 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 view_->UpdateCursorIfOverSelf(); | 827 view_->UpdateCursorIfOverSelf(); |
828 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); | 828 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); |
829 | 829 |
830 // Cursor is below the window. | 830 // Cursor is below the window. |
831 cursor_client.reset_calls_to_set_cursor(); | 831 cursor_client.reset_calls_to_set_cursor(); |
832 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161)); | 832 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161)); |
833 view_->UpdateCursorIfOverSelf(); | 833 view_->UpdateCursorIfOverSelf(); |
834 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); | 834 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); |
835 } | 835 } |
836 | 836 |
837 scoped_ptr<cc::CompositorFrame> MakeGLFrame(float scale_factor, | |
838 gfx::Size size, | |
839 gfx::Rect damage) { | |
840 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
841 frame->metadata.device_scale_factor = scale_factor; | |
842 frame->gl_frame_data.reset(new cc::GLFrameData); | |
843 frame->gl_frame_data->sync_point = 1; | |
844 memset(frame->gl_frame_data->mailbox.name, '1', 64); | |
845 frame->gl_frame_data->size = size; | |
846 frame->gl_frame_data->sub_buffer_rect = damage; | |
847 return frame.Pass(); | |
848 } | |
849 | |
850 scoped_ptr<cc::CompositorFrame> MakeSoftwareFrame(float scale_factor, | 837 scoped_ptr<cc::CompositorFrame> MakeSoftwareFrame(float scale_factor, |
851 gfx::Size size, | 838 gfx::Size size, |
852 gfx::Rect damage) { | 839 gfx::Rect damage) { |
853 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 840 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
854 frame->metadata.device_scale_factor = scale_factor; | 841 frame->metadata.device_scale_factor = scale_factor; |
855 frame->software_frame_data.reset(new cc::SoftwareFrameData); | 842 frame->software_frame_data.reset(new cc::SoftwareFrameData); |
856 frame->software_frame_data->id = 1; | 843 frame->software_frame_data->id = 1; |
857 frame->software_frame_data->size = size; | 844 frame->software_frame_data->size = size; |
858 frame->software_frame_data->damage_rect = damage; | 845 frame->software_frame_data->damage_rect = damage; |
859 base::SharedMemory shm; | 846 base::SharedMemory shm; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 const IPC::Message* msg = sink_->GetMessageAt(0); | 882 const IPC::Message* msg = sink_->GetMessageAt(0); |
896 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 883 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
897 ViewMsg_Resize::Param params; | 884 ViewMsg_Resize::Param params; |
898 ViewMsg_Resize::Read(msg, ¶ms); | 885 ViewMsg_Resize::Read(msg, ¶ms); |
899 EXPECT_EQ("0,0 800x600", | 886 EXPECT_EQ("0,0 800x600", |
900 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 887 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
901 EXPECT_EQ("800x600", params.a.new_size.ToString()); | 888 EXPECT_EQ("800x600", params.a.new_size.ToString()); |
902 // Resizes are blocked until we swapped a frame of the correct size, and | 889 // Resizes are blocked until we swapped a frame of the correct size, and |
903 // we've committed it. | 890 // we've committed it. |
904 view_->OnSwapCompositorFrame( | 891 view_->OnSwapCompositorFrame( |
905 0, MakeGLFrame(1.f, params.a.new_size, gfx::Rect(params.a.new_size))); | 892 0, |
| 893 MakeDelegatedFrame( |
| 894 1.f, params.a.new_size, gfx::Rect(params.a.new_size))); |
906 ui::DrawWaiterForTest::WaitForCommit( | 895 ui::DrawWaiterForTest::WaitForCommit( |
907 root_window->GetDispatcher()->host()->compositor()); | 896 root_window->GetDispatcher()->host()->compositor()); |
908 } | 897 } |
909 | 898 |
910 widget_host_->ResetSizeAndRepaintPendingFlags(); | 899 widget_host_->ResetSizeAndRepaintPendingFlags(); |
911 sink_->ClearMessages(); | 900 sink_->ClearMessages(); |
912 | 901 |
913 // Make sure the corrent screen size is set along in the resize | 902 // Make sure the corrent screen size is set along in the resize |
914 // request when the screen size has changed. | 903 // request when the screen size has changed. |
915 aura_test_helper_->test_screen()->SetUIScale(0.5); | 904 aura_test_helper_->test_screen()->SetUIScale(0.5); |
916 EXPECT_EQ(1u, sink_->message_count()); | 905 EXPECT_EQ(1u, sink_->message_count()); |
917 { | 906 { |
918 const IPC::Message* msg = sink_->GetMessageAt(0); | 907 const IPC::Message* msg = sink_->GetMessageAt(0); |
919 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 908 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
920 ViewMsg_Resize::Param params; | 909 ViewMsg_Resize::Param params; |
921 ViewMsg_Resize::Read(msg, ¶ms); | 910 ViewMsg_Resize::Read(msg, ¶ms); |
922 EXPECT_EQ("0,0 1600x1200", | 911 EXPECT_EQ("0,0 1600x1200", |
923 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 912 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
924 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); | 913 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); |
925 view_->OnSwapCompositorFrame( | 914 view_->OnSwapCompositorFrame( |
926 0, MakeGLFrame(1.f, params.a.new_size, gfx::Rect(params.a.new_size))); | 915 0, |
| 916 MakeDelegatedFrame( |
| 917 1.f, params.a.new_size, gfx::Rect(params.a.new_size))); |
927 ui::DrawWaiterForTest::WaitForCommit( | 918 ui::DrawWaiterForTest::WaitForCommit( |
928 root_window->GetDispatcher()->host()->compositor()); | 919 root_window->GetDispatcher()->host()->compositor()); |
929 } | 920 } |
930 } | 921 } |
931 | 922 |
932 // Swapping a frame should notify the window. | 923 // Swapping a frame should notify the window. |
933 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { | 924 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { |
934 gfx::Size view_size(100, 100); | 925 gfx::Size view_size(100, 100); |
935 gfx::Rect view_rect(view_size); | 926 gfx::Rect view_rect(view_size); |
936 | 927 |
937 view_->InitAsChild(NULL); | 928 view_->InitAsChild(NULL); |
938 aura::client::ParentWindowWithContext( | 929 aura::client::ParentWindowWithContext( |
939 view_->GetNativeView(), | 930 view_->GetNativeView(), |
940 parent_view_->GetNativeView()->GetRootWindow(), | 931 parent_view_->GetNativeView()->GetRootWindow(), |
941 gfx::Rect()); | 932 gfx::Rect()); |
942 view_->SetSize(view_size); | 933 view_->SetSize(view_size); |
943 view_->WasShown(); | 934 view_->WasShown(); |
944 | 935 |
945 MockWindowObserver observer; | 936 MockWindowObserver observer; |
946 view_->window_->AddObserver(&observer); | 937 view_->window_->AddObserver(&observer); |
947 | 938 |
948 // Swap a frame through the GPU path. | |
949 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
950 params.surface_id = widget_host_->surface_id(); | |
951 params.route_id = widget_host_->GetRoutingID(); | |
952 params.mailbox_name = std::string(64, '1'); | |
953 params.size = view_size; | |
954 params.scale_factor = 1.f; | |
955 | |
956 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
957 view_->AcceleratedSurfaceBuffersSwapped(params, 0); | |
958 testing::Mock::VerifyAndClearExpectations(&observer); | |
959 | |
960 // DSF = 2 | |
961 params.size = gfx::Size(200, 200); | |
962 params.scale_factor = 2.f; | |
963 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
964 view_->AcceleratedSurfaceBuffersSwapped(params, 0); | |
965 testing::Mock::VerifyAndClearExpectations(&observer); | |
966 | |
967 // Partial frames though GPU path | |
968 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params post_params; | |
969 post_params.surface_id = widget_host_->surface_id(); | |
970 post_params.route_id = widget_host_->GetRoutingID(); | |
971 post_params.mailbox_name = std::string(64, '1'); | |
972 post_params.surface_size = gfx::Size(200, 200); | |
973 post_params.surface_scale_factor = 2.f; | |
974 post_params.x = 40; | |
975 post_params.y = 40; | |
976 post_params.width = 80; | |
977 post_params.height = 80; | |
978 // rect from params is upside down, and is inflated in RWHVA, just because. | |
979 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | |
980 gfx::Rect(19, 39, 42, 42))); | |
981 view_->AcceleratedSurfacePostSubBuffer(post_params, 0); | |
982 testing::Mock::VerifyAndClearExpectations(&observer); | |
983 | |
984 // Composite-to-mailbox path | |
985 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
986 view_->OnSwapCompositorFrame(0, MakeGLFrame(1.f, view_size, view_rect)); | |
987 testing::Mock::VerifyAndClearExpectations(&observer); | |
988 | |
989 // rect from GL frame is upside down, and is inflated in RWHVA, just because. | |
990 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | |
991 gfx::Rect(4, 89, 7, 7))); | |
992 view_->OnSwapCompositorFrame( | |
993 0, MakeGLFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); | |
994 testing::Mock::VerifyAndClearExpectations(&observer); | |
995 | |
996 // Software path | 939 // Software path |
997 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | 940 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); |
998 view_->OnSwapCompositorFrame(0, MakeSoftwareFrame(1.f, view_size, view_rect)); | 941 view_->OnSwapCompositorFrame(0, MakeSoftwareFrame(1.f, view_size, view_rect)); |
999 testing::Mock::VerifyAndClearExpectations(&observer); | 942 testing::Mock::VerifyAndClearExpectations(&observer); |
1000 | 943 |
1001 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | 944 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, |
1002 gfx::Rect(5, 5, 5, 5))); | 945 gfx::Rect(5, 5, 5, 5))); |
1003 view_->OnSwapCompositorFrame( | 946 view_->OnSwapCompositorFrame( |
1004 0, MakeSoftwareFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); | 947 0, MakeSoftwareFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); |
1005 testing::Mock::VerifyAndClearExpectations(&observer); | 948 testing::Mock::VerifyAndClearExpectations(&observer); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 | 1356 |
1414 // Because the copy request callback may be holding state within it, that | 1357 // Because the copy request callback may be holding state within it, that |
1415 // state must handle the RWHVA and ImageTransportFactory going away before the | 1358 // state must handle the RWHVA and ImageTransportFactory going away before the |
1416 // callback is called. This test passes if it does not crash as a result of | 1359 // callback is called. This test passes if it does not crash as a result of |
1417 // these things being destroyed. | 1360 // these things being destroyed. |
1418 EXPECT_EQ(2, callback_count_); | 1361 EXPECT_EQ(2, callback_count_); |
1419 EXPECT_FALSE(result_); | 1362 EXPECT_FALSE(result_); |
1420 } | 1363 } |
1421 | 1364 |
1422 } // namespace content | 1365 } // namespace content |
OLD | NEW |