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

Latest commit

 

History

History
1029 lines (875 loc) · 27.4 KB

SDL_ph_image.c

File metadata and controls

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