1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxDisp -- Windows Guest OpenGL ICD
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
11 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
12 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
13 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | *
|
---|
15 | * If you received this file as part of a commercial VirtualBox
|
---|
16 | * distribution, then only the terms of your commercial VirtualBox
|
---|
17 | * license agreement apply instead of the previous paragraph.
|
---|
18 | *
|
---|
19 | */
|
---|
20 | #define VBOX_OGL_WITH_CMD_STRINGS
|
---|
21 | #include "VBoxOGL.h"
|
---|
22 | #include <VBox/version.h>
|
---|
23 | #include <stdarg.h>
|
---|
24 | #include <stdio.h>
|
---|
25 |
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Queue a new OpenGL command
|
---|
29 | *
|
---|
30 | * @param enmOp OpenGL command op
|
---|
31 | * @param cParams Number of parameters
|
---|
32 | * @param cbParams Memory needed for parameters
|
---|
33 | */
|
---|
34 | void VBoxCmdStart(uint32_t enmOp, uint32_t cParams, uint32_t cbParams)
|
---|
35 | {
|
---|
36 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
37 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
38 |
|
---|
39 | DbgPrintf(("Start %s cParams=%d cbParams=%d\n", pszVBoxOGLCmd[enmOp], cParams, cbParams));
|
---|
40 |
|
---|
41 | if (pCtx->pCurrentCmd + cParams*VBOX_OGL_CMD_ALIGN + cbParams + sizeof(VBOX_OGL_CMD) >= pCtx->pCmdBufferEnd)
|
---|
42 | {
|
---|
43 | DbgPrintf(("VBoxCmdStart -> cmd queue full -> flush!\n"));
|
---|
44 | VBoxOGLFlush();
|
---|
45 | pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
46 | }
|
---|
47 | Assert(pCtx->pCurrentCmd + cbParams + sizeof(VBOX_OGL_CMD) < pCtx->pCmdBufferEnd);
|
---|
48 |
|
---|
49 | #ifdef VBOX_OGL_CMD_STRICT
|
---|
50 | pCmd->Magic = VBOX_OGL_CMD_MAGIC;
|
---|
51 | #endif
|
---|
52 | pCmd->enmOp = enmOp;
|
---|
53 | pCmd->cbCmd = sizeof(VBOX_OGL_CMD);
|
---|
54 | pCmd->cParams = cParams;
|
---|
55 | return;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Add a parameter (fixed size) to the currently queued OpenGL command
|
---|
60 | *
|
---|
61 | * @param pParam Parameter ptr
|
---|
62 | * @param cbParam Parameter value size
|
---|
63 | */
|
---|
64 | void VBoxCmdSaveParameter(uint8_t *pParam, uint32_t cbParam)
|
---|
65 | {
|
---|
66 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
67 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
68 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
69 |
|
---|
70 | Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
|
---|
71 |
|
---|
72 | #ifdef DEBUG
|
---|
73 | switch(cbParam)
|
---|
74 | {
|
---|
75 | case 1:
|
---|
76 | DbgPrintf(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint8_t *)pParam, cbParam));
|
---|
77 | break;
|
---|
78 | case 2:
|
---|
79 | DbgPrintf(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint16_t *)pParam, cbParam));
|
---|
80 | break;
|
---|
81 | case 4:
|
---|
82 | default:
|
---|
83 | DbgPrintf(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint32_t *)pParam, cbParam));
|
---|
84 | break;
|
---|
85 | }
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | memcpy(pCurrentCmdBlock, pParam, cbParam);
|
---|
89 | pCmd->cbCmd += cbParam;
|
---|
90 | pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Add a parameter (variable size) to the currently queued OpenGL command
|
---|
95 | *
|
---|
96 | * @param pParam Parameter ptr
|
---|
97 | * @param cbParam Parameter value size
|
---|
98 | */
|
---|
99 | void VBoxCmdSaveMemParameter(uint8_t *pParam, uint32_t cbParam)
|
---|
100 | {
|
---|
101 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
102 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
103 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
104 | PVBOX_OGL_VAR_PARAM pCurrentParam = (PVBOX_OGL_VAR_PARAM)pCurrentCmdBlock;
|
---|
105 |
|
---|
106 | Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
|
---|
107 |
|
---|
108 | DbgPrintf(("Mem Param %s cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], cbParam));
|
---|
109 |
|
---|
110 | #ifdef VBOX_OGL_CMD_STRICT
|
---|
111 | pCurrentParam->Magic = VBOX_OGL_CMD_MAGIC;
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | if (pParam && cbParam)
|
---|
115 | {
|
---|
116 | pCurrentParam->cbParam = cbParam;
|
---|
117 | memcpy(pCurrentParam+1, pParam, cbParam);
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | pCurrentParam->cbParam = 0;
|
---|
122 | cbParam = 0;
|
---|
123 | }
|
---|
124 | pCmd->cbCmd += sizeof(*pCurrentParam) + cbParam;
|
---|
125 | pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Finish the queued command
|
---|
130 | *
|
---|
131 | * @param enmOp OpenGL command op
|
---|
132 | */
|
---|
133 | void VBoxCmdStop(uint32_t enmOp)
|
---|
134 | {
|
---|
135 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
136 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
137 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
138 |
|
---|
139 | DbgPrintf(("End %s cbCmd=%d\n", pszVBoxOGLCmd[pCmd->enmOp], pCmd->cbCmd));
|
---|
140 |
|
---|
141 | pCtx->pCurrentCmd = pCurrentCmdBlock;
|
---|
142 | pCtx->cCommands++;
|
---|
143 | }
|
---|
144 |
|
---|