diff --git a/alloc.c b/alloc.c index 052837b..a5bf394 100644 --- a/alloc.c +++ b/alloc.c @@ -570,8 +570,8 @@ static void log_reuse(struct liftoff_output *output) static void log_no_reuse(struct liftoff_output *output) { - liftoff_log(LIFTOFF_DEBUG, - "\n== Apply request for output %"PRIu32" ==", output->crtc_id); + liftoff_log_formatted(LIFTOFF_DEBUG, LIFTOFF_LOG_SECTION_START, + "== Apply request for output %"PRIu32" ==", output->crtc_id); if (output->alloc_reused_counter != 0) { liftoff_log(LIFTOFF_DEBUG, @@ -619,7 +619,7 @@ static void log_planes(struct liftoff_device *device, } else { debug_cnt(device, ":"); } - debug_cnt(device, NULL); + debug_end(device, LIFTOFF_LOG_SECTION_START); liftoff_list_for_each(plane, &device->planes, link) { bool active = false; @@ -662,7 +662,7 @@ static void log_planes(struct liftoff_device *device, char *name; if (++per_line == max_per_line) { - debug_cnt(device, NULL); + debug_end(device, 0); debug_cnt(device, " "); per_line = 0; } @@ -694,7 +694,7 @@ static void log_planes(struct liftoff_device *device, } debug_cnt(device, " %s: %"PRIu64, name, value); } - debug_cnt(device, NULL); + debug_end(device, 0); } } @@ -704,7 +704,7 @@ static bool reset_planes(struct liftoff_device *device, drmModeAtomicReq *req) uint32_t debug_type = DRM_PLANE_TYPE_PRIMARY; bool compatible; - debug_cnt(device, "\nReset planes:"); + debug_cnt(device, "Reset planes:"); liftoff_list_for_each(plane, &device->planes, link) { if (plane->layer != NULL) { @@ -721,13 +721,14 @@ static bool reset_planes(struct liftoff_device *device, drmModeAtomicReq *req) if (!plane_apply(plane, NULL, req, &compatible)) { debug_cnt(device, "... Error resetting: %"PRIu32, plane->id); - debug_cnt(device, NULL); + debug_end(device, + LIFTOFF_LOG_SECTION_START | LIFTOFF_LOG_SECTION_END); return false; } assert(compatible); } - debug_cnt(device, NULL); + debug_end(device, LIFTOFF_LOG_SECTION_START | LIFTOFF_LOG_SECTION_END); return true; } @@ -806,7 +807,8 @@ bool liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req) "score=%d:", (void *)output, result.best_score); /* Apply the best allocation */ - liftoff_log(LIFTOFF_DEBUG, "\nFinal assignment of layers to planes:"); + liftoff_log_formatted(LIFTOFF_DEBUG, LIFTOFF_LOG_SECTION_START, + "Final assignment of layers to planes:"); i = j = 0; liftoff_list_for_each(plane, &device->planes, link) { layer = result.best[i]; diff --git a/include/libliftoff.h b/include/libliftoff.h index f3ec515..da6ee92 100644 --- a/include/libliftoff.h +++ b/include/libliftoff.h @@ -74,8 +74,15 @@ enum liftoff_log_importance { LIFTOFF_DEBUG, }; +enum liftoff_log_flags { + LIFTOFF_LOG_NO_FLAG = 0, + LIFTOFF_LOG_SECTION_START = 1, + LIFTOFF_LOG_SECTION_END = 2, +}; + typedef void (*liftoff_log_func)(enum liftoff_log_importance importance, - const char *fmt, va_list args); + enum liftoff_log_flags flags, + const char *fmt, va_list args); void liftoff_log_init(enum liftoff_log_importance verbosity, liftoff_log_func callback); diff --git a/include/log.h b/include/log.h index 21e93c3..646a99f 100644 --- a/include/log.h +++ b/include/log.h @@ -13,9 +13,13 @@ bool log_has(enum liftoff_log_importance verbosity); void liftoff_log(enum liftoff_log_importance verbosity, const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3); +void liftoff_log_formatted(enum liftoff_log_importance verbosity, + enum liftoff_log_flags flags, + const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(3, 4); void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg); void debug_cnt(struct liftoff_device *device, const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3); +void debug_end(struct liftoff_device *device, enum liftoff_log_flags flags); #endif diff --git a/log.c b/log.c index ce14044..bce64a6 100644 --- a/log.c +++ b/log.c @@ -7,11 +7,18 @@ static enum liftoff_log_importance log_importance = LIFTOFF_ERROR; -static void log_stderr(enum liftoff_log_importance verbosity, const char *fmt, - va_list args) +static void log_stderr(enum liftoff_log_importance verbosity, + enum liftoff_log_flags flags, + const char *fmt, va_list args) { + if (flags & LIFTOFF_LOG_SECTION_START) { + fprintf(stderr, "\n"); + } vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); + if (flags & LIFTOFF_LOG_SECTION_END) { + fprintf(stderr, "\n"); + } } static liftoff_log_func log_callback = log_stderr; @@ -39,7 +46,21 @@ 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, 0, fmt, args); + va_end(args); +} + +void liftoff_log_formatted(enum liftoff_log_importance verbosity, + enum liftoff_log_flags flags, + const char *fmt, ...) +{ + if (!log_has(verbosity)) { + return; + } + + va_list args; + va_start(args, fmt); + log_callback(verbosity, flags, fmt, args); va_end(args); } @@ -55,18 +76,6 @@ void debug_cnt(struct liftoff_device *device, const char *fmt, ...) return; } - if (fmt == NULL) { - if (device->log_buf == 0) { - return; - } - liftoff_log(LIFTOFF_DEBUG, "%s", device->log_buf); - free(device->log_buf); - device->log_buf = NULL; - device->log_buf_index = 0; - device->log_buf_len = 0; - return; - } - va_list args; va_start(args, fmt); @@ -112,3 +121,18 @@ cleanup_out: final_out: va_end(args); } + +void debug_end(struct liftoff_device *device, enum liftoff_log_flags flags) +{ + if (!log_has(LIFTOFF_DEBUG)) { + return; + } + if (device->log_buf == NULL) { + return; + } + liftoff_log_formatted(LIFTOFF_DEBUG, flags, "%s", device->log_buf); + free(device->log_buf); + device->log_buf = NULL; + device->log_buf_index = 0; + device->log_buf_len = 0; +} diff --git a/plane.c b/plane.c index 6511a1c..7f86d9d 100644 --- a/plane.c +++ b/plane.c @@ -48,21 +48,21 @@ static void log_plane(struct liftoff_device *device, } else { debug_cnt(device, "Overlay"); } - debug_cnt(device, NULL); + debug_end(device, 0); liftoff_log(LIFTOFF_DEBUG, " zpos: %"PRIu32, plane->zpos); debug_cnt(device, " props:"); for (i = 0; i < plane->props_len; i++) { if (per_line == 5) { - debug_cnt(device, NULL); + debug_end(device, 0); debug_cnt(device, " "); per_line = 0; } debug_cnt(device, " %s", plane->props[i].name); per_line++; } - debug_cnt(device, NULL); + debug_end(device, 0); } struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id) @@ -77,7 +77,7 @@ struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id) bool has_type = false, has_zpos = false; debug_cnt(device, "Plane %"PRIu32, id); - debug_cnt(device, NULL); + debug_end(device, 0); plane = calloc(1, sizeof(*plane)); if (plane == NULL) {