1 /*
2  * This file is part of mpv.
3  *
4  * mpv is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * mpv is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MP_GL_VIDEO_H
19 #define MP_GL_VIDEO_H
20 
21 #include <stdbool.h>
22 
23 #include "options/m_option.h"
24 #include "sub/osd.h"
25 #include "utils.h"
26 #include "lcms.h"
27 #include "shader_cache.h"
28 #include "video/csputils.h"
29 #include "video/out/filter_kernels.h"
30 
31 struct scaler_fun {
32     char *name;
33     float params[2];
34     float blur;
35     float taper;
36 };
37 
38 struct scaler_config {
39     struct scaler_fun kernel;
40     struct scaler_fun window;
41     float radius;
42     float antiring;
43     float cutoff;
44     float clamp;
45 };
46 
47 struct scaler {
48     int index;
49     struct scaler_config conf;
50     double scale_factor;
51     bool initialized;
52     struct filter_kernel *kernel;
53     struct ra_tex *lut;
54     struct ra_tex *sep_fbo;
55     bool insufficient;
56     int lut_size;
57 
58     // kernel points here
59     struct filter_kernel kernel_storage;
60 };
61 
62 enum scaler_unit {
63     SCALER_SCALE,  // luma/video
64     SCALER_DSCALE, // luma-video downscaling
65     SCALER_CSCALE, // chroma upscaling
66     SCALER_TSCALE, // temporal scaling (interpolation)
67     SCALER_COUNT
68 };
69 
70 enum dither_algo {
71     DITHER_NONE = 0,
72     DITHER_FRUIT,
73     DITHER_ORDERED,
74     DITHER_ERROR_DIFFUSION,
75 };
76 
77 enum alpha_mode {
78     ALPHA_NO = 0,
79     ALPHA_YES,
80     ALPHA_BLEND,
81     ALPHA_BLEND_TILES,
82 };
83 
84 enum blend_subs_mode {
85     BLEND_SUBS_NO = 0,
86     BLEND_SUBS_YES,
87     BLEND_SUBS_VIDEO,
88 };
89 
90 enum tone_mapping {
91     TONE_MAPPING_CLIP,
92     TONE_MAPPING_MOBIUS,
93     TONE_MAPPING_REINHARD,
94     TONE_MAPPING_HABLE,
95     TONE_MAPPING_GAMMA,
96     TONE_MAPPING_LINEAR,
97     TONE_MAPPING_BT_2390,
98 };
99 
100 struct gl_tone_map_opts {
101     int curve;
102     float curve_param;
103     float max_boost;
104     int compute_peak;
105     float decay_rate;
106     float scene_threshold_low;
107     float scene_threshold_high;
108     float desat;
109     float desat_exp;
110     int gamut_warning; // bool
111     int gamut_clipping; // bool
112 };
113 
114 struct gl_video_opts {
115     int dumb_mode;
116     struct scaler_config scaler[4];
117     int scaler_lut_size;
118     float gamma;
119     int gamma_auto;
120     int target_prim;
121     int target_trc;
122     int target_peak;
123     struct gl_tone_map_opts tone_map;
124     int correct_downscaling;
125     int linear_downscaling;
126     int linear_upscaling;
127     int sigmoid_upscaling;
128     float sigmoid_center;
129     float sigmoid_slope;
130     int scaler_resizes_only;
131     int pbo;
132     int dither_depth;
133     int dither_algo;
134     int dither_size;
135     int temporal_dither;
136     int temporal_dither_period;
137     char *error_diffusion;
138     char *fbo_format;
139     int alpha_mode;
140     int use_rectangle;
141     struct m_color background;
142     int interpolation;
143     float interpolation_threshold;
144     int blend_subs;
145     char **user_shaders;
146     int deband;
147     struct deband_opts *deband_opts;
148     float unsharp;
149     int tex_pad_x, tex_pad_y;
150     struct mp_icc_opts *icc_opts;
151     int early_flush;
152     char *shader_cache_dir;
153     char *hwdec_interop;
154 };
155 
156 extern const struct m_sub_options gl_video_conf;
157 
158 struct gl_video;
159 struct vo_frame;
160 struct voctrl_screenshot;
161 
162 enum {
163     RENDER_FRAME_SUBS = 1 << 0,
164     RENDER_FRAME_OSD = 1 << 1,
165     RENDER_FRAME_VF_SUBS = 1 << 2,
166     RENDER_FRAME_DEF = RENDER_FRAME_SUBS | RENDER_FRAME_OSD,
167 };
168 
169 struct gl_video *gl_video_init(struct ra *ra, struct mp_log *log,
170                                struct mpv_global *g);
171 void gl_video_uninit(struct gl_video *p);
172 void gl_video_set_osd_source(struct gl_video *p, struct osd_state *osd);
173 bool gl_video_check_format(struct gl_video *p, int mp_format);
174 void gl_video_config(struct gl_video *p, struct mp_image_params *params);
175 void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
176                            struct ra_fbo fbo, int flags);
177 void gl_video_resize(struct gl_video *p,
178                      struct mp_rect *src, struct mp_rect *dst,
179                      struct mp_osd_res *osd);
180 void gl_video_set_fb_depth(struct gl_video *p, int fb_depth);
181 void gl_video_perfdata(struct gl_video *p, struct voctrl_performance_data *out);
182 void gl_video_set_clear_color(struct gl_video *p, struct m_color color);
183 void gl_video_set_osd_pts(struct gl_video *p, double pts);
184 bool gl_video_check_osd_change(struct gl_video *p, struct mp_osd_res *osd,
185                                double pts);
186 
187 void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
188                          struct voctrl_screenshot *args);
189 
190 float gl_video_scale_ambient_lux(float lmin, float lmax,
191                                  float rmin, float rmax, float lux);
192 void gl_video_set_ambient_lux(struct gl_video *p, int lux);
193 void gl_video_set_icc_profile(struct gl_video *p, bstr icc_data);
194 bool gl_video_icc_auto_enabled(struct gl_video *p);
195 bool gl_video_gamma_auto_enabled(struct gl_video *p);
196 struct mp_colorspace gl_video_get_output_colorspace(struct gl_video *p);
197 
198 void gl_video_reset(struct gl_video *p);
199 bool gl_video_showing_interpolated_frame(struct gl_video *p);
200 
201 struct mp_hwdec_devices;
202 void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
203                           bool load_all_by_default);
204 void gl_video_load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs);
205 
206 struct vo;
207 void gl_video_configure_queue(struct gl_video *p, struct vo *vo);
208 
209 struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h,
210                                     int stride_align);
211 
212 
213 #endif
214