rbug: Add Gallium Remote Debugger Protocol code
[mesa.git] / src / gallium / auxiliary / rbug / rbug_context.c
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_context.h"
39
40 int rbug_send_context_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_CONTEXT_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_CONTEXT_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
75 int rbug_send_context_info(struct rbug_connection *__con,
76 rbug_context_t context,
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); /* context */
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_CONTEXT_INFO));
95 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
96 WRITE(8, rbug_context_t, context); /* context */
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_CONTEXT_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
113 int rbug_send_context_block_draw(struct rbug_connection *__con,
114 rbug_context_t context,
115 uint32_t *__serial)
116 {
117 uint32_t __len = 0;
118 uint32_t __pos = 0;
119 uint8_t *__data = NULL;
120 int __ret = 0;
121
122 LEN(8); /* header */
123 LEN(8); /* context */
124
125 /* align */
126 PAD(__len, 8);
127
128 __data = (uint8_t*)MALLOC(__len);
129 if (!__data)
130 return -ENOMEM;
131
132 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_BLOCK_DRAW));
133 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
134 WRITE(8, rbug_context_t, context); /* context */
135
136 /* final pad */
137 PAD(__pos, 8);
138
139 if (__pos != __len) {
140 __ret = -EINVAL;
141 } else {
142 rbug_connection_send_start(__con, RBUG_OP_CONTEXT_BLOCK_DRAW, __len);
143 rbug_connection_write(__con, __data, __len);
144 __ret = rbug_connection_send_finish(__con, __serial);
145 }
146
147 FREE(__data);
148 return __ret;
149 }
150
151 int rbug_send_context_unblock_draw(struct rbug_connection *__con,
152 rbug_context_t context,
153 uint32_t *__serial)
154 {
155 uint32_t __len = 0;
156 uint32_t __pos = 0;
157 uint8_t *__data = NULL;
158 int __ret = 0;
159
160 LEN(8); /* header */
161 LEN(8); /* context */
162
163 /* align */
164 PAD(__len, 8);
165
166 __data = (uint8_t*)MALLOC(__len);
167 if (!__data)
168 return -ENOMEM;
169
170 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_UNBLOCK_DRAW));
171 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
172 WRITE(8, rbug_context_t, context); /* context */
173
174 /* final pad */
175 PAD(__pos, 8);
176
177 if (__pos != __len) {
178 __ret = -EINVAL;
179 } else {
180 rbug_connection_send_start(__con, RBUG_OP_CONTEXT_UNBLOCK_DRAW, __len);
181 rbug_connection_write(__con, __data, __len);
182 __ret = rbug_connection_send_finish(__con, __serial);
183 }
184
185 FREE(__data);
186 return __ret;
187 }
188
189 int rbug_send_context_list_reply(struct rbug_connection *__con,
190 uint32_t serial,
191 rbug_context_t *contexts,
192 uint32_t contexts_len,
193 uint32_t *__serial)
194 {
195 uint32_t __len = 0;
196 uint32_t __pos = 0;
197 uint8_t *__data = NULL;
198 int __ret = 0;
199
200 LEN(8); /* header */
201 LEN(4); /* serial */
202 LEN_ARRAY(8, contexts); /* contexts */
203
204 /* align */
205 PAD(__len, 8);
206
207 __data = (uint8_t*)MALLOC(__len);
208 if (!__data)
209 return -ENOMEM;
210
211 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY));
212 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
213 WRITE(4, uint32_t, serial); /* serial */
214 WRITE_ARRAY(8, rbug_context_t, contexts); /* contexts */
215
216 /* final pad */
217 PAD(__pos, 8);
218
219 if (__pos != __len) {
220 __ret = -EINVAL;
221 } else {
222 rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST_REPLY, __len);
223 rbug_connection_write(__con, __data, __len);
224 __ret = rbug_connection_send_finish(__con, __serial);
225 }
226
227 FREE(__data);
228 return __ret;
229 }
230
231 int rbug_send_context_info_reply(struct rbug_connection *__con,
232 uint32_t serial,
233 rbug_texture_t *cbufs,
234 uint32_t cbufs_len,
235 rbug_texture_t zdbuf,
236 uint8_t blocked,
237 uint32_t *__serial)
238 {
239 uint32_t __len = 0;
240 uint32_t __pos = 0;
241 uint8_t *__data = NULL;
242 int __ret = 0;
243
244 LEN(8); /* header */
245 LEN(4); /* serial */
246 LEN_ARRAY(8, cbufs); /* cbufs */
247 LEN(8); /* zdbuf */
248 LEN(1); /* blocked */
249
250 /* align */
251 PAD(__len, 8);
252
253 __data = (uint8_t*)MALLOC(__len);
254 if (!__data)
255 return -ENOMEM;
256
257 WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY));
258 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
259 WRITE(4, uint32_t, serial); /* serial */
260 WRITE_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
261 WRITE(8, rbug_texture_t, zdbuf); /* zdbuf */
262 WRITE(1, uint8_t, blocked); /* blocked */
263
264 /* final pad */
265 PAD(__pos, 8);
266
267 if (__pos != __len) {
268 __ret = -EINVAL;
269 } else {
270 rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO_REPLY, __len);
271 rbug_connection_write(__con, __data, __len);
272 __ret = rbug_connection_send_finish(__con, __serial);
273 }
274
275 FREE(__data);
276 return __ret;
277 }
278
279 struct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header)
280 {
281 uint32_t len = 0;
282 uint32_t pos = 0;
283 uint8_t *data = NULL;
284 struct rbug_proto_context_list *ret;
285
286 if (!header)
287 return NULL;
288 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_LIST)
289 return NULL;
290
291 pos = 0;
292 len = header->length * 4;
293 data = (uint8_t*)&header[1];
294 ret = MALLOC(sizeof(*ret));
295 if (!ret)
296 return NULL;
297
298 ret->header.__message = header;
299 ret->header.opcode = header->opcode;
300
301
302 return ret;
303 }
304
305 struct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header)
306 {
307 uint32_t len = 0;
308 uint32_t pos = 0;
309 uint8_t *data = NULL;
310 struct rbug_proto_context_info *ret;
311
312 if (!header)
313 return NULL;
314 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_INFO)
315 return NULL;
316
317 pos = 0;
318 len = header->length * 4;
319 data = (uint8_t*)&header[1];
320 ret = MALLOC(sizeof(*ret));
321 if (!ret)
322 return NULL;
323
324 ret->header.__message = header;
325 ret->header.opcode = header->opcode;
326
327 READ(8, rbug_context_t, context); /* context */
328
329 return ret;
330 }
331
332 struct rbug_proto_context_block_draw * rbug_demarshal_context_block_draw(struct rbug_proto_header *header)
333 {
334 uint32_t len = 0;
335 uint32_t pos = 0;
336 uint8_t *data = NULL;
337 struct rbug_proto_context_block_draw *ret;
338
339 if (!header)
340 return NULL;
341 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_BLOCK_DRAW)
342 return NULL;
343
344 pos = 0;
345 len = header->length * 4;
346 data = (uint8_t*)&header[1];
347 ret = MALLOC(sizeof(*ret));
348 if (!ret)
349 return NULL;
350
351 ret->header.__message = header;
352 ret->header.opcode = header->opcode;
353
354 READ(8, rbug_context_t, context); /* context */
355
356 return ret;
357 }
358
359 struct rbug_proto_context_unblock_draw * rbug_demarshal_context_unblock_draw(struct rbug_proto_header *header)
360 {
361 uint32_t len = 0;
362 uint32_t pos = 0;
363 uint8_t *data = NULL;
364 struct rbug_proto_context_unblock_draw *ret;
365
366 if (!header)
367 return NULL;
368 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_UNBLOCK_DRAW)
369 return NULL;
370
371 pos = 0;
372 len = header->length * 4;
373 data = (uint8_t*)&header[1];
374 ret = MALLOC(sizeof(*ret));
375 if (!ret)
376 return NULL;
377
378 ret->header.__message = header;
379 ret->header.opcode = header->opcode;
380
381 READ(8, rbug_context_t, context); /* context */
382
383 return ret;
384 }
385
386 struct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header)
387 {
388 uint32_t len = 0;
389 uint32_t pos = 0;
390 uint8_t *data = NULL;
391 struct rbug_proto_context_list_reply *ret;
392
393 if (!header)
394 return NULL;
395 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_LIST_REPLY)
396 return NULL;
397
398 pos = 0;
399 len = header->length * 4;
400 data = (uint8_t*)&header[1];
401 ret = MALLOC(sizeof(*ret));
402 if (!ret)
403 return NULL;
404
405 ret->header.__message = header;
406 ret->header.opcode = header->opcode;
407
408 READ(4, uint32_t, serial); /* serial */
409 READ_ARRAY(8, rbug_context_t, contexts); /* contexts */
410
411 return ret;
412 }
413
414 struct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header)
415 {
416 uint32_t len = 0;
417 uint32_t pos = 0;
418 uint8_t *data = NULL;
419 struct rbug_proto_context_info_reply *ret;
420
421 if (!header)
422 return NULL;
423 if (header->opcode != (int16_t)RBUG_OP_CONTEXT_INFO_REPLY)
424 return NULL;
425
426 pos = 0;
427 len = header->length * 4;
428 data = (uint8_t*)&header[1];
429 ret = MALLOC(sizeof(*ret));
430 if (!ret)
431 return NULL;
432
433 ret->header.__message = header;
434 ret->header.opcode = header->opcode;
435
436 READ(4, uint32_t, serial); /* serial */
437 READ_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
438 READ(8, rbug_texture_t, zdbuf); /* zdbuf */
439 READ(1, uint8_t, blocked); /* blocked */
440
441 return ret;
442 }