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
62 void (*uninit)(struct ra_ctx *ctx);62 void (*uninit)(struct ra_ctx *ctx);
63};63};
64 64
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
70struct 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
65// Extra struct for the swapchain-related functions so they can be easily95// Extra struct for the swapchain-related functions so they can be easily
66// inherited from helpers.96// inherited from helpers.
67struct ra_swapchain {97struct ra_swapchain {
video/out/opengl/context.c+2−2
@@ -77,7 +77,7 @@ const struct m_sub_options opengl_conf = { · 76 unmodified lines
77struct priv {77struct priv {
78 GL *gl;78 GL *gl;
79 struct mp_log *log;79 struct mp_log *log;
80 struct ra_gl_ctx_params params;80 struct ra_ctx_params params;
81 struct opengl_opts *opts;81 struct opengl_opts *opts;
82 struct ra_swapchain_fns fns;82 struct ra_swapchain_fns fns;
83 GLuint main_fb;83 GLuint main_fb;
@@ -125,7 +125,7 @@ void ra_gl_ctx_uninit(struct ra_ctx *ctx) · 41 unmodified lines
125 125
126static const struct ra_swapchain_fns ra_gl_swapchain_fns;126static const struct ra_swapchain_fns ra_gl_swapchain_fns;
127 127
128bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_gl_ctx_params params)128bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_ctx_params params)
129{129{
130 struct ra_swapchain *sw = ctx->swapchain = talloc_ptrtype(NULL, sw);130 struct ra_swapchain *sw = ctx->swapchain = talloc_ptrtype(NULL, sw);
131 *sw = (struct ra_swapchain) {131 *sw = (struct ra_swapchain) {
video/out/opengl/context.h+1−28
@@ -14,35 +14,8 @@ enum gles_mode { · 13 unmodified lines
14// Returns the gles mode based on the --opengl opts.14// Returns the gles mode based on the --opengl opts.
15enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx);15enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx);
16 16
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
22struct 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
44void ra_gl_ctx_uninit(struct ra_ctx *ctx);17void ra_gl_ctx_uninit(struct ra_ctx *ctx);
45bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_gl_ctx_params params);18bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_ctx_params params);
46 19
47// Call this any time the window size or main framebuffer changes20// Call this any time the window size or main framebuffer changes
48void ra_gl_ctx_resize(struct ra_swapchain *sw, int w, int h, int fbo);21void 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
90 90
91 mpegl_load_functions(&p->gl, ctx->log);91 mpegl_load_functions(&p->gl, ctx->log);
92 92
93 struct ra_gl_ctx_params params = {93 struct ra_ctx_params params = {
94 .swap_buffers = android_swap_buffers,94 .swap_buffers = android_swap_buffers,
95 };95 };
96 96
video/out/opengl/context_angle.c+1−1
@@ -601,7 +601,7 @@ static bool angle_init(struct ra_ctx *ctx) · 600 unmodified lines
601 .color_depth = angle_color_depth,601 .color_depth = angle_color_depth,
602 .submit_frame = angle_submit_frame,602 .submit_frame = angle_submit_frame,
603 };603 };
604 struct ra_gl_ctx_params params = {604 struct ra_ctx_params params = {
605 .swap_buffers = angle_swap_buffers,605 .swap_buffers = angle_swap_buffers,
606 .external_swapchain = p->dxgi_swapchain ? &dxgi_swapchain_fns : NULL,606 .external_swapchain = p->dxgi_swapchain ? &dxgi_swapchain_fns : NULL,
607 };607 };
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
682 MP_VERBOSE(ctx, "Could not find path to render node.\n");682 MP_VERBOSE(ctx, "Could not find path to render node.\n");
683 }683 }
684 684
685 struct ra_gl_ctx_params params = {685 struct ra_ctx_params params = {
686 .external_swapchain = &drm_egl_swapchain,686 .external_swapchain = &drm_egl_swapchain,
687 .get_vsync = &drm_egl_get_vsync,687 .get_vsync = &drm_egl_get_vsync,
688 };688 };
video/out/opengl/context_dxinterop.c+1−1
@@ -548,7 +548,7 @@ static bool dxgl_init(struct ra_ctx *ctx) · 547 unmodified lines
548 goto fail;548 goto fail;
549 549
550 static const struct ra_swapchain_fns empty_swapchain_fns = {0};550 static const struct ra_swapchain_fns empty_swapchain_fns = {0};
551 struct ra_gl_ctx_params params = {551 struct ra_ctx_params params = {
552 .swap_buffers = dxgl_swap_buffers,552 .swap_buffers = dxgl_swap_buffers,
553 .external_swapchain = &empty_swapchain_fns,553 .external_swapchain = &empty_swapchain_fns,
554 };554 };
video/out/opengl/context_glx.c+1−1
@@ -290,7 +290,7 @@ static bool glx_init(struct ra_ctx *ctx) · 289 unmodified lines
290 if (!success)290 if (!success)
291 goto uninit;291 goto uninit;
292 292
293 struct ra_gl_ctx_params params = {293 struct ra_ctx_params params = {
294 .check_visible = glx_check_visible,294 .check_visible = glx_check_visible,
295 .swap_buffers = glx_swap_buffers,295 .swap_buffers = glx_swap_buffers,
296 .get_vsync = glx_get_vsync,296 .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
104 104
105 mpegl_load_functions(&p->gl, wl->log);105 mpegl_load_functions(&p->gl, wl->log);
106 106
107 struct ra_gl_ctx_params params = {107 struct ra_ctx_params params = {
108 .check_visible = wayland_egl_check_visible,108 .check_visible = wayland_egl_check_visible,
109 .swap_buffers = wayland_egl_swap_buffers,109 .swap_buffers = wayland_egl_swap_buffers,
110 .get_vsync = wayland_egl_get_vsync,110 .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
312 gl->SwapInterval = wgl_swap_interval;312 gl->SwapInterval = wgl_swap_interval;
313 p->current_swapinterval = -1;313 p->current_swapinterval = -1;
314 314
315 struct ra_gl_ctx_params params = {315 struct ra_ctx_params params = {
316 .swap_buffers = wgl_swap_buffers,316 .swap_buffers = wgl_swap_buffers,
317 };317 };
318 318
video/out/opengl/context_x11egl.c+1−1
@@ -163,7 +163,7 @@ static bool mpegl_init(struct ra_ctx *ctx) · 162 unmodified lines
163 163
164 mpegl_load_functions(&p->gl, ctx->log);164 mpegl_load_functions(&p->gl, ctx->log);
165 165
166 struct ra_gl_ctx_params params = {166 struct ra_ctx_params params = {
167 .check_visible = mpegl_check_visible,167 .check_visible = mpegl_check_visible,
168 .swap_buffers = mpegl_swap_buffers,168 .swap_buffers = mpegl_swap_buffers,
169 .get_vsync = mpegl_get_vsync,169 .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
40 };40 };
41 41
42 static const struct ra_swapchain_fns empty_swapchain_fns = {0};42 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 = {
44 // vo_libmpv is essentially like a gigantic external swapchain where44 // vo_libmpv is essentially like a gigantic external swapchain where
45 // the user is in charge of presentation / swapping etc. But we don't45 // the user is in charge of presentation / swapping etc. But we don't
46 // actually need to provide any of these functions, since we can just46 // 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
134struct priv {134struct priv {
135 struct mpvk_ctx *vk;135 struct mpvk_ctx *vk;
136 struct vulkan_opts *opts;136 struct vulkan_opts *opts;
137 struct ra_vk_ctx_params params;137 struct ra_ctx_params params;
138 struct ra_tex proxy_tex;138 struct ra_tex proxy_tex;
139};139};
140 140
@@ -249,7 +249,7 @@ pl_vulkan mppl_create_vulkan(struct vulkan_opts *opts, · 108 unmodified lines
249}249}
250 250
251bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk,251bool 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,
253 VkPresentModeKHR preferred_mode)253 VkPresentModeKHR preferred_mode)
254{254{
255 struct ra_swapchain *sw = ctx->swapchain = talloc_zero(NULL, struct ra_swapchain);255 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
3#include "video/out/gpu/context.h"3#include "video/out/gpu/context.h"
4#include "common.h"4#include "common.h"
5 5
6struct 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
21// Helpers for ra_ctx based on ra_vk. These initialize ctx->ra and ctx->swchain.6// Helpers for ra_ctx based on ra_vk. These initialize ctx->ra and ctx->swchain.
22void ra_vk_ctx_uninit(struct ra_ctx *ctx);7void ra_vk_ctx_uninit(struct ra_ctx *ctx);
23bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk,8bool 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,
25 VkPresentModeKHR preferred_mode);10 VkPresentModeKHR preferred_mode);
26 11
27// Helper for initializing mpvk_ctx->vulkan12// 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
53 .window = vo_android_native_window(ctx->vo)53 .window = vo_android_native_window(ctx->vo)
54 };54 };
55 55
56 struct ra_vk_ctx_params params = {0};56 struct ra_ctx_params params = {0};
57 57
58 VkInstance inst = vk->vkinst->instance;58 VkInstance inst = vk->vkinst->instance;
59 VkResult res = vkCreateAndroidSurfaceKHR(inst, &info, NULL, &vk->surface);59 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
441 p->height = mode->parameters.visibleRegion.height;441 p->height = mode->parameters.visibleRegion.height;
442 p->refresh_rate = mode->parameters.refreshRate;442 p->refresh_rate = mode->parameters.refreshRate;
443 443
444 struct ra_vk_ctx_params params = {0};444 struct ra_ctx_params params = {0};
445 if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_FIFO_KHR))445 if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_FIFO_KHR))
446 goto error;446 goto error;
447 447
video/out/vulkan/context_mac.m+1−1
@@ -80,7 +80,7 @@ static bool mac_vk_init(struct ra_ctx *ctx) · 79 unmodified lines
80 .pLayer = p->vo_mac.layer,80 .pLayer = p->vo_mac.layer,
81 };81 };
82 82
83 struct ra_vk_ctx_params params = {83 struct ra_ctx_params params = {
84 .swap_buffers = mac_vk_swap_buffers,84 .swap_buffers = mac_vk_swap_buffers,
85 .get_vsync = mac_vk_get_vsync,85 .get_vsync = mac_vk_get_vsync,
86 .color_depth = mac_vk_color_depth,86 .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
79 .surface = ctx->vo->wl->surface,79 .surface = ctx->vo->wl->surface,
80 };80 };
81 81
82 struct ra_vk_ctx_params params = {82 struct ra_ctx_params params = {
83 .check_visible = wayland_vk_check_visible,83 .check_visible = wayland_vk_check_visible,
84 .swap_buffers = wayland_vk_swap_buffers,84 .swap_buffers = wayland_vk_swap_buffers,
85 .get_vsync = wayland_vk_get_vsync,85 .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
59 .hwnd = vo_w32_hwnd(ctx->vo),59 .hwnd = vo_w32_hwnd(ctx->vo),
60 };60 };
61 61
62 struct ra_vk_ctx_params params = {0};62 struct ra_ctx_params params = {0};
63 63
64 VkInstance inst = vk->vkinst->instance;64 VkInstance inst = vk->vkinst->instance;
65 VkResult res = vkCreateWin32SurfaceKHR(inst, &wininfo, NULL, &vk->surface);65 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
75 .window = ctx->vo->x11->window,75 .window = ctx->vo->x11->window,
76 };76 };
77 77
78 struct ra_vk_ctx_params params = {78 struct ra_ctx_params params = {
79 .check_visible = xlib_check_visible,79 .check_visible = xlib_check_visible,
80 .swap_buffers = xlib_vk_swap_buffers,80 .swap_buffers = xlib_vk_swap_buffers,
81 .get_vsync = xlib_vk_get_vsync,81 .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