Commit 49a65490 authored by Niklas Haas's avatar Niklas Haas

context: add a way to update the context params

There's no reason the user shouldn't be allowed to change the log
parameters around later on.
parent 6ac417a8
Pipeline #4157 passed with stages
in 2 minutes and 3 seconds
......@@ -2,7 +2,7 @@ project('libplacebo', ['c', 'cpp'],
license: 'LGPL2.1+',
default_options: ['c_std=c99'],
meson_version: '>=0.47',
version: '1.16.0',
version: '1.17.0',
)
# Version number
......
......@@ -79,6 +79,12 @@ void pl_context_destroy(struct pl_context **ctx)
pthread_mutex_unlock(&pl_ctx_mutex);
}
void pl_context_update(struct pl_context *ctx,
const struct pl_context_params *params)
{
ctx->params = *PL_DEF(params, &pl_context_default_params);
}
static FILE *default_stream(void *stream, enum pl_log_level level)
{
return PL_DEF(stream, level <= PL_LOG_WARN ? stderr : stdout);
......
......@@ -58,7 +58,7 @@ struct pl_context_params {
// Creates a new, blank pl_context. The argument `api_ver` must be given as
// PL_API_VER (this is used to detect ABI mismatch due to broken linking).
// `params` defaults to `pl_context_default_params` if left as NULL.
// `params` defaults to `&pl_context_default_params` if left as NULL.
// Returns NULL on failure.
//
// Note: As a general rule, any `params` struct used as an argument to a
......@@ -78,6 +78,12 @@ extern const struct pl_context_params pl_context_default_params;
// on NULL itself is invalid.
void pl_context_destroy(struct pl_context **ctx);
// Update the parameters of a `pl_context` without destroying it. This can be
// used to change the log function, log context or log level retroactively.
// `params` defaults to `&pl_context_default_params` if left as NULL.
void pl_context_update(struct pl_context *ctx,
const struct pl_context_params *params);
// Two simple, stream-based loggers. You can use these as the log_cb. If you
// also set log_priv to a FILE* (e.g. stdout or stderr) it will be printed
// there; otherwise, it will be printed to stdout or stderr depending on the
......
......@@ -8,6 +8,7 @@ static int irand()
int main()
{
struct pl_context *ctx = pl_test_context();
pl_context_update(ctx, NULL);
pl_context_destroy(&ctx);
// Test some misc helper functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment