diff --git a/gendarme/sdl2.ignore b/gendarme/sdl2.ignore index dcbf36d..6f89099 100644 --- a/gendarme/sdl2.ignore +++ b/gendarme/sdl2.ignore @@ -82,6 +82,7 @@ M: System.IntPtr SDL2.SDL::SDL_GetClosestDisplayMode(System.Int32,SDL2.SDL/SDL_D M: System.Int32 SDL2.SDL::SDL_GetCurrentDisplayMode(System.Int32,SDL2.SDL/SDL_DisplayMode&) M: System.String SDL2.SDL::SDL_GetCurrentVideoDriver() M: System.Int32 SDL2.SDL::SDL_GetDesktopDisplayMode(System.Int32,SDL2.SDL/SDL_DisplayMode&) +M: System.String SDL2.SDL::SDL_GetDisplayName(System.Int32) M: System.Int32 SDL2.SDL::SDL_GetDisplayBounds(System.Int32,SDL2.SDL/SDL_Rect&) M: System.Int32 SDL2.SDL::SDL_GetDisplayDPI(System.Int32,System.Single&,System.Single&,System.Single&) M: System.Int32 SDL2.SDL::SDL_GetDisplayMode(System.Int32,System.Int32,SDL2.SDL/SDL_DisplayMode&) @@ -982,6 +983,7 @@ M: System.IntPtr SDL2.SDL::SDL_GetClosestDisplayMode(System.Int32,SDL2.SDL/SDL_D M: System.Int32 SDL2.SDL::SDL_GetCurrentDisplayMode(System.Int32,SDL2.SDL/SDL_DisplayMode&) M: System.String SDL2.SDL::SDL_GetCurrentVideoDriver() M: System.Int32 SDL2.SDL::SDL_GetDesktopDisplayMode(System.Int32,SDL2.SDL/SDL_DisplayMode&) +M: System.String SDL2.SDL::SDL_GetDisplayName(System.Int32) M: System.Int32 SDL2.SDL::SDL_GetDisplayBounds(System.Int32,SDL2.SDL/SDL_Rect&) M: System.Int32 SDL2.SDL::SDL_GetDisplayDPI(System.Int32,System.Single&,System.Single&,System.Single&) M: System.Int32 SDL2.SDL::SDL_GetDisplayMode(System.Int32,System.Int32,SDL2.SDL/SDL_DisplayMode&) diff --git a/lib/SDL2-CS b/lib/SDL2-CS index c6fa4d1..9b6f16a 160000 --- a/lib/SDL2-CS +++ b/lib/SDL2-CS @@ -1 +1 @@ -Subproject commit c6fa4d14572783392d4c6bcbcedb5defda5effc7 +Subproject commit 9b6f16a23821fadd22da5eb81810410a301c81a3 diff --git a/src/GamePlatform.cs b/src/GamePlatform.cs index ad8eadf..75b9732 100644 --- a/src/GamePlatform.cs +++ b/src/GamePlatform.cs @@ -103,9 +103,7 @@ namespace Microsoft.Xna.Framework String message ); - public abstract DisplayMode GetCurrentDisplayMode(); - - public abstract DisplayModeCollection GetDisplayModes(); + public abstract GraphicsAdapter[] GetGraphicsAdapters(); public abstract void SetPresentationInterval(PresentInterval interval); diff --git a/src/Graphics/GraphicsAdapter.cs b/src/Graphics/GraphicsAdapter.cs index 46b79c3..5106f92 100644 --- a/src/Graphics/GraphicsAdapter.cs +++ b/src/Graphics/GraphicsAdapter.cs @@ -20,26 +20,20 @@ namespace Microsoft.Xna.Framework.Graphics public DisplayMode CurrentDisplayMode { - get - { - return Game.Instance.Platform.GetCurrentDisplayMode(); - } + get; + private set; } public DisplayModeCollection SupportedDisplayModes { - get - { - return Game.Instance.Platform.GetDisplayModes(); - } + get; + private set; } public string Description { - get - { - throw new NotImplementedException(); - } + get; + private set; } public int DeviceId @@ -149,10 +143,7 @@ namespace Microsoft.Xna.Framework.Graphics if (adapters == null) { adapters = new ReadOnlyCollection( - new GraphicsAdapter[] - { - new GraphicsAdapter() - } + Game.Instance.Platform.GetGraphicsAdapters() ); } return adapters; @@ -169,8 +160,14 @@ namespace Microsoft.Xna.Framework.Graphics #region Internal Constructor - internal GraphicsAdapter() - { + internal GraphicsAdapter( + DisplayMode currentMode, + DisplayModeCollection modes, + string description + ) { + CurrentDisplayMode = currentMode; + SupportedDisplayModes = modes; + Description = description; UseNullDevice = false; UseReferenceDevice = false; } diff --git a/src/SDL2/SDL2_GamePlatform.cs b/src/SDL2/SDL2_GamePlatform.cs index 204793d..7c4db39 100644 --- a/src/SDL2/SDL2_GamePlatform.cs +++ b/src/SDL2/SDL2_GamePlatform.cs @@ -40,13 +40,6 @@ namespace Microsoft.Xna.Framework { class SDL2_GamePlatform : GamePlatform { - #region Private DisplayMode Variables - - private int displayIndex = 0; - private DisplayModeCollection supportedDisplayModes = null; - - #endregion - #region Public Constructor public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform()) @@ -104,12 +97,6 @@ namespace Microsoft.Xna.Framework forceCoreProfile ); - // Create the DisplayMode list - displayIndex = SDL.SDL_GetWindowDisplayIndex( - game.Window.Handle - ); - INTERNAL_GenerateDisplayModes(); - // Disable the screensaver. SDL.SDL_DisableScreenSaver(); @@ -125,6 +112,11 @@ namespace Microsoft.Xna.Framework { SDL.SDL_ShowWindow(Game.Window.Handle); + // Which display did we end up on? + int displayIndex = SDL.SDL_GetWindowDisplayIndex( + Game.Window.Handle + ); + // OSX has some fancy fullscreen features, let's use them! bool osxUseSpaces; if (OSVersion.Equals("Mac OS X")) @@ -315,8 +307,10 @@ namespace Microsoft.Xna.Framework if (newIndex != displayIndex) { displayIndex = newIndex; - INTERNAL_GenerateDisplayModes(); - Game.GraphicsDevice.Reset(); + Game.GraphicsDevice.Reset( + Game.GraphicsDevice.PresentationParameters, + GraphicsAdapter.Adapters[displayIndex] + ); } } @@ -429,20 +423,50 @@ namespace Microsoft.Xna.Framework ); } - public override DisplayMode GetCurrentDisplayMode() + public override GraphicsAdapter[] GetGraphicsAdapters() { - SDL.SDL_DisplayMode mode; - SDL.SDL_GetCurrentDisplayMode(displayIndex, out mode); - return new DisplayMode( - mode.w, - mode.h, - SurfaceFormat.Color - ); - } + SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode(); + GraphicsAdapter[] adapters = new GraphicsAdapter[SDL.SDL_GetNumVideoDisplays()]; + for (int i = 0; i < adapters.Length; i += 1) + { + List modes = new List(); + int numModes = SDL.SDL_GetNumDisplayModes(i); + for (int j = 0; j < numModes; j += 1) + { + SDL.SDL_GetDisplayMode(i, j, out filler); - public override DisplayModeCollection GetDisplayModes() - { - return supportedDisplayModes; + // Check for dupes caused by varying refresh rates. + bool dupe = false; + foreach (DisplayMode mode in modes) + { + if (filler.w == mode.Width && filler.h == mode.Height) + { + dupe = true; + } + } + if (!dupe) + { + modes.Add( + new DisplayMode( + filler.w, + filler.h, + SurfaceFormat.Color // FIXME: Assumption! + ) + ); + } + } + SDL.SDL_GetCurrentDisplayMode(i, out filler); + adapters[i] = new GraphicsAdapter( + new DisplayMode( + filler.w, + filler.h, + SurfaceFormat.Color // FIXME: Assumption! + ), + new DisplayModeCollection(modes), + SDL.SDL_GetDisplayName(i) + ); + } + return adapters; } public override void SetPresentationInterval(PresentInterval interval) @@ -822,42 +846,6 @@ namespace Microsoft.Xna.Framework #endregion - #region Private DisplayMode Methods - - private void INTERNAL_GenerateDisplayModes() - { - List modes = new List(); - SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode(); - int numModes = SDL.SDL_GetNumDisplayModes(displayIndex); - for (int i = 0; i < numModes; i += 1) - { - SDL.SDL_GetDisplayMode(displayIndex, i, out filler); - - // Check for dupes caused by varying refresh rates. - bool dupe = false; - foreach (DisplayMode mode in modes) - { - if (filler.w == mode.Width && filler.h == mode.Height) - { - dupe = true; - } - } - if (!dupe) - { - modes.Add( - new DisplayMode( - filler.w, - filler.h, - SurfaceFormat.Color // FIXME: Assumption! - ) - ); - } - } - supportedDisplayModes = new DisplayModeCollection(modes); - } - - #endregion - #region Private Static SDL_Surface Interop [StructLayout(LayoutKind.Sequential)]