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
.array_size
= 1;
140 templ
.format
= dri2surf
->color_format
;
141 templ
.bind
= PIPE_BIND_RENDER_TARGET
;
144 for (i
= 0; i
< num_xbufs
; i
++) {
145 struct x11_drawable_buffer
*xbuf
= &xbufs
[i
];
147 enum native_attachment natt
;
149 switch (xbuf
->attachment
) {
150 case DRI2BufferFrontLeft
:
151 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
152 desc
= "DRI2 Front Buffer";
154 case DRI2BufferFakeFrontLeft
:
155 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
156 desc
= "DRI2 Fake Front Buffer";
157 dri2surf
->have_fake
= TRUE
;
159 case DRI2BufferBackLeft
:
160 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
161 desc
= "DRI2 Back Buffer";
162 dri2surf
->have_back
= TRUE
;
169 if (!desc
|| dri2surf
->textures
[natt
]) {
171 _eglLog(_EGL_WARNING
, "unknown buffer %d", xbuf
->attachment
);
173 _eglLog(_EGL_WARNING
, "both real and fake front buffers are listed");
177 memset(&whandle
, 0, sizeof(whandle
));
178 whandle
.stride
= xbuf
->pitch
;
179 whandle
.handle
= xbuf
->name
;
180 dri2surf
->textures
[natt
] = dri2dpy
->base
.screen
->resource_from_handle(
181 dri2dpy
->base
.screen
, &templ
, &whandle
);
182 if (dri2surf
->textures
[natt
])
183 valid_mask
|= 1 << natt
;
186 dri2surf
->valid_mask
= valid_mask
;
190 * Get the buffers from the server.
193 dri2_surface_get_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
195 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
196 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
197 unsigned int dri2atts
[NUM_NATIVE_ATTACHMENTS
* 2];
198 int num_ins
, num_outs
, att
;
199 struct x11_drawable_buffer
*xbufs
;
200 uint bpp
= util_format_get_blocksizebits(dri2surf
->color_format
);
201 boolean with_format
= FALSE
; /* never ask for depth/stencil */
203 /* We must get the front on servers which doesn't support with format
204 * due to a silly bug in core dri2. You can't copy to/from a buffer
205 * that you haven't requested and you recive BadValue errors */
206 if (dri2surf
->dri2dpy
->dri_minor
< 1) {
208 buffer_mask
|= (1 << NATIVE_ATTACHMENT_FRONT_LEFT
);
211 /* prepare the attachments */
213 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
214 if (native_attachment_mask_test(buffer_mask
, att
)) {
215 unsigned int dri2att
;
218 case NATIVE_ATTACHMENT_FRONT_LEFT
:
219 dri2att
= DRI2BufferFrontLeft
;
221 case NATIVE_ATTACHMENT_BACK_LEFT
:
222 dri2att
= DRI2BufferBackLeft
;
224 case NATIVE_ATTACHMENT_FRONT_RIGHT
:
225 dri2att
= DRI2BufferFrontRight
;
227 case NATIVE_ATTACHMENT_BACK_RIGHT
:
228 dri2att
= DRI2BufferBackRight
;
236 dri2atts
[num_ins
++] = dri2att
;
238 dri2atts
[num_ins
++] = bpp
;
244 xbufs
= x11_drawable_get_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
245 &dri2surf
->width
, &dri2surf
->height
,
246 dri2atts
, with_format
, num_ins
, &num_outs
);
248 /* we should be able to do better... */
249 if (xbufs
&& dri2surf
->last_num_xbufs
== num_outs
&&
250 memcmp(dri2surf
->last_xbufs
, xbufs
, sizeof(*xbufs
) * num_outs
) == 0) {
252 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
256 dri2_surface_process_drawable_buffers(&dri2surf
->base
, xbufs
, num_outs
);
258 dri2surf
->server_stamp
++;
259 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
261 if (dri2surf
->last_xbufs
)
262 FREE(dri2surf
->last_xbufs
);
263 dri2surf
->last_xbufs
= xbufs
;
264 dri2surf
->last_num_xbufs
= num_outs
;
268 * Update the buffers of the surface. This is a slow function due to the
269 * round-trip to the server.
272 dri2_surface_update_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
274 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
276 dri2_surface_get_buffers(&dri2surf
->base
, buffer_mask
);
278 return ((dri2surf
->valid_mask
& buffer_mask
) == buffer_mask
);
282 * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
284 static INLINE boolean
285 dri2_surface_receive_events(struct native_surface
*nsurf
)
287 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
288 return (dri2surf
->dri2dpy
->dri_minor
>= 3);
292 dri2_surface_flush_frontbuffer(struct native_surface
*nsurf
)
294 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
295 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
297 /* copy to real front buffer */
298 if (dri2surf
->have_fake
)
299 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
300 0, 0, dri2surf
->width
, dri2surf
->height
,
301 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
303 /* force buffers to be updated in next validation call */
304 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
305 dri2surf
->server_stamp
++;
306 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
307 &dri2surf
->base
, dri2surf
->server_stamp
);
314 dri2_surface_swap_buffers(struct native_surface
*nsurf
)
316 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
317 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
319 /* copy to front buffer */
320 if (dri2surf
->have_back
)
321 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
322 0, 0, dri2surf
->width
, dri2surf
->height
,
323 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
325 /* and update fake front buffer */
326 if (dri2surf
->have_fake
)
327 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
328 0, 0, dri2surf
->width
, dri2surf
->height
,
329 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
331 /* force buffers to be updated in next validation call */
332 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
333 dri2surf
->server_stamp
++;
334 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
335 &dri2surf
->base
, dri2surf
->server_stamp
);
342 dri2_surface_present(struct native_surface
*nsurf
,
343 enum native_attachment natt
,
353 case NATIVE_ATTACHMENT_FRONT_LEFT
:
354 ret
= dri2_surface_flush_frontbuffer(nsurf
);
356 case NATIVE_ATTACHMENT_BACK_LEFT
:
357 ret
= dri2_surface_swap_buffers(nsurf
);
368 dri2_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
369 unsigned int *seq_num
, struct pipe_resource
**textures
,
370 int *width
, int *height
)
372 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
374 if (dri2surf
->server_stamp
!= dri2surf
->client_stamp
||
375 (dri2surf
->valid_mask
& attachment_mask
) != attachment_mask
) {
376 if (!dri2_surface_update_buffers(&dri2surf
->base
, attachment_mask
))
381 *seq_num
= dri2surf
->client_stamp
;
385 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
386 if (native_attachment_mask_test(attachment_mask
, att
)) {
387 struct pipe_resource
*ptex
= dri2surf
->textures
[att
];
389 textures
[att
] = NULL
;
390 pipe_resource_reference(&textures
[att
], ptex
);
396 *width
= dri2surf
->width
;
398 *height
= dri2surf
->height
;
404 dri2_surface_wait(struct native_surface
*nsurf
)
406 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
407 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
409 if (dri2surf
->have_fake
) {
410 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
411 0, 0, dri2surf
->width
, dri2surf
->height
,
412 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
417 dri2_surface_destroy(struct native_surface
*nsurf
)
419 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
422 if (dri2surf
->last_xbufs
)
423 FREE(dri2surf
->last_xbufs
);
425 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
426 struct pipe_resource
*ptex
= dri2surf
->textures
[i
];
427 pipe_resource_reference(&ptex
, NULL
);
430 if (dri2surf
->drawable
) {
431 x11_drawable_enable_dri2(dri2surf
->dri2dpy
->xscr
,
432 dri2surf
->drawable
, FALSE
);
434 util_hash_table_remove(dri2surf
->dri2dpy
->surfaces
,
435 (void *) dri2surf
->drawable
);
440 static struct dri2_surface
*
441 dri2_display_create_surface(struct native_display
*ndpy
,
442 enum dri2_surface_type type
,
444 const struct native_config
*nconf
)
446 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
447 struct dri2_config
*dri2conf
= dri2_config(nconf
);
448 struct dri2_surface
*dri2surf
;
450 dri2surf
= CALLOC_STRUCT(dri2_surface
);
454 dri2surf
->dri2dpy
= dri2dpy
;
455 dri2surf
->type
= type
;
456 dri2surf
->drawable
= drawable
;
457 dri2surf
->color_format
= dri2conf
->base
.color_format
;
459 dri2surf
->base
.destroy
= dri2_surface_destroy
;
460 dri2surf
->base
.present
= dri2_surface_present
;
461 dri2surf
->base
.validate
= dri2_surface_validate
;
462 dri2surf
->base
.wait
= dri2_surface_wait
;
465 x11_drawable_enable_dri2(dri2dpy
->xscr
, drawable
, TRUE
);
466 /* initialize the geometry */
467 dri2_surface_update_buffers(&dri2surf
->base
, 0x0);
469 util_hash_table_set(dri2surf
->dri2dpy
->surfaces
,
470 (void *) dri2surf
->drawable
, (void *) &dri2surf
->base
);
476 static struct native_surface
*
477 dri2_display_create_window_surface(struct native_display
*ndpy
,
478 EGLNativeWindowType win
,
479 const struct native_config
*nconf
)
481 struct dri2_surface
*dri2surf
;
483 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_WINDOW
,
484 (Drawable
) win
, nconf
);
485 return (dri2surf
) ? &dri2surf
->base
: NULL
;
488 static struct native_surface
*
489 dri2_display_create_pixmap_surface(struct native_display
*ndpy
,
490 EGLNativePixmapType pix
,
491 const struct native_config
*nconf
)
493 struct dri2_surface
*dri2surf
;
495 dri2surf
= dri2_display_create_surface(ndpy
, DRI2_SURFACE_TYPE_PIXMAP
,
496 (Drawable
) pix
, nconf
);
497 return (dri2surf
) ? &dri2surf
->base
: NULL
;
501 choose_color_format(const __GLcontextModes
*mode
, enum pipe_format formats
[32])
505 switch (mode
->rgbBits
) {
507 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
508 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
511 formats
[count
++] = PIPE_FORMAT_B8G8R8X8_UNORM
;
512 formats
[count
++] = PIPE_FORMAT_X8R8G8B8_UNORM
;
513 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
514 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
517 formats
[count
++] = PIPE_FORMAT_B5G6R5_UNORM
;
527 is_format_supported(struct pipe_screen
*screen
,
528 enum pipe_format fmt
, unsigned sample_count
, boolean is_color
)
530 return screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
, sample_count
,
531 (is_color
) ? PIPE_BIND_RENDER_TARGET
:
532 PIPE_BIND_DEPTH_STENCIL
, 0);
536 dri2_display_convert_config(struct native_display
*ndpy
,
537 const __GLcontextModes
*mode
,
538 struct native_config
*nconf
)
540 enum pipe_format formats
[32];
542 int sample_count
= 0;
544 if (!(mode
->renderType
& GLX_RGBA_BIT
) || !mode
->rgbMode
)
547 /* only interested in native renderable configs */
548 if (!mode
->xRenderable
|| !mode
->drawableType
)
551 nconf
->buffer_mask
= 1 << NATIVE_ATTACHMENT_FRONT_LEFT
;
552 if (mode
->doubleBufferMode
)
553 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_LEFT
;
554 if (mode
->stereoMode
) {
555 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT
;
556 if (mode
->doubleBufferMode
)
557 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_RIGHT
;
560 /* choose color format */
561 num_formats
= choose_color_format(mode
, formats
);
562 for (i
= 0; i
< num_formats
; i
++) {
563 if (is_format_supported(ndpy
->screen
, formats
[i
], sample_count
, TRUE
)) {
564 nconf
->color_format
= formats
[i
];
568 if (nconf
->color_format
== PIPE_FORMAT_NONE
)
571 if (mode
->drawableType
& GLX_WINDOW_BIT
)
572 nconf
->window_bit
= TRUE
;
573 if (mode
->drawableType
& GLX_PIXMAP_BIT
)
574 nconf
->pixmap_bit
= TRUE
;
576 nconf
->native_visual_id
= mode
->visualID
;
577 nconf
->native_visual_type
= mode
->visualType
;
578 nconf
->level
= mode
->level
;
579 nconf
->samples
= mode
->samples
;
581 nconf
->slow_config
= (mode
->visualRating
== GLX_SLOW_CONFIG
);
583 if (mode
->transparentPixel
== GLX_TRANSPARENT_RGB
) {
584 nconf
->transparent_rgb
= TRUE
;
585 nconf
->transparent_rgb_values
[0] = mode
->transparentRed
;
586 nconf
->transparent_rgb_values
[1] = mode
->transparentGreen
;
587 nconf
->transparent_rgb_values
[2] = mode
->transparentBlue
;
593 static const struct native_config
**
594 dri2_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
596 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
597 const struct native_config
**configs
;
601 if (!dri2dpy
->configs
) {
602 const __GLcontextModes
*modes
;
603 int num_modes
, count
;
605 modes
= x11_screen_get_glx_configs(dri2dpy
->xscr
);
608 num_modes
= x11_context_modes_count(modes
);
610 dri2dpy
->configs
= CALLOC(num_modes
, sizeof(*dri2dpy
->configs
));
611 if (!dri2dpy
->configs
)
615 for (i
= 0; i
< num_modes
; i
++) {
616 struct native_config
*nconf
= &dri2dpy
->configs
[count
].base
;
617 if (dri2_display_convert_config(&dri2dpy
->base
, modes
, nconf
))
622 dri2dpy
->num_configs
= count
;
625 configs
= MALLOC(dri2dpy
->num_configs
* sizeof(*configs
));
627 for (i
= 0; i
< dri2dpy
->num_configs
; i
++)
628 configs
[i
] = (const struct native_config
*) &dri2dpy
->configs
[i
];
630 *num_configs
= dri2dpy
->num_configs
;
637 dri2_display_is_pixmap_supported(struct native_display
*ndpy
,
638 EGLNativePixmapType pix
,
639 const struct native_config
*nconf
)
641 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
642 uint depth
, nconf_depth
;
644 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
645 nconf_depth
= util_format_get_blocksizebits(nconf
->color_format
);
647 /* simple depth match for now */
648 return (depth
== nconf_depth
|| (depth
== 24 && depth
+ 8 == nconf_depth
));
652 dri2_display_get_param(struct native_display
*ndpy
,
653 enum native_param_type param
)
658 case NATIVE_PARAM_USE_NATIVE_BUFFER
:
659 /* DRI2GetBuffers uses the native buffers */
662 case NATIVE_PARAM_PRESERVE_BUFFER
:
663 /* DRI2CopyRegion is used */
666 case NATIVE_PARAM_MAX_SWAP_INTERVAL
:
676 dri2_display_destroy(struct native_display
*ndpy
)
678 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
680 if (dri2dpy
->configs
)
681 FREE(dri2dpy
->configs
);
683 if (dri2dpy
->base
.screen
)
684 dri2dpy
->base
.screen
->destroy(dri2dpy
->base
.screen
);
686 if (dri2dpy
->surfaces
)
687 util_hash_table_destroy(dri2dpy
->surfaces
);
690 x11_screen_destroy(dri2dpy
->xscr
);
691 if (dri2dpy
->own_dpy
)
692 XCloseDisplay(dri2dpy
->dpy
);
697 dri2_display_invalidate_buffers(struct x11_screen
*xscr
, Drawable drawable
,
700 struct native_display
*ndpy
= (struct native_display
* ) user_data
;
701 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
702 struct native_surface
*nsurf
;
703 struct dri2_surface
*dri2surf
;
705 nsurf
= (struct native_surface
*)
706 util_hash_table_get(dri2dpy
->surfaces
, (void *) drawable
);
710 dri2surf
= dri2_surface(nsurf
);
712 dri2surf
->server_stamp
++;
713 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
714 &dri2surf
->base
, dri2surf
->server_stamp
);
718 * Initialize DRI2 and pipe screen.
721 dri2_display_init_screen(struct native_display
*ndpy
)
723 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
726 if (!x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_DRI2
) ||
727 !x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_GLX
)) {
728 _eglLog(_EGL_WARNING
, "GLX/DRI2 is not supported");
732 dri2dpy
->dri_driver
= x11_screen_probe_dri2(dri2dpy
->xscr
,
733 &dri2dpy
->dri_major
, &dri2dpy
->dri_minor
);
735 fd
= x11_screen_enable_dri2(dri2dpy
->xscr
,
736 dri2_display_invalidate_buffers
, &dri2dpy
->base
);
740 dri2dpy
->base
.screen
=
741 dri2dpy
->event_handler
->new_drm_screen(&dri2dpy
->base
,
742 dri2dpy
->dri_driver
, fd
);
743 if (!dri2dpy
->base
.screen
) {
744 _eglLog(_EGL_WARNING
, "failed to create DRM screen");
752 dri2_display_hash_table_hash(void *key
)
754 XID drawable
= pointer_to_uintptr(key
);
755 return (unsigned) drawable
;
759 dri2_display_hash_table_compare(void *key1
, void *key2
)
761 return (key1
- key2
);
764 struct native_display
*
765 x11_create_dri2_display(Display
*dpy
,
766 struct native_event_handler
*event_handler
,
769 struct dri2_display
*dri2dpy
;
771 dri2dpy
= CALLOC_STRUCT(dri2_display
);
775 dri2dpy
->event_handler
= event_handler
;
776 dri2dpy
->base
.user_data
= user_data
;
780 dri2dpy
->dpy
= XOpenDisplay(NULL
);
782 dri2_display_destroy(&dri2dpy
->base
);
785 dri2dpy
->own_dpy
= TRUE
;
788 dri2dpy
->xscr_number
= DefaultScreen(dri2dpy
->dpy
);
789 dri2dpy
->xscr
= x11_screen_create(dri2dpy
->dpy
, dri2dpy
->xscr_number
);
790 if (!dri2dpy
->xscr
) {
791 dri2_display_destroy(&dri2dpy
->base
);
795 if (!dri2_display_init_screen(&dri2dpy
->base
)) {
796 dri2_display_destroy(&dri2dpy
->base
);
800 dri2dpy
->surfaces
= util_hash_table_create(dri2_display_hash_table_hash
,
801 dri2_display_hash_table_compare
);
802 if (!dri2dpy
->surfaces
) {
803 dri2_display_destroy(&dri2dpy
->base
);
807 dri2dpy
->base
.destroy
= dri2_display_destroy
;
808 dri2dpy
->base
.get_param
= dri2_display_get_param
;
809 dri2dpy
->base
.get_configs
= dri2_display_get_configs
;
810 dri2dpy
->base
.is_pixmap_supported
= dri2_display_is_pixmap_supported
;
811 dri2dpy
->base
.create_window_surface
= dri2_display_create_window_surface
;
812 dri2dpy
->base
.create_pixmap_surface
= dri2_display_create_pixmap_surface
;
814 return &dri2dpy
->base
;
817 #else /* GLX_DIRECT_RENDERING */
819 struct native_display
*
820 x11_create_dri2_display(Display
*dpy
,
821 struct native_event_handler
*event_handler
,
827 #endif /* GLX_DIRECT_RENDERING */