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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/*
* Copyright © 2004 David Reveman
*
* 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
* David Reveman not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* David Reveman makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL DAVID REVEMAN 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.
*
* Author: David Reveman <davidr@novell.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <math.h>
#include <glitz-egl.h>
#include "inputstr.h"
#include "cursorstr.h"
#include "mipointer.h"
#include "xegl.h"
#define XEGL_DEFAULT_SCREEN_WIDTH 800
#define XEGL_DEFAULT_SCREEN_HEIGHT 600
int xeglScreenGeneration = -1;
int xeglScreenPrivateIndex;
#define XEGL_GET_SCREEN_PRIV(pScreen) \
((xeglScreenPtr) (pScreen)->devPrivates[xeglScreenPrivateIndex].ptr)
#define XEGL_SET_SCREEN_PRIV(pScreen, v) \
((pScreen)->devPrivates[xeglScreenPrivateIndex].ptr = (pointer) v)
#define XEGL_SCREEN_PRIV(pScreen) \
xeglScreenPtr pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen)
static EGLDisplay eDisplay;
static EGLScreenMESA eScreen;
static ScreenPtr currentScreen = 0;
static Bool softCursor = TRUE;
extern miPointerScreenFuncRec kdPointerScreenFuncs;
static Bool
xeglAllocatePrivates (ScreenPtr pScreen)
{
xeglScreenPtr pScreenPriv;
if (xeglScreenGeneration != serverGeneration)
{
xeglScreenPrivateIndex = AllocateScreenPrivateIndex ();
if (xeglScreenPrivateIndex < 0)
return FALSE;
xeglScreenGeneration = serverGeneration;
}
pScreenPriv = xalloc (sizeof (xeglScreenRec));
if (!pScreenPriv)
return FALSE;
XEGL_SET_SCREEN_PRIV (pScreen, pScreenPriv);
return TRUE;
}
static Bool
xeglCloseScreen (int index,
ScreenPtr pScreen)
{
glitz_drawable_t *drawable;
XEGL_SCREEN_PRIV (pScreen);
drawable = XGL_GET_SCREEN_PRIV (pScreen)->drawable;
if (drawable)
glitz_drawable_destroy (drawable);
xglClearVisualTypes ();
XGL_SCREEN_UNWRAP (CloseScreen);
xfree (pScreenPriv);
return (*pScreen->CloseScreen) (index, pScreen);
}
static Bool
xeglScreenInit (int index,
ScreenPtr pScreen,
int argc,
char **argv)
{
EGLSurface eSurface;
EGLModeMESA mode;
int count;
xeglScreenPtr pScreenPriv;
glitz_drawable_format_t *format;
glitz_drawable_t *drawable;
EGLint screenAttribs[] = {
EGL_WIDTH, 1024,
EGL_HEIGHT, 768,
EGL_NONE
};
if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0)
{
xglScreenInfo.width = XEGL_DEFAULT_SCREEN_WIDTH;
xglScreenInfo.height = XEGL_DEFAULT_SCREEN_HEIGHT;
}
screenAttribs[1] = xglScreenInfo.width;
screenAttribs[3] = xglScreenInfo.height;
format = xglVisuals[0].format;
if (!xeglAllocatePrivates (pScreen))
return FALSE;
currentScreen = pScreen;
pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen);
if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0)
{
xglScreenInfo.width = XEGL_DEFAULT_SCREEN_WIDTH;
xglScreenInfo.height = XEGL_DEFAULT_SCREEN_HEIGHT;
}
eglGetModesMESA (eDisplay, eScreen, &mode, 1, &count);
eSurface = eglCreateScreenSurfaceMESA (eDisplay, format->id, screenAttribs);
if (eSurface == EGL_NO_SURFACE)
{
ErrorF ("failed to create screen surface\n");
return FALSE;
}
eglShowScreenSurfaceMESA (eDisplay, eScreen, eSurface, mode);
drawable = glitz_egl_create_surface (eDisplay, eScreen, format, eSurface,
xglScreenInfo.width,
xglScreenInfo.height);
if (!drawable)
{
ErrorF ("[%d] couldn't create glitz drawable for window\n", index);
return FALSE;
}
xglScreenInfo.drawable = drawable;
if (!xglScreenInit (pScreen))
return FALSE;
#ifdef GLXEXT
if (!xglInitVisualConfigs (pScreen))
return FALSE;
#endif
XGL_SCREEN_WRAP (CloseScreen, xeglCloseScreen);
miDCInitialize (pScreen, &kdPointerScreenFuncs);
miCreateDefColormap(pScreen);
if (!xglFinishScreenInit (pScreen))
return FALSE;
return TRUE;
}
void
xeglInitOutput (ScreenInfo *pScreenInfo,
int argc,
char **argv)
{
glitz_drawable_format_t *format, templ;
int i, maj, min, count;
unsigned long mask;
xglSetPixmapFormats (pScreenInfo);
if (!eDisplay)
{
eDisplay = eglGetDisplay (":0");
if (!eglInitialize (eDisplay, &maj, &min))
FatalError ("can't open display");
eglGetScreensMESA (eDisplay, &eScreen, 1, &count);
}
templ.samples = 1;
templ.doublebuffer = 1;
templ.color.alpha_size = 8;
mask = GLITZ_FORMAT_SAMPLES_MASK;
format = glitz_egl_find_window_config (eDisplay, eScreen,
mask, &templ, 0);
if (!format)
FatalError ("no visual format found");
xglSetVisualTypesAndMasks (pScreenInfo, format, (1 << TrueColor));
xglInitVisuals (pScreenInfo);
AddScreen (xeglScreenInit, argc, argv);
}
static void
xeglBlockHandler (pointer blockData,
OSTimePtr pTimeout,
pointer pReadMask)
{
XGL_SCREEN_PRIV (currentScreen);
if (!xglSyncSurface (&pScreenPriv->pScreenPixmap->drawable))
FatalError (XGL_SW_FAILURE_STRING);
glitz_surface_flush (pScreenPriv->surface);
glitz_drawable_finish (pScreenPriv->drawable);
}
void
xeglInitInput (int argc,
char **argv)
{
eglInitInput (&LinuxEvdevMouseFuncs, &LinuxEvdevKeyboardFuncs);
RegisterBlockAndWakeupHandlers (xeglBlockHandler, KdWakeupHandler, NULL);
}
Bool
xeglLegalModifier (unsigned int key,
DeviceIntPtr pDev)
{
return KdLegalModifier (key, pDev);
}
void
xeglProcessInputEvents (void)
{
KdProcessInputEvents ();
}
void
xeglUseMsg (void)
{
ErrorF ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM] "
"specify screen characteristics\n");
ErrorF ("-softcursor force software cursor\n");
}
int
xeglProcessArgument (int argc,
char **argv,
int i)
{
if (!strcmp (argv[i], "-screen"))
{
if ((i + 1) < argc)
{
xglParseScreen (argv[i + 1]);
}
else
return 1;
return 2;
}
else if (!strcmp (argv[i], "-softcursor"))
{
softCursor = TRUE;
return 1;
}
return 0;
}
void
xeglAbort (void)
{
}
void
xeglGiveUp (void)
{
AbortDDX ();
}
void
xeglOsVendorInit (void)
{
}
|