File: context.h

package info (click to toggle)
mpv 0.41.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,404 kB
  • sloc: ansic: 155,875; python: 1,235; sh: 643; javascript: 612; cpp: 468; objc: 302; pascal: 49; xml: 29; makefile: 18
file content (144 lines) | stat: -rw-r--r-- 5,325 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once

#include <libplacebo/colorspace.h>

#include "video/out/vo.h"
#include "video/csputils.h"

#include "ra.h"

struct ra_ctx_opts {
    bool allow_sw;        // allow software renderers
    bool want_alpha;      // create an alpha framebuffer if possible
    bool debug;           // enable debugging layers/callbacks etc.
    bool probing;        // the backend was auto-probed
    bool composition;    // enable swapchain composition
    struct m_obj_settings *context_list; // list of `ra_ctx_fns.name` to probe
    struct m_obj_settings *context_type_list;  // list of `ra_ctx_fns.type` to probe
};

extern const struct m_sub_options ra_ctx_conf;

struct ra_ctx {
    struct vo *vo;
    struct ra *ra;
    struct mpv_global *global;
    struct mp_log *log;

    struct ra_ctx_opts opts;
    const struct ra_ctx_fns *fns;
    struct ra_swapchain *swapchain;
    struct spirv_compiler *spirv;

    void *priv;
};

// The functions that make up a ra_ctx.
struct ra_ctx_fns {
    const char *type; // API type (for --gpu-api)
    const char *name; // name (for --gpu-context)
    const char *description; // description (for --gpu-context=help)

    // Resize the window, or create a new window if there isn't one yet.
    // Currently, there is an unfortunate interaction with ctx->vo, and
    // display size etc. are determined by it.
    bool (*reconfig)(struct ra_ctx *ctx);

    // Signal if the underlying context can use colorspace/hdr related functionality
    // on its own.
    bool (*pass_colorspace)(struct ra_ctx *ctx);

    // This behaves exactly like vo_driver.control().
    int (*control)(struct ra_ctx *ctx, int *events, int request, void *arg);

    // These behave exactly like vo_driver.wakeup/wait_events. They are
    // optional.
    void (*wakeup)(struct ra_ctx *ctx);
    void (*wait_events)(struct ra_ctx *ctx, int64_t until_time_ns);
    void (*update_render_opts)(struct ra_ctx *ctx);

    // Initialize/destroy the 'struct ra' and possibly the underlying VO backend.
    // Not normally called by the user of the ra_ctx.
    bool (*init)(struct ra_ctx *ctx);
    void (*uninit)(struct ra_ctx *ctx);
};

typedef struct pl_color_space pl_color_space_t;

// These are a set of helpers for ra_ctx providers based on ra_gl.
// The init function also initializes ctx->ra and ctx->swapchain, so the user
// doesn't have to do this manually. (Similarly, the uninit function will
// clean them up)

struct ra_ctx_params {
    // For special contexts (i.e. wayland) that want to check visibility
    // before drawing a frame.
    bool (*check_visible)(struct ra_ctx *ctx);

    // See ra_swapchain_fns.color_depth.
    int (*color_depth)(struct ra_ctx *ctx);

    // Preferred device color space. Optional.
    pl_color_space_t (*preferred_csp)(struct ra_ctx *ctx);

    // See ra_swapchain_fns.get_vsync.
    void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info);

    // Set to the platform-specific function to swap buffers, like
    // glXSwapBuffers, eglSwapBuffers etc. This will be called by
    // ra_gl_ctx_swap_buffers. Required unless you either never call that
    // function or if you override it yourself.
    void (*swap_buffers)(struct ra_ctx *ctx);
};

// Extra struct for the swapchain-related functions so they can be easily
// inherited from helpers.
struct ra_swapchain {
    struct ra_ctx *ctx;
    struct priv *priv;
    const struct ra_swapchain_fns *fns;
};

// Represents a framebuffer / render target
struct ra_fbo {
    struct ra_tex *tex;
    bool flip; // rendering needs to be inverted

    // Host system's colorspace that it will be interpreting
    // the frame buffer as.
    struct pl_color_space color_space;
};

struct ra_swapchain_fns {
    // Gets the current framebuffer depth in bits (0 if unknown). Optional.
    int (*color_depth)(struct ra_swapchain *sw);

    // Target device color space. Optional.
    pl_color_space_t (*target_csp)(struct ra_swapchain *sw);

    // Called when rendering starts. Returns NULL on failure. This must be
    // followed by submit_frame, to submit the rendered frame. This function
    // can also fail sporadically, and such errors should be ignored unless
    // they persist.
    bool (*start_frame)(struct ra_swapchain *sw, struct ra_fbo *out_fbo);

    // Present the frame. Issued in lockstep with start_frame, with rendering
    // commands in between. The `frame` is just there for timing data, for
    // swapchains smart enough to do something with it.
    bool (*submit_frame)(struct ra_swapchain *sw, const struct vo_frame *frame);

    // Performs a buffer swap. This blocks for as long as necessary to meet
    // params.swapchain_depth, or until the next vblank (for vsynced contexts)
    void (*swap_buffers)(struct ra_swapchain *sw);

    // See vo. Usually called after swap_buffers().
    void (*get_vsync)(struct ra_swapchain *sw, struct vo_vsync_info *info);
};

// Create and destroy a ra_ctx. This also takes care of creating and destroying
// the underlying `struct ra`, and perhaps the underlying VO backend.
struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts);
void ra_ctx_destroy(struct ra_ctx **ctx);

// Special case of creating a ra_ctx while specifying a specific context by name.
struct ra_ctx *ra_ctx_create_by_name(struct vo *vo, const char *name);