SDL  2.0
SDL_naclvideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_NACL
24 
25 #include "ppapi/c/pp_errors.h"
26 #include "ppapi/c/pp_instance.h"
27 #include "ppapi_simple/ps.h"
28 #include "ppapi_simple/ps_interface.h"
29 #include "ppapi_simple/ps_event.h"
30 #include "nacl_io/nacl_io.h"
31 
32 #include "SDL_naclvideo.h"
33 #include "SDL_naclwindow.h"
34 #include "SDL_naclevents_c.h"
35 #include "SDL_naclopengles.h"
36 #include "SDL_video.h"
37 #include "../SDL_sysvideo.h"
38 #include "../../events/SDL_events_c.h"
39 
40 #define NACLVID_DRIVER_NAME "nacl"
41 
42 /* Static init required because NACL_SetScreenResolution
43  * may appear even before SDL starts and we want to remember
44  * the window width and height
45  */
46 static SDL_VideoData nacl = {0};
47 
48 void
50 {
51  PP_Resource context;
52 
53  nacl.w = width;
54  nacl.h = height;
55  nacl.format = format;
56 
57  if (nacl.window) {
58  nacl.window->w = width;
59  nacl.window->h = height;
61  }
62 
63  /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
64  context = (PP_Resource) SDL_GL_GetCurrentContext();
65  if (context) {
66  PSInterfaceGraphics3D()->ResizeBuffers(context, width, height);
67  }
68 
69 }
70 
71 
72 
73 /* Initialization/Query functions */
74 static int NACL_VideoInit(_THIS);
75 static void NACL_VideoQuit(_THIS);
76 
77 static int NACL_Available(void) {
78  return PSGetInstanceId() != 0;
79 }
80 
81 static void NACL_DeleteDevice(SDL_VideoDevice *device) {
82  SDL_VideoData *driverdata = (SDL_VideoData*) device->driverdata;
83  driverdata->ppb_core->ReleaseResource((PP_Resource) driverdata->ppb_message_loop);
84  /* device->driverdata is not freed because it points to static memory */
85  SDL_free(device);
86 }
87 
88 static int
89 NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
90 {
91  return 0;
92 }
93 
94 static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
96 
97  /* Initialize all variables that we clean on shutdown */
98  device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
99  if (!device) {
100  SDL_OutOfMemory();
101  return NULL;
102  }
103  device->driverdata = &nacl;
104 
105  /* Set the function pointers */
106  device->VideoInit = NACL_VideoInit;
107  device->VideoQuit = NACL_VideoQuit;
108  device->PumpEvents = NACL_PumpEvents;
109 
113 
114  device->SetDisplayMode = NACL_SetDisplayMode;
115 
116  device->free = NACL_DeleteDevice;
117 
118  /* GL pointers */
128 
129 
130  return device;
131 }
132 
134  NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
135  NACL_Available, NACL_CreateDevice
136 };
137 
138 int NACL_VideoInit(_THIS) {
139  SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
141 
142  SDL_zero(mode);
143  mode.format = driverdata->format;
144  mode.w = driverdata->w;
145  mode.h = driverdata->h;
146  mode.refresh_rate = 0;
147  mode.driverdata = NULL;
148  if (SDL_AddBasicVideoDisplay(&mode) < 0) {
149  return -1;
150  }
151 
153 
154  PSInterfaceInit();
155  driverdata->instance = PSGetInstanceId();
156  driverdata->ppb_graphics = PSInterfaceGraphics3D();
157  driverdata->ppb_message_loop = PSInterfaceMessageLoop();
158  driverdata->ppb_core = PSInterfaceCore();
159  driverdata->ppb_fullscreen = PSInterfaceFullscreen();
160  driverdata->ppb_instance = PSInterfaceInstance();
161  driverdata->ppb_image_data = PSInterfaceImageData();
162  driverdata->ppb_view = PSInterfaceView();
163  driverdata->ppb_var = PSInterfaceVar();
164  driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
165  driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
166  driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
167  driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
168  driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
169 
170 
171  driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance);
172 
173  PSEventSetFilter(PSE_ALL);
174 
175  /* We're done! */
176  return 0;
177 }
178 
179 void NACL_VideoQuit(_THIS) {
180 }
181 
182 #endif /* SDL_VIDEO_DRIVER_NACL */
183 /* vi: set ts=4 sw=4 expandtab: */
void NACL_SetWindowTitle(_THIS, SDL_Window *window)
const PPB_MouseInputEvent * ppb_mouse_input_event
Definition: SDL_naclvideo.h:52
const PPB_TouchInputEvent * ppb_touch_input_event
Definition: SDL_naclvideo.h:54
const PPB_WheelInputEvent * ppb_wheel_input_event
Definition: SDL_naclvideo.h:53
const PPB_Instance * ppb_instance
Definition: SDL_naclvideo.h:46
void(* free)(_THIS)
Definition: SDL_sysvideo.h:390
const PPB_Graphics3D * ppb_graphics
Definition: SDL_naclvideo.h:42
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:592
const PPB_InputEvent * ppb_input_event
Definition: SDL_naclvideo.h:50
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:260
PP_Resource message_loop
Definition: SDL_naclvideo.h:56
static screen_context_t context
Definition: video.c:25
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window *window)
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
uint32_t Uint32
Definition: SDL_stdinc.h:181
const PPB_View * ppb_view
Definition: SDL_naclvideo.h:48
VideoBootStrap NACL_bootstrap
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:254
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:204
SDL_Window * window
Definition: SDL_naclvideo.h:40
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:257
int NACL_GLES_SwapWindow(_THIS, SDL_Window *window)
#define _THIS
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:258
#define SDL_free
int NACL_CreateWindow(_THIS, SDL_Window *window)
GLenum mode
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:312
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:234
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
int NACL_GLES_GetSwapInterval(_THIS)
void NACL_SetScreenResolution(int width, int height, Uint32 format)
PP_Instance instance
Definition: SDL_naclvideo.h:57
int NACL_GLES_LoadLibrary(_THIS, const char *path)
const PPB_ImageData * ppb_image_data
Definition: SDL_naclvideo.h:47
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:256
void NACL_PumpEvents(_THIS)
const PPB_KeyboardInputEvent * ppb_keyboard_input_event
Definition: SDL_naclvideo.h:51
#define NULL
Definition: begin_code.h:164
int(* CreateSDLWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:210
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_GL_GetCurrentContext
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:166
int NACL_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
#define SDL_calloc
void NACL_DestroyWindow(_THIS, SDL_Window *window)
const PPB_Var * ppb_var
Definition: SDL_naclvideo.h:49
void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
void NACL_GLES_UnloadLibrary(_THIS)
const PPB_MessageLoop * ppb_message_loop
Definition: SDL_naclvideo.h:43
int(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:262
const PPB_Fullscreen * ppb_fullscreen
Definition: SDL_naclvideo.h:45
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:743
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:160
const PPB_Core * ppb_core
Definition: SDL_naclvideo.h:44
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:263
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:212
int(* GL_GetSwapInterval)(_THIS)
Definition: SDL_sysvideo.h:261
int NACL_GLES_SetSwapInterval(_THIS, int interval)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:255
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:280
void * NACL_GLES_GetProcAddress(_THIS, const char *proc)