private void CleanupPersistentResources() { device?.Dispose(); device = null !; sharpDXDevice?.Dispose(); sharpDXDevice = null !; }
private void Application_SlideShowBegin(SlideShowWindow Wn) { if (!PresentationToNDIAddIn.Properties.Settings.Default.NDIDynamic) { return; } _window = Wn; _wasFullscreenBefore = IsFullscreen; _xOrig = Wn.Presentation.SlideMaster.Width; _yOrig = Wn.Presentation.SlideMaster.Height; _device = Direct3D11Helper.CreateDevice(!PresentationToNDIAddIn.Properties.Settings.Default.UseHw); _d3dDevice = Direct3D11Helper.CreateSharpDXDevice(_device); _factory = new Factory2(); _item = GetItem(); CreateCaptureItemDependendStuff(); _ndiSender = new Thread(SendNdi) { Priority = ThreadPriority.Normal, Name = "DynamicNdiSenderThread", IsBackground = true }; _ndiSender.Start(); }
internal static IDXGIDevice CreateDXGIDevice(IDirect3DDevice direct3DDevice) { IDirect3DDxgiInterfaceAccess dxgiDeviceInterfaceAccess = (IDirect3DDxgiInterfaceAccess)direct3DDevice; IntPtr device = dxgiDeviceInterfaceAccess.GetInterface(ID3D11Resource); return(new IDXGIDevice(device)); }
public WindowsMixedRealityGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { holographicSpace = HolographicSpace.CreateForCoreWindow(CoreWindow.GetForCurrentThread()); CoreWindow.GetForCurrentThread().Activate(); Device3 d3DDevice = device.NativeDevice.QueryInterface <Device3>(); IDirect3DDevice d3DInteropDevice = null; // Acquire the DXGI interface for the Direct3D device. using (var dxgiDevice = d3DDevice.QueryInterface <SharpDX.DXGI.Device3>()) { // Wrap the native device using a WinRT interop object. uint hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr pUnknown); if (hr == 0) { d3DInteropDevice = Marshal.GetObjectForIUnknown(pUnknown) as IDirect3DDevice; Marshal.Release(pUnknown); } } holographicSpace.SetDirect3D11Device(d3DInteropDevice); BeginDraw(null); ResizeDepthStencilBuffer(backBuffer.Width, backBuffer.Height, 0); // Set a dummy back buffer as we use a seperate one for each eye. BackBuffer = Texture.New(GraphicsDevice, backBuffer.Description, null); }
public BasicSampleApplication(Compositor c) { compositor = c; device = Direct3D11Helper.CreateDevice(); // Setup the root. root = compositor.CreateContainerVisual(); root.RelativeSizeAdjustment = Vector2.One; // Setup the content. brush = compositor.CreateSurfaceBrush(); brush.HorizontalAlignmentRatio = 0.5f; brush.VerticalAlignmentRatio = 0.5f; brush.Stretch = CompositionStretch.Uniform; var shadow = compositor.CreateDropShadow(); shadow.Mask = brush; content = compositor.CreateSpriteVisual(); content.AnchorPoint = new Vector2(0.5f); content.RelativeOffsetAdjustment = new Vector3(0.5f, 0.5f, 0); content.RelativeSizeAdjustment = Vector2.One; content.Size = new Vector2(-80, -80); content.Brush = brush; content.Shadow = shadow; root.Children.InsertAtTop(content); }
public OverlayScreenCaptureCaptureHandler(Compositor c) { __compositor = c; __device = Direct3D11Helper.CreateDevice(); // Setup the root. __root = __compositor.CreateContainerVisual(); __root.RelativeSizeAdjustment = Vector2.One; // Setup the content. __brush = __compositor.CreateSurfaceBrush(); __brush.HorizontalAlignmentRatio = 0.5f; __brush.VerticalAlignmentRatio = 0.5f; __brush.Stretch = CompositionStretch.Uniform; var shadow = __compositor.CreateDropShadow(); shadow.Mask = __brush; __content = __compositor.CreateSpriteVisual(); __content.AnchorPoint = new Vector2(0.5f); __content.RelativeOffsetAdjustment = new Vector3(0.5f, 0.5f, 0); __content.RelativeSizeAdjustment = Vector2.One; __content.Brush = __brush; __content.Shadow = shadow; __root.Children.InsertAtTop(__content); }
public MainPage() { InitializeComponent(); if (!GraphicsCaptureSession.IsSupported()) { IsEnabled = false; var dialog = new MessageDialog( "Screen capture is not supported on this device for this release of Windows!", "Screen capture unsupported"); var ignored = dialog.ShowAsync(); return; } // initialize screen recording screenDevice = Direct3D11Helpers.CreateDevice(); // connect to the powerpoint app service App.AppServiceConnected += MainPage_AppServiceConnected; _timer.Interval = new TimeSpan(0, 0, 1); _timer.Tick += _timer_Tick; }
public void GraphicsInteropFromManaged() { // // This test interops a C# component (ie this one) with a C++/CX // component (GraphicsDeviceComponent) using Direct3DDevice and // Direct3DSurface to pass a IDXGIDevice and IDXGISurface between // them. // // Create a device. IDirect3DDevice graphicsDevice = NativeComponent.DeviceCreator.CreateDevice(); // We should be able to call Trim() without anything bad happening graphicsDevice.Trim(); // Now create a surface using this device. int expectedWidth = 128; int expectedHeight = 256; var expectedGraphicsFormat = DirectXPixelFormat.R32Float; IDirect3DSurface surface = NativeComponent.SurfaceCreator.CreateSurface( graphicsDevice, expectedWidth, expectedHeight, expectedGraphicsFormat); // Look at the surface description to make sure it seems valid. var desc = surface.Description; Assert.AreEqual(expectedWidth, desc.Width); Assert.AreEqual(expectedHeight, desc.Height); Assert.AreEqual(expectedGraphicsFormat, desc.Format); Assert.AreEqual(1, desc.MultisampleDescription.Count); Assert.AreEqual(0, desc.MultisampleDescription.Quality); }
public HolographicGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, HolographicSpace holographicSpace) : base(device, presentationParameters) { if (GraphicsDevice.RenderTargetViewAllocator.DescriptorHeap.Description.DescriptorCount != BufferCount) { GraphicsDevice.RenderTargetViewAllocator.Dispose(); GraphicsDevice.RenderTargetViewAllocator = new DescriptorAllocator(GraphicsDevice, DescriptorHeapType.RenderTargetView, descriptorCount: BufferCount); } using (IDXGIDevice dxgiDevice = GraphicsDevice.NativeDirect3D11Device.QueryInterface <IDXGIDevice>()) { IDirect3DDevice direct3DInteropDevice = Direct3DInterop.CreateDirect3DDevice(dxgiDevice); HolographicSpace = holographicSpace; HolographicSpace.SetDirect3D11Device(direct3DInteropDevice); } HolographicDisplay = HolographicDisplay.GetDefault(); SpatialStationaryFrameOfReference = HolographicDisplay.SpatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation(); HolographicFrame = HolographicSpace.CreateNextFrame(); HolographicSurface = HolographicFrame.GetRenderingParameters(HolographicFrame.CurrentPrediction.CameraPoses[0]).Direct3D11BackBuffer; HolographicBackBuffer = GetHolographicBackBuffer(); renderTarget = CreateRenderTarget(); direct3D11RenderTarget = CreateDirect3D11RenderTarget(); }
public void Dispose() { _closedEvent.Set(); _framePool?.Dispose(); _session?.Dispose(); if (_captureItem != null) { _captureItem.Closed -= OnClosed; } _captureItem = null; _device = null; _d3dDevice = null; _composeTexture?.Dispose(); _composeTexture = null; _composeRenderTargetView?.Dispose(); _composeRenderTargetView = null; _currentFrame?.Dispose(); //_session?.Dispose(); //_swapChain?.Dispose(); //_swapChain = null; //_framePool = null; //_session = null; //_captureItem = null; }
protected virtual void ResetFramePool(SizeInt32 size, bool recreateDevice) { do { try { if (recreateDevice) { _device = Direct3D11Helper.CreateDevice(!PresentationToNDIAddIn.Properties.Settings.Default.UseHw); } } catch { _device = null; recreateDevice = true; } } while (_device == null); // detect change from or to fullscreen --> captureItem needs to be recreated if ((_wasFullscreenBefore && !IsFullscreen) || (!_wasFullscreenBefore && IsFullscreen)) { _wasFullscreenBefore = IsFullscreen; DisposeCaptureItemDependentStuff(); _item = GetItem(); CreateCaptureItemDependendStuff(); } else { _framePool.Recreate(_device, PixelFormat, 2, size); } }
public KinectD3DImage() { if (App.Current.MainWindow != null) { IntPtr window = new WindowInteropHelper(App.Current.MainWindow).Handle; var presentparams = new SharpDX.Direct3D9.PresentParameters { Windowed = true, SwapEffect = SharpDX.Direct3D9.SwapEffect.Discard, DeviceWindowHandle = window, PresentationInterval = PresentInterval.Immediate, }; const CreateFlags deviceFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve; this.direct3d = new Direct3DEx(); this.imagingFactory = new ImagingFactory(); this.device = Capture.Direct3D11Helper.CreateDevice(); this.d3dDevice = Capture.Direct3D11Helper.CreateSharpDXDevice(this.device); this.d9device = new DeviceEx(this.direct3d, 0, DeviceType.Hardware, IntPtr.Zero, deviceFlags, presentparams); this.IsFrontBufferAvailableChanged += this.GraphicItemD3DImageIsFrontBufferAvailableChanged; this.renderEvent = new ManualResetEventSlim(false); var renderThread = new Thread(this.RenderThread); renderThread.Start(); } }
public Encoder(IDirect3DDevice device, GraphicsCaptureItem item) { _device = device; _captureItem = item; _isRecording = false; CreateMediaObjects(); }
public static Device CreateSharpDXDevice(IDirect3DDevice device) { var access = (IDirect3DDxgiInterfaceAccess)device; var d3dPointer = access.GetInterface(_id3D11Device); var d3dDevice = new Device(d3dPointer); return(d3dDevice); }
public static SharpDX.Direct3D11.Device CreateSharpDXDevice(IDirect3DDevice device) { var access = device.As <IDirect3DDxgiInterfaceAccess>(); var d3dPointer = access.GetInterface(ID3D11Device); var d3dDevice = new SharpDX.Direct3D11.Device(d3dPointer); return(d3dDevice); }
public void Dispose() { this.Stop(); this.CleanupItem(); this.device = null; this.d3dDevice = null; this.blankTexture?.Dispose(); this.blankTexture = null; }
public ModernCaptureMonitorSession(IDirect3DDevice device, ModernCaptureMonitorDescription description) : base(description) { this.CaptureItem = WinRTCaptureHelper.CreateItemForMonitor(description.MonitorInfo.Hmon); this.FramePool = Direct3D11CaptureFramePool.Create(device, description.HdrMetadata.EnableHdrProcessing ? DirectXPixelFormat.R16G16B16A16Float : DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, CaptureItem.Size); this.Session = FramePool.CreateCaptureSession(CaptureItem); this.Session.IsCursorCaptureEnabled = description.CaptureCursor; }
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device) { m_encodingProperties = encodingProperties; m_device = device; if (m_device != null) { m_canvasDevice = CanvasDevice.CreateFromDirect3D11Device(m_device); } }
/// <summary> /// Disposes of a device-based resources. /// </summary> private void DisposeDeviceAndContext() { // Dispose existing references to Direct3D 11 device and context, and set to null. this.RemoveAndDispose(ref d3dDevice); this.RemoveAndDispose(ref d3dContext); // Release the interop device. d3dInteropDevice = null; }
public Encoder(IDirect3DDevice device, GraphicsCaptureItem item) { _device = device; _d3dDevice = Direct3D11Helpers.CreateSharpDXDevice(device); _captureItem = item; _isRecording = false; _previewLock = new object(); CreateMediaObjects(); }
public CaptureEngine(IDirect3DDevice device, GraphicsCaptureItem item) { _device = device; _d3dDevice = Direct3D11Helper.CreateSharpDXDevice(_device); _framePool = Direct3D11CaptureFramePool.Create( _device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size); _session = _framePool.CreateCaptureSession(item); _lastSize = item.Size; _framePool.FrameArrived += OnFrameArrived; }
/// <summary> /// Creates a SharpDX device from a Direct3D device. /// </summary> /// <param name="device">The device to create the SharpDX device from.</param> /// <returns>The created SharpDX device.</returns> internal static Device?CreateSharpDXDevice(IDirect3DDevice device) { var access = device as IDirect3DDxgiInterfaceAccess; var d3dPointer = access?.GetInterface(ID3D11Device); if (d3dPointer != null) { var d3dDevice = new Device(d3dPointer.Value); return(d3dDevice); } return(null); }
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable. #endregion #region Initialization private void InitializeDevices() { var createdDevice = Direct3D11Helper.CreateDevice(); device = createdDevice ?? throw new Exception("Failed to create Direct3D device."); var createdSharpDXDevice = Direct3D11Helper.CreateSharpDXDevice(device); sharpDXDevice = createdSharpDXDevice ?? throw new Exception("Failed to create SharpDX device."); multithread = sharpDXDevice.QueryInterface <Multithread>(); multithread.SetMultithreadProtected(true); }
public CaptureEncode(IDirect3DDevice device, GraphicsCaptureItem item) { _device = device; _lastSize = item.Size; _d3dDevice = Direct3D11Helpers.CreateSharpDXDevice(device); _captureItem = item; _isRecording = false; //_multithread = _d3dDevice.QueryInterface<SharpDX.Direct3D11.Multithread>(); //_multithread.SetMultithreadProtected(true); //_frameEvent = new ManualResetEvent(false); //_closedEvent = new ManualResetEvent(false); //_events = new[] { _closedEvent, _frameEvent }; CreateMediaObjects(); }
public MediaSampleGenerator(IDirect3DDevice device, GraphicsCaptureItem item) { m_item = item; m_framePool = Direct3D11CaptureFramePool.CreateFreeThreaded( device, pixelFormat: DirectXPixelFormat.B8G8R8A8UIntNormalized, numberOfBuffers: 1, item.Size); m_session = m_framePool.CreateCaptureSession(m_item); m_session.IsCursorCaptureEnabled = true; m_item.Closed += OnClosed; m_framePool.FrameArrived += OnFrameArrived; }
public MainPage() { this.InitializeComponent(); _device = Direct3D11Helpers.CreateDevice(); _semaphore = new SemaphoreSlim(0, 1); var appView = ApplicationView.GetForCurrentView(); if (!appView.IsViewModeSupported(ApplicationViewMode.CompactOverlay)) { OverlayButton.IsEnabled = false; } }
public BasicCapture(IDirect3DDevice d, GraphicsCaptureItem i) { item = i; device = d; d3dDevice = Direct3D11Helper.CreateSharpDXDevice(device); var size = item.Size; if (size.Height == 0 || size.Width == 0) { size = new SizeInt32() { Height = 1, Width = 1 } } ; var dxgiFactory = new SharpDX.DXGI.Factory2(); var description = new SharpDX.DXGI.SwapChainDescription1() { Width = size.Width, Height = size.Height, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Stereo = false, SampleDescription = new SharpDX.DXGI.SampleDescription() { Count = 1, Quality = 0 }, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 2, Scaling = SharpDX.DXGI.Scaling.Stretch, SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential, AlphaMode = SharpDX.DXGI.AlphaMode.Premultiplied, Flags = SharpDX.DXGI.SwapChainFlags.None }; swapChain = new SharpDX.DXGI.SwapChain1(dxgiFactory, d3dDevice, ref description); framePool = Direct3D11CaptureFramePool.Create( device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, size); session = framePool.CreateCaptureSession(i); lastSize = size; framePool.FrameArrived += OnFrameArrived; }
internal static IDirect3DDevice CreateDirect3DDevice(IDXGIDevice dxgiDevice) { Result result = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr graphicsDevice); if (result.Failure) { throw new COMException("Device creation failed.", result.Code); } IDirect3DDevice d3DInteropDevice = (IDirect3DDevice)Marshal.GetObjectForIUnknown(graphicsDevice); Marshal.Release(graphicsDevice); return(d3DInteropDevice); }
internal static IDirect3DDevice CreateDirect3DDevice(IDXGIDevice dxgiDevice) { Result result = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr graphicsDevice); if (result.Failure) { throw new InvalidOperationException(result.Code.ToString()); } IDirect3DDevice d3DInteropDevice = (IDirect3DDevice)Marshal.GetObjectForIUnknown(graphicsDevice); Marshal.Release(graphicsDevice); return(d3DInteropDevice); }
public CaptureFrameWait(IDirect3DDevice device, Func <GraphicsCaptureItem> itemFactory) { this.device = device; this.d3dDevice = Direct3D11Helper.CreateSharpDXDevice(device); this.multithread = d3dDevice.QueryInterface <SharpDX.Direct3D11.Multithread>(); this.multithread.SetMultithreadProtected(true); this.frameEvent = new ManualResetEvent(false); this.closedEvent = new ManualResetEvent(false); this.events = new[] { closedEvent, frameEvent }; this.itemFactory = itemFactory; this.CurrentItem = this.itemFactory(); InitializeBlankTexture(this.CurrentItem.Size); InitializeCapture(); }
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device) { canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device); numColumns = (uint)(encodingProperties.Width / pixelsPerTile); numRows = (uint)(encodingProperties.Height / pixelsPerTile); transforms = new Transform2DEffect[numColumns, numRows]; crops = new CropEffect[numColumns, numRows]; for (uint i = 0; i < numColumns; i++) { for (uint j = 0; j < numRows; j++) { crops[i, j] = new CropEffect(); crops[i, j].SourceRectangle = new Rect(i * pixelsPerTile, j * pixelsPerTile, pixelsPerTile, pixelsPerTile); transforms[i, j] = new Transform2DEffect(); transforms[i, j].Source = crops[i, j]; } } }
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device) { }
public void SetEncodingProperties(VideoEncodingProperties backgroundProperties, IDirect3DDevice device) { _backgroundProperties = backgroundProperties; _canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device, CanvasDebugLevel.Error); }
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device) { canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device); }
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device) { _currentEncodingProperties = encodingProperties; _canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device, CanvasDebugLevel.Error); }