1 CROSS-PLATFORM PORTABILITY GUIDELINES FOR GALLIUM3D
4 = General Considerations =
6 The state tracker and winsys driver support a rather limited number of
7 platforms. However, the pipe drivers are meant to run in a wide number of
8 platforms. Hence the pipe drivers, the auxiliary modules, and all public
9 headers in general, should strictly follow these guidelines to ensure
14 * Include the p_compiler.h.
16 * Cast explicitly when converting to integer types of smaller sizes.
18 * Cast explicitly when converting between float, double and integral types.
20 * Don't use named struct initializers.
22 * Don't use variable number of macro arguments. Use static inline functions
25 * Don't use C99 features.
29 * Avoid including standard library headers. Most standard library functions are
30 not available in Windows Kernel Mode. Use the appropriate p_*.h include.
32 == Memory Allocation ==
34 * Use MALLOC, CALLOC, FREE instead of the malloc, calloc, free functions.
36 * Use align_pointer() function defined in u_memory.h for aligning pointers
41 * Use the functions/macros in p_debug.h.
43 * Don't include assert.h, call abort, printf, etc.
48 == Inherantice in C ==
50 The main thing we do is mimic inheritance by structure containment.
52 Here's a silly made-up example:
58 void (*validate)(struct buffer *buf);
61 /* sub-class of bufffer */
64 struct buffer base; /* the base class, MUST COME FIRST! */
70 Then, we'll typically have cast-wrapper functions to convert base-class
71 pointers to sub-class pointers where needed:
73 static inline struct vertex_buffer *vertex_buffer(struct buffer *buf)
75 return (struct vertex_buffer *) buf;
79 To create/init a sub-classed object:
81 struct buffer *create_texture_buffer(int w, int h, int format)
83 struct texture_buffer *t = malloc(sizeof(*t));
88 t->base.validate = tex_validate;
92 Example sub-class method:
94 void tex_validate(struct buffer *buf)
96 struct texture_buffer *tb = texture_buffer(buf);
103 Note that we typically do not use typedefs to make "class names"; we use
104 'struct whatever' everywhere.
106 Gallium's pipe_context and the subclassed psb_context, etc are prime examples
107 of this. There's also many examples in Mesa and the Mesa state tracker.