Changeset 38363 in vbox for trunk/src/VBox/Additions/WINNT/Graphics/Video
- Timestamp:
- Aug 8, 2011 7:01:30 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 73385
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
r38112 r38363 1767 1767 pSwapchain->pSwapChainIf->Release(); 1768 1768 Assert(pSwapchain->hWnd); 1769 HRESULT hr = VBoxDispWndDestroy(pDevice->pAdapter, pSwapchain->hWnd);1770 Assert(hr == S_OK);1771 1769 pSwapchain->pSwapChainIf = NULL; 1772 1770 pSwapchain->hWnd = NULL; 1773 return hr;1771 return S_OK; 1774 1772 } 1775 1773 … … 2297 2295 { 2298 2296 //#define VBOXDISP_NEWWND_ON_SWAPCHAINUPDATE 2299 #ifndef VBOXDISP_NEWWND_ON_SWAPCHAINUPDATE2300 if (!hOldWnd)2301 #endif2302 {2303 hr = VBoxDispWndCreate(pAdapter, Params.BackBufferWidth, Params.BackBufferHeight, &pSwapchain->hWnd);2304 Assert(hr == S_OK);2305 }2306 2297 if (hr == S_OK) 2307 2298 { 2308 2299 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; 2309 if (pDevice->fFlags.AllowMultithreading)2310 fFlags |= D3DCREATE_MULTITHREADED;2311 2312 Params.hDeviceWindow = pSwapchain->hWnd;2300 // if (pDevice->fFlags.AllowMultithreading) 2301 // fFlags |= D3DCREATE_MULTITHREADED; 2302 2303 Params.hDeviceWindow = NULL; 2313 2304 /* @todo: it seems there should be a way to detect this correctly since 2314 2305 * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */ … … 2321 2312 if (!pDevice->pDevice9If) 2322 2313 { 2323 hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pSwapchain->hWnd, fFlags, &Params, &pDevice9If);2314 hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags, &Params, &pDevice9If); 2324 2315 Assert(hr == S_OK); 2325 2316 if (hr == S_OK) 2326 2317 { 2318 Assert(Params.hDeviceWindow); 2319 pSwapchain->hWnd = Params.hDeviceWindow; 2327 2320 pDevice->pDevice9If = pDevice9If; 2328 2321 hr = pDevice9If->GetSwapChain(0, &pNewIf); … … 2410 2403 if (hr == S_OK) 2411 2404 { 2405 Assert(Params.hDeviceWindow); 2406 pSwapchain->hWnd = Params.hDeviceWindow; 2412 2407 Assert(pNewIf); 2413 2408 } … … 2496 2491 Assert(hOldWnd); 2497 2492 pOldIf->Release(); 2498 if (hOldWnd != pSwapchain->hWnd)2499 {2500 VBoxDispWndDestroy(pAdapter, hOldWnd);2501 }2502 2493 } 2503 2494 else … … 2513 2504 2514 2505 Assert(hr != S_OK); 2515 if (hOldWnd != pSwapchain->hWnd) 2516 { 2517 HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pSwapchain->hWnd); 2518 Assert(tmpHr == S_OK); 2519 pSwapchain->hWnd = hOldWnd; 2520 } 2506 pSwapchain->hWnd = hOldWnd; 2521 2507 } 2522 2508 … … 5326 5312 if (VBOXDISPMODE_IS_3D(pAdapter)) 5327 5313 { 5328 // if (pRc->RcDesc.fFlags.RenderTarget)5329 // {5330 // Assert(pDevice->hWnd);5331 // Assert(pDevice->pDevice9If);5332 // }5333 5334 5314 for (UINT i = 0; i < pRc->cAllocations; ++i) 5335 5315 { … … 5498 5478 } 5499 5479 #endif 5500 #if 15501 5480 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource; 5502 5481 Assert(pRc); … … 5505 5484 hr = vboxWddmSwapchainPresent(pDevice, pAlloc); 5506 5485 Assert(hr == S_OK); 5507 #else 5508 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource; 5509 Assert(pRc); 5510 PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[pRc->RcDesc.VidPnSourceId]; 5511 Assert(pScreen->hWnd); 5512 Assert(pScreen->pDevice9If); 5513 Assert(pRc == pScreen->pRenderTargetRc); 5514 #if 1 5515 VBOXVDBG_RTGT_STATECHECK(pDevice); 5516 5517 if (pRc->RcDesc.VidPnSourceId != pDevice->iPrimaryScreen) 5518 { 5519 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex]; 5520 PVBOXWDDMDISP_SCREEN pPrimaryScreen = &pDevice->aScreens[pDevice->iPrimaryScreen]; 5521 Assert(pPrimaryScreen->pDevice9If); 5522 IDirect3DSurface9 *pSecondaryRt; 5523 Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE); 5524 IDirect3DSurface9 *pDataRt = (IDirect3DSurface9*)pAlloc->pSecondaryOpenedD3DIf; 5525 Assert(pDataRt); 5526 hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9Flush((IDirect3DDevice9Ex*)pPrimaryScreen->pDevice9If); 5527 Assert(hr == S_OK); 5528 if (hr == S_OK) 5529 { 5530 hr = pScreen->pDevice9If->GetRenderTarget(0, &pSecondaryRt); 5531 Assert(hr == S_OK); 5532 if (hr == S_OK) 5533 { 5534 hr = pScreen->pDevice9If->StretchRect(pDataRt, 5535 NULL, 5536 pSecondaryRt, 5537 NULL, 5538 D3DTEXF_NONE); 5539 pSecondaryRt->Release(); 5540 } 5541 } 5542 } 5543 5544 hr = pScreen->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */ 5545 NULL, /* CONST RECT * pDestRect */ 5546 NULL, /* HWND hDestWindowOverride */ 5547 NULL /*CONST RGNDATA * pDirtyRegion */ 5548 ); 5549 Assert(hr == S_OK); 5550 #endif 5551 #endif 5552 } 5553 #if 0 5554 else 5555 #endif 5556 { 5557 // if (pData->Flags.Flip) 5558 // { 5559 // Assert(pData->hSrcResource); 5560 // PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource; 5561 // PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[pRc->RcDesc.VidPnSourceId]; 5562 // Assert(pScreen->hWnd); 5563 // Assert(pScreen->pDevice9If); 5564 // Assert(pScreen->pRenderTargetRc == pRc); 5565 // Assert(pRc->cAllocations >= 2); 5566 // Assert(pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE); 5567 // Assert(pRc->RcDesc.fFlags.RenderTarget); 5568 // uint32_t iNewRTFB = (pScreen->iRenderTargetFrontBuf + 1) % pRc->cAllocations; 5569 // 5570 // Assert(pScreen->iRenderTargetFrontBuf != iNewRTFB); 5571 // Assert(pData->SrcSubResourceIndex == iNewRTFB); 5572 // 5573 // vboxWddmRenderTargetUpdate(pDevice, pRc, iNewRTFB); 5574 // 5575 // /* assign a new frontbuffer index */ 5576 // pScreen->iRenderTargetFrontBuf = iNewRTFB; 5577 // 5578 // VBOXVDBG_RTGT_STATECHECK(pDevice); 5579 // } 5486 } 5487 5488 { 5580 5489 D3DDDICB_PRESENT DdiPresent = {0}; 5581 5490 if (pData->hSrcResource) … … 5596 5505 } 5597 5506 DdiPresent.hContext = pDevice->DefaultContext.ContextInfo.hContext; 5598 // DdiPresent.BroadcastContextCount;5599 // DdiPresent.BroadcastContext[D3DDDI_MAX_BROADCAST_CONTEXT];5600 5507 5601 5508 hr = pDevice->RtCallbacks.pfnPresentCb(pDevice->hDevice, &DdiPresent); … … 7215 7122 { 7216 7123 VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL(); 7217 HRESULT hr = VBoxDispWorkerDestroy(&pAdapter->WndWorker);7218 Assert(hr == S_OK);7219 7124 pAdapter->pD3D9If->Release(); 7220 7125 VBoxDispD3DClose(&pAdapter->D3D); … … 7329 7234 Assert(pAdapter->cMaxSimRTs); 7330 7235 Assert(pAdapter->cMaxSimRTs < UINT32_MAX/2); 7331 hr = VBoxDispWorkerCreate(&pAdapter->WndWorker); 7332 Assert(hr == S_OK); 7333 if (hr == S_OK) 7334 { 7335 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter)); 7336 break; 7337 } 7236 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter)); 7237 break; 7338 7238 } 7339 7239 pAdapter->pD3D9If->Release(); -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h
r38112 r38363 56 56 UINT uRtVersion; 57 57 VBOXDISPD3D D3D; 58 VBOXDISPWORKER WndWorker;59 58 IDirect3D9Ex * pD3D9If; 60 59 D3DDDI_ADAPTERCALLBACKS RtCallbacks; … … 148 147 #endif 149 148 IDirect3DSwapChain9 *pSwapChainIf; 149 /* a read-only hWnd we receive from wine 150 * we use it for visible region notifications only, 151 * it MUST NOT be destroyed on swapchain destruction, 152 * wine will handle that for us */ 150 153 HWND hWnd; 151 154 VBOXDISP_KMHANDLE hSwapchainKm; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
r38112 r38363 81 81 return E_FAIL; 82 82 } 83 84 #define WM_VBOXDISP_CALLPROC (WM_APP+1)85 86 typedef struct VBOXDISP_CALLPROC87 {88 PFNVBOXDISPWORKERCB pfnCb;89 void *pvCb;90 } VBOXDISP_CALLPROC;91 92 static DWORD WINAPI vboxDispWorkerThread(void *pvUser)93 {94 VBOXDISPWORKER *pWorker = (VBOXDISPWORKER*)pvUser;95 MSG Msg;96 97 PeekMessage(&Msg,98 NULL /* HWND hWnd */,99 WM_USER /* UINT wMsgFilterMin */,100 WM_USER /* UINT wMsgFilterMax */,101 PM_NOREMOVE);102 RTSemEventSignal(pWorker->hEvent);103 104 do105 {106 BOOL bResult = GetMessage(&Msg,107 0 /*HWND hWnd*/,108 0 /*UINT wMsgFilterMin*/,109 0 /*UINT wMsgFilterMax*/110 );111 112 if(!bResult) /* WM_QUIT was posted */113 break;114 115 Assert(bResult != -1);116 if(bResult == -1) /* error occurred */117 break;118 119 switch (Msg.message)120 {121 case WM_VBOXDISP_CALLPROC:122 {123 VBOXDISP_CALLPROC* pData = (VBOXDISP_CALLPROC*)Msg.lParam;124 pData->pfnCb(pData->pvCb);125 RTSemEventSignal(pWorker->hEvent);126 break;127 }128 default:129 TranslateMessage(&Msg);130 DispatchMessage(&Msg);131 }132 } while (1);133 return 0;134 }135 136 static int vboxDispWorkerSubmit(VBOXDISPWORKER *pWorker, UINT Msg, LPARAM lParam)137 {138 /* need to serialize since vboxDispWorkerThread is using one pWorker->hEvent139 * to signal job completion */140 int rc = RTCritSectEnter(&pWorker->CritSect);141 AssertRC(rc);142 if (RT_SUCCESS(rc))143 {144 BOOL bResult = PostThreadMessage(pWorker->idThread, Msg, 0, lParam);145 Assert(bResult);146 if (bResult)147 {148 rc = RTSemEventWait(pWorker->hEvent, RT_INDEFINITE_WAIT);149 AssertRC(rc);150 }151 else152 rc = VERR_GENERAL_FAILURE;153 154 int tmpRc = RTCritSectLeave(&pWorker->CritSect);155 AssertRC(tmpRc);156 }157 return rc;158 }159 160 HRESULT VBoxDispWorkerSubmitProc(VBOXDISPWORKER *pWorker, PFNVBOXDISPWORKERCB pfnCb, void *pvCb)161 {162 VBOXDISP_CALLPROC Ctx;163 Ctx.pfnCb = pfnCb;164 Ctx.pvCb = pvCb;165 int rc = vboxDispWorkerSubmit(pWorker, WM_VBOXDISP_CALLPROC, (LPARAM)&Ctx);166 AssertRC(rc);167 return RT_SUCCESS(rc) ? S_OK : E_FAIL;168 }169 170 HRESULT VBoxDispWorkerCreate(VBOXDISPWORKER *pWorker)171 {172 int rc = RTCritSectInit(&pWorker->CritSect);173 AssertRC(rc);174 if (RT_SUCCESS(rc))175 {176 rc = RTSemEventCreate(&pWorker->hEvent);177 AssertRC(rc);178 if (RT_SUCCESS(rc))179 {180 pWorker->hThread = CreateThread(181 NULL /* LPSECURITY_ATTRIBUTES lpThreadAttributes */,182 0 /* SIZE_T dwStackSize */,183 vboxDispWorkerThread,184 pWorker,185 0 /* DWORD dwCreationFlags */,186 &pWorker->idThread);187 Assert(pWorker->hThread);188 if (pWorker->hThread)189 {190 rc = RTSemEventWait(pWorker->hEvent, RT_INDEFINITE_WAIT);191 AssertRC(rc);192 if (RT_SUCCESS(rc))193 return S_OK;194 /* destroy thread ? */195 }196 else197 {198 DWORD winErr = GetLastError();199 vboxVDbgPrintR((__FUNCTION__": CreateThread failed, winErr = (%d)", winErr));200 rc = VERR_GENERAL_FAILURE;201 }202 int tmpRc = RTSemEventDestroy(pWorker->hEvent);203 AssertRC(tmpRc);204 }205 int tmpRc = RTCritSectDelete(&pWorker->CritSect);206 AssertRC(tmpRc);207 }208 return E_FAIL;209 }210 211 HRESULT VBoxDispWorkerDestroy(VBOXDISPWORKER *pWorker)212 {213 int rc = VINF_SUCCESS;214 BOOL bResult = PostThreadMessage(pWorker->idThread, WM_QUIT, 0, 0);215 Assert(bResult);216 if (bResult)217 {218 DWORD dwErr = WaitForSingleObject(pWorker->hThread, INFINITE);219 Assert(dwErr == WAIT_OBJECT_0);220 if (dwErr == WAIT_OBJECT_0)221 {222 rc = RTSemEventDestroy(pWorker->hEvent);223 AssertRC(rc);224 if (RT_SUCCESS(rc))225 {226 rc = RTCritSectDelete(&pWorker->CritSect);227 AssertRC(rc);228 }229 }230 else231 rc = VERR_GENERAL_FAILURE;232 }233 else234 rc = VERR_GENERAL_FAILURE;235 236 return RT_SUCCESS(rc) ? S_OK : E_FAIL;237 }238 239 static LRESULT CALLBACK WindowProc(HWND hwnd,240 UINT uMsg,241 WPARAM wParam,242 LPARAM lParam243 )244 {245 switch(uMsg)246 {247 case WM_CLOSE:248 vboxVDbgPrint((__FUNCTION__": got WM_CLOSE for hwnd(0x%x)", hwnd));249 return 0;250 case WM_DESTROY:251 vboxVDbgPrint((__FUNCTION__": got WM_DESTROY for hwnd(0x%x)", hwnd));252 return 0;253 case WM_NCHITTEST:254 vboxVDbgPrint((__FUNCTION__": got WM_NCHITTEST for hwnd(0x%x)\n", hwnd));255 return HTNOWHERE;256 }257 258 return DefWindowProc(hwnd, uMsg, wParam, lParam);259 }260 261 #define VBOXDISPWND_NAME L"VboxDispD3DWindow"262 263 HRESULT vboxDispWndDoCreate(DWORD w, DWORD h, HWND *phWnd)264 {265 HRESULT hr = S_OK;266 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);267 /* Register the Window Class. */268 WNDCLASS wc;269 if (!GetClassInfo(hInstance, VBOXDISPWND_NAME, &wc))270 {271 wc.style = 0;//CS_OWNDC;272 wc.lpfnWndProc = WindowProc;273 wc.cbClsExtra = 0;274 wc.cbWndExtra = 0;275 wc.hInstance = hInstance;276 wc.hIcon = NULL;277 wc.hCursor = NULL;278 wc.hbrBackground = NULL;279 wc.lpszMenuName = NULL;280 wc.lpszClassName = VBOXDISPWND_NAME;281 if (!RegisterClass(&wc))282 {283 DWORD winErr = GetLastError();284 vboxVDbgPrint((__FUNCTION__": RegisterClass failed, winErr(%d)\n", winErr));285 hr = E_FAIL;286 }287 }288 289 if (hr == S_OK)290 {291 HWND hWnd = CreateWindowEx (WS_EX_TOOLWINDOW,292 VBOXDISPWND_NAME, VBOXDISPWND_NAME,293 WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED,294 0, 0,295 w, h,296 NULL, //GetDesktopWindow() /* hWndParent */,297 NULL /* hMenu */,298 hInstance,299 NULL /* lpParam */);300 Assert(hWnd);301 if (hWnd)302 {303 *phWnd = hWnd;304 }305 else306 {307 DWORD winErr = GetLastError();308 vboxVDbgPrint((__FUNCTION__": CreateWindowEx failed, winErr(%d)\n", winErr));309 hr = E_FAIL;310 }311 }312 313 return hr;314 }315 316 static HRESULT vboxDispWndDoDestroy(HWND hWnd)317 {318 BOOL bResult = DestroyWindow(hWnd);319 Assert(bResult);320 if (bResult)321 return S_OK;322 323 DWORD winErr = GetLastError();324 vboxVDbgPrint((__FUNCTION__": DestroyWindow failed, winErr(%d) for hWnd(0x%x)\n", winErr, hWnd));325 326 return E_FAIL;327 }328 329 typedef struct VBOXDISPWND_CREATE_INFO330 {331 int hr;332 HWND hWnd;333 DWORD width;334 DWORD height;335 } VBOXDISPWND_CREATE_INFO;336 337 typedef struct VBOXDISPWND_DESTROY_INFO338 {339 int hr;340 HWND hWnd;341 } VBOXDISPWND_DESTROY_INFO;342 343 DECLCALLBACK(void) vboxDispWndDestroyWorker(void *pvUser)344 {345 VBOXDISPWND_DESTROY_INFO *pInfo = (VBOXDISPWND_DESTROY_INFO*)pvUser;346 pInfo->hr = vboxDispWndDoDestroy(pInfo->hWnd);347 Assert(pInfo->hr == S_OK);348 }349 350 DECLCALLBACK(void) vboxDispWndCreateWorker(void *pvUser)351 {352 VBOXDISPWND_CREATE_INFO *pInfo = (VBOXDISPWND_CREATE_INFO*)pvUser;353 pInfo->hr = vboxDispWndDoCreate(pInfo->width, pInfo->height, &pInfo->hWnd);354 Assert(pInfo->hr == S_OK);355 }356 357 358 HRESULT VBoxDispWndDestroy(PVBOXWDDMDISP_ADAPTER pAdapter, HWND hWnd)359 {360 VBOXDISPWND_DESTROY_INFO Info;361 Info.hr = E_FAIL;362 Info.hWnd = hWnd;363 HRESULT hr = VBoxDispWorkerSubmitProc(&pAdapter->WndWorker, vboxDispWndDestroyWorker, &Info);364 Assert(hr == S_OK);365 if (hr == S_OK)366 {367 Assert(Info.hr == S_OK);368 return Info.hr;369 }370 return hr;371 }372 373 HRESULT VBoxDispWndCreate(PVBOXWDDMDISP_ADAPTER pAdapter, DWORD width, DWORD height, HWND *phWnd)374 {375 VBOXDISPWND_CREATE_INFO Info;376 Info.hr = E_FAIL;377 Info.width = width;378 Info.height = height;379 HRESULT hr = VBoxDispWorkerSubmitProc(&pAdapter->WndWorker, vboxDispWndCreateWorker, &Info);380 Assert(hr == S_OK);381 if (hr == S_OK)382 {383 Assert(Info.hr == S_OK);384 if (Info.hr == S_OK)385 *phWnd = Info.hWnd;386 return Info.hr;387 }388 return hr;389 } -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h
r36867 r38363 53 53 void VBoxDispD3DClose(VBOXDISPD3D *pD3D); 54 54 55 56 typedef struct VBOXDISPWORKER57 {58 RTCRITSECT CritSect;59 60 RTSEMEVENT hEvent;61 62 HANDLE hThread;63 DWORD idThread;64 } VBOXDISPWORKER;65 66 HRESULT VBoxDispWorkerCreate(VBOXDISPWORKER *pWorker);67 HRESULT VBoxDispWorkerDestroy(VBOXDISPWORKER *pWorker);68 69 typedef DECLCALLBACK(void) FNVBOXDISPWORKERCB(void *pvUser);70 typedef FNVBOXDISPWORKERCB *PFNVBOXDISPWORKERCB;71 72 HRESULT VBoxDispWorkerSubmitProc(VBOXDISPWORKER *pWorker, PFNVBOXDISPWORKERCB pfnCb, void *pvCb);73 74 typedef struct VBOXWDDMDISP_ADAPTER *PVBOXWDDMDISP_ADAPTER;75 76 HRESULT VBoxDispWndDestroy(PVBOXWDDMDISP_ADAPTER pAdapter, HWND hWnd);77 HRESULT VBoxDispWndCreate(PVBOXWDDMDISP_ADAPTER pAdapter, DWORD width, DWORD height, HWND *phWnd);78 79 55 #endif /* ifndef ___VBoxDispD3DIf_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.