locked
Using Direct2D in media foundation transform

    Question

  • Hi,

    I'm trying to use Direct2D in my custom media foundation transform (IMFTransform). For some reason creating Direct2D device fails. CreateDevice method returns E_INVALIDARG. Is there any reason why Direct2D couldn't be used in IMFTransform? Do I need to configure Direct3D11/DXGI device somehow to make it work? 

    D2D1_FACTORY_OPTIONS options;
    ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));
    
    D2D1CreateFactory(
    	D2D1_FACTORY_TYPE_SINGLE_THREADED,
    	__uuidof(ID2D1Factory),
    	&options,
    	&m_d2dFactory);
    
    ComPtr<IDXGIDevice> pDXGIDevice = nullptr;
    hr = pDevice->QueryInterface<IDXGIDevice>(&pDXGIDevice);
    if (FAILED(hr))
    {
    	return hr;
    }
    
    hr = m_d2dFactory->CreateDevice(pDXGIDevice.Get(), &m_d2dDevice);
    if (FAILED(hr))
    {
    	return hr;
    }
    
    hr = m_d2dDevice->CreateDeviceContext(
            D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
    	&m_d2dContext);
    if (FAILED(hr))
    {
    	return hr;
    }


    Wednesday, November 07, 2012 2:36 PM

All replies

  • Hi Antti,

    If you have the Windows Kits installed in your machine (which I assume you do since you're able to build with D2D header file), you can enable the D2D debug layer to inspect in more detail what causes that error to return. Here is how:

            // If you set the options.debugLevel to D2D1_DEBUG_LEVEL_NONE,
            // the debug layer is not enabled.
    #if defined(DEBUG) || defined(_DEBUG)
            D2D1_FACTORY_OPTIONS options;
            options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
    
            hr = D2D1CreateFactory(
                D2D1_FACTORY_TYPE_SINGLE_THREADED,
                options,
                &m_pD2DFactory
                );
    #else
            hr = D2D1CreateFactory(
                D2D1_FACTORY_TYPE_SINGLE_THREADED,
                &m_pD2DFactory
                );
    #endif

    More detail about D2D debug layer can be found here: http://msdn.microsoft.com/en-us/library/windows/desktop/ee794277(v=vs.85).aspx

    Also it would help to know what is the type of 'pDevice' in the sample code above.

    Worachai Chaoweeraprasit

    Tuesday, September 17, 2013 8:41 PM