rbug_texture.c revision dfa4ebcbcc9c7e9e7562f73a4ddc367756623e5e
1/*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24
25/*
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.
29 *
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.
33 *
34 * Functions ending with _reply are replies to requests.
35 */
36
37#include "rbug_internal.h"
38#include "rbug/rbug_texture.h"
39
40int rbug_send_texture_list(struct rbug_connection *__con,
41                           uint32_t *__serial)
42{
43	uint32_t __len = 0;
44	uint32_t __pos = 0;
45	uint8_t *__data = NULL;
46	int __ret = 0;
47
48	LEN(8); /* header */
49
50	/* align */
51	PAD(__len, 8);
52
53	__data = (uint8_t*)MALLOC(__len);
54	if (!__data)
55		return -ENOMEM;
56
57	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST));
58	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
59
60	/* final pad */
61	PAD(__pos, 8);
62
63	if (__pos != __len) {
64		__ret = -EINVAL;
65	} else {
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);
69	}
70
71	FREE(__data);
72	return __ret;
73}
74
75int rbug_send_texture_info(struct rbug_connection *__con,
76                           rbug_texture_t texture,
77                           uint32_t *__serial)
78{
79	uint32_t __len = 0;
80	uint32_t __pos = 0;
81	uint8_t *__data = NULL;
82	int __ret = 0;
83
84	LEN(8); /* header */
85	LEN(8); /* texture */
86
87	/* align */
88	PAD(__len, 8);
89
90	__data = (uint8_t*)MALLOC(__len);
91	if (!__data)
92		return -ENOMEM;
93
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 */
97
98	/* final pad */
99	PAD(__pos, 8);
100
101	if (__pos != __len) {
102		__ret = -EINVAL;
103	} else {
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);
107	}
108
109	FREE(__data);
110	return __ret;
111}
112
113int rbug_send_texture_write(struct rbug_connection *__con,
114                            rbug_texture_t texture,
115                            uint32_t face,
116                            uint32_t level,
117                            uint32_t zslice,
118                            uint32_t x,
119                            uint32_t y,
120                            uint32_t w,
121                            uint32_t h,
122                            uint8_t *data,
123                            uint32_t data_len,
124                            uint32_t stride,
125                            uint32_t *__serial)
126{
127	uint32_t __len = 0;
128	uint32_t __pos = 0;
129	uint8_t *__data = NULL;
130	int __ret = 0;
131
132	LEN(8); /* header */
133	LEN(8); /* texture */
134	LEN(4); /* face */
135	LEN(4); /* level */
136	LEN(4); /* zslice */
137	LEN(4); /* x */
138	LEN(4); /* y */
139	LEN(4); /* w */
140	LEN(4); /* h */
141	LEN_ARRAY(1, data); /* data */
142	LEN(4); /* stride */
143
144	/* align */
145	PAD(__len, 8);
146
147	__data = (uint8_t*)MALLOC(__len);
148	if (!__data)
149		return -ENOMEM;
150
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 */
163
164	/* final pad */
165	PAD(__pos, 8);
166
167	if (__pos != __len) {
168		__ret = -EINVAL;
169	} else {
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);
173	}
174
175	FREE(__data);
176	return __ret;
177}
178
179int rbug_send_texture_read(struct rbug_connection *__con,
180                           rbug_texture_t texture,
181                           uint32_t face,
182                           uint32_t level,
183                           uint32_t zslice,
184                           uint32_t x,
185                           uint32_t y,
186                           uint32_t w,
187                           uint32_t h,
188                           uint32_t *__serial)
189{
190	uint32_t __len = 0;
191	uint32_t __pos = 0;
192	uint8_t *__data = NULL;
193	int __ret = 0;
194
195	LEN(8); /* header */
196	LEN(8); /* texture */
197	LEN(4); /* face */
198	LEN(4); /* level */
199	LEN(4); /* zslice */
200	LEN(4); /* x */
201	LEN(4); /* y */
202	LEN(4); /* w */
203	LEN(4); /* h */
204
205	/* align */
206	PAD(__len, 8);
207
208	__data = (uint8_t*)MALLOC(__len);
209	if (!__data)
210		return -ENOMEM;
211
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 */
222
223	/* final pad */
224	PAD(__pos, 8);
225
226	if (__pos != __len) {
227		__ret = -EINVAL;
228	} else {
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);
232	}
233
234	FREE(__data);
235	return __ret;
236}
237
238int rbug_send_texture_list_reply(struct rbug_connection *__con,
239                                 uint32_t serial,
240                                 rbug_texture_t *textures,
241                                 uint32_t textures_len,
242                                 uint32_t *__serial)
243{
244	uint32_t __len = 0;
245	uint32_t __pos = 0;
246	uint8_t *__data = NULL;
247	int __ret = 0;
248
249	LEN(8); /* header */
250	LEN(4); /* serial */
251	LEN_ARRAY(8, textures); /* textures */
252
253	/* align */
254	PAD(__len, 8);
255
256	__data = (uint8_t*)MALLOC(__len);
257	if (!__data)
258		return -ENOMEM;
259
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 */
264
265	/* final pad */
266	PAD(__pos, 8);
267
268	if (__pos != __len) {
269		__ret = -EINVAL;
270	} else {
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);
274	}
275
276	FREE(__data);
277	return __ret;
278}
279
280int rbug_send_texture_info_reply(struct rbug_connection *__con,
281                                 uint32_t serial,
282                                 uint32_t target,
283                                 uint32_t format,
284                                 uint32_t *width,
285                                 uint32_t width_len,
286                                 uint32_t *height,
287                                 uint32_t height_len,
288                                 uint32_t *depth,
289                                 uint32_t depth_len,
290                                 uint32_t blockw,
291                                 uint32_t blockh,
292                                 uint32_t blocksize,
293                                 uint32_t last_level,
294                                 uint32_t nr_samples,
295                                 uint32_t tex_usage,
296                                 uint32_t *__serial)
297{
298	uint32_t __len = 0;
299	uint32_t __pos = 0;
300	uint8_t *__data = NULL;
301	int __ret = 0;
302
303	LEN(8); /* header */
304	LEN(4); /* serial */
305	LEN(4); /* target */
306	LEN(4); /* format */
307	LEN_ARRAY(4, width); /* width */
308	LEN_ARRAY(4, height); /* height */
309	LEN_ARRAY(4, depth); /* depth */
310	LEN(4); /* blockw */
311	LEN(4); /* blockh */
312	LEN(4); /* blocksize */
313	LEN(4); /* last_level */
314	LEN(4); /* nr_samples */
315	LEN(4); /* tex_usage */
316
317	/* align */
318	PAD(__len, 8);
319
320	__data = (uint8_t*)MALLOC(__len);
321	if (!__data)
322		return -ENOMEM;
323
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 */
338
339	/* final pad */
340	PAD(__pos, 8);
341
342	if (__pos != __len) {
343		__ret = -EINVAL;
344	} else {
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);
348	}
349
350	FREE(__data);
351	return __ret;
352}
353
354int rbug_send_texture_read_reply(struct rbug_connection *__con,
355                                 uint32_t serial,
356                                 uint32_t format,
357                                 uint32_t blockw,
358                                 uint32_t blockh,
359                                 uint32_t blocksize,
360                                 uint8_t *data,
361                                 uint32_t data_len,
362                                 uint32_t stride,
363                                 uint32_t *__serial)
364{
365	uint32_t __len = 0;
366	uint32_t __pos = 0;
367	uint8_t *__data = NULL;
368	int __ret = 0;
369
370	LEN(8); /* header */
371	LEN(4); /* serial */
372	LEN(4); /* format */
373	LEN(4); /* blockw */
374	LEN(4); /* blockh */
375	LEN(4); /* blocksize */
376	LEN_ARRAY(1, data); /* data */
377	LEN(4); /* stride */
378
379	/* align */
380	PAD(__len, 8);
381
382	__data = (uint8_t*)MALLOC(__len);
383	if (!__data)
384		return -ENOMEM;
385
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 */
395
396	/* final pad */
397	PAD(__pos, 8);
398
399	if (__pos != __len) {
400		__ret = -EINVAL;
401	} else {
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);
405	}
406
407	FREE(__data);
408	return __ret;
409}
410
411struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header)
412{
413	uint32_t len = 0;
414	uint32_t pos = 0;
415	uint8_t *data =  NULL;
416	struct rbug_proto_texture_list *ret;
417
418	if (!header)
419		return NULL;
420	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST)
421		return NULL;
422
423	pos = 0;
424	len = header->length * 4;
425	data = (uint8_t*)&header[1];
426	ret = MALLOC(sizeof(*ret));
427	if (!ret)
428		return NULL;
429
430	ret->header.__message = header;
431	ret->header.opcode = header->opcode;
432
433
434	return ret;
435}
436
437struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header)
438{
439	uint32_t len = 0;
440	uint32_t pos = 0;
441	uint8_t *data =  NULL;
442	struct rbug_proto_texture_info *ret;
443
444	if (!header)
445		return NULL;
446	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO)
447		return NULL;
448
449	pos = 0;
450	len = header->length * 4;
451	data = (uint8_t*)&header[1];
452	ret = MALLOC(sizeof(*ret));
453	if (!ret)
454		return NULL;
455
456	ret->header.__message = header;
457	ret->header.opcode = header->opcode;
458
459	READ(8, rbug_texture_t, texture); /* texture */
460
461	return ret;
462}
463
464struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header)
465{
466	uint32_t len = 0;
467	uint32_t pos = 0;
468	uint8_t *data =  NULL;
469	struct rbug_proto_texture_write *ret;
470
471	if (!header)
472		return NULL;
473	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_WRITE)
474		return NULL;
475
476	pos = 0;
477	len = header->length * 4;
478	data = (uint8_t*)&header[1];
479	ret = MALLOC(sizeof(*ret));
480	if (!ret)
481		return NULL;
482
483	ret->header.__message = header;
484	ret->header.opcode = header->opcode;
485
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 */
496
497	return ret;
498}
499
500struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header)
501{
502	uint32_t len = 0;
503	uint32_t pos = 0;
504	uint8_t *data =  NULL;
505	struct rbug_proto_texture_read *ret;
506
507	if (!header)
508		return NULL;
509	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ)
510		return NULL;
511
512	pos = 0;
513	len = header->length * 4;
514	data = (uint8_t*)&header[1];
515	ret = MALLOC(sizeof(*ret));
516	if (!ret)
517		return NULL;
518
519	ret->header.__message = header;
520	ret->header.opcode = header->opcode;
521
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 */
530
531	return ret;
532}
533
534struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header)
535{
536	uint32_t len = 0;
537	uint32_t pos = 0;
538	uint8_t *data =  NULL;
539	struct rbug_proto_texture_list_reply *ret;
540
541	if (!header)
542		return NULL;
543	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST_REPLY)
544		return NULL;
545
546	pos = 0;
547	len = header->length * 4;
548	data = (uint8_t*)&header[1];
549	ret = MALLOC(sizeof(*ret));
550	if (!ret)
551		return NULL;
552
553	ret->header.__message = header;
554	ret->header.opcode = header->opcode;
555
556	READ(4, uint32_t, serial); /* serial */
557	READ_ARRAY(8, rbug_texture_t, textures); /* textures */
558
559	return ret;
560}
561
562struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header)
563{
564	uint32_t len = 0;
565	uint32_t pos = 0;
566	uint8_t *data =  NULL;
567	struct rbug_proto_texture_info_reply *ret;
568
569	if (!header)
570		return NULL;
571	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO_REPLY)
572		return NULL;
573
574	pos = 0;
575	len = header->length * 4;
576	data = (uint8_t*)&header[1];
577	ret = MALLOC(sizeof(*ret));
578	if (!ret)
579		return NULL;
580
581	ret->header.__message = header;
582	ret->header.opcode = header->opcode;
583
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 */
596
597	return ret;
598}
599
600struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header)
601{
602	uint32_t len = 0;
603	uint32_t pos = 0;
604	uint8_t *data =  NULL;
605	struct rbug_proto_texture_read_reply *ret;
606
607	if (!header)
608		return NULL;
609	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ_REPLY)
610		return NULL;
611
612	pos = 0;
613	len = header->length * 4;
614	data = (uint8_t*)&header[1];
615	ret = MALLOC(sizeof(*ret));
616	if (!ret)
617		return NULL;
618
619	ret->header.__message = header;
620	ret->header.opcode = header->opcode;
621
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 */
629
630	return ret;
631}
632