SDL  2.0
video.c File Reference
#include "../../SDL_internal.h"
#include "../SDL_sysvideo.h"
#include "sdl_qnx.h"
+ Include dependency graph for video.c:

Go to the source code of this file.

Functions

static int videoInit (_THIS)
 
static void videoQuit (_THIS)
 
static int createWindow (_THIS, SDL_Window *window)
 
static int createWindowFramebuffer (_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
 
static int updateWindowFramebuffer (_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
 
static void pumpEvents (_THIS)
 
static void setWindowSize (_THIS, SDL_Window *window)
 
static void showWindow (_THIS, SDL_Window *window)
 
static void hideWindow (_THIS, SDL_Window *window)
 
static void destroyWindow (_THIS, SDL_Window *window)
 
static void deleteDevice (SDL_VideoDevice *device)
 
static SDL_VideoDevicecreateDevice (int devindex)
 
static int available ()
 

Variables

static screen_context_t context
 
static screen_event_t event
 
VideoBootStrap QNX_bootstrap
 

Function Documentation

◆ available()

static int available ( )
static

Definition at line 356 of file video.c.

Referenced by SDL_VideoInit().

357 {
358  return 1;
359 }

◆ createDevice()

static SDL_VideoDevice* createDevice ( int  devindex)
static

Creates the QNX video plugin used by SDL.

Parameters
devindexUnused
Returns
Initialized device if successful, NULL otherwise

Definition at line 321 of file video.c.

References SDL_VideoDevice::CreateSDLWindow, createWindow(), createWindowFramebuffer(), SDL_VideoDevice::CreateWindowFramebuffer, deleteDevice(), SDL_VideoDevice::DestroyWindow, destroyWindow(), device, SDL_VideoDevice::driverdata, SDL_VideoDevice::free, SDL_VideoDevice::GL_CreateContext, SDL_VideoDevice::GL_DeleteContext, SDL_VideoDevice::GL_GetProcAddress, SDL_VideoDevice::GL_LoadLibrary, SDL_VideoDevice::GL_MakeCurrent, SDL_VideoDevice::GL_SetSwapInterval, SDL_VideoDevice::GL_SwapWindow, SDL_VideoDevice::GL_UnloadLibrary, glCreateContext(), glDeleteContext(), glGetProcAddress(), glLoadLibrary(), glMakeCurrent(), glSetSwapInterval(), glSwapWindow(), glUnloadLibrary(), SDL_VideoDevice::HideWindow, hideWindow(), NULL, pumpEvents(), SDL_VideoDevice::PumpEvents, SDL_calloc, SDL_VideoDevice::SetWindowSize, setWindowSize(), SDL_VideoDevice::ShowWindow, showWindow(), updateWindowFramebuffer(), SDL_VideoDevice::UpdateWindowFramebuffer, videoInit(), SDL_VideoDevice::VideoInit, videoQuit(), and SDL_VideoDevice::VideoQuit.

322 {
324 
325  device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
326  if (device == NULL) {
327  return NULL;
328  }
329 
330  device->driverdata = NULL;
331  device->VideoInit = videoInit;
332  device->VideoQuit = videoQuit;
333  device->CreateSDLWindow = createWindow;
336  device->SetWindowSize = setWindowSize;
337  device->ShowWindow = showWindow;
338  device->HideWindow = hideWindow;
339  device->PumpEvents = pumpEvents;
340  device->DestroyWindow = destroyWindow;
341 
342  device->GL_LoadLibrary = glLoadLibrary;
346  device->GL_SwapWindow = glSwapWindow;
347  device->GL_MakeCurrent = glMakeCurrent;
350 
351  device->free = deleteDevice;
352  return device;
353 }
static int updateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
Definition: video.c:190
static int videoInit(_THIS)
Definition: video.c:36
SDL_GLContext glCreateContext(_THIS, SDL_Window *window)
Definition: gl.c:171
void(* free)(_THIS)
Definition: SDL_sysvideo.h:390
void glUnloadLibrary(_THIS)
Definition: gl.c:282
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:260
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:222
int glLoadLibrary(_THIS, const char *name)
Definition: gl.c:136
void(* SetWindowSize)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:215
static void setWindowSize(_THIS, SDL_Window *window)
Definition: video.c:246
static void hideWindow(_THIS, SDL_Window *window)
Definition: video.c:280
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:254
void glDeleteContext(_THIS, SDL_GLContext context)
Definition: gl.c:272
static void pumpEvents(_THIS)
Definition: video.c:211
int glSetSwapInterval(_THIS, int interval)
Definition: gl.c:218
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:223
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:257
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:258
static int createWindow(_THIS, SDL_Window *window)
Definition: video.c:71
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:234
static void showWindow(_THIS, SDL_Window *window)
Definition: video.c:265
static int createWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
Definition: video.c:154
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:256
#define NULL
Definition: begin_code.h:164
int(* CreateSDLWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:210
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:166
#define SDL_calloc
int(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:262
static void destroyWindow(_THIS, SDL_Window *window)
Definition: video.c:295
void * glGetProcAddress(_THIS, const char *proc)
Definition: gl.c:158
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:160
int(* UpdateWindowFramebuffer)(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
Definition: SDL_sysvideo.h:236
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:263
static void videoQuit(_THIS)
Definition: video.c:59
int glMakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: gl.c:249
int glSwapWindow(_THIS, SDL_Window *window)
Definition: gl.c:234
int(* CreateWindowFramebuffer)(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
Definition: SDL_sysvideo.h:235
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:255
static void deleteDevice(SDL_VideoDevice *device)
Definition: video.c:310
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:280

◆ createWindow()

static int createWindow ( _THIS  ,
SDL_Window window 
)
static

Creates a new native Screen window and associates it with the given SDL window.

Parameters
_THIS
windowSDL window to initialize
Returns
0 if successful, -1 on error

Definition at line 71 of file video.c.

References window_impl_t::conf, context, SDL_Window::driverdata, SDL_Window::flags, glGetConfig(), SDL_Window::h, NULL, SDL_calloc, SDL_free, SDL_WINDOW_OPENGL, SDL_Window::w, and window_impl_t::window.

Referenced by createDevice().

72 {
73  window_impl_t *impl;
74  int size[2];
75  int numbufs;
76  int format;
77  int usage;
78 
79  impl = SDL_calloc(1, sizeof(*impl));
80  if (impl == NULL) {
81  return -1;
82  }
83 
84  // Create a native window.
85  if (screen_create_window(&impl->window, context) < 0) {
86  goto fail;
87  }
88 
89  // Set the native window's size to match the SDL window.
90  size[0] = window->w;
91  size[1] = window->h;
92 
93  if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE,
94  size) < 0) {
95  goto fail;
96  }
97 
98  if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE,
99  size) < 0) {
100  goto fail;
101  }
102 
103  // Create window buffer(s).
104  if (window->flags & SDL_WINDOW_OPENGL) {
105  if (glGetConfig(&impl->conf, &format) < 0) {
106  goto fail;
107  }
108  numbufs = 2;
109 
110  usage = SCREEN_USAGE_OPENGL_ES2;
111  if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_USAGE,
112  &usage) < 0) {
113  return -1;
114  }
115  } else {
116  format = SCREEN_FORMAT_RGBX8888;
117  numbufs = 1;
118  }
119 
120  // Set pixel format.
121  if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_FORMAT,
122  &format) < 0) {
123  goto fail;
124  }
125 
126  // Create buffer(s).
127  if (screen_create_window_buffers(impl->window, numbufs) < 0) {
128  goto fail;
129  }
130 
131  window->driverdata = impl;
132  return 0;
133 
134 fail:
135  if (impl->window) {
136  screen_destroy_window(impl->window);
137  }
138 
139  SDL_free(impl);
140  return -1;
141 }
int glGetConfig(EGLConfig *pconf, int *pformat)
Definition: gl.c:68
EGLConfig conf
Definition: sdl_qnx.h:33
static screen_context_t context
Definition: video.c:25
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
GLsizeiptr const void GLenum usage
#define SDL_free
screen_window_t window
Definition: sdl_qnx.h:31
GLsizeiptr size
#define NULL
Definition: begin_code.h:164
#define SDL_calloc
void * driverdata
Definition: SDL_sysvideo.h:111
Uint32 flags
Definition: SDL_sysvideo.h:83

◆ createWindowFramebuffer()

static int createWindowFramebuffer ( _THIS  ,
SDL_Window window,
Uint32 format,
void **  pixels,
int *  pitch 
)
static

Gets a pointer to the Screen buffer associated with the given window. Note that the buffer is actually created in createWindow().

Parameters
_THIS
windowSDL window to get the buffer for
[out]pixlesHolds a pointer to the window's buffer
[out]formatHolds the pixel format for the buffer
[out]pitchHolds the number of bytes per line
Returns
0 if successful, -1 on error

Definition at line 154 of file video.c.

References SDL_Window::driverdata, SDL_PIXELFORMAT_RGB888, and window_impl_t::window.

Referenced by createDevice().

156 {
157  window_impl_t *impl = (window_impl_t *)window->driverdata;
158  screen_buffer_t buffer;
159 
160  // Get a pointer to the buffer's memory.
161  if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS,
162  (void **)&buffer) < 0) {
163  return -1;
164  }
165 
166  if (screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER,
167  pixels) < 0) {
168  return -1;
169  }
170 
171  // Set format and pitch.
172  if (screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE,
173  pitch) < 0) {
174  return -1;
175  }
176 
178  return 0;
179 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
screen_window_t window
Definition: sdl_qnx.h:31
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
GLuint buffer
void * driverdata
Definition: SDL_sysvideo.h:111

◆ deleteDevice()

static void deleteDevice ( SDL_VideoDevice device)
static

Frees the plugin object created by createDevice().

Parameters
devicePlugin object to free

Definition at line 310 of file video.c.

References SDL_free.

Referenced by createDevice().

311 {
312  SDL_free(device);
313 }
#define SDL_free

◆ destroyWindow()

static void destroyWindow ( _THIS  ,
SDL_Window window 
)
static

Destroys the native window associated with the given SDL window.

Parameters
_THIS
windowSDL window that is being destroyed

Definition at line 295 of file video.c.

References SDL_Window::driverdata, NULL, and window_impl_t::window.

Referenced by createDevice().

296 {
297  window_impl_t *impl = (window_impl_t *)window->driverdata;
298 
299  if (impl) {
300  screen_destroy_window(impl->window);
301  window->driverdata = NULL;
302  }
303 }
screen_window_t window
Definition: sdl_qnx.h:31
#define NULL
Definition: begin_code.h:164
void * driverdata
Definition: SDL_sysvideo.h:111

◆ hideWindow()

static void hideWindow ( _THIS  ,
SDL_Window window 
)
static

Makes the native window associated with the given SDL window invisible.

Parameters
_THIS
windowSDL window to update

Definition at line 280 of file video.c.

References SDL_Window::driverdata, and window_impl_t::window.

Referenced by createDevice().

281 {
282  window_impl_t *impl = (window_impl_t *)window->driverdata;
283  const int visible = 0;
284 
285  screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE,
286  &visible);
287 }
screen_window_t window
Definition: sdl_qnx.h:31
void * driverdata
Definition: SDL_sysvideo.h:111

◆ pumpEvents()

static void pumpEvents ( _THIS  )
static

Runs the main event loop.

Parameters
_THIS

Definition at line 211 of file video.c.

References context, and handleKeyboardEvent().

Referenced by createDevice().

212 {
213  int type;
214 
215  for (;;) {
216  if (screen_get_event(context, event, 0) < 0) {
217  break;
218  }
219 
220  if (screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type)
221  < 0) {
222  break;
223  }
224 
225  if (type == SCREEN_EVENT_NONE) {
226  break;
227  }
228 
229  switch (type) {
230  case SCREEN_EVENT_KEYBOARD:
232  break;
233 
234  default:
235  break;
236  }
237  }
238 }
static screen_context_t context
Definition: video.c:25
struct _cl_event * event
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
void handleKeyboardEvent(screen_event_t event)
Definition: keyboard.c:99

◆ setWindowSize()

static void setWindowSize ( _THIS  ,
SDL_Window window 
)
static

Updates the size of the native window using the geometry of the SDL window.

Parameters
_THIS
windowSDL window to update

Definition at line 246 of file video.c.

References SDL_Window::driverdata, SDL_Window::h, SDL_Window::w, and window_impl_t::window.

Referenced by createDevice().

247 {
248  window_impl_t *impl = (window_impl_t *)window->driverdata;
249  int size[2];
250 
251  size[0] = window->w;
252  size[1] = window->h;
253 
254  screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE, size);
255  screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE,
256  size);
257 }
screen_window_t window
Definition: sdl_qnx.h:31
GLsizeiptr size
void * driverdata
Definition: SDL_sysvideo.h:111

◆ showWindow()

static void showWindow ( _THIS  ,
SDL_Window window 
)
static

Makes the native window associated with the given SDL window visible.

Parameters
_THIS
windowSDL window to update

Definition at line 265 of file video.c.

References SDL_Window::driverdata, and window_impl_t::window.

Referenced by createDevice().

266 {
267  window_impl_t *impl = (window_impl_t *)window->driverdata;
268  const int visible = 1;
269 
270  screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE,
271  &visible);
272 }
screen_window_t window
Definition: sdl_qnx.h:31
void * driverdata
Definition: SDL_sysvideo.h:111

◆ updateWindowFramebuffer()

static int updateWindowFramebuffer ( _THIS  ,
SDL_Window window,
const SDL_Rect rects,
int  numrects 
)
static

Informs the window manager that the window needs to be updated.

Parameters
_THIS
windowThe window to update
rectsAn array of reectangular areas to update
numrectsRect array length
Returns
0 if successful, -1 on error

Definition at line 190 of file video.c.

References context, SDL_Window::driverdata, and window_impl_t::window.

Referenced by createDevice().

192 {
193  window_impl_t *impl = (window_impl_t *)window->driverdata;
194  screen_buffer_t buffer;
195 
196  if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS,
197  (void **)&buffer) < 0) {
198  return -1;
199  }
200 
201  screen_post_window(impl->window, buffer, numrects, (int *)rects, 0);
202  screen_flush_context(context, 0);
203  return 0;
204 }
static screen_context_t context
Definition: video.c:25
screen_window_t window
Definition: sdl_qnx.h:31
GLuint buffer
void * driverdata
Definition: SDL_sysvideo.h:111

◆ videoInit()

static int videoInit ( _THIS  )
static

Initializes the QNX video plugin. Creates the Screen context and event handles used for all window operations by the plugin.

Parameters
_THIS
Returns
0 if successful, -1 on error

Definition at line 36 of file video.c.

References _this, context, SDL_VideoDevice::num_displays, SDL_AddVideoDisplay(), and SDL_zero.

Referenced by createDevice().

37 {
38  SDL_VideoDisplay display;
39 
40  if (screen_create_context(&context, 0) < 0) {
41  return -1;
42  }
43 
44  if (screen_create_event(&event) < 0) {
45  return -1;
46  }
47 
48  SDL_zero(display);
49 
50  if (SDL_AddVideoDisplay(&display) < 0) {
51  return -1;
52  }
53 
54  _this->num_displays = 1;
55  return 0;
56 }
static screen_context_t context
Definition: video.c:25
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
Definition: SDL_video.c:606
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
struct _cl_event * event
#define SDL_zero(x)
Definition: SDL_stdinc.h:416

◆ videoQuit()

static void videoQuit ( _THIS  )
static

Definition at line 59 of file video.c.

Referenced by createDevice().

60 {
61 }

Variable Documentation

◆ context

screen_context_t context
static

◆ event

screen_event_t event
static

Definition at line 26 of file video.c.

◆ QNX_bootstrap

VideoBootStrap QNX_bootstrap
Initial value:
= {
"qnx", "QNX Screen",
}
static int available()
Definition: video.c:356
static SDL_VideoDevice * createDevice(int devindex)
Definition: video.c:321

Definition at line 361 of file video.c.