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_context.h"
39848b8605Smrg
40848b8605Smrgint rbug_send_context_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_CONTEXT_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_CONTEXT_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_context_info(struct rbug_connection *__con,
76848b8605Smrg                           rbug_context_t context,
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); /* context */
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_CONTEXT_INFO));
95848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
96848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
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_CONTEXT_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_context_draw_block(struct rbug_connection *__con,
114848b8605Smrg                                 rbug_context_t context,
115848b8605Smrg                                 rbug_block_t block,
116848b8605Smrg                                 uint32_t *__serial)
117848b8605Smrg{
118848b8605Smrg	uint32_t __len = 0;
119848b8605Smrg	uint32_t __pos = 0;
120848b8605Smrg	uint8_t *__data = NULL;
121848b8605Smrg	int __ret = 0;
122848b8605Smrg
123848b8605Smrg	LEN(8); /* header */
124848b8605Smrg	LEN(8); /* context */
125848b8605Smrg	LEN(4); /* block */
126848b8605Smrg
127848b8605Smrg	/* align */
128848b8605Smrg	PAD(__len, 8);
129848b8605Smrg
130848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
131848b8605Smrg	if (!__data)
132848b8605Smrg		return -ENOMEM;
133848b8605Smrg
134848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK));
135848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
136848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
137848b8605Smrg	WRITE(4, rbug_block_t, block); /* block */
138848b8605Smrg
139848b8605Smrg	/* final pad */
140848b8605Smrg	PAD(__pos, 8);
141848b8605Smrg
142848b8605Smrg	if (__pos != __len) {
143848b8605Smrg		__ret = -EINVAL;
144848b8605Smrg	} else {
145848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCK, __len);
146848b8605Smrg		rbug_connection_write(__con, __data, __len);
147848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
148848b8605Smrg	}
149848b8605Smrg
150848b8605Smrg	FREE(__data);
151848b8605Smrg	return __ret;
152848b8605Smrg}
153848b8605Smrg
154848b8605Smrgint rbug_send_context_draw_step(struct rbug_connection *__con,
155848b8605Smrg                                rbug_context_t context,
156848b8605Smrg                                rbug_block_t step,
157848b8605Smrg                                uint32_t *__serial)
158848b8605Smrg{
159848b8605Smrg	uint32_t __len = 0;
160848b8605Smrg	uint32_t __pos = 0;
161848b8605Smrg	uint8_t *__data = NULL;
162848b8605Smrg	int __ret = 0;
163848b8605Smrg
164848b8605Smrg	LEN(8); /* header */
165848b8605Smrg	LEN(8); /* context */
166848b8605Smrg	LEN(4); /* step */
167848b8605Smrg
168848b8605Smrg	/* align */
169848b8605Smrg	PAD(__len, 8);
170848b8605Smrg
171848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
172848b8605Smrg	if (!__data)
173848b8605Smrg		return -ENOMEM;
174848b8605Smrg
175848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_STEP));
176848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
177848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
178848b8605Smrg	WRITE(4, rbug_block_t, step); /* step */
179848b8605Smrg
180848b8605Smrg	/* final pad */
181848b8605Smrg	PAD(__pos, 8);
182848b8605Smrg
183848b8605Smrg	if (__pos != __len) {
184848b8605Smrg		__ret = -EINVAL;
185848b8605Smrg	} else {
186848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_STEP, __len);
187848b8605Smrg		rbug_connection_write(__con, __data, __len);
188848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
189848b8605Smrg	}
190848b8605Smrg
191848b8605Smrg	FREE(__data);
192848b8605Smrg	return __ret;
193848b8605Smrg}
194848b8605Smrg
195848b8605Smrgint rbug_send_context_draw_unblock(struct rbug_connection *__con,
196848b8605Smrg                                   rbug_context_t context,
197848b8605Smrg                                   rbug_block_t unblock,
198848b8605Smrg                                   uint32_t *__serial)
199848b8605Smrg{
200848b8605Smrg	uint32_t __len = 0;
201848b8605Smrg	uint32_t __pos = 0;
202848b8605Smrg	uint8_t *__data = NULL;
203848b8605Smrg	int __ret = 0;
204848b8605Smrg
205848b8605Smrg	LEN(8); /* header */
206848b8605Smrg	LEN(8); /* context */
207848b8605Smrg	LEN(4); /* unblock */
208848b8605Smrg
209848b8605Smrg	/* align */
210848b8605Smrg	PAD(__len, 8);
211848b8605Smrg
212848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
213848b8605Smrg	if (!__data)
214848b8605Smrg		return -ENOMEM;
215848b8605Smrg
216848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK));
217848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
218848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
219848b8605Smrg	WRITE(4, rbug_block_t, unblock); /* unblock */
220848b8605Smrg
221848b8605Smrg	/* final pad */
222848b8605Smrg	PAD(__pos, 8);
223848b8605Smrg
224848b8605Smrg	if (__pos != __len) {
225848b8605Smrg		__ret = -EINVAL;
226848b8605Smrg	} else {
227848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_UNBLOCK, __len);
228848b8605Smrg		rbug_connection_write(__con, __data, __len);
229848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
230848b8605Smrg	}
231848b8605Smrg
232848b8605Smrg	FREE(__data);
233848b8605Smrg	return __ret;
234848b8605Smrg}
235848b8605Smrg
236848b8605Smrgint rbug_send_context_draw_rule(struct rbug_connection *__con,
237848b8605Smrg                                rbug_context_t context,
238848b8605Smrg                                rbug_shader_t vertex,
239848b8605Smrg                                rbug_shader_t fragment,
240848b8605Smrg                                rbug_texture_t texture,
241848b8605Smrg                                rbug_texture_t surface,
242848b8605Smrg                                rbug_block_t block,
243848b8605Smrg                                uint32_t *__serial)
244848b8605Smrg{
245848b8605Smrg	uint32_t __len = 0;
246848b8605Smrg	uint32_t __pos = 0;
247848b8605Smrg	uint8_t *__data = NULL;
248848b8605Smrg	int __ret = 0;
249848b8605Smrg
250848b8605Smrg	LEN(8); /* header */
251848b8605Smrg	LEN(8); /* context */
252848b8605Smrg	LEN(8); /* vertex */
253848b8605Smrg	LEN(8); /* fragment */
254848b8605Smrg	LEN(8); /* texture */
255848b8605Smrg	LEN(8); /* surface */
256848b8605Smrg	LEN(4); /* block */
257848b8605Smrg
258848b8605Smrg	/* align */
259848b8605Smrg	PAD(__len, 8);
260848b8605Smrg
261848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
262848b8605Smrg	if (!__data)
263848b8605Smrg		return -ENOMEM;
264848b8605Smrg
265848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_RULE));
266848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
267848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
268848b8605Smrg	WRITE(8, rbug_shader_t, vertex); /* vertex */
269848b8605Smrg	WRITE(8, rbug_shader_t, fragment); /* fragment */
270848b8605Smrg	WRITE(8, rbug_texture_t, texture); /* texture */
271848b8605Smrg	WRITE(8, rbug_texture_t, surface); /* surface */
272848b8605Smrg	WRITE(4, rbug_block_t, block); /* block */
273848b8605Smrg
274848b8605Smrg	/* final pad */
275848b8605Smrg	PAD(__pos, 8);
276848b8605Smrg
277848b8605Smrg	if (__pos != __len) {
278848b8605Smrg		__ret = -EINVAL;
279848b8605Smrg	} else {
280848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_RULE, __len);
281848b8605Smrg		rbug_connection_write(__con, __data, __len);
282848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
283848b8605Smrg	}
284848b8605Smrg
285848b8605Smrg	FREE(__data);
286848b8605Smrg	return __ret;
287848b8605Smrg}
288848b8605Smrg
289848b8605Smrgint rbug_send_context_flush(struct rbug_connection *__con,
290848b8605Smrg                            rbug_context_t context,
291848b8605Smrg                            uint32_t *__serial)
292848b8605Smrg{
293848b8605Smrg	uint32_t __len = 0;
294848b8605Smrg	uint32_t __pos = 0;
295848b8605Smrg	uint8_t *__data = NULL;
296848b8605Smrg	int __ret = 0;
297848b8605Smrg
298848b8605Smrg	LEN(8); /* header */
299848b8605Smrg	LEN(8); /* context */
300848b8605Smrg
301848b8605Smrg	/* align */
302848b8605Smrg	PAD(__len, 8);
303848b8605Smrg
304848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
305848b8605Smrg	if (!__data)
306848b8605Smrg		return -ENOMEM;
307848b8605Smrg
308848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_FLUSH));
309848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
310848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
311848b8605Smrg
312848b8605Smrg	/* final pad */
313848b8605Smrg	PAD(__pos, 8);
314848b8605Smrg
315848b8605Smrg	if (__pos != __len) {
316848b8605Smrg		__ret = -EINVAL;
317848b8605Smrg	} else {
318848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_FLUSH, __len);
319848b8605Smrg		rbug_connection_write(__con, __data, __len);
320848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
321848b8605Smrg	}
322848b8605Smrg
323848b8605Smrg	FREE(__data);
324848b8605Smrg	return __ret;
325848b8605Smrg}
326848b8605Smrg
327848b8605Smrgint rbug_send_context_list_reply(struct rbug_connection *__con,
328848b8605Smrg                                 uint32_t serial,
329848b8605Smrg                                 rbug_context_t *contexts,
330848b8605Smrg                                 uint32_t contexts_len,
331848b8605Smrg                                 uint32_t *__serial)
332848b8605Smrg{
333848b8605Smrg	uint32_t __len = 0;
334848b8605Smrg	uint32_t __pos = 0;
335848b8605Smrg	uint8_t *__data = NULL;
336848b8605Smrg	int __ret = 0;
337848b8605Smrg
338848b8605Smrg	LEN(8); /* header */
339848b8605Smrg	LEN(4); /* serial */
340848b8605Smrg	LEN_ARRAY(8, contexts); /* contexts */
341848b8605Smrg
342848b8605Smrg	/* align */
343848b8605Smrg	PAD(__len, 8);
344848b8605Smrg
345848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
346848b8605Smrg	if (!__data)
347848b8605Smrg		return -ENOMEM;
348848b8605Smrg
349848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY));
350848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
351848b8605Smrg	WRITE(4, uint32_t, serial); /* serial */
352848b8605Smrg	WRITE_ARRAY(8, rbug_context_t, contexts); /* contexts */
353848b8605Smrg
354848b8605Smrg	/* final pad */
355848b8605Smrg	PAD(__pos, 8);
356848b8605Smrg
357848b8605Smrg	if (__pos != __len) {
358848b8605Smrg		__ret = -EINVAL;
359848b8605Smrg	} else {
360848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST_REPLY, __len);
361848b8605Smrg		rbug_connection_write(__con, __data, __len);
362848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
363848b8605Smrg	}
364848b8605Smrg
365848b8605Smrg	FREE(__data);
366848b8605Smrg	return __ret;
367848b8605Smrg}
368848b8605Smrg
369848b8605Smrgint rbug_send_context_info_reply(struct rbug_connection *__con,
370848b8605Smrg                                 uint32_t serial,
371848b8605Smrg                                 rbug_shader_t vertex,
372848b8605Smrg                                 rbug_shader_t fragment,
373848b8605Smrg                                 rbug_texture_t *texs,
374848b8605Smrg                                 uint32_t texs_len,
375848b8605Smrg                                 rbug_texture_t *cbufs,
376848b8605Smrg                                 uint32_t cbufs_len,
377848b8605Smrg                                 rbug_texture_t zsbuf,
378848b8605Smrg                                 rbug_block_t blocker,
379848b8605Smrg                                 rbug_block_t blocked,
380848b8605Smrg                                 uint32_t *__serial)
381848b8605Smrg{
382848b8605Smrg	uint32_t __len = 0;
383848b8605Smrg	uint32_t __pos = 0;
384848b8605Smrg	uint8_t *__data = NULL;
385848b8605Smrg	int __ret = 0;
386848b8605Smrg
387848b8605Smrg	LEN(8); /* header */
388848b8605Smrg	LEN(4); /* serial */
389848b8605Smrg	LEN(8); /* vertex */
390848b8605Smrg	LEN(8); /* fragment */
391848b8605Smrg	LEN_ARRAY(8, texs); /* texs */
392848b8605Smrg	LEN_ARRAY(8, cbufs); /* cbufs */
393848b8605Smrg	LEN(8); /* zsbuf */
394848b8605Smrg	LEN(4); /* blocker */
395848b8605Smrg	LEN(4); /* blocked */
396848b8605Smrg
397848b8605Smrg	/* align */
398848b8605Smrg	PAD(__len, 8);
399848b8605Smrg
400848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
401848b8605Smrg	if (!__data)
402848b8605Smrg		return -ENOMEM;
403848b8605Smrg
404848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY));
405848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
406848b8605Smrg	WRITE(4, uint32_t, serial); /* serial */
407848b8605Smrg	WRITE(8, rbug_shader_t, vertex); /* vertex */
408848b8605Smrg	WRITE(8, rbug_shader_t, fragment); /* fragment */
409848b8605Smrg	WRITE_ARRAY(8, rbug_texture_t, texs); /* texs */
410848b8605Smrg	WRITE_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
411848b8605Smrg	WRITE(8, rbug_texture_t, zsbuf); /* zsbuf */
412848b8605Smrg	WRITE(4, rbug_block_t, blocker); /* blocker */
413848b8605Smrg	WRITE(4, rbug_block_t, blocked); /* blocked */
414848b8605Smrg
415848b8605Smrg	/* final pad */
416848b8605Smrg	PAD(__pos, 8);
417848b8605Smrg
418848b8605Smrg	if (__pos != __len) {
419848b8605Smrg		__ret = -EINVAL;
420848b8605Smrg	} else {
421848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO_REPLY, __len);
422848b8605Smrg		rbug_connection_write(__con, __data, __len);
423848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
424848b8605Smrg	}
425848b8605Smrg
426848b8605Smrg	FREE(__data);
427848b8605Smrg	return __ret;
428848b8605Smrg}
429848b8605Smrg
430848b8605Smrgint rbug_send_context_draw_blocked(struct rbug_connection *__con,
431848b8605Smrg                                   rbug_context_t context,
432848b8605Smrg                                   rbug_block_t block,
433848b8605Smrg                                   uint32_t *__serial)
434848b8605Smrg{
435848b8605Smrg	uint32_t __len = 0;
436848b8605Smrg	uint32_t __pos = 0;
437848b8605Smrg	uint8_t *__data = NULL;
438848b8605Smrg	int __ret = 0;
439848b8605Smrg
440848b8605Smrg	LEN(8); /* header */
441848b8605Smrg	LEN(8); /* context */
442848b8605Smrg	LEN(4); /* block */
443848b8605Smrg
444848b8605Smrg	/* align */
445848b8605Smrg	PAD(__len, 8);
446848b8605Smrg
447848b8605Smrg	__data = (uint8_t*)MALLOC(__len);
448848b8605Smrg	if (!__data)
449848b8605Smrg		return -ENOMEM;
450848b8605Smrg
451848b8605Smrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED));
452848b8605Smrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
453848b8605Smrg	WRITE(8, rbug_context_t, context); /* context */
454848b8605Smrg	WRITE(4, rbug_block_t, block); /* block */
455848b8605Smrg
456848b8605Smrg	/* final pad */
457848b8605Smrg	PAD(__pos, 8);
458848b8605Smrg
459848b8605Smrg	if (__pos != __len) {
460848b8605Smrg		__ret = -EINVAL;
461848b8605Smrg	} else {
462848b8605Smrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCKED, __len);
463848b8605Smrg		rbug_connection_write(__con, __data, __len);
464848b8605Smrg		__ret = rbug_connection_send_finish(__con, __serial);
465848b8605Smrg	}
466848b8605Smrg
467848b8605Smrg	FREE(__data);
468848b8605Smrg	return __ret;
469848b8605Smrg}
470848b8605Smrg
471848b8605Smrgstruct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header)
472848b8605Smrg{
473848b8605Smrg	struct rbug_proto_context_list *ret;
474848b8605Smrg
475848b8605Smrg	if (!header)
476848b8605Smrg		return NULL;
477848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST)
478848b8605Smrg		return NULL;
479848b8605Smrg
480848b8605Smrg	ret = MALLOC(sizeof(*ret));
481848b8605Smrg	if (!ret)
482848b8605Smrg		return NULL;
483848b8605Smrg
484848b8605Smrg	ret->header.__message = header;
485848b8605Smrg	ret->header.opcode = header->opcode;
486848b8605Smrg
487848b8605Smrg	return ret;
488848b8605Smrg}
489848b8605Smrg
490848b8605Smrgstruct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header)
491848b8605Smrg{
492848b8605Smrg	uint32_t len = 0;
493848b8605Smrg	uint32_t pos = 0;
494848b8605Smrg	uint8_t *data =  NULL;
495848b8605Smrg	struct rbug_proto_context_info *ret;
496848b8605Smrg
497848b8605Smrg	if (!header)
498848b8605Smrg		return NULL;
499848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO)
500848b8605Smrg		return NULL;
501848b8605Smrg
502848b8605Smrg	pos = 0;
503848b8605Smrg	len = header->length * 4;
504848b8605Smrg	data = (uint8_t*)&header[1];
505848b8605Smrg	ret = MALLOC(sizeof(*ret));
506848b8605Smrg	if (!ret)
507848b8605Smrg		return NULL;
508848b8605Smrg
509848b8605Smrg	ret->header.__message = header;
510848b8605Smrg	ret->header.opcode = header->opcode;
511848b8605Smrg
512848b8605Smrg	READ(8, rbug_context_t, context); /* context */
513848b8605Smrg
514848b8605Smrg	return ret;
515848b8605Smrg}
516848b8605Smrg
517848b8605Smrgstruct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header)
518848b8605Smrg{
519848b8605Smrg	uint32_t len = 0;
520848b8605Smrg	uint32_t pos = 0;
521848b8605Smrg	uint8_t *data =  NULL;
522848b8605Smrg	struct rbug_proto_context_draw_block *ret;
523848b8605Smrg
524848b8605Smrg	if (!header)
525848b8605Smrg		return NULL;
526848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK)
527848b8605Smrg		return NULL;
528848b8605Smrg
529848b8605Smrg	pos = 0;
530848b8605Smrg	len = header->length * 4;
531848b8605Smrg	data = (uint8_t*)&header[1];
532848b8605Smrg	ret = MALLOC(sizeof(*ret));
533848b8605Smrg	if (!ret)
534848b8605Smrg		return NULL;
535848b8605Smrg
536848b8605Smrg	ret->header.__message = header;
537848b8605Smrg	ret->header.opcode = header->opcode;
538848b8605Smrg
539848b8605Smrg	READ(8, rbug_context_t, context); /* context */
540848b8605Smrg	READ(4, rbug_block_t, block); /* block */
541848b8605Smrg
542848b8605Smrg	return ret;
543848b8605Smrg}
544848b8605Smrg
545848b8605Smrgstruct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header)
546848b8605Smrg{
547848b8605Smrg	uint32_t len = 0;
548848b8605Smrg	uint32_t pos = 0;
549848b8605Smrg	uint8_t *data =  NULL;
550848b8605Smrg	struct rbug_proto_context_draw_step *ret;
551848b8605Smrg
552848b8605Smrg	if (!header)
553848b8605Smrg		return NULL;
554848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_STEP)
555848b8605Smrg		return NULL;
556848b8605Smrg
557848b8605Smrg	pos = 0;
558848b8605Smrg	len = header->length * 4;
559848b8605Smrg	data = (uint8_t*)&header[1];
560848b8605Smrg	ret = MALLOC(sizeof(*ret));
561848b8605Smrg	if (!ret)
562848b8605Smrg		return NULL;
563848b8605Smrg
564848b8605Smrg	ret->header.__message = header;
565848b8605Smrg	ret->header.opcode = header->opcode;
566848b8605Smrg
567848b8605Smrg	READ(8, rbug_context_t, context); /* context */
568848b8605Smrg	READ(4, rbug_block_t, step); /* step */
569848b8605Smrg
570848b8605Smrg	return ret;
571848b8605Smrg}
572848b8605Smrg
573848b8605Smrgstruct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header)
574848b8605Smrg{
575848b8605Smrg	uint32_t len = 0;
576848b8605Smrg	uint32_t pos = 0;
577848b8605Smrg	uint8_t *data =  NULL;
578848b8605Smrg	struct rbug_proto_context_draw_unblock *ret;
579848b8605Smrg
580848b8605Smrg	if (!header)
581848b8605Smrg		return NULL;
582848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK)
583848b8605Smrg		return NULL;
584848b8605Smrg
585848b8605Smrg	pos = 0;
586848b8605Smrg	len = header->length * 4;
587848b8605Smrg	data = (uint8_t*)&header[1];
588848b8605Smrg	ret = MALLOC(sizeof(*ret));
589848b8605Smrg	if (!ret)
590848b8605Smrg		return NULL;
591848b8605Smrg
592848b8605Smrg	ret->header.__message = header;
593848b8605Smrg	ret->header.opcode = header->opcode;
594848b8605Smrg
595848b8605Smrg	READ(8, rbug_context_t, context); /* context */
596848b8605Smrg	READ(4, rbug_block_t, unblock); /* unblock */
597848b8605Smrg
598848b8605Smrg	return ret;
599848b8605Smrg}
600848b8605Smrg
601848b8605Smrgstruct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header)
602848b8605Smrg{
603848b8605Smrg	uint32_t len = 0;
604848b8605Smrg	uint32_t pos = 0;
605848b8605Smrg	uint8_t *data =  NULL;
606848b8605Smrg	struct rbug_proto_context_draw_rule *ret;
607848b8605Smrg
608848b8605Smrg	if (!header)
609848b8605Smrg		return NULL;
610848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_RULE)
611848b8605Smrg		return NULL;
612848b8605Smrg
613848b8605Smrg	pos = 0;
614848b8605Smrg	len = header->length * 4;
615848b8605Smrg	data = (uint8_t*)&header[1];
616848b8605Smrg	ret = MALLOC(sizeof(*ret));
617848b8605Smrg	if (!ret)
618848b8605Smrg		return NULL;
619848b8605Smrg
620848b8605Smrg	ret->header.__message = header;
621848b8605Smrg	ret->header.opcode = header->opcode;
622848b8605Smrg
623848b8605Smrg	READ(8, rbug_context_t, context); /* context */
624848b8605Smrg	READ(8, rbug_shader_t, vertex); /* vertex */
625848b8605Smrg	READ(8, rbug_shader_t, fragment); /* fragment */
626848b8605Smrg	READ(8, rbug_texture_t, texture); /* texture */
627848b8605Smrg	READ(8, rbug_texture_t, surface); /* surface */
628848b8605Smrg	READ(4, rbug_block_t, block); /* block */
629848b8605Smrg
630848b8605Smrg	return ret;
631848b8605Smrg}
632848b8605Smrg
633848b8605Smrgstruct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header)
634848b8605Smrg{
635848b8605Smrg	uint32_t len = 0;
636848b8605Smrg	uint32_t pos = 0;
637848b8605Smrg	uint8_t *data =  NULL;
638848b8605Smrg	struct rbug_proto_context_flush *ret;
639848b8605Smrg
640848b8605Smrg	if (!header)
641848b8605Smrg		return NULL;
642848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_FLUSH)
643848b8605Smrg		return NULL;
644848b8605Smrg
645848b8605Smrg	pos = 0;
646848b8605Smrg	len = header->length * 4;
647848b8605Smrg	data = (uint8_t*)&header[1];
648848b8605Smrg	ret = MALLOC(sizeof(*ret));
649848b8605Smrg	if (!ret)
650848b8605Smrg		return NULL;
651848b8605Smrg
652848b8605Smrg	ret->header.__message = header;
653848b8605Smrg	ret->header.opcode = header->opcode;
654848b8605Smrg
655848b8605Smrg	READ(8, rbug_context_t, context); /* context */
656848b8605Smrg
657848b8605Smrg	return ret;
658848b8605Smrg}
659848b8605Smrg
660848b8605Smrgstruct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header)
661848b8605Smrg{
662848b8605Smrg	uint32_t len = 0;
663848b8605Smrg	uint32_t pos = 0;
664848b8605Smrg	uint8_t *data =  NULL;
665848b8605Smrg	struct rbug_proto_context_list_reply *ret;
666848b8605Smrg
667848b8605Smrg	if (!header)
668848b8605Smrg		return NULL;
669848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST_REPLY)
670848b8605Smrg		return NULL;
671848b8605Smrg
672848b8605Smrg	pos = 0;
673848b8605Smrg	len = header->length * 4;
674848b8605Smrg	data = (uint8_t*)&header[1];
675848b8605Smrg	ret = MALLOC(sizeof(*ret));
676848b8605Smrg	if (!ret)
677848b8605Smrg		return NULL;
678848b8605Smrg
679848b8605Smrg	ret->header.__message = header;
680848b8605Smrg	ret->header.opcode = header->opcode;
681848b8605Smrg
682848b8605Smrg	READ(4, uint32_t, serial); /* serial */
683848b8605Smrg	READ_ARRAY(8, rbug_context_t, contexts); /* contexts */
684848b8605Smrg
685848b8605Smrg	return ret;
686848b8605Smrg}
687848b8605Smrg
688848b8605Smrgstruct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header)
689848b8605Smrg{
690848b8605Smrg	uint32_t len = 0;
691848b8605Smrg	uint32_t pos = 0;
692848b8605Smrg	uint8_t *data =  NULL;
693848b8605Smrg	struct rbug_proto_context_info_reply *ret;
694848b8605Smrg
695848b8605Smrg	if (!header)
696848b8605Smrg		return NULL;
697848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO_REPLY)
698848b8605Smrg		return NULL;
699848b8605Smrg
700848b8605Smrg	pos = 0;
701848b8605Smrg	len = header->length * 4;
702848b8605Smrg	data = (uint8_t*)&header[1];
703848b8605Smrg	ret = MALLOC(sizeof(*ret));
704848b8605Smrg	if (!ret)
705848b8605Smrg		return NULL;
706848b8605Smrg
707848b8605Smrg	ret->header.__message = header;
708848b8605Smrg	ret->header.opcode = header->opcode;
709848b8605Smrg
710848b8605Smrg	READ(4, uint32_t, serial); /* serial */
711848b8605Smrg	READ(8, rbug_shader_t, vertex); /* vertex */
712848b8605Smrg	READ(8, rbug_shader_t, fragment); /* fragment */
713848b8605Smrg	READ_ARRAY(8, rbug_texture_t, texs); /* texs */
714848b8605Smrg	READ_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
715848b8605Smrg	READ(8, rbug_texture_t, zsbuf); /* zsbuf */
716848b8605Smrg	READ(4, rbug_block_t, blocker); /* blocker */
717848b8605Smrg	READ(4, rbug_block_t, blocked); /* blocked */
718848b8605Smrg
719848b8605Smrg	return ret;
720848b8605Smrg}
721848b8605Smrg
722848b8605Smrgstruct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header)
723848b8605Smrg{
724848b8605Smrg	uint32_t len = 0;
725848b8605Smrg	uint32_t pos = 0;
726848b8605Smrg	uint8_t *data =  NULL;
727848b8605Smrg	struct rbug_proto_context_draw_blocked *ret;
728848b8605Smrg
729848b8605Smrg	if (!header)
730848b8605Smrg		return NULL;
731848b8605Smrg	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED)
732848b8605Smrg		return NULL;
733848b8605Smrg
734848b8605Smrg	pos = 0;
735848b8605Smrg	len = header->length * 4;
736848b8605Smrg	data = (uint8_t*)&header[1];
737848b8605Smrg	ret = MALLOC(sizeof(*ret));
738848b8605Smrg	if (!ret)
739848b8605Smrg		return NULL;
740848b8605Smrg
741848b8605Smrg	ret->header.__message = header;
742848b8605Smrg	ret->header.opcode = header->opcode;
743848b8605Smrg
744848b8605Smrg	READ(8, rbug_context_t, context); /* context */
745848b8605Smrg	READ(4, rbug_block_t, block); /* block */
746848b8605Smrg
747848b8605Smrg	return ret;
748848b8605Smrg}
749