static bool SDL_AddDisplayMode(SDL_VideoDisplay display, SDL_DisplayMode mode) { SDL_DisplayMode[] modes; int i, nmodes; // Make sure we don't already have the mode in the list modes = display.display_modes; nmodes = display.num_display_modes; for (i = nmodes; CBool(i--);) { if (CompareMemory(mode, modes[i]) == 0) { return(false); } } // Go ahead and add the new mode if (nmodes == display.max_display_modes) { modes = Resize(display.display_modes, display.max_display_modes + 32); display.display_modes = modes; display.max_display_modes += 32; } modes[nmodes] = mode; display.num_display_modes++; // Re-sort video modes Array.Sort(display.display_modes, 0, display.num_display_modes , Comparer <SDL_DisplayMode> .Create(CompareModes)); return(true); }
static void SDL_SetDisplayModeForDisplay(SDL_VideoDisplay display, SDL_DisplayMode mode) { SDL_DisplayMode display_mode; SDL_DisplayMode current_mode; if (mode != null) { display_mode = mode.DeepCopy(); // Default to the current mode if (!CBool(display_mode.format)) { display_mode.format = display.current_mode.format; } if (!CBool(display_mode.w)) { display_mode.w = display.current_mode.w; } if (!CBool(display_mode.h)) { display_mode.h = display.current_mode.h; } if (!CBool(display_mode.refresh_rate)) { display_mode.refresh_rate = display.current_mode.refresh_rate; } // Get a good video mode, the closest one possible if (SDL_GetClosestDisplayModeForDisplay(display , display_mode , display_mode) == null) { throw new NativeException("No video mode large enough for {0}x{1}" , display_mode.w , display_mode.h); } } else { display_mode = display.desktop_mode; } // See if there's anything left to do current_mode = display.current_mode; if (CompareMemory(display_mode, current_mode) == 0) { return; } // Actually change the display mode if (_video.SetDisplayMode == null) { throw new NativeException("Video driver doesn't support changing display mode"); } _video.SetDisplayMode(_video, display, display_mode); display.current_mode = display_mode; }
static int CompareMemory(SDL_DisplayMode a, SDL_DisplayMode b) { if (a.format != b.format) { return((int)(a.format - b.format)); } if (a.w != b.w) { return(a.w - b.w); } if (a.h != b.h) { return(a.h - b.h); } if (a.refresh_rate != b.refresh_rate) { return(a.refresh_rate - b.refresh_rate); } if (_video.CompareMemory != null) { return(_video.CompareMemory(a.driverdata, b.driverdata)); } return(0); }
static int CompareModes(SDL_DisplayMode a, SDL_DisplayMode b) { if (a.w != b.w) { return(b.w - a.w); } if (a.h != b.h) { return(b.h - a.h); } if (SDL_BitsPerPixel(a.format) != SDL_BitsPerPixel(b.format)) { return((int)(SDL_BitsPerPixel(b.format) - SDL_BitsPerPixel(a.format))); } if (SDL_PixelLayout(a.format) != SDL_PixelLayout(b.format)) { return((int)(SDL_PixelLayout(b.format) - SDL_PixelLayout(a.format))); } if (a.refresh_rate != b.refresh_rate) { return(b.refresh_rate - a.refresh_rate);// ιεΊζε } return(0); }
static SDL_DisplayMode SDL_GetClosestDisplayModeForDisplay( SDL_VideoDisplay display, SDL_DisplayMode mode, SDL_DisplayMode closest) { uint target_format; int target_refresh_rate; int i; SDL_DisplayMode current, match; if (CBool(mode) || CBool(closest)) { throw new NativeException("Missing desired mode or closest mode parameter"); } // Default to the desktop format if (CBool(mode.format)) { target_format = mode.format; } else { target_format = display.desktop_mode.format; } // Default to the desktop refresh rate if (CBool(mode.refresh_rate)) { target_refresh_rate = mode.refresh_rate; } else { target_refresh_rate = display.desktop_mode.refresh_rate; } match = null; for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) { current = display.display_modes[i]; if (CBool(current.w) && (current.w < mode.w)) { // Out of sorted modes large enough here break; } if (CBool(current.h) && (current.h < mode.h)) { if (CBool(current.w) && (current.w == mode.w)) { // Out of sorted modes large enough here break; } /* * Wider, but not tall enough, due to a different * aspect ratio. This mode must be skipped, but closer * modes may still follow. */ continue; } if (match == null || current.w < match.w || current.h < match.h) { match = current; continue; } if (current.format != match.format) { // Sorted highest depth to lowest if (current.format == target_format || (SDL_BitsPerPixel(current.format) >= SDL_BitsPerPixel(target_format) && SDL_PixelType(current.format) == SDL_PixelType(target_format)) ) { match = current; } continue; } if (current.refresh_rate != match.refresh_rate) { // Sorted highest refresh to lowest if (current.refresh_rate >= target_refresh_rate) { match = current; } } } if (match != null) { if (CBool(match.format)) { closest.format = match.format; } else { closest.format = mode.format; } if (CBool(match.w) && CBool(match.h)) { closest.w = match.w; closest.h = match.h; } else { closest.w = mode.w; closest.h = mode.h; } if (CBool(match.refresh_rate)) { closest.refresh_rate = match.refresh_rate; } else { closest.refresh_rate = mode.refresh_rate; } closest.driverdata = match.driverdata; // Pick some reasonable defaults if the app and driver don't care if (!CBool(closest.format)) { closest.format = SDL_PIXELFORMAT_RGB888; } if (!CBool(closest.w)) { closest.w = 640; } if (!CBool(closest.h)) { closest.h = 480; } return(closest); } return(null); }