Skip to content

Latest commit

 

History

History
1057 lines (901 loc) · 26.9 KB

SDL_ph_image.c

File metadata and controls

1057 lines (901 loc) · 26.9 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2004 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
22
23
24
25
26
27
28
29
30
31
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include <stdlib.h>
#include <Ph.h>
#include <photon/Pg.h>
Jan 20, 2003
Jan 20, 2003
32
#include "SDL.h"
Apr 26, 2001
Apr 26, 2001
33
34
#include "SDL_error.h"
#include "SDL_endian.h"
Jan 20, 2003
Jan 20, 2003
35
36
#include "SDL_video.h"
#include "SDL_pixels_c.h"
Apr 26, 2001
Apr 26, 2001
37
#include "SDL_ph_image_c.h"
Aug 4, 2003
Aug 4, 2003
38
#include "SDL_ph_modes_c.h"
Mar 23, 2002
Mar 23, 2002
39
Apr 26, 2001
Apr 26, 2001
40
41
int ph_SetupImage(_THIS, SDL_Surface *screen)
{
Mar 23, 2002
Mar 23, 2002
42
PgColor_t* palette=NULL;
May 28, 2002
May 28, 2002
43
44
45
46
int type=0;
int bpp;
bpp=screen->format->BitsPerPixel;
Apr 26, 2001
Apr 26, 2001
47
Mar 2, 2002
Mar 2, 2002
48
/* Determine image type */
May 28, 2002
May 28, 2002
49
switch(bpp)
Mar 2, 2002
Mar 2, 2002
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
case 8:{
type = Pg_IMAGE_PALETTE_BYTE;
}
break;
case 15:{
type = Pg_IMAGE_DIRECT_555;
}
break;
case 16:{
type = Pg_IMAGE_DIRECT_565;
}
break;
case 24:{
type = Pg_IMAGE_DIRECT_888;
}
break;
case 32:{
type = Pg_IMAGE_DIRECT_8888;
}
break;
default:{
Aug 4, 2003
Aug 4, 2003
72
SDL_SetError("ph_SetupImage(): unsupported bpp=%d !\n", bpp);
Mar 2, 2002
Mar 2, 2002
73
74
75
76
return -1;
}
break;
}
Apr 26, 2001
Apr 26, 2001
77
Mar 23, 2002
Mar 23, 2002
78
/* palette emulation code */
May 28, 2002
May 28, 2002
79
if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE))
Mar 23, 2002
Mar 23, 2002
80
81
82
{
/* creating image palette */
palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
Aug 4, 2003
Aug 4, 2003
83
84
85
86
87
if (palette==NULL)
{
SDL_SetError("ph_SetupImage(): can't allocate memory for palette !\n");
return -1;
}
Mar 23, 2002
Mar 23, 2002
88
89
90
91
92
PgGetPalette(palette);
/* using shared memory for speed (set last param to 1) */
if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
{
Aug 4, 2003
Aug 4, 2003
93
94
SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
free(palette);
Mar 23, 2002
Mar 23, 2002
95
96
97
98
return -1;
}
}
else
Mar 2, 2002
Mar 2, 2002
99
{
Mar 23, 2002
Mar 23, 2002
100
101
102
/* using shared memory for speed (set last param to 1) */
if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
{
Aug 4, 2003
Aug 4, 2003
103
SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n", bpp);
Mar 23, 2002
Mar 23, 2002
104
105
return -1;
}
Mar 2, 2002
Mar 2, 2002
106
}
Jan 20, 2003
Jan 20, 2003
107
Mar 2, 2002
Mar 2, 2002
108
screen->pixels = SDL_Image->image;
Aug 4, 2003
Aug 4, 2003
109
screen->pitch = SDL_Image->bpl;
Jan 20, 2003
Jan 20, 2003
110
Mar 2, 2002
Mar 2, 2002
111
this->UpdateRects = ph_NormalUpdate;
Apr 26, 2001
Apr 26, 2001
112
Mar 2, 2002
Mar 2, 2002
113
return 0;
Apr 26, 2001
Apr 26, 2001
114
115
}
Mar 23, 2002
Mar 23, 2002
116
int ph_SetupOCImage(_THIS, SDL_Surface *screen)
Apr 26, 2001
Apr 26, 2001
117
{
May 19, 2002
May 19, 2002
118
int type = 0;
May 28, 2002
May 28, 2002
119
int bpp;
Jan 20, 2003
Jan 20, 2003
120
121
OCImage.flags = screen->flags;
May 28, 2002
May 28, 2002
122
123
bpp=screen->format->BitsPerPixel;
Apr 26, 2001
Apr 26, 2001
124
May 19, 2002
May 19, 2002
125
/* Determine image type */
May 28, 2002
May 28, 2002
126
switch(bpp)
May 19, 2002
May 19, 2002
127
128
129
130
131
132
133
{
case 8: {
type = Pg_IMAGE_PALETTE_BYTE;
}
break;
case 15:{
type = Pg_IMAGE_DIRECT_555;
Apr 26, 2001
Apr 26, 2001
134
135
}
break;
May 19, 2002
May 19, 2002
136
137
138
139
140
141
142
143
144
145
146
147
148
case 16:{
type = Pg_IMAGE_DIRECT_565;
}
break;
case 24:{
type = Pg_IMAGE_DIRECT_888;
}
break;
case 32:{
type = Pg_IMAGE_DIRECT_8888;
}
break;
default:{
Aug 4, 2003
Aug 4, 2003
149
SDL_SetError("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
May 19, 2002
May 19, 2002
150
151
152
153
return -1;
}
break;
}
Apr 26, 2001
Apr 26, 2001
154
Jan 20, 2003
Jan 20, 2003
155
156
/* Currently only offscreen contexts with the same bit depth as the
* display can be created. */
May 19, 2002
May 19, 2002
157
158
159
160
OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
if (OCImage.offscreen_context == NULL)
{
Aug 4, 2003
Aug 4, 2003
161
SDL_SetError("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n");
May 19, 2002
May 19, 2002
162
163
164
return -1;
}
Aug 4, 2003
Aug 4, 2003
165
screen->pitch = OCImage.offscreen_context->pitch;
May 19, 2002
May 19, 2002
166
Feb 14, 2004
Feb 14, 2004
167
OCImage.dc_ptr = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
Jan 20, 2003
Jan 20, 2003
168
Aug 4, 2003
Aug 4, 2003
169
if (OCImage.dc_ptr == NULL)
May 19, 2002
May 19, 2002
170
{
Aug 4, 2003
Aug 4, 2003
171
172
SDL_SetError("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n");
PhDCRelease(OCImage.offscreen_context);
May 19, 2002
May 19, 2002
173
174
175
return -1;
}
Aug 4, 2003
Aug 4, 2003
176
OCImage.FrameData0 = OCImage.dc_ptr;
May 19, 2002
May 19, 2002
177
178
179
180
181
OCImage.CurrentFrameData = OCImage.FrameData0;
OCImage.current = 0;
PhDCSetCurrent(OCImage.offscreen_context);
Jan 20, 2003
Jan 20, 2003
182
screen->pixels = OCImage.CurrentFrameData;
May 19, 2002
May 19, 2002
183
184
185
186
this->UpdateRects = ph_OCUpdate;
return 0;
Apr 26, 2001
Apr 26, 2001
187
188
}
Jan 20, 2003
Jan 20, 2003
189
190
191
192
int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
{
OCImage.flags = screen->flags;
Aug 4, 2003
Aug 4, 2003
193
194
/* Begin direct mode */
if (!ph_EnterFullScreen(this, screen))
Jan 20, 2003
Jan 20, 2003
195
196
197
198
{
return -1;
}
Aug 4, 2003
Aug 4, 2003
199
200
/* store palette for fullscreen */
if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
Jan 20, 2003
Jan 20, 2003
201
{
Aug 4, 2003
Aug 4, 2003
202
203
204
PgGetPalette(savedpal);
PgGetPalette(syspalph);
}
Jan 20, 2003
Jan 20, 2003
205
Aug 30, 2003
Aug 30, 2003
206
OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
Aug 4, 2003
Aug 4, 2003
207
208
209
210
211
212
213
214
if (OCImage.offscreen_context == NULL)
{
SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
return -1;
}
if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
{
Feb 14, 2004
Feb 14, 2004
215
OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
Aug 4, 2003
Aug 4, 2003
216
if (OCImage.offscreen_backcontext == NULL)
Jan 20, 2003
Jan 20, 2003
217
{
Aug 4, 2003
Aug 4, 2003
218
219
SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
return -1;
Jan 20, 2003
Jan 20, 2003
220
221
222
}
}
Aug 4, 2003
Aug 4, 2003
223
224
OCImage.FrameData0 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
if (OCImage.FrameData0 == NULL)
Jan 20, 2003
Jan 20, 2003
225
{
Aug 4, 2003
Aug 4, 2003
226
227
SDL_SetError("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n");
ph_DestroyImage(this, screen);
Jan 20, 2003
Jan 20, 2003
228
229
230
return -1;
}
Aug 4, 2003
Aug 4, 2003
231
232
233
234
235
236
237
238
239
240
if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
{
OCImage.FrameData1 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_backcontext);
if (OCImage.FrameData1 == NULL)
{
SDL_SetError("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
ph_DestroyImage(this, screen);
return -1;
}
}
Jan 20, 2003
Jan 20, 2003
241
Aug 4, 2003
Aug 4, 2003
242
/* wait for the hardware */
Feb 14, 2004
Feb 14, 2004
243
PgFlush();
Aug 4, 2003
Aug 4, 2003
244
PgWaitHWIdle();
Jan 20, 2003
Jan 20, 2003
245
Aug 4, 2003
Aug 4, 2003
246
247
if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
{
Feb 14, 2004
Feb 14, 2004
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
OCImage.current = 0;
PhDCSetCurrent(OCImage.offscreen_context);
screen->pitch = OCImage.offscreen_context->pitch;
screen->pixels = OCImage.FrameData0;
/* emulate 640x400 videomode */
if (videomode_emulatemode==1)
{
int i;
for (i=0; i<40; i++)
{
memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
}
for (i=440; i<480; i++)
{
memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
}
screen->pixels+=screen->pitch*40;
}
PgSwapDisplay(OCImage.offscreen_backcontext, 0);
Aug 4, 2003
Aug 4, 2003
269
270
271
272
273
274
275
}
else
{
OCImage.current = 0;
PhDCSetCurrent(OCImage.offscreen_context);
screen->pitch = OCImage.offscreen_context->pitch;
screen->pixels = OCImage.FrameData0;
Feb 14, 2004
Feb 14, 2004
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* emulate 640x400 videomode */
if (videomode_emulatemode==1)
{
int i;
for (i=0; i<40; i++)
{
memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
}
for (i=440; i<480; i++)
{
memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
}
screen->pixels+=screen->pitch*40;
}
Aug 4, 2003
Aug 4, 2003
292
}
Jan 20, 2003
Jan 20, 2003
293
Aug 4, 2003
Aug 4, 2003
294
this->UpdateRects = ph_OCDCUpdate;
Jan 20, 2003
Jan 20, 2003
295
Feb 14, 2004
Feb 14, 2004
296
/* wait for the hardware */
Aug 23, 2003
Aug 23, 2003
297
PgFlush();
Feb 14, 2004
Feb 14, 2004
298
PgWaitHWIdle();
Aug 23, 2003
Aug 23, 2003
299
Jan 20, 2003
Jan 20, 2003
300
301
302
return 0;
}
Aug 30, 2003
Aug 30, 2003
303
304
305
#ifdef HAVE_OPENGL
static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
306
{
Aug 30, 2003
Aug 30, 2003
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
PhDim_t dim;
uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
int exposepost=0;
int OGLargc;
dim.w=width;
dim.h=height;
if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
{
PdOpenGLContextResize(oglctx, &dim);
PhDCSetCurrent(oglctx);
return 0;
}
else
{
if (oglctx!=NULL)
{
PhDCSetCurrent(NULL);
PhDCRelease(oglctx);
oglctx=NULL;
exposepost=1;
}
}
OGLargc=0;
if (this->gl_config.depth_size)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
OGLAttrib[OGLargc++]=this->gl_config.depth_size;
}
if (this->gl_config.stencil_size)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
}
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
if (flags & SDL_FULLSCREEN)
{
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
}
OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
if (this->gl_config.double_buffer)
{
oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
}
else
{
oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
}
if (oglctx==NULL)
{
SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
return (-1);
}
PhDCSetCurrent(oglctx);
PtFlush();
oglflags=flags;
oglbpp=bpp;
if (exposepost!=0)
{
/* OpenGL context has been recreated, so report about this fact */
SDL_PrivateExpose();
}
return 0;
}
int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
{
this->UpdateRects = ph_OpenGLUpdate;
screen->pixels=NULL;
screen->pitch=NULL;
if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
{
screen->flags &= ~SDL_OPENGL;
return -1;
}
return 0;
}
#endif /* HAVE_OPENGL */
void ph_DestroyImage(_THIS, SDL_Surface* screen)
{
#ifdef HAVE_OPENGL
if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
{
if (oglctx)
{
PhDCSetCurrent(NULL);
PhDCRelease(oglctx);
oglctx=NULL;
oglflags=0;
oglbpp=0;
}
return;
}
#endif /* HAVE_OPENGL */
Aug 4, 2003
Aug 4, 2003
419
420
421
422
423
424
425
426
427
428
429
430
if (currently_fullscreen)
{
/* if we right now in 8bpp fullscreen we must release palette */
if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
{
PgSetPalette(syspalph, 0, -1, 0, 0, 0);
PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
PgFlush();
}
ph_LeaveFullScreen(this);
}
Mar 2, 2002
Mar 2, 2002
431
432
433
434
435
if (OCImage.offscreen_context != NULL)
{
PhDCRelease(OCImage.offscreen_context);
OCImage.offscreen_context = NULL;
OCImage.FrameData0 = NULL;
Aug 4, 2003
Aug 4, 2003
436
437
438
439
440
}
if (OCImage.offscreen_backcontext != NULL)
{
PhDCRelease(OCImage.offscreen_backcontext);
OCImage.offscreen_backcontext = NULL;
Mar 2, 2002
Mar 2, 2002
441
442
OCImage.FrameData1 = NULL;
}
Aug 4, 2003
Aug 4, 2003
443
OCImage.CurrentFrameData = NULL;
Apr 26, 2001
Apr 26, 2001
444
Mar 2, 2002
Mar 2, 2002
445
446
if (SDL_Image)
{
Mar 23, 2002
Mar 23, 2002
447
448
449
450
451
/* if palette allocated, free it */
if (SDL_Image->palette)
{
free(SDL_Image->palette);
}
Mar 2, 2002
Mar 2, 2002
452
453
454
PgShmemDestroy(SDL_Image->image);
free(SDL_Image);
}
Apr 26, 2001
Apr 26, 2001
455
Mar 23, 2002
Mar 23, 2002
456
457
458
/* Must be zeroed everytime */
SDL_Image = NULL;
Mar 2, 2002
Mar 2, 2002
459
460
461
462
if (screen)
{
screen->pixels = NULL;
}
Apr 26, 2001
Apr 26, 2001
463
464
}
Feb 14, 2004
Feb 14, 2004
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
int ph_UpdateHWInfo(_THIS)
{
PgVideoModeInfo_t vmode;
PgHWCaps_t hwcaps;
/* Update video ram amount */
if (PgGetGraphicsHWCaps(&hwcaps) < 0)
{
SDL_SetError("ph_UpdateHWInfo(): GetGraphicsHWCaps() function failed !\n");
return -1;
}
this->info.video_mem=hwcaps.currently_available_video_ram/1024;
/* obtain current mode capabilities */
if (PgGetVideoModeInfo(hwcaps.current_video_mode, &vmode) < 0)
{
SDL_SetError("ph_UpdateHWInfo(): GetVideoModeInfo() function failed !\n");
return -1;
}
this->info.blit_hw = 1;
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND) == PgVM_MODE_CAP2_ALPHA_BLEND)
{
this->info.blit_hw_A = 1;
}
else
{
this->info.blit_hw_A = 0;
}
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_CHROMA) == PgVM_MODE_CAP2_CHROMA)
{
this->info.blit_hw_CC = 1;
}
else
{
this->info.blit_hw_CC = 0;
}
return 0;
}
Aug 30, 2003
Aug 30, 2003
508
int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
509
{
Feb 14, 2004
Feb 14, 2004
510
511
int setupresult=-1;
Apr 26, 2001
Apr 26, 2001
512
513
ph_DestroyImage(this, screen);
Aug 30, 2003
Aug 30, 2003
514
515
516
#ifdef HAVE_OPENGL
if ((flags & SDL_OPENGL)==SDL_OPENGL)
{
Feb 14, 2004
Feb 14, 2004
517
setupresult=ph_SetupOpenGLImage(this, screen);
Aug 30, 2003
Aug 30, 2003
518
}
Feb 14, 2004
Feb 14, 2004
519
else
Jan 20, 2003
Jan 20, 2003
520
{
Feb 14, 2004
Feb 14, 2004
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
#endif /* HAVE_OPENGL */
if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
{
setupresult=ph_SetupFullScreenImage(this, screen);
}
else
{
if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
{
setupresult=ph_SetupOCImage(this, screen);
}
else
{
setupresult=ph_SetupImage(this, screen);
}
}
#ifdef HAVE_OPENGL
Jan 20, 2003
Jan 20, 2003
538
}
Feb 14, 2004
Feb 14, 2004
539
540
#endif /* HAVE_OPENGL */
if (setupresult!=-1)
Apr 26, 2001
Apr 26, 2001
541
{
Feb 14, 2004
Feb 14, 2004
542
ph_UpdateHWInfo(this);
Apr 26, 2001
Apr 26, 2001
543
}
Feb 14, 2004
Feb 14, 2004
544
545
return setupresult;
Apr 26, 2001
Apr 26, 2001
546
}
Aug 4, 2003
Aug 4, 2003
547
Aug 30, 2003
Aug 30, 2003
548
int ph_AllocHWSurface(_THIS, SDL_Surface* surface)
Apr 26, 2001
Apr 26, 2001
549
{
Feb 14, 2004
Feb 14, 2004
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
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
597
PgHWCaps_t hwcaps;
if (surface->hwdata!=NULL)
{
SDL_SetError("ph_AllocHWSurface(): hwdata already exists!\n");
return -1;
}
surface->hwdata=malloc(sizeof(struct private_hwdata));
memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
surface->hwdata->offscreenctx=PdCreateOffscreenContext(0, surface->w, surface->h, Pg_OSC_MEM_PAGE_ALIGN);
if (surface->hwdata->offscreenctx == NULL)
{
SDL_SetError("ph_AllocHWSurface(): PdCreateOffscreenContext() function failed !\n");
return -1;
}
surface->pixels=PdGetOffscreenContextPtr(surface->hwdata->offscreenctx);
if (surface->pixels==NULL)
{
PhDCRelease(surface->hwdata->offscreenctx);
SDL_SetError("ph_AllocHWSurface(): PdGetOffscreenContextPtr() function failed !\n");
return -1;
}
surface->pitch=surface->hwdata->offscreenctx->pitch;
surface->flags|=SDL_HWSURFACE;
surface->flags|=SDL_PREALLOC;
#if 0 /* FIXME */
/* create simple offscreen lock */
surface->hwdata->crlockparam.flags=0;
if (PdCreateOffscreenLock(surface->hwdata->offscreenctx, &surface->hwdata->crlockparam)!=EOK)
{
PhDCRelease(surface->hwdata->offscreenctx);
SDL_SetError("ph_AllocHWSurface(): Can't create offscreen lock !\n");
return -1;
}
#endif /* 0 */
/* Update video ram amount */
if (PgGetGraphicsHWCaps(&hwcaps) < 0)
{
PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
PhDCRelease(surface->hwdata->offscreenctx);
SDL_SetError("ph_AllocHWSurface(): GetGraphicsHWCaps() function failed !\n");
return -1;
}
this->info.video_mem=hwcaps.currently_available_video_ram/1024;
return 0;
Apr 26, 2001
Apr 26, 2001
598
599
}
Aug 30, 2003
Aug 30, 2003
600
void ph_FreeHWSurface(_THIS, SDL_Surface* surface)
Apr 26, 2001
Apr 26, 2001
601
{
Feb 14, 2004
Feb 14, 2004
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
PgHWCaps_t hwcaps;
if (surface->hwdata==NULL)
{
SDL_SetError("ph_FreeHWSurface(): no hwdata!\n");
return;
}
if (surface->hwdata->offscreenctx == NULL)
{
SDL_SetError("ph_FreeHWSurface(): no offscreen context to delete!\n");
return;
}
#if 0 /* FIXME */
/* unlock the offscreen context if it has been locked before destroy it */
if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
{
PdUnlockOffscreen(surface->hwdata->offscreenctx);
}
PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
#endif /* 0 */
PhDCRelease(surface->hwdata->offscreenctx);
free(surface->hwdata);
surface->hwdata=NULL;
/* Update video ram amount */
if (PgGetGraphicsHWCaps(&hwcaps) < 0)
{
SDL_SetError("ph_FreeHWSurface(): GetGraphicsHWCaps() function failed !\n");
return;
}
this->info.video_mem=hwcaps.currently_available_video_ram/1024;
Mar 23, 2002
Mar 23, 2002
638
return;
Apr 26, 2001
Apr 26, 2001
639
640
}
Feb 14, 2004
Feb 14, 2004
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
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
int ph_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
{
if ((src->hwdata==NULL) && (src != this->screen))
{
SDL_SetError("ph_CheckHWBlit(): Source surface haven't hardware specific data.\n");
src->flags&=~SDL_HWACCEL;
return -1;
}
if ((src->flags & SDL_HWSURFACE) != SDL_HWSURFACE)
{
SDL_SetError("ph_CheckHWBlit(): Source surface isn't a hardware surface.\n");
src->flags&=~SDL_HWACCEL;
return -1;
}
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
{
if (this->info.blit_hw_CC!=1)
{
src->flags&=~SDL_HWACCEL;
src->map->hw_blit=NULL;
return -1;
}
}
if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA)
{
if (this->info.blit_hw_A!=1)
{
src->flags&=~SDL_HWACCEL;
src->map->hw_blit=NULL;
return -1;
}
}
src->flags|=SDL_HWACCEL;
src->map->hw_blit = ph_HWAccelBlit;
return 1;
}
PgColor_t ph_ExpandColor(_THIS, SDL_Surface* surface, Uint32 color)
{
Uint32 truecolor;
/* Photon API accepts true colors only during hw filling operations */
switch(surface->format->BitsPerPixel)
{
case 8:
{
if ((surface->format->palette) && (color<=surface->format->palette->ncolors))
{
truecolor=PgRGB(surface->format->palette->colors[color].r,
surface->format->palette->colors[color].g,
surface->format->palette->colors[color].b);
}
else
{
SDL_SetError("ph_ExpandColor(): Color out of range for the 8bpp mode !\n");
return 0xFFFFFFFFUL;
}
}
break;
case 15:
{
truecolor = ((color & 0x00007C00UL) << 9) | /* R */
((color & 0x000003E0UL) << 6) | /* G */
((color & 0x0000001FUL) << 3) | /* B */
((color & 0x00007000UL) << 4) | /* R compensation */
((color & 0x00000380UL) << 1) | /* G compensation */
((color & 0x0000001CUL) >> 2); /* B compensation */
}
break;
case 16:
{
truecolor = ((color & 0x0000F800UL) << 8) | /* R */
((color & 0x000007E0UL) << 5) | /* G */
((color & 0x0000001FUL) << 3) | /* B */
((color & 0x0000E000UL) << 3) | /* R compensation */
((color & 0x00000600UL) >> 1) | /* G compensation */
((color & 0x0000001CUL) >> 2); /* B compensation */
}
break;
case 24:
{
truecolor=color & 0x00FFFFFFUL;
}
break;
case 32:
{
truecolor=color;
}
break;
default:
{
SDL_SetError("ph_ExpandColor(): Unsupported depth for the hardware operations !\n");
return 0xFFFFFFFFUL;
}
}
return truecolor;
}
int ph_FillHWRect(_THIS, SDL_Surface* surface, SDL_Rect* rect, Uint32 color)
{
PgColor_t oldcolor;
Uint32 truecolor;
int ydisp=0;
truecolor=ph_ExpandColor(this, surface, color);
if (truecolor==0xFFFFFFFFUL)
{
return -1;
}
oldcolor=PgSetFillColor(truecolor);
/* 640x400 videomode emulation */
if (videomode_emulatemode==1)
{
ydisp+=40;
}
PgDrawIRect(rect->x, rect->y+ydisp, rect->w+rect->x-1, rect->h+rect->y+ydisp-1, Pg_DRAW_FILL);
PgSetFillColor(oldcolor);
PgFlush();
PgWaitHWIdle();
return 0;
}
Aug 30, 2003
Aug 30, 2003
773
int ph_FlipHWSurface(_THIS, SDL_Surface* screen)
Apr 26, 2001
Apr 26, 2001
774
{
Feb 14, 2004
Feb 14, 2004
775
776
PhArea_t farea;
Aug 4, 2003
Aug 4, 2003
777
778
if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
{
Feb 14, 2004
Feb 14, 2004
779
780
/* flush all drawing ops before blitting */
PgFlush();
Aug 30, 2003
Aug 30, 2003
781
PgWaitHWIdle();
Feb 14, 2004
Feb 14, 2004
782
783
784
785
786
787
788
789
farea.pos.x=0;
farea.pos.y=0;
farea.size.w=screen->w;
farea.size.h=screen->h;
/* emulate 640x400 videomode */
if (videomode_emulatemode==1)
Aug 4, 2003
Aug 4, 2003
790
{
Feb 14, 2004
Feb 14, 2004
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
farea.pos.y+=40;
}
PgContextBlitArea(OCImage.offscreen_context, &farea, OCImage.offscreen_backcontext, &farea);
/* flush the blitting */
PgFlush();
PgWaitHWIdle();
}
return 0;
}
int ph_LockHWSurface(_THIS, SDL_Surface* surface)
{
#if 0 /* FIXME */
int lockresult;
if (surface->hwdata == NULL)
{
return;
}
surface->hwdata->lockparam.flags=0;
surface->hwdata->lockparam.time_out=NULL;
lockresult=PdLockOffscreen(surface->hwdata->offscreenctx, &surface->hwdata->lockparam);
switch (lockresult)
{
case EOK:
break;
case Pg_OSC_LOCK_DEADLOCK:
SDL_SetError("ph_LockHWSurface(): Deadlock detected !\n");
return -1;
case Pg_OSC_LOCK_INVALID:
SDL_SetError("ph_LockHWSurface(): Lock invalid !\n");
return -1;
default:
SDL_SetError("ph_LockHWSurface(): Can't lock the surface !\n");
return -1;
}
#endif /* 0 */
return 0;
}
void ph_UnlockHWSurface(_THIS, SDL_Surface* surface)
{
#if 0 /* FIXME */
int unlockresult;
if ((surface == NULL) || (surface->hwdata == NULL))
{
return;
}
if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
{
unlockresult=PdUnlockOffscreen(surface->hwdata->offscreenctx);
}
#endif /* 0 */
return;
}
int ph_HWAccelBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect)
{
SDL_VideoDevice* this=current_video;
PhArea_t srcarea;
PhArea_t dstarea;
int ydisp=0;
/* 640x400 videomode emulation */
if (videomode_emulatemode==1)
{
ydisp+=40;
}
srcarea.pos.x=srcrect->x;
srcarea.pos.y=srcrect->y;
srcarea.size.w=srcrect->w;
srcarea.size.h=srcrect->h;
dstarea.pos.x=dstrect->x;
dstarea.pos.y=dstrect->y;
dstarea.size.w=dstrect->w;
dstarea.size.h=dstrect->h;
if (((src == this->screen) || (src->hwdata!=NULL)) && ((dst == this->screen) || (dst->hwdata!=NULL)))
{
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
{
ph_SetHWColorKey(this, src, src->format->colorkey);
PgChromaOn();
}
if (dst == this->screen)
{
if (src == this->screen)
{
/* blitting from main screen to main screen */
dstarea.pos.y+=ydisp;
srcarea.pos.y+=ydisp;
PgContextBlitArea(OCImage.offscreen_context, &srcarea, OCImage.offscreen_context, &dstarea);
}
else
{
/* blitting from offscreen to main screen */
dstarea.pos.y+=ydisp;
PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, OCImage.offscreen_context, &dstarea);
}
Aug 4, 2003
Aug 4, 2003
903
904
905
}
else
{
Feb 14, 2004
Feb 14, 2004
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
if (src == this->screen)
{
/* blitting from main screen to offscreen */
srcarea.pos.y+=ydisp;
PgContextBlitArea(OCImage.offscreen_context, &srcarea, dst->hwdata->offscreenctx, &dstarea);
}
else
{
/* blitting offscreen to offscreen */
PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, dst->hwdata->offscreenctx, &dstarea);
}
}
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
{
PgChromaOff();
Aug 4, 2003
Aug 4, 2003
922
923
}
}
Feb 14, 2004
Feb 14, 2004
924
925
926
927
928
929
930
931
932
else
{
SDL_SetError("ph_HWAccelBlit(): Source or target surface is not a hardware surface !\n");
return -1;
}
PgFlush();
PgWaitHWIdle();
Aug 4, 2003
Aug 4, 2003
933
return 0;
Apr 26, 2001
Apr 26, 2001
934
935
}
Feb 14, 2004
Feb 14, 2004
936
int ph_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
Apr 26, 2001
Apr 26, 2001
937
{
Feb 14, 2004
Feb 14, 2004
938
939
940
941
942
943
944
945
946
947
948
if (surface->hwdata!=NULL)
{
surface->hwdata->colorkey=ph_ExpandColor(this, surface, key);
if (surface->hwdata->colorkey==0xFFFFFFFFUL)
{
return -1;
}
}
PgSetChroma(surface->hwdata->colorkey, Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
return 0;
Apr 26, 2001
Apr 26, 2001
949
950
}
Feb 14, 2004
Feb 14, 2004
951
int ph_SetHWAlpha(_THIS, SDL_Surface* surface, Uint8 alpha)
Apr 26, 2001
Apr 26, 2001
952
{
Feb 14, 2004
Feb 14, 2004
953
return -1;
Apr 26, 2001
Apr 26, 2001
954
955
}
Aug 30, 2003
Aug 30, 2003
956
#ifdef HAVE_OPENGL
Mar 2, 2002
Mar 2, 2002
957
958
959
960
961
962
void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
{
this->GL_SwapBuffers(this);
return;
}
Aug 30, 2003
Aug 30, 2003
963
#endif /* HAVE_OPENGL */
Mar 2, 2002
Mar 2, 2002
964
Apr 26, 2001
Apr 26, 2001
965
966
void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
{
May 28, 2002
May 28, 2002
967
968
969
970
971
PhPoint_t ph_pos;
PhRect_t ph_rect;
int i;
for (i=0; i<numrects; ++i)
Mar 23, 2002
Mar 23, 2002
972
{
Feb 14, 2004
Feb 14, 2004
973
if (rects[i].w==0) /* Clipped? dunno why but this occurs sometime. */
Mar 23, 2002
Mar 23, 2002
974
975
{
continue;
Apr 26, 2001
Apr 26, 2001
976
977
}
Feb 14, 2004
Feb 14, 2004
978
if (rects[i].h==0) /* Clipped? dunno why but this occurs sometime. */
Aug 4, 2003
Aug 4, 2003
979
980
981
982
{
continue;
}
Mar 23, 2002
Mar 23, 2002
983
984
985
986
987
988
989
990
991
ph_pos.x = rects[i].x;
ph_pos.y = rects[i].y;
ph_rect.ul.x = rects[i].x;
ph_rect.ul.y = rects[i].y;
ph_rect.lr.x = rects[i].x + rects[i].w;
ph_rect.lr.y = rects[i].y + rects[i].h;
if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
{
Feb 14, 2004
Feb 14, 2004
992
993
SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed!\n");
return;
Mar 23, 2002
Mar 23, 2002
994
995
}
}
Apr 26, 2001
Apr 26, 2001
996
997
if (PgFlush() < 0)
Jan 18, 2002
Jan 18, 2002
998
{
Feb 14, 2004
Feb 14, 2004
999
SDL_SetError("ph_NormalUpdate(): PgFlush() function failed!\n");
Apr 26, 2001
Apr 26, 2001
1000
}