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 "c99_alloca.h"
39 #include "rbug_internal.h"
40 #include "rbug_texture.h"
42 int rbug_send_texture_list(struct rbug_connection
*__con
,
47 uint8_t *__data
= NULL
;
55 __data
= (uint8_t*)MALLOC(__len
);
59 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST
));
60 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
68 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_LIST
, __len
);
69 rbug_connection_write(__con
, __data
, __len
);
70 __ret
= rbug_connection_send_finish(__con
, __serial
);
77 int rbug_send_texture_info(struct rbug_connection
*__con
,
78 rbug_texture_t texture
,
83 uint8_t *__data
= NULL
;
92 __data
= (uint8_t*)MALLOC(__len
);
96 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO
));
97 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
98 WRITE(8, rbug_texture_t
, texture
); /* texture */
103 if (__pos
!= __len
) {
106 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_INFO
, __len
);
107 rbug_connection_write(__con
, __data
, __len
);
108 __ret
= rbug_connection_send_finish(__con
, __serial
);
115 int rbug_send_texture_write(struct rbug_connection
*__con
,
116 rbug_texture_t texture
,
131 uint8_t *__data
= NULL
;
135 LEN(8); /* texture */
143 LEN_ARRAY(1, data
); /* data */
149 __data
= (uint8_t*)MALLOC(__len
);
153 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE
));
154 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
155 WRITE(8, rbug_texture_t
, texture
); /* texture */
156 WRITE(4, uint32_t, face
); /* face */
157 WRITE(4, uint32_t, level
); /* level */
158 WRITE(4, uint32_t, zslice
); /* zslice */
159 WRITE(4, uint32_t, x
); /* x */
160 WRITE(4, uint32_t, y
); /* y */
161 WRITE(4, uint32_t, w
); /* w */
162 WRITE(4, uint32_t, h
); /* h */
163 WRITE_ARRAY(1, uint8_t, data
); /* data */
164 WRITE(4, uint32_t, stride
); /* stride */
169 if (__pos
!= __len
) {
172 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_WRITE
, __len
);
173 rbug_connection_write(__con
, __data
, __len
);
174 __ret
= rbug_connection_send_finish(__con
, __serial
);
181 int rbug_send_texture_read(struct rbug_connection
*__con
,
182 rbug_texture_t texture
,
194 uint8_t *__data
= NULL
;
198 LEN(8); /* texture */
210 __data
= (uint8_t*)MALLOC(__len
);
214 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ
));
215 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
216 WRITE(8, rbug_texture_t
, texture
); /* texture */
217 WRITE(4, uint32_t, face
); /* face */
218 WRITE(4, uint32_t, level
); /* level */
219 WRITE(4, uint32_t, zslice
); /* zslice */
220 WRITE(4, uint32_t, x
); /* x */
221 WRITE(4, uint32_t, y
); /* y */
222 WRITE(4, uint32_t, w
); /* w */
223 WRITE(4, uint32_t, h
); /* h */
228 if (__pos
!= __len
) {
231 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_READ
, __len
);
232 rbug_connection_write(__con
, __data
, __len
);
233 __ret
= rbug_connection_send_finish(__con
, __serial
);
240 int rbug_send_texture_list_reply(struct rbug_connection
*__con
,
242 rbug_texture_t
*textures
,
243 uint32_t textures_len
,
248 uint8_t *__data
= NULL
;
253 LEN_ARRAY(8, textures
); /* textures */
258 __data
= (uint8_t*)MALLOC(__len
);
262 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY
));
263 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
264 WRITE(4, uint32_t, serial
); /* serial */
265 WRITE_ARRAY(8, rbug_texture_t
, textures
); /* textures */
270 if (__pos
!= __len
) {
273 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_LIST_REPLY
, __len
);
274 rbug_connection_write(__con
, __data
, __len
);
275 __ret
= rbug_connection_send_finish(__con
, __serial
);
282 int rbug_send_texture_info_reply(struct rbug_connection
*__con
,
302 uint8_t *__data
= NULL
;
304 uint32_t *height
= alloca(sizeof(uint32_t) * height_len
);
305 uint32_t *depth
= alloca(sizeof(uint32_t) * height_len
);
311 LEN_ARRAY(4, width
); /* width */
312 LEN_ARRAY(4, height
); /* height */
313 LEN_ARRAY(4, depth
); /* depth */
316 LEN(4); /* blocksize */
317 LEN(4); /* last_level */
318 LEN(4); /* nr_samples */
319 LEN(4); /* tex_usage */
324 __data
= (uint8_t*)MALLOC(__len
);
328 for (int i
= 0; i
< height_len
; i
++)
330 for (int i
= 0; i
< depth_len
; i
++)
333 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY
));
334 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
335 WRITE(4, uint32_t, serial
); /* serial */
336 WRITE(4, uint32_t, target
); /* target */
337 WRITE(4, uint32_t, format
); /* format */
338 WRITE_ARRAY(4, uint32_t, width
); /* width */
339 WRITE_ARRAY(4, uint32_t, height
); /* height */
340 WRITE_ARRAY(4, uint32_t, depth
); /* depth */
341 WRITE(4, uint32_t, blockw
); /* blockw */
342 WRITE(4, uint32_t, blockh
); /* blockh */
343 WRITE(4, uint32_t, blocksize
); /* blocksize */
344 WRITE(4, uint32_t, last_level
); /* last_level */
345 WRITE(4, uint32_t, nr_samples
); /* nr_samples */
346 WRITE(4, uint32_t, tex_usage
); /* tex_usage */
351 if (__pos
!= __len
) {
354 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_INFO_REPLY
, __len
);
355 rbug_connection_write(__con
, __data
, __len
);
356 __ret
= rbug_connection_send_finish(__con
, __serial
);
363 int rbug_send_texture_read_reply(struct rbug_connection
*__con
,
376 uint8_t *__data
= NULL
;
384 LEN(4); /* blocksize */
385 LEN_ARRAY(1, data
); /* data */
391 __data
= (uint8_t*)MALLOC(__len
);
395 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY
));
396 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
397 WRITE(4, uint32_t, serial
); /* serial */
398 WRITE(4, uint32_t, format
); /* format */
399 WRITE(4, uint32_t, blockw
); /* blockw */
400 WRITE(4, uint32_t, blockh
); /* blockh */
401 WRITE(4, uint32_t, blocksize
); /* blocksize */
402 WRITE_ARRAY(1, uint8_t, data
); /* data */
403 WRITE(4, uint32_t, stride
); /* stride */
408 if (__pos
!= __len
) {
411 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_READ_REPLY
, __len
);
412 rbug_connection_write(__con
, __data
, __len
);
413 __ret
= rbug_connection_send_finish(__con
, __serial
);
420 struct rbug_proto_texture_list
* rbug_demarshal_texture_list(struct rbug_proto_header
*header
)
422 struct rbug_proto_texture_list
*ret
;
426 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_LIST
)
429 ret
= MALLOC(sizeof(*ret
));
433 ret
->header
.__message
= header
;
434 ret
->header
.opcode
= header
->opcode
;
439 struct rbug_proto_texture_info
* rbug_demarshal_texture_info(struct rbug_proto_header
*header
)
443 uint8_t *data
= NULL
;
444 struct rbug_proto_texture_info
*ret
;
448 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_INFO
)
452 len
= header
->length
* 4;
453 data
= (uint8_t*)&header
[1];
454 ret
= MALLOC(sizeof(*ret
));
458 ret
->header
.__message
= header
;
459 ret
->header
.opcode
= header
->opcode
;
461 READ(8, rbug_texture_t
, texture
); /* texture */
466 struct rbug_proto_texture_write
* rbug_demarshal_texture_write(struct rbug_proto_header
*header
)
470 uint8_t *data
= NULL
;
471 struct rbug_proto_texture_write
*ret
;
475 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_WRITE
)
479 len
= header
->length
* 4;
480 data
= (uint8_t*)&header
[1];
481 ret
= MALLOC(sizeof(*ret
));
485 ret
->header
.__message
= header
;
486 ret
->header
.opcode
= header
->opcode
;
488 READ(8, rbug_texture_t
, texture
); /* texture */
489 READ(4, uint32_t, face
); /* face */
490 READ(4, uint32_t, level
); /* level */
491 READ(4, uint32_t, zslice
); /* zslice */
492 READ(4, uint32_t, x
); /* x */
493 READ(4, uint32_t, y
); /* y */
494 READ(4, uint32_t, w
); /* w */
495 READ(4, uint32_t, h
); /* h */
496 READ_ARRAY(1, uint8_t, data
); /* data */
497 READ(4, uint32_t, stride
); /* stride */
502 struct rbug_proto_texture_read
* rbug_demarshal_texture_read(struct rbug_proto_header
*header
)
506 uint8_t *data
= NULL
;
507 struct rbug_proto_texture_read
*ret
;
511 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_READ
)
515 len
= header
->length
* 4;
516 data
= (uint8_t*)&header
[1];
517 ret
= MALLOC(sizeof(*ret
));
521 ret
->header
.__message
= header
;
522 ret
->header
.opcode
= header
->opcode
;
524 READ(8, rbug_texture_t
, texture
); /* texture */
525 READ(4, uint32_t, face
); /* face */
526 READ(4, uint32_t, level
); /* level */
527 READ(4, uint32_t, zslice
); /* zslice */
528 READ(4, uint32_t, x
); /* x */
529 READ(4, uint32_t, y
); /* y */
530 READ(4, uint32_t, w
); /* w */
531 READ(4, uint32_t, h
); /* h */
536 struct rbug_proto_texture_list_reply
* rbug_demarshal_texture_list_reply(struct rbug_proto_header
*header
)
540 uint8_t *data
= NULL
;
541 struct rbug_proto_texture_list_reply
*ret
;
545 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_LIST_REPLY
)
549 len
= header
->length
* 4;
550 data
= (uint8_t*)&header
[1];
551 ret
= MALLOC(sizeof(*ret
));
555 ret
->header
.__message
= header
;
556 ret
->header
.opcode
= header
->opcode
;
558 READ(4, uint32_t, serial
); /* serial */
559 READ_ARRAY(8, rbug_texture_t
, textures
); /* textures */
564 struct rbug_proto_texture_info_reply
* rbug_demarshal_texture_info_reply(struct rbug_proto_header
*header
)
568 uint8_t *data
= NULL
;
569 struct rbug_proto_texture_info_reply
*ret
;
573 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_INFO_REPLY
)
577 len
= header
->length
* 4;
578 data
= (uint8_t*)&header
[1];
579 ret
= MALLOC(sizeof(*ret
));
583 ret
->header
.__message
= header
;
584 ret
->header
.opcode
= header
->opcode
;
586 READ(4, uint32_t, serial
); /* serial */
587 READ(4, uint32_t, target
); /* target */
588 READ(4, uint32_t, format
); /* format */
589 READ_ARRAY(4, uint32_t, width
); /* width */
590 READ_ARRAY(4, uint32_t, height
); /* height */
591 READ_ARRAY(4, uint32_t, depth
); /* depth */
592 READ(4, uint32_t, blockw
); /* blockw */
593 READ(4, uint32_t, blockh
); /* blockh */
594 READ(4, uint32_t, blocksize
); /* blocksize */
595 READ(4, uint32_t, last_level
); /* last_level */
596 READ(4, uint32_t, nr_samples
); /* nr_samples */
597 READ(4, uint32_t, tex_usage
); /* tex_usage */
602 struct rbug_proto_texture_read_reply
* rbug_demarshal_texture_read_reply(struct rbug_proto_header
*header
)
606 uint8_t *data
= NULL
;
607 struct rbug_proto_texture_read_reply
*ret
;
611 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_READ_REPLY
)
615 len
= header
->length
* 4;
616 data
= (uint8_t*)&header
[1];
617 ret
= MALLOC(sizeof(*ret
));
621 ret
->header
.__message
= header
;
622 ret
->header
.opcode
= header
->opcode
;
624 READ(4, uint32_t, serial
); /* serial */
625 READ(4, uint32_t, format
); /* format */
626 READ(4, uint32_t, blockw
); /* blockw */
627 READ(4, uint32_t, blockh
); /* blockh */
628 READ(4, uint32_t, blocksize
); /* blocksize */
629 READ_ARRAY(1, uint8_t, data
); /* data */
630 READ(4, uint32_t, stride
); /* stride */