gr2d-fill.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright © 2014 NVIDIA Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifdef HAVE_CONFIG_H
  23. # include "config.h"
  24. #endif
  25. #include <errno.h>
  26. #include <fcntl.h>
  27. #include <stdbool.h>
  28. #include <stdint.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <unistd.h>
  33. #include <sys/ioctl.h>
  34. #include "xf86drm.h"
  35. #include "xf86drmMode.h"
  36. #include "drm_fourcc.h"
  37. #include "drm-test-tegra.h"
  38. #include "tegra.h"
  39. int main(int argc, char *argv[])
  40. {
  41. uint32_t format = DRM_FORMAT_XRGB8888;
  42. struct drm_tegra_gr2d *gr2d;
  43. struct drm_framebuffer *fb;
  44. struct drm_screen *screen;
  45. unsigned int pitch, size;
  46. struct drm_tegra_bo *bo;
  47. struct drm_tegra *drm;
  48. uint32_t handle;
  49. int fd, err;
  50. void *ptr;
  51. fd = drm_open(argv[1]);
  52. if (fd < 0) {
  53. fprintf(stderr, "failed to open DRM device %s: %s\n", argv[1],
  54. strerror(errno));
  55. return 1;
  56. }
  57. err = drm_screen_open(&screen, fd);
  58. if (err < 0) {
  59. fprintf(stderr, "failed to open screen: %s\n", strerror(-err));
  60. return 1;
  61. }
  62. err = drm_tegra_new(fd, &drm);
  63. if (err < 0) {
  64. fprintf(stderr, "failed to create Tegra DRM context: %s\n",
  65. strerror(-err));
  66. return 1;
  67. }
  68. err = drm_tegra_gr2d_open(drm, &gr2d);
  69. if (err < 0) {
  70. fprintf(stderr, "failed to open gr2d channel: %s\n",
  71. strerror(-err));
  72. return 1;
  73. }
  74. pitch = screen->width * screen->bpp / 8;
  75. size = pitch * screen->height;
  76. err = drm_tegra_bo_new(drm, 0, size, &bo);
  77. if (err < 0) {
  78. fprintf(stderr, "failed to create buffer object: %s\n",
  79. strerror(-err));
  80. return 1;
  81. }
  82. err = drm_tegra_bo_get_handle(bo, &handle);
  83. if (err < 0) {
  84. fprintf(stderr, "failed to get handle to buffer object: %s\n",
  85. strerror(-err));
  86. return 1;
  87. }
  88. err = drm_tegra_bo_map(bo, &ptr);
  89. if (err < 0) {
  90. fprintf(stderr, "failed to map buffer object: %s\n",
  91. strerror(-err));
  92. return 1;
  93. }
  94. memset(ptr, 0xff, size);
  95. err = drm_framebuffer_new(&fb, screen, handle, screen->width,
  96. screen->height, pitch, format, bo);
  97. if (err < 0) {
  98. fprintf(stderr, "failed to create framebuffer: %s\n",
  99. strerror(-err));
  100. return 1;
  101. }
  102. err = drm_screen_set_framebuffer(screen, fb);
  103. if (err < 0) {
  104. fprintf(stderr, "failed to display framebuffer: %s\n",
  105. strerror(-err));
  106. return 1;
  107. }
  108. sleep(1);
  109. err = drm_tegra_gr2d_fill(gr2d, fb, fb->width / 4, fb->height / 4,
  110. fb->width / 2, fb->height / 2, 0x00000000);
  111. if (err < 0) {
  112. fprintf(stderr, "failed to fill rectangle: %s\n",
  113. strerror(-err));
  114. return 1;
  115. }
  116. sleep(1);
  117. drm_framebuffer_free(fb);
  118. drm_tegra_bo_unref(bo);
  119. drm_tegra_gr2d_close(gr2d);
  120. drm_tegra_close(drm);
  121. drm_screen_close(screen);
  122. drm_close(fd);
  123. return 0;
  124. }