src/video/psp/SDL_pspvideo.c
changeset 7009 161b7b6a5303
child 7037 3fedf1f25b94
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/psp/SDL_pspvideo.c	Sun Mar 17 20:07:02 2013 +0800
     1.3 @@ -0,0 +1,334 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#if SDL_VIDEO_DRIVER_PSP
    1.28 +
    1.29 +/* SDL internals */
    1.30 +#include "../SDL_sysvideo.h"
    1.31 +#include "SDL_version.h"
    1.32 +#include "SDL_syswm.h"
    1.33 +#include "SDL_loadso.h"
    1.34 +#include "SDL_events.h"
    1.35 +#include "../../events/SDL_mouse_c.h"
    1.36 +#include "../../events/SDL_keyboard_c.h"
    1.37 +
    1.38 +
    1.39 +
    1.40 +/* PSP declarations */
    1.41 +#include "SDL_pspvideo.h"
    1.42 +#include "SDL_pspevents_c.h"
    1.43 +#include "SDL_pspgl_c.h"
    1.44 +
    1.45 +/* unused
    1.46 +static SDL_bool PSP_initialized = SDL_FALSE;
    1.47 +*/
    1.48 +static int
    1.49 +PSP_Available(void)
    1.50 +{
    1.51 +    return 1;
    1.52 +}
    1.53 +
    1.54 +static void
    1.55 +PSP_Destroy(SDL_VideoDevice * device)
    1.56 +{
    1.57 +//    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
    1.58 +
    1.59 +    if (device->driverdata != NULL) {
    1.60 +        device->driverdata = NULL;
    1.61 +    }
    1.62 +}
    1.63 +
    1.64 +static SDL_VideoDevice *
    1.65 +PSP_Create()
    1.66 +{
    1.67 +    SDL_VideoDevice *device;
    1.68 +    SDL_VideoData *phdata;
    1.69 +    SDL_GLDriverData *gldata;
    1.70 +    int status;
    1.71 +
    1.72 +    /* Check if pandora could be initialized */
    1.73 +    status = PSP_Available();
    1.74 +    if (status == 0) {
    1.75 +        /* PSP could not be used */
    1.76 +        return NULL;
    1.77 +    }
    1.78 +
    1.79 +    /* Initialize SDL_VideoDevice structure */
    1.80 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    1.81 +    if (device == NULL) {
    1.82 +        SDL_OutOfMemory();
    1.83 +        return NULL;
    1.84 +    }
    1.85 +
    1.86 +    /* Initialize internal Pandora specific data */
    1.87 +    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    1.88 +    if (phdata == NULL) {
    1.89 +        SDL_OutOfMemory();
    1.90 +        SDL_free(device);
    1.91 +        return NULL;
    1.92 +    }
    1.93 +        
    1.94 +		gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData));
    1.95 +    if (gldata == NULL) {
    1.96 +        SDL_OutOfMemory();
    1.97 +        SDL_free(device);
    1.98 +        return NULL;
    1.99 +    }	
   1.100 +    device->gl_data = gldata;
   1.101 +    
   1.102 +    device->driverdata = phdata;
   1.103 +
   1.104 +    phdata->egl_initialized = SDL_TRUE;
   1.105 +
   1.106 +
   1.107 +    /* Setup amount of available displays and current display */
   1.108 +    device->num_displays = 0;
   1.109 +
   1.110 +    /* Set device free function */
   1.111 +    device->free = PSP_Destroy;
   1.112 +
   1.113 +    /* Setup all functions which we can handle */
   1.114 +    device->VideoInit = PSP_VideoInit;
   1.115 +    device->VideoQuit = PSP_VideoQuit;
   1.116 +    device->GetDisplayModes = PSP_GetDisplayModes;
   1.117 +    device->SetDisplayMode = PSP_SetDisplayMode;
   1.118 +    device->CreateWindow = PSP_CreateWindow;
   1.119 +    device->CreateWindowFrom = PSP_CreateWindowFrom;
   1.120 +    device->SetWindowTitle = PSP_SetWindowTitle;
   1.121 +    device->SetWindowIcon = PSP_SetWindowIcon;
   1.122 +    device->SetWindowPosition = PSP_SetWindowPosition;
   1.123 +    device->SetWindowSize = PSP_SetWindowSize;
   1.124 +    device->ShowWindow = PSP_ShowWindow;
   1.125 +    device->HideWindow = PSP_HideWindow;
   1.126 +    device->RaiseWindow = PSP_RaiseWindow;
   1.127 +    device->MaximizeWindow = PSP_MaximizeWindow;
   1.128 +    device->MinimizeWindow = PSP_MinimizeWindow;
   1.129 +    device->RestoreWindow = PSP_RestoreWindow;
   1.130 +    device->SetWindowGrab = PSP_SetWindowGrab;
   1.131 +    device->DestroyWindow = PSP_DestroyWindow;
   1.132 +    device->GetWindowWMInfo = PSP_GetWindowWMInfo;
   1.133 +    device->GL_LoadLibrary = PSP_GL_LoadLibrary;
   1.134 +    device->GL_GetProcAddress = PSP_GL_GetProcAddress;
   1.135 +    device->GL_UnloadLibrary = PSP_GL_UnloadLibrary;
   1.136 +    device->GL_CreateContext = PSP_GL_CreateContext;
   1.137 +    device->GL_MakeCurrent = PSP_GL_MakeCurrent;
   1.138 +    device->GL_SetSwapInterval = PSP_GL_SetSwapInterval;
   1.139 +    device->GL_GetSwapInterval = PSP_GL_GetSwapInterval;
   1.140 +    device->GL_SwapWindow = PSP_GL_SwapWindow;
   1.141 +    device->GL_DeleteContext = PSP_GL_DeleteContext;
   1.142 +	device->SDL_HasScreenKeyboardSupport = PSP_SDL_HasScreenKeyboardSupport;
   1.143 +	device->SDL_ShowScreenKeyboard = PSP_SDL_ShowScreenKeyboard;
   1.144 +	device->SDL_HideScreenKeyboard = PSP_SDL_HideScreenKeyboard;
   1.145 +	device->SDL_IsScreenKeyboardShown = PSP_SDL_IsScreenKeyboardShown;    
   1.146 +    
   1.147 +    device->PumpEvents = PSP_PumpEvents;
   1.148 +
   1.149 +    return device;
   1.150 +}
   1.151 +
   1.152 +VideoBootStrap PSP_bootstrap = {
   1.153 +    "PSP",
   1.154 +    "PSP Video Driver",
   1.155 +    PSP_Available,
   1.156 +    PSP_Create
   1.157 +};
   1.158 +
   1.159 +/*****************************************************************************/
   1.160 +/* SDL Video and Display initialization/handling functions                   */
   1.161 +/*****************************************************************************/
   1.162 +int
   1.163 +PSP_VideoInit(_THIS)
   1.164 +{
   1.165 +    SDL_VideoDisplay display;
   1.166 +    SDL_DisplayMode current_mode;
   1.167 +
   1.168 +    SDL_zero(current_mode);
   1.169 +    
   1.170 +    current_mode.w = 480;
   1.171 +    current_mode.h = 272;
   1.172 +    
   1.173 +    current_mode.refresh_rate = 60;
   1.174 +    // 32 bpp for default 
   1.175 +   // current_mode.format = SDL_PIXELFORMAT_RGBA8888;
   1.176 +    current_mode.format = SDL_PIXELFORMAT_ABGR8888;
   1.177 +    
   1.178 +    current_mode.driverdata = NULL;
   1.179 +
   1.180 +    SDL_zero(display);
   1.181 +    display.desktop_mode = current_mode;
   1.182 +    display.current_mode = current_mode;
   1.183 +    display.driverdata = NULL;
   1.184 +
   1.185 +    SDL_AddVideoDisplay(&display);
   1.186 +
   1.187 +    return 1;
   1.188 +}
   1.189 +
   1.190 +void
   1.191 +PSP_VideoQuit(_THIS)
   1.192 +{
   1.193 +
   1.194 +}
   1.195 +
   1.196 +void
   1.197 +PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
   1.198 +{
   1.199 +
   1.200 +}
   1.201 +
   1.202 +int
   1.203 +PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   1.204 +{
   1.205 +    return 0;
   1.206 +}
   1.207 +#define EGLCHK(stmt)							\
   1.208 +	do {										\
   1.209 +		EGLint err;								\
   1.210 +												\
   1.211 +		stmt;									\
   1.212 +		err = eglGetError();					\
   1.213 +		if (err != EGL_SUCCESS) {				\
   1.214 +			SDL_SetError("EGL error %d", err);	\
   1.215 +			return 0;							\
   1.216 +		}										\
   1.217 +	} while (0)
   1.218 +	
   1.219 +int
   1.220 +PSP_CreateWindow(_THIS, SDL_Window * window)
   1.221 +{
   1.222 +//    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   1.223 +
   1.224 +    SDL_WindowData *wdata;
   1.225 +
   1.226 +    /* Allocate window internal data */
   1.227 +    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
   1.228 +    if (wdata == NULL) {
   1.229 +        SDL_OutOfMemory();
   1.230 +        return -1;
   1.231 +    }
   1.232 +
   1.233 +    /* Setup driver data for this window */
   1.234 +    window->driverdata = wdata;
   1.235 +
   1.236 +
   1.237 +    /* Window has been successfully created */
   1.238 +    return 0;
   1.239 +}
   1.240 +
   1.241 +int
   1.242 +PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   1.243 +{
   1.244 +    return -1;
   1.245 +}
   1.246 +
   1.247 +void
   1.248 +PSP_SetWindowTitle(_THIS, SDL_Window * window)
   1.249 +{
   1.250 +}
   1.251 +void
   1.252 +PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
   1.253 +{
   1.254 +}
   1.255 +void
   1.256 +PSP_SetWindowPosition(_THIS, SDL_Window * window)
   1.257 +{
   1.258 +}
   1.259 +void
   1.260 +PSP_SetWindowSize(_THIS, SDL_Window * window)
   1.261 +{
   1.262 +}
   1.263 +void
   1.264 +PSP_ShowWindow(_THIS, SDL_Window * window)
   1.265 +{
   1.266 +}
   1.267 +void
   1.268 +PSP_HideWindow(_THIS, SDL_Window * window)
   1.269 +{
   1.270 +}
   1.271 +void
   1.272 +PSP_RaiseWindow(_THIS, SDL_Window * window)
   1.273 +{
   1.274 +}
   1.275 +void
   1.276 +PSP_MaximizeWindow(_THIS, SDL_Window * window)
   1.277 +{
   1.278 +}
   1.279 +void
   1.280 +PSP_MinimizeWindow(_THIS, SDL_Window * window)
   1.281 +{
   1.282 +}
   1.283 +void
   1.284 +PSP_RestoreWindow(_THIS, SDL_Window * window)
   1.285 +{
   1.286 +}
   1.287 +void
   1.288 +PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
   1.289 +{
   1.290 +
   1.291 +}
   1.292 +void
   1.293 +PSP_DestroyWindow(_THIS, SDL_Window * window)
   1.294 +{
   1.295 +	
   1.296 +//    eglTerminate(_this->gl_data->display);
   1.297 +}
   1.298 +
   1.299 +/*****************************************************************************/
   1.300 +/* SDL Window Manager function                                               */
   1.301 +/*****************************************************************************/
   1.302 +SDL_bool
   1.303 +PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
   1.304 +{
   1.305 +    if (info->version.major <= SDL_MAJOR_VERSION) {
   1.306 +        return SDL_TRUE;
   1.307 +    } else {
   1.308 +        SDL_SetError("application not compiled with SDL %d.%d\n",
   1.309 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   1.310 +        return SDL_FALSE;
   1.311 +    }
   1.312 +
   1.313 +    /* Failed to get window manager information */
   1.314 +    return SDL_FALSE;
   1.315 +}
   1.316 +
   1.317 +
   1.318 +/* TO Write Me*/
   1.319 +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS)
   1.320 +{
   1.321 +	return SDL_TRUE;
   1.322 +}
   1.323 +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window)
   1.324 +{
   1.325 +}
   1.326 +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window)
   1.327 +{
   1.328 +}
   1.329 +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window)
   1.330 +{
   1.331 +	return SDL_FALSE;
   1.332 +}
   1.333 +
   1.334 +
   1.335 +#endif /* SDL_VIDEO_DRIVER_PSP */
   1.336 +
   1.337 +/* vi: set ts=4 sw=4 expandtab: */