/// <summary> /// Get the correct Output1 based on region to be captured. /// </summary> private Output1 GetOutput(Factory1 factory) { try { //Gets the output with the bigger area being intersected. var output = factory.Adapters1.SelectMany(s => s.Outputs).FirstOrDefault(f => f.Description.DeviceName == DeviceName) ?? factory.Adapters1.SelectMany(s => s.Outputs).OrderByDescending(f => { var x = Math.Max(Left, f.Description.DesktopBounds.Left); var num1 = Math.Min(Left + Width, f.Description.DesktopBounds.Right); var y = Math.Max(Top, f.Description.DesktopBounds.Top); var num2 = Math.Min(Top + Height, f.Description.DesktopBounds.Bottom); if (num1 >= x && num2 >= y) { return(num1 - x + num2 - y); } return(0); }).FirstOrDefault(); if (output == null) { throw new Exception($"Could not find a proper output device for the area of L: {Left}, T: {Top}, Width: {Width}, Height: {Height}."); } //Position adjustments, so the correct region is captured. OffsetLeft = output.Description.DesktopBounds.Left; OffsetTop = output.Description.DesktopBounds.Top; DisplayRotation = output.Description.Rotation; if (DisplayRotation != DisplayModeRotation.Identity) { //Texture that is used to recieve the pixel data from the GPU. TransformTexture = new Texture2D(Device, new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.B8G8R8A8_UNorm, Width = Height, Height = Width, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default }); } //Create textures in here, after detecting the orientation? return(output.QueryInterface <Output1>()); } catch (SharpDXException ex) { throw new Exception("Could not find the specified output device.", ex); } }
public DirectXOutput(Adapter1 adapter, SharpDX.Direct3D11.Device device, OutputDuplication outputDuplication, Texture2D texture2D, DisplayModeRotation rotation) { Adapter = adapter; Device = device; OutputDuplication = outputDuplication; Texture2D = texture2D; Rotation = rotation; }