gbm: Add documentation for the public facing API
[mesa.git] / src / gbm / main / gbm.h
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28 #ifndef _GBM_H_
29 #define _GBM_H_
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36 #define __GBM__ 1
37
38 #include <stdint.h>
39
40 /**
41 * \file gbm.h
42 * \brief Generic Buffer Manager
43 */
44
45 struct gbm_device;
46 struct gbm_bo;
47
48 /**
49 * \mainpage The Generic Buffer Manager
50 *
51 * This module provides an abstraction that the caller can use to request a
52 * buffer from the underlying memory management system for the platform.
53 *
54 * This allows the creation of portable code whilst still allowing access to
55 * the underlying memory manager.
56 */
57
58 /**
59 * Abstraction representing the handle to a buffer allocated by the
60 * manager
61 */
62 union gbm_bo_handle {
63 void *ptr;
64 int32_t s32;
65 uint32_t u32;
66 int64_t s64;
67 uint64_t u64;
68 };
69
70 /** Format of the allocated buffer */
71 enum gbm_bo_format {
72 /** RGB with 8 bits per channel in a 32 bit value */
73 GBM_BO_FORMAT_XRGB8888,
74 /** ARGB with 8 bits per channel in a 32 bit value */
75 GBM_BO_FORMAT_ARGB8888
76 };
77
78 /**
79 * Flags to indicate the intended use for the buffer - these are passed into
80 * gbm_bo_create(). The caller must set the union of all the flags that are
81 * appropriate
82 *
83 * \sa Use gbm_device_is_format_supported() to check if the combination of format
84 * and use flags are supported
85 */
86 enum gbm_bo_flags {
87 /**
88 * Buffer is going to be presented to the screen using an API such as KMS
89 */
90 GBM_BO_USE_SCANOUT = (1 << 0),
91 /**
92 * Buffer is going to be used as cursor - the dimensions for the buffer
93 * must be 64x64 if this flag is passed.
94 */
95 GBM_BO_USE_CURSOR_64X64 = (1 << 1),
96 /**
97 * Buffer is to be used for rendering - for example it is going to be used
98 * as the storage for a color buffer
99 */
100 GBM_BO_USE_RENDERING = (1 << 2),
101 };
102
103 int
104 gbm_device_get_fd(struct gbm_device *gbm);
105
106 const char *
107 gbm_device_get_backend_name(struct gbm_device *gbm);
108
109 int
110 gbm_device_is_format_supported(struct gbm_device *gbm,
111 enum gbm_bo_format format,
112 uint32_t usage);
113
114 void
115 gbm_device_destroy(struct gbm_device *gbm);
116
117 struct gbm_device *
118 gbm_create_device(int fd);
119
120 struct gbm_bo *
121 gbm_bo_create(struct gbm_device *gbm,
122 uint32_t width, uint32_t height,
123 enum gbm_bo_format format, uint32_t flags);
124
125 struct gbm_bo *
126 gbm_bo_create_from_egl_image(struct gbm_device *gbm,
127 void *egl_dpy, void *egl_img,
128 uint32_t width, uint32_t height,
129 uint32_t usage);
130
131 uint32_t
132 gbm_bo_get_width(struct gbm_bo *bo);
133
134 uint32_t
135 gbm_bo_get_height(struct gbm_bo *bo);
136
137 uint32_t
138 gbm_bo_get_pitch(struct gbm_bo *bo);
139
140 union gbm_bo_handle
141 gbm_bo_get_handle(struct gbm_bo *bo);
142
143 void
144 gbm_bo_destroy(struct gbm_bo *bo);
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif