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) || (defined(OS_LINUX) && defined(USE_AURA)) | 17 #elif defined(TOOLKIT_GTK) |
18 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
19 #endif | 19 #endif |
20 | 20 |
21 class SkCanvas; | 21 class SkCanvas; |
22 | 22 |
23 // ----------------------------------------------------------------------------- | 23 // ----------------------------------------------------------------------------- |
24 // 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 |
25 // between processes: from the renderer process to the browser, and | 25 // between processes: from the renderer process to the browser, and |
26 // between renderer and plugin processes. | 26 // between renderer and plugin processes. |
27 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // 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 |
74 // Transport DIB. | 74 // Transport DIB. |
75 static Handle DefaultHandleValue() { return NULL; } | 75 static Handle DefaultHandleValue() { return NULL; } |
76 | 76 |
77 // 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 |
78 // ACTUALLY USED AS A REAL HANDLE. | 78 // ACTUALLY USED AS A REAL HANDLE. |
79 static Handle GetFakeHandleForTest() { | 79 static Handle GetFakeHandleForTest() { |
80 static int fake_handle = 10; | 80 static int fake_handle = 10; |
81 return reinterpret_cast<Handle>(fake_handle++); | 81 return reinterpret_cast<Handle>(fake_handle++); |
82 } | 82 } |
83 #elif defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA)) | 83 #elif defined(TOOLKIT_GTK) |
84 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 |
85 struct Id { | 85 struct Id { |
86 // Ensure that default initialized Ids are invalid. | 86 // Ensure that default initialized Ids are invalid. |
87 Id() : shmkey(-1) { | 87 Id() : shmkey(-1) { |
88 } | 88 } |
89 | 89 |
90 bool operator<(const Id& other) const { | 90 bool operator<(const Id& other) const { |
91 return shmkey < other.shmkey; | 91 return shmkey < other.shmkey; |
92 } | 92 } |
93 | 93 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 size_t size() const { return size_; } | 179 size_t size() const { return size_; } |
180 | 180 |
181 // 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 |
182 // on the wire. | 182 // on the wire. |
183 Id id() const; | 183 Id id() const; |
184 | 184 |
185 // 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 |
186 // wire to give this transport DIB to another process. | 186 // wire to give this transport DIB to another process. |
187 Handle handle() const; | 187 Handle handle() const; |
188 | 188 |
189 #if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA)) | 189 #if defined(TOOLKIT_GTK) |
190 // 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 |
191 // segment. | 191 // segment. |
192 XID MapToX(Display* connection); | 192 XID MapToX(Display* connection); |
193 | 193 |
194 void IncreaseInFlightCounter() { inflight_counter_++; } | 194 void IncreaseInFlightCounter() { inflight_counter_++; } |
195 // 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 |
196 // detached. | 196 // detached. |
197 void DecreaseInFlightCounter(); | 197 void DecreaseInFlightCounter(); |
198 | 198 |
199 // Deletes this transport DIB and detaches the shared memory once the | 199 // Deletes this transport DIB and detaches the shared memory once the |
200 // |inflight_counter_| is zero. | 200 // |inflight_counter_| is zero. |
201 void Detach(); | 201 void Detach(); |
202 #endif | 202 #endif |
203 | 203 |
204 private: | 204 private: |
205 TransportDIB(); | 205 TransportDIB(); |
206 | 206 |
207 // 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. |
208 bool VerifyCanvasSize(int w, int h); | 208 bool VerifyCanvasSize(int w, int h); |
209 | 209 |
210 #if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA)) | 210 #if defined(TOOLKIT_GTK) |
211 Id key_; // SysV shared memory id | 211 Id key_; // SysV shared memory id |
212 void* address_; // mapped address | 212 void* address_; // mapped address |
213 XSharedMemoryId x_shm_; // X id for the shared segment | 213 XSharedMemoryId x_shm_; // X id for the shared segment |
214 Display* display_; // connection to the X server | 214 Display* display_; // connection to the X server |
215 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 |
216 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 |
217 #else | 217 #else |
218 explicit TransportDIB(base::SharedMemoryHandle dib); | 218 explicit TransportDIB(base::SharedMemoryHandle dib); |
219 base::SharedMemory shared_memory_; | 219 base::SharedMemory shared_memory_; |
220 uint32 sequence_num_; | 220 uint32 sequence_num_; |
221 #endif | 221 #endif |
222 size_t size_; // length, in bytes | 222 size_t size_; // length, in bytes |
223 | 223 |
224 DISALLOW_COPY_AND_ASSIGN(TransportDIB); | 224 DISALLOW_COPY_AND_ASSIGN(TransportDIB); |
225 }; | 225 }; |
226 | 226 |
227 #endif // UI_SURFACE_TRANSPORT_DIB_H_ | 227 #endif // UI_SURFACE_TRANSPORT_DIB_H_ |
OLD | NEW |