| 106 | | return VINF_SUCCESS; |
|---|
| 107 | | } |
|---|
| 108 | | |
|---|
| 109 | | /** |
|---|
| 110 | | * Client connect init |
|---|
| 111 | | * |
|---|
| 112 | | * @returns VBox error code |
|---|
| 113 | | * @param pClient Client context |
|---|
| 114 | | */ |
|---|
| 115 | | int vboxglConnect(PVBOXOGLCTX pClient) |
|---|
| 116 | | { |
|---|
| 117 | | Log(("vboxglConnect\n")); |
|---|
| 118 | | return VINF_SUCCESS; |
|---|
| 119 | | } |
|---|
| 120 | | |
|---|
| 121 | | /** |
|---|
| 122 | | * Client disconnect cleanup |
|---|
| 123 | | * |
|---|
| 124 | | * @returns VBox error code |
|---|
| 125 | | * @param pClient Client context |
|---|
| 126 | | */ |
|---|
| 127 | | int vboxglDisconnect(PVBOXOGLCTX pClient) |
|---|
| 128 | | { |
|---|
| 129 | | Log(("vboxglDisconnect\n")); |
|---|
| 130 | | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT |
|---|
| 131 | | if (pClient->hwnd) |
|---|
| 132 | | { |
|---|
| 133 | | if (pClient->hdc) |
|---|
| 134 | | ReleaseDC(pClient->hwnd, pClient->hdc); |
|---|
| 135 | | PostMessage(pClient->hwnd, WM_CLOSE, 0, 0); |
|---|
| 136 | | pClient->hwnd = 0; |
|---|
| 137 | | } |
|---|
| 138 | | #endif |
|---|
| 139 | | return VINF_SUCCESS; |
|---|
| 140 | | } |
|---|
| 141 | | |
|---|
| 142 | | |
|---|
| 143 | | /* Driver functions */ |
|---|
| 144 | | void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 145 | | { |
|---|
| 146 | | HGLRC glrc = 0; |
|---|
| 147 | | |
|---|
| 148 | | OGL_CMD(DrvCreateContext, 1); |
|---|
| 149 | | OGL_PARAM(HDC, hdc); |
|---|
| 150 | | |
|---|
| 151 | | Log(("DrvCreateContext %x\n", hdc)); |
|---|
| 152 | | Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| 153 | | glrc = wglCreateContext(pClient->hdc); |
|---|
| 154 | | |
|---|
| 155 | | pClient->lastretval = (uint64_t)glrc; |
|---|
| 156 | | pClient->fHasLastError = true; |
|---|
| 157 | | pClient->ulLastError = GetLastError(); |
|---|
| 158 | | } |
|---|
| 159 | | |
|---|
| 160 | | void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 161 | | { |
|---|
| 162 | | OGL_CMD(DrvSetContext, 2); |
|---|
| 163 | | OGL_PARAM(HDC, hdc); |
|---|
| 164 | | OGL_PARAM(HGLRC, hglrc); |
|---|
| 165 | | |
|---|
| 166 | | Log(("DrvSetyContext %x %x\n", hdc, hglrc)); |
|---|
| 167 | | pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), hglrc); |
|---|
| 168 | | if (!pClient->lastretval) |
|---|
| 169 | | Log(("wglMakeCurrent failed with %d\n", GetLastError())); |
|---|
| 170 | | |
|---|
| 171 | | pClient->fHasLastError = true; |
|---|
| 172 | | pClient->ulLastError = GetLastError(); |
|---|
| 173 | | } |
|---|
| 174 | | |
|---|
| 175 | | void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 176 | | { |
|---|
| 177 | | OGL_CMD(DrvDeleteContext, 3); |
|---|
| 178 | | OGL_PARAM(HGLRC, hglrcSrc); |
|---|
| 179 | | OGL_PARAM(HGLRC, hglrcDst); |
|---|
| 180 | | OGL_PARAM(UINT, mask); |
|---|
| 181 | | Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask)); |
|---|
| 182 | | pClient->lastretval = wglCopyContext(hglrcSrc, hglrcDst, mask); |
|---|
| 183 | | if (!pClient->lastretval) |
|---|
| 184 | | Log(("wglCopyContext failed with %d\n", GetLastError())); |
|---|
| 185 | | |
|---|
| 186 | | pClient->fHasLastError = true; |
|---|
| 187 | | pClient->ulLastError = GetLastError(); |
|---|
| 188 | | } |
|---|
| 189 | | |
|---|
| 190 | | void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 191 | | { |
|---|
| 192 | | OGL_CMD(DrvReleaseContext, 1); |
|---|
| 193 | | OGL_PARAM(HGLRC, hglrc); |
|---|
| 194 | | |
|---|
| 195 | | Log(("DrvReleaseContext %x\n", hglrc)); |
|---|
| 196 | | /* clear current selection */ |
|---|
| 197 | | pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), NULL); |
|---|
| 198 | | if (!pClient->lastretval) |
|---|
| 199 | | Log(("wglMakeCurrent failed with %d\n", GetLastError())); |
|---|
| 200 | | pClient->fHasLastError = true; |
|---|
| 201 | | pClient->ulLastError = GetLastError(); |
|---|
| 202 | | } |
|---|
| 203 | | |
|---|
| 204 | | void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 205 | | { |
|---|
| 206 | | OGL_CMD(DrvDeleteContext, 1); |
|---|
| 207 | | OGL_PARAM(HGLRC, hglrc); |
|---|
| 208 | | |
|---|
| 209 | | Log(("DrvDeleteContext %x\n", hglrc)); |
|---|
| 210 | | pClient->lastretval = wglDeleteContext(hglrc); |
|---|
| 211 | | if (!pClient->lastretval) |
|---|
| 212 | | Log(("wglDeleteContext failed with %d\n", GetLastError())); |
|---|
| 213 | | pClient->fHasLastError = true; |
|---|
| 214 | | pClient->ulLastError = GetLastError(); |
|---|
| 215 | | } |
|---|
| 216 | | |
|---|
| 217 | | void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 218 | | { |
|---|
| 219 | | HGLRC glrc = 0; |
|---|
| 220 | | |
|---|
| 221 | | OGL_CMD(DrvCreateLayerContext, 2); |
|---|
| 222 | | OGL_PARAM(HDC, hdc); |
|---|
| 223 | | OGL_PARAM(int, iLayerPlane); |
|---|
| 224 | | |
|---|
| 225 | | Log(("DrvCreateLayerContext %x %d\n", hdc, iLayerPlane)); |
|---|
| 226 | | Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| 227 | | glrc = wglCreateLayerContext(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane); |
|---|
| 228 | | |
|---|
| 229 | | pClient->lastretval = (uint64_t)glrc; |
|---|
| 230 | | pClient->fHasLastError = true; |
|---|
| 231 | | pClient->ulLastError = GetLastError(); |
|---|
| 232 | | } |
|---|
| 233 | | |
|---|
| 234 | | void vboxglDrvShareLists(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 235 | | { |
|---|
| 236 | | OGL_CMD(DrvShareLists, 3); |
|---|
| 237 | | OGL_PARAM(HGLRC, hglrc1); |
|---|
| 238 | | OGL_PARAM(HGLRC, hglrc2); |
|---|
| 239 | | |
|---|
| 240 | | Log(("DrvShareLists %x %x\n", hglrc1, hglrc2)); |
|---|
| 241 | | pClient->lastretval = wglShareLists(hglrc1, hglrc2); |
|---|
| 242 | | pClient->fHasLastError = true; |
|---|
| 243 | | pClient->ulLastError = GetLastError(); |
|---|
| 244 | | } |
|---|
| 245 | | |
|---|
| 246 | | |
|---|
| 247 | | void vboxglDrvRealizeLayerPalette(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 248 | | { |
|---|
| 249 | | OGL_CMD(DrvRealizeLayerPalette, 3); |
|---|
| 250 | | OGL_PARAM(HDC, hdc); |
|---|
| 251 | | OGL_PARAM(int, iLayerPlane); |
|---|
| 252 | | OGL_PARAM(BOOL, bRealize); |
|---|
| 253 | | Log(("DrvRealizeLayerPalette %x %d %d\n", hdc, iLayerPlane, bRealize)); |
|---|
| 254 | | pClient->lastretval = wglRealizeLayerPalette(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, bRealize); |
|---|
| 255 | | pClient->fHasLastError = true; |
|---|
| 256 | | pClient->ulLastError = GetLastError(); |
|---|
| 257 | | } |
|---|
| 258 | | |
|---|
| 259 | | void vboxglDrvSwapLayerBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 260 | | { |
|---|
| 261 | | OGL_CMD(DrvSwapLayerBuffers, 2); |
|---|
| 262 | | OGL_PARAM(HDC, hdc); |
|---|
| 263 | | OGL_PARAM(UINT, fuPlanes); |
|---|
| 264 | | Log(("DrvSwapLayerBuffers %x %d\n", hdc, fuPlanes)); |
|---|
| 265 | | pClient->lastretval = wglSwapLayerBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), fuPlanes); |
|---|
| 266 | | pClient->fHasLastError = true; |
|---|
| 267 | | pClient->ulLastError = GetLastError(); |
|---|
| 268 | | } |
|---|
| 269 | | |
|---|
| 270 | | void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 271 | | { |
|---|
| 272 | | int rc; |
|---|
| 273 | | PIXELFORMATDESCRIPTOR pfd; |
|---|
| 274 | | |
|---|
| 275 | | OGL_CMD(DrvSetPixelFormat, 4); |
|---|
| 276 | | OGL_PARAM(HDC, hdc); |
|---|
| 277 | | OGL_PARAM(int, iPixelFormat); |
|---|
| 278 | | OGL_PARAM(uint32_t, cx); |
|---|
| 279 | | OGL_PARAM(uint32_t, cy); |
|---|
| 280 | | |
|---|
| 281 | | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT |
|---|
| 282 | | if (!pClient->hwnd) |
|---|
| 283 | | { |
|---|
| 284 | | RTThreadCreate(NULL, vboxWndThread, pClient, 0, RTTHREADTYPE_DEFAULT, 0, "OpenGLWnd"); |
|---|
| 285 | | while (!pClient->hwnd) |
|---|
| 286 | | RTThreadSleep(100); |
|---|
| 287 | | } |
|---|
| 288 | | RECT rect; |
|---|
| 289 | | rect.bottom = 0; |
|---|
| 290 | | rect.left = 0; |
|---|
| 291 | | rect.right = cx; |
|---|
| 292 | | rect.top = cy; |
|---|
| 293 | | /* Convert client rectangel to window rectangle */ |
|---|
| 294 | | AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, FALSE); |
|---|
| 295 | | SetWindowPos(pClient->hwnd, NULL, 0, 0, rect.right - rect.left, rect.top - rect.bottom, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
|---|
| 296 | | |
|---|
| 297 | | pClient->hdc = GetDC(pClient->hwnd); |
|---|
| 298 | | |
|---|
| 299 | | rc = DescribePixelFormat(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, sizeof(pfd), &pfd); |
|---|
| 300 | | if (rc) |
|---|
| 301 | | { |
|---|
| 302 | | pClient->lastretval = SetPixelFormat(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, &pfd); |
|---|
| 303 | | } |
|---|
| 304 | | else |
|---|
| 305 | | { |
|---|
| 306 | | Log(("DescribePixelFormat %d failed with 0 (%d)\n", iPixelFormat, GetLastError())); |
|---|
| 307 | | pClient->lastretval = 0; |
|---|
| 308 | | } |
|---|
| 309 | | |
|---|
| 310 | | #else |
|---|
| 311 | | AssertFailed(); |
|---|
| 312 | | #endif |
|---|
| 313 | | |
|---|
| 314 | | Log(("DrvSetPixelFormat %x %d (%d,%d)\n", hdc, iPixelFormat, cx, cy)); |
|---|
| 315 | | pClient->fHasLastError = true; |
|---|
| 316 | | pClient->ulLastError = GetLastError(); |
|---|
| 317 | | } |
|---|
| 318 | | |
|---|
| 319 | | void vboxglDrvSwapBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 320 | | { |
|---|
| 321 | | OGL_CMD(DrvSwapBuffers, 1); |
|---|
| 322 | | OGL_PARAM(HDC, hdc); |
|---|
| 323 | | |
|---|
| 324 | | Log(("DrvSwapBuffers %x\n", hdc)); |
|---|
| 325 | | pClient->lastretval = SwapBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| 326 | | if (!pClient->lastretval) |
|---|
| 327 | | Log(("SwapBuffers failed with %d\n", GetLastError())); |
|---|
| 328 | | |
|---|
| 329 | | /** @todo sync bitmap/screen contents */ |
|---|
| 330 | | pClient->fHasLastError = true; |
|---|
| 331 | | pClient->ulLastError = GetLastError(); |
|---|
| 332 | | } |
|---|
| 333 | | |
|---|
| 334 | | void vboxglDrvDescribeLayerPlane(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 335 | | { |
|---|
| 336 | | PLAYERPLANEDESCRIPTOR plpd; |
|---|
| 337 | | |
|---|
| 338 | | OGL_CMD(DrvDescribeLayerPlane, 4); |
|---|
| 339 | | OGL_PARAM(HDC, hdc); |
|---|
| 340 | | OGL_PARAM(int, iPixelFormat); |
|---|
| 341 | | OGL_PARAM(int, iLayerPlane); |
|---|
| 342 | | OGL_PARAM(UINT, nBytes); |
|---|
| 343 | | Assert(pClient->cbLastParam == nBytes); |
|---|
| 344 | | plpd = (PLAYERPLANEDESCRIPTOR)pClient->pLastParam; |
|---|
| 345 | | |
|---|
| 346 | | Log(("DrvDescribeLayerPlane %x %d %d %d %x\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd)); |
|---|
| 347 | | pClient->lastretval = wglDescribeLayerPlane(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, iLayerPlane, nBytes, plpd); |
|---|
| 348 | | if (!pClient->lastretval) |
|---|
| 349 | | Log(("wglDescribeLayerPlane failed with %d\n", GetLastError())); |
|---|
| 350 | | pClient->fHasLastError = true; |
|---|
| 351 | | pClient->ulLastError = GetLastError(); |
|---|
| 352 | | } |
|---|
| 353 | | |
|---|
| 354 | | void vboxglDrvSetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 355 | | { |
|---|
| 356 | | OGL_CMD(DrvSetLayerPaletteEntries, 5); |
|---|
| 357 | | OGL_PARAM(HDC, hdc); |
|---|
| 358 | | OGL_PARAM(int, iLayerPlane); |
|---|
| 359 | | OGL_PARAM(int, iStart); |
|---|
| 360 | | OGL_PARAM(int, cEntries); |
|---|
| 361 | | OGL_MEMPARAM(COLORREF, pcr); |
|---|
| 362 | | |
|---|
| 363 | | Log(("DrvSetLayerPaletteEntries %x %d %d %d %x\n", hdc, iLayerPlane, iStart, cEntries, pcr)); |
|---|
| 364 | | pClient->lastretval = wglSetLayerPaletteEntries(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, iStart, cEntries, pcr); |
|---|
| 365 | | if (!pClient->lastretval) |
|---|
| 366 | | Log(("wglSetLayerPaletteEntries failed with %d\n", GetLastError())); |
|---|
| 367 | | pClient->fHasLastError = true; |
|---|
| 368 | | pClient->ulLastError = GetLastError(); |
|---|
| 369 | | } |
|---|
| 370 | | |
|---|
| 371 | | void vboxglDrvGetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 372 | | { |
|---|
| 373 | | COLORREF *pcr; |
|---|
| 374 | | |
|---|
| 375 | | OGL_CMD(DrvGetLayerPaletteEntries, 4); |
|---|
| 376 | | OGL_PARAM(HDC, hdc); |
|---|
| 377 | | OGL_PARAM(int, iLayerPlane); |
|---|
| 378 | | OGL_PARAM(int, iStart); |
|---|
| 379 | | OGL_PARAM(int, cEntries); |
|---|
| 380 | | |
|---|
| 381 | | Assert(pClient->cbLastParam == sizeof(COLORREF)*cEntries); |
|---|
| 382 | | pcr = (COLORREF *)pClient->pLastParam; |
|---|
| 383 | | |
|---|
| 384 | | Log(("DrvGetLayerPaletteEntries %x %d %d %d %x\n", hdc, iLayerPlane, iStart, cEntries, pcr)); |
|---|
| 385 | | pClient->lastretval = wglGetLayerPaletteEntries(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, iStart, cEntries, pcr); |
|---|
| 386 | | if (!pClient->lastretval) |
|---|
| 387 | | Log(("wglGetLayerPaletteEntries failed with %d\n", GetLastError())); |
|---|
| 388 | | pClient->fHasLastError = true; |
|---|
| 389 | | pClient->ulLastError = GetLastError(); |
|---|
| 390 | | } |
|---|
| 391 | | |
|---|
| 392 | | void vboxglDrvDescribePixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| 393 | | { |
|---|
| 394 | | LPPIXELFORMATDESCRIPTOR ppfd; |
|---|
| 395 | | |
|---|
| 396 | | OGL_CMD(DrvDescribePixelFormat, 3); |
|---|
| 397 | | OGL_PARAM(HDC, hdc); |
|---|
| 398 | | OGL_PARAM(int, iPixelFormat); |
|---|
| 399 | | OGL_PARAM(UINT, nBytes); |
|---|
| 400 | | Assert(pClient->cbLastParam == nBytes); |
|---|
| 401 | | ppfd = (LPPIXELFORMATDESCRIPTOR)pClient->pLastParam; |
|---|
| 402 | | |
|---|
| 403 | | hdc = VBOX_OGL_GUEST_TO_HOST_HDC(hdc); |
|---|
| 404 | | if (!hdc) |
|---|
| 405 | | hdc = GetDC(0); |
|---|
| 406 | | |
|---|
| 407 | | Log(("DrvDescribePixelFormat %x %d %d %x\n", hdc, iPixelFormat, nBytes, ppfd)); |
|---|
| 408 | | pClient->lastretval = DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd); |
|---|
| 409 | | if (!pClient->lastretval) |
|---|
| 410 | | Log(("DescribePixelFormat failed with %d\n", GetLastError())); |
|---|
| 411 | | |
|---|
| 412 | | pClient->fHasLastError = true; |
|---|
| 413 | | pClient->ulLastError = GetLastError(); |
|---|
| 414 | | |
|---|
| 415 | | if (!VBOX_OGL_GUEST_TO_HOST_HDC(hdc)) |
|---|
| 416 | | ReleaseDC(0, pClient->hdc); |
|---|
| 417 | | } |
|---|
| 418 | | |
|---|
| 419 | | bool vboxDrvIsExtensionAvailable(char *pszExtFunctionName) |
|---|
| 420 | | { |
|---|
| | 130 | return VINF_SUCCESS; |
|---|
| | 131 | } |
|---|
| | 132 | |
|---|
| | 133 | /** |
|---|
| | 134 | * Client connect init |
|---|
| | 135 | * |
|---|
| | 136 | * @returns VBox error code |
|---|
| | 137 | * @param pClient Client context |
|---|
| | 138 | */ |
|---|
| | 139 | int vboxglConnect(PVBOXOGLCTX pClient) |
|---|
| | 140 | { |
|---|
| | 141 | Log(("vboxglConnect\n")); |
|---|
| | 142 | return VINF_SUCCESS; |
|---|
| | 143 | } |
|---|
| | 144 | |
|---|
| | 145 | /** |
|---|
| | 146 | * Client disconnect cleanup |
|---|
| | 147 | * |
|---|
| | 148 | * @returns VBox error code |
|---|
| | 149 | * @param pClient Client context |
|---|
| | 150 | */ |
|---|
| | 151 | int vboxglDisconnect(PVBOXOGLCTX pClient) |
|---|
| | 152 | { |
|---|
| | 153 | Log(("vboxglDisconnect\n")); |
|---|
| | 154 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT |
|---|
| | 155 | if (pClient->hwnd) |
|---|
| | 156 | { |
|---|
| | 157 | if (pClient->hdc) |
|---|
| | 158 | ReleaseDC(pClient->hwnd, pClient->hdc); |
|---|
| | 159 | PostMessage(pClient->hwnd, WM_CLOSE, 0, 0); |
|---|
| | 160 | pClient->hwnd = 0; |
|---|
| | 161 | } |
|---|
| | 162 | #endif |
|---|
| | 163 | return VINF_SUCCESS; |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | |
|---|
| | 167 | /* Driver functions */ |
|---|
| | 168 | void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 169 | { |
|---|
| | 170 | HGLRC glrc = 0; |
|---|
| | 171 | |
|---|
| | 172 | OGL_CMD(DrvCreateContext, 1); |
|---|
| | 173 | OGL_PARAM(HDC, hdc); |
|---|
| | 174 | |
|---|
| | 175 | Log(("DrvCreateContext %x\n", hdc)); |
|---|
| | 176 | Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| | 177 | glrc = wglCreateContext(pClient->hdc); |
|---|
| | 178 | |
|---|
| | 179 | pClient->lastretval = (uint64_t)glrc; |
|---|
| | 180 | pClient->fHasLastError = true; |
|---|
| | 181 | pClient->ulLastError = GetLastError(); |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 185 | { |
|---|
| | 186 | OGL_CMD(DrvSetContext, 2); |
|---|
| | 187 | OGL_PARAM(HDC, hdc); |
|---|
| | 188 | OGL_PARAM(HGLRC, hglrc); |
|---|
| | 189 | |
|---|
| | 190 | Log(("DrvSetyContext %x %x\n", hdc, hglrc)); |
|---|
| | 191 | pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), hglrc); |
|---|
| | 192 | if (!pClient->lastretval) |
|---|
| | 193 | Log(("wglMakeCurrent failed with %d\n", GetLastError())); |
|---|
| | 194 | |
|---|
| | 195 | pClient->fHasLastError = true; |
|---|
| | 196 | pClient->ulLastError = GetLastError(); |
|---|
| | 197 | } |
|---|
| | 198 | |
|---|
| | 199 | void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 200 | { |
|---|
| | 201 | OGL_CMD(DrvDeleteContext, 3); |
|---|
| | 202 | OGL_PARAM(HGLRC, hglrcSrc); |
|---|
| | 203 | OGL_PARAM(HGLRC, hglrcDst); |
|---|
| | 204 | OGL_PARAM(UINT, mask); |
|---|
| | 205 | Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask)); |
|---|
| | 206 | pClient->lastretval = wglCopyContext(hglrcSrc, hglrcDst, mask); |
|---|
| | 207 | if (!pClient->lastretval) |
|---|
| | 208 | Log(("wglCopyContext failed with %d\n", GetLastError())); |
|---|
| | 209 | |
|---|
| | 210 | pClient->fHasLastError = true; |
|---|
| | 211 | pClient->ulLastError = GetLastError(); |
|---|
| | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 215 | { |
|---|
| | 216 | OGL_CMD(DrvReleaseContext, 1); |
|---|
| | 217 | OGL_PARAM(HGLRC, hglrc); |
|---|
| | 218 | |
|---|
| | 219 | Log(("DrvReleaseContext %x\n", hglrc)); |
|---|
| | 220 | /* clear current selection */ |
|---|
| | 221 | pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), NULL); |
|---|
| | 222 | if (!pClient->lastretval) |
|---|
| | 223 | Log(("wglMakeCurrent failed with %d\n", GetLastError())); |
|---|
| | 224 | pClient->fHasLastError = true; |
|---|
| | 225 | pClient->ulLastError = GetLastError(); |
|---|
| | 226 | } |
|---|
| | 227 | |
|---|
| | 228 | void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 229 | { |
|---|
| | 230 | OGL_CMD(DrvDeleteContext, 1); |
|---|
| | 231 | OGL_PARAM(HGLRC, hglrc); |
|---|
| | 232 | |
|---|
| | 233 | Log(("DrvDeleteContext %x\n", hglrc)); |
|---|
| | 234 | pClient->lastretval = wglDeleteContext(hglrc); |
|---|
| | 235 | if (!pClient->lastretval) |
|---|
| | 236 | Log(("wglDeleteContext failed with %d\n", GetLastError())); |
|---|
| | 237 | pClient->fHasLastError = true; |
|---|
| | 238 | pClient->ulLastError = GetLastError(); |
|---|
| | 239 | } |
|---|
| | 240 | |
|---|
| | 241 | void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 242 | { |
|---|
| | 243 | HGLRC glrc = 0; |
|---|
| | 244 | |
|---|
| | 245 | OGL_CMD(DrvCreateLayerContext, 2); |
|---|
| | 246 | OGL_PARAM(HDC, hdc); |
|---|
| | 247 | OGL_PARAM(int, iLayerPlane); |
|---|
| | 248 | |
|---|
| | 249 | Log(("DrvCreateLayerContext %x %d\n", hdc, iLayerPlane)); |
|---|
| | 250 | Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| | 251 | glrc = wglCreateLayerContext(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane); |
|---|
| | 252 | |
|---|
| | 253 | pClient->lastretval = (uint64_t)glrc; |
|---|
| | 254 | pClient->fHasLastError = true; |
|---|
| | 255 | pClient->ulLastError = GetLastError(); |
|---|
| | 256 | } |
|---|
| | 257 | |
|---|
| | 258 | void vboxglDrvShareLists(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 259 | { |
|---|
| | 260 | OGL_CMD(DrvShareLists, 3); |
|---|
| | 261 | OGL_PARAM(HGLRC, hglrc1); |
|---|
| | 262 | OGL_PARAM(HGLRC, hglrc2); |
|---|
| | 263 | |
|---|
| | 264 | Log(("DrvShareLists %x %x\n", hglrc1, hglrc2)); |
|---|
| | 265 | pClient->lastretval = wglShareLists(hglrc1, hglrc2); |
|---|
| | 266 | pClient->fHasLastError = true; |
|---|
| | 267 | pClient->ulLastError = GetLastError(); |
|---|
| | 268 | } |
|---|
| | 269 | |
|---|
| | 270 | |
|---|
| | 271 | void vboxglDrvRealizeLayerPalette(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 272 | { |
|---|
| | 273 | OGL_CMD(DrvRealizeLayerPalette, 3); |
|---|
| | 274 | OGL_PARAM(HDC, hdc); |
|---|
| | 275 | OGL_PARAM(int, iLayerPlane); |
|---|
| | 276 | OGL_PARAM(BOOL, bRealize); |
|---|
| | 277 | Log(("DrvRealizeLayerPalette %x %d %d\n", hdc, iLayerPlane, bRealize)); |
|---|
| | 278 | pClient->lastretval = wglRealizeLayerPalette(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, bRealize); |
|---|
| | 279 | pClient->fHasLastError = true; |
|---|
| | 280 | pClient->ulLastError = GetLastError(); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | void vboxglDrvSwapLayerBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 284 | { |
|---|
| | 285 | OGL_CMD(DrvSwapLayerBuffers, 2); |
|---|
| | 286 | OGL_PARAM(HDC, hdc); |
|---|
| | 287 | OGL_PARAM(UINT, fuPlanes); |
|---|
| | 288 | Log(("DrvSwapLayerBuffers %x %d\n", hdc, fuPlanes)); |
|---|
| | 289 | pClient->lastretval = wglSwapLayerBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), fuPlanes); |
|---|
| | 290 | pClient->fHasLastError = true; |
|---|
| | 291 | pClient->ulLastError = GetLastError(); |
|---|
| | 292 | } |
|---|
| | 293 | |
|---|
| | 294 | void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 295 | { |
|---|
| | 296 | int rc; |
|---|
| | 297 | PIXELFORMATDESCRIPTOR pfd; |
|---|
| | 298 | |
|---|
| | 299 | OGL_CMD(DrvSetPixelFormat, 4); |
|---|
| | 300 | OGL_PARAM(HDC, hdc); |
|---|
| | 301 | OGL_PARAM(int, iPixelFormat); |
|---|
| | 302 | OGL_PARAM(uint32_t, cx); |
|---|
| | 303 | OGL_PARAM(uint32_t, cy); |
|---|
| | 304 | |
|---|
| | 305 | #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT |
|---|
| | 306 | if (!pClient->hwnd) |
|---|
| | 307 | { |
|---|
| | 308 | RTThreadCreate(NULL, vboxWndThread, pClient, 0, RTTHREADTYPE_DEFAULT, 0, "OpenGLWnd"); |
|---|
| | 309 | while (!pClient->hwnd) |
|---|
| | 310 | RTThreadSleep(100); |
|---|
| | 311 | } |
|---|
| | 312 | RECT rect; |
|---|
| | 313 | rect.bottom = 0; |
|---|
| | 314 | rect.left = 0; |
|---|
| | 315 | rect.right = cx; |
|---|
| | 316 | rect.top = cy; |
|---|
| | 317 | /* Convert client rectangel to window rectangle */ |
|---|
| | 318 | AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, FALSE); |
|---|
| | 319 | SetWindowPos(pClient->hwnd, NULL, 0, 0, rect.right - rect.left, rect.top - rect.bottom, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
|---|
| | 320 | |
|---|
| | 321 | pClient->hdc = GetDC(pClient->hwnd); |
|---|
| | 322 | |
|---|
| | 323 | rc = DescribePixelFormat(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, sizeof(pfd), &pfd); |
|---|
| | 324 | if (rc) |
|---|
| | 325 | { |
|---|
| | 326 | pClient->lastretval = SetPixelFormat(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, &pfd); |
|---|
| | 327 | } |
|---|
| | 328 | else |
|---|
| | 329 | { |
|---|
| | 330 | Log(("DescribePixelFormat %d failed with 0 (%d)\n", iPixelFormat, GetLastError())); |
|---|
| | 331 | pClient->lastretval = 0; |
|---|
| | 332 | } |
|---|
| | 333 | |
|---|
| | 334 | #else |
|---|
| | 335 | AssertFailed(); |
|---|
| | 336 | #endif |
|---|
| | 337 | |
|---|
| | 338 | Log(("DrvSetPixelFormat %x %d (%d,%d)\n", hdc, iPixelFormat, cx, cy)); |
|---|
| | 339 | pClient->fHasLastError = true; |
|---|
| | 340 | pClient->ulLastError = GetLastError(); |
|---|
| | 341 | } |
|---|
| | 342 | |
|---|
| | 343 | void vboxglDrvSwapBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 344 | { |
|---|
| | 345 | OGL_CMD(DrvSwapBuffers, 1); |
|---|
| | 346 | OGL_PARAM(HDC, hdc); |
|---|
| | 347 | |
|---|
| | 348 | Log(("DrvSwapBuffers %x\n", hdc)); |
|---|
| | 349 | pClient->lastretval = SwapBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc)); |
|---|
| | 350 | if (!pClient->lastretval) |
|---|
| | 351 | Log(("SwapBuffers failed with %d\n", GetLastError())); |
|---|
| | 352 | |
|---|
| | 353 | /** @todo sync bitmap/screen contents */ |
|---|
| | 354 | pClient->fHasLastError = true; |
|---|
| | 355 | pClient->ulLastError = GetLastError(); |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | void vboxglDrvDescribeLayerPlane(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 359 | { |
|---|
| | 360 | PLAYERPLANEDESCRIPTOR plpd; |
|---|
| | 361 | |
|---|
| | 362 | OGL_CMD(DrvDescribeLayerPlane, 4); |
|---|
| | 363 | OGL_PARAM(HDC, hdc); |
|---|
| | 364 | OGL_PARAM(int, iPixelFormat); |
|---|
| | 365 | OGL_PARAM(int, iLayerPlane); |
|---|
| | 366 | OGL_PARAM(UINT, nBytes); |
|---|
| | 367 | Assert(pClient->cbLastParam == nBytes); |
|---|
| | 368 | plpd = (PLAYERPLANEDESCRIPTOR)pClient->pLastParam; |
|---|
| | 369 | |
|---|
| | 370 | Log(("DrvDescribeLayerPlane %x %d %d %d %x\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd)); |
|---|
| | 371 | pClient->lastretval = wglDescribeLayerPlane(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, iLayerPlane, nBytes, plpd); |
|---|
| | 372 | if (!pClient->lastretval) |
|---|
| | 373 | Log(("wglDescribeLayerPlane failed with %d\n", GetLastError())); |
|---|
| | 374 | pClient->fHasLastError = true; |
|---|
| | 375 | pClient->ulLastError = GetLastError(); |
|---|
| | 376 | } |
|---|
| | 377 | |
|---|
| | 378 | void vboxglDrvSetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 379 | { |
|---|
| | 380 | OGL_CMD(DrvSetLayerPaletteEntries, 5); |
|---|
| | 381 | OGL_PARAM(HDC, hdc); |
|---|
| | 382 | OGL_PARAM(int, iLayerPlane); |
|---|
| | 383 | OGL_PARAM(int, iStart); |
|---|
| | 384 | OGL_PARAM(int, cEntries); |
|---|
| | 385 | OGL_MEMPARAM(COLORREF, pcr); |
|---|
| | 386 | |
|---|
| | 387 | Log(("DrvSetLayerPaletteEntries %x %d %d %d %x\n", hdc, iLayerPlane, iStart, cEntries, pcr)); |
|---|
| | 388 | pClient->lastretval = wglSetLayerPaletteEntries(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, iStart, cEntries, pcr); |
|---|
| | 389 | if (!pClient->lastretval) |
|---|
| | 390 | Log(("wglSetLayerPaletteEntries failed with %d\n", GetLastError())); |
|---|
| | 391 | pClient->fHasLastError = true; |
|---|
| | 392 | pClient->ulLastError = GetLastError(); |
|---|
| | 393 | } |
|---|
| | 394 | |
|---|
| | 395 | void vboxglDrvGetLayerPaletteEntries(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 396 | { |
|---|
| | 397 | COLORREF *pcr; |
|---|
| | 398 | |
|---|
| | 399 | OGL_CMD(DrvGetLayerPaletteEntries, 4); |
|---|
| | 400 | OGL_PARAM(HDC, hdc); |
|---|
| | 401 | OGL_PARAM(int, iLayerPlane); |
|---|
| | 402 | OGL_PARAM(int, iStart); |
|---|
| | 403 | OGL_PARAM(int, cEntries); |
|---|
| | 404 | |
|---|
| | 405 | Assert(pClient->cbLastParam == sizeof(COLORREF)*cEntries); |
|---|
| | 406 | pcr = (COLORREF *)pClient->pLastParam; |
|---|
| | 407 | |
|---|
| | 408 | Log(("DrvGetLayerPaletteEntries %x %d %d %d %x\n", hdc, iLayerPlane, iStart, cEntries, pcr)); |
|---|
| | 409 | pClient->lastretval = wglGetLayerPaletteEntries(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, iStart, cEntries, pcr); |
|---|
| | 410 | if (!pClient->lastretval) |
|---|
| | 411 | Log(("wglGetLayerPaletteEntries failed with %d\n", GetLastError())); |
|---|
| | 412 | pClient->fHasLastError = true; |
|---|
| | 413 | pClient->ulLastError = GetLastError(); |
|---|
| | 414 | } |
|---|
| | 415 | |
|---|
| | 416 | void vboxglDrvDescribePixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer) |
|---|
| | 417 | { |
|---|
| | 418 | LPPIXELFORMATDESCRIPTOR ppfd; |
|---|
| | 419 | |
|---|
| | 420 | OGL_CMD(DrvDescribePixelFormat, 3); |
|---|
| | 421 | OGL_PARAM(HDC, hdc); |
|---|
| | 422 | OGL_PARAM(int, iPixelFormat); |
|---|
| | 423 | OGL_PARAM(UINT, nBytes); |
|---|
| | 424 | Assert(pClient->cbLastParam == nBytes); |
|---|
| | 425 | ppfd = (LPPIXELFORMATDESCRIPTOR)pClient->pLastParam; |
|---|
| | 426 | |
|---|
| | 427 | hdc = VBOX_OGL_GUEST_TO_HOST_HDC(hdc); |
|---|
| | 428 | if (!hdc) |
|---|
| | 429 | hdc = GetDC(0); |
|---|
| | 430 | |
|---|
| | 431 | Log(("DrvDescribePixelFormat %x %d %d %x\n", hdc, iPixelFormat, nBytes, ppfd)); |
|---|
| | 432 | pClient->lastretval = DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd); |
|---|
| | 433 | if (!pClient->lastretval) |
|---|
| | 434 | Log(("DescribePixelFormat failed with %d\n", GetLastError())); |
|---|
| | 435 | |
|---|
| | 436 | pClient->fHasLastError = true; |
|---|
| | 437 | pClient->ulLastError = GetLastError(); |
|---|
| | 438 | |
|---|
| | 439 | if (!VBOX_OGL_GUEST_TO_HOST_HDC(hdc)) |
|---|
| | 440 | ReleaseDC(0, pClient->hdc); |
|---|
| | 441 | } |
|---|
| | 442 | |
|---|
| | 443 | bool vboxDrvIsExtensionAvailable(char *pszExtFunctionName) |
|---|
| | 444 | { |
|---|
| | 445 | bool fAvailable = !!wglGetProcAddress(pszExtFunctionName); |
|---|
| | 446 | |
|---|
| | 447 | Log(("vboxDrvIsExtensionAvailable %s -> %d\n", pszExtFunctionName, fAvailable)); |
|---|