This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_ph_image.c
1034 lines (880 loc) · 27.7 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
#include "SDL_config.h"
23
24
25
26
27
#include <Ph.h>
#include <photon/Pg.h>
#include "SDL_endian.h"
28
#include "SDL_video.h"
29
#include "../SDL_pixels_c.h"
30
#include "SDL_ph_video.h"
31
#include "SDL_ph_image_c.h"
32
#include "SDL_ph_modes_c.h"
33
#include "SDL_ph_gl.h"
34
35
36
int
ph_SetupImage (_THIS, SDL_Surface * screen)
37
{
38
39
PgColor_t *palette = NULL;
int type = 0;
40
int bpp;
41
42
bpp = screen->format->BitsPerPixel;
43
44
/* Determine image type */
45
46
47
switch (bpp) {
case 8:
{
48
49
50
type = Pg_IMAGE_PALETTE_BYTE;
}
break;
51
52
53
case 15:
{
type = Pg_IMAGE_DIRECT_555;
54
55
}
break;
56
57
58
case 16:
{
type = Pg_IMAGE_DIRECT_565;
59
60
}
break;
61
62
case 24:
{
63
64
65
type = Pg_IMAGE_DIRECT_888;
}
break;
66
67
case 32:
{
68
69
70
type = Pg_IMAGE_DIRECT_8888;
}
break;
71
72
73
default:
{
SDL_SetError ("ph_SetupImage(): unsupported bpp=%d !\n", bpp);
74
75
76
77
return -1;
}
break;
}
78
79
/* palette emulation code */
80
if ((bpp == 8) && (desktoppal == SDLPH_PAL_EMULATE)) {
81
/* creating image palette */
82
83
84
85
palette = SDL_malloc (_Pg_MAX_PALETTE * sizeof (PgColor_t));
if (palette == NULL) {
SDL_SetError
("ph_SetupImage(): can't allocate memory for palette !\n");
86
87
return -1;
}
88
PgGetPalette (palette);
89
90
/* using shared memory for speed (set last param to 1) */
91
92
93
94
95
96
if ((SDL_Image =
PhCreateImage (NULL, screen->w, screen->h, type, palette,
_Pg_MAX_PALETTE, 1)) == NULL) {
SDL_SetError
("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
SDL_free (palette);
97
98
return -1;
}
99
} else {
100
/* using shared memory for speed (set last param to 1) */
101
102
103
104
105
106
if ((SDL_Image =
PhCreateImage (NULL, screen->w, screen->h, type, NULL, 0,
1)) == NULL) {
SDL_SetError
("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n",
bpp);
107
108
return -1;
}
109
}
110
111
screen->pixels = SDL_Image->image;
112
screen->pitch = SDL_Image->bpl;
113
114
this->UpdateRects = ph_NormalUpdate;
115
116
return 0;
117
118
}
119
120
int
ph_SetupOCImage (_THIS, SDL_Surface * screen)
121
{
122
int type = 0;
123
int bpp;
124
125
OCImage.flags = screen->flags;
126
127
bpp = screen->format->BitsPerPixel;
128
129
/* Determine image type */
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
switch (bpp) {
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:
{
SDL_SetError ("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
return -1;
}
break;
162
}
163
164
/* Currently offscreen contexts with the same bit depth as display bpp only can be created */
165
166
167
OCImage.offscreen_context =
PdCreateOffscreenContext (0, screen->w, screen->h,
Pg_OSC_MEM_PAGE_ALIGN);
168
169
170
171
if (OCImage.offscreen_context == NULL) {
SDL_SetError
("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n");
172
173
174
return -1;
}
175
screen->pitch = OCImage.offscreen_context->pitch;
176
177
178
179
OCImage.dc_ptr =
(unsigned char *) PdGetOffscreenContextPtr (OCImage.
offscreen_context);
180
181
182
183
184
if (OCImage.dc_ptr == NULL) {
SDL_SetError
("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n");
PhDCRelease (OCImage.offscreen_context);
185
186
187
return -1;
}
188
OCImage.FrameData0 = OCImage.dc_ptr;
189
190
191
OCImage.CurrentFrameData = OCImage.FrameData0;
OCImage.current = 0;
192
PhDCSetCurrent (OCImage.offscreen_context);
193
194
screen->pixels = OCImage.CurrentFrameData;
195
196
197
198
this->UpdateRects = ph_OCUpdate;
return 0;
199
200
}
201
202
int
ph_SetupFullScreenImage (_THIS, SDL_Surface * screen)
203
204
205
{
OCImage.flags = screen->flags;
206
/* Begin direct and fullscreen mode */
207
if (!ph_EnterFullScreen (this, screen, PH_ENTER_DIRECTMODE)) {
208
209
210
return -1;
}
211
/* store palette for fullscreen */
212
213
214
215
216
217
218
219
220
221
222
223
if ((screen->format->BitsPerPixel == 8) && (desktopbpp != 8)) {
PgGetPalette (savedpal);
PgGetPalette (syspalph);
}
OCImage.offscreen_context =
PdCreateOffscreenContext (0, 0, 0,
Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN
| Pg_OSC_CRTC_SAFE);
if (OCImage.offscreen_context == NULL) {
SDL_SetError
("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
224
225
return -1;
}
226
227
228
229
230
231
232
233
if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
OCImage.offscreen_backcontext =
PdDupOffscreenContext (OCImage.offscreen_context,
Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
if (OCImage.offscreen_backcontext == NULL) {
SDL_SetError
("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
234
return -1;
235
236
237
}
}
238
239
240
241
242
243
244
OCImage.FrameData0 =
(unsigned char *) PdGetOffscreenContextPtr (OCImage.
offscreen_context);
if (OCImage.FrameData0 == NULL) {
SDL_SetError
("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n");
ph_DestroyImage (this, screen);
245
246
247
return -1;
}
248
249
250
251
252
253
254
255
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);
256
257
258
return -1;
}
}
259
260
/* wait for the hardware */
261
262
PgFlush ();
PgWaitHWIdle ();
263
264
if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
265
OCImage.current = 0;
266
PhDCSetCurrent (OCImage.offscreen_context);
267
268
screen->pitch = OCImage.offscreen_context->pitch;
screen->pixels = OCImage.FrameData0;
269
270
/* emulate 640x400 videomode */
271
272
273
274
275
276
277
278
279
280
281
282
if (videomode_emulatemode == 1) {
int i;
for (i = 0; i < 40; i++) {
SDL_memset (screen->pixels + screen->pitch * i, 0x00,
screen->pitch);
}
for (i = 440; i < 480; i++) {
SDL_memset (screen->pixels + screen->pitch * i, 0x00,
screen->pitch);
}
screen->pixels += screen->pitch * 40;
283
}
284
285
PgSwapDisplay (OCImage.offscreen_backcontext, 0);
} else {
286
OCImage.current = 0;
287
PhDCSetCurrent (OCImage.offscreen_context);
288
289
screen->pitch = OCImage.offscreen_context->pitch;
screen->pixels = OCImage.FrameData0;
290
291
/* emulate 640x400 videomode */
292
293
294
295
296
297
298
299
300
301
302
303
if (videomode_emulatemode == 1) {
int i;
for (i = 0; i < 40; i++) {
SDL_memset (screen->pixels + screen->pitch * i, 0x00,
screen->pitch);
}
for (i = 440; i < 480; i++) {
SDL_memset (screen->pixels + screen->pitch * i, 0x00,
screen->pitch);
}
screen->pixels += screen->pitch * 40;
304
}
305
}
306
307
this->UpdateRects = ph_OCDCUpdate;
308
309
/* wait for the hardware */
310
311
PgFlush ();
PgWaitHWIdle ();
312
313
314
315
return 0;
}
316
#if SDL_VIDEO_OPENGL
317
318
319
int
ph_SetupOpenGLImage (_THIS, SDL_Surface * screen)
320
{
321
this->UpdateRects = ph_OpenGLUpdate;
322
323
screen->pixels = NULL;
screen->pitch = NULL;
324
325
326
327
328
329
#if (_NTO_VERSION >= 630)
if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
if (!ph_EnterFullScreen (this, screen, PH_IGNORE_DIRECTMODE)) {
screen->flags &= ~SDL_FULLSCREEN;
return -1;
330
}
331
332
}
#endif /* 6.3.0 */
333
334
335
336
if (ph_SetupOpenGLContext
(this, screen->w, screen->h, screen->format->BitsPerPixel,
screen->flags) != 0) {
337
screen->flags &= ~SDL_INTERNALOPENGL;
338
return -1;
339
}
340
341
return 0;
342
343
}
344
#endif /* SDL_VIDEO_OPENGL */
345
346
347
void
ph_DestroyImage (_THIS, SDL_Surface * screen)
348
349
{
350
#if SDL_VIDEO_OPENGL
351
352
353
354
355
356
357
358
359
360
361
362
363
364
if (screen->flags & SDL_INTERNALOPENGL) {
if (oglctx) {
#if (_NTO_VERSION < 630)
PhDCSetCurrent (NULL);
PhDCRelease (oglctx);
#else
qnxgl_context_destroy (oglctx);
qnxgl_buffers_destroy (oglbuffers);
qnxgl_finish ();
#endif /* 6.3.0 */
oglctx = NULL;
oglbuffers = NULL;
oglflags = 0;
oglbpp = 0;
365
}
366
367
368
369
370
#if (_NTO_VERSION >= 630)
if (currently_fullscreen) {
ph_LeaveFullScreen (this);
}
#endif /* 6.3.0 */
371
372
373
return;
}
374
#endif /* SDL_VIDEO_OPENGL */
375
376
if (currently_fullscreen) {
377
/* if we right now in 8bpp fullscreen we must release palette */
378
379
380
381
382
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 ();
383
}
384
ph_LeaveFullScreen (this);
385
386
}
387
388
if (OCImage.offscreen_context != NULL) {
PhDCRelease (OCImage.offscreen_context);
389
390
OCImage.offscreen_context = NULL;
OCImage.FrameData0 = NULL;
391
}
392
393
if (OCImage.offscreen_backcontext != NULL) {
PhDCRelease (OCImage.offscreen_backcontext);
394
OCImage.offscreen_backcontext = NULL;
395
396
OCImage.FrameData1 = NULL;
}
397
OCImage.CurrentFrameData = NULL;
398
399
if (SDL_Image) {
400
/* if palette allocated, free it */
401
402
if (SDL_Image->palette) {
SDL_free (SDL_Image->palette);
403
}
404
405
PgShmemDestroy (SDL_Image->image);
SDL_free (SDL_Image);
406
}
407
408
409
410
/* Must be zeroed everytime */
SDL_Image = NULL;
411
if (screen) {
412
413
screen->pixels = NULL;
}
414
415
}
416
417
int
ph_UpdateHWInfo (_THIS)
418
419
420
421
422
{
PgVideoModeInfo_t vmode;
PgHWCaps_t hwcaps;
/* Update video ram amount */
423
424
425
if (PgGetGraphicsHWCaps (&hwcaps) < 0) {
SDL_SetError
("ph_UpdateHWInfo(): GetGraphicsHWCaps() function failed !\n");
426
427
return -1;
}
428
this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
429
430
/* obtain current mode capabilities */
431
432
433
if (PgGetVideoModeInfo (hwcaps.current_video_mode, &vmode) < 0) {
SDL_SetError
("ph_UpdateHWInfo(): GetVideoModeInfo() function failed !\n");
434
435
436
return -1;
}
437
438
if ((vmode.mode_capabilities1 & PgVM_MODE_CAP1_OFFSCREEN) ==
PgVM_MODE_CAP1_OFFSCREEN) {
439
/* this is a special test for drivers which tries to lie about offscreen capability */
440
441
442
443
if (hwcaps.currently_available_video_ram != 0) {
this->info.hw_available = 1;
} else {
this->info.hw_available = 0;
444
}
445
} else {
446
447
448
this->info.hw_available = 0;
}
449
450
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_RECTANGLE) ==
PgVM_MODE_CAP2_RECTANGLE) {
451
this->info.blit_fill = 1;
452
} else {
453
454
455
this->info.blit_fill = 0;
}
456
457
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_BITBLT) ==
PgVM_MODE_CAP2_BITBLT) {
458
this->info.blit_hw = 1;
459
} else {
460
461
this->info.blit_hw = 0;
}
462
463
464
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND) ==
PgVM_MODE_CAP2_ALPHA_BLEND) {
465
this->info.blit_hw_A = 1;
466
} else {
467
this->info.blit_hw_A = 0;
468
}
469
470
471
if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_CHROMA) ==
PgVM_MODE_CAP2_CHROMA) {
472
this->info.blit_hw_CC = 1;
473
} else {
474
this->info.blit_hw_CC = 0;
475
}
476
477
478
479
return 0;
}
480
481
int
ph_SetupUpdateFunction (_THIS, SDL_Surface * screen, Uint32 flags)
482
{
483
484
485
int setupresult = -1;
ph_DestroyImage (this, screen);
486
487
#if SDL_VIDEO_OPENGL
488
489
490
if (flags & SDL_INTERNALOPENGL) {
setupresult = ph_SetupOpenGLImage (this, screen);
} else {
491
#endif
492
493
494
495
496
497
498
499
500
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);
}
}
501
#if SDL_VIDEO_OPENGL
502
}
503
#endif
504
505
if (setupresult != -1) {
ph_UpdateHWInfo (this);
506
}
507
508
return setupresult;
509
}
510
511
512
int
ph_AllocHWSurface (_THIS, SDL_Surface * surface)
513
{
514
515
PgHWCaps_t hwcaps;
516
517
518
if (surface->hwdata != NULL) {
SDL_SetError ("ph_AllocHWSurface(): hwdata already exists!\n");
return -1;
519
}
520
521
522
523
524
525
526
527
surface->hwdata = SDL_malloc (sizeof (struct private_hwdata));
SDL_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");
528
529
return -1;
}
530
531
532
533
534
535
surface->pixels =
PdGetOffscreenContextPtr (surface->hwdata->offscreenctx);
if (surface->pixels == NULL) {
PhDCRelease (surface->hwdata->offscreenctx);
SDL_SetError
("ph_AllocHWSurface(): PdGetOffscreenContextPtr() function failed !\n");
536
537
return -1;
}
538
539
540
541
542
surface->pitch = surface->hwdata->offscreenctx->pitch;
surface->flags |= SDL_HWSURFACE;
surface->flags |= SDL_PREALLOC;
#if 0 /* FIXME */
543
/* create simple offscreen lock */
544
545
546
surface->hwdata->crlockparam.flags = 0;
if (PdCreateOffscreenLock
(surface->hwdata->offscreenctx, &surface->hwdata->crlockparam) != EOK)
547
{
548
549
PhDCRelease (surface->hwdata->offscreenctx);
SDL_SetError ("ph_AllocHWSurface(): Can't create offscreen lock !\n");
550
551
552
553
554
return -1;
}
#endif /* 0 */
/* Update video ram amount */
555
556
557
558
559
if (PgGetGraphicsHWCaps (&hwcaps) < 0) {
PdDestroyOffscreenLock (surface->hwdata->offscreenctx);
PhDCRelease (surface->hwdata->offscreenctx);
SDL_SetError
("ph_AllocHWSurface(): GetGraphicsHWCaps() function failed !\n");
560
561
return -1;
}
562
this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
563
564
return 0;
565
566
}
567
568
void
ph_FreeHWSurface (_THIS, SDL_Surface * surface)
569
{
570
571
PgHWCaps_t hwcaps;
572
573
574
if (surface->hwdata == NULL) {
SDL_SetError ("ph_FreeHWSurface(): no hwdata!\n");
return;
575
}
576
577
578
579
if (surface->hwdata->offscreenctx == NULL) {
SDL_SetError
("ph_FreeHWSurface(): no offscreen context to delete!\n");
return;
580
}
581
#if 0 /* FIXME */
582
/* unlock the offscreen context if it has been locked before destroy it */
583
584
if (PdIsOffscreenLocked (surface->hwdata->offscreenctx) == Pg_OSC_LOCKED) {
PdUnlockOffscreen (surface->hwdata->offscreenctx);
585
586
}
587
PdDestroyOffscreenLock (surface->hwdata->offscreenctx);
588
589
#endif /* 0 */
590
591
592
593
PhDCRelease (surface->hwdata->offscreenctx);
SDL_free (surface->hwdata);
surface->hwdata = NULL;
594
595
/* Update video ram amount */
596
597
598
if (PgGetGraphicsHWCaps (&hwcaps) < 0) {
SDL_SetError
("ph_FreeHWSurface(): GetGraphicsHWCaps() function failed !\n");
599
600
return;
}
601
this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
602
603
return;
604
605
}
606
607
int
ph_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst)
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
638
639
640
641
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;
642
643
}
644
645
PgColor_t
ph_ExpandColor (_THIS, SDL_Surface * surface, Uint32 color)
646
647
648
649
{
Uint32 truecolor;
/* Photon API accepts true colors only during hw filling operations */
650
651
652
653
654
655
656
657
658
659
660
661
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");
662
663
return 0xFFFFFFFFUL;
}
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
}
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;
}
703
704
705
706
707
}
return truecolor;
}
708
709
int
ph_FillHWRect (_THIS, SDL_Surface * surface, SDL_Rect * rect, Uint32 color)
710
711
712
{
PgColor_t oldcolor;
Uint32 truecolor;
713
int ydisp = 0;
714
715
716
if (this->info.blit_fill != 1) {
return -1;
717
718
}
719
720
truecolor = ph_ExpandColor (this, surface, color);
if (truecolor == 0xFFFFFFFFUL) {
721
722
723
return -1;
}
724
oldcolor = PgSetFillColor (truecolor);
725
726
/* 640x400 videomode emulation */
727
728
if (videomode_emulatemode == 1) {
ydisp += 40;
729
730
}
731
732
733
734
735
PgDrawIRect (rect->x, rect->y + ydisp, rect->w + rect->x - 1,
rect->h + rect->y + ydisp - 1, Pg_DRAW_FILL);
PgSetFillColor (oldcolor);
PgFlush ();
PgWaitHWIdle ();
736
737
738
739
return 0;
}
740
741
int
ph_FlipHWSurface (_THIS, SDL_Surface * screen)
742
{
743
744
PhArea_t farea;
745
if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
746
/* flush all drawing ops before blitting */
747
748
PgFlush ();
PgWaitHWIdle ();
749
750
751
752
753
farea.pos.x = 0;
farea.pos.y = 0;
farea.size.w = screen->w;
farea.size.h = screen->h;
754
755
/* emulate 640x400 videomode */
756
757
if (videomode_emulatemode == 1) {
farea.pos.y += 40;
758
759
}
760
761
PgContextBlitArea (OCImage.offscreen_context, &farea,
OCImage.offscreen_backcontext, &farea);
762
763
/* flush the blitting */
764
765
PgFlush ();
PgWaitHWIdle ();
766
767
768
769
}
return 0;
}
770
771
int
ph_LockHWSurface (_THIS, SDL_Surface * surface)
772
773
{
774
#if 0 /* FIXME */
775
776
int lockresult;
777
if (surface->hwdata == NULL) {
778
779
780
return;
}
781
782
783
784
785
surface->hwdata->lockparam.flags = 0;
surface->hwdata->lockparam.time_out = NULL;
lockresult =
PdLockOffscreen (surface->hwdata->offscreenctx,
&surface->hwdata->lockparam);
786
787
788
789
790
791
792
793
794
795
796
797
798
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;
799
800
801
802
803
804
}
#endif /* 0 */
return 0;
}
805
806
void
ph_UnlockHWSurface (_THIS, SDL_Surface * surface)
807
808
{
809
#if 0 /* FIXME */
810
811
int unlockresult;
812
if ((surface == NULL) || (surface->hwdata == NULL)) {
813
814
815
return;
}
816
817
if (PdIsOffscreenLocked (surface->hwdata->offscreenctx) == Pg_OSC_LOCKED) {
unlockresult = PdUnlockOffscreen (surface->hwdata->offscreenctx);
818
819
820
821
822
823
}
#endif /* 0 */
return;
}
824
825
826
int
ph_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst,
SDL_Rect * dstrect)
827
{
828
SDL_VideoDevice *this = current_video;
829
830
PhArea_t srcarea;
PhArea_t dstarea;
831
int ydisp = 0;
832
833
/* 640x400 videomode emulation */
834
835
if (videomode_emulatemode == 1) {
ydisp += 40;
836
837
}
838
839
840
841
srcarea.pos.x = srcrect->x;
srcarea.pos.y = srcrect->y;
srcarea.size.w = srcrect->w;
srcarea.size.h = srcrect->h;
842
843
844
845
846
dstarea.pos.x = dstrect->x;
dstarea.pos.y = dstrect->y;
dstarea.size.w = dstrect->w;
dstarea.size.h = dstrect->h;
847
848
849
850
851
852
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 ();
853
854
}
855
856
857
if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
ph_SetHWAlpha (this, src, src->format->alpha);
PgAlphaOn ();
858
859
}
860
861
if (dst == this->screen) {
if (src == this->screen) {
862
/* blitting from main screen to main screen */
863
864
865
866
867
dstarea.pos.y += ydisp;
srcarea.pos.y += ydisp;
PgContextBlitArea (OCImage.offscreen_context, &srcarea,
OCImage.offscreen_context, &dstarea);
} else {
868
/* blitting from offscreen to main screen */
869
870
871
dstarea.pos.y += ydisp;
PgContextBlitArea (src->hwdata->offscreenctx, &srcarea,
OCImage.offscreen_context, &dstarea);
872
}
873
874
} else {
if (src == this->screen) {
875
/* blitting from main screen to offscreen */
876
877
878
879
srcarea.pos.y += ydisp;
PgContextBlitArea (OCImage.offscreen_context, &srcarea,
dst->hwdata->offscreenctx, &dstarea);
} else {
880
/* blitting offscreen to offscreen */
881
882
PgContextBlitArea (src->hwdata->offscreenctx, &srcarea,
dst->hwdata->offscreenctx, &dstarea);
883
884
885
}
}
886
887
if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
PgAlphaOff ();
888
889
}
890
891
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
PgChromaOff ();
892
}
893
894
895
} else {
SDL_SetError
("ph_HWAccelBlit(): Source or target surface is not a hardware surface !\n");
896
897
898
return -1;
}
899
900
PgFlush ();
PgWaitHWIdle ();
901
902
return 0;
903
904
}
905
906
int
ph_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key)
907
{
908
909
if (this->info.blit_hw_CC != 1) {
return -1;
910
911
}
912
913
914
if (surface->hwdata != NULL) {
surface->hwdata->colorkey = ph_ExpandColor (this, surface, key);
if (surface->hwdata->colorkey == 0xFFFFFFFFUL) {
915
916
917
return -1;
}
}
918
919
PgSetChroma (surface->hwdata->colorkey,
Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
920
921
return 0;
922
923
}
924
925
int
ph_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha)
926
{
927
928
if (this->info.blit_hw_A != 1) {
return -1;
929
930
}
931
PgSetAlphaBlend (NULL, alpha);
932
933
return 0;
934
935
}
936
#if SDL_VIDEO_OPENGL
937
938
void
ph_OpenGLUpdate (_THIS, int numrects, SDL_Rect * rects)
939
{
940
941
942
this->GL_SwapBuffers (this);
return;
943
}
944
#endif /* SDL_VIDEO_OPENGL */
945
946
947
void
ph_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
948
{
949
950
951
952
PhPoint_t ph_pos;
PhRect_t ph_rect;
int i;
953
954
for (i = 0; i < numrects; ++i) {
if (rects[i].w == 0) { /* Clipped? dunno why but this occurs sometime. */
955
continue;
956
957
}
958
if (rects[i].h == 0) { /* Clipped? dunno why but this occurs sometime. */
959
960
961
continue;
}
962
963
964
965
966
967
968
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;
969
970
if (PgDrawPhImageRectmx (&ph_pos, SDL_Image, &ph_rect, 0) < 0) {
SDL_SetError ("ph_NormalUpdate(): PgDrawPhImageRectmx failed!\n");
971
return;
972
973
}
}
974
975
976
if (PgFlush () < 0) {
SDL_SetError ("ph_NormalUpdate(): PgFlush() function failed!\n");
977
978
}
}
979
980
981
void
ph_OCUpdate (_THIS, int numrects, SDL_Rect * rects)
982
{
983
984
int i;
985
PhPoint_t zero = { 0, 0 };
986
987
PhArea_t src_rect;
PhArea_t dest_rect;
988
989
990
991
PgSetTranslation (&zero, 0);
PgSetRegion (PtWidgetRid (window));
PgSetClipping (0, NULL);
992
993
994
PgFlush ();
PgWaitHWIdle ();
995
996
997
for (i = 0; i < numrects; ++i) {
if (rects[i].w == 0) { /* Clipped? */
998
continue;
999
1000
}