123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 |
- /*
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- /*
- * This file holds the function implementation for one of the rbug extensions.
- * Prototypes and declerations of functions and structs is in the same folder
- * in the header file matching this file's name.
- *
- * The functions starting rbug_send_* encodes a call to the write format and
- * sends that to the supplied connection, while functions starting with
- * rbug_demarshal_* demarshal data in the wire protocol.
- *
- * Functions ending with _reply are replies to requests.
- */
-
- #include "rbug_internal.h"
- #include "rbug/rbug_texture.h"
-
- int rbug_send_texture_list(struct rbug_connection *__con,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_info(struct rbug_connection *__con,
- rbug_texture_t texture,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(8); /* texture */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(8, rbug_texture_t, texture); /* texture */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_write(struct rbug_connection *__con,
- rbug_texture_t texture,
- uint32_t face,
- uint32_t level,
- uint32_t zslice,
- uint32_t x,
- uint32_t y,
- uint32_t w,
- uint32_t h,
- uint8_t *data,
- uint32_t data_len,
- uint32_t stride,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(8); /* texture */
- LEN(4); /* face */
- LEN(4); /* level */
- LEN(4); /* zslice */
- LEN(4); /* x */
- LEN(4); /* y */
- LEN(4); /* w */
- LEN(4); /* h */
- LEN_ARRAY(1, data); /* data */
- LEN(4); /* stride */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(8, rbug_texture_t, texture); /* texture */
- WRITE(4, uint32_t, face); /* face */
- WRITE(4, uint32_t, level); /* level */
- WRITE(4, uint32_t, zslice); /* zslice */
- WRITE(4, uint32_t, x); /* x */
- WRITE(4, uint32_t, y); /* y */
- WRITE(4, uint32_t, w); /* w */
- WRITE(4, uint32_t, h); /* h */
- WRITE_ARRAY(1, uint8_t, data); /* data */
- WRITE(4, uint32_t, stride); /* stride */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_read(struct rbug_connection *__con,
- rbug_texture_t texture,
- uint32_t face,
- uint32_t level,
- uint32_t zslice,
- uint32_t x,
- uint32_t y,
- uint32_t w,
- uint32_t h,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(8); /* texture */
- LEN(4); /* face */
- LEN(4); /* level */
- LEN(4); /* zslice */
- LEN(4); /* x */
- LEN(4); /* y */
- LEN(4); /* w */
- LEN(4); /* h */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(8, rbug_texture_t, texture); /* texture */
- WRITE(4, uint32_t, face); /* face */
- WRITE(4, uint32_t, level); /* level */
- WRITE(4, uint32_t, zslice); /* zslice */
- WRITE(4, uint32_t, x); /* x */
- WRITE(4, uint32_t, y); /* y */
- WRITE(4, uint32_t, w); /* w */
- WRITE(4, uint32_t, h); /* h */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_list_reply(struct rbug_connection *__con,
- uint32_t serial,
- rbug_texture_t *textures,
- uint32_t textures_len,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(4); /* serial */
- LEN_ARRAY(8, textures); /* textures */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(4, uint32_t, serial); /* serial */
- WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_info_reply(struct rbug_connection *__con,
- uint32_t serial,
- uint32_t target,
- uint32_t format,
- uint32_t *width,
- uint32_t width_len,
- uint32_t *height,
- uint32_t height_len,
- uint32_t *depth,
- uint32_t depth_len,
- uint32_t blockw,
- uint32_t blockh,
- uint32_t blocksize,
- uint32_t last_level,
- uint32_t nr_samples,
- uint32_t tex_usage,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(4); /* serial */
- LEN(4); /* target */
- LEN(4); /* format */
- LEN_ARRAY(4, width); /* width */
- LEN_ARRAY(4, height); /* height */
- LEN_ARRAY(4, depth); /* depth */
- LEN(4); /* blockw */
- LEN(4); /* blockh */
- LEN(4); /* blocksize */
- LEN(4); /* last_level */
- LEN(4); /* nr_samples */
- LEN(4); /* tex_usage */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(4, uint32_t, serial); /* serial */
- WRITE(4, uint32_t, target); /* target */
- WRITE(4, uint32_t, format); /* format */
- WRITE_ARRAY(4, uint32_t, width); /* width */
- WRITE_ARRAY(4, uint32_t, height); /* height */
- WRITE_ARRAY(4, uint32_t, depth); /* depth */
- WRITE(4, uint32_t, blockw); /* blockw */
- WRITE(4, uint32_t, blockh); /* blockh */
- WRITE(4, uint32_t, blocksize); /* blocksize */
- WRITE(4, uint32_t, last_level); /* last_level */
- WRITE(4, uint32_t, nr_samples); /* nr_samples */
- WRITE(4, uint32_t, tex_usage); /* tex_usage */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- int rbug_send_texture_read_reply(struct rbug_connection *__con,
- uint32_t serial,
- uint32_t format,
- uint32_t blockw,
- uint32_t blockh,
- uint32_t blocksize,
- uint8_t *data,
- uint32_t data_len,
- uint32_t stride,
- uint32_t *__serial)
- {
- uint32_t __len = 0;
- uint32_t __pos = 0;
- uint8_t *__data = NULL;
- int __ret = 0;
-
- LEN(8); /* header */
- LEN(4); /* serial */
- LEN(4); /* format */
- LEN(4); /* blockw */
- LEN(4); /* blockh */
- LEN(4); /* blocksize */
- LEN_ARRAY(1, data); /* data */
- LEN(4); /* stride */
-
- /* align */
- PAD(__len, 8);
-
- __data = (uint8_t*)MALLOC(__len);
- if (!__data)
- return -ENOMEM;
-
- WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY));
- WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
- WRITE(4, uint32_t, serial); /* serial */
- WRITE(4, uint32_t, format); /* format */
- WRITE(4, uint32_t, blockw); /* blockw */
- WRITE(4, uint32_t, blockh); /* blockh */
- WRITE(4, uint32_t, blocksize); /* blocksize */
- WRITE_ARRAY(1, uint8_t, data); /* data */
- WRITE(4, uint32_t, stride); /* stride */
-
- /* final pad */
- PAD(__pos, 8);
-
- if (__pos != __len) {
- __ret = -EINVAL;
- } else {
- rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len);
- rbug_connection_write(__con, __data, __len);
- __ret = rbug_connection_send_finish(__con, __serial);
- }
-
- FREE(__data);
- return __ret;
- }
-
- struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_list *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
-
- return ret;
- }
-
- struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_info *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(8, rbug_texture_t, texture); /* texture */
-
- return ret;
- }
-
- struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_write *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_WRITE)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(8, rbug_texture_t, texture); /* texture */
- READ(4, uint32_t, face); /* face */
- READ(4, uint32_t, level); /* level */
- READ(4, uint32_t, zslice); /* zslice */
- READ(4, uint32_t, x); /* x */
- READ(4, uint32_t, y); /* y */
- READ(4, uint32_t, w); /* w */
- READ(4, uint32_t, h); /* h */
- READ_ARRAY(1, uint8_t, data); /* data */
- READ(4, uint32_t, stride); /* stride */
-
- return ret;
- }
-
- struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_read *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(8, rbug_texture_t, texture); /* texture */
- READ(4, uint32_t, face); /* face */
- READ(4, uint32_t, level); /* level */
- READ(4, uint32_t, zslice); /* zslice */
- READ(4, uint32_t, x); /* x */
- READ(4, uint32_t, y); /* y */
- READ(4, uint32_t, w); /* w */
- READ(4, uint32_t, h); /* h */
-
- return ret;
- }
-
- struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_list_reply *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST_REPLY)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(4, uint32_t, serial); /* serial */
- READ_ARRAY(8, rbug_texture_t, textures); /* textures */
-
- return ret;
- }
-
- struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_info_reply *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO_REPLY)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(4, uint32_t, serial); /* serial */
- READ(4, uint32_t, target); /* target */
- READ(4, uint32_t, format); /* format */
- READ_ARRAY(4, uint32_t, width); /* width */
- READ_ARRAY(4, uint32_t, height); /* height */
- READ_ARRAY(4, uint32_t, depth); /* depth */
- READ(4, uint32_t, blockw); /* blockw */
- READ(4, uint32_t, blockh); /* blockh */
- READ(4, uint32_t, blocksize); /* blocksize */
- READ(4, uint32_t, last_level); /* last_level */
- READ(4, uint32_t, nr_samples); /* nr_samples */
- READ(4, uint32_t, tex_usage); /* tex_usage */
-
- return ret;
- }
-
- struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header)
- {
- uint32_t len = 0;
- uint32_t pos = 0;
- uint8_t *data = NULL;
- struct rbug_proto_texture_read_reply *ret;
-
- if (!header)
- return NULL;
- if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ_REPLY)
- return NULL;
-
- pos = 0;
- len = header->length * 4;
- data = (uint8_t*)&header[1];
- ret = MALLOC(sizeof(*ret));
- if (!ret)
- return NULL;
-
- ret->header.__message = header;
- ret->header.opcode = header->opcode;
-
- READ(4, uint32_t, serial); /* serial */
- READ(4, uint32_t, format); /* format */
- READ(4, uint32_t, blockw); /* blockw */
- READ(4, uint32_t, blockh); /* blockh */
- READ(4, uint32_t, blocksize); /* blocksize */
- READ_ARRAY(1, uint8_t, data); /* data */
- READ(4, uint32_t, stride); /* stride */
-
- return ret;
- }
|