0055-egl-null-introduce-NULL_DRM_DISPLAY.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From 58e030c23402e2ea7a5e7627daabe1e68f1d8130 Mon Sep 17 00:00:00 2001
  2. From: Brendan King <Brendan.King@imgtec.com>
  3. Date: Mon, 28 Jun 2021 16:36:15 +0100
  4. Subject: [PATCH] egl/null: introduce NULL_DRM_DISPLAY
  5. Introduce the NULL_DRM_DISPLAY environment variable, which allows
  6. a particular DRM display to be selected, rather than the first
  7. suitable DRM device found.
  8. To select a particular display, NULL_DRM_DISPLAY should be set to
  9. the card number (i.e. minor number) of the DRM device representing
  10. the display. For example, NULL_DRM_DISPLAY=2 will select
  11. /dev/dri/card2.
  12. ---
  13. src/egl/drivers/dri2/platform_null.c | 65 ++++++++++++++++++++--------
  14. 1 file changed, 46 insertions(+), 19 deletions(-)
  15. diff --git a/src/egl/drivers/dri2/platform_null.c b/src/egl/drivers/dri2/platform_null.c
  16. index 0d81151..c9409c0 100644
  17. --- a/src/egl/drivers/dri2/platform_null.c
  18. +++ b/src/egl/drivers/dri2/platform_null.c
  19. @@ -1819,6 +1819,8 @@ dri2_null_try_device(_EGLDisplay *disp)
  20. {
  21. struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
  22. + dri2_dpy->fd = -1;
  23. +
  24. if (!dri2_null_device_is_kms(dri2_dpy->fd_dpy))
  25. return false;
  26. @@ -1876,34 +1878,56 @@ dri2_null_try_device(_EGLDisplay *disp)
  27. }
  28. static bool
  29. -dri2_null_probe_device(_EGLDisplay *disp)
  30. +dri2_null_probe_device(_EGLDisplay *disp, unsigned minor)
  31. {
  32. struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
  33. + char *card_path;
  34. - dri2_dpy->fd = -1;
  35. - dri2_dpy->fd_dpy = -1;
  36. + if (asprintf(&card_path, DRM_DEV_NAME, DRM_DIR_NAME, minor) < 0)
  37. + goto cleanup;
  38. - for (unsigned i = 0; i <= NULL_CARD_MINOR_MAX; i++) {
  39. - char *card_path;
  40. + dri2_dpy->fd_dpy = loader_open_device(card_path);
  41. + free(card_path);
  42. + if (dri2_dpy->fd_dpy < 0)
  43. + goto cleanup;
  44. - if (asprintf(&card_path, DRM_DEV_NAME, DRM_DIR_NAME, i) < 0)
  45. - continue;
  46. + if (dri2_null_try_device(disp))
  47. + return true;
  48. - dri2_dpy->fd_dpy = loader_open_device(card_path);
  49. - free(card_path);
  50. - if (dri2_dpy->fd_dpy < 0)
  51. - continue;
  52. + close(dri2_dpy->fd_dpy);
  53. - if (dri2_null_try_device(disp))
  54. - return true;
  55. + if (dri2_dpy->fd >= 0 && dri2_dpy->fd != dri2_dpy->fd_dpy)
  56. + close(dri2_dpy->fd);
  57. - close(dri2_dpy->fd_dpy);
  58. +cleanup:
  59. + dri2_dpy->fd_dpy = -1;
  60. + dri2_dpy->fd = -1;
  61. - if (dri2_dpy->fd >= 0 && dri2_dpy->fd != dri2_dpy->fd_dpy)
  62. - close(dri2_dpy->fd);
  63. + return false;
  64. +}
  65. +
  66. +static bool
  67. +dri2_null_probe_devices(_EGLDisplay *disp)
  68. +{
  69. + const char *null_drm_display = getenv("NULL_DRM_DISPLAY");
  70. +
  71. + if (null_drm_display) {
  72. + char *endptr;
  73. + long val = strtol(null_drm_display, &endptr, 10);
  74. - dri2_dpy->fd_dpy = -1;
  75. - dri2_dpy->fd = -1;
  76. + if (endptr != null_drm_display && !*endptr &&
  77. + val >= 0 && val <= NULL_CARD_MINOR_MAX) {
  78. + if (dri2_null_probe_device(disp, (unsigned)val))
  79. + return true;
  80. + } else {
  81. + _eglLog(_EGL_FATAL, "NULL_DRM_DISPLAY is invalid: %s",
  82. + null_drm_display);
  83. + }
  84. + } else {
  85. + for (unsigned i = 0; i <= NULL_CARD_MINOR_MAX; i++) {
  86. + if (dri2_null_probe_device(disp, i))
  87. + return true;
  88. + }
  89. }
  90. return false;
  91. @@ -2001,7 +2025,10 @@ dri2_initialize_null(_EGLDisplay *disp)
  92. disp->DriverData = (void *) dri2_dpy;
  93. - if (!dri2_null_probe_device(disp)) {
  94. + dri2_dpy->fd_dpy = -1;
  95. + dri2_dpy->fd = -1;
  96. +
  97. + if (!dri2_null_probe_devices(disp)) {
  98. _eglError(EGL_NOT_INITIALIZED, "failed to load driver");
  99. goto cleanup;
  100. }