0001-opengl-backend-support-multiple-backends.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. From 9c397af0dabfff7177bcb76409af5b8f9ae608cf Mon Sep 17 00:00:00 2001
  2. From: Drew DeVault <sir@cmpwn.com>
  3. Date: Thu, 27 Apr 2017 17:19:58 -0400
  4. Subject: [PATCH 1/4] --opengl-backend: support multiple backends
  5. Will attempt each backend specified in order. The x11 backend is still
  6. preferred, even on Wayland, but the user can now use
  7. --opengl-backend=wayland,x11 to prefer wayland and fall back to x11 if
  8. wayland is unavailable.
  9. ---
  10. video/out/opengl/context.c | 66 +++++++++++++++++++++++++++++++++++++++++-----
  11. video/out/opengl/context.h | 8 ++----
  12. video/out/vo_opengl.c | 7 +++--
  13. 3 files changed, 64 insertions(+), 17 deletions(-)
  14. diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c
  15. index 72311e11fa..568bb662b8 100644
  16. --- a/video/out/opengl/context.c
  17. +++ b/video/out/opengl/context.c
  18. @@ -89,6 +89,30 @@ static const struct mpgl_driver *const backends[] = {
  19. #endif
  20. };
  21. +static bool get_desc(struct m_obj_desc *dst, int index)
  22. +{
  23. + if (index >= MP_ARRAY_SIZE(backends) - 1)
  24. + return false;
  25. + const struct mpgl_driver *driver = backends[index];
  26. + *dst = (struct m_obj_desc) {
  27. + .name = driver->name,
  28. + .description = driver->name,
  29. + .priv_size = sizeof(struct mpgl_driver),
  30. + .p = driver,
  31. + };
  32. + return true;
  33. +}
  34. +
  35. +// for backend option
  36. +const struct m_obj_list mpgl_backend_list = {
  37. + .get_desc = get_desc,
  38. + .description = "OpenGL windowing backends",
  39. + .allow_unknown_entries = true,
  40. + .allow_disable_entries = true,
  41. + .allow_trailer = true,
  42. + .disallow_positional_parameters = true,
  43. +};
  44. +
  45. // 0-terminated list of desktop GL versions a backend should try to
  46. // initialize. The first entry is the most preferred version.
  47. const int mpgl_preferred_gl_versions[] = {
  48. @@ -100,7 +124,7 @@ const int mpgl_preferred_gl_versions[] = {
  49. 0
  50. };
  51. -int mpgl_find_backend(const char *name)
  52. +static int mpgl_find_backend(const char *name)
  53. {
  54. if (name == NULL || strcmp(name, "auto") == 0)
  55. return -1;
  56. @@ -126,7 +150,7 @@ int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
  57. return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
  58. }
  59. -static void *get_native_display(void *pctx, const char *name)
  60. +static void *get_native_display(const char *name)
  61. {
  62. MPGLContext *ctx = pctx;
  63. if (!ctx->native_display_type || !name)
  64. @@ -186,11 +210,41 @@ cleanup:
  65. // Create a VO window and create a GL context on it.
  66. // vo_flags: passed to the backend's create window function
  67. -MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
  68. +MPGLContext *mpgl_init(struct vo *vo, struct m_obj_settings *backend_list, int vo_flags)
  69. {
  70. MPGLContext *ctx = NULL;
  71. - int index = mpgl_find_backend(backend_name);
  72. - if (index == -1) {
  73. + if (backend_list && backend_list[0].name) {
  74. + int n;
  75. + for (n = 0; backend_list[n].name; n++) {
  76. + // Something like "--opengl-backend=name," allows fallback to autoprobing.
  77. + int index = mpgl_find_backend(backend_list[n].name);
  78. + if (index == -1 || strlen(backend_list[n].name) == 0)
  79. + goto autoprobe;
  80. + if (index == -2) {
  81. + MP_FATAL(vo, "Unknown opengl backend '%s'\n", backend_list[n].name);
  82. + exit(-2);
  83. + return NULL;
  84. + }
  85. + ctx = init_backend(vo, backends[index], true, vo_flags);
  86. + if (ctx)
  87. + break;
  88. + }
  89. + if (!ctx && !vo->probing) {
  90. + // Now try with probing off
  91. + for (n = 0; backend_list[n].name; n++) {
  92. + int index = mpgl_find_backend(backend_list[n].name);
  93. + ctx = init_backend(vo, backends[index], false, vo_flags);
  94. + if (ctx)
  95. + break;
  96. + }
  97. + if (!ctx) {
  98. + // Backend explicitly requested, but unable to fulfill
  99. + return NULL;
  100. + }
  101. + }
  102. + }
  103. + if (!ctx) {
  104. +autoprobe:
  105. for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
  106. ctx = init_backend(vo, backends[n], true, vo_flags);
  107. if (ctx)
  108. @@ -204,8 +258,6 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
  109. break;
  110. }
  111. }
  112. - } else if (index >= 0) {
  113. - ctx = init_backend(vo, backends[index], false, vo_flags);
  114. }
  115. return ctx;
  116. }
  117. diff --git a/video/out/opengl/context.h b/video/out/opengl/context.h
  118. index 229c5ef54f..7cf439c1a0 100644
  119. --- a/video/out/opengl/context.h
  120. +++ b/video/out/opengl/context.h
  121. @@ -100,17 +100,13 @@ typedef struct MPGLContext {
  122. void *priv;
  123. } MPGLContext;
  124. -MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags);
  125. +MPGLContext *mpgl_init(struct vo *vo, struct m_obj_settings *backend_list, int vo_flags);
  126. void mpgl_uninit(MPGLContext *ctx);
  127. int mpgl_reconfig_window(struct MPGLContext *ctx);
  128. int mpgl_control(struct MPGLContext *ctx, int *events, int request, void *arg);
  129. void mpgl_start_frame(struct MPGLContext *ctx);
  130. void mpgl_swap_buffers(struct MPGLContext *ctx);
  131. -int mpgl_find_backend(const char *name);
  132. -
  133. -struct m_option;
  134. -int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
  135. - struct bstr name, struct bstr param);
  136. +extern const struct m_obj_list mpgl_backend_list;
  137. #endif
  138. diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c
  139. index 9b3f944e21..91e55b3b2f 100644
  140. --- a/video/out/vo_opengl.c
  141. +++ b/video/out/vo_opengl.c
  142. @@ -55,7 +55,7 @@ struct vo_opengl_opts {
  143. int allow_sw;
  144. int swap_interval;
  145. int vsync_fences;
  146. - char *backend;
  147. + struct m_obj_settings *backend_list;
  148. int es;
  149. int pattern[2];
  150. };
  151. @@ -383,7 +383,7 @@ static int preinit(struct vo *vo)
  152. if (p->opts.allow_sw)
  153. vo_flags |= VOFLAG_SW;
  154. - p->glctx = mpgl_init(vo, p->opts.backend, vo_flags);
  155. + p->glctx = mpgl_init(vo, p->opts.backend_list, vo_flags);
  156. if (!p->glctx)
  157. goto err_out;
  158. p->gl = p->glctx->gl;
  159. @@ -438,8 +438,7 @@ const struct vo_driver video_out_opengl = {
  160. OPT_FLAG("opengl-waitvsync", opts.waitvsync, 0),
  161. OPT_INT("opengl-swapinterval", opts.swap_interval, 0),
  162. OPT_FLAG("opengl-debug", opts.use_gl_debug, 0),
  163. - OPT_STRING_VALIDATE("opengl-backend", opts.backend, 0,
  164. - mpgl_validate_backend_opt),
  165. + OPT_SETTINGSLIST("opengl-backend", opts.backend_list, 0, &mpgl_backend_list ),
  166. OPT_FLAG("opengl-sw", opts.allow_sw, 0),
  167. OPT_CHOICE("opengl-es", opts.es, 0, ({"no", -1}, {"auto", 0},
  168. {"yes", 1}, {"force2", 2})),
  169. From 4e89fae50f70d065ff8ffee40aa8dffe8131210e Mon Sep 17 00:00:00 2001
  170. From: Drew DeVault <sir@cmpwn.com>
  171. Date: Thu, 27 Apr 2017 17:51:39 -0400
  172. Subject: [PATCH 2/4] Update mpv.1
  173. ---
  174. DOCS/man/options.rst | 7 ++++---
  175. 1 file changed, 4 insertions(+), 3 deletions(-)
  176. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
  177. index 925c501881..5d57720e3d 100644
  178. --- a/DOCS/man/options.rst
  179. +++ b/DOCS/man/options.rst
  180. @@ -4480,9 +4480,10 @@ The following video options are currently all specific to ``--vo=opengl`` and
  181. Continue even if a software renderer is detected.
  182. ``--opengl-backend=<sys>``
  183. - The value ``auto`` (the default) selects the windowing backend. You can
  184. - also pass ``help`` to get a complete list of compiled in backends (sorted
  185. - by autoprobe order).
  186. + Specify a priority list of windowing backends to use with OpenGL. The value
  187. + ``auto`` (the default) automatically probes for the most suitable backend.
  188. + You can also pass ``help`` to get a complete list of compiled in backends
  189. + (sorted by autoprobe order).
  190. auto
  191. auto-select (default)
  192. From 3fb437fa09ebf20635c02f41ce0e3d13423d1454 Mon Sep 17 00:00:00 2001
  193. From: Drew DeVault <sir@cmpwn.com>
  194. Date: Thu, 27 Apr 2017 20:12:51 -0400
  195. Subject: [PATCH 3/4] Let options handle invalid backends
  196. ---
  197. video/out/opengl/context.c | 17 +++++++++--------
  198. 1 file changed, 9 insertions(+), 8 deletions(-)
  199. diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c
  200. index 568bb662b8..8aa44b67cc 100644
  201. --- a/video/out/opengl/context.c
  202. +++ b/video/out/opengl/context.c
  203. @@ -91,6 +91,14 @@ static const struct mpgl_driver *const backends[] = {
  204. static bool get_desc(struct m_obj_desc *dst, int index)
  205. {
  206. + if (index == 0) {
  207. + *dst = (struct m_obj_desc) {
  208. + .name = "auto",
  209. + .description = "automatically select most suitable backend"
  210. + };
  211. + return true;
  212. + }
  213. + index--;
  214. if (index >= MP_ARRAY_SIZE(backends) - 1)
  215. return false;
  216. const struct mpgl_driver *driver = backends[index];
  217. @@ -107,8 +115,6 @@ static bool get_desc(struct m_obj_desc *dst, int index)
  218. const struct m_obj_list mpgl_backend_list = {
  219. .get_desc = get_desc,
  220. .description = "OpenGL windowing backends",
  221. - .allow_unknown_entries = true,
  222. - .allow_disable_entries = true,
  223. .allow_trailer = true,
  224. .disallow_positional_parameters = true,
  225. };
  226. @@ -218,13 +224,8 @@ MPGLContext *mpgl_init(struct vo *vo, struct m_obj_settings *backend_list, int v
  227. for (n = 0; backend_list[n].name; n++) {
  228. // Something like "--opengl-backend=name," allows fallback to autoprobing.
  229. int index = mpgl_find_backend(backend_list[n].name);
  230. - if (index == -1 || strlen(backend_list[n].name) == 0)
  231. + if (index < 0 || strlen(backend_list[n].name) == 0)
  232. goto autoprobe;
  233. - if (index == -2) {
  234. - MP_FATAL(vo, "Unknown opengl backend '%s'\n", backend_list[n].name);
  235. - exit(-2);
  236. - return NULL;
  237. - }
  238. ctx = init_backend(vo, backends[index], true, vo_flags);
  239. if (ctx)
  240. break;
  241. From 605785c4846ecaa969309f7fb63cfba59751ba61 Mon Sep 17 00:00:00 2001
  242. From: Drew DeVault <sir@cmpwn.com>
  243. Date: Fri, 26 May 2017 15:31:24 -0400
  244. Subject: [PATCH 4/4] Updates following HEAD
  245. ---
  246. video/out/opengl/context.c | 17 +----------------
  247. 1 file changed, 1 insertion(+), 16 deletions(-)
  248. diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c
  249. index 8aa44b67cc..4cc0829c90 100644
  250. --- a/video/out/opengl/context.c
  251. +++ b/video/out/opengl/context.c
  252. @@ -141,22 +141,7 @@ static int mpgl_find_backend(const char *name)
  253. return -2;
  254. }
  255. -int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
  256. - struct bstr name, struct bstr param)
  257. -{
  258. - if (bstr_equals0(param, "help")) {
  259. - mp_info(log, "OpenGL windowing backends:\n");
  260. - mp_info(log, " auto (autodetect)\n");
  261. - for (int n = 0; n < MP_ARRAY_SIZE(backends); n++)
  262. - mp_info(log, " %s\n", backends[n]->name);
  263. - return M_OPT_EXIT;
  264. - }
  265. - char s[20];
  266. - snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
  267. - return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
  268. -}
  269. -
  270. -static void *get_native_display(const char *name)
  271. +static void *get_native_display(void *pctx, const char *name)
  272. {
  273. MPGLContext *ctx = pctx;
  274. if (!ctx->native_display_type || !name)