SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode_found; int i; VGLMode **modes; modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); mode_found = 0; for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Xsize == width) && (modes[i]->ModeInfo.Ysize == height) && ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32))) { mode_found = 1; break; } } if (mode_found == 0) { SDL_SetError("No matching video mode found"); return NULL; } if (VGLCurMode != NULL) VGLEnd(); if (VGLInit(modes[i]->ModeId) != 0) { SDL_SetError("Unable to switch to requested mode"); return NULL; } VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode)); VGLCurMode->ModeInfo = *VGLDisplay; VGLCurMode->Depth = modes[i]->Depth; VGLCurMode->ModeId = modes[i]->ModeId; VGLCurMode->Rmask = modes[i]->Rmask; VGLCurMode->Gmask = modes[i]->Gmask; VGLCurMode->Bmask = modes[i]->Bmask; if (VGLCurMode->ModeInfo.PixelBytes == 0) (VGLCurMode->ModeInfo.PixelBytes = 1); current->w = VGLCurMode->ModeInfo.Xsize; current->h = VGLCurMode->ModeInfo.Ysize; current->pixels = VGLCurMode->ModeInfo.Bitmap; current->pitch = VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.PixelBytes; current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); if (VGLCurMode->ModeInfo.Type == VIDBUF8) current->flags |= SDL_HWPALETTE; if (flags & SDL_DOUBLEBUF) { if (VGLCurMode->ModeInfo.Xsize * 2 <= VGLCurMode->ModeInfo.VYsize) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_address[0] = (byte *)current->pixels; flip_address[1] = (byte *)current->pixels + current->h * current->pitch; VGL_FlipHWSurface(this, current); } } if (! SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask, VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) { return NULL; } VGL_UpdateVideoInfo(this); this->UpdateRects = VGL_DirectUpdate; return current; }
SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode_found; int i; VGLMode **modes; modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); mode_found = 0; for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Xsize == width) && (modes[i]->ModeInfo.Ysize == height) && ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32))) { mode_found = 1; break; } } if (mode_found == 0) { SDL_SetError("No matching video mode found"); return NULL; } /* Shutdown previous videomode (if any) */ if (VGLCurMode != NULL) VGLEnd(); /* Try to set the requested linear video mode */ if (VGLInit(modes[i]->ModeId) != 0) { SDL_SetError("Unable to switch to requested mode"); return NULL; } VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode)); VGLCurMode->ModeInfo = *VGLDisplay; VGLCurMode->Depth = modes[i]->Depth; VGLCurMode->ModeId = modes[i]->ModeId; VGLCurMode->Rmask = modes[i]->Rmask; VGLCurMode->Gmask = modes[i]->Gmask; VGLCurMode->Bmask = modes[i]->Bmask; /* Workaround a bug in libvgl */ if (VGLCurMode->ModeInfo.PixelBytes == 0) (VGLCurMode->ModeInfo.PixelBytes = 1); current->w = VGLCurMode->ModeInfo.Xsize; current->h = VGLCurMode->ModeInfo.Ysize; current->pixels = VGLCurMode->ModeInfo.Bitmap; current->pitch = VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.PixelBytes; current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); /* Check if we are in a pseudo-color mode */ if (VGLCurMode->ModeInfo.Type == VIDBUF8) current->flags |= SDL_HWPALETTE; /* Check if we can do doublebuffering */ if (flags & SDL_DOUBLEBUF) { if (VGLCurMode->ModeInfo.Xsize * 2 <= VGLCurMode->ModeInfo.VYsize) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_address[0] = (byte *)current->pixels; flip_address[1] = (byte *)current->pixels + current->h * current->pitch; VGL_FlipHWSurface(this, current); } } if (! SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask, VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) { return NULL; } /* Update hardware acceleration info */ VGL_UpdateVideoInfo(this); /* Set the blit function */ this->UpdateRects = VGL_DirectUpdate; /* We're done */ return current; }
int VGL_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i; int total_modes; VGLMode **modes; for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_nummodes[i] = 0; SDL_modelist[i] = NULL; } if (SDL_getenv("SDL_NO_RAWKBD") == NULL) { if (VGLKeyboardInit(VGL_CODEKEYS) != 0) { SDL_SetError("Unable to initialize keyboard"); return -1; } } else { warnx("Requiest to put keyboard into a raw mode ignored"); } if (VGL_initkeymaps(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize keymap"); return -1; } if (VGL_initmouse(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize mouse"); return -1; } if (VGLCurMode != NULL) { this->info.current_w = VGLCurMode->ModeInfo.Xsize; this->info.current_h = VGLCurMode->ModeInfo.Ysize; } if (VGLCurMode != NULL) vformat->BitsPerPixel = VGLCurMode->Depth; else vformat->BitsPerPixel = 16; total_modes = 0; modes = VGLListModes(-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32)) { VGL_AddMode(this, modes[i]); total_modes++; } } if (total_modes == 0) { SDL_SetError("No linear video modes available"); return -1; } VGL_UpdateVideoInfo(this); hw_lock = SDL_CreateMutex(); if (hw_lock == NULL) { SDL_SetError("Unable to create lock mutex"); VGL_VideoQuit(this); return -1; } return 0; }
int VGL_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i; int total_modes; VGLMode **modes; /* Initialize all variables that we clean on shutdown */ for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_nummodes[i] = 0; SDL_modelist[i] = NULL; } /* Enable mouse and keyboard support */ if (SDL_getenv("SDL_NO_RAWKBD") == NULL) { if (VGLKeyboardInit(VGL_CODEKEYS) != 0) { SDL_SetError("Unable to initialize keyboard"); return -1; } } else { warnx("Requiest to put keyboard into a raw mode ignored"); } if (VGL_initkeymaps(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize keymap"); return -1; } if (VGL_initmouse(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize mouse"); return -1; } /* Determine the current screen size */ if (VGLCurMode != NULL) { this->info.current_w = VGLCurMode->ModeInfo.Xsize; this->info.current_h = VGLCurMode->ModeInfo.Ysize; } /* Determine the screen depth */ if (VGLCurMode != NULL) vformat->BitsPerPixel = VGLCurMode->Depth; else vformat->BitsPerPixel = 16; /* Good default */ /* Query for the list of available video modes */ total_modes = 0; modes = VGLListModes(-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32)) { VGL_AddMode(this, modes[i]); total_modes++; } } if (total_modes == 0) { SDL_SetError("No linear video modes available"); return -1; } /* Fill in our hardware acceleration capabilities */ VGL_UpdateVideoInfo(this); /* Create the hardware surface lock mutex */ hw_lock = SDL_CreateMutex(); if (hw_lock == NULL) { SDL_SetError("Unable to create lock mutex"); VGL_VideoQuit(this); return -1; } /* We're done! */ return 0; }