Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Side by Side Diff: chrome/common/transport_dib.h

Issue 21485: Bitmap transport (Closed)
Patch Set: Fix some mac crashes Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_COMMON_TRANSPORT_DIB_H_
6 #define CHROME_COMMON_TRANSPORT_DIB_H_
7
8 #include "base/basictypes.h"
9
10 #if defined(OS_WIN) || defined(OS_MACOSX)
11 #include "base/shared_memory.h"
12 #endif
13
14 #if defined(OS_WIN)
15 #include <windows.h>
16 #endif
17
18 // -----------------------------------------------------------------------------
19 // A TransportDIB is a block of memory that is used to transport pixels
20 // from the renderer process to the browser.
21 // -----------------------------------------------------------------------------
22 class TransportDIB {
23 public:
24 ~TransportDIB();
25
26 // Two typedefs are defined. A Handle is the type which can be sent over
27 // the wire so that the remote side can map the transport DIB. The Id typedef
28 // is sufficient to identify the transport DIB when you know that the remote
29 // side already may have it mapped.
30 #if defined(OS_WIN)
31 typedef HANDLE Handle;
32 // On Windows, the Id type includes a sequence number (epoch) to solve an ABA
33 // issue:
34 // 1) Process A creates a transport DIB with HANDLE=1 and sends to B.
35 // 2) Process B maps the transport DIB and caches 1 -> DIB.
36 // 3) Process A closes the transport DIB and creates a new one. The new DIB
37 // is also assigned HANDLE=1.
38 // 4) Process A sends the Handle to B, but B incorrectly believes that it
39 // already has it cached.
40 struct HandleAndSequenceNum {
41 HandleAndSequenceNum()
42 : handle(NULL),
43 sequence_num(0) {
44 }
45
46 HandleAndSequenceNum(HANDLE h, uint32 seq_num)
47 : handle(h),
48 sequence_num(seq_num) {
49 }
50
51 bool operator< (const HandleAndSequenceNum& other) const {
52 if (other.handle < handle)
53 return true;
54 if (other.sequence_num < sequence_num)
55 return true;
56 return false;
57 }
58
59 HANDLE handle;
60 uint32 sequence_num;
61 };
62 typedef HandleAndSequenceNum Id;
63 #elif defined(OS_MACOSX)
64 typedef base::SharedMemoryHandle Handle;
65 // On Mac, the inode number of the backing file is used as an id.
66 typedef base::SharedMemoryId Id;
67 #elif defined(OS_LINUX)
68 typedef int Handle; // These two ints are SysV IPC shared memory keys
69 typedef int Id;
70 #endif
71
72 // Create a new TransportDIB
73 // size: the minimum size, in bytes
74 // epoch: Windows only: a global counter. See comment above.
75 // returns: NULL on failure
76 static TransportDIB* Create(size_t size, uint32 sequence_num);
77
78 // Map the referenced transport DIB. Returns NULL on failure.
79 static TransportDIB* Map(Handle transport_dib);
80
81 // Return a pointer to the shared memory
82 void* memory() const;
83
84 // Return the maximum size of the shared memory. This is not the amount of
85 // data which is valid, you have to know that via other means, this is simply
86 // the maximum amount that /could/ be valid.
87 size_t size() const { return size_; }
88
89 // Return the identifier which can be used to refer to this shared memory
90 // on the wire.
91 Id id() const;
92
93 // Return a handle to the underlying shared memory. This can be sent over the
94 // wire to give this transport DIB to another process.
95 Handle handle() const;
96
97 private:
98 TransportDIB();
99 #if defined(OS_WIN) || defined(OS_MACOSX)
100 explicit TransportDIB(base::SharedMemoryHandle dib);
101 base::SharedMemory shared_memory_;
102 uint32 sequence_num_;
103 #elif defined(OS_LINUX)
104 int key_; // SysV shared memory id
105 void* address_; // mapped address
106 #endif
107 size_t size_; // length, in bytes
108 };
109
110 class MessageLoop;
111
112 #endif // CHROME_COMMON_TRANSPORT_DIB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698