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_texture.h"
40 int rbug_send_texture_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_TEXTURE_LIST
));
58 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
66 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_LIST
, __len
);
67 rbug_connection_write(__con
, __data
, __len
);
68 __ret
= rbug_connection_send_finish(__con
, __serial
);
75 int rbug_send_texture_info(struct rbug_connection
*__con
,
76 rbug_texture_t texture
,
81 uint8_t *__data
= NULL
;
90 __data
= (uint8_t*)MALLOC(__len
);
94 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO
));
95 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
96 WRITE(8, rbug_texture_t
, texture
); /* texture */
101 if (__pos
!= __len
) {
104 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_INFO
, __len
);
105 rbug_connection_write(__con
, __data
, __len
);
106 __ret
= rbug_connection_send_finish(__con
, __serial
);
113 int rbug_send_texture_write(struct rbug_connection
*__con
,
114 rbug_texture_t texture
,
129 uint8_t *__data
= NULL
;
133 LEN(8); /* texture */
141 LEN_ARRAY(1, data
); /* data */
147 __data
= (uint8_t*)MALLOC(__len
);
151 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE
));
152 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
153 WRITE(8, rbug_texture_t
, texture
); /* texture */
154 WRITE(4, uint32_t, face
); /* face */
155 WRITE(4, uint32_t, level
); /* level */
156 WRITE(4, uint32_t, zslice
); /* zslice */
157 WRITE(4, uint32_t, x
); /* x */
158 WRITE(4, uint32_t, y
); /* y */
159 WRITE(4, uint32_t, w
); /* w */
160 WRITE(4, uint32_t, h
); /* h */
161 WRITE_ARRAY(1, uint8_t, data
); /* data */
162 WRITE(4, uint32_t, stride
); /* stride */
167 if (__pos
!= __len
) {
170 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_WRITE
, __len
);
171 rbug_connection_write(__con
, __data
, __len
);
172 __ret
= rbug_connection_send_finish(__con
, __serial
);
179 int rbug_send_texture_read(struct rbug_connection
*__con
,
180 rbug_texture_t texture
,
192 uint8_t *__data
= NULL
;
196 LEN(8); /* texture */
208 __data
= (uint8_t*)MALLOC(__len
);
212 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ
));
213 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
214 WRITE(8, rbug_texture_t
, texture
); /* texture */
215 WRITE(4, uint32_t, face
); /* face */
216 WRITE(4, uint32_t, level
); /* level */
217 WRITE(4, uint32_t, zslice
); /* zslice */
218 WRITE(4, uint32_t, x
); /* x */
219 WRITE(4, uint32_t, y
); /* y */
220 WRITE(4, uint32_t, w
); /* w */
221 WRITE(4, uint32_t, h
); /* h */
226 if (__pos
!= __len
) {
229 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_READ
, __len
);
230 rbug_connection_write(__con
, __data
, __len
);
231 __ret
= rbug_connection_send_finish(__con
, __serial
);
238 int rbug_send_texture_list_reply(struct rbug_connection
*__con
,
240 rbug_texture_t
*textures
,
241 uint32_t textures_len
,
246 uint8_t *__data
= NULL
;
251 LEN_ARRAY(8, textures
); /* textures */
256 __data
= (uint8_t*)MALLOC(__len
);
260 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY
));
261 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
262 WRITE(4, uint32_t, serial
); /* serial */
263 WRITE_ARRAY(8, rbug_texture_t
, textures
); /* textures */
268 if (__pos
!= __len
) {
271 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_LIST_REPLY
, __len
);
272 rbug_connection_write(__con
, __data
, __len
);
273 __ret
= rbug_connection_send_finish(__con
, __serial
);
280 int rbug_send_texture_info_reply(struct rbug_connection
*__con
,
300 uint8_t *__data
= NULL
;
307 LEN_ARRAY(4, width
); /* width */
308 LEN_ARRAY(4, height
); /* height */
309 LEN_ARRAY(4, depth
); /* depth */
312 LEN(4); /* blocksize */
313 LEN(4); /* last_level */
314 LEN(4); /* nr_samples */
315 LEN(4); /* tex_usage */
320 __data
= (uint8_t*)MALLOC(__len
);
324 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY
));
325 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
326 WRITE(4, uint32_t, serial
); /* serial */
327 WRITE(4, uint32_t, target
); /* target */
328 WRITE(4, uint32_t, format
); /* format */
329 WRITE_ARRAY(4, uint32_t, width
); /* width */
330 WRITE_ARRAY(4, uint32_t, height
); /* height */
331 WRITE_ARRAY(4, uint32_t, depth
); /* depth */
332 WRITE(4, uint32_t, blockw
); /* blockw */
333 WRITE(4, uint32_t, blockh
); /* blockh */
334 WRITE(4, uint32_t, blocksize
); /* blocksize */
335 WRITE(4, uint32_t, last_level
); /* last_level */
336 WRITE(4, uint32_t, nr_samples
); /* nr_samples */
337 WRITE(4, uint32_t, tex_usage
); /* tex_usage */
342 if (__pos
!= __len
) {
345 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_INFO_REPLY
, __len
);
346 rbug_connection_write(__con
, __data
, __len
);
347 __ret
= rbug_connection_send_finish(__con
, __serial
);
354 int rbug_send_texture_read_reply(struct rbug_connection
*__con
,
367 uint8_t *__data
= NULL
;
375 LEN(4); /* blocksize */
376 LEN_ARRAY(1, data
); /* data */
382 __data
= (uint8_t*)MALLOC(__len
);
386 WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY
));
387 WRITE(4, uint32_t, ((uint32_t)(__len
/ 4)));
388 WRITE(4, uint32_t, serial
); /* serial */
389 WRITE(4, uint32_t, format
); /* format */
390 WRITE(4, uint32_t, blockw
); /* blockw */
391 WRITE(4, uint32_t, blockh
); /* blockh */
392 WRITE(4, uint32_t, blocksize
); /* blocksize */
393 WRITE_ARRAY(1, uint8_t, data
); /* data */
394 WRITE(4, uint32_t, stride
); /* stride */
399 if (__pos
!= __len
) {
402 rbug_connection_send_start(__con
, RBUG_OP_TEXTURE_READ_REPLY
, __len
);
403 rbug_connection_write(__con
, __data
, __len
);
404 __ret
= rbug_connection_send_finish(__con
, __serial
);
411 struct rbug_proto_texture_list
* rbug_demarshal_texture_list(struct rbug_proto_header
*header
)
415 uint8_t *data
= NULL
;
416 struct rbug_proto_texture_list
*ret
;
420 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_LIST
)
424 len
= header
->length
* 4;
425 data
= (uint8_t*)&header
[1];
426 ret
= MALLOC(sizeof(*ret
));
430 ret
->header
.__message
= header
;
431 ret
->header
.opcode
= header
->opcode
;
437 struct rbug_proto_texture_info
* rbug_demarshal_texture_info(struct rbug_proto_header
*header
)
441 uint8_t *data
= NULL
;
442 struct rbug_proto_texture_info
*ret
;
446 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_INFO
)
450 len
= header
->length
* 4;
451 data
= (uint8_t*)&header
[1];
452 ret
= MALLOC(sizeof(*ret
));
456 ret
->header
.__message
= header
;
457 ret
->header
.opcode
= header
->opcode
;
459 READ(8, rbug_texture_t
, texture
); /* texture */
464 struct rbug_proto_texture_write
* rbug_demarshal_texture_write(struct rbug_proto_header
*header
)
468 uint8_t *data
= NULL
;
469 struct rbug_proto_texture_write
*ret
;
473 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_WRITE
)
477 len
= header
->length
* 4;
478 data
= (uint8_t*)&header
[1];
479 ret
= MALLOC(sizeof(*ret
));
483 ret
->header
.__message
= header
;
484 ret
->header
.opcode
= header
->opcode
;
486 READ(8, rbug_texture_t
, texture
); /* texture */
487 READ(4, uint32_t, face
); /* face */
488 READ(4, uint32_t, level
); /* level */
489 READ(4, uint32_t, zslice
); /* zslice */
490 READ(4, uint32_t, x
); /* x */
491 READ(4, uint32_t, y
); /* y */
492 READ(4, uint32_t, w
); /* w */
493 READ(4, uint32_t, h
); /* h */
494 READ_ARRAY(1, uint8_t, data
); /* data */
495 READ(4, uint32_t, stride
); /* stride */
500 struct rbug_proto_texture_read
* rbug_demarshal_texture_read(struct rbug_proto_header
*header
)
504 uint8_t *data
= NULL
;
505 struct rbug_proto_texture_read
*ret
;
509 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_READ
)
513 len
= header
->length
* 4;
514 data
= (uint8_t*)&header
[1];
515 ret
= MALLOC(sizeof(*ret
));
519 ret
->header
.__message
= header
;
520 ret
->header
.opcode
= header
->opcode
;
522 READ(8, rbug_texture_t
, texture
); /* texture */
523 READ(4, uint32_t, face
); /* face */
524 READ(4, uint32_t, level
); /* level */
525 READ(4, uint32_t, zslice
); /* zslice */
526 READ(4, uint32_t, x
); /* x */
527 READ(4, uint32_t, y
); /* y */
528 READ(4, uint32_t, w
); /* w */
529 READ(4, uint32_t, h
); /* h */
534 struct rbug_proto_texture_list_reply
* rbug_demarshal_texture_list_reply(struct rbug_proto_header
*header
)
538 uint8_t *data
= NULL
;
539 struct rbug_proto_texture_list_reply
*ret
;
543 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_LIST_REPLY
)
547 len
= header
->length
* 4;
548 data
= (uint8_t*)&header
[1];
549 ret
= MALLOC(sizeof(*ret
));
553 ret
->header
.__message
= header
;
554 ret
->header
.opcode
= header
->opcode
;
556 READ(4, uint32_t, serial
); /* serial */
557 READ_ARRAY(8, rbug_texture_t
, textures
); /* textures */
562 struct rbug_proto_texture_info_reply
* rbug_demarshal_texture_info_reply(struct rbug_proto_header
*header
)
566 uint8_t *data
= NULL
;
567 struct rbug_proto_texture_info_reply
*ret
;
571 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_INFO_REPLY
)
575 len
= header
->length
* 4;
576 data
= (uint8_t*)&header
[1];
577 ret
= MALLOC(sizeof(*ret
));
581 ret
->header
.__message
= header
;
582 ret
->header
.opcode
= header
->opcode
;
584 READ(4, uint32_t, serial
); /* serial */
585 READ(4, uint32_t, target
); /* target */
586 READ(4, uint32_t, format
); /* format */
587 READ_ARRAY(4, uint32_t, width
); /* width */
588 READ_ARRAY(4, uint32_t, height
); /* height */
589 READ_ARRAY(4, uint32_t, depth
); /* depth */
590 READ(4, uint32_t, blockw
); /* blockw */
591 READ(4, uint32_t, blockh
); /* blockh */
592 READ(4, uint32_t, blocksize
); /* blocksize */
593 READ(4, uint32_t, last_level
); /* last_level */
594 READ(4, uint32_t, nr_samples
); /* nr_samples */
595 READ(4, uint32_t, tex_usage
); /* tex_usage */
600 struct rbug_proto_texture_read_reply
* rbug_demarshal_texture_read_reply(struct rbug_proto_header
*header
)
604 uint8_t *data
= NULL
;
605 struct rbug_proto_texture_read_reply
*ret
;
609 if (header
->opcode
!= (int16_t)RBUG_OP_TEXTURE_READ_REPLY
)
613 len
= header
->length
* 4;
614 data
= (uint8_t*)&header
[1];
615 ret
= MALLOC(sizeof(*ret
));
619 ret
->header
.__message
= header
;
620 ret
->header
.opcode
= header
->opcode
;
622 READ(4, uint32_t, serial
); /* serial */
623 READ(4, uint32_t, format
); /* format */
624 READ(4, uint32_t, blockw
); /* blockw */
625 READ(4, uint32_t, blockh
); /* blockh */
626 READ(4, uint32_t, blocksize
); /* blocksize */
627 READ_ARRAY(1, uint8_t, data
); /* data */
628 READ(4, uint32_t, stride
); /* stride */