private static void CreateDevice() { if (_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; _d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, _hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); _device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
private void CreateDevice() { if (m_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; /* Windows Vista runs much more performant with the IDirect3DDevice9Ex */ if (IsVistaOrBetter) { m_d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); } else/* Windows XP */ { m_d3d.CreateDevice(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, out dev); } m_device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
public DwmCapture(IntPtr hWnd) { _captureHwnd = hWnd; #region Initialise the Direct3D device int adapterOrdinal = 0; _d3dEx = new Direct3DEx(); _adapterLuid = _d3dEx.GetAdapterLuid(adapterOrdinal); var presentParams = new PresentParameters { PresentFlags = PresentFlags.LockableBackBuffer, Windowed = true, BackBufferFormat = Format.A8R8G8B8, SwapEffect = SwapEffect.Flip }; _deviceEx = new DeviceEx(_d3dEx, adapterOrdinal, DeviceType.Hardware, _captureHwnd, SlimDX.Direct3D9.CreateFlags.Multithreaded | SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, presentParams); #endregion #region Setup the shared surface (using DWM) uint format = 0; IntPtr pSharedHandle = IntPtr.Zero; int hr = NativeMethods.GetSharedSurface(_captureHwnd, _adapterLuid, 0, 0, ref format, out pSharedHandle, 0); NativeMethods.UpdateWindowShared(_captureHwnd, 0, 0, 0, IntPtr.Zero, IntPtr.Zero); RECT winRect; NativeMethods.GetWindowRect(_captureHwnd, out winRect); Size size = new Size(winRect.Right - winRect.Left, winRect.Bottom - winRect.Top); /* Hack because SlimDX does not let you specify a shared handle for creating shared resources we * have to create an IDirect3DDevice9 reference to the device instead */ IDirect3DDevice9 devEx = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(_deviceEx.ComPointer); IntPtr pTexture; devEx.CreateTexture((int)size.Width, (int)size.Height, 1, 1, format, 0, out pTexture, ref pSharedHandle); Texture texture = Texture.FromPointer(pTexture); _sharedSurface = texture.GetSurfaceLevel(0); _renderTarget = Surface.CreateRenderTarget(_deviceEx, (int)size.Width, (int)size.Height, Format.X8R8G8B8, MultisampleType.None, 0, false); _deviceEx.SetRenderTarget(0, _renderTarget); Surface.FromSurface(_renderTarget, _sharedSurface, Filter.None, 0); _systemMemorySurface = Surface.CreateOffscreenPlain(_deviceEx, (int)size.Width, (int)size.Height, Format.X8R8G8B8, Pool.SystemMemory); #endregion }
private void CreateDevice() { if (m_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; /* Windows Vista runs much more performant with the IDirect3DDevice9Ex */ int hr = 0; if (m_d3dEx != null) { hr = m_d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); } else/* Windows XP */ { hr = m_d3d.CreateDevice(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, out dev); } if (dev == IntPtr.Zero) { throw new WPFMediaKitException($"Cannot create D3D device ({hr:X}). Do you have D3D acceleration enabled for your graphics card?"); } m_device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
/// <summary> /// Part of the dispose pattern /// </summary> protected virtual void Dispose(bool disposing) { //if (m_disposed) return; if (disposing) { InvokeNewSurfaceEvent(IntPtr.Zero); /* Pass a dummy cookie to TerminateDevice */ TerminateDevice(IntPtr.Zero); if (m_allocatorNotify != null) { Marshal.FinalReleaseComObject(m_allocatorNotify); m_allocatorNotify = null; } if (m_d3d != null) { Marshal.FinalReleaseComObject(m_d3d); m_d3d = null; } if (m_d3dEx != null) { Marshal.FinalReleaseComObject(m_d3dEx); m_d3dEx = null; } if (m_device != null) { Marshal.FinalReleaseComObject(m_device); m_device = null; } } m_disposed = true; }
private void CreateDevice() { if (m_device != null) return; var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; /* Windows Vista runs much more performant with the IDirect3DDevice9Ex */ if (IsVistaOrBetter) { m_d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); } else/* Windows XP */ { m_d3d.CreateDevice(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, out dev); } m_device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
public static extern Win32.HRESULT GetPhysicalMonitorsFromIDirect3DDevice9([In] ref IDirect3DDevice9 pDirect3DDevice9, [In] UInt32 dwPhysicalMonitorArraySize, [Out] PHYSICAL_MONITOR[] pPhysicalMonitorArray);
public static extern Win32.HRESULT GetNumberOfPhysicalMonitorsFromIDirect3DDevice9([In] ref IDirect3DDevice9 pDirect3DDevice9, [Out] out UInt32 pdwNumberOfPhysicalMonitors);