0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

vo_opengl: refactor how framebuffer depth is passed from backends

Store the determined framebuffer depth in struct GL instead of
MPGLContext. This means gl_video_set_output_depth() can be removed, and
also justifies adding new fields describing framebuffer/backend
properties to struct GL instead of having to add more functions just to
shovel the information around.

Keep in mind that mpgl_load_functions() will wipe struct GL, so the
new fields must be set before calling it.
This commit is contained in:
wm4 2015-12-19 11:56:19 +01:00
parent d2baaaa7df
commit 3394d37b4e
7 changed files with 22 additions and 30 deletions

View File

@ -127,8 +127,8 @@ static bool create_gl_context(struct MPGLContext *ctx, int vo_flags)
if (vo_flags & VOFLAG_ALPHA)
CGLSetParameter(p->ctx, kCGLCPSurfaceOpacity, &(GLint){0});
ctx->depth_r = ctx->depth_g = ctx->depth_b = cgl_color_size(ctx);
mpgl_load_functions(ctx->gl, (void *)cocoa_glgetaddr, NULL, ctx->vo->log);
ctx->gl->fb_r = ctx->gl->fb_g = ctx->gl->fb_b = cgl_color_size(ctx);
CGLReleasePixelFormat(p->pix);

View File

@ -119,9 +119,6 @@ typedef struct MPGLContext {
struct vo *vo;
const struct mpgl_driver *driver;
// Bit size of each component in the created framebuffer. 0 if unknown.
int depth_r, depth_g, depth_b;
// For hwdec_vaegl.c.
const char *native_display_type;
void *native_display;
@ -164,6 +161,7 @@ struct GL {
char *extensions; // Equivalent to GL_EXTENSIONS
int mpgl_caps; // Bitfield of MPGL_CAP_* constants
bool debug_context; // use of e.g. GLX_CONTEXT_DEBUG_BIT_ARB
int fb_r, fb_g, fb_b; // frame buffer bit depth (0 if unknown)
void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei);
void (GLAPIENTRY *Clear)(GLbitfield);

View File

@ -275,17 +275,17 @@ static int d3d_size_dependent_create(MPGLContext *ctx)
// work is needed.
switch (bb_desc.Format) {
case D3DFMT_X1R5G5B5: case D3DFMT_A1R5G5B5:
ctx->depth_r = ctx->depth_g = ctx->depth_b = 5;
ctx->gl->fb_r = ctx->gl->fb_g = ctx->gl->fb_b = 5;
break;
case D3DFMT_R5G6B5:
ctx->depth_r = 5; ctx->depth_g = 6; ctx->depth_b = 5;
ctx->gl->fb_r = 5; ctx->gl->fb_g = 6; ctx->gl->fb_b = 5;
break;
case D3DFMT_R8G8B8: case D3DFMT_A8R8G8B8: case D3DFMT_X8R8G8B8:
case D3DFMT_A8B8G8R8: case D3DFMT_X8B8G8R8: default:
ctx->depth_r = ctx->depth_g = ctx->depth_b = 8;
ctx->gl->fb_r = ctx->gl->fb_g = ctx->gl->fb_b = 8;
break;
case D3DFMT_A2R10G10B10: case D3DFMT_A2B10G10R10:
ctx->depth_r = ctx->depth_g = ctx->depth_b = 10;
ctx->gl->fb_r = ctx->gl->fb_g = ctx->gl->fb_b = 10;
break;
}

View File

@ -137,7 +137,6 @@ struct gl_video {
struct gl_video_opts opts;
bool gl_debug;
int depth_g;
int texture_16bit_depth; // actual bits available in 16 bit textures
struct gl_shader_cache *sc;
@ -1703,7 +1702,7 @@ static void pass_dither(struct gl_video *p)
GL *gl = p->gl;
// Assume 8 bits per component if unknown.
int dst_depth = p->depth_g ? p->depth_g : 8;
int dst_depth = gl->fb_g ? gl->fb_g : 8;
if (p->opts.dither_depth > 0)
dst_depth = p->opts.dither_depth;
@ -2508,6 +2507,9 @@ static void init_gl(struct gl_video *p)
debug_check_gl(p, "before init_gl");
MP_VERBOSE(p, "Reported display depth: R=%d, G=%d, B=%d\n",
gl->fb_r, gl->fb_g, gl->fb_b);
gl->Disable(GL_DITHER);
gl_vao_init(&p->vao, gl, sizeof(struct vertex), vertex_vao);
@ -2744,12 +2746,6 @@ void gl_video_config(struct gl_video *p, struct mp_image_params *params)
gl_video_reset_surfaces(p);
}
void gl_video_set_output_depth(struct gl_video *p, int r, int g, int b)
{
MP_VERBOSE(p, "Display depth: R=%d, G=%d, B=%d\n", r, g, b);
p->depth_g = g;
}
void gl_video_set_osd_source(struct gl_video *p, struct osd_state *osd)
{
mpgl_osd_destroy(p->osd);

View File

@ -80,13 +80,6 @@ static bool create_dc(struct MPGLContext *ctx, int flags)
SetPixelFormat(hdc, pf, &pfd);
int pfmt = GetPixelFormat(hdc);
if (DescribePixelFormat(hdc, pfmt, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) {
ctx->depth_r = pfd.cRedBits;
ctx->depth_g = pfd.cGreenBits;
ctx->depth_b = pfd.cBlueBits;
}
w32_ctx->hdc = hdc;
return true;
}
@ -221,6 +214,14 @@ static void create_ctx(void *ptr)
if (!w32_ctx->context)
create_context_w32_old(ctx);
int pfmt = GetPixelFormat(w32_ctx->hdc);
PIXELFORMATDESCRIPTOR pfd;
if (DescribePixelFormat(w32_ctx->hdc, pfmt, sizeof(pfd), &pfd)) {
ctx->gl->fb_r = pfd.cRedBits;
ctx->gl->fb_g = pfd.cGreenBits;
ctx->gl->fb_b = pfd.cBlueBits;
}
wglMakeCurrent(w32_ctx->hdc, NULL);
}

View File

@ -253,11 +253,6 @@ static int glx_init(struct MPGLContext *ctx, int flags)
MP_WARN(vo, "Selected GLX FB config has no associated X visual\n");
}
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_RED_SIZE, &ctx->depth_r);
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_GREEN_SIZE, &ctx->depth_g);
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_BLUE_SIZE, &ctx->depth_b);
if (!vo_x11_create_vo_window(vo, glx_ctx->vinfo, "gl"))
goto uninit;
@ -274,6 +269,10 @@ static int glx_init(struct MPGLContext *ctx, int flags)
if (!success)
goto uninit;
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_RED_SIZE, &ctx->gl->fb_r);
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_GREEN_SIZE, &ctx->gl->fb_g);
glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_BLUE_SIZE, &ctx->gl->fb_b);
return 0;
uninit:

View File

@ -423,8 +423,6 @@ static int preinit(struct vo *vo)
if (!p->renderer)
goto err_out;
gl_video_set_osd_source(p->renderer, vo->osd);
gl_video_set_output_depth(p->renderer, p->glctx->depth_r, p->glctx->depth_g,
p->glctx->depth_b);
gl_video_set_options(p->renderer, p->renderer_opts);
gl_video_configure_queue(p->renderer, vo);