src/video/psp/SDL_pspvideo.c
author Captain Lex <kimonline@126.com>
Sun, 17 Mar 2013 20:07:02 +0800
changeset 7009 161b7b6a5303
child 7037 3fedf1f25b94
permissions -rw-r--r--
Add PSP support
kimonline@7009
     1
/*
kimonline@7009
     2
  Simple DirectMedia Layer
kimonline@7009
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
kimonline@7009
     4
kimonline@7009
     5
  This software is provided 'as-is', without any express or implied
kimonline@7009
     6
  warranty.  In no event will the authors be held liable for any damages
kimonline@7009
     7
  arising from the use of this software.
kimonline@7009
     8
kimonline@7009
     9
  Permission is granted to anyone to use this software for any purpose,
kimonline@7009
    10
  including commercial applications, and to alter it and redistribute it
kimonline@7009
    11
  freely, subject to the following restrictions:
kimonline@7009
    12
kimonline@7009
    13
  1. The origin of this software must not be misrepresented; you must not
kimonline@7009
    14
     claim that you wrote the original software. If you use this software
kimonline@7009
    15
     in a product, an acknowledgment in the product documentation would be
kimonline@7009
    16
     appreciated but is not required.
kimonline@7009
    17
  2. Altered source versions must be plainly marked as such, and must not be
kimonline@7009
    18
     misrepresented as being the original software.
kimonline@7009
    19
  3. This notice may not be removed or altered from any source distribution.
kimonline@7009
    20
*/
kimonline@7009
    21
kimonline@7009
    22
#include "SDL_config.h"
kimonline@7009
    23
kimonline@7009
    24
#if SDL_VIDEO_DRIVER_PSP
kimonline@7009
    25
kimonline@7009
    26
/* SDL internals */
kimonline@7009
    27
#include "../SDL_sysvideo.h"
kimonline@7009
    28
#include "SDL_version.h"
kimonline@7009
    29
#include "SDL_syswm.h"
kimonline@7009
    30
#include "SDL_loadso.h"
kimonline@7009
    31
#include "SDL_events.h"
kimonline@7009
    32
#include "../../events/SDL_mouse_c.h"
kimonline@7009
    33
#include "../../events/SDL_keyboard_c.h"
kimonline@7009
    34
kimonline@7009
    35
kimonline@7009
    36
kimonline@7009
    37
/* PSP declarations */
kimonline@7009
    38
#include "SDL_pspvideo.h"
kimonline@7009
    39
#include "SDL_pspevents_c.h"
kimonline@7009
    40
#include "SDL_pspgl_c.h"
kimonline@7009
    41
kimonline@7009
    42
/* unused
kimonline@7009
    43
static SDL_bool PSP_initialized = SDL_FALSE;
kimonline@7009
    44
*/
kimonline@7009
    45
static int
kimonline@7009
    46
PSP_Available(void)
kimonline@7009
    47
{
kimonline@7009
    48
    return 1;
kimonline@7009
    49
}
kimonline@7009
    50
kimonline@7009
    51
static void
kimonline@7009
    52
PSP_Destroy(SDL_VideoDevice * device)
kimonline@7009
    53
{
kimonline@7009
    54
//    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
kimonline@7009
    55
kimonline@7009
    56
    if (device->driverdata != NULL) {
kimonline@7009
    57
        device->driverdata = NULL;
kimonline@7009
    58
    }
kimonline@7009
    59
}
kimonline@7009
    60
kimonline@7009
    61
static SDL_VideoDevice *
kimonline@7009
    62
PSP_Create()
kimonline@7009
    63
{
kimonline@7009
    64
    SDL_VideoDevice *device;
kimonline@7009
    65
    SDL_VideoData *phdata;
kimonline@7009
    66
    SDL_GLDriverData *gldata;
kimonline@7009
    67
    int status;
kimonline@7009
    68
kimonline@7009
    69
    /* Check if pandora could be initialized */
kimonline@7009
    70
    status = PSP_Available();
kimonline@7009
    71
    if (status == 0) {
kimonline@7009
    72
        /* PSP could not be used */
kimonline@7009
    73
        return NULL;
kimonline@7009
    74
    }
kimonline@7009
    75
kimonline@7009
    76
    /* Initialize SDL_VideoDevice structure */
kimonline@7009
    77
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
kimonline@7009
    78
    if (device == NULL) {
kimonline@7009
    79
        SDL_OutOfMemory();
kimonline@7009
    80
        return NULL;
kimonline@7009
    81
    }
kimonline@7009
    82
kimonline@7009
    83
    /* Initialize internal Pandora specific data */
kimonline@7009
    84
    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
kimonline@7009
    85
    if (phdata == NULL) {
kimonline@7009
    86
        SDL_OutOfMemory();
kimonline@7009
    87
        SDL_free(device);
kimonline@7009
    88
        return NULL;
kimonline@7009
    89
    }
kimonline@7009
    90
        
kimonline@7009
    91
		gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData));
kimonline@7009
    92
    if (gldata == NULL) {
kimonline@7009
    93
        SDL_OutOfMemory();
kimonline@7009
    94
        SDL_free(device);
kimonline@7009
    95
        return NULL;
kimonline@7009
    96
    }	
kimonline@7009
    97
    device->gl_data = gldata;
kimonline@7009
    98
    
kimonline@7009
    99
    device->driverdata = phdata;
kimonline@7009
   100
kimonline@7009
   101
    phdata->egl_initialized = SDL_TRUE;
kimonline@7009
   102
kimonline@7009
   103
kimonline@7009
   104
    /* Setup amount of available displays and current display */
kimonline@7009
   105
    device->num_displays = 0;
kimonline@7009
   106
kimonline@7009
   107
    /* Set device free function */
kimonline@7009
   108
    device->free = PSP_Destroy;
kimonline@7009
   109
kimonline@7009
   110
    /* Setup all functions which we can handle */
kimonline@7009
   111
    device->VideoInit = PSP_VideoInit;
kimonline@7009
   112
    device->VideoQuit = PSP_VideoQuit;
kimonline@7009
   113
    device->GetDisplayModes = PSP_GetDisplayModes;
kimonline@7009
   114
    device->SetDisplayMode = PSP_SetDisplayMode;
kimonline@7009
   115
    device->CreateWindow = PSP_CreateWindow;
kimonline@7009
   116
    device->CreateWindowFrom = PSP_CreateWindowFrom;
kimonline@7009
   117
    device->SetWindowTitle = PSP_SetWindowTitle;
kimonline@7009
   118
    device->SetWindowIcon = PSP_SetWindowIcon;
kimonline@7009
   119
    device->SetWindowPosition = PSP_SetWindowPosition;
kimonline@7009
   120
    device->SetWindowSize = PSP_SetWindowSize;
kimonline@7009
   121
    device->ShowWindow = PSP_ShowWindow;
kimonline@7009
   122
    device->HideWindow = PSP_HideWindow;
kimonline@7009
   123
    device->RaiseWindow = PSP_RaiseWindow;
kimonline@7009
   124
    device->MaximizeWindow = PSP_MaximizeWindow;
kimonline@7009
   125
    device->MinimizeWindow = PSP_MinimizeWindow;
kimonline@7009
   126
    device->RestoreWindow = PSP_RestoreWindow;
kimonline@7009
   127
    device->SetWindowGrab = PSP_SetWindowGrab;
kimonline@7009
   128
    device->DestroyWindow = PSP_DestroyWindow;
kimonline@7009
   129
    device->GetWindowWMInfo = PSP_GetWindowWMInfo;
kimonline@7009
   130
    device->GL_LoadLibrary = PSP_GL_LoadLibrary;
kimonline@7009
   131
    device->GL_GetProcAddress = PSP_GL_GetProcAddress;
kimonline@7009
   132
    device->GL_UnloadLibrary = PSP_GL_UnloadLibrary;
kimonline@7009
   133
    device->GL_CreateContext = PSP_GL_CreateContext;
kimonline@7009
   134
    device->GL_MakeCurrent = PSP_GL_MakeCurrent;
kimonline@7009
   135
    device->GL_SetSwapInterval = PSP_GL_SetSwapInterval;
kimonline@7009
   136
    device->GL_GetSwapInterval = PSP_GL_GetSwapInterval;
kimonline@7009
   137
    device->GL_SwapWindow = PSP_GL_SwapWindow;
kimonline@7009
   138
    device->GL_DeleteContext = PSP_GL_DeleteContext;
kimonline@7009
   139
	device->SDL_HasScreenKeyboardSupport = PSP_SDL_HasScreenKeyboardSupport;
kimonline@7009
   140
	device->SDL_ShowScreenKeyboard = PSP_SDL_ShowScreenKeyboard;
kimonline@7009
   141
	device->SDL_HideScreenKeyboard = PSP_SDL_HideScreenKeyboard;
kimonline@7009
   142
	device->SDL_IsScreenKeyboardShown = PSP_SDL_IsScreenKeyboardShown;    
kimonline@7009
   143
    
kimonline@7009
   144
    device->PumpEvents = PSP_PumpEvents;
kimonline@7009
   145
kimonline@7009
   146
    return device;
kimonline@7009
   147
}
kimonline@7009
   148
kimonline@7009
   149
VideoBootStrap PSP_bootstrap = {
kimonline@7009
   150
    "PSP",
kimonline@7009
   151
    "PSP Video Driver",
kimonline@7009
   152
    PSP_Available,
kimonline@7009
   153
    PSP_Create
kimonline@7009
   154
};
kimonline@7009
   155
kimonline@7009
   156
/*****************************************************************************/
kimonline@7009
   157
/* SDL Video and Display initialization/handling functions                   */
kimonline@7009
   158
/*****************************************************************************/
kimonline@7009
   159
int
kimonline@7009
   160
PSP_VideoInit(_THIS)
kimonline@7009
   161
{
kimonline@7009
   162
    SDL_VideoDisplay display;
kimonline@7009
   163
    SDL_DisplayMode current_mode;
kimonline@7009
   164
kimonline@7009
   165
    SDL_zero(current_mode);
kimonline@7009
   166
    
kimonline@7009
   167
    current_mode.w = 480;
kimonline@7009
   168
    current_mode.h = 272;
kimonline@7009
   169
    
kimonline@7009
   170
    current_mode.refresh_rate = 60;
kimonline@7009
   171
    // 32 bpp for default 
kimonline@7009
   172
   // current_mode.format = SDL_PIXELFORMAT_RGBA8888;
kimonline@7009
   173
    current_mode.format = SDL_PIXELFORMAT_ABGR8888;
kimonline@7009
   174
    
kimonline@7009
   175
    current_mode.driverdata = NULL;
kimonline@7009
   176
kimonline@7009
   177
    SDL_zero(display);
kimonline@7009
   178
    display.desktop_mode = current_mode;
kimonline@7009
   179
    display.current_mode = current_mode;
kimonline@7009
   180
    display.driverdata = NULL;
kimonline@7009
   181
kimonline@7009
   182
    SDL_AddVideoDisplay(&display);
kimonline@7009
   183
kimonline@7009
   184
    return 1;
kimonline@7009
   185
}
kimonline@7009
   186
kimonline@7009
   187
void
kimonline@7009
   188
PSP_VideoQuit(_THIS)
kimonline@7009
   189
{
kimonline@7009
   190
kimonline@7009
   191
}
kimonline@7009
   192
kimonline@7009
   193
void
kimonline@7009
   194
PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
kimonline@7009
   195
{
kimonline@7009
   196
kimonline@7009
   197
}
kimonline@7009
   198
kimonline@7009
   199
int
kimonline@7009
   200
PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
kimonline@7009
   201
{
kimonline@7009
   202
    return 0;
kimonline@7009
   203
}
kimonline@7009
   204
#define EGLCHK(stmt)							\
kimonline@7009
   205
	do {										\
kimonline@7009
   206
		EGLint err;								\
kimonline@7009
   207
												\
kimonline@7009
   208
		stmt;									\
kimonline@7009
   209
		err = eglGetError();					\
kimonline@7009
   210
		if (err != EGL_SUCCESS) {				\
kimonline@7009
   211
			SDL_SetError("EGL error %d", err);	\
kimonline@7009
   212
			return 0;							\
kimonline@7009
   213
		}										\
kimonline@7009
   214
	} while (0)
kimonline@7009
   215
	
kimonline@7009
   216
int
kimonline@7009
   217
PSP_CreateWindow(_THIS, SDL_Window * window)
kimonline@7009
   218
{
kimonline@7009
   219
//    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
kimonline@7009
   220
kimonline@7009
   221
    SDL_WindowData *wdata;
kimonline@7009
   222
kimonline@7009
   223
    /* Allocate window internal data */
kimonline@7009
   224
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
kimonline@7009
   225
    if (wdata == NULL) {
kimonline@7009
   226
        SDL_OutOfMemory();
kimonline@7009
   227
        return -1;
kimonline@7009
   228
    }
kimonline@7009
   229
kimonline@7009
   230
    /* Setup driver data for this window */
kimonline@7009
   231
    window->driverdata = wdata;
kimonline@7009
   232
kimonline@7009
   233
kimonline@7009
   234
    /* Window has been successfully created */
kimonline@7009
   235
    return 0;
kimonline@7009
   236
}
kimonline@7009
   237
kimonline@7009
   238
int
kimonline@7009
   239
PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
kimonline@7009
   240
{
kimonline@7009
   241
    return -1;
kimonline@7009
   242
}
kimonline@7009
   243
kimonline@7009
   244
void
kimonline@7009
   245
PSP_SetWindowTitle(_THIS, SDL_Window * window)
kimonline@7009
   246
{
kimonline@7009
   247
}
kimonline@7009
   248
void
kimonline@7009
   249
PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
kimonline@7009
   250
{
kimonline@7009
   251
}
kimonline@7009
   252
void
kimonline@7009
   253
PSP_SetWindowPosition(_THIS, SDL_Window * window)
kimonline@7009
   254
{
kimonline@7009
   255
}
kimonline@7009
   256
void
kimonline@7009
   257
PSP_SetWindowSize(_THIS, SDL_Window * window)
kimonline@7009
   258
{
kimonline@7009
   259
}
kimonline@7009
   260
void
kimonline@7009
   261
PSP_ShowWindow(_THIS, SDL_Window * window)
kimonline@7009
   262
{
kimonline@7009
   263
}
kimonline@7009
   264
void
kimonline@7009
   265
PSP_HideWindow(_THIS, SDL_Window * window)
kimonline@7009
   266
{
kimonline@7009
   267
}
kimonline@7009
   268
void
kimonline@7009
   269
PSP_RaiseWindow(_THIS, SDL_Window * window)
kimonline@7009
   270
{
kimonline@7009
   271
}
kimonline@7009
   272
void
kimonline@7009
   273
PSP_MaximizeWindow(_THIS, SDL_Window * window)
kimonline@7009
   274
{
kimonline@7009
   275
}
kimonline@7009
   276
void
kimonline@7009
   277
PSP_MinimizeWindow(_THIS, SDL_Window * window)
kimonline@7009
   278
{
kimonline@7009
   279
}
kimonline@7009
   280
void
kimonline@7009
   281
PSP_RestoreWindow(_THIS, SDL_Window * window)
kimonline@7009
   282
{
kimonline@7009
   283
}
kimonline@7009
   284
void
kimonline@7009
   285
PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
kimonline@7009
   286
{
kimonline@7009
   287
kimonline@7009
   288
}
kimonline@7009
   289
void
kimonline@7009
   290
PSP_DestroyWindow(_THIS, SDL_Window * window)
kimonline@7009
   291
{
kimonline@7009
   292
	
kimonline@7009
   293
//    eglTerminate(_this->gl_data->display);
kimonline@7009
   294
}
kimonline@7009
   295
kimonline@7009
   296
/*****************************************************************************/
kimonline@7009
   297
/* SDL Window Manager function                                               */
kimonline@7009
   298
/*****************************************************************************/
kimonline@7009
   299
SDL_bool
kimonline@7009
   300
PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
kimonline@7009
   301
{
kimonline@7009
   302
    if (info->version.major <= SDL_MAJOR_VERSION) {
kimonline@7009
   303
        return SDL_TRUE;
kimonline@7009
   304
    } else {
kimonline@7009
   305
        SDL_SetError("application not compiled with SDL %d.%d\n",
kimonline@7009
   306
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
kimonline@7009
   307
        return SDL_FALSE;
kimonline@7009
   308
    }
kimonline@7009
   309
kimonline@7009
   310
    /* Failed to get window manager information */
kimonline@7009
   311
    return SDL_FALSE;
kimonline@7009
   312
}
kimonline@7009
   313
kimonline@7009
   314
kimonline@7009
   315
/* TO Write Me*/
kimonline@7009
   316
SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS)
kimonline@7009
   317
{
kimonline@7009
   318
	return SDL_TRUE;
kimonline@7009
   319
}
kimonline@7009
   320
void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window)
kimonline@7009
   321
{
kimonline@7009
   322
}
kimonline@7009
   323
void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window)
kimonline@7009
   324
{
kimonline@7009
   325
}
kimonline@7009
   326
SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window)
kimonline@7009
   327
{
kimonline@7009
   328
	return SDL_FALSE;
kimonline@7009
   329
}
kimonline@7009
   330
kimonline@7009
   331
kimonline@7009
   332
#endif /* SDL_VIDEO_DRIVER_PSP */
kimonline@7009
   333
kimonline@7009
   334
/* vi: set ts=4 sw=4 expandtab: */