2 * Copyright © 2010 Intel Corporation
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:
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
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.
25 * Kristian Høgsberg <krh@bitplanet.net>
38 #include <GL/internal/dri_interface.h>
41 #include <xcb/xfixes.h>
42 #include <X11/Xlib-xcb.h>
44 #include <glapi/glapi.h>
45 #include "eglconfig.h"
46 #include "eglcontext.h"
47 #include "egldisplay.h"
48 #include "egldriver.h"
49 #include "eglcurrent.h"
51 #include "eglsurface.h"
54 struct dri2_egl_driver
59 struct dri2_egl_display
61 xcb_connection_t
*conn
;
64 __DRIscreen
*dri_screen
;
65 const __DRIconfig
**driver_configs
;
67 __DRIcoreExtension
*core
;
68 __DRIdri2Extension
*dri2
;
69 __DRI2flushExtension
*flush
;
70 __DRItexBufferExtension
*tex_buffer
;
71 __DRIimageExtension
*image
;
77 __DRIdri2LoaderExtension loader_extension
;
78 __DRIimageLookupExtension image_lookup_extension
;
79 const __DRIextension
*extensions
[3];
82 struct dri2_egl_context
85 __DRIcontext
*dri_context
;
88 struct dri2_egl_surface
91 __DRIdrawable
*dri_drawable
;
92 xcb_drawable_t drawable
;
93 __DRIbuffer buffers
[5];
95 xcb_xfixes_region_t region
;
100 struct dri2_egl_config
103 const __DRIconfig
*dri_config
;
106 struct dri2_egl_image
109 __DRIimage
*dri_image
;
112 /* standard typecasts */
113 _EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl
)
114 _EGL_DRIVER_TYPECAST(dri2_egl_image
, _EGLImage
, obj
)
116 EGLint dri2_to_egl_attribute_map
[] = {
118 EGL_BUFFER_SIZE
, /* __DRI_ATTRIB_BUFFER_SIZE */
119 EGL_LEVEL
, /* __DRI_ATTRIB_LEVEL */
120 EGL_RED_SIZE
, /* __DRI_ATTRIB_RED_SIZE */
121 EGL_GREEN_SIZE
, /* __DRI_ATTRIB_GREEN_SIZE */
122 EGL_BLUE_SIZE
, /* __DRI_ATTRIB_BLUE_SIZE */
123 EGL_LUMINANCE_SIZE
, /* __DRI_ATTRIB_LUMINANCE_SIZE */
124 EGL_ALPHA_SIZE
, /* __DRI_ATTRIB_ALPHA_SIZE */
125 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */
126 EGL_DEPTH_SIZE
, /* __DRI_ATTRIB_DEPTH_SIZE */
127 EGL_STENCIL_SIZE
, /* __DRI_ATTRIB_STENCIL_SIZE */
128 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */
129 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */
130 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */
131 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */
132 EGL_SAMPLE_BUFFERS
, /* __DRI_ATTRIB_SAMPLE_BUFFERS */
133 EGL_SAMPLES
, /* __DRI_ATTRIB_SAMPLES */
134 0, /* __DRI_ATTRIB_RENDER_TYPE, */
135 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */
136 0, /* __DRI_ATTRIB_CONFORMANT */
137 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */
138 0, /* __DRI_ATTRIB_STEREO */
139 0, /* __DRI_ATTRIB_AUX_BUFFERS */
140 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */
141 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */
142 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */
143 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */
144 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */
145 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */
146 0, /* __DRI_ATTRIB_FLOAT_MODE */
147 0, /* __DRI_ATTRIB_RED_MASK */
148 0, /* __DRI_ATTRIB_GREEN_MASK */
149 0, /* __DRI_ATTRIB_BLUE_MASK */
150 0, /* __DRI_ATTRIB_ALPHA_MASK */
151 EGL_MAX_PBUFFER_WIDTH
, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */
152 EGL_MAX_PBUFFER_HEIGHT
, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */
153 EGL_MAX_PBUFFER_PIXELS
, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */
154 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */
155 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */
156 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */
157 0, /* __DRI_ATTRIB_SWAP_METHOD */
158 EGL_MAX_SWAP_INTERVAL
, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */
159 EGL_MIN_SWAP_INTERVAL
, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */
160 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */
161 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */
162 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */
163 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
164 0, /* __DRI_ATTRIB_YINVERTED */
168 dri2_add_config(_EGLDisplay
*disp
, const __DRIconfig
*dri_config
, int id
,
169 int depth
, xcb_visualtype_t
*visual
)
171 struct dri2_egl_config
*conf
;
172 struct dri2_egl_display
*dri2_dpy
;
174 unsigned int attrib
, value
, double_buffer
;
175 EGLint key
, bind_to_texture_rgb
, bind_to_texture_rgba
;
178 dri2_dpy
= disp
->DriverData
;
179 _eglInitConfig(&base
, disp
, id
);
182 while (dri2_dpy
->core
->indexConfigAttrib(dri_config
, i
++, &attrib
, &value
)) {
184 case __DRI_ATTRIB_RENDER_TYPE
:
185 if (value
& __DRI_ATTRIB_RGBA_BIT
)
186 value
= EGL_RGB_BUFFER
;
187 else if (value
& __DRI_ATTRIB_LUMINANCE_BIT
)
188 value
= EGL_LUMINANCE_BUFFER
;
191 _eglSetConfigKey(&base
, EGL_COLOR_BUFFER_TYPE
, value
);
194 case __DRI_ATTRIB_CONFIG_CAVEAT
:
195 if (value
& __DRI_ATTRIB_NON_CONFORMANT_CONFIG
)
196 value
= EGL_NON_CONFORMANT_CONFIG
;
197 else if (value
& __DRI_ATTRIB_SLOW_BIT
)
198 value
= EGL_SLOW_CONFIG
;
201 _eglSetConfigKey(&base
, EGL_CONFIG_CAVEAT
, value
);
204 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB
:
205 bind_to_texture_rgb
= value
;
208 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
:
209 bind_to_texture_rgba
= value
;
212 case __DRI_ATTRIB_DOUBLE_BUFFER
:
213 double_buffer
= value
;
217 key
= dri2_to_egl_attribute_map
[attrib
];
219 _eglSetConfigKey(&base
, key
, value
);
224 /* In EGL, double buffer or not isn't a config attribute. Pixmaps
225 * surfaces are always single buffered, pbuffer surfaces are always
226 * back buffers and windows can be either, selected by passing an
227 * attribute at window surface construction time. To support this
228 * we ignore all double buffer configs and manipulate the buffer we
229 * return in the getBuffer callback to get the behaviour we want. */
234 if (visual
!= NULL
) {
235 if (depth
!= _eglGetConfigKey(&base
, EGL_BUFFER_SIZE
))
238 _eglSetConfigKey(&base
, EGL_SURFACE_TYPE
,
239 EGL_WINDOW_BIT
| EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
|
240 EGL_SWAP_BEHAVIOR_PRESERVED_BIT
);
242 _eglSetConfigKey(&base
, EGL_NATIVE_VISUAL_ID
, visual
->visual_id
);
243 _eglSetConfigKey(&base
, EGL_NATIVE_VISUAL_TYPE
, visual
->_class
);
245 _eglSetConfigKey(&base
, EGL_SURFACE_TYPE
,
246 EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
);
249 _eglSetConfigKey(&base
, EGL_NATIVE_RENDERABLE
, EGL_TRUE
);
250 _eglSetConfigKey(&base
, EGL_BIND_TO_TEXTURE_RGB
, bind_to_texture_rgb
);
251 if (_eglGetConfigKey(&base
, EGL_ALPHA_SIZE
) > 0)
252 _eglSetConfigKey(&base
,
253 EGL_BIND_TO_TEXTURE_RGBA
, bind_to_texture_rgba
);
255 /* EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT, EGL_OPENGL_ES2_BIT */
256 _eglSetConfigKey(&base
, EGL_RENDERABLE_TYPE
, EGL_OPENGL_BIT
);
257 _eglSetConfigKey(&base
, EGL_CONFORMANT
, EGL_OPENGL_BIT
);
259 if (!_eglValidateConfig(&base
, EGL_FALSE
)) {
260 _eglLog(_EGL_DEBUG
, "DRI2: failed to validate config %d", id
);
264 conf
= malloc(sizeof *conf
);
266 memcpy(&conf
->base
, &base
, sizeof base
);
267 conf
->dri_config
= dri_config
;
268 _eglAddConfig(disp
, &conf
->base
);
273 * Process list of buffer received from the server
275 * Processes the list of buffers received in a reply from the server to either
276 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
279 dri2_process_buffers(struct dri2_egl_surface
*dri2_surf
,
280 xcb_dri2_dri2_buffer_t
*buffers
, unsigned count
)
282 struct dri2_egl_display
*dri2_dpy
=
283 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
284 xcb_rectangle_t rectangle
;
287 dri2_surf
->buffer_count
= count
;
288 dri2_surf
->have_fake_front
= 0;
290 /* This assumes the DRI2 buffer attachment tokens matches the
291 * __DRIbuffer tokens. */
292 for (i
= 0; i
< count
; i
++) {
293 dri2_surf
->buffers
[i
].attachment
= buffers
[i
].attachment
;
294 dri2_surf
->buffers
[i
].name
= buffers
[i
].name
;
295 dri2_surf
->buffers
[i
].pitch
= buffers
[i
].pitch
;
296 dri2_surf
->buffers
[i
].cpp
= buffers
[i
].cpp
;
297 dri2_surf
->buffers
[i
].flags
= buffers
[i
].flags
;
299 /* We only use the DRI drivers single buffer configs. This
300 * means that if we try to render to a window, DRI2 will give us
301 * the fake front buffer, which we'll use as a back buffer.
302 * Note that EGL doesn't require that several clients rendering
303 * to the same window must see the same aux buffers. */
304 if (dri2_surf
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
305 dri2_surf
->have_fake_front
= 1;
308 if (dri2_surf
->region
!= XCB_NONE
)
309 xcb_xfixes_destroy_region(dri2_dpy
->conn
, dri2_surf
->region
);
313 rectangle
.width
= dri2_surf
->base
.Width
;
314 rectangle
.height
= dri2_surf
->base
.Height
;
315 dri2_surf
->region
= xcb_generate_id(dri2_dpy
->conn
);
316 xcb_xfixes_create_region(dri2_dpy
->conn
, dri2_surf
->region
, 1, &rectangle
);
320 dri2_get_buffers(__DRIdrawable
* driDrawable
,
321 int *width
, int *height
,
322 unsigned int *attachments
, int count
,
323 int *out_count
, void *loaderPrivate
)
325 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
326 struct dri2_egl_display
*dri2_dpy
=
327 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
328 xcb_dri2_dri2_buffer_t
*buffers
;
329 xcb_dri2_get_buffers_reply_t
*reply
;
330 xcb_dri2_get_buffers_cookie_t cookie
;
332 cookie
= xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
334 count
, count
, attachments
);
335 reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
, cookie
, NULL
);
336 buffers
= xcb_dri2_get_buffers_buffers (reply
);
340 *out_count
= reply
->count
;
341 dri2_surf
->base
.Width
= *width
= reply
->width
;
342 dri2_surf
->base
.Height
= *height
= reply
->height
;
343 dri2_process_buffers(dri2_surf
, buffers
, *out_count
);
347 return dri2_surf
->buffers
;
351 dri2_flush_front_buffer(__DRIdrawable
* driDrawable
, void *loaderPrivate
)
353 /* FIXME: Does EGL support front buffer rendering at all? */
356 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
358 dri2WaitGL(dri2_surf
);
363 dri2_lookup_egl_image(__DRIcontext
*context
, void *image
, void *data
)
365 struct dri2_egl_context
*dri2_ctx
= data
;
366 _EGLDisplay
*disp
= dri2_ctx
->base
.Resource
.Display
;
367 struct dri2_egl_image
*dri2_img
;
370 img
= _eglLookupImage(image
, disp
);
372 _eglError(EGL_BAD_PARAMETER
, "dri2_lookup_egl_image");
376 dri2_img
= dri2_egl_image(image
);
378 return dri2_img
->dri_image
;
382 dri2_get_buffers_with_format(__DRIdrawable
* driDrawable
,
383 int *width
, int *height
,
384 unsigned int *attachments
, int count
,
385 int *out_count
, void *loaderPrivate
)
387 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
388 struct dri2_egl_display
*dri2_dpy
=
389 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
390 xcb_dri2_dri2_buffer_t
*buffers
;
391 xcb_dri2_get_buffers_with_format_reply_t
*reply
;
392 xcb_dri2_get_buffers_with_format_cookie_t cookie
;
393 xcb_dri2_attach_format_t
*format_attachments
;
395 format_attachments
= (xcb_dri2_attach_format_t
*) attachments
;
396 cookie
= xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy
->conn
,
401 reply
= xcb_dri2_get_buffers_with_format_reply (dri2_dpy
->conn
,
406 buffers
= xcb_dri2_get_buffers_with_format_buffers (reply
);
407 dri2_surf
->base
.Width
= *width
= reply
->width
;
408 dri2_surf
->base
.Height
= *height
= reply
->height
;
409 *out_count
= reply
->count
;
410 dri2_process_buffers(dri2_surf
, buffers
, *out_count
);
414 return dri2_surf
->buffers
;
418 static const char dri_driver_format
[] = "%.*s/tls/%s_dri.so";
420 static const char dri_driver_format
[] = "%.*s/%s_dri.so";
423 static const char dri_driver_path
[] = DEFAULT_DRIVER_DIR
;
425 struct dri2_extension_match
{
431 static struct dri2_extension_match dri2_driver_extensions
[] = {
432 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
433 { __DRI_DRI2
, 1, offsetof(struct dri2_egl_display
, dri2
) },
437 static struct dri2_extension_match dri2_core_extensions
[] = {
438 { __DRI2_FLUSH
, 1, offsetof(struct dri2_egl_display
, flush
) },
439 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
440 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
445 dri2_bind_extensions(struct dri2_egl_display
*dri2_dpy
,
446 struct dri2_extension_match
*matches
,
447 const __DRIextension
**extensions
)
449 int i
, j
, ret
= EGL_TRUE
;
452 for (i
= 0; extensions
[i
]; i
++) {
453 _eglLog(_EGL_DEBUG
, "DRI2: found extension `%s'", extensions
[i
]->name
);
454 for (j
= 0; matches
[j
].name
; j
++) {
455 if (strcmp(extensions
[i
]->name
, matches
[j
].name
) == 0 &&
456 extensions
[i
]->version
>= matches
[j
].version
) {
457 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
458 *(const __DRIextension
**) field
= extensions
[i
];
459 _eglLog(_EGL_INFO
, "DRI2: found extension %s version %d",
460 extensions
[i
]->name
, extensions
[i
]->version
);
465 for (j
= 0; matches
[j
].name
; j
++) {
466 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
467 if (*(const __DRIextension
**) field
== NULL
) {
468 _eglLog(_EGL_FATAL
, "DRI2: did not find extension %s version %d",
469 matches
[j
].name
, matches
[j
].version
);
478 dri2_strndup(const char *s
, int length
)
482 d
= malloc(length
+ 1);
486 memcpy(d
, s
, length
);
493 dri2_connect(struct dri2_egl_display
*dri2_dpy
)
495 xcb_xfixes_query_version_reply_t
*xfixes_query
;
496 xcb_xfixes_query_version_cookie_t xfixes_query_cookie
;
497 xcb_dri2_query_version_reply_t
*dri2_query
;
498 xcb_dri2_query_version_cookie_t dri2_query_cookie
;
499 xcb_dri2_connect_reply_t
*connect
;
500 xcb_dri2_connect_cookie_t connect_cookie
;
501 xcb_generic_error_t
*error
;
502 xcb_screen_iterator_t s
;
504 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_xfixes_id
);
505 xcb_prefetch_extension_data (dri2_dpy
->conn
, &xcb_dri2_id
);
507 xfixes_query_cookie
= xcb_xfixes_query_version(dri2_dpy
->conn
,
508 XCB_XFIXES_MAJOR_VERSION
,
509 XCB_XFIXES_MINOR_VERSION
);
511 dri2_query_cookie
= xcb_dri2_query_version (dri2_dpy
->conn
,
512 XCB_DRI2_MAJOR_VERSION
,
513 XCB_DRI2_MINOR_VERSION
);
515 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
516 connect_cookie
= xcb_dri2_connect_unchecked (dri2_dpy
->conn
,
518 XCB_DRI2_DRIVER_TYPE_DRI
);
521 xcb_xfixes_query_version_reply (dri2_dpy
->conn
,
522 xfixes_query_cookie
, &error
);
523 if (xfixes_query
== NULL
||
524 error
!= NULL
|| xfixes_query
->major_version
< 2) {
525 _eglLog(_EGL_FATAL
, "DRI2: failed to query xfixes version");
532 xcb_dri2_query_version_reply (dri2_dpy
->conn
, dri2_query_cookie
, &error
);
533 if (dri2_query
== NULL
|| error
!= NULL
) {
534 _eglLog(_EGL_FATAL
, "DRI2: failed to query version");
538 dri2_dpy
->dri2_major
= dri2_query
->major_version
;
539 dri2_dpy
->dri2_minor
= dri2_query
->minor_version
;
542 connect
= xcb_dri2_connect_reply (dri2_dpy
->conn
, connect_cookie
, NULL
);
543 if (connect
== NULL
||
544 connect
->driver_name_length
+ connect
->device_name_length
== 0) {
545 _eglLog(_EGL_FATAL
, "DRI2: failed to authenticate");
549 dri2_dpy
->device_name
=
550 dri2_strndup(xcb_dri2_connect_device_name (connect
),
551 xcb_dri2_connect_device_name_length (connect
));
553 dri2_dpy
->driver_name
=
554 dri2_strndup(xcb_dri2_connect_driver_name (connect
),
555 xcb_dri2_connect_driver_name_length (connect
));
557 if (dri2_dpy
->device_name
== NULL
|| dri2_dpy
->driver_name
== NULL
) {
558 free(dri2_dpy
->device_name
);
559 free(dri2_dpy
->driver_name
);
569 dri2_authenticate(struct dri2_egl_display
*dri2_dpy
)
571 xcb_dri2_authenticate_reply_t
*authenticate
;
572 xcb_dri2_authenticate_cookie_t authenticate_cookie
;
573 xcb_screen_iterator_t s
;
576 if (drmGetMagic(dri2_dpy
->fd
, &magic
)) {
577 _eglLog(_EGL_FATAL
, "DRI2: failed to get drm magic");
581 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
582 authenticate_cookie
=
583 xcb_dri2_authenticate_unchecked(dri2_dpy
->conn
, s
.data
->root
, magic
);
585 xcb_dri2_authenticate_reply(dri2_dpy
->conn
, authenticate_cookie
, NULL
);
586 if (authenticate
== NULL
|| !authenticate
->authenticated
) {
587 _eglLog(_EGL_FATAL
, "DRI2: failed to authenticate");
598 dri2_add_configs_for_visuals(struct dri2_egl_display
*dri2_dpy
,
601 xcb_screen_iterator_t s
;
602 xcb_depth_iterator_t d
;
603 xcb_visualtype_t
*visuals
;
606 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
607 d
= xcb_screen_allowed_depths_iterator(s
.data
);
610 EGLBoolean class_added
[6] = { 0, };
612 visuals
= xcb_depth_visuals(d
.data
);
613 for (i
= 0; i
< xcb_depth_visuals_length(d
.data
); i
++) {
614 if (class_added
[visuals
[i
]._class
])
617 class_added
[visuals
[i
]._class
] = EGL_TRUE
;
618 for (j
= 0; dri2_dpy
->driver_configs
[j
]; j
++)
619 dri2_add_config(disp
, dri2_dpy
->driver_configs
[j
],
620 id
++, d
.data
->depth
, &visuals
[i
]);
626 if (!disp
->NumConfigs
) {
627 _eglLog(_EGL_WARNING
, "DRI2: failed to create any config");
635 * Called via eglInitialize(), GLX_drv->API.Initialize().
638 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
,
639 EGLint
*major
, EGLint
*minor
)
641 const __DRIextension
**extensions
;
642 struct dri2_egl_display
*dri2_dpy
;
643 char path
[PATH_MAX
], *search_paths
, *p
, *next
, *end
;
645 dri2_dpy
= malloc(sizeof *dri2_dpy
);
647 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
649 disp
->DriverData
= (void *) dri2_dpy
;
650 if (disp
->NativeDisplay
== NULL
) {
651 dri2_dpy
->conn
= xcb_connect(0, 0);
652 if (!dri2_dpy
->conn
) {
653 _eglLog(_EGL_WARNING
, "DRI2: xcb_connect failed");
657 dri2_dpy
->conn
= XGetXCBConnection(disp
->NativeDisplay
);
660 if (dri2_dpy
->conn
== NULL
)
663 if (dri2_dpy
->conn
) {
664 if (!dri2_connect(dri2_dpy
))
669 if (geteuid() == getuid()) {
670 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
671 search_paths
= getenv("LIBGL_DRIVERS_PATH");
673 if (search_paths
== NULL
)
674 search_paths
= DEFAULT_DRIVER_DIR
;
676 dri2_dpy
->driver
= NULL
;
677 end
= search_paths
+ strlen(search_paths
);
678 for (p
= search_paths
; p
< end
&& dri2_dpy
->driver
== NULL
; p
= next
+ 1) {
679 next
= strchr(p
, ':');
683 snprintf(path
, sizeof path
,
684 dri_driver_format
, (int) (next
- p
), p
, dri2_dpy
->driver_name
);
685 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
688 if (dri2_dpy
->driver
== NULL
) {
690 "DRI2: failed to open any driver (search paths %s)",
695 _eglLog(_EGL_DEBUG
, "DRI2: dlopen(%s)", path
);
696 extensions
= dlsym(dri2_dpy
->driver
, __DRI_DRIVER_EXTENSIONS
);
697 if (extensions
== NULL
) {
699 "DRI2: driver exports no extensions (%s)", dlerror());
703 if (!dri2_bind_extensions(dri2_dpy
, dri2_driver_extensions
, extensions
))
706 dri2_dpy
->fd
= open(dri2_dpy
->device_name
, O_RDWR
);
707 if (dri2_dpy
->fd
== -1) {
709 "DRI2: could not open %s (%s)", path
, strerror(errno
));
713 if (dri2_dpy
->conn
) {
714 if (!dri2_authenticate(dri2_dpy
))
718 if (dri2_dpy
->dri2_minor
>= 1) {
719 dri2_dpy
->loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
720 dri2_dpy
->loader_extension
.base
.version
= 3;
721 dri2_dpy
->loader_extension
.getBuffers
= dri2_get_buffers
;
722 dri2_dpy
->loader_extension
.flushFrontBuffer
= dri2_flush_front_buffer
;
723 dri2_dpy
->loader_extension
.getBuffersWithFormat
=
724 dri2_get_buffers_with_format
;
726 dri2_dpy
->loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
727 dri2_dpy
->loader_extension
.base
.version
= 2;
728 dri2_dpy
->loader_extension
.getBuffers
= dri2_get_buffers
;
729 dri2_dpy
->loader_extension
.flushFrontBuffer
= dri2_flush_front_buffer
;
730 dri2_dpy
->loader_extension
.getBuffersWithFormat
= NULL
;
733 dri2_dpy
->image_lookup_extension
.base
.name
= __DRI_IMAGE_LOOKUP
;
734 dri2_dpy
->image_lookup_extension
.base
.version
= 1;
735 dri2_dpy
->image_lookup_extension
.lookupEGLImage
= dri2_lookup_egl_image
;
737 dri2_dpy
->extensions
[0] = &dri2_dpy
->loader_extension
.base
;
738 dri2_dpy
->extensions
[1] = &dri2_dpy
->image_lookup_extension
.base
;
739 dri2_dpy
->extensions
[2] = NULL
;
741 dri2_dpy
->dri_screen
=
742 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
, dri2_dpy
->extensions
,
743 &dri2_dpy
->driver_configs
, dri2_dpy
);
745 if (dri2_dpy
->dri_screen
== NULL
) {
746 _eglLog(_EGL_FATAL
, "DRI2: failed to create dri screen");
750 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
751 if (!dri2_bind_extensions(dri2_dpy
, dri2_core_extensions
, extensions
))
752 goto cleanup_dri_screen
;
754 if (dri2_dpy
->conn
) {
755 if (!dri2_add_configs_for_visuals(dri2_dpy
, disp
))
756 goto cleanup_configs
;
759 disp
->ClientAPIsMask
= EGL_OPENGL_BIT
;
760 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
761 disp
->Extensions
.KHR_image_pixmap
= EGL_TRUE
;
762 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
764 /* we're supporting EGL 1.4 */
771 _eglCleanupDisplay(disp
);
773 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
777 dlclose(dri2_dpy
->driver
);
779 if (disp
->NativeDisplay
== NULL
)
780 xcb_disconnect(dri2_dpy
->conn
);
788 * Called via eglTerminate(), drv->API.Terminate().
791 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
793 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
795 _eglReleaseDisplayResources(drv
, disp
);
796 _eglCleanupDisplay(disp
);
798 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
800 dlclose(dri2_dpy
->driver
);
801 if (disp
->NativeDisplay
== NULL
)
802 xcb_disconnect(dri2_dpy
->conn
);
804 disp
->DriverData
= NULL
;
811 * Called via eglCreateContext(), drv->API.CreateContext().
814 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
815 _EGLContext
*share_list
, const EGLint
*attrib_list
)
817 struct dri2_egl_context
*dri2_ctx
;
818 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
819 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
820 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
822 dri2_ctx
= malloc(sizeof *dri2_ctx
);
824 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
828 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
831 dri2_ctx
->dri_context
=
832 dri2_dpy
->dri2
->createNewContext(dri2_dpy
->dri_screen
,
833 dri2_config
->dri_config
,
835 dri2_ctx_shared
->dri_context
: NULL
,
838 if (!dri2_ctx
->dri_context
)
841 return &dri2_ctx
->base
;
849 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
851 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
852 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
854 if (_eglIsSurfaceBound(surf
))
857 (*dri2_dpy
->core
->destroyDrawable
)(dri2_surf
->dri_drawable
);
859 xcb_dri2_destroy_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
861 if (surf
->Type
== EGL_PBUFFER_BIT
)
862 xcb_free_pixmap (dri2_dpy
->conn
, dri2_surf
->drawable
);
870 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
873 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
874 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
876 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
877 struct dri2_egl_surface
*dri2_dsurf
= dri2_egl_surface(dsurf
);
878 struct dri2_egl_surface
*dri2_rsurf
= dri2_egl_surface(rsurf
);
879 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
880 __DRIdrawable
*ddraw
, *rdraw
;
883 /* bind the new context and return the "orphaned" one */
884 if (!_eglBindContext(&ctx
, &dsurf
, &rsurf
))
887 ddraw
= (dri2_dsurf
) ? dri2_dsurf
->dri_drawable
: NULL
;
888 rdraw
= (dri2_rsurf
) ? dri2_rsurf
->dri_drawable
: NULL
;
889 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
891 if ((cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
) ||
892 dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
893 if (dsurf
&& !_eglIsSurfaceLinked(dsurf
))
894 dri2_destroy_surface(drv
, disp
, dsurf
);
895 if (rsurf
&& rsurf
!= dsurf
&& !_eglIsSurfaceLinked(dsurf
))
896 dri2_destroy_surface(drv
, disp
, rsurf
);
897 if (ctx
!= NULL
&& !_eglIsContextLinked(ctx
))
898 dri2_dpy
->core
->unbindContext(dri2_egl_context(ctx
)->dri_context
);
902 _eglBindContext(&ctx
, &dsurf
, &rsurf
);
909 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
912 dri2_create_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint type
,
913 _EGLConfig
*conf
, EGLNativeWindowType window
,
914 const EGLint
*attrib_list
)
916 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
917 struct dri2_egl_config
*dri2_conf
= dri2_egl_config(conf
);
918 struct dri2_egl_surface
*dri2_surf
;
919 xcb_get_geometry_cookie_t cookie
;
920 xcb_get_geometry_reply_t
*reply
;
921 xcb_screen_iterator_t s
;
922 xcb_generic_error_t
*error
;
924 dri2_surf
= malloc(sizeof *dri2_surf
);
926 _eglError(EGL_BAD_ALLOC
, "dri2_create_surface");
930 if (!_eglInitSurface(&dri2_surf
->base
, disp
, type
, conf
, attrib_list
))
933 dri2_surf
->region
= XCB_NONE
;
934 if (type
== EGL_PBUFFER_BIT
) {
935 dri2_surf
->drawable
= xcb_generate_id(dri2_dpy
->conn
);
936 s
= xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy
->conn
));
937 xcb_create_pixmap(dri2_dpy
->conn
,
938 _eglGetConfigKey(conf
, EGL_BUFFER_SIZE
),
939 dri2_surf
->drawable
, s
.data
->root
,
940 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
942 dri2_surf
->drawable
= window
;
945 dri2_surf
->dri_drawable
=
946 (*dri2_dpy
->dri2
->createNewDrawable
) (dri2_dpy
->dri_screen
,
947 dri2_conf
->dri_config
, dri2_surf
);
948 if (dri2_surf
->dri_drawable
== NULL
) {
949 _eglError(EGL_BAD_ALLOC
, "dri2->createNewDrawable");
953 xcb_dri2_create_drawable (dri2_dpy
->conn
, dri2_surf
->drawable
);
955 if (type
!= EGL_PBUFFER_BIT
) {
956 cookie
= xcb_get_geometry (dri2_dpy
->conn
, dri2_surf
->drawable
);
957 reply
= xcb_get_geometry_reply (dri2_dpy
->conn
, cookie
, &error
);
958 if (reply
== NULL
|| error
!= NULL
) {
959 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
961 goto cleanup_dri_drawable
;
964 dri2_surf
->base
.Width
= reply
->width
;
965 dri2_surf
->base
.Height
= reply
->height
;
969 return &dri2_surf
->base
;
971 cleanup_dri_drawable
:
972 dri2_dpy
->core
->destroyDrawable(dri2_surf
->dri_drawable
);
974 if (type
== EGL_PBUFFER_BIT
)
975 xcb_free_pixmap(dri2_dpy
->conn
, dri2_surf
->drawable
);
983 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
986 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
987 _EGLConfig
*conf
, EGLNativeWindowType window
,
988 const EGLint
*attrib_list
)
990 return dri2_create_surface(drv
, disp
, EGL_WINDOW_BIT
, conf
,
991 window
, attrib_list
);
995 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
996 _EGLConfig
*conf
, EGLNativePixmapType pixmap
,
997 const EGLint
*attrib_list
)
999 return dri2_create_surface(drv
, disp
, EGL_PIXMAP_BIT
, conf
,
1000 pixmap
, attrib_list
);
1003 static _EGLSurface
*
1004 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
1005 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1007 return dri2_create_surface(drv
, disp
, EGL_PBUFFER_BIT
, conf
,
1008 XCB_WINDOW_NONE
, attrib_list
);
1012 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
1014 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1015 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(draw
);
1016 xcb_dri2_copy_region_cookie_t cookie
;
1018 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
1021 /* FIXME: Add support for dri swapbuffers, that'll give us swap
1022 * interval and page flipping (at least for fullscreen windows) as
1023 * well as the page flip event. Unless surface->SwapBehavior is
1024 * EGL_BUFFER_PRESERVED. */
1025 #if __DRI2_FLUSH_VERSION >= 2
1027 (*pdraw
->psc
->f
->flushInvalidate
)(pdraw
->driDrawable
);
1031 if (!dri2_surf
->have_fake_front
)
1034 cookie
= xcb_dri2_copy_region_unchecked(dri2_dpy
->conn
,
1035 dri2_surf
->drawable
,
1037 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
,
1038 XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT
);
1039 free(xcb_dri2_copy_region_reply(dri2_dpy
->conn
, cookie
, NULL
));
1045 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1048 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1050 /* FIXME: Do we need to support lookup of EGL symbols too? */
1052 return (_EGLProc
) _glapi_get_proc_address(procname
);
1056 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1058 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1059 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(ctx
->DrawSurface
);
1061 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1062 * we need to copy fake to real here.*/
1064 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
1070 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1072 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1073 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1080 dri2_unload(_EGLDriver
*drv
)
1082 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
1087 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
,
1088 EGLNativePixmapType target
)
1090 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1091 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1094 (*dri2_dpy
->flush
->flush
)(dri2_surf
->dri_drawable
);
1096 gc
= xcb_generate_id(dri2_dpy
->conn
);
1097 xcb_create_gc(dri2_dpy
->conn
, gc
, target
, 0, NULL
);
1098 xcb_copy_area(dri2_dpy
->conn
,
1099 dri2_surf
->drawable
,
1104 dri2_surf
->base
.Width
,
1105 dri2_surf
->base
.Height
);
1106 xcb_free_gc(dri2_dpy
->conn
, gc
);
1112 dri2_bind_tex_image(_EGLDriver
*drv
,
1113 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1115 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1116 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1117 struct dri2_egl_context
*dri2_ctx
;
1119 GLint format
, target
;
1121 ctx
= _eglGetCurrentContext();
1122 dri2_ctx
= dri2_egl_context(ctx
);
1124 if (buffer
!= EGL_BACK_BUFFER
) {
1125 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
1129 /* We allow binding pixmaps too... Not conformat, but we can do it
1130 * for free and it's useful for X compositors. Supposedly there's
1131 * a EGL_NOKIA_texture_from_pixmap extension that allows that, but
1132 * I couldn't find it at this time. */
1133 if ((dri2_surf
->base
.Type
& (EGL_PBUFFER_BIT
| EGL_PIXMAP_BIT
)) == 0) {
1134 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
1138 switch (dri2_surf
->base
.TextureFormat
) {
1139 case EGL_TEXTURE_RGB
:
1140 format
= __DRI_TEXTURE_FORMAT_RGB
;
1142 case EGL_TEXTURE_RGBA
:
1143 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1146 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
1150 switch (dri2_surf
->base
.TextureTarget
) {
1151 case EGL_TEXTURE_2D
:
1152 target
= GL_TEXTURE_2D
;
1155 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
1159 (*dri2_dpy
->tex_buffer
->setTexBuffer2
)(dri2_ctx
->dri_context
,
1161 dri2_surf
->dri_drawable
);
1163 return dri2_surf
->base
.BoundToTexture
= EGL_TRUE
;
1167 dri2_release_tex_image(_EGLDriver
*drv
,
1168 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1174 dri2_create_image_khr_pixmap(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1175 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1177 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1178 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1179 struct dri2_egl_image
*dri2_img
;
1180 unsigned int attachments
[1];
1181 xcb_drawable_t drawable
;
1182 xcb_dri2_get_buffers_cookie_t buffers_cookie
;
1183 xcb_dri2_get_buffers_reply_t
*buffers_reply
;
1184 xcb_dri2_dri2_buffer_t
*buffers
;
1185 xcb_get_geometry_cookie_t geometry_cookie
;
1186 xcb_get_geometry_reply_t
*geometry_reply
;
1187 xcb_generic_error_t
*error
;
1190 drawable
= (xcb_drawable_t
) buffer
;
1191 xcb_dri2_create_drawable (dri2_dpy
->conn
, drawable
);
1192 attachments
[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT
;
1194 xcb_dri2_get_buffers_unchecked (dri2_dpy
->conn
,
1195 drawable
, 1, 1, attachments
);
1196 geometry_cookie
= xcb_get_geometry (dri2_dpy
->conn
, drawable
);
1197 buffers_reply
= xcb_dri2_get_buffers_reply (dri2_dpy
->conn
,
1198 buffers_cookie
, NULL
);
1199 buffers
= xcb_dri2_get_buffers_buffers (buffers_reply
);
1200 if (buffers
== NULL
) {
1204 geometry_reply
= xcb_get_geometry_reply (dri2_dpy
->conn
,
1205 geometry_cookie
, &error
);
1206 if (geometry_reply
== NULL
|| error
!= NULL
) {
1207 _eglError(EGL_BAD_ALLOC
, "xcb_get_geometry");
1209 free(buffers_reply
);
1212 switch (geometry_reply
->depth
) {
1214 format
= __DRI_IMAGE_FORMAT_RGB565
;
1217 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
1220 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
1223 _eglError(EGL_BAD_PARAMETER
,
1224 "dri2_create_image_khr: unsupported pixmap depth");
1225 free(buffers_reply
);
1226 free(geometry_reply
);
1230 dri2_img
= malloc(sizeof *dri2_img
);
1232 free(buffers_reply
);
1233 free(geometry_reply
);
1234 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1235 return EGL_NO_IMAGE_KHR
;
1238 if (!_eglInitImage(&dri2_img
->base
, disp
, attr_list
)) {
1239 free(buffers_reply
);
1240 free(geometry_reply
);
1241 return EGL_NO_IMAGE_KHR
;
1244 stride
= buffers
[0].pitch
/ buffers
[0].cpp
;
1245 dri2_img
->dri_image
=
1246 dri2_dpy
->image
->createImageFromName(dri2_ctx
->dri_context
,
1247 buffers_reply
->width
,
1248 buffers_reply
->height
,
1254 free(buffers_reply
);
1255 free(geometry_reply
);
1257 return &dri2_img
->base
;
1261 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1262 EGLClientBuffer buffer
,
1263 const EGLint
*attr_list
)
1265 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1266 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1267 struct dri2_egl_image
*dri2_img
;
1268 GLuint renderbuffer
= (GLuint
) buffer
;
1270 if (renderbuffer
== 0) {
1271 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1272 return EGL_NO_IMAGE_KHR
;
1275 dri2_img
= malloc(sizeof *dri2_img
);
1277 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1278 return EGL_NO_IMAGE_KHR
;
1281 if (!_eglInitImage(&dri2_img
->base
, disp
, attr_list
))
1282 return EGL_NO_IMAGE_KHR
;
1284 dri2_img
->dri_image
=
1285 dri2_dpy
->image
->createImageFromRenderbuffer(dri2_ctx
->dri_context
,
1289 return &dri2_img
->base
;
1293 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
1294 _EGLContext
*ctx
, EGLenum target
,
1295 EGLClientBuffer buffer
, const EGLint
*attr_list
)
1298 case EGL_NATIVE_PIXMAP_KHR
:
1299 return dri2_create_image_khr_pixmap(disp
, ctx
, buffer
, attr_list
);
1300 case EGL_GL_RENDERBUFFER_KHR
:
1301 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
1303 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1304 return EGL_NO_IMAGE_KHR
;
1309 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
1311 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1312 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
1314 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
1321 * This is the main entrypoint into the driver, called by libEGL.
1322 * Create a new _EGLDriver object and init its dispatch table.
1325 _eglMain(const char *args
)
1327 struct dri2_egl_driver
*dri2_drv
;
1329 dri2_drv
= malloc(sizeof *dri2_drv
);
1333 _eglInitDriverFallbacks(&dri2_drv
->base
);
1334 dri2_drv
->base
.API
.Initialize
= dri2_initialize
;
1335 dri2_drv
->base
.API
.Terminate
= dri2_terminate
;
1336 dri2_drv
->base
.API
.CreateContext
= dri2_create_context
;
1337 dri2_drv
->base
.API
.MakeCurrent
= dri2_make_current
;
1338 dri2_drv
->base
.API
.CreateWindowSurface
= dri2_create_window_surface
;
1339 dri2_drv
->base
.API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
1340 dri2_drv
->base
.API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
1341 dri2_drv
->base
.API
.DestroySurface
= dri2_destroy_surface
;
1342 dri2_drv
->base
.API
.SwapBuffers
= dri2_swap_buffers
;
1343 dri2_drv
->base
.API
.GetProcAddress
= dri2_get_proc_address
;
1344 dri2_drv
->base
.API
.WaitClient
= dri2_wait_client
;
1345 dri2_drv
->base
.API
.WaitNative
= dri2_wait_native
;
1346 dri2_drv
->base
.API
.CopyBuffers
= dri2_copy_buffers
;
1347 dri2_drv
->base
.API
.BindTexImage
= dri2_bind_tex_image
;
1348 dri2_drv
->base
.API
.ReleaseTexImage
= dri2_release_tex_image
;
1349 dri2_drv
->base
.API
.CreateImageKHR
= dri2_create_image_khr
;
1350 dri2_drv
->base
.API
.DestroyImageKHR
= dri2_destroy_image_khr
;
1352 dri2_drv
->base
.Name
= "DRI2";
1353 dri2_drv
->base
.Unload
= dri2_unload
;
1355 return &dri2_drv
->base
;