SDL  2.0
SDL_naclvideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2019 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 */
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 */
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 
110  device->CreateSDLWindow = NACL_CreateWindow;
111  device->SetWindowTitle = NACL_SetWindowTitle;
112  device->DestroyWindow = NACL_DestroyWindow;
113 
114  device->SetDisplayMode = NACL_SetDisplayMode;
115 
116  device->free = NACL_DeleteDevice;
117 
118  /* GL pointers */
119  device->GL_LoadLibrary = NACL_GLES_LoadLibrary;
120  device->GL_GetProcAddress = NACL_GLES_GetProcAddress;
121  device->GL_UnloadLibrary = NACL_GLES_UnloadLibrary;
122  device->GL_CreateContext = NACL_GLES_CreateContext;
123  device->GL_MakeCurrent = NACL_GLES_MakeCurrent;
124  device->GL_SetSwapInterval = NACL_GLES_SetSwapInterval;
125  device->GL_GetSwapInterval = NACL_GLES_GetSwapInterval;
126  device->GL_SwapWindow = NACL_GLES_SwapWindow;
127  device->GL_DeleteContext = NACL_GLES_DeleteContext;
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: */
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_VideoData::format
Uint32 format
Definition: SDL_naclvideo.h:38
SDL_naclevents_c.h
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1571
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:381
SDL_naclopengles.h
NACL_GLES_SetSwapInterval
int NACL_GLES_SetSwapInterval(_THIS, int interval)
SDL_naclvideo.h
NULL
#define NULL
Definition: begin_code.h:167
NACL_DestroyWindow
void NACL_DestroyWindow(_THIS, SDL_Window *window)
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1571
SDL_VideoData::ppb_mouse_input_event
const PPB_MouseInputEvent * ppb_mouse_input_event
Definition: SDL_naclvideo.h:52
SDL_VideoData::h
int h
Definition: SDL_naclvideo.h:39
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
SDL_VideoData::ppb_view
const PPB_View * ppb_view
Definition: SDL_naclvideo.h:48
SDL_VideoData::ppb_input_event
const PPB_InputEvent * ppb_input_event
Definition: SDL_naclvideo.h:50
NACL_PumpEvents
void NACL_PumpEvents(_THIS)
SDL_naclwindow.h
NACL_SetScreenResolution
void NACL_SetScreenResolution(int width, int height, Uint32 format)
SDL_VideoData::w
int w
Definition: SDL_naclvideo.h:39
NACL_GLES_GetProcAddress
void * NACL_GLES_GetProcAddress(_THIS, const char *proc)
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_AddDisplayMode
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:751
SDL_VideoData::ppb_message_loop
const PPB_MessageLoop * ppb_message_loop
Definition: SDL_naclvideo.h:43
SDL_Window::w
int w
Definition: SDL_sysvideo.h:80
context
static screen_context_t context
Definition: video.c:25
SDL_VideoData::ppb_keyboard_input_event
const PPB_KeyboardInputEvent * ppb_keyboard_input_event
Definition: SDL_naclvideo.h:51
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
SDL_VideoData::instance
PP_Instance instance
Definition: SDL_naclvideo.h:57
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_VideoData::ppb_image_data
const PPB_ImageData * ppb_image_data
Definition: SDL_naclvideo.h:47
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1571
NACL_GLES_MakeCurrent
int NACL_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_VideoDevice::displays
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:316
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
NACL_GLES_UnloadLibrary
void NACL_GLES_UnloadLibrary(_THIS)
NACL_GLES_DeleteContext
void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
SDL_VideoData::message_loop
PP_Resource message_loop
Definition: SDL_naclvideo.h:56
SDL_GL_GetCurrentContext
#define SDL_GL_GetCurrentContext
Definition: SDL_dynapi_overrides.h:562
NACL_bootstrap
VideoBootStrap NACL_bootstrap
SDL_Window::h
int h
Definition: SDL_sysvideo.h:80
NACL_GLES_CreateContext
SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window *window)
SDL_VideoDevice
Definition: SDL_sysvideo.h:148
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_VideoData::window
SDL_Window * window
Definition: SDL_naclvideo.h:40
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_VideoData::ppb_var
const PPB_Var * ppb_var
Definition: SDL_naclvideo.h:49
SDL_AddBasicVideoDisplay
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:589
SDL_VideoData::ppb_wheel_input_event
const PPB_WheelInputEvent * ppb_wheel_input_event
Definition: SDL_naclvideo.h:53
NACL_CreateWindow
int NACL_CreateWindow(_THIS, SDL_Window *window)
SDL_VideoData::ppb_core
const PPB_Core * ppb_core
Definition: SDL_naclvideo.h:44
SDL_VideoDisplay
Definition: SDL_sysvideo.h:125
NACL_GLES_LoadLibrary
int NACL_GLES_LoadLibrary(_THIS, const char *path)
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_VideoData::ppb_fullscreen
const PPB_Fullscreen * ppb_fullscreen
Definition: SDL_naclvideo.h:45
SDL_video.h
VideoBootStrap
Definition: SDL_sysvideo.h:397
SDL_VideoData::ppb_instance
const PPB_Instance * ppb_instance
Definition: SDL_naclvideo.h:46
SDL_VideoData::ppb_graphics
const PPB_Graphics3D * ppb_graphics
Definition: SDL_naclvideo.h:42
NACL_GLES_GetSwapInterval
int NACL_GLES_GetSwapInterval(_THIS)
SDL_VideoData::ppb_touch_input_event
const PPB_TouchInputEvent * ppb_touch_input_event
Definition: SDL_naclvideo.h:54
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
NACL_SetWindowTitle
void NACL_SetWindowTitle(_THIS, SDL_Window *window)
NACL_GLES_SwapWindow
int NACL_GLES_SwapWindow(_THIS, SDL_Window *window)
SDL_VideoData
Definition: SDL_androidvideo.h:36