2 * Copyright © 2010 Intel Corporation
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@bitplanet.net)
34 #include "glxclient.h"
36 extern struct _glapi_table
*__glXNewIndirectAPI(void);
39 ** All indirect rendering contexts will share the same indirect dispatch table.
41 static struct _glapi_table
*IndirectAPI
= NULL
;
44 indirect_destroy_context(struct glx_context
*gc
)
46 if (!gc
->imported
&& gc
->xid
)
47 glx_send_destroy_context(gc
->psc
->dpy
, gc
->xid
);
49 __glXFreeVertexArrayState(gc
);
52 XFree((char *) gc
->vendor
);
54 XFree((char *) gc
->renderer
);
56 XFree((char *) gc
->version
);
58 XFree((char *) gc
->extensions
);
59 __glFreeAttributeState(gc
);
60 XFree((char *) gc
->buf
);
61 Xfree((char *) gc
->client_state_private
);
66 SendMakeCurrentRequest(Display
* dpy
, CARD8 opcode
,
67 GLXContextID gc_id
, GLXContextTag gc_tag
,
68 GLXDrawable draw
, GLXDrawable read
,
69 xGLXMakeCurrentReply
* reply
)
76 xGLXMakeCurrentReq
*req
;
78 GetReq(GLXMakeCurrent
, req
);
79 req
->reqType
= opcode
;
80 req
->glxCode
= X_GLXMakeCurrent
;
83 req
->oldContextTag
= gc_tag
;
86 struct glx_display
*priv
= __glXInitialize(dpy
);
88 /* If the server can support the GLX 1.3 version, we should
89 * perfer that. Not only that, some servers support GLX 1.3 but
90 * not the SGI extension.
93 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
94 xGLXMakeContextCurrentReq
*req
;
96 GetReq(GLXMakeContextCurrent
, req
);
97 req
->reqType
= opcode
;
98 req
->glxCode
= X_GLXMakeContextCurrent
;
100 req
->readdrawable
= read
;
101 req
->context
= gc_id
;
102 req
->oldContextTag
= gc_tag
;
105 xGLXVendorPrivateWithReplyReq
*vpreq
;
106 xGLXMakeCurrentReadSGIReq
*req
;
108 GetReqExtra(GLXVendorPrivateWithReply
,
109 sz_xGLXMakeCurrentReadSGIReq
-
110 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
111 req
= (xGLXMakeCurrentReadSGIReq
*) vpreq
;
112 req
->reqType
= opcode
;
113 req
->glxCode
= X_GLXVendorPrivateWithReply
;
114 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
115 req
->drawable
= draw
;
116 req
->readable
= read
;
117 req
->context
= gc_id
;
118 req
->oldContextTag
= gc_tag
;
122 ret
= _XReply(dpy
, (xReply
*) reply
, 0, False
);
131 indirect_bind_context(struct glx_context
*gc
, struct glx_context
*old
,
132 GLXDrawable draw
, GLXDrawable read
)
134 xGLXMakeCurrentReply reply
;
136 __GLXattribute
*state
;
137 Display
*dpy
= gc
->psc
->dpy
;
138 int opcode
= __glXSetupForCommand(dpy
);
140 if (old
!= &dummyContext
&& !old
->isDirect
&& old
->psc
->dpy
== dpy
) {
141 tag
= old
->currentContextTag
;
142 old
->currentContextTag
= 0;
147 SendMakeCurrentRequest(dpy
, opcode
, gc
->xid
, tag
, draw
, read
, &reply
);
150 IndirectAPI
= __glXNewIndirectAPI();
151 _glapi_set_dispatch(IndirectAPI
);
153 gc
->currentContextTag
= reply
.contextTag
;
154 state
= gc
->client_state_private
;
155 if (state
->array_state
== NULL
) {
156 glGetString(GL_EXTENSIONS
);
157 glGetString(GL_VERSION
);
158 __glXInitVertexArrayState(gc
);
165 indirect_unbind_context(struct glx_context
*gc
, struct glx_context
*new)
167 Display
*dpy
= gc
->psc
->dpy
;
168 int opcode
= __glXSetupForCommand(dpy
);
169 xGLXMakeCurrentReply reply
;
174 /* We are either switching to no context, away from a indirect
175 * context to a direct context or from one dpy to another and have
176 * to send a request to the dpy to unbind the previous context.
178 if (!new || new->isDirect
|| new->psc
->dpy
!= dpy
) {
179 SendMakeCurrentRequest(dpy
, opcode
, None
,
180 gc
->currentContextTag
, None
, None
, &reply
);
181 gc
->currentContextTag
= 0;
186 indirect_wait_gl(struct glx_context
*gc
)
189 Display
*dpy
= gc
->currentDpy
;
191 /* Flush any pending commands out */
192 __glXFlushRenderBuffer(gc
, gc
->pc
);
194 /* Send the glXWaitGL request */
196 GetReq(GLXWaitGL
, req
);
197 req
->reqType
= gc
->majorOpcode
;
198 req
->glxCode
= X_GLXWaitGL
;
199 req
->contextTag
= gc
->currentContextTag
;
205 indirect_wait_x(struct glx_context
*gc
)
208 Display
*dpy
= gc
->currentDpy
;
210 /* Flush any pending commands out */
211 __glXFlushRenderBuffer(gc
, gc
->pc
);
214 GetReq(GLXWaitX
, req
);
215 req
->reqType
= gc
->majorOpcode
;
216 req
->glxCode
= X_GLXWaitX
;
217 req
->contextTag
= gc
->currentContextTag
;
223 indirect_use_x_font(struct glx_context
*gc
,
224 Font font
, int first
, int count
, int listBase
)
226 xGLXUseXFontReq
*req
;
227 Display
*dpy
= gc
->currentDpy
;
229 /* Flush any pending commands out */
230 __glXFlushRenderBuffer(gc
, gc
->pc
);
232 /* Send the glXUseFont request */
234 GetReq(GLXUseXFont
, req
);
235 req
->reqType
= gc
->majorOpcode
;
236 req
->glxCode
= X_GLXUseXFont
;
237 req
->contextTag
= gc
->currentContextTag
;
241 req
->listBase
= listBase
;
247 indirect_bind_tex_image(Display
* dpy
,
248 GLXDrawable drawable
,
249 int buffer
, const int *attrib_list
)
251 xGLXVendorPrivateReq
*req
;
252 struct glx_context
*gc
= __glXGetCurrentContext();
253 CARD32
*drawable_ptr
;
255 CARD32
*num_attrib_ptr
;
262 while (attrib_list
[i
* 2] != None
)
266 opcode
= __glXSetupForCommand(dpy
);
271 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
272 req
->reqType
= opcode
;
273 req
->glxCode
= X_GLXVendorPrivate
;
274 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
275 req
->contextTag
= gc
->currentContextTag
;
277 drawable_ptr
= (CARD32
*) (req
+ 1);
278 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
279 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
280 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
282 *drawable_ptr
= drawable
;
283 *buffer_ptr
= buffer
;
284 *num_attrib_ptr
= (CARD32
) i
;
288 while (attrib_list
[i
* 2] != None
) {
289 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
290 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
300 indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
302 xGLXVendorPrivateReq
*req
;
303 struct glx_context
*gc
= __glXGetCurrentContext();
304 CARD32
*drawable_ptr
;
308 opcode
= __glXSetupForCommand(dpy
);
313 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
314 req
->reqType
= opcode
;
315 req
->glxCode
= X_GLXVendorPrivate
;
316 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
317 req
->contextTag
= gc
->currentContextTag
;
319 drawable_ptr
= (CARD32
*) (req
+ 1);
320 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
322 *drawable_ptr
= drawable
;
323 *buffer_ptr
= buffer
;
329 static const struct glx_context_vtable indirect_context_vtable
= {
330 indirect_destroy_context
,
331 indirect_bind_context
,
332 indirect_unbind_context
,
336 indirect_bind_tex_image
,
337 indirect_release_tex_image
,
338 NULL
, /* get_proc_address */
342 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
343 * function called \c __glXAllocateClientState that allocates the memory and
344 * does all the initialization (including the pixel pack / unpack).
346 _X_HIDDEN
struct glx_context
*
347 indirect_create_context(struct glx_screen
*psc
,
348 struct glx_config
*mode
,
349 struct glx_context
*shareList
, int renderType
)
351 struct glx_context
*gc
;
354 __GLXattribute
*state
;
356 opcode
= __glXSetupForCommand(psc
->dpy
);
361 /* Allocate our context record */
362 gc
= Xmalloc(sizeof *gc
);
367 memset(gc
, 0, sizeof *gc
);
369 glx_context_init(gc
, psc
, mode
);
370 gc
->isDirect
= GL_FALSE
;
371 gc
->vtable
= &indirect_context_vtable
;
372 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
378 gc
->client_state_private
= state
;
379 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
380 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
383 ** Create a temporary buffer to hold GLX rendering commands. The size
384 ** of the buffer is selected so that the maximum number of GLX rendering
385 ** commands can fit in a single X packet and still have room in the X
386 ** packet for the GLXRenderReq header.
389 bufSize
= (XMaxRequestSize(psc
->dpy
) * 4) - sz_xGLXRenderReq
;
390 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
392 Xfree(gc
->client_state_private
);
396 gc
->bufSize
= bufSize
;
398 /* Fill in the new context */
399 gc
->renderMode
= GL_RENDER
;
401 state
->storePack
.alignment
= 4;
402 state
->storeUnpack
.alignment
= 4;
404 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
407 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
409 gc
->fillImage
= __glFillImage
;
411 gc
->bufEnd
= gc
->buf
+ bufSize
;
412 gc
->isDirect
= GL_FALSE
;
415 ** Set limit register so that there will be one command per packet
420 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
422 gc
->majorOpcode
= opcode
;
425 ** Constrain the maximum drawing command size allowed to be
426 ** transfered using the X_GLXRender protocol request. First
427 ** constrain by a software limit, then constrain by the protocl
430 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
431 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
433 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
434 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
436 gc
->maxSmallRenderCommandSize
= bufSize
;
442 struct glx_screen_vtable indirect_screen_vtable
= {
443 indirect_create_context
446 _X_HIDDEN
struct glx_screen
*
447 indirect_create_screen(int screen
, struct glx_display
* priv
)
449 struct glx_screen
*psc
;
451 psc
= Xmalloc(sizeof *psc
);
455 memset(psc
, 0, sizeof *psc
);
456 glx_screen_init(psc
, screen
, priv
);
457 psc
->vtable
= &indirect_screen_vtable
;