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"
43 #include "native_wayland_bufmgr.h"
46 * Only color buffers are listed. The others are allocated privately through,
47 * for example, st_renderbuffer_alloc_storage().
49 enum native_attachment
{
50 NATIVE_ATTACHMENT_FRONT_LEFT
,
51 NATIVE_ATTACHMENT_BACK_LEFT
,
52 NATIVE_ATTACHMENT_FRONT_RIGHT
,
53 NATIVE_ATTACHMENT_BACK_RIGHT
,
55 NUM_NATIVE_ATTACHMENTS
58 enum native_param_type
{
60 * Return TRUE if window/pixmap surfaces use the buffers of the native
63 NATIVE_PARAM_USE_NATIVE_BUFFER
,
66 * Return TRUE if native_surface::present can preserve the buffer.
68 NATIVE_PARAM_PRESERVE_BUFFER
,
71 * Return the maximum supported swap interval.
73 NATIVE_PARAM_MAX_SWAP_INTERVAL
,
76 * Return TRUE if the display supports premultiplied alpha, regardless of
77 * the surface color format.
79 * Note that returning TRUE for this parameter will make
80 * EGL_VG_ALPHA_FORMAT_PRE_BIT to be set for all EGLConfig's with non-zero
81 * EGL_ALPHA_SIZE. EGL_VG_ALPHA_FORMAT attribute of a surface will affect
82 * how the surface is presented.
84 NATIVE_PARAM_PREMULTIPLIED_ALPHA
88 * Control how a surface presentation should happen.
90 struct native_present_control
{
91 /**< the attachment to present */
92 enum native_attachment natt
;
94 /**< the contents of the presented attachment should be preserved */
97 /**< wait until the given vsyncs has passed since the last presentation */
100 /**< pixels use premultiplied alpha */
101 boolean premultiplied_alpha
;
104 struct native_surface
{
106 * Available for caller's use.
110 void (*destroy
)(struct native_surface
*nsurf
);
113 * Present the given buffer to the native engine.
115 boolean (*present
)(struct native_surface
*nsurf
,
116 const struct native_present_control
*ctrl
);
119 * Validate the buffers of the surface. textures, if not NULL, points to an
120 * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
121 * by the caller. A sequence number is also returned. The caller can use
122 * it to check if anything has changed since the last call. Any of the
123 * pointers may be NULL and it indicates the caller has no interest in those
126 * If this function is called multiple times with different attachment
127 * masks, those not listed in the latest call might be destroyed. This
128 * behavior might change in the future.
130 boolean (*validate
)(struct native_surface
*nsurf
, uint attachment_mask
,
131 unsigned int *seq_num
, struct pipe_resource
**textures
,
132 int *width
, int *height
);
135 * Wait until all native commands affecting the surface has been executed.
137 void (*wait
)(struct native_surface
*nsurf
);
141 * Describe a native display config.
143 struct native_config
{
144 /* available buffers and their format */
146 enum pipe_format color_format
;
148 /* supported surface types */
153 int native_visual_id
;
154 int native_visual_type
;
156 boolean transparent_rgb
;
157 int transparent_rgb_values
[3];
161 * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis
162 * hardware. A native display consists of a pipe winsys, a pipe screen, and
163 * the native display server.
165 struct native_display
{
167 * The pipe screen of the native display.
169 struct pipe_screen
*screen
;
172 * Context used for copy operations.
174 struct pipe_context
*pipe
;
177 * Available for caller's use.
182 * Initialize and create the pipe screen.
184 boolean (*init_screen
)(struct native_display
*ndpy
);
186 void (*destroy
)(struct native_display
*ndpy
);
189 * Query the parameters of the native display.
191 * The return value is defined by the parameter.
193 int (*get_param
)(struct native_display
*ndpy
,
194 enum native_param_type param
);
197 * Get the supported configs. The configs are owned by the display, but
198 * the returned array should be FREE()ed.
200 const struct native_config
**(*get_configs
)(struct native_display
*ndpy
,
204 * Get the color format of the pixmap. Required unless no config has
207 boolean (*get_pixmap_format
)(struct native_display
*ndpy
,
208 EGLNativePixmapType pix
,
209 enum pipe_format
*format
);
212 * Copy the contents of the resource to the pixmap's front-left attachment.
213 * This is used to implement eglCopyBuffers. Required unless no config has
216 boolean (*copy_to_pixmap
)(struct native_display
*ndpy
,
217 EGLNativePixmapType pix
,
218 struct pipe_resource
*src
);
221 * Create a window surface. Required unless no config has window_bit set.
223 struct native_surface
*(*create_window_surface
)(struct native_display
*ndpy
,
224 EGLNativeWindowType win
,
225 const struct native_config
*nconf
);
228 * Create a pixmap surface. The native config may be NULL. In that case, a
229 * "best config" will be picked. Required unless no config has pixmap_bit
232 struct native_surface
*(*create_pixmap_surface
)(struct native_display
*ndpy
,
233 EGLNativePixmapType pix
,
234 const struct native_config
*nconf
);
236 const struct native_display_buffer
*buffer
;
237 const struct native_display_modeset
*modeset
;
238 const struct native_display_wayland_bufmgr
*wayland_bufmgr
;
242 * The handler for events that a native display may generate. The events are
243 * generated asynchronously and the handler may be called by any thread at any
246 struct native_event_handler
{
248 * This function is called when a surface needs to be validated.
250 void (*invalid_surface
)(struct native_display
*ndpy
,
251 struct native_surface
*nsurf
,
252 unsigned int seq_num
);
254 struct pipe_screen
*(*new_drm_screen
)(struct native_display
*ndpy
,
255 const char *name
, int fd
);
256 struct pipe_screen
*(*new_sw_screen
)(struct native_display
*ndpy
,
257 struct sw_winsys
*ws
);
259 struct pipe_resource
*(*lookup_egl_image
)(struct native_display
*ndpy
,
264 * Test whether an attachment is set in the mask.
266 static INLINE boolean
267 native_attachment_mask_test(uint mask
, enum native_attachment att
)
269 return !!(mask
& (1 << att
));
273 * Get the display copy context
275 static INLINE
struct pipe_context
*
276 ndpy_get_copy_context(struct native_display
*ndpy
)
279 ndpy
->pipe
= ndpy
->screen
->context_create(ndpy
->screen
, NULL
);
284 * Free display screen and context resources
287 ndpy_uninit(struct native_display
*ndpy
)
290 ndpy
->pipe
->destroy(ndpy
->pipe
);
292 ndpy
->screen
->destroy(ndpy
->screen
);
295 struct native_platform
{
299 * Create the native display and usually establish a connection to the
302 * No event should be generated at this stage.
304 struct native_display
*(*create_display
)(void *dpy
, boolean use_sw
);
307 const struct native_platform
*
308 native_get_gdi_platform(const struct native_event_handler
*event_handler
);
310 const struct native_platform
*
311 native_get_x11_platform(const struct native_event_handler
*event_handler
);
313 const struct native_platform
*
314 native_get_wayland_platform(const struct native_event_handler
*event_handler
);
316 const struct native_platform
*
317 native_get_drm_platform(const struct native_event_handler
*event_handler
);
319 const struct native_platform
*
320 native_get_fbdev_platform(const struct native_event_handler
*event_handler
);
322 const struct native_platform
*
323 native_get_null_platform(const struct native_event_handler
*event_handler
);
325 const struct native_platform
*
326 native_get_android_platform(const struct native_event_handler
*event_handler
);
332 #endif /* _NATIVE_H_ */