| 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 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 HANDLE handle; | 69 HANDLE handle; |
| 70 uint32 sequence_num; | 70 uint32 sequence_num; |
| 71 }; | 71 }; |
| 72 typedef HandleAndSequenceNum Id; | 72 typedef HandleAndSequenceNum Id; |
| 73 | 73 |
| 74 // Returns a default, invalid handle, that is meant to indicate a missing | 74 // Returns a default, invalid handle, that is meant to indicate a missing |
| 75 // Transport DIB. | 75 // Transport DIB. |
| 76 static Handle DefaultHandleValue() { return NULL; } | 76 static Handle DefaultHandleValue() { return NULL; } |
| 77 | |
| 78 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE | |
| 79 // ACTUALLY USED AS A REAL HANDLE. | |
| 80 static Handle GetFakeHandleForTest() { | |
| 81 static int fake_handle = 10; | |
| 82 return reinterpret_cast<Handle>(fake_handle++); | |
| 83 } | |
| 84 #elif defined(TOOLKIT_GTK) | 77 #elif defined(TOOLKIT_GTK) |
| 85 typedef int Handle; // These two ints are SysV IPC shared memory keys | 78 typedef int Handle; // These two ints are SysV IPC shared memory keys |
| 86 struct Id { | 79 struct Id { |
| 87 // Ensure that default initialized Ids are invalid. | 80 // Ensure that default initialized Ids are invalid. |
| 88 Id() : shmkey(-1) { | 81 Id() : shmkey(-1) { |
| 89 } | 82 } |
| 90 | 83 |
| 91 bool operator<(const Id& other) const { | 84 bool operator<(const Id& other) const { |
| 92 return shmkey < other.shmkey; | 85 return shmkey < other.shmkey; |
| 93 } | 86 } |
| 94 | 87 |
| 95 bool operator==(const Id& other) const { | 88 bool operator==(const Id& other) const { |
| 96 return shmkey == other.shmkey; | 89 return shmkey == other.shmkey; |
| 97 } | 90 } |
| 98 | 91 |
| 99 int shmkey; | 92 int shmkey; |
| 100 }; | 93 }; |
| 101 | 94 |
| 102 // Returns a default, invalid handle, that is meant to indicate a missing | 95 // Returns a default, invalid handle, that is meant to indicate a missing |
| 103 // Transport DIB. | 96 // Transport DIB. |
| 104 static Handle DefaultHandleValue() { return -1; } | 97 static Handle DefaultHandleValue() { return -1; } |
| 105 | |
| 106 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE | |
| 107 // ACTUALLY USED AS A REAL HANDLE. | |
| 108 static Handle GetFakeHandleForTest() { | |
| 109 static int fake_handle = 10; | |
| 110 return fake_handle++; | |
| 111 } | |
| 112 #else // OS_POSIX | 98 #else // OS_POSIX |
| 113 typedef base::SharedMemoryHandle Handle; | 99 typedef base::SharedMemoryHandle Handle; |
| 114 // On POSIX, the inode number of the backing file is used as an id. | 100 // On POSIX, the inode number of the backing file is used as an id. |
| 115 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
| 116 typedef base::SharedMemoryHandle Id; | 102 typedef base::SharedMemoryHandle Id; |
| 117 #else | 103 #else |
| 118 typedef base::SharedMemoryId Id; | 104 typedef base::SharedMemoryId Id; |
| 119 #endif | 105 #endif |
| 120 | 106 |
| 121 // Returns a default, invalid handle, that is meant to indicate a missing | 107 // Returns a default, invalid handle, that is meant to indicate a missing |
| 122 // Transport DIB. | 108 // Transport DIB. |
| 123 static Handle DefaultHandleValue() { return Handle(); } | 109 static Handle DefaultHandleValue() { return Handle(); } |
| 124 | |
| 125 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE | |
| 126 // ACTUALLY USED AS A REAL HANDLE. | |
| 127 static Handle GetFakeHandleForTest() { | |
| 128 static int fake_handle = 10; | |
| 129 return Handle(fake_handle++, false); | |
| 130 } | |
| 131 #endif | 110 #endif |
| 132 | 111 |
| 133 // Create a new TransportDIB, returning NULL on failure. | 112 // Create a new TransportDIB, returning NULL on failure. |
| 134 // | 113 // |
| 135 // The size is the minimum size in bytes of the memory backing the transport | 114 // The size is the minimum size in bytes of the memory backing the transport |
| 136 // DIB (we may actually allocate more than that to give us better reuse when | 115 // DIB (we may actually allocate more than that to give us better reuse when |
| 137 // cached). | 116 // cached). |
| 138 // | 117 // |
| 139 // The sequence number is used to uniquely identify the transport DIB. It | 118 // The sequence number is used to uniquely identify the transport DIB. It |
| 140 // should be unique for all transport DIBs ever created in the same | 119 // should be unique for all transport DIBs ever created in the same |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 explicit TransportDIB(base::SharedMemoryHandle dib); | 198 explicit TransportDIB(base::SharedMemoryHandle dib); |
| 220 base::SharedMemory shared_memory_; | 199 base::SharedMemory shared_memory_; |
| 221 uint32 sequence_num_; | 200 uint32 sequence_num_; |
| 222 #endif | 201 #endif |
| 223 size_t size_; // length, in bytes | 202 size_t size_; // length, in bytes |
| 224 | 203 |
| 225 DISALLOW_COPY_AND_ASSIGN(TransportDIB); | 204 DISALLOW_COPY_AND_ASSIGN(TransportDIB); |
| 226 }; | 205 }; |
| 227 | 206 |
| 228 #endif // UI_SURFACE_TRANSPORT_DIB_H_ | 207 #endif // UI_SURFACE_TRANSPORT_DIB_H_ |
| OLD | NEW |