Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
feat: log disabling planes without line breaks
Browse files Browse the repository at this point in the history
Enumerating all planes to be disabled makes the log unnecessary
sparse. Instead just list all planes in a single line.

For that introduce new API function to log something without line
break in the end and adapt the log callback function pointer.

BREAKING CHANGE: log callback function arguments change.
  • Loading branch information
romangg committed Feb 26, 2020
1 parent fbcbbba commit d99499e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,17 @@ bool liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req)

/* Disable all planes. Do it before building mappings to make sure not
to hit bandwidth limits because too many planes are enabled. */
liftoff_log_cnt(LIFTOFF_DEBUG, "Disabling planes:");
liftoff_list_for_each(plane, &device->planes, link) {
if (plane->layer == NULL) {
liftoff_log(LIFTOFF_DEBUG,
"Disabling plane %"PRIu32, plane->id);
liftoff_log_cnt(LIFTOFF_DEBUG, " %"PRIu32, plane->id);
if (!plane_apply(plane, NULL, req, &compatible)) {
return false;
}
assert(compatible);
}
}
liftoff_log(LIFTOFF_DEBUG, "");

result.req = req;
result.planes_len = liftoff_list_length(&device->planes);
Expand Down
2 changes: 1 addition & 1 deletion include/libliftoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ enum liftoff_log_importance {
LIFTOFF_DEBUG,
};

typedef void (*liftoff_log_func)(enum liftoff_log_importance importance,
typedef void (*liftoff_log_func)(enum liftoff_log_importance importance, bool newline,
const char *fmt, va_list args);

void liftoff_log_init(enum liftoff_log_importance verbosity,
Expand Down
2 changes: 2 additions & 0 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

void liftoff_log(enum liftoff_log_importance verbosity,
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3);
void liftoff_log_cnt(enum liftoff_log_importance verbosity,
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3);
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg);

#endif
20 changes: 17 additions & 3 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

static enum liftoff_log_importance log_importance = LIFTOFF_ERROR;

static void log_stderr(enum liftoff_log_importance verbosity, const char *fmt,
static void log_stderr(enum liftoff_log_importance verbosity, bool newline, const char *fmt,
va_list args)
{
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
if (newline) {
fprintf(stderr, "\n");
}
}

static liftoff_log_func log_callback = log_stderr;
Expand Down Expand Up @@ -37,7 +39,19 @@ void liftoff_log(enum liftoff_log_importance verbosity, const char *fmt, ...)

va_list args;
va_start(args, fmt);
log_callback(verbosity, fmt, args);
log_callback(verbosity, true, fmt, args);
va_end(args);
}

void liftoff_log_cnt(enum liftoff_log_importance verbosity, const char *fmt, ...)
{
if (!log_has(verbosity)) {
return;
}

va_list args;
va_start(args, fmt);
log_callback(verbosity, false, fmt, args);
va_end(args);
}

Expand Down

0 comments on commit d99499e

Please sign in to comment.