1848b8605Smrg/*
2848b8605Smrg * Copyright 2009 VMware, Inc.
3848b8605Smrg * All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
9848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom
10848b8605Smrg * the Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice (including the next
13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
14848b8605Smrg * Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg/*
26848b8605Smrg * This file holds the function implementation for one of the rbug extensions.
27848b8605Smrg * Prototypes and declerations of functions and structs is in the same folder
28848b8605Smrg * in the header file matching this file's name.
29848b8605Smrg *
30848b8605Smrg * The functions starting rbug_send_* encodes a call to the write format and
31848b8605Smrg * sends that to the supplied connection, while functions starting with
32848b8605Smrg * rbug_demarshal_* demarshal data in the wire protocol.
33848b8605Smrg *
34848b8605Smrg * Functions ending with _reply are replies to requests.
35848b8605Smrg */
36848b8605Smrg
37848b8605Smrg#include "rbug_internal.h"
38848b8605Smrg#include "rbug_texture.h"
39848b8605Smrg
40848b8605Smrgint rbug_send_texture_list(struct rbug_connection *__con,
41848b8605Smrg                           uint32_t *__serial)
42848b8605Smrg{
43848b8605Smrg	uint32_t __len = 0;
44848b8605Smrg	uint32_t __pos = 0;
45848b8605Smrg	uint8_t *__data = NULL;
46848b8605Smrg	int __ret = 0;
47848b8605Smrg
48848b8605Smrg	LEN(8); /* header */
49848b8605Smrg
50848b8605Smrg	/* align */
51848b8605Smrg	PAD(__len, 8);
52848b8605Smrg
53848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
54848b8605Smrg	if (!__data)
55848b8605Smrg		return -ENOMEM;
56848b8605Smrg
57848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST));
58848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
59848b8605Smrg
60848b8605Smrg	/* final pad */
61848b8605Smrg	PAD(__pos, 8);
62848b8605Smrg
63848b8605Smrg	if (__pos != __len) {
64848b8605Smrg		__ret = -EINVAL;
65848b8605Smrg	} else {
66848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len);
67848b8605Smrg		rbug_connection_write(__con, __data, __len);
68848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
69848b8605Smrg	}
70848b8605Smrg
71848b8605Smrg	FREE(__data);
72848b8605Smrg	return __ret;
73848b8605Smrg}
74848b8605Smrg
75848b8605Smrgint rbug_send_texture_info(struct rbug_connection *__con,
76848b8605Smrg                           rbug_texture_t texture,
77848b8605Smrg                           uint32_t *__serial)
78848b8605Smrg{
79848b8605Smrg	uint32_t __len = 0;
80848b8605Smrg	uint32_t __pos = 0;
81848b8605Smrg	uint8_t *__data = NULL;
82848b8605Smrg	int __ret = 0;
83848b8605Smrg
84848b8605Smrg	LEN(8); /* header */
85848b8605Smrg	LEN(8); /* texture */
86848b8605Smrg
87848b8605Smrg	/* align */
88848b8605Smrg	PAD(__len, 8);
89848b8605Smrg
90848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
91848b8605Smrg	if (!__data)
92848b8605Smrg		return -ENOMEM;
93848b8605Smrg
94848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO));
95848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
96848b8605Smrg	WRITE(8, rbug_texture_t, texture); /* texture */
97848b8605Smrg
98848b8605Smrg	/* final pad */
99848b8605Smrg	PAD(__pos, 8);
100848b8605Smrg
101848b8605Smrg	if (__pos != __len) {
102848b8605Smrg		__ret = -EINVAL;
103848b8605Smrg	} else {
104848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len);
105848b8605Smrg		rbug_connection_write(__con, __data, __len);
106848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
107848b8605Smrg	}
108848b8605Smrg
109848b8605Smrg	FREE(__data);
110848b8605Smrg	return __ret;
111848b8605Smrg}
112848b8605Smrg
113848b8605Smrgint rbug_send_texture_write(struct rbug_connection *__con,
114848b8605Smrg                            rbug_texture_t texture,
115848b8605Smrg                            uint32_t face,
116848b8605Smrg                            uint32_t level,
117848b8605Smrg                            uint32_t zslice,
118848b8605Smrg                            uint32_t x,
119848b8605Smrg                            uint32_t y,
120848b8605Smrg                            uint32_t w,
121848b8605Smrg                            uint32_t h,
122848b8605Smrg                            uint8_t *data,
123848b8605Smrg                            uint32_t data_len,
124848b8605Smrg                            uint32_t stride,
125848b8605Smrg                            uint32_t *__serial)
126848b8605Smrg{
127848b8605Smrg	uint32_t __len = 0;
128848b8605Smrg	uint32_t __pos = 0;
129848b8605Smrg	uint8_t *__data = NULL;
130848b8605Smrg	int __ret = 0;
131848b8605Smrg
132848b8605Smrg	LEN(8); /* header */
133848b8605Smrg	LEN(8); /* texture */
134848b8605Smrg	LEN(4); /* face */
135848b8605Smrg	LEN(4); /* level */
136848b8605Smrg	LEN(4); /* zslice */
137848b8605Smrg	LEN(4); /* x */
138848b8605Smrg	LEN(4); /* y */
139848b8605Smrg	LEN(4); /* w */
140848b8605Smrg	LEN(4); /* h */
141848b8605Smrg	LEN_ARRAY(1, data); /* data */
142848b8605Smrg	LEN(4); /* stride */
143848b8605Smrg
144848b8605Smrg	/* align */
145848b8605Smrg	PAD(__len, 8);
146848b8605Smrg
147848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
148848b8605Smrg	if (!__data)
149848b8605Smrg		return -ENOMEM;
150848b8605Smrg
151848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE));
152848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
153848b8605Smrg	WRITE(8, rbug_texture_t, texture); /* texture */
154848b8605Smrg	WRITE(4, uint32_t, face); /* face */
155848b8605Smrg	WRITE(4, uint32_t, level); /* level */
156848b8605Smrg	WRITE(4, uint32_t, zslice); /* zslice */
157848b8605Smrg	WRITE(4, uint32_t, x); /* x */
158848b8605Smrg	WRITE(4, uint32_t, y); /* y */
159848b8605Smrg	WRITE(4, uint32_t, w); /* w */
160848b8605Smrg	WRITE(4, uint32_t, h); /* h */
161848b8605Smrg	WRITE_ARRAY(1, uint8_t, data); /* data */
162848b8605Smrg	WRITE(4, uint32_t, stride); /* stride */
163848b8605Smrg
164848b8605Smrg	/* final pad */
165848b8605Smrg	PAD(__pos, 8);
166848b8605Smrg
167848b8605Smrg	if (__pos != __len) {
168848b8605Smrg		__ret = -EINVAL;
169848b8605Smrg	} else {
170848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len);
171848b8605Smrg		rbug_connection_write(__con, __data, __len);
172848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
173848b8605Smrg	}
174848b8605Smrg
175848b8605Smrg	FREE(__data);
176848b8605Smrg	return __ret;
177848b8605Smrg}
178848b8605Smrg
179848b8605Smrgint rbug_send_texture_read(struct rbug_connection *__con,
180848b8605Smrg                           rbug_texture_t texture,
181848b8605Smrg                           uint32_t face,
182848b8605Smrg                           uint32_t level,
183848b8605Smrg                           uint32_t zslice,
184848b8605Smrg                           uint32_t x,
185848b8605Smrg                           uint32_t y,
186848b8605Smrg                           uint32_t w,
187848b8605Smrg                           uint32_t h,
188848b8605Smrg                           uint32_t *__serial)
189848b8605Smrg{
190848b8605Smrg	uint32_t __len = 0;
191848b8605Smrg	uint32_t __pos = 0;
192848b8605Smrg	uint8_t *__data = NULL;
193848b8605Smrg	int __ret = 0;
194848b8605Smrg
195848b8605Smrg	LEN(8); /* header */
196848b8605Smrg	LEN(8); /* texture */
197848b8605Smrg	LEN(4); /* face */
198848b8605Smrg	LEN(4); /* level */
199848b8605Smrg	LEN(4); /* zslice */
200848b8605Smrg	LEN(4); /* x */
201848b8605Smrg	LEN(4); /* y */
202848b8605Smrg	LEN(4); /* w */
203848b8605Smrg	LEN(4); /* h */
204848b8605Smrg
205848b8605Smrg	/* align */
206848b8605Smrg	PAD(__len, 8);
207848b8605Smrg
208848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
209848b8605Smrg	if (!__data)
210848b8605Smrg		return -ENOMEM;
211848b8605Smrg
212848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ));
213848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
214848b8605Smrg	WRITE(8, rbug_texture_t, texture); /* texture */
215848b8605Smrg	WRITE(4, uint32_t, face); /* face */
216848b8605Smrg	WRITE(4, uint32_t, level); /* level */
217848b8605Smrg	WRITE(4, uint32_t, zslice); /* zslice */
218848b8605Smrg	WRITE(4, uint32_t, x); /* x */
219848b8605Smrg	WRITE(4, uint32_t, y); /* y */
220848b8605Smrg	WRITE(4, uint32_t, w); /* w */
221848b8605Smrg	WRITE(4, uint32_t, h); /* h */
222848b8605Smrg
223848b8605Smrg	/* final pad */
224848b8605Smrg	PAD(__pos, 8);
225848b8605Smrg
226848b8605Smrg	if (__pos != __len) {
227848b8605Smrg		__ret = -EINVAL;
228848b8605Smrg	} else {
229848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len);
230848b8605Smrg		rbug_connection_write(__con, __data, __len);
231848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
232848b8605Smrg	}
233848b8605Smrg
234848b8605Smrg	FREE(__data);
235848b8605Smrg	return __ret;
236848b8605Smrg}
237848b8605Smrg
238848b8605Smrgint rbug_send_texture_list_reply(struct rbug_connection *__con,
239848b8605Smrg                                 uint32_t serial,
240848b8605Smrg                                 rbug_texture_t *textures,
241848b8605Smrg                                 uint32_t textures_len,
242848b8605Smrg                                 uint32_t *__serial)
243848b8605Smrg{
244848b8605Smrg	uint32_t __len = 0;
245848b8605Smrg	uint32_t __pos = 0;
246848b8605Smrg	uint8_t *__data = NULL;
247848b8605Smrg	int __ret = 0;
248848b8605Smrg
249848b8605Smrg	LEN(8); /* header */
250848b8605Smrg	LEN(4); /* serial */
251848b8605Smrg	LEN_ARRAY(8, textures); /* textures */
252848b8605Smrg
253848b8605Smrg	/* align */
254848b8605Smrg	PAD(__len, 8);
255848b8605Smrg
256848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
257848b8605Smrg	if (!__data)
258848b8605Smrg		return -ENOMEM;
259848b8605Smrg
260848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY));
261848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
262848b8605Smrg	WRITE(4, uint32_t, serial); /* serial */
263848b8605Smrg	WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */
264848b8605Smrg
265848b8605Smrg	/* final pad */
266848b8605Smrg	PAD(__pos, 8);
267848b8605Smrg
268848b8605Smrg	if (__pos != __len) {
269848b8605Smrg		__ret = -EINVAL;
270848b8605Smrg	} else {
271848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len);
272848b8605Smrg		rbug_connection_write(__con, __data, __len);
273848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
274848b8605Smrg	}
275848b8605Smrg
276848b8605Smrg	FREE(__data);
277848b8605Smrg	return __ret;
278848b8605Smrg}
279848b8605Smrg
280848b8605Smrgint rbug_send_texture_info_reply(struct rbug_connection *__con,
281848b8605Smrg                                 uint32_t serial,
282848b8605Smrg                                 uint32_t target,
283848b8605Smrg                                 uint32_t format,
284848b8605Smrg                                 uint32_t *width,
285848b8605Smrg                                 uint32_t width_len,
286b8e80941Smrg                                 uint16_t *height,
287848b8605Smrg                                 uint32_t height_len,
288b8e80941Smrg                                 uint16_t *depth,
289848b8605Smrg                                 uint32_t depth_len,
290848b8605Smrg                                 uint32_t blockw,
291848b8605Smrg                                 uint32_t blockh,
292848b8605Smrg                                 uint32_t blocksize,
293848b8605Smrg                                 uint32_t last_level,
294848b8605Smrg                                 uint32_t nr_samples,
295848b8605Smrg                                 uint32_t tex_usage,
296848b8605Smrg                                 uint32_t *__serial)
297848b8605Smrg{
298848b8605Smrg	uint32_t __len = 0;
299848b8605Smrg	uint32_t __pos = 0;
300848b8605Smrg	uint8_t *__data = NULL;
301848b8605Smrg	int __ret = 0;
302848b8605Smrg
303848b8605Smrg	LEN(8); /* header */
304848b8605Smrg	LEN(4); /* serial */
305848b8605Smrg	LEN(4); /* target */
306848b8605Smrg	LEN(4); /* format */
307848b8605Smrg	LEN_ARRAY(4, width); /* width */
308848b8605Smrg	LEN_ARRAY(4, height); /* height */
309848b8605Smrg	LEN_ARRAY(4, depth); /* depth */
310848b8605Smrg	LEN(4); /* blockw */
311848b8605Smrg	LEN(4); /* blockh */
312848b8605Smrg	LEN(4); /* blocksize */
313848b8605Smrg	LEN(4); /* last_level */
314848b8605Smrg	LEN(4); /* nr_samples */
315848b8605Smrg	LEN(4); /* tex_usage */
316848b8605Smrg
317848b8605Smrg	/* align */
318848b8605Smrg	PAD(__len, 8);
319848b8605Smrg
320848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
321848b8605Smrg	if (!__data)
322848b8605Smrg		return -ENOMEM;
323848b8605Smrg
324848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY));
325848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
326848b8605Smrg	WRITE(4, uint32_t, serial); /* serial */
327848b8605Smrg	WRITE(4, uint32_t, target); /* target */
328848b8605Smrg	WRITE(4, uint32_t, format); /* format */
329848b8605Smrg	WRITE_ARRAY(4, uint32_t, width); /* width */
330848b8605Smrg	WRITE_ARRAY(4, uint32_t, height); /* height */
331848b8605Smrg	WRITE_ARRAY(4, uint32_t, depth); /* depth */
332848b8605Smrg	WRITE(4, uint32_t, blockw); /* blockw */
333848b8605Smrg	WRITE(4, uint32_t, blockh); /* blockh */
334848b8605Smrg	WRITE(4, uint32_t, blocksize); /* blocksize */
335848b8605Smrg	WRITE(4, uint32_t, last_level); /* last_level */
336848b8605Smrg	WRITE(4, uint32_t, nr_samples); /* nr_samples */
337848b8605Smrg	WRITE(4, uint32_t, tex_usage); /* tex_usage */
338848b8605Smrg
339848b8605Smrg	/* final pad */
340848b8605Smrg	PAD(__pos, 8);
341848b8605Smrg
342848b8605Smrg	if (__pos != __len) {
343848b8605Smrg		__ret = -EINVAL;
344848b8605Smrg	} else {
345848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len);
346848b8605Smrg		rbug_connection_write(__con, __data, __len);
347848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
348848b8605Smrg	}
349848b8605Smrg
350848b8605Smrg	FREE(__data);
351848b8605Smrg	return __ret;
352848b8605Smrg}
353848b8605Smrg
354848b8605Smrgint rbug_send_texture_read_reply(struct rbug_connection *__con,
355848b8605Smrg                                 uint32_t serial,
356848b8605Smrg                                 uint32_t format,
357848b8605Smrg                                 uint32_t blockw,
358848b8605Smrg                                 uint32_t blockh,
359848b8605Smrg                                 uint32_t blocksize,
360848b8605Smrg                                 uint8_t *data,
361848b8605Smrg                                 uint32_t data_len,
362848b8605Smrg                                 uint32_t stride,
363848b8605Smrg                                 uint32_t *__serial)
364848b8605Smrg{
365848b8605Smrg	uint32_t __len = 0;
366848b8605Smrg	uint32_t __pos = 0;
367848b8605Smrg	uint8_t *__data = NULL;
368848b8605Smrg	int __ret = 0;
369848b8605Smrg
370848b8605Smrg	LEN(8); /* header */
371848b8605Smrg	LEN(4); /* serial */
372848b8605Smrg	LEN(4); /* format */
373848b8605Smrg	LEN(4); /* blockw */
374848b8605Smrg	LEN(4); /* blockh */
375848b8605Smrg	LEN(4); /* blocksize */
376848b8605Smrg	LEN_ARRAY(1, data); /* data */
377848b8605Smrg	LEN(4); /* stride */
378848b8605Smrg
379848b8605Smrg	/* align */
380848b8605Smrg	PAD(__len, 8);
381848b8605Smrg
382848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
383848b8605Smrg	if (!__data)
384848b8605Smrg		return -ENOMEM;
385848b8605Smrg
386848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY));
387848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
388848b8605Smrg	WRITE(4, uint32_t, serial); /* serial */
389848b8605Smrg	WRITE(4, uint32_t, format); /* format */
390848b8605Smrg	WRITE(4, uint32_t, blockw); /* blockw */
391848b8605Smrg	WRITE(4, uint32_t, blockh); /* blockh */
392848b8605Smrg	WRITE(4, uint32_t, blocksize); /* blocksize */
393848b8605Smrg	WRITE_ARRAY(1, uint8_t, data); /* data */
394848b8605Smrg	WRITE(4, uint32_t, stride); /* stride */
395848b8605Smrg
396848b8605Smrg	/* final pad */
397848b8605Smrg	PAD(__pos, 8);
398848b8605Smrg
399848b8605Smrg	if (__pos != __len) {
400848b8605Smrg		__ret = -EINVAL;
401848b8605Smrg	} else {
402848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len);
403848b8605Smrg		rbug_connection_write(__con, __data, __len);
404848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
405848b8605Smrg	}
406848b8605Smrg
407848b8605Smrg	FREE(__data);
408848b8605Smrg	return __ret;
409848b8605Smrg}
410848b8605Smrg
411848b8605Smrgstruct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header)
412848b8605Smrg{
413848b8605Smrg	struct rbug_proto_texture_list *ret;
414848b8605Smrg
415848b8605Smrg	if (!header)
416848b8605Smrg		return NULL;
417848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST)
418848b8605Smrg		return NULL;
419848b8605Smrg
420848b8605Smrg	ret = MALLOC(sizeof(*ret));
421848b8605Smrg	if (!ret)
422848b8605Smrg		return NULL;
423848b8605Smrg
424848b8605Smrg	ret->header.__message = header;
425848b8605Smrg	ret->header.opcode = header->opcode;
426848b8605Smrg
427848b8605Smrg	return ret;
428848b8605Smrg}
429848b8605Smrg
430848b8605Smrgstruct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header)
431848b8605Smrg{
432848b8605Smrg	uint32_t len = 0;
433848b8605Smrg	uint32_t pos = 0;
434848b8605Smrg	uint8_t *data =  NULL;
435848b8605Smrg	struct rbug_proto_texture_info *ret;
436848b8605Smrg
437848b8605Smrg	if (!header)
438848b8605Smrg		return NULL;
439848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO)
440848b8605Smrg		return NULL;
441848b8605Smrg
442848b8605Smrg	pos = 0;
443848b8605Smrg	len = header->length * 4;
444848b8605Smrg	data = (uint8_t*)&header[1];
445848b8605Smrg	ret = MALLOC(sizeof(*ret));
446848b8605Smrg	if (!ret)
447848b8605Smrg		return NULL;
448848b8605Smrg
449848b8605Smrg	ret->header.__message = header;
450848b8605Smrg	ret->header.opcode = header->opcode;
451848b8605Smrg
452848b8605Smrg	READ(8, rbug_texture_t, texture); /* texture */
453848b8605Smrg
454848b8605Smrg	return ret;
455848b8605Smrg}
456848b8605Smrg
457848b8605Smrgstruct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header)
458848b8605Smrg{
459848b8605Smrg	uint32_t len = 0;
460848b8605Smrg	uint32_t pos = 0;
461848b8605Smrg	uint8_t *data =  NULL;
462848b8605Smrg	struct rbug_proto_texture_write *ret;
463848b8605Smrg
464848b8605Smrg	if (!header)
465848b8605Smrg		return NULL;
466848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_WRITE)
467848b8605Smrg		return NULL;
468848b8605Smrg
469848b8605Smrg	pos = 0;
470848b8605Smrg	len = header->length * 4;
471848b8605Smrg	data = (uint8_t*)&header[1];
472848b8605Smrg	ret = MALLOC(sizeof(*ret));
473848b8605Smrg	if (!ret)
474848b8605Smrg		return NULL;
475848b8605Smrg
476848b8605Smrg	ret->header.__message = header;
477848b8605Smrg	ret->header.opcode = header->opcode;
478848b8605Smrg
479848b8605Smrg	READ(8, rbug_texture_t, texture); /* texture */
480848b8605Smrg	READ(4, uint32_t, face); /* face */
481848b8605Smrg	READ(4, uint32_t, level); /* level */
482848b8605Smrg	READ(4, uint32_t, zslice); /* zslice */
483848b8605Smrg	READ(4, uint32_t, x); /* x */
484848b8605Smrg	READ(4, uint32_t, y); /* y */
485848b8605Smrg	READ(4, uint32_t, w); /* w */
486848b8605Smrg	READ(4, uint32_t, h); /* h */
487848b8605Smrg	READ_ARRAY(1, uint8_t, data); /* data */
488848b8605Smrg	READ(4, uint32_t, stride); /* stride */
489848b8605Smrg
490848b8605Smrg	return ret;
491848b8605Smrg}
492848b8605Smrg
493848b8605Smrgstruct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header)
494848b8605Smrg{
495848b8605Smrg	uint32_t len = 0;
496848b8605Smrg	uint32_t pos = 0;
497848b8605Smrg	uint8_t *data =  NULL;
498848b8605Smrg	struct rbug_proto_texture_read *ret;
499848b8605Smrg
500848b8605Smrg	if (!header)
501848b8605Smrg		return NULL;
502848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ)
503848b8605Smrg		return NULL;
504848b8605Smrg
505848b8605Smrg	pos = 0;
506848b8605Smrg	len = header->length * 4;
507848b8605Smrg	data = (uint8_t*)&header[1];
508848b8605Smrg	ret = MALLOC(sizeof(*ret));
509848b8605Smrg	if (!ret)
510848b8605Smrg		return NULL;
511848b8605Smrg
512848b8605Smrg	ret->header.__message = header;
513848b8605Smrg	ret->header.opcode = header->opcode;
514848b8605Smrg
515848b8605Smrg	READ(8, rbug_texture_t, texture); /* texture */
516848b8605Smrg	READ(4, uint32_t, face); /* face */
517848b8605Smrg	READ(4, uint32_t, level); /* level */
518848b8605Smrg	READ(4, uint32_t, zslice); /* zslice */
519848b8605Smrg	READ(4, uint32_t, x); /* x */
520848b8605Smrg	READ(4, uint32_t, y); /* y */
521848b8605Smrg	READ(4, uint32_t, w); /* w */
522848b8605Smrg	READ(4, uint32_t, h); /* h */
523848b8605Smrg
524848b8605Smrg	return ret;
525848b8605Smrg}
526848b8605Smrg
527848b8605Smrgstruct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header)
528848b8605Smrg{
529848b8605Smrg	uint32_t len = 0;
530848b8605Smrg	uint32_t pos = 0;
531848b8605Smrg	uint8_t *data =  NULL;
532848b8605Smrg	struct rbug_proto_texture_list_reply *ret;
533848b8605Smrg
534848b8605Smrg	if (!header)
535848b8605Smrg		return NULL;
536848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST_REPLY)
537848b8605Smrg		return NULL;
538848b8605Smrg
539848b8605Smrg	pos = 0;
540848b8605Smrg	len = header->length * 4;
541848b8605Smrg	data = (uint8_t*)&header[1];
542848b8605Smrg	ret = MALLOC(sizeof(*ret));
543848b8605Smrg	if (!ret)
544848b8605Smrg		return NULL;
545848b8605Smrg
546848b8605Smrg	ret->header.__message = header;
547848b8605Smrg	ret->header.opcode = header->opcode;
548848b8605Smrg
549848b8605Smrg	READ(4, uint32_t, serial); /* serial */
550848b8605Smrg	READ_ARRAY(8, rbug_texture_t, textures); /* textures */
551848b8605Smrg
552848b8605Smrg	return ret;
553848b8605Smrg}
554848b8605Smrg
555848b8605Smrgstruct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header)
556848b8605Smrg{
557848b8605Smrg	uint32_t len = 0;
558848b8605Smrg	uint32_t pos = 0;
559848b8605Smrg	uint8_t *data =  NULL;
560848b8605Smrg	struct rbug_proto_texture_info_reply *ret;
561848b8605Smrg
562848b8605Smrg	if (!header)
563848b8605Smrg		return NULL;
564848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO_REPLY)
565848b8605Smrg		return NULL;
566848b8605Smrg
567848b8605Smrg	pos = 0;
568848b8605Smrg	len = header->length * 4;
569848b8605Smrg	data = (uint8_t*)&header[1];
570848b8605Smrg	ret = MALLOC(sizeof(*ret));
571848b8605Smrg	if (!ret)
572848b8605Smrg		return NULL;
573848b8605Smrg
574848b8605Smrg	ret->header.__message = header;
575848b8605Smrg	ret->header.opcode = header->opcode;
576848b8605Smrg
577848b8605Smrg	READ(4, uint32_t, serial); /* serial */
578848b8605Smrg	READ(4, uint32_t, target); /* target */
579848b8605Smrg	READ(4, uint32_t, format); /* format */
580848b8605Smrg	READ_ARRAY(4, uint32_t, width); /* width */
581848b8605Smrg	READ_ARRAY(4, uint32_t, height); /* height */
582848b8605Smrg	READ_ARRAY(4, uint32_t, depth); /* depth */
583848b8605Smrg	READ(4, uint32_t, blockw); /* blockw */
584848b8605Smrg	READ(4, uint32_t, blockh); /* blockh */
585848b8605Smrg	READ(4, uint32_t, blocksize); /* blocksize */
586848b8605Smrg	READ(4, uint32_t, last_level); /* last_level */
587848b8605Smrg	READ(4, uint32_t, nr_samples); /* nr_samples */
588848b8605Smrg	READ(4, uint32_t, tex_usage); /* tex_usage */
589848b8605Smrg
590848b8605Smrg	return ret;
591848b8605Smrg}
592848b8605Smrg
593848b8605Smrgstruct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header)
594848b8605Smrg{
595848b8605Smrg	uint32_t len = 0;
596848b8605Smrg	uint32_t pos = 0;
597848b8605Smrg	uint8_t *data =  NULL;
598848b8605Smrg	struct rbug_proto_texture_read_reply *ret;
599848b8605Smrg
600848b8605Smrg	if (!header)
601848b8605Smrg		return NULL;
602848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ_REPLY)
603848b8605Smrg		return NULL;
604848b8605Smrg
605848b8605Smrg	pos = 0;
606848b8605Smrg	len = header->length * 4;
607848b8605Smrg	data = (uint8_t*)&header[1];
608848b8605Smrg	ret = MALLOC(sizeof(*ret));
609848b8605Smrg	if (!ret)
610848b8605Smrg		return NULL;
611848b8605Smrg
612848b8605Smrg	ret->header.__message = header;
613848b8605Smrg	ret->header.opcode = header->opcode;
614848b8605Smrg
615848b8605Smrg	READ(4, uint32_t, serial); /* serial */
616848b8605Smrg	READ(4, uint32_t, format); /* format */
617848b8605Smrg	READ(4, uint32_t, blockw); /* blockw */
618848b8605Smrg	READ(4, uint32_t, blockh); /* blockh */
619848b8605Smrg	READ(4, uint32_t, blocksize); /* blocksize */
620848b8605Smrg	READ_ARRAY(1, uint8_t, data); /* data */
621848b8605Smrg	READ(4, uint32_t, stride); /* stride */
622848b8605Smrg
623848b8605Smrg	return ret;
624848b8605Smrg}
625