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 __glXFreeVertexArrayState(gc
);
48 free((char *) gc
->vendor
);
49 free((char *) gc
->renderer
);
50 free((char *) gc
->version
);
51 free((char *) gc
->extensions
);
52 __glFreeAttributeState(gc
);
53 free((char *) gc
->buf
);
54 free((char *) gc
->client_state_private
);
59 SendMakeCurrentRequest(Display
* dpy
, CARD8 opcode
,
60 GLXContextID gc_id
, GLXContextTag gc_tag
,
61 GLXDrawable draw
, GLXDrawable read
,
62 xGLXMakeCurrentReply
* reply
)
69 xGLXMakeCurrentReq
*req
;
71 GetReq(GLXMakeCurrent
, req
);
72 req
->reqType
= opcode
;
73 req
->glxCode
= X_GLXMakeCurrent
;
76 req
->oldContextTag
= gc_tag
;
79 struct glx_display
*priv
= __glXInitialize(dpy
);
81 /* If the server can support the GLX 1.3 version, we should
82 * perfer that. Not only that, some servers support GLX 1.3 but
83 * not the SGI extension.
86 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
87 xGLXMakeContextCurrentReq
*req
;
89 GetReq(GLXMakeContextCurrent
, req
);
90 req
->reqType
= opcode
;
91 req
->glxCode
= X_GLXMakeContextCurrent
;
93 req
->readdrawable
= read
;
95 req
->oldContextTag
= gc_tag
;
98 xGLXVendorPrivateWithReplyReq
*vpreq
;
99 xGLXMakeCurrentReadSGIReq
*req
;
101 GetReqExtra(GLXVendorPrivateWithReply
,
102 sz_xGLXMakeCurrentReadSGIReq
-
103 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
104 req
= (xGLXMakeCurrentReadSGIReq
*) vpreq
;
105 req
->reqType
= opcode
;
106 req
->glxCode
= X_GLXVendorPrivateWithReply
;
107 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
108 req
->drawable
= draw
;
109 req
->readable
= read
;
110 req
->context
= gc_id
;
111 req
->oldContextTag
= gc_tag
;
115 ret
= _XReply(dpy
, (xReply
*) reply
, 0, False
);
124 indirect_bind_context(struct glx_context
*gc
, struct glx_context
*old
,
125 GLXDrawable draw
, GLXDrawable read
)
127 xGLXMakeCurrentReply reply
;
129 __GLXattribute
*state
;
130 Display
*dpy
= gc
->psc
->dpy
;
131 int opcode
= __glXSetupForCommand(dpy
);
133 if (old
!= &dummyContext
&& !old
->isDirect
&& old
->psc
->dpy
== dpy
) {
134 tag
= old
->currentContextTag
;
135 old
->currentContextTag
= 0;
140 SendMakeCurrentRequest(dpy
, opcode
, gc
->xid
, tag
, draw
, read
, &reply
);
143 IndirectAPI
= __glXNewIndirectAPI();
144 _glapi_set_dispatch(IndirectAPI
);
146 gc
->currentContextTag
= reply
.contextTag
;
147 state
= gc
->client_state_private
;
148 if (state
->array_state
== NULL
) {
149 glGetString(GL_EXTENSIONS
);
150 glGetString(GL_VERSION
);
151 __glXInitVertexArrayState(gc
);
158 indirect_unbind_context(struct glx_context
*gc
, struct glx_context
*new)
160 Display
*dpy
= gc
->psc
->dpy
;
161 int opcode
= __glXSetupForCommand(dpy
);
162 xGLXMakeCurrentReply reply
;
167 /* We are either switching to no context, away from a indirect
168 * context to a direct context or from one dpy to another and have
169 * to send a request to the dpy to unbind the previous context.
171 if (!new || new->isDirect
|| new->psc
->dpy
!= dpy
) {
172 SendMakeCurrentRequest(dpy
, opcode
, None
,
173 gc
->currentContextTag
, None
, None
, &reply
);
174 gc
->currentContextTag
= 0;
179 indirect_wait_gl(struct glx_context
*gc
)
182 Display
*dpy
= gc
->currentDpy
;
184 /* Flush any pending commands out */
185 __glXFlushRenderBuffer(gc
, gc
->pc
);
187 /* Send the glXWaitGL request */
189 GetReq(GLXWaitGL
, req
);
190 req
->reqType
= gc
->majorOpcode
;
191 req
->glxCode
= X_GLXWaitGL
;
192 req
->contextTag
= gc
->currentContextTag
;
198 indirect_wait_x(struct glx_context
*gc
)
201 Display
*dpy
= gc
->currentDpy
;
203 /* Flush any pending commands out */
204 __glXFlushRenderBuffer(gc
, gc
->pc
);
207 GetReq(GLXWaitX
, req
);
208 req
->reqType
= gc
->majorOpcode
;
209 req
->glxCode
= X_GLXWaitX
;
210 req
->contextTag
= gc
->currentContextTag
;
216 indirect_use_x_font(struct glx_context
*gc
,
217 Font font
, int first
, int count
, int listBase
)
219 xGLXUseXFontReq
*req
;
220 Display
*dpy
= gc
->currentDpy
;
222 /* Flush any pending commands out */
223 __glXFlushRenderBuffer(gc
, gc
->pc
);
225 /* Send the glXUseFont request */
227 GetReq(GLXUseXFont
, req
);
228 req
->reqType
= gc
->majorOpcode
;
229 req
->glxCode
= X_GLXUseXFont
;
230 req
->contextTag
= gc
->currentContextTag
;
234 req
->listBase
= listBase
;
240 indirect_bind_tex_image(Display
* dpy
,
241 GLXDrawable drawable
,
242 int buffer
, const int *attrib_list
)
244 xGLXVendorPrivateReq
*req
;
245 struct glx_context
*gc
= __glXGetCurrentContext();
246 CARD32
*drawable_ptr
;
248 CARD32
*num_attrib_ptr
;
255 while (attrib_list
[i
* 2] != None
)
259 opcode
= __glXSetupForCommand(dpy
);
264 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
265 req
->reqType
= opcode
;
266 req
->glxCode
= X_GLXVendorPrivate
;
267 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
268 req
->contextTag
= gc
->currentContextTag
;
270 drawable_ptr
= (CARD32
*) (req
+ 1);
271 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
272 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
273 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
275 *drawable_ptr
= drawable
;
276 *buffer_ptr
= buffer
;
277 *num_attrib_ptr
= (CARD32
) i
;
281 while (attrib_list
[i
* 2] != None
) {
282 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
283 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
293 indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
295 xGLXVendorPrivateReq
*req
;
296 struct glx_context
*gc
= __glXGetCurrentContext();
297 CARD32
*drawable_ptr
;
301 opcode
= __glXSetupForCommand(dpy
);
306 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
307 req
->reqType
= opcode
;
308 req
->glxCode
= X_GLXVendorPrivate
;
309 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
310 req
->contextTag
= gc
->currentContextTag
;
312 drawable_ptr
= (CARD32
*) (req
+ 1);
313 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
315 *drawable_ptr
= drawable
;
316 *buffer_ptr
= buffer
;
322 static const struct glx_context_vtable indirect_context_vtable
= {
323 indirect_destroy_context
,
324 indirect_bind_context
,
325 indirect_unbind_context
,
329 indirect_bind_tex_image
,
330 indirect_release_tex_image
,
331 NULL
, /* get_proc_address */
335 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
336 * function called \c __glXAllocateClientState that allocates the memory and
337 * does all the initialization (including the pixel pack / unpack).
339 _X_HIDDEN
struct glx_context
*
340 indirect_create_context(struct glx_screen
*psc
,
341 struct glx_config
*mode
,
342 struct glx_context
*shareList
, int renderType
)
344 struct glx_context
*gc
;
347 __GLXattribute
*state
;
349 opcode
= __glXSetupForCommand(psc
->dpy
);
354 /* Allocate our context record */
355 gc
= calloc(1, sizeof *gc
);
361 glx_context_init(gc
, psc
, mode
);
362 gc
->isDirect
= GL_FALSE
;
363 gc
->vtable
= &indirect_context_vtable
;
364 state
= malloc(sizeof(struct __GLXattributeRec
));
370 gc
->client_state_private
= state
;
371 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
372 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
375 ** Create a temporary buffer to hold GLX rendering commands. The size
376 ** of the buffer is selected so that the maximum number of GLX rendering
377 ** commands can fit in a single X packet and still have room in the X
378 ** packet for the GLXRenderReq header.
381 bufSize
= (XMaxRequestSize(psc
->dpy
) * 4) - sz_xGLXRenderReq
;
382 gc
->buf
= malloc(bufSize
);
384 free(gc
->client_state_private
);
388 gc
->bufSize
= bufSize
;
390 /* Fill in the new context */
391 gc
->renderMode
= GL_RENDER
;
393 state
->storePack
.alignment
= 4;
394 state
->storeUnpack
.alignment
= 4;
396 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
399 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
401 gc
->fillImage
= __glFillImage
;
403 gc
->bufEnd
= gc
->buf
+ bufSize
;
404 gc
->isDirect
= GL_FALSE
;
407 ** Set limit register so that there will be one command per packet
412 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
414 gc
->majorOpcode
= opcode
;
417 ** Constrain the maximum drawing command size allowed to be
418 ** transfered using the X_GLXRender protocol request. First
419 ** constrain by a software limit, then constrain by the protocl
422 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
423 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
425 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
426 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
428 gc
->maxSmallRenderCommandSize
= bufSize
;
434 static struct glx_context
*
435 indirect_create_context_attribs(struct glx_screen
*base
,
436 struct glx_config
*config_base
,
437 struct glx_context
*shareList
,
438 unsigned num_attribs
,
439 const uint32_t *attribs
,
442 /* All of the attribute validation for indirect contexts is handled on the
443 * server, so there's not much to do here.
448 /* The error parameter is only used on the server so that correct GLX
449 * protocol errors can be generated. On the client, it can be ignored.
453 return indirect_create_context(base
, config_base
, shareList
, 0);
456 struct glx_screen_vtable indirect_screen_vtable
= {
457 indirect_create_context
,
458 indirect_create_context_attribs
461 _X_HIDDEN
struct glx_screen
*
462 indirect_create_screen(int screen
, struct glx_display
* priv
)
464 struct glx_screen
*psc
;
466 psc
= calloc(1, sizeof *psc
);
470 glx_screen_init(psc
, screen
, priv
);
471 psc
->vtable
= &indirect_screen_vtable
;