int stdlib_sscanf(void *arg) { int output; int result; int expected_output; int expected_result; expected_output = output = 123; expected_result = -1; result = SDL_sscanf("", "%i", &output); SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)"); SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output); SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); expected_output = output = 123; expected_result = 0; result = SDL_sscanf("a", "%i", &output); SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)"); SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output); SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); output = 123; expected_output = 2; expected_result = 1; result = SDL_sscanf("2", "%i", &output); SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)"); SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output); SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); return TEST_COMPLETED; }
int main(int argc, char *argv[]) { static int nums[1024 * 100]; static const int itervals[] = { SDL_arraysize(nums), 12 }; int iteration; SDLTest_RandomContext rndctx; if (argc > 1) { int success; Uint64 seed = 0; if (argv[1][0] == '0' && argv[1][1] == 'x') success = SDL_sscanf(argv[1] + 2, "%llx", &seed); else success = SDL_sscanf(argv[1], "%llu", &seed); if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n"); return 1; } if (seed <= 0xffffffff) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n"); return 1; } SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff)); }
/* This whole function is a hack. :) */ static Uint32 get_video_size(_THIS) { /* This is a non-exported function from libXxf86dga.a */ extern unsigned char *SDL_NAME(XDGAGetMappedMemory)(int screen); FILE *proc; unsigned long mem; unsigned start, stop; char line[BUFSIZ]; Uint32 size; mem = (unsigned long)SDL_NAME(XDGAGetMappedMemory)(DGA_Screen); size = 0; proc = fopen("/proc/self/maps", "r"); if ( proc ) { while ( fgets(line, sizeof(line)-1, proc) ) { SDL_sscanf(line, "%x-%x", &start, &stop); if ( start == mem ) { size = (Uint32)((stop-start)/1024); break; } } fclose(proc); } return(size); }
static int get_header(SDL_RWops *src, int *w, int *h) { char line[1024]; *w = 0; *h = 0; /* Check the header magic */ if ( (get_line(src, line, sizeof(line)) < 0) || (SDL_memcmp(line, "P7 332", 6) != 0) ) { return -1; } /* Read the header */ while ( get_line(src, line, sizeof(line)) == 0 ) { if ( SDL_memcmp(line, "#BUILTIN:", 9) == 0 ) { /* Builtin image, no data */ break; } if ( SDL_memcmp(line, "#END_OF_COMMENTS", 16) == 0 ) { if ( get_line(src, line, sizeof(line)) == 0 ) { SDL_sscanf(line, "%d %d", w, h); if ( *w >= 0 && *h >= 0 ) { return 0; } } break; } } /* No image data */ return -1; }
int WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { HWND hwnd = (HWND) data; LPTSTR title; int titleLen; /* Query the title from the existing window */ titleLen = GetWindowTextLength(hwnd); title = SDL_stack_alloc(TCHAR, titleLen + 1); if (title) { titleLen = GetWindowText(hwnd, title, titleLen); } else { titleLen = 0; } if (titleLen > 0) { window->title = WIN_StringToUTF8(title); } if (title) { SDL_stack_free(title); } if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) { return -1; } // Urho3D: if window will be used for OpenGL, choose pixel format if (window->flags & SDL_WINDOW_OPENGL) { if (WIN_GL_SetupWindow(_this, window) < 0) { return -1; } } #if SDL_VIDEO_OPENGL_WGL { const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT); if (hint) { // This hint is a pointer (in string form) of the address of // the window to share a pixel format with SDL_Window *otherWindow = NULL; SDL_sscanf(hint, "%p", (void**)&otherWindow); // Do some error checking on the pointer if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) { // If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well if (otherWindow->flags & SDL_WINDOW_OPENGL) { window->flags |= SDL_WINDOW_OPENGL; if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) { return -1; } } } } } #endif return 0; }
char *skip_version(char *src) { int glslVersion = -1; SDL_sscanf(src, "#version %d", &glslVersion); if( glslVersion != -1 ){ char *eol = strstr(src, "\n"); for(int i = 0; i < eol-src; i++) src[i]=' '; } return src; }
/* Workaround for older pulse: pa_context_new() must have non-NULL appname */ static const char * getAppName(void) { const char *verstr = PULSEAUDIO_pa_get_library_version(); if (verstr != NULL) { int maj, min, patch; if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) { if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) { return NULL; /* 0.9.15+ handles NULL correctly. */ } } } return "SDL Application"; /* oh well. */ }
static void GetEnvironmentWindowPosition(int w, int h, int *x, int *y) { int display = GetVideoDisplay(); const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); const char *center = SDL_getenv("SDL_VIDEO_CENTERED"); if (window) { if (SDL_sscanf(window, "%d,%d", x, y) == 2) { return; } if (SDL_strcmp(window, "center") == 0) { center = window; } } if (center) { *x = SDL_WINDOWPOS_CENTERED_DISPLAY(display); *y = SDL_WINDOWPOS_CENTERED_DISPLAY(display); } }
static void GetEnvironmentWindowPosition(int w, int h, int *x, int *y) { const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); const char *center = SDL_getenv("SDL_VIDEO_CENTERED"); if (window) { if (SDL_sscanf(window, "%d,%d", x, y) == 2) { return; } if (SDL_strcmp(window, "center") == 0) { center = window; } } if (center) { SDL_DisplayMode mode; SDL_GetDesktopDisplayMode(&mode); *x = (mode.w - w) / 2; *y = (mode.h - h) / 2; } }
int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode) { PgDisplaySettings_t settings; int mode; char* refreshrate; int refreshratenum; if (!currently_fullscreen) { /* Get the video mode and set it */ if (screen->flags & SDL_ANYFORMAT) { if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0) { SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n"); return 0; } } else { if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0) { SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n"); return 0; } if (PgGetVideoModeInfo(mode, &mode_info) < 0) { SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n"); return 0; } if (mode_info.height != screen->h) { if ((mode_info.height==480) && (screen->h==400)) { videomode_emulatemode=1; } } else { videomode_emulatemode=0; } } /* save old video mode caps */ PgGetVideoMode(&settings); old_video_mode=settings.mode; old_refresh_rate=settings.refresh; /* setup new video mode */ settings.mode = mode; settings.refresh = 0; settings.flags = 0; refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH"); if (refreshrate!=NULL) { if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1) { settings.refresh = refreshratenum; } } if (PgSetVideoMode(&settings) < 0) { SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n"); return 0; } if (this->screen) { if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) { #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) return 0; /* 6.3.0 */ #endif } } if (fmode==0) { if (OCImage.direct_context==NULL) { OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); if (!OCImage.direct_context) { SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n"); ph_LeaveFullScreen(this); return 0; } } OCImage.oldDC=PdDirectStart(OCImage.direct_context); } currently_fullscreen = 1; } PgFlush(); return 1; }
static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) { SDL_bool handled; unsigned char n; int tmp_naxes, tmp_nhats, tmp_nballs; const char *name; char *env, env_name[128]; int i; handled = SDL_FALSE; /* Default joystick device settings */ if ( ioctl(fd, JSIOCGAXES, &n) < 0 ) { joystick->naxes = 2; } else { joystick->naxes = n; } if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { joystick->nbuttons = 2; } else { joystick->nbuttons = n; } name = SDL_SYS_JoystickName(joystick->index); /* Generic analog joystick support */ if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) { if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat", &tmp_naxes, &tmp_nhats) == 2 ) { joystick->naxes = tmp_naxes; joystick->nhats = tmp_nhats; handled = SDL_TRUE; } } /* Special joystick support */ for ( i=0; i < SDL_arraysize(special_joysticks); ++i ) { if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) { joystick->naxes = special_joysticks[i].naxes; joystick->nhats = special_joysticks[i].nhats; joystick->nballs = special_joysticks[i].nballs; handled = SDL_TRUE; break; } } /* User environment joystick support */ if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) { *env_name = '\0'; if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 ) env += SDL_strlen(env_name)+2; else if ( SDL_sscanf(env, "%s", env_name) == 1 ) env += SDL_strlen(env_name); if ( SDL_strcmp(name, env_name) == 0 ) { if ( SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, &tmp_nballs) == 3 ) { joystick->naxes = tmp_naxes; joystick->nhats = tmp_nhats; joystick->nballs = tmp_nballs; handled = SDL_TRUE; } } } /* Remap hats and balls */ if (handled) { if ( joystick->nhats > 0 ) { if ( allocate_hatdata(joystick) < 0 ) { joystick->nhats = 0; } } if ( joystick->nballs > 0 ) { if ( allocate_balldata(joystick) < 0 ) { joystick->nballs = 0; } } } return(handled); }
/* read XPM from either array or RWops */ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) { Sint64 start = 0; SDL_Surface *image = NULL; int index; int x, y; int w, h, ncolors, cpp; int indexed; Uint8 *dst; struct color_hash *colors = NULL; SDL_Color *im_colors = NULL; char *keystrings = NULL, *nextkey; const char *line; const char ***xpmlines = NULL; int pixels_len; error = NULL; linebuf = NULL; buflen = 0; if (src) start = SDL_RWtell(src); if (xpm) xpmlines = &xpm; line = get_next_line(xpmlines, src, 0); if (!line) goto done; /* * The header string of an XPMv3 image has the format * * <width> <height> <ncolors> <cpp> [ <hotspot_x> <hotspot_y> ] * * where the hotspot coords are intended for mouse cursors. * Right now we don't use the hotspots but it should be handled * one day. */ if (SDL_sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4 || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) { error = "Invalid format description"; goto done; } keystrings = (char *)SDL_malloc(ncolors * cpp); if (!keystrings) { error = "Out of memory"; goto done; } nextkey = keystrings; /* Create the new surface */ if (ncolors <= 256) { indexed = 1; image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, 0, 0, 0, 0); im_colors = image->format->palette->colors; image->format->palette->ncolors = ncolors; } else { indexed = 0; image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0xff0000, 0x00ff00, 0x0000ff, 0); } if (!image) { /* Hmm, some SDL error (out of memory?) */ goto done; } /* Read the colors */ colors = create_colorhash(ncolors); if (!colors) { error = "Out of memory"; goto done; } for (index = 0; index < ncolors; ++index ) { const char *p; line = get_next_line(xpmlines, src, 0); if (!line) goto done; p = line + cpp + 1; /* parse a colour definition */ for (;;) { char nametype; const char *colname; Uint32 rgb, pixel; SKIPSPACE(p); if (!*p) { error = "colour parse error"; goto done; } nametype = *p; SKIPNONSPACE(p); SKIPSPACE(p); colname = p; SKIPNONSPACE(p); if (nametype == 's') continue; /* skip symbolic colour names */ if (!color_to_rgb(colname, (int)(p - colname), &rgb)) continue; SDL_memcpy(nextkey, line, cpp); if (indexed) { SDL_Color *c = im_colors + index; c->r = (Uint8)(rgb >> 16); c->g = (Uint8)(rgb >> 8); c->b = (Uint8)(rgb); pixel = index; } else pixel = rgb; add_colorhash(colors, nextkey, cpp, pixel); nextkey += cpp; if (rgb == 0xffffffff) SDL_SetColorKey(image, SDL_TRUE, pixel); break; } }
int SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform) { void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */ const char *path = NULL; int egl_version_major = 0, egl_version_minor = 0; #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT const char *d3dcompiler; #endif if (_this->egl_data) { return SDL_SetError("OpenGL ES context already created"); } _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData)); if (!_this->egl_data) { return SDL_OutOfMemory(); } #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER); if (!d3dcompiler) { if (WIN_IsWindowsVistaOrGreater()) { d3dcompiler = "d3dcompiler_46.dll"; } else { d3dcompiler = "d3dcompiler_43.dll"; } } if (SDL_strcasecmp(d3dcompiler, "none") != 0) { if (SDL_LoadObject(d3dcompiler) == NULL) { SDL_ClearError(); } } #endif #ifndef SDL_VIDEO_STATIC_ANGLE /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */ path = SDL_getenv("SDL_VIDEO_GL_DRIVER"); if (path != NULL) { egl_dll_handle = SDL_LoadObject(path); } if (egl_dll_handle == NULL) { if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { if (_this->gl_config.major_version > 1) { path = DEFAULT_OGL_ES2; egl_dll_handle = SDL_LoadObject(path); #ifdef ALT_OGL_ES2 if (egl_dll_handle == NULL) { path = ALT_OGL_ES2; egl_dll_handle = SDL_LoadObject(path); } #endif } else { path = DEFAULT_OGL_ES; egl_dll_handle = SDL_LoadObject(path); if (egl_dll_handle == NULL) { path = DEFAULT_OGL_ES_PVR; egl_dll_handle = SDL_LoadObject(path); } } } #ifdef DEFAULT_OGL else { path = DEFAULT_OGL; egl_dll_handle = SDL_LoadObject(path); } #endif } _this->egl_data->egl_dll_handle = egl_dll_handle; if (egl_dll_handle == NULL) { return SDL_SetError("Could not initialize OpenGL / GLES library"); } /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */ if (egl_path != NULL) { dll_handle = SDL_LoadObject(egl_path); } /* Try loading a EGL symbol, if it does not work try the default library paths */ if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) { if (dll_handle != NULL) { SDL_UnloadObject(dll_handle); } path = SDL_getenv("SDL_VIDEO_EGL_DRIVER"); if (path == NULL) { path = DEFAULT_EGL; } dll_handle = SDL_LoadObject(path); #ifdef ALT_EGL if (dll_handle == NULL) { path = ALT_EGL; dll_handle = SDL_LoadObject(path); } #endif if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) { if (dll_handle != NULL) { SDL_UnloadObject(dll_handle); } return SDL_SetError("Could not load EGL library"); } SDL_ClearError(); } #endif _this->egl_data->dll_handle = dll_handle; /* Load new function pointers */ LOAD_FUNC(eglGetDisplay); LOAD_FUNC(eglInitialize); LOAD_FUNC(eglTerminate); LOAD_FUNC(eglGetProcAddress); LOAD_FUNC(eglChooseConfig); LOAD_FUNC(eglGetConfigAttrib); LOAD_FUNC(eglCreateContext); LOAD_FUNC(eglDestroyContext); LOAD_FUNC(eglCreateWindowSurface); LOAD_FUNC(eglDestroySurface); LOAD_FUNC(eglMakeCurrent); LOAD_FUNC(eglSwapBuffers); LOAD_FUNC(eglSwapInterval); LOAD_FUNC(eglWaitNative); LOAD_FUNC(eglWaitGL); LOAD_FUNC(eglBindAPI); LOAD_FUNC(eglQueryString); LOAD_FUNC(eglGetError); if (_this->egl_data->eglQueryString) { /* EGL 1.5 allows querying for client version */ const char *egl_version = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_VERSION); if (egl_version != NULL) { if (SDL_sscanf(egl_version, "%d.%d", &egl_version_major, &egl_version_minor) != 2) { egl_version_major = 0; egl_version_minor = 0; SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not parse EGL version string: %s", egl_version); } } } if (egl_version_major == 1 && egl_version_minor == 5) { LOAD_FUNC(eglGetPlatformDisplay); } _this->egl_data->egl_display = EGL_NO_DISPLAY; #if !defined(__WINRT__) if (platform) { if (egl_version_major == 1 && egl_version_minor == 5) { _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplay(platform, (void *)(size_t)native_display, NULL); } else { if (SDL_EGL_HasExtension(_this, SDL_EGL_CLIENT_EXTENSION, "EGL_EXT_platform_base")) { _this->egl_data->eglGetPlatformDisplayEXT = SDL_EGL_GetProcAddress(_this, "eglGetPlatformDisplayEXT"); if (_this->egl_data->eglGetPlatformDisplayEXT) { _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplayEXT(platform, (void *)(size_t)native_display, NULL); } } } } /* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */ if (_this->egl_data->egl_display == EGL_NO_DISPLAY) { _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display); } if (_this->egl_data->egl_display == EGL_NO_DISPLAY) { return SDL_SetError("Could not get EGL display"); } if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) { return SDL_SetError("Could not initialize EGL"); } #endif if (path) { SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1); } else { *_this->gl_config.driver_path = '\0'; } return 0; }
static int ph_SetupWindow(_THIS, int w, int h, int flags) { PtArg_t args[32]; PhPoint_t pos = {0, 0}; PhDim_t* olddim; PhDim_t dim = {w, h}; PhRect_t desktopextent; int nargs = 0; const char* windowpos; const char* iscentered; int x, y; /* check if window size has been changed by Window Manager */ PtGetResource(window, Pt_ARG_DIM, &olddim, 0); if ((olddim->w!=w) || (olddim->h!=h)) { PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0); } if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE) { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_CLOSE | Ph_WM_MAX | Ph_WM_RESTORE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED); } else { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN); PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); } if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)) { if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); } else { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER); } } else { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE | Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN); } if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0); PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY); } else { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_FFRONT | Ph_WM_CONSWITCH); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY); if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL); } else { PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0); } if (!currently_maximized) { windowpos = SDL_getenv("SDL_VIDEO_WINDOW_POS"); iscentered = SDL_getenv("SDL_VIDEO_CENTERED"); if ((iscentered) || ((windowpos) && (SDL_strcmp(windowpos, "center")==0))) { PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent); if (desktop_mode.width>w) { pos.x = (desktop_mode.width - w)/2; } if (desktop_mode.height>h) { pos.y = (desktop_mode.height - h)/2; } pos.x+=desktopextent.ul.x; pos.y+=desktopextent.ul.y; PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0); } else { if (windowpos) { if (SDL_sscanf(windowpos, "%d,%d", &x, &y) == 2) { if ((x<desktop_mode.width) && (y<desktop_mode.height)) { PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent); pos.x=x+desktopextent.ul.x; pos.y=y+desktopextent.ul.y; } PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0); } } } } /* if window is maximized render it as maximized */ if (currently_maximized) { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISMAX); } else { PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISMAX); } /* do not grab the keyboard by default */ PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISALTKEY); /* bring the focus to the window */ PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFOCUS); /* allow to catch hide event */ PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE); } PtSetResources(window, nargs, args); PtRealizeWidget(window); PtWindowToFront(window); #if 0 /* FIXME */ PtGetResource(window, Pt_ARG_POS, &olddim, 0); fprintf(stderr, "POSITION: %d, %d\n", olddim->w, olddim->h); #endif return 0; }
void mythStreamMapServer::ServerDecodeCallBack(MythSocket* people, char* data, int datalength) { if (strstr(data, "GET /list")){ string tmp = showAllClients(); /* HTTP/1.1 200 OK Date: Sat, 31 Dec 2005 23:59:59 GMT Content-Type: text/html;charset=ISO-8859-1 Content-Length: 122 */ //int len = tmp.length(); //char header[256] = { 0 }; //sprintf(header, "HTTP/1.1 200 OK\r\nDate: Sat, 31 Dec 2005 23:59:59 GMT\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n", len); //people->socket_SendStr(header); people->socket_SendStr(tmp.c_str(),tmp.length()); closePeople(people); //people->socket_CloseSocket(1); return; } map<int,mythStreamServer*>::iterator Iter; int cameraid = -1; char cameratype[20] = { 0 }; SDL_sscanf(data,"GET /CameraID=%d&Type=%s ",&cameraid,cameratype); if(cameraid != -1){ mythStreamServer* server = NULL; //find cameraid from map Iter = servermap.find(cameraid); if(Iter == servermap.end() || Iter->second == NULL){ //if (servermap[cameraid] != NULL){ SDL_LockMutex(mapmutex); server = mythStreamServer::CreateNew(cameraid); //add a new server into map list,not found ,so create servermap[cameraid] = server; SDL_UnlockMutex(mapmutex); server->start(); } else{ SDL_LockMutex(mapmutex); server = Iter->second; //find an existing server from map list,then add client into server list SDL_UnlockMutex(mapmutex); } mythBaseClient* client = NULL; if(!people->addtionaldata){ SDL_LockMutex(mapmutex); int usingthread = read_profile_int("config", "usethread", 0, MYTH_INFORMATIONINI_FILE); client = mythBaseClient::CreateNew(people, usingthread,cameratype); people->data = server; people->addtionaldata = client; people->server = this; server->AppendClient(client); SDL_UnlockMutex(mapmutex); } } else{ SDL_sscanf(data, "PUT /CameraID=%d", &cameraid); if (cameraid != -1){ people->isPush = 1; mythStreamServer* server = NULL; //find cameraid from map Iter = servermap.find(cameraid); if (Iter == servermap.end() || Iter->second == NULL){ //if (servermap[cameraid] != NULL){ SDL_LockMutex(mapmutex); server = mythStreamServer::CreateNew(cameraid,people); //add a new server into map list,not found ,so create servermap[cameraid] = server; SDL_UnlockMutex(mapmutex); server->start(); } else{ SDL_LockMutex(mapmutex); server = Iter->second; //find an existing server from map list,then add client into server list if (server){ ((mythProxyDecoder*) server->GetDecoder())->refreshSocket(people); //problem } SDL_UnlockMutex(mapmutex); } /*mythBaseClient* client = NULL; if (!people->addtionaldata){ SDL_LockMutex(mapmutex); int usingthread = read_profile_int("config", "usethread", 0, MYTH_INFORMATIONINI_FILE); if (usingthread == 1) client = mythBaseClient::CreateNew(people, true); else client = mythBaseClient::CreateNew(people, false); people->data = server; people->addtionaldata = client; server->AppendClient(client); SDL_UnlockMutex(mapmutex); }*/ } else{ people->socket_SendStr("404"); closePeople(people); //ServerCloseCallBack(people); } } return; }
/* parser an argument, updates the state object and returns the number of arguments processed; returns -1 on failure */ static int ParseArg(char** argv, int index, SDLVisualTest_HarnessState* state) { if(!argv || !argv[index] || !state) return 0; if(StrCaseCmpIgnoreHyphen("sutapp", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for sutapp."); return -1; } SDL_strlcpy(state->sutapp, argv[index], MAX_PATH_LEN); SDLTest_Log("SUT Application: %s", state->sutapp); return 2; } else if(StrCaseCmpIgnoreHyphen("output-dir", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for output-dir."); return -1; } SDL_strlcpy(state->output_dir, argv[index], MAX_PATH_LEN); SDLTest_Log("Screenshot Output Directory: %s", state->output_dir); return 2; } else if(StrCaseCmpIgnoreHyphen("verify-dir", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for verify-dir."); return -1; } SDL_strlcpy(state->verify_dir, argv[index], MAX_PATH_LEN); SDLTest_Log("Screenshot Verification Directory: %s", state->verify_dir); return 2; } else if(StrCaseCmpIgnoreHyphen("sutargs", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for sutargs."); return -1; } SDL_strlcpy(state->sutargs, argv[index], MAX_SUT_ARGS_LEN); SDLTest_Log("SUT Arguments: %s", state->sutargs); return 2; } else if(StrCaseCmpIgnoreHyphen("timeout", argv[index]) == 0) { int hr, min, sec; index++; if(!argv[index] || SDL_sscanf(argv[index], "%d:%d:%d", &hr, &min, &sec) != 3) { SDLTest_LogError("Arguments parsing error: Invalid argument for timeout."); return -1; } state->timeout = (((hr * 60) + min) * 60 + sec) * 1000; SDLTest_Log("Maximum Timeout for each SUT run: %d milliseconds", state->timeout); return 2; } else if(StrCaseCmpIgnoreHyphen("parameter-config", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for parameter-config."); return -1; } SDLTest_Log("SUT Parameters file: %s", argv[index]); SDLVisualTest_FreeSUTConfig(&state->sut_config); if(!SDLVisualTest_ParseSUTConfig(argv[index], &state->sut_config)) { SDLTest_LogError("Failed to parse SUT parameters file"); return -1; } return 2; } else if(StrCaseCmpIgnoreHyphen("variator", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for variator."); return -1; } SDLTest_Log("Variator: %s", argv[index]); if(SDL_strcasecmp("exhaustive", argv[index]) == 0) state->variator_type = SDL_VARIATOR_EXHAUSTIVE; else if(SDL_strcasecmp("random", argv[index]) == 0) state->variator_type = SDL_VARIATOR_RANDOM; else { SDLTest_LogError("Arguments parsing error: Invalid variator name."); return -1; } return 2; } else if(StrCaseCmpIgnoreHyphen("num-variations", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: Invalid argument for num-variations."); return -1; } state->num_variations = SDL_atoi(argv[index]); SDLTest_Log("Number of variations to run: %d", state->num_variations); if(state->num_variations <= 0) { SDLTest_LogError("Arguments parsing error: num-variations must be positive."); return -1; } return 2; } else if(StrCaseCmpIgnoreHyphen("no-launch", argv[index]) == 0) { state->no_launch = SDL_TRUE; SDLTest_Log("SUT will not be launched."); return 1; } else if(StrCaseCmpIgnoreHyphen("action-config", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: invalid argument for action-config"); return -1; } SDLTest_Log("Action Config file: %s", argv[index]); SDLVisualTest_EmptyActionQueue(&state->action_queue); if(!SDLVisualTest_ParseActionConfig(argv[index], &state->action_queue)) { SDLTest_LogError("SDLVisualTest_ParseActionConfig() failed"); return -1; } return 2; } else if(StrCaseCmpIgnoreHyphen("config", argv[index]) == 0) { index++; if(!argv[index]) { SDLTest_LogError("Arguments parsing error: invalid argument for config"); return -1; } /* do nothing, this option has already been handled */ return 2; } return 0; }
int main(int argc, char *argv[]) { int result; int testIterations = 1; Uint64 userExecKey = 0; char *userRunSeed = NULL; char *filter = NULL; int i, done; SDL_Event event; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } /* Parse commandline */ for (i = 1; i < argc;) { int consumed; consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { consumed = -1; if (SDL_strcasecmp(argv[i], "--iterations") == 0) { if (argv[i + 1]) { testIterations = SDL_atoi(argv[i + 1]); if (testIterations < 1) testIterations = 1; consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--execKey") == 0) { if (argv[i + 1]) { SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, (long long unsigned int *)&userExecKey); consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--seed") == 0) { if (argv[i + 1]) { userRunSeed = SDL_strdup(argv[i + 1]); consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--filter") == 0) { if (argv[i + 1]) { filter = SDL_strdup(argv[i + 1]); consumed = 2; } } } if (consumed < 0) { SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } i += consumed; } /* Initialize common state */ if (!SDLTest_CommonInit(state)) { quit(2); } /* Create the windows, initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(renderer); } /* Call Harness */ result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations); /* Empty event queue */ done = 0; for (i=0; i<100; i++) { while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); } SDL_Delay(10); } /* Clean up */ SDL_free(userRunSeed); SDL_free(filter); /* Shutdown everything */ quit(result); return(result); }
SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { SDL_Surface *video; int prev_w, prev_h; Uint32 prev_flags; DWORD style; const DWORD directstyle = (WS_POPUP); const DWORD windowstyle = (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); const DWORD resizestyle = (WS_THICKFRAME|WS_MAXIMIZEBOX); int binfo_size; BITMAPINFO *binfo; HDC hdc; RECT bounds; int x, y; Uint32 Rmask, Gmask, Bmask; /* Clean up any GL context that may be hanging around */ if ( current->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } SDL_resizing = 1; /* Recalculate the bitmasks if necessary */ if ( bpp == current->format->BitsPerPixel ) { video = current; } else { switch (bpp) { case 15: case 16: if ( DIB_SussScreenDepth() == 15 ) { /* 5-5-5 */ Rmask = 0x00007c00; Gmask = 0x000003e0; Bmask = 0x0000001f; } else { /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; } break; case 24: case 32: /* GDI defined as 8-8-8 */ Rmask = 0x00ff0000; Gmask = 0x0000ff00; Bmask = 0x000000ff; break; default: Rmask = 0x00000000; Gmask = 0x00000000; Bmask = 0x00000000; break; } video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, Rmask, Gmask, Bmask, 0); if ( video == NULL ) { SDL_OutOfMemory(); return(NULL); } } /* Fill in part of the video surface */ prev_flags = video->flags; prev_w = video->w; prev_h = video->h; video->flags = 0; /* Clear flags */ video->w = width; video->h = height; video->pitch = SDL_CalculatePitch(video); /* Small fix for WinCE/Win32 - when activating window SDL_VideoSurface is equal to zero, so activating code is not called properly for fullscreen windows because macros WINDIB_FULLSCREEN uses SDL_VideoSurface */ SDL_VideoSurface = video; #if defined(_WIN32_WCE) if ( flags & SDL_FULLSCREEN ) video->flags |= SDL_FULLSCREEN; #endif #ifndef NO_CHANGEDISPLAYSETTINGS /* Set fullscreen mode if appropriate */ if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { DEVMODE settings; BOOL changed; SDL_memset(&settings, 0, sizeof(DEVMODE)); settings.dmSize = sizeof(DEVMODE); #ifdef _WIN32_WCE // try to rotate screen to fit requested resolution if( this->hidden->supportRotation ) { DWORD rotation; // ask current mode settings.dmFields = DM_DISPLAYORIENTATION; ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL); rotation = settings.dmDisplayOrientation; if( (width > GetDeviceCaps(GetDC(NULL), HORZRES)) && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) { switch( rotation ) { case DMDO_0: settings.dmDisplayOrientation = DMDO_90; break; case DMDO_270: settings.dmDisplayOrientation = DMDO_180; break; } if( settings.dmDisplayOrientation != rotation ) { // go to landscape this->hidden->origRotation = rotation; ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); } } if( (width < GetDeviceCaps(GetDC(NULL), HORZRES)) && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) { switch( rotation ) { case DMDO_90: settings.dmDisplayOrientation = DMDO_0; break; case DMDO_180: settings.dmDisplayOrientation = DMDO_270; break; } if( settings.dmDisplayOrientation != rotation ) { // go to portrait this->hidden->origRotation = rotation; ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); } } } #endif #ifndef _WIN32_WCE settings.dmBitsPerPel = video->format->BitsPerPixel; settings.dmPelsWidth = width; settings.dmPelsHeight = height; settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; if ( width <= (int)SDL_desktop_mode.dmPelsWidth && height <= (int)SDL_desktop_mode.dmPelsHeight ) { settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; settings.dmFields |= DM_DISPLAYFREQUENCY; } changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { settings.dmFields &= ~DM_DISPLAYFREQUENCY; changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); } #else changed = 1; #endif if ( changed ) { video->flags |= SDL_FULLSCREEN; SDL_fullscreen_mode = settings; } } #endif /* !NO_CHANGEDISPLAYSETTINGS */ /* Reset the palette and create a new one if necessary */ if ( grab_palette ) { DIB_ReleaseStaticColors(SDL_Window); grab_palette = FALSE; } if ( screen_pal != NULL ) { /* RJR: March 28, 2000 delete identity palette if switching from a palettized mode */ DeleteObject(screen_pal); screen_pal = NULL; } if ( screen_logpal != NULL ) { SDL_free(screen_logpal); screen_logpal = NULL; } if ( bpp <= 8 ) { /* RJR: March 28, 2000 create identity palette switching to a palettized mode */ DIB_CreatePalette(this, bpp); } style = GetWindowLong(SDL_Window, GWL_STYLE); style &= ~(resizestyle|WS_MAXIMIZE); if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { style &= ~windowstyle; style |= directstyle; } else { #ifndef NO_CHANGEDISPLAYSETTINGS if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); } #endif if ( flags & SDL_NOFRAME ) { style &= ~windowstyle; style |= directstyle; video->flags |= SDL_NOFRAME; } else { style &= ~directstyle; style |= windowstyle; if ( flags & SDL_RESIZABLE ) { style |= resizestyle; video->flags |= SDL_RESIZABLE; } } #if WS_MAXIMIZE if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; #endif } /* DJM: Don't piss of anyone who has setup his own window */ if ( !SDL_windowid ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Delete the old bitmap if necessary */ if ( screen_bmp != NULL ) { DeleteObject(screen_bmp); } if ( ! (flags & SDL_OPENGL) ) { BOOL is16bitmode = (video->format->BytesPerPixel == 2); /* Suss out the bitmap info header */ binfo_size = sizeof(*binfo); if( is16bitmode ) { /* 16bit modes, palette area used for rgb bitmasks */ binfo_size += 3*sizeof(DWORD); } else if ( video->format->palette ) { binfo_size += video->format->palette->ncolors * sizeof(RGBQUAD); } binfo = (BITMAPINFO *)SDL_malloc(binfo_size); if ( ! binfo ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_OutOfMemory(); return(NULL); } binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); binfo->bmiHeader.biWidth = video->w; binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ binfo->bmiHeader.biPlanes = 1; binfo->bmiHeader.biSizeImage = video->h * video->pitch; binfo->bmiHeader.biXPelsPerMeter = 0; binfo->bmiHeader.biYPelsPerMeter = 0; binfo->bmiHeader.biClrUsed = 0; binfo->bmiHeader.biClrImportant = 0; binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; if ( is16bitmode ) { /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ binfo->bmiHeader.biCompression = BI_BITFIELDS; ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; } else { binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ if ( video->format->palette ) { SDL_memset(binfo->bmiColors, 0, video->format->palette->ncolors*sizeof(RGBQUAD)); } } /* Create the offscreen bitmap buffer */ hdc = GetDC(SDL_Window); screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, (void **)(&video->pixels), NULL, 0); ReleaseDC(SDL_Window, hdc); SDL_free(binfo); if ( screen_bmp == NULL ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_SetError("Couldn't create DIB section"); return(NULL); } this->UpdateRects = DIB_NormalUpdate; /* Set video surface flags */ if ( screen_pal && (flags & (SDL_FULLSCREEN|SDL_HWPALETTE)) ) { grab_palette = TRUE; } /* BitBlt() maps colors for us */ video->flags |= SDL_HWPALETTE; } #ifndef _WIN32_WCE /* Resize the window */ if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { #else if ( !SDL_windowid ) { #endif HWND top; UINT swp_flags; const char *window = NULL; const char *center = NULL; if ( video->w != prev_w || video->h != prev_h ) { window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); center = SDL_getenv("SDL_VIDEO_CENTERED"); if ( window ) { if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) { SDL_windowX = x; SDL_windowY = y; } if ( SDL_strcmp(window, "center") == 0 ) { center = window; } } } swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); bounds.left = SDL_windowX; bounds.top = SDL_windowY; bounds.right = SDL_windowX+video->w; bounds.bottom = SDL_windowY+video->h; #ifndef _WIN32_WCE AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), (GetMenu(SDL_Window) != NULL), 0); #else // The bMenu parameter must be FALSE; menu bars are not supported AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), 0, 0); #endif width = bounds.right-bounds.left; height = bounds.bottom-bounds.top; if ( (flags & SDL_FULLSCREEN) ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else if ( center ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else if ( SDL_windowX || SDL_windowY || window ) { x = bounds.left; y = bounds.top; } else { x = y = -1; swp_flags |= SWP_NOMOVE; } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { top = HWND_NOTOPMOST; } SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); if ( !(flags & SDL_FULLSCREEN) ) { SDL_windowX = SDL_bounds.left; SDL_windowY = SDL_bounds.top; } SetForegroundWindow(SDL_Window); } SDL_resizing = 0; /* Set up for OpenGL */ if ( flags & SDL_OPENGL ) { if ( WIN_GL_SetupWindow(this) < 0 ) { return(NULL); } video->flags |= SDL_OPENGL; } /* JC 14 Mar 2006 Flush the message loop or this can cause big problems later Especially if the user decides to use dialog boxes or assert()! */ WIN_FlushMessageQueue(); /* We're live! */ return(video); } /* We don't actually allow hardware surfaces in the DIB driver */ static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) { return(-1); } static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) { return; } static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) { return(0); } static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) { return; } static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) { HDC hdc, mdc; int i; hdc = GetDC(SDL_Window); if ( screen_pal ) { SelectPalette(hdc, screen_pal, FALSE); } mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); for ( i=0; i<numrects; ++i ) { BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, mdc, rects[i].x, rects[i].y, SRCCOPY); } DeleteDC(mdc); ReleaseDC(SDL_Window, hdc); }