compositor-x11: Rename the output make to "weston-X11"
[platform/upstream/weston.git] / clients / wscreensaver-glue.h
1 /*
2  * Copyright © 2011 Collabora, Ltd.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #ifndef WSCREENSAVER_GLUE_H
24 #define WSCREENSAVER_GLUE_H
25
26 /*
27  * This file is glue, that tries to avoid changing glmatrix.c from the
28  * original too much, hopefully easing the porting of other (GL)
29  * xscreensaver "hacks".
30  */
31
32 #include "wscreensaver.h"
33
34 #include <stdbool.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <time.h>
40 #include <math.h>
41 #include <assert.h>
42
43 #include <GL/gl.h>
44 #include <GL/glu.h>
45
46 #include "window.h"
47
48 #define ENTRYPOINT static
49
50 typedef bool Bool;
51 #define True true
52 #define False false
53
54 typedef struct ModeInfo ModeInfo;
55
56 #define MI_DISPLAY(mi) NULL
57 #define MI_WINDOW(mi) (mi)
58 #define MI_SCREEN(mi) ((mi)->instance_number)
59 #define MI_WIDTH(mi) ((mi)->width)
60 #define MI_HEIGHT(mi) ((mi)->height)
61 #define MI_IS_WIREFRAME(mi) 0
62 #define MI_NUM_SCREENS(mi) 16
63
64 typedef EGLContext GLXContext;
65
66 double frand(double f);
67 void clear_gl_error(void);
68 void check_gl_error(const char *msg);
69
70 static inline void
71 glXMakeCurrent(void *dummy, ModeInfo *mi, EGLContext ctx)
72 {
73         assert(mi->eglctx == ctx);
74 }
75
76 static inline void
77 glXSwapBuffers(void *dummy, ModeInfo *mi)
78 {
79         mi->swap_buffers = 1;
80 }
81
82 static inline void
83 do_fps(ModeInfo *mi)
84 {
85 }
86
87 /* just enough XImage to satisfy glmatrix.c */
88
89 typedef struct _XImage {
90         int width;
91         int height;
92         char *data;
93         int bytes_per_line;
94 } XImage;
95
96 XImage *xpm_to_ximage(char **xpm_data);
97 void XDestroyImage(XImage *xi);
98
99 static inline unsigned long
100 XGetPixel(XImage *xi, int x, int y)
101 {
102         return *(uint32_t *)(xi->data + xi->bytes_per_line * y + 4 * x);
103 }
104
105 static inline void
106 XPutPixel(XImage *xi, int x, int y, unsigned long pixel)
107 {
108         *(uint32_t *)(xi->data + xi->bytes_per_line * y + 4 * x) = pixel;
109 }
110
111 /*
112  * override glViewport from the plugin, so we can set it up properly
113  * rendering to a regular decorated Wayland window.
114  */
115 #ifdef glViewport
116 #undef glViewport
117 #endif
118 #define glViewport(x,y,w,h) do {} while (0)
119
120 #endif /* WSCREENSAVER_GLUE_H */