History

vo: unify ra_gl_ctx_params and ra_vk_ctx_params into ra_ctx_params

These were separate for some reason which makes no sense and is really annoying if you want to use something that's in the vk version and not the gl one or vice versa. As a bonus, these now get to live right above the ra_swapchain definition which is more convenient.

Dudemanguy committed 1 year ago

Commit 8ddc5631 parent b97b13b20 files · +51 −63Browse files

Unified · Split

20 files
  1. video/out/gpu/context.h +30 −0
  2. video/out/opengl/context.c +2 −2
  3. video/out/opengl/context.h +1 −28
  4. video/out/opengl/context_android.c +1 −1
  5. video/out/opengl/context_angle.c +1 −1
  6. video/out/opengl/context_drm_egl.c +1 −1
  7. video/out/opengl/context_dxinterop.c +1 −1
  8. video/out/opengl/context_glx.c +1 −1
  9. video/out/opengl/context_wayland.c +1 −1
  10. video/out/opengl/context_win.c +1 −1
  11. video/out/opengl/context_x11egl.c +1 −1
  12. video/out/opengl/libmpv_gl.c +1 −1
  13. video/out/vulkan/context.c +2 −2
  14. video/out/vulkan/context.h +1 −16
  15. video/out/vulkan/context_android.c +1 −1
  16. video/out/vulkan/context_display.c +1 −1
  17. video/out/vulkan/context_mac.m +1 −1
  18. video/out/vulkan/context_wayland.c +1 −1
  19. video/out/vulkan/context_win.c +1 −1
  20. video/out/vulkan/context_xlib.c +1 −1
video/out/gpu/context.h+30−0
@@ -62,6 +62,36 @@ struct ra_ctx_fns { · 61 unmodified lines
6262 void (*uninit)(struct ra_ctx *ctx);
6363 };
6464
65+// These are a set of helpers for ra_ctx providers based on ra_gl.
66+// The init function also initializes ctx->ra and ctx->swapchain, so the user
67+// doesn't have to do this manually. (Similarly, the uninit function will
68+// clean them up)
69+
70+struct ra_ctx_params {
71+ // For special contexts (i.e. wayland) that want to check visibility
72+ // before drawing a frame.
73+ bool (*check_visible)(struct ra_ctx *ctx);
74+
75+ // See ra_swapchain_fns.color_depth.
76+ int (*color_depth)(struct ra_ctx *ctx);
77+
78+ // See ra_swapchain_fns.get_vsync.
79+ void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info);
80+
81+ // Set to the platform-specific function to swap buffers, like
82+ // glXSwapBuffers, eglSwapBuffers etc. This will be called by
83+ // ra_gl_ctx_swap_buffers. Required unless you either never call that
84+ // function or if you override it yourself.
85+ void (*swap_buffers)(struct ra_ctx *ctx);
86+
87+ // If this is set to non-NULL, then the ra_gl_ctx will consider the GL
88+ // implementation to be using an external swapchain, which disables the
89+ // software simulation of --swapchain-depth. Any functions defined by this
90+ // ra_swapchain_fns structs will entirely replace the equivalent ra_gl_ctx
91+ // functions in the resulting ra_swapchain.
92+ const struct ra_swapchain_fns *external_swapchain;
93+};
94+
6595 // Extra struct for the swapchain-related functions so they can be easily
6696 // inherited from helpers.
6797 struct ra_swapchain {
video/out/opengl/context.c+2−2
@@ -77,7 +77,7 @@ const struct m_sub_options opengl_conf = { · 76 unmodified lines
7777 struct priv {
7878 GL *gl;
7979 struct mp_log *log;
80− struct ra_gl_ctx_params params;
80+ struct ra_ctx_params params;
8181 struct opengl_opts *opts;
8282 struct ra_swapchain_fns fns;
8383 GLuint main_fb;
@@ -125,7 +125,7 @@ void ra_gl_ctx_uninit(struct ra_ctx *ctx) · 41 unmodified lines
125125
126126 static const struct ra_swapchain_fns ra_gl_swapchain_fns;
127127
128−bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_gl_ctx_params params)
128+bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_ctx_params params)
129129 {
130130 struct ra_swapchain *sw = ctx->swapchain = talloc_ptrtype(NULL, sw);
131131 *sw = (struct ra_swapchain) {
video/out/opengl/context.h+1−28
@@ -14,35 +14,8 @@ enum gles_mode { · 13 unmodified lines
1414 // Returns the gles mode based on the --opengl opts.
1515 enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx);
1616
17−// These are a set of helpers for ra_ctx providers based on ra_gl.
18−// The init function also initializes ctx->ra and ctx->swapchain, so the user
19−// doesn't have to do this manually. (Similarly, the uninit function will
20−// clean them up)
21−
22−struct ra_gl_ctx_params {
23− // For special contexts (i.e. wayland) that want to check visibility
24− // before drawing a frame.
25− bool (*check_visible)(struct ra_ctx *ctx);
26−
27− // Set to the platform-specific function to swap buffers, like
28− // glXSwapBuffers, eglSwapBuffers etc. This will be called by
29− // ra_gl_ctx_swap_buffers. Required unless you either never call that
30− // function or if you override it yourself.
31− void (*swap_buffers)(struct ra_ctx *ctx);
32−
33− // See ra_swapchain_fns.get_vsync.
34− void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info);
35−
36− // If this is set to non-NULL, then the ra_gl_ctx will consider the GL
37− // implementation to be using an external swapchain, which disables the
38− // software simulation of --swapchain-depth. Any functions defined by this
39− // ra_swapchain_fns structs will entirely replace the equivalent ra_gl_ctx
40− // functions in the resulting ra_swapchain.
41− const struct ra_swapchain_fns *external_swapchain;
42−};
43−
4417 void ra_gl_ctx_uninit(struct ra_ctx *ctx);
45−bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_gl_ctx_params params);
18+bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_ctx_params params);
4619
4720 // Call this any time the window size or main framebuffer changes
4821 void ra_gl_ctx_resize(struct ra_swapchain *sw, int w, int h, int fbo);
video/out/opengl/context_android.c+1−1
@@ -90,7 +90,7 @@ static bool android_init(struct ra_ctx *ctx) · 89 unmodified lines
9090
9191 mpegl_load_functions(&p->gl, ctx->log);
9292
93− struct ra_gl_ctx_params params = {
93+ struct ra_ctx_params params = {
9494 .swap_buffers = android_swap_buffers,
9595 };
9696
video/out/opengl/context_angle.c+1−1
@@ -601,7 +601,7 @@ static bool angle_init(struct ra_ctx *ctx) · 600 unmodified lines
601601 .color_depth = angle_color_depth,
602602 .submit_frame = angle_submit_frame,
603603 };
604− struct ra_gl_ctx_params params = {
604+ struct ra_ctx_params params = {
605605 .swap_buffers = angle_swap_buffers,
606606 .external_swapchain = p->dxgi_swapchain ? &dxgi_swapchain_fns : NULL,
607607 };
video/out/opengl/context_drm_egl.c+1−1
@@ -682,7 +682,7 @@ static bool drm_egl_init(struct ra_ctx *ctx) · 681 unmodified lines
682682 MP_VERBOSE(ctx, "Could not find path to render node.\n");
683683 }
684684
685− struct ra_gl_ctx_params params = {
685+ struct ra_ctx_params params = {
686686 .external_swapchain = &drm_egl_swapchain,
687687 .get_vsync = &drm_egl_get_vsync,
688688 };
video/out/opengl/context_dxinterop.c+1−1
@@ -548,7 +548,7 @@ static bool dxgl_init(struct ra_ctx *ctx) · 547 unmodified lines
548548 goto fail;
549549
550550 static const struct ra_swapchain_fns empty_swapchain_fns = {0};
551− struct ra_gl_ctx_params params = {
551+ struct ra_ctx_params params = {
552552 .swap_buffers = dxgl_swap_buffers,
553553 .external_swapchain = &empty_swapchain_fns,
554554 };
video/out/opengl/context_glx.c+1−1
@@ -290,7 +290,7 @@ static bool glx_init(struct ra_ctx *ctx) · 289 unmodified lines
290290 if (!success)
291291 goto uninit;
292292
293− struct ra_gl_ctx_params params = {
293+ struct ra_ctx_params params = {
294294 .check_visible = glx_check_visible,
295295 .swap_buffers = glx_swap_buffers,
296296 .get_vsync = glx_get_vsync,
video/out/opengl/context_wayland.c+1−1
@@ -104,7 +104,7 @@ static bool egl_create_context(struct ra_ctx *ctx) · 103 unmodified lines
104104
105105 mpegl_load_functions(&p->gl, wl->log);
106106
107− struct ra_gl_ctx_params params = {
107+ struct ra_ctx_params params = {
108108 .check_visible = wayland_egl_check_visible,
109109 .swap_buffers = wayland_egl_swap_buffers,
110110 .get_vsync = wayland_egl_get_vsync,
video/out/opengl/context_win.c+1−1
@@ -312,7 +312,7 @@ static bool wgl_init(struct ra_ctx *ctx) · 311 unmodified lines
312312 gl->SwapInterval = wgl_swap_interval;
313313 p->current_swapinterval = -1;
314314
315− struct ra_gl_ctx_params params = {
315+ struct ra_ctx_params params = {
316316 .swap_buffers = wgl_swap_buffers,
317317 };
318318
video/out/opengl/context_x11egl.c+1−1
@@ -163,7 +163,7 @@ static bool mpegl_init(struct ra_ctx *ctx) · 162 unmodified lines
163163
164164 mpegl_load_functions(&p->gl, ctx->log);
165165
166− struct ra_gl_ctx_params params = {
166+ struct ra_ctx_params params = {
167167 .check_visible = mpegl_check_visible,
168168 .swap_buffers = mpegl_swap_buffers,
169169 .get_vsync = mpegl_get_vsync,
video/out/opengl/libmpv_gl.c+1−1
@@ -40,7 +40,7 @@ static int init(struct libmpv_gpu_context *ctx, mpv_render_param *params) · 39 unmodified lines
4040 };
4141
4242 static const struct ra_swapchain_fns empty_swapchain_fns = {0};
43− struct ra_gl_ctx_params gl_params = {
43+ struct ra_ctx_params gl_params = {
4444 // vo_libmpv is essentially like a gigantic external swapchain where
4545 // the user is in charge of presentation / swapping etc. But we don't
4646 // actually need to provide any of these functions, since we can just
video/out/vulkan/context.c+2−2
@@ -134,7 +134,7 @@ const struct m_sub_options vulkan_conf = { · 133 unmodified lines
134134 struct priv {
135135 struct mpvk_ctx *vk;
136136 struct vulkan_opts *opts;
137− struct ra_vk_ctx_params params;
137+ struct ra_ctx_params params;
138138 struct ra_tex proxy_tex;
139139 };
140140
@@ -249,7 +249,7 @@ pl_vulkan mppl_create_vulkan(struct vulkan_opts *opts, · 108 unmodified lines
249249 }
250250
251251 bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk,
252− struct ra_vk_ctx_params params,
252+ struct ra_ctx_params params,
253253 VkPresentModeKHR preferred_mode)
254254 {
255255 struct ra_swapchain *sw = ctx->swapchain = talloc_zero(NULL, struct ra_swapchain);
video/out/vulkan/context.h+1−16
@@ -3,25 +3,10 @@ · 2 unmodified lines
33 #include "video/out/gpu/context.h"
44 #include "common.h"
55
6−struct ra_vk_ctx_params {
7− // See ra_swapchain_fns.get_vsync.
8− void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info);
9−
10− // For special contexts (i.e. wayland) that want to check visibility
11− // before drawing a frame.
12− bool (*check_visible)(struct ra_ctx *ctx);
13−
14− // In case something special needs to be done on the buffer swap.
15− void (*swap_buffers)(struct ra_ctx *ctx);
16−
17− // See ra_swapchain_fns.color_depth.
18− int (*color_depth)(struct ra_ctx *ctx);
19−};
20−
216 // Helpers for ra_ctx based on ra_vk. These initialize ctx->ra and ctx->swchain.
227 void ra_vk_ctx_uninit(struct ra_ctx *ctx);
238 bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk,
24− struct ra_vk_ctx_params params,
9+ struct ra_ctx_params params,
2510 VkPresentModeKHR preferred_mode);
2611
2712 // Helper for initializing mpvk_ctx->vulkan
video/out/vulkan/context_android.c+1−1
@@ -53,7 +53,7 @@ static bool android_init(struct ra_ctx *ctx) · 52 unmodified lines
5353 .window = vo_android_native_window(ctx->vo)
5454 };
5555
56− struct ra_vk_ctx_params params = {0};
56+ struct ra_ctx_params params = {0};
5757
5858 VkInstance inst = vk->vkinst->instance;
5959 VkResult res = vkCreateAndroidSurfaceKHR(inst, &info, NULL, &vk->surface);
video/out/vulkan/context_display.c+1−1
@@ -441,7 +441,7 @@ static bool display_init(struct ra_ctx *ctx) · 440 unmodified lines
441441 p->height = mode->parameters.visibleRegion.height;
442442 p->refresh_rate = mode->parameters.refreshRate;
443443
444− struct ra_vk_ctx_params params = {0};
444+ struct ra_ctx_params params = {0};
445445 if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_FIFO_KHR))
446446 goto error;
447447
video/out/vulkan/context_mac.m+1−1
@@ -80,7 +80,7 @@ static bool mac_vk_init(struct ra_ctx *ctx) · 79 unmodified lines
8080 .pLayer = p->vo_mac.layer,
8181 };
8282
83− struct ra_vk_ctx_params params = {
83+ struct ra_ctx_params params = {
8484 .swap_buffers = mac_vk_swap_buffers,
8585 .get_vsync = mac_vk_get_vsync,
8686 .color_depth = mac_vk_color_depth,
video/out/vulkan/context_wayland.c+1−1
@@ -79,7 +79,7 @@ static bool wayland_vk_init(struct ra_ctx *ctx) · 78 unmodified lines
7979 .surface = ctx->vo->wl->surface,
8080 };
8181
82− struct ra_vk_ctx_params params = {
82+ struct ra_ctx_params params = {
8383 .check_visible = wayland_vk_check_visible,
8484 .swap_buffers = wayland_vk_swap_buffers,
8585 .get_vsync = wayland_vk_get_vsync,
video/out/vulkan/context_win.c+1−1
@@ -59,7 +59,7 @@ static bool win_init(struct ra_ctx *ctx) · 58 unmodified lines
5959 .hwnd = vo_w32_hwnd(ctx->vo),
6060 };
6161
62− struct ra_vk_ctx_params params = {0};
62+ struct ra_ctx_params params = {0};
6363
6464 VkInstance inst = vk->vkinst->instance;
6565 VkResult res = vkCreateWin32SurfaceKHR(inst, &wininfo, NULL, &vk->surface);
video/out/vulkan/context_xlib.c+1−1
@@ -75,7 +75,7 @@ static bool xlib_init(struct ra_ctx *ctx) · 74 unmodified lines
7575 .window = ctx->vo->x11->window,
7676 };
7777
78− struct ra_vk_ctx_params params = {
78+ struct ra_ctx_params params = {
7979 .check_visible = xlib_check_visible,
8080 .swap_buffers = xlib_vk_swap_buffers,
8181 .get_vsync = xlib_vk_get_vsync,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t