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.
26 #include "util/u_memory.h"
27 #include "util/u_math.h"
28 #include "util/u_format.h"
29 #include "util/u_inlines.h"
30 #include "util/u_hash_table.h"
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/drm_api.h"
38 #include "native_x11.h"
39 #include "x11_screen.h"
41 enum dri2_surface_type
{
42 DRI2_SURFACE_TYPE_WINDOW
,
43 DRI2_SURFACE_TYPE_PIXMAP
,
47 struct native_display base
;
51 struct native_event_handler
*event_handler
;
54 struct x11_screen
*xscr
;
56 const char *dri_driver
;
57 int dri_major
, dri_minor
;
59 struct dri2_config
*configs
;
62 struct util_hash_table
*surfaces
;
66 struct native_surface base
;
68 enum dri2_surface_type type
;
69 enum pipe_format color_format
;
70 struct dri2_display
*dri2dpy
;
72 unsigned int server_stamp
;
73 unsigned int client_stamp
;
75 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
78 boolean have_back
, have_fake
;
80 struct x11_drawable_buffer
*last_xbufs
;
85 struct native_config base
;
88 static INLINE
struct dri2_display
*
89 dri2_display(const struct native_display
*ndpy
)
91 return (struct dri2_display
*) ndpy
;
94 static INLINE
struct dri2_surface
*
95 dri2_surface(const struct native_surface
*nsurf
)
97 return (struct dri2_surface
*) nsurf
;
100 static INLINE
struct dri2_config
*
101 dri2_config(const struct native_config
*nconf
)
103 return (struct dri2_config
*) nconf
;
107 * Process the buffers returned by the server.
110 dri2_surface_process_drawable_buffers(struct native_surface
*nsurf
,
111 struct x11_drawable_buffer
*xbufs
,
114 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
115 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
116 struct pipe_resource templ
;
117 struct winsys_handle whandle
;
121 /* free the old textures */
122 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++)
123 pipe_resource_reference(&dri2surf
->textures
[i
], NULL
);
124 dri2surf
->valid_mask
= 0x0;
126 dri2surf
->have_back
= FALSE
;
127 dri2surf
->have_fake
= FALSE
;
132 memset(&templ
, 0, sizeof(templ
));
133 templ
.target
= PIPE_TEXTURE_2D
;
134 templ
.last_level
= 0;
135 templ
.width0
= dri2surf
->width
;
136 templ
.height0
= dri2surf
->height
;
138 templ
.format
= dri2surf
->color_format
;
139 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
142 for (i
= 0; i
< num_xbufs
; i
++) {
143 struct x11_drawable_buffer
*xbuf
= &xbufs
[i
];
145 enum native_attachment natt
;
147 switch (xbuf
->attachment
) {
148 case DRI2BufferFrontLeft
:
149 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
150 desc
= "DRI2 Front Buffer";
152 case DRI2BufferFakeFrontLeft
:
153 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
154 desc
= "DRI2 Fake Front Buffer";
155 dri2surf
->have_fake
= TRUE
;
157 case DRI2BufferBackLeft
:
158 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
159 desc
= "DRI2 Back Buffer";
160 dri2surf
->have_back
= TRUE
;
167 if (!desc
|| dri2surf
->textures
[natt
]) {
169 _eglLog(_EGL_WARNING
, "unknown buffer %d", xbuf
->attachment
);
171 _eglLog(_EGL_WARNING
, "both real and fake front buffers are listed");
175 memset(&whandle
, 0, sizeof(whandle
));
176 whandle
.stride
= xbuf
->pitch
;
177 whandle
.handle
= xbuf
->name
;
178 dri2surf
->textures
[natt
] = dri2dpy
->base
.screen
->resource_from_handle(
179 dri2dpy
->base
.screen
, &templ
, &whandle
);
180 if (dri2surf
->textures
[natt
])
181 valid_mask
|= 1 << natt
;
184 dri2surf
->valid_mask
= valid_mask
;
188 * Get the buffers from the server.
191 dri2_surface_get_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
193 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
194 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
195 unsigned int dri2atts
[NUM_NATIVE_ATTACHMENTS
];
196 int num_ins
, num_outs
, att
;
197 struct x11_drawable_buffer
*xbufs
;
199 /* prepare the attachments */
201 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
202 if (native_attachment_mask_test(buffer_mask
, att
)) {
203 unsigned int dri2att
;
206 case NATIVE_ATTACHMENT_FRONT_LEFT
:
207 dri2att
= DRI2BufferFrontLeft
;
209 case NATIVE_ATTACHMENT_BACK_LEFT
:
210 dri2att
= DRI2BufferBackLeft
;
212 case NATIVE_ATTACHMENT_FRONT_RIGHT
:
213 dri2att
= DRI2BufferFrontRight
;
215 case NATIVE_ATTACHMENT_BACK_RIGHT
:
216 dri2att
= DRI2BufferBackRight
;
224 dri2atts
[num_ins
] = dri2att
;
229 xbufs
= x11_drawable_get_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
230 &dri2surf
->width
, &dri2surf
->height
,
231 dri2atts
, FALSE
, num_ins
, &num_outs
);
233 /* we should be able to do better... */
234 if (xbufs
&& dri2surf
->last_num_xbufs
== num_outs
&&
235 memcmp(dri2surf
->last_xbufs
, xbufs
, sizeof(*xbufs
) * num_outs
) == 0) {
237 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
241 dri2_surface_process_drawable_buffers(&dri2surf
->base
, xbufs
, num_outs
);
243 dri2surf
->server_stamp
++;
244 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
246 if (dri2surf
->last_xbufs
)
247 FREE(dri2surf
->last_xbufs
);
248 dri2surf
->last_xbufs
= xbufs
;
249 dri2surf
->last_num_xbufs
= num_outs
;
253 * Update the buffers of the surface. This is a slow function due to the
254 * round-trip to the server.
257 dri2_surface_update_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
259 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
261 dri2_surface_get_buffers(&dri2surf
->base
, buffer_mask
);
263 return ((dri2surf
->valid_mask
& buffer_mask
) == buffer_mask
);
267 * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
269 static INLINE boolean
270 dri2_surface_receive_events(struct native_surface
*nsurf
)
272 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
273 return (dri2surf
->dri2dpy
->dri_minor
>= 3);
277 dri2_surface_flush_frontbuffer(struct native_surface
*nsurf
)
279 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
280 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
282 /* copy to real front buffer */
283 if (dri2surf
->have_fake
)
284 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
285 0, 0, dri2surf
->width
, dri2surf
->height
,
286 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
288 /* force buffers to be updated in next validation call */
289 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
290 dri2surf
->server_stamp
++;
291 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
292 &dri2surf
->base
, dri2surf
->server_stamp
);
299 dri2_surface_swap_buffers(struct native_surface
*nsurf
)
301 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
302 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
304 /* copy to front buffer */
305 if (dri2surf
->have_back
)
306 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
307 0, 0, dri2surf
->width
, dri2surf
->height
,
308 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
310 /* and update fake front buffer */
311 if (dri2surf
->have_fake
)
312 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
313 0, 0, dri2surf
->width
, dri2surf
->height
,
314 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
316 /* force buffers to be updated in next validation call */
317 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
318 dri2surf
->server_stamp
++;
319 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
320 &dri2surf
->base
, dri2surf
->server_stamp
);
327 dri2_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
328 unsigned int *seq_num
, struct pipe_resource
**textures
,
329 int *width
, int *height
)
331 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
333 if (dri2surf
->server_stamp
!= dri2surf
->client_stamp
||
334 (dri2surf
->valid_mask
& attachment_mask
) != attachment_mask
) {
335 if (!dri2_surface_update_buffers(&dri2surf
->base
, attachment_mask
))
340 *seq_num
= dri2surf
->client_stamp
;
344 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
345 if (native_attachment_mask_test(attachment_mask
, att
)) {
346 struct pipe_resource
*ptex
= dri2surf
->textures
[att
];
348 textures
[att
] = NULL
;
349 pipe_resource_reference(&textures
[att
], ptex
);
355 *width
= dri2surf
->width
;
357 *height
= dri2surf
->height
;
363 dri2_surface_wait(struct native_surface
*nsurf
)
365 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
366 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
368 if (dri2surf
->have_fake
) {
369 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
370 0, 0, dri2surf
->width
, dri2surf
->height
,
371 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
376 dri2_surface_destroy(struct native_surface
*nsurf
)
378 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
381 if (dri2surf
->last_xbufs
)
382 FREE(dri2surf
->last_xbufs
);
384 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
385 struct pipe_resource
*ptex
= dri2surf
->textures
[i
];
386 pipe_resource_reference(&ptex
, NULL
);
389 if (dri2surf
->drawable
) {
390 x11_drawable_enable_dri2(dri2surf
->dri2dpy
->xscr
,
391 dri2surf
->drawable
, FALSE
);
393 util_hash_table_remove(dri2surf
->dri2dpy
->surfaces
,
394 (void *) dri2surf
->drawable
);
399 static struct dri2_surface
*
400 dri2_display_create_surface(struct native_display
*ndpy
,
401 enum dri2_surface_type type
,
403 const struct native_config
*nconf
)
405 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
406 struct dri2_config
*dri2conf
= dri2_config(nconf
);
407 struct dri2_surface
*dri2surf
;
409 dri2surf
= CALLOC_STRUCT(dri2_surface
);
413 dri2surf
->dri2dpy
= dri2dpy
;
414 dri2surf
->type
= type
;
415 dri2surf
->drawable
= drawable
;
416 dri2surf
->color_format
= dri2conf
->base
.color_format
;
418 dri2surf
->base
.destroy
= dri2_surface_destroy
;
419 dri2surf
->base
.swap_buffers
= dri2_surface_swap_buffers
;
420 dri2surf
->base
.flush_frontbuffer
= dri2_surface_flush_frontbuffer
;
421 dri2surf
->base
.validate
= dri2_surface_validate
;
422 dri2surf
->base
.wait
= dri2_surface_wait
;
425 x11_drawable_enable_dri2(dri2dpy
->xscr
, drawable
, TRUE
);
426 /* initialize the geometry */
427 dri2_surface_update_buffers(&dri2surf
->base
, 0x0);
429 util_hash_table_set(dri2surf
->dri2dpy
->surfaces
,
430 (void *) dri2surf
->drawable
, (void *) &dri2surf
->base
);
436 static struct native_surface
*
437 dri2_display_create_window_surface(struct native_display
*ndpy
,
438 EGLNativeWindowType win
,
439 const struct native_config
*nconf
)
441 struct dri2_surface
*dri2surf
;
443 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_WINDOW
,
444 (Drawable
) win
, nconf
);
445 return (dri2surf
) ? &dri2surf
->base
: NULL
;
448 static struct native_surface
*
449 dri2_display_create_pixmap_surface(struct native_display
*ndpy
,
450 EGLNativePixmapType pix
,
451 const struct native_config
*nconf
)
453 struct dri2_surface
*dri2surf
;
455 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_PIXMAP
,
456 (Drawable
) pix
, nconf
);
457 return (dri2surf
) ? &dri2surf
->base
: NULL
;
461 choose_color_format(const __GLcontextModes
*mode
, enum pipe_format formats
[32])
465 switch (mode
->rgbBits
) {
467 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
468 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
471 formats
[count
++] = PIPE_FORMAT_B8G8R8X8_UNORM
;
472 formats
[count
++] = PIPE_FORMAT_X8R8G8B8_UNORM
;
473 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
474 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
477 formats
[count
++] = PIPE_FORMAT_B5G6R5_UNORM
;
487 is_format_supported(struct pipe_screen
*screen
,
488 enum pipe_format fmt
, boolean is_color
)
490 return screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
,
491 (is_color
) ? PIPE_BIND_RENDER_TARGET
:
492 PIPE_BIND_DEPTH_STENCIL
, 0);
496 dri2_display_convert_config(struct native_display
*ndpy
,
497 const __GLcontextModes
*mode
,
498 struct native_config
*nconf
)
500 enum pipe_format formats
[32];
503 if (!(mode
->renderType
& GLX_RGBA_BIT
) || !mode
->rgbMode
)
506 /* skip single-buffered configs */
507 if (!mode
->doubleBufferMode
)
510 /* only interested in native renderable configs */
511 if (!mode
->xRenderable
|| !mode
->drawableType
)
514 nconf
->buffer_mask
= 1 << NATIVE_ATTACHMENT_FRONT_LEFT
;
515 if (mode
->doubleBufferMode
)
516 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_LEFT
;
517 if (mode
->stereoMode
) {
518 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT
;
519 if (mode
->doubleBufferMode
)
520 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_RIGHT
;
523 /* choose color format */
524 num_formats
= choose_color_format(mode
, formats
);
525 for (i
= 0; i
< num_formats
; i
++) {
526 if (is_format_supported(ndpy
->screen
, formats
[i
], TRUE
)) {
527 nconf
->color_format
= formats
[i
];
531 if (nconf
->color_format
== PIPE_FORMAT_NONE
)
534 if (mode
->drawableType
& GLX_WINDOW_BIT
)
535 nconf
->window_bit
= TRUE
;
536 if (mode
->drawableType
& GLX_PIXMAP_BIT
)
537 nconf
->pixmap_bit
= TRUE
;
539 nconf
->native_visual_id
= mode
->visualID
;
540 nconf
->native_visual_type
= mode
->visualType
;
541 nconf
->level
= mode
->level
;
542 nconf
->samples
= mode
->samples
;
544 nconf
->slow_config
= (mode
->visualRating
== GLX_SLOW_CONFIG
);
546 if (mode
->transparentPixel
== GLX_TRANSPARENT_RGB
) {
547 nconf
->transparent_rgb
= TRUE
;
548 nconf
->transparent_rgb_values
[0] = mode
->transparentRed
;
549 nconf
->transparent_rgb_values
[1] = mode
->transparentGreen
;
550 nconf
->transparent_rgb_values
[2] = mode
->transparentBlue
;
556 static const struct native_config
**
557 dri2_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
559 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
560 const struct native_config
**configs
;
564 if (!dri2dpy
->configs
) {
565 const __GLcontextModes
*modes
;
566 int num_modes
, count
;
568 modes
= x11_screen_get_glx_configs(dri2dpy
->xscr
);
571 num_modes
= x11_context_modes_count(modes
);
573 dri2dpy
->configs
= CALLOC(num_modes
, sizeof(*dri2dpy
->configs
));
574 if (!dri2dpy
->configs
)
578 for (i
= 0; i
< num_modes
; i
++) {
579 struct native_config
*nconf
= &dri2dpy
->configs
[count
].base
;
580 if (dri2_display_convert_config(&dri2dpy
->base
, modes
, nconf
))
585 dri2dpy
->num_configs
= count
;
588 configs
= MALLOC(dri2dpy
->num_configs
* sizeof(*configs
));
590 for (i
= 0; i
< dri2dpy
->num_configs
; i
++)
591 configs
[i
] = (const struct native_config
*) &dri2dpy
->configs
[i
];
593 *num_configs
= dri2dpy
->num_configs
;
600 dri2_display_is_pixmap_supported(struct native_display
*ndpy
,
601 EGLNativePixmapType pix
,
602 const struct native_config
*nconf
)
604 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
605 uint depth
, nconf_depth
;
607 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
608 nconf_depth
= util_format_get_blocksizebits(nconf
->color_format
);
610 /* simple depth match for now */
611 return (depth
== nconf_depth
|| (depth
== 24 && depth
+ 8 == nconf_depth
));
615 dri2_display_get_param(struct native_display
*ndpy
,
616 enum native_param_type param
)
621 case NATIVE_PARAM_USE_NATIVE_BUFFER
:
622 /* DRI2GetBuffers use the native buffers */
634 dri2_display_destroy(struct native_display
*ndpy
)
636 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
638 if (dri2dpy
->configs
)
639 FREE(dri2dpy
->configs
);
641 if (dri2dpy
->base
.screen
)
642 dri2dpy
->base
.screen
->destroy(dri2dpy
->base
.screen
);
644 if (dri2dpy
->surfaces
)
645 util_hash_table_destroy(dri2dpy
->surfaces
);
648 x11_screen_destroy(dri2dpy
->xscr
);
649 if (dri2dpy
->own_dpy
)
650 XCloseDisplay(dri2dpy
->dpy
);
651 if (dri2dpy
->api
&& dri2dpy
->api
->destroy
)
652 dri2dpy
->api
->destroy(dri2dpy
->api
);
657 dri2_display_invalidate_buffers(struct x11_screen
*xscr
, Drawable drawable
,
660 struct native_display
*ndpy
= (struct native_display
* ) user_data
;
661 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
662 struct native_surface
*nsurf
;
663 struct dri2_surface
*dri2surf
;
665 nsurf
= (struct native_surface
*)
666 util_hash_table_get(dri2dpy
->surfaces
, (void *) drawable
);
670 dri2surf
= dri2_surface(nsurf
);
672 dri2surf
->server_stamp
++;
673 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
674 &dri2surf
->base
, dri2surf
->server_stamp
);
678 * Initialize DRI2 and pipe screen.
681 dri2_display_init_screen(struct native_display
*ndpy
)
683 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
684 const char *driver
= dri2dpy
->api
->name
;
685 struct drm_create_screen_arg arg
;
688 if (!x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_DRI2
) ||
689 !x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_GLX
)) {
690 _eglLog(_EGL_WARNING
, "GLX/DRI2 is not supported");
694 dri2dpy
->dri_driver
= x11_screen_probe_dri2(dri2dpy
->xscr
,
695 &dri2dpy
->dri_major
, &dri2dpy
->dri_minor
);
696 if (!dri2dpy
->dri_driver
|| !driver
||
697 strcmp(dri2dpy
->dri_driver
, driver
) != 0) {
698 _eglLog(_EGL_WARNING
, "Driver mismatch: %s != %s",
699 dri2dpy
->dri_driver
, dri2dpy
->api
->name
);
703 fd
= x11_screen_enable_dri2(dri2dpy
->xscr
,
704 dri2_display_invalidate_buffers
, &dri2dpy
->base
);
708 memset(&arg
, 0, sizeof(arg
));
709 arg
.mode
= DRM_CREATE_NORMAL
;
710 dri2dpy
->base
.screen
= dri2dpy
->api
->create_screen(dri2dpy
->api
, fd
, &arg
);
711 if (!dri2dpy
->base
.screen
) {
712 _eglLog(_EGL_WARNING
, "failed to create DRM screen");
720 dri2_display_hash_table_hash(void *key
)
722 XID drawable
= pointer_to_uintptr(key
);
723 return (unsigned) drawable
;
727 dri2_display_hash_table_compare(void *key1
, void *key2
)
729 return (key1
- key2
);
732 struct native_display
*
733 x11_create_dri2_display(EGLNativeDisplayType dpy
,
734 struct native_event_handler
*event_handler
,
737 struct dri2_display
*dri2dpy
;
739 dri2dpy
= CALLOC_STRUCT(dri2_display
);
743 dri2dpy
->event_handler
= event_handler
;
748 dri2dpy
->dpy
= XOpenDisplay(NULL
);
750 dri2_display_destroy(&dri2dpy
->base
);
753 dri2dpy
->own_dpy
= TRUE
;
756 dri2dpy
->xscr_number
= DefaultScreen(dri2dpy
->dpy
);
757 dri2dpy
->xscr
= x11_screen_create(dri2dpy
->dpy
, dri2dpy
->xscr_number
);
758 if (!dri2dpy
->xscr
) {
759 dri2_display_destroy(&dri2dpy
->base
);
763 if (!dri2_display_init_screen(&dri2dpy
->base
)) {
764 dri2_display_destroy(&dri2dpy
->base
);
768 dri2dpy
->surfaces
= util_hash_table_create(dri2_display_hash_table_hash
,
769 dri2_display_hash_table_compare
);
770 if (!dri2dpy
->surfaces
) {
771 dri2_display_destroy(&dri2dpy
->base
);
775 dri2dpy
->base
.destroy
= dri2_display_destroy
;
776 dri2dpy
->base
.get_param
= dri2_display_get_param
;
777 dri2dpy
->base
.get_configs
= dri2_display_get_configs
;
778 dri2dpy
->base
.is_pixmap_supported
= dri2_display_is_pixmap_supported
;
779 dri2dpy
->base
.create_window_surface
= dri2_display_create_window_surface
;
780 dri2dpy
->base
.create_pixmap_surface
= dri2_display_create_pixmap_surface
;
782 return &dri2dpy
->base
;