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 */
46static SDL_VideoData nacl = {0};
47
48void
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 */
74static int NACL_VideoInit(_THIS);
75static void NACL_VideoQuit(_THIS);
76
77static int NACL_Available(void) {
78 return PSGetInstanceId() != 0;
79}
80
81static 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
88static int
89NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
90{
91 return 0;
92}
93
94static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
96
97 /* Initialize all variables that we clean on shutdown */
99 if (!device) {
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
138int 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
179void NACL_VideoQuit(_THIS) {
180}
181
182#endif /* SDL_VIDEO_DRIVER_NACL */
183/* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_free
#define SDL_calloc
#define SDL_GL_GetCurrentContext
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
void NACL_PumpEvents(_THIS)
int NACL_GLES_SwapWindow(_THIS, SDL_Window *window)
int NACL_GLES_GetSwapInterval(_THIS)
void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
void * NACL_GLES_GetProcAddress(_THIS, const char *proc)
int NACL_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int NACL_GLES_SetSwapInterval(_THIS, int interval)
void NACL_GLES_UnloadLibrary(_THIS)
int NACL_GLES_LoadLibrary(_THIS, const char *path)
SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window *window)
void NACL_SetScreenResolution(int width, int height, Uint32 format)
void NACL_SetWindowTitle(_THIS, SDL_Window *window)
void NACL_DestroyWindow(_THIS, SDL_Window *window)
int NACL_CreateWindow(_THIS, SDL_Window *window)
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
GLenum mode
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
uint32_t Uint32
Definition: SDL_stdinc.h:203
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:589
VideoBootStrap NACL_bootstrap
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:751
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define NULL
Definition: begin_code.h:167
static SDL_AudioDeviceID device
Definition: loopwave.c:37
The structure that defines a display mode.
Definition: SDL_video.h:54
const PPB_InputEvent * ppb_input_event
Definition: SDL_naclvideo.h:50
const PPB_TouchInputEvent * ppb_touch_input_event
Definition: SDL_naclvideo.h:54
SDL_Window * window
Definition: SDL_naclvideo.h:40
const PPB_WheelInputEvent * ppb_wheel_input_event
Definition: SDL_naclvideo.h:53
const PPB_Var * ppb_var
Definition: SDL_naclvideo.h:49
const PPB_View * ppb_view
Definition: SDL_naclvideo.h:48
const PPB_KeyboardInputEvent * ppb_keyboard_input_event
Definition: SDL_naclvideo.h:51
const PPB_Instance * ppb_instance
Definition: SDL_naclvideo.h:46
const PPB_ImageData * ppb_image_data
Definition: SDL_naclvideo.h:47
const PPB_Fullscreen * ppb_fullscreen
Definition: SDL_naclvideo.h:45
PP_Resource message_loop
Definition: SDL_naclvideo.h:56
const PPB_Graphics3D * ppb_graphics
Definition: SDL_naclvideo.h:42
const PPB_MessageLoop * ppb_message_loop
Definition: SDL_naclvideo.h:43
const PPB_Core * ppb_core
Definition: SDL_naclvideo.h:44
PP_Instance instance
Definition: SDL_naclvideo.h:57
const PPB_MouseInputEvent * ppb_mouse_input_event
Definition: SDL_naclvideo.h:52
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:316
static screen_context_t context
Definition: video.c:25