src/video/nacl/SDL_naclvideo.c
changeset 8833 ae720d61d14d
child 8873 77ffe680093f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/nacl/SDL_naclvideo.c	Fri Jun 06 15:45:59 2014 -0300
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2014 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 +#include "../../SDL_internal.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_NACL
    1.27 +
    1.28 +#include "ppapi/c/pp_errors.h"
    1.29 +#include "ppapi/c/pp_instance.h"
    1.30 +#include "ppapi_simple/ps.h"
    1.31 +#include "ppapi_simple/ps_interface.h"
    1.32 +#include "ppapi_simple/ps_event.h"
    1.33 +#include "nacl_io/nacl_io.h"
    1.34 +
    1.35 +#include "SDL_naclvideo.h"
    1.36 +#include "SDL_naclwindow.h"
    1.37 +#include "SDL_naclevents_c.h"
    1.38 +#include "SDL_naclopengles.h"   
    1.39 +#include "SDL_video.h"
    1.40 +#include "../SDL_sysvideo.h"
    1.41 +#include "../../events/SDL_events_c.h"
    1.42 +
    1.43 +#define NACLVID_DRIVER_NAME "nacl"
    1.44 +
    1.45 +/* Static init required because NACL_SetScreenResolution 
    1.46 + * may appear even before SDL starts and we want to remember
    1.47 + * the window width and height
    1.48 + */
    1.49 +static SDL_VideoData nacl = {0};
    1.50 +
    1.51 +void
    1.52 +NACL_SetScreenResolution(int width, int height, Uint32 format)
    1.53 +{
    1.54 +    PP_Resource context;
    1.55 +    
    1.56 +    nacl.w = width;
    1.57 +    nacl.h = height;   
    1.58 +    nacl.format = format;
    1.59 +    
    1.60 +    if (nacl.window) {
    1.61 +        nacl.window->w = width;
    1.62 +        nacl.window->h = height;
    1.63 +        SDL_SendWindowEvent(nacl.window, SDL_WINDOWEVENT_RESIZED, width, height);
    1.64 +    }
    1.65 +    
    1.66 +    /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
    1.67 +    context = (PP_Resource) SDL_GL_GetCurrentContext();
    1.68 +    if (context) {
    1.69 +        PSInterfaceGraphics3D()->ResizeBuffers(context, width, height);
    1.70 +    }
    1.71 +
    1.72 +}
    1.73 +
    1.74 +
    1.75 +
    1.76 +/* Initialization/Query functions */
    1.77 +static int NACL_VideoInit(_THIS);
    1.78 +static void NACL_VideoQuit(_THIS);
    1.79 +
    1.80 +static int NACL_Available(void) {
    1.81 +    return PSGetInstanceId() != 0;
    1.82 +}
    1.83 +
    1.84 +static void NACL_DeleteDevice(SDL_VideoDevice *device) {
    1.85 +    SDL_VideoData *driverdata = (SDL_VideoData*) device->driverdata;
    1.86 +    driverdata->ppb_core->ReleaseResource((PP_Resource) driverdata->ppb_message_loop);
    1.87 +    SDL_free(device->driverdata);
    1.88 +    SDL_free(device);
    1.89 +}
    1.90 +
    1.91 +static int
    1.92 +NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
    1.93 +{
    1.94 +    return 0;
    1.95 +}
    1.96 +
    1.97 +static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
    1.98 +    SDL_VideoDevice *device;
    1.99 +    
   1.100 +    /* Initialize all variables that we clean on shutdown */
   1.101 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   1.102 +    if (!device) {
   1.103 +        SDL_OutOfMemory();
   1.104 +        return NULL;
   1.105 +    }
   1.106 +    device->driverdata = &nacl;
   1.107 +  
   1.108 +    /* Set the function pointers */
   1.109 +    device->VideoInit = NACL_VideoInit;
   1.110 +    device->VideoQuit = NACL_VideoQuit;
   1.111 +    device->PumpEvents = NACL_PumpEvents;
   1.112 +    
   1.113 +    device->CreateWindow = NACL_CreateWindow;
   1.114 +    device->SetWindowTitle = NACL_SetWindowTitle;
   1.115 +    device->DestroyWindow = NACL_DestroyWindow;
   1.116 +    
   1.117 +    device->SetDisplayMode = NACL_SetDisplayMode;
   1.118 +    
   1.119 +    device->free = NACL_DeleteDevice;
   1.120 +    
   1.121 +    /* GL pointers */
   1.122 +    device->GL_LoadLibrary = NACL_GLES_LoadLibrary;
   1.123 +    device->GL_GetProcAddress = NACL_GLES_GetProcAddress;
   1.124 +    device->GL_UnloadLibrary = NACL_GLES_UnloadLibrary;
   1.125 +    device->GL_CreateContext = NACL_GLES_CreateContext;
   1.126 +    device->GL_MakeCurrent = NACL_GLES_MakeCurrent;
   1.127 +    device->GL_SetSwapInterval = NACL_GLES_SetSwapInterval;
   1.128 +    device->GL_GetSwapInterval = NACL_GLES_GetSwapInterval;
   1.129 +    device->GL_SwapWindow = NACL_GLES_SwapWindow;
   1.130 +    device->GL_DeleteContext = NACL_GLES_DeleteContext;
   1.131 +    
   1.132 +    
   1.133 +    return device;
   1.134 +}
   1.135 +
   1.136 +VideoBootStrap NACL_bootstrap = {
   1.137 +    NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
   1.138 +    NACL_Available, NACL_CreateDevice
   1.139 +};
   1.140 +
   1.141 +int NACL_VideoInit(_THIS) {
   1.142 +    SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
   1.143 +    SDL_DisplayMode mode;
   1.144 +
   1.145 +    mode.format = driverdata->format;
   1.146 +    mode.w = driverdata->w;
   1.147 +    mode.h = driverdata->h;
   1.148 +    mode.refresh_rate = 0;
   1.149 +    mode.driverdata = NULL;
   1.150 +    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   1.151 +        return -1;
   1.152 +    }
   1.153 +    
   1.154 +    SDL_zero(mode);
   1.155 +    SDL_AddDisplayMode(&_this->displays[0], &mode);
   1.156 +    
   1.157 +    PSInterfaceInit();
   1.158 +    driverdata->instance = PSGetInstanceId();
   1.159 +    driverdata->ppb_graphics = PSInterfaceGraphics3D();
   1.160 +    driverdata->ppb_message_loop = PSInterfaceMessageLoop();
   1.161 +    driverdata->ppb_core = PSInterfaceCore();
   1.162 +    driverdata->ppb_fullscreen = PSInterfaceFullscreen();
   1.163 +    driverdata->ppb_instance = PSInterfaceInstance();
   1.164 +    driverdata->ppb_image_data = PSInterfaceImageData();
   1.165 +    driverdata->ppb_view = PSInterfaceView();
   1.166 +    driverdata->ppb_var = PSInterfaceVar();
   1.167 +    driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
   1.168 +    driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
   1.169 +    driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
   1.170 +    driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
   1.171 +    driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
   1.172 +    
   1.173 +    
   1.174 +    driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance);
   1.175 +    
   1.176 +    PSEventSetFilter(PSE_ALL);
   1.177 +    
   1.178 +    /* We're done! */
   1.179 +    return 0;
   1.180 +}
   1.181 +
   1.182 +void NACL_VideoQuit(_THIS) {
   1.183 +}
   1.184 +
   1.185 +#endif /* SDL_VIDEO_DRIVER_NACL */
   1.186 +/* vi: set ts=4 sw=4 expandtab: */
   1.187 \ No newline at end of file