Exemple #1
0
static int validate_backend_opt(const m_option_t *opt, struct bstr name,
                                struct bstr param)
{
    char s[20];
    snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
    return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
}
Exemple #2
0
int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
                              struct bstr name, struct bstr param)
{
    if (bstr_equals0(param, "help")) {
        mp_info(log, "OpenGL windowing backends:\n");
        mp_info(log, "    auto (autodetect)\n");
        for (int n = 0; n < MP_ARRAY_SIZE(backends); n++)
            mp_info(log, "    %s\n", backends[n]->name);
        return M_OPT_EXIT;
    }
    char s[20];
    snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
    return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
}
Exemple #3
0
static MPGLContext *init_backend(struct vo *vo, const struct mpgl_driver *driver,
                                 bool probing, int vo_flags)
{
    MPGLContext *ctx = talloc_ptrtype(NULL, ctx);
    *ctx = (MPGLContext) {
        .gl = talloc_zero(ctx, GL),
        .vo = vo,
        .driver = driver,
    };
    if (probing)
        vo_flags |= VOFLAG_PROBING;
    bool old_probing = vo->probing;
    vo->probing = probing; // hack; kill it once backends are separate
    MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", ctx->driver->name);
    ctx->priv = talloc_zero_size(ctx, ctx->driver->priv_size);
    if (ctx->driver->init(ctx, vo_flags) < 0) {
        vo->probing = old_probing;
        talloc_free(ctx);
        return NULL;
    }
    vo->probing = old_probing;

    if (!ctx->gl->version && !ctx->gl->es)
        goto cleanup;

    if (probing && ctx->gl->es && (vo_flags & VOFLAG_NO_GLES)) {
        MP_VERBOSE(ctx->vo, "Skipping GLES backend.\n");
        goto cleanup;
    }

    if (ctx->gl->mpgl_caps & MPGL_CAP_SW) {
        MP_WARN(ctx->vo, "Suspected software renderer or indirect context.\n");
        if (vo->probing && !(vo_flags & VOFLAG_SW))
            goto cleanup;
    }

    ctx->gl->debug_context = !!(vo_flags & VOFLAG_GL_DEBUG);

    set_current_context(ctx);

    return ctx;

cleanup:
    mpgl_uninit(ctx);
    return NULL;
}

// Create a VO window and create a GL context on it.
//  vo_flags: passed to the backend's create window function
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
{
    MPGLContext *ctx = NULL;
    int index = mpgl_find_backend(backend_name);
    if (index == -1) {
        for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
            ctx = init_backend(vo, backends[n], true, vo_flags);
            if (ctx)
                break;
        }
        // VO forced, but no backend is ok => force the first that works at all
        if (!ctx && !vo->probing) {
            for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
                ctx = init_backend(vo, backends[n], false, vo_flags);
                if (ctx)
                    break;
            }
        }
    } else if (index >= 0) {
        ctx = init_backend(vo, backends[index], false, vo_flags);
    }
    return ctx;
}