Engine/lib/sdl/src/video/SDL_video.c
/*
 * Initialize the video and event subsystems -- determine native pixel format
 */
Initialize the video and event subsystems -- determine native pixel format
Initialize the video and event subsystems -- determine native pixel format
int
SDL_VideoInit(const char *driver_name)
{
    SDL_VideoDevice *video;
    const char *hint;
    int index;
    int i;
    SDL_bool allow_screensaver;
    if (_this != NULL) {
        SDL_VideoQuit();
    }
#if !SDL_TIMERS_DISABLED
    SDL_TicksInit();
#endif
    if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
        SDL_KeyboardInit() < 0 ||
        SDL_MouseInit() < 0 ||
        SDL_TouchInit() < 0) {
        return -1;
    }
    index = 0;
    video = NULL;
    if (driver_name == NULL) {
        driver_name = SDL_getenv("SDL_VIDEODRIVER");
    }
    if (driver_name != NULL) {
        for (i = 0; bootstrap[i]; ++i) {
            if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
                if (bootstrap[i]->available()) {
                    video = bootstrap[i]->create(index);
                    break;
                }
            }
        }
    } else {
        for (i = 0; bootstrap[i]; ++i) {
            if (bootstrap[i]->available()) {
                video = bootstrap[i]->create(index);
                if (video != NULL) {
                    break;
                }
            }
        }
    }
    if (video == NULL) {
        if (driver_name) {
            return SDL_SetError("%s not available", driver_name);
        }
        return SDL_SetError("No available video device");
    }
    _this = video;
    _this->name = bootstrap[i]->name;
    _this->next_object_id = 1;
    _this->gl_config.driver_loaded = 0;
    _this->gl_config.dll_handle = NULL;
    SDL_GL_ResetAttributes();
    _this->current_glwin_tls = SDL_TLSCreate();
    _this->current_glctx_tls = SDL_TLSCreate();
    if (_this->VideoInit(_this) < 0) {
        SDL_VideoQuit();
        return -1;
    }
    if (_this->num_displays == 0) {
        SDL_VideoQuit();
        return SDL_SetError("The video driver did not add any displays");
    }
    if (ShouldUseTextureFramebuffer()) {
        _this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
        _this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
        _this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
    }
    hint = SDL_GetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER);
    if (hint) {
        allow_screensaver = SDL_atoi(hint) ? SDL_TRUE : SDL_FALSE;
    } else {
        allow_screensaver = SDL_FALSE;
    }
    if (!allow_screensaver) {
        SDL_DisableScreenSaver();
    }
    if (!SDL_HasScreenKeyboardSupport()) {
        SDL_StartTextInput();
    }
    return 0;
}
int SDL_VideoInit ( const char * driver_name ) { SDL_VideoDevice * video ; const char * hint ; int index ; int i ; SDL_bool allow_screensaver ; if ( _this != NULL ) { SDL_VideoQuit ( ) ; } #if ! SDL_TIMERS_DISABLED SDL_TicksInit ( ) ; #endif if ( SDL_InitSubSystem ( SDL_INIT_EVENTS ) < 0 || SDL_KeyboardInit ( ) < 0 || SDL_MouseInit ( ) < 0 || SDL_TouchInit ( ) < 0 ) { return -1 ; } index = 0 ; video = NULL ; if ( driver_name == NULL ) { driver_name = SDL_getenv ( " " ) ; } if ( driver_name != NULL ) { for ( i = 0 ; bootstrap [ i ] ; ++ i ) { if ( SDL_strncasecmp ( bootstrap [ i ] -> name , driver_name , SDL_strlen ( driver_name ) ) == 0 ) { if ( bootstrap [ i ] -> available ( ) ) { video = bootstrap [ i ] -> create ( index ) ; break ; } } } } else { for ( i = 0 ; bootstrap [ i ] ; ++ i ) { if ( bootstrap [ i ] -> available ( ) ) { video = bootstrap [ i ] -> create ( index ) ; if ( video != NULL ) { break ; } } } } if ( video == NULL ) { if ( driver_name ) { return SDL_SetError ( " " , driver_name ) ; } return SDL_SetError ( " " ) ; } _this = video ; _this -> name = bootstrap [ i ] -> name ; _this -> next_object_id = 1 ; _this -> gl_config . driver_loaded = 0 ; _this -> gl_config . dll_handle = NULL ; SDL_GL_ResetAttributes ( ) ; _this -> current_glwin_tls = SDL_TLSCreate ( ) ; _this -> current_glctx_tls = SDL_TLSCreate ( ) ; if ( _this -> VideoInit ( _this ) < 0 ) { SDL_VideoQuit ( ) ; return -1 ; } if ( _this -> num_displays == 0 ) { SDL_VideoQuit ( ) ; return SDL_SetError ( " " ) ; } if ( ShouldUseTextureFramebuffer ( ) ) { _this -> CreateWindowFramebuffer = SDL_CreateWindowTexture ; _this -> UpdateWindowFramebuffer = SDL_UpdateWindowTexture ; _this -> DestroyWindowFramebuffer = SDL_DestroyWindowTexture ; } hint = SDL_GetHint ( SDL_HINT_VIDEO_ALLOW_SCREENSAVER ) ; if ( hint ) { allow_screensaver = SDL_atoi ( hint ) ? SDL_TRUE : SDL_FALSE ; } else { allow_screensaver = SDL_FALSE ; } if ( ! allow_screensaver ) { SDL_DisableScreenSaver ( ) ; } if ( ! SDL_HasScreenKeyboardSupport ( ) ) { SDL_StartTextInput ( ) ; } return 0 ; }
Initialize the video and event subsystems -- determine native pixel format
Initialize the video and event subsystems -- determine native pixel format
/* Check to make sure we don't overwrite '_this' */ /* Start the event loop */ /* Select the proper video driver */ /* Set some very sane GL defaults */ /* Initialize the video subsystem */ /* Make sure some displays were added */ /* Add the renderer framebuffer emulation if desired */ /* Disable the screen saver by default. This is a change from <= 2.0.1,
       but most things using SDL are games or media players; you wouldn't
       want a screensaver to trigger if you're playing exclusively with a
       joystick, or passively watching a movie. Things that use SDL but
       function more like a normal desktop app should explicitly reenable the
       screensaver. */ /* If we don't use a screen keyboard, turn on text input by default,
       otherwise programs that expect to get text events without enabling
       UNICODE input won't get any events.

       Actually, come to think of it, you needed to call SDL_EnableUNICODE(1)
       in SDL 1.2 before you got text input events.  Hmm...
     */ /* We're ready to go! */