Add a stride parameter to nvnc_fb
parent
4594517571
commit
c7dd062498
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -55,6 +55,7 @@ static int run_benchmark(const char *image)
|
||||||
void *addr = nvnc_fb_get_addr(fb);
|
void *addr = nvnc_fb_get_addr(fb);
|
||||||
int width = nvnc_fb_get_width(fb);
|
int width = nvnc_fb_get_width(fb);
|
||||||
int height = nvnc_fb_get_height(fb);
|
int height = nvnc_fb_get_height(fb);
|
||||||
|
int stride = nvnc_fb_get_stride(fb);
|
||||||
|
|
||||||
struct rfb_pixel_format pixfmt;
|
struct rfb_pixel_format pixfmt;
|
||||||
rfb_pixfmt_from_fourcc(&pixfmt, DRM_FORMAT_ARGB8888);
|
rfb_pixfmt_from_fourcc(&pixfmt, DRM_FORMAT_ARGB8888);
|
||||||
|
@ -65,7 +66,7 @@ static int run_benchmark(const char *image)
|
||||||
pixman_region_union_rect(®ion, ®ion, 0, 0, width, height);
|
pixman_region_union_rect(®ion, ®ion, 0, 0, width, height);
|
||||||
|
|
||||||
struct vec frame;
|
struct vec frame;
|
||||||
vec_init(&frame, width * height * 3 / 2);
|
vec_init(&frame, stride * height * 3 / 2);
|
||||||
|
|
||||||
z_stream zs = { 0 };
|
z_stream zs = { 0 };
|
||||||
|
|
||||||
|
@ -75,13 +76,13 @@ static int run_benchmark(const char *image)
|
||||||
/* mem level: */ 9,
|
/* mem level: */ 9,
|
||||||
/* strategy: */ Z_DEFAULT_STRATEGY);
|
/* strategy: */ Z_DEFAULT_STRATEGY);
|
||||||
|
|
||||||
void *dummy = malloc(width * height * 4);
|
void *dummy = malloc(stride * height * 4);
|
||||||
if (!dummy)
|
if (!dummy)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
uint64_t start_time = gettime_us(CLOCK_PROCESS_CPUTIME_ID);
|
uint64_t start_time = gettime_us(CLOCK_PROCESS_CPUTIME_ID);
|
||||||
|
|
||||||
memcpy_unoptimized(dummy, addr, width * height * 4);
|
memcpy_unoptimized(dummy, addr, stride * height * 4);
|
||||||
|
|
||||||
uint64_t end_time = gettime_us(CLOCK_PROCESS_CPUTIME_ID);
|
uint64_t end_time = gettime_us(CLOCK_PROCESS_CPUTIME_ID);
|
||||||
printf("memcpy baseline for %s took %"PRIu64" micro seconds\n", image,
|
printf("memcpy baseline for %s took %"PRIu64" micro seconds\n", image,
|
||||||
|
@ -96,7 +97,7 @@ static int run_benchmark(const char *image)
|
||||||
printf("Encoding %s took %"PRIu64" micro seconds\n", image,
|
printf("Encoding %s took %"PRIu64" micro seconds\n", image,
|
||||||
end_time - start_time);
|
end_time - start_time);
|
||||||
|
|
||||||
double orig_size = width * height * 4;
|
double orig_size = stride * height * 4;
|
||||||
double compressed_size = frame.len;
|
double compressed_size = frame.len;
|
||||||
|
|
||||||
double reduction = (orig_size - compressed_size) / orig_size;
|
double reduction = (orig_size - compressed_size) / orig_size;
|
||||||
|
|
|
@ -213,7 +213,8 @@ int main(int argc, char* argv[])
|
||||||
draw.width * 4);
|
draw.width * 4);
|
||||||
assert(draw.whiteboard);
|
assert(draw.whiteboard);
|
||||||
|
|
||||||
draw.fb_pool = nvnc_fb_pool_new(draw.width, draw.height, draw.format);
|
draw.fb_pool = nvnc_fb_pool_new(draw.width, draw.height, draw.format,
|
||||||
|
draw.width);
|
||||||
assert(draw.fb_pool);
|
assert(draw.fb_pool);
|
||||||
|
|
||||||
struct nvnc* server = nvnc_open("127.0.0.1", 5900);
|
struct nvnc* server = nvnc_open("127.0.0.1", 5900);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -34,6 +34,7 @@ struct nvnc_fb {
|
||||||
size_t size;
|
size_t size;
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
|
int32_t stride;
|
||||||
uint32_t fourcc_format;
|
uint32_t fourcc_format;
|
||||||
uint64_t fourcc_modifier;
|
uint64_t fourcc_modifier;
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,7 +82,7 @@ int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
|
||||||
const char* cert_path, nvnc_auth_fn, void* userdata);
|
const char* cert_path, nvnc_auth_fn, void* userdata);
|
||||||
|
|
||||||
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format);
|
uint32_t fourcc_format, uint16_t stride);
|
||||||
|
|
||||||
void nvnc_fb_ref(struct nvnc_fb* fb);
|
void nvnc_fb_ref(struct nvnc_fb* fb);
|
||||||
void nvnc_fb_unref(struct nvnc_fb* fb);
|
void nvnc_fb_unref(struct nvnc_fb* fb);
|
||||||
|
@ -96,11 +96,12 @@ void* nvnc_fb_get_addr(const struct nvnc_fb* fb);
|
||||||
uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb);
|
uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb);
|
||||||
uint16_t nvnc_fb_get_height(const struct nvnc_fb* fb);
|
uint16_t nvnc_fb_get_height(const struct nvnc_fb* fb);
|
||||||
uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb);
|
uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb);
|
||||||
|
int32_t nvnc_fb_get_stride(const struct nvnc_fb* fb);
|
||||||
|
|
||||||
struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format);
|
uint32_t fourcc_format, uint16_t stride);
|
||||||
bool nvnc_fb_pool_resize(struct nvnc_fb_pool*, uint16_t width, uint16_t height,
|
bool nvnc_fb_pool_resize(struct nvnc_fb_pool*, uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format);
|
uint32_t fourcc_format, uint16_t stride);
|
||||||
|
|
||||||
void nvnc_fb_pool_ref(struct nvnc_fb_pool*);
|
void nvnc_fb_pool_ref(struct nvnc_fb_pool*);
|
||||||
void nvnc_fb_pool_unref(struct nvnc_fb_pool*);
|
void nvnc_fb_pool_unref(struct nvnc_fb_pool*);
|
||||||
|
|
13
src/fb.c
13
src/fb.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format)
|
uint32_t fourcc_format, uint16_t stride)
|
||||||
{
|
{
|
||||||
struct nvnc_fb* fb = calloc(1, sizeof(*fb));
|
struct nvnc_fb* fb = calloc(1, sizeof(*fb));
|
||||||
if (!fb)
|
if (!fb)
|
||||||
|
@ -38,7 +38,8 @@ struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
||||||
fb->width = width;
|
fb->width = width;
|
||||||
fb->height = height;
|
fb->height = height;
|
||||||
fb->fourcc_format = fourcc_format;
|
fb->fourcc_format = fourcc_format;
|
||||||
fb->size = width * height * 4; /* Assume 4 byte format for now */
|
fb->stride = stride;
|
||||||
|
fb->size = width * stride * 4; /* Assume 4 byte format for now */
|
||||||
|
|
||||||
size_t alignment = MAX(4, sizeof(void*));
|
size_t alignment = MAX(4, sizeof(void*));
|
||||||
size_t aligned_size = ALIGN_UP(fb->size, alignment);
|
size_t aligned_size = ALIGN_UP(fb->size, alignment);
|
||||||
|
@ -92,6 +93,12 @@ uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb)
|
||||||
return fb->fourcc_format;
|
return fb->fourcc_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT
|
||||||
|
int32_t nvnc_fb_get_stride(const struct nvnc_fb* fb)
|
||||||
|
{
|
||||||
|
return fb->stride;
|
||||||
|
}
|
||||||
|
|
||||||
static void nvnc__fb_free(struct nvnc_fb* fb)
|
static void nvnc__fb_free(struct nvnc_fb* fb)
|
||||||
{
|
{
|
||||||
nvnc_cleanup_fn cleanup = fb->common.cleanup_fn;
|
nvnc_cleanup_fn cleanup = fb->common.cleanup_fn;
|
||||||
|
|
|
@ -38,12 +38,13 @@ struct nvnc_fb_pool {
|
||||||
|
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
|
int32_t stride;
|
||||||
uint32_t fourcc_format;
|
uint32_t fourcc_format;
|
||||||
};
|
};
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format)
|
uint32_t fourcc_format, uint16_t stride)
|
||||||
{
|
{
|
||||||
struct nvnc_fb_pool* self = calloc(1, sizeof(*self));
|
struct nvnc_fb_pool* self = calloc(1, sizeof(*self));
|
||||||
if (!self)
|
if (!self)
|
||||||
|
@ -54,6 +55,7 @@ struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
||||||
TAILQ_INIT(&self->fbs);
|
TAILQ_INIT(&self->fbs);
|
||||||
self->width = width;
|
self->width = width;
|
||||||
self->height = height;
|
self->height = height;
|
||||||
|
self->stride = stride;
|
||||||
self->fourcc_format = fourcc_format;
|
self->fourcc_format = fourcc_format;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -77,16 +79,18 @@ static void nvnc_fb_pool__destroy(struct nvnc_fb_pool* self)
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
bool nvnc_fb_pool_resize(struct nvnc_fb_pool* self, uint16_t width,
|
bool nvnc_fb_pool_resize(struct nvnc_fb_pool* self, uint16_t width,
|
||||||
uint16_t height, uint32_t fourcc_format)
|
uint16_t height, uint32_t fourcc_format, uint16_t stride)
|
||||||
{
|
{
|
||||||
if (width == self->width && height == self->height &&
|
if (width == self->width && height == self->height &&
|
||||||
fourcc_format == self->fourcc_format)
|
fourcc_format == self->fourcc_format &&
|
||||||
|
stride == self->stride)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
nvnc_fb_pool__destroy_fbs(self);
|
nvnc_fb_pool__destroy_fbs(self);
|
||||||
|
|
||||||
self->width = width;
|
self->width = width;
|
||||||
self->height = height;
|
self->height = height;
|
||||||
|
self->stride = stride;
|
||||||
self->fourcc_format = fourcc_format;
|
self->fourcc_format = fourcc_format;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -116,7 +120,7 @@ static void nvnc_fb_pool__on_fb_release(struct nvnc_fb* fb, void* userdata)
|
||||||
static struct nvnc_fb* nvnc_fb_pool__acquire_new(struct nvnc_fb_pool* self)
|
static struct nvnc_fb* nvnc_fb_pool__acquire_new(struct nvnc_fb_pool* self)
|
||||||
{
|
{
|
||||||
struct nvnc_fb* fb = nvnc_fb_new(self->width, self->height,
|
struct nvnc_fb* fb = nvnc_fb_new(self->width, self->height,
|
||||||
self->fourcc_format);
|
self->fourcc_format, self->stride);
|
||||||
if (!fb)
|
if (!fb)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -152,7 +156,8 @@ EXPORT
|
||||||
void nvnc_fb_pool_release(struct nvnc_fb_pool* self, struct nvnc_fb* fb)
|
void nvnc_fb_pool_release(struct nvnc_fb_pool* self, struct nvnc_fb* fb)
|
||||||
{
|
{
|
||||||
if (fb->width != self->width || fb->height != self->height ||
|
if (fb->width != self->width || fb->height != self->height ||
|
||||||
fb->fourcc_format != self->fourcc_format) {
|
fb->fourcc_format != self->fourcc_format ||
|
||||||
|
fb->stride != self->stride) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,8 @@ struct nvnc_fb* read_png_file(const char* filename)
|
||||||
png_read_update_info(png, info);
|
png_read_update_info(png, info);
|
||||||
|
|
||||||
size_t row_bytes = png_get_rowbytes(png, info);
|
size_t row_bytes = png_get_rowbytes(png, info);
|
||||||
assert(row_bytes == width * 4);
|
struct nvnc_fb* fb = nvnc_fb_new(width, height, DRM_FORMAT_ABGR8888,
|
||||||
struct nvnc_fb* fb = nvnc_fb_new(width, height, DRM_FORMAT_ABGR8888);
|
row_bytes / 4);
|
||||||
assert(fb);
|
assert(fb);
|
||||||
|
|
||||||
uint8_t* addr = nvnc_fb_get_addr(fb);
|
uint8_t* addr = nvnc_fb_get_addr(fb);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -86,7 +86,7 @@ int raw_encode_frame(struct vec* dst, const struct rfb_pixel_format* dst_fmt,
|
||||||
int box_height = box[i].y2 - y;
|
int box_height = box[i].y2 - y;
|
||||||
|
|
||||||
rc = raw_encode_box(dst, dst_fmt, src, src_fmt, x, y,
|
rc = raw_encode_box(dst, dst_fmt, src, src_fmt, x, y,
|
||||||
src->width, box_width, box_height);
|
src->stride, box_width, box_height);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -260,7 +260,7 @@ static void tight_encode_tile_basic(struct tight_encoder* self,
|
||||||
memcpy(&cfmt, &self->dfmt, sizeof(cfmt));
|
memcpy(&cfmt, &self->dfmt, sizeof(cfmt));
|
||||||
|
|
||||||
uint32_t* addr = nvnc_fb_get_addr(self->fb);
|
uint32_t* addr = nvnc_fb_get_addr(self->fb);
|
||||||
uint32_t stride = nvnc_fb_get_width(self->fb);
|
int32_t stride = nvnc_fb_get_stride(self->fb);
|
||||||
|
|
||||||
// TODO: Limit width and hight to the sides
|
// TODO: Limit width and hight to the sides
|
||||||
for (uint32_t y = y_start; y < y_start + height; ++y) {
|
for (uint32_t y = y_start; y < y_start + height; ++y) {
|
||||||
|
@ -324,7 +324,7 @@ static int tight_encode_tile_jpeg(struct tight_encoder* self,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint32_t* addr = nvnc_fb_get_addr(self->fb);
|
uint32_t* addr = nvnc_fb_get_addr(self->fb);
|
||||||
uint32_t stride = nvnc_fb_get_width(self->fb);
|
int32_t stride = nvnc_fb_get_stride(self->fb);
|
||||||
void* img = (uint32_t*)addr + x + y * stride;
|
void* img = (uint32_t*)addr + x + y * stride;
|
||||||
|
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2021 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -287,7 +287,7 @@ int zrle_encode_frame(z_stream* zs, struct vec* dst,
|
||||||
int box_height = box[i].y2 - y;
|
int box_height = box[i].y2 - y;
|
||||||
|
|
||||||
rc = zrle_encode_box(dst, dst_fmt, src, src_fmt, x, y,
|
rc = zrle_encode_box(dst, dst_fmt, src, src_fmt, x, y,
|
||||||
src->width, box_width, box_height, zs);
|
src->stride, box_width, box_height, zs);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue