Changeset 30038 in vbox
- Timestamp:
- Jun 4, 2010 3:15:24 PM (15 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
r30003 r30038 854 854 } 855 855 return NULL; 856 } 857 858 static D3DFORMAT vboxFormatDDI2D3D(D3DDDIFORMAT format) 859 { 860 /* @todo: check they are all equal */ 861 return (D3DFORMAT)format; 862 } 863 864 static void vboxResourcePopulateRcDesc(VBOXWDDM_RC_DESC *pDesc, D3DDDIARG_CREATERESOURCE* pResource) 865 { 866 pDesc->fFlags = pResource->Flags; 867 pDesc->enmFormat = pResource->Format; 868 pDesc->enmPool = pResource->Pool; 869 pDesc->enmMultisampleType = pResource->MultisampleType; 870 pDesc->MultisampleQuality = pResource->MultisampleQuality; 871 pDesc->MipLevels = pResource->MipLevels; 872 pDesc->Fvf = pResource->Fvf; 873 pDesc->VidPnSourceId = pResource->VidPnSourceId; 874 pDesc->RefreshRate = pResource->RefreshRate; 875 pDesc->enmRotation = pResource->Rotation; 856 876 } 857 877 … … 1071 1091 if (pData->DataSize >= sizeof (D3DCAPS9)) 1072 1092 { 1073 if ( pAdapter->pD3D9If)1093 if (VBOXDISPMODE_IS_3D(pAdapter)) 1074 1094 { 1075 1095 D3DCAPS9* pCaps = (D3DCAPS9*)pData->pData; … … 1566 1586 Assert(pDevice); 1567 1587 Assert(pResource); 1568 1569 /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */ 1570 uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE); 1571 uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3; 1572 uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount; 1573 cbBuf = offDdiAllocInfos + cbDdiAllocInfos; 1574 uint32_t offRcInfo = (cbBuf + 7) & ~3; 1575 uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO); 1576 cbBuf = offRcInfo + cbRcInfo; 1577 uint32_t offAllocInfos = (cbBuf + 7) & ~3; 1578 uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount; 1579 cbBuf = offAllocInfos + cbAllocInfos; 1580 uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf); 1581 if (pvBuf) 1582 { 1583 D3DDDICB_ALLOCATE *pAllocate = (D3DDDICB_ALLOCATE*)pvBuf; 1584 D3DDDI_ALLOCATIONINFO* pDdiAllocInfos = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos); 1585 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo); 1586 PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos); 1587 pAllocate->pPrivateDriverData = pRcInfo; 1588 pAllocate->PrivateDriverDataSize = cbRcInfo; 1589 pAllocate->hResource = pResource->hResource; 1590 pAllocate->hKMResource = NULL; 1591 pAllocate->NumAllocations = pResource->SurfCount; 1592 pAllocate->pAllocationInfo = pDdiAllocInfos; 1593 1594 pRcInfo->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC; 1595 pRcInfo->RcDesc.fFlags = pResource->Flags; 1596 pRcInfo->RcDesc.enmFormat = pResource->Format; 1597 pRcInfo->RcDesc.enmPool = pResource->Pool; 1598 pRcInfo->RcDesc.enmMultisampleType = pResource->MultisampleType; 1599 pRcInfo->RcDesc.MultisampleQuality = pResource->MultisampleQuality; 1600 pRcInfo->RcDesc.MipLevels = pResource->MipLevels; 1601 pRcInfo->RcDesc.Fvf = pResource->Fvf; 1602 pRcInfo->RcDesc.VidPnSourceId = pResource->VidPnSourceId; 1603 pRcInfo->RcDesc.RefreshRate = pResource->RefreshRate; 1604 pRcInfo->RcDesc.enmRotation = pResource->Rotation; 1605 pRcInfo->cAllocInfos = pResource->SurfCount; 1606 1607 for (UINT i = 0; i < pResource->SurfCount; ++i) 1608 { 1609 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i]; 1610 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i]; 1611 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 1612 pDdiAllocInfo->hAllocation = NULL; 1613 pDdiAllocInfo->pSystemMem = pSurf->pSysMem; 1614 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)); 1615 pDdiAllocInfo->pPrivateDriverData = pAllocInfo; 1616 pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO); 1617 pDdiAllocInfo->VidPnSourceId = pResource->VidPnSourceId; 1618 pDdiAllocInfo->Flags.Value = 0; 1619 if (pResource->Flags.Primary) 1620 pDdiAllocInfo->Flags.Primary = 1; 1621 1622 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 1623 pAllocInfo->SurfDesc.width = pSurf->Width; 1624 pAllocInfo->SurfDesc.height = pSurf->Height; 1625 pAllocInfo->SurfDesc.format = pResource->Format; 1626 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 1627 1628 if (pSurf->SysMemPitch) 1629 { 1630 pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch; 1631 #ifdef DEBUG 1632 UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp); 1633 Assert(tst == pSurf->SysMemPitch); 1634 #endif 1588 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter; 1589 1590 Assert(0); 1591 1592 if (VBOXDISPMODE_IS_3D(pAdapter)) 1593 { 1594 if (pResource->Flags.RenderTarget) 1595 { 1596 HWND hWnd = NULL; 1597 Assert(pResource->SurfCount); 1598 Assert(!pDevice->pDevice9If); 1599 Assert(!pDevice->hWnd); 1600 hr = VBoxDispWndCreate(pAdapter, pResource->pSurfList[0].Width, pResource->pSurfList[0].Height, &hWnd); 1601 Assert(hr == S_OK); 1602 if (hr == S_OK) 1603 { 1604 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; 1605 if (pDevice->fFlags.AllowMultithreading) 1606 fFlags |= D3DCREATE_MULTITHREADED; 1607 1608 IDirect3DDevice9 *pDevice9If = NULL; 1609 D3DPRESENT_PARAMETERS params; 1610 memset(¶ms, 0, sizeof (params)); 1611 // params.BackBufferWidth = 0; 1612 // params.BackBufferHeight = 0; 1613 params.BackBufferFormat = vboxFormatDDI2D3D(pResource->Format); 1614 Assert(pResource->SurfCount); 1615 params.BackBufferCount = pResource->SurfCount - 1; 1616 params.MultiSampleType = D3DMULTISAMPLE_NONE; 1617 if (pResource->Flags.DiscardRenderTarget) 1618 params.SwapEffect = D3DSWAPEFFECT_DISCARD; 1619 params.hDeviceWindow = hWnd; 1620 /* @todo: it seems there should be a way to detect this correctly since 1621 * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */ 1622 params.Windowed = TRUE; 1623 // params.EnableAutoDepthStencil = FALSE; 1624 // params.AutoDepthStencilFormat = D3DFMT_UNKNOWN; 1625 // params.Flags; 1626 // params.FullScreen_RefreshRateInHz; 1627 // params.FullScreen_PresentationInterval; 1628 hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, fFlags, ¶ms, &pDevice9If); 1629 Assert(hr == S_OK); 1630 if (hr == S_OK) 1631 { 1632 pDevice->pDevice9If = pDevice9If; 1633 pDevice->hWnd = hWnd; 1634 } 1635 else 1636 { 1637 VBoxDispWndDestroy(pAdapter, hWnd); 1638 } 1635 1639 } 1636 else1637 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);1638 1639 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;1640 pAllocInfo->SurfDesc.depth = pSurf->Depth;1641 pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;1642 pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;1643 pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate;1644 1640 } 1645 1646 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pAllocate); 1647 Assert(hr == S_OK); 1641 else 1642 { 1643 Assert(pDevice->pDevice9If); 1644 } 1645 1648 1646 if (hr == S_OK) 1649 1647 { 1650 Assert(pAllocate->hKMResource);1651 1648 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount); 1649 Assert(pRc); 1652 1650 if (pRc) 1653 1651 { 1654 1652 pRc->hResource = pResource->hResource; 1655 pRc->hKMResource = pAllocate->hKMResource;1656 1653 pRc->pDevice = pDevice; 1657 pRc->fFlags = pRcInfo->fFlags;1658 pRc->RcDesc = pRcInfo->RcDesc;1659 pRc->cAllocations = pR cInfo->cAllocInfos;1660 for (UINT i = 0; i < pR cInfo->cAllocInfos; ++i)1654 pRc->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC; 1655 vboxResourcePopulateRcDesc(&pRc->RcDesc, pResource); 1656 pRc->cAllocations = pResource->SurfCount; 1657 for (UINT i = 0; i < pResource->SurfCount; ++i) 1661 1658 { 1662 1659 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 1663 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i];1664 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];1665 1660 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 1666 pAllocation->hAllocation = pDdiAllocInfo->hAllocation;1661 pAllocation->hAllocation = NULL; 1667 1662 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 1668 1663 pAllocation->pvMem = pSurf->pSysMem; 1669 pAllocation->SurfDesc = pAllocInfo->SurfDesc; 1664 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch; 1665 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch; 1666 pAllocation->SurfDesc.depth = pSurf->Depth; 1667 pAllocation->SurfDesc.width = pSurf->Width; 1668 pAllocation->SurfDesc.height = pSurf->Height; 1669 pAllocation->SurfDesc.format = pResource->Format; 1670 1670 } 1671 1671 … … 1678 1678 } 1679 1679 } 1680 1681 RTMemFree(pvBuf);1682 1680 } 1683 1681 else 1684 1682 { 1685 hr = E_OUTOFMEMORY; 1683 /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */ 1684 uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE); 1685 uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3; 1686 uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount; 1687 cbBuf = offDdiAllocInfos + cbDdiAllocInfos; 1688 uint32_t offRcInfo = (cbBuf + 7) & ~3; 1689 uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO); 1690 cbBuf = offRcInfo + cbRcInfo; 1691 uint32_t offAllocInfos = (cbBuf + 7) & ~3; 1692 uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount; 1693 cbBuf = offAllocInfos + cbAllocInfos; 1694 uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf); 1695 if (pvBuf) 1696 { 1697 D3DDDICB_ALLOCATE *pAllocate = (D3DDDICB_ALLOCATE*)pvBuf; 1698 D3DDDI_ALLOCATIONINFO* pDdiAllocInfos = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos); 1699 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo); 1700 PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos); 1701 pAllocate->pPrivateDriverData = pRcInfo; 1702 pAllocate->PrivateDriverDataSize = cbRcInfo; 1703 pAllocate->hResource = pResource->hResource; 1704 pAllocate->hKMResource = NULL; 1705 pAllocate->NumAllocations = pResource->SurfCount; 1706 pAllocate->pAllocationInfo = pDdiAllocInfos; 1707 1708 pRcInfo->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC; 1709 pRcInfo->RcDesc.fFlags = pResource->Flags; 1710 pRcInfo->RcDesc.enmFormat = pResource->Format; 1711 pRcInfo->RcDesc.enmPool = pResource->Pool; 1712 pRcInfo->RcDesc.enmMultisampleType = pResource->MultisampleType; 1713 pRcInfo->RcDesc.MultisampleQuality = pResource->MultisampleQuality; 1714 pRcInfo->RcDesc.MipLevels = pResource->MipLevels; 1715 pRcInfo->RcDesc.Fvf = pResource->Fvf; 1716 pRcInfo->RcDesc.VidPnSourceId = pResource->VidPnSourceId; 1717 pRcInfo->RcDesc.RefreshRate = pResource->RefreshRate; 1718 pRcInfo->RcDesc.enmRotation = pResource->Rotation; 1719 pRcInfo->cAllocInfos = pResource->SurfCount; 1720 1721 for (UINT i = 0; i < pResource->SurfCount; ++i) 1722 { 1723 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i]; 1724 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i]; 1725 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 1726 pDdiAllocInfo->hAllocation = NULL; 1727 pDdiAllocInfo->pSystemMem = pSurf->pSysMem; 1728 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)); 1729 pDdiAllocInfo->pPrivateDriverData = pAllocInfo; 1730 pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO); 1731 pDdiAllocInfo->VidPnSourceId = pResource->VidPnSourceId; 1732 pDdiAllocInfo->Flags.Value = 0; 1733 if (pResource->Flags.Primary) 1734 pDdiAllocInfo->Flags.Primary = 1; 1735 1736 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 1737 pAllocInfo->SurfDesc.width = pSurf->Width; 1738 pAllocInfo->SurfDesc.height = pSurf->Height; 1739 pAllocInfo->SurfDesc.format = pResource->Format; 1740 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format); 1741 1742 if (pSurf->SysMemPitch) 1743 { 1744 pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch; 1745 #ifdef DEBUG 1746 UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp); 1747 Assert(tst == pSurf->SysMemPitch); 1748 #endif 1749 } 1750 else 1751 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp); 1752 1753 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height; 1754 pAllocInfo->SurfDesc.depth = pSurf->Depth; 1755 pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch; 1756 pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId; 1757 pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate; 1758 } 1759 1760 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pAllocate); 1761 Assert(hr == S_OK); 1762 if (hr == S_OK) 1763 { 1764 Assert(pAllocate->hKMResource); 1765 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount); 1766 Assert(pRc); 1767 if (pRc) 1768 { 1769 pRc->hResource = pResource->hResource; 1770 pRc->hKMResource = pAllocate->hKMResource; 1771 pRc->pDevice = pDevice; 1772 pRc->fFlags = pRcInfo->fFlags; 1773 pRc->RcDesc = pRcInfo->RcDesc; 1774 pRc->cAllocations = pRcInfo->cAllocInfos; 1775 for (UINT i = 0; i < pRcInfo->cAllocInfos; ++i) 1776 { 1777 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i]; 1778 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pDdiAllocInfos[i]; 1779 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i]; 1780 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i]; 1781 pAllocation->hAllocation = pDdiAllocInfo->hAllocation; 1782 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; 1783 pAllocation->pvMem = pSurf->pSysMem; 1784 pAllocation->SurfDesc = pAllocInfo->SurfDesc; 1785 } 1786 1787 pResource->hResource = pRc; 1788 // vboxResourceFree(pRc); 1789 } 1790 else 1791 { 1792 hr = E_OUTOFMEMORY; 1793 } 1794 } 1795 1796 RTMemFree(pvBuf); 1797 } 1798 else 1799 { 1800 hr = E_OUTOFMEMORY; 1801 } 1686 1802 } 1687 1803 … … 1694 1810 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice)); 1695 1811 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice; 1812 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter; 1813 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource; 1814 1696 1815 HRESULT hr = S_OK; 1697 1816 1698 1817 Assert(pDevice); 1699 1818 Assert(hResource); 1700 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource; 1701 if (!(pRc->fFlags & VBOXWDDM_RESOURCE_F_OPENNED)) 1702 { 1703 D3DDDICB_DEALLOCATE Dealloc; 1704 Dealloc.hResource = pRc->hResource; 1705 Assert(pRc->hResource); 1706 /* according to the docs the below two are ignored in case we set the hResource */ 1707 Dealloc.NumAllocations = 0; 1708 Dealloc.HandleList = NULL; 1709 hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc); 1710 Assert(hr == S_OK); 1819 1820 if (VBOXDISPMODE_IS_3D(pAdapter)) 1821 { 1822 if (pRc->RcDesc.fFlags.RenderTarget) 1823 { 1824 Assert(pDevice->hWnd); 1825 Assert(pDevice->pDevice9If); 1826 pDevice->pDevice9If->Release(); 1827 HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pDevice->hWnd); 1828 Assert(tmpHr == S_OK); 1829 } 1830 } 1831 else 1832 { 1833 if (!(pRc->fFlags & VBOXWDDM_RESOURCE_F_OPENNED)) 1834 { 1835 D3DDDICB_DEALLOCATE Dealloc; 1836 Dealloc.hResource = pRc->hResource; 1837 Assert(pRc->hResource); 1838 /* according to the docs the below two are ignored in case we set the hResource */ 1839 Dealloc.NumAllocations = 0; 1840 Dealloc.HandleList = NULL; 1841 hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc); 1842 Assert(hr == S_OK); 1843 } 1711 1844 } 1712 1845 … … 2391 2524 if (hr == S_OK) 2392 2525 { 2393 if ( pDevice->u32IfVersion > 7)2526 if (VBOXDISPMODE_IS_3D(pAdapter)) 2394 2527 { 2395 /* D3D */ 2396 if (pAdapter->pD3D9If) 2397 { 2398 /* */ 2399 vboxVDbgPrint((__FUNCTION__": TODO: Implement D3D Device Creation\n")); 2400 break; 2401 } 2402 else 2403 { 2404 /* ballback */ 2405 vboxVDbgPrint((__FUNCTION__": D3D Device Being Created, but D3D is unavailable\n")); 2406 break; 2407 } 2528 /* we postpone IDirect3DDevice device creation to CreateResource, 2529 * where resource render target gets created, 2530 * which is actually done as part of d3dx.dll Direct3DDevice creation */ 2531 vboxVDbgPrint((__FUNCTION__": D3D Device Created\n")); 2532 break; 2408 2533 } 2409 2534 else … … 2452 2577 2453 2578 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter; 2454 if (pAdapter->pD3D9If) 2455 { 2456 HRESULT hr = pAdapter->pD3D9If->Release(); 2579 if (VBOXDISPMODE_IS_3D(pAdapter)) 2580 { 2581 HRESULT hr = VBoxDispWorkerDestroy(&pAdapter->WndWorker); 2582 Assert(hr == S_OK); 2583 hr = pAdapter->pD3D9If->Release(); 2457 2584 Assert(hr == S_OK); 2458 2585 VBoxDispD3DClose(&pAdapter->D3D); … … 2536 2663 if (hr == S_OK) 2537 2664 { 2538 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter)); 2539 break; 2665 hr = VBoxDispWorkerCreate(&pAdapter->WndWorker); 2666 Assert(hr == S_OK); 2667 if (hr == S_OK) 2668 { 2669 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter)); 2670 break; 2671 } 2672 pAdapter->pD3D9If->Release(); 2540 2673 } 2541 2674 else -
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
r29883 r30038 43 43 UINT uRtVersion; 44 44 VBOXDISPD3D D3D; 45 VBOXDISPWORKER WndWorker; 45 46 IDirect3D9Ex * pD3D9If; 46 47 D3DDDI_ADAPTERCALLBACKS RtCallbacks; … … 71 72 UINT cbCmdBuffer; 72 73 D3DDDI_CREATEDEVICEFLAGS fFlags; 74 HWND hWnd; 75 IDirect3DDevice9 *pDevice9If; 73 76 VBOXWDDMDISP_CONTEXT DefaultContext; 74 77 } VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE; … … 93 96 } VBOXWDDMDISP_RESOURCE, *PVBOXWDDMDISP_RESOURCE; 94 97 95 DECLINLINE(bool) vboxDispD3DIs3DEnabled(VBOXWDDMDISP_ADAPTER * pAdapter) 96 { 97 return !!(pAdapter->pD3D9If); 98 } 98 #define VBOXDISPMODE_IS_3D(_p) (!!((_p)->pD3D9If)) 99 99 100 100 #endif /* #ifndef ___VBoxDispD3D_h___ */ -
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h
r29539 r30038 15 15 #ifndef ___VBoxDispD3DCmn_h___ 16 16 #define ___VBoxDispD3DCmn_h___ 17 18 #include <windows.h> 19 #include <d3d9types.h> 20 //#include <d3dtypes.h> 21 #include <D3dumddi.h> 22 #include <d3dhal.h> 23 24 25 #include <iprt/initterm.h> 26 #include <iprt/log.h> 27 #include <iprt/mem.h> 28 29 #include <VBox/Log.h> 30 31 #include <VBox/VBoxGuestLib.h> 32 33 #include "VBoxDispD3DIf.h" 34 #include "../../Miniport/wddm/VBoxVideoIf.h" 35 #include "VBoxDispD3D.h" 17 36 18 37 #ifdef DEBUG -
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp
r29432 r30038 51 51 return E_FAIL; 52 52 } 53 54 #define WM_VBOXDISP_CALLPROC (WM_APP+1) 55 56 typedef struct VBOXDISP_CALLPROC 57 { 58 PFNVBOXDISPWORKERCB pfnCb; 59 void *pvCb; 60 } VBOXDISP_CALLPROC; 61 62 static DWORD WINAPI vboxDispWorkerThread(void *pvUser) 63 { 64 VBOXDISPWORKER *pWorker = (VBOXDISPWORKER*)pvUser; 65 MSG Msg; 66 67 PeekMessage(&Msg, 68 NULL /* HWND hWnd */, 69 WM_USER /* UINT wMsgFilterMin */, 70 WM_USER /* UINT wMsgFilterMax */, 71 PM_NOREMOVE); 72 RTSemEventSignal(pWorker->hEvent); 73 74 do 75 { 76 BOOL bResult = GetMessage(&Msg, 77 0 /*HWND hWnd*/, 78 0 /*UINT wMsgFilterMin*/, 79 0 /*UINT wMsgFilterMax*/ 80 ); 81 82 Assert(0); 83 84 if(!bResult) /* WM_QUIT was posted */ 85 break; 86 87 Assert(bResult != -1); 88 if(bResult == -1) /* error occured */ 89 break; 90 91 switch (Msg.message) 92 { 93 case WM_VBOXDISP_CALLPROC: 94 { 95 VBOXDISP_CALLPROC* pData = (VBOXDISP_CALLPROC*)Msg.lParam; 96 pData->pfnCb(pData->pvCb); 97 RTSemEventSignal(pWorker->hEvent); 98 break; 99 } 100 default: 101 TranslateMessage(&Msg); 102 DispatchMessage(&Msg); 103 } 104 } while (1); 105 return 0; 106 } 107 108 static int vboxDispWorkerSubmit(VBOXDISPWORKER *pWorker, UINT Msg, LPARAM lParam) 109 { 110 /* need to serialize since vboxDispWorkerThread is using one pWorker->hEvent 111 * to signal job completion */ 112 int rc = RTCritSectEnter(&pWorker->CritSect); 113 AssertRC(rc); 114 if (RT_SUCCESS(rc)) 115 { 116 BOOL bResult = PostThreadMessage(pWorker->idThread, Msg, 0, lParam); 117 Assert(bResult); 118 if (bResult) 119 { 120 rc = RTSemEventWait(pWorker->hEvent, RT_INDEFINITE_WAIT); 121 AssertRC(rc); 122 } 123 else 124 rc = VERR_GENERAL_FAILURE; 125 126 int tmpRc = RTCritSectLeave(&pWorker->CritSect); 127 AssertRC(tmpRc); 128 } 129 return rc; 130 } 131 132 HRESULT VBoxDispWorkerSubmitProc(VBOXDISPWORKER *pWorker, PFNVBOXDISPWORKERCB pfnCb, void *pvCb) 133 { 134 VBOXDISP_CALLPROC Ctx; 135 Ctx.pfnCb = pfnCb; 136 Ctx.pvCb = pvCb; 137 int rc = vboxDispWorkerSubmit(pWorker, WM_VBOXDISP_CALLPROC, (LPARAM)&Ctx); 138 AssertRC(rc); 139 return RT_SUCCESS(rc) ? S_OK : E_FAIL; 140 } 141 142 HRESULT VBoxDispWorkerCreate(VBOXDISPWORKER *pWorker) 143 { 144 int rc = RTCritSectInit(&pWorker->CritSect); 145 AssertRC(rc); 146 if (RT_SUCCESS(rc)) 147 { 148 rc = RTSemEventCreate(&pWorker->hEvent); 149 AssertRC(rc); 150 if (RT_SUCCESS(rc)) 151 { 152 pWorker->hThread = CreateThread( 153 NULL /* LPSECURITY_ATTRIBUTES lpThreadAttributes */, 154 0 /* SIZE_T dwStackSize */, 155 vboxDispWorkerThread, 156 pWorker, 157 0 /* DWORD dwCreationFlags */, 158 &pWorker->idThread); 159 Assert(pWorker->hThread); 160 if (pWorker->hThread) 161 { 162 Assert(0); 163 rc = RTSemEventWait(pWorker->hEvent, RT_INDEFINITE_WAIT); 164 AssertRC(rc); 165 if (RT_SUCCESS(rc)) 166 return S_OK; 167 /* destroy thread ? */ 168 } 169 else 170 { 171 DWORD winErr = GetLastError(); 172 vboxVDbgPrintR((__FUNCTION__": CreateThread failed, winErr = (%d)", winErr)); 173 rc = VERR_GENERAL_FAILURE; 174 } 175 int tmpRc = RTSemEventDestroy(pWorker->hEvent); 176 AssertRC(tmpRc); 177 } 178 int tmpRc = RTCritSectDelete(&pWorker->CritSect); 179 AssertRC(tmpRc); 180 } 181 return E_FAIL; 182 } 183 184 HRESULT VBoxDispWorkerDestroy(VBOXDISPWORKER *pWorker) 185 { 186 int rc = VINF_SUCCESS; 187 BOOL bResult = PostThreadMessage(pWorker->idThread, WM_QUIT, 0, 0); 188 Assert(bResult); 189 if (bResult) 190 { 191 DWORD dwErr = WaitForSingleObject(pWorker->hThread, INFINITE); 192 Assert(dwErr == WAIT_OBJECT_0); 193 if (dwErr == WAIT_OBJECT_0) 194 { 195 rc = RTSemEventDestroy(pWorker->hEvent); 196 AssertRC(rc); 197 if (RT_SUCCESS(rc)) 198 { 199 rc = RTCritSectDelete(&pWorker->CritSect); 200 AssertRC(rc); 201 } 202 } 203 else 204 rc = VERR_GENERAL_FAILURE; 205 } 206 else 207 rc = VERR_GENERAL_FAILURE; 208 209 return RT_SUCCESS(rc) ? S_OK : E_FAIL; 210 } 211 212 static LRESULT CALLBACK WindowProc(HWND hwnd, 213 UINT uMsg, 214 WPARAM wParam, 215 LPARAM lParam 216 ) 217 { 218 switch(uMsg) 219 { 220 case WM_CLOSE: 221 vboxVDbgPrint((__FUNCTION__": got WM_CLOSE for hwnd(0x%x)", hwnd)); 222 return 0; 223 case WM_DESTROY: 224 vboxVDbgPrint((__FUNCTION__": got WM_DESTROY for hwnd(0x%x)", hwnd)); 225 return 0; 226 case WM_NCHITTEST: 227 vboxVDbgPrint((__FUNCTION__": got WM_NCHITTEST for hwnd(0x%x)\n", hwnd)); 228 return HTNOWHERE; 229 } 230 231 return DefWindowProc(hwnd, uMsg, wParam, lParam); 232 } 233 234 #define VBOXDISPWND_NAME L"VboxDispD3DWindow" 235 236 HRESULT vboxDispWndDoCreate(DWORD w, DWORD h, HWND *phWnd) 237 { 238 HRESULT hr = S_OK; 239 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 240 /* Register the Window Class. */ 241 WNDCLASS wc; 242 if (!GetClassInfo(hInstance, VBOXDISPWND_NAME, &wc)) 243 { 244 wc.style = CS_OWNDC; 245 wc.lpfnWndProc = WindowProc; 246 wc.cbClsExtra = 0; 247 wc.cbWndExtra = 0; 248 wc.hInstance = hInstance; 249 wc.hIcon = NULL; 250 wc.hCursor = NULL; 251 wc.hbrBackground = NULL; 252 wc.lpszMenuName = NULL; 253 wc.lpszClassName = VBOXDISPWND_NAME; 254 if (!RegisterClass(&wc)) 255 { 256 DWORD winErr = GetLastError(); 257 vboxVDbgPrint((__FUNCTION__": RegisterClass failed, winErr(%d)\n", winErr)); 258 hr = E_FAIL; 259 } 260 } 261 262 if (hr == S_OK) 263 { 264 HWND hWnd = CreateWindowEx (WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY, 265 VBOXDISPWND_NAME, VBOXDISPWND_NAME, 266 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED, 267 0, 0, w, h, 268 GetDesktopWindow() /* hWndParent */, 269 NULL /* hMenu */, 270 hInstance, 271 NULL /* lpParam */); 272 Assert(hWnd); 273 if (hWnd) 274 { 275 *phWnd = hWnd; 276 } 277 else 278 { 279 DWORD winErr = GetLastError(); 280 vboxVDbgPrint((__FUNCTION__": CreateWindowEx failed, winErr(%d)\n", winErr)); 281 hr = E_FAIL; 282 } 283 } 284 285 return hr; 286 } 287 288 static HRESULT vboxDispWndDoDestroy(HWND hWnd) 289 { 290 BOOL bResult = DestroyWindow(hWnd); 291 Assert(bResult); 292 if (bResult) 293 return S_OK; 294 295 DWORD winErr = GetLastError(); 296 vboxVDbgPrint((__FUNCTION__": DestroyWindow failed, winErr(%d) for hWnd(0x%x)\n", winErr, hWnd)); 297 298 return E_FAIL; 299 } 300 301 typedef struct VBOXDISPWND_CREATE_INFO 302 { 303 int hr; 304 HWND hWnd; 305 DWORD width; 306 DWORD height; 307 } VBOXDISPWND_CREATE_INFO; 308 309 typedef struct VBOXDISPWND_DESTROY_INFO 310 { 311 int hr; 312 HWND hWnd; 313 } VBOXDISPWND_DESTROY_INFO; 314 315 DECLCALLBACK(void) vboxDispWndDestroyWorker(void *pvUser) 316 { 317 VBOXDISPWND_DESTROY_INFO *pInfo = (VBOXDISPWND_DESTROY_INFO*)pvUser; 318 pInfo->hr = vboxDispWndDoDestroy(pInfo->hWnd); 319 Assert(pInfo->hr == S_OK); 320 } 321 322 DECLCALLBACK(void) vboxDispWndCreateWorker(void *pvUser) 323 { 324 VBOXDISPWND_CREATE_INFO *pInfo = (VBOXDISPWND_CREATE_INFO*)pvUser; 325 pInfo->hr = vboxDispWndDoCreate(pInfo->width, pInfo->height, &pInfo->hWnd); 326 Assert(pInfo->hr == S_OK); 327 } 328 329 330 HRESULT VBoxDispWndDestroy(PVBOXWDDMDISP_ADAPTER pAdapter, HWND hWnd) 331 { 332 VBOXDISPWND_DESTROY_INFO Info; 333 Info.hr = E_FAIL; 334 Info.hWnd = hWnd; 335 HRESULT hr = VBoxDispWorkerSubmitProc(&pAdapter->WndWorker, vboxDispWndDestroyWorker, &Info); 336 Assert(hr == S_OK); 337 if (hr == S_OK) 338 { 339 Assert(Info.hr == S_OK); 340 return Info.hr; 341 } 342 return hr; 343 } 344 345 HRESULT VBoxDispWndCreate(PVBOXWDDMDISP_ADAPTER pAdapter, DWORD width, DWORD height, HWND *phWnd) 346 { 347 VBOXDISPWND_CREATE_INFO Info; 348 Info.hr = E_FAIL; 349 Info.width = width; 350 Info.height = height; 351 HRESULT hr = VBoxDispWorkerSubmitProc(&pAdapter->WndWorker, vboxDispWndCreateWorker, &Info); 352 Assert(hr == S_OK); 353 if (hr == S_OK) 354 { 355 Assert(Info.hr == S_OK); 356 if (Info.hr == S_OK) 357 *phWnd = Info.hWnd; 358 return Info.hr; 359 } 360 return hr; 361 } -
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h
r29434 r30038 17 17 18 18 /* D3D headers */ 19 #include <iprt/critsect.h> 20 #include <iprt/semaphore.h> 21 19 22 #include <D3D9.h> 20 23 … … 35 38 void VBoxDispD3DClose(VBOXDISPD3D *pD3D); 36 39 40 41 typedef struct VBOXDISPWORKER 42 { 43 RTCRITSECT CritSect; 44 45 RTSEMEVENT hEvent; 46 47 HANDLE hThread; 48 DWORD idThread; 49 } VBOXDISPWORKER; 50 51 HRESULT VBoxDispWorkerCreate(VBOXDISPWORKER *pWorker); 52 HRESULT VBoxDispWorkerDestroy(VBOXDISPWORKER *pWorker); 53 54 typedef DECLCALLBACK(void) FNVBOXDISPWORKERCB(void *pvUser); 55 typedef FNVBOXDISPWORKERCB *PFNVBOXDISPWORKERCB; 56 57 HRESULT VBoxDispWorkerSubmitProc(VBOXDISPWORKER *pWorker, PFNVBOXDISPWORKERCB pfnCb, void *pvCb); 58 59 typedef struct VBOXWDDMDISP_ADAPTER *PVBOXWDDMDISP_ADAPTER; 60 61 HRESULT VBoxDispWndDestroy(PVBOXWDDMDISP_ADAPTER pAdapter, HWND hWnd); 62 HRESULT VBoxDispWndCreate(PVBOXWDDMDISP_ADAPTER pAdapter, DWORD width, DWORD height, HWND *phWnd); 63 37 64 #endif /* ifndef ___VBoxDispD3DIf_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.