| 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 "base/memory/shared_memory.h" |
| 9 #include "ui/surface/surface_export.h" | 10 #include "ui/surface/surface_export.h" |
| 10 | 11 |
| 11 #if !defined(TOOLKIT_GTK) | |
| 12 #include "base/memory/shared_memory.h" | |
| 13 #endif | |
| 14 | |
| 15 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 16 #include <windows.h> | 13 #include <windows.h> |
| 17 #elif defined(TOOLKIT_GTK) | |
| 18 #include "ui/base/x/x11_util.h" | |
| 19 #include "ui/gfx/x/x11_types.h" | |
| 20 #endif | 14 #endif |
| 21 | 15 |
| 22 class SkCanvas; | 16 class SkCanvas; |
| 23 | 17 |
| 24 // ----------------------------------------------------------------------------- | 18 // ----------------------------------------------------------------------------- |
| 25 // A TransportDIB is a block of memory that is used to transport pixels | 19 // A TransportDIB is a block of memory that is used to transport pixels |
| 26 // between processes: from the renderer process to the browser, and | 20 // between processes: from the renderer process to the browser, and |
| 27 // between renderer and plugin processes. | 21 // between renderer and plugin processes. |
| 28 // ----------------------------------------------------------------------------- | 22 // ----------------------------------------------------------------------------- |
| 29 class SURFACE_EXPORT TransportDIB { | 23 class SURFACE_EXPORT TransportDIB { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 61 } |
| 68 | 62 |
| 69 HANDLE handle; | 63 HANDLE handle; |
| 70 uint32 sequence_num; | 64 uint32 sequence_num; |
| 71 }; | 65 }; |
| 72 typedef HandleAndSequenceNum Id; | 66 typedef HandleAndSequenceNum Id; |
| 73 | 67 |
| 74 // Returns a default, invalid handle, that is meant to indicate a missing | 68 // Returns a default, invalid handle, that is meant to indicate a missing |
| 75 // Transport DIB. | 69 // Transport DIB. |
| 76 static Handle DefaultHandleValue() { return NULL; } | 70 static Handle DefaultHandleValue() { return NULL; } |
| 77 #elif defined(TOOLKIT_GTK) | |
| 78 typedef int Handle; // These two ints are SysV IPC shared memory keys | |
| 79 struct Id { | |
| 80 // Ensure that default initialized Ids are invalid. | |
| 81 Id() : shmkey(-1) { | |
| 82 } | |
| 83 | |
| 84 bool operator<(const Id& other) const { | |
| 85 return shmkey < other.shmkey; | |
| 86 } | |
| 87 | |
| 88 bool operator==(const Id& other) const { | |
| 89 return shmkey == other.shmkey; | |
| 90 } | |
| 91 | |
| 92 int shmkey; | |
| 93 }; | |
| 94 | |
| 95 // Returns a default, invalid handle, that is meant to indicate a missing | |
| 96 // Transport DIB. | |
| 97 static Handle DefaultHandleValue() { return -1; } | |
| 98 #else // OS_POSIX | 71 #else // OS_POSIX |
| 99 typedef base::SharedMemoryHandle Handle; | 72 typedef base::SharedMemoryHandle Handle; |
| 100 // On POSIX, the inode number of the backing file is used as an id. | 73 // On POSIX, the inode number of the backing file is used as an id. |
| 101 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
| 102 typedef base::SharedMemoryHandle Id; | 75 typedef base::SharedMemoryHandle Id; |
| 103 #else | 76 #else |
| 104 typedef base::SharedMemoryId Id; | 77 typedef base::SharedMemoryId Id; |
| 105 #endif | 78 #endif |
| 106 | 79 |
| 107 // Returns a default, invalid handle, that is meant to indicate a missing | 80 // Returns a default, invalid handle, that is meant to indicate a missing |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 size_t size() const { return size_; } | 132 size_t size() const { return size_; } |
| 160 | 133 |
| 161 // Return the identifier which can be used to refer to this shared memory | 134 // Return the identifier which can be used to refer to this shared memory |
| 162 // on the wire. | 135 // on the wire. |
| 163 Id id() const; | 136 Id id() const; |
| 164 | 137 |
| 165 // Return a handle to the underlying shared memory. This can be sent over the | 138 // Return a handle to the underlying shared memory. This can be sent over the |
| 166 // wire to give this transport DIB to another process. | 139 // wire to give this transport DIB to another process. |
| 167 Handle handle() const; | 140 Handle handle() const; |
| 168 | 141 |
| 169 #if defined(TOOLKIT_GTK) | |
| 170 // Map the shared memory into the X server and return an id for the shared | |
| 171 // segment. | |
| 172 XID MapToX(XDisplay* connection); | |
| 173 | |
| 174 void IncreaseInFlightCounter() { inflight_counter_++; } | |
| 175 // Decreases the inflight counter, and deletes the transport DIB if it is | |
| 176 // detached. | |
| 177 void DecreaseInFlightCounter(); | |
| 178 | |
| 179 // Deletes this transport DIB and detaches the shared memory once the | |
| 180 // |inflight_counter_| is zero. | |
| 181 void Detach(); | |
| 182 #endif | |
| 183 | |
| 184 private: | 142 private: |
| 185 TransportDIB(); | 143 TransportDIB(); |
| 186 | 144 |
| 187 // Verifies that the dib can hold a canvas of the requested dimensions. | 145 // Verifies that the dib can hold a canvas of the requested dimensions. |
| 188 bool VerifyCanvasSize(int w, int h); | 146 bool VerifyCanvasSize(int w, int h); |
| 189 | 147 |
| 190 #if defined(TOOLKIT_GTK) | |
| 191 Id key_; // SysV shared memory id | |
| 192 void* address_; // mapped address | |
| 193 XSharedMemoryId x_shm_; // X id for the shared segment | |
| 194 XDisplay* display_; // connection to the X server | |
| 195 size_t inflight_counter_; // How many requests to the X server are in flight | |
| 196 bool detached_; // If true, delete the transport DIB when it is idle | |
| 197 #else | |
| 198 explicit TransportDIB(base::SharedMemoryHandle dib); | 148 explicit TransportDIB(base::SharedMemoryHandle dib); |
| 199 base::SharedMemory shared_memory_; | 149 base::SharedMemory shared_memory_; |
| 200 uint32 sequence_num_; | 150 uint32 sequence_num_; |
| 201 #endif | |
| 202 size_t size_; // length, in bytes | 151 size_t size_; // length, in bytes |
| 203 | 152 |
| 204 DISALLOW_COPY_AND_ASSIGN(TransportDIB); | 153 DISALLOW_COPY_AND_ASSIGN(TransportDIB); |
| 205 }; | 154 }; |
| 206 | 155 |
| 207 #endif // UI_SURFACE_TRANSPORT_DIB_H_ | 156 #endif // UI_SURFACE_TRANSPORT_DIB_H_ |
| OLD | NEW |