OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer_frame_manager.h" | 5 #include "content/browser/renderer_host/renderer_frame_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | |
10 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
12 #include "content/common/host_shared_bitmap_manager.h" | |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 RendererFrameManager* RendererFrameManager::GetInstance() { | 16 RendererFrameManager* RendererFrameManager::GetInstance() { |
15 return Singleton<RendererFrameManager>::get(); | 17 return Singleton<RendererFrameManager>::get(); |
16 } | 18 } |
17 | 19 |
18 void RendererFrameManager::AddFrame(RendererFrameManagerClient* frame, | 20 void RendererFrameManager::AddFrame(RendererFrameManagerClient* frame, |
19 bool locked) { | 21 bool locked) { |
20 RemoveFrame(frame); | 22 RemoveFrame(frame); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 #if defined(OS_ANDROID) | 66 #if defined(OS_ANDROID) |
65 1; | 67 1; |
66 #else | 68 #else |
67 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); | 69 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); |
68 #endif | 70 #endif |
69 } | 71 } |
70 | 72 |
71 RendererFrameManager::~RendererFrameManager() {} | 73 RendererFrameManager::~RendererFrameManager() {} |
72 | 74 |
73 void RendererFrameManager::CullUnlockedFrames() { | 75 void RendererFrameManager::CullUnlockedFrames() { |
76 uint32 saved_frame_limit = max_number_of_saved_frames(); | |
77 | |
78 if (saved_frame_limit > 2) { | |
79 // Reduce the number of saved frames to attempt to limit browser to using at | |
80 // most 1/8 of the available shared memory handles. This is only a soft | |
81 // limit, and it may go over as necessary. | |
82 const float kHandleMaxFraction = 1 / 8.0f; | |
83 float memory_handle_fraction = | |
84 HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f / | |
85 base::SharedMemory::GetHandleLimit(); | |
86 float fraction_to_reduce = | |
87 std::min(1.0f, memory_handle_fraction / kHandleMaxFraction); | |
88 saved_frame_limit -= | |
89 static_cast<uint32>((saved_frame_limit - 2) * fraction_to_reduce); | |
piman
2014/04/23 00:32:02
I'm not sure I agree with this computation. If we'
| |
90 } | |
piman
2014/04/23 00:32:02
RenderWidgetHostViewAuraTest.DiscardDelegatedFrame
| |
74 while (!unlocked_frames_.empty() && | 91 while (!unlocked_frames_.empty() && |
75 unlocked_frames_.size() + locked_frames_.size() > | 92 unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) { |
76 max_number_of_saved_frames()) { | |
77 size_t old_size = unlocked_frames_.size(); | 93 size_t old_size = unlocked_frames_.size(); |
78 // Should remove self from list. | 94 // Should remove self from list. |
79 unlocked_frames_.back()->EvictCurrentFrame(); | 95 unlocked_frames_.back()->EvictCurrentFrame(); |
80 DCHECK_EQ(unlocked_frames_.size() + 1, old_size); | 96 DCHECK_EQ(unlocked_frames_.size() + 1, old_size); |
81 } | 97 } |
82 } | 98 } |
83 | 99 |
84 } // namespace content | 100 } // namespace content |
OLD | NEW |