| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <objidl.h> | 9 #include <objidl.h> |
| 10 #include <mlang.h> | 10 #include <mlang.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 28 #include "chrome/common/transport_dib.h" | 28 #include "chrome/common/transport_dib.h" |
| 29 #include "chrome/renderer/render_view.h" | 29 #include "chrome/renderer/render_view.h" |
| 30 #include "ipc/ipc_channel.h" | 30 #include "ipc/ipc_channel.h" |
| 31 #include "ipc/ipc_message_utils.h" | 31 #include "ipc/ipc_message_utils.h" |
| 32 #include "media/base/media.h" | 32 #include "media/base/media.h" |
| 33 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
| 34 | 34 |
| 35 static size_t GetMaxSharedMemorySize() { | |
| 36 static int size = 0; | |
| 37 #if defined(OS_LINUX) | |
| 38 if (size == 0) { | |
| 39 std::string contents; | |
| 40 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | |
| 41 size = strtoul(contents.c_str(), NULL, 0); | |
| 42 } | |
| 43 #endif | |
| 44 return size; | |
| 45 } | |
| 46 | |
| 47 //----------------------------------------------------------------------------- | 35 //----------------------------------------------------------------------------- |
| 48 | 36 |
| 49 RenderProcess::RenderProcess() | 37 RenderProcess::RenderProcess() |
| 50 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_( | 38 : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_( |
| 51 base::TimeDelta::FromSeconds(5), | 39 base::TimeDelta::FromSeconds(5), |
| 52 this, &RenderProcess::ClearTransportDIBCache)), | 40 this, &RenderProcess::ClearTransportDIBCache)), |
| 53 sequence_number_(0) { | 41 sequence_number_(0) { |
| 54 in_process_plugins_ = InProcessPlugins(); | 42 in_process_plugins_ = InProcessPlugins(); |
| 55 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) | 43 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) |
| 56 shared_mem_cache_[i] = NULL; | 44 shared_mem_cache_[i] = NULL; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 147 } |
| 160 | 148 |
| 161 // ----------------------------------------------------------------------------- | 149 // ----------------------------------------------------------------------------- |
| 162 | 150 |
| 163 | 151 |
| 164 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas( | 152 skia::PlatformCanvas* RenderProcess::GetDrawingCanvas( |
| 165 TransportDIB** memory, const gfx::Rect& rect) { | 153 TransportDIB** memory, const gfx::Rect& rect) { |
| 166 int width = rect.width(); | 154 int width = rect.width(); |
| 167 int height = rect.height(); | 155 int height = rect.height(); |
| 168 const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width()); | 156 const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width()); |
| 169 const size_t max_size = GetMaxSharedMemorySize(); | 157 const size_t max_size = base::SysInfo::MaxSharedMemorySize(); |
| 170 | 158 |
| 171 // If the requested size is too big, reduce the height. Ideally we might like | 159 // If the requested size is too big, reduce the height. Ideally we might like |
| 172 // to reduce the width as well to make the size reduction more "balanced", but | 160 // to reduce the width as well to make the size reduction more "balanced", but |
| 173 // it rarely comes up in practice. | 161 // it rarely comes up in practice. |
| 174 if ((max_size != 0) && (height * stride > max_size)) | 162 if ((max_size != 0) && (height * stride > max_size)) |
| 175 height = max_size / stride; | 163 height = max_size / stride; |
| 176 | 164 |
| 177 const size_t size = height * stride; | 165 const size_t size = height * stride; |
| 178 | 166 |
| 179 if (!GetTransportDIBFromCache(memory, size)) { | 167 if (!GetTransportDIBFromCache(memory, size)) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 235 } |
| 248 | 236 |
| 249 void RenderProcess::ClearTransportDIBCache() { | 237 void RenderProcess::ClearTransportDIBCache() { |
| 250 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { | 238 for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) { |
| 251 if (shared_mem_cache_[i]) { | 239 if (shared_mem_cache_[i]) { |
| 252 FreeTransportDIB(shared_mem_cache_[i]); | 240 FreeTransportDIB(shared_mem_cache_[i]); |
| 253 shared_mem_cache_[i] = NULL; | 241 shared_mem_cache_[i] = NULL; |
| 254 } | 242 } |
| 255 } | 243 } |
| 256 } | 244 } |
| OLD | NEW |