Esempio n. 1
0
#pragma warning restore 0618
        #endregion

        #region Constructor/Destructor.
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonVideoOutput"/> class.
        /// </summary>
        /// <param name="output">Output to evaluate.</param>
        /// <param name="device">Video device that owns the output.</param>
        /// <param name="index">The index of the output.</param>
        internal GorgonVideoOutput(GI.Output output, GorgonVideoDevice device, int index)
        {
            VideoDevice = device;

            Index  = index;
            Handle = output.Description.MonitorHandle;
            IsAttachedToDesktop = output.Description.IsAttachedToDesktop;
            Name         = output.Description.DeviceName;
            OutputBounds = new Rectangle(output.Description.DesktopBounds.Left,
                                         output.Description.DesktopBounds.Top,
                                         output.Description.DesktopBounds.Width,
                                         output.Description.DesktopBounds.Height);
            switch (output.Description.Rotation)
            {
            case GI.DisplayModeRotation.Rotate90:
                Rotation = 90;
                break;

            case GI.DisplayModeRotation.Rotate270:
                Rotation = 270;
                break;

            case GI.DisplayModeRotation.Rotate180:
                Rotation = 180;
                break;

            default:
                Rotation = 0;
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="GraphicsOutput" />.
        /// </summary>
        /// <param name="adapter">The adapter.</param>
        /// <param name="output">The DXGI <see cref="Output" /> counterpart of this instance.</param>
        /// <exception cref="System.ArgumentNullException">output</exception>
        /// <exception cref="ArgumentOutOfRangeException">Is thrown when <paramref name="outputOrdinal" /> is less than zero.</exception>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="output" /> is null.</exception>
        internal GraphicsOutput(GraphicsAdapter adapter, Output output)
        {
            if(adapter == null) throw new ArgumentNullException("adapter");
            if (output == null) throw new ArgumentNullException("output");

            this.adapter = adapter;
            this.output = ToDispose(output);
            outputDescription = output.Description;
        }
Esempio n. 3
0
        /// <summary>
        /// Function to find the nearest video mode to the one specified.
        /// </summary>
        /// <param name="output">Output for the video mode.</param>
        /// <param name="mode">Mode to find.</param>
        /// <returns>The closest matching video mode to the <paramref name="mode"/> parameter.</returns>
        internal GorgonVideoMode FindMode(GI.Output output, GorgonVideoMode mode)
        {
            GI.ModeDescription findMode = GorgonVideoMode.Convert(mode);
            GI.ModeDescription result;

            output.GetClosestMatchingMode(VideoDevice.Graphics.D3DDevice, findMode, out result);

            return(GorgonVideoMode.Convert(result));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of <see cref="GraphicsOutput"/>.
        /// </summary>
        /// <param name="output">The DXGI <see cref="Output"/> counterpart of this instance.</param>
        /// <exception cref="ArgumentOutOfRangeException">Is thrown when <paramref name="outputOrdinal"/> is less than zero.</exception>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="output"/> is null.</exception>
        internal GraphicsOutput(Output output)
        {
            if (output == null) throw new ArgumentNullException("output");

            this.output = ToDispose(output);
            outputDescription = output.Description;

            InitializeSupportedDisplayModes();

            InitializeCurrentDisplayMode();
        }
        /// <summary>
        /// Initializes a new instance of <see cref="GraphicsOutput" />.
        /// </summary>
        /// <param name="adapter">The adapter.</param>
        /// <param name="outputIndex">Index of the output.</param>
        /// <exception cref="System.ArgumentNullException">output</exception>
        /// <exception cref="ArgumentOutOfRangeException">output</exception>
        internal GraphicsOutput(GraphicsAdapter adapter, int outputIndex)
        {
            if (adapter == null) throw new ArgumentNullException("adapter");

            this.outputIndex = outputIndex;
            this.adapter = adapter;
            this.output = adapter.NativeAdapter.GetOutput(outputIndex).DisposeBy(this);
            outputDescription = output.Description;

            unsafe
            {
                var rectangle = outputDescription.DesktopBounds;
                desktopBounds = *(Rectangle*)&rectangle;
            }
        }
        /// <summary>
        /// Init some variables one times to spend execution time.
        /// </summary>
        public DirectX()
        {
            try
            {
                factory = new Factory1();
                adapter = factory.GetAdapter1(numAdapter);
                device = new Device(adapter);
                output = adapter.GetOutput(numOutput);
                output1 = output.QueryInterface<Output1>();
                // get screen wize

                textureDesc = new Texture2DDescription
                {
                    CpuAccessFlags = CpuAccessFlags.Read,
                    BindFlags = BindFlags.None,
                    Format = Format.B8G8R8A8_UNorm,
                    Width = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Right - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Left,
                    Height = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Bottom - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Top,
                    OptionFlags = ResourceOptionFlags.None,
                    MipLevels = 1,
                    ArraySize = 1,
                    SampleDescription = { Count = 1, Quality = 0 },
                    Usage = ResourceUsage.Staging
                };

                screenTexture = new Texture2D(device, textureDesc);
                try
                {
                    duplicatedOutput = output1.DuplicateOutput(device);
                }
                catch (SharpDXException e)
                {
                    if (e.ResultCode.Code == SharpDX.DXGI.ResultCode.Unsupported.Result.Code)
                    {
                        throw new System.ApplicationException("Your system does not support DirectX 11.2 (normally on windows 7). Please use 'Use GDI Capture' option to prevent this error!");

                    }
                    else {
                        throw e;
                    }

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 7
0
        internal COutput(Output dxgiOutput)
        {
            this.dxgiOutput = dxgiOutput;

            var dxgiDesc = dxgiOutput.Description;
            var bounds = dxgiDesc.DesktopBounds;

            desc = new OutputDescription
            {
                DeviceName = dxgiDesc.DeviceName,
                DesctopCoordinates = new Math.Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height),
                AttachedToDesctop = dxgiDesc.IsAttachedToDesktop,
                Rotation = CtBeholder.ModeRotation(dxgiDesc.Rotation),
                MonitorHandle = dxgiDesc.MonitorHandle
            };
        }
Esempio n. 8
0
        void IRenderLoopHost.OnRenderLoop_PrepareRendering(EngineDevice device)
        {
            // Start showing the target form
            if (!m_dummyForm.Visible)
            {
                m_dummyForm.Show();
            }

            // Switch to fullscreen
            if (!m_isInFullscreen)
            {
                m_isInFullscreen          = true;
                m_checkFullscreenNextTime = false;
                using (var targetOutput = GraphicsCore.Current.HardwareInfo.GetOutputByOutputInfo(m_targetOutput))
                {
                    m_swapChain.SetFullscreenState(
                        new SharpDX.Mathematics.Interop.RawBool(true),
                        targetOutput);
                    m_isInFullscreen = true;
                }
            }
            else if (m_checkFullscreenNextTime)
            {
                m_checkFullscreenNextTime = false;

                SharpDX.Mathematics.Interop.RawBool isFullscreen = false;
                DXGI.Output fullscreenOutput = null;
                m_swapChain.GetFullscreenState(out isFullscreen, out fullscreenOutput);
                GraphicsHelper.SafeDispose(ref fullscreenOutput);
                if (isFullscreen == false)
                {
                    m_isInFullscreen = false;

                    if ((m_dummyForm.IsHandleCreated) &&
                        (m_dummyForm.Focused || m_dummyForm.ContainsFocus))
                    {
                        m_isInFullscreen = true;
                        using (var targetOutput = GraphicsCore.Current.HardwareInfo.GetOutputByOutputInfo(m_targetOutput))
                        {
                            m_swapChain.SetFullscreenState(
                                new SharpDX.Mathematics.Interop.RawBool(true),
                                targetOutput);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public GxContext(RenderControl window)
        {
            mWindow = window;
            mFactory = new Factory1();
            if (mFactory.Adapters1.Length == 0)
                throw new InvalidOperationException(
                    "Sorry, but DirectX returned that there is no graphics card installed on your system. Please check if all your drivers are up to date!");

            Adapter = mFactory.GetAdapter1(0);
            if (Adapter.Outputs.Length == 0)
                throw new InvalidOperationException(
                    "Sorry, but DirectX returned that there is no output (monitor) assigned to the graphics card: \"" +
                    Adapter.Description.Description
                    +
                    "\". Please check if your drivers are OK and if your graphics card and monitor show up in the device manager.");

            mOutput = Adapter.Outputs[0];
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EngineOutputInfo" /> class.
        /// </summary>
        internal EngineOutputInfo(int adapterIndex, int outputIndex, DXGI.Output output)
        {
            m_adapterIndex      = adapterIndex;
            m_outputIndex       = outputIndex;
            m_outputDescription = output.Description;

            // Get all supported modes
            DXGI.ModeDescription[] modes = output.GetDisplayModeList(
                GraphicsHelper.DEFAULT_TEXTURE_FORMAT,
                DXGI.DisplayModeEnumerationFlags.Interlaced);

            // Convert and sort them
            EngineOutputModeInfo[] engineModes = new EngineOutputModeInfo[modes.Length];
            for (int loop = 0; loop < engineModes.Length; loop++)
            {
                engineModes[loop] = new EngineOutputModeInfo(this, modes[loop]);
            }
            Array.Sort(engineModes, (left, right) =>
            {
                int result = left.PixelCount.CompareTo(right.PixelCount);
                if (result == 0)
                {
                    result = left.RefreshRateNumerator.CompareTo(right.RefreshRateNumerator);
                }
                return(result);
            });

            // Strip them (we want to have each relevant mode once)
            List <EngineOutputModeInfo> strippedModeList = new List <EngineOutputModeInfo>(engineModes.Length);
            EngineOutputModeInfo        lastOutputMode   = new EngineOutputModeInfo();

            for (int loop = engineModes.Length - 1; loop > -1; loop--)
            {
                if (!engineModes[loop].Equals(lastOutputMode))
                {
                    lastOutputMode = engineModes[loop];
                    strippedModeList.Add(lastOutputMode);
                }
            }

            // Store mode list
            m_outputInfos = strippedModeList.ToArray();
        }
        /// <summary>
        /// Init some variables one times to spend execution time.
        /// </summary>
        public DirectX()
        {

            try
            {

                factory = new Factory1();
                adapter = factory.GetAdapter1(numAdapter);
                device = new Device(adapter);
                output = adapter.GetOutput(numOutput);
                output1 = output.QueryInterface<Output1>();
                // get screen wize

                textureDesc = new Texture2DDescription
                {
                    CpuAccessFlags = CpuAccessFlags.Read,
                    BindFlags = BindFlags.None,
                    Format = Format.B8G8R8A8_UNorm,
                    Width = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Right - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Left,
                    Height = ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Bottom - ((SharpDX.Mathematics.Interop.RawRectangle)output.Description.DesktopBounds).Top,

                    OptionFlags = ResourceOptionFlags.None,
                    MipLevels = 1,
                    ArraySize = 1,
                    SampleDescription = { Count = 1, Quality = 0 },
                    Usage = ResourceUsage.Staging
                };

                screenTexture = new Texture2D(device, textureDesc);
                duplicatedOutput = output1.DuplicateOutput(device);

           
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EngineAdapterInfo" /> class.
        /// </summary>
        internal EngineAdapterInfo(int adapterIndex, DXGI.Adapter1 adapter)
        {
            m_outputs      = new List <EngineOutputInfo>();
            m_adapter      = adapter;
            m_adapterIndex = adapterIndex;

            m_adapterDescription = adapter.Description;
            m_isSoftware         =
                (m_adapterDescription.Description == "Microsoft Basic Render Driver") ||
                ((!string.IsNullOrEmpty(m_adapterDescription.Description)) && m_adapterDescription.Description.Contains("Software")) ||
                ((!string.IsNullOrEmpty(m_adapterDescription.Description)) && m_adapterDescription.Description.Contains("Microsoft Basic Render Driver"));

            m_d3d11FeatureLevel = D3D11.Device.GetSupportedFeatureLevel(adapter);

            //Query for output information
            DXGI.Output[] outputs = adapter.Outputs;
            for (int loop = 0; loop < outputs.Length; loop++)
            {
                try
                {
                    DXGI.Output actOutput = outputs[loop];
                    try
                    {
                        m_outputs.Add(new EngineOutputInfo(adapterIndex, loop, actOutput));
                    }
                    finally
                    {
                        actOutput.Dispose();
                    }
                }
                catch (Exception)
                {
                    //Query for output information not possible
                    // .. no special handling needed here
                }
            }
        }
Esempio n. 13
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="parameters"></param>
		/// <param name="output"></param>
		/// <returns></returns>
		public Form CreateTouchForm(GraphicsParameters parameters, Output output)
		{
			var form = new TouchForm() {
				Text			=	Game.GameTitle,
				BackColor		=	System.Drawing.Color.Black,
				ClientSize		=	new System.Drawing.Size(parameters.Width, parameters.Height),
				Icon			=	Game.Icon ?? Fusion.Properties.Resources.fusionIcon,
				ControlBox		=	false,
				StartPosition	=	output == null ? FormStartPosition.CenterScreen : FormStartPosition.Manual,
			};


			if (output != null) {
				var bounds	= output.Description.DesktopBounds;
				var scrW	= bounds.Right - bounds.Left;
				var scrH	= bounds.Bottom - bounds.Top;

				form.Location = new System.Drawing.Point(bounds.Left + (scrW - form.Width) / 2, bounds.Top + (scrH - form.Height) / 2);
				form.Text += " - [" + output.Description.DeviceName + "]";
			}

			form.KeyDown	+= form_KeyDown;
			form.KeyUp		+= form_KeyUp;
			form.KeyPress	+= form_KeyPress;
			form.Resize		+= (s, e) => Game.InputDevice.RemoveAllPressedKeys();
			form.Move		+= (s, e) => Game.InputDevice.RemoveAllPressedKeys();

			form.TouchTap			+= (pos) => Game.InputDevice.NotifyTouchTap(pos);
			form.TouchDoubleTap		+= (pos) => Game.InputDevice.NotifyTouchDoubleTap(pos);
			form.TouchSecondaryTap	+= (pos) => Game.InputDevice.NotifyTouchSecondaryTap(pos);
			form.TouchManipulation	+= (center, delta, scale) => Game.InputDevice.NotifyTouchManipulation(center, delta, scale);

			return form;
		}
Esempio n. 14
0
 private static Rational GetHighestAvailableRefreshFrequency(Output monitor)
 {
     if (ConfigurationManager.Config.WindowedMode)
         return new Rational(60, 1);
     return monitor.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced).
         Where(mode =>
                 mode.Width == ConfigurationManager.Config.Width &&
                 mode.Height == ConfigurationManager.Config.Height).Last().RefreshRate;
 }
Esempio n. 15
0
 /// <summary>
 /// Creates a swapchain associated to the specified HWND. This is applicable only for Desktop platform.
 /// </summary>
 /// <param name="factory">The DXGI Factory used to create the swapchain.</param>
 /// <param name="device">The associated device instance.</param>
 /// <param name="hwnd">The HWND of the window to which this swapchain is associated.</param>
 /// <param name="description">The swap chain description.</param>
 /// <param name="fullScreenDescription">The fullscreen description of the swap chain. Default is null.</param>
 /// <param name="restrictToOutput">The output to which this swap chain should be restricted. Default is null, meaning that there is no restriction.</param>
 public SwapChain1(Factory2 factory, ComObject device, IntPtr hwnd, ref SwapChainDescription1 description, SwapChainFullScreenDescription? fullScreenDescription = null, Output restrictToOutput = null)
     : base(IntPtr.Zero)
 {
     factory.CreateSwapChainForHwnd(device, hwnd, ref description, fullScreenDescription, restrictToOutput, this);
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a swapchain for DirectComposition API or WinRT XAML framework. This is applicable only for WinRT platform.
 /// </summary>
 /// <param name="factory">The DXGI Factory used to create the swapchain.</param>
 /// <param name="device">The associated device instance.</param>
 /// <param name="description">The swap chain description.</param>
 /// <param name="restrictToOutput">The output to which this swap chain should be restricted. Default is null, meaning that there is no restriction.</param>
 public SwapChain1(Factory2 factory, ComObject device, ref SwapChainDescription1 description, Output restrictToOutput = null)
     : base(IntPtr.Zero)
 {
     factory.CreateSwapChainForComposition(device, ref description, restrictToOutput, this);
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="adapter"></param>
		/// <param name="leftOut"></param>
		/// <param name="rightOut"></param>
		void GetDualHeadAdapter ( FeatureLevel fl, out Adapter adapter, out Output leftOut, out Output rightOut )
		{
			using ( var factory2 = new Factory() ) {

				adapter	=	factory2.Adapters.FirstOrDefault( a => a.Outputs.Length>=2 && D3D.Device.IsSupportedFeatureLevel( a, fl ) );

				if (adapter==null) {
					throw new GraphicsException("No DualHead adapters with Direct3D11 support found.");
				}

				leftOut		=	adapter.Outputs[0];
				rightOut	=	adapter.Outputs[1];

				if (leftOut.Description.DesktopBounds.Left > rightOut.Description.DesktopBounds.Left ) {
					Misc.Swap( ref leftOut, ref rightOut );
				}
			}
		}
        private static GraphicsAdapter CreateAdapter(SharpDX.DXGI.Adapter1 device, SharpDX.DXGI.Output monitor)
        {
            var adapter = new GraphicsAdapter();

            adapter._adapter = device;

            adapter.DeviceName    = monitor.Description.DeviceName.TrimEnd(new char[] { '\0' });
            adapter.Description   = device.Description1.Description.TrimEnd(new char[] { '\0' });
            adapter.DeviceId      = device.Description1.DeviceId;
            adapter.Revision      = device.Description1.Revision;
            adapter.VendorId      = device.Description1.VendorId;
            adapter.SubSystemId   = device.Description1.SubsystemId;
            adapter.MonitorHandle = monitor.Description.MonitorHandle;

#if WINDOWS_UAP
            var desktopWidth  = monitor.Description.DesktopBounds.Right - monitor.Description.DesktopBounds.Left;
            var desktopHeight = monitor.Description.DesktopBounds.Bottom - monitor.Description.DesktopBounds.Top;
#else
            var desktopWidth  = monitor.Description.DesktopBounds.Width;
            var desktopHeight = monitor.Description.DesktopBounds.Height;
#endif

            var modes = new List <DisplayMode>();

            foreach (var formatTranslation in FormatTranslations)
            {
                SharpDX.DXGI.ModeDescription[] displayModes;

                // This can fail on headless machines, so just assume the desktop size
                // is a valid mode and return that... so at least our unit tests work.
                try
                {
                    displayModes = monitor.GetDisplayModeList(formatTranslation.Key, 0);
                }
                catch (SharpDX.SharpDXException)
                {
                    var mode = new DisplayMode(desktopWidth, desktopHeight, SurfaceFormat.Color);
                    modes.Add(mode);
                    adapter._currentDisplayMode = mode;
                    break;
                }


                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 (adapter._currentDisplayMode == null)
                    {
                        if (mode.Width == desktopWidth && mode.Height == desktopHeight && mode.Format == SurfaceFormat.Color)
                        {
                            adapter._currentDisplayMode = mode;
                        }
                    }
                }
            }

            adapter._supportedDisplayModes = new DisplayModeCollection(modes);

            if (adapter._currentDisplayMode == null) //(i.e. desktop mode wasn't found in the available modes)
            {
                adapter._currentDisplayMode = new DisplayMode(desktopWidth, desktopHeight, SurfaceFormat.Color);
            }

            return(adapter);
        }
 private OutputDuplication InitializeOutputDuplication(Output output)
 {
     try
     {
         using (var output1 = output.QueryInterface<Output1>())
         {
             return output1.DuplicateOutput(_device);
         }
     }
     catch (SharpDXException)
     {
         throw new ScreenException("Unable to initialize the Desktop Duplication API.");
     }
 }