Merge branch '7.8'
[mesa.git] / src / gallium / state_trackers / egl / common / native.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.8
4 *
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
24 */
25
26 #ifndef _NATIVE_H_
27 #define _NATIVE_H_
28
29 #include "EGL/egl.h" /* for EGL native types */
30
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
36 #include "native_probe.h"
37 #include "native_modeset.h"
38
39 /**
40 * Only color buffers are listed. The others are allocated privately through,
41 * for example, st_renderbuffer_alloc_storage().
42 */
43 enum native_attachment {
44 NATIVE_ATTACHMENT_FRONT_LEFT,
45 NATIVE_ATTACHMENT_BACK_LEFT,
46 NATIVE_ATTACHMENT_FRONT_RIGHT,
47 NATIVE_ATTACHMENT_BACK_RIGHT,
48
49 NUM_NATIVE_ATTACHMENTS
50 };
51
52 enum native_param_type {
53 /*
54 * Return TRUE if window/pixmap surfaces use the buffers of the native
55 * types.
56 */
57 NATIVE_PARAM_USE_NATIVE_BUFFER
58 };
59
60 struct native_surface {
61 /**
62 * Available for caller's use.
63 */
64 void *user_data;
65
66 void (*destroy)(struct native_surface *nsurf);
67
68 /**
69 * Swap the front and back buffers so that the back buffer is visible. It
70 * is no-op if the surface is single-buffered. The contents of the back
71 * buffer after swapping may or may not be preserved.
72 */
73 boolean (*swap_buffers)(struct native_surface *nsurf);
74
75 /**
76 * Make the front buffer visible. In some native displays, changes to the
77 * front buffer might not be visible immediately and require manual flush.
78 */
79 boolean (*flush_frontbuffer)(struct native_surface *nsurf);
80
81 /**
82 * Validate the buffers of the surface. textures, if not NULL, points to an
83 * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
84 * by the caller. A sequence number is also returned. The caller can use
85 * it to check if anything has changed since the last call. Any of the
86 * pointers may be NULL and it indicates the caller has no interest in those
87 * values.
88 *
89 * If this function is called multiple times with different attachment
90 * masks, those not listed in the latest call might be destroyed. This
91 * behavior might change in the future.
92 */
93 boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
94 unsigned int *seq_num, struct pipe_resource **textures,
95 int *width, int *height);
96
97 /**
98 * Wait until all native commands affecting the surface has been executed.
99 */
100 void (*wait)(struct native_surface *nsurf);
101 };
102
103 /**
104 * Describe a native display config.
105 */
106 struct native_config {
107 /* available buffers and their format */
108 uint buffer_mask;
109 enum pipe_format color_format;
110
111 /* supported surface types */
112 boolean window_bit;
113 boolean pixmap_bit;
114 boolean scanout_bit;
115
116 int native_visual_id;
117 int native_visual_type;
118 int level;
119 int samples;
120 boolean slow_config;
121 boolean transparent_rgb;
122 int transparent_rgb_values[3];
123 };
124
125 /**
126 * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis
127 * hardware. A native display consists of a pipe winsys, a pipe screen, and
128 * the native display server.
129 */
130 struct native_display {
131 /**
132 * The pipe screen of the native display.
133 */
134 struct pipe_screen *screen;
135
136 /**
137 * Available for caller's use.
138 */
139 void *user_data;
140
141 void (*destroy)(struct native_display *ndpy);
142
143 /**
144 * Query the parameters of the native display.
145 *
146 * The return value is defined by the parameter.
147 */
148 int (*get_param)(struct native_display *ndpy,
149 enum native_param_type param);
150
151 /**
152 * Get the supported configs. The configs are owned by the display, but
153 * the returned array should be FREE()ed.
154 */
155 const struct native_config **(*get_configs)(struct native_display *ndpy,
156 int *num_configs);
157
158 /**
159 * Test if a pixmap is supported by the given config. Required unless no
160 * config has pixmap_bit set.
161 *
162 * This function is usually called to find a config that supports a given
163 * pixmap. Thus, it is usually called with the same pixmap in a row.
164 */
165 boolean (*is_pixmap_supported)(struct native_display *ndpy,
166 EGLNativePixmapType pix,
167 const struct native_config *nconf);
168
169
170 /**
171 * Create a window surface. Required unless no config has window_bit set.
172 */
173 struct native_surface *(*create_window_surface)(struct native_display *ndpy,
174 EGLNativeWindowType win,
175 const struct native_config *nconf);
176
177 /**
178 * Create a pixmap surface. Required unless no config has pixmap_bit set.
179 */
180 struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
181 EGLNativePixmapType pix,
182 const struct native_config *nconf);
183
184 const struct native_display_modeset *modeset;
185 };
186
187 /**
188 * The handler for events that a native display may generate. The events are
189 * generated asynchronously and the handler may be called by any thread at any
190 * time.
191 */
192 struct native_event_handler {
193 /**
194 * This function is called when a surface needs to be validated.
195 */
196 void (*invalid_surface)(struct native_display *ndpy,
197 struct native_surface *nsurf,
198 unsigned int seq_num);
199 };
200
201 /**
202 * Test whether an attachment is set in the mask.
203 */
204 static INLINE boolean
205 native_attachment_mask_test(uint mask, enum native_attachment att)
206 {
207 return !!(mask & (1 << att));
208 }
209
210 const char *
211 native_get_name(void);
212
213 struct native_display *
214 native_create_display(EGLNativeDisplayType dpy,
215 struct native_event_handler *handler);
216
217 #endif /* _NATIVE_H_ */