VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_net.c@ 68643

Last change on this file since 68643 was 63205, checked in by vboxsync, 8 years ago

GA/common/crOpenGL: warnings (gcc)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
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 "cr_pack.h"
8#include "cr_mem.h"
9#include "cr_net.h"
10#include "cr_pixeldata.h"
11#include "cr_protocol.h"
12#include "cr_error.h"
13#include "packspu.h"
14#include "packspu_proto.h"
15
16uint32_t g_u32VBoxHostCaps = 0;
17
18static void
19packspuWriteback( const CRMessageWriteback *wb )
20{
21 int *writeback;
22 crMemcpy( &writeback, &(wb->writeback_ptr), sizeof( writeback ) );
23 *writeback = 0;
24}
25
26/**
27 * XXX Note that this routine is identical to crNetRecvReadback except
28 * we set *writeback=0 instead of decrementing it. Hmmm.
29 */
30static void
31packspuReadback( const CRMessageReadback *rb, unsigned int len )
32{
33 /* minus the header, the destination pointer,
34 * *and* the implicit writeback pointer at the head. */
35
36 int payload_len = len - sizeof( *rb );
37 int *writeback;
38 void *dest_ptr;
39 crMemcpy( &writeback, &(rb->writeback_ptr), sizeof( writeback ) );
40 crMemcpy( &dest_ptr, &(rb->readback_ptr), sizeof( dest_ptr ) );
41
42 *writeback = 0;
43 crMemcpy( dest_ptr, ((char *)rb) + sizeof(*rb), payload_len );
44}
45
46static void
47packspuReadPixels( const CRMessageReadPixels *rp, unsigned int len )
48{
49 crNetRecvReadPixels( rp, len );
50 --pack_spu.ReadPixels;
51}
52
53static int
54packspuReceiveData( CRConnection *conn, CRMessage *msg, unsigned int len )
55{
56 RT_NOREF(conn);
57 if (msg->header.type == CR_MESSAGE_REDIR_PTR)
58 msg = (CRMessage*) msg->redirptr.pMessage;
59
60 switch( msg->header.type )
61 {
62 case CR_MESSAGE_READ_PIXELS:
63 packspuReadPixels( &(msg->readPixels), len );
64 break;
65 case CR_MESSAGE_WRITEBACK:
66 packspuWriteback( &(msg->writeback) );
67 break;
68 case CR_MESSAGE_READBACK:
69 packspuReadback( &(msg->readback), len );
70 break;
71 default:
72 /*crWarning( "Why is the pack SPU getting a message of type 0x%x?", msg->type ); */
73 return 0; /* NOT HANDLED */
74 }
75 return 1; /* HANDLED */
76}
77
78static CRMessageOpcodes *
79__prependHeader( CRPackBuffer *buf, unsigned int *len, unsigned int senderID )
80{
81 int num_opcodes;
82 CRMessageOpcodes *hdr;
83 RT_NOREF(senderID);
84
85 CRASSERT( buf );
86 CRASSERT( buf->opcode_current < buf->opcode_start );
87 CRASSERT( buf->opcode_current >= buf->opcode_end );
88 CRASSERT( buf->data_current > buf->data_start );
89 CRASSERT( buf->data_current <= buf->data_end );
90
91 num_opcodes = buf->opcode_start - buf->opcode_current;
92 hdr = (CRMessageOpcodes *)
93 ( buf->data_start - ( ( num_opcodes + 3 ) & ~0x3 ) - sizeof(*hdr) );
94
95 CRASSERT( (void *) hdr >= buf->pack );
96
97 if (pack_spu.swap)
98 {
99 hdr->header.type = (CRMessageType) SWAP32(CR_MESSAGE_OPCODES);
100 hdr->numOpcodes = SWAP32(num_opcodes);
101 }
102 else
103 {
104 hdr->header.type = CR_MESSAGE_OPCODES;
105 hdr->numOpcodes = num_opcodes;
106 }
107
108 *len = buf->data_current - (unsigned char *) hdr;
109
110 return hdr;
111}
112
113
114/*
115 * This is called from either the Pack SPU and the packer library whenever
116 * we need to send a data buffer to the server.
117 */
118void packspuFlush(void *arg )
119{
120 ThreadInfo *thread = (ThreadInfo *) arg;
121 ContextInfo *ctx;
122 unsigned int len;
123 CRMessageOpcodes *hdr;
124 CRPackBuffer *buf;
125
126 /* we should _always_ pass a valid <arg> value */
127 CRASSERT(thread && thread->inUse);
128#ifdef CHROMIUM_THREADSAFE
129 CR_LOCK_PACKER_CONTEXT(thread->packer);
130#endif
131 ctx = thread->currentContext;
132 buf = &(thread->buffer);
133 CRASSERT(buf);
134
135 if (ctx && ctx->fCheckZerroVertAttr)
136 crStateCurrentRecoverNew(ctx->clientState, &thread->packer->current);
137
138 /* We're done packing into the current buffer, unbind it */
139 crPackReleaseBuffer( thread->packer );
140
141 /*
142 printf("%s thread=%p thread->id = %d thread->pc=%p t2->id=%d t2->pc=%p packbuf=%p packbuf=%p\n",
143 __FUNCTION__, (void*) thread, (int) thread->id, thread->packer,
144 (int) t2->id, t2->packer,
145 buf->pack, thread->packer->buffer.pack);
146 */
147
148 if ( buf->opcode_current == buf->opcode_start ) {
149 /*
150 printf("%s early return\n", __FUNCTION__);
151 */
152 /* XXX these calls seem to help, but might be appropriate */
153 crPackSetBuffer( thread->packer, buf );
154 crPackResetPointers(thread->packer);
155#ifdef CHROMIUM_THREADSAFE
156 CR_UNLOCK_PACKER_CONTEXT(thread->packer);
157#endif
158 return;
159 }
160
161 hdr = __prependHeader( buf, &len, 0 );
162
163 CRASSERT( thread->netServer.conn );
164
165 if ( buf->holds_BeginEnd )
166 {
167 /*crDebug("crNetBarf %d, (%d)", len, buf->size);*/
168 crNetBarf( thread->netServer.conn, &(buf->pack), hdr, len );
169 }
170 else
171 {
172 /*crDebug("crNetSend %d, (%d)", len, buf->size);*/
173 crNetSend( thread->netServer.conn, &(buf->pack), hdr, len );
174 }
175
176 buf->pack = crNetAlloc( thread->netServer.conn );
177
178 /* The network may have found a new mtu */
179 buf->mtu = thread->netServer.conn->mtu;
180
181 crPackSetBuffer( thread->packer, buf );
182
183 crPackResetPointers(thread->packer);
184
185#ifdef CHROMIUM_THREADSAFE
186 CR_UNLOCK_PACKER_CONTEXT(thread->packer);
187#endif
188}
189
190
191/**
192 * XXX NOTE: there's a lot of duplicate code here common to the
193 * pack, tilesort and replicate SPUs. Try to simplify someday!
194 */
195void packspuHuge( CROpcode opcode, void *buf )
196{
197 GET_THREAD(thread);
198 unsigned int len;
199 unsigned char *src;
200 CRMessageOpcodes *msg;
201
202 CRASSERT(thread);
203
204 /* packet length is indicated by the variable length field, and
205 includes an additional word for the opcode (with alignment) and
206 a header */
207 len = ((unsigned int *) buf)[-1];
208 if (pack_spu.swap)
209 {
210 /* It's already been swapped, swap it back. */
211 len = SWAP32(len);
212 }
213 len += 4 + sizeof(CRMessageOpcodes);
214
215 /* write the opcode in just before the length */
216 ((unsigned char *) buf)[-5] = (unsigned char) opcode;
217
218 /* fix up the pointer to the packet to include the length & opcode
219 & header */
220 src = (unsigned char *) buf - 8 - sizeof(CRMessageOpcodes);
221
222 msg = (CRMessageOpcodes *) src;
223
224 if (pack_spu.swap)
225 {
226 msg->header.type = (CRMessageType) SWAP32(CR_MESSAGE_OPCODES);
227 msg->numOpcodes = SWAP32(1);
228 }
229 else
230 {
231 msg->header.type = CR_MESSAGE_OPCODES;
232 msg->numOpcodes = 1;
233 }
234
235 CRASSERT( thread->netServer.conn );
236 crNetSend( thread->netServer.conn, NULL, src, len );
237}
238
239static void packspuFirstConnectToServer( CRNetServer *server
240#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
241 , struct VBOXUHGSMI *pHgsmi
242#endif
243 )
244{
245 crNetInit( packspuReceiveData, NULL );
246 crNetServerConnect( server
247#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
248 , pHgsmi
249#endif
250 );
251 if (server->conn)
252 {
253 g_u32VBoxHostCaps = crNetHostCapsGet();
254 crPackCapsSet(g_u32VBoxHostCaps);
255 }
256}
257
258void packspuConnectToServer( CRNetServer *server
259#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
260 , struct VBOXUHGSMI *pHgsmi
261#endif
262 )
263{
264 if (pack_spu.numThreads == 0) {
265 packspuFirstConnectToServer( server
266#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
267 , pHgsmi
268#endif
269 );
270 if (!server->conn) {
271 crError("packspuConnectToServer: no connection on first create!");
272 return;
273 }
274 pack_spu.swap = server->conn->swap;
275 }
276 else {
277 /* a new pthread */
278 crNetNewClient(server
279#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
280 , pHgsmi
281#endif
282 );
283 }
284}
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