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