Ejemplo n.º 1
0
            /// <summary>
            /// Creates device with necessary flags for video processing
            /// </summary>
            /// <param name="manager">DXGI Manager, used to create media engine</param>
            /// <returns>Device with video support</returns>
            internal static DXDevice CreateDeviceForVideo(out DXGIDeviceManager manager)
            {
                //Device need bgra and video support
                var device = new DXDevice(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.VideoSupport);

                //Add multi thread protection on device
                DeviceMultithread mt = device.QueryInterface <DeviceMultithread>();

                mt.SetMultithreadProtected(true);

                //Reset device
                manager = new DXGIDeviceManager();
                manager.ResetDevice(device);

                return(device);
            }
Ejemplo n.º 2
0
 public void Initialize(SharpDXContext context)
 {
     lock (this.lockObject)
     {
         this.sharpDxContext = context;
         MediaManager.Startup(false);
         this.multithread = this.sharpDxContext.D3DContext.QueryInterface <DeviceMultithread>();
         this.multithread.SetMultithreadProtected((Bool)true);
         this.dxgiDeviceManager = new DXGIDeviceManager();
         this.dxgiDeviceManager.ResetDevice((ComObject)this.sharpDxContext.D3DDevice);
         this.attributes = new MediaEngineAttributes(0)
         {
             DxgiManager       = this.dxgiDeviceManager,
             VideoOutputFormat = 87
         };
         using (MediaEngineClassFactory resource_0 = new MediaEngineClassFactory())
             this.mediaEngine = new MediaEngine(resource_0, this.attributes, MediaEngineCreateFlags.None, new MediaEngineNotifyDelegate(this.OnMediaEngineEvent));
         this.mediaEngineEx        = this.mediaEngine.QueryInterface <MediaEngineEx>();
         this.mediaEngine.Loop     = (Bool)true;
         this.mediaEngine.AutoPlay = (Bool)true;
     }
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        protected override void OnInitialize(IServiceRegistry registry)
        {
            _graphicsDevice = registry.GetService <IGraphicsDevice>();
            _spriteBatch    = ToDispose(new SpriteBatch(_graphicsDevice));
            MediaManager.Startup();
            DeviceMultithread multithread = _graphicsDevice.Device.QueryInterface <DeviceMultithread>();

            multithread.SetMultithreadProtected(true);
            _dxgiDeviceManager = ToDispose(new DXGIDeviceManager());
            _dxgiDeviceManager.ResetDevice(_graphicsDevice.Device);

            MediaEngineAttributes attributes = new MediaEngineAttributes
            {
                DxgiManager = _dxgiDeviceManager, VideoOutputFormat = (int)Format.B8G8R8A8_UNorm
            };

            using (MediaEngineClassFactory factory = new MediaEngineClassFactory())
            {
                _mediaEngine = ToDispose(
                    new MediaEngine(
                        factory, attributes, MediaEngineCreateFlags.WaitForStableState, OnMediaEngineEvent));
            }
            _mediaEngineEx = ToDispose(_mediaEngine.QueryInterface <MediaEngineEx>());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Configures the Direct3D device, and stores handles to it and the device context.
        /// </summary>
        private void CreateDeviceResources()
        {
            DisposeDeviceAndContext();

            // This flag adds support for surfaces with a different color channel ordering
            // than the API default. It is required for compatibility with Direct2D.
            DeviceCreationFlags creationFlags = DeviceCreationFlags.BgraSupport;

            creationFlags |= DeviceCreationFlags.VideoSupport;

#if DEBUG
            if (DirectXHelper.SdkLayersAvailable())
            {
                // If the project is in a debug build, enable debugging via SDK Layers with this flag.
                creationFlags |= DeviceCreationFlags.Debug;
            }
#endif

            // This array defines the set of DirectX hardware feature levels this app will support.
            // Note the ordering should be preserved.
            // Note that HoloLens supports feature level 11.1. The HoloLens emulator is also capable
            // of running on graphics cards starting with feature level 10.0.
            FeatureLevel[] featureLevels =
            {
                FeatureLevel.Level_12_1,
                FeatureLevel.Level_12_0,
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0
            };
            RasterizerStateDescription rasterDesc = new RasterizerStateDescription()
            {
                FillMode = FillMode.Solid,
                CullMode = CullMode.Back,
                IsFrontCounterClockwise = false,
                DepthBias                = 0,
                SlopeScaledDepthBias     = 0,
                DepthBiasClamp           = 0,
                IsDepthClipEnabled       = true,
                IsScissorEnabled         = false,
                IsMultisampleEnabled     = true,
                IsAntialiasedLineEnabled = true
            };

            // Create the Direct3D 11 API device object and a corresponding context.
            try
            {
                if (null != dxgiAdapter)
                {
                    using (var device = new Device(dxgiAdapter, creationFlags, featureLevels))
                    {
                        // Store pointers to the Direct3D 11.1 API device.
                        d3dDevice = this.ToDispose(device.QueryInterface <Device3>());
                    }
                }
                else
                {
                    using (var device = new Device(DriverType.Hardware, creationFlags, featureLevels))
                    {
                        // Store a pointer to the Direct3D device.
                        d3dDevice = this.ToDispose(device.QueryInterface <Device3>());
                    }
                }
            }
            catch
            {
                // If the initialization fails, fall back to the WARP device.
                // For more information on WARP, see:
                // http://go.microsoft.com/fwlink/?LinkId=286690
                using (var device = new Device(DriverType.Warp, creationFlags, featureLevels))
                {
                    d3dDevice = this.ToDispose(device.QueryInterface <Device3>());
                }
            }

            // Cache the feature level of the device that was created.
            d3dFeatureLevel = d3dDevice.FeatureLevel;

            // Store a pointer to the Direct3D immediate context.
            d3dContext = this.ToDispose(d3dDevice.ImmediateContext3);

            // 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.
                IntPtr pUnknown;
                UInt32 hr = InteropStatics.CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out pUnknown);
                if (hr == 0)
                {
                    d3dInteropDevice = (IDirect3DDevice)Marshal.GetObjectForIUnknown(pUnknown);
                    Marshal.Release(pUnknown);
                }

                // Store a pointer to the DXGI adapter.
                // This is for the case of no preferred DXGI adapter, or fallback to WARP.
                dxgiAdapter = this.ToDispose(dxgiDevice.Adapter.QueryInterface <SharpDX.DXGI.Adapter3>());
            }

            // Check for device support for the optional feature that allows setting the render target array index from the vertex shader stage.
            var options = d3dDevice.CheckD3D113Features3();
            if (options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer)
            {
                d3dDeviceSupportsVprt = true;
            }

            RasterizerState rsState = new RasterizerState(d3dDevice, rasterDesc);
            d3dContext.Rasterizer.State = rsState;
            // Need to multithread for video Playback MF threads
            DeviceMultithread mt = d3dDevice.QueryInterface <SharpDX.Direct3D.DeviceMultithread>();
            mt.SetMultithreadProtected(true);
        }