1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
3bf215546Sopenharmony_ci * All Rights Reserved.
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
9bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
10bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci/*
26bf215546Sopenharmony_ci * This file holds the function implementation for one of the rbug extensions.
27bf215546Sopenharmony_ci * Prototypes and declerations of functions and structs is in the same folder
28bf215546Sopenharmony_ci * in the header file matching this file's name.
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * The functions starting rbug_send_* encodes a call to the write format and
31bf215546Sopenharmony_ci * sends that to the supplied connection, while functions starting with
32bf215546Sopenharmony_ci * rbug_demarshal_* demarshal data in the wire protocol.
33bf215546Sopenharmony_ci *
34bf215546Sopenharmony_ci * Functions ending with _reply are replies to requests.
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "c99_alloca.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "rbug_internal.h"
40bf215546Sopenharmony_ci#include "rbug_texture.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ciint rbug_send_texture_list(struct rbug_connection *__con,
43bf215546Sopenharmony_ci                           uint32_t *__serial)
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci	uint32_t __len = 0;
46bf215546Sopenharmony_ci	uint32_t __pos = 0;
47bf215546Sopenharmony_ci	uint8_t *__data = NULL;
48bf215546Sopenharmony_ci	int __ret = 0;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci	LEN(8); /* header */
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci	/* align */
53bf215546Sopenharmony_ci	PAD(__len, 8);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
56bf215546Sopenharmony_ci	if (!__data)
57bf215546Sopenharmony_ci		return -ENOMEM;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST));
60bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci	/* final pad */
63bf215546Sopenharmony_ci	PAD(__pos, 8);
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci	if (__pos != __len) {
66bf215546Sopenharmony_ci		__ret = -EINVAL;
67bf215546Sopenharmony_ci	} else {
68bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len);
69bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
70bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
71bf215546Sopenharmony_ci	}
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci	FREE(__data);
74bf215546Sopenharmony_ci	return __ret;
75bf215546Sopenharmony_ci}
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ciint rbug_send_texture_info(struct rbug_connection *__con,
78bf215546Sopenharmony_ci                           rbug_texture_t texture,
79bf215546Sopenharmony_ci                           uint32_t *__serial)
80bf215546Sopenharmony_ci{
81bf215546Sopenharmony_ci	uint32_t __len = 0;
82bf215546Sopenharmony_ci	uint32_t __pos = 0;
83bf215546Sopenharmony_ci	uint8_t *__data = NULL;
84bf215546Sopenharmony_ci	int __ret = 0;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci	LEN(8); /* header */
87bf215546Sopenharmony_ci	LEN(8); /* texture */
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci	/* align */
90bf215546Sopenharmony_ci	PAD(__len, 8);
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
93bf215546Sopenharmony_ci	if (!__data)
94bf215546Sopenharmony_ci		return -ENOMEM;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO));
97bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
98bf215546Sopenharmony_ci	WRITE(8, rbug_texture_t, texture); /* texture */
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci	/* final pad */
101bf215546Sopenharmony_ci	PAD(__pos, 8);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci	if (__pos != __len) {
104bf215546Sopenharmony_ci		__ret = -EINVAL;
105bf215546Sopenharmony_ci	} else {
106bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len);
107bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
108bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
109bf215546Sopenharmony_ci	}
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci	FREE(__data);
112bf215546Sopenharmony_ci	return __ret;
113bf215546Sopenharmony_ci}
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ciint rbug_send_texture_write(struct rbug_connection *__con,
116bf215546Sopenharmony_ci                            rbug_texture_t texture,
117bf215546Sopenharmony_ci                            uint32_t face,
118bf215546Sopenharmony_ci                            uint32_t level,
119bf215546Sopenharmony_ci                            uint32_t zslice,
120bf215546Sopenharmony_ci                            uint32_t x,
121bf215546Sopenharmony_ci                            uint32_t y,
122bf215546Sopenharmony_ci                            uint32_t w,
123bf215546Sopenharmony_ci                            uint32_t h,
124bf215546Sopenharmony_ci                            uint8_t *data,
125bf215546Sopenharmony_ci                            uint32_t data_len,
126bf215546Sopenharmony_ci                            uint32_t stride,
127bf215546Sopenharmony_ci                            uint32_t *__serial)
128bf215546Sopenharmony_ci{
129bf215546Sopenharmony_ci	uint32_t __len = 0;
130bf215546Sopenharmony_ci	uint32_t __pos = 0;
131bf215546Sopenharmony_ci	uint8_t *__data = NULL;
132bf215546Sopenharmony_ci	int __ret = 0;
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_ci	LEN(8); /* header */
135bf215546Sopenharmony_ci	LEN(8); /* texture */
136bf215546Sopenharmony_ci	LEN(4); /* face */
137bf215546Sopenharmony_ci	LEN(4); /* level */
138bf215546Sopenharmony_ci	LEN(4); /* zslice */
139bf215546Sopenharmony_ci	LEN(4); /* x */
140bf215546Sopenharmony_ci	LEN(4); /* y */
141bf215546Sopenharmony_ci	LEN(4); /* w */
142bf215546Sopenharmony_ci	LEN(4); /* h */
143bf215546Sopenharmony_ci	LEN_ARRAY(1, data); /* data */
144bf215546Sopenharmony_ci	LEN(4); /* stride */
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci	/* align */
147bf215546Sopenharmony_ci	PAD(__len, 8);
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
150bf215546Sopenharmony_ci	if (!__data)
151bf215546Sopenharmony_ci		return -ENOMEM;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE));
154bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
155bf215546Sopenharmony_ci	WRITE(8, rbug_texture_t, texture); /* texture */
156bf215546Sopenharmony_ci	WRITE(4, uint32_t, face); /* face */
157bf215546Sopenharmony_ci	WRITE(4, uint32_t, level); /* level */
158bf215546Sopenharmony_ci	WRITE(4, uint32_t, zslice); /* zslice */
159bf215546Sopenharmony_ci	WRITE(4, uint32_t, x); /* x */
160bf215546Sopenharmony_ci	WRITE(4, uint32_t, y); /* y */
161bf215546Sopenharmony_ci	WRITE(4, uint32_t, w); /* w */
162bf215546Sopenharmony_ci	WRITE(4, uint32_t, h); /* h */
163bf215546Sopenharmony_ci	WRITE_ARRAY(1, uint8_t, data); /* data */
164bf215546Sopenharmony_ci	WRITE(4, uint32_t, stride); /* stride */
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci	/* final pad */
167bf215546Sopenharmony_ci	PAD(__pos, 8);
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci	if (__pos != __len) {
170bf215546Sopenharmony_ci		__ret = -EINVAL;
171bf215546Sopenharmony_ci	} else {
172bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len);
173bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
174bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
175bf215546Sopenharmony_ci	}
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci	FREE(__data);
178bf215546Sopenharmony_ci	return __ret;
179bf215546Sopenharmony_ci}
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ciint rbug_send_texture_read(struct rbug_connection *__con,
182bf215546Sopenharmony_ci                           rbug_texture_t texture,
183bf215546Sopenharmony_ci                           uint32_t face,
184bf215546Sopenharmony_ci                           uint32_t level,
185bf215546Sopenharmony_ci                           uint32_t zslice,
186bf215546Sopenharmony_ci                           uint32_t x,
187bf215546Sopenharmony_ci                           uint32_t y,
188bf215546Sopenharmony_ci                           uint32_t w,
189bf215546Sopenharmony_ci                           uint32_t h,
190bf215546Sopenharmony_ci                           uint32_t *__serial)
191bf215546Sopenharmony_ci{
192bf215546Sopenharmony_ci	uint32_t __len = 0;
193bf215546Sopenharmony_ci	uint32_t __pos = 0;
194bf215546Sopenharmony_ci	uint8_t *__data = NULL;
195bf215546Sopenharmony_ci	int __ret = 0;
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci	LEN(8); /* header */
198bf215546Sopenharmony_ci	LEN(8); /* texture */
199bf215546Sopenharmony_ci	LEN(4); /* face */
200bf215546Sopenharmony_ci	LEN(4); /* level */
201bf215546Sopenharmony_ci	LEN(4); /* zslice */
202bf215546Sopenharmony_ci	LEN(4); /* x */
203bf215546Sopenharmony_ci	LEN(4); /* y */
204bf215546Sopenharmony_ci	LEN(4); /* w */
205bf215546Sopenharmony_ci	LEN(4); /* h */
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci	/* align */
208bf215546Sopenharmony_ci	PAD(__len, 8);
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
211bf215546Sopenharmony_ci	if (!__data)
212bf215546Sopenharmony_ci		return -ENOMEM;
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ));
215bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
216bf215546Sopenharmony_ci	WRITE(8, rbug_texture_t, texture); /* texture */
217bf215546Sopenharmony_ci	WRITE(4, uint32_t, face); /* face */
218bf215546Sopenharmony_ci	WRITE(4, uint32_t, level); /* level */
219bf215546Sopenharmony_ci	WRITE(4, uint32_t, zslice); /* zslice */
220bf215546Sopenharmony_ci	WRITE(4, uint32_t, x); /* x */
221bf215546Sopenharmony_ci	WRITE(4, uint32_t, y); /* y */
222bf215546Sopenharmony_ci	WRITE(4, uint32_t, w); /* w */
223bf215546Sopenharmony_ci	WRITE(4, uint32_t, h); /* h */
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci	/* final pad */
226bf215546Sopenharmony_ci	PAD(__pos, 8);
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ci	if (__pos != __len) {
229bf215546Sopenharmony_ci		__ret = -EINVAL;
230bf215546Sopenharmony_ci	} else {
231bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len);
232bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
233bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
234bf215546Sopenharmony_ci	}
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci	FREE(__data);
237bf215546Sopenharmony_ci	return __ret;
238bf215546Sopenharmony_ci}
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ciint rbug_send_texture_list_reply(struct rbug_connection *__con,
241bf215546Sopenharmony_ci                                 uint32_t serial,
242bf215546Sopenharmony_ci                                 rbug_texture_t *textures,
243bf215546Sopenharmony_ci                                 uint32_t textures_len,
244bf215546Sopenharmony_ci                                 uint32_t *__serial)
245bf215546Sopenharmony_ci{
246bf215546Sopenharmony_ci	uint32_t __len = 0;
247bf215546Sopenharmony_ci	uint32_t __pos = 0;
248bf215546Sopenharmony_ci	uint8_t *__data = NULL;
249bf215546Sopenharmony_ci	int __ret = 0;
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci	LEN(8); /* header */
252bf215546Sopenharmony_ci	LEN(4); /* serial */
253bf215546Sopenharmony_ci	LEN_ARRAY(8, textures); /* textures */
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_ci	/* align */
256bf215546Sopenharmony_ci	PAD(__len, 8);
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
259bf215546Sopenharmony_ci	if (!__data)
260bf215546Sopenharmony_ci		return -ENOMEM;
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY));
263bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
264bf215546Sopenharmony_ci	WRITE(4, uint32_t, serial); /* serial */
265bf215546Sopenharmony_ci	WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */
266bf215546Sopenharmony_ci
267bf215546Sopenharmony_ci	/* final pad */
268bf215546Sopenharmony_ci	PAD(__pos, 8);
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci	if (__pos != __len) {
271bf215546Sopenharmony_ci		__ret = -EINVAL;
272bf215546Sopenharmony_ci	} else {
273bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len);
274bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
275bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
276bf215546Sopenharmony_ci	}
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci	FREE(__data);
279bf215546Sopenharmony_ci	return __ret;
280bf215546Sopenharmony_ci}
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ciint rbug_send_texture_info_reply(struct rbug_connection *__con,
283bf215546Sopenharmony_ci                                 uint32_t serial,
284bf215546Sopenharmony_ci                                 uint32_t target,
285bf215546Sopenharmony_ci                                 uint32_t format,
286bf215546Sopenharmony_ci                                 uint32_t *width,
287bf215546Sopenharmony_ci                                 uint32_t width_len,
288bf215546Sopenharmony_ci                                 uint16_t *h16,
289bf215546Sopenharmony_ci                                 uint32_t height_len,
290bf215546Sopenharmony_ci                                 uint16_t *d16,
291bf215546Sopenharmony_ci                                 uint32_t depth_len,
292bf215546Sopenharmony_ci                                 uint32_t blockw,
293bf215546Sopenharmony_ci                                 uint32_t blockh,
294bf215546Sopenharmony_ci                                 uint32_t blocksize,
295bf215546Sopenharmony_ci                                 uint32_t last_level,
296bf215546Sopenharmony_ci                                 uint32_t nr_samples,
297bf215546Sopenharmony_ci                                 uint32_t tex_usage,
298bf215546Sopenharmony_ci                                 uint32_t *__serial)
299bf215546Sopenharmony_ci{
300bf215546Sopenharmony_ci	uint32_t __len = 0;
301bf215546Sopenharmony_ci	uint32_t __pos = 0;
302bf215546Sopenharmony_ci	uint8_t *__data = NULL;
303bf215546Sopenharmony_ci	int __ret = 0;
304bf215546Sopenharmony_ci	uint32_t *height = alloca(sizeof(uint32_t) * height_len);
305bf215546Sopenharmony_ci	uint32_t *depth = alloca(sizeof(uint32_t) * height_len);
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci	LEN(8); /* header */
308bf215546Sopenharmony_ci	LEN(4); /* serial */
309bf215546Sopenharmony_ci	LEN(4); /* target */
310bf215546Sopenharmony_ci	LEN(4); /* format */
311bf215546Sopenharmony_ci	LEN_ARRAY(4, width); /* width */
312bf215546Sopenharmony_ci	LEN_ARRAY(4, height); /* height */
313bf215546Sopenharmony_ci	LEN_ARRAY(4, depth); /* depth */
314bf215546Sopenharmony_ci	LEN(4); /* blockw */
315bf215546Sopenharmony_ci	LEN(4); /* blockh */
316bf215546Sopenharmony_ci	LEN(4); /* blocksize */
317bf215546Sopenharmony_ci	LEN(4); /* last_level */
318bf215546Sopenharmony_ci	LEN(4); /* nr_samples */
319bf215546Sopenharmony_ci	LEN(4); /* tex_usage */
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci	/* align */
322bf215546Sopenharmony_ci	PAD(__len, 8);
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
325bf215546Sopenharmony_ci	if (!__data)
326bf215546Sopenharmony_ci		return -ENOMEM;
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci	for (int i = 0; i < height_len; i++)
329bf215546Sopenharmony_ci		height[i] = h16[i];
330bf215546Sopenharmony_ci	for (int i = 0; i < depth_len; i++)
331bf215546Sopenharmony_ci		depth[i] = d16[i];
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY));
334bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
335bf215546Sopenharmony_ci	WRITE(4, uint32_t, serial); /* serial */
336bf215546Sopenharmony_ci	WRITE(4, uint32_t, target); /* target */
337bf215546Sopenharmony_ci	WRITE(4, uint32_t, format); /* format */
338bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, width); /* width */
339bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, height); /* height */
340bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, depth); /* depth */
341bf215546Sopenharmony_ci	WRITE(4, uint32_t, blockw); /* blockw */
342bf215546Sopenharmony_ci	WRITE(4, uint32_t, blockh); /* blockh */
343bf215546Sopenharmony_ci	WRITE(4, uint32_t, blocksize); /* blocksize */
344bf215546Sopenharmony_ci	WRITE(4, uint32_t, last_level); /* last_level */
345bf215546Sopenharmony_ci	WRITE(4, uint32_t, nr_samples); /* nr_samples */
346bf215546Sopenharmony_ci	WRITE(4, uint32_t, tex_usage); /* tex_usage */
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci	/* final pad */
349bf215546Sopenharmony_ci	PAD(__pos, 8);
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci	if (__pos != __len) {
352bf215546Sopenharmony_ci		__ret = -EINVAL;
353bf215546Sopenharmony_ci	} else {
354bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len);
355bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
356bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
357bf215546Sopenharmony_ci	}
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci	FREE(__data);
360bf215546Sopenharmony_ci	return __ret;
361bf215546Sopenharmony_ci}
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ciint rbug_send_texture_read_reply(struct rbug_connection *__con,
364bf215546Sopenharmony_ci                                 uint32_t serial,
365bf215546Sopenharmony_ci                                 uint32_t format,
366bf215546Sopenharmony_ci                                 uint32_t blockw,
367bf215546Sopenharmony_ci                                 uint32_t blockh,
368bf215546Sopenharmony_ci                                 uint32_t blocksize,
369bf215546Sopenharmony_ci                                 uint8_t *data,
370bf215546Sopenharmony_ci                                 uint32_t data_len,
371bf215546Sopenharmony_ci                                 uint32_t stride,
372bf215546Sopenharmony_ci                                 uint32_t *__serial)
373bf215546Sopenharmony_ci{
374bf215546Sopenharmony_ci	uint32_t __len = 0;
375bf215546Sopenharmony_ci	uint32_t __pos = 0;
376bf215546Sopenharmony_ci	uint8_t *__data = NULL;
377bf215546Sopenharmony_ci	int __ret = 0;
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci	LEN(8); /* header */
380bf215546Sopenharmony_ci	LEN(4); /* serial */
381bf215546Sopenharmony_ci	LEN(4); /* format */
382bf215546Sopenharmony_ci	LEN(4); /* blockw */
383bf215546Sopenharmony_ci	LEN(4); /* blockh */
384bf215546Sopenharmony_ci	LEN(4); /* blocksize */
385bf215546Sopenharmony_ci	LEN_ARRAY(1, data); /* data */
386bf215546Sopenharmony_ci	LEN(4); /* stride */
387bf215546Sopenharmony_ci
388bf215546Sopenharmony_ci	/* align */
389bf215546Sopenharmony_ci	PAD(__len, 8);
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
392bf215546Sopenharmony_ci	if (!__data)
393bf215546Sopenharmony_ci		return -ENOMEM;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY));
396bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
397bf215546Sopenharmony_ci	WRITE(4, uint32_t, serial); /* serial */
398bf215546Sopenharmony_ci	WRITE(4, uint32_t, format); /* format */
399bf215546Sopenharmony_ci	WRITE(4, uint32_t, blockw); /* blockw */
400bf215546Sopenharmony_ci	WRITE(4, uint32_t, blockh); /* blockh */
401bf215546Sopenharmony_ci	WRITE(4, uint32_t, blocksize); /* blocksize */
402bf215546Sopenharmony_ci	WRITE_ARRAY(1, uint8_t, data); /* data */
403bf215546Sopenharmony_ci	WRITE(4, uint32_t, stride); /* stride */
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci	/* final pad */
406bf215546Sopenharmony_ci	PAD(__pos, 8);
407bf215546Sopenharmony_ci
408bf215546Sopenharmony_ci	if (__pos != __len) {
409bf215546Sopenharmony_ci		__ret = -EINVAL;
410bf215546Sopenharmony_ci	} else {
411bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len);
412bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
413bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
414bf215546Sopenharmony_ci	}
415bf215546Sopenharmony_ci
416bf215546Sopenharmony_ci	FREE(__data);
417bf215546Sopenharmony_ci	return __ret;
418bf215546Sopenharmony_ci}
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_cistruct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header)
421bf215546Sopenharmony_ci{
422bf215546Sopenharmony_ci	struct rbug_proto_texture_list *ret;
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci	if (!header)
425bf215546Sopenharmony_ci		return NULL;
426bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST)
427bf215546Sopenharmony_ci		return NULL;
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
430bf215546Sopenharmony_ci	if (!ret)
431bf215546Sopenharmony_ci		return NULL;
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci	ret->header.__message = header;
434bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci	return ret;
437bf215546Sopenharmony_ci}
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_cistruct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header)
440bf215546Sopenharmony_ci{
441bf215546Sopenharmony_ci	uint32_t len = 0;
442bf215546Sopenharmony_ci	uint32_t pos = 0;
443bf215546Sopenharmony_ci	uint8_t *data =  NULL;
444bf215546Sopenharmony_ci	struct rbug_proto_texture_info *ret;
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_ci	if (!header)
447bf215546Sopenharmony_ci		return NULL;
448bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO)
449bf215546Sopenharmony_ci		return NULL;
450bf215546Sopenharmony_ci
451bf215546Sopenharmony_ci	pos = 0;
452bf215546Sopenharmony_ci	len = header->length * 4;
453bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
454bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
455bf215546Sopenharmony_ci	if (!ret)
456bf215546Sopenharmony_ci		return NULL;
457bf215546Sopenharmony_ci
458bf215546Sopenharmony_ci	ret->header.__message = header;
459bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ci	READ(8, rbug_texture_t, texture); /* texture */
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci	return ret;
464bf215546Sopenharmony_ci}
465bf215546Sopenharmony_ci
466bf215546Sopenharmony_cistruct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header)
467bf215546Sopenharmony_ci{
468bf215546Sopenharmony_ci	uint32_t len = 0;
469bf215546Sopenharmony_ci	uint32_t pos = 0;
470bf215546Sopenharmony_ci	uint8_t *data =  NULL;
471bf215546Sopenharmony_ci	struct rbug_proto_texture_write *ret;
472bf215546Sopenharmony_ci
473bf215546Sopenharmony_ci	if (!header)
474bf215546Sopenharmony_ci		return NULL;
475bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_WRITE)
476bf215546Sopenharmony_ci		return NULL;
477bf215546Sopenharmony_ci
478bf215546Sopenharmony_ci	pos = 0;
479bf215546Sopenharmony_ci	len = header->length * 4;
480bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
481bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
482bf215546Sopenharmony_ci	if (!ret)
483bf215546Sopenharmony_ci		return NULL;
484bf215546Sopenharmony_ci
485bf215546Sopenharmony_ci	ret->header.__message = header;
486bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
487bf215546Sopenharmony_ci
488bf215546Sopenharmony_ci	READ(8, rbug_texture_t, texture); /* texture */
489bf215546Sopenharmony_ci	READ(4, uint32_t, face); /* face */
490bf215546Sopenharmony_ci	READ(4, uint32_t, level); /* level */
491bf215546Sopenharmony_ci	READ(4, uint32_t, zslice); /* zslice */
492bf215546Sopenharmony_ci	READ(4, uint32_t, x); /* x */
493bf215546Sopenharmony_ci	READ(4, uint32_t, y); /* y */
494bf215546Sopenharmony_ci	READ(4, uint32_t, w); /* w */
495bf215546Sopenharmony_ci	READ(4, uint32_t, h); /* h */
496bf215546Sopenharmony_ci	READ_ARRAY(1, uint8_t, data); /* data */
497bf215546Sopenharmony_ci	READ(4, uint32_t, stride); /* stride */
498bf215546Sopenharmony_ci
499bf215546Sopenharmony_ci	return ret;
500bf215546Sopenharmony_ci}
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_cistruct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header)
503bf215546Sopenharmony_ci{
504bf215546Sopenharmony_ci	uint32_t len = 0;
505bf215546Sopenharmony_ci	uint32_t pos = 0;
506bf215546Sopenharmony_ci	uint8_t *data =  NULL;
507bf215546Sopenharmony_ci	struct rbug_proto_texture_read *ret;
508bf215546Sopenharmony_ci
509bf215546Sopenharmony_ci	if (!header)
510bf215546Sopenharmony_ci		return NULL;
511bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ)
512bf215546Sopenharmony_ci		return NULL;
513bf215546Sopenharmony_ci
514bf215546Sopenharmony_ci	pos = 0;
515bf215546Sopenharmony_ci	len = header->length * 4;
516bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
517bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
518bf215546Sopenharmony_ci	if (!ret)
519bf215546Sopenharmony_ci		return NULL;
520bf215546Sopenharmony_ci
521bf215546Sopenharmony_ci	ret->header.__message = header;
522bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
523bf215546Sopenharmony_ci
524bf215546Sopenharmony_ci	READ(8, rbug_texture_t, texture); /* texture */
525bf215546Sopenharmony_ci	READ(4, uint32_t, face); /* face */
526bf215546Sopenharmony_ci	READ(4, uint32_t, level); /* level */
527bf215546Sopenharmony_ci	READ(4, uint32_t, zslice); /* zslice */
528bf215546Sopenharmony_ci	READ(4, uint32_t, x); /* x */
529bf215546Sopenharmony_ci	READ(4, uint32_t, y); /* y */
530bf215546Sopenharmony_ci	READ(4, uint32_t, w); /* w */
531bf215546Sopenharmony_ci	READ(4, uint32_t, h); /* h */
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_ci	return ret;
534bf215546Sopenharmony_ci}
535bf215546Sopenharmony_ci
536bf215546Sopenharmony_cistruct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header)
537bf215546Sopenharmony_ci{
538bf215546Sopenharmony_ci	uint32_t len = 0;
539bf215546Sopenharmony_ci	uint32_t pos = 0;
540bf215546Sopenharmony_ci	uint8_t *data =  NULL;
541bf215546Sopenharmony_ci	struct rbug_proto_texture_list_reply *ret;
542bf215546Sopenharmony_ci
543bf215546Sopenharmony_ci	if (!header)
544bf215546Sopenharmony_ci		return NULL;
545bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST_REPLY)
546bf215546Sopenharmony_ci		return NULL;
547bf215546Sopenharmony_ci
548bf215546Sopenharmony_ci	pos = 0;
549bf215546Sopenharmony_ci	len = header->length * 4;
550bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
551bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
552bf215546Sopenharmony_ci	if (!ret)
553bf215546Sopenharmony_ci		return NULL;
554bf215546Sopenharmony_ci
555bf215546Sopenharmony_ci	ret->header.__message = header;
556bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
557bf215546Sopenharmony_ci
558bf215546Sopenharmony_ci	READ(4, uint32_t, serial); /* serial */
559bf215546Sopenharmony_ci	READ_ARRAY(8, rbug_texture_t, textures); /* textures */
560bf215546Sopenharmony_ci
561bf215546Sopenharmony_ci	return ret;
562bf215546Sopenharmony_ci}
563bf215546Sopenharmony_ci
564bf215546Sopenharmony_cistruct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header)
565bf215546Sopenharmony_ci{
566bf215546Sopenharmony_ci	uint32_t len = 0;
567bf215546Sopenharmony_ci	uint32_t pos = 0;
568bf215546Sopenharmony_ci	uint8_t *data =  NULL;
569bf215546Sopenharmony_ci	struct rbug_proto_texture_info_reply *ret;
570bf215546Sopenharmony_ci
571bf215546Sopenharmony_ci	if (!header)
572bf215546Sopenharmony_ci		return NULL;
573bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO_REPLY)
574bf215546Sopenharmony_ci		return NULL;
575bf215546Sopenharmony_ci
576bf215546Sopenharmony_ci	pos = 0;
577bf215546Sopenharmony_ci	len = header->length * 4;
578bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
579bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
580bf215546Sopenharmony_ci	if (!ret)
581bf215546Sopenharmony_ci		return NULL;
582bf215546Sopenharmony_ci
583bf215546Sopenharmony_ci	ret->header.__message = header;
584bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci	READ(4, uint32_t, serial); /* serial */
587bf215546Sopenharmony_ci	READ(4, uint32_t, target); /* target */
588bf215546Sopenharmony_ci	READ(4, uint32_t, format); /* format */
589bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, width); /* width */
590bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, height); /* height */
591bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, depth); /* depth */
592bf215546Sopenharmony_ci	READ(4, uint32_t, blockw); /* blockw */
593bf215546Sopenharmony_ci	READ(4, uint32_t, blockh); /* blockh */
594bf215546Sopenharmony_ci	READ(4, uint32_t, blocksize); /* blocksize */
595bf215546Sopenharmony_ci	READ(4, uint32_t, last_level); /* last_level */
596bf215546Sopenharmony_ci	READ(4, uint32_t, nr_samples); /* nr_samples */
597bf215546Sopenharmony_ci	READ(4, uint32_t, tex_usage); /* tex_usage */
598bf215546Sopenharmony_ci
599bf215546Sopenharmony_ci	return ret;
600bf215546Sopenharmony_ci}
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_cistruct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header)
603bf215546Sopenharmony_ci{
604bf215546Sopenharmony_ci	uint32_t len = 0;
605bf215546Sopenharmony_ci	uint32_t pos = 0;
606bf215546Sopenharmony_ci	uint8_t *data =  NULL;
607bf215546Sopenharmony_ci	struct rbug_proto_texture_read_reply *ret;
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci	if (!header)
610bf215546Sopenharmony_ci		return NULL;
611bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ_REPLY)
612bf215546Sopenharmony_ci		return NULL;
613bf215546Sopenharmony_ci
614bf215546Sopenharmony_ci	pos = 0;
615bf215546Sopenharmony_ci	len = header->length * 4;
616bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
617bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
618bf215546Sopenharmony_ci	if (!ret)
619bf215546Sopenharmony_ci		return NULL;
620bf215546Sopenharmony_ci
621bf215546Sopenharmony_ci	ret->header.__message = header;
622bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
623bf215546Sopenharmony_ci
624bf215546Sopenharmony_ci	READ(4, uint32_t, serial); /* serial */
625bf215546Sopenharmony_ci	READ(4, uint32_t, format); /* format */
626bf215546Sopenharmony_ci	READ(4, uint32_t, blockw); /* blockw */
627bf215546Sopenharmony_ci	READ(4, uint32_t, blockh); /* blockh */
628bf215546Sopenharmony_ci	READ(4, uint32_t, blocksize); /* blocksize */
629bf215546Sopenharmony_ci	READ_ARRAY(1, uint8_t, data); /* data */
630bf215546Sopenharmony_ci	READ(4, uint32_t, stride); /* stride */
631bf215546Sopenharmony_ci
632bf215546Sopenharmony_ci	return ret;
633bf215546Sopenharmony_ci}
634