comparison src/video/photon/SDL_ph_image.c @ 370:ba72f259bc88

Date: Sat, 18 May 2002 17:40:53 +0300 From: Mike Gorchak <mike@malva.ua> Subject: New QNX patches - Added more error check to avoid SEGFAULTS; - Fixed bug in update function for SDL_HWSURFACE. BTW: update is much faster than before. - Added checks for SDL_HWSURFACE flag, chosen bpp must be equal to desktop bpp for SDL_HWSURFACE. - Fixed overlay bug, no more SEGFAULTS.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 19 May 2002 19:54:01 +0000
parents 3333b6e68289
children bce7171e7a85
comparison
equal deleted inserted replaced
369:e405cf8bf580 370:ba72f259bc88
63 case 32:{ 63 case 32:{
64 type = Pg_IMAGE_DIRECT_8888; 64 type = Pg_IMAGE_DIRECT_8888;
65 } 65 }
66 break; 66 break;
67 default:{ 67 default:{
68 /* should never get here */ 68 fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", screen->format->BitsPerPixel);
69 fprintf(stderr,"error: unsupported bbp = %d\n",
70 screen->format->BitsPerPixel);
71 return -1; 69 return -1;
72 } 70 }
73 break; 71 break;
74 } 72 }
75 73
104 return 0; 102 return 0;
105 } 103 }
106 104
107 int ph_SetupOCImage(_THIS, SDL_Surface *screen) 105 int ph_SetupOCImage(_THIS, SDL_Surface *screen)
108 { 106 {
109 int type = 0; 107 int type = 0;
110 108
111 /* Determine image type */ 109 /* Determine image type */
112 switch(screen->format->BitsPerPixel) 110 switch(screen->format->BitsPerPixel)
113 { 111 {
114 case 8:{ 112 case 8: {
115 type = Pg_IMAGE_PALETTE_BYTE; 113 type = Pg_IMAGE_PALETTE_BYTE;
114 }
115 break;
116 case 15:{
117 type = Pg_IMAGE_DIRECT_555;
116 } 118 }
117 break; 119 break;
118 case 15:{ 120 case 16:{
119 type = Pg_IMAGE_DIRECT_555; 121 type = Pg_IMAGE_DIRECT_565;
120 } 122 }
121 break; 123 break;
122 case 16:{ 124 case 24:{
123 type = Pg_IMAGE_DIRECT_565; 125 type = Pg_IMAGE_DIRECT_888;
124 } 126 }
125 break; 127 break;
126 128 case 32:{
127 case 24:{ 129 type = Pg_IMAGE_DIRECT_8888;
128 type = Pg_IMAGE_DIRECT_888; 130 }
129 } 131 break;
130 break; 132 default:{
131 133 fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", screen->format->BitsPerPixel);
132 case 32:{ 134 return -1;
133 type = Pg_IMAGE_DIRECT_8888; 135 }
134 } 136 break;
135 break; 137 }
136 default:{ 138
137 /* should never get here */ 139 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
138 fprintf(stderr,"error: unsupported bbp = %d\n", 140 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
139 screen->format->BitsPerPixel); 141
140 return -1; 142 if(OCImage.direct_context == NULL)
141 } 143 {
142 break; 144 OCImage.direct_context = PdCreateDirectContext();
143 } 145 }
144 146
145 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); 147 OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
146 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); 148
147 149 if (OCImage.offscreen_context == NULL)
148 if(OCImage.direct_context == NULL) 150 {
149 OCImage.direct_context = PdCreateDirectContext(); 151 fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n");
150 152 return -1;
151 OCImage.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN); 153 }
152 154
153 if (OCImage.offscreen_context == NULL) 155 OCImage.Stride = OCImage.offscreen_context->pitch;
154 { 156
155 printf("PdCreateOffscreenContext failed\n"); 157 if (OCImage.flags & SDL_DOUBLEBUF)
156 return -1; 158 {
157 } 159 fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n");
158 160 }
159 OCImage.Stride = OCImage.offscreen_context->pitch; 161
160 162 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
161 if (OCImage.flags & SDL_DOUBLEBUF) 163
162 printf("hardware flag for doublebuf offscreen context\n"); 164 if (OCImage.dc_ptr.ptr8 == NULL)
163 165 {
164 166 fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
165 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); 167 return -1;
166 168 }
167 OCImage.CurrentFrameData = OCImage.FrameData0; 169
168 OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8; 170 OCImage.CurrentFrameData = OCImage.FrameData0;
169 OCImage.CurrentFrameData->U = NULL; 171 OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8;
170 OCImage.CurrentFrameData->V = NULL; 172 OCImage.CurrentFrameData->U = NULL;
171 OCImage.current = 0; 173 OCImage.CurrentFrameData->V = NULL;
172 174 OCImage.current = 0;
173 if(OCImage.dc_ptr.ptr8 == NULL) 175
174 { 176 PhDCSetCurrent(OCImage.offscreen_context);
175 printf("PdGetOffscreenContextPtr failed\n"); 177
176 return -1; 178 screen->pixels = OCImage.CurrentFrameData->Y;
177 } 179
178 180 this->UpdateRects = ph_OCUpdate;
179 PhDCSetCurrent(OCImage.offscreen_context); 181
180 182 return 0;
181 screen->pixels = OCImage.CurrentFrameData->Y;
182
183 this->UpdateRects = ph_OCUpdate;
184
185 return 0;
186 } 183 }
187 184
188 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen) 185 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
189 { 186 {
190 this->UpdateRects = ph_OpenGLUpdate; 187 this->UpdateRects = ph_OpenGLUpdate;
240 else 237 else
241 { 238 {
242 return ph_SetupImage(this, screen); 239 return ph_SetupImage(this, screen);
243 } 240 }
244 } 241 }
245
246 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) 242 int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
247 { 243 {
248 return(-1); 244 return(-1);
249 } 245 }
250 246
300 ph_rect.lr.x = rects[i].x + rects[i].w; 296 ph_rect.lr.x = rects[i].x + rects[i].w;
301 ph_rect.lr.y = rects[i].y + rects[i].h; 297 ph_rect.lr.y = rects[i].y + rects[i].h;
302 298
303 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0) 299 if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
304 { 300 {
305 fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n"); 301 fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed.\n");
306 } 302 }
307 } 303 }
308 304
309 if (PgFlush() < 0) 305 if (PgFlush() < 0)
310 { 306 {
311 fprintf(stderr,"ph_NormalUpdate: PgFlush failed.\n"); 307 fprintf(stderr,"ph_NormalUpdate(): PgFlush failed.\n");
312 } 308 }
313 } 309 }
310
314 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) 311 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
315 { 312 {
316 PhPoint_t zero = {0}; 313 PhPoint_t zero = {0};
317 PhRect_t src_rect; 314 PhArea_t src_rect;
318 PhRect_t dest_rect; 315 PhArea_t dest_rect;
319 316
320 if(OCImage.direct_context == NULL) 317 if(OCImage.direct_context == NULL)
321 { 318 {
322 return; 319 return;
323 } 320 }
324 321
325 PgSetRegion(PtWidgetRid(window)); 322 PgSetRegion(PtWidgetRid(window));
326 PgSetClipping(0,NULL); 323 PgSetClipping(0, NULL);
327 PgWaitHWIdle(); 324 PgWaitHWIdle();
328 325
329 for (i=0; i<numrects; ++i) 326 for (i=0; i<numrects; ++i)
330 { 327 {
331 if (rects[i].w == 0) /* Clipped? */ 328 if (rects[i].w == 0) /* Clipped? */
332 { 329 {
333 continue; 330 continue;
334 } 331 }
335 332
336 src_rect.ul.x=rects[i].x; 333 src_rect.pos.x=rects[i].x;
337 src_rect.ul.y=rects[i].y; 334 src_rect.pos.y=rects[i].y;
338 dest_rect.ul.x=rects[i].x; 335 dest_rect.pos.x=rects[i].x;
339 dest_rect.ul.y=rects[i].y; 336 dest_rect.pos.y=rects[i].y;
340 337
341 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; 338 src_rect.size.w=rects[i].w;
342 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; 339 src_rect.size.h=rects[i].h;
343 340 dest_rect.size.w=rects[i].w;
344 zero.x = zero.y = 0; 341 dest_rect.size.h=rects[i].h;
345 PgSetTranslation (&zero, 0); 342
343 zero.x = 0;
344 zero.y = 0;
345 PgSetTranslation(&zero, 0);
346 PgSetRegion(PtWidgetRid(window)); 346 PgSetRegion(PtWidgetRid(window));
347 PgSetClipping(0,NULL); 347 PgSetClipping(0, NULL);
348 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); 348 PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL, &dest_rect);
349 349 }
350 } 350
351 if (PgFlush() < 0) 351 if (PgFlush() < 0)
352 { 352 {
353 fprintf(stderr,"ph_OCUpdate: PgFlush failed.\n"); 353 fprintf(stderr,"ph_OCUpdate(): PgFlush failed.\n");
354 } 354 }
355 355
356 /* later used to toggling double buffer */ 356 /* later used to toggling double buffer */
357 if (OCImage.current == 0) 357 if (OCImage.current == 0)
358 { 358 {