comparison src/video/photon/SDL_ph_image.c @ 571:8e3ce997621c

Date: Thu, 16 Jan 2003 13:48:31 +0200 From: "Mike Gorchak" Subject: All QNX patches whole patches concerning QNX. Almost all code has been rewritten by Julian and me. Added initial support for hw overlays in QNX and many many others fixes. P.S. This patches has been reviewed by Dave Rempel from QSSL and included in SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1 version of QNX, which will be available soon.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Jan 2003 01:38:37 +0000
parents bce7171e7a85
children 8bedd6d61642
comparison
equal deleted inserted replaced
570:04d6411da49d 571:8e3ce997621c
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <Ph.h> 29 #include <Ph.h>
30 #include <photon/Pg.h> 30 #include <photon/Pg.h>
31 31
32 #include "SDL.h"
32 #include "SDL_error.h" 33 #include "SDL_error.h"
33 #include "SDL_endian.h" 34 #include "SDL_endian.h"
35 #include "SDL_video.h"
36 #include "SDL_pixels_c.h"
34 #include "SDL_ph_image_c.h" 37 #include "SDL_ph_image_c.h"
35 38
36 /* remove this line, if photon headers updates */ 39 /* Mask values for SDL_ReallocFormat() */
37 int PgWaitHWIdle(void); 40 struct ColourMasks
41 {
42 Uint32 red;
43 Uint32 green;
44 Uint32 blue;
45 Uint32 alpha;
46 Uint32 bpp;
47 };
48
49 static const struct ColourMasks *ph_GetColourMasks( int format )
50 {
51 /* The alpha mask doesn't appear to be needed */
52 static const struct ColourMasks phColorMasks[5] = {
53 /* 8 bit */ {0, 0, 0, 0, 8},
54 /* 15 bit ARGB */ {0x7C00, 0x03E0, 0x001F, 0x8000, 16},
55 /* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16},
56 /* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
57 /* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
58 };
59
60 switch( format )
61 {
62 case Pg_IMAGE_PALETTE_BYTE:
63 return &phColorMasks[0];
64 break;
65 case Pg_IMAGE_DIRECT_1555:
66 case Pg_IMAGE_DIRECT_555:
67 return &phColorMasks[1];
68 break;
69 case Pg_IMAGE_DIRECT_565:
70 return &phColorMasks[2];
71 break;
72 case Pg_IMAGE_DIRECT_888:
73 return &phColorMasks[3];
74 break;
75 case Pg_IMAGE_DIRECT_8888:
76 return &phColorMasks[4];
77 break;
78 }
79 return NULL;
80 }
38 81
39 int ph_SetupImage(_THIS, SDL_Surface *screen) 82 int ph_SetupImage(_THIS, SDL_Surface *screen)
40 { 83 {
41 PgColor_t* palette=NULL; 84 PgColor_t* palette=NULL;
85 const struct ColourMasks* mask;
42 int type=0; 86 int type=0;
43 int bpp; 87 int bpp;
44 88
45 bpp=screen->format->BitsPerPixel; 89 bpp=screen->format->BitsPerPixel;
46 90
66 case 32:{ 110 case 32:{
67 type = Pg_IMAGE_DIRECT_8888; 111 type = Pg_IMAGE_DIRECT_8888;
68 } 112 }
69 break; 113 break;
70 default:{ 114 default:{
71 fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp); 115 fprintf(stderr,"ph_SetupImage(): unsupported bpp=%d !\n", bpp);
72 return -1; 116 return -1;
73 } 117 }
74 break; 118 break;
75 } 119 }
76 120
82 PgGetPalette(palette); 126 PgGetPalette(palette);
83 127
84 /* using shared memory for speed (set last param to 1) */ 128 /* using shared memory for speed (set last param to 1) */
85 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL) 129 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
86 { 130 {
87 fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n"); 131 fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8 !\n");
88 return -1; 132 return -1;
89 } 133 }
90 } 134 }
91 else 135 else
92 { 136 {
93 /* using shared memory for speed (set last param to 1) */ 137 /* using shared memory for speed (set last param to 1) */
94 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL) 138 if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
95 { 139 {
96 fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n"); 140 fprintf(stderr,"ph_SetupImage: PhCreateImage failed !\n");
97 return -1; 141 return -1;
98 } 142 }
99 } 143 }
100 144
101 screen->pixels = SDL_Image->image; 145 screen->pixels = SDL_Image->image;
102 screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */ 146 screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
103 147
148 mask = ph_GetColourMasks(type);
149 if (mask != NULL)
150 {
151 SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
152 }
153
104 this->UpdateRects = ph_NormalUpdate; 154 this->UpdateRects = ph_NormalUpdate;
105 155
106 return 0; 156 return 0;
107 } 157 }
108 158
109 int ph_SetupOCImage(_THIS, SDL_Surface *screen) 159 int ph_SetupOCImage(_THIS, SDL_Surface *screen)
110 { 160 {
161 const struct ColourMasks *mask;
111 int type = 0; 162 int type = 0;
112 int bpp; 163 int bpp;
164
165 screen->flags &= ~SDL_DOUBLEBUF;
166 OCImage.flags = screen->flags;
113 167
114 bpp=screen->format->BitsPerPixel; 168 bpp=screen->format->BitsPerPixel;
115 169
116 /* Determine image type */ 170 /* Determine image type */
117 switch(bpp) 171 switch(bpp)
135 case 32:{ 189 case 32:{
136 type = Pg_IMAGE_DIRECT_8888; 190 type = Pg_IMAGE_DIRECT_8888;
137 } 191 }
138 break; 192 break;
139 default:{ 193 default:{
140 fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp); 194 fprintf(stderr,"ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
141 return -1; 195 return -1;
142 } 196 }
143 break; 197 break;
144 } 198 }
145 199
146 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); 200 /* Currently only offscreen contexts with the same bit depth as the
147 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); 201 * display can be created. */
148 memset(OCImage.FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
149 memset(OCImage.FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
150
151 if(OCImage.direct_context == NULL)
152 {
153 OCImage.direct_context = PdCreateDirectContext();
154 }
155
156 OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN); 202 OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
157 203
158 if (OCImage.offscreen_context == NULL) 204 if (OCImage.offscreen_context == NULL)
159 { 205 {
160 fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n"); 206 fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n");
161 return -1; 207 return -1;
162 } 208 }
163 209
210 /* If the bit depth of the context is different than was requested,
211 * these values need to be updated accordingly. SDL will
212 * allocate a shadow surface if it needs to. */
213 mask = ph_GetColourMasks(OCImage.offscreen_context->format);
214 if (mask != NULL)
215 {
216 SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
217
218 if (mask->bpp > 8)
219 {
220 screen->flags &= ~SDL_HWPALETTE;
221 }
222 }
223
164 screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */ 224 screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
165
166 if (OCImage.flags & SDL_DOUBLEBUF)
167 {
168 fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n");
169 }
170 225
171 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); 226 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
172 227
173 if (OCImage.dc_ptr.ptr8 == NULL) 228 if (OCImage.dc_ptr.ptr8 == NULL)
174 { 229 {
175 fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n"); 230 fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
176 return -1; 231 return -1;
177 } 232 }
178 233
234 OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
179 OCImage.CurrentFrameData = OCImage.FrameData0; 235 OCImage.CurrentFrameData = OCImage.FrameData0;
180 OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8;
181 OCImage.CurrentFrameData->U = NULL;
182 OCImage.CurrentFrameData->V = NULL;
183 OCImage.current = 0; 236 OCImage.current = 0;
184 237
185 PhDCSetCurrent(OCImage.offscreen_context); 238 PhDCSetCurrent(OCImage.offscreen_context);
186 239
187 screen->pixels = OCImage.CurrentFrameData->Y; 240 screen->pixels = OCImage.CurrentFrameData;
188 241
189 this->UpdateRects = ph_OCUpdate; 242 this->UpdateRects = ph_OCUpdate;
190 243
191 return 0; 244 return 0;
192 } 245 }
196 this->UpdateRects = ph_OpenGLUpdate; 249 this->UpdateRects = ph_OpenGLUpdate;
197 250
198 return 0; 251 return 0;
199 } 252 }
200 253
254 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
255 {
256 const struct ColourMasks *mask;
257 screen->flags &= ~SDL_DOUBLEBUF;
258 OCImage.flags = screen->flags;
259
260 OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
261
262 if (OCImage.offscreen_context == NULL)
263 {
264 fprintf(stderr, "ph_SetupFullScreenImage(): PdCreateOffscreenContext failed !\n");
265 return -1;
266 }
267
268 /* If the bit depth of the context is different than was requested,
269 * these values need to be updated accordingly. SDL will
270 * allocate a shadow surface if it needs to. */
271 mask = ph_GetColourMasks(OCImage.offscreen_context->format);
272 if (mask != NULL)
273 {
274 SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
275
276 if (mask->bpp > 8)
277 {
278 screen->flags &= ~SDL_HWPALETTE;
279 }
280 }
281
282 screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
283
284 OCImage.dc_ptr.ptr8 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
285
286 if (OCImage.dc_ptr.ptr8 == NULL)
287 {
288 fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
289 return -1;
290 }
291
292 /* wait for hw */
293 PgWaitHWIdle();
294
295 OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
296 OCImage.CurrentFrameData = OCImage.FrameData0;
297 OCImage.current = 0;
298
299 PhDCSetCurrent(OCImage.offscreen_context);
300
301 screen->pixels = OCImage.CurrentFrameData;
302
303 this->UpdateRects = ph_OCUpdate;
304
305 return 0;
306 }
307
201 void ph_DestroyImage(_THIS, SDL_Surface *screen) 308 void ph_DestroyImage(_THIS, SDL_Surface *screen)
202 { 309 {
203 if (OCImage.offscreen_context != NULL) 310 if (OCImage.offscreen_context != NULL)
204 { 311 {
205 PhDCRelease(OCImage.offscreen_context); 312 PhDCRelease(OCImage.offscreen_context);
206 OCImage.offscreen_context = NULL; 313 OCImage.offscreen_context = NULL;
207 free(OCImage.FrameData0);
208 OCImage.FrameData0 = NULL; 314 OCImage.FrameData0 = NULL;
209 free(OCImage.FrameData1);
210 OCImage.FrameData1 = NULL; 315 OCImage.FrameData1 = NULL;
211 } 316 }
212 317
213 if (SDL_Image) 318 if (SDL_Image)
214 { 319 {
228 { 333 {
229 screen->pixels = NULL; 334 screen->pixels = NULL;
230 } 335 }
231 } 336 }
232 337
233 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) 338 int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags)
234 { 339 {
235 ph_DestroyImage(this, screen); 340 ph_DestroyImage(this, screen);
236 341
237 if (flags & SDL_HWSURFACE) 342 if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
238 { 343 {
239 OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */ 344 return ph_SetupFullScreenImage(this, screen);
345 }
346 if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
347 {
240 return ph_SetupOCImage(this, screen); 348 return ph_SetupOCImage(this, screen);
241 } 349 }
242 else if (flags & SDL_OPENGL) 350 if ((flags & SDL_OPENGL)==SDL_OPENGL)
243 { 351 {
244 return ph_SetupOpenGLImage(this, screen); 352 return ph_SetupOpenGLImage(this, screen);
245 } 353 }
246 else 354
247 { 355 return ph_SetupImage(this, screen);
248 return ph_SetupImage(this, screen);
249 }
250 } 356 }
251 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) 357 int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
252 { 358 {
253 return(-1); 359 return(-1);
254 } 360 }
263 return(0); 369 return(0);
264 } 370 }
265 371
266 int ph_LockHWSurface(_THIS, SDL_Surface *surface) 372 int ph_LockHWSurface(_THIS, SDL_Surface *surface)
267 { 373 {
268 if ((surface == SDL_VideoSurface) && blit_queued) {
269 PgFlush();
270 blit_queued = 0;
271 }
272
273 return(0); 374 return(0);
274 } 375 }
275 376
276 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) 377 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
277 { 378 {
305 ph_rect.lr.x = rects[i].x + rects[i].w; 406 ph_rect.lr.x = rects[i].x + rects[i].w;
306 ph_rect.lr.y = rects[i].y + rects[i].h; 407 ph_rect.lr.y = rects[i].y + rects[i].h;
307 408
308 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0) 409 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
309 { 410 {
310 fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed.\n"); 411 fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
311 } 412 }
312 } 413 }
313 414
314 if (PgFlush() < 0) 415 if (PgFlush() < 0)
315 { 416 {
322 int i; 423 int i;
323 424
324 PhPoint_t zero = {0}; 425 PhPoint_t zero = {0};
325 PhArea_t src_rect; 426 PhArea_t src_rect;
326 PhArea_t dest_rect; 427 PhArea_t dest_rect;
327
328 if(OCImage.direct_context == NULL)
329 {
330 return;
331 }
332 428
333 PgSetRegion(PtWidgetRid(window)); 429 PgSetRegion(PtWidgetRid(window));
334 PgSetClipping(0, NULL); 430 PgSetClipping(0, NULL);
335 PgWaitHWIdle(); 431 PgWaitHWIdle();
336 432