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_driver.h"
38 #include "native_x11.h"
39 #include "x11_screen.h"
41 #ifdef GLX_DIRECT_RENDERING
43 enum dri2_surface_type
{
44 DRI2_SURFACE_TYPE_WINDOW
,
45 DRI2_SURFACE_TYPE_PIXMAP
,
49 struct native_display base
;
53 struct native_event_handler
*event_handler
;
55 struct x11_screen
*xscr
;
57 const char *dri_driver
;
58 int dri_major
, dri_minor
;
60 struct dri2_config
*configs
;
63 struct util_hash_table
*surfaces
;
67 struct native_surface base
;
69 enum dri2_surface_type type
;
70 enum pipe_format color_format
;
71 struct dri2_display
*dri2dpy
;
73 unsigned int server_stamp
;
74 unsigned int client_stamp
;
76 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
79 boolean have_back
, have_fake
;
81 struct x11_drawable_buffer
*last_xbufs
;
86 struct native_config base
;
89 static INLINE
struct dri2_display
*
90 dri2_display(const struct native_display
*ndpy
)
92 return (struct dri2_display
*) ndpy
;
95 static INLINE
struct dri2_surface
*
96 dri2_surface(const struct native_surface
*nsurf
)
98 return (struct dri2_surface
*) nsurf
;
101 static INLINE
struct dri2_config
*
102 dri2_config(const struct native_config
*nconf
)
104 return (struct dri2_config
*) nconf
;
108 * Process the buffers returned by the server.
111 dri2_surface_process_drawable_buffers(struct native_surface
*nsurf
,
112 struct x11_drawable_buffer
*xbufs
,
115 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
116 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
117 struct pipe_resource templ
;
118 struct winsys_handle whandle
;
122 /* free the old textures */
123 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++)
124 pipe_resource_reference(&dri2surf
->textures
[i
], NULL
);
125 dri2surf
->valid_mask
= 0x0;
127 dri2surf
->have_back
= FALSE
;
128 dri2surf
->have_fake
= FALSE
;
133 memset(&templ
, 0, sizeof(templ
));
134 templ
.target
= PIPE_TEXTURE_2D
;
135 templ
.last_level
= 0;
136 templ
.width0
= dri2surf
->width
;
137 templ
.height0
= dri2surf
->height
;
139 templ
.format
= dri2surf
->color_format
;
140 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
143 for (i
= 0; i
< num_xbufs
; i
++) {
144 struct x11_drawable_buffer
*xbuf
= &xbufs
[i
];
146 enum native_attachment natt
;
148 switch (xbuf
->attachment
) {
149 case DRI2BufferFrontLeft
:
150 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
151 desc
= "DRI2 Front Buffer";
153 case DRI2BufferFakeFrontLeft
:
154 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
155 desc
= "DRI2 Fake Front Buffer";
156 dri2surf
->have_fake
= TRUE
;
158 case DRI2BufferBackLeft
:
159 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
160 desc
= "DRI2 Back Buffer";
161 dri2surf
->have_back
= TRUE
;
168 if (!desc
|| dri2surf
->textures
[natt
]) {
170 _eglLog(_EGL_WARNING
, "unknown buffer %d", xbuf
->attachment
);
172 _eglLog(_EGL_WARNING
, "both real and fake front buffers are listed");
176 memset(&whandle
, 0, sizeof(whandle
));
177 whandle
.stride
= xbuf
->pitch
;
178 whandle
.handle
= xbuf
->name
;
179 dri2surf
->textures
[natt
] = dri2dpy
->base
.screen
->resource_from_handle(
180 dri2dpy
->base
.screen
, &templ
, &whandle
);
181 if (dri2surf
->textures
[natt
])
182 valid_mask
|= 1 << natt
;
185 dri2surf
->valid_mask
= valid_mask
;
189 * Get the buffers from the server.
192 dri2_surface_get_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
194 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
195 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
196 unsigned int dri2atts
[NUM_NATIVE_ATTACHMENTS
* 2];
197 int num_ins
, num_outs
, att
;
198 struct x11_drawable_buffer
*xbufs
;
199 uint bpp
= util_format_get_blocksizebits(dri2surf
->color_format
);
200 boolean with_format
= FALSE
; /* never ask for depth/stencil */
202 /* We must get the front on servers which doesn't support with format
203 * due to a silly bug in core dri2. You can't copy to/from a buffer
204 * that you haven't requested and you recive BadValue errors */
205 if (dri2surf
->dri2dpy
->dri_minor
< 1) {
207 buffer_mask
|= (1 << NATIVE_ATTACHMENT_FRONT_LEFT
);
210 /* prepare the attachments */
212 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
213 if (native_attachment_mask_test(buffer_mask
, att
)) {
214 unsigned int dri2att
;
217 case NATIVE_ATTACHMENT_FRONT_LEFT
:
218 dri2att
= DRI2BufferFrontLeft
;
220 case NATIVE_ATTACHMENT_BACK_LEFT
:
221 dri2att
= DRI2BufferBackLeft
;
223 case NATIVE_ATTACHMENT_FRONT_RIGHT
:
224 dri2att
= DRI2BufferFrontRight
;
226 case NATIVE_ATTACHMENT_BACK_RIGHT
:
227 dri2att
= DRI2BufferBackRight
;
235 dri2atts
[num_ins
++] = dri2att
;
237 dri2atts
[num_ins
++] = bpp
;
243 xbufs
= x11_drawable_get_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
244 &dri2surf
->width
, &dri2surf
->height
,
245 dri2atts
, with_format
, num_ins
, &num_outs
);
247 /* we should be able to do better... */
248 if (xbufs
&& dri2surf
->last_num_xbufs
== num_outs
&&
249 memcmp(dri2surf
->last_xbufs
, xbufs
, sizeof(*xbufs
) * num_outs
) == 0) {
251 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
255 dri2_surface_process_drawable_buffers(&dri2surf
->base
, xbufs
, num_outs
);
257 dri2surf
->server_stamp
++;
258 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
260 if (dri2surf
->last_xbufs
)
261 FREE(dri2surf
->last_xbufs
);
262 dri2surf
->last_xbufs
= xbufs
;
263 dri2surf
->last_num_xbufs
= num_outs
;
267 * Update the buffers of the surface. This is a slow function due to the
268 * round-trip to the server.
271 dri2_surface_update_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
273 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
275 dri2_surface_get_buffers(&dri2surf
->base
, buffer_mask
);
277 return ((dri2surf
->valid_mask
& buffer_mask
) == buffer_mask
);
281 * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
283 static INLINE boolean
284 dri2_surface_receive_events(struct native_surface
*nsurf
)
286 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
287 return (dri2surf
->dri2dpy
->dri_minor
>= 3);
291 dri2_surface_flush_frontbuffer(struct native_surface
*nsurf
)
293 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
294 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
296 /* copy to real front buffer */
297 if (dri2surf
->have_fake
)
298 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
299 0, 0, dri2surf
->width
, dri2surf
->height
,
300 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
302 /* force buffers to be updated in next validation call */
303 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
304 dri2surf
->server_stamp
++;
305 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
306 &dri2surf
->base
, dri2surf
->server_stamp
);
313 dri2_surface_swap_buffers(struct native_surface
*nsurf
)
315 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
316 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
318 /* copy to front buffer */
319 if (dri2surf
->have_back
)
320 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
321 0, 0, dri2surf
->width
, dri2surf
->height
,
322 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
324 /* and update fake front buffer */
325 if (dri2surf
->have_fake
)
326 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
327 0, 0, dri2surf
->width
, dri2surf
->height
,
328 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
330 /* force buffers to be updated in next validation call */
331 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
332 dri2surf
->server_stamp
++;
333 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
334 &dri2surf
->base
, dri2surf
->server_stamp
);
341 dri2_surface_present(struct native_surface
*nsurf
,
342 enum native_attachment natt
,
352 case NATIVE_ATTACHMENT_FRONT_LEFT
:
353 ret
= dri2_surface_flush_frontbuffer(nsurf
);
355 case NATIVE_ATTACHMENT_BACK_LEFT
:
356 ret
= dri2_surface_swap_buffers(nsurf
);
367 dri2_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
368 unsigned int *seq_num
, struct pipe_resource
**textures
,
369 int *width
, int *height
)
371 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
373 if (dri2surf
->server_stamp
!= dri2surf
->client_stamp
||
374 (dri2surf
->valid_mask
& attachment_mask
) != attachment_mask
) {
375 if (!dri2_surface_update_buffers(&dri2surf
->base
, attachment_mask
))
380 *seq_num
= dri2surf
->client_stamp
;
384 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
385 if (native_attachment_mask_test(attachment_mask
, att
)) {
386 struct pipe_resource
*ptex
= dri2surf
->textures
[att
];
388 textures
[att
] = NULL
;
389 pipe_resource_reference(&textures
[att
], ptex
);
395 *width
= dri2surf
->width
;
397 *height
= dri2surf
->height
;
403 dri2_surface_wait(struct native_surface
*nsurf
)
405 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
406 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
408 if (dri2surf
->have_fake
) {
409 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
410 0, 0, dri2surf
->width
, dri2surf
->height
,
411 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
416 dri2_surface_destroy(struct native_surface
*nsurf
)
418 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
421 if (dri2surf
->last_xbufs
)
422 FREE(dri2surf
->last_xbufs
);
424 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
425 struct pipe_resource
*ptex
= dri2surf
->textures
[i
];
426 pipe_resource_reference(&ptex
, NULL
);
429 if (dri2surf
->drawable
) {
430 x11_drawable_enable_dri2(dri2surf
->dri2dpy
->xscr
,
431 dri2surf
->drawable
, FALSE
);
433 util_hash_table_remove(dri2surf
->dri2dpy
->surfaces
,
434 (void *) dri2surf
->drawable
);
439 static struct dri2_surface
*
440 dri2_display_create_surface(struct native_display
*ndpy
,
441 enum dri2_surface_type type
,
443 const struct native_config
*nconf
)
445 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
446 struct dri2_config
*dri2conf
= dri2_config(nconf
);
447 struct dri2_surface
*dri2surf
;
449 dri2surf
= CALLOC_STRUCT(dri2_surface
);
453 dri2surf
->dri2dpy
= dri2dpy
;
454 dri2surf
->type
= type
;
455 dri2surf
->drawable
= drawable
;
456 dri2surf
->color_format
= dri2conf
->base
.color_format
;
458 dri2surf
->base
.destroy
= dri2_surface_destroy
;
459 dri2surf
->base
.present
= dri2_surface_present
;
460 dri2surf
->base
.validate
= dri2_surface_validate
;
461 dri2surf
->base
.wait
= dri2_surface_wait
;
464 x11_drawable_enable_dri2(dri2dpy
->xscr
, drawable
, TRUE
);
465 /* initialize the geometry */
466 dri2_surface_update_buffers(&dri2surf
->base
, 0x0);
468 util_hash_table_set(dri2surf
->dri2dpy
->surfaces
,
469 (void *) dri2surf
->drawable
, (void *) &dri2surf
->base
);
475 static struct native_surface
*
476 dri2_display_create_window_surface(struct native_display
*ndpy
,
477 EGLNativeWindowType win
,
478 const struct native_config
*nconf
)
480 struct dri2_surface
*dri2surf
;
482 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_WINDOW
,
483 (Drawable
) win
, nconf
);
484 return (dri2surf
) ? &dri2surf
->base
: NULL
;
487 static struct native_surface
*
488 dri2_display_create_pixmap_surface(struct native_display
*ndpy
,
489 EGLNativePixmapType pix
,
490 const struct native_config
*nconf
)
492 struct dri2_surface
*dri2surf
;
494 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_PIXMAP
,
495 (Drawable
) pix
, nconf
);
496 return (dri2surf
) ? &dri2surf
->base
: NULL
;
500 choose_color_format(const __GLcontextModes
*mode
, enum pipe_format formats
[32])
504 switch (mode
->rgbBits
) {
506 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
507 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
510 formats
[count
++] = PIPE_FORMAT_B8G8R8X8_UNORM
;
511 formats
[count
++] = PIPE_FORMAT_X8R8G8B8_UNORM
;
512 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
513 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
516 formats
[count
++] = PIPE_FORMAT_B5G6R5_UNORM
;
526 is_format_supported(struct pipe_screen
*screen
,
527 enum pipe_format fmt
, unsigned sample_count
, boolean is_color
)
529 return screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
, sample_count
,
530 (is_color
) ? PIPE_BIND_RENDER_TARGET
:
531 PIPE_BIND_DEPTH_STENCIL
, 0);
535 dri2_display_convert_config(struct native_display
*ndpy
,
536 const __GLcontextModes
*mode
,
537 struct native_config
*nconf
)
539 enum pipe_format formats
[32];
541 int sample_count
= 0;
543 if (!(mode
->renderType
& GLX_RGBA_BIT
) || !mode
->rgbMode
)
546 /* only interested in native renderable configs */
547 if (!mode
->xRenderable
|| !mode
->drawableType
)
550 nconf
->buffer_mask
= 1 << NATIVE_ATTACHMENT_FRONT_LEFT
;
551 if (mode
->doubleBufferMode
)
552 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_LEFT
;
553 if (mode
->stereoMode
) {
554 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT
;
555 if (mode
->doubleBufferMode
)
556 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_RIGHT
;
559 /* choose color format */
560 num_formats
= choose_color_format(mode
, formats
);
561 for (i
= 0; i
< num_formats
; i
++) {
562 if (is_format_supported(ndpy
->screen
, formats
[i
], sample_count
, TRUE
)) {
563 nconf
->color_format
= formats
[i
];
567 if (nconf
->color_format
== PIPE_FORMAT_NONE
)
570 if (mode
->drawableType
& GLX_WINDOW_BIT
)
571 nconf
->window_bit
= TRUE
;
572 if (mode
->drawableType
& GLX_PIXMAP_BIT
)
573 nconf
->pixmap_bit
= TRUE
;
575 nconf
->native_visual_id
= mode
->visualID
;
576 nconf
->native_visual_type
= mode
->visualType
;
577 nconf
->level
= mode
->level
;
578 nconf
->samples
= mode
->samples
;
580 nconf
->slow_config
= (mode
->visualRating
== GLX_SLOW_CONFIG
);
582 if (mode
->transparentPixel
== GLX_TRANSPARENT_RGB
) {
583 nconf
->transparent_rgb
= TRUE
;
584 nconf
->transparent_rgb_values
[0] = mode
->transparentRed
;
585 nconf
->transparent_rgb_values
[1] = mode
->transparentGreen
;
586 nconf
->transparent_rgb_values
[2] = mode
->transparentBlue
;
592 static const struct native_config
**
593 dri2_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
595 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
596 const struct native_config
**configs
;
600 if (!dri2dpy
->configs
) {
601 const __GLcontextModes
*modes
;
602 int num_modes
, count
;
604 modes
= x11_screen_get_glx_configs(dri2dpy
->xscr
);
607 num_modes
= x11_context_modes_count(modes
);
609 dri2dpy
->configs
= CALLOC(num_modes
, sizeof(*dri2dpy
->configs
));
610 if (!dri2dpy
->configs
)
614 for (i
= 0; i
< num_modes
; i
++) {
615 struct native_config
*nconf
= &dri2dpy
->configs
[count
].base
;
616 if (dri2_display_convert_config(&dri2dpy
->base
, modes
, nconf
))
621 dri2dpy
->num_configs
= count
;
624 configs
= MALLOC(dri2dpy
->num_configs
* sizeof(*configs
));
626 for (i
= 0; i
< dri2dpy
->num_configs
; i
++)
627 configs
[i
] = (const struct native_config
*) &dri2dpy
->configs
[i
];
629 *num_configs
= dri2dpy
->num_configs
;
636 dri2_display_is_pixmap_supported(struct native_display
*ndpy
,
637 EGLNativePixmapType pix
,
638 const struct native_config
*nconf
)
640 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
641 uint depth
, nconf_depth
;
643 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
644 nconf_depth
= util_format_get_blocksizebits(nconf
->color_format
);
646 /* simple depth match for now */
647 return (depth
== nconf_depth
|| (depth
== 24 && depth
+ 8 == nconf_depth
));
651 dri2_display_get_param(struct native_display
*ndpy
,
652 enum native_param_type param
)
657 case NATIVE_PARAM_USE_NATIVE_BUFFER
:
658 /* DRI2GetBuffers uses the native buffers */
661 case NATIVE_PARAM_PRESERVE_BUFFER
:
662 /* DRI2CopyRegion is used */
665 case NATIVE_PARAM_MAX_SWAP_INTERVAL
:
675 dri2_display_destroy(struct native_display
*ndpy
)
677 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
679 if (dri2dpy
->configs
)
680 FREE(dri2dpy
->configs
);
682 if (dri2dpy
->base
.screen
)
683 dri2dpy
->base
.screen
->destroy(dri2dpy
->base
.screen
);
685 if (dri2dpy
->surfaces
)
686 util_hash_table_destroy(dri2dpy
->surfaces
);
689 x11_screen_destroy(dri2dpy
->xscr
);
690 if (dri2dpy
->own_dpy
)
691 XCloseDisplay(dri2dpy
->dpy
);
696 dri2_display_invalidate_buffers(struct x11_screen
*xscr
, Drawable drawable
,
699 struct native_display
*ndpy
= (struct native_display
* ) user_data
;
700 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
701 struct native_surface
*nsurf
;
702 struct dri2_surface
*dri2surf
;
704 nsurf
= (struct native_surface
*)
705 util_hash_table_get(dri2dpy
->surfaces
, (void *) drawable
);
709 dri2surf
= dri2_surface(nsurf
);
711 dri2surf
->server_stamp
++;
712 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
713 &dri2surf
->base
, dri2surf
->server_stamp
);
717 * Initialize DRI2 and pipe screen.
720 dri2_display_init_screen(struct native_display
*ndpy
)
722 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
725 if (!x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_DRI2
) ||
726 !x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_GLX
)) {
727 _eglLog(_EGL_WARNING
, "GLX/DRI2 is not supported");
731 dri2dpy
->dri_driver
= x11_screen_probe_dri2(dri2dpy
->xscr
,
732 &dri2dpy
->dri_major
, &dri2dpy
->dri_minor
);
734 fd
= x11_screen_enable_dri2(dri2dpy
->xscr
,
735 dri2_display_invalidate_buffers
, &dri2dpy
->base
);
739 dri2dpy
->base
.screen
=
740 dri2dpy
->event_handler
->new_drm_screen(&dri2dpy
->base
,
741 dri2dpy
->dri_driver
, fd
);
742 if (!dri2dpy
->base
.screen
) {
743 _eglLog(_EGL_WARNING
, "failed to create DRM screen");
751 dri2_display_hash_table_hash(void *key
)
753 XID drawable
= pointer_to_uintptr(key
);
754 return (unsigned) drawable
;
758 dri2_display_hash_table_compare(void *key1
, void *key2
)
760 return (key1
- key2
);
763 struct native_display
*
764 x11_create_dri2_display(Display
*dpy
,
765 struct native_event_handler
*event_handler
,
768 struct dri2_display
*dri2dpy
;
770 dri2dpy
= CALLOC_STRUCT(dri2_display
);
774 dri2dpy
->event_handler
= event_handler
;
775 dri2dpy
->base
.user_data
= user_data
;
779 dri2dpy
->dpy
= XOpenDisplay(NULL
);
781 dri2_display_destroy(&dri2dpy
->base
);
784 dri2dpy
->own_dpy
= TRUE
;
787 dri2dpy
->xscr_number
= DefaultScreen(dri2dpy
->dpy
);
788 dri2dpy
->xscr
= x11_screen_create(dri2dpy
->dpy
, dri2dpy
->xscr_number
);
789 if (!dri2dpy
->xscr
) {
790 dri2_display_destroy(&dri2dpy
->base
);
794 if (!dri2_display_init_screen(&dri2dpy
->base
)) {
795 dri2_display_destroy(&dri2dpy
->base
);
799 dri2dpy
->surfaces
= util_hash_table_create(dri2_display_hash_table_hash
,
800 dri2_display_hash_table_compare
);
801 if (!dri2dpy
->surfaces
) {
802 dri2_display_destroy(&dri2dpy
->base
);
806 dri2dpy
->base
.destroy
= dri2_display_destroy
;
807 dri2dpy
->base
.get_param
= dri2_display_get_param
;
808 dri2dpy
->base
.get_configs
= dri2_display_get_configs
;
809 dri2dpy
->base
.is_pixmap_supported
= dri2_display_is_pixmap_supported
;
810 dri2dpy
->base
.create_window_surface
= dri2_display_create_window_surface
;
811 dri2dpy
->base
.create_pixmap_surface
= dri2_display_create_pixmap_surface
;
813 return &dri2dpy
->base
;
816 #else /* GLX_DIRECT_RENDERING */
818 struct native_display
*
819 x11_create_dri2_display(Display
*dpy
,
820 struct native_event_handler
*event_handler
,
826 #endif /* GLX_DIRECT_RENDERING */