tester.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include <errno.h>
  2. #include <fcntl.h>
  3. #include <getopt.h>
  4. #include <limits.h>
  5. #include <stdbool.h>
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <sys/mman.h>
  11. #include <time.h>
  12. #include <unistd.h>
  13. #include <wayland-client.h>
  14. #include "buffers.h"
  15. #include "common.h"
  16. static void print_usage_and_exit(void) {
  17. printf("Usages:\n\n"
  18. "wl-tester -d /dev/dri/card0 -w 1280 -h 720 -f /path-to/test.yuv -x 100 -y 200 -s -b\n\n"
  19. "\t-d: DRM device node path\n"
  20. "\t-w: RAW YUV file's width\n"
  21. "\t-h: RAW YUV file's height\n"
  22. "\t-f: RAW YUV file's path\n"
  23. "\t-x: Window Surface's x position if compositor supports window position\n"
  24. "\t-y: Window Surface's y position if compositor supports window position\n"
  25. "\t-b: Show Sub Surface/bar\n"
  26. "\t-s: sync mode of sub surface\n"
  27. "\t-n: not read YUV file in loop, for perf debug purpose\n"
  28. "\t-u: Sub Surface use DMA Buf also, default is using Share Memory\n"
  29. );
  30. exit(0);
  31. }
  32. int main(int argc, char *argv[]) {
  33. struct example_window window = {0};
  34. int c, option_index;
  35. int ret = 0;
  36. char default_drm_node[32] = "/dev/dri/card0";
  37. window.drm_node = default_drm_node;
  38. static struct option long_options[] = {
  39. {"drm-node", required_argument, 0, 'd'},
  40. {"raw-file", required_argument, 0, 'f'},
  41. {"width", required_argument, 0, 'w'},
  42. {"height", required_argument, 0, 'h'},
  43. {"sx", required_argument, 0, 'x'},
  44. {"sy", required_argument, 0, 'y'},
  45. {"show-bar", no_argument, NULL, 'b'},
  46. {"sync", no_argument, NULL, 's'},
  47. {"noread", no_argument, NULL, 'n'},
  48. {"ss-usedma", no_argument, NULL, 'u'},
  49. {"help", no_argument, 0, 0},
  50. {0, 0, 0, 0}};
  51. while ((c = getopt_long(argc, argv, "bsnud:f:w:h:x:y:", long_options, &option_index)) !=
  52. -1) {
  53. switch (c) {
  54. case 'w':
  55. window.width = atoi(optarg);
  56. break;
  57. case 'h':
  58. window.height = atoi(optarg);
  59. break;
  60. case 'x':
  61. window.x = atoi(optarg);
  62. break;
  63. case 'y':
  64. window.y = atoi(optarg);
  65. break;
  66. case 'd':
  67. window.drm_node = optarg;
  68. break;
  69. case 'f':
  70. window.raw_file = optarg;
  71. break;
  72. case 's':
  73. window.sync = true;
  74. break;
  75. case 'n':
  76. window.noread = true;
  77. break;
  78. case 'u':
  79. window.ss_usedma = true;
  80. break;
  81. case 'b':
  82. window.show_bar = true;
  83. break;
  84. default:
  85. print_usage_and_exit();
  86. }
  87. }
  88. window.raw_fp = fopen(window.raw_file, "rb");
  89. if (!window.raw_fp) {
  90. fprintf(stderr, "Error opening yuv image for read\n");
  91. return -1;
  92. }
  93. ret = init_window(&window);
  94. if (ret){
  95. return 1;
  96. }
  97. return 0;
  98. }