VBoxDispKmt.cpp revision d9e3fb31ad27094d4e0e2664b75b3c608708cfbc
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VBoxVideo Display D3D User mode dll
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2011 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pCallbacks->pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromHdc");
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log((__FUNCTION__"pfnD3DKMTOpenAdapterFromHdc = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromHdc));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromHdc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCloseAdapter");
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Log((__FUNCTION__": pfnD3DKMTCloseAdapter = %p\n", pCallbacks->pfnD3DKMTCloseAdapter));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCloseAdapter);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEscape");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTEscape = %p\n", pCallbacks->pfnD3DKMTEscape));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync pCallbacks->pfnD3DKMTCreateDevice = (PFND3DKMT_CREATEDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateDevice");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTCreateDevice = %p\n", pCallbacks->pfnD3DKMTCreateDevice));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateDevice);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyDevice = (PFND3DKMT_DESTROYDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyDevice");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyDevice = %p\n", pCallbacks->pfnD3DKMTDestroyDevice));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyDevice);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCreateContext = (PFND3DKMT_CREATECONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateContext");
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Log((__FUNCTION__": pfnD3DKMTCreateContext = %p\n", pCallbacks->pfnD3DKMTCreateContext));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateContext);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyContext = (PFND3DKMT_DESTROYCONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyContext");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyContext = %p\n", pCallbacks->pfnD3DKMTDestroyContext));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyContext);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTRender = (PFND3DKMT_RENDER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTRender");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTRender = %p\n", pCallbacks->pfnD3DKMTRender));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCreateAllocation = (PFND3DKMT_CREATEALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateAllocation");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTCreateAllocation = %p\n", pCallbacks->pfnD3DKMTCreateAllocation));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateAllocation);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyAllocation = (PFND3DKMT_DESTROYALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyAllocation");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyAllocation = %p\n", pCallbacks->pfnD3DKMTDestroyAllocation));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyAllocation);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTLock = (PFND3DKMT_LOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTLock");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTLock = %p\n", pCallbacks->pfnD3DKMTLock));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTUnlock = (PFND3DKMT_UNLOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTUnlock");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTUnlock = %p\n", pCallbacks->pfnD3DKMTUnlock));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /*Assert(bSupported);*/
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": one of pfnD3DKMT function pointers failed to initialize\n"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncHRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (int i = 0; ; ++i)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (EnumDisplayDevices(NULL, /* LPCTSTR lpDevice */ i, /* DWORD iDevNum */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (DDev.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HDC hDc = CreateDC(NULL, DDev.DeviceName, NULL, NULL);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// BP_WARN();
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncHRESULT vboxDispKmtOpenAdapter(PVBOXDISPKMT_CALLBACKS pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync HRESULT hr = vboxDispKmtAdpHdcCreate(&OpenAdapterData.hDc);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync NTSTATUS Status = pCallbacks->pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData);
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync /* may fail with xpdm driver */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName failed, Status (0x%x)\n", Status));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncHRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCloseAdapter(&ClosaAdapterData);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Log((__FUNCTION__": pfnD3DKMTCloseAdapter failed, Status (0x%x)\n", Status));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncHRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCreateDevice(&CreateDeviceData);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->pCommandBuffer = CreateDeviceData.pCommandBuffer;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->CommandBufferSize = CreateDeviceData.CommandBufferSize;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->pAllocationList = CreateDeviceData.pAllocationList;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->AllocationListSize = CreateDeviceData.AllocationListSize;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->pPatchLocationList = CreateDeviceData.pPatchLocationList;
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync pDevice->PatchLocationListSize = CreateDeviceData.PatchLocationListSize;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncHRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyDevice(&DestroyDeviceData);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync VBOXWDDM_CONTEXT_TYPE enmType, HANDLE hEvent, uint64_t u64UmInfo)
ContextData.ClientHint = enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL ? D3DKMT_CLIENTHINT_OPENGL : D3DKMT_CLIENTHINT_DX9;
if (!Status)
return S_OK;
return E_FAIL;
NTSTATUS Status = pContext->pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyContext(&DestroyContextData);
if (!Status)
return S_OK;
return E_FAIL;