Bug 1869647 - Mark hasStorageAccess.sub.https.window.html as intermittent after wpt...
[gecko.git] / widget / gtk / gbm.h
blobbd94fa8967d8239ae1b398dce21eea308313b4f5
1 /*
2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
28 #ifndef _GBM_H_
29 #define _GBM_H_
31 #define __GBM__ 1
33 #include <stddef.h>
34 #include <stdint.h>
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
40 /**
41 * \file gbm.h
42 * \brief Generic Buffer Manager
45 struct gbm_device;
46 struct gbm_bo;
47 struct gbm_surface;
49 /**
50 * \mainpage The Generic Buffer Manager
52 * This module provides an abstraction that the caller can use to request a
53 * buffer from the underlying memory management system for the platform.
55 * This allows the creation of portable code whilst still allowing access to
56 * the underlying memory manager.
59 /**
60 * Abstraction representing the handle to a buffer allocated by the
61 * manager
63 union gbm_bo_handle {
64 void* ptr;
65 int32_t s32;
66 uint32_t u32;
67 int64_t s64;
68 uint64_t u64;
71 /** Format of the allocated buffer */
72 enum gbm_bo_format {
73 /** RGB with 8 bits per channel in a 32 bit value */
74 GBM_BO_FORMAT_XRGB8888,
75 /** ARGB with 8 bits per channel in a 32 bit value */
76 GBM_BO_FORMAT_ARGB8888
79 /**
80 * The FourCC format codes are taken from the drm_fourcc.h definition, and
81 * re-namespaced. New GBM formats must not be added, unless they are
82 * identical ports from drm_fourcc.
84 #define __gbm_fourcc_code(a, b, c, d) \
85 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | \
86 ((uint32_t)(d) << 24))
88 #define GBM_FORMAT_BIG_ENDIAN \
89 (1 << 31) /* format is big endian instead of little endian */
91 /* color index */
92 #define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
94 /* 8 bpp Red */
95 #define GBM_FORMAT_R8 __gbm_fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
97 /* 16 bpp RG */
98 #define GBM_FORMAT_GR88 \
99 __gbm_fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
101 /* 8 bpp RGB */
102 #define GBM_FORMAT_RGB332 \
103 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
104 #define GBM_FORMAT_BGR233 \
105 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
107 /* 16 bpp RGB */
108 #define GBM_FORMAT_XRGB4444 \
109 __gbm_fourcc_code('X', 'R', '1', \
110 '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
111 #define GBM_FORMAT_XBGR4444 \
112 __gbm_fourcc_code('X', 'B', '1', \
113 '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
114 #define GBM_FORMAT_RGBX4444 \
115 __gbm_fourcc_code('R', 'X', '1', \
116 '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
117 #define GBM_FORMAT_BGRX4444 \
118 __gbm_fourcc_code('B', 'X', '1', \
119 '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
121 #define GBM_FORMAT_ARGB4444 \
122 __gbm_fourcc_code('A', 'R', '1', \
123 '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
124 #define GBM_FORMAT_ABGR4444 \
125 __gbm_fourcc_code('A', 'B', '1', \
126 '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
127 #define GBM_FORMAT_RGBA4444 \
128 __gbm_fourcc_code('R', 'A', '1', \
129 '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
130 #define GBM_FORMAT_BGRA4444 \
131 __gbm_fourcc_code('B', 'A', '1', \
132 '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
134 #define GBM_FORMAT_XRGB1555 \
135 __gbm_fourcc_code('X', 'R', '1', \
136 '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
137 #define GBM_FORMAT_XBGR1555 \
138 __gbm_fourcc_code('X', 'B', '1', \
139 '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
140 #define GBM_FORMAT_RGBX5551 \
141 __gbm_fourcc_code('R', 'X', '1', \
142 '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
143 #define GBM_FORMAT_BGRX5551 \
144 __gbm_fourcc_code('B', 'X', '1', \
145 '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
147 #define GBM_FORMAT_ARGB1555 \
148 __gbm_fourcc_code('A', 'R', '1', \
149 '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
150 #define GBM_FORMAT_ABGR1555 \
151 __gbm_fourcc_code('A', 'B', '1', \
152 '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
153 #define GBM_FORMAT_RGBA5551 \
154 __gbm_fourcc_code('R', 'A', '1', \
155 '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
156 #define GBM_FORMAT_BGRA5551 \
157 __gbm_fourcc_code('B', 'A', '1', \
158 '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
160 #define GBM_FORMAT_RGB565 \
161 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
162 #define GBM_FORMAT_BGR565 \
163 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
165 /* 24 bpp RGB */
166 #define GBM_FORMAT_RGB888 \
167 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
168 #define GBM_FORMAT_BGR888 \
169 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
171 /* 32 bpp RGB */
172 #define GBM_FORMAT_XRGB8888 \
173 __gbm_fourcc_code('X', 'R', '2', \
174 '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
175 #define GBM_FORMAT_XBGR8888 \
176 __gbm_fourcc_code('X', 'B', '2', \
177 '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
178 #define GBM_FORMAT_RGBX8888 \
179 __gbm_fourcc_code('R', 'X', '2', \
180 '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
181 #define GBM_FORMAT_BGRX8888 \
182 __gbm_fourcc_code('B', 'X', '2', \
183 '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
185 #define GBM_FORMAT_ARGB8888 \
186 __gbm_fourcc_code('A', 'R', '2', \
187 '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
188 #define GBM_FORMAT_ABGR8888 \
189 __gbm_fourcc_code('A', 'B', '2', \
190 '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
191 #define GBM_FORMAT_RGBA8888 \
192 __gbm_fourcc_code('R', 'A', '2', \
193 '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
194 #define GBM_FORMAT_BGRA8888 \
195 __gbm_fourcc_code('B', 'A', '2', \
196 '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
198 #define GBM_FORMAT_XRGB2101010 \
199 __gbm_fourcc_code('X', 'R', '3', \
200 '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
201 #define GBM_FORMAT_XBGR2101010 \
202 __gbm_fourcc_code('X', 'B', '3', \
203 '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
204 #define GBM_FORMAT_RGBX1010102 \
205 __gbm_fourcc_code('R', 'X', '3', \
206 '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
207 #define GBM_FORMAT_BGRX1010102 \
208 __gbm_fourcc_code('B', 'X', '3', \
209 '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
211 #define GBM_FORMAT_ARGB2101010 \
212 __gbm_fourcc_code('A', 'R', '3', \
213 '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
214 #define GBM_FORMAT_ABGR2101010 \
215 __gbm_fourcc_code('A', 'B', '3', \
216 '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
217 #define GBM_FORMAT_RGBA1010102 \
218 __gbm_fourcc_code('R', 'A', '3', \
219 '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
220 #define GBM_FORMAT_BGRA1010102 \
221 __gbm_fourcc_code('B', 'A', '3', \
222 '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
224 /* packed YCbCr */
225 #define GBM_FORMAT_YUYV \
226 __gbm_fourcc_code('Y', 'U', 'Y', \
227 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
228 #define GBM_FORMAT_YVYU \
229 __gbm_fourcc_code('Y', 'V', 'Y', \
230 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
231 #define GBM_FORMAT_UYVY \
232 __gbm_fourcc_code('U', 'Y', 'V', \
233 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
234 #define GBM_FORMAT_VYUY \
235 __gbm_fourcc_code('V', 'Y', 'U', \
236 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
238 #define GBM_FORMAT_AYUV \
239 __gbm_fourcc_code('A', 'Y', 'U', \
240 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
243 * 2 plane YCbCr
244 * index 0 = Y plane, [7:0] Y
245 * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
246 * or
247 * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
249 #define GBM_FORMAT_NV12 \
250 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
251 #define GBM_FORMAT_NV21 \
252 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
253 #define GBM_FORMAT_NV16 \
254 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
255 #define GBM_FORMAT_NV61 \
256 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
259 * 3 plane YCbCr
260 * index 0: Y plane, [7:0] Y
261 * index 1: Cb plane, [7:0] Cb
262 * index 2: Cr plane, [7:0] Cr
263 * or
264 * index 1: Cr plane, [7:0] Cr
265 * index 2: Cb plane, [7:0] Cb
267 #define GBM_FORMAT_YUV410 \
268 __gbm_fourcc_code('Y', 'U', 'V', \
269 '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
270 #define GBM_FORMAT_YVU410 \
271 __gbm_fourcc_code('Y', 'V', 'U', \
272 '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
273 #define GBM_FORMAT_YUV411 \
274 __gbm_fourcc_code('Y', 'U', '1', \
275 '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
276 #define GBM_FORMAT_YVU411 \
277 __gbm_fourcc_code('Y', 'V', '1', \
278 '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
279 #define GBM_FORMAT_YUV420 \
280 __gbm_fourcc_code('Y', 'U', '1', \
281 '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
282 #define GBM_FORMAT_YVU420 \
283 __gbm_fourcc_code('Y', 'V', '1', \
284 '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
285 #define GBM_FORMAT_YUV422 \
286 __gbm_fourcc_code('Y', 'U', '1', \
287 '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
288 #define GBM_FORMAT_YVU422 \
289 __gbm_fourcc_code('Y', 'V', '1', \
290 '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
291 #define GBM_FORMAT_YUV444 \
292 __gbm_fourcc_code('Y', 'U', '2', \
293 '4') /* non-subsampled Cb (1) and Cr (2) planes */
294 #define GBM_FORMAT_YVU444 \
295 __gbm_fourcc_code('Y', 'V', '2', \
296 '4') /* non-subsampled Cr (1) and Cb (2) planes */
298 struct gbm_format_name_desc {
299 char name[5];
303 * Flags to indicate the intended use for the buffer - these are passed into
304 * gbm_bo_create(). The caller must set the union of all the flags that are
305 * appropriate
307 * \sa Use gbm_device_is_format_supported() to check if the combination of
308 * format and use flags are supported
310 enum gbm_bo_flags {
312 * Buffer is going to be presented to the screen using an API such as KMS
314 GBM_BO_USE_SCANOUT = (1 << 0),
316 * Buffer is going to be used as cursor
318 GBM_BO_USE_CURSOR = (1 << 1),
320 * Deprecated
322 GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR,
324 * Buffer is to be used for rendering - for example it is going to be used
325 * as the storage for a color buffer
327 GBM_BO_USE_RENDERING = (1 << 2),
329 * Buffer can be used for gbm_bo_write. This is guaranteed to work
330 * with GBM_BO_USE_CURSOR, but may not work for other combinations.
332 GBM_BO_USE_WRITE = (1 << 3),
334 * Buffer is linear, i.e. not tiled.
336 GBM_BO_USE_LINEAR = (1 << 4),
339 int gbm_device_get_fd(struct gbm_device* gbm);
341 const char* gbm_device_get_backend_name(struct gbm_device* gbm);
343 int gbm_device_is_format_supported(struct gbm_device* gbm, uint32_t format,
344 uint32_t usage);
346 int gbm_device_get_format_modifier_plane_count(struct gbm_device* gbm,
347 uint32_t format,
348 uint64_t modifier);
350 void gbm_device_destroy(struct gbm_device* gbm);
352 struct gbm_device* gbm_create_device(int fd);
354 struct gbm_bo* gbm_bo_create(struct gbm_device* gbm, uint32_t width,
355 uint32_t height, uint32_t format, uint32_t flags);
357 struct gbm_bo* gbm_bo_create_with_modifiers(struct gbm_device* gbm,
358 uint32_t width, uint32_t height,
359 uint32_t format,
360 const uint64_t* modifiers,
361 const unsigned int count);
362 #define GBM_BO_IMPORT_WL_BUFFER 0x5501
363 #define GBM_BO_IMPORT_EGL_IMAGE 0x5502
364 #define GBM_BO_IMPORT_FD 0x5503
365 #define GBM_BO_IMPORT_FD_MODIFIER 0x5504
367 struct gbm_import_fd_data {
368 int fd;
369 uint32_t width;
370 uint32_t height;
371 uint32_t stride;
372 uint32_t format;
375 struct gbm_import_fd_modifier_data {
376 uint32_t width;
377 uint32_t height;
378 uint32_t format;
379 uint32_t num_fds;
380 int fds[4];
381 int strides[4];
382 int offsets[4];
383 uint64_t modifier;
386 struct gbm_bo* gbm_bo_import(struct gbm_device* gbm, uint32_t type,
387 void* buffer, uint32_t usage);
390 * Flags to indicate the type of mapping for the buffer - these are
391 * passed into gbm_bo_map(). The caller must set the union of all the
392 * flags that are appropriate.
394 * These flags are independent of the GBM_BO_USE_* creation flags. However,
395 * mapping the buffer may require copying to/from a staging buffer.
397 * See also: pipe_transfer_usage
399 enum gbm_bo_transfer_flags {
401 * Buffer contents read back (or accessed directly) at transfer
402 * create time.
404 GBM_BO_TRANSFER_READ = (1 << 0),
406 * Buffer contents will be written back at unmap time
407 * (or modified as a result of being accessed directly).
409 GBM_BO_TRANSFER_WRITE = (1 << 1),
411 * Read/modify/write
413 GBM_BO_TRANSFER_READ_WRITE = (GBM_BO_TRANSFER_READ | GBM_BO_TRANSFER_WRITE),
416 void* gbm_bo_map(struct gbm_bo* bo, uint32_t x, uint32_t y, uint32_t width,
417 uint32_t height, uint32_t flags, uint32_t* stride,
418 void** map_data);
420 void gbm_bo_unmap(struct gbm_bo* bo, void* map_data);
422 uint32_t gbm_bo_get_width(struct gbm_bo* bo);
424 uint32_t gbm_bo_get_height(struct gbm_bo* bo);
426 uint32_t gbm_bo_get_stride(struct gbm_bo* bo);
428 uint32_t gbm_bo_get_stride_for_plane(struct gbm_bo* bo, int plane);
430 uint32_t gbm_bo_get_format(struct gbm_bo* bo);
432 uint32_t gbm_bo_get_bpp(struct gbm_bo* bo);
434 uint32_t gbm_bo_get_offset(struct gbm_bo* bo, int plane);
436 struct gbm_device* gbm_bo_get_device(struct gbm_bo* bo);
438 union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo* bo);
440 int gbm_bo_get_fd(struct gbm_bo* bo);
442 uint64_t gbm_bo_get_modifier(struct gbm_bo* bo);
444 int gbm_bo_get_plane_count(struct gbm_bo* bo);
446 union gbm_bo_handle gbm_bo_get_handle_for_plane(struct gbm_bo* bo, int plane);
448 int gbm_bo_write(struct gbm_bo* bo, const void* buf, size_t count);
450 void gbm_bo_set_user_data(struct gbm_bo* bo, void* data,
451 void (*destroy_user_data)(struct gbm_bo*, void*));
453 void* gbm_bo_get_user_data(struct gbm_bo* bo);
455 void gbm_bo_destroy(struct gbm_bo* bo);
457 struct gbm_surface* gbm_surface_create(struct gbm_device* gbm, uint32_t width,
458 uint32_t height, uint32_t format,
459 uint32_t flags);
461 struct gbm_surface* gbm_surface_create_with_modifiers(
462 struct gbm_device* gbm, uint32_t width, uint32_t height, uint32_t format,
463 const uint64_t* modifiers, const unsigned int count);
465 struct gbm_bo* gbm_surface_lock_front_buffer(struct gbm_surface* surface);
467 void gbm_surface_release_buffer(struct gbm_surface* surface, struct gbm_bo* bo);
469 int gbm_surface_has_free_buffers(struct gbm_surface* surface);
471 void gbm_surface_destroy(struct gbm_surface* surface);
473 char* gbm_format_get_name(uint32_t gbm_format,
474 struct gbm_format_name_desc* desc);
476 #ifdef __cplusplus
478 #endif
480 #endif