2 * Copyright 2009 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * This file holds the function implementation for one of the rbug extensions.
27 * Prototypes and declerations of functions and structs is in the same folder
28 * in the header file matching this file's name.
30 * The functions starting rbug_send_* encodes a call to the write format and
31 * sends that to the supplied connection, while functions starting with
32 * rbug_demarshal_* demarshal data in the wire protocol.
34 * Functions ending with _reply are replies to requests.
37 #include "rbug_internal.h"
38 #include "rbug/rbug_context.h"
40 int rbug_send_context_list(struct rbug_connection
*__con
,
45 uint8_t *__data
= NULL
;
53 __data
= (uint8_t*)MALLOC(__len
);
57 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST
));
58 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
66 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_LIST
, __len
);
67 rbug_connection_write(__con
, __data
, __len
);
68 __ret
= rbug_connection_send_finish(__con
, __serial
);
75 int rbug_send_context_info(struct rbug_connection
*__con
,
76 rbug_context_t context
,
81 uint8_t *__data
= NULL
;
90 __data
= (uint8_t*)MALLOC(__len
);
94 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO
));
95 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
96 WRITE(8, rbug_context_t
, context
); /* context */
101 if (__pos
!= __len
) {
104 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_INFO
, __len
);
105 rbug_connection_write(__con
, __data
, __len
);
106 __ret
= rbug_connection_send_finish(__con
, __serial
);
113 int rbug_send_context_block_draw(struct rbug_connection
*__con
,
114 rbug_context_t context
,
119 uint8_t *__data
= NULL
;
123 LEN(8); /* context */
128 __data
= (uint8_t*)MALLOC(__len
);
132 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_BLOCK_DRAW
));
133 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
134 WRITE(8, rbug_context_t
, context
); /* context */
139 if (__pos
!= __len
) {
142 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_BLOCK_DRAW
, __len
);
143 rbug_connection_write(__con
, __data
, __len
);
144 __ret
= rbug_connection_send_finish(__con
, __serial
);
151 int rbug_send_context_unblock_draw(struct rbug_connection
*__con
,
152 rbug_context_t context
,
157 uint8_t *__data
= NULL
;
161 LEN(8); /* context */
166 __data
= (uint8_t*)MALLOC(__len
);
170 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_UNBLOCK_DRAW
));
171 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
172 WRITE(8, rbug_context_t
, context
); /* context */
177 if (__pos
!= __len
) {
180 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_UNBLOCK_DRAW
, __len
);
181 rbug_connection_write(__con
, __data
, __len
);
182 __ret
= rbug_connection_send_finish(__con
, __serial
);
189 int rbug_send_context_list_reply(struct rbug_connection
*__con
,
191 rbug_context_t
*contexts
,
192 uint32_t contexts_len
,
197 uint8_t *__data
= NULL
;
202 LEN_ARRAY(8, contexts
); /* contexts */
207 __data
= (uint8_t*)MALLOC(__len
);
211 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY
));
212 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
213 WRITE(4, uint32_t, serial
); /* serial */
214 WRITE_ARRAY(8, rbug_context_t
, contexts
); /* contexts */
219 if (__pos
!= __len
) {
222 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_LIST_REPLY
, __len
);
223 rbug_connection_write(__con
, __data
, __len
);
224 __ret
= rbug_connection_send_finish(__con
, __serial
);
231 int rbug_send_context_info_reply(struct rbug_connection
*__con
,
233 rbug_texture_t
*cbufs
,
235 rbug_texture_t zdbuf
,
241 uint8_t *__data
= NULL
;
246 LEN_ARRAY(8, cbufs
); /* cbufs */
248 LEN(1); /* blocked */
253 __data
= (uint8_t*)MALLOC(__len
);
257 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY
));
258 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
259 WRITE(4, uint32_t, serial
); /* serial */
260 WRITE_ARRAY(8, rbug_texture_t
, cbufs
); /* cbufs */
261 WRITE(8, rbug_texture_t
, zdbuf
); /* zdbuf */
262 WRITE(1, uint8_t, blocked
); /* blocked */
267 if (__pos
!= __len
) {
270 rbug_connection_send_start(__con
, RBUG_OP_CONTEXT_INFO_REPLY
, __len
);
271 rbug_connection_write(__con
, __data
, __len
);
272 __ret
= rbug_connection_send_finish(__con
, __serial
);
279 struct rbug_proto_context_list
* rbug_demarshal_context_list(struct rbug_proto_header
*header
)
283 uint8_t *data
= NULL
;
284 struct rbug_proto_context_list
*ret
;
288 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_LIST
)
292 len
= header
->length
* 4;
293 data
= (uint8_t*)&header
[1];
294 ret
= MALLOC(sizeof(*ret
));
298 ret
->header
.__message
= header
;
299 ret
->header
.opcode
= header
->opcode
;
305 struct rbug_proto_context_info
* rbug_demarshal_context_info(struct rbug_proto_header
*header
)
309 uint8_t *data
= NULL
;
310 struct rbug_proto_context_info
*ret
;
314 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_INFO
)
318 len
= header
->length
* 4;
319 data
= (uint8_t*)&header
[1];
320 ret
= MALLOC(sizeof(*ret
));
324 ret
->header
.__message
= header
;
325 ret
->header
.opcode
= header
->opcode
;
327 READ(8, rbug_context_t
, context
); /* context */
332 struct rbug_proto_context_block_draw
* rbug_demarshal_context_block_draw(struct rbug_proto_header
*header
)
336 uint8_t *data
= NULL
;
337 struct rbug_proto_context_block_draw
*ret
;
341 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_BLOCK_DRAW
)
345 len
= header
->length
* 4;
346 data
= (uint8_t*)&header
[1];
347 ret
= MALLOC(sizeof(*ret
));
351 ret
->header
.__message
= header
;
352 ret
->header
.opcode
= header
->opcode
;
354 READ(8, rbug_context_t
, context
); /* context */
359 struct rbug_proto_context_unblock_draw
* rbug_demarshal_context_unblock_draw(struct rbug_proto_header
*header
)
363 uint8_t *data
= NULL
;
364 struct rbug_proto_context_unblock_draw
*ret
;
368 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_UNBLOCK_DRAW
)
372 len
= header
->length
* 4;
373 data
= (uint8_t*)&header
[1];
374 ret
= MALLOC(sizeof(*ret
));
378 ret
->header
.__message
= header
;
379 ret
->header
.opcode
= header
->opcode
;
381 READ(8, rbug_context_t
, context
); /* context */
386 struct rbug_proto_context_list_reply
* rbug_demarshal_context_list_reply(struct rbug_proto_header
*header
)
390 uint8_t *data
= NULL
;
391 struct rbug_proto_context_list_reply
*ret
;
395 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_LIST_REPLY
)
399 len
= header
->length
* 4;
400 data
= (uint8_t*)&header
[1];
401 ret
= MALLOC(sizeof(*ret
));
405 ret
->header
.__message
= header
;
406 ret
->header
.opcode
= header
->opcode
;
408 READ(4, uint32_t, serial
); /* serial */
409 READ_ARRAY(8, rbug_context_t
, contexts
); /* contexts */
414 struct rbug_proto_context_info_reply
* rbug_demarshal_context_info_reply(struct rbug_proto_header
*header
)
418 uint8_t *data
= NULL
;
419 struct rbug_proto_context_info_reply
*ret
;
423 if (header
->opcode
!= (int16_t)RBUG_OP_CONTEXT_INFO_REPLY
)
427 len
= header
->length
* 4;
428 data
= (uint8_t*)&header
[1];
429 ret
= MALLOC(sizeof(*ret
));
433 ret
->header
.__message
= header
;
434 ret
->header
.opcode
= header
->opcode
;
436 READ(4, uint32_t, serial
); /* serial */
437 READ_ARRAY(8, rbug_texture_t
, cbufs
); /* cbufs */
438 READ(8, rbug_texture_t
, zdbuf
); /* zdbuf */
439 READ(1, uint8_t, blocked
); /* blocked */