summaryrefslogtreecommitdiffstats
path: root/base/shared_memory.h
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-20 02:00:04 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-20 02:00:04 +0000
commite68e62fa169c45bd779bfe890aa4fcdaa24d267d (patch)
treeefdb18adec880e7f780d8cde4e12893d3a20234f /base/shared_memory.h
parent7fe07d0726bad485fa40150aa9f7cecb1318217e (diff)
downloadchromium_src-e68e62fa169c45bd779bfe890aa4fcdaa24d267d.zip
chromium_src-e68e62fa169c45bd779bfe890aa4fcdaa24d267d.tar.gz
chromium_src-e68e62fa169c45bd779bfe890aa4fcdaa24d267d.tar.bz2
Bitmap transport
This patch reworks bitmap transport on all platforms. Linux and Mac are switched from serialising bitmaps over the IPC channel to using shared memory. All platforms gain a shared memory mapping cache on the host side. The concept of a TransportDIB (device independent bitmap) is added to encapsulate most of the platform specifics. On Linux, we use SysV shared memory. This is because X shared pixmaps, which predate POSIX SHM, can only use SysV. By using SysV between renderer and browser, we open up the possibility to map the shared memory directly from the renderer to the X server. On Mac, we use POSIX shared memory. However, since this needs filesystem access and the Mac renderer is sandboxed from the filesystem, we add two new messages from renderer -> browser: The first, AllocTransportDIB, synchronously creates a transport DIB in the browser and passes a handle back to the renderer. The second, FreeTransportDIB, asynchronously, notifies the browser that it may close its handle to the shared memory region. On Mac, the shared memory regions are identified by their inode numbers on the wire. This means that the browser must keep handles open to all the allocated shared memory regions (since an inode number is insufficient to map the region). The alternative design is that the renderer passes the file descriptor with each paint operation. Since passing file descriptors is special case in the code, I felt that it would be best to minimise their use. Creating and freeing transport DIBs are relatively rare operations relative to paints and scrolls. On Windows, most of the code remains the same, except that Windows now uses the mapping cache added in this patch. This allows the browser to maintain a shared memory mapping for a transport DIB over several paints. Previously it mapped and unmapped for every operation, causing lots of TLB and VM churn. Review URL: http://codereview.chromium.org/21485 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory.h')
-rw-r--r--base/shared_memory.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h
index b44367a..744b348 100644
--- a/base/shared_memory.h
+++ b/base/shared_memory.h
@@ -8,6 +8,7 @@
#include "build/build_config.h"
#if defined(OS_POSIX)
+#include <sys/types.h>
#include <semaphore.h>
#include "base/file_descriptor_posix.h"
#endif
@@ -24,7 +25,10 @@ namespace base {
typedef HANDLE SharedMemoryHandle;
typedef HANDLE SharedMemoryLock;
#elif defined(OS_POSIX)
+// A SharedMemoryId is sufficient to identify a given shared memory segment on a
+// system, but insufficient to map it.
typedef FileDescriptor SharedMemoryHandle;
+typedef ino_t SharedMemoryId;
// On POSIX, the lock is implemented as a lockf() on the mapped file,
// so no additional member (or definition of SharedMemoryLock) is
// needed.
@@ -99,6 +103,14 @@ class SharedMemory {
// identifier is not portable.
SharedMemoryHandle handle() const;
+#if defined(OS_POSIX)
+ // Return a unique identifier for this shared memory segment. Inode numbers
+ // are technically only unique to a single filesystem. However, we always
+ // allocate shared memory backing files from the same directory, so will end
+ // up on the same filesystem.
+ SharedMemoryId id() const { return inode_; }
+#endif
+
// Closes the open shared memory segment.
// It is safe to call Close repeatedly.
void Close();
@@ -153,9 +165,10 @@ class SharedMemory {
std::wstring name_;
#if defined(OS_WIN)
- HANDLE mapped_file_;
+ HANDLE mapped_file_;
#elif defined(OS_POSIX)
- int mapped_file_;
+ int mapped_file_;
+ ino_t inode_;
#endif
void* memory_;
bool read_only_;