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