Re-format using clang-format
parent
13c52175d2
commit
80b1f3cb4c
|
@ -12,4 +12,3 @@ struct nvnc_fb {
|
|||
uint32_t fourcc_format;
|
||||
uint64_t fourcc_modifier;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,4 +18,3 @@
|
|||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
|
|
|
@ -32,12 +32,13 @@ enum nvnc_button_mask {
|
|||
NVNC_SCROLL_DOWN = 1 << 4,
|
||||
};
|
||||
|
||||
typedef void (*nvnc_key_fn)(struct nvnc_client*, uint32_t keysym, bool is_pressed);
|
||||
typedef void (*nvnc_key_fn)(struct nvnc_client*, uint32_t keysym,
|
||||
bool is_pressed);
|
||||
typedef void (*nvnc_pointer_fn)(struct nvnc_client*, uint16_t x, uint16_t y,
|
||||
enum nvnc_button_mask);
|
||||
typedef void (*nvnc_fb_req_fn)(struct nvnc_client*, bool is_incremental,
|
||||
uint16_t x, uint16_t y,
|
||||
uint16_t width, uint16_t height);
|
||||
uint16_t x, uint16_t y, uint16_t width,
|
||||
uint16_t height);
|
||||
typedef void (*nvnc_client_fn)(struct nvnc_client*);
|
||||
typedef void (*nvnc_damage_fn)(struct pixman_region16* damage, void* userdata);
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ struct rfb_pixel_format;
|
|||
struct pixman_region16;
|
||||
struct vec;
|
||||
|
||||
int raw_encode_frame(struct vec *dst,
|
||||
const struct rfb_pixel_format *dst_fmt,
|
||||
int raw_encode_frame(struct vec* dst, const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* src,
|
||||
const struct rfb_pixel_format* src_fmt,
|
||||
struct pixman_region16* region);
|
||||
|
|
|
@ -26,8 +26,7 @@ struct rfb_pixel_format;
|
|||
struct pixman_region16;
|
||||
struct vec;
|
||||
|
||||
int zrle_encode_frame(z_stream *zs,
|
||||
struct vec *dst,
|
||||
int zrle_encode_frame(z_stream* zs, struct vec* dst,
|
||||
const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* src,
|
||||
const struct rfb_pixel_format* src_fmt,
|
||||
|
|
24
src/damage.c
24
src/damage.c
|
@ -30,9 +30,8 @@ struct damage_check {
|
|||
static bool fbs_are_compatible(const struct nvnc_fb* fb0,
|
||||
const struct nvnc_fb* fb1)
|
||||
{
|
||||
return fb0->fourcc_format == fb1->fourcc_format
|
||||
&& fb0->width == fb1->width
|
||||
&& fb0->height == fb1->height;
|
||||
return fb0->fourcc_format == fb1->fourcc_format &&
|
||||
fb0->width == fb1->width && fb0->height == fb1->height;
|
||||
}
|
||||
|
||||
static inline bool are_tiles_equal(const uint32_t* a, const uint32_t* b,
|
||||
|
@ -62,8 +61,7 @@ int check_damage_linear(struct pixman_region16 *damage,
|
|||
int x_start = ALIGN_DOWN(x_hint, TILE_SIDE_LENGTH);
|
||||
int y_start = ALIGN_DOWN(y_hint, TILE_SIDE_LENGTH);
|
||||
|
||||
for (int y = y_start; y < y_start + height_hint;
|
||||
y += TILE_SIDE_LENGTH) {
|
||||
for (int y = y_start; y < y_start + height_hint; y += TILE_SIDE_LENGTH) {
|
||||
int tile_height = MIN(TILE_SIDE_LENGTH, height - y);
|
||||
|
||||
for (int x = x_start; x < x_start + width_hint;
|
||||
|
@ -72,8 +70,8 @@ int check_damage_linear(struct pixman_region16 *damage,
|
|||
|
||||
int offset = x + y * width;
|
||||
|
||||
if (are_tiles_equal(b0 + offset, b1 + offset,
|
||||
width, tile_width, tile_height))
|
||||
if (are_tiles_equal(b0 + offset, b1 + offset, width,
|
||||
tile_width, tile_height))
|
||||
continue;
|
||||
|
||||
pixman_region_union_rect(damage, damage, x, y,
|
||||
|
@ -90,8 +88,8 @@ void do_damage_check_linear(uv_work_t *work)
|
|||
struct damage_check* check = (void*)work;
|
||||
|
||||
check_damage_linear(&check->damage, check->fb0, check->fb1,
|
||||
check->x_hint, check->y_hint,
|
||||
check->width_hint, check->height_hint);
|
||||
check->x_hint, check->y_hint, check->width_hint,
|
||||
check->height_hint);
|
||||
}
|
||||
|
||||
void on_damage_check_done_linear(uv_work_t* work, int status)
|
||||
|
@ -107,11 +105,9 @@ void on_damage_check_done_linear(uv_work_t *work, int status)
|
|||
}
|
||||
|
||||
int check_damage_linear_threaded(const struct nvnc_fb* fb0,
|
||||
const struct nvnc_fb *fb1,
|
||||
int x_hint, int y_hint,
|
||||
int width_hint, int height_hint,
|
||||
nvnc_damage_fn on_check_done,
|
||||
void *userdata)
|
||||
const struct nvnc_fb* fb1, int x_hint,
|
||||
int y_hint, int width_hint, int height_hint,
|
||||
nvnc_damage_fn on_check_done, void* userdata)
|
||||
{
|
||||
struct damage_check* work = calloc(1, sizeof(*work));
|
||||
if (!work)
|
||||
|
|
15
src/pngfb.c
15
src/pngfb.c
|
@ -13,7 +13,8 @@
|
|||
#include <assert.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
|
||||
struct nvnc_fb* read_png_file(const char *filename) {
|
||||
struct nvnc_fb* read_png_file(const char* filename)
|
||||
{
|
||||
int width, height;
|
||||
png_byte color_type;
|
||||
png_byte bit_depth;
|
||||
|
@ -21,13 +22,17 @@ struct nvnc_fb* read_png_file(const char *filename) {
|
|||
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(!png) abort();
|
||||
png_structp png =
|
||||
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png)
|
||||
abort();
|
||||
|
||||
png_infop info = png_create_info_struct(png);
|
||||
if(!info) abort();
|
||||
if (!info)
|
||||
abort();
|
||||
|
||||
if(setjmp(png_jmpbuf(png))) abort();
|
||||
if (setjmp(png_jmpbuf(png)))
|
||||
abort();
|
||||
|
||||
png_init_io(png, fp);
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
int raw_encode_box(struct vec* dst, const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* fb,
|
||||
const struct rfb_pixel_format *src_fmt,
|
||||
int x_start, int y_start, int stride, int width, int height)
|
||||
const struct rfb_pixel_format* src_fmt, int x_start,
|
||||
int y_start, int stride, int width, int height)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
|
@ -36,8 +36,7 @@ int raw_encode_box(struct vec *dst, const struct rfb_pixel_format *dst_fmt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int raw_encode_frame(struct vec *dst,
|
||||
const struct rfb_pixel_format *dst_fmt,
|
||||
int raw_encode_frame(struct vec* dst, const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* src,
|
||||
const struct rfb_pixel_format* src_fmt,
|
||||
struct pixman_region16* region)
|
||||
|
|
55
src/server.c
55
src/server.c
|
@ -140,9 +140,8 @@ static void allocate_read_buffer(uv_handle_t *handle, size_t suggested_size,
|
|||
|
||||
static void cleanup_client(uv_handle_t* handle)
|
||||
{
|
||||
struct nvnc_client *client =
|
||||
container_of((uv_tcp_t*)handle, struct nvnc_client,
|
||||
stream_handle);
|
||||
struct nvnc_client* client = container_of(
|
||||
(uv_tcp_t*)handle, struct nvnc_client, stream_handle);
|
||||
|
||||
nvnc_client_fn fn = client->cleanup_fn;
|
||||
if (fn)
|
||||
|
@ -173,9 +172,8 @@ static inline void client_ref(struct nvnc_client *client)
|
|||
|
||||
static void close_after_write(uv_write_t* req, int status)
|
||||
{
|
||||
struct nvnc_client* client =
|
||||
container_of((uv_tcp_t*)req->handle, struct nvnc_client,
|
||||
stream_handle);
|
||||
struct nvnc_client* client = container_of(
|
||||
(uv_tcp_t*)req->handle, struct nvnc_client, stream_handle);
|
||||
|
||||
client_unref(client);
|
||||
}
|
||||
|
@ -186,8 +184,7 @@ static int handle_unsupported_version(struct nvnc_client *client)
|
|||
|
||||
client->state = VNC_CLIENT_STATE_ERROR;
|
||||
|
||||
struct rfb_error_reason *reason =
|
||||
(struct rfb_error_reason*)(buffer + 1);
|
||||
struct rfb_error_reason* reason = (struct rfb_error_reason*)(buffer + 1);
|
||||
|
||||
static const char reason_string[] = "Unsupported version\n";
|
||||
|
||||
|
@ -214,14 +211,17 @@ static int on_version_message(struct nvnc_client *client)
|
|||
if (strcmp(RFB_VERSION_MESSAGE, version_string) != 0)
|
||||
return handle_unsupported_version(client);
|
||||
|
||||
/* clang-format off */
|
||||
const static struct rfb_security_types_msg security = {
|
||||
.n = 1,
|
||||
.types = {
|
||||
RFB_SECURITY_TYPE_NONE,
|
||||
},
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
vnc__write((uv_stream_t*)&client->stream_handle, &security, sizeof(security), NULL);
|
||||
vnc__write((uv_stream_t*)&client->stream_handle, &security,
|
||||
sizeof(security), NULL);
|
||||
|
||||
client->state = VNC_CLIENT_STATE_WAITING_FOR_SECURITY;
|
||||
return 12;
|
||||
|
@ -261,10 +261,11 @@ static int on_security_message(struct nvnc_client *client)
|
|||
if (type != RFB_SECURITY_TYPE_NONE)
|
||||
return handle_invalid_security_type(client);
|
||||
|
||||
enum rfb_security_handshake_result result
|
||||
= htonl(RFB_SECURITY_HANDSHAKE_OK);
|
||||
enum rfb_security_handshake_result result =
|
||||
htonl(RFB_SECURITY_HANDSHAKE_OK);
|
||||
|
||||
vnc__write((uv_stream_t*)&client->stream_handle, &result, sizeof(result), NULL);
|
||||
vnc__write((uv_stream_t*)&client->stream_handle, &result,
|
||||
sizeof(result), NULL);
|
||||
|
||||
client->state = VNC_CLIENT_STATE_WAITING_FOR_INIT;
|
||||
return sizeof(type);
|
||||
|
@ -278,6 +279,7 @@ static void disconnect_all_other_clients(struct nvnc_client *client)
|
|||
client_unref(client);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
int rfb_pixfmt_from_fourcc(struct rfb_pixel_format *dst, uint32_t src) {
|
||||
switch (src & ~DRM_FORMAT_BIG_ENDIAN) {
|
||||
case DRM_FORMAT_RGBA8888:
|
||||
|
@ -396,6 +398,7 @@ static uint32_t shift_values_to_fourcc(int r, int g, int b, int bpp)
|
|||
return DRM_FORMAT_INVALID;
|
||||
#undef RGBEQ
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
int get_fourcc_depth(uint32_t fourcc)
|
||||
{
|
||||
|
@ -415,8 +418,8 @@ uint32_t rfb_pixfmt_to_fourcc(const struct rfb_pixel_format *fmt)
|
|||
return DRM_FORMAT_INVALID;
|
||||
|
||||
/* Note: The depth value given by the client is ignored */
|
||||
int depth = max_values_to_depth(fmt->red_max, fmt->green_max,
|
||||
fmt->blue_max);
|
||||
int depth =
|
||||
max_values_to_depth(fmt->red_max, fmt->green_max, fmt->blue_max);
|
||||
if (depth < 0)
|
||||
return DRM_FORMAT_INVALID;
|
||||
|
||||
|
@ -450,8 +453,7 @@ static void send_server_init_message(struct nvnc_client *client)
|
|||
}
|
||||
|
||||
msg->width = htons(display->width),
|
||||
msg->height = htons(display->height),
|
||||
msg->name_length = htonl(name_len),
|
||||
msg->height = htons(display->height), msg->name_length = htonl(name_len),
|
||||
memcpy(msg->name_string, display->name, name_len);
|
||||
|
||||
int rc = rfb_pixfmt_from_fourcc(&msg->pixel_format, display->pixfmt);
|
||||
|
@ -490,8 +492,8 @@ static int on_init_message(struct nvnc_client *client)
|
|||
|
||||
static int on_client_set_pixel_format(struct nvnc_client* client)
|
||||
{
|
||||
if (client->buffer_len - client->buffer_index
|
||||
< 4 + sizeof(struct rfb_pixel_format))
|
||||
if (client->buffer_len - client->buffer_index <
|
||||
4 + sizeof(struct rfb_pixel_format))
|
||||
return 0;
|
||||
|
||||
struct rfb_pixel_format* fmt =
|
||||
|
@ -584,8 +586,8 @@ static int on_client_fb_update_request(struct nvnc_client *client)
|
|||
* updates. This avoids superfluous complexity.
|
||||
*/
|
||||
if (!incremental)
|
||||
pixman_region_union_rect(&client->damage, &client->damage,
|
||||
x, y, width, height);
|
||||
pixman_region_union_rect(&client->damage, &client->damage, x, y,
|
||||
width, height);
|
||||
|
||||
nvnc_fb_req_fn fn = server->fb_req_fn;
|
||||
if (fn)
|
||||
|
@ -696,9 +698,8 @@ static int try_read_client_message(struct nvnc_client *client)
|
|||
static void on_client_read(uv_stream_t* stream, ssize_t n_read,
|
||||
const uv_buf_t* buf)
|
||||
{
|
||||
struct nvnc_client *client =
|
||||
container_of((uv_tcp_t*)stream, struct nvnc_client,
|
||||
stream_handle);
|
||||
struct nvnc_client* client = container_of(
|
||||
(uv_tcp_t*)stream, struct nvnc_client, stream_handle);
|
||||
|
||||
if (n_read == UV_EOF) {
|
||||
client_unref(client);
|
||||
|
@ -738,8 +739,8 @@ static void on_client_read(uv_stream_t *stream, ssize_t n_read,
|
|||
|
||||
static void on_connection(uv_stream_t* server_stream, int status)
|
||||
{
|
||||
struct nvnc *server = container_of((uv_tcp_t*)server_stream,
|
||||
struct nvnc, tcp_handle);
|
||||
struct nvnc* server =
|
||||
container_of((uv_tcp_t*)server_stream, struct nvnc, tcp_handle);
|
||||
|
||||
struct nvnc_client* client = calloc(1, sizeof(*client));
|
||||
if (!client)
|
||||
|
@ -901,8 +902,8 @@ void on_client_update_fb_done(uv_work_t *work, int status)
|
|||
struct vec* frame = &update->frame;
|
||||
|
||||
if (!uv_is_closing((uv_handle_t*)&client->stream_handle))
|
||||
vnc__write((uv_stream_t*)&client->stream_handle,
|
||||
frame->data, frame->len, free_write_buffer);
|
||||
vnc__write((uv_stream_t*)&client->stream_handle, frame->data,
|
||||
frame->len, free_write_buffer);
|
||||
|
||||
client->is_updating = false;
|
||||
client->n_pending_requests--;
|
||||
|
|
38
src/zrle.c
38
src/zrle.c
|
@ -103,14 +103,13 @@ void zrle_encode_packed_tile(struct vec *dst,
|
|||
const struct rfb_pixel_format* dst_fmt,
|
||||
const uint32_t* src,
|
||||
const struct rfb_pixel_format* src_fmt,
|
||||
size_t length,
|
||||
uint32_t *palette, int palette_size)
|
||||
size_t length, uint32_t* palette, int palette_size)
|
||||
{
|
||||
int bytes_per_cpixel = dst_fmt->depth / 8;
|
||||
|
||||
uint8_t cpalette[16 * 3];
|
||||
pixel32_to_cpixel((uint8_t*)cpalette, dst_fmt, palette,
|
||||
src_fmt, bytes_per_cpixel, palette_size);
|
||||
pixel32_to_cpixel((uint8_t*)cpalette, dst_fmt, palette, src_fmt,
|
||||
bytes_per_cpixel, palette_size);
|
||||
|
||||
vec_fast_append_8(dst, 128 | palette_size);
|
||||
|
||||
|
@ -125,8 +124,7 @@ void zrle_encode_packed_tile(struct vec *dst,
|
|||
continue;
|
||||
}
|
||||
|
||||
index = find_colour_in_palette(palette, palette_size,
|
||||
src[i - 1]);
|
||||
index = find_colour_in_palette(palette, palette_size, src[i - 1]);
|
||||
encode_run_length(dst, index, run_length);
|
||||
run_length = 1;
|
||||
}
|
||||
|
@ -138,8 +136,8 @@ void zrle_encode_packed_tile(struct vec *dst,
|
|||
}
|
||||
}
|
||||
|
||||
void zrle_copy_tile(uint32_t *dst, const uint32_t *src, int stride,
|
||||
int width, int height)
|
||||
void zrle_copy_tile(uint32_t* dst, const uint32_t* src, int stride, int width,
|
||||
int height)
|
||||
{
|
||||
for (int y = 0; y < height; ++y)
|
||||
memcpy(dst + y * width, src + y * stride, width * 4);
|
||||
|
@ -147,8 +145,7 @@ void zrle_copy_tile(uint32_t *dst, const uint32_t *src, int stride,
|
|||
|
||||
void zrle_encode_tile(struct vec* dst, const struct rfb_pixel_format* dst_fmt,
|
||||
const uint32_t* src,
|
||||
const struct rfb_pixel_format *src_fmt,
|
||||
size_t length)
|
||||
const struct rfb_pixel_format* src_fmt, size_t length)
|
||||
{
|
||||
int bytes_per_cpixel = dst_fmt->depth / 8;
|
||||
|
||||
|
@ -176,8 +173,7 @@ void zrle_encode_tile(struct vec *dst, const struct rfb_pixel_format *dst_fmt,
|
|||
dst->len += bytes_per_cpixel * length;
|
||||
}
|
||||
|
||||
int zrle_deflate(struct vec* dst, const struct vec* src, z_stream* zs,
|
||||
bool flush)
|
||||
int zrle_deflate(struct vec* dst, const struct vec* src, z_stream* zs, bool flush)
|
||||
{
|
||||
int r = Z_STREAM_ERROR;
|
||||
|
||||
|
@ -204,9 +200,8 @@ int zrle_deflate(struct vec* dst, const struct vec* src, z_stream* zs,
|
|||
|
||||
int zrle_encode_box(struct vec* out, const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* fb,
|
||||
const struct rfb_pixel_format *src_fmt,
|
||||
int x, int y, int stride, int width, int height,
|
||||
z_stream* zs)
|
||||
const struct rfb_pixel_format* src_fmt, int x, int y,
|
||||
int stride, int width, int height, z_stream* zs)
|
||||
{
|
||||
int r = -1;
|
||||
int bytes_per_cpixel = dst_fmt->depth / 8;
|
||||
|
@ -236,15 +231,17 @@ int zrle_encode_box(struct vec* out, const struct rfb_pixel_format *dst_fmt,
|
|||
size_t size_index = out->len;
|
||||
vec_append_zero(out, 4);
|
||||
|
||||
int n_tiles =
|
||||
UDIV_UP(width, TILE_LENGTH) * UDIV_UP(height, TILE_LENGTH);
|
||||
int n_tiles = UDIV_UP(width, TILE_LENGTH) * UDIV_UP(height, TILE_LENGTH);
|
||||
|
||||
for (int i = 0; i < n_tiles; ++i) {
|
||||
int tile_x = (i % UDIV_UP(width, TILE_LENGTH)) * TILE_LENGTH;
|
||||
int tile_y = (i / UDIV_UP(width, TILE_LENGTH)) * TILE_LENGTH;
|
||||
|
||||
int tile_width = width - tile_x >= TILE_LENGTH ? TILE_LENGTH : width - tile_x;
|
||||
int tile_height = height - tile_y >= TILE_LENGTH ? TILE_LENGTH : height - tile_y;
|
||||
int tile_width = width - tile_x >= TILE_LENGTH ? TILE_LENGTH
|
||||
: width - tile_x;
|
||||
int tile_height = height - tile_y >= TILE_LENGTH
|
||||
? TILE_LENGTH
|
||||
: height - tile_y;
|
||||
|
||||
int y_off = y + tile_y;
|
||||
|
||||
|
@ -270,8 +267,7 @@ failure:
|
|||
#undef CHUNK
|
||||
}
|
||||
|
||||
int zrle_encode_frame(z_stream *zs,
|
||||
struct vec* dst,
|
||||
int zrle_encode_frame(z_stream* zs, struct vec* dst,
|
||||
const struct rfb_pixel_format* dst_fmt,
|
||||
const struct nvnc_fb* src,
|
||||
const struct rfb_pixel_format* src_fmt,
|
||||
|
|
Loading…
Reference in New Issue