8 #include "SDL_sysvideo.h"
9 #include "SDL_pixels_c.h"
10 #include "SDL_events_c.h"
12 #include "SDL_l4fbvideo.h"
16 double L4FB_video_scale_factor __attribute__ ((weak)) = 1.0;
18 static void FreeAndNull(void** ptr) {
27 SDL_Surface *L4FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) {
28 char* apptitle = APPTITLE;
29 char* wintitle = WINTITLE;
31 printf("L4FB_SetVideoMode: %dx%d@%d:\n", width, height, bpp);
33 * is requested resolution higher than the framebuffer's one?
36 if( width > (int)this->hidden->vvi.width
37 || height > (int)this->hidden->vvi.height)
43 * calc the offsets for current resolution the center the image
46 this->hidden->x_offset = (this->hidden->vvi.width - width ) / 2;
47 this->hidden->y_offset = (this->hidden->vvi.height - height) / 2;
49 // make sure to have correct scale
50 if (L4FB_video_scale_factor<=0) L4FB_video_scale_factor = 1.0;
52 // reject unsupported bpp
53 if (bpp != 16) return NULL;
54 // reject unsupported flags
55 if (flags & SDL_OPENGL) return NULL;
57 /* Allocate the new pixel format for the screen */
58 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
59 SDL_SetError("Couldn't allocate new pixel format for requested mode");
63 // if we were double buffered clear shadow buffer
64 if (current->flags & SDL_DOUBLEBUF) {
65 FreeAndNull(current->pixels);
69 if (this->wm_title) wintitle = this->wm_title;
70 if (this->wm_icon) apptitle = this->wm_icon;
74 // L4FB_SetCaption(this, wintitle, apptitle);
76 if (l4_is_invalid_cap(this->hidden->ev_ds) || !this->hidden->ev_ds)
77 L4FB_InstallEventHandler(this);
79 /* Set up the new mode framebuffer */
82 current->pitch = SDL_CalculatePitch(current);
83 this->hidden->pitch = current->pitch;
84 current->flags = SDL_PREALLOC | SDL_ASYNCBLIT;
87 // if (current->pixels)
89 // /* TODO: ERROR HANDLING */
92 // memset(current->pixels, 0, current->h*current->pitch);
95 /* since we want to center image in fb we allway have to use doublebuf... */
97 this->hidden->fb_start = this->hidden->fbmem_vaddr + this->hidden->vvi.buffer_offset;
99 current->pixels = malloc(current->h*current->pitch);
101 if (current->pixels) {
103 printf("allocated shadow buffer\n");
104 this->hidden->pixels = current->pixels;
105 memset(current->pixels, 0, current->h*current->pitch);
110 if (flags&SDL_DOUBLEBUF) {
112 current->flags |= SDL_DOUBLEBUF|SDL_HWSURFACE;
113 // try to alloc shadow buffer
120 int L4FB_ToggleFullScreen(_THIS, int on) {
122 /* TODO: NOT IMPLENETED */
124 // remember window size for fullscreen toggle
126 static int is_fs = 0;
133 else if((!on)&&(is_fs))
141 int L4FB_AllocHWSurface(_THIS, SDL_Surface *surface) {
144 //INFO(LOG_Enter("");)
147 void L4FB_FreeHWSurface(_THIS, SDL_Surface *surface) {
150 //INFO(LOG_Enter("");)
154 int L4FB_LockHWSurface(_THIS, SDL_Surface *surface) {
157 // INFO(LOG_Enter("");)
160 void L4FB_UnlockHWSurface(_THIS, SDL_Surface *surface) {
163 // INFO(LOG_Enter("");)
167 void L4FB_UpdateRects(_THIS, int numrects, SDL_Rect *rects) {
170 l4re_video_view_info_t * vvi = &this->hidden->vvi;
172 for (i=0; i<numrects; i++) {
174 for (j=0; j<rects[i].h; j++) {
175 void *dest = this->hidden->fb_start
176 + vvi->bytes_per_line
177 *(this->hidden->y_offset+rects[i].y+j)
178 + this->hidden->x_offset*vvi->pixel_info.bytes_per_pixel
179 + rects[i].x*vvi->pixel_info.bytes_per_pixel;
181 void *src = this->hidden->pixels
182 + (this->hidden->pitch
184 + rects[i].x * vvi->pixel_info.bytes_per_pixel;
186 unsigned len = rects[i].w * vvi->pixel_info.bytes_per_pixel;
187 memcpy(dest,src,len);
190 l4re_util_video_goos_fb_refresh(&this->hidden->goosfb, rects[i].x+this->hidden->x_offset, rects[i].y+this->hidden->y_offset, rects[i].w, rects[i].h);
194 int L4FB_FlipHWSurface(_THIS, SDL_Surface *surface) {
195 l4re_video_view_info_t * vvi = &this->hidden->vvi;
197 // copy buffer and update screen
200 * we have to do it linewise because real screen size and surface size my differ
202 for(i=0; i<surface->h; i++) {
204 void *dest = this->hidden->fb_start
205 + vvi->bytes_per_line
206 * (this->hidden->y_offset+i)
207 + this->hidden->x_offset * vvi->pixel_info.bytes_per_pixel;
209 memcpy(dest, surface->pixels+(surface->pitch * i), surface->pitch);
212 l4re_util_video_goos_fb_refresh(&this->hidden->goosfb, this->hidden->x_offset, this->hidden->y_offset, surface->w, surface->h);
213 // printf("refresh\n");
217 int L4FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) {
226 void L4FB_WarpWMCursor(_THIS, Uint16 x, Uint16 y) {
230 /* TODO: not implemented */
233 SDL_GrabMode L4FB_GrabInput(_THIS, SDL_GrabMode mode) {
235 //(mode==SDL_GRAB_OFF?"no":"yes"));
236 /*TODO: not implemented */