Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of GraphicsAdapter into partial class.
Implemented GraphicsAdapter for DirectX platforms. Added unit tests for GraphicsAdapter.
- Loading branch information
1 parent
68513fa
commit 9c9fe5c
Showing
9 changed files
with
656 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// MonoGame - Copyright (C) The MonoGame Team | ||
// This file is subject to the terms and conditions defined in | ||
// file 'LICENSE.txt', which is part of this source code package. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Microsoft.Xna.Framework.Graphics | ||
{ | ||
partial class GraphicsAdapter | ||
{ | ||
private static void PlatformInitializeAdapters(out ReadOnlyCollection<GraphicsAdapter> adapters) | ||
{ | ||
var dxgiFactory = new SharpDX.DXGI.Factory1(); | ||
|
||
var adapterCount = dxgiFactory.GetAdapterCount(); | ||
var adapterList = new List<GraphicsAdapter>(adapterCount); | ||
|
||
for (var i = 0; i < adapterCount; i++) | ||
{ | ||
var dxgiAdapter = dxgiFactory.GetAdapter1(i); | ||
|
||
var outputsCount = dxgiAdapter.GetOutputCount(); | ||
for (var j = 0; j < outputsCount; j++) | ||
{ | ||
var output = dxgiAdapter.GetOutput(j); | ||
|
||
var adapter = CreateAdapter(dxgiAdapter, output); | ||
adapterList.Add(adapter); | ||
|
||
output.Dispose(); | ||
} | ||
|
||
dxgiAdapter.Dispose(); | ||
} | ||
|
||
dxgiFactory.Dispose(); | ||
|
||
adapters = new ReadOnlyCollection<GraphicsAdapter>(adapterList); | ||
} | ||
|
||
private static readonly Dictionary<SharpDX.DXGI.Format, SurfaceFormat> FormatTranslations = new Dictionary<SharpDX.DXGI.Format, SurfaceFormat> | ||
{ | ||
{ SharpDX.DXGI.Format.R8G8B8A8_UNorm, SurfaceFormat.Color }, | ||
{ SharpDX.DXGI.Format.B8G8R8A8_UNorm, SurfaceFormat.Color }, | ||
{ SharpDX.DXGI.Format.B5G6R5_UNorm, SurfaceFormat.Bgr565 }, | ||
}; | ||
|
||
private static GraphicsAdapter CreateAdapter(SharpDX.DXGI.Adapter1 dxgiAdapter, SharpDX.DXGI.Output output) | ||
{ | ||
var adapter = new GraphicsAdapter(); | ||
|
||
adapter.DeviceName = output.Description.DeviceName; | ||
adapter.Description = dxgiAdapter.Description1.Description; | ||
adapter.DeviceId = dxgiAdapter.Description1.DeviceId; | ||
adapter.Revision = dxgiAdapter.Description1.Revision; | ||
adapter.VendorId = dxgiAdapter.Description1.VendorId; | ||
adapter.SubSystemId = dxgiAdapter.Description1.SubsystemId; | ||
adapter.MonitorHandle = output.Description.MonitorHandle; | ||
|
||
var desktopWidth = output.Description.DesktopBounds.Width; | ||
var desktopHeight = output.Description.DesktopBounds.Height; | ||
|
||
var modes = new List<DisplayMode>(); | ||
|
||
foreach (var formatTranslation in FormatTranslations) | ||
{ | ||
var displayModes = output.GetDisplayModeList(formatTranslation.Key, 0); | ||
foreach (var displayMode in displayModes) | ||
{ | ||
var mode = new DisplayMode(displayMode.Width, displayMode.Height, formatTranslation.Value); | ||
|
||
// Skip duplicate modes with the same width/height/formats. | ||
if (modes.Contains(mode)) | ||
continue; | ||
|
||
modes.Add(mode); | ||
|
||
if (mode.Width == desktopWidth && mode.Height == desktopHeight && mode.Format == SurfaceFormat.Color) | ||
{ | ||
if (adapter._currentDisplayMode == null) | ||
adapter._currentDisplayMode = mode; | ||
} | ||
} | ||
} | ||
|
||
adapter._supportedDisplayModes = new DisplayModeCollection(modes); | ||
|
||
return adapter; | ||
} | ||
} | ||
} |
Oops, something went wrong.