Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / renderer_frame_manager.cc
index 15c9814..0a93e29 100644 (file)
@@ -7,7 +7,9 @@
 #include <algorithm>
 
 #include "base/logging.h"
+#include "base/memory/shared_memory.h"
 #include "base/sys_info.h"
+#include "content/common/host_shared_bitmap_manager.h"
 
 namespace content {
 
@@ -66,14 +68,26 @@ RendererFrameManager::RendererFrameManager() {
 #else
       std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256));
 #endif
+  max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f;
 }
 
 RendererFrameManager::~RendererFrameManager() {}
 
 void RendererFrameManager::CullUnlockedFrames() {
+  uint32 saved_frame_limit = max_number_of_saved_frames();
+
+  if (unlocked_frames_.size() + locked_frames_.size() > 0) {
+    float handles_per_frame =
+        HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f /
+        (unlocked_frames_.size() + locked_frames_.size());
+
+    saved_frame_limit = std::max(
+        1,
+        static_cast<int>(std::min(static_cast<float>(saved_frame_limit),
+                                  max_handles_ / handles_per_frame)));
+  }
   while (!unlocked_frames_.empty() &&
-         unlocked_frames_.size() + locked_frames_.size() >
-             max_number_of_saved_frames()) {
+         unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) {
     size_t old_size = unlocked_frames_.size();
     // Should remove self from list.
     unlocked_frames_.back()->EvictCurrentFrame();