SDL  2.0
SDL_test_common.h File Reference
#include "SDL.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDLTest_CommonState
 

Macros

#define DEFAULT_WINDOW_WIDTH   640
 
#define DEFAULT_WINDOW_HEIGHT   480
 
#define VERBOSE_VIDEO   0x00000001
 
#define VERBOSE_MODES   0x00000002
 
#define VERBOSE_RENDER   0x00000004
 
#define VERBOSE_EVENT   0x00000008
 
#define VERBOSE_AUDIO   0x00000010
 

Functions

SDLTest_CommonStateSDLTest_CommonCreateState (char **argv, Uint32 flags)
 Parse command line parameters and create common state. More...
 
int SDLTest_CommonArg (SDLTest_CommonState *state, int index)
 Process one common argument. More...
 
void SDLTest_CommonLogUsage (SDLTest_CommonState *state, const char *argv0, const char **options)
 Logs command line usage info. More...
 
const char * SDLTest_CommonUsage (SDLTest_CommonState *state)
 Returns common usage information. More...
 
SDL_bool SDLTest_CommonInit (SDLTest_CommonState *state)
 Open test window. More...
 
SDL_bool SDLTest_CommonDefaultArgs (SDLTest_CommonState *state, const int argc, char **argv)
 Easy argument handling when test app doesn't need any custom args. More...
 
void SDLTest_CommonEvent (SDLTest_CommonState *state, SDL_Event *event, int *done)
 Common event handler for test windows. More...
 
void SDLTest_CommonQuit (SDLTest_CommonState *state)
 Close test window. More...
 

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_common.h.

Macro Definition Documentation

◆ DEFAULT_WINDOW_HEIGHT

#define DEFAULT_WINDOW_HEIGHT   480

Definition at line 42 of file SDL_test_common.h.

◆ DEFAULT_WINDOW_WIDTH

#define DEFAULT_WINDOW_WIDTH   640

Definition at line 41 of file SDL_test_common.h.

◆ VERBOSE_AUDIO

#define VERBOSE_AUDIO   0x00000010

Definition at line 49 of file SDL_test_common.h.

◆ VERBOSE_EVENT

#define VERBOSE_EVENT   0x00000008

Definition at line 48 of file SDL_test_common.h.

◆ VERBOSE_MODES

#define VERBOSE_MODES   0x00000002

Definition at line 46 of file SDL_test_common.h.

◆ VERBOSE_RENDER

#define VERBOSE_RENDER   0x00000004

Definition at line 47 of file SDL_test_common.h.

◆ VERBOSE_VIDEO

#define VERBOSE_VIDEO   0x00000001

Definition at line 45 of file SDL_test_common.h.

Function Documentation

◆ SDLTest_CommonArg()

int SDLTest_CommonArg ( SDLTest_CommonState state,
int  index 
)

Process one common argument.

Parameters
stateThe common state describing the test window to create.
indexThe index of the argument to process in argv[].
Returns
The number of arguments processed (i.e. 1 for –fullscreen, 2 for –video [videodriver], or -1 on error.

Definition at line 117 of file SDL_test_common.c.

118 {
119  char **argv = state->argv;
120 
121  if (SDL_strcasecmp(argv[index], "--video") == 0) {
122  ++index;
123  if (!argv[index]) {
124  return -1;
125  }
126  state->videodriver = argv[index];
127  return 2;
128  }
129  if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
130  ++index;
131  if (!argv[index]) {
132  return -1;
133  }
134  state->renderdriver = argv[index];
135  return 2;
136  }
137  if (SDL_strcasecmp(argv[index], "--gldebug") == 0) {
138  state->gl_debug = 1;
139  return 1;
140  }
141  if (SDL_strcasecmp(argv[index], "--info") == 0) {
142  ++index;
143  if (!argv[index]) {
144  return -1;
145  }
146  if (SDL_strcasecmp(argv[index], "all") == 0) {
147  state->verbose |=
149  VERBOSE_EVENT);
150  return 2;
151  }
152  if (SDL_strcasecmp(argv[index], "video") == 0) {
153  state->verbose |= VERBOSE_VIDEO;
154  return 2;
155  }
156  if (SDL_strcasecmp(argv[index], "modes") == 0) {
157  state->verbose |= VERBOSE_MODES;
158  return 2;
159  }
160  if (SDL_strcasecmp(argv[index], "render") == 0) {
161  state->verbose |= VERBOSE_RENDER;
162  return 2;
163  }
164  if (SDL_strcasecmp(argv[index], "event") == 0) {
165  state->verbose |= VERBOSE_EVENT;
166  return 2;
167  }
168  return -1;
169  }
170  if (SDL_strcasecmp(argv[index], "--log") == 0) {
171  ++index;
172  if (!argv[index]) {
173  return -1;
174  }
175  if (SDL_strcasecmp(argv[index], "all") == 0) {
177  return 2;
178  }
179  if (SDL_strcasecmp(argv[index], "error") == 0) {
181  return 2;
182  }
183  if (SDL_strcasecmp(argv[index], "system") == 0) {
185  return 2;
186  }
187  if (SDL_strcasecmp(argv[index], "audio") == 0) {
189  return 2;
190  }
191  if (SDL_strcasecmp(argv[index], "video") == 0) {
193  return 2;
194  }
195  if (SDL_strcasecmp(argv[index], "render") == 0) {
197  return 2;
198  }
199  if (SDL_strcasecmp(argv[index], "input") == 0) {
201  return 2;
202  }
203  return -1;
204  }
205  if (SDL_strcasecmp(argv[index], "--display") == 0) {
206  ++index;
207  if (!argv[index]) {
208  return -1;
209  }
210  state->display = SDL_atoi(argv[index]);
211  if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
212  state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
213  state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
214  }
215  if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
216  state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
217  state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
218  }
219  return 2;
220  }
221  if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
222  state->window_flags |= SDL_WINDOW_FULLSCREEN;
223  state->num_windows = 1;
224  return 1;
225  }
226  if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
227  state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
228  state->num_windows = 1;
229  return 1;
230  }
231  if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) {
232  state->window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
233  return 1;
234  }
235  if (SDL_strcasecmp(argv[index], "--windows") == 0) {
236  ++index;
237  if (!argv[index] || !SDL_isdigit(*argv[index])) {
238  return -1;
239  }
240  if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
241  state->num_windows = SDL_atoi(argv[index]);
242  }
243  return 2;
244  }
245  if (SDL_strcasecmp(argv[index], "--title") == 0) {
246  ++index;
247  if (!argv[index]) {
248  return -1;
249  }
250  state->window_title = argv[index];
251  return 2;
252  }
253  if (SDL_strcasecmp(argv[index], "--icon") == 0) {
254  ++index;
255  if (!argv[index]) {
256  return -1;
257  }
258  state->window_icon = argv[index];
259  return 2;
260  }
261  if (SDL_strcasecmp(argv[index], "--center") == 0) {
262  state->window_x = SDL_WINDOWPOS_CENTERED;
263  state->window_y = SDL_WINDOWPOS_CENTERED;
264  return 1;
265  }
266  if (SDL_strcasecmp(argv[index], "--position") == 0) {
267  char *x, *y;
268  ++index;
269  if (!argv[index]) {
270  return -1;
271  }
272  x = argv[index];
273  y = argv[index];
274  while (*y && *y != ',') {
275  ++y;
276  }
277  if (!*y) {
278  return -1;
279  }
280  *y++ = '\0';
281  state->window_x = SDL_atoi(x);
282  state->window_y = SDL_atoi(y);
283  return 2;
284  }
285  if (SDL_strcasecmp(argv[index], "--usable-bounds") == 0) {
286  /* !!! FIXME: this is a bit of a hack, but I don't want to add a
287  !!! FIXME: flag to the public structure in 2.0.x */
288  state->window_x = -1;
289  state->window_y = -1;
290  state->window_w = -1;
291  state->window_h = -1;
292  return 1;
293  }
294  if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
295  char *w, *h;
296  ++index;
297  if (!argv[index]) {
298  return -1;
299  }
300  w = argv[index];
301  h = argv[index];
302  while (*h && *h != 'x') {
303  ++h;
304  }
305  if (!*h) {
306  return -1;
307  }
308  *h++ = '\0';
309  state->window_w = SDL_atoi(w);
310  state->window_h = SDL_atoi(h);
311  return 2;
312  }
313  if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
314  char *w, *h;
315  ++index;
316  if (!argv[index]) {
317  return -1;
318  }
319  w = argv[index];
320  h = argv[index];
321  while (*h && *h != 'x') {
322  ++h;
323  }
324  if (!*h) {
325  return -1;
326  }
327  *h++ = '\0';
328  state->window_minW = SDL_atoi(w);
329  state->window_minH = SDL_atoi(h);
330  return 2;
331  }
332  if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
333  char *w, *h;
334  ++index;
335  if (!argv[index]) {
336  return -1;
337  }
338  w = argv[index];
339  h = argv[index];
340  while (*h && *h != 'x') {
341  ++h;
342  }
343  if (!*h) {
344  return -1;
345  }
346  *h++ = '\0';
347  state->window_maxW = SDL_atoi(w);
348  state->window_maxH = SDL_atoi(h);
349  return 2;
350  }
351  if (SDL_strcasecmp(argv[index], "--logical") == 0) {
352  char *w, *h;
353  ++index;
354  if (!argv[index]) {
355  return -1;
356  }
357  w = argv[index];
358  h = argv[index];
359  while (*h && *h != 'x') {
360  ++h;
361  }
362  if (!*h) {
363  return -1;
364  }
365  *h++ = '\0';
366  state->logical_w = SDL_atoi(w);
367  state->logical_h = SDL_atoi(h);
368  return 2;
369  }
370  if (SDL_strcasecmp(argv[index], "--scale") == 0) {
371  ++index;
372  if (!argv[index]) {
373  return -1;
374  }
375  state->scale = (float)SDL_atof(argv[index]);
376  return 2;
377  }
378  if (SDL_strcasecmp(argv[index], "--depth") == 0) {
379  ++index;
380  if (!argv[index]) {
381  return -1;
382  }
383  state->depth = SDL_atoi(argv[index]);
384  return 2;
385  }
386  if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
387  ++index;
388  if (!argv[index]) {
389  return -1;
390  }
391  state->refresh_rate = SDL_atoi(argv[index]);
392  return 2;
393  }
394  if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
395  state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
396  return 1;
397  }
398  if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
399  state->window_flags |= SDL_WINDOW_BORDERLESS;
400  return 1;
401  }
402  if (SDL_strcasecmp(argv[index], "--resize") == 0) {
403  state->window_flags |= SDL_WINDOW_RESIZABLE;
404  return 1;
405  }
406  if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
407  state->window_flags |= SDL_WINDOW_MINIMIZED;
408  return 1;
409  }
410  if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
411  state->window_flags |= SDL_WINDOW_MAXIMIZED;
412  return 1;
413  }
414  if (SDL_strcasecmp(argv[index], "--grab") == 0) {
415  state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
416  return 1;
417  }
418  if (SDL_strcasecmp(argv[index], "--rate") == 0) {
419  ++index;
420  if (!argv[index]) {
421  return -1;
422  }
423  state->audiospec.freq = SDL_atoi(argv[index]);
424  return 2;
425  }
426  if (SDL_strcasecmp(argv[index], "--format") == 0) {
427  ++index;
428  if (!argv[index]) {
429  return -1;
430  }
431  if (SDL_strcasecmp(argv[index], "U8") == 0) {
432  state->audiospec.format = AUDIO_U8;
433  return 2;
434  }
435  if (SDL_strcasecmp(argv[index], "S8") == 0) {
436  state->audiospec.format = AUDIO_S8;
437  return 2;
438  }
439  if (SDL_strcasecmp(argv[index], "U16") == 0) {
440  state->audiospec.format = AUDIO_U16;
441  return 2;
442  }
443  if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
444  state->audiospec.format = AUDIO_U16LSB;
445  return 2;
446  }
447  if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
448  state->audiospec.format = AUDIO_U16MSB;
449  return 2;
450  }
451  if (SDL_strcasecmp(argv[index], "S16") == 0) {
452  state->audiospec.format = AUDIO_S16;
453  return 2;
454  }
455  if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
456  state->audiospec.format = AUDIO_S16LSB;
457  return 2;
458  }
459  if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
460  state->audiospec.format = AUDIO_S16MSB;
461  return 2;
462  }
463  return -1;
464  }
465  if (SDL_strcasecmp(argv[index], "--channels") == 0) {
466  ++index;
467  if (!argv[index]) {
468  return -1;
469  }
470  state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
471  return 2;
472  }
473  if (SDL_strcasecmp(argv[index], "--samples") == 0) {
474  ++index;
475  if (!argv[index]) {
476  return -1;
477  }
478  state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
479  return 2;
480  }
481  if (SDL_strcasecmp(argv[index], "--trackmem") == 0) {
482  /* Already handled in SDLTest_CommonCreateState() */
483  return 1;
484  }
485  if ((SDL_strcasecmp(argv[index], "-h") == 0)
486  || (SDL_strcasecmp(argv[index], "--help") == 0)) {
487  /* Print the usage message */
488  return -1;
489  }
490  if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
491  /* Debug flag sent by Xcode */
492  return 2;
493  }
494  return 0;
495 }
#define AUDIO_U16LSB
Definition: SDL_audio.h:91
#define AUDIO_S16LSB
Definition: SDL_audio.h:92
#define AUDIO_S16MSB
Definition: SDL_audio.h:94
#define AUDIO_U16MSB
Definition: SDL_audio.h:93
#define AUDIO_S16
Definition: SDL_audio.h:96
#define AUDIO_U8
Definition: SDL_audio.h:89
#define AUDIO_S8
Definition: SDL_audio.h:90
#define AUDIO_U16
Definition: SDL_audio.h:95
#define SDL_isdigit
#define SDL_LogSetAllPriority
#define SDL_atof
#define SDL_strcasecmp
#define SDL_LogSetPriority
#define SDL_strcmp
#define SDL_atoi
@ SDL_LOG_PRIORITY_VERBOSE
Definition: SDL_log.h:104
@ SDL_LOG_CATEGORY_ERROR
Definition: SDL_log.h:67
@ SDL_LOG_CATEGORY_RENDER
Definition: SDL_log.h:72
@ SDL_LOG_CATEGORY_INPUT
Definition: SDL_log.h:73
@ SDL_LOG_CATEGORY_SYSTEM
Definition: SDL_log.h:69
@ SDL_LOG_CATEGORY_AUDIO
Definition: SDL_log.h:70
@ SDL_LOG_CATEGORY_VIDEO
Definition: SDL_log.h:71
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLuint index
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
@ SDL_RENDERER_PRESENTVSYNC
Definition: SDL_render.h:69
uint16_t Uint16
Definition: SDL_stdinc.h:197
uint8_t Uint8
Definition: SDL_stdinc.h:185
#define VERBOSE_MODES
#define VERBOSE_EVENT
#define VERBOSE_RENDER
#define VERBOSE_VIDEO
#define SDL_WINDOWPOS_ISCENTERED(X)
Definition: SDL_video.h:140
#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X)
Definition: SDL_video.h:129
#define SDL_WINDOWPOS_CENTERED_DISPLAY(X)
Definition: SDL_video.h:138
#define SDL_WINDOWPOS_CENTERED
Definition: SDL_video.h:139
#define SDL_WINDOWPOS_ISUNDEFINED(X)
Definition: SDL_video.h:131
@ SDL_WINDOW_ALLOW_HIGHDPI
Definition: SDL_video.h:112
@ SDL_WINDOW_MINIMIZED
Definition: SDL_video.h:105
@ SDL_WINDOW_INPUT_GRABBED
Definition: SDL_video.h:107
@ SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:104
@ SDL_WINDOW_FULLSCREEN_DESKTOP
Definition: SDL_video.h:110
@ SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:99
@ SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:106
@ SDL_WINDOW_BORDERLESS
Definition: SDL_video.h:103
struct xkb_state * state

References AUDIO_S16, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S8, AUDIO_U16, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, SDL_atof, SDL_atoi, SDL_isdigit, SDL_LOG_CATEGORY_AUDIO, SDL_LOG_CATEGORY_ERROR, SDL_LOG_CATEGORY_INPUT, SDL_LOG_CATEGORY_RENDER, SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE, SDL_LogSetAllPriority, SDL_LogSetPriority, SDL_RENDERER_PRESENTVSYNC, SDL_strcasecmp, SDL_strcmp, SDL_WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_INPUT_GRABBED, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_RESIZABLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED_DISPLAY, SDL_WINDOWPOS_ISCENTERED, SDL_WINDOWPOS_ISUNDEFINED, SDL_WINDOWPOS_UNDEFINED_DISPLAY, state, VERBOSE_EVENT, VERBOSE_MODES, VERBOSE_RENDER, and VERBOSE_VIDEO.

Referenced by main(), and SDLTest_CommonDefaultArgs().

◆ SDLTest_CommonCreateState()

SDLTest_CommonState* SDLTest_CommonCreateState ( char **  argv,
Uint32  flags 
)

Parse command line parameters and create common state.

Parameters
argvArray of command line parameters
flagsFlags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
Returns
Returns a newly allocated common state object.

Definition at line 59 of file SDL_test_common.c.

60 {
61  int i;
63 
64  /* Do this first so we catch all allocations */
65  for (i = 1; argv[i]; ++i) {
66  if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
68  break;
69  }
70  }
71 
72  state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
73  if (!state) {
75  return NULL;
76  }
77 
78  /* Initialize some defaults */
79  state->argv = argv;
80  state->flags = flags;
81  state->window_title = argv[0];
82  state->window_flags = 0;
83  state->window_x = SDL_WINDOWPOS_UNDEFINED;
84  state->window_y = SDL_WINDOWPOS_UNDEFINED;
85  state->window_w = DEFAULT_WINDOW_WIDTH;
86  state->window_h = DEFAULT_WINDOW_HEIGHT;
87  state->num_windows = 1;
88  state->audiospec.freq = 22050;
89  state->audiospec.format = AUDIO_S16;
90  state->audiospec.channels = 2;
91  state->audiospec.samples = 2048;
92 
93  /* Set some very sane GL defaults */
94  state->gl_red_size = 3;
95  state->gl_green_size = 3;
96  state->gl_blue_size = 2;
97  state->gl_alpha_size = 0;
98  state->gl_buffer_size = 0;
99  state->gl_depth_size = 16;
100  state->gl_stencil_size = 0;
101  state->gl_double_buffer = 1;
102  state->gl_accum_red_size = 0;
103  state->gl_accum_green_size = 0;
104  state->gl_accum_blue_size = 0;
105  state->gl_accum_alpha_size = 0;
106  state->gl_stereo = 0;
107  state->gl_multisamplebuffers = 0;
108  state->gl_multisamplesamples = 0;
109  state->gl_retained_backing = 1;
110  state->gl_accelerated = -1;
111  state->gl_debug = 0;
112 
113  return state;
114 }
#define SDL_calloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
GLbitfield flags
#define DEFAULT_WINDOW_HEIGHT
#define DEFAULT_WINDOW_WIDTH
int SDLTest_TrackAllocations(void)
Start tracking SDL memory allocations.
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:163

References AUDIO_S16, DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, i, NULL, SDL_calloc, SDL_OutOfMemory, SDL_strcasecmp, SDL_WINDOWPOS_UNDEFINED, SDLTest_TrackAllocations(), and state.

Referenced by main().

◆ SDLTest_CommonDefaultArgs()

SDL_bool SDLTest_CommonDefaultArgs ( SDLTest_CommonState state,
const int  argc,
char **  argv 
)

Easy argument handling when test app doesn't need any custom args.

Parameters
stateThe common state describing the test window to create.
argcargc, as supplied to SDL_main
argvargv, as supplied to SDL_main
Returns
False if app should quit, true otherwise.

Definition at line 584 of file SDL_test_common.c.

585 {
586  int i = 1;
587  while (i < argc) {
588  const int consumed = SDLTest_CommonArg(state, i);
589  if (consumed == 0) {
590  SDLTest_CommonLogUsage(state, argv[0], NULL);
591  return SDL_FALSE;
592  }
593  i += consumed;
594  }
595  return SDL_TRUE;
596 }
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
void SDLTest_CommonLogUsage(SDLTest_CommonState *state, const char *argv0, const char **options)
Logs command line usage info.

References i, NULL, SDL_FALSE, SDL_TRUE, SDLTest_CommonArg(), SDLTest_CommonLogUsage(), and state.

Referenced by main().

◆ SDLTest_CommonEvent()

void SDLTest_CommonEvent ( SDLTest_CommonState state,
SDL_Event event,
int done 
)

Common event handler for test windows.

Parameters
stateThe common state used to create test window.
eventThe event to handle.
doneFlag indicating we are done.

Definition at line 1581 of file SDL_test_common.c.

1582 {
1583  int i;
1584  static SDL_MouseMotionEvent lastEvent;
1585 
1586  if (state->verbose & VERBOSE_EVENT) {
1588  }
1589 
1590  switch (event->type) {
1591  case SDL_WINDOWEVENT:
1592  switch (event->window.event) {
1593  case SDL_WINDOWEVENT_CLOSE:
1594  {
1595  SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
1596  if (window) {
1597  for (i = 0; i < state->num_windows; ++i) {
1598  if (window == state->windows[i]) {
1599  if (state->targets[i]) {
1600  SDL_DestroyTexture(state->targets[i]);
1601  state->targets[i] = NULL;
1602  }
1603  if (state->renderers[i]) {
1604  SDL_DestroyRenderer(state->renderers[i]);
1605  state->renderers[i] = NULL;
1606  }
1607  SDL_DestroyWindow(state->windows[i]);
1608  state->windows[i] = NULL;
1609  break;
1610  }
1611  }
1612  }
1613  }
1614  break;
1615  }
1616  break;
1617  case SDL_KEYDOWN: {
1618  SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
1619  SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
1620  SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
1621 
1622  switch (event->key.keysym.sym) {
1623  /* Add hotkeys here */
1624  case SDLK_PRINTSCREEN: {
1625  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1626  if (window) {
1627  for (i = 0; i < state->num_windows; ++i) {
1628  if (window == state->windows[i]) {
1629  SDLTest_ScreenShot(state->renderers[i]);
1630  }
1631  }
1632  }
1633  }
1634  break;
1635  case SDLK_EQUALS:
1636  if (withControl) {
1637  /* Ctrl-+ double the size of the window */
1638  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1639  if (window) {
1640  int w, h;
1641  SDL_GetWindowSize(window, &w, &h);
1642  SDL_SetWindowSize(window, w*2, h*2);
1643  }
1644  }
1645  break;
1646  case SDLK_MINUS:
1647  if (withControl) {
1648  /* Ctrl-- half the size of the window */
1649  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1650  if (window) {
1651  int w, h;
1652  SDL_GetWindowSize(window, &w, &h);
1653  SDL_SetWindowSize(window, w/2, h/2);
1654  }
1655  }
1656  break;
1657  case SDLK_UP:
1658  case SDLK_DOWN:
1659  case SDLK_LEFT:
1660  case SDLK_RIGHT:
1661  if (withAlt) {
1662  /* Alt-Up/Down/Left/Right switches between displays */
1663  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1664  if (window) {
1665  int currentIndex = SDL_GetWindowDisplayIndex(window);
1666  int numDisplays = SDL_GetNumVideoDisplays();
1667 
1668  if (currentIndex >= 0 && numDisplays >= 1) {
1669  int dest;
1670  if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) {
1671  dest = (currentIndex + numDisplays - 1) % numDisplays;
1672  } else {
1673  dest = (currentIndex + numDisplays + 1) % numDisplays;
1674  }
1675  SDL_Log("Centering on display %d\n", dest);
1679  }
1680  }
1681  }
1682  if (withShift) {
1683  /* Shift-Up/Down/Left/Right shift the window by 100px */
1684  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1685  if (window) {
1686  const int delta = 100;
1687  int x, y;
1689 
1690  if (event->key.keysym.sym == SDLK_UP) y -= delta;
1691  if (event->key.keysym.sym == SDLK_DOWN) y += delta;
1692  if (event->key.keysym.sym == SDLK_LEFT) x -= delta;
1693  if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
1694 
1695  SDL_Log("Setting position to (%d, %d)\n", x, y);
1697  }
1698  }
1699  break;
1700  case SDLK_o:
1701  if (withControl) {
1702  /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */
1703  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1704  if (window) {
1705  float opacity;
1706  if (SDL_GetWindowOpacity(window, &opacity) == 0) {
1707  if (withShift) {
1708  opacity += 0.20f;
1709  } else {
1710  opacity -= 0.20f;
1711  }
1712  SDL_SetWindowOpacity(window, opacity);
1713  }
1714  }
1715  }
1716  break;
1717 
1718  case SDLK_c:
1719  if (withControl) {
1720  /* Ctrl-C copy awesome text! */
1721  SDL_SetClipboardText("SDL rocks!\nYou know it!");
1722  printf("Copied text to clipboard\n");
1723  }
1724  if (withAlt) {
1725  /* Alt-C toggle a render clip rectangle */
1726  for (i = 0; i < state->num_windows; ++i) {
1727  int w, h;
1728  if (state->renderers[i]) {
1729  SDL_Rect clip;
1730  SDL_GetWindowSize(state->windows[i], &w, &h);
1731  SDL_RenderGetClipRect(state->renderers[i], &clip);
1732  if (SDL_RectEmpty(&clip)) {
1733  clip.x = w/4;
1734  clip.y = h/4;
1735  clip.w = w/2;
1736  clip.h = h/2;
1737  SDL_RenderSetClipRect(state->renderers[i], &clip);
1738  } else {
1739  SDL_RenderSetClipRect(state->renderers[i], NULL);
1740  }
1741  }
1742  }
1743  }
1744  if (withShift) {
1745  SDL_Window *current_win = SDL_GetKeyboardFocus();
1746  if (current_win) {
1747  const SDL_bool shouldCapture = (SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE) == 0;
1748  const int rc = SDL_CaptureMouse(shouldCapture);
1749  SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed");
1750  }
1751  }
1752  break;
1753  case SDLK_v:
1754  if (withControl) {
1755  /* Ctrl-V paste awesome text! */
1756  char *text = SDL_GetClipboardText();
1757  if (*text) {
1758  printf("Clipboard: %s\n", text);
1759  } else {
1760  printf("Clipboard is empty\n");
1761  }
1762  SDL_free(text);
1763  }
1764  break;
1765  case SDLK_g:
1766  if (withControl) {
1767  /* Ctrl-G toggle grab */
1768  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1769  if (window) {
1771  }
1772  }
1773  break;
1774  case SDLK_m:
1775  if (withControl) {
1776  /* Ctrl-M maximize */
1777  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1778  if (window) {
1780  if (flags & SDL_WINDOW_MAXIMIZED) {
1782  } else {
1784  }
1785  }
1786  }
1787  break;
1788  case SDLK_r:
1789  if (withControl) {
1790  /* Ctrl-R toggle mouse relative mode */
1792  }
1793  break;
1794  case SDLK_z:
1795  if (withControl) {
1796  /* Ctrl-Z minimize */
1797  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1798  if (window) {
1800  }
1801  }
1802  break;
1803  case SDLK_RETURN:
1804  if (withControl) {
1805  /* Ctrl-Enter toggle fullscreen */
1806  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1807  if (window) {
1809  if (flags & SDL_WINDOW_FULLSCREEN) {
1811  } else {
1813  }
1814  }
1815  } else if (withAlt) {
1816  /* Alt-Enter toggle fullscreen desktop */
1817  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1818  if (window) {
1820  if (flags & SDL_WINDOW_FULLSCREEN) {
1822  } else {
1824  }
1825  }
1826  } else if (withShift) {
1827  /* Shift-Enter toggle fullscreen desktop / fullscreen */
1828  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1829  if (window) {
1833  } else {
1835  }
1836  }
1837  }
1838 
1839  break;
1840  case SDLK_b:
1841  if (withControl) {
1842  /* Ctrl-B toggle window border */
1843  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1844  if (window) {
1846  const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE;
1848  }
1849  }
1850  break;
1851  case SDLK_a:
1852  if (withControl) {
1853  /* Ctrl-A reports absolute mouse position. */
1854  int x, y;
1855  const Uint32 mask = SDL_GetGlobalMouseState(&x, &y);
1856  SDL_Log("ABSOLUTE MOUSE: (%d, %d)%s%s%s%s%s\n", x, y,
1857  (mask & SDL_BUTTON_LMASK) ? " [LBUTTON]" : "",
1858  (mask & SDL_BUTTON_MMASK) ? " [MBUTTON]" : "",
1859  (mask & SDL_BUTTON_RMASK) ? " [RBUTTON]" : "",
1860  (mask & SDL_BUTTON_X1MASK) ? " [X2BUTTON]" : "",
1861  (mask & SDL_BUTTON_X2MASK) ? " [X2BUTTON]" : "");
1862  }
1863  break;
1864  case SDLK_0:
1865  if (withControl) {
1866  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1867  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
1868  }
1869  break;
1870  case SDLK_1:
1871  if (withControl) {
1872  FullscreenTo(0, event->key.windowID);
1873  }
1874  break;
1875  case SDLK_2:
1876  if (withControl) {
1877  FullscreenTo(1, event->key.windowID);
1878  }
1879  break;
1880  case SDLK_ESCAPE:
1881  *done = 1;
1882  break;
1883  case SDLK_SPACE:
1884  {
1885  char message[256];
1886  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1887 
1888  SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
1890  break;
1891  }
1892  default:
1893  break;
1894  }
1895  break;
1896  }
1897  case SDL_QUIT:
1898  *done = 1;
1899  break;
1900  case SDL_MOUSEMOTION:
1901  lastEvent = event->motion;
1902  break;
1903 
1904  case SDL_DROPFILE:
1905  case SDL_DROPTEXT:
1906  SDL_free(event->drop.file);
1907  break;
1908  }
1909 }
#define SDL_GetWindowGrab
#define SDL_SetWindowGrab
#define SDL_GetWindowSize
#define SDL_DestroyWindow
#define SDL_SetWindowOpacity
#define SDL_MaximizeWindow
#define SDL_DestroyRenderer
#define SDL_DestroyTexture
#define SDL_SetWindowFullscreen
#define SDL_RenderSetClipRect
#define SDL_RestoreWindow
#define SDL_SetRelativeMouseMode
#define SDL_GetWindowFlags
#define SDL_SetClipboardText
#define SDL_CaptureMouse
#define SDL_GetKeyboardFocus
#define SDL_SetWindowPosition
#define SDL_GetClipboardText
#define SDL_RenderGetClipRect
#define SDL_free
#define SDL_ShowSimpleMessageBox
#define SDL_SetWindowBordered
#define SDL_GetWindowDisplayIndex
#define SDL_GetWindowFromID
#define SDL_GetWindowPosition
#define SDL_SetWindowSize
#define SDL_GetNumVideoDisplays
#define SDL_MinimizeWindow
#define SDL_GetWindowOpacity
#define SDL_Log
#define SDL_snprintf
#define SDL_GetGlobalMouseState
#define SDL_GetRelativeMouseMode
@ SDL_MOUSEMOTION
Definition: SDL_events.h:107
@ SDL_DROPTEXT
Definition: SDL_events.h:148
@ SDL_QUIT
Definition: SDL_events.h:60
@ SDL_WINDOWEVENT
Definition: SDL_events.h:94
@ SDL_KEYDOWN
Definition: SDL_events.h:98
@ SDL_DROPFILE
Definition: SDL_events.h:147
@ SDLK_g
Definition: SDL_keycode.h:108
@ SDLK_c
Definition: SDL_keycode.h:104
@ SDLK_0
Definition: SDL_keycode.h:74
@ SDLK_a
Definition: SDL_keycode.h:102
@ SDLK_EQUALS
Definition: SDL_keycode.h:87
@ SDLK_UP
Definition: SDL_keycode.h:156
@ SDLK_DOWN
Definition: SDL_keycode.h:155
@ SDLK_z
Definition: SDL_keycode.h:127
@ SDLK_v
Definition: SDL_keycode.h:123
@ SDLK_PRINTSCREEN
Definition: SDL_keycode.h:144
@ SDLK_r
Definition: SDL_keycode.h:119
@ SDLK_MINUS
Definition: SDL_keycode.h:71
@ SDLK_b
Definition: SDL_keycode.h:103
@ SDLK_m
Definition: SDL_keycode.h:114
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
@ SDLK_1
Definition: SDL_keycode.h:75
@ SDLK_SPACE
Definition: SDL_keycode.h:58
@ SDLK_LEFT
Definition: SDL_keycode.h:154
@ SDLK_o
Definition: SDL_keycode.h:116
@ SDLK_RIGHT
Definition: SDL_keycode.h:153
@ SDLK_RETURN
Definition: SDL_keycode.h:54
@ SDLK_2
Definition: SDL_keycode.h:76
@ KMOD_SHIFT
Definition: SDL_keycode.h:344
@ KMOD_ALT
Definition: SDL_keycode.h:345
@ KMOD_CTRL
Definition: SDL_keycode.h:343
@ SDL_MESSAGEBOX_INFORMATION
#define SDL_BUTTON_MMASK
Definition: SDL_mouse.h:288
#define SDL_BUTTON_LMASK
Definition: SDL_mouse.h:287
#define SDL_BUTTON_X1MASK
Definition: SDL_mouse.h:290
#define SDL_BUTTON_RMASK
Definition: SDL_mouse.h:289
#define SDL_BUTTON_X2MASK
Definition: SDL_mouse.h:291
GLboolean GLboolean GLboolean b
struct _cl_event * event
GLuint GLsizei const GLchar * message
GLenum GLint GLuint mask
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:108
SDL_bool
Definition: SDL_stdinc.h:168
uint32_t Uint32
Definition: SDL_stdinc.h:209
static void SDLTest_PrintEvent(SDL_Event *event)
static void FullscreenTo(int index, int windowId)
static void SDLTest_ScreenShot(SDL_Renderer *renderer)
@ SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:115
@ SDL_WINDOWEVENT_CLOSE
Definition: SDL_video.h:167
int done
Definition: checkkeys.c:28
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:260
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
The type used to identify a window.
Definition: SDL_sysvideo.h:75
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47

References done, FullscreenTo(), SDL_Rect::h, i, KMOD_ALT, KMOD_CTRL, KMOD_SHIFT, NULL, SDL_BUTTON_LMASK, SDL_BUTTON_MMASK, SDL_BUTTON_RMASK, SDL_BUTTON_X1MASK, SDL_BUTTON_X2MASK, SDL_CaptureMouse, SDL_DestroyRenderer, SDL_DestroyTexture, SDL_DestroyWindow, SDL_DROPFILE, SDL_DROPTEXT, SDL_FALSE, SDL_free, SDL_GetClipboardText, SDL_GetGlobalMouseState, SDL_GetKeyboardFocus, SDL_GetNumVideoDisplays, SDL_GetRelativeMouseMode, SDL_GetWindowDisplayIndex, SDL_GetWindowFlags, SDL_GetWindowFromID, SDL_GetWindowGrab, SDL_GetWindowOpacity, SDL_GetWindowPosition, SDL_GetWindowSize, SDL_KEYDOWN, SDL_Log, SDL_MaximizeWindow, SDL_MESSAGEBOX_INFORMATION, SDL_MinimizeWindow, SDL_MOUSEMOTION, SDL_QUIT, SDL_RectEmpty(), SDL_RenderGetClipRect, SDL_RenderSetClipRect, SDL_RestoreWindow, SDL_SetClipboardText, SDL_SetRelativeMouseMode, SDL_SetWindowBordered, SDL_SetWindowFullscreen, SDL_SetWindowGrab, SDL_SetWindowOpacity, SDL_SetWindowPosition, SDL_SetWindowSize, SDL_ShowSimpleMessageBox, SDL_snprintf, SDL_TRUE, SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MOUSE_CAPTURE, SDL_WINDOWEVENT, SDL_WINDOWEVENT_CLOSE, SDL_WINDOWPOS_CENTERED_DISPLAY, SDLK_0, SDLK_1, SDLK_2, SDLK_a, SDLK_b, SDLK_c, SDLK_DOWN, SDLK_EQUALS, SDLK_ESCAPE, SDLK_g, SDLK_LEFT, SDLK_m, SDLK_MINUS, SDLK_o, SDLK_PRINTSCREEN, SDLK_r, SDLK_RETURN, SDLK_RIGHT, SDLK_SPACE, SDLK_UP, SDLK_v, SDLK_z, SDLTest_PrintEvent(), SDLTest_ScreenShot(), state, text, VERBOSE_EVENT, SDL_Rect::w, SDL_MouseMotionEvent::x, SDL_Rect::x, SDL_MouseMotionEvent::xrel, SDL_MouseMotionEvent::y, SDL_Rect::y, and SDL_MouseMotionEvent::yrel.

Referenced by loop(), and main().

◆ SDLTest_CommonInit()

SDL_bool SDLTest_CommonInit ( SDLTest_CommonState state)

Open test window.

Parameters
stateThe common state describing the test window to create.
Returns
True if initialization succeeded, false otherwise

Definition at line 835 of file SDL_test_common.c.

836 {
837  int i, j, m, n, w, h;
838  SDL_DisplayMode fullscreen_mode;
839  char text[1024];
840 
841  if (state->flags & SDL_INIT_VIDEO) {
842  if (state->verbose & VERBOSE_VIDEO) {
844  if (n == 0) {
845  SDL_Log("No built-in video drivers\n");
846  } else {
847  SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
848  for (i = 0; i < n; ++i) {
849  if (i > 0) {
850  SDL_snprintfcat(text, sizeof(text), ",");
851  }
852  SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
853  }
854  SDL_Log("%s\n", text);
855  }
856  }
857  if (SDL_VideoInit(state->videodriver) < 0) {
858  SDL_Log("Couldn't initialize video driver: %s\n",
859  SDL_GetError());
860  return SDL_FALSE;
861  }
862  if (state->verbose & VERBOSE_VIDEO) {
863  SDL_Log("Video driver: %s\n",
865  }
866 
867  /* Upload GL settings */
872  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
873  SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
875  SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
876  SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
877  SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
878  SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
879  SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
881  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
882  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
883  if (state->gl_accelerated >= 0) {
885  state->gl_accelerated);
886  }
887  SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
888  if (state->gl_major_version) {
891  }
892  if (state->gl_debug) {
894  }
895  if (state->gl_profile_mask) {
897  }
898 
899  if (state->verbose & VERBOSE_MODES) {
900  SDL_Rect bounds, usablebounds;
901  float hdpi = 0;
902  float vdpi = 0;
904  int bpp;
905  Uint32 Rmask, Gmask, Bmask, Amask;
906 #if SDL_VIDEO_DRIVER_WINDOWS
907  int adapterIndex = 0;
908  int outputIndex = 0;
909 #endif
911  SDL_Log("Number of displays: %d\n", n);
912  for (i = 0; i < n; ++i) {
913  SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i));
914 
915  SDL_zero(bounds);
916  SDL_GetDisplayBounds(i, &bounds);
917 
918  SDL_zero(usablebounds);
919  SDL_GetDisplayUsableBounds(i, &usablebounds);
920 
921  SDL_GetDisplayDPI(i, NULL, &hdpi, &vdpi);
922 
923  SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
924  SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
925  SDL_Log("DPI: %fx%f\n", hdpi, vdpi);
926 
928  SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
929  &Bmask, &Amask);
930  SDL_Log(" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
931  mode.w, mode.h, mode.refresh_rate, bpp,
932  SDL_GetPixelFormatName(mode.format));
933  if (Rmask || Gmask || Bmask) {
934  SDL_Log(" Red Mask = 0x%.8x\n", Rmask);
935  SDL_Log(" Green Mask = 0x%.8x\n", Gmask);
936  SDL_Log(" Blue Mask = 0x%.8x\n", Bmask);
937  if (Amask)
938  SDL_Log(" Alpha Mask = 0x%.8x\n", Amask);
939  }
940 
941  /* Print available fullscreen video modes */
943  if (m == 0) {
944  SDL_Log("No available fullscreen video modes\n");
945  } else {
946  SDL_Log(" Fullscreen video modes:\n");
947  for (j = 0; j < m; ++j) {
949  SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
950  &Gmask, &Bmask, &Amask);
951  SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
952  j, mode.w, mode.h, mode.refresh_rate, bpp,
953  SDL_GetPixelFormatName(mode.format));
954  if (Rmask || Gmask || Bmask) {
955  SDL_Log(" Red Mask = 0x%.8x\n",
956  Rmask);
957  SDL_Log(" Green Mask = 0x%.8x\n",
958  Gmask);
959  SDL_Log(" Blue Mask = 0x%.8x\n",
960  Bmask);
961  if (Amask)
962  SDL_Log(" Alpha Mask = 0x%.8x\n",
963  Amask);
964  }
965  }
966  }
967 
968 #if SDL_VIDEO_DRIVER_WINDOWS
969  /* Print the D3D9 adapter index */
970  adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
971  SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
972 
973  /* Print the DXGI adapter and output indices */
974  SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
975  SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
976 #endif
977  }
978  }
979 
980  if (state->verbose & VERBOSE_RENDER) {
981  SDL_RendererInfo info;
982 
984  if (n == 0) {
985  SDL_Log("No built-in render drivers\n");
986  } else {
987  SDL_Log("Built-in render drivers:\n");
988  for (i = 0; i < n; ++i) {
989  SDL_GetRenderDriverInfo(i, &info);
990  SDLTest_PrintRenderer(&info);
991  }
992  }
993  }
994 
995  SDL_zero(fullscreen_mode);
996  switch (state->depth) {
997  case 8:
998  fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
999  break;
1000  case 15:
1001  fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
1002  break;
1003  case 16:
1004  fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
1005  break;
1006  case 24:
1007  fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
1008  break;
1009  default:
1010  fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
1011  break;
1012  }
1013  fullscreen_mode.refresh_rate = state->refresh_rate;
1014 
1015  state->windows =
1016  (SDL_Window **) SDL_calloc(state->num_windows,
1017  sizeof(*state->windows));
1018  state->renderers =
1019  (SDL_Renderer **) SDL_calloc(state->num_windows,
1020  sizeof(*state->renderers));
1021  state->targets =
1022  (SDL_Texture **) SDL_calloc(state->num_windows,
1023  sizeof(*state->targets));
1024  if (!state->windows || !state->renderers) {
1025  SDL_Log("Out of memory!\n");
1026  return SDL_FALSE;
1027  }
1028  for (i = 0; i < state->num_windows; ++i) {
1029  char title[1024];
1030  SDL_Rect r;
1031 
1032  r.x = state->window_x;
1033  r.y = state->window_y;
1034  r.w = state->window_w;
1035  r.h = state->window_h;
1036 
1037  /* !!! FIXME: hack to make --usable-bounds work for now. */
1038  if ((r.x == -1) && (r.y == -1) && (r.w == -1) && (r.h == -1)) {
1039  SDL_GetDisplayUsableBounds(state->display, &r);
1040  }
1041 
1042  if (state->num_windows > 1) {
1043  SDL_snprintf(title, SDL_arraysize(title), "%s %d",
1044  state->window_title, i + 1);
1045  } else {
1046  SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
1047  }
1048  state->windows[i] =
1049  SDL_CreateWindow(title, r.x, r.y, r.w, r.h, state->window_flags);
1050  if (!state->windows[i]) {
1051  SDL_Log("Couldn't create window: %s\n",
1052  SDL_GetError());
1053  return SDL_FALSE;
1054  }
1055  if (state->window_minW || state->window_minH) {
1056  SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
1057  }
1058  if (state->window_maxW || state->window_maxH) {
1059  SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
1060  }
1061  SDL_GetWindowSize(state->windows[i], &w, &h);
1062  if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
1063  (w != state->window_w || h != state->window_h)) {
1064  printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
1065  state->window_w = w;
1066  state->window_h = h;
1067  }
1068  if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
1069  SDL_Log("Can't set up fullscreen display mode: %s\n",
1070  SDL_GetError());
1071  return SDL_FALSE;
1072  }
1073 
1074  /* Add resize/drag areas for windows that are borderless and resizable */
1075  if ((state->window_flags & (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) ==
1078  }
1079 
1080  if (state->window_icon) {
1081  SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
1082  if (icon) {
1083  SDL_SetWindowIcon(state->windows[i], icon);
1084  SDL_FreeSurface(icon);
1085  }
1086  }
1087 
1088  SDL_ShowWindow(state->windows[i]);
1089 
1090  if (!state->skip_renderer
1091  && (state->renderdriver
1092  || !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN)))) {
1093  m = -1;
1094  if (state->renderdriver) {
1095  SDL_RendererInfo info;
1097  for (j = 0; j < n; ++j) {
1098  SDL_GetRenderDriverInfo(j, &info);
1099  if (SDL_strcasecmp(info.name, state->renderdriver) ==
1100  0) {
1101  m = j;
1102  break;
1103  }
1104  }
1105  if (m == -1) {
1106  SDL_Log("Couldn't find render driver named %s",
1107  state->renderdriver);
1108  return SDL_FALSE;
1109  }
1110  }
1111  state->renderers[i] = SDL_CreateRenderer(state->windows[i],
1112  m, state->render_flags);
1113  if (!state->renderers[i]) {
1114  SDL_Log("Couldn't create renderer: %s\n",
1115  SDL_GetError());
1116  return SDL_FALSE;
1117  }
1118  if (state->logical_w && state->logical_h) {
1119  SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h);
1120  } else if (state->scale != 0.) {
1121  SDL_RenderSetScale(state->renderers[i], state->scale, state->scale);
1122  }
1123  if (state->verbose & VERBOSE_RENDER) {
1124  SDL_RendererInfo info;
1125 
1126  SDL_Log("Current renderer:\n");
1127  SDL_GetRendererInfo(state->renderers[i], &info);
1128  SDLTest_PrintRenderer(&info);
1129  }
1130  }
1131  }
1132  }
1133 
1134  if (state->flags & SDL_INIT_AUDIO) {
1135  if (state->verbose & VERBOSE_AUDIO) {
1137  if (n == 0) {
1138  SDL_Log("No built-in audio drivers\n");
1139  } else {
1140  SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
1141  for (i = 0; i < n; ++i) {
1142  if (i > 0) {
1143  SDL_snprintfcat(text, sizeof(text), ",");
1144  }
1145  SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
1146  }
1147  SDL_Log("%s\n", text);
1148  }
1149  }
1150  if (SDL_AudioInit(state->audiodriver) < 0) {
1151  SDL_Log("Couldn't initialize audio driver: %s\n",
1152  SDL_GetError());
1153  return SDL_FALSE;
1154  }
1155  if (state->verbose & VERBOSE_AUDIO) {
1156  SDL_Log("Audio driver: %s\n",
1158  }
1159 
1160  if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
1161  SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
1162  return SDL_FALSE;
1163  }
1164  }
1165 
1166  return SDL_TRUE;
1167 }
#define SDL_INIT_AUDIO
Definition: SDL.h:81
#define SDL_INIT_VIDEO
Definition: SDL.h:82
#define SDL_SetWindowHitTest
#define SDL_GetError
#define SDL_SetWindowMinimumSize
#define SDL_GetCurrentVideoDriver
#define SDL_AudioInit
#define SDL_VideoInit
#define SDL_CreateWindow
#define SDL_GetNumAudioDrivers
#define SDL_GetPixelFormatName
#define SDL_GetRenderDriverInfo
#define SDL_GetDisplayName
#define SDL_RenderSetLogicalSize
#define SDL_ShowWindow
#define SDL_OpenAudio
#define SDL_GetDisplayDPI
#define SDL_RenderSetScale
#define SDL_CreateRenderer
#define SDL_GetNumDisplayModes
#define SDL_GL_SetAttribute
#define SDL_GetCurrentAudioDriver
#define SDL_strlcpy
#define SDL_SetWindowIcon
#define SDL_PixelFormatEnumToMasks
#define SDL_GetDisplayMode
#define SDL_SetWindowMaximumSize
#define SDL_GetNumRenderDrivers
#define SDL_GetVideoDriver
#define SDL_GetRendererInfo
#define SDL_SetWindowDisplayMode
#define SDL_FreeSurface
#define SDL_GetDesktopDisplayMode
#define SDL_GetDisplayBounds
#define SDL_GetAudioDriver
#define SDL_GetNumVideoDrivers
#define SDL_GetDisplayUsableBounds
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
const GLfloat * m
GLenum mode
GLdouble n
@ SDL_PIXELFORMAT_RGB555
Definition: SDL_pixels.h:202
@ SDL_PIXELFORMAT_INDEX8
Definition: SDL_pixels.h:186
@ SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:237
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:246
@ SDL_PIXELFORMAT_RGB565
Definition: SDL_pixels.h:231
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
int SDL_Direct3D9GetAdapterIndex(int displayIndex)
Returns the D3D9 adapter index that matches the specified display index.
SDL_bool SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
Returns the DXGI Adapter and Output indices for the specified display index.
static void SDLTest_PrintRenderer(SDL_RendererInfo *info)
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
static SDL_HitTestResult SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
static SDL_Surface * SDLTest_LoadIcon(const char *file)
#define VERBOSE_AUDIO
@ SDL_GL_DOUBLEBUFFER
Definition: SDL_video.h:207
@ SDL_GL_STENCIL_SIZE
Definition: SDL_video.h:209
@ SDL_GL_CONTEXT_MAJOR_VERSION
Definition: SDL_video.h:219
@ SDL_GL_ACCUM_ALPHA_SIZE
Definition: SDL_video.h:213
@ SDL_GL_MULTISAMPLESAMPLES
Definition: SDL_video.h:216
@ SDL_GL_CONTEXT_MINOR_VERSION
Definition: SDL_video.h:220
@ SDL_GL_STEREO
Definition: SDL_video.h:214
@ SDL_GL_MULTISAMPLEBUFFERS
Definition: SDL_video.h:215
@ SDL_GL_ACCUM_GREEN_SIZE
Definition: SDL_video.h:211
@ SDL_GL_BLUE_SIZE
Definition: SDL_video.h:204
@ SDL_GL_RETAINED_BACKING
Definition: SDL_video.h:218
@ SDL_GL_RED_SIZE
Definition: SDL_video.h:202
@ SDL_GL_ALPHA_SIZE
Definition: SDL_video.h:205
@ SDL_GL_BUFFER_SIZE
Definition: SDL_video.h:206
@ SDL_GL_ACCELERATED_VISUAL
Definition: SDL_video.h:217
@ SDL_GL_ACCUM_BLUE_SIZE
Definition: SDL_video.h:212
@ SDL_GL_DEPTH_SIZE
Definition: SDL_video.h:208
@ SDL_GL_ACCUM_RED_SIZE
Definition: SDL_video.h:210
@ SDL_GL_CONTEXT_FLAGS
Definition: SDL_video.h:222
@ SDL_GL_CONTEXT_PROFILE_MASK
Definition: SDL_video.h:223
@ SDL_GL_GREEN_SIZE
Definition: SDL_video.h:203
@ SDL_WINDOW_VULKAN
Definition: SDL_video.h:121
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:100
@ SDL_GL_CONTEXT_DEBUG_FLAG
Definition: SDL_video.h:240
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
The structure that defines a display mode.
Definition: SDL_video.h:54
Uint32 format
Definition: SDL_video.h:55
Information on the capabilities of a render driver or context.
Definition: SDL_render.h:79
const char * name
Definition: SDL_render.h:80
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71

References bpp, SDL_DisplayMode::format, SDL_Rect::h, i, j, SDL_RendererInfo::name, NULL, SDL_DisplayMode::refresh_rate, SDL_arraysize, SDL_AudioInit, SDL_calloc, SDL_CreateRenderer, SDL_CreateWindow, SDL_Direct3D9GetAdapterIndex(), SDL_DXGIGetOutputInfo(), SDL_FALSE, SDL_FreeSurface, SDL_GetAudioDriver, SDL_GetCurrentAudioDriver, SDL_GetCurrentVideoDriver, SDL_GetDesktopDisplayMode, SDL_GetDisplayBounds, SDL_GetDisplayDPI, SDL_GetDisplayMode, SDL_GetDisplayName, SDL_GetDisplayUsableBounds, SDL_GetError, SDL_GetNumAudioDrivers, SDL_GetNumDisplayModes, SDL_GetNumRenderDrivers, SDL_GetNumVideoDisplays, SDL_GetNumVideoDrivers, SDL_GetPixelFormatName, SDL_GetRenderDriverInfo, SDL_GetRendererInfo, SDL_GetVideoDriver, SDL_GetWindowSize, SDL_GL_ACCELERATED_VISUAL, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_GREEN_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ALPHA_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_CONTEXT_DEBUG_FLAG, SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_DEPTH_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_GREEN_SIZE, SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES, SDL_GL_RED_SIZE, SDL_GL_RETAINED_BACKING, SDL_GL_SetAttribute, SDL_GL_STENCIL_SIZE, SDL_GL_STEREO, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_Log, SDL_OpenAudio, SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT_RGB555, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB888, SDL_PixelFormatEnumToMasks, SDL_RenderSetLogicalSize, SDL_RenderSetScale, SDL_SetWindowDisplayMode, SDL_SetWindowHitTest, SDL_SetWindowIcon, SDL_SetWindowMaximumSize, SDL_SetWindowMinimumSize, SDL_ShowWindow, SDL_snprintf, SDL_snprintfcat(), SDL_strcasecmp, SDL_strlcpy, SDL_TRUE, SDL_VideoInit, SDL_WINDOW_BORDERLESS, SDL_WINDOW_OPENGL, SDL_WINDOW_RESIZABLE, SDL_WINDOW_VULKAN, SDL_zero, SDLTest_ExampleHitTestCallback(), SDLTest_LoadIcon(), SDLTest_PrintRenderer(), state, text, VERBOSE_AUDIO, VERBOSE_MODES, VERBOSE_RENDER, VERBOSE_VIDEO, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by main().

◆ SDLTest_CommonLogUsage()

void SDLTest_CommonLogUsage ( SDLTest_CommonState state,
const char *  argv0,
const char **  options 
)

Logs command line usage info.

This logs the appropriate command line options for the subsystems in use plus other common options, and then any application-specific options. This uses the SDL_Log() function and splits up output to be friendly to 80-character-wide terminals.

Parameters
stateThe common state describing the test window for the app.
argv0argv[0], as passed to main/SDL_main.
optionsan array of strings for application specific options. The last element of the array should be NULL.

Definition at line 498 of file SDL_test_common.c.

499 {
500  int i;
501 
502  SDL_Log("USAGE: %s", argv0);
503  SDL_Log(" %s", "[--trackmem]");
504 
505  if (state->flags & SDL_INIT_VIDEO) {
506  for (i = 0; i < SDL_arraysize(video_usage); i++) {
507  SDL_Log(" %s", video_usage[i]);
508  }
509  }
510 
511  if (state->flags & SDL_INIT_AUDIO) {
512  for (i = 0; i < SDL_arraysize(audio_usage); i++) {
513  SDL_Log(" %s", audio_usage[i]);
514  }
515  }
516 
517  if (options) {
518  for (i = 0; options[i] != NULL; i++) {
519  SDL_Log(" %s", options[i]);
520  }
521  }
522 }
static const char * video_usage[]
static const char * audio_usage[]

References audio_usage, i, NULL, SDL_arraysize, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_Log, state, and video_usage.

Referenced by main(), and SDLTest_CommonDefaultArgs().

◆ SDLTest_CommonQuit()

void SDLTest_CommonQuit ( SDLTest_CommonState state)

Close test window.

Parameters
stateThe common state used to create test window.

Definition at line 1912 of file SDL_test_common.c.

1913 {
1914  int i;
1915 
1922 
1923  SDL_free(state->windows);
1924  if (state->targets) {
1925  for (i = 0; i < state->num_windows; ++i) {
1926  if (state->targets[i]) {
1927  SDL_DestroyTexture(state->targets[i]);
1928  }
1929  }
1930  SDL_free(state->targets);
1931  }
1932  if (state->renderers) {
1933  for (i = 0; i < state->num_windows; ++i) {
1934  if (state->renderers[i]) {
1935  SDL_DestroyRenderer(state->renderers[i]);
1936  }
1937  }
1938  SDL_free(state->renderers);
1939  }
1940  if (state->flags & SDL_INIT_VIDEO) {
1941  SDL_VideoQuit();
1942  }
1943  if (state->flags & SDL_INIT_AUDIO) {
1944  SDL_AudioQuit();
1945  }
1946  SDL_free(state);
1947  SDL_Quit();
1949 }
#define SDL_AudioQuit
#define SDL_VideoQuit
#define SDL_Quit
static char * common_usage_video
static char * common_usage_audio
static char * common_usage_videoaudio
void SDLTest_LogAllocations(void)
Print a log of any outstanding allocations.

References common_usage_audio, common_usage_video, common_usage_videoaudio, i, NULL, SDL_AudioQuit, SDL_DestroyRenderer, SDL_DestroyTexture, SDL_free, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_Quit, SDL_VideoQuit, SDLTest_LogAllocations(), and state.

Referenced by main(), and quit().

◆ SDLTest_CommonUsage()

const char* SDLTest_CommonUsage ( SDLTest_CommonState state)

Returns common usage information.

You should (probably) be using SDLTest_CommonLogUsage() instead, but this function remains for binary compatibility. Strings returned from this function are valid until SDLTest_CommonQuit() is called, in which case those strings' memory is freed and can no longer be used.

Parameters
stateThe common state describing the test window to create.
Returns
String with usage information

Definition at line 567 of file SDL_test_common.c.

568 {
569 
570  switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
571  case SDL_INIT_VIDEO:
573  case SDL_INIT_AUDIO:
577  default:
578  return "[--trackmem]";
579  }
580 }
static const char * BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2)

References audio_usage, BuildCommonUsageString(), common_usage_audio, common_usage_video, common_usage_videoaudio, NULL, SDL_arraysize, SDL_INIT_AUDIO, SDL_INIT_VIDEO, state, and video_usage.