OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GFX_SURFACE_TRANSPORT_DIB_H_ | 5 #ifndef UI_GFX_SURFACE_TRANSPORT_DIB_H_ |
6 #define UI_GFX_SURFACE_TRANSPORT_DIB_H_ | 6 #define UI_GFX_SURFACE_TRANSPORT_DIB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "ui/gfx/surface/surface_export.h" | 10 #include "ui/gfx/surface/surface_export.h" |
11 | 11 |
12 #if defined(OS_WIN) || defined(OS_MACOSX) | 12 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID) |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #endif | 14 #endif |
15 | 15 |
16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
17 #include <windows.h> | 17 #include <windows.h> |
18 #elif defined(USE_X11) | 18 #elif defined(USE_X11) |
19 #include "ui/base/x/x11_util.h" | 19 #include "ui/base/x/x11_util.h" |
20 #endif | 20 #endif |
21 | 21 |
22 namespace skia { | 22 namespace skia { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Returns a default, invalid handle, that is meant to indicate a missing | 111 // Returns a default, invalid handle, that is meant to indicate a missing |
112 // Transport DIB. | 112 // Transport DIB. |
113 static Handle DefaultHandleValue() { return -1; } | 113 static Handle DefaultHandleValue() { return -1; } |
114 | 114 |
115 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE | 115 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE |
116 // ACTUALLY USED AS A REAL HANDLE. | 116 // ACTUALLY USED AS A REAL HANDLE. |
117 static Handle GetFakeHandleForTest() { | 117 static Handle GetFakeHandleForTest() { |
118 static int fake_handle = 10; | 118 static int fake_handle = 10; |
119 return fake_handle++; | 119 return fake_handle++; |
120 } | 120 } |
| 121 #elif defined(OS_ANDROID) |
| 122 typedef base::SharedMemoryHandle Handle; |
| 123 typedef base::SharedMemoryHandle Id; |
| 124 |
| 125 // Returns a default, invalid handle, that is meant to indicate a missing |
| 126 // Transport DIB. |
| 127 static Handle DefaultHandleValue() { return Handle(); } |
| 128 |
| 129 // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE |
| 130 // ACTUALLY USED AS A REAL HANDLE. |
| 131 static Handle GetFakeHandleForTest() { |
| 132 static int fake_handle = 10; |
| 133 return Handle(fake_handle++, false); |
| 134 } |
121 #endif | 135 #endif |
122 | 136 |
123 // Create a new TransportDIB, returning NULL on failure. | 137 // Create a new TransportDIB, returning NULL on failure. |
124 // | 138 // |
125 // The size is the minimum size in bytes of the memory backing the transport | 139 // The size is the minimum size in bytes of the memory backing the transport |
126 // DIB (we may actually allocate more than that to give us better reuse when | 140 // DIB (we may actually allocate more than that to give us better reuse when |
127 // cached). | 141 // cached). |
128 // | 142 // |
129 // The sequence number is used to uniquely identify the transport DIB. It | 143 // The sequence number is used to uniquely identify the transport DIB. It |
130 // should be unique for all transport DIBs ever created in the same | 144 // should be unique for all transport DIBs ever created in the same |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 Handle handle() const; | 192 Handle handle() const; |
179 | 193 |
180 #if defined(USE_X11) | 194 #if defined(USE_X11) |
181 // Map the shared memory into the X server and return an id for the shared | 195 // Map the shared memory into the X server and return an id for the shared |
182 // segment. | 196 // segment. |
183 XID MapToX(Display* connection); | 197 XID MapToX(Display* connection); |
184 #endif | 198 #endif |
185 | 199 |
186 private: | 200 private: |
187 TransportDIB(); | 201 TransportDIB(); |
188 #if defined(OS_WIN) || defined(OS_MACOSX) | 202 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID) |
189 explicit TransportDIB(base::SharedMemoryHandle dib); | 203 explicit TransportDIB(base::SharedMemoryHandle dib); |
190 base::SharedMemory shared_memory_; | 204 base::SharedMemory shared_memory_; |
191 uint32 sequence_num_; | 205 uint32 sequence_num_; |
192 #elif defined(USE_X11) | 206 #elif defined(USE_X11) |
193 Id key_; // SysV shared memory id | 207 Id key_; // SysV shared memory id |
194 void* address_; // mapped address | 208 void* address_; // mapped address |
195 XSharedMemoryId x_shm_; // X id for the shared segment | 209 XSharedMemoryId x_shm_; // X id for the shared segment |
196 Display* display_; // connection to the X server | 210 Display* display_; // connection to the X server |
197 #endif | 211 #endif |
198 size_t size_; // length, in bytes | 212 size_t size_; // length, in bytes |
199 | 213 |
200 DISALLOW_COPY_AND_ASSIGN(TransportDIB); | 214 DISALLOW_COPY_AND_ASSIGN(TransportDIB); |
201 }; | 215 }; |
202 | 216 |
203 #endif // UI_GFX_SURFACE_TRANSPORT_DIB_H_ | 217 #endif // UI_GFX_SURFACE_TRANSPORT_DIB_H_ |
OLD | NEW |