VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispMp.cpp@ 32425

Last change on this file since 32425 was 32425, checked in by vboxsync, 14 years ago

wddm/3d: multiple swapchain handling (needed for win7 & multi-screen)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
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 "VBoxDispD3DCmn.h"
16#include "VBoxDispMp.h"
17
18#include <iprt/assert.h>
19
20typedef struct VBOXVIDEOCM_ITERATOR
21{
22 PVBOXVIDEOCM_CMD_HDR pCur;
23 uint32_t cbRemain;
24} VBOXVIDEOCM_ITERATOR, *PVBOXVIDEOCM_ITERATOR;
25
26typedef struct VBOXDISPMP
27{
28 PVBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD pEscapeCmd;
29 uint32_t cbEscapeCmd;
30 VBOXVIDEOCM_ITERATOR Iterator;
31} VBOXDISPMP, *PVBOXDISPMP;
32
33DECLINLINE(void) vboxVideoCmIterInit(PVBOXVIDEOCM_ITERATOR pIter, PVBOXVIDEOCM_CMD_HDR pStart, uint32_t cbCmds)
34{
35 pIter->pCur = pStart;
36 pIter->cbRemain= cbCmds;
37}
38
39DECLINLINE(PVBOXVIDEOCM_CMD_HDR) vboxVideoCmIterNext(PVBOXVIDEOCM_ITERATOR pIter)
40{
41 if (pIter->cbRemain)
42 {
43 PVBOXVIDEOCM_CMD_HDR pCur = pIter->pCur;
44 Assert(pIter->cbRemain >= pIter->pCur->cbCmd);
45 pIter->cbRemain -= pIter->pCur->cbCmd;
46 pIter->pCur = (PVBOXVIDEOCM_CMD_HDR)(((uint8_t*)pIter->pCur) + pIter->pCur->cbCmd);
47 return pCur;
48 }
49 return NULL;
50}
51
52DECLINLINE(bool) vboxVideoCmIterHasNext(PVBOXVIDEOCM_ITERATOR pIter)
53{
54 return !!(pIter->cbRemain);
55}
56
57static VBOXDISPMP g_VBoxDispMp;
58
59DECLCALLBACK(HRESULT) vboxDispMpEnableEvents()
60{
61 g_VBoxDispMp.pEscapeCmd = NULL;
62 g_VBoxDispMp.cbEscapeCmd = 0;
63 vboxVideoCmIterInit(&g_VBoxDispMp.Iterator, NULL, 0);
64 return S_OK;
65}
66
67
68DECLCALLBACK(HRESULT) vboxDispMpDisableEvents()
69{
70 if (g_VBoxDispMp.pEscapeCmd)
71 RTMemFree(g_VBoxDispMp.pEscapeCmd);
72 return S_OK;
73}
74
75#define VBOXDISPMP_BUF_INITSIZE 4000
76#define VBOXDISPMP_BUF_INCREASE 4096
77#define VBOXDISPMP_BUF_MAXSIZE ((4096*4096)-96)
78
79DECLCALLBACK(HRESULT) vboxDispMpGetRegions(PVBOXDISPMP_REGIONS pRegions, DWORD dwMilliseconds)
80{
81 HRESULT hr = S_OK;
82 PVBOXVIDEOCM_CMD_HDR pHdr = vboxVideoCmIterNext(&g_VBoxDispMp.Iterator);
83 if (!pHdr)
84 {
85 if (!g_VBoxDispMp.pEscapeCmd)
86 {
87 g_VBoxDispMp.pEscapeCmd = (PVBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD)RTMemAlloc(VBOXDISPMP_BUF_INITSIZE);
88 Assert(g_VBoxDispMp.pEscapeCmd);
89 if (g_VBoxDispMp.pEscapeCmd)
90 g_VBoxDispMp.cbEscapeCmd = VBOXDISPMP_BUF_INITSIZE;
91 else
92 return E_OUTOFMEMORY;
93 }
94
95 do
96 {
97 hr = vboxDispCmCmdGet(g_VBoxDispMp.pEscapeCmd, g_VBoxDispMp.cbEscapeCmd, dwMilliseconds);
98 Assert(hr == S_OK || (dwMilliseconds != INFINITE && hr == WAIT_TIMEOUT));
99 if (hr == S_OK)
100 {
101 if (g_VBoxDispMp.pEscapeCmd->Hdr.cbCmdsReturned)
102 {
103 pHdr = (PVBOXVIDEOCM_CMD_HDR)(((uint8_t*)g_VBoxDispMp.pEscapeCmd) + sizeof (VBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD));
104 vboxVideoCmIterInit(&g_VBoxDispMp.Iterator, pHdr, g_VBoxDispMp.pEscapeCmd->Hdr.cbCmdsReturned);
105 pHdr = vboxVideoCmIterNext(&g_VBoxDispMp.Iterator);
106 Assert(pHdr);
107 break;
108 }
109 else
110 {
111 Assert(g_VBoxDispMp.pEscapeCmd->Hdr.cbRemainingCmds);
112 Assert(g_VBoxDispMp.pEscapeCmd->Hdr.cbRemainingFirstCmd);
113 RTMemFree(g_VBoxDispMp.pEscapeCmd);
114 uint32_t newSize = RT_MAX(g_VBoxDispMp.cbEscapeCmd + VBOXDISPMP_BUF_INCREASE, g_VBoxDispMp.pEscapeCmd->Hdr.cbRemainingFirstCmd);
115 if (newSize < VBOXDISPMP_BUF_MAXSIZE)
116 newSize = RT_MAX(newSize, RT_MIN(g_VBoxDispMp.pEscapeCmd->Hdr.cbRemainingCmds, VBOXDISPMP_BUF_MAXSIZE));
117 Assert(g_VBoxDispMp.cbEscapeCmd < newSize);
118 g_VBoxDispMp.pEscapeCmd = (PVBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD)RTMemAlloc(newSize);
119 Assert(g_VBoxDispMp.pEscapeCmd);
120 if (g_VBoxDispMp.pEscapeCmd)
121 g_VBoxDispMp.cbEscapeCmd = newSize;
122 else
123 {
124 g_VBoxDispMp.pEscapeCmd = NULL;
125 g_VBoxDispMp.cbEscapeCmd = 0;
126 hr = E_OUTOFMEMORY;
127 break;
128 }
129 }
130 }
131 else
132 break;
133 } while (1);
134 }
135
136 if (hr == S_OK)
137 {
138 Assert(pHdr);
139 VBOXWDDMDISP_CONTEXT *pContext = (VBOXWDDMDISP_CONTEXT*)pHdr->u64UmData;
140 PVBOXVIDEOCM_CMD_RECTS_INTERNAL pCmdInternal = (PVBOXVIDEOCM_CMD_RECTS_INTERNAL)(((uint8_t*)pHdr) + sizeof (VBOXVIDEOCM_CMD_HDR));
141// UINT iScreen = pContext->pDevice->cScreens == 1 ? pContext->pDevice->iPrimaryScreen : pCmdInternal->VidPnSourceId;
142// PVBOXWDDMDISP_SCREEN pScreen = &pContext->pDevice->aScreens[iScreen];
143// Assert(pScreen->hWnd);
144// Assert(pScreen->pDevice9If);
145// pRegions->hWnd = pScreen->hWnd;
146 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = RTListNodeGetLast(&pContext->pDevice->SwapchainList, VBOXWDDMDISP_SWAPCHAIN, ListEntry);
147 Assert(pSwapchain);
148 pRegions->hWnd = pSwapchain->hWnd;
149 pRegions->pRegions = &pCmdInternal->Cmd;
150 }
151 return hr;
152}
153
154VBOXDISPMP_DECL(HRESULT) VBoxDispMpGetCallbacks(uint32_t u32Version, PVBOXDISPMP_CALLBACKS pCallbacks)
155{
156 Assert(u32Version == VBOXDISPMP_VERSION);
157 if (u32Version != VBOXDISPMP_VERSION)
158 return E_INVALIDARG;
159
160 pCallbacks->pfnEnableEvents = vboxDispMpEnableEvents;
161 pCallbacks->pfnDisableEvents = vboxDispMpDisableEvents;
162 pCallbacks->pfnGetRegions = vboxDispMpGetRegions;
163 return S_OK;
164}
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