1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxVideo Display D3D User mode dll
|
---|
4 | *
|
---|
5 | * Copyright (C) 2010 Oracle Corporation
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License (GPL) as published by the Free Software
|
---|
11 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | */
|
---|
15 | #include "VBoxDispMp.h"
|
---|
16 |
|
---|
17 | #include <iprt/thread.h>
|
---|
18 | #include <iprt/err.h>
|
---|
19 |
|
---|
20 | #include "VBoxDispD3DCmn.h"
|
---|
21 |
|
---|
22 | #ifdef VBOXWDDM_TEST_UHGSMI
|
---|
23 | #include "VBoxDispProfile.h"
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | static RTTHREAD g_VBoxDispMpTstThread;
|
---|
27 | static VBOXDISPMP_CALLBACKS g_VBoxDispMpTstCallbacks;
|
---|
28 | static HMODULE g_hVBoxDispMpModule;
|
---|
29 | static PFNVBOXDISPMP_GETCALLBACKS g_pfnVBoxDispMpGetCallbacks;
|
---|
30 |
|
---|
31 |
|
---|
32 | static void vboxDispMpTstLogRect(const char * pPrefix, RECT *pRect, const char * pSuffix)
|
---|
33 | {
|
---|
34 | vboxVDbgPrint(("%s left(%d), top(%d), right(%d), bottom(%d) %s", pPrefix, pRect->left, pRect->top, pRect->right, pRect->bottom, pSuffix));
|
---|
35 | }
|
---|
36 |
|
---|
37 | static DECLCALLBACK(int) vboxDispMpTstThreadProc(RTTHREAD ThreadSelf, void *pvUser)
|
---|
38 | {
|
---|
39 | VBOXDISPMP_REGIONS Regions;
|
---|
40 |
|
---|
41 | HRESULT hr = g_VBoxDispMpTstCallbacks.pfnEnableEvents();
|
---|
42 | Assert(hr == S_OK);
|
---|
43 | if (hr != S_OK)
|
---|
44 | return VERR_GENERAL_FAILURE;
|
---|
45 |
|
---|
46 | do
|
---|
47 | {
|
---|
48 | hr = g_VBoxDispMpTstCallbacks.pfnGetRegions(&Regions, INFINITE);
|
---|
49 | Assert(hr == S_OK);
|
---|
50 | if (hr == S_OK)
|
---|
51 | {
|
---|
52 | vboxVDbgPrint(("\n>>>\n"));
|
---|
53 | HWND hWnd = Regions.hWnd;
|
---|
54 | if (Regions.pRegions->fFlags.bSetVisibleRects)
|
---|
55 | {
|
---|
56 | uint32_t iVisibleRects = 0;
|
---|
57 | uint32_t cVisibleRects = Regions.pRegions->RectsInfo.cRects;
|
---|
58 | if (Regions.pRegions->fFlags.bSetViewRect)
|
---|
59 | {
|
---|
60 | iVisibleRects = 1;
|
---|
61 |
|
---|
62 | vboxVDbgPrint(("hWnd (0x%p), position and/or size changed: ", hWnd));
|
---|
63 | vboxDispMpTstLogRect("", Regions.pRegions->RectsInfo.aRects, "\n");
|
---|
64 | }
|
---|
65 |
|
---|
66 | vboxVDbgPrint(("hWnd (0x%p), visibleRects: \n", hWnd));
|
---|
67 | for (uint32_t i = iVisibleRects; i < cVisibleRects; ++i)
|
---|
68 | {
|
---|
69 | vboxDispMpTstLogRect("", &Regions.pRegions->RectsInfo.aRects[i], "");
|
---|
70 | }
|
---|
71 | }
|
---|
72 | else if (Regions.pRegions->fFlags.bAddHiddenRects)
|
---|
73 | {
|
---|
74 | vboxVDbgPrint(("hWnd (0x%p), hiddenRects: \n", hWnd));
|
---|
75 | for (uint32_t i = 0; i < Regions.pRegions->RectsInfo.cRects; ++i)
|
---|
76 | {
|
---|
77 | vboxDispMpTstLogRect("", &Regions.pRegions->RectsInfo.aRects[i], "");
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | vboxVDbgPrint(("\n<<<\n"));
|
---|
82 | }
|
---|
83 | } while (1);
|
---|
84 |
|
---|
85 | hr = g_VBoxDispMpTstCallbacks.pfnDisableEvents();
|
---|
86 | Assert(hr == S_OK);
|
---|
87 |
|
---|
88 | return VINF_SUCCESS;
|
---|
89 | }
|
---|
90 |
|
---|
91 | HRESULT vboxDispMpTstStart()
|
---|
92 | {
|
---|
93 | HRESULT hr = E_FAIL;
|
---|
94 | g_hVBoxDispMpModule = GetModuleHandleW(L"VBoxDispD3D.dll");
|
---|
95 | Assert(g_hVBoxDispMpModule);
|
---|
96 |
|
---|
97 | if (g_hVBoxDispMpModule)
|
---|
98 | {
|
---|
99 | g_pfnVBoxDispMpGetCallbacks = (PFNVBOXDISPMP_GETCALLBACKS)GetProcAddress(g_hVBoxDispMpModule, "VBoxDispMpGetCallbacks");
|
---|
100 | Assert(g_pfnVBoxDispMpGetCallbacks);
|
---|
101 | if (g_pfnVBoxDispMpGetCallbacks)
|
---|
102 | {
|
---|
103 | hr = g_pfnVBoxDispMpGetCallbacks(VBOXDISPMP_VERSION, &g_VBoxDispMpTstCallbacks);
|
---|
104 | Assert(hr == S_OK);
|
---|
105 | if (hr == S_OK)
|
---|
106 | {
|
---|
107 | int rc = RTThreadCreate(&g_VBoxDispMpTstThread, vboxDispMpTstThreadProc, NULL, 0,
|
---|
108 | RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VBoxDispMpTst");
|
---|
109 | AssertRC(rc);
|
---|
110 | if (RT_SUCCESS(rc))
|
---|
111 | return S_OK;
|
---|
112 |
|
---|
113 | hr = E_FAIL;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | FreeLibrary(g_hVBoxDispMpModule);
|
---|
117 | }
|
---|
118 |
|
---|
119 | return hr;
|
---|
120 | }
|
---|
121 |
|
---|
122 | HRESULT vboxDispMpTstStop()
|
---|
123 | {
|
---|
124 | HRESULT hr = g_VBoxDispMpTstCallbacks.pfnDisableEvents();
|
---|
125 | Assert(hr == S_OK);
|
---|
126 | #if 0
|
---|
127 | if (hr == S_OK)
|
---|
128 | {
|
---|
129 | int rc = RTThreadWaitNoResume(g_VBoxDispMpTstThread, RT_INDEFINITE_WAIT, NULL);
|
---|
130 | AssertRC(rc);
|
---|
131 | if (RT_SUCCESS(rc))
|
---|
132 | {
|
---|
133 | BOOL bResult = FreeLibrary(g_hVBoxDispMpModule);
|
---|
134 | Assert(bResult);
|
---|
135 | #ifdef DEBUG
|
---|
136 | if (!bResult)
|
---|
137 | {
|
---|
138 | DWORD winEr = GetLastError();
|
---|
139 | hr = HRESULT_FROM_WIN32(winEr);
|
---|
140 | }
|
---|
141 | #endif
|
---|
142 | }
|
---|
143 | else
|
---|
144 | hr = E_FAIL;
|
---|
145 | }
|
---|
146 | #endif
|
---|
147 | return hr;
|
---|
148 | }
|
---|
149 |
|
---|
150 | #ifdef VBOXWDDM_TEST_UHGSMI
|
---|
151 | int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs)
|
---|
152 | {
|
---|
153 | PVBOXUHGSMI_BUFFER pBuf;
|
---|
154 | int rc = pUhgsmi->pfnBufferCreate(pUhgsmi, cbBuf, VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT, NULL, &pBuf);
|
---|
155 | AssertRC(rc);
|
---|
156 | if (RT_SUCCESS(rc))
|
---|
157 | {
|
---|
158 | uint64_t TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI();
|
---|
159 | do
|
---|
160 | {
|
---|
161 | VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags;
|
---|
162 | fFlags.Value = 0;
|
---|
163 | fFlags.bLockEntire = 1;
|
---|
164 | fFlags.bDiscard = 1;
|
---|
165 |
|
---|
166 | void *pvLock;
|
---|
167 | rc = pBuf->pfnLock(pBuf, 0, cbBuf, fFlags, &pvLock);
|
---|
168 | AssertRC(rc);
|
---|
169 | if (!RT_SUCCESS(rc))
|
---|
170 | break;
|
---|
171 |
|
---|
172 | rc = pBuf->pfnUnlock(pBuf);
|
---|
173 | AssertRC(rc);
|
---|
174 | if (!RT_SUCCESS(rc))
|
---|
175 | break;
|
---|
176 |
|
---|
177 | VBOXUHGSMI_BUFFER_SUBMIT SubmitData;
|
---|
178 | SubmitData.pBuf = pBuf;
|
---|
179 | SubmitData.fFlags.Value = 0;
|
---|
180 | SubmitData.fFlags.bDoNotRetire = 1;
|
---|
181 | SubmitData.fFlags.bEntireBuffer = 1;
|
---|
182 |
|
---|
183 | rc = pUhgsmi->pfnBufferSubmitAsynch(pUhgsmi, &SubmitData, 1);
|
---|
184 | AssertRC(rc);
|
---|
185 | if (!RT_SUCCESS(rc))
|
---|
186 | break;
|
---|
187 |
|
---|
188 | DWORD dw = WaitForSingleObject(pBuf->hSynch, INFINITE);
|
---|
189 | Assert(dw == WAIT_OBJECT_0);
|
---|
190 | if (dw)
|
---|
191 | break;
|
---|
192 | } while (--cNumCals);
|
---|
193 |
|
---|
194 | TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI() - TimeMs;
|
---|
195 | *pTimeMs = TimeMs;
|
---|
196 |
|
---|
197 | pBuf->pfnDestroy(pBuf);
|
---|
198 | }
|
---|
199 | return rc;
|
---|
200 | }
|
---|
201 | #endif
|
---|