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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 150 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
151 public: | 151 public: |
152 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) | 152 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) |
153 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} | 153 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} |
154 | 154 |
155 virtual ~FakeRenderWidgetHostViewAura() {} | 155 virtual ~FakeRenderWidgetHostViewAura() {} |
156 | 156 |
157 virtual bool ShouldCreateResizeLock() OVERRIDE { | 157 virtual bool ShouldCreateResizeLock() OVERRIDE { |
158 gfx::Size desired_size = window()->bounds().size(); | 158 gfx::Size desired_size = window()->bounds().size(); |
159 return desired_size != current_frame_size(); | 159 return desired_size != current_frame_size_in_dip(); |
160 } | 160 } |
161 | 161 |
162 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) | 162 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) |
163 OVERRIDE { | 163 OVERRIDE { |
164 gfx::Size desired_size = window()->bounds().size(); | 164 gfx::Size desired_size = window()->bounds().size(); |
165 return scoped_ptr<ResizeLock>( | 165 return scoped_ptr<ResizeLock>( |
166 new FakeResizeLock(desired_size, defer_compositor_lock)); | 166 new FakeResizeLock(desired_size, defer_compositor_lock)); |
167 } | 167 } |
168 | 168 |
169 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) | 169 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 view_->UpdateCursorIfOverSelf(); | 836 view_->UpdateCursorIfOverSelf(); |
837 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); | 837 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); |
838 | 838 |
839 // Cursor is below the window. | 839 // Cursor is below the window. |
840 cursor_client.reset_calls_to_set_cursor(); | 840 cursor_client.reset_calls_to_set_cursor(); |
841 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161)); | 841 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161)); |
842 view_->UpdateCursorIfOverSelf(); | 842 view_->UpdateCursorIfOverSelf(); |
843 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); | 843 EXPECT_EQ(0, cursor_client.calls_to_set_cursor()); |
844 } | 844 } |
845 | 845 |
846 scoped_ptr<cc::CompositorFrame> MakeGLFrame(float scale_factor, | |
847 gfx::Size size, | |
848 gfx::Rect damage, | |
849 OwnedMailbox* owned_mailbox) { | |
850 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
851 frame->metadata.device_scale_factor = scale_factor; | |
852 frame->gl_frame_data.reset(new cc::GLFrameData); | |
853 DCHECK(owned_mailbox->sync_point()); | |
854 frame->gl_frame_data->sync_point = owned_mailbox->sync_point(); | |
855 memcpy(frame->gl_frame_data->mailbox.name, | |
856 owned_mailbox->mailbox().name, | |
857 sizeof(frame->gl_frame_data->mailbox.name)); | |
858 frame->gl_frame_data->size = size; | |
859 frame->gl_frame_data->sub_buffer_rect = damage; | |
860 return frame.Pass(); | |
861 } | |
862 | |
863 scoped_ptr<cc::CompositorFrame> MakeSoftwareFrame(float scale_factor, | 846 scoped_ptr<cc::CompositorFrame> MakeSoftwareFrame(float scale_factor, |
864 gfx::Size size, | 847 gfx::Size size, |
865 gfx::Rect damage) { | 848 gfx::Rect damage) { |
866 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 849 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
867 frame->metadata.device_scale_factor = scale_factor; | 850 frame->metadata.device_scale_factor = scale_factor; |
868 frame->software_frame_data.reset(new cc::SoftwareFrameData); | 851 frame->software_frame_data.reset(new cc::SoftwareFrameData); |
869 frame->software_frame_data->id = 1; | 852 frame->software_frame_data->id = 1; |
870 frame->software_frame_data->size = size; | 853 frame->software_frame_data->size = size; |
871 frame->software_frame_data->damage_rect = damage; | 854 frame->software_frame_data->damage_rect = damage; |
872 base::SharedMemory shm; | 855 base::SharedMemory shm; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 // 0 is CreatingNew message. | 895 // 0 is CreatingNew message. |
913 const IPC::Message* msg = sink_->GetMessageAt(0); | 896 const IPC::Message* msg = sink_->GetMessageAt(0); |
914 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 897 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
915 ViewMsg_Resize::Param params; | 898 ViewMsg_Resize::Param params; |
916 ViewMsg_Resize::Read(msg, ¶ms); | 899 ViewMsg_Resize::Read(msg, ¶ms); |
917 EXPECT_EQ("0,0 800x600", | 900 EXPECT_EQ("0,0 800x600", |
918 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 901 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
919 EXPECT_EQ("800x600", params.a.new_size.ToString()); | 902 EXPECT_EQ("800x600", params.a.new_size.ToString()); |
920 // Resizes are blocked until we swapped a frame of the correct size, and | 903 // Resizes are blocked until we swapped a frame of the correct size, and |
921 // we've committed it. | 904 // we've committed it. |
922 view_->OnSwapCompositorFrame(0, | 905 view_->OnSwapCompositorFrame( |
923 MakeGLFrame(1.f, | 906 0, |
924 params.a.new_size, | 907 MakeDelegatedFrame( |
925 gfx::Rect(params.a.new_size), | 908 1.f, params.a.new_size, gfx::Rect(params.a.new_size))); |
926 owned_mailbox.get())); | |
927 ui::DrawWaiterForTest::WaitForCommit( | 909 ui::DrawWaiterForTest::WaitForCommit( |
928 root_window->GetHost()->compositor()); | 910 root_window->GetHost()->compositor()); |
929 } | 911 } |
930 | 912 |
931 widget_host_->ResetSizeAndRepaintPendingFlags(); | 913 widget_host_->ResetSizeAndRepaintPendingFlags(); |
932 sink_->ClearMessages(); | 914 sink_->ClearMessages(); |
933 | 915 |
934 // Make sure the corrent screen size is set along in the resize | 916 // Make sure the corrent screen size is set along in the resize |
935 // request when the screen size has changed. | 917 // request when the screen size has changed. |
936 aura_test_helper_->test_screen()->SetUIScale(0.5); | 918 aura_test_helper_->test_screen()->SetUIScale(0.5); |
937 EXPECT_EQ(1u, sink_->message_count()); | 919 EXPECT_EQ(1u, sink_->message_count()); |
938 { | 920 { |
939 const IPC::Message* msg = sink_->GetMessageAt(0); | 921 const IPC::Message* msg = sink_->GetMessageAt(0); |
940 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 922 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
941 ViewMsg_Resize::Param params; | 923 ViewMsg_Resize::Param params; |
942 ViewMsg_Resize::Read(msg, ¶ms); | 924 ViewMsg_Resize::Read(msg, ¶ms); |
943 EXPECT_EQ("0,0 1600x1200", | 925 EXPECT_EQ("0,0 1600x1200", |
944 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 926 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
945 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); | 927 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); |
946 view_->OnSwapCompositorFrame(0, | 928 view_->OnSwapCompositorFrame( |
947 MakeGLFrame(1.f, | 929 0, |
948 params.a.new_size, | 930 MakeDelegatedFrame( |
949 gfx::Rect(params.a.new_size), | 931 1.f, params.a.new_size, gfx::Rect(params.a.new_size))); |
950 owned_mailbox.get())); | |
951 ui::DrawWaiterForTest::WaitForCommit( | 932 ui::DrawWaiterForTest::WaitForCommit( |
952 root_window->GetHost()->compositor()); | 933 root_window->GetHost()->compositor()); |
953 } | 934 } |
954 } | 935 } |
955 | 936 |
956 // Swapping a frame should notify the window. | 937 // Swapping a frame should notify the window. |
957 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { | 938 TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) { |
958 gfx::Size view_size(100, 100); | 939 gfx::Size view_size(100, 100); |
959 gfx::Rect view_rect(view_size); | 940 gfx::Rect view_rect(view_size); |
960 | 941 |
961 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 942 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
962 scoped_refptr<OwnedMailbox> owned_mailbox = new OwnedMailbox(gl_helper); | 943 scoped_refptr<OwnedMailbox> owned_mailbox = new OwnedMailbox(gl_helper); |
963 gl_helper->ResizeTexture(owned_mailbox->texture_id(), gfx::Size(400, 400)); | 944 gl_helper->ResizeTexture(owned_mailbox->texture_id(), gfx::Size(400, 400)); |
964 owned_mailbox->UpdateSyncPoint(gl_helper->InsertSyncPoint()); | 945 owned_mailbox->UpdateSyncPoint(gl_helper->InsertSyncPoint()); |
965 | 946 |
966 view_->InitAsChild(NULL); | 947 view_->InitAsChild(NULL); |
967 aura::client::ParentWindowWithContext( | 948 aura::client::ParentWindowWithContext( |
968 view_->GetNativeView(), | 949 view_->GetNativeView(), |
969 parent_view_->GetNativeView()->GetRootWindow(), | 950 parent_view_->GetNativeView()->GetRootWindow(), |
970 gfx::Rect()); | 951 gfx::Rect()); |
971 view_->SetSize(view_size); | 952 view_->SetSize(view_size); |
972 view_->WasShown(); | 953 view_->WasShown(); |
973 | 954 |
974 MockWindowObserver observer; | 955 MockWindowObserver observer; |
975 view_->window_->AddObserver(&observer); | 956 view_->window_->AddObserver(&observer); |
976 | 957 |
977 // Swap a frame through the GPU path. | |
978 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
979 params.surface_id = widget_host_->surface_id(); | |
980 params.route_id = widget_host_->GetRoutingID(); | |
981 memcpy(params.mailbox.name, | |
982 owned_mailbox->mailbox().name, | |
983 sizeof(params.mailbox.name)); | |
984 params.size = view_size; | |
985 params.scale_factor = 1.f; | |
986 | |
987 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
988 view_->AcceleratedSurfaceBuffersSwapped(params, 0); | |
989 testing::Mock::VerifyAndClearExpectations(&observer); | |
990 | |
991 // DSF = 2 | |
992 params.size = gfx::Size(200, 200); | |
993 params.scale_factor = 2.f; | |
994 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
995 view_->AcceleratedSurfaceBuffersSwapped(params, 0); | |
996 testing::Mock::VerifyAndClearExpectations(&observer); | |
997 | |
998 // Partial frames though GPU path | |
999 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params post_params; | |
1000 post_params.surface_id = widget_host_->surface_id(); | |
1001 post_params.route_id = widget_host_->GetRoutingID(); | |
1002 memcpy(post_params.mailbox.name, | |
1003 owned_mailbox->mailbox().name, | |
1004 sizeof(params.mailbox.name)); | |
1005 post_params.surface_size = gfx::Size(200, 200); | |
1006 post_params.surface_scale_factor = 2.f; | |
1007 post_params.x = 40; | |
1008 post_params.y = 40; | |
1009 post_params.width = 80; | |
1010 post_params.height = 80; | |
1011 // rect from params is upside down, and is inflated in RWHVA, just because. | |
1012 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | |
1013 gfx::Rect(19, 39, 42, 42))); | |
1014 view_->AcceleratedSurfacePostSubBuffer(post_params, 0); | |
1015 testing::Mock::VerifyAndClearExpectations(&observer); | |
1016 | |
1017 // Composite-to-mailbox path | |
1018 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | |
1019 view_->OnSwapCompositorFrame( | |
1020 0, MakeGLFrame(1.f, view_size, view_rect, owned_mailbox.get())); | |
1021 testing::Mock::VerifyAndClearExpectations(&observer); | |
1022 | |
1023 // rect from GL frame is upside down, and is inflated in RWHVA, just because. | |
1024 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | |
1025 gfx::Rect(4, 89, 7, 7))); | |
1026 view_->OnSwapCompositorFrame( | |
1027 0, | |
1028 MakeGLFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5), owned_mailbox.get())); | |
1029 testing::Mock::VerifyAndClearExpectations(&observer); | |
1030 | |
1031 // Software path | 958 // Software path |
1032 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); | 959 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); |
1033 view_->OnSwapCompositorFrame(0, MakeSoftwareFrame(1.f, view_size, view_rect)); | 960 view_->OnSwapCompositorFrame(0, MakeSoftwareFrame(1.f, view_size, view_rect)); |
1034 testing::Mock::VerifyAndClearExpectations(&observer); | 961 testing::Mock::VerifyAndClearExpectations(&observer); |
1035 | 962 |
1036 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | 963 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, |
1037 gfx::Rect(5, 5, 5, 5))); | 964 gfx::Rect(5, 5, 5, 5))); |
1038 view_->OnSwapCompositorFrame( | 965 view_->OnSwapCompositorFrame( |
1039 0, MakeSoftwareFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); | 966 0, MakeSoftwareFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); |
1040 testing::Mock::VerifyAndClearExpectations(&observer); | 967 testing::Mock::VerifyAndClearExpectations(&observer); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1379 |
1453 // Because the copy request callback may be holding state within it, that | 1380 // Because the copy request callback may be holding state within it, that |
1454 // state must handle the RWHVA and ImageTransportFactory going away before the | 1381 // state must handle the RWHVA and ImageTransportFactory going away before the |
1455 // callback is called. This test passes if it does not crash as a result of | 1382 // callback is called. This test passes if it does not crash as a result of |
1456 // these things being destroyed. | 1383 // these things being destroyed. |
1457 EXPECT_EQ(2, callback_count_); | 1384 EXPECT_EQ(2, callback_count_); |
1458 EXPECT_FALSE(result_); | 1385 EXPECT_FALSE(result_); |
1459 } | 1386 } |
1460 | 1387 |
1461 } // namespace content | 1388 } // namespace content |
OLD | NEW |