Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
386 lines (326 loc) · 11.6 KB

SDL_pgvideo.c

File metadata and controls

386 lines (326 loc) · 11.6 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
22
23
24
Sam Lantinga
slouken@libsdl.org
Micah Dowty
micahjd@users.sourceforge.net
*/
Feb 21, 2006
Feb 21, 2006
25
#include "SDL_config.h"
26
27
28
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
29
30
31
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
32
33
34
35
36
37
38
#include "SDL_pgvideo.h"
#include "SDL_pgevents_c.h"
#define PGVID_DRIVER_NAME "picogui"
/* Initialization/Query functions */
May 29, 2006
May 29, 2006
39
40
41
42
43
44
45
static int PG_VideoInit(_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **PG_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
static SDL_Surface *PG_SetVideoMode(_THIS, SDL_Surface * current, int width,
int height, int bpp, Uint32 flags);
static int PG_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static void PG_VideoQuit(_THIS);
46
47
/* Hardware surface functions */
May 29, 2006
May 29, 2006
48
49
50
51
static int PG_AllocHWSurface(_THIS, SDL_Surface * surface);
static int PG_LockHWSurface(_THIS, SDL_Surface * surface);
static void PG_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void PG_FreeHWSurface(_THIS, SDL_Surface * surface);
52
53
/* etc. */
May 29, 2006
May 29, 2006
54
static void PG_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
55
56
// The implementation dependent data for the window manager cursor
May 28, 2006
May 28, 2006
57
58
59
60
61
struct WMcursor
{
/* Our cursor is a PicoGUI theme */
pghandle theme;
};
62
63
/* WM functions */
May 29, 2006
May 29, 2006
64
65
66
67
68
69
void PG_SetCaption(_THIS, const char *title, const char *icon);
WMcursor *PG_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
int w, int h, int hot_x, int hot_y);
void PG_FreeWMCursor(_THIS, WMcursor * cursor);
void PG_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
int PG_ShowWMCursor(_THIS, WMcursor * cursor);
70
71
72
/* PicoGUI driver bootstrap functions */
May 28, 2006
May 28, 2006
73
static int
May 29, 2006
May 29, 2006
74
PG_Available(void)
May 28, 2006
May 28, 2006
76
77
78
79
80
81
82
/* FIXME: The current client lib doesn't give a way to see if the picogui
* server is reachable without causing a fatal error if it isn't.
* This should be fixed in cli_c2, but until then assume we can
* connect. Since more common drivers like X11 are probed first anyway,
* this shouldn't be a huge problem.
*/
return (1);
May 28, 2006
May 28, 2006
85
static void
May 29, 2006
May 29, 2006
86
PG_DeleteDevice(SDL_VideoDevice * device)
May 29, 2006
May 29, 2006
88
89
SDL_free(device->hidden);
SDL_free(device);
May 28, 2006
May 28, 2006
92
static SDL_VideoDevice *
May 29, 2006
May 29, 2006
93
PG_CreateDevice(int devindex)
May 28, 2006
May 28, 2006
95
96
97
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
98
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
99
if (device) {
May 29, 2006
May 29, 2006
100
SDL_memset(device, 0, (sizeof *device));
May 28, 2006
May 28, 2006
101
device->hidden = (struct SDL_PrivateVideoData *)
May 29, 2006
May 29, 2006
102
SDL_malloc((sizeof *device->hidden));
May 28, 2006
May 28, 2006
103
104
}
if ((device == NULL) || (device->hidden == NULL)) {
May 29, 2006
May 29, 2006
105
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
106
if (device) {
May 29, 2006
May 29, 2006
107
SDL_free(device);
May 28, 2006
May 28, 2006
108
109
110
}
return (0);
}
May 29, 2006
May 29, 2006
111
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
May 28, 2006
May 28, 2006
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
/* Set the function pointers */
device->VideoInit = PG_VideoInit;
device->ListModes = PG_ListModes;
device->SetVideoMode = PG_SetVideoMode;
device->CreateYUVOverlay = NULL;
device->SetColors = PG_SetColors;
device->UpdateRects = PG_UpdateRects;
device->VideoQuit = PG_VideoQuit;
device->AllocHWSurface = PG_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = PG_LockHWSurface;
device->UnlockHWSurface = PG_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = PG_FreeHWSurface;
device->SetCaption = PG_SetCaption;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->PumpEvents = PG_PumpEvents;
device->InitOSKeymap = PG_InitOSKeymap;
device->ShowWMCursor = PG_ShowWMCursor;
device->CreateWMCursor = PG_CreateWMCursor;
device->FreeWMCursor = PG_FreeWMCursor;
device->WarpWMCursor = PG_WarpWMCursor;
device->free = PG_DeleteDevice;
return device;
146
147
148
}
VideoBootStrap PG_bootstrap = {
May 28, 2006
May 28, 2006
149
150
PGVID_DRIVER_NAME, "PicoGUI SDL driver",
PG_Available, PG_CreateDevice
151
152
153
};
May 28, 2006
May 28, 2006
154
int
May 29, 2006
May 29, 2006
155
PG_VideoInit(_THIS, SDL_PixelFormat * vformat)
May 28, 2006
May 28, 2006
157
158
159
160
161
162
163
/* Connect to the PicoGUI server. No way to process command line args yet,
* but since this is based on SHM it's not important to be able to specify
* a remote PicoGUI server.
*
* FIXME: Another nitpick about the current client lib is there's no
* clean way to indicate that command line args are not available.
*/
May 29, 2006
May 29, 2006
164
165
pgInit(0, (char **) "");
this->hidden->mi = *pgGetVideoMode();
May 28, 2006
May 28, 2006
166
167
/* Create a picogui application and canvas. We'll populate the canvas later. */
May 29, 2006
May 29, 2006
168
169
170
this->hidden->wApp = pgRegisterApp(PG_APP_NORMAL, "SDL", 0);
this->hidden->wCanvas = pgNewWidget(PG_WIDGET_CANVAS, 0, 0);
pgSetWidget(PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0);
May 28, 2006
May 28, 2006
171
May 29, 2006
May 29, 2006
172
PG_InitEvents(this);
May 28, 2006
May 28, 2006
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Determine the current screen size */
this->info.current_w = this->hidden->mi.lxres;
this->info.current_h = this->hidden->mi.lyres;
/* Determine the screen depth.
* We change this during the SDL_SetVideoMode implementation...
* Round up to the nearest Bytes per pixel
*/
vformat->BitsPerPixel = this->hidden->mi.bpp;
vformat->BytesPerPixel = this->hidden->mi.bpp >> 3;
if (this->hidden->mi.bpp & 7)
vformat->BytesPerPixel++;
/* We're done! */
return (0);
May 28, 2006
May 28, 2006
191
SDL_Rect **
May 29, 2006
May 29, 2006
192
PG_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
May 28, 2006
May 28, 2006
194
return (SDL_Rect **) - 1;
May 28, 2006
May 28, 2006
197
SDL_Surface *
May 29, 2006
May 29, 2006
198
199
PG_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
May 28, 2006
May 28, 2006
201
202
203
if (this->hidden->bitmap) {
/* Free old bitmap */
if (current->pixels) {
May 29, 2006
May 29, 2006
204
shmdt(current->pixels);
May 28, 2006
May 28, 2006
205
206
current->pixels = NULL;
}
May 29, 2006
May 29, 2006
207
pgDelete(this->hidden->bitmap);
May 28, 2006
May 28, 2006
208
209
210
}
/* Allocate the new pixel format for the screen */
May 29, 2006
May 29, 2006
211
212
if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) {
SDL_SetError("Couldn't allocate new pixel format for requested mode");
May 28, 2006
May 28, 2006
213
214
215
216
return (NULL);
}
/* Create a new picogui bitmap */
May 29, 2006
May 29, 2006
217
218
219
220
this->hidden->bitmap = pgCreateBitmap(width, height);
this->hidden->shm = *pgMakeSHMBitmap(this->hidden->bitmap);
current->pixels = shmat(shmget(this->hidden->shm.shm_key,
this->hidden->shm.shm_length, 0), NULL, 0);
May 28, 2006
May 28, 2006
221
222
223
224
225
/* Reset the canvas, and draw persistent and incremental grops.
* Use mapping and offsets to center it.
*/
May 29, 2006
May 29, 2006
226
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_NUKE, 0);
May 28, 2006
May 28, 2006
227
228
229
/* 0. Set the source position during incremental rendering
*/
May 29, 2006
May 29, 2006
230
231
232
233
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 5, PG_GROP_SETSRC, 0, 0,
0, 0);
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1,
PG_GROPF_INCREMENTAL);
May 28, 2006
May 28, 2006
234
235
236
/* 1. Incremental bitmap rendering
*/
May 29, 2006
May 29, 2006
237
238
239
240
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP,
0, 0, 0, 0, this->hidden->bitmap);
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1,
PG_GROPF_INCREMENTAL);
May 28, 2006
May 28, 2006
241
242
243
/* 2. Normal bitmap rendering
*/
May 29, 2006
May 29, 2006
244
245
246
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP,
0, 0, this->hidden->shm.width, this->hidden->shm.height,
this->hidden->bitmap);
May 28, 2006
May 28, 2006
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
/* Set up the new mode framebuffer */
current->flags = 0;
current->w = this->hidden->shm.width;
current->h = this->hidden->shm.height;
current->pitch = this->hidden->shm.pitch;
/* Set up pixel format */
current->format->BitsPerPixel = this->hidden->shm.bpp;
current->format->BytesPerPixel = this->hidden->shm.bpp >> 3;
if (this->hidden->shm.bpp & 7)
current->format->BytesPerPixel++;
current->format->palette = NULL;
current->format->Rmask = this->hidden->shm.red_mask;
current->format->Gmask = this->hidden->shm.green_mask;
current->format->Bmask = this->hidden->shm.blue_mask;
current->format->Amask = this->hidden->shm.alpha_mask;
current->format->Rshift = this->hidden->shm.red_shift;
current->format->Gshift = this->hidden->shm.green_shift;
current->format->Bshift = this->hidden->shm.blue_shift;
current->format->Ashift = this->hidden->shm.alpha_shift;
current->format->Rloss = 8 - this->hidden->shm.red_length;
current->format->Gloss = 8 - this->hidden->shm.green_length;
current->format->Bloss = 8 - this->hidden->shm.blue_length;
current->format->Aloss = 8 - this->hidden->shm.alpha_length;
/* Draw the app */
May 29, 2006
May 29, 2006
274
pgUpdate();
May 28, 2006
May 28, 2006
275
276
277
/* We're done */
return (current);
278
279
280
}
/* We don't actually allow hardware surfaces other than the main one */
May 28, 2006
May 28, 2006
281
static int
May 29, 2006
May 29, 2006
282
PG_AllocHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
284
return (-1);
May 28, 2006
May 28, 2006
286
static void
May 29, 2006
May 29, 2006
287
PG_FreeHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
289
return;
290
291
292
}
/* We need to wait for vertical retrace on page flipped displays */
May 28, 2006
May 28, 2006
293
static int
May 29, 2006
May 29, 2006
294
PG_LockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
296
return (0);
May 28, 2006
May 28, 2006
299
static void
May 29, 2006
May 29, 2006
300
PG_UnlockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
302
return;
May 28, 2006
May 28, 2006
305
static void
May 29, 2006
May 29, 2006
306
PG_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
May 28, 2006
May 28, 2006
308
309
310
311
312
313
314
315
316
int i;
for (i = 0; i < numrects; i++) {
if (rects[i].w <= 0 || rects[i].h <= 0)
continue;
/* Schedule an incremental update for this rectangle, using
* the canvas gropnodes we've loaded beforehand.
*/
May 29, 2006
May 29, 2006
317
318
319
320
321
322
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 0);
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4,
rects[i].x, rects[i].y, rects[i].w, rects[i].h);
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_FINDGROP, 1, 1);
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_MOVEGROP, 4,
rects[i].x, rects[i].y, rects[i].w, rects[i].h);
May 28, 2006
May 28, 2006
323
324
/* Go perform the update */
May 29, 2006
May 29, 2006
325
326
pgWriteCmd(this->hidden->wCanvas, PGCANVAS_INCREMENTAL, 0);
pgSubUpdate(this->hidden->wCanvas);
May 28, 2006
May 28, 2006
327
}
May 28, 2006
May 28, 2006
330
int
May 29, 2006
May 29, 2006
331
PG_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
May 28, 2006
May 28, 2006
333
334
/* do nothing of note. */
return (1);
335
336
337
338
339
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
May 28, 2006
May 28, 2006
340
void
May 29, 2006
May 29, 2006
341
PG_VideoQuit(_THIS)
May 28, 2006
May 28, 2006
343
if (this->screen->pixels != NULL) {
May 29, 2006
May 29, 2006
344
shmdt(this->screen->pixels);
May 28, 2006
May 28, 2006
345
this->screen->pixels = NULL;
May 29, 2006
May 29, 2006
346
pgDelete(this->hidden->bitmap);
May 28, 2006
May 28, 2006
347
}
May 29, 2006
May 29, 2006
348
349
pgDelete(this->hidden->wCanvas);
pgDelete(this->hidden->wApp);
May 28, 2006
May 28, 2006
352
void
May 29, 2006
May 29, 2006
353
PG_SetCaption(_THIS, const char *title, const char *icon)
May 28, 2006
May 28, 2006
355
if (title != NULL)
May 29, 2006
May 29, 2006
356
357
pgReplaceText(this->hidden->wApp, title);
pgUpdate();
358
359
360
361
}
/* FIXME: The cursor stuff isn't implemented yet! */
May 28, 2006
May 28, 2006
362
WMcursor *
May 29, 2006
May 29, 2006
363
364
PG_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
int w, int h, int hot_x, int hot_y)
May 28, 2006
May 28, 2006
366
367
static WMcursor dummy;
return &dummy;
May 28, 2006
May 28, 2006
370
void
May 29, 2006
May 29, 2006
371
PG_FreeWMCursor(_THIS, WMcursor * cursor)
372
373
374
{
}
May 28, 2006
May 28, 2006
375
void
May 29, 2006
May 29, 2006
376
PG_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
377
378
379
{
}
May 28, 2006
May 28, 2006
380
int
May 29, 2006
May 29, 2006
381
PG_ShowWMCursor(_THIS, WMcursor * cursor)
May 28, 2006
May 28, 2006
383
return 1;
May 28, 2006
May 28, 2006
385
386
/* vi: set ts=4 sw=4 expandtab: */