VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpTst.cpp@ 46606

Last change on this file since 46606 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: VBoxDispMpTst.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011-2012 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 "VBoxDispD3DCmn.h"
20#include "VBoxDispMp.h"
21
22#include <iprt/thread.h>
23#include <iprt/err.h>
24
25#ifdef VBOXWDDM_TEST_UHGSMI
26#include "VBoxDispProfile.h"
27#endif
28
29static RTTHREAD g_VBoxDispMpTstThread;
30static VBOXDISPMP_CALLBACKS g_VBoxDispMpTstCallbacks;
31static HMODULE g_hVBoxDispMpModule;
32static PFNVBOXDISPMP_GETCALLBACKS g_pfnVBoxDispMpGetCallbacks;
33
34
35static void vboxDispMpTstLogRect(const char * pPrefix, RECT *pRect, const char * pSuffix)
36{
37 vboxVDbgPrint(("%s left(%d), top(%d), right(%d), bottom(%d) %s", pPrefix, pRect->left, pRect->top, pRect->right, pRect->bottom, pSuffix));
38}
39
40static DECLCALLBACK(int) vboxDispMpTstThreadProc(RTTHREAD ThreadSelf, void *pvUser)
41{
42 VBOXDISPMP_REGIONS Regions;
43
44 HRESULT hr = g_VBoxDispMpTstCallbacks.pfnEnableEvents();
45 Assert(hr == S_OK);
46 if (hr != S_OK)
47 return VERR_GENERAL_FAILURE;
48
49 do
50 {
51 hr = g_VBoxDispMpTstCallbacks.pfnGetRegions(&Regions, INFINITE);
52 Assert(hr == S_OK);
53 if (hr == S_OK)
54 {
55 vboxVDbgPrint(("\n>>>\n"));
56 HWND hWnd = Regions.hWnd;
57 if (Regions.pRegions->fFlags.bAddVisibleRects)
58 {
59 uint32_t iVisibleRects = 0;
60 uint32_t cVisibleRects = Regions.pRegions->RectsInfo.cRects;
61 if (Regions.pRegions->fFlags.bSetViewRect)
62 {
63 iVisibleRects = 1;
64
65 vboxVDbgPrint(("hWnd (0x%p), position and/or size changed: ", hWnd));
66 vboxDispMpTstLogRect("", Regions.pRegions->RectsInfo.aRects, "\n");
67 }
68
69 vboxVDbgPrint(("hWnd (0x%p), visibleRects: \n", hWnd));
70 for (uint32_t i = iVisibleRects; i < cVisibleRects; ++i)
71 {
72 vboxDispMpTstLogRect("", &Regions.pRegions->RectsInfo.aRects[i], "");
73 }
74 }
75 else if (Regions.pRegions->fFlags.bAddHiddenRects)
76 {
77 vboxVDbgPrint(("hWnd (0x%p), hiddenRects: \n", hWnd));
78 for (uint32_t i = 0; i < Regions.pRegions->RectsInfo.cRects; ++i)
79 {
80 vboxDispMpTstLogRect("", &Regions.pRegions->RectsInfo.aRects[i], "");
81 }
82 }
83
84 vboxVDbgPrint(("\n<<<\n"));
85 }
86 } while (1);
87
88 hr = g_VBoxDispMpTstCallbacks.pfnDisableEvents();
89 Assert(hr == S_OK);
90
91 return VINF_SUCCESS;
92}
93
94HRESULT vboxDispMpTstStart()
95{
96 HRESULT hr = E_FAIL;
97 g_hVBoxDispMpModule = GetModuleHandleW(L"VBoxDispD3D.dll");
98 Assert(g_hVBoxDispMpModule);
99
100 if (g_hVBoxDispMpModule)
101 {
102 g_pfnVBoxDispMpGetCallbacks = (PFNVBOXDISPMP_GETCALLBACKS)GetProcAddress(g_hVBoxDispMpModule, "VBoxDispMpGetCallbacks");
103 Assert(g_pfnVBoxDispMpGetCallbacks);
104 if (g_pfnVBoxDispMpGetCallbacks)
105 {
106 hr = g_pfnVBoxDispMpGetCallbacks(VBOXDISPMP_VERSION, &g_VBoxDispMpTstCallbacks);
107 Assert(hr == S_OK);
108 if (hr == S_OK)
109 {
110 int rc = RTThreadCreate(&g_VBoxDispMpTstThread, vboxDispMpTstThreadProc, NULL, 0,
111 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VBoxDispMpTst");
112 AssertRC(rc);
113 if (RT_SUCCESS(rc))
114 return S_OK;
115
116 hr = E_FAIL;
117 }
118 }
119 FreeLibrary(g_hVBoxDispMpModule);
120 }
121
122 return hr;
123}
124
125HRESULT vboxDispMpTstStop()
126{
127 HRESULT hr = g_VBoxDispMpTstCallbacks.pfnDisableEvents();
128 Assert(hr == S_OK);
129#if 0
130 if (hr == S_OK)
131 {
132 int rc = RTThreadWaitNoResume(g_VBoxDispMpTstThread, RT_INDEFINITE_WAIT, NULL);
133 AssertRC(rc);
134 if (RT_SUCCESS(rc))
135 {
136 BOOL bResult = FreeLibrary(g_hVBoxDispMpModule);
137 Assert(bResult);
138#ifdef DEBUG
139 if (!bResult)
140 {
141 DWORD winEr = GetLastError();
142 hr = HRESULT_FROM_WIN32(winEr);
143 }
144#endif
145 }
146 else
147 hr = E_FAIL;
148 }
149#endif
150 return hr;
151}
152
153#ifdef VBOXWDDM_TEST_UHGSMI
154int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs)
155{
156 PVBOXUHGSMI_BUFFER pBuf;
157 int rc = pUhgsmi->pfnBufferCreate(pUhgsmi, cbBuf, VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT, NULL, &pBuf);
158 AssertRC(rc);
159 if (RT_SUCCESS(rc))
160 {
161 uint64_t TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI();
162 do
163 {
164 VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags;
165 fFlags.Value = 0;
166 fFlags.bLockEntire = 1;
167 fFlags.bDiscard = 1;
168
169 void *pvLock;
170 rc = pBuf->pfnLock(pBuf, 0, cbBuf, fFlags, &pvLock);
171 AssertRC(rc);
172 if (!RT_SUCCESS(rc))
173 break;
174
175 rc = pBuf->pfnUnlock(pBuf);
176 AssertRC(rc);
177 if (!RT_SUCCESS(rc))
178 break;
179
180 VBOXUHGSMI_BUFFER_SUBMIT SubmitData;
181 SubmitData.pBuf = pBuf;
182 SubmitData.fFlags.Value = 0;
183 SubmitData.fFlags.bDoNotRetire = 1;
184 SubmitData.fFlags.bEntireBuffer = 1;
185
186 rc = pUhgsmi->pfnBufferSubmitAsynch(pUhgsmi, &SubmitData, 1);
187 AssertRC(rc);
188 if (!RT_SUCCESS(rc))
189 break;
190
191 DWORD dw = WaitForSingleObject(pBuf->hSynch, INFINITE);
192 Assert(dw == WAIT_OBJECT_0);
193 if (dw)
194 break;
195 } while (--cNumCals);
196
197 TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI() - TimeMs;
198 *pTimeMs = TimeMs;
199
200 pBuf->pfnDestroy(pBuf);
201 }
202 return rc;
203}
204#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette