1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxDisp -- Windows Guest OpenGL ICD
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
16 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
17 | * additional information or have any questions.
|
---|
18 | */
|
---|
19 | #define VBOX_OGL_WITH_CMD_STRINGS
|
---|
20 | #include "VBoxOGL.h"
|
---|
21 | #include <VBox/version.h>
|
---|
22 | #include <stdarg.h>
|
---|
23 | #include <stdio.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Queue a new OpenGL command
|
---|
28 | *
|
---|
29 | * @param enmOp OpenGL command op
|
---|
30 | * @param cParams Number of parameters
|
---|
31 | * @param cbParams Memory needed for parameters
|
---|
32 | */
|
---|
33 | void VBoxCmdStart(uint32_t enmOp, uint32_t cParams, uint32_t cbParams)
|
---|
34 | {
|
---|
35 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
36 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
37 |
|
---|
38 | DbgPrintf2(("Start %s cParams=%d cbParams=%d\n", pszVBoxOGLCmd[enmOp], cParams, cbParams));
|
---|
39 |
|
---|
40 | if (pCtx->pCurrentCmd + cParams*VBOX_OGL_CMD_ALIGN + cbParams + sizeof(VBOX_OGL_CMD) >= pCtx->pCmdBufferEnd)
|
---|
41 | {
|
---|
42 | DbgPrintf(("VBoxCmdStart -> cmd queue full -> flush!\n"));
|
---|
43 | VBoxOGLFlush();
|
---|
44 | pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
45 | }
|
---|
46 | Assert(pCtx->pCurrentCmd + cbParams + sizeof(VBOX_OGL_CMD) < pCtx->pCmdBufferEnd);
|
---|
47 |
|
---|
48 | #ifdef VBOX_OGL_CMD_STRICT
|
---|
49 | pCmd->Magic = VBOX_OGL_CMD_MAGIC;
|
---|
50 | #endif
|
---|
51 | pCmd->enmOp = enmOp;
|
---|
52 | pCmd->cbCmd = sizeof(VBOX_OGL_CMD);
|
---|
53 | pCmd->cParams = cParams;
|
---|
54 | return;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Add a parameter (fixed size) to the currently queued OpenGL command
|
---|
59 | *
|
---|
60 | * @param pParam Parameter ptr
|
---|
61 | * @param cbParam Parameter value size
|
---|
62 | */
|
---|
63 | void VBoxCmdSaveParameter(uint8_t *pParam, uint32_t cbParam)
|
---|
64 | {
|
---|
65 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
66 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
67 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
68 |
|
---|
69 | Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
|
---|
70 |
|
---|
71 | #ifdef DEBUG
|
---|
72 | switch(cbParam)
|
---|
73 | {
|
---|
74 | case 1:
|
---|
75 | DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint8_t *)pParam, cbParam));
|
---|
76 | break;
|
---|
77 | case 2:
|
---|
78 | DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint16_t *)pParam, cbParam));
|
---|
79 | break;
|
---|
80 | case 4:
|
---|
81 | default:
|
---|
82 | DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint32_t *)pParam, cbParam));
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | memcpy(pCurrentCmdBlock, pParam, cbParam);
|
---|
88 | pCmd->cbCmd += cbParam;
|
---|
89 | pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Add a parameter (variable size) to the currently queued OpenGL command
|
---|
94 | *
|
---|
95 | * @param pParam Parameter ptr
|
---|
96 | * @param cbParam Parameter value size
|
---|
97 | */
|
---|
98 | void VBoxCmdSaveMemParameter(uint8_t *pParam, uint32_t cbParam)
|
---|
99 | {
|
---|
100 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
101 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
102 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
103 | PVBOX_OGL_VAR_PARAM pCurrentParam = (PVBOX_OGL_VAR_PARAM)pCurrentCmdBlock;
|
---|
104 |
|
---|
105 | Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
|
---|
106 |
|
---|
107 | DbgPrintf2(("Mem Param %s cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], cbParam));
|
---|
108 |
|
---|
109 | #ifdef VBOX_OGL_CMD_STRICT
|
---|
110 | pCurrentParam->Magic = VBOX_OGL_CMD_MAGIC;
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | if (pParam && cbParam)
|
---|
114 | {
|
---|
115 | pCurrentParam->cbParam = cbParam;
|
---|
116 | memcpy(pCurrentParam+1, pParam, cbParam);
|
---|
117 | }
|
---|
118 | else
|
---|
119 | {
|
---|
120 | pCurrentParam->cbParam = 0;
|
---|
121 | cbParam = 0;
|
---|
122 | }
|
---|
123 | pCmd->cbCmd += sizeof(*pCurrentParam) + cbParam;
|
---|
124 | pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Finish the queued command
|
---|
129 | *
|
---|
130 | * @param enmOp OpenGL command op
|
---|
131 | */
|
---|
132 | void VBoxCmdStop(uint32_t enmOp)
|
---|
133 | {
|
---|
134 | PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
|
---|
135 | PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
|
---|
136 | uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
|
---|
137 |
|
---|
138 | DbgPrintf2(("End %s cbCmd=%d\n", pszVBoxOGLCmd[pCmd->enmOp], pCmd->cbCmd));
|
---|
139 |
|
---|
140 | pCtx->pCurrentCmd = pCurrentCmdBlock;
|
---|
141 | pCtx->cCommands++;
|
---|
142 | }
|
---|
143 |
|
---|