示例#1
0
        //-----------------------------------------------------------------------------
        // GetSwapChainPresentParameters
        //
        // Given a media type that describes the video format, fills in the
        // D3DPRESENT_PARAMETERS for creating a swap chain.
        //-----------------------------------------------------------------------------
        protected void GetSwapChainPresentParameters(IMFMediaType pType, out D3DPRESENT_PARAMETERS pPP)
        {
            pPP = new D3DPRESENT_PARAMETERS();
            // Caller holds the object lock.

            int width = 0, height = 0;
            int d3dFormat = 0;

            VideoTypeBuilder pTypeHelper = null;

            if (m_hwnd == IntPtr.Zero)
            {
                throw new COMException("D3DPresentEngine::GetSwapChainPresentParameters", MFError.MF_E_INVALIDREQUEST);
            }

            try
            {
                // Create the helper object for reading the proposed type.
                pTypeHelper = new VideoTypeBuilder(pType);

                // Get some information about the video format.
                pTypeHelper.GetFrameDimensions(out width, out height);
                pTypeHelper.GetFourCC(out d3dFormat);

                pPP.BackBufferWidth = width;
                pPP.BackBufferHeight = height;
                pPP.Windowed = true;
                pPP.SwapEffect = D3DSWAPEFFECT.Copy;
                pPP.BackBufferFormat = (D3DFORMAT)d3dFormat;
                pPP.hDeviceWindow = m_hwnd;
                pPP.Flags = D3DPRESENTFLAG.Video;
                pPP.PresentationInterval = D3DPRESENT_INTERVAL.Default;

                D3DDEVICE_CREATION_PARAMETERS dparams;
                m_pDevice.GetCreationParameters(out dparams);

                if (dparams.DeviceType != D3DDEVTYPE.HAL)
                {
                    pPP.Flags |= D3DPRESENTFLAG.LockableBackbuffer;
                }
            }
            catch { }

            //SafeRelease(pTypeHelper);
        }
示例#2
0
        //-----------------------------------------------------------------------------
        // CreateD3DDevice
        //
        // Creates the Direct3D device.
        //-----------------------------------------------------------------------------
        protected void CreateD3DDevice()
        {
            IntPtr hwnd = IntPtr.Zero;
            IntPtr hMonitor = IntPtr.Zero;
            int uAdapterID = 0;
            D3DCREATE vp = 0;

            D3DCAPS9 ddCaps;

            IDirect3DDevice9Ex pDevice = null;

            // Hold the lock because we might be discarding an exisiting device.
            lock (this)
            {
                if ((m_pD3D9 == null) || (m_pDeviceManager == null))
                {
                    throw new COMException("D3DPresentEngine::CreateD3DDevice", MFError.MF_E_NOT_INITIALIZED);
                }

                hwnd = GetDesktopWindow();

                // Note: The presenter creates additional swap chains to present the
                // video frames. Therefore, it does not use the device's implicit
                // swap chain, so the size of the back buffer here is 1 x 1.

                D3DPRESENT_PARAMETERS pp = new D3DPRESENT_PARAMETERS();

                pp.BackBufferWidth = 1;
                pp.BackBufferHeight = 1;
                pp.Windowed = true;
                pp.SwapEffect = D3DSWAPEFFECT.Copy;
                pp.BackBufferFormat = D3DFORMAT.Unknown;
                pp.hDeviceWindow = hwnd;
                pp.Flags = D3DPRESENTFLAG.Video;
                pp.PresentationInterval = D3DPRESENT_INTERVAL.Default;

                // Find the monitor for this window.
                if (m_hwnd != IntPtr.Zero)
                {
                    hMonitor = MonitorFromWindow(m_hwnd, MonitorFlags.DefaultToNearest);

                    // Find the corresponding adapter.
                    FindAdapter(m_pD3D9 as IDirect3D9, hMonitor, out uAdapterID);
                }

                // Get the device caps for this adapter.
                m_pD3D9.GetDeviceCaps(uAdapterID, D3DDEVTYPE.HAL, out ddCaps);

                if ((ddCaps.DevCaps & D3DDEVCAPS.HWTRANSFORMANDLIGHT) > 0)
                {
                    vp = D3DCREATE.HardwareVertexProcessing;
                }
                else
                {
                    vp = D3DCREATE.SoftwareVertexProcessing;
                }

                // Create the device.
                m_pD3D9.CreateDeviceEx(
                    uAdapterID,
                    D3DDEVTYPE.HAL,
                    pp.hDeviceWindow,
                    vp | D3DCREATE.NoWindowChanges | D3DCREATE.MultiThreaded | D3DCREATE.FPU_PRESERVE,
                    pp,
                    null,
                    out pDevice
                    );

                // Get the adapter display mode.
                m_pD3D9.GetAdapterDisplayMode(uAdapterID, out m_DisplayMode);

                // Reset the D3DDeviceManager with the new device
                m_pDeviceManager.ResetDevice(pDevice, m_DeviceResetToken);

                if (m_pDevice != pDevice)
                {
                    SafeRelease(m_pDevice);

                    m_pDevice = pDevice;
                }

                //SafeRelease(pDevice);
            }
        }