summaryrefslogtreecommitdiff
path: root/src/mapi/glapi/gen/templates/indirect.c.mako
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapi/glapi/gen/templates/indirect.c.mako')
-rw-r--r--src/mapi/glapi/gen/templates/indirect.c.mako221
1 files changed, 221 insertions, 0 deletions
diff --git a/src/mapi/glapi/gen/templates/indirect.c.mako b/src/mapi/glapi/gen/templates/indirect.c.mako
new file mode 100644
index 0000000000..129ca42e58
--- /dev/null
+++ b/src/mapi/glapi/gen/templates/indirect.c.mako
@@ -0,0 +1,221 @@
+## Copyright (c) 2015 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining a copy
+## of this software and associated documentation files (the "Software"), to deal
+## in the Software without restriction, including without limitation the rights
+## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+## copies of the Software, and to permit persons to whom the Software is
+## furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included in
+## all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+## SOFTWARE.
+
+<%def name="print_function(func, name)">
+ <% footer = '}' %>\
+ % if func.glx_rop == ~0:
+ static ${func.return_type}
+ ${func.name}( unsigned opcode, unsigned dim, ${func.get_parameter_string()} )
+ {
+ % elif func.has_different_protocol(name):
+ #define ${func.opcode_vendor_name(name)} ${func.glx_vendorpriv)}
+ ${func.return_type} gl${func.static_glx_name(name)}(${func.get_parameter_string()})
+ {
+ struct glx_context * const gc = __glXGetCurrentContext();
+
+ #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+ if (gc->isDirect) {
+ const _glapi_proc *const disp_table = (_glapi_proc *)GET_DISPATCH();
+ PFNGL${name.upper()}PROC p =
+ (PFNGL${name.upper()}PROC) disp_table[${func.offset}];
+ ${'return ' if func.return_type != 'void' else ''}(${func.get_called_parameter_string()});
+ } else
+ #endif
+ {
+ <% footer = '}}' %>\
+ % else:
+ #define ${func.opcode_name()} ${func.opcode_value()}
+
+ ${func.return_type} __indirect_gl${name}(${func.get_parameter_string()})
+ {
+ % endif
+
+ % if func.glx_rop != 0 or func.vectorequiv is not None:
+ % if func.images: ## XXX: This was len() originally
+ ## TODO: print pixel functions
+ % else:
+ ## TODO: print render functions
+ % endif
+ % elif func.glx_sop != 0 or func.glx_vendorpriv != 0:
+ ## TODO: print single function
+ % else:
+ /* Missing GLX protocol for ${name} */
+ % endif
+ ${footer}
+</%def>
+
+<%namespace name="utils" file="utils.mako"/>
+
+${utils.copyright(['2004, 2005 IBM Corporation'], 'glX_proto_send.py')}
+
+
+#include <GL/gl.h>
+#include "indirect.h"
+#include "glxclient.h"
+#include "indirect_size.h"
+#include "glapi.h"
+#include <GL/glxproto.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/xcb.h>
+#include <xcb/glx.h>
+
+#define __GLX_PAD(n) (((n) + 3) & ~3)
+## TODO: self.printFastcall()
+## TODO: self.printNoinline()
+
+#ifndef __GNUC__
+# define __builtin_expect(x, y) x
+#endif
+
+/* If the size and opcode values are known at compile-time, this will, on
+ * x86 at least, emit them with a single instruction.
+ */
+#define emit_header(dest, op, size) \
+ do { union { short s[2]; int i; } temp; \
+ temp.s[0] = (size); temp.s[1] = (op); \
+ *((int *)(dest)) = temp.i; } while(0)
+
+NOINLINE CARD32
+__glXReadReply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_array )
+{
+ xGLXSingleReply reply;
+
+ (void) _XReply(dpy, (xReply *) & reply, 0, False);
+ if (size != 0) {
+ if ((reply.length > 0) || reply_is_always_array) {
+ const GLint bytes = (reply_is_always_array)
+ ? (4 * reply.length) : (reply.size * size);
+ const GLint extra = 4 - (bytes & 3);
+
+ _XRead(dpy, dest, bytes);
+ if ( extra < 4 ) {
+ _XEatData(dpy, extra);
+ }
+ }
+ else {
+ (void) memcpy( dest, &(reply.pad3), size);
+ }
+ }
+
+ return reply.retval;
+}
+
+NOINLINE void
+__glXReadPixelReply( Display *dpy, struct glx_context * gc, unsigned max_dim,
+ GLint width, GLint height, GLint depth, GLenum format, GLenum type,
+ void * dest, GLboolean dimensions_in_reply )
+{
+ xGLXSingleReply reply;
+ GLint size;
+
+ (void) _XReply(dpy, (xReply *) & reply, 0, False);
+
+ if ( dimensions_in_reply ) {
+ width = reply.pad3;
+ height = reply.pad4;
+ depth = reply.pad5;
+
+ if ((height == 0) || (max_dim < 2)) { height = 1; }
+ if ((depth == 0) || (max_dim < 3)) { depth = 1; }
+ }
+
+ size = reply.length * 4;
+ if (size != 0) {
+ void * buf = malloc( size );
+
+ if ( buf == NULL ) {
+ _XEatData(dpy, size);
+ __glXSetError(gc, GL_OUT_OF_MEMORY);
+ }
+ else {
+ const GLint extra = 4 - (size & 3);
+
+ _XRead(dpy, buf, size);
+ if ( extra < 4 ) {
+ _XEatData(dpy, extra);
+ }
+
+ __glEmptyImage(gc, 3, width, height, depth, format, type,
+ buf, dest);
+ free(buf);
+ }
+ }
+}
+
+#define X_GLXSingle 0
+
+NOINLINE FASTCALL GLubyte *
+__glXSetupSingleRequest( struct glx_context * gc, GLint sop, GLint cmdlen )
+{
+ xGLXSingleReq * req;
+ Display * const dpy = gc->currentDpy;
+
+ (void) __glXFlushRenderBuffer(gc, gc->pc);
+ LockDisplay(dpy);
+ GetReqExtra(GLXSingle, cmdlen, req);
+ req->reqType = gc->majorOpcode;
+ req->contextTag = gc->currentContextTag;
+ req->glxCode = sop;
+ return (GLubyte *)(req) + sz_xGLXSingleReq;
+}
+
+NOINLINE FASTCALL GLubyte *
+__glXSetupVendorRequest( struct glx_context * gc, GLint code, GLint vop, GLint cmdlen )
+{
+ xGLXVendorPrivateReq * req;
+ Display * const dpy = gc->currentDpy;
+
+ (void) __glXFlushRenderBuffer(gc, gc->pc);
+ LockDisplay(dpy);
+ GetReqExtra(GLXVendorPrivate, cmdlen, req);
+ req->reqType = gc->majorOpcode;
+ req->glxCode = code;
+ req->vendorCode = vop;
+ req->contextTag = gc->currentContextTag;
+ return (GLubyte *)(req) + sz_xGLXVendorPrivateReq;
+}
+
+const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+
+#define zero (__glXDefaultPixelStore+0)
+#define one (__glXDefaultPixelStore+8)
+#define default_pixel_store_1D (__glXDefaultPixelStore+4)
+#define default_pixel_store_1D_size 20
+#define default_pixel_store_2D (__glXDefaultPixelStore+4)
+#define default_pixel_store_2D_size 20
+#define default_pixel_store_3D (__glXDefaultPixelStore+0)
+#define default_pixel_store_3D_size 36
+#define default_pixel_store_4D (__glXDefaultPixelStore+0)
+#define default_pixel_store_4D_size 36
+
+% for size_ in data.generic_sizes:
+ <% size = (size_ + 3) & ~3 %>\
+ static FASTCALL NOINLINE void
+ generic_${size_}_byte( GLint rop, const void * ptr )
+ {
+ struct glx_context * const gc = __glXGetCurrentContext();
+ const GLuint cmdlen = ${size + 4};
+
+ emit_header(gc->pc, rop, cmdlen);
+ (void) memcpy((void *)(gc->pc + 4), ptr, ${size});
+ gc->pc += cmdlen;
+ if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }
+ }
+% endfor