buffers.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * DRM based mode setting test program
  3. * Copyright 2008 Tungsten Graphics
  4. * Jakob Bornecrantz <jakob@tungstengraphics.com>
  5. * Copyright 2008 Intel Corporation
  6. * Jesse Barnes <jesse.barnes@intel.com>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. * IN THE SOFTWARE.
  25. */
  26. #include <assert.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <stdint.h>
  31. #include <string.h>
  32. #include <sys/ioctl.h>
  33. #include "drm.h"
  34. #include "drm_fourcc.h"
  35. #include "libdrm_macros.h"
  36. #include "xf86drm.h"
  37. #include "buffers.h"
  38. struct bo
  39. {
  40. int fd;
  41. void *ptr;
  42. size_t size;
  43. size_t offset;
  44. size_t pitch;
  45. unsigned handle;
  46. };
  47. /* -----------------------------------------------------------------------------
  48. * Buffers management
  49. */
  50. static struct bo *
  51. bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp)
  52. {
  53. struct drm_mode_create_dumb arg;
  54. struct bo *bo;
  55. int ret;
  56. bo = calloc(1, sizeof(*bo));
  57. if (bo == NULL) {
  58. fprintf(stderr, "failed to allocate buffer object\n");
  59. return NULL;
  60. }
  61. memset(&arg, 0, sizeof(arg));
  62. arg.bpp = bpp;
  63. arg.width = width;
  64. arg.height = height;
  65. ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
  66. if (ret) {
  67. fprintf(stderr, "failed to create dumb buffer: %s\n",
  68. strerror(errno));
  69. free(bo);
  70. return NULL;
  71. }
  72. bo->fd = fd;
  73. bo->handle = arg.handle;
  74. bo->size = arg.size;
  75. bo->pitch = arg.pitch;
  76. return bo;
  77. }
  78. struct bo g_bo;
  79. static struct bo *
  80. bo_create_dumb_plink(int fd, unsigned int width, unsigned int height, unsigned int bpp, int prime_fd, int stride_y)
  81. {
  82. struct drm_mode_create_dumb arg;
  83. struct bo *bo = &g_bo;
  84. int ret;
  85. unsigned int handle;
  86. /*
  87. bo = calloc(1, sizeof(*bo));
  88. if (bo == NULL) {
  89. fprintf(stderr, "failed to allocate buffer object\n");
  90. return NULL;
  91. }
  92. */
  93. memset(&arg, 0, sizeof(arg));
  94. arg.bpp = bpp;
  95. arg.width = width;
  96. arg.height = height;
  97. #if 0
  98. ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
  99. if (ret) {
  100. fprintf(stderr, "failed to create dumb buffer: %s\n",
  101. strerror(errno));
  102. free(bo);
  103. return NULL;
  104. }
  105. #else
  106. ret = drmPrimeFDToHandle(fd, prime_fd, &handle);
  107. if (ret) {
  108. fprintf(stderr, "failed to drmPrimeFDToHandle: %s\n",
  109. strerror(errno));
  110. //free(bo);
  111. return NULL;
  112. }
  113. #endif
  114. bo->fd = fd;
  115. bo->handle = handle;
  116. bo->pitch = stride_y;//(arg.width * arg.bpp)/8; //3840;
  117. bo->size = bo->pitch * arg.height;
  118. // printf("fd:%d handle:%d width:%d height:%d bpp:%dpitch:%d size:%d\n",
  119. // fd, handle, width, height, bpp, bo->pitch, bo->size);
  120. return bo;
  121. }
  122. static int bo_map(struct bo *bo, void **out)
  123. {
  124. struct drm_mode_map_dumb arg;
  125. void *map;
  126. int ret;
  127. memset(&arg, 0, sizeof(arg));
  128. arg.handle = bo->handle;
  129. ret = drmIoctl(bo->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
  130. if (ret)
  131. return ret;
  132. map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
  133. bo->fd, arg.offset);
  134. if (map == MAP_FAILED)
  135. return -EINVAL;
  136. bo->ptr = map;
  137. *out = map;
  138. return 0;
  139. }
  140. static void bo_unmap(struct bo *bo)
  141. {
  142. if (!bo->ptr)
  143. return;
  144. drm_munmap(bo->ptr, bo->size);
  145. bo->ptr = NULL;
  146. }
  147. struct bo *
  148. bo_create(int fd, unsigned int format,
  149. unsigned int width, unsigned int height,
  150. unsigned int handles[4], unsigned int pitches[4],
  151. unsigned int offsets[4], enum util_fill_pattern pattern)
  152. {
  153. unsigned int virtual_height;
  154. struct bo *bo;
  155. unsigned int bpp;
  156. void *planes[3] = { 0, };
  157. void *virtual;
  158. int ret;
  159. switch (format) {
  160. case DRM_FORMAT_C8:
  161. case DRM_FORMAT_NV12:
  162. case DRM_FORMAT_NV21:
  163. case DRM_FORMAT_NV16:
  164. case DRM_FORMAT_NV61:
  165. case DRM_FORMAT_YUV420:
  166. case DRM_FORMAT_YVU420:
  167. bpp = 8;
  168. break;
  169. case DRM_FORMAT_ARGB4444:
  170. case DRM_FORMAT_XRGB4444:
  171. case DRM_FORMAT_ABGR4444:
  172. case DRM_FORMAT_XBGR4444:
  173. case DRM_FORMAT_RGBA4444:
  174. case DRM_FORMAT_RGBX4444:
  175. case DRM_FORMAT_BGRA4444:
  176. case DRM_FORMAT_BGRX4444:
  177. case DRM_FORMAT_ARGB1555:
  178. case DRM_FORMAT_XRGB1555:
  179. case DRM_FORMAT_ABGR1555:
  180. case DRM_FORMAT_XBGR1555:
  181. case DRM_FORMAT_RGBA5551:
  182. case DRM_FORMAT_RGBX5551:
  183. case DRM_FORMAT_BGRA5551:
  184. case DRM_FORMAT_BGRX5551:
  185. case DRM_FORMAT_RGB565:
  186. case DRM_FORMAT_BGR565:
  187. case DRM_FORMAT_UYVY:
  188. case DRM_FORMAT_VYUY:
  189. case DRM_FORMAT_YUYV:
  190. case DRM_FORMAT_YVYU:
  191. bpp = 16;
  192. break;
  193. case DRM_FORMAT_BGR888:
  194. case DRM_FORMAT_RGB888:
  195. bpp = 24;
  196. break;
  197. case DRM_FORMAT_ARGB8888:
  198. case DRM_FORMAT_XRGB8888:
  199. case DRM_FORMAT_ABGR8888:
  200. case DRM_FORMAT_XBGR8888:
  201. case DRM_FORMAT_RGBA8888:
  202. case DRM_FORMAT_RGBX8888:
  203. case DRM_FORMAT_BGRA8888:
  204. case DRM_FORMAT_BGRX8888:
  205. case DRM_FORMAT_ARGB2101010:
  206. case DRM_FORMAT_XRGB2101010:
  207. case DRM_FORMAT_ABGR2101010:
  208. case DRM_FORMAT_XBGR2101010:
  209. case DRM_FORMAT_RGBA1010102:
  210. case DRM_FORMAT_RGBX1010102:
  211. case DRM_FORMAT_BGRA1010102:
  212. case DRM_FORMAT_BGRX1010102:
  213. bpp = 32;
  214. break;
  215. case DRM_FORMAT_XRGB16161616F:
  216. case DRM_FORMAT_XBGR16161616F:
  217. case DRM_FORMAT_ARGB16161616F:
  218. case DRM_FORMAT_ABGR16161616F:
  219. bpp = 64;
  220. break;
  221. default:
  222. fprintf(stderr, "unsupported format 0x%08x\n", format);
  223. return NULL;
  224. }
  225. switch (format) {
  226. case DRM_FORMAT_NV12:
  227. case DRM_FORMAT_NV21:
  228. case DRM_FORMAT_YUV420:
  229. case DRM_FORMAT_YVU420:
  230. virtual_height = height * 3 / 2;
  231. break;
  232. case DRM_FORMAT_NV16:
  233. case DRM_FORMAT_NV61:
  234. virtual_height = height * 2;
  235. break;
  236. default:
  237. virtual_height = height;
  238. break;
  239. }
  240. bo = bo_create_dumb(fd, width, virtual_height, bpp);
  241. if (!bo)
  242. return NULL;
  243. ret = bo_map(bo, &virtual);
  244. if (ret) {
  245. fprintf(stderr, "failed to map buffer: %s\n",
  246. strerror(-errno));
  247. bo_destroy(bo);
  248. return NULL;
  249. }
  250. /* just testing a limited # of formats to test single
  251. * and multi-planar path.. would be nice to add more..
  252. */
  253. switch (format) {
  254. case DRM_FORMAT_UYVY:
  255. case DRM_FORMAT_VYUY:
  256. case DRM_FORMAT_YUYV:
  257. case DRM_FORMAT_YVYU:
  258. offsets[0] = 0;
  259. handles[0] = bo->handle;
  260. pitches[0] = bo->pitch;
  261. planes[0] = virtual;
  262. break;
  263. case DRM_FORMAT_NV12:
  264. case DRM_FORMAT_NV21:
  265. case DRM_FORMAT_NV16:
  266. case DRM_FORMAT_NV61:
  267. offsets[0] = 0;
  268. handles[0] = bo->handle;
  269. pitches[0] = bo->pitch;
  270. pitches[1] = pitches[0];
  271. offsets[1] = pitches[0] * height;
  272. handles[1] = bo->handle;
  273. planes[0] = virtual;
  274. planes[1] = virtual + offsets[1];
  275. break;
  276. case DRM_FORMAT_YUV420:
  277. case DRM_FORMAT_YVU420:
  278. offsets[0] = 0;
  279. handles[0] = bo->handle;
  280. pitches[0] = bo->pitch;
  281. pitches[1] = pitches[0] / 2;
  282. offsets[1] = pitches[0] * height;
  283. handles[1] = bo->handle;
  284. pitches[2] = pitches[1];
  285. offsets[2] = offsets[1] + pitches[1] * height / 2;
  286. handles[2] = bo->handle;
  287. planes[0] = virtual;
  288. planes[1] = virtual + offsets[1];
  289. planes[2] = virtual + offsets[2];
  290. break;
  291. case DRM_FORMAT_C8:
  292. case DRM_FORMAT_ARGB4444:
  293. case DRM_FORMAT_XRGB4444:
  294. case DRM_FORMAT_ABGR4444:
  295. case DRM_FORMAT_XBGR4444:
  296. case DRM_FORMAT_RGBA4444:
  297. case DRM_FORMAT_RGBX4444:
  298. case DRM_FORMAT_BGRA4444:
  299. case DRM_FORMAT_BGRX4444:
  300. case DRM_FORMAT_ARGB1555:
  301. case DRM_FORMAT_XRGB1555:
  302. case DRM_FORMAT_ABGR1555:
  303. case DRM_FORMAT_XBGR1555:
  304. case DRM_FORMAT_RGBA5551:
  305. case DRM_FORMAT_RGBX5551:
  306. case DRM_FORMAT_BGRA5551:
  307. case DRM_FORMAT_BGRX5551:
  308. case DRM_FORMAT_RGB565:
  309. case DRM_FORMAT_BGR565:
  310. case DRM_FORMAT_BGR888:
  311. case DRM_FORMAT_RGB888:
  312. case DRM_FORMAT_ARGB8888:
  313. case DRM_FORMAT_XRGB8888:
  314. case DRM_FORMAT_ABGR8888:
  315. case DRM_FORMAT_XBGR8888:
  316. case DRM_FORMAT_RGBA8888:
  317. case DRM_FORMAT_RGBX8888:
  318. case DRM_FORMAT_BGRA8888:
  319. case DRM_FORMAT_BGRX8888:
  320. case DRM_FORMAT_ARGB2101010:
  321. case DRM_FORMAT_XRGB2101010:
  322. case DRM_FORMAT_ABGR2101010:
  323. case DRM_FORMAT_XBGR2101010:
  324. case DRM_FORMAT_RGBA1010102:
  325. case DRM_FORMAT_RGBX1010102:
  326. case DRM_FORMAT_BGRA1010102:
  327. case DRM_FORMAT_BGRX1010102:
  328. case DRM_FORMAT_XRGB16161616F:
  329. case DRM_FORMAT_XBGR16161616F:
  330. case DRM_FORMAT_ARGB16161616F:
  331. case DRM_FORMAT_ABGR16161616F:
  332. offsets[0] = 0;
  333. handles[0] = bo->handle;
  334. pitches[0] = bo->pitch;
  335. planes[0] = virtual;
  336. break;
  337. }
  338. util_fill_pattern(format, pattern, planes, width, height, pitches[0]);
  339. bo_unmap(bo);
  340. return bo;
  341. }
  342. struct bo *
  343. bo_create_plink(int fd, unsigned int format,
  344. unsigned int width, unsigned int height,
  345. unsigned int handles[4], unsigned int pitches[4],
  346. unsigned int offsets[4], enum util_fill_pattern pattern,
  347. int prime_fd, int stride_y)
  348. {
  349. unsigned int virtual_height;
  350. struct bo *bo;
  351. unsigned int bpp;
  352. void *planes[3] = { 0, };
  353. void *virtual;
  354. int ret;
  355. switch (format) {
  356. case DRM_FORMAT_C8:
  357. case DRM_FORMAT_NV12:
  358. case DRM_FORMAT_NV21:
  359. case DRM_FORMAT_NV16:
  360. case DRM_FORMAT_NV61:
  361. case DRM_FORMAT_YUV420:
  362. case DRM_FORMAT_YVU420:
  363. bpp = 8;
  364. break;
  365. case DRM_FORMAT_ARGB4444:
  366. case DRM_FORMAT_XRGB4444:
  367. case DRM_FORMAT_ABGR4444:
  368. case DRM_FORMAT_XBGR4444:
  369. case DRM_FORMAT_RGBA4444:
  370. case DRM_FORMAT_RGBX4444:
  371. case DRM_FORMAT_BGRA4444:
  372. case DRM_FORMAT_BGRX4444:
  373. case DRM_FORMAT_ARGB1555:
  374. case DRM_FORMAT_XRGB1555:
  375. case DRM_FORMAT_ABGR1555:
  376. case DRM_FORMAT_XBGR1555:
  377. case DRM_FORMAT_RGBA5551:
  378. case DRM_FORMAT_RGBX5551:
  379. case DRM_FORMAT_BGRA5551:
  380. case DRM_FORMAT_BGRX5551:
  381. case DRM_FORMAT_RGB565:
  382. case DRM_FORMAT_BGR565:
  383. case DRM_FORMAT_UYVY:
  384. case DRM_FORMAT_VYUY:
  385. case DRM_FORMAT_YUYV:
  386. case DRM_FORMAT_YVYU:
  387. bpp = 16;
  388. break;
  389. case DRM_FORMAT_BGR888:
  390. case DRM_FORMAT_RGB888:
  391. bpp = 24;
  392. break;
  393. case DRM_FORMAT_ARGB8888:
  394. case DRM_FORMAT_XRGB8888:
  395. case DRM_FORMAT_ABGR8888:
  396. case DRM_FORMAT_XBGR8888:
  397. case DRM_FORMAT_RGBA8888:
  398. case DRM_FORMAT_RGBX8888:
  399. case DRM_FORMAT_BGRA8888:
  400. case DRM_FORMAT_BGRX8888:
  401. case DRM_FORMAT_ARGB2101010:
  402. case DRM_FORMAT_XRGB2101010:
  403. case DRM_FORMAT_ABGR2101010:
  404. case DRM_FORMAT_XBGR2101010:
  405. case DRM_FORMAT_RGBA1010102:
  406. case DRM_FORMAT_RGBX1010102:
  407. case DRM_FORMAT_BGRA1010102:
  408. case DRM_FORMAT_BGRX1010102:
  409. bpp = 32;
  410. break;
  411. case DRM_FORMAT_XRGB16161616F:
  412. case DRM_FORMAT_XBGR16161616F:
  413. case DRM_FORMAT_ARGB16161616F:
  414. case DRM_FORMAT_ABGR16161616F:
  415. bpp = 64;
  416. break;
  417. default:
  418. fprintf(stderr, "unsupported format 0x%08x\n", format);
  419. return NULL;
  420. }
  421. switch (format) {
  422. case DRM_FORMAT_NV12:
  423. case DRM_FORMAT_NV21:
  424. case DRM_FORMAT_YUV420:
  425. case DRM_FORMAT_YVU420:
  426. virtual_height = height * 3 / 2;
  427. break;
  428. case DRM_FORMAT_NV16:
  429. case DRM_FORMAT_NV61:
  430. virtual_height = height * 2;
  431. break;
  432. default:
  433. virtual_height = height;
  434. break;
  435. }
  436. #if 0
  437. bo = bo_create_dumb(fd, width, virtual_height, bpp);
  438. if (!bo)
  439. return NULL;
  440. ret = bo_map(bo, &virtual);
  441. if (ret) {
  442. fprintf(stderr, "failed to map buffer: %s\n",
  443. strerror(-errno));
  444. bo_destroy(bo);
  445. return NULL;
  446. }
  447. #else
  448. bo = bo_create_dumb_plink(fd, width, virtual_height, bpp, prime_fd, stride_y);
  449. if (!bo)
  450. return NULL;
  451. #endif
  452. /* just testing a limited # of formats to test single
  453. * and multi-planar path.. would be nice to add more..
  454. */
  455. switch (format) {
  456. case DRM_FORMAT_UYVY:
  457. case DRM_FORMAT_VYUY:
  458. case DRM_FORMAT_YUYV:
  459. case DRM_FORMAT_YVYU:
  460. offsets[0] = 0;
  461. handles[0] = bo->handle;
  462. pitches[0] = bo->pitch;
  463. planes[0] = virtual;
  464. break;
  465. case DRM_FORMAT_NV12:
  466. case DRM_FORMAT_NV21:
  467. case DRM_FORMAT_NV16:
  468. case DRM_FORMAT_NV61:
  469. offsets[0] = 0;
  470. handles[0] = bo->handle;
  471. pitches[0] = bo->pitch;
  472. pitches[1] = pitches[0];
  473. offsets[1] = pitches[0] * height;//8294400;
  474. handles[1] = bo->handle;
  475. planes[0] = virtual;
  476. planes[1] = virtual + offsets[1];
  477. break;
  478. case DRM_FORMAT_YUV420:
  479. case DRM_FORMAT_YVU420:
  480. offsets[0] = 0;
  481. handles[0] = bo->handle;
  482. pitches[0] = bo->pitch;
  483. pitches[1] = pitches[0] / 2;
  484. offsets[1] = pitches[0] * height;
  485. handles[1] = bo->handle;
  486. pitches[2] = pitches[1];
  487. offsets[2] = offsets[1] + pitches[1] * height / 2;
  488. handles[2] = bo->handle;
  489. planes[0] = virtual;
  490. planes[1] = virtual + offsets[1];
  491. planes[2] = virtual + offsets[2];
  492. break;
  493. case DRM_FORMAT_C8:
  494. case DRM_FORMAT_ARGB4444:
  495. case DRM_FORMAT_XRGB4444:
  496. case DRM_FORMAT_ABGR4444:
  497. case DRM_FORMAT_XBGR4444:
  498. case DRM_FORMAT_RGBA4444:
  499. case DRM_FORMAT_RGBX4444:
  500. case DRM_FORMAT_BGRA4444:
  501. case DRM_FORMAT_BGRX4444:
  502. case DRM_FORMAT_ARGB1555:
  503. case DRM_FORMAT_XRGB1555:
  504. case DRM_FORMAT_ABGR1555:
  505. case DRM_FORMAT_XBGR1555:
  506. case DRM_FORMAT_RGBA5551:
  507. case DRM_FORMAT_RGBX5551:
  508. case DRM_FORMAT_BGRA5551:
  509. case DRM_FORMAT_BGRX5551:
  510. case DRM_FORMAT_RGB565:
  511. case DRM_FORMAT_BGR565:
  512. case DRM_FORMAT_BGR888:
  513. case DRM_FORMAT_RGB888:
  514. case DRM_FORMAT_ARGB8888:
  515. case DRM_FORMAT_XRGB8888:
  516. case DRM_FORMAT_ABGR8888:
  517. case DRM_FORMAT_XBGR8888:
  518. case DRM_FORMAT_RGBA8888:
  519. case DRM_FORMAT_RGBX8888:
  520. case DRM_FORMAT_BGRA8888:
  521. case DRM_FORMAT_BGRX8888:
  522. case DRM_FORMAT_ARGB2101010:
  523. case DRM_FORMAT_XRGB2101010:
  524. case DRM_FORMAT_ABGR2101010:
  525. case DRM_FORMAT_XBGR2101010:
  526. case DRM_FORMAT_RGBA1010102:
  527. case DRM_FORMAT_RGBX1010102:
  528. case DRM_FORMAT_BGRA1010102:
  529. case DRM_FORMAT_BGRX1010102:
  530. case DRM_FORMAT_XRGB16161616F:
  531. case DRM_FORMAT_XBGR16161616F:
  532. case DRM_FORMAT_ARGB16161616F:
  533. case DRM_FORMAT_ABGR16161616F:
  534. offsets[0] = 0;
  535. handles[0] = bo->handle;
  536. pitches[0] = bo->pitch;
  537. planes[0] = virtual;
  538. break;
  539. }
  540. #if 0
  541. util_fill_pattern(format, pattern, planes, width, height, pitches[0]);
  542. bo_unmap(bo);
  543. #endif
  544. return bo;
  545. }
  546. void bo_destroy(struct bo *bo)
  547. {
  548. struct drm_mode_destroy_dumb arg;
  549. int ret;
  550. memset(&arg, 0, sizeof(arg));
  551. arg.handle = bo->handle;
  552. ret = drmIoctl(bo->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
  553. if (ret)
  554. fprintf(stderr, "failed to destroy dumb buffer: %s\n",
  555. strerror(errno));
  556. free(bo);
  557. }