1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <string.h>
|
---|
8 | #include "cr_mem.h"
|
---|
9 | #include "cr_string.h"
|
---|
10 | #include "cr_error.h"
|
---|
11 | #include "cr_glstate.h"
|
---|
12 | #include "server.h"
|
---|
13 |
|
---|
14 | #include <iprt/env.h>
|
---|
15 |
|
---|
16 | #ifdef WINDOWS
|
---|
17 | #pragma warning( disable: 4706 )
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | static void
|
---|
21 | setDefaults(void)
|
---|
22 | {
|
---|
23 | cr_server.run_queue = NULL;
|
---|
24 | cr_server.optimizeBucket = 1;
|
---|
25 | cr_server.useL2 = 0;
|
---|
26 | cr_server.maxBarrierCount = 0;
|
---|
27 | cr_server.ignore_papi = 0;
|
---|
28 | cr_server.only_swap_once = 0;
|
---|
29 | cr_server.overlapBlending = 0;
|
---|
30 | cr_server.debug_barriers = 0;
|
---|
31 | cr_server.sharedDisplayLists = 0;
|
---|
32 | cr_server.sharedTextureObjects = 0;
|
---|
33 | cr_server.sharedPrograms = 0;
|
---|
34 | cr_server.sharedWindows = 0;
|
---|
35 | cr_server.useDMX = 0;
|
---|
36 | cr_server.vpProjectionMatrixParameter = -1;
|
---|
37 | cr_server.vpProjectionMatrixVariable = NULL;
|
---|
38 | cr_server.currentProgram = 0;
|
---|
39 |
|
---|
40 | cr_server.num_overlap_intens = 0;
|
---|
41 | cr_server.overlap_intens = 0;
|
---|
42 | crMemset(&cr_server.MainContextInfo, 0, sizeof (cr_server.MainContextInfo));
|
---|
43 |
|
---|
44 | crMatrixInit(&cr_server.viewMatrix[0]);
|
---|
45 | crMatrixInit(&cr_server.viewMatrix[1]);
|
---|
46 | crMatrixInit(&cr_server.projectionMatrix[0]);
|
---|
47 | crMatrixInit(&cr_server.projectionMatrix[1]);
|
---|
48 | cr_server.currentEye = -1;
|
---|
49 |
|
---|
50 | cr_server.uniqueWindows = 0;
|
---|
51 |
|
---|
52 | cr_server.screenCount = 0;
|
---|
53 | cr_server.bUsePBOForReadback = GL_FALSE;
|
---|
54 | cr_server.bWindowsInitiallyHidden = GL_FALSE;
|
---|
55 |
|
---|
56 | cr_server.pfnNotifyEventCB = NULL;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* Check if host reports minimal OpenGL capabilities.
|
---|
60 | *
|
---|
61 | * Require OpenGL 2.1 or later.
|
---|
62 | *
|
---|
63 | * For example, on Windows host this may happen if host has no graphics
|
---|
64 | * card drivers installed or drivers were not properly signed or VBox
|
---|
65 | * is running via remote desktop session etc. Currently, we take care
|
---|
66 | * about Windows host only when specific RENDERER and VERSION strings
|
---|
67 | * returned in this case. Later this check should be expanded to the
|
---|
68 | * rest of hosts. */
|
---|
69 | static bool crServerHasInsufficientCaps()
|
---|
70 | {
|
---|
71 | const char *pszRealVersion;
|
---|
72 | int rc;
|
---|
73 | uint32_t u32VerMajor = 0;
|
---|
74 | uint32_t u32VerMinor = 0;
|
---|
75 | char *pszNext = NULL;
|
---|
76 |
|
---|
77 | if (!cr_server.head_spu)
|
---|
78 | return true;
|
---|
79 |
|
---|
80 | pszRealVersion = (const char *)cr_server.head_spu->dispatch_table.GetString(GL_REAL_VERSION);
|
---|
81 | if (!pszRealVersion)
|
---|
82 | return true; /* No version == insufficient. */
|
---|
83 |
|
---|
84 | rc = RTStrToUInt32Ex(pszRealVersion, &pszNext, 10, &u32VerMajor);
|
---|
85 | if ( RT_SUCCESS(rc)
|
---|
86 | && *pszNext == '.')
|
---|
87 | RTStrToUInt32Ex(pszNext + 1, NULL, 10, &u32VerMinor);
|
---|
88 |
|
---|
89 | crInfo("Host supports version %d.%d [%s]", u32VerMajor, u32VerMinor, pszRealVersion);
|
---|
90 |
|
---|
91 | if ( u32VerMajor > 2
|
---|
92 | || (u32VerMajor == 2 && u32VerMinor >= 1))
|
---|
93 | return false; /* >= 2.1, i.e. good enough. */
|
---|
94 |
|
---|
95 | return true; /* Insufficient. */
|
---|
96 | }
|
---|
97 |
|
---|
98 | void crServerSetVBoxConfigurationHGCM()
|
---|
99 | {
|
---|
100 | CRMuralInfo *defaultMural;
|
---|
101 |
|
---|
102 | int spu_ids[1] = {0};
|
---|
103 | char *spu_names[1] = {"render"};
|
---|
104 | char *spu_dir = NULL;
|
---|
105 | int i;
|
---|
106 | GLint dims[4];
|
---|
107 | const char * env;
|
---|
108 |
|
---|
109 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
110 | CRASSERT(defaultMural);
|
---|
111 |
|
---|
112 | /// @todo should be moved to addclient so we have a chain for each client
|
---|
113 |
|
---|
114 | setDefaults();
|
---|
115 |
|
---|
116 | /* Load the SPUs */
|
---|
117 | cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
|
---|
118 |
|
---|
119 | if (!cr_server.head_spu)
|
---|
120 | return;
|
---|
121 |
|
---|
122 |
|
---|
123 | env = RTEnvGet( "CR_SERVER_DEFAULT_VISUAL_BITS" );
|
---|
124 | if (env != NULL && env[0] != '\0')
|
---|
125 | {
|
---|
126 | unsigned int bits = (unsigned int)crStrParseI32(env, 0);
|
---|
127 | if (bits <= CR_ALL_BITS)
|
---|
128 | cr_server.fVisualBitsDefault = bits;
|
---|
129 | else
|
---|
130 | crWarning("invalid bits option %c", bits);
|
---|
131 | }
|
---|
132 | else
|
---|
133 | cr_server.fVisualBitsDefault = CR_RGB_BIT | CR_ALPHA_BIT | CR_DOUBLE_BIT;
|
---|
134 |
|
---|
135 |
|
---|
136 | env = RTEnvGet("CR_SERVER_CAPS");
|
---|
137 | if (env && env[0] != '\0')
|
---|
138 | {
|
---|
139 | cr_server.u32Caps = crStrParseI32(env, 0);
|
---|
140 | cr_server.u32Caps &= CR_VBOX_CAPS_ALL;
|
---|
141 | }
|
---|
142 | else
|
---|
143 | {
|
---|
144 | cr_server.u32Caps = CR_VBOX_CAP_TEX_PRESENT
|
---|
145 | | CR_VBOX_CAP_CMDVBVA
|
---|
146 | | CR_VBOX_CAP_CMDBLOCKS
|
---|
147 | | CR_VBOX_CAP_GETATTRIBSLOCATIONS
|
---|
148 | | CR_VBOX_CAP_CMDBLOCKS_FLUSH
|
---|
149 | ;
|
---|
150 | }
|
---|
151 |
|
---|
152 | if (crServerHasInsufficientCaps())
|
---|
153 | {
|
---|
154 | crDebug("Cfg: report minimal OpenGL capabilities");
|
---|
155 | cr_server.u32Caps |= CR_VBOX_CAP_HOST_CAPS_NOT_SUFFICIENT;
|
---|
156 | }
|
---|
157 |
|
---|
158 | crInfo("Cfg: u32Caps(%#x), fVisualBitsDefault(%#x)",
|
---|
159 | cr_server.u32Caps,
|
---|
160 | cr_server.fVisualBitsDefault);
|
---|
161 |
|
---|
162 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
|
---|
163 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
|
---|
164 |
|
---|
165 | defaultMural->gX = dims[0];
|
---|
166 | defaultMural->gY = dims[1];
|
---|
167 | defaultMural->width = dims[2];
|
---|
168 | defaultMural->height = dims[3];
|
---|
169 |
|
---|
170 | cr_server.mtu = 1024 * 250;
|
---|
171 |
|
---|
172 | cr_server.numClients = 0;
|
---|
173 | strcpy(cr_server.protocol, "vboxhgcm");
|
---|
174 |
|
---|
175 | for (i = 0; i < cr_server.numClients; i++)
|
---|
176 | {
|
---|
177 | CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
|
---|
178 | newClient->spu_id = 0;
|
---|
179 | newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
|
---|
180 | cr_server.tcpip_port,
|
---|
181 | cr_server.mtu, 0);
|
---|
182 | newClient->currentCtxInfo = &cr_server.MainContextInfo;
|
---|
183 | crServerAddToRunQueue(newClient);
|
---|
184 |
|
---|
185 | cr_server.clients[i] = newClient;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* set default client and mural */
|
---|
189 | if (cr_server.numClients > 0) {
|
---|
190 | cr_server.curClient = cr_server.clients[0];
|
---|
191 | cr_server.curClient->currentMural = defaultMural;
|
---|
192 | cr_server.client_spu_id =cr_server.clients[0]->spu_id;
|
---|
193 | }
|
---|
194 | }
|
---|