comparison src/video/ps3/SDL_ps3render.c @ 3143:8fdabaa064c3 gsoc2009_ps3

Fixed centering. Added debug msgs for RenderCopy().
author Martin Lowinski <martin@goldtopf.org>
date Sat, 06 Jun 2009 06:40:23 +0000
parents c146645a770e
children 0d8d1f870964
comparison
equal deleted inserted replaced
3142:c146645a770e 3143:8fdabaa064c3
35 #include <linux/kd.h> 35 #include <linux/kd.h>
36 #include <linux/fb.h> 36 #include <linux/fb.h>
37 #include <sys/mman.h> 37 #include <sys/mman.h>
38 38
39 #include <asm/ps3fb.h> 39 #include <asm/ps3fb.h>
40
41 /* Debugging
42 * 0: No debug messages
43 * 1: Video debug messages
44 * 2: SPE debug messages
45 * 3: Memory adresses
46 */
47 #define DEBUG_LEVEL 2
48
49 #ifdef DEBUG_LEVEL
50 #define deprintf( level, fmt, args... ) \
51 do \
52 { \
53 if ( (unsigned)(level) <= DEBUG_LEVEL ) \
54 { \
55 fprintf( stdout, fmt, ##args ); \
56 fflush( stdout ); \
57 } \
58 } while ( 0 )
59 #else
60 #define deprintf( level, fmt, args... )
61 #endif
62 40
63 /* SDL surface based renderer implementation */ 41 /* SDL surface based renderer implementation */
64 42
65 static SDL_Renderer *SDL_PS3_CreateRenderer(SDL_Window * window, 43 static SDL_Renderer *SDL_PS3_CreateRenderer(SDL_Window * window,
66 Uint32 flags); 44 Uint32 flags);
156 SDL_OutOfMemory(); 134 SDL_OutOfMemory();
157 return NULL; 135 return NULL;
158 } 136 }
159 SDL_zerop(data); 137 SDL_zerop(data);
160 138
161 renderer->CreateTexture = PS3_CreateTexture; 139 //renderer->CreateTexture = PS3_CreateTexture;
162 renderer->DestroyTexture = PS3_DestroyTexture; 140 //renderer->DestroyTexture = PS3_DestroyTexture;
163 renderer->RenderPoint = SDL_PS3_RenderPoint; 141 renderer->RenderPoint = SDL_PS3_RenderPoint;
164 renderer->RenderLine = SDL_PS3_RenderLine; 142 renderer->RenderLine = SDL_PS3_RenderLine;
165 renderer->RenderFill = SDL_PS3_RenderFill; 143 renderer->RenderFill = SDL_PS3_RenderFill;
166 renderer->RenderCopy = SDL_PS3_RenderCopy; 144 renderer->RenderCopy = SDL_PS3_RenderCopy;
167 renderer->RenderPresent = SDL_PS3_RenderPresent; 145 renderer->RenderPresent = SDL_PS3_RenderPresent;
169 renderer->info.name = SDL_PS3_RenderDriver.info.name; 147 renderer->info.name = SDL_PS3_RenderDriver.info.name;
170 renderer->info.flags = 0; 148 renderer->info.flags = 0;
171 renderer->window = window->id; 149 renderer->window = window->id;
172 renderer->driverdata = data; 150 renderer->driverdata = data;
173 Setup_SoftwareRenderer(renderer); 151 Setup_SoftwareRenderer(renderer);
152
153 deprintf(1, "window->w = %u\n", window->w);
154 deprintf(1, "window->h = %u\n", window->h);
174 155
175 data->double_buffering = 0; 156 data->double_buffering = 0;
176 157
177 if (flags & SDL_RENDERER_PRESENTFLIP2) { 158 if (flags & SDL_RENDERER_PRESENTFLIP2) {
178 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; 159 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
339 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 320 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
340 SDL_Surface *target = data->screens[data->current_screen]; 321 SDL_Surface *target = data->screens[data->current_screen];
341 SDL_Rect real_srcrect = *srcrect; 322 SDL_Rect real_srcrect = *srcrect;
342 SDL_Rect real_dstrect = *dstrect; 323 SDL_Rect real_dstrect = *dstrect;
343 324
344 /* For testing */ 325 deprintf(1, "surface->w = %u\n", surface->w); // FIXME: surface->w changes to 32
345 int width = 1280; 326 deprintf(1, "surface->h = %u\n", surface->h);
346 int height = 720; 327
347 void *pixels = (void *)memalign(16, height * data->screens[0]->pitch); 328 deprintf(1, "srcrect->w = %u\n", srcrect->w);
348 SDL_memset(pixels, 0x42, height * data->screens[0]->pitch); 329 deprintf(1, "srcrect->h = %u\n", srcrect->h);
330 deprintf(1, "dstrect->w = %u\n", dstrect->w);
331 deprintf(1, "dstrect->h = %u\n", dstrect->h);
332
333 deprintf(1, "txdata->bpp = %u\n", txdata->bpp);
334 deprintf(1, "texture->format (bpp) = %u\n", SDL_BYTESPERPIXEL(texture->format));
335
336 /* For testing, align pixels */
337 void *pixels = (void *)memalign(16, dstrect->h * data->screens[0]->pitch);
338 SDL_memcpy(pixels, surface->pixels, dstrect->h * data->screens[0]->pitch);
349 339
350 /* Get screeninfo */ 340 /* Get screeninfo */
351 struct fb_fix_screeninfo fb_finfo; 341 struct fb_fix_screeninfo fb_finfo;
352 if (ioctl(devdata->fbdev, FBIOGET_FSCREENINFO, &fb_finfo)) { 342 if (ioctl(devdata->fbdev, FBIOGET_FSCREENINFO, &fb_finfo)) {
353 SDL_SetError("[PS3] Can't get fixed screeninfo"); 343 SDL_SetError("[PS3] Can't get fixed screeninfo");
362 txdata->bpp = fb_vinfo.bits_per_pixel; 352 txdata->bpp = fb_vinfo.bits_per_pixel;
363 if (txdata->bpp == 16) 353 if (txdata->bpp == 16)
364 txdata->bpp = fb_vinfo.red.length + fb_vinfo.green.length + fb_vinfo.blue.length; 354 txdata->bpp = fb_vinfo.red.length + fb_vinfo.green.length + fb_vinfo.blue.length;
365 355
366 /* Adjust centering */ 356 /* Adjust centering */
367 data->bounded_width = width < fb_vinfo.xres ? width : fb_vinfo.xres; 357 data->bounded_width = window->w < fb_vinfo.xres ? window->w : fb_vinfo.xres;
368 data->bounded_height = height < fb_vinfo.yres ? height : fb_vinfo.yres; 358 data->bounded_height = window->h < fb_vinfo.yres ? window->h : fb_vinfo.yres;
369 data->offset_left = (fb_vinfo.xres - data->bounded_width) >> 1; 359 data->offset_left = (fb_vinfo.xres - data->bounded_width) >> 1;
370 data->offset_top = (fb_vinfo.yres - data->bounded_height) >> 1; 360 data->offset_top = (fb_vinfo.yres - data->bounded_height) >> 1;
371 data->center[0] = devdata->frame_buffer + data->offset_left * txdata->bpp/8 + 361 data->center[0] = devdata->frame_buffer + data->offset_left * /*txdata->bpp/8*/ 4 +
372 data->offset_top * fb_finfo.line_length; 362 data->offset_top * fb_finfo.line_length;
373 data->center[1] = data->center[0] + fb_vinfo.yres * fb_finfo.line_length; 363 data->center[1] = data->center[0] + fb_vinfo.yres * fb_finfo.line_length;
364
365 deprintf(1, "offset_left = %u\n", data->offset_left);
366 deprintf(1, "offset_top = %u\n", data->offset_top);
374 367
375 /* Set SPU parms for copying the surface to framebuffer */ 368 /* Set SPU parms for copying the surface to framebuffer */
376 devdata->fb_parms->data = (unsigned char *)pixels; 369 devdata->fb_parms->data = (unsigned char *)pixels;
377 devdata->fb_parms->center = data->center[data->current_screen]; 370 devdata->fb_parms->center = data->center[data->current_screen];
378 devdata->fb_parms->out_line_stride = fb_finfo.line_length; 371 devdata->fb_parms->out_line_stride = fb_finfo.line_length;
379 devdata->fb_parms->in_line_stride = surface->w * txdata->bpp / 8; 372 devdata->fb_parms->in_line_stride = dstrect->w * /*txdata->bpp / 8*/4;
380 devdata->fb_parms->bounded_input_height = data->bounded_height; 373 devdata->fb_parms->bounded_input_height = data->bounded_height;
381 devdata->fb_parms->bounded_input_width = data->bounded_width; 374 devdata->fb_parms->bounded_input_width = data->bounded_width;
382 devdata->fb_parms->fb_pixel_size = txdata->bpp / 8; 375 devdata->fb_parms->fb_pixel_size = txdata->bpp / 8;
383 376
384 deprintf(3, "[PS3->SPU] fb_thread_data->argp = 0x%x\n", devdata->fb_thread_data->argp); 377 deprintf(3, "[PS3->SPU] fb_thread_data->argp = 0x%x\n", devdata->fb_thread_data->argp);
388 SPE_SendMsg(devdata->fb_thread_data, (unsigned int)devdata->fb_thread_data->argp); 381 SPE_SendMsg(devdata->fb_thread_data, (unsigned int)devdata->fb_thread_data->argp);
389 382
390 SPE_WaitForMsg(devdata->fb_thread_data, SPU_FIN); 383 SPE_WaitForMsg(devdata->fb_thread_data, SPU_FIN);
391 free(pixels); 384 free(pixels);
392 385
393 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 386 return 0;
387 //return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
394 } 388 }
395 } 389 }
396 390
397 static void 391 static void
398 SDL_PS3_RenderPresent(SDL_Renderer * renderer) 392 SDL_PS3_RenderPresent(SDL_Renderer * renderer)