Subversion Repositories Kolibri OS

Rev

Rev 4358 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 2009-2010 Chia-I Wu 
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 */
24
 
25
#ifndef _NATIVE_H_
26
#define _NATIVE_H_
27
 
28
#include "EGL/egl.h"  /* for EGL native types */
29
 
30
#include "pipe/p_compiler.h"
31
#include "pipe/p_screen.h"
32
#include "pipe/p_context.h"
33
#include "pipe/p_state.h"
34
#include "state_tracker/sw_winsys.h"
35
 
36
#ifdef __cplusplus
37
extern "C" {
38
#endif
39
 
40
#include "native_buffer.h"
41
#include "native_modeset.h"
42
#include "native_wayland_bufmgr.h"
43
 
44
/**
45
 * Only color buffers are listed.  The others are allocated privately through,
46
 * for example, st_renderbuffer_alloc_storage().
47
 */
48
enum native_attachment {
49
   NATIVE_ATTACHMENT_FRONT_LEFT,
50
   NATIVE_ATTACHMENT_BACK_LEFT,
51
   NATIVE_ATTACHMENT_FRONT_RIGHT,
52
   NATIVE_ATTACHMENT_BACK_RIGHT,
53
 
54
   NUM_NATIVE_ATTACHMENTS
55
};
56
 
57
enum native_param_type {
58
   /*
59
    * Return TRUE if window/pixmap surfaces use the buffers of the native
60
    * types.
61
    */
62
   NATIVE_PARAM_USE_NATIVE_BUFFER,
63
 
64
   /**
65
    * Return TRUE if native_surface::present can preserve the buffer.
66
    */
67
   NATIVE_PARAM_PRESERVE_BUFFER,
68
 
69
   /**
70
    * Return the maximum supported swap interval.
71
    */
72
   NATIVE_PARAM_MAX_SWAP_INTERVAL,
73
 
74
   /**
75
    * Return TRUE if the display supports premultiplied alpha, regardless of
76
    * the surface color format.
77
    *
78
    * Note that returning TRUE for this parameter will make
79
    * EGL_VG_ALPHA_FORMAT_PRE_BIT to be set for all EGLConfig's with non-zero
80
    * EGL_ALPHA_SIZE.  EGL_VG_ALPHA_FORMAT attribute of a surface will affect
81
    * how the surface is presented.
82
    */
83
   NATIVE_PARAM_PREMULTIPLIED_ALPHA,
84
 
85
   /**
86
    * Return TRUE if native_surface::present supports presenting a partial
87
    * surface.
88
    */
89
   NATIVE_PARAM_PRESENT_REGION
90
};
91
 
92
/**
93
 * Control how a surface presentation should happen.
94
 */
95
struct native_present_control {
96
   /**< the attachment to present */
97
   enum native_attachment natt;
98
 
99
   /**< the contents of the presented attachment should be preserved */
100
   boolean preserve;
101
 
102
   /**< wait until the given vsyncs has passed since the last presentation */
103
   uint swap_interval;
104
 
105
   /**< pixels use premultiplied alpha */
106
   boolean premultiplied_alpha;
107
 
108
   /**< The region to present. y=0=top.
109
        If num_rects is 0, the whole surface is to be presented */
110
   int num_rects;
111
   const int *rects; /* x, y, width, height */
112
};
113
 
114
struct native_surface {
115
   /**
116
    * Available for caller's use.
117
    */
118
   void *user_data;
119
 
120
   void (*destroy)(struct native_surface *nsurf);
121
 
122
   /**
123
    * Present the given buffer to the native engine.
124
    */
125
   boolean (*present)(struct native_surface *nsurf,
126
                      const struct native_present_control *ctrl);
127
 
128
   /**
129
    * Validate the buffers of the surface.  textures, if not NULL, points to an
130
    * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
131
    * by the caller.  A sequence number is also returned.  The caller can use
132
    * it to check if anything has changed since the last call. Any of the
133
    * pointers may be NULL and it indicates the caller has no interest in those
134
    * values.
135
    *
136
    * If this function is called multiple times with different attachment
137
    * masks, those not listed in the latest call might be destroyed.  This
138
    * behavior might change in the future.
139
    */
140
   boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
141
                       unsigned int *seq_num, struct pipe_resource **textures,
142
                       int *width, int *height);
143
 
144
   /**
145
    * Wait until all native commands affecting the surface has been executed.
146
    */
147
   void (*wait)(struct native_surface *nsurf);
148
};
149
 
150
/**
151
 * Describe a native display config.
152
 */
153
struct native_config {
154
   /* available buffers and their format */
155
   uint buffer_mask;
156
   enum pipe_format color_format;
157
 
158
   /* supported surface types */
159
   boolean window_bit;
160
   boolean pixmap_bit;
161
   boolean scanout_bit;
162
 
163
   int native_visual_id;
164
   int native_visual_type;
165
   int level;
166
   boolean transparent_rgb;
167
   int transparent_rgb_values[3];
168
};
169
 
170
/**
171
 * A pipe winsys abstracts the OS.  A pipe screen abstracts the graphcis
172
 * hardware.  A native display consists of a pipe winsys, a pipe screen, and
173
 * the native display server.
174
 */
175
struct native_display {
176
   /**
177
    * The pipe screen of the native display.
178
    */
179
   struct pipe_screen *screen;
180
 
181
   /**
182
    * Context used for copy operations.
183
    */
184
   struct pipe_context *pipe;
185
 
186
   /**
187
    * Available for caller's use.
188
    */
189
   void *user_data;
190
 
191
   /**
192
    * Initialize and create the pipe screen.
193
    */
194
   boolean (*init_screen)(struct native_display *ndpy);
195
 
196
   void (*destroy)(struct native_display *ndpy);
197
 
198
   /**
199
    * Query the parameters of the native display.
200
    *
201
    * The return value is defined by the parameter.
202
    */
203
   int (*get_param)(struct native_display *ndpy,
204
                    enum native_param_type param);
205
 
206
   /**
207
    * Get the supported configs.  The configs are owned by the display, but
208
    * the returned array should be FREE()ed.
209
    */
210
   const struct native_config **(*get_configs)(struct native_display *ndpy,
211
                                               int *num_configs);
212
 
213
   /**
214
    * Get the color format of the pixmap.  Required unless no config has
215
    * pixmap_bit set.
216
    */
217
   boolean (*get_pixmap_format)(struct native_display *ndpy,
218
                                EGLNativePixmapType pix,
219
                                enum pipe_format *format);
220
 
221
   /**
222
    * Copy the contents of the resource to the pixmap's front-left attachment.
223
    * This is used to implement eglCopyBuffers.  Required unless no config has
224
    * pixmap_bit set.
225
    */
226
   boolean (*copy_to_pixmap)(struct native_display *ndpy,
227
                             EGLNativePixmapType pix,
228
                             struct pipe_resource *src);
229
 
230
   /**
231
    * Create a window surface.  Required unless no config has window_bit set.
232
    */
233
   struct native_surface *(*create_window_surface)(struct native_display *ndpy,
234
                                                   EGLNativeWindowType win,
235
                                                   const struct native_config *nconf);
236
 
237
   /**
238
    * Create a pixmap surface.  The native config may be NULL.  In that case, a
239
    * "best config" will be picked.  Required unless no config has pixmap_bit
240
    * set.
241
    */
242
   struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
243
                                                   EGLNativePixmapType pix,
244
                                                   const struct native_config *nconf);
245
 
246
   const struct native_display_buffer *buffer;
247
   const struct native_display_modeset *modeset;
248
   const struct native_display_wayland_bufmgr *wayland_bufmgr;
4401 Serge 249
 
250
#ifdef HAVE_WAYLAND_BACKEND
251
   struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
252
#endif
4358 Serge 253
};
254
 
255
/**
256
 * The handler for events that a native display may generate.  The events are
257
 * generated asynchronously and the handler may be called by any thread at any
258
 * time.
259
 */
260
struct native_event_handler {
261
   /**
262
    * This function is called when a surface needs to be validated.
263
    */
264
   void (*invalid_surface)(struct native_display *ndpy,
265
                           struct native_surface *nsurf,
266
                           unsigned int seq_num);
267
 
268
   struct pipe_screen *(*new_drm_screen)(struct native_display *ndpy,
269
                                         const char *name, int fd);
270
   struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy,
271
                                        struct sw_winsys *ws);
272
 
273
   struct pipe_resource *(*lookup_egl_image)(struct native_display *ndpy,
274
                                             void *egl_image);
275
};
276
 
277
/**
278
 * Test whether an attachment is set in the mask.
279
 */
280
static INLINE boolean
281
native_attachment_mask_test(uint mask, enum native_attachment att)
282
{
283
   return !!(mask & (1 << att));
284
}
285
 
286
/**
287
 * Get the display copy context
288
 */
289
static INLINE struct pipe_context *
290
ndpy_get_copy_context(struct native_display *ndpy)
291
{
292
   if (!ndpy->pipe)
293
      ndpy->pipe = ndpy->screen->context_create(ndpy->screen, NULL);
294
   return ndpy->pipe;
295
}
296
 
297
/**
298
 * Free display screen and context resources
299
 */
300
static INLINE void
301
ndpy_uninit(struct native_display *ndpy)
302
{
303
   if (ndpy->pipe)
304
      ndpy->pipe->destroy(ndpy->pipe);
305
   if (ndpy->screen)
306
      ndpy->screen->destroy(ndpy->screen);
307
}
308
 
309
struct native_platform {
310
   const char *name;
311
 
312
   /**
313
    * Create the native display and usually establish a connection to the
314
    * display server.
315
    *
316
    * No event should be generated at this stage.
317
    */
318
   struct native_display *(*create_display)(void *dpy, boolean use_sw);
319
};
320
 
321
const struct native_platform *
322
native_get_gdi_platform(const struct native_event_handler *event_handler);
323
 
324
const struct native_platform *
325
native_get_x11_platform(const struct native_event_handler *event_handler);
326
 
327
const struct native_platform *
328
native_get_wayland_platform(const struct native_event_handler *event_handler);
329
 
330
const struct native_platform *
331
native_get_drm_platform(const struct native_event_handler *event_handler);
332
 
333
const struct native_platform *
334
native_get_fbdev_platform(const struct native_event_handler *event_handler);
335
 
336
const struct native_platform *
337
native_get_null_platform(const struct native_event_handler *event_handler);
338
 
339
const struct native_platform *
340
native_get_android_platform(const struct native_event_handler *event_handler);
341
 
342
#ifdef __cplusplus
343
}
344
#endif
345
 
346
#endif /* _NATIVE_H_ */