1 /* Copyright © 2013, Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 /* This is C code intended to be included (yes, included) by test
23 * programs in the fips test suite.
25 * It defines two functions for use by the test:
28 * common_create_context (Display *dpy, GLXContext *ctx, XVisualInfo **vi);
31 * common_handle_events (Display *dpy, Window window);
33 * Before including this file, the test program must define a macro
34 * COMMON_GL_PREFIX to some prefix. This macro can be empty (to
35 * directly call functions in an OpenGL-library directly linked) or
36 * can be some custom prefix to call through symbols defined in the
40 #ifndef COMMON_GL_PREFIX
41 #error Code including common.c must define COMMON_GL_PREFIX
44 #define concat_(a,b) a ## b
45 #define concat(a,b) concat_(a,b)
46 #define _(func) concat(COMMON_GL_PREFIX, func)
49 set_2d_projection (int width, int height)
51 _(glMatrixMode) (GL_PROJECTION);
53 _(glOrtho) (0, width, height, 0, 0, 1);
54 _(glMatrixMode) (GL_MODELVIEW);
58 paint_rgb_using_clear (double r, double g, double b)
60 _(glClearColor) (r, g, b, 1.0);
61 _(glClear) (GL_COLOR_BUFFER_BIT);
65 common_create_context (Display *dpy,
66 GLXContext *ctx_ret, XVisualInfo **visual_info_ret)
77 GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
81 /* Window and context setup. */
82 *visual_info_ret = _(glXChooseVisual) (dpy, 0, visual_attr);
83 *ctx_ret = _(glXCreateContext) (dpy, *visual_info_ret, NULL, True);
87 draw (Display *dpy, GLXContext ctx, Window window, int width, int height)
90 _(glXMakeCurrent) (dpy, window, ctx);
92 _(glViewport) (0, 0, width, height);
94 set_2d_projection (width, height);
96 /* Simply count through some colors, frame by frame. */
97 #define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
100 for (i = 0; i < 2; i++) {
101 /* Frame: Draw a solid (magenta) frame */
102 paint_rgb_using_clear (RGB(frame));
103 _(glXSwapBuffers) (dpy, window);
106 /* Frame: Draw a solid (yellow) frame */
107 paint_rgb_using_clear (RGB(frame));
108 _(glXSwapBuffers) (dpy, window);
111 /* Frame: Draw a solid (cyan) frame */
112 paint_rgb_using_clear (RGB(frame));
113 _(glXSwapBuffers) (dpy, window);
118 _(glXDestroyContext) (dpy, ctx);
122 common_handle_events(Display *dpy, GLXContext ctx, Window window)
128 XNextEvent (dpy, &xev);
131 XNextEvent (dpy, &xev);
133 case ConfigureNotify:
134 width = xev.xconfigure.width;
135 height = xev.xconfigure.height;
138 if (xev.xexpose.count == 0) {
139 draw (dpy, ctx, window, width, height);