public ScreenCapture(int numAdapter, int numOutput) { var factory = new Factory1(); Adapter1 adapter = new Factory1().GetAdapter1(numAdapter); device = new Device(adapter); Output output = adapter.GetOutput(numOutput); var output1 = output.QueryInterface <Output1>(); outputDescription = output.Description; outputDuplication = output1.DuplicateOutput(device); width = outputDescription.DesktopBounds.GetWidth(); height = outputDescription.DesktopBounds.GetHeight(); desktopImageTexture = new Texture2D(device, new Texture2DDescription() { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }); image = new Bitmap(width, height, PixelFormat.Format32bppRgb); boundsRect = new Rectangle(0, 0, width, height); }
/// <summary> /// Initializes all adapters with the specified factory. /// </summary> internal static void InitializeInternal() { staticCollector.Dispose(); #if DIRECTX11_1 using (var factory = new Factory1()) NativeFactory = factory.QueryInterface <Factory2>(); #elif SILICONSTUDIO_PLATFORM_UWP // Maybe this will become default code for everybody if we switch to DX 11.1/11.2 SharpDX dll? NativeFactory = new Factory2(); #else NativeFactory = new Factory1(); #endif staticCollector.Add(NativeFactory); int countAdapters = NativeFactory.GetAdapterCount1(); var adapterList = new List <GraphicsAdapter>(); for (int i = 0; i < countAdapters; i++) { var adapter = new GraphicsAdapter(NativeFactory, i); staticCollector.Add(adapter); adapterList.Add(adapter); } defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null; adapters = adapterList.ToArray(); }
public DesktopDuplicator(IntPtr window) { User32.GetWindowRect(window, out var rectNative); var windowRect = rectNative.ToRect(); // Search all outputs on all adapters and find the window rect. var factory = new Factory1(); for (var j = 0; j < factory.GetAdapterCount1(); j++) { var adapter = factory.GetAdapter1(j); for (var i = 0; i < adapter.GetOutputCount(); i++) { var output = adapter.GetOutput(i); var bounds = output.Description.DesktopBounds.ToRectangle(); if (bounds.Contains(windowRect)) { Initialize(0, i); return; } } } throw new Exception($"Didn't find the {window} window on any display output."); }
private void Initialize() { factory = new Factory1(); //Get first adapter adapter = factory.GetAdapter1(0); //Get device from adapter device = new SharpDX.Direct3D11.Device(adapter); //Get front buffer of the adapter output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture int width = output.Description.DesktopBounds.Right; int height = output.Description.DesktopBounds.Bottom; size = new Vector2Int(width, height); // Create Staging texture CPU-accessible textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); }
public static void Run() { var factory = new Factory1(); // 0: Intel 1: Nvidia 2: CPU var adapter = factory.Adapters1[1]; var device = new D3DDevice(adapter); var gpuName = adapter.Description.Description; var _64MB = new byte[64 * 1024 * 1024]; var buffer = new DXDynamicVertexBuffer(device); for (int i = 64; i <= 2048; i += 64) { buffer.Reset(_64MB); var result = MessageBox.Show(i + " MB! Flush?", "Memory Test - " + gpuName, MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { device.ImmediateContext.Flush(); } else if (result == DialogResult.No) { continue; } else { break; } } buffer.Dispose(); device.Dispose(); adapter.Dispose(); factory.Dispose(); }
public void AdapterTest() { using (var factory = new Factory1()) { foreach (var item in factory.Adapters) { var description = item.Description; var level = SharpDX.Direct3D11.Device.GetSupportedFeatureLevel(item); var sb = new StringBuilder(); sb.AppendLine(description.Description); sb.AppendLine("\tVendorId: 0x" + description.VendorId.ToString("X")); sb.AppendLine("\tDeviceId: 0x" + description.DeviceId.ToString("X")); sb.AppendLine("\tDedicatedVideoMemory: " + description.DedicatedVideoMemory); sb.AppendLine("\tDedicatedSystemMemory: " + description.DedicatedSystemMemory); sb.AppendLine("\tSharedSystemMemory: " + description.SharedSystemMemory); sb.AppendLine("\tFeatureLevel: " + level); sb.AppendLine("\tOutputs:"); foreach (var output in item.Outputs) { sb.AppendLine("\t\t" + output.Description.DeviceName); } Console.Write(sb); } } }
public static void LogUnhandledException(Exception e, Game game) { using (var fs = File.CreateText("crashlog.txt")) { fs.WriteLine(e.ToString()); fs.WriteLine(); fs.WriteLine(RuntimeInformation.OSDescription); RenderContext renderContext = game.SystemRegistry.GetSystem <GraphicsSystem>().Context; string backend = renderContext is OpenGLRenderContext ? "OpenGL" : "Direct3D11"; fs.WriteLine($"Using {backend} backend."); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { fs.WriteLine("GPU Devices:"); var factory = new Factory1(); foreach (var adapter in factory.Adapters) { fs.WriteLine(CreateString(adapter.Description)); } } fs.WriteLine($"Resolution: {renderContext.Window.Width}x{renderContext.Window.Height}"); var audioEngine = game.SystemRegistry.GetSystem <AudioSystem>().Engine; fs.WriteLine($"Audio Engine: {audioEngine.GetType()}"); } }
private void Initialize() { _factory = new Factory1(); var adapterOutput = _factory.Adapters1 .Select(adapter => new { adapter, adapter.Outputs }) .SelectMany(_ => _.Outputs.Select(output => new { _.adapter, output })) .FirstOrDefault(_ => _.output.Description.MonitorHandle == Screen.HMon) ?? throw new InvalidOperationException(); _device = new Device(adapterOutput.adapter); _output = adapterOutput.output; _adapter = adapterOutput.adapter; _output1 = _output.QueryInterface <Output1>(); _screenTexture = new Texture2D(_device, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = _width, Height = _height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }); _duplicatedOutput = _output1.DuplicateOutput(_device); }
public ProjectorFormLoader(String path) { Forms = new List <ProjectorForm>(); // load ensemble.xml string directory = Path.GetDirectoryName(path); var ensemble = ProjectorCameraEnsemble.FromFile(path); // create d3d device var factory = new Factory1(); var adapter = factory.Adapters[0]; // When using DeviceCreationFlags.Debug on Windows 10, ensure that "Graphics Tools" are installed via Settings/System/Apps & features/Manage optional features. // Also, when debugging in VS, "Enable native code debugging" must be selected on the project. var device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None); Object renderLock = new Object(); // create a form for each projector foreach (var projector in ensemble.projectors) { var form = new ProjectorForm(factory, device, renderLock, projector); form.FullScreen = FULLSCREEN_ENABLED; // TODO: fix this so can be called after Show form.Show(); Forms.Add(form); } }
public void getCaps() { Factory1 fac = new Factory1(); int numAdapters = fac.GetAdapterCount1(); List <Adapter1> adapts = new List <Adapter1>(); for (int i = 0; i < numAdapters; i++) { adapts.Add(fac.GetAdapter1(i)); } Output outp = adapts[0].GetOutput(0); List <Format> formats = new List <Format>(); foreach (Format format in Enum.GetValues(typeof(Format))) { formats.Add(format); } //List<ReadOnlyCollection<ModeDescription>> ll = new List<ReadOnlyCollection<ModeDescription>>(); List <ModeDescription[]> ll = new List <ModeDescription[]>(); for (int i = 0; i < formats.Count - 1; i++) { //ReadOnlyCollection<ModeDescription> mdl; ModeDescription[] mdl; mdl = outp.GetDisplayModeList(formats[i], DisplayModeEnumerationFlags.Interlaced); ll.Add(mdl); if (mdl != null) { Console.WriteLine(formats[i].ToString()); } } }
/// <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; } }
public DXCapture() { // # of graphics card adapter const int numAdapter = 0; // # of output device (i.e. monitor) const int numOutput = 0; // const string outputFileName = "ScreenCapture.bmp"; // Create DXGI Factory1 var factory = new Factory1(); var adapter = factory.GetAdapter1(numAdapter); // Create device from Adapter device = new Device(adapter); // Get DXGI.Output var output = adapter.GetOutput(numOutput); output1 = output.QueryInterface <Output1>(); // Width/Height of desktop to capture width = output.Description.DesktopBounds.Right - output.Description.DesktopBounds.Left; height = output.Description.DesktopBounds.Bottom - output.Description.DesktopBounds.Top; }
private void Initialize(int whichGraphicsCardAdapter, int whichOutputDevice) { var adapter = new Factory1().GetAdapter1(whichGraphicsCardAdapter); this._device = new Device(adapter); Output output = adapter.GetOutput(whichOutputDevice); var output1 = output.QueryInterface <Output1>(); this._outputDescription = output.Description; this._desktopTextureDescription = new Texture2DDescription() { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = this._outputDescription.DesktopBounds.Width(), Height = this._outputDescription.DesktopBounds.Height(), OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; this._desktopImageTexture = new Texture2D(_device, _desktopTextureDescription); this._desktopDuplication = output1.DuplicateOutput(_device); }
public DuplicatorOptions() { Adapter1 adapter; using (var fac = new Factory1()) { adapter = fac.Adapters1.FirstOrDefault(a => !a.Description1.Flags.HasFlag(AdapterFlags.Software)); if (adapter == null) { adapter = fac.Adapters1.First(); } } Adapter = adapter.Description.Description; Output = adapter.Outputs.First().Description.DeviceName; FrameAcquisitionTimeout = 500; AudioAcquisitionTimeout = 500; ShowCursor = true; PreserveRatio = true; RecordingFrameRate = 0; OutputFileFormat = DefaultFileFormat; OutputDirectoryPath = GetDefaultOutputDirectoryPath(); EnableHardwareTransforms = true; CaptureSound = true; CaptureMicrophone = false; SoundDevice = AudioCapture.GetSpeakersDevice()?.FriendlyName; MicrophoneDevice = AudioCapture.GetMicrophoneDevice()?.FriendlyName; UseRecordingQueue = false; }
/// <summary> /// (Re)configures the class to a fresh state. /// </summary> private void Configure(int adapterIndex, int displayIndex) { Dispose(false); factory = new Factory1(); adapter = factory.GetAdapter1(adapterIndex); device = new Device(adapter); output = adapter.GetOutput(displayIndex); screen = output.QueryInterface <Output1>(); bounds = screen.Description.DesktopBounds; Texture2DDescription textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = bounds.Right - bounds.Left, Height = bounds.Bottom - bounds.Top, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); ResetOutputDuplicator(); }
private bool disposedValue = false; // 要检测冗余调用 protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: 释放托管状态(托管对象)。 factory.Dispose(); adapter.Dispose(); device.Dispose(); output.Dispose(); output1.Dispose(); screenTexture.Dispose(); } // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。 // TODO: 将大型字段设置为 null。 factory = null; adapter = null; device = null; output = null; output1 = null; screenTexture = null; disposedValue = true; } }
public static List <DxEnumeratedDisplay> GetMonitors(int adapterId) { var displays = new List <DxEnumeratedDisplay>(); try { using var factory = new Factory1(); using var adapter = factory.GetAdapter1(adapterId); using var device = new SharpDX.Direct3D11.Device(adapter); var displayCount = adapter.GetOutputCount(); for (var i = 0; i < displayCount; ++i) { using var output = adapter.GetOutput(i); using var output6 = output.QueryInterface <Output6>(); using var duplicatedOutput = output6.DuplicateOutput1(device, 0, 1, new Format[] { Format.B8G8R8A8_UNorm }); displays.Add(new DxEnumeratedDisplay() { OutputId = i, Name = output.Description.DeviceName.ToString(), Width = duplicatedOutput.Description.ModeDescription.Width, Height = duplicatedOutput.Description.ModeDescription.Height, RefreshRate = duplicatedOutput.Description.ModeDescription.RefreshRate.Numerator / duplicatedOutput.Description.ModeDescription.RefreshRate.Denominator, Format = duplicatedOutput.Description.ModeDescription.Format.ToString(), Bpp = output6.Description1.BitsPerColor, ColorSpace = output6.Description1.ColorSpace.ToString() }); } } catch (Exception ex) { Console.WriteLine(ex); } return(displays); }
public static DxEnumeratedDisplay GetMonitor(int adapterId, int id) { DxEnumeratedDisplay display = null; try { using var factory = new Factory1(); using var adapter = factory.GetAdapter1(adapterId); using var device = new SharpDX.Direct3D11.Device(adapter); if (id > adapter.GetOutputCount()) { return(null); } using var output = adapter.GetOutput(id); using var output6 = output.QueryInterface <Output6>(); using var duplicatedOutput = output6.DuplicateOutput1(device, 0, 1, new Format[] { Format.B8G8R8A8_UNorm }); display = new DxEnumeratedDisplay() { OutputId = id, Name = output.Description.DeviceName.ToString(), Width = duplicatedOutput.Description.ModeDescription.Width, Height = duplicatedOutput.Description.ModeDescription.Height, RefreshRate = duplicatedOutput.Description.ModeDescription.RefreshRate.Numerator / duplicatedOutput.Description.ModeDescription.RefreshRate.Denominator, Format = duplicatedOutput.Description.ModeDescription.Format.ToString(), Bpp = output6.Description1.BitsPerColor, ColorSpace = output6.Description1.ColorSpace.ToString() }; } catch (Exception ex) { Console.WriteLine(ex); } return(display); }
public FullScreenDesktopDuplicator(bool IncludeCursor, IPreviewWindow PreviewWindow, IPlatformServices PlatformServices) { using var factory = new Factory1(); var outputs = factory .Adapters1 .SelectMany(M => M.Outputs) .ToArray(); var bounds = PlatformServices.DesktopRectangle; Width = bounds.Width; Height = bounds.Height; PointTransform = P => new Point(P.X - bounds.Left, P.Y - bounds.Top); _editorSession = new Direct2DEditorSession(Width, Height, PreviewWindow); _outputs.AddRange(outputs.Select(M => { var output1 = M.QueryInterface <Output1>(); var rect = M.Description.DesktopBounds; return(new DeskDuplOutputEntry { DuplCapture = new DuplCapture(output1), Location = new SharpDX.Point(rect.Left - bounds.Left, rect.Top - bounds.Top), MousePointer = IncludeCursor ? new DxMousePointer(_editorSession) : null }); })); }
public DirectXScreenCapturer() { // 获取输出设备(显卡、显示器),这里是主显卡和主显示器 factory = new Factory1(); adapter = factory.GetAdapter1(0); device = new SharpDX.Direct3D11.Device(adapter); output = adapter.GetOutput(0); output1 = output.QueryInterface <Output1>(); //设置纹理信息,供后续使用(截图大小和质量) textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = output.Description.DesktopBounds.Right, Height = output.Description.DesktopBounds.Bottom, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; screenTexture = new Texture2D(device, textureDesc); }
private static DXGI.SwapChain CreateSwapChain( IntPtr windowHandle, D3D11.Device device, PixelFormat backBufferFormat, int backBufferCount, int width, int height) { var swapChainDescription = new SwapChainDescription { IsWindowed = true, ModeDescription = new ModeDescription(width, height, new Rational(60, 0), backBufferFormat.ToDxgiFormat()), OutputHandle = windowHandle, SampleDescription = new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, BufferCount = backBufferCount, SwapEffect = SwapEffect.Discard, Flags = SwapChainFlags.None }; using (var dxgiFactory = new Factory1()) { return(new DXGI.SwapChain(dxgiFactory, device, swapChainDescription)); } }
/// <summary> /// /// </summary> protected void ShowAdapterInfo(GraphicsParameters parameters) { Log.Message("Mode : {0}x{1} {3} MS:{2} Stereo:{5} {4}", parameters.Width, parameters.Height, 0, parameters.FullScreen ? "FS" : "W", parameters.UseDebugDevice ? "(Debug)" : "", parameters.StereoMode); using (var factory2 = new Factory1()) { Log.Message("Adapters:"); try { foreach (var adapter in factory2.Adapters) { var aDesc = adapter.Description; Log.Message(" {0} - {1}", aDesc.Description, D3D.Device.GetSupportedFeatureLevel(adapter)); foreach (var output in adapter.Outputs) { var desc = output.Description; var bnds = output.Description.DesktopBounds; var bndsString = string.Format("x:{0} y:{1} w:{2} h:{3}", bnds.Left, bnds.Top, bnds.Right - bnds.Left, bnds.Bottom - bnds.Top); Log.Message(" {0} [{1}] {2}", desc.DeviceName, bndsString, desc.Rotation); } } } catch (Exception e) { Log.Warning(e.Message); } } }
public AppSwapChainPanel() { this.InitializeComponent(); var list = new Factory1().Adapters.ToList(); var query = from a in list where a.Description.VendorId == 0x10DE || a.Description.VendorId == 0x1022 || a.Description.VendorId == 0x8086 select a; query.OrderBy((x) => { if (x.Description.VendorId == 0x10DE) { return(0); } if (x.Description.VendorId == 0x1022) { return(1); } if (x.Description.VendorId == 0x8086) { return(2); } return(3); }); Adapter adapter = query.ElementAtOrDefault(0); Loaded += (a, b) => { if (adapter != null) { CreateDirectXSwapChain(adapter); } }; }
public DX11DisplayManager() { this.Factory = new Factory1(); //Scan once on creation this.Refresh(); }
private bool Set(IScreen screen) { var outputs = new Factory1() .Adapters1 .SelectMany(adapter1 => adapter1.Outputs .Select(output => output.QueryInterface <Output1>())); var match = outputs.FirstOrDefault(output1 => { var r1 = output1.Description.DesktopBounds; var r2 = screen.Rectangle; return(r1.Left == r2.Left && r1.Right == r2.Right && r1.Top == r2.Top && r1.Bottom == r2.Bottom); }); if (match == null) { return(false); } Source = new DesktopDuplicationItem(match); return(true); }
bool Set(IScreen Screen) { var outputs = new Factory1() .Adapters1 .SelectMany(M => M.Outputs .Select(N => N.QueryInterface <Output1>())); var match = outputs.FirstOrDefault(M => { var r1 = M.Description.DesktopBounds; var r2 = Screen.Rectangle; return(r1.Left == r2.Left && r1.Right == r2.Right && r1.Top == r2.Top && r1.Bottom == r2.Bottom); }); if (match == null) { return(false); } Source = new DeskDuplItem(match, _previewWindow); return(true); }
public ChooseAdapter(string selectedAdapter) { InitializeComponent(); Icon = Main.EmbeddedIcon; using (var fac = new Factory1()) { listViewMain.Select(); foreach (var adapter in fac.Adapters1) { var item = listViewMain.Items.Add(adapter.Description1.Description); item.Tag = adapter; item.SubItems.Add(adapter.Description1.Flags.ToString()); item.SubItems.Add(adapter.Description1.Revision.ToString()); item.SubItems.Add(adapter.Description1.DedicatedVideoMemory.ToString()); if (selectedAdapter != null && adapter.Description.Description == selectedAdapter) { Adapter = adapter; item.Selected = true; } } } listViewMain.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private Rational GetRefreshRateAndSetVideoCardProperties(Dimension size) { var refreshRate = new Rational(0, 1); using (var factory = new Factory1()) using (var adapter = factory.GetAdapter1(0)) using (var monitor = adapter.GetOutput(0)) { var modes = monitor.GetDisplayModeList(RGB8_UNorm, DisplayModeEnumerationFlags.Interlaced); if (_verticalSyncEnabled) { foreach (var mode in modes) { if (size.SameSizeAs(mode)) { refreshRate = new Rational(mode.RefreshRate.Numerator, mode.RefreshRate.Denominator); break; } } } var adapterDescription = adapter.Description; VideoCardMemory = adapterDescription.DedicatedVideoMemory / 1024 / 1024; // In MB VideoCardDescription = adapterDescription.Description.Trim('\0'); } return(refreshRate); }
public DesktopDuplicator(Rectangle Rect, bool IncludeCursor, int Monitor, int Adapter = 0) { _rect = Rect; _includeCursor = IncludeCursor; Adapter1 adapter; try { adapter = new Factory1().GetAdapter1(Adapter); } catch (SharpDXException e) { throw new Exception("Could not find the specified graphics card adapter.", e); } _device = new Device(adapter); Output output; try { output = adapter.GetOutput(Monitor); } catch (SharpDXException e) { throw new Exception("Could not find the specified output device.", e); } var output1 = output.QueryInterface <Output1>(); _outputDesc = output.Description; _textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = _rect.Width, Height = _rect.Height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; try { _deskDupl = output1.DuplicateOutput(_device); } catch (SharpDXException e) when(e.Descriptor == SharpDX.DXGI.ResultCode.NotCurrentlyAvailable) { throw new Exception("There is already the maximum number of applications using the Desktop Duplication API running, please close one of the applications and try again.", e); } catch (SharpDXException e) when(e.Descriptor == SharpDX.DXGI.ResultCode.Unsupported) { throw new NotSupportedException("Desktop Duplication is not supported on this system.\nIf you have multiple graphic cards, try running Captura on integrated graphics.", e); } }
private void DisposeNative() { this.factory?.Dispose(); this.factory = null; if (this.renderBitmaps != null) { for (var i = 0; i < this.renderBitmaps.Length; i++) { this.renderBitmaps[i]?.Dispose(); this.renderBitmaps[i] = null; } this.renderBitmaps = null; } if (this.inputs != null) { for (var i = 0; i < this.inputs.Length; i++) { this.inputs[i]?.Dispose(); this.inputs[i] = null; } this.inputs = null; } }
public DX11RenderContext(Factory1 factory, DXGIScreen screen, DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Factory = factory; this.Screen = screen; this.Device = new Device(screen.Adapter, flags); this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
/// <summary> /// Initializes static members of the <see cref="GraphicsAdapter" /> class. /// </summary> static GraphicsAdapter() { #if DIRECTX11_1 using (var factory = new Factory1()) Initialize(factory.QueryInterface<Factory2>()); #else Initialize(); #endif }
public void ScalarWithNoArguments() { FunctionProvider factory1 = null; Assert.DoesNotThrow(() => factory1 = new Factory1()); IFunction function = null; Assert.DoesNotThrow(() => function = factory1.ResolveFunction("user2")); Assert.IsNotNull(function); ExecuteResult result=null; Assert.DoesNotThrow(() => result = function.Execute(QueryContext)); Assert.IsNotNull(result); Assert.AreEqual(AdminUserName, result.ReturnValue.Value.ToString()); }
public DeviceContext10_1(DeviceSettings10_1 settings) { m_settings = settings; Direct3DFactory = new Factory1(); /* Create a Direct3D device using our passed settings */ Device = new SlimDX.Direct3D10_1.Device1(Direct3DFactory.GetAdapter(m_settings.AdapterOrdinal), DriverType.Hardware, settings.CreationFlags, FeatureLevel.Level_10_0); /* Create a Direct2D factory while we are at it...*/ Direct2DFactory = new SlimDX.Direct2D.Factory(FactoryType.Multithreaded); MakeBothSidesRendered(); }
/// <summary> /// Initializes a new instance of the <see cref="PathGeometry1"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <unmanaged>HRESULT ID2D1Factory1::CreatePathGeometry([Out, Fast] ID2D1PathGeometry1** pathGeometry)</unmanaged> public PathGeometry1(Factory1 factory) : base(IntPtr.Zero) { factory.CreatePathGeometry(this); }
/// <summary> /// /// </summary> /// <returns></returns> private static Adapter GetBestAdapter(out int bestAdapterIndex) { using (var f = new Factory1()) { Adapter bestAdapter = null; bestAdapterIndex = -1; int adapterIndex = -1; long bestVideoMemory = 0; long bestSystemMemory = 0; foreach (var item in f.Adapters) { adapterIndex++; // not skip the render only WARP device if (item.Description.VendorId != 0x1414 || item.Description.DeviceId != 0x8c) { // Windows 10 fix if (item.Outputs == null || item.Outputs.Length == 0) { continue; } } var level = global::SharpDX.Direct3D11.Device.GetSupportedFeatureLevel(item); if (level < DefaultEffectsManager.MinimumFeatureLevel) { continue; } long videoMemory = item.Description.DedicatedVideoMemory; long systemMemory = item.Description.DedicatedSystemMemory; if ((bestAdapter == null) || (videoMemory > bestVideoMemory) || ((videoMemory == bestVideoMemory) && (systemMemory > bestSystemMemory))) { bestAdapter = item; bestAdapterIndex = adapterIndex; bestVideoMemory = videoMemory; bestSystemMemory = systemMemory; } } return bestAdapter; } }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.DrawingStateBlock1"/> that can be used with the {{SaveDrawingState}} and {{RestoreDrawingState}} methods of a render target. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory1" /></param> /// <param name="textRenderingParams">Optional text parameters that indicate how text should be rendered. </param> public DrawingStateBlock1(Factory1 factory, SharpDX.DirectWrite.RenderingParams textRenderingParams) : base(IntPtr.Zero) { factory.CreateDrawingStateBlock(null, textRenderingParams, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.DrawingStateBlock1"/> that can be used with the {{SaveDrawingState}} and {{RestoreDrawingState}} methods of a render target. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory1" /></param> /// <param name="drawingStateDescription">A structure that contains antialiasing, transform, and tags information.</param> /// <param name="textRenderingParams">Optional text parameters that indicate how text should be rendered. </param> public DrawingStateBlock1(Factory1 factory, SharpDX.Direct2D1.DrawingStateDescription1 drawingStateDescription, SharpDX.DirectWrite.RenderingParams textRenderingParams) : base(IntPtr.Zero) { factory.CreateDrawingStateBlock(drawingStateDescription, textRenderingParams, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.DrawingStateBlock1"/> that can be used with the {{SaveDrawingState}} and {{RestoreDrawingState}} methods of a render target. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory1" /></param> public DrawingStateBlock1(Factory1 factory) : base(IntPtr.Zero) { factory.CreateDrawingStateBlock(null, null, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.DrawingStateBlock1"/> that can be used with the {{SaveDrawingState}} and {{RestoreDrawingState}} methods of a render target. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory1" /></param> /// <param name="drawingStateDescription">A structure that contains antialiasing, transform, and tags information.</param> public DrawingStateBlock1(Factory1 factory, SharpDX.Direct2D1.DrawingStateDescription1 drawingStateDescription) : this(factory, drawingStateDescription, null) { }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="factory"><para>The <see cref="Factory1"/> object used when creating the <see cref="SharpDX.Direct2D1.Device"/>. </para></param> /// <param name="device"><para>The <see cref="SharpDX.DXGI.Device"/> object used when creating the <see cref="SharpDX.Direct2D1.Device"/>. </para></param> /// <remarks> /// Each call to CreateDevice returns a unique <see cref="SharpDX.Direct2D1.Device"/> object.The <see cref="SharpDX.DXGI.Device"/> object is obtained by calling QueryInterface on an ID3D10Device or an ID3D11Device. /// </remarks> /// <unmanaged>HRESULT ID2D1Factory1::CreateDevice([In] IDXGIDevice* dxgiDevice,[Out] ID2D1Device** d2dDevice)</unmanaged> public Device(Factory1 factory, SharpDX.DXGI.Device device) : base(IntPtr.Zero) { factory.CreateDevice(device, this); }
char _token; // Non whitespace character returned by ReadToken public PathGeometry parse(string path, Factory1 d2dfactory) { _factory = d2dfactory; _pathGeometry = new PathGeometry(d2dfactory); _figure = _pathGeometry.Open(); //GeometrySink _sink = _pathGeometry.Open(); _formatProvider = CultureInfo.InvariantCulture; _pathString = path; _pathLength = path.Length; _curIndex = 0; _secondLastPoint = new Point(0, 0); _lastPoint = new Point(0, 0); _lastStart = new Point(0, 0); _figureStarted = false; bool first = true; char last_cmd = ' '; while (ReadToken()) // Empty path is allowed in XAML { char cmd = _token; if (first) { if ((cmd != 'M') && (cmd != 'm')) // Path starts with M|m { ThrowBadToken(); } first = false; } switch (cmd) { case 'm': case 'M': // XAML allows multiple points after M/m _lastPoint = ReadPoint(cmd, !AllowComma); _figure.BeginFigure(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), IsFilled ? FigureBegin.Filled : FigureBegin.Hollow); //_figure.StartPoint = _lastPoint; //_figure.IsFilled = IsFilled; //if (!IsClosed) _figure.Close(); //_figure.IsClosed = !IsClosed; //context.BeginFigure(_lastPoint, IsFilled, !IsClosed); _figureStarted = true; _lastStart = _lastPoint; last_cmd = 'M'; while (IsNumber(AllowComma)) { _lastPoint = ReadPoint(cmd, !AllowComma); //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //_figure.Segments.Add(_lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'L'; } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': EnsureFigure(); do { switch (cmd) { case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'h': _lastPoint.X += ReadNumber(!AllowComma); break; case 'H': _lastPoint.X = ReadNumber(!AllowComma); break; case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break; case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break; } //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; //_figure.Segments.Add(_lineSegment); _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); } while (IsNumber(AllowComma)); last_cmd = 'L'; break; case 'c': case 'C': // cubic Bezier case 's': case 'S': // smooth cublic Bezier EnsureFigure(); do { Point p; if ((cmd == 's') || (cmd == 'S')) { if (last_cmd == 'C') { p = Reflect(); } else { p = _lastPoint; } _secondLastPoint = ReadPoint(cmd, !AllowComma); } else { p = ReadPoint(cmd, !AllowComma); _secondLastPoint = ReadPoint(cmd, AllowComma); } _lastPoint = ReadPoint(cmd, AllowComma); //BezierSegment _bizierSegment = new BezierSegment(); //_bizierSegment.Point1 = p; //_bizierSegment.Point2 = _secondLastPoint; //_bizierSegment.Point3 = _lastPoint; //_figure.Segments.Add(_bizierSegment); _figure.AddBezier(new BezierSegment() { Point1 = new SharpDX.Vector2((float)p.X, (float)p.Y), Point2 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point3 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'C'; } while (IsNumber(AllowComma)); break; case 'q': case 'Q': // quadratic Bezier case 't': case 'T': // smooth quadratic Bezier EnsureFigure(); do { if ((cmd == 't') || (cmd == 'T')) { if (last_cmd == 'Q') { _secondLastPoint = Reflect(); } else { _secondLastPoint = _lastPoint; } _lastPoint = ReadPoint(cmd, !AllowComma); } else { _secondLastPoint = ReadPoint(cmd, !AllowComma); _lastPoint = ReadPoint(cmd, AllowComma); } //QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment(); //_quadraticBezierSegment.Point1 = _secondLastPoint; //_quadraticBezierSegment.Point2 = _lastPoint; //_figure.Segments.Add(_quadraticBezierSegment); _figure.AddQuadraticBezier(new QuadraticBezierSegment() { Point1 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point2 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'Q'; } while (IsNumber(AllowComma)); break; case 'a': case 'A': EnsureFigure(); do { // A 3,4 5, 0, 0, 6,7 double w = ReadNumber(!AllowComma); double h = ReadNumber(AllowComma); double rotation = ReadNumber(AllowComma); bool large = ReadBool(); bool sweep = ReadBool(); _lastPoint = ReadPoint(cmd, AllowComma); //ArcSegment _arcSegment = new ArcSegment(); //_arcSegment.Point = _lastPoint; //_arcSegment.Size = new Size(w, h); //_arcSegment.RotationAngle = rotation; //_arcSegment.IsLargeArc = large; //_arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; //_figure.Segments.Add(_arcSegment); _figure.AddArc(new ArcSegment() { Point = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), Size = new SharpDX.Size2F((float)w, (float)h), RotationAngle = (float)rotation, ArcSize = large ? ArcSize.Large : ArcSize.Small, SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.CounterClockwise }); //context.ArcTo( // _lastPoint, // new Size(w, h), // rotation, // large, // sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, // IsStroked, // !IsSmoothJoin // ); } while (IsNumber(AllowComma)); last_cmd = 'A'; break; case 'z': case 'Z': EnsureFigure(); //_figure.IsClosed = IsClosed; //context.SetClosedState(IsClosed); _figure.EndFigure(IsClosed ? FigureEnd.Closed : FigureEnd.Open); _figureStarted = false; last_cmd = 'Z'; _lastPoint = _lastStart; // Set reference point to be first point of current figure break; default: ThrowBadToken(); break; } } //if (null != _figure) //{ // _pathGeometry = new PathGeometry(d2dfactory); // _pathGeometry.Figures.Add(_figure); //} _figure.Close(); //_sink.Close(); return _pathGeometry; }
public override void Hook() { this.DebugMessage("Hook: Begin"); // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain if (_d3d10_1VTblAddresses == null) { _d3d10_1VTblAddresses = new List<IntPtr>(); _dxgiSwapChainVTblAddresses = new List<IntPtr>(); this.DebugMessage("Hook: Before device creation"); using (Factory1 factory = new Factory1()) { using (var device = new SlimDX.Direct3D10_1.Device1(factory.GetAdapter(0), DriverType.Hardware, SlimDX.Direct3D10.DeviceCreationFlags.None, FeatureLevel.Level_10_1)) { this.DebugMessage("Hook: Device created"); _d3d10_1VTblAddresses.AddRange(GetVTblAddresses(device.ComPointer, D3D10_1_DEVICE_METHOD_COUNT)); using (var renderForm = new SlimDX.Windows.RenderForm()) { using (var sc = new SwapChain(factory, device, DXGI.CreateSwapChainDescription(renderForm.Handle))) { _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.ComPointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT)); } } } } } // We will capture the backbuffer here DXGISwapChain_PresentHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present], new DXGISwapChain_PresentDelegate(PresentHook), this); // We will capture target/window resizes here DXGISwapChain_ResizeTargetHook = LocalHook.Create( _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.ResizeTarget], new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook), this); /* * Don't forget that all hooks will start deactivated... * The following ensures that all threads are intercepted: * Note: you must do this for each hook. */ DXGISwapChain_PresentHook.ThreadACL.SetExclusiveACL(new Int32[1]); DXGISwapChain_ResizeTargetHook.ThreadACL.SetExclusiveACL(new Int32[1]); }
/// <summary> /// Initializes a new instance of the <see cref="StrokeStyle1"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="strokeStyleProperties">No documentation.</param> /// <unmanaged>HRESULT ID2D1Factory1::CreateStrokeStyle([In] const D2D1_STROKE_STYLE_PROPERTIES1* strokeStyleProperties,[In, Buffer, Optional] const float* dashes,[In] unsigned int dashesCount,[Out, Fast] ID2D1StrokeStyle1** strokeStyle)</unmanaged> public StrokeStyle1(Factory1 factory, SharpDX.Direct2D1.StrokeStyleProperties1 strokeStyleProperties) : base(IntPtr.Zero) { factory.CreateStrokeStyle(ref strokeStyleProperties, null, 0, this); }
/// <summary> /// Initializes a new instance of the <see cref="StrokeStyle1"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="strokeStyleProperties">No documentation.</param> /// <param name="dashes">No documentation.</param> /// <unmanaged>HRESULT ID2D1Factory1::CreateStrokeStyle([In] const D2D1_STROKE_STYLE_PROPERTIES1* strokeStyleProperties,[In, Buffer, Optional] const float* dashes,[In] unsigned int dashesCount,[Out, Fast] ID2D1StrokeStyle1** strokeStyle)</unmanaged> /// /// <unmanaged>HRESULT ID2D1Factory1::CreateStrokeStyle([In] const D2D1_STROKE_STYLE_PROPERTIES1* strokeStyleProperties,[In, Buffer, Optional] const float* dashes,[In] unsigned int dashesCount,[Out, Fast] ID2D1StrokeStyle1** strokeStyle)</unmanaged> /// <remarks> /// It is valid to specify a dash array only if <see cref="SharpDX.Direct2D1.DashStyle.Custom"/> is also specified. /// </remarks> public StrokeStyle1(Factory1 factory, SharpDX.Direct2D1.StrokeStyleProperties1 strokeStyleProperties, float[] dashes) : base(IntPtr.Zero) { factory.CreateStrokeStyle(ref strokeStyleProperties, dashes, dashes.Length, this); }