2 * Copyright © 2008 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Soft-
6 * ware"), to deal in the Software without restriction, including without
7 * limitation the rights to use, copy, modify, merge, publish, distribute,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, provided that the above copyright
10 * notice(s) and this permission notice appear in all copies of the Soft-
11 * ware and that both the above copyright notice(s) and this permission
12 * notice appear in supporting documentation.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
17 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
18 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
19 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
22 * MANCE OF THIS SOFTWARE.
24 * Except as contained in this notice, the name of a copyright holder shall
25 * not be used in advertising or otherwise to promote the sale, use or
26 * other dealings in this Software without prior written authorization of
27 * the copyright holder.
30 * Kristian Høgsberg (krh@redhat.com)
33 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
36 #include <X11/extensions/Xfixes.h>
37 #include <X11/extensions/Xdamage.h>
39 #include "glxclient.h"
40 #include <X11/extensions/dri2proto.h>
45 #include <sys/types.h>
49 #include "dri_common.h"
51 /* From xmlpool/options.h, user exposed so should be stable */
52 #define DRI_CONF_VBLANK_NEVER 0
53 #define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
54 #define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
55 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
65 ** XFree86-DRI version information
71 int invalidateAvailable
;
73 __glxHashTable
*dri2Hash
;
75 const __DRIextension
*loader_extensions
[4];
79 struct glx_screen base
;
81 __DRIscreen
*driScreen
;
82 __GLXDRIscreen vtable
;
83 const __DRIdri2Extension
*dri2
;
84 const __DRIcoreExtension
*core
;
86 const __DRI2flushExtension
*f
;
87 const __DRI2configQueryExtension
*config
;
88 const __DRItexBufferExtension
*texBuffer
;
89 const __DRIconfig
**driver_configs
;
97 struct glx_context base
;
98 __DRIcontext
*driContext
;
103 __GLXDRIdrawable base
;
104 __DRIdrawable
*driDrawable
;
105 __DRIbuffer buffers
[5];
113 static const struct glx_context_vtable dri2_context_vtable
;
116 dri2_destroy_context(struct glx_context
*context
)
118 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
119 struct dri2_screen
*psc
= (struct dri2_screen
*) context
->psc
;
122 glx_send_destroy_context(psc
->base
.dpy
, context
->xid
);
124 if (context
->extensions
)
125 XFree((char *) context
->extensions
);
127 GarbageCollectDRIDrawables(context
->psc
);
129 (*psc
->core
->destroyContext
) (pcp
->driContext
);
135 dri2_bind_context(struct glx_context
*context
, struct glx_context
*old
,
136 GLXDrawable draw
, GLXDrawable read
)
138 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
139 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->base
.psc
;
140 struct dri2_drawable
*pdraw
, *pread
;
142 pdraw
= (struct dri2_drawable
*) driFetchDrawable(context
, draw
);
143 pread
= (struct dri2_drawable
*) driFetchDrawable(context
, read
);
145 if (pdraw
== NULL
|| pread
== NULL
)
146 return GLXBadDrawable
;
148 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
149 pdraw
->driDrawable
, pread
->driDrawable
))
152 return GLXBadContext
;
156 dri2_unbind_context(struct glx_context
*context
, struct glx_context
*new)
158 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
159 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->base
.psc
;
161 (*psc
->core
->unbindContext
) (pcp
->driContext
);
164 static struct glx_context
*
165 dri2_create_context(struct glx_screen
*base
,
166 struct glx_config
*config_base
,
167 struct glx_context
*shareList
, int renderType
)
169 struct dri2_context
*pcp
, *pcp_shared
;
170 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
171 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
172 __DRIcontext
*shared
= NULL
;
175 pcp_shared
= (struct dri2_context
*) shareList
;
176 shared
= pcp_shared
->driContext
;
179 pcp
= Xmalloc(sizeof *pcp
);
183 memset(pcp
, 0, sizeof *pcp
);
184 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
190 (*psc
->dri2
->createNewContext
) (psc
->driScreen
,
191 config
->driConfig
, shared
, pcp
);
193 if (pcp
->driContext
== NULL
) {
198 pcp
->base
.vtable
= &dri2_context_vtable
;
204 dri2DestroyDrawable(__GLXDRIdrawable
*base
)
206 struct dri2_screen
*psc
= (struct dri2_screen
*) base
->psc
;
207 struct dri2_drawable
*pdraw
= (struct dri2_drawable
*) base
;
208 struct glx_display
*dpyPriv
= psc
->base
.display
;
209 struct dri2_display
*pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;
211 __glxHashDelete(pdp
->dri2Hash
, pdraw
->base
.xDrawable
);
212 (*psc
->core
->destroyDrawable
) (pdraw
->driDrawable
);
213 DRI2DestroyDrawable(psc
->base
.dpy
, pdraw
->base
.xDrawable
);
217 static __GLXDRIdrawable
*
218 dri2CreateDrawable(struct glx_screen
*base
, XID xDrawable
,
219 GLXDrawable drawable
, struct glx_config
*config_base
)
221 struct dri2_drawable
*pdraw
;
222 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
223 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
224 struct glx_display
*dpyPriv
;
225 struct dri2_display
*pdp
;
226 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
228 pdraw
= Xmalloc(sizeof(*pdraw
));
232 memset(pdraw
, 0, sizeof *pdraw
);
233 pdraw
->base
.destroyDrawable
= dri2DestroyDrawable
;
234 pdraw
->base
.xDrawable
= xDrawable
;
235 pdraw
->base
.drawable
= drawable
;
236 pdraw
->base
.psc
= &psc
->base
;
237 pdraw
->bufferCount
= 0;
238 pdraw
->swap_interval
= 1; /* default may be overridden below */
239 pdraw
->have_back
= 0;
242 psc
->config
->configQueryi(psc
->driScreen
,
243 "vblank_mode", &vblank_mode
);
245 switch (vblank_mode
) {
246 case DRI_CONF_VBLANK_NEVER
:
247 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
248 pdraw
->swap_interval
= 0;
250 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
251 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
253 pdraw
->swap_interval
= 1;
257 DRI2CreateDrawable(psc
->base
.dpy
, xDrawable
);
259 dpyPriv
= __glXInitialize(psc
->base
.dpy
);
260 pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;;
261 /* Create a new drawable */
263 (*psc
->dri2
->createNewDrawable
) (psc
->driScreen
,
264 config
->driConfig
, pdraw
);
266 if (!pdraw
->driDrawable
) {
267 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
272 if (__glxHashInsert(pdp
->dri2Hash
, xDrawable
, pdraw
)) {
273 (*psc
->core
->destroyDrawable
) (pdraw
->driDrawable
);
274 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
280 #ifdef X_DRI2SwapInterval
282 * Make sure server has the same swap interval we do for the new
285 if (pdp
->swapAvailable
)
286 DRI2SwapInterval(psc
->base
.dpy
, xDrawable
, pdraw
->swap_interval
);
295 dri2DrawableGetMSC(struct glx_screen
*psc
, __GLXDRIdrawable
*pdraw
,
296 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
298 CARD64 dri2_ust
, dri2_msc
, dri2_sbc
;
301 ret
= DRI2GetMSC(psc
->dpy
, pdraw
->xDrawable
,
302 &dri2_ust
, &dri2_msc
, &dri2_sbc
);
316 dri2WaitForMSC(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
317 int64_t remainder
, int64_t *ust
, int64_t *msc
, int64_t *sbc
)
319 CARD64 dri2_ust
, dri2_msc
, dri2_sbc
;
322 ret
= DRI2WaitMSC(pdraw
->psc
->dpy
, pdraw
->xDrawable
, target_msc
, divisor
,
323 remainder
, &dri2_ust
, &dri2_msc
, &dri2_sbc
);
332 dri2WaitForSBC(__GLXDRIdrawable
*pdraw
, int64_t target_sbc
, int64_t *ust
,
333 int64_t *msc
, int64_t *sbc
)
335 CARD64 dri2_ust
, dri2_msc
, dri2_sbc
;
338 ret
= DRI2WaitSBC(pdraw
->psc
->dpy
, pdraw
->xDrawable
,
339 target_sbc
, &dri2_ust
, &dri2_msc
, &dri2_sbc
);
347 #endif /* X_DRI2WaitMSC */
350 dri2CopySubBuffer(__GLXDRIdrawable
*pdraw
, int x
, int y
, int width
, int height
)
352 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
353 struct dri2_screen
*psc
= (struct dri2_screen
*) pdraw
->psc
;
355 XserverRegion region
;
357 /* Check we have the right attachments */
358 if (!priv
->have_back
)
362 xrect
.y
= priv
->height
- y
- height
;
364 xrect
.height
= height
;
368 (*psc
->f
->flush
) (priv
->driDrawable
);
371 region
= XFixesCreateRegion(psc
->base
.dpy
, &xrect
, 1);
372 DRI2CopyRegion(psc
->base
.dpy
, pdraw
->xDrawable
, region
,
373 DRI2BufferFrontLeft
, DRI2BufferBackLeft
);
375 /* Refresh the fake front (if present) after we just damaged the real
378 if (priv
->have_fake_front
)
379 DRI2CopyRegion(psc
->base
.dpy
, pdraw
->xDrawable
, region
,
380 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
382 XFixesDestroyRegion(psc
->base
.dpy
, region
);
386 dri2_copy_drawable(struct dri2_drawable
*priv
, int dest
, int src
)
389 XserverRegion region
;
390 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
394 xrect
.width
= priv
->width
;
395 xrect
.height
= priv
->height
;
399 (*psc
->f
->flush
) (priv
->driDrawable
);
402 region
= XFixesCreateRegion(psc
->base
.dpy
, &xrect
, 1);
403 DRI2CopyRegion(psc
->base
.dpy
, priv
->base
.xDrawable
, region
, dest
, src
);
404 XFixesDestroyRegion(psc
->base
.dpy
, region
);
409 dri2_wait_x(struct glx_context
*gc
)
411 struct dri2_drawable
*priv
= (struct dri2_drawable
*)
412 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
414 if (priv
== NULL
|| !priv
->have_fake_front
)
417 dri2_copy_drawable(priv
, DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
421 dri2_wait_gl(struct glx_context
*gc
)
423 struct dri2_drawable
*priv
= (struct dri2_drawable
*)
424 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
426 if (priv
== NULL
|| !priv
->have_fake_front
)
429 dri2_copy_drawable(priv
, DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
433 dri2FlushFrontBuffer(__DRIdrawable
*driDrawable
, void *loaderPrivate
)
435 struct dri2_drawable
*pdraw
= loaderPrivate
;
436 struct glx_display
*priv
= __glXInitialize(pdraw
->base
.psc
->dpy
);
437 struct dri2_display
*pdp
= (struct dri2_display
*)priv
->dri2Display
;
438 struct glx_context
*gc
= __glXGetCurrentContext();
440 /* Old servers don't send invalidate events */
441 if (!pdp
->invalidateAvailable
)
442 dri2InvalidateBuffers(priv
->dpy
, pdraw
->base
.xDrawable
);
449 dri2DestroyScreen(struct glx_screen
*base
)
451 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
453 /* Free the direct rendering per screen data */
454 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
455 driDestroyConfigs(psc
->driver_configs
);
461 * Process list of buffer received from the server
463 * Processes the list of buffers received in a reply from the server to either
464 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
467 process_buffers(struct dri2_drawable
* pdraw
, DRI2Buffer
* buffers
,
472 pdraw
->bufferCount
= count
;
473 pdraw
->have_fake_front
= 0;
474 pdraw
->have_back
= 0;
476 /* This assumes the DRI2 buffer attachment tokens matches the
477 * __DRIbuffer tokens. */
478 for (i
= 0; i
< count
; i
++) {
479 pdraw
->buffers
[i
].attachment
= buffers
[i
].attachment
;
480 pdraw
->buffers
[i
].name
= buffers
[i
].name
;
481 pdraw
->buffers
[i
].pitch
= buffers
[i
].pitch
;
482 pdraw
->buffers
[i
].cpp
= buffers
[i
].cpp
;
483 pdraw
->buffers
[i
].flags
= buffers
[i
].flags
;
484 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
485 pdraw
->have_fake_front
= 1;
486 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_BACK_LEFT
)
487 pdraw
->have_back
= 1;
493 dri2SwapBuffers(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
496 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
497 struct glx_display
*dpyPriv
= __glXInitialize(priv
->base
.psc
->dpy
);
498 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
499 struct dri2_display
*pdp
=
500 (struct dri2_display
*)dpyPriv
->dri2Display
;
505 (*psc
->f
->flush
)(priv
->driDrawable
);
508 /* Old servers don't send invalidate events */
509 if (!pdp
->invalidateAvailable
)
510 dri2InvalidateBuffers(dpyPriv
->dpy
, pdraw
->xDrawable
);
512 /* Old servers can't handle swapbuffers */
513 if (!pdp
->swapAvailable
) {
514 dri2CopySubBuffer(pdraw
, 0, 0, priv
->width
, priv
->height
);
518 #ifdef X_DRI2SwapBuffers
519 DRI2SwapBuffers(psc
->base
.dpy
, pdraw
->xDrawable
, target_msc
, divisor
,
527 dri2GetBuffers(__DRIdrawable
* driDrawable
,
528 int *width
, int *height
,
529 unsigned int *attachments
, int count
,
530 int *out_count
, void *loaderPrivate
)
532 struct dri2_drawable
*pdraw
= loaderPrivate
;
535 buffers
= DRI2GetBuffers(pdraw
->base
.psc
->dpy
, pdraw
->base
.xDrawable
,
536 width
, height
, attachments
, count
, out_count
);
540 pdraw
->width
= *width
;
541 pdraw
->height
= *height
;
542 process_buffers(pdraw
, buffers
, *out_count
);
546 return pdraw
->buffers
;
550 dri2GetBuffersWithFormat(__DRIdrawable
* driDrawable
,
551 int *width
, int *height
,
552 unsigned int *attachments
, int count
,
553 int *out_count
, void *loaderPrivate
)
555 struct dri2_drawable
*pdraw
= loaderPrivate
;
558 buffers
= DRI2GetBuffersWithFormat(pdraw
->base
.psc
->dpy
,
559 pdraw
->base
.xDrawable
,
560 width
, height
, attachments
,
565 pdraw
->width
= *width
;
566 pdraw
->height
= *height
;
567 process_buffers(pdraw
, buffers
, *out_count
);
571 return pdraw
->buffers
;
574 #ifdef X_DRI2SwapInterval
577 dri2SetSwapInterval(__GLXDRIdrawable
*pdraw
, int interval
)
579 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
580 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
581 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
584 psc
->config
->configQueryi(psc
->driScreen
,
585 "vblank_mode", &vblank_mode
);
587 switch (vblank_mode
) {
588 case DRI_CONF_VBLANK_NEVER
:
589 return GLX_BAD_VALUE
;
590 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
592 return GLX_BAD_VALUE
;
598 DRI2SwapInterval(priv
->base
.psc
->dpy
, priv
->base
.xDrawable
, interval
);
599 priv
->swap_interval
= interval
;
605 dri2GetSwapInterval(__GLXDRIdrawable
*pdraw
)
607 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
609 return priv
->swap_interval
;
612 #endif /* X_DRI2SwapInterval */
614 static const __DRIdri2LoaderExtension dri2LoaderExtension
= {
615 {__DRI_DRI2_LOADER
, __DRI_DRI2_LOADER_VERSION
},
617 dri2FlushFrontBuffer
,
618 dri2GetBuffersWithFormat
,
621 static const __DRIdri2LoaderExtension dri2LoaderExtension_old
= {
622 {__DRI_DRI2_LOADER
, __DRI_DRI2_LOADER_VERSION
},
624 dri2FlushFrontBuffer
,
628 #ifdef __DRI_USE_INVALIDATE
629 static const __DRIuseInvalidateExtension dri2UseInvalidate
= {
630 { __DRI_USE_INVALIDATE
, __DRI_USE_INVALIDATE_VERSION
}
635 dri2InvalidateBuffers(Display
*dpy
, XID drawable
)
637 __GLXDRIdrawable
*pdraw
=
638 dri2GetGlxDrawableFromXDrawableId(dpy
, drawable
);
639 struct dri2_screen
*psc
= (struct dri2_screen
*) pdraw
->psc
;
640 struct dri2_drawable
*pdp
= (struct dri2_drawable
*) pdraw
;
642 #if __DRI2_FLUSH_VERSION >= 3
644 psc
->f
->invalidate(pdp
->driDrawable
);
649 dri2_bind_tex_image(Display
* dpy
,
650 GLXDrawable drawable
,
651 int buffer
, const int *attrib_list
)
653 struct glx_context
*gc
= __glXGetCurrentContext();
654 struct dri2_context
*pcp
= (struct dri2_context
*) gc
;
655 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
656 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
657 struct dri2_drawable
*pdraw
= (struct dri2_drawable
*) base
;
658 struct dri2_display
*pdp
=
659 (struct dri2_display
*) dpyPriv
->dri2Display
;
660 struct dri2_screen
*psc
;
663 psc
= (struct dri2_screen
*) base
->psc
;
665 #if __DRI2_FLUSH_VERSION >= 3
666 if (!pdp
->invalidateAvailable
&& psc
->f
)
667 psc
->f
->invalidate(pdraw
->driDrawable
);
670 if (psc
->texBuffer
->base
.version
>= 2 &&
671 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
672 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
673 pdraw
->base
.textureTarget
,
674 pdraw
->base
.textureFormat
,
678 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
679 pdraw
->base
.textureTarget
,
686 dri2_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
690 static const struct glx_context_vtable dri2_context_vtable
= {
691 dri2_destroy_context
,
698 dri2_release_tex_image
,
702 dri2BindExtensions(struct dri2_screen
*psc
, const __DRIextension
**extensions
)
706 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_video_sync");
707 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_swap_control");
708 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_swap_control");
709 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
711 /* FIXME: if DRI2 version supports it... */
712 __glXEnableDirectExtension(&psc
->base
, "INTEL_swap_event");
714 for (i
= 0; extensions
[i
]; i
++) {
715 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
716 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
717 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
720 if ((strcmp(extensions
[i
]->name
, __DRI2_FLUSH
) == 0)) {
721 psc
->f
= (__DRI2flushExtension
*) extensions
[i
];
722 /* internal driver extension, no GL extension exposed */
725 if ((strcmp(extensions
[i
]->name
, __DRI2_CONFIG_QUERY
) == 0))
726 psc
->config
= (__DRI2configQueryExtension
*) extensions
[i
];
730 static const struct glx_screen_vtable dri2_screen_vtable
= {
734 static struct glx_screen
*
735 dri2CreateScreen(int screen
, struct glx_display
* priv
)
737 const __DRIconfig
**driver_configs
;
738 const __DRIextension
**extensions
;
739 const struct dri2_display
*const pdp
= (struct dri2_display
*)
741 struct dri2_screen
*psc
;
743 char *driverName
, *deviceName
;
747 psc
= Xmalloc(sizeof *psc
);
751 memset(psc
, 0, sizeof *psc
);
752 if (!glx_screen_init(&psc
->base
, screen
, priv
))
755 if (!DRI2Connect(priv
->dpy
, RootWindow(priv
->dpy
, screen
),
756 &driverName
, &deviceName
)) {
761 psc
->driver
= driOpenDriver(driverName
);
762 if (psc
->driver
== NULL
) {
763 ErrorMessageF("driver pointer missing\n");
767 extensions
= dlsym(psc
->driver
, __DRI_DRIVER_EXTENSIONS
);
768 if (extensions
== NULL
) {
769 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
773 for (i
= 0; extensions
[i
]; i
++) {
774 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
775 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
776 if (strcmp(extensions
[i
]->name
, __DRI_DRI2
) == 0)
777 psc
->dri2
= (__DRIdri2Extension
*) extensions
[i
];
780 if (psc
->core
== NULL
|| psc
->dri2
== NULL
) {
781 ErrorMessageF("core dri or dri2 extension not found\n");
785 psc
->fd
= open(deviceName
, O_RDWR
);
787 ErrorMessageF("failed to open drm device: %s\n", strerror(errno
));
791 if (drmGetMagic(psc
->fd
, &magic
)) {
792 ErrorMessageF("failed to get magic\n");
796 if (!DRI2Authenticate(priv
->dpy
, RootWindow(priv
->dpy
, screen
), magic
)) {
797 ErrorMessageF("failed to authenticate magic %d\n", magic
);
802 /* If the server does not support the protocol for
803 * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
806 psc
->dri2
->createNewScreen(screen
, psc
->fd
,
807 (const __DRIextension
**)
808 &pdp
->loader_extensions
[0],
809 &driver_configs
, psc
);
811 if (psc
->driScreen
== NULL
) {
812 ErrorMessageF("failed to create dri screen\n");
816 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
817 dri2BindExtensions(psc
, extensions
);
820 driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
822 driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
824 psc
->driver_configs
= driver_configs
;
826 psc
->base
.vtable
= &dri2_screen_vtable
;
828 psc
->base
.driScreen
= psp
;
829 psp
->destroyScreen
= dri2DestroyScreen
;
830 psp
->createDrawable
= dri2CreateDrawable
;
831 psp
->swapBuffers
= dri2SwapBuffers
;
832 psp
->getDrawableMSC
= NULL
;
833 psp
->waitForMSC
= NULL
;
834 psp
->waitForSBC
= NULL
;
835 psp
->setSwapInterval
= NULL
;
836 psp
->getSwapInterval
= NULL
;
838 if (pdp
->driMinor
>= 2) {
840 psp
->getDrawableMSC
= dri2DrawableGetMSC
;
843 psp
->waitForMSC
= dri2WaitForMSC
;
844 psp
->waitForSBC
= dri2WaitForSBC
;
846 #ifdef X_DRI2SwapInterval
847 psp
->setSwapInterval
= dri2SetSwapInterval
;
848 psp
->getSwapInterval
= dri2GetSwapInterval
;
850 #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval)
851 __glXEnableDirectExtension(&psc
->base
, "GLX_OML_sync_control");
855 /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
857 psp
->copySubBuffer
= dri2CopySubBuffer
;
858 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
870 /* FIXME: clean up here */
875 /* Called from __glXFreeDisplayPrivate.
878 dri2DestroyDisplay(__GLXDRIdisplay
* dpy
)
883 _X_HIDDEN __GLXDRIdrawable
*
884 dri2GetGlxDrawableFromXDrawableId(Display
*dpy
, XID id
)
886 struct glx_display
*d
= __glXInitialize(dpy
);
887 struct dri2_display
*pdp
= (struct dri2_display
*) d
->dri2Display
;
888 __GLXDRIdrawable
*pdraw
;
890 if (__glxHashLookup(pdp
->dri2Hash
, id
, (void *) &pdraw
) == 0)
897 * Allocate, initialize and return a __DRIdisplayPrivate object.
898 * This is called from __glXInitialize() when we are given a new
901 _X_HIDDEN __GLXDRIdisplay
*
902 dri2CreateDisplay(Display
* dpy
)
904 struct dri2_display
*pdp
;
905 int eventBase
, errorBase
, i
;
907 if (!DRI2QueryExtension(dpy
, &eventBase
, &errorBase
))
910 pdp
= Xmalloc(sizeof *pdp
);
914 if (!DRI2QueryVersion(dpy
, &pdp
->driMajor
, &pdp
->driMinor
)) {
920 pdp
->swapAvailable
= (pdp
->driMinor
>= 2);
921 pdp
->invalidateAvailable
= (pdp
->driMinor
>= 3);
923 pdp
->base
.destroyDisplay
= dri2DestroyDisplay
;
924 pdp
->base
.createScreen
= dri2CreateScreen
;
927 if (pdp
->driMinor
< 1)
928 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension_old
.base
;
930 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension
.base
;
932 pdp
->loader_extensions
[i
++] = &systemTimeExtension
.base
;
934 #ifdef __DRI_USE_INVALIDATE
935 pdp
->loader_extensions
[i
++] = &dri2UseInvalidate
.base
;
937 pdp
->loader_extensions
[i
++] = NULL
;
939 pdp
->dri2Hash
= __glxHashCreate();
940 if (pdp
->dri2Hash
== NULL
) {
948 #endif /* GLX_DIRECT_RENDERING */