2 * Mesa 3-D graphics library
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
29 #include "EGL/egl.h" /* for EGL native types */
31 #include "pipe/p_compiler.h"
32 #include "pipe/p_screen.h"
33 #include "pipe/p_context.h"
34 #include "pipe/p_state.h"
35 #include "state_tracker/sw_winsys.h"
41 #include "native_buffer.h"
42 #include "native_modeset.h"
45 * Only color buffers are listed. The others are allocated privately through,
46 * for example, st_renderbuffer_alloc_storage().
48 enum native_attachment
{
49 NATIVE_ATTACHMENT_FRONT_LEFT
,
50 NATIVE_ATTACHMENT_BACK_LEFT
,
51 NATIVE_ATTACHMENT_FRONT_RIGHT
,
52 NATIVE_ATTACHMENT_BACK_RIGHT
,
54 NUM_NATIVE_ATTACHMENTS
57 enum native_param_type
{
59 * Return TRUE if window/pixmap surfaces use the buffers of the native
62 NATIVE_PARAM_USE_NATIVE_BUFFER
,
65 * Return TRUE if native_surface::present can preserve the buffer.
67 NATIVE_PARAM_PRESERVE_BUFFER
,
70 * Return the maximum supported swap interval.
72 NATIVE_PARAM_MAX_SWAP_INTERVAL
75 struct native_surface
{
77 * Available for caller's use.
81 void (*destroy
)(struct native_surface
*nsurf
);
84 * Present the given buffer to the native engine.
86 boolean (*present
)(struct native_surface
*nsurf
,
87 enum native_attachment natt
,
92 * Validate the buffers of the surface. textures, if not NULL, points to an
93 * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
94 * by the caller. A sequence number is also returned. The caller can use
95 * it to check if anything has changed since the last call. Any of the
96 * pointers may be NULL and it indicates the caller has no interest in those
99 * If this function is called multiple times with different attachment
100 * masks, those not listed in the latest call might be destroyed. This
101 * behavior might change in the future.
103 boolean (*validate
)(struct native_surface
*nsurf
, uint attachment_mask
,
104 unsigned int *seq_num
, struct pipe_resource
**textures
,
105 int *width
, int *height
);
108 * Wait until all native commands affecting the surface has been executed.
110 void (*wait
)(struct native_surface
*nsurf
);
114 * Describe a native display config.
116 struct native_config
{
117 /* available buffers and their format */
119 enum pipe_format color_format
;
121 /* supported surface types */
126 int native_visual_id
;
127 int native_visual_type
;
129 boolean transparent_rgb
;
130 int transparent_rgb_values
[3];
134 * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis
135 * hardware. A native display consists of a pipe winsys, a pipe screen, and
136 * the native display server.
138 struct native_display
{
140 * The pipe screen of the native display.
142 struct pipe_screen
*screen
;
145 * Context used for copy operations.
147 struct pipe_context
*pipe
;
150 * Available for caller's use.
154 void (*destroy
)(struct native_display
*ndpy
);
157 * Query the parameters of the native display.
159 * The return value is defined by the parameter.
161 int (*get_param
)(struct native_display
*ndpy
,
162 enum native_param_type param
);
165 * Get the supported configs. The configs are owned by the display, but
166 * the returned array should be FREE()ed.
168 const struct native_config
**(*get_configs
)(struct native_display
*ndpy
,
172 * Test if a pixmap is supported by the given config. Required unless no
173 * config has pixmap_bit set.
175 * This function is usually called to find a config that supports a given
176 * pixmap. Thus, it is usually called with the same pixmap in a row.
178 boolean (*is_pixmap_supported
)(struct native_display
*ndpy
,
179 EGLNativePixmapType pix
,
180 const struct native_config
*nconf
);
184 * Create a window surface. Required unless no config has window_bit set.
186 struct native_surface
*(*create_window_surface
)(struct native_display
*ndpy
,
187 EGLNativeWindowType win
,
188 const struct native_config
*nconf
);
191 * Create a pixmap surface. The native config may be NULL. In that case, a
192 * "best config" will be picked. Required unless no config has pixmap_bit
195 struct native_surface
*(*create_pixmap_surface
)(struct native_display
*ndpy
,
196 EGLNativePixmapType pix
,
197 const struct native_config
*nconf
);
199 const struct native_display_buffer
*buffer
;
200 const struct native_display_modeset
*modeset
;
204 * The handler for events that a native display may generate. The events are
205 * generated asynchronously and the handler may be called by any thread at any
208 struct native_event_handler
{
210 * This function is called when a surface needs to be validated.
212 void (*invalid_surface
)(struct native_display
*ndpy
,
213 struct native_surface
*nsurf
,
214 unsigned int seq_num
);
216 struct pipe_screen
*(*new_drm_screen
)(struct native_display
*ndpy
,
217 const char *name
, int fd
);
218 struct pipe_screen
*(*new_sw_screen
)(struct native_display
*ndpy
,
219 struct sw_winsys
*ws
);
223 * Test whether an attachment is set in the mask.
225 static INLINE boolean
226 native_attachment_mask_test(uint mask
, enum native_attachment att
)
228 return !!(mask
& (1 << att
));
232 * Get the display copy context
234 static INLINE
struct pipe_context
*
235 ndpy_get_copy_context(struct native_display
*ndpy
)
238 ndpy
->pipe
= ndpy
->screen
->context_create(ndpy
->screen
, NULL
);
243 * Free display screen and context resources
246 ndpy_uninit(struct native_display
*ndpy
)
249 ndpy
->pipe
->destroy(ndpy
->pipe
);
251 ndpy
->screen
->destroy(ndpy
->screen
);
254 struct native_platform
{
257 void (*set_event_handler
)(struct native_event_handler
*handler
);
258 struct native_display
*(*create_display
)(void *dpy
,
263 const struct native_platform
*
264 native_get_gdi_platform(void);
266 const struct native_platform
*
267 native_get_x11_platform(void);
269 const struct native_platform
*
270 native_get_wayland_platform(void);
272 const struct native_platform
*
273 native_get_drm_platform(void);
275 const struct native_platform
*
276 native_get_fbdev_platform(void);
282 #endif /* _NATIVE_H_ */