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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "cc/output/compositor_frame.h" | 12 #include "cc/output/compositor_frame.h" |
13 #include "cc/output/compositor_frame_metadata.h" | 13 #include "cc/output/compositor_frame_metadata.h" |
14 #include "cc/output/copy_output_request.h" | 14 #include "cc/output/copy_output_request.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/compositor/resize_lock.h" | 16 #include "content/browser/compositor/resize_lock.h" |
17 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 17 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
18 #include "content/browser/renderer_host/render_widget_host_impl.h" | 18 #include "content/browser/renderer_host/render_widget_host_impl.h" |
19 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/common/host_shared_bitmap_manager.h" |
20 #include "content/common/input_messages.h" | 21 #include "content/common/input_messages.h" |
21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
22 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 23 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
23 #include "content/public/browser/render_widget_host_view.h" | 24 #include "content/public/browser/render_widget_host_view.h" |
24 #include "content/public/test/mock_render_process_host.h" | 25 #include "content/public/test/mock_render_process_host.h" |
25 #include "content/public/test/test_browser_context.h" | 26 #include "content/public/test/test_browser_context.h" |
26 #include "ipc/ipc_test_sink.h" | 27 #include "ipc/ipc_test_sink.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 view_->window_->RemoveObserver(&observer); | 1059 view_->window_->RemoveObserver(&observer); |
1059 } | 1060 } |
1060 | 1061 |
1061 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { | 1062 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) { |
1062 size_t max_renderer_frames = | 1063 size_t max_renderer_frames = |
1063 RendererFrameManager::GetInstance()->max_number_of_saved_frames(); | 1064 RendererFrameManager::GetInstance()->max_number_of_saved_frames(); |
1064 ASSERT_LE(2u, max_renderer_frames); | 1065 ASSERT_LE(2u, max_renderer_frames); |
1065 size_t renderer_count = max_renderer_frames + 1; | 1066 size_t renderer_count = max_renderer_frames + 1; |
1066 gfx::Rect view_rect(100, 100); | 1067 gfx::Rect view_rect(100, 100); |
1067 gfx::Size frame_size = view_rect.size(); | 1068 gfx::Size frame_size = view_rect.size(); |
| 1069 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount()); |
1068 | 1070 |
1069 scoped_ptr<RenderWidgetHostImpl * []> hosts( | 1071 scoped_ptr<RenderWidgetHostImpl * []> hosts( |
1070 new RenderWidgetHostImpl* [renderer_count]); | 1072 new RenderWidgetHostImpl* [renderer_count]); |
1071 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( | 1073 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( |
1072 new FakeRenderWidgetHostViewAura* [renderer_count]); | 1074 new FakeRenderWidgetHostViewAura* [renderer_count]); |
1073 | 1075 |
1074 // Create a bunch of renderers. | 1076 // Create a bunch of renderers. |
1075 for (size_t i = 0; i < renderer_count; ++i) { | 1077 for (size_t i = 0; i < renderer_count; ++i) { |
1076 hosts[i] = new RenderWidgetHostImpl( | 1078 hosts[i] = new RenderWidgetHostImpl( |
1077 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 1079 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 views[0]->WasShown(); | 1146 views[0]->WasShown(); |
1145 views[0]->OnSwapCompositorFrame( | 1147 views[0]->OnSwapCompositorFrame( |
1146 1, MakeDelegatedFrame(1.f, frame_size, view_rect)); | 1148 1, MakeDelegatedFrame(1.f, frame_size, view_rect)); |
1147 for (size_t i = 0; i < renderer_count; ++i) | 1149 for (size_t i = 0; i < renderer_count; ++i) |
1148 EXPECT_TRUE(views[i]->frame_provider_); | 1150 EXPECT_TRUE(views[i]->frame_provider_); |
1149 | 1151 |
1150 // Make [0] hidden, it should evict its frame. | 1152 // Make [0] hidden, it should evict its frame. |
1151 views[0]->WasHidden(); | 1153 views[0]->WasHidden(); |
1152 EXPECT_FALSE(views[0]->frame_provider_); | 1154 EXPECT_FALSE(views[0]->frame_provider_); |
1153 | 1155 |
| 1156 for (size_t i = 0; i < renderer_count - 1; ++i) |
| 1157 views[i]->WasHidden(); |
| 1158 |
| 1159 // Allocate enough bitmaps so that two frames (proportionally) would be |
| 1160 // enough hit the handle limit. |
| 1161 int handles_per_frame = 5; |
| 1162 RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame * 2); |
| 1163 |
| 1164 for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) { |
| 1165 HostSharedBitmapManager::current()->ChildAllocatedSharedBitmap( |
| 1166 1, |
| 1167 base::SharedMemory::NULLHandle(), |
| 1168 base::GetCurrentProcessHandle(), |
| 1169 cc::SharedBitmap::GenerateId()); |
| 1170 } |
| 1171 |
| 1172 // Hiding this last bitmap should evict all but two frames. |
| 1173 views[renderer_count - 1]->WasHidden(); |
| 1174 for (size_t i = 0; i < renderer_count; ++i) { |
| 1175 if (i + 2 < renderer_count) |
| 1176 EXPECT_FALSE(views[i]->frame_provider_); |
| 1177 else |
| 1178 EXPECT_TRUE(views[i]->frame_provider_); |
| 1179 } |
| 1180 HostSharedBitmapManager::current()->ProcessRemoved( |
| 1181 base::GetCurrentProcessHandle()); |
| 1182 |
1154 for (size_t i = 0; i < renderer_count; ++i) { | 1183 for (size_t i = 0; i < renderer_count; ++i) { |
1155 views[i]->Destroy(); | 1184 views[i]->Destroy(); |
1156 delete hosts[i]; | 1185 delete hosts[i]; |
1157 } | 1186 } |
1158 } | 1187 } |
1159 | 1188 |
1160 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { | 1189 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) { |
1161 size_t max_renderer_frames = | 1190 size_t max_renderer_frames = |
1162 RendererFrameManager::GetInstance()->max_number_of_saved_frames(); | 1191 RendererFrameManager::GetInstance()->max_number_of_saved_frames(); |
1163 ASSERT_LE(2u, max_renderer_frames); | 1192 ASSERT_LE(2u, max_renderer_frames); |
1164 size_t renderer_count = max_renderer_frames + 1; | 1193 size_t renderer_count = max_renderer_frames + 1; |
1165 gfx::Rect view_rect(100, 100); | 1194 gfx::Rect view_rect(100, 100); |
1166 gfx::Size frame_size = view_rect.size(); | 1195 gfx::Size frame_size = view_rect.size(); |
| 1196 DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount()); |
1167 | 1197 |
1168 scoped_ptr<RenderWidgetHostImpl * []> hosts( | 1198 scoped_ptr<RenderWidgetHostImpl * []> hosts( |
1169 new RenderWidgetHostImpl* [renderer_count]); | 1199 new RenderWidgetHostImpl* [renderer_count]); |
1170 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( | 1200 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( |
1171 new FakeRenderWidgetHostViewAura* [renderer_count]); | 1201 new FakeRenderWidgetHostViewAura* [renderer_count]); |
1172 | 1202 |
1173 // Create a bunch of renderers. | 1203 // Create a bunch of renderers. |
1174 for (size_t i = 0; i < renderer_count; ++i) { | 1204 for (size_t i = 0; i < renderer_count; ++i) { |
1175 hosts[i] = new RenderWidgetHostImpl( | 1205 hosts[i] = new RenderWidgetHostImpl( |
1176 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 1206 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 | 1368 |
1339 // Because the copy request callback may be holding state within it, that | 1369 // Because the copy request callback may be holding state within it, that |
1340 // state must handle the RWHVA and ImageTransportFactory going away before the | 1370 // state must handle the RWHVA and ImageTransportFactory going away before the |
1341 // callback is called. This test passes if it does not crash as a result of | 1371 // callback is called. This test passes if it does not crash as a result of |
1342 // these things being destroyed. | 1372 // these things being destroyed. |
1343 EXPECT_EQ(2, callback_count_); | 1373 EXPECT_EQ(2, callback_count_); |
1344 EXPECT_FALSE(result_); | 1374 EXPECT_FALSE(result_); |
1345 } | 1375 } |
1346 | 1376 |
1347 } // namespace content | 1377 } // namespace content |
OLD | NEW |