2 * Mesa 3-D graphics library
4 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #include "util/u_memory.h"
26 #include "util/u_math.h"
27 #include "util/u_format.h"
28 #include "util/u_inlines.h"
29 #include "util/u_hash_table.h"
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_screen.h"
32 #include "pipe/p_context.h"
33 #include "pipe/p_state.h"
34 #include "state_tracker/drm_driver.h"
37 #include "native_x11.h"
38 #include "x11_screen.h"
40 #include "common/native_helper.h"
41 #ifdef HAVE_WAYLAND_BACKEND
42 #include "common/native_wayland_drm_bufmgr.h"
45 #ifdef GLX_DIRECT_RENDERING
48 struct native_display base
;
52 const 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 pipe_format color_format
;
69 struct dri2_display
*dri2dpy
;
71 unsigned int server_stamp
;
72 unsigned int client_stamp
;
74 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
77 boolean have_back
, have_fake
;
79 struct x11_drawable_buffer
*last_xbufs
;
84 struct native_config base
;
87 static INLINE
struct dri2_display
*
88 dri2_display(const struct native_display
*ndpy
)
90 return (struct dri2_display
*) ndpy
;
93 static INLINE
struct dri2_surface
*
94 dri2_surface(const struct native_surface
*nsurf
)
96 return (struct dri2_surface
*) nsurf
;
99 static INLINE
struct dri2_config
*
100 dri2_config(const struct native_config
*nconf
)
102 return (struct dri2_config
*) nconf
;
106 * Process the buffers returned by the server.
109 dri2_surface_process_drawable_buffers(struct native_surface
*nsurf
,
110 struct x11_drawable_buffer
*xbufs
,
113 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
114 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
115 struct pipe_resource templ
;
116 struct winsys_handle whandle
;
120 /* free the old textures */
121 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++)
122 pipe_resource_reference(&dri2surf
->textures
[i
], NULL
);
123 dri2surf
->valid_mask
= 0x0;
125 dri2surf
->have_back
= FALSE
;
126 dri2surf
->have_fake
= FALSE
;
131 memset(&templ
, 0, sizeof(templ
));
132 templ
.target
= PIPE_TEXTURE_2D
;
133 templ
.last_level
= 0;
134 templ
.width0
= dri2surf
->width
;
135 templ
.height0
= dri2surf
->height
;
137 templ
.array_size
= 1;
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
* 2];
196 int num_ins
, num_outs
, att
;
197 struct x11_drawable_buffer
*xbufs
;
198 uint bpp
= util_format_get_blocksizebits(dri2surf
->color_format
);
199 boolean with_format
= FALSE
; /* never ask for depth/stencil */
201 /* We must get the front on servers which doesn't support with format
202 * due to a silly bug in core dri2. You can't copy to/from a buffer
203 * that you haven't requested and you recive BadValue errors */
204 if (dri2surf
->dri2dpy
->dri_minor
< 1) {
206 buffer_mask
|= (1 << NATIVE_ATTACHMENT_FRONT_LEFT
);
209 /* prepare the attachments */
211 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
212 if (native_attachment_mask_test(buffer_mask
, att
)) {
213 unsigned int dri2att
;
216 case NATIVE_ATTACHMENT_FRONT_LEFT
:
217 dri2att
= DRI2BufferFrontLeft
;
219 case NATIVE_ATTACHMENT_BACK_LEFT
:
220 dri2att
= DRI2BufferBackLeft
;
222 case NATIVE_ATTACHMENT_FRONT_RIGHT
:
223 dri2att
= DRI2BufferFrontRight
;
225 case NATIVE_ATTACHMENT_BACK_RIGHT
:
226 dri2att
= DRI2BufferBackRight
;
234 dri2atts
[num_ins
++] = dri2att
;
236 dri2atts
[num_ins
++] = bpp
;
242 xbufs
= x11_drawable_get_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
243 &dri2surf
->width
, &dri2surf
->height
,
244 dri2atts
, with_format
, num_ins
, &num_outs
);
246 /* we should be able to do better... */
247 if (xbufs
&& dri2surf
->last_num_xbufs
== num_outs
&&
248 memcmp(dri2surf
->last_xbufs
, xbufs
, sizeof(*xbufs
) * num_outs
) == 0) {
250 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
254 dri2_surface_process_drawable_buffers(&dri2surf
->base
, xbufs
, num_outs
);
256 dri2surf
->server_stamp
++;
257 dri2surf
->client_stamp
= dri2surf
->server_stamp
;
259 FREE(dri2surf
->last_xbufs
);
260 dri2surf
->last_xbufs
= xbufs
;
261 dri2surf
->last_num_xbufs
= num_outs
;
265 * Update the buffers of the surface. This is a slow function due to the
266 * round-trip to the server.
269 dri2_surface_update_buffers(struct native_surface
*nsurf
, uint buffer_mask
)
271 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
273 dri2_surface_get_buffers(&dri2surf
->base
, buffer_mask
);
275 return ((dri2surf
->valid_mask
& buffer_mask
) == buffer_mask
);
279 * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
281 static INLINE boolean
282 dri2_surface_receive_events(struct native_surface
*nsurf
)
284 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
285 return (dri2surf
->dri2dpy
->dri_minor
>= 3);
289 dri2_surface_flush_frontbuffer(struct native_surface
*nsurf
)
291 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
292 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
294 /* copy to real front buffer */
295 if (dri2surf
->have_fake
)
296 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
297 0, 0, dri2surf
->width
, dri2surf
->height
,
298 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
300 /* force buffers to be updated in next validation call */
301 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
302 dri2surf
->server_stamp
++;
303 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
304 &dri2surf
->base
, dri2surf
->server_stamp
);
311 dri2_surface_swap_buffers(struct native_surface
*nsurf
, int num_rects
,
314 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
315 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
317 /* copy to front buffer */
318 if (dri2surf
->have_back
) {
320 x11_drawable_copy_buffers_region(dri2dpy
->xscr
, dri2surf
->drawable
,
322 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
324 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
325 0, 0, dri2surf
->width
, dri2surf
->height
,
326 DRI2BufferBackLeft
, DRI2BufferFrontLeft
);
329 /* and update fake front buffer */
330 if (dri2surf
->have_fake
) {
332 x11_drawable_copy_buffers_region(dri2dpy
->xscr
, dri2surf
->drawable
,
334 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
336 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
337 0, 0, dri2surf
->width
, dri2surf
->height
,
338 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
341 /* force buffers to be updated in next validation call */
342 if (!dri2_surface_receive_events(&dri2surf
->base
)) {
343 dri2surf
->server_stamp
++;
344 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
345 &dri2surf
->base
, dri2surf
->server_stamp
);
352 dri2_surface_present(struct native_surface
*nsurf
,
353 const struct native_present_control
*ctrl
)
357 if (ctrl
->swap_interval
)
360 switch (ctrl
->natt
) {
361 case NATIVE_ATTACHMENT_FRONT_LEFT
:
362 ret
= dri2_surface_flush_frontbuffer(nsurf
);
364 case NATIVE_ATTACHMENT_BACK_LEFT
:
365 ret
= dri2_surface_swap_buffers(nsurf
, ctrl
->num_rects
, ctrl
->rects
);
376 dri2_surface_validate(struct native_surface
*nsurf
, uint attachment_mask
,
377 unsigned int *seq_num
, struct pipe_resource
**textures
,
378 int *width
, int *height
)
380 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
382 if (dri2surf
->server_stamp
!= dri2surf
->client_stamp
||
383 (dri2surf
->valid_mask
& attachment_mask
) != attachment_mask
) {
384 if (!dri2_surface_update_buffers(&dri2surf
->base
, attachment_mask
))
389 *seq_num
= dri2surf
->client_stamp
;
393 for (att
= 0; att
< NUM_NATIVE_ATTACHMENTS
; att
++) {
394 if (native_attachment_mask_test(attachment_mask
, att
)) {
395 struct pipe_resource
*ptex
= dri2surf
->textures
[att
];
397 textures
[att
] = NULL
;
398 pipe_resource_reference(&textures
[att
], ptex
);
404 *width
= dri2surf
->width
;
406 *height
= dri2surf
->height
;
412 dri2_surface_wait(struct native_surface
*nsurf
)
414 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
415 struct dri2_display
*dri2dpy
= dri2surf
->dri2dpy
;
417 if (dri2surf
->have_fake
) {
418 x11_drawable_copy_buffers(dri2dpy
->xscr
, dri2surf
->drawable
,
419 0, 0, dri2surf
->width
, dri2surf
->height
,
420 DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
425 dri2_surface_destroy(struct native_surface
*nsurf
)
427 struct dri2_surface
*dri2surf
= dri2_surface(nsurf
);
430 FREE(dri2surf
->last_xbufs
);
432 for (i
= 0; i
< NUM_NATIVE_ATTACHMENTS
; i
++) {
433 struct pipe_resource
*ptex
= dri2surf
->textures
[i
];
434 pipe_resource_reference(&ptex
, NULL
);
437 if (dri2surf
->drawable
) {
438 x11_drawable_enable_dri2(dri2surf
->dri2dpy
->xscr
,
439 dri2surf
->drawable
, FALSE
);
441 util_hash_table_remove(dri2surf
->dri2dpy
->surfaces
,
442 (void *) dri2surf
->drawable
);
447 static struct dri2_surface
*
448 dri2_display_create_surface(struct native_display
*ndpy
,
450 enum pipe_format color_format
)
452 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
453 struct dri2_surface
*dri2surf
;
455 dri2surf
= CALLOC_STRUCT(dri2_surface
);
459 dri2surf
->dri2dpy
= dri2dpy
;
460 dri2surf
->drawable
= drawable
;
461 dri2surf
->color_format
= color_format
;
463 dri2surf
->base
.destroy
= dri2_surface_destroy
;
464 dri2surf
->base
.present
= dri2_surface_present
;
465 dri2surf
->base
.validate
= dri2_surface_validate
;
466 dri2surf
->base
.wait
= dri2_surface_wait
;
469 x11_drawable_enable_dri2(dri2dpy
->xscr
, drawable
, TRUE
);
470 /* initialize the geometry */
471 dri2_surface_update_buffers(&dri2surf
->base
, 0x0);
473 util_hash_table_set(dri2surf
->dri2dpy
->surfaces
,
474 (void *) dri2surf
->drawable
, (void *) &dri2surf
->base
);
480 static struct native_surface
*
481 dri2_display_create_window_surface(struct native_display
*ndpy
,
482 EGLNativeWindowType win
,
483 const struct native_config
*nconf
)
485 struct dri2_surface
*dri2surf
;
487 dri2surf
= dri2_display_create_surface(ndpy
,
488 (Drawable
) win
, nconf
->color_format
);
489 return (dri2surf
) ? &dri2surf
->base
: NULL
;
492 static struct native_surface
*
493 dri2_display_create_pixmap_surface(struct native_display
*ndpy
,
494 EGLNativePixmapType pix
,
495 const struct native_config
*nconf
)
497 struct dri2_surface
*dri2surf
;
500 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
501 uint depth
, nconf_depth
;
504 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
505 for (i
= 0; i
< dri2dpy
->num_configs
; i
++) {
506 nconf_depth
= util_format_get_blocksizebits(
507 dri2dpy
->configs
[i
].base
.color_format
);
508 /* simple depth match for now */
509 if (depth
== nconf_depth
||
510 (depth
== 24 && depth
+ 8 == nconf_depth
)) {
511 nconf
= &dri2dpy
->configs
[i
].base
;
520 dri2surf
= dri2_display_create_surface(ndpy
,
521 (Drawable
) pix
, nconf
->color_format
);
522 return (dri2surf
) ? &dri2surf
->base
: NULL
;
526 choose_color_format(const __GLcontextModes
*mode
, enum pipe_format formats
[32])
530 switch (mode
->rgbBits
) {
532 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
533 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
536 formats
[count
++] = PIPE_FORMAT_B8G8R8X8_UNORM
;
537 formats
[count
++] = PIPE_FORMAT_X8R8G8B8_UNORM
;
538 formats
[count
++] = PIPE_FORMAT_B8G8R8A8_UNORM
;
539 formats
[count
++] = PIPE_FORMAT_A8R8G8B8_UNORM
;
542 formats
[count
++] = PIPE_FORMAT_B5G6R5_UNORM
;
552 is_format_supported(struct pipe_screen
*screen
,
553 enum pipe_format fmt
, unsigned sample_count
, boolean is_color
)
555 return screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
, sample_count
,
556 (is_color
) ? PIPE_BIND_RENDER_TARGET
:
557 PIPE_BIND_DEPTH_STENCIL
);
561 dri2_display_convert_config(struct native_display
*ndpy
,
562 const __GLcontextModes
*mode
,
563 struct native_config
*nconf
)
565 enum pipe_format formats
[32];
567 int sample_count
= 0;
569 if (!(mode
->renderType
& GLX_RGBA_BIT
) || !mode
->rgbMode
)
572 /* only interested in native renderable configs */
573 if (!mode
->xRenderable
|| !mode
->drawableType
)
576 /* fast/slow configs are probably not relevant */
577 if (mode
->visualRating
== GLX_SLOW_CONFIG
)
580 nconf
->buffer_mask
= 1 << NATIVE_ATTACHMENT_FRONT_LEFT
;
581 if (mode
->doubleBufferMode
)
582 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_LEFT
;
583 if (mode
->stereoMode
) {
584 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT
;
585 if (mode
->doubleBufferMode
)
586 nconf
->buffer_mask
|= 1 << NATIVE_ATTACHMENT_BACK_RIGHT
;
589 /* choose color format */
590 num_formats
= choose_color_format(mode
, formats
);
591 for (i
= 0; i
< num_formats
; i
++) {
592 if (is_format_supported(ndpy
->screen
, formats
[i
], sample_count
, TRUE
)) {
593 nconf
->color_format
= formats
[i
];
597 if (nconf
->color_format
== PIPE_FORMAT_NONE
)
600 if ((mode
->drawableType
& GLX_WINDOW_BIT
) && mode
->visualID
)
601 nconf
->window_bit
= TRUE
;
602 if (mode
->drawableType
& GLX_PIXMAP_BIT
)
603 nconf
->pixmap_bit
= TRUE
;
605 nconf
->native_visual_id
= mode
->visualID
;
606 switch (mode
->visualType
) {
608 nconf
->native_visual_type
= TrueColor
;
610 case GLX_DIRECT_COLOR
:
611 nconf
->native_visual_type
= DirectColor
;
613 case GLX_PSEUDO_COLOR
:
614 nconf
->native_visual_type
= PseudoColor
;
616 case GLX_STATIC_COLOR
:
617 nconf
->native_visual_type
= StaticColor
;
620 nconf
->native_visual_type
= GrayScale
;
622 case GLX_STATIC_GRAY
:
623 nconf
->native_visual_type
= StaticGray
;
626 nconf
->level
= mode
->level
;
628 if (mode
->transparentPixel
== GLX_TRANSPARENT_RGB
) {
629 nconf
->transparent_rgb
= TRUE
;
630 nconf
->transparent_rgb_values
[0] = mode
->transparentRed
;
631 nconf
->transparent_rgb_values
[1] = mode
->transparentGreen
;
632 nconf
->transparent_rgb_values
[2] = mode
->transparentBlue
;
638 static const struct native_config
**
639 dri2_display_get_configs(struct native_display
*ndpy
, int *num_configs
)
641 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
642 const struct native_config
**configs
;
646 if (!dri2dpy
->configs
) {
647 const __GLcontextModes
*modes
;
648 int num_modes
, count
;
650 modes
= x11_screen_get_glx_configs(dri2dpy
->xscr
);
653 num_modes
= x11_context_modes_count(modes
);
655 dri2dpy
->configs
= CALLOC(num_modes
, sizeof(*dri2dpy
->configs
));
656 if (!dri2dpy
->configs
)
660 for (i
= 0; i
< num_modes
; i
++) {
661 struct native_config
*nconf
= &dri2dpy
->configs
[count
].base
;
663 if (dri2_display_convert_config(&dri2dpy
->base
, modes
, nconf
)) {
665 /* look for duplicates */
666 for (j
= 0; j
< count
; j
++) {
667 if (memcmp(&dri2dpy
->configs
[j
], nconf
, sizeof(*nconf
)) == 0)
676 dri2dpy
->num_configs
= count
;
679 configs
= MALLOC(dri2dpy
->num_configs
* sizeof(*configs
));
681 for (i
= 0; i
< dri2dpy
->num_configs
; i
++)
682 configs
[i
] = (const struct native_config
*) &dri2dpy
->configs
[i
];
684 *num_configs
= dri2dpy
->num_configs
;
691 dri2_display_get_pixmap_format(struct native_display
*ndpy
,
692 EGLNativePixmapType pix
,
693 enum pipe_format
*format
)
695 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
696 boolean ret
= EGL_TRUE
;
699 depth
= x11_drawable_get_depth(dri2dpy
->xscr
, (Drawable
) pix
);
703 *format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
706 *format
= PIPE_FORMAT_B5G6R5_UNORM
;
709 *format
= PIPE_FORMAT_NONE
;
718 dri2_display_get_param(struct native_display
*ndpy
,
719 enum native_param_type param
)
724 case NATIVE_PARAM_USE_NATIVE_BUFFER
:
725 /* DRI2GetBuffers uses the native buffers */
728 case NATIVE_PARAM_PRESERVE_BUFFER
:
729 /* DRI2CopyRegion is used */
732 case NATIVE_PARAM_PRESENT_REGION
:
735 case NATIVE_PARAM_MAX_SWAP_INTERVAL
:
745 dri2_display_destroy(struct native_display
*ndpy
)
747 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
749 FREE(dri2dpy
->configs
);
751 if (dri2dpy
->base
.screen
)
752 dri2dpy
->base
.screen
->destroy(dri2dpy
->base
.screen
);
754 if (dri2dpy
->surfaces
)
755 util_hash_table_destroy(dri2dpy
->surfaces
);
757 #ifdef HAVE_WAYLAND_BACKEND
758 wayland_drm_bufmgr_destroy(ndpy
->wayland_bufmgr
);
762 x11_screen_destroy(dri2dpy
->xscr
);
763 if (dri2dpy
->own_dpy
)
764 XCloseDisplay(dri2dpy
->dpy
);
769 dri2_display_invalidate_buffers(struct x11_screen
*xscr
, Drawable drawable
,
772 struct native_display
*ndpy
= (struct native_display
* ) user_data
;
773 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
774 struct native_surface
*nsurf
;
775 struct dri2_surface
*dri2surf
;
777 nsurf
= (struct native_surface
*)
778 util_hash_table_get(dri2dpy
->surfaces
, (void *) drawable
);
782 dri2surf
= dri2_surface(nsurf
);
784 dri2surf
->server_stamp
++;
785 dri2dpy
->event_handler
->invalid_surface(&dri2dpy
->base
,
786 &dri2surf
->base
, dri2surf
->server_stamp
);
789 #ifdef HAVE_WAYLAND_BACKEND
792 dri2_display_authenticate(void *user_data
, uint32_t magic
)
794 struct native_display
*ndpy
= user_data
;
795 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
797 return x11_screen_authenticate(dri2dpy
->xscr
, magic
);
800 #endif /* HAVE_WAYLAND_BACKEND */
803 * Initialize DRI2 and pipe screen.
806 dri2_display_init_screen(struct native_display
*ndpy
)
808 struct dri2_display
*dri2dpy
= dri2_display(ndpy
);
811 if (!x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_DRI2
) ||
812 !x11_screen_support(dri2dpy
->xscr
, X11_SCREEN_EXTENSION_GLX
)) {
813 _eglLog(_EGL_WARNING
, "GLX/DRI2 is not supported");
817 dri2dpy
->dri_driver
= x11_screen_probe_dri2(dri2dpy
->xscr
,
818 &dri2dpy
->dri_major
, &dri2dpy
->dri_minor
);
820 fd
= x11_screen_enable_dri2(dri2dpy
->xscr
,
821 dri2_display_invalidate_buffers
, &dri2dpy
->base
);
825 dri2dpy
->base
.screen
=
826 dri2dpy
->event_handler
->new_drm_screen(&dri2dpy
->base
,
827 dri2dpy
->dri_driver
, fd
);
828 if (!dri2dpy
->base
.screen
) {
829 _eglLog(_EGL_DEBUG
, "failed to create DRM screen");
833 #ifdef HAVE_WAYLAND_BACKEND
834 dri2dpy
->base
.wayland_bufmgr
= wayland_drm_bufmgr_create(
835 dri2_display_authenticate
, dri2dpy
,
836 x11_screen_get_device_name(dri2dpy
->xscr
));
844 dri2_display_hash_table_hash(void *key
)
846 XID drawable
= pointer_to_uintptr(key
);
847 return (unsigned) drawable
;
851 dri2_display_hash_table_compare(void *key1
, void *key2
)
853 return ((char *) key1
- (char *) key2
);
856 struct native_display
*
857 x11_create_dri2_display(Display
*dpy
,
858 const struct native_event_handler
*event_handler
)
860 struct dri2_display
*dri2dpy
;
862 dri2dpy
= CALLOC_STRUCT(dri2_display
);
866 dri2dpy
->event_handler
= event_handler
;
870 dri2dpy
->dpy
= XOpenDisplay(NULL
);
872 dri2_display_destroy(&dri2dpy
->base
);
875 dri2dpy
->own_dpy
= TRUE
;
878 dri2dpy
->xscr_number
= DefaultScreen(dri2dpy
->dpy
);
879 dri2dpy
->xscr
= x11_screen_create(dri2dpy
->dpy
, dri2dpy
->xscr_number
);
880 if (!dri2dpy
->xscr
) {
881 dri2_display_destroy(&dri2dpy
->base
);
885 dri2dpy
->surfaces
= util_hash_table_create(dri2_display_hash_table_hash
,
886 dri2_display_hash_table_compare
);
887 if (!dri2dpy
->surfaces
) {
888 dri2_display_destroy(&dri2dpy
->base
);
892 dri2dpy
->base
.init_screen
= dri2_display_init_screen
;
893 dri2dpy
->base
.destroy
= dri2_display_destroy
;
894 dri2dpy
->base
.get_param
= dri2_display_get_param
;
895 dri2dpy
->base
.get_configs
= dri2_display_get_configs
;
896 dri2dpy
->base
.get_pixmap_format
= dri2_display_get_pixmap_format
;
897 dri2dpy
->base
.copy_to_pixmap
= native_display_copy_to_pixmap
;
898 dri2dpy
->base
.create_window_surface
= dri2_display_create_window_surface
;
899 dri2dpy
->base
.create_pixmap_surface
= dri2_display_create_pixmap_surface
;
901 return &dri2dpy
->base
;
904 #else /* GLX_DIRECT_RENDERING */
906 struct native_display
*
907 x11_create_dri2_display(Display
*dpy
,
908 const struct native_event_handler
*event_handler
)
913 #endif /* GLX_DIRECT_RENDERING */