vkr: add vkr_log

It automatically prefixes the message with "vkr: ".

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Acked-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 3 years ago
parent c61eb90392
commit ec5275adbf
  1. 39
      src/venus/vkr_common.c
  2. 3
      src/venus/vkr_common.h

@ -5,8 +5,47 @@
#include "vkr_common.h" #include "vkr_common.h"
#include <stdarg.h>
#include <stdio.h>
#include "vkr_cs.h" #include "vkr_cs.h"
void
vkr_log(const char *fmt, ...)
{
const char prefix[] = "vkr: ";
char line[1024];
size_t len;
va_list va;
int ret;
len = ARRAY_SIZE(prefix) - 1;
memcpy(line, prefix, len);
va_start(va, fmt);
ret = vsnprintf(line + len, ARRAY_SIZE(line) - len, fmt, va);
va_end(va);
if (ret < 0) {
const char log_error[] = "log error";
memcpy(line + len, log_error, ARRAY_SIZE(log_error) - 1);
len += ARRAY_SIZE(log_error) - 1;
} else if ((size_t)ret < ARRAY_SIZE(line) - len) {
len += ret;
} else {
len = ARRAY_SIZE(line) - 1;
}
/* make room for newline */
if (len + 1 >= ARRAY_SIZE(line))
len--;
line[len++] = '\n';
line[len] = '\0';
virgl_log(line);
}
void void
object_array_fini(struct object_array *arr) object_array_fini(struct object_array *arr)
{ {

@ -288,6 +288,9 @@ struct object_array {
extern uint32_t vkr_renderer_flags; extern uint32_t vkr_renderer_flags;
extern uint32_t vkr_debug_flags; extern uint32_t vkr_debug_flags;
void
vkr_log(const char *fmt, ...);
bool bool
object_array_init(struct object_array *arr, object_array_init(struct object_array *arr,
uint32_t count, uint32_t count,

Loading…
Cancel
Save