Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rbug_texture.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. * This file holds the function implementation for one of the rbug extensions.
  26. * Prototypes and declerations of functions and structs is in the same folder
  27. * in the header file matching this file's name.
  28. *
  29. * The functions starting rbug_send_* encodes a call to the write format and
  30. * sends that to the supplied connection, while functions starting with
  31. * rbug_demarshal_* demarshal data in the wire protocol.
  32. *
  33. * Functions ending with _reply are replies to requests.
  34. */
  35. #include "rbug_internal.h"
  36. #include "rbug/rbug_texture.h"
  37. int rbug_send_texture_list(struct rbug_connection *__con,
  38. uint32_t *__serial)
  39. {
  40. uint32_t __len = 0;
  41. uint32_t __pos = 0;
  42. uint8_t *__data = NULL;
  43. int __ret = 0;
  44. LEN(8); /* header */
  45. /* align */
  46. PAD(__len, 8);
  47. __data = (uint8_t*)MALLOC(__len);
  48. if (!__data)
  49. return -ENOMEM;
  50. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST));
  51. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  52. /* final pad */
  53. PAD(__pos, 8);
  54. if (__pos != __len) {
  55. __ret = -EINVAL;
  56. } else {
  57. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len);
  58. rbug_connection_write(__con, __data, __len);
  59. __ret = rbug_connection_send_finish(__con, __serial);
  60. }
  61. FREE(__data);
  62. return __ret;
  63. }
  64. int rbug_send_texture_info(struct rbug_connection *__con,
  65. rbug_texture_t texture,
  66. uint32_t *__serial)
  67. {
  68. uint32_t __len = 0;
  69. uint32_t __pos = 0;
  70. uint8_t *__data = NULL;
  71. int __ret = 0;
  72. LEN(8); /* header */
  73. LEN(8); /* texture */
  74. /* align */
  75. PAD(__len, 8);
  76. __data = (uint8_t*)MALLOC(__len);
  77. if (!__data)
  78. return -ENOMEM;
  79. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO));
  80. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  81. WRITE(8, rbug_texture_t, texture); /* texture */
  82. /* final pad */
  83. PAD(__pos, 8);
  84. if (__pos != __len) {
  85. __ret = -EINVAL;
  86. } else {
  87. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len);
  88. rbug_connection_write(__con, __data, __len);
  89. __ret = rbug_connection_send_finish(__con, __serial);
  90. }
  91. FREE(__data);
  92. return __ret;
  93. }
  94. int rbug_send_texture_write(struct rbug_connection *__con,
  95. rbug_texture_t texture,
  96. uint32_t face,
  97. uint32_t level,
  98. uint32_t zslice,
  99. uint32_t x,
  100. uint32_t y,
  101. uint32_t w,
  102. uint32_t h,
  103. uint8_t *data,
  104. uint32_t data_len,
  105. uint32_t stride,
  106. uint32_t *__serial)
  107. {
  108. uint32_t __len = 0;
  109. uint32_t __pos = 0;
  110. uint8_t *__data = NULL;
  111. int __ret = 0;
  112. LEN(8); /* header */
  113. LEN(8); /* texture */
  114. LEN(4); /* face */
  115. LEN(4); /* level */
  116. LEN(4); /* zslice */
  117. LEN(4); /* x */
  118. LEN(4); /* y */
  119. LEN(4); /* w */
  120. LEN(4); /* h */
  121. LEN_ARRAY(1, data); /* data */
  122. LEN(4); /* stride */
  123. /* align */
  124. PAD(__len, 8);
  125. __data = (uint8_t*)MALLOC(__len);
  126. if (!__data)
  127. return -ENOMEM;
  128. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE));
  129. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  130. WRITE(8, rbug_texture_t, texture); /* texture */
  131. WRITE(4, uint32_t, face); /* face */
  132. WRITE(4, uint32_t, level); /* level */
  133. WRITE(4, uint32_t, zslice); /* zslice */
  134. WRITE(4, uint32_t, x); /* x */
  135. WRITE(4, uint32_t, y); /* y */
  136. WRITE(4, uint32_t, w); /* w */
  137. WRITE(4, uint32_t, h); /* h */
  138. WRITE_ARRAY(1, uint8_t, data); /* data */
  139. WRITE(4, uint32_t, stride); /* stride */
  140. /* final pad */
  141. PAD(__pos, 8);
  142. if (__pos != __len) {
  143. __ret = -EINVAL;
  144. } else {
  145. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len);
  146. rbug_connection_write(__con, __data, __len);
  147. __ret = rbug_connection_send_finish(__con, __serial);
  148. }
  149. FREE(__data);
  150. return __ret;
  151. }
  152. int rbug_send_texture_read(struct rbug_connection *__con,
  153. rbug_texture_t texture,
  154. uint32_t face,
  155. uint32_t level,
  156. uint32_t zslice,
  157. uint32_t x,
  158. uint32_t y,
  159. uint32_t w,
  160. uint32_t h,
  161. uint32_t *__serial)
  162. {
  163. uint32_t __len = 0;
  164. uint32_t __pos = 0;
  165. uint8_t *__data = NULL;
  166. int __ret = 0;
  167. LEN(8); /* header */
  168. LEN(8); /* texture */
  169. LEN(4); /* face */
  170. LEN(4); /* level */
  171. LEN(4); /* zslice */
  172. LEN(4); /* x */
  173. LEN(4); /* y */
  174. LEN(4); /* w */
  175. LEN(4); /* h */
  176. /* align */
  177. PAD(__len, 8);
  178. __data = (uint8_t*)MALLOC(__len);
  179. if (!__data)
  180. return -ENOMEM;
  181. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ));
  182. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  183. WRITE(8, rbug_texture_t, texture); /* texture */
  184. WRITE(4, uint32_t, face); /* face */
  185. WRITE(4, uint32_t, level); /* level */
  186. WRITE(4, uint32_t, zslice); /* zslice */
  187. WRITE(4, uint32_t, x); /* x */
  188. WRITE(4, uint32_t, y); /* y */
  189. WRITE(4, uint32_t, w); /* w */
  190. WRITE(4, uint32_t, h); /* h */
  191. /* final pad */
  192. PAD(__pos, 8);
  193. if (__pos != __len) {
  194. __ret = -EINVAL;
  195. } else {
  196. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len);
  197. rbug_connection_write(__con, __data, __len);
  198. __ret = rbug_connection_send_finish(__con, __serial);
  199. }
  200. FREE(__data);
  201. return __ret;
  202. }
  203. int rbug_send_texture_list_reply(struct rbug_connection *__con,
  204. uint32_t serial,
  205. rbug_texture_t *textures,
  206. uint32_t textures_len,
  207. uint32_t *__serial)
  208. {
  209. uint32_t __len = 0;
  210. uint32_t __pos = 0;
  211. uint8_t *__data = NULL;
  212. int __ret = 0;
  213. LEN(8); /* header */
  214. LEN(4); /* serial */
  215. LEN_ARRAY(8, textures); /* textures */
  216. /* align */
  217. PAD(__len, 8);
  218. __data = (uint8_t*)MALLOC(__len);
  219. if (!__data)
  220. return -ENOMEM;
  221. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY));
  222. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  223. WRITE(4, uint32_t, serial); /* serial */
  224. WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */
  225. /* final pad */
  226. PAD(__pos, 8);
  227. if (__pos != __len) {
  228. __ret = -EINVAL;
  229. } else {
  230. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len);
  231. rbug_connection_write(__con, __data, __len);
  232. __ret = rbug_connection_send_finish(__con, __serial);
  233. }
  234. FREE(__data);
  235. return __ret;
  236. }
  237. int rbug_send_texture_info_reply(struct rbug_connection *__con,
  238. uint32_t serial,
  239. uint32_t target,
  240. uint32_t format,
  241. uint32_t *width,
  242. uint32_t width_len,
  243. uint32_t *height,
  244. uint32_t height_len,
  245. uint32_t *depth,
  246. uint32_t depth_len,
  247. uint32_t blockw,
  248. uint32_t blockh,
  249. uint32_t blocksize,
  250. uint32_t last_level,
  251. uint32_t nr_samples,
  252. uint32_t tex_usage,
  253. uint32_t *__serial)
  254. {
  255. uint32_t __len = 0;
  256. uint32_t __pos = 0;
  257. uint8_t *__data = NULL;
  258. int __ret = 0;
  259. LEN(8); /* header */
  260. LEN(4); /* serial */
  261. LEN(4); /* target */
  262. LEN(4); /* format */
  263. LEN_ARRAY(4, width); /* width */
  264. LEN_ARRAY(4, height); /* height */
  265. LEN_ARRAY(4, depth); /* depth */
  266. LEN(4); /* blockw */
  267. LEN(4); /* blockh */
  268. LEN(4); /* blocksize */
  269. LEN(4); /* last_level */
  270. LEN(4); /* nr_samples */
  271. LEN(4); /* tex_usage */
  272. /* align */
  273. PAD(__len, 8);
  274. __data = (uint8_t*)MALLOC(__len);
  275. if (!__data)
  276. return -ENOMEM;
  277. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY));
  278. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  279. WRITE(4, uint32_t, serial); /* serial */
  280. WRITE(4, uint32_t, target); /* target */
  281. WRITE(4, uint32_t, format); /* format */
  282. WRITE_ARRAY(4, uint32_t, width); /* width */
  283. WRITE_ARRAY(4, uint32_t, height); /* height */
  284. WRITE_ARRAY(4, uint32_t, depth); /* depth */
  285. WRITE(4, uint32_t, blockw); /* blockw */
  286. WRITE(4, uint32_t, blockh); /* blockh */
  287. WRITE(4, uint32_t, blocksize); /* blocksize */
  288. WRITE(4, uint32_t, last_level); /* last_level */
  289. WRITE(4, uint32_t, nr_samples); /* nr_samples */
  290. WRITE(4, uint32_t, tex_usage); /* tex_usage */
  291. /* final pad */
  292. PAD(__pos, 8);
  293. if (__pos != __len) {
  294. __ret = -EINVAL;
  295. } else {
  296. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len);
  297. rbug_connection_write(__con, __data, __len);
  298. __ret = rbug_connection_send_finish(__con, __serial);
  299. }
  300. FREE(__data);
  301. return __ret;
  302. }
  303. int rbug_send_texture_read_reply(struct rbug_connection *__con,
  304. uint32_t serial,
  305. uint32_t format,
  306. uint32_t blockw,
  307. uint32_t blockh,
  308. uint32_t blocksize,
  309. uint8_t *data,
  310. uint32_t data_len,
  311. uint32_t stride,
  312. uint32_t *__serial)
  313. {
  314. uint32_t __len = 0;
  315. uint32_t __pos = 0;
  316. uint8_t *__data = NULL;
  317. int __ret = 0;
  318. LEN(8); /* header */
  319. LEN(4); /* serial */
  320. LEN(4); /* format */
  321. LEN(4); /* blockw */
  322. LEN(4); /* blockh */
  323. LEN(4); /* blocksize */
  324. LEN_ARRAY(1, data); /* data */
  325. LEN(4); /* stride */
  326. /* align */
  327. PAD(__len, 8);
  328. __data = (uint8_t*)MALLOC(__len);
  329. if (!__data)
  330. return -ENOMEM;
  331. WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY));
  332. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  333. WRITE(4, uint32_t, serial); /* serial */
  334. WRITE(4, uint32_t, format); /* format */
  335. WRITE(4, uint32_t, blockw); /* blockw */
  336. WRITE(4, uint32_t, blockh); /* blockh */
  337. WRITE(4, uint32_t, blocksize); /* blocksize */
  338. WRITE_ARRAY(1, uint8_t, data); /* data */
  339. WRITE(4, uint32_t, stride); /* stride */
  340. /* final pad */
  341. PAD(__pos, 8);
  342. if (__pos != __len) {
  343. __ret = -EINVAL;
  344. } else {
  345. rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len);
  346. rbug_connection_write(__con, __data, __len);
  347. __ret = rbug_connection_send_finish(__con, __serial);
  348. }
  349. FREE(__data);
  350. return __ret;
  351. }
  352. struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header)
  353. {
  354. uint32_t len = 0;
  355. uint32_t pos = 0;
  356. uint8_t *data = NULL;
  357. struct rbug_proto_texture_list *ret;
  358. if (!header)
  359. return NULL;
  360. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST)
  361. return NULL;
  362. pos = 0;
  363. len = header->length * 4;
  364. data = (uint8_t*)&header[1];
  365. ret = MALLOC(sizeof(*ret));
  366. if (!ret)
  367. return NULL;
  368. ret->header.__message = header;
  369. ret->header.opcode = header->opcode;
  370. return ret;
  371. }
  372. struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header)
  373. {
  374. uint32_t len = 0;
  375. uint32_t pos = 0;
  376. uint8_t *data = NULL;
  377. struct rbug_proto_texture_info *ret;
  378. if (!header)
  379. return NULL;
  380. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO)
  381. return NULL;
  382. pos = 0;
  383. len = header->length * 4;
  384. data = (uint8_t*)&header[1];
  385. ret = MALLOC(sizeof(*ret));
  386. if (!ret)
  387. return NULL;
  388. ret->header.__message = header;
  389. ret->header.opcode = header->opcode;
  390. READ(8, rbug_texture_t, texture); /* texture */
  391. return ret;
  392. }
  393. struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header)
  394. {
  395. uint32_t len = 0;
  396. uint32_t pos = 0;
  397. uint8_t *data = NULL;
  398. struct rbug_proto_texture_write *ret;
  399. if (!header)
  400. return NULL;
  401. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_WRITE)
  402. return NULL;
  403. pos = 0;
  404. len = header->length * 4;
  405. data = (uint8_t*)&header[1];
  406. ret = MALLOC(sizeof(*ret));
  407. if (!ret)
  408. return NULL;
  409. ret->header.__message = header;
  410. ret->header.opcode = header->opcode;
  411. READ(8, rbug_texture_t, texture); /* texture */
  412. READ(4, uint32_t, face); /* face */
  413. READ(4, uint32_t, level); /* level */
  414. READ(4, uint32_t, zslice); /* zslice */
  415. READ(4, uint32_t, x); /* x */
  416. READ(4, uint32_t, y); /* y */
  417. READ(4, uint32_t, w); /* w */
  418. READ(4, uint32_t, h); /* h */
  419. READ_ARRAY(1, uint8_t, data); /* data */
  420. READ(4, uint32_t, stride); /* stride */
  421. return ret;
  422. }
  423. struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header)
  424. {
  425. uint32_t len = 0;
  426. uint32_t pos = 0;
  427. uint8_t *data = NULL;
  428. struct rbug_proto_texture_read *ret;
  429. if (!header)
  430. return NULL;
  431. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ)
  432. return NULL;
  433. pos = 0;
  434. len = header->length * 4;
  435. data = (uint8_t*)&header[1];
  436. ret = MALLOC(sizeof(*ret));
  437. if (!ret)
  438. return NULL;
  439. ret->header.__message = header;
  440. ret->header.opcode = header->opcode;
  441. READ(8, rbug_texture_t, texture); /* texture */
  442. READ(4, uint32_t, face); /* face */
  443. READ(4, uint32_t, level); /* level */
  444. READ(4, uint32_t, zslice); /* zslice */
  445. READ(4, uint32_t, x); /* x */
  446. READ(4, uint32_t, y); /* y */
  447. READ(4, uint32_t, w); /* w */
  448. READ(4, uint32_t, h); /* h */
  449. return ret;
  450. }
  451. struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header)
  452. {
  453. uint32_t len = 0;
  454. uint32_t pos = 0;
  455. uint8_t *data = NULL;
  456. struct rbug_proto_texture_list_reply *ret;
  457. if (!header)
  458. return NULL;
  459. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST_REPLY)
  460. return NULL;
  461. pos = 0;
  462. len = header->length * 4;
  463. data = (uint8_t*)&header[1];
  464. ret = MALLOC(sizeof(*ret));
  465. if (!ret)
  466. return NULL;
  467. ret->header.__message = header;
  468. ret->header.opcode = header->opcode;
  469. READ(4, uint32_t, serial); /* serial */
  470. READ_ARRAY(8, rbug_texture_t, textures); /* textures */
  471. return ret;
  472. }
  473. struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header)
  474. {
  475. uint32_t len = 0;
  476. uint32_t pos = 0;
  477. uint8_t *data = NULL;
  478. struct rbug_proto_texture_info_reply *ret;
  479. if (!header)
  480. return NULL;
  481. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO_REPLY)
  482. return NULL;
  483. pos = 0;
  484. len = header->length * 4;
  485. data = (uint8_t*)&header[1];
  486. ret = MALLOC(sizeof(*ret));
  487. if (!ret)
  488. return NULL;
  489. ret->header.__message = header;
  490. ret->header.opcode = header->opcode;
  491. READ(4, uint32_t, serial); /* serial */
  492. READ(4, uint32_t, target); /* target */
  493. READ(4, uint32_t, format); /* format */
  494. READ_ARRAY(4, uint32_t, width); /* width */
  495. READ_ARRAY(4, uint32_t, height); /* height */
  496. READ_ARRAY(4, uint32_t, depth); /* depth */
  497. READ(4, uint32_t, blockw); /* blockw */
  498. READ(4, uint32_t, blockh); /* blockh */
  499. READ(4, uint32_t, blocksize); /* blocksize */
  500. READ(4, uint32_t, last_level); /* last_level */
  501. READ(4, uint32_t, nr_samples); /* nr_samples */
  502. READ(4, uint32_t, tex_usage); /* tex_usage */
  503. return ret;
  504. }
  505. struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header)
  506. {
  507. uint32_t len = 0;
  508. uint32_t pos = 0;
  509. uint8_t *data = NULL;
  510. struct rbug_proto_texture_read_reply *ret;
  511. if (!header)
  512. return NULL;
  513. if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ_REPLY)
  514. return NULL;
  515. pos = 0;
  516. len = header->length * 4;
  517. data = (uint8_t*)&header[1];
  518. ret = MALLOC(sizeof(*ret));
  519. if (!ret)
  520. return NULL;
  521. ret->header.__message = header;
  522. ret->header.opcode = header->opcode;
  523. READ(4, uint32_t, serial); /* serial */
  524. READ(4, uint32_t, format); /* format */
  525. READ(4, uint32_t, blockw); /* blockw */
  526. READ(4, uint32_t, blockh); /* blockh */
  527. READ(4, uint32_t, blocksize); /* blocksize */
  528. READ_ARRAY(1, uint8_t, data); /* data */
  529. READ(4, uint32_t, stride); /* stride */
  530. return ret;
  531. }