Esempio n. 1
0
        static public void D2dRelease(Direct2DInformationW info)
        {
            info._bufferBack?.Dispose();
            info.View?.Dispose();

            info.ImagingFacy?.Dispose();


            info.d2DDevice?.Dispose();
            info.D2DFacy?.Dispose();
            info.dxgiDevice?.Dispose();
            info.d3DDevice?.Dispose();
            info.backbuffer.Dispose();

            info.swapChain.Dispose();
        }
Esempio n. 2
0
        static public Direct2DInformationW D2dInit(Size size, IntPtr handle, bool isfullwindow)
        {
            Direct2DInformationW result = new Direct2DInformationW();

            result.d3DDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
            var __dxgiDevice = result.d3DDevice.QueryInterface <Device>();

            result.dxgiDevice = __dxgiDevice.QueryInterface <SharpDX.DXGI.Device2>();
            __dxgiDevice.Dispose();

            result.D2DFacy   = new D2DFactory();
            result.d2DDevice = new SharpDX.Direct2D1.Device(result.D2DFacy, result.dxgiDevice);

            result.View        = new DeviceContext(result.d2DDevice, DeviceContextOptions.EnableMultithreadedOptimizations);
            result.ImagingFacy = new ImagingFactory();

            result.swapChainDesc = new SwapChainDescription1();


            result.swapChainDesc.Width             = size.Width;            // use automatic sizing
            result.swapChainDesc.Height            = size.Height;
            result.swapChainDesc.Format            = Format.B8G8R8A8_UNorm; // this is the most common swapchain format
            result.swapChainDesc.Stereo            = false;
            result.swapChainDesc.SampleDescription = new SampleDescription()
            {
                Count   = 1,
                Quality = 0
            };
            result.swapChainDesc.Usage       = Usage.RenderTargetOutput;
            result.swapChainDesc.BufferCount = 2;                         // use double buffering to enable flip
            result.swapChainDesc.Scaling     = Scaling.None;
            result.swapChainDesc.SwapEffect  = SwapEffect.FlipSequential; // all apps must use this SwapEffect
            result.swapChainDesc.Flags       = SwapChainFlags.AllowModeSwitch;
            var vb_ns = result.dxgiDevice.GetParent <Adapter>().GetParent <SharpDX.DXGI.Factory2>();

            result.swapChain = new SwapChain1(vb_ns, result.d3DDevice, handle, ref result.swapChainDesc);
            RawBool isFulls;
            Output  opt;

            result.swapChain.GetFullscreenState(out isFulls, out opt);
            if (!isfullwindow && !isFulls)
            {
                ModeDescription res = new ModeDescription();
                res.Format           = Format.B8G8R8A8_UNorm;
                res.Height           = size.Height;
                res.Width            = size.Width;
                res.Scaling          = DisplayModeScaling.Stretched;
                res.RefreshRate      = Rational.Empty;
                res.ScanlineOrdering = DisplayModeScanlineOrder.LowerFieldFirst;

                result.swapChain.ResizeTarget(ref res);

                result.swapChain.SetFullscreenState(!isfullwindow, opt);
                result.swapChain.ResizeBuffers(2, size.Width, size.Height, Format.B8G8R8A8_UNorm, SwapChainFlags.AllowModeSwitch);
            }
            result.backbuffer = Surface.FromSwapChain(result.swapChain, 0);

            result._bufferBack = new D2DBitmap(result.View, result.backbuffer);


            result.View.Target        = result._bufferBack;
            result.Dpi                = result._bufferBack.DotsPerInch;
            result.View.AntialiasMode = AntialiasMode.Aliased;
            vb_ns.Dispose();

            return(result);
        }