OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_SURFACE_TRANSPORT_DIB_H_ | 5 #ifndef UI_SURFACE_TRANSPORT_DIB_H_ |
6 #define UI_SURFACE_TRANSPORT_DIB_H_ | 6 #define UI_SURFACE_TRANSPORT_DIB_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ui/surface/surface_export.h" | 9 #include "ui/surface/surface_export.h" |
10 | 10 |
11 #if !defined(TOOLKIT_GTK) | 11 #if !defined(TOOLKIT_GTK) |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #endif | 13 #endif |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 #include <windows.h> | 16 #include <windows.h> |
17 #elif defined(TOOLKIT_GTK) || \ | 17 #elif defined(TOOLKIT_GTK) |
18 (defined(OS_LINUX) && defined(USE_AURA) && defined(USE_X11)) | |
19 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
20 #endif | 19 #endif |
21 | 20 |
22 class SkCanvas; | 21 class SkCanvas; |
23 | 22 |
24 // ----------------------------------------------------------------------------- | 23 // ----------------------------------------------------------------------------- |
25 // A TransportDIB is a block of memory that is used to transport pixels | 24 // A TransportDIB is a block of memory that is used to transport pixels |
26 // between processes: from the renderer process to the browser, and | 25 // between processes: from the renderer process to the browser, and |
27 // between renderer and plugin processes. | 26 // between renderer and plugin processes. |
28 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Returns a default, invalid handle, that is meant to indicate a missing | 73 // Returns a default, invalid handle, that is meant to indicate a missing |
75 // Transport DIB. | 74 // Transport DIB. |
76 static Handle DefaultHandleValue() { return NULL; } | 75 static Handle DefaultHandleValue() { return NULL; } |
77 | 76 |
78 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE | 77 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE |
79 // ACTUALLY USED AS A REAL HANDLE. | 78 // ACTUALLY USED AS A REAL HANDLE. |
80 static Handle GetFakeHandleForTest() { | 79 static Handle GetFakeHandleForTest() { |
81 static int fake_handle = 10; | 80 static int fake_handle = 10; |
82 return reinterpret_cast<Handle>(fake_handle++); | 81 return reinterpret_cast<Handle>(fake_handle++); |
83 } | 82 } |
84 #elif defined(TOOLKIT_GTK) || \ | 83 #elif defined(TOOLKIT_GTK) |
85 (defined(OS_LINUX) && defined(USE_AURA) && defined(USE_X11)) | |
86 typedef int Handle; // These two ints are SysV IPC shared memory keys | 84 typedef int Handle; // These two ints are SysV IPC shared memory keys |
87 struct Id { | 85 struct Id { |
88 // Ensure that default initialized Ids are invalid. | 86 // Ensure that default initialized Ids are invalid. |
89 Id() : shmkey(-1) { | 87 Id() : shmkey(-1) { |
90 } | 88 } |
91 | 89 |
92 bool operator<(const Id& other) const { | 90 bool operator<(const Id& other) const { |
93 return shmkey < other.shmkey; | 91 return shmkey < other.shmkey; |
94 } | 92 } |
95 | 93 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 size_t size() const { return size_; } | 179 size_t size() const { return size_; } |
182 | 180 |
183 // Return the identifier which can be used to refer to this shared memory | 181 // Return the identifier which can be used to refer to this shared memory |
184 // on the wire. | 182 // on the wire. |
185 Id id() const; | 183 Id id() const; |
186 | 184 |
187 // Return a handle to the underlying shared memory. This can be sent over the | 185 // Return a handle to the underlying shared memory. This can be sent over the |
188 // wire to give this transport DIB to another process. | 186 // wire to give this transport DIB to another process. |
189 Handle handle() const; | 187 Handle handle() const; |
190 | 188 |
191 #if defined(TOOLKIT_GTK) || \ | 189 #if defined(TOOLKIT_GTK) |
192 (defined(OS_LINUX) && defined(USE_AURA) && defined(USE_X11)) | |
193 // Map the shared memory into the X server and return an id for the shared | 190 // Map the shared memory into the X server and return an id for the shared |
194 // segment. | 191 // segment. |
195 XID MapToX(Display* connection); | 192 XID MapToX(Display* connection); |
196 | 193 |
197 void IncreaseInFlightCounter() { inflight_counter_++; } | 194 void IncreaseInFlightCounter() { inflight_counter_++; } |
198 // Decreases the inflight counter, and deletes the transport DIB if it is | 195 // Decreases the inflight counter, and deletes the transport DIB if it is |
199 // detached. | 196 // detached. |
200 void DecreaseInFlightCounter(); | 197 void DecreaseInFlightCounter(); |
201 | 198 |
202 // Deletes this transport DIB and detaches the shared memory once the | 199 // Deletes this transport DIB and detaches the shared memory once the |
203 // |inflight_counter_| is zero. | 200 // |inflight_counter_| is zero. |
204 void Detach(); | 201 void Detach(); |
205 #endif | 202 #endif |
206 | 203 |
207 private: | 204 private: |
208 TransportDIB(); | 205 TransportDIB(); |
209 | 206 |
210 // Verifies that the dib can hold a canvas of the requested dimensions. | 207 // Verifies that the dib can hold a canvas of the requested dimensions. |
211 bool VerifyCanvasSize(int w, int h); | 208 bool VerifyCanvasSize(int w, int h); |
212 | 209 |
213 #if defined(TOOLKIT_GTK) || \ | 210 #if defined(TOOLKIT_GTK) |
214 (defined(OS_LINUX) && defined(USE_AURA) && defined(USE_X11)) | |
215 Id key_; // SysV shared memory id | 211 Id key_; // SysV shared memory id |
216 void* address_; // mapped address | 212 void* address_; // mapped address |
217 XSharedMemoryId x_shm_; // X id for the shared segment | 213 XSharedMemoryId x_shm_; // X id for the shared segment |
218 Display* display_; // connection to the X server | 214 Display* display_; // connection to the X server |
219 size_t inflight_counter_; // How many requests to the X server are in flight | 215 size_t inflight_counter_; // How many requests to the X server are in flight |
220 bool detached_; // If true, delete the transport DIB when it is idle | 216 bool detached_; // If true, delete the transport DIB when it is idle |
221 #else | 217 #else |
222 explicit TransportDIB(base::SharedMemoryHandle dib); | 218 explicit TransportDIB(base::SharedMemoryHandle dib); |
223 base::SharedMemory shared_memory_; | 219 base::SharedMemory shared_memory_; |
224 uint32 sequence_num_; | 220 uint32 sequence_num_; |
225 #endif | 221 #endif |
226 size_t size_; // length, in bytes | 222 size_t size_; // length, in bytes |
227 | 223 |
228 DISALLOW_COPY_AND_ASSIGN(TransportDIB); | 224 DISALLOW_COPY_AND_ASSIGN(TransportDIB); |
229 }; | 225 }; |
230 | 226 |
231 #endif // UI_SURFACE_TRANSPORT_DIB_H_ | 227 #endif // UI_SURFACE_TRANSPORT_DIB_H_ |
OLD | NEW |