VBoxDispKmt.cpp revision d9e3fb31ad27094d4e0e2664b75b3c608708cfbc
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/* $Id$ */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/** @file
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VBoxVideo Display D3D User mode dll
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2011 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
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.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "VBoxDispD3DCmn.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HRESULT hr = S_OK;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync memset(pCallbacks, 0, sizeof (*pCallbacks));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pCallbacks->hGdi32 = LoadLibraryW(L"gdi32.dll");
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync if (pCallbacks->hGdi32 != NULL)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync bool bSupported = true;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pCallbacks->pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromHdc");
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log((__FUNCTION__"pfnD3DKMTOpenAdapterFromHdc = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromHdc));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromHdc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCloseAdapter");
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Log((__FUNCTION__": pfnD3DKMTCloseAdapter = %p\n", pCallbacks->pfnD3DKMTCloseAdapter));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCloseAdapter);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEscape");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTEscape = %p\n", pCallbacks->pfnD3DKMTEscape));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTEscape);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync pCallbacks->pfnD3DKMTCreateDevice = (PFND3DKMT_CREATEDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateDevice");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTCreateDevice = %p\n", pCallbacks->pfnD3DKMTCreateDevice));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateDevice);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyDevice = (PFND3DKMT_DESTROYDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyDevice");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyDevice = %p\n", pCallbacks->pfnD3DKMTDestroyDevice));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyDevice);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCreateContext = (PFND3DKMT_CREATECONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateContext");
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Log((__FUNCTION__": pfnD3DKMTCreateContext = %p\n", pCallbacks->pfnD3DKMTCreateContext));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateContext);
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyContext = (PFND3DKMT_DESTROYCONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyContext");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyContext = %p\n", pCallbacks->pfnD3DKMTDestroyContext));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyContext);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTRender = (PFND3DKMT_RENDER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTRender");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTRender = %p\n", pCallbacks->pfnD3DKMTRender));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTRender);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTCreateAllocation = (PFND3DKMT_CREATEALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateAllocation");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTCreateAllocation = %p\n", pCallbacks->pfnD3DKMTCreateAllocation));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTCreateAllocation);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTDestroyAllocation = (PFND3DKMT_DESTROYALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyAllocation");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTDestroyAllocation = %p\n", pCallbacks->pfnD3DKMTDestroyAllocation));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTDestroyAllocation);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTLock = (PFND3DKMT_LOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTLock");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTLock = %p\n", pCallbacks->pfnD3DKMTLock));
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTLock);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pCallbacks->pfnD3DKMTUnlock = (PFND3DKMT_UNLOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTUnlock");
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": pfnD3DKMTUnlock = %p\n", pCallbacks->pfnD3DKMTUnlock));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync bSupported &= !!(pCallbacks->pfnD3DKMTUnlock);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /*Assert(bSupported);*/
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync if (bSupported)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return S_OK;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Log((__FUNCTION__": one of pfnD3DKMT function pointers failed to initialize\n"));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync hr = E_NOINTERFACE;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync FreeLibrary(pCallbacks->hGdi32);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync DWORD winEr = GetLastError();
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync hr = HRESULT_FROM_WIN32(winEr);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Assert(0);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Assert(hr != S_OK);
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync Assert(hr != S_FALSE);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (hr == S_OK || hr == S_FALSE)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync hr = E_FAIL;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return hr;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync}
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsyncHRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync{
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync FreeLibrary(pCallbacks->hGdi32);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT vboxDispKmtAdpHdcCreate(HDC *phDc)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HRESULT hr = E_FAIL;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync DISPLAY_DEVICE DDev;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync memset(&DDev, 0, sizeof (DDev));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync DDev.cb = sizeof (DDev);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *phDc = NULL;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (int i = 0; ; ++i)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (EnumDisplayDevices(NULL, /* LPCTSTR lpDevice */ i, /* DWORD iDevNum */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync &DDev, 0 /* DWORD dwFlags*/))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (DDev.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HDC hDc = CreateDC(NULL, DDev.DeviceName, NULL, NULL);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (hDc)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *phDc = hDc;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync else
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync {
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync DWORD winEr = GetLastError();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(0);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync hr = HRESULT_FROM_WIN32(winEr);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync Assert(FAILED(hr));
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync break;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync DWORD winEr = GetLastError();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync// BP_WARN();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync hr = HRESULT_FROM_WIN32(winEr);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifdef DEBUG_misha
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Assert(FAILED(hr));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (!FAILED(hr))
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync hr = E_FAIL;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync break;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync return hr;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncHRESULT vboxDispKmtOpenAdapter(PVBOXDISPKMT_CALLBACKS pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync{
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync D3DKMT_OPENADAPTERFROMHDC OpenAdapterData = {0};
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync HRESULT hr = vboxDispKmtAdpHdcCreate(&OpenAdapterData.hDc);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (hr == S_OK)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync Assert(OpenAdapterData.hDc);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync NTSTATUS Status = pCallbacks->pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync#ifdef DEBUG_misha
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync /* may fail with xpdm driver */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync Assert(!Status);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync#endif
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (!Status)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync pAdapter->hAdapter = OpenAdapterData.hAdapter;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync pAdapter->hDc = OpenAdapterData.hDc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pAdapter->pCallbacks = pCallbacks;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return S_OK;
a937991834fc0b6218eab7f473c139c326d4cebdvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
a937991834fc0b6218eab7f473c139c326d4cebdvboxsync {
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName failed, Status (0x%x)\n", Status));
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync hr = E_FAIL;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync DeleteDC(OpenAdapterData.hDc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return hr;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync}
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncHRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync{
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync D3DKMT_CLOSEADAPTER ClosaAdapterData = {0};
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync ClosaAdapterData.hAdapter = pAdapter->hAdapter;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCloseAdapter(&ClosaAdapterData);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(!Status);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!Status)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync DeleteDC(pAdapter->hDc);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return S_OK;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Log((__FUNCTION__": pfnD3DKMTCloseAdapter failed, Status (0x%x)\n", Status));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync return E_FAIL;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync}
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncHRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice)
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync{
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync D3DKMT_CREATEDEVICE CreateDeviceData = {0};
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync CreateDeviceData.hAdapter = pAdapter->hAdapter;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCreateDevice(&CreateDeviceData);
24ef2ade0f53030e73f5b4e43f52892b03f7915dvboxsync Assert(!Status);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (!Status)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync pDevice->pAdapter = pAdapter;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pDevice->hDevice = CreateDeviceData.hDevice;
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;
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync return S_OK;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return E_FAIL;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncHRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync D3DKMT_DESTROYDEVICE DestroyDeviceData = {0};
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync DestroyDeviceData.hDevice = pDevice->hDevice;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyDevice(&DestroyDeviceData);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Assert(!Status);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!Status)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return S_OK;
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync }
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync return E_FAIL;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync}
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncHRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync VBOXWDDM_CONTEXT_TYPE enmType, HANDLE hEvent, uint64_t u64UmInfo)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
02f7c106d33c45f99ec412a5fe0adde868f700fcvboxsync VBOXWDDM_CREATECONTEXT_INFO Info = {0};
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Info.u32IfVersion = 9;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Info.enmType = enmType;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Info.hUmEvent = (uint64_t)hEvent;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Info.u64UmInfo = u64UmInfo;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync D3DKMT_CREATECONTEXT ContextData = {0};
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync ContextData.hDevice = pDevice->hDevice;
ContextData.NodeOrdinal = VBOXWDDM_NODE_ID_3D_KMT;
ContextData.EngineAffinity = VBOXWDDM_ENGINE_ID_3D_KMT;
ContextData.pPrivateDriverData = &Info;
ContextData.PrivateDriverDataSize = sizeof (Info);
ContextData.ClientHint = enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL ? D3DKMT_CLIENTHINT_OPENGL : D3DKMT_CLIENTHINT_DX9;
NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTCreateContext(&ContextData);
Assert(!Status);
if (!Status)
{
pContext->pDevice = pDevice;
pContext->hContext = ContextData.hContext;
pContext->pCommandBuffer = ContextData.pCommandBuffer;
pContext->CommandBufferSize = ContextData.CommandBufferSize;
pContext->pAllocationList = ContextData.pAllocationList;
pContext->AllocationListSize = ContextData.AllocationListSize;
pContext->pPatchLocationList = ContextData.pPatchLocationList;
pContext->PatchLocationListSize = ContextData.PatchLocationListSize;
return S_OK;
}
return E_FAIL;
}
HRESULT vboxDispKmtDestroyContext(PVBOXDISPKMT_CONTEXT pContext)
{
D3DKMT_DESTROYCONTEXT DestroyContextData = {0};
DestroyContextData.hContext = pContext->hContext;
NTSTATUS Status = pContext->pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyContext(&DestroyContextData);
Assert(!Status);
if (!Status)
return S_OK;
return E_FAIL;
}