summaryrefslogtreecommitdiff
path: root/clients/wscreensaver-glue.h
blob: e07915f9cac0aa0a00d4bdc7aef58eece6ed9414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright © 2011 Collabora, Ltd.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of the copyright holders not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no representations
 * about the suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 */

#ifndef WSCREENSAVER_GLUE_H
#define WSCREENSAVER_GLUE_H

/*
 * This file is glue, that tries to avoid changing glmatrix.c from the
 * original too much, hopefully easing the porting of other (GL)
 * xscreensaver "hacks".
 */

#include "wscreensaver.h"

#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <math.h>
#include <assert.h>

#include <GL/gl.h>
#include <GL/glu.h>

#include "window.h"

#define ENTRYPOINT static

typedef bool Bool;
#define True true
#define False false

typedef struct ModeInfo ModeInfo;

#define MI_DISPLAY(mi) NULL
#define MI_WINDOW(mi) (mi)
#define MI_SCREEN(mi) ((mi)->instance_number)
#define MI_WIDTH(mi) ((mi)->width)
#define MI_HEIGHT(mi) ((mi)->height)
#define MI_IS_WIREFRAME(mi) 0
#define MI_NUM_SCREENS(mi) 16

typedef EGLContext GLXContext;

double frand(double f);
void clear_gl_error(void);
void check_gl_error(const char *msg);

static inline void
glXMakeCurrent(void *dummy, ModeInfo *mi, EGLContext ctx)
{
	assert(mi->eglctx == ctx);
}

static inline void
glXSwapBuffers(void *dummy, ModeInfo *mi)
{
	mi->swap_buffers = 1;
}

static inline void
do_fps(ModeInfo *mi)
{
}

/* just enough XImage to satisfy glmatrix.c */

typedef struct _XImage {
	int width;
	int height;
	char *data;
	int bytes_per_line;
} XImage;

XImage *xpm_to_ximage(char **xpm_data);
void XDestroyImage(XImage *xi);

static inline unsigned long
XGetPixel(XImage *xi, int x, int y)
{
	return *(uint32_t *)(xi->data + xi->bytes_per_line * y + 4 * x);
}

static inline void
XPutPixel(XImage *xi, int x, int y, unsigned long pixel)
{
	*(uint32_t *)(xi->data + xi->bytes_per_line * y + 4 * x) = pixel;
}

/*
 * override glViewport from the plugin, so we can set it up properly
 * rendering to a regular decorated Wayland window.
 */
#ifdef glViewport
#undef glViewport
#endif
#define glViewport(x,y,w,h) do {} while (0)

#endif /* WSCREENSAVER_GLUE_H */