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
)
413 struct rbug_proto_texture_list
*ret
;
417 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_LIST
)
420 ret
= MALLOC(sizeof(*ret
));
424 ret
->header
.__message
= header
;
425 ret
->header
.opcode
= header
->opcode
;
430 struct rbug_proto_texture_info
* rbug_demarshal_texture_info(struct rbug_proto_header
*header
)
434 uint8_t *data
= NULL
;
435 struct rbug_proto_texture_info
*ret
;
439 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_INFO
)
443 len
= header
->length
* 4;
444 data
= (uint8_t*)&header
[1];
445 ret
= MALLOC(sizeof(*ret
));
449 ret
->header
.__message
= header
;
450 ret
->header
.opcode
= header
->opcode
;
452 READ(8, rbug_texture_t
, texture
); /* texture */
457 struct rbug_proto_texture_write
* rbug_demarshal_texture_write(struct rbug_proto_header
*header
)
461 uint8_t *data
= NULL
;
462 struct rbug_proto_texture_write
*ret
;
466 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_WRITE
)
470 len
= header
->length
* 4;
471 data
= (uint8_t*)&header
[1];
472 ret
= MALLOC(sizeof(*ret
));
476 ret
->header
.__message
= header
;
477 ret
->header
.opcode
= header
->opcode
;
479 READ(8, rbug_texture_t
, texture
); /* texture */
480 READ(4, uint32_t, face
); /* face */
481 READ(4, uint32_t, level
); /* level */
482 READ(4, uint32_t, zslice
); /* zslice */
483 READ(4, uint32_t, x
); /* x */
484 READ(4, uint32_t, y
); /* y */
485 READ(4, uint32_t, w
); /* w */
486 READ(4, uint32_t, h
); /* h */
487 READ_ARRAY(1, uint8_t, data
); /* data */
488 READ(4, uint32_t, stride
); /* stride */
493 struct rbug_proto_texture_read
* rbug_demarshal_texture_read(struct rbug_proto_header
*header
)
497 uint8_t *data
= NULL
;
498 struct rbug_proto_texture_read
*ret
;
502 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_READ
)
506 len
= header
->length
* 4;
507 data
= (uint8_t*)&header
[1];
508 ret
= MALLOC(sizeof(*ret
));
512 ret
->header
.__message
= header
;
513 ret
->header
.opcode
= header
->opcode
;
515 READ(8, rbug_texture_t
, texture
); /* texture */
516 READ(4, uint32_t, face
); /* face */
517 READ(4, uint32_t, level
); /* level */
518 READ(4, uint32_t, zslice
); /* zslice */
519 READ(4, uint32_t, x
); /* x */
520 READ(4, uint32_t, y
); /* y */
521 READ(4, uint32_t, w
); /* w */
522 READ(4, uint32_t, h
); /* h */
527 struct rbug_proto_texture_list_reply
* rbug_demarshal_texture_list_reply(struct rbug_proto_header
*header
)
531 uint8_t *data
= NULL
;
532 struct rbug_proto_texture_list_reply
*ret
;
536 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_LIST_REPLY
)
540 len
= header
->length
* 4;
541 data
= (uint8_t*)&header
[1];
542 ret
= MALLOC(sizeof(*ret
));
546 ret
->header
.__message
= header
;
547 ret
->header
.opcode
= header
->opcode
;
549 READ(4, uint32_t, serial
); /* serial */
550 READ_ARRAY(8, rbug_texture_t
, textures
); /* textures */
555 struct rbug_proto_texture_info_reply
* rbug_demarshal_texture_info_reply(struct rbug_proto_header
*header
)
559 uint8_t *data
= NULL
;
560 struct rbug_proto_texture_info_reply
*ret
;
564 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_INFO_REPLY
)
568 len
= header
->length
* 4;
569 data
= (uint8_t*)&header
[1];
570 ret
= MALLOC(sizeof(*ret
));
574 ret
->header
.__message
= header
;
575 ret
->header
.opcode
= header
->opcode
;
577 READ(4, uint32_t, serial
); /* serial */
578 READ(4, uint32_t, target
); /* target */
579 READ(4, uint32_t, format
); /* format */
580 READ_ARRAY(4, uint32_t, width
); /* width */
581 READ_ARRAY(4, uint32_t, height
); /* height */
582 READ_ARRAY(4, uint32_t, depth
); /* depth */
583 READ(4, uint32_t, blockw
); /* blockw */
584 READ(4, uint32_t, blockh
); /* blockh */
585 READ(4, uint32_t, blocksize
); /* blocksize */
586 READ(4, uint32_t, last_level
); /* last_level */
587 READ(4, uint32_t, nr_samples
); /* nr_samples */
588 READ(4, uint32_t, tex_usage
); /* tex_usage */
593 struct rbug_proto_texture_read_reply
* rbug_demarshal_texture_read_reply(struct rbug_proto_header
*header
)
597 uint8_t *data
= NULL
;
598 struct rbug_proto_texture_read_reply
*ret
;
602 if (header
->opcode
!= (int32_t)RBUG_OP_TEXTURE_READ_REPLY
)
606 len
= header
->length
* 4;
607 data
= (uint8_t*)&header
[1];
608 ret
= MALLOC(sizeof(*ret
));
612 ret
->header
.__message
= header
;
613 ret
->header
.opcode
= header
->opcode
;
615 READ(4, uint32_t, serial
); /* serial */
616 READ(4, uint32_t, format
); /* format */
617 READ(4, uint32_t, blockw
); /* blockw */
618 READ(4, uint32_t, blockh
); /* blockh */
619 READ(4, uint32_t, blocksize
); /* blocksize */
620 READ_ARRAY(1, uint8_t, data
); /* data */
621 READ(4, uint32_t, stride
); /* stride */