/
SDL_ph_video.c
654 lines (570 loc) · 19.6 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
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
13
Lesser General Public License for more details.
14
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
Sam Lantinga
20
slouken@libsdl.org
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_thread.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_endian.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_ph_video.h"
#include "SDL_ph_modes_c.h"
#include "SDL_ph_image_c.h"
#include "SDL_ph_events_c.h"
#include "SDL_ph_mouse_c.h"
44
#include "SDL_ph_wm_c.h"
45
#include "SDL_ph_gl.h"
46
47
48
#include "SDL_phyuv_c.h"
#include "blank_cursor.h"
49
50
51
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
52
53
static void ph_VideoQuit(_THIS);
static void ph_DeleteDevice(SDL_VideoDevice *device);
54
55
56
static int phstatus=-1;
57
58
static int ph_Available(void)
{
59
if (phstatus!=0)
60
{
61
62
63
64
65
66
67
68
69
phstatus=PtInit(NULL);
if (phstatus==0)
{
return 1;
}
else
{
return 0;
}
70
}
71
return 1;
72
73
}
74
static SDL_VideoDevice* ph_CreateDevice(int devindex)
75
{
76
SDL_VideoDevice* device;
77
78
79
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
80
81
if (device)
{
82
memset(device, 0, (sizeof *device));
83
device->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *device->hidden));
84
85
device->gl_data = NULL;
}
86
87
if ((device == NULL) || (device->hidden == NULL))
{
88
89
SDL_OutOfMemory();
ph_DeleteDevice(device);
90
return NULL;
91
92
93
94
}
memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the driver flags */
95
device->handles_any_size = 1;
96
97
/* Set the function pointers */
98
device->CreateYUVOverlay = ph_CreateYUVOverlay;
99
100
101
device->VideoInit = ph_VideoInit;
device->ListModes = ph_ListModes;
device->SetVideoMode = ph_SetVideoMode;
102
device->ToggleFullScreen = ph_ToggleFullScreen;
103
device->UpdateMouse = ph_UpdateMouse;
104
device->SetColors = ph_SetColors;
105
device->UpdateRects = NULL; /* set up in ph_SetupUpdateFunction */
106
107
device->VideoQuit = ph_VideoQuit;
device->AllocHWSurface = ph_AllocHWSurface;
108
109
110
111
device->CheckHWBlit = ph_CheckHWBlit;
device->FillHWRect = ph_FillHWRect;
device->SetHWColorKey = ph_SetHWColorKey;
device->SetHWAlpha = ph_SetHWAlpha;
112
113
114
115
device->LockHWSurface = ph_LockHWSurface;
device->UnlockHWSurface = ph_UnlockHWSurface;
device->FlipHWSurface = ph_FlipHWSurface;
device->FreeHWSurface = ph_FreeHWSurface;
116
device->SetCaption = ph_SetCaption;
117
device->SetIcon = NULL;
118
device->IconifyWindow = ph_IconifyWindow;
119
device->GrabInput = ph_GrabInput;
120
device->GetWMInfo = ph_GetWMInfo;
121
122
123
124
device->FreeWMCursor = ph_FreeWMCursor;
device->CreateWMCursor = ph_CreateWMCursor;
device->ShowWMCursor = ph_ShowWMCursor;
device->WarpWMCursor = ph_WarpWMCursor;
125
device->MoveWMCursor = NULL;
126
127
128
129
device->CheckMouseMode = ph_CheckMouseMode;
device->InitOSKeymap = ph_InitOSKeymap;
device->PumpEvents = ph_PumpEvents;
130
131
/* OpenGL support. */
#ifdef HAVE_OPENGL
132
device->GL_MakeCurrent = ph_GL_MakeCurrent;
133
device->GL_SwapBuffers = ph_GL_SwapBuffers;
134
device->GL_GetAttribute = ph_GL_GetAttribute;
135
136
device->GL_LoadLibrary = ph_GL_LoadLibrary;
device->GL_GetProcAddress = ph_GL_GetProcAddress;
137
#else
138
device->GL_MakeCurrent = NULL;
139
device->GL_SwapBuffers = NULL;
140
device->GL_GetAttribute = NULL;
141
142
device->GL_LoadLibrary = NULL;
device->GL_GetProcAddress = NULL;
143
#endif /* HAVE_OPENGL */
144
145
device->free = ph_DeleteDevice;
146
147
148
149
return device;
}
150
VideoBootStrap ph_bootstrap = {
151
152
"photon", "QNX Photon video output",
ph_Available, ph_CreateDevice
153
154
155
156
};
static void ph_DeleteDevice(SDL_VideoDevice *device)
{
157
158
159
160
if (device)
{
if (device->hidden)
{
161
162
163
free(device->hidden);
device->hidden = NULL;
}
164
165
if (device->gl_data)
{
166
167
168
169
170
171
172
173
free(device->gl_data);
device->gl_data = NULL;
}
free(device);
device = NULL;
}
}
174
175
176
177
static PtWidget_t *ph_CreateWindow(_THIS)
{
PtWidget_t *widget;
178
widget = PtCreateWidget(PtWindow, NULL, 0, NULL);
179
180
181
182
183
184
185
186
return widget;
}
static int ph_SetupWindow(_THIS, int w, int h, int flags)
{
PtArg_t args[32];
PhPoint_t pos = {0, 0};
187
PhDim_t* olddim;
188
PhDim_t dim = {w, h};
189
PhRect_t desktopextent;
190
int nargs = 0;
191
192
193
const char* windowpos;
const char* iscentered;
int x, y;
194
195
196
197
198
199
200
/* check if window size has been changed by Window Manager */
PtGetResource(window, Pt_ARG_DIM, &olddim, 0);
if ((olddim->w!=w) || (olddim->h!=h))
{
PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0);
}
201
202
203
if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE)
{
204
205
206
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX | Ph_WM_RESTORE);
207
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
208
PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
209
210
211
}
else
{
212
213
214
215
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
216
PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
217
218
219
220
}
if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN))
{
221
222
223
224
225
226
227
228
229
if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER);
}
230
231
232
233
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
234
Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
235
236
}
237
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
238
239
{
PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
240
PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
241
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
242
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY);
243
244
245
}
else
{
246
247
248
249
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_FFRONT | Ph_WM_CONSWITCH);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT);
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
250
251
252
253
254
255
256
257
if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE)
{
PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
}
258
if (!currently_maximized)
259
{
260
261
262
263
windowpos = getenv("SDL_VIDEO_WINDOW_POS");
iscentered = getenv("SDL_VIDEO_CENTERED");
if ((iscentered) || ((windowpos) && (strcmp(windowpos, "center")==0)))
264
{
265
266
PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
if (desktop_mode.width>w)
267
{
268
269
270
271
272
pos.x = (desktop_mode.width - w)/2;
}
if (desktop_mode.height>h)
{
pos.y = (desktop_mode.height - h)/2;
273
274
}
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
pos.x+=desktopextent.ul.x;
pos.y+=desktopextent.ul.y;
PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
}
else
{
if (windowpos)
{
if (sscanf(windowpos, "%d,%d", &x, &y) == 2)
{
if ((x<desktop_mode.width) && (y<desktop_mode.height))
{
PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
pos.x=x+desktopextent.ul.x;
pos.y=y+desktopextent.ul.y;
}
PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
}
}
}
}
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* if window is maximized render it as maximized */
if (currently_maximized)
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISMAX);
}
else
{
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISMAX);
}
/* do not grab the keyboard by default */
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISALTKEY);
/* bring the focus to the window */
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFOCUS);
313
/* allow to catch hide event */
314
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
315
PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE);
316
317
318
319
}
PtSetResources(window, nargs, args);
PtRealizeWidget(window);
320
PtWindowToFront(window);
321
322
323
324
325
326
#if 0 /* FIXME */
PtGetResource(window, Pt_ARG_POS, &olddim, 0);
fprintf(stderr, "POSITION: %d, %d\n", olddim->w, olddim->h);
#endif
327
328
329
return 0;
}
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
static const struct ColourMasks* ph_GetColourMasks(int bpp)
{
/* The alpha mask doesn't appears to be needed */
static const struct ColourMasks phColorMasks[5] = {
/* 8 bit */ {0, 0, 0, 0, 8},
/* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 15},
/* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16},
/* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
/* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
};
switch (bpp)
{
case 8:
return &phColorMasks[0];
case 15:
return &phColorMasks[1];
case 16:
return &phColorMasks[2];
case 24:
return &phColorMasks[3];
case 32:
return &phColorMasks[4];
}
return NULL;
}
357
static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat)
358
{
359
PgHWCaps_t hwcaps;
360
int i;
361
362
window=NULL;
363
desktoppal=SDLPH_PAL_NONE;
364
365
366
#ifdef HAVE_OPENGL
oglctx=NULL;
367
oglbuffers=NULL;
368
369
oglflags=0;
oglbpp=0;
370
#endif /* HAVE_OPENGL */
371
372
373
old_video_mode=-1;
old_refresh_rate=-1;
374
375
376
if (NULL == (event = malloc(EVENT_SIZE)))
{
377
378
SDL_OutOfMemory();
return -1;
379
}
380
memset(event, 0x00, EVENT_SIZE);
381
382
383
384
window = ph_CreateWindow(this);
if (window == NULL)
{
385
SDL_SetError("ph_VideoInit(): Couldn't create video window !\n");
386
387
388
return -1;
}
389
390
391
392
393
394
395
/* Create the blank cursor */
SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
(int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
(int)BLANK_CHOTX, (int)BLANK_CHOTY);
if (SDL_BlankCursor == NULL)
{
396
return -1;
397
398
}
399
if (PgGetGraphicsHWCaps(&hwcaps) < 0)
400
{
401
402
403
SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
this->FreeWMCursor(this, SDL_BlankCursor);
return -1;
404
405
}
406
if (PgGetVideoModeInfo(hwcaps.current_video_mode, &desktop_mode) < 0)
407
{
408
409
410
SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
this->FreeWMCursor(this, SDL_BlankCursor);
return -1;
411
412
413
}
/* We need to return BytesPerPixel as it in used by CreateRGBsurface */
414
415
416
vformat->BitsPerPixel = desktop_mode.bits_per_pixel;
vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width;
desktopbpp = desktop_mode.bits_per_pixel;
417
418
419
/* save current palette */
if (desktopbpp==8)
420
{
421
422
PgGetPalette(savedpal);
PgGetPalette(syspalph);
423
}
424
425
426
427
428
429
430
431
else
{
for(i=0; i<_Pg_MAX_PALETTE; i++)
{
savedpal[i]=PgRGB(0, 0, 0);
syspalph[i]=PgRGB(0, 0, 0);
}
}
432
433
currently_fullscreen = 0;
434
currently_hided = 0;
435
currently_maximized = 0;
436
437
438
439
440
441
442
443
444
current_overlay = NULL;
OCImage.direct_context = NULL;
OCImage.offscreen_context = NULL;
OCImage.offscreen_backcontext = NULL;
OCImage.oldDC = NULL;
OCImage.CurrentFrameData = NULL;
OCImage.FrameData0 = NULL;
OCImage.FrameData1 = NULL;
445
videomode_emulatemode = 0;
446
447
this->info.wm_available = 1;
448
449
ph_UpdateHWInfo(this);
450
451
452
453
return 0;
}
454
static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
455
{
456
const struct ColourMasks* mask;
457
458
459
460
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
461
462
current->flags = flags;
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/* if we do not have desired fullscreen mode, then fallback into window mode */
if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0))
{
current->flags &= ~SDL_FULLSCREEN;
current->flags &= ~SDL_NOFRAME;
current->flags &= ~SDL_RESIZABLE;
}
ph_SetupWindow(this, width, height, current->flags);
mask = ph_GetColourMasks(bpp);
if (mask != NULL)
{
SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0);
}
else
{
SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n");
return NULL;
}
483
484
if ((current->flags & SDL_OPENGL)==SDL_OPENGL)
485
{
486
487
488
#if !defined(HAVE_OPENGL)
/* if no built-in OpenGL support */
SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n");
489
current->flags &= ~SDL_OPENGL;
490
return NULL;
491
#endif /* HAVE_OPENGL */
492
}
493
494
else
{
495
496
/* Initialize internal variables */
if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
497
{
498
499
500
501
if (bpp==8)
{
desktoppal=SDLPH_PAL_SYSTEM;
}
502
503
current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
504
current->flags |= SDL_HWSURFACE;
505
}
506
507
else
{
508
/* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */
509
510
511
512
current->flags &= ~SDL_DOUBLEBUF;
/* Use offscreen memory if SDL_HWSURFACE flag is set */
if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
513
{
514
515
516
517
if (desktopbpp!=bpp)
{
current->flags &= ~SDL_HWSURFACE;
}
518
}
519
520
521
522
523
524
/* using palette emulation code in window mode */
if (bpp==8)
{
if (desktopbpp>=15)
{
525
desktoppal = SDLPH_PAL_EMULATE;
526
527
528
}
else
{
529
desktoppal = SDLPH_PAL_SYSTEM;
530
531
532
}
}
else
533
{
534
desktoppal = SDLPH_PAL_NONE;
535
}
536
}
537
538
539
540
}
current->w = width;
current->h = height;
541
542
543
544
545
if (desktoppal==SDLPH_PAL_SYSTEM)
{
current->flags|=SDL_HWPALETTE;
}
546
547
548
/* Must call at least once for setup image planes */
if (ph_SetupUpdateFunction(this, current, current->flags)==-1)
549
{
550
/* Error string was filled in the ph_SetupUpdateFunction() */
551
552
return NULL;
}
553
554
555
556
557
558
/* finish window drawing, if we are not in fullscreen, of course */
if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{
PtFlush();
}
559
560
561
562
else
{
PgFlush();
}
563
564
565
visualbpp=bpp;
566
ph_UpdateHWInfo(this);
567
568
569
SDL_Unlock_EventThread();
570
/* We've done! */
571
return (current);
572
573
574
575
}
static void ph_VideoQuit(_THIS)
{
576
577
/* restore palette */
if (desktopbpp==8)
578
{
579
580
581
PgSetPalette(syspalph, 0, -1, 0, 0, 0);
PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
PgFlush();
582
}
583
584
585
ph_DestroyImage(this, SDL_VideoSurface);
586
587
588
589
590
591
592
if (window)
{
PtUnrealizeWidget(window);
PtDestroyWidget(window);
window=NULL;
}
593
594
595
596
597
if (event!=NULL)
{
free(event);
event=NULL;
}
598
}
599
600
601
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
602
int i;
603
604
605
606
607
SDL_Rect updaterect;
updaterect.x = updaterect.y = 0;
updaterect.w = this->screen->w;
updaterect.h = this->screen->h;
608
609
610
611
612
613
614
615
/* palette emulation code, using palette of the PhImage_t struct */
if (desktoppal==SDLPH_PAL_EMULATE)
{
if ((SDL_Image) && (SDL_Image->palette))
{
for (i=firstcolor; i<firstcolor+ncolors; i++)
{
616
617
syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
SDL_Image->palette[i] = syspalph[i];
618
}
619
620
621
/* image needs to be redrawn */
this->UpdateRects(this, 1, &updaterect);
622
}
623
}
624
625
626
else
{
if (desktoppal==SDLPH_PAL_SYSTEM)
627
{
628
629
for (i=firstcolor; i<firstcolor+ncolors; i++)
{
630
syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
631
632
633
634
}
if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{
635
/* window mode must use soft palette */
636
PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
637
638
/* image needs to be redrawn */
this->UpdateRects(this, 1, &updaterect);
639
640
641
642
}
else
{
/* fullscreen mode must use hardware palette */
643
PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
644
}
645
}
646
else
647
{
648
/* SDLPH_PAL_NONE do nothing */
649
}
650
651
652
}
return 1;
653
}