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 * Don't use the 'inline' keyword, use the INLINE macro in p_compiler.h instead.
18 * Cast explicitly when converting to integer types of smaller sizes.
20 * Cast explicitly when converting between float, double and integral types.
22 * Don't use named struct initializers.
24 * Don't use variable number of macro arguments. Use static inline functions
27 * Don't use C99 features.
31 * Avoid including standard library headers. Most standard library functions are
32 not available in Windows Kernel Mode. Use the appropriate p_*.h include.
34 == Memory Allocation ==
36 * Use MALLOC, CALLOC, FREE instead of the malloc, calloc, free functions.
38 * Use align_pointer() function defined in u_memory.h for aligning pointers
43 * Use the functions/macros in p_debug.h.
45 * Don't include assert.h, call abort, printf, etc.
50 == Inherantice in C ==
52 The main thing we do is mimic inheritance by structure containment.
54 Here's a silly made-up example:
60 void (*validate)(struct buffer *buf);
63 /* sub-class of bufffer */
66 struct buffer base; /* the base class, MUST COME FIRST! */
72 Then, we'll typically have cast-wrapper functions to convert base-class
73 pointers to sub-class pointers where needed:
75 static inline struct vertex_buffer *vertex_buffer(struct buffer *buf)
77 return (struct vertex_buffer *) buf;
81 To create/init a sub-classed object:
83 struct buffer *create_texture_buffer(int w, int h, int format)
85 struct texture_buffer *t = malloc(sizeof(*t));
90 t->base.validate = tex_validate;
94 Example sub-class method:
96 void tex_validate(struct buffer *buf)
98 struct texture_buffer *tb = texture_buffer(buf);
105 Note that we typically do not use typedefs to make "class names"; we use
106 'struct whatever' everywhere.
108 Gallium's pipe_context and the subclassed psb_context, etc are prime examples
109 of this. There's also many examples in Mesa and the Mesa state tracker.