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

Latest commit

 

History

History
1358 lines (1215 loc) · 36.7 KB

SDL_compat.c

File metadata and controls

1358 lines (1215 loc) · 36.7 KB
 
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
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
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
Lesser General Public License for more details.
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
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This file contains functions for backwards compatibility with SDL 1.2 */
#include "SDL.h"
Jun 26, 2006
Jun 26, 2006
27
#include "SDL_syswm.h"
28
Jun 30, 2006
Jun 30, 2006
29
#include "video/SDL_sysvideo.h"
Jun 14, 2006
Jun 14, 2006
30
#include "video/SDL_pixels_c.h"
31
32
Jun 14, 2006
Jun 14, 2006
33
34
35
36
37
static SDL_WindowID SDL_VideoWindow;
static SDL_TextureID SDL_VideoTexture;
static SDL_Surface *SDL_VideoSurface;
static SDL_Surface *SDL_ShadowSurface;
static SDL_Surface *SDL_PublicSurface;
38
39
40
static char *wm_title;
char *
May 29, 2006
May 29, 2006
41
SDL_AudioDriverName(char *namebuf, int maxlen)
42
{
May 29, 2006
May 29, 2006
43
const char *name = SDL_GetCurrentAudioDriver();
44
if (name) {
May 29, 2006
May 29, 2006
45
SDL_strlcpy(namebuf, name, maxlen);
46
47
48
49
50
51
return namebuf;
}
return NULL;
}
char *
May 29, 2006
May 29, 2006
52
SDL_VideoDriverName(char *namebuf, int maxlen)
53
{
May 29, 2006
May 29, 2006
54
const char *name = SDL_GetCurrentVideoDriver();
55
if (name) {
May 29, 2006
May 29, 2006
56
SDL_strlcpy(namebuf, name, maxlen);
57
58
59
60
61
return namebuf;
}
return NULL;
}
Jun 7, 2006
Jun 7, 2006
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const SDL_VideoInfo *
SDL_GetVideoInfo(void)
{
static SDL_VideoInfo info;
/* Memory leak, compatibility code, who cares? */
if (!info.vfmt && SDL_GetDesktopDisplayMode()) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
&Rmask, &Gmask, &Bmask, &Amask);
info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
}
return &info;
}
79
int
May 29, 2006
May 29, 2006
80
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
81
82
83
{
int i, actual_bpp = 0;
May 29, 2006
May 29, 2006
84
if (!SDL_GetVideoDevice()) {
85
86
87
88
return 0;
}
if (!(flags & SDL_FULLSCREEN)) {
May 29, 2006
May 29, 2006
89
return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format);
90
91
}
May 29, 2006
May 29, 2006
92
93
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
94
95
96
97
if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
if (!mode->format) {
return bpp;
}
Jun 30, 2006
Jun 30, 2006
98
if (SDL_BITSPERPIXEL(mode->format) >= (Uint32) bpp) {
May 29, 2006
May 29, 2006
99
actual_bpp = SDL_BITSPERPIXEL(mode->format);
100
101
102
103
104
105
106
}
}
}
return actual_bpp;
}
SDL_Rect **
May 29, 2006
May 29, 2006
107
SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
108
109
110
111
{
int i, nmodes;
SDL_Rect **modes;
May 29, 2006
May 29, 2006
112
if (!SDL_GetVideoDevice()) {
113
114
115
116
117
118
119
120
121
return NULL;
}
if (!(flags & SDL_FULLSCREEN)) {
return (SDL_Rect **) (-1);
}
/* Memory leak, but this is a compatibility function, who cares? */
nmodes = 0;
Jun 30, 2006
Jun 30, 2006
122
modes = NULL;
May 29, 2006
May 29, 2006
123
124
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
125
126
127
if (!mode->w || !mode->h) {
return (SDL_Rect **) (-1);
}
May 29, 2006
May 29, 2006
128
if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) {
129
130
131
132
133
134
135
continue;
}
if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
&& modes[nmodes - 1]->h == mode->h) {
continue;
}
May 29, 2006
May 29, 2006
136
modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
137
138
139
if (!modes) {
return NULL;
}
May 29, 2006
May 29, 2006
140
modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
if (!modes[nmodes]) {
return NULL;
}
modes[nmodes]->x = 0;
modes[nmodes]->y = 0;
modes[nmodes]->w = mode->w;
modes[nmodes]->h = mode->h;
++nmodes;
}
if (modes) {
modes[nmodes] = NULL;
}
return modes;
}
Jun 30, 2006
Jun 30, 2006
156
157
static SDL_EventFilter orig_eventfilter;
static void *orig_eventfilterparam;
May 29, 2006
May 29, 2006
158
159
static int
Jun 30, 2006
Jun 30, 2006
160
SDL_CompatEventFilter(void *userdata, SDL_Event * event)
May 29, 2006
May 29, 2006
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
{
SDL_Event fake;
switch (event->type) {
case SDL_WINDOWEVENT:
switch (event->window.event) {
case SDL_WINDOWEVENT_RESIZED:
fake.type = SDL_VIDEORESIZE;
fake.resize.w = event->window.data1;
fake.resize.h = event->window.data2;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_MINIMIZED:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 0;
fake.active.state = SDL_APPACTIVE;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_RESTORED:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 1;
fake.active.state = SDL_APPACTIVE;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_ENTER:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 1;
fake.active.state = SDL_APPMOUSEFOCUS;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_LEAVE:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 0;
fake.active.state = SDL_APPMOUSEFOCUS;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 1;
fake.active.state = SDL_APPINPUTFOCUS;
SDL_PushEvent(&fake);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
fake.type = SDL_ACTIVEEVENT;
fake.active.gain = 1;
fake.active.state = SDL_APPINPUTFOCUS;
SDL_PushEvent(&fake);
break;
}
Jun 18, 2006
Jun 18, 2006
210
211
212
213
214
case SDL_KEYDOWN:
case SDL_KEYUP:
{
Uint32 unicode = 0;
if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) {
Jun 18, 2006
Jun 18, 2006
215
unicode = event->key.keysym.sym;
Jun 20, 2006
Jun 20, 2006
216
if (unicode >= 'a' && unicode <= 'z') {
Jun 18, 2006
Jun 18, 2006
217
218
219
220
221
int shifted = !!(event->key.keysym.mod & KMOD_SHIFT);
int capslock = !!(event->key.keysym.mod & KMOD_CAPS);
if ((shifted ^ capslock) != 0) {
unicode = SDL_toupper(unicode);
}
Jun 18, 2006
Jun 18, 2006
222
223
224
225
226
227
228
}
}
if (unicode) {
event->key.keysym.unicode = unicode;
}
break;
}
May 29, 2006
May 29, 2006
229
}
Jun 17, 2006
Jun 17, 2006
230
if (orig_eventfilter) {
Jun 30, 2006
Jun 30, 2006
231
return orig_eventfilter(orig_eventfilterparam, event);
Jun 17, 2006
Jun 17, 2006
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
} else {
return 1;
}
}
static int
SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
{
if (userdata == SDL_ShadowSurface) {
/* If the shadow palette changed, make the changes visible */
if (!SDL_VideoSurface->format->palette) {
SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
}
}
if (userdata == SDL_VideoSurface) {
return SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors);
}
Jun 30, 2006
Jun 30, 2006
249
return 0;
May 29, 2006
May 29, 2006
250
251
}
252
SDL_Surface *
May 29, 2006
May 29, 2006
253
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
254
{
Jun 30, 2006
Jun 30, 2006
255
256
SDL_EventFilter filter;
void *filterparam;
May 29, 2006
May 29, 2006
257
const SDL_DisplayMode *desktop_mode;
258
259
260
261
SDL_DisplayMode mode;
Uint32 window_flags;
Uint32 desktop_format;
Uint32 desired_format;
Jun 16, 2006
Jun 16, 2006
262
Uint32 surface_flags;
263
May 29, 2006
May 29, 2006
264
265
if (!SDL_GetVideoDevice()) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
266
267
268
269
270
return NULL;
}
}
/* Destroy existing window */
Jun 14, 2006
Jun 14, 2006
271
272
273
274
275
276
SDL_PublicSurface = NULL;
if (SDL_ShadowSurface) {
SDL_FreeSurface(SDL_ShadowSurface);
SDL_ShadowSurface = NULL;
}
if (SDL_VideoSurface) {
Jun 17, 2006
Jun 17, 2006
277
278
279
SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
SDL_VideoPaletteChanged, NULL);
SDL_FreeSurface(SDL_VideoSurface);
Jun 14, 2006
Jun 14, 2006
280
281
282
SDL_VideoSurface = NULL;
}
SDL_DestroyWindow(SDL_VideoWindow);
283
May 29, 2006
May 29, 2006
284
/* Set up the event filter */
Jun 30, 2006
Jun 30, 2006
285
filter = SDL_GetEventFilter(&filterparam);
May 29, 2006
May 29, 2006
286
287
if (filter != SDL_CompatEventFilter) {
orig_eventfilter = filter;
Jun 30, 2006
Jun 30, 2006
288
orig_eventfilterparam = filterparam;
May 29, 2006
May 29, 2006
289
}
Jun 30, 2006
Jun 30, 2006
290
SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
May 29, 2006
May 29, 2006
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* Create a new window */
window_flags = SDL_WINDOW_SHOWN;
if (flags & SDL_FULLSCREEN) {
window_flags |= SDL_WINDOW_FULLSCREEN;
}
if (flags & SDL_OPENGL) {
window_flags |= SDL_WINDOW_OPENGL;
}
if (flags & SDL_RESIZABLE) {
window_flags |= SDL_WINDOW_RESIZABLE;
}
if (flags & SDL_NOFRAME) {
window_flags |= SDL_WINDOW_BORDERLESS;
}
Jun 14, 2006
Jun 14, 2006
306
307
308
SDL_VideoWindow =
SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
if (!SDL_VideoWindow) {
309
310
311
return NULL;
}
Jun 16, 2006
Jun 16, 2006
312
window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
Jun 26, 2006
Jun 26, 2006
313
surface_flags = 0;
Jun 16, 2006
Jun 16, 2006
314
315
316
317
318
319
320
321
322
323
324
325
326
if (window_flags & SDL_WINDOW_FULLSCREEN) {
surface_flags |= SDL_FULLSCREEN;
}
if (window_flags & SDL_WINDOW_OPENGL) {
surface_flags |= SDL_OPENGL;
}
if (window_flags & SDL_WINDOW_RESIZABLE) {
surface_flags |= SDL_RESIZABLE;
}
if (window_flags & SDL_WINDOW_BORDERLESS) {
surface_flags |= SDL_NOFRAME;
}
327
/* Set up the desired display mode */
May 29, 2006
May 29, 2006
328
329
330
331
desktop_mode = SDL_GetDesktopDisplayMode();
desktop_format = desktop_mode->format;
if (desktop_format && ((flags & SDL_ANYFORMAT)
|| (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
332
333
334
desired_format = desktop_format;
} else {
switch (bpp) {
May 29, 2006
May 29, 2006
335
336
337
338
339
340
341
case 0:
if (desktop_format) {
desired_format = desktop_format;
} else {
desired_format = SDL_PixelFormat_RGB888;
}
break;
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
case 8:
desired_format = SDL_PixelFormat_Index8;
break;
case 15:
desired_format = SDL_PixelFormat_RGB555;
break;
case 16:
desired_format = SDL_PixelFormat_RGB565;
break;
case 24:
desired_format = SDL_PixelFormat_RGB24;
break;
case 32:
desired_format = SDL_PixelFormat_RGB888;
break;
default:
May 29, 2006
May 29, 2006
358
SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
359
360
361
362
363
364
365
366
367
368
return NULL;
}
}
mode.format = desired_format;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;
/* Set the desired display mode */
if (flags & SDL_FULLSCREEN) {
May 29, 2006
May 29, 2006
369
if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
370
371
372
return NULL;
}
} else {
May 29, 2006
May 29, 2006
373
374
375
376
377
378
379
380
if (desktop_format) {
mode.format = desktop_format;
}
if (desktop_mode->w && desktop_mode->h) {
mode.w = desktop_mode->w;
mode.h = desktop_mode->h;
}
mode.refresh_rate = desktop_mode->refresh_rate;
381
}
May 29, 2006
May 29, 2006
382
if (SDL_SetDisplayMode(&mode) < 0) {
383
384
385
return NULL;
}
Jun 16, 2006
Jun 16, 2006
386
387
388
389
390
391
392
393
394
395
396
397
/* If we're in OpenGL mode, just create a stub surface and we're done! */
if (flags & SDL_OPENGL) {
SDL_VideoSurface =
SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
if (!SDL_VideoSurface) {
return NULL;
}
SDL_VideoSurface->flags |= surface_flags;
SDL_PublicSurface = SDL_VideoSurface;
return SDL_PublicSurface;
}
Jun 14, 2006
Jun 14, 2006
398
399
/* Create a renderer for the window */
if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
Jun 7, 2006
Jun 7, 2006
400
401
402
return NULL;
}
Jun 14, 2006
Jun 14, 2006
403
404
405
406
407
408
409
410
411
/* Create a texture for the screen surface */
SDL_VideoTexture =
SDL_CreateTexture(desired_format, SDL_TextureAccess_Local, width,
height);
if (!SDL_VideoTexture) {
SDL_VideoTexture =
SDL_CreateTexture(0, SDL_TextureAccess_Local, width, height);
}
if (!SDL_VideoTexture) {
Jun 7, 2006
Jun 7, 2006
412
413
414
return NULL;
}
Jun 14, 2006
Jun 14, 2006
415
416
417
418
/* Create the screen surface */
SDL_VideoSurface = SDL_CreateRGBSurfaceFromTexture(SDL_VideoTexture);
if (!SDL_VideoSurface) {
return NULL;
Jun 7, 2006
Jun 7, 2006
419
}
Jun 16, 2006
Jun 16, 2006
420
SDL_VideoSurface->flags |= surface_flags;
Jun 7, 2006
Jun 7, 2006
421
Jun 14, 2006
Jun 14, 2006
422
423
424
425
426
/* Set a default screen palette */
if (SDL_VideoSurface->format->palette) {
SDL_VideoSurface->flags |= SDL_HWPALETTE;
SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
SDL_VideoSurface->format->BitsPerPixel);
Jun 17, 2006
Jun 17, 2006
427
428
429
430
431
SDL_AddPaletteWatch(SDL_VideoSurface->format->palette,
SDL_VideoPaletteChanged, NULL);
SDL_SetPaletteColors(SDL_VideoSurface->format->palette,
SDL_VideoSurface->format->palette->colors, 0,
SDL_VideoSurface->format->palette->ncolors);
Jun 7, 2006
Jun 7, 2006
432
433
434
}
/* Create a shadow surface if necessary */
Jun 14, 2006
Jun 14, 2006
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
if (((bpp != SDL_VideoSurface->format->BitsPerPixel)
&& !(flags & SDL_ANYFORMAT))
|| ((SDL_VideoSurface->flags & SDL_HWSURFACE)
&& !(flags & SDL_HWSURFACE))) {
if ((bpp == SDL_VideoSurface->format->BitsPerPixel)
|| (flags & SDL_ANYFORMAT)) {
SDL_ShadowSurface =
SDL_CreateRGBSurface(0, width, height,
SDL_VideoSurface->format->BitsPerPixel,
SDL_VideoSurface->format->Rmask,
SDL_VideoSurface->format->Gmask,
SDL_VideoSurface->format->Bmask,
SDL_VideoSurface->format->Amask);
} else {
SDL_ShadowSurface =
SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
}
if (!SDL_ShadowSurface) {
Jun 7, 2006
Jun 7, 2006
453
454
return NULL;
}
Jun 16, 2006
Jun 16, 2006
455
SDL_ShadowSurface->flags |= surface_flags;
Jun 14, 2006
Jun 14, 2006
456
457
458
459
/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
if (SDL_ShadowSurface->format->palette) {
SDL_ShadowSurface->flags |= SDL_HWPALETTE;
Jun 17, 2006
Jun 17, 2006
460
461
462
463
464
465
466
if (SDL_VideoSurface->format->palette) {
SDL_SetSurfacePalette(SDL_ShadowSurface,
SDL_VideoSurface->format->palette);
} else {
SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
SDL_ShadowSurface->format->BitsPerPixel);
}
Jun 7, 2006
Jun 7, 2006
467
468
}
}
Jun 14, 2006
Jun 14, 2006
469
470
SDL_PublicSurface =
(SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
Jun 7, 2006
Jun 7, 2006
471
472
/* Clear the surface for display */
Jun 14, 2006
Jun 14, 2006
473
SDL_FillRect(SDL_PublicSurface, NULL, 0);
Jun 7, 2006
Jun 7, 2006
474
Jun 14, 2006
Jun 14, 2006
475
476
/* We're finally done! */
return SDL_PublicSurface;
Jun 7, 2006
Jun 7, 2006
477
478
}
479
SDL_Surface *
May 29, 2006
May 29, 2006
480
SDL_GetVideoSurface(void)
481
{
Jun 14, 2006
Jun 14, 2006
482
return SDL_PublicSurface;
483
484
}
Jun 7, 2006
Jun 7, 2006
485
486
487
488
489
490
491
SDL_Surface *
SDL_DisplayFormat(SDL_Surface * surface)
{
Uint32 flags;
if (!SDL_PublicSurface) {
SDL_SetError("No video mode has been set");
Jun 14, 2006
Jun 14, 2006
492
return NULL;
Jun 7, 2006
Jun 7, 2006
493
}
Jun 14, 2006
Jun 14, 2006
494
Jun 7, 2006
Jun 7, 2006
495
/* Set the flags appropriate for copying to display surface */
Jun 14, 2006
Jun 14, 2006
496
flags = SDL_SWSURFACE;
Jun 7, 2006
Jun 7, 2006
497
498
499
500
501
502
503
#ifdef AUTORLE_DISPLAYFORMAT
flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
flags |= SDL_RLEACCELOK;
#else
flags |=
surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
#endif
Jun 14, 2006
Jun 14, 2006
504
return SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags);
Jun 7, 2006
Jun 7, 2006
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
}
SDL_Surface *
SDL_DisplayFormatAlpha(SDL_Surface * surface)
{
SDL_PixelFormat *vf;
SDL_PixelFormat *format;
SDL_Surface *converted;
Uint32 flags;
/* default to ARGB8888 */
Uint32 amask = 0xff000000;
Uint32 rmask = 0x00ff0000;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x000000ff;
if (!SDL_PublicSurface) {
SDL_SetError("No video mode has been set");
Jun 14, 2006
Jun 14, 2006
522
return NULL;
Jun 7, 2006
Jun 7, 2006
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
}
vf = SDL_PublicSurface->format;
switch (vf->BytesPerPixel) {
case 2:
/* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
For anything else (like ARGB4444) it doesn't matter
since we have no special code for it anyway */
if ((vf->Rmask == 0x1f) &&
(vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
rmask = 0xff;
bmask = 0xff0000;
}
break;
case 3:
case 4:
/* Keep the video format, as long as the high 8 bits are
unused or alpha */
if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
rmask = 0xff;
bmask = 0xff0000;
}
break;
default:
/* We have no other optimised formats right now. When/if a new
optimised alpha format is written, add the converter here */
break;
}
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
converted = SDL_ConvertSurface(surface, format, flags);
SDL_FreeFormat(format);
Jun 14, 2006
Jun 14, 2006
558
559
560
561
562
563
564
565
return converted;
}
int
SDL_Flip(SDL_Surface * screen)
{
SDL_UpdateRect(screen, 0, 0, 0, 0);
return 0;
Jun 7, 2006
Jun 7, 2006
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
}
void
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
if (screen) {
SDL_Rect rect;
/* Perform some checking */
if (w == 0)
w = screen->w;
if (h == 0)
h = screen->h;
if ((int) (x + w) > screen->w)
return;
if ((int) (y + h) > screen->h)
return;
/* Fill the rectangle */
rect.x = (Sint16) x;
rect.y = (Sint16) y;
rect.w = (Uint16) w;
rect.h = (Uint16) h;
SDL_UpdateRects(screen, 1, &rect);
}
}
void
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
{
int i;
Jun 14, 2006
Jun 14, 2006
597
598
599
600
if (screen == SDL_ShadowSurface) {
for (i = 0; i < numrects; ++i) {
SDL_LowerBlit(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
&rects[i]);
Jun 7, 2006
Jun 7, 2006
601
602
603
}
/* Fall through to video surface update */
Jun 14, 2006
Jun 14, 2006
604
screen = SDL_VideoSurface;
Jun 7, 2006
Jun 7, 2006
605
}
Jun 14, 2006
Jun 14, 2006
606
607
608
609
610
if (screen == SDL_VideoSurface) {
for (i = 0; i < numrects; ++i) {
SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i],
SDL_TextureBlendMode_None,
SDL_TextureScaleMode_None);
Jun 7, 2006
Jun 7, 2006
611
}
Jun 14, 2006
Jun 14, 2006
612
SDL_RenderPresent();
Jun 7, 2006
Jun 7, 2006
613
614
615
}
}
616
void
May 29, 2006
May 29, 2006
617
SDL_WM_SetCaption(const char *title, const char *icon)
618
619
{
if (wm_title) {
May 29, 2006
May 29, 2006
620
SDL_free(wm_title);
621
} else {
May 29, 2006
May 29, 2006
622
wm_title = SDL_strdup(title);
623
}
Jun 14, 2006
Jun 14, 2006
624
SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
625
626
627
}
void
May 29, 2006
May 29, 2006
628
SDL_WM_GetCaption(char **title, char **icon)
629
630
631
632
633
634
635
636
637
638
{
if (title) {
*title = wm_title;
}
if (icon) {
*icon = "";
}
}
void
May 29, 2006
May 29, 2006
639
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
640
641
642
643
644
{
/* FIXME */
}
int
May 29, 2006
May 29, 2006
645
SDL_WM_IconifyWindow(void)
646
{
Jun 14, 2006
Jun 14, 2006
647
SDL_MinimizeWindow(SDL_VideoWindow);
Jun 30, 2006
Jun 30, 2006
648
return 0;
649
650
651
}
int
May 29, 2006
May 29, 2006
652
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
653
654
655
656
657
{
return 0;
}
SDL_GrabMode
May 29, 2006
May 29, 2006
658
SDL_WM_GrabInput(SDL_GrabMode mode)
659
660
{
if (mode != SDL_GRAB_QUERY) {
Jun 14, 2006
Jun 14, 2006
661
SDL_SetWindowGrab(SDL_VideoWindow, mode);
662
}
Jun 14, 2006
Jun 14, 2006
663
return (SDL_GrabMode) SDL_GetWindowGrab(SDL_VideoWindow);
664
665
}
Jun 14, 2006
Jun 14, 2006
666
667
668
669
670
671
void
SDL_WarpMouse(Uint16 x, Uint16 y)
{
SDL_WarpMouseInWindow(SDL_VideoWindow, x, y);
}
672
Uint8
May 29, 2006
May 29, 2006
673
SDL_GetAppState(void)
674
675
676
677
{
Uint8 state = 0;
Uint32 flags = 0;
Jun 14, 2006
Jun 14, 2006
678
flags = SDL_GetWindowFlags(SDL_VideoWindow);
679
680
681
682
683
684
685
686
687
688
689
690
691
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
state |= SDL_APPACTIVE;
}
if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
state |= SDL_APPINPUTFOCUS;
}
if (flags & SDL_WINDOW_MOUSE_FOCUS) {
state |= SDL_APPMOUSEFOCUS;
}
return state;
}
const SDL_version *
May 29, 2006
May 29, 2006
692
SDL_Linked_Version(void)
693
694
{
static SDL_version version;
May 29, 2006
May 29, 2006
695
SDL_VERSION(&version);
696
697
698
699
return &version;
}
int
Jun 16, 2006
Jun 16, 2006
700
SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
May 29, 2006
May 29, 2006
701
int firstcolor, int ncolors)
702
{
Jun 30, 2006
Jun 30, 2006
703
return SDL_SetColors(surface, colors, firstcolor, ncolors);
704
705
}
Jun 7, 2006
Jun 7, 2006
706
int
Jun 17, 2006
Jun 17, 2006
707
708
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
int ncolors)
Jun 7, 2006
Jun 7, 2006
709
{
Jun 17, 2006
Jun 17, 2006
710
711
712
713
714
if (SDL_SetPaletteColors
(surface->format->palette, colors, firstcolor, ncolors) == 0) {
return 1;
} else {
return 0;
Jun 7, 2006
Jun 7, 2006
715
716
717
}
}
718
int
May 29, 2006
May 29, 2006
719
SDL_GetWMInfo(SDL_SysWMinfo * info)
720
{
Jun 14, 2006
Jun 14, 2006
721
return SDL_GetWindowWMInfo(SDL_VideoWindow, info);
722
723
}
Jun 14, 2006
Jun 14, 2006
724
#if 0
Jun 7, 2006
Jun 7, 2006
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
void
SDL_MoveCursor(int x, int y)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
/* Erase and update the current mouse position */
if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
/* Erase and redraw mouse cursor in new position */
SDL_LockCursor();
SDL_EraseCursor(SDL_VideoSurface);
SDL_cursor->area.x = (x - SDL_cursor->hot_x);
SDL_cursor->area.y = (y - SDL_cursor->hot_y);
SDL_DrawCursor(SDL_VideoSurface);
SDL_UnlockCursor();
} else if (_this->MoveWMCursor) {
_this->MoveWMCursor(_this, x, y);
}
}
/* Keep track of the current cursor colors */
static int palette_changed = 1;
static Uint8 pixels8[2];
void
SDL_CursorPaletteChanged(void)
{
palette_changed = 1;
}
void
SDL_MouseRect(SDL_Rect * area)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
int clip_diff;
*area = SDL_cursor->area;
if (area->x < 0) {
area->w += area->x;
area->x = 0;
}
if (area->y < 0) {
area->h += area->y;
area->y = 0;
}
clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
if (clip_diff > 0) {
area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
}
clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
if (clip_diff > 0) {
area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
}
}
static void
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
{
const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
int i, w, h;
Uint8 *data, datab;
Uint8 *mask, maskb;
data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
switch (screen->format->BytesPerPixel) {
case 1:
{
Uint8 *dst;
int dstskip;
if (palette_changed) {
pixels8[0] =
(Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
palette_changed = 0;
}
dst = (Uint8 *) screen->pixels +
(SDL_cursor->area.y + area->y) * screen->pitch +
SDL_cursor->area.x;
dstskip = screen->pitch - area->w;
for (h = area->h; h; h--) {
for (w = area->w / 8; w; w--) {
maskb = *mask++;
datab = *data++;
for (i = 0; i < 8; ++i) {
if (maskb & 0x80) {
*dst = pixels8[datab >> 7];
}
maskb <<= 1;
datab <<= 1;
dst++;
}
}
dst += dstskip;
}
}
break;
case 2:
{
Uint16 *dst;
int dstskip;
dst = (Uint16 *) screen->pixels +
(SDL_cursor->area.y + area->y) * screen->pitch / 2 +
SDL_cursor->area.x;
dstskip = (screen->pitch / 2) - area->w;
for (h = area->h; h; h--) {
for (w = area->w / 8; w; w--) {
maskb = *mask++;
datab = *data++;
for (i = 0; i < 8; ++i) {
if (maskb & 0x80) {
*dst = (Uint16) pixels[datab >> 7];
}
maskb <<= 1;
datab <<= 1;
dst++;
}
}
dst += dstskip;
}
}
break;
case 3:
{
Uint8 *dst;
int dstskip;
dst = (Uint8 *) screen->pixels +
(SDL_cursor->area.y + area->y) * screen->pitch +
SDL_cursor->area.x * 3;
dstskip = screen->pitch - area->w * 3;
for (h = area->h; h; h--) {
for (w = area->w / 8; w; w--) {
maskb = *mask++;
datab = *data++;
for (i = 0; i < 8; ++i) {
if (maskb & 0x80) {
SDL_memset(dst, pixels[datab >> 7], 3);
}
maskb <<= 1;
datab <<= 1;
dst += 3;
}
}
dst += dstskip;
}
}
break;
case 4:
{
Uint32 *dst;
int dstskip;
dst = (Uint32 *) screen->pixels +
(SDL_cursor->area.y + area->y) * screen->pitch / 4 +
SDL_cursor->area.x;
dstskip = (screen->pitch / 4) - area->w;
for (h = area->h; h; h--) {
for (w = area->w / 8; w; w--) {
maskb = *mask++;
datab = *data++;
for (i = 0; i < 8; ++i) {
if (maskb & 0x80) {
*dst = pixels[datab >> 7];
}
maskb <<= 1;
datab <<= 1;
dst++;
}
}
dst += dstskip;
}
}
break;
}
}
static void
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
{
const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
int h;
int x, minx, maxx;
Uint8 *data, datab = 0;
Uint8 *mask, maskb = 0;
Uint8 *dst;
int dstbpp, dstskip;
data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
dstbpp = screen->format->BytesPerPixel;
dst = (Uint8 *) screen->pixels +
(SDL_cursor->area.y + area->y) * screen->pitch +
SDL_cursor->area.x * dstbpp;
dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
minx = area->x;
maxx = area->x + area->w;
if (screen->format->BytesPerPixel == 1) {
if (palette_changed) {
pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
palette_changed = 0;
}
for (h = area->h; h; h--) {
for (x = 0; x < SDL_cursor->area.w; ++x) {
if ((x % 8) == 0) {
maskb = *mask++;
datab = *data++;
}
if ((x >= minx) && (x < maxx)) {
if (maskb & 0x80) {
SDL_memset(dst, pixels8[datab >> 7], dstbpp);
}
}
maskb <<= 1;
datab <<= 1;
dst += dstbpp;
}
dst += dstskip;
}
} else {
for (h = area->h; h; h--) {
for (x = 0; x < SDL_cursor->area.w; ++x) {
if ((x % 8) == 0) {
maskb = *mask++;
datab = *data++;
}
if ((x >= minx) && (x < maxx)) {
if (maskb & 0x80) {
SDL_memset(dst, pixels[datab >> 7], dstbpp);
}
}
maskb <<= 1;
datab <<= 1;
dst += dstbpp;
}
dst += dstskip;
}
}
}
/* This handles the ugly work of converting the saved cursor background from
the pixel format of the shadow surface to that of the video surface.
This is only necessary when blitting from a shadow surface of a different
pixel format than the video surface, and using a software rendered cursor.
*/
static void
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_BlitInfo info;
SDL_loblit RunBlit;
/* Make sure we can steal the blit mapping */
if (screen->map->dst != SDL_VideoSurface) {
return;
}
/* Set up the blit information */
info.s_pixels = SDL_cursor->save[1];
info.s_width = w;
info.s_height = h;
info.s_skip = 0;
info.d_pixels = SDL_cursor->save[0];
info.d_width = w;
info.d_height = h;