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
44 struct native_display base
;
48 struct native_event_handler
*event_handler
;
50 struct x11_screen
*xscr
;
52 const char *dri_driver
;
53 int dri_major
, dri_minor
;
55 struct dri2_config
*configs
;
58 struct util_hash_table
*surfaces
;
62 struct native_surface base
;
64 enum pipe_format color_format
;
65 struct dri2_display
*dri2dpy
;
67 unsigned int server_stamp
;
68 unsigned int client_stamp
;
70 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
73 boolean have_back
, have_fake
;
75 struct x11_drawable_buffer
*last_xbufs
;
80 struct native_config base
;
83 static INLINE
struct dri2_display
*
84 dri2_display(const struct native_display
*ndpy
)
86 return (struct dri2_display
*) ndpy
;
89 static INLINE
struct dri2_surface
*
90 dri2_surface(const struct native_surface
*nsurf
)
92 return (struct dri2_surface
*) nsurf
;
95 static INLINE
struct dri2_config
*
96 dri2_config(const struct native_config
*nconf
)
98 return (struct dri2_config
*) nconf
;
102 * Process the buffers returned by the server.
105 dri2_surface_process_drawable_buffers(struct native_surface
*nsurf
,
106 struct x11_drawable_buffer
*xbufs
,
109 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
110 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
111 struct pipe_resource templ
;
112 struct winsys_handle whandle
;
116 /* free the old textures */
117 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++)
118 pipe_resource_reference(&dri2surf
->textures
[i
], NULL
);
119 dri2surf
->valid_mask
= 0x0;
121 dri2surf
->have_back
= FALSE
;
122 dri2surf
->have_fake
= FALSE
;
127 memset(&templ
, 0, sizeof(templ
));
128 templ
.target
= PIPE_TEXTURE_2D
;
129 templ
.last_level
= 0;
130 templ
.width0
= dri2surf
->width
;
131 templ
.height0
= dri2surf
->height
;
133 templ
.array_size
= 1;
134 templ
.format
= dri2surf
->color_format
;
135 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
138 for (i
= 0; i
< num_xbufs
; i
++) {
139 struct x11_drawable_buffer
*xbuf
= &xbufs
[i
];
141 enum native_attachment natt
;
143 switch (xbuf
->attachment
) {
144 case DRI2BufferFrontLeft
:
145 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
146 desc
= "DRI2 Front Buffer";
148 case DRI2BufferFakeFrontLeft
:
149 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
150 desc
= "DRI2 Fake Front Buffer";
151 dri2surf
->have_fake
= TRUE
;
153 case DRI2BufferBackLeft
:
154 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
155 desc
= "DRI2 Back Buffer";
156 dri2surf
->have_back
= TRUE
;
163 if (!desc
|| dri2surf
->textures
[natt
]) {
165 _eglLog(_EGL_WARNING
, "unknown buffer %d", xbuf
->attachment
);
167 _eglLog(_EGL_WARNING
, "both real and fake front buffers are listed");
171 memset(&whandle
, 0, sizeof(whandle
));
172 whandle
.stride
= xbuf
->pitch
;
173 whandle
.handle
= xbuf
->name
;
174 dri2surf
->textures
[natt
] = dri2dpy
->base
.screen
->resource_from_handle(
175 dri2dpy
->base
.screen
, &templ
, &whandle
);
176 if (dri2surf
->textures
[natt
])
177 valid_mask
|= 1 << natt
;
180 dri2surf
->valid_mask
= valid_mask
;
184 * Get the buffers from the server.
187 dri2_surface_get_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
189 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
190 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
191 unsigned int dri2atts
[NUM_NATIVE_ATTACHMENTS
* 2];
192 int num_ins
, num_outs
, att
;
193 struct x11_drawable_buffer
*xbufs
;
194 uint bpp
= util_format_get_blocksizebits(dri2surf
->color_format
);
195 boolean with_format
= FALSE
; /* never ask for depth/stencil */
197 /* We must get the front on servers which doesn't support with format
198 * due to a silly bug in core dri2. You can't copy to/from a buffer
199 * that you haven't requested and you recive BadValue errors */
200 if (dri2surf
->dri2dpy
->dri_minor
< 1) {
202 buffer_mask
|= (1 << NATIVE_ATTACHMENT_FRONT_LEFT
);
205 /* prepare the attachments */
207 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
208 if (native_attachment_mask_test(buffer_mask
, att
)) {
209 unsigned int dri2att
;
212 case NATIVE_ATTACHMENT_FRONT_LEFT
:
213 dri2att
= DRI2BufferFrontLeft
;
215 case NATIVE_ATTACHMENT_BACK_LEFT
:
216 dri2att
= DRI2BufferBackLeft
;
218 case NATIVE_ATTACHMENT_FRONT_RIGHT
:
219 dri2att
= DRI2BufferFrontRight
;
221 case NATIVE_ATTACHMENT_BACK_RIGHT
:
222 dri2att
= DRI2BufferBackRight
;
230 dri2atts
[num_ins
++] = dri2att
;
232 dri2atts
[num_ins
++] = bpp
;
238 xbufs
= x11_drawable_get_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
239 &dri2surf
->width
, &dri2surf
->height
,
240 dri2atts
, with_format
, num_ins
, &num_outs
);
242 /* we should be able to do better... */
243 if (xbufs
&& dri2surf
->last_num_xbufs
== num_outs
&&
244 memcmp(dri2surf
->last_xbufs
, xbufs
, sizeof(*xbufs
) * num_outs
) == 0) {
246 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
250 dri2_surface_process_drawable_buffers(&dri2surf
->base
, xbufs
, num_outs
);
252 dri2surf
->server_stamp
++;
253 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
255 if (dri2surf
->last_xbufs
)
256 FREE(dri2surf
->last_xbufs
);
257 dri2surf
->last_xbufs
= xbufs
;
258 dri2surf
->last_num_xbufs
= num_outs
;
262 * Update the buffers of the surface. This is a slow function due to the
263 * round-trip to the server.
266 dri2_surface_update_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
268 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
270 dri2_surface_get_buffers(&dri2surf
->base
, buffer_mask
);
272 return ((dri2surf
->valid_mask
& buffer_mask
) == buffer_mask
);
276 * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
278 static INLINE boolean
279 dri2_surface_receive_events(struct native_surface
*nsurf
)
281 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
282 return (dri2surf
->dri2dpy
->dri_minor
>= 3);
286 dri2_surface_flush_frontbuffer(struct native_surface
*nsurf
)
288 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
289 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
291 /* copy to real front buffer */
292 if (dri2surf
->have_fake
)
293 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
294 0, 0, dri2surf
->width
, dri2surf
->height
,
295 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
297 /* force buffers to be updated in next validation call */
298 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
299 dri2surf
->server_stamp
++;
300 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
301 &dri2surf
->base
, dri2surf
->server_stamp
);
308 dri2_surface_swap_buffers(struct native_surface
*nsurf
)
310 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
311 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
313 /* copy to front buffer */
314 if (dri2surf
->have_back
)
315 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
316 0, 0, dri2surf
->width
, dri2surf
->height
,
317 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
319 /* and update fake front buffer */
320 if (dri2surf
->have_fake
)
321 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
322 0, 0, dri2surf
->width
, dri2surf
->height
,
323 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
325 /* force buffers to be updated in next validation call */
326 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
327 dri2surf
->server_stamp
++;
328 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
329 &dri2surf
->base
, dri2surf
->server_stamp
);
336 dri2_surface_present(struct native_surface
*nsurf
,
337 enum native_attachment natt
,
347 case NATIVE_ATTACHMENT_FRONT_LEFT
:
348 ret
= dri2_surface_flush_frontbuffer(nsurf
);
350 case NATIVE_ATTACHMENT_BACK_LEFT
:
351 ret
= dri2_surface_swap_buffers(nsurf
);
362 dri2_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
363 unsigned int *seq_num
, struct pipe_resource
**textures
,
364 int *width
, int *height
)
366 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
368 if (dri2surf
->server_stamp
!= dri2surf
->client_stamp
||
369 (dri2surf
->valid_mask
& attachment_mask
) != attachment_mask
) {
370 if (!dri2_surface_update_buffers(&dri2surf
->base
, attachment_mask
))
375 *seq_num
= dri2surf
->client_stamp
;
379 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
380 if (native_attachment_mask_test(attachment_mask
, att
)) {
381 struct pipe_resource
*ptex
= dri2surf
->textures
[att
];
383 textures
[att
] = NULL
;
384 pipe_resource_reference(&textures
[att
], ptex
);
390 *width
= dri2surf
->width
;
392 *height
= dri2surf
->height
;
398 dri2_surface_wait(struct native_surface
*nsurf
)
400 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
401 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
403 if (dri2surf
->have_fake
) {
404 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
405 0, 0, dri2surf
->width
, dri2surf
->height
,
406 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
411 dri2_surface_destroy(struct native_surface
*nsurf
)
413 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
416 if (dri2surf
->last_xbufs
)
417 FREE(dri2surf
->last_xbufs
);
419 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
420 struct pipe_resource
*ptex
= dri2surf
->textures
[i
];
421 pipe_resource_reference(&ptex
, NULL
);
424 if (dri2surf
->drawable
) {
425 x11_drawable_enable_dri2(dri2surf
->dri2dpy
->xscr
,
426 dri2surf
->drawable
, FALSE
);
428 util_hash_table_remove(dri2surf
->dri2dpy
->surfaces
,
429 (void *) dri2surf
->drawable
);
434 static struct dri2_surface
*
435 dri2_display_create_surface(struct native_display
*ndpy
,
437 enum pipe_format color_format
)
439 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
440 struct dri2_surface
*dri2surf
;
442 dri2surf
= CALLOC_STRUCT(dri2_surface
);
446 dri2surf
->dri2dpy
= dri2dpy
;
447 dri2surf
->drawable
= drawable
;
448 dri2surf
->color_format
= color_format
;
450 dri2surf
->base
.destroy
= dri2_surface_destroy
;
451 dri2surf
->base
.present
= dri2_surface_present
;
452 dri2surf
->base
.validate
= dri2_surface_validate
;
453 dri2surf
->base
.wait
= dri2_surface_wait
;
456 x11_drawable_enable_dri2(dri2dpy
->xscr
, drawable
, TRUE
);
457 /* initialize the geometry */
458 dri2_surface_update_buffers(&dri2surf
->base
, 0x0);
460 util_hash_table_set(dri2surf
->dri2dpy
->surfaces
,
461 (void *) dri2surf
->drawable
, (void *) &dri2surf
->base
);
467 static struct native_surface
*
468 dri2_display_create_window_surface(struct native_display
*ndpy
,
469 EGLNativeWindowType win
,
470 const struct native_config
*nconf
)
472 struct dri2_surface
*dri2surf
;
474 dri2surf
= dri2_display_create_surface(ndpy
,
475 (Drawable
) win
, nconf
->color_format
);
476 return (dri2surf
) ? &dri2surf
->base
: NULL
;
479 static struct native_surface
*
480 dri2_display_create_pixmap_surface(struct native_display
*ndpy
,
481 EGLNativePixmapType pix
,
482 const struct native_config
*nconf
)
484 struct dri2_surface
*dri2surf
;
487 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
488 uint depth
, nconf_depth
;
491 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
492 for (i
= 0; i
< dri2dpy
->num_configs
; i
++) {
493 nconf_depth
= util_format_get_blocksizebits(
494 dri2dpy
->configs
[i
].base
.color_format
);
495 /* simple depth match for now */
496 if (depth
== nconf_depth
||
497 (depth
== 24 && depth
+ 8 == nconf_depth
)) {
498 nconf
= &dri2dpy
->configs
[i
].base
;
507 dri2surf
= dri2_display_create_surface(ndpy
,
508 (Drawable
) pix
, nconf
->color_format
);
509 return (dri2surf
) ? &dri2surf
->base
: NULL
;
513 choose_color_format(const __GLcontextModes
*mode
, enum pipe_format formats
[32])
517 switch (mode
->rgbBits
) {
519 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
520 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
523 formats
[count
++] = PIPE_FORMAT_B8G8R8X8_UNORM
;
524 formats
[count
++] = PIPE_FORMAT_X8R8G8B8_UNORM
;
525 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
526 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
529 formats
[count
++] = PIPE_FORMAT_B5G6R5_UNORM
;
539 is_format_supported(struct pipe_screen
*screen
,
540 enum pipe_format fmt
, unsigned sample_count
, boolean is_color
)
542 return screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
, sample_count
,
543 (is_color
) ? PIPE_BIND_RENDER_TARGET
:
544 PIPE_BIND_DEPTH_STENCIL
, 0);
548 dri2_display_convert_config(struct native_display
*ndpy
,
549 const __GLcontextModes
*mode
,
550 struct native_config
*nconf
)
552 enum pipe_format formats
[32];
554 int sample_count
= 0;
556 if (!(mode
->renderType
& GLX_RGBA_BIT
) || !mode
->rgbMode
)
559 /* only interested in native renderable configs */
560 if (!mode
->xRenderable
|| !mode
->drawableType
)
563 nconf
->buffer_mask
= 1 << NATIVE_ATTACHMENT_FRONT_LEFT
;
564 if (mode
->doubleBufferMode
)
565 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_LEFT
;
566 if (mode
->stereoMode
) {
567 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT
;
568 if (mode
->doubleBufferMode
)
569 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_RIGHT
;
572 /* choose color format */
573 num_formats
= choose_color_format(mode
, formats
);
574 for (i
= 0; i
< num_formats
; i
++) {
575 if (is_format_supported(ndpy
->screen
, formats
[i
], sample_count
, TRUE
)) {
576 nconf
->color_format
= formats
[i
];
580 if (nconf
->color_format
== PIPE_FORMAT_NONE
)
583 if (mode
->drawableType
& GLX_WINDOW_BIT
)
584 nconf
->window_bit
= TRUE
;
585 if (mode
->drawableType
& GLX_PIXMAP_BIT
)
586 nconf
->pixmap_bit
= TRUE
;
588 nconf
->native_visual_id
= mode
->visualID
;
589 nconf
->native_visual_type
= mode
->visualType
;
590 nconf
->level
= mode
->level
;
591 nconf
->samples
= mode
->samples
;
593 nconf
->slow_config
= (mode
->visualRating
== GLX_SLOW_CONFIG
);
595 if (mode
->transparentPixel
== GLX_TRANSPARENT_RGB
) {
596 nconf
->transparent_rgb
= TRUE
;
597 nconf
->transparent_rgb_values
[0] = mode
->transparentRed
;
598 nconf
->transparent_rgb_values
[1] = mode
->transparentGreen
;
599 nconf
->transparent_rgb_values
[2] = mode
->transparentBlue
;
605 static const struct native_config
**
606 dri2_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
608 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
609 const struct native_config
**configs
;
613 if (!dri2dpy
->configs
) {
614 const __GLcontextModes
*modes
;
615 int num_modes
, count
;
617 modes
= x11_screen_get_glx_configs(dri2dpy
->xscr
);
620 num_modes
= x11_context_modes_count(modes
);
622 dri2dpy
->configs
= CALLOC(num_modes
, sizeof(*dri2dpy
->configs
));
623 if (!dri2dpy
->configs
)
627 for (i
= 0; i
< num_modes
; i
++) {
628 struct native_config
*nconf
= &dri2dpy
->configs
[count
].base
;
629 if (dri2_display_convert_config(&dri2dpy
->base
, modes
, nconf
))
634 dri2dpy
->num_configs
= count
;
637 configs
= MALLOC(dri2dpy
->num_configs
* sizeof(*configs
));
639 for (i
= 0; i
< dri2dpy
->num_configs
; i
++)
640 configs
[i
] = (const struct native_config
*) &dri2dpy
->configs
[i
];
642 *num_configs
= dri2dpy
->num_configs
;
649 dri2_display_is_pixmap_supported(struct native_display
*ndpy
,
650 EGLNativePixmapType pix
,
651 const struct native_config
*nconf
)
653 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
654 uint depth
, nconf_depth
;
656 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
657 nconf_depth
= util_format_get_blocksizebits(nconf
->color_format
);
659 /* simple depth match for now */
660 return (depth
== nconf_depth
|| (depth
== 24 && depth
+ 8 == nconf_depth
));
664 dri2_display_get_param(struct native_display
*ndpy
,
665 enum native_param_type param
)
670 case NATIVE_PARAM_USE_NATIVE_BUFFER
:
671 /* DRI2GetBuffers uses the native buffers */
674 case NATIVE_PARAM_PRESERVE_BUFFER
:
675 /* DRI2CopyRegion is used */
678 case NATIVE_PARAM_MAX_SWAP_INTERVAL
:
688 dri2_display_destroy(struct native_display
*ndpy
)
690 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
692 if (dri2dpy
->configs
)
693 FREE(dri2dpy
->configs
);
695 if (dri2dpy
->base
.screen
)
696 dri2dpy
->base
.screen
->destroy(dri2dpy
->base
.screen
);
698 if (dri2dpy
->surfaces
)
699 util_hash_table_destroy(dri2dpy
->surfaces
);
702 x11_screen_destroy(dri2dpy
->xscr
);
703 if (dri2dpy
->own_dpy
)
704 XCloseDisplay(dri2dpy
->dpy
);
709 dri2_display_invalidate_buffers(struct x11_screen
*xscr
, Drawable drawable
,
712 struct native_display
*ndpy
= (struct native_display
* ) user_data
;
713 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
714 struct native_surface
*nsurf
;
715 struct dri2_surface
*dri2surf
;
717 nsurf
= (struct native_surface
*)
718 util_hash_table_get(dri2dpy
->surfaces
, (void *) drawable
);
722 dri2surf
= dri2_surface(nsurf
);
724 dri2surf
->server_stamp
++;
725 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
726 &dri2surf
->base
, dri2surf
->server_stamp
);
730 * Initialize DRI2 and pipe screen.
733 dri2_display_init_screen(struct native_display
*ndpy
)
735 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
738 if (!x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_DRI2
) ||
739 !x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_GLX
)) {
740 _eglLog(_EGL_WARNING
, "GLX/DRI2 is not supported");
744 dri2dpy
->dri_driver
= x11_screen_probe_dri2(dri2dpy
->xscr
,
745 &dri2dpy
->dri_major
, &dri2dpy
->dri_minor
);
747 fd
= x11_screen_enable_dri2(dri2dpy
->xscr
,
748 dri2_display_invalidate_buffers
, &dri2dpy
->base
);
752 dri2dpy
->base
.screen
=
753 dri2dpy
->event_handler
->new_drm_screen(&dri2dpy
->base
,
754 dri2dpy
->dri_driver
, fd
);
755 if (!dri2dpy
->base
.screen
) {
756 _eglLog(_EGL_WARNING
, "failed to create DRM screen");
764 dri2_display_hash_table_hash(void *key
)
766 XID drawable
= pointer_to_uintptr(key
);
767 return (unsigned) drawable
;
771 dri2_display_hash_table_compare(void *key1
, void *key2
)
773 return (key1
- key2
);
776 struct native_display
*
777 x11_create_dri2_display(Display
*dpy
,
778 struct native_event_handler
*event_handler
,
781 struct dri2_display
*dri2dpy
;
783 dri2dpy
= CALLOC_STRUCT(dri2_display
);
787 dri2dpy
->event_handler
= event_handler
;
788 dri2dpy
->base
.user_data
= user_data
;
792 dri2dpy
->dpy
= XOpenDisplay(NULL
);
794 dri2_display_destroy(&dri2dpy
->base
);
797 dri2dpy
->own_dpy
= TRUE
;
800 dri2dpy
->xscr_number
= DefaultScreen(dri2dpy
->dpy
);
801 dri2dpy
->xscr
= x11_screen_create(dri2dpy
->dpy
, dri2dpy
->xscr_number
);
802 if (!dri2dpy
->xscr
) {
803 dri2_display_destroy(&dri2dpy
->base
);
807 if (!dri2_display_init_screen(&dri2dpy
->base
)) {
808 dri2_display_destroy(&dri2dpy
->base
);
812 dri2dpy
->surfaces
= util_hash_table_create(dri2_display_hash_table_hash
,
813 dri2_display_hash_table_compare
);
814 if (!dri2dpy
->surfaces
) {
815 dri2_display_destroy(&dri2dpy
->base
);
819 dri2dpy
->base
.destroy
= dri2_display_destroy
;
820 dri2dpy
->base
.get_param
= dri2_display_get_param
;
821 dri2dpy
->base
.get_configs
= dri2_display_get_configs
;
822 dri2dpy
->base
.is_pixmap_supported
= dri2_display_is_pixmap_supported
;
823 dri2dpy
->base
.create_window_surface
= dri2_display_create_window_surface
;
824 dri2dpy
->base
.create_pixmap_surface
= dri2_display_create_pixmap_surface
;
826 return &dri2dpy
->base
;
829 #else /* GLX_DIRECT_RENDERING */
831 struct native_display
*
832 x11_create_dri2_display(Display
*dpy
,
833 struct native_event_handler
*event_handler
,
839 #endif /* GLX_DIRECT_RENDERING */