2019-09-07 16:51:07 +00:00
|
|
|
/*
|
2022-02-19 23:06:15 +00:00
|
|
|
* Copyright (c) 2019 - 2022 Andri Yngvason
|
2019-09-07 16:51:07 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-08-28 22:46:47 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2022-04-14 16:56:41 +00:00
|
|
|
#include <limits.h>
|
2022-06-25 15:04:58 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2022-04-14 16:56:41 +00:00
|
|
|
|
|
|
|
#define NVNC_NO_PTS UINT64_MAX
|
2019-08-28 22:46:47 +00:00
|
|
|
|
2022-06-25 15:04:58 +00:00
|
|
|
#define nvnc_log(lvl, fmt, ...) do { \
|
|
|
|
assert(lvl != NVNC_LOG_TRACE); \
|
|
|
|
struct nvnc_log_data ld = { \
|
|
|
|
.level = lvl, \
|
|
|
|
.file = __FILE__, \
|
|
|
|
.line = __LINE__, \
|
|
|
|
}; \
|
|
|
|
nvnc__log(&ld, fmt, ## __VA_ARGS__); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#define nvnc_trace(fmt, ...) do { \
|
|
|
|
struct nvnc_log_data ld = { \
|
|
|
|
.level = NVNC_LOG_TRACE, \
|
|
|
|
.file = __FILE__, \
|
|
|
|
.line = __LINE__, \
|
|
|
|
}; \
|
|
|
|
nvnc__log(&ld, fmt, ## __VA_ARGS__); \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define nvnc_trace(...)
|
|
|
|
#endif
|
|
|
|
|
2019-08-28 22:46:47 +00:00
|
|
|
struct nvnc;
|
2019-08-31 23:16:55 +00:00
|
|
|
struct nvnc_client;
|
2020-04-12 18:16:19 +00:00
|
|
|
struct nvnc_display;
|
2019-10-07 17:39:54 +00:00
|
|
|
struct nvnc_fb;
|
2021-08-29 16:30:00 +00:00
|
|
|
struct nvnc_fb_pool;
|
2019-08-28 22:46:47 +00:00
|
|
|
struct pixman_region16;
|
2021-09-12 18:01:58 +00:00
|
|
|
struct gbm_bo;
|
2019-08-28 22:46:47 +00:00
|
|
|
|
|
|
|
enum nvnc_button_mask {
|
2019-10-20 22:13:51 +00:00
|
|
|
NVNC_BUTTON_LEFT = 1 << 0,
|
|
|
|
NVNC_BUTTON_MIDDLE = 1 << 1,
|
|
|
|
NVNC_BUTTON_RIGHT = 1 << 2,
|
|
|
|
NVNC_SCROLL_UP = 1 << 3,
|
|
|
|
NVNC_SCROLL_DOWN = 1 << 4,
|
2022-07-28 20:13:48 +00:00
|
|
|
NVNC_SCROLL_LEFT = 1 << 5,
|
|
|
|
NVNC_SCROLL_RIGHT = 1 << 6,
|
2019-08-28 22:46:47 +00:00
|
|
|
};
|
|
|
|
|
2021-09-12 18:01:58 +00:00
|
|
|
enum nvnc_fb_type {
|
|
|
|
NVNC_FB_UNSPEC = 0,
|
|
|
|
NVNC_FB_SIMPLE,
|
|
|
|
NVNC_FB_GBM_BO,
|
|
|
|
};
|
|
|
|
|
2021-09-19 19:56:56 +00:00
|
|
|
/* This is the same as wl_output_transform */
|
|
|
|
enum nvnc_transform {
|
|
|
|
NVNC_TRANSFORM_NORMAL = 0,
|
|
|
|
NVNC_TRANSFORM_90 = 1,
|
|
|
|
NVNC_TRANSFORM_180 = 2,
|
|
|
|
NVNC_TRANSFORM_270 = 3,
|
|
|
|
NVNC_TRANSFORM_FLIPPED = 4,
|
|
|
|
NVNC_TRANSFORM_FLIPPED_90 = 5,
|
|
|
|
NVNC_TRANSFORM_FLIPPED_180 = 6,
|
|
|
|
NVNC_TRANSFORM_FLIPPED_270 = 7,
|
|
|
|
};
|
|
|
|
|
2022-06-25 15:04:58 +00:00
|
|
|
enum nvnc_log_level {
|
|
|
|
NVNC_LOG_PANIC = 0,
|
|
|
|
NVNC_LOG_ERROR = 1,
|
|
|
|
NVNC_LOG_WARNING = 2,
|
|
|
|
NVNC_LOG_INFO = 3,
|
|
|
|
NVNC_LOG_DEBUG = 4,
|
|
|
|
NVNC_LOG_TRACE = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvnc_log_data {
|
|
|
|
enum nvnc_log_level level;
|
|
|
|
const char* file;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
2020-11-29 17:35:06 +00:00
|
|
|
typedef void (*nvnc_key_fn)(struct nvnc_client*, uint32_t key,
|
2019-10-20 22:13:51 +00:00
|
|
|
bool is_pressed);
|
2019-08-31 23:16:55 +00:00
|
|
|
typedef void (*nvnc_pointer_fn)(struct nvnc_client*, uint16_t x, uint16_t y,
|
2019-08-28 22:46:47 +00:00
|
|
|
enum nvnc_button_mask);
|
2019-08-31 23:16:55 +00:00
|
|
|
typedef void (*nvnc_fb_req_fn)(struct nvnc_client*, bool is_incremental,
|
2019-10-20 22:13:51 +00:00
|
|
|
uint16_t x, uint16_t y, uint16_t width,
|
|
|
|
uint16_t height);
|
2019-08-31 23:30:08 +00:00
|
|
|
typedef void (*nvnc_client_fn)(struct nvnc_client*);
|
2019-10-20 22:13:51 +00:00
|
|
|
typedef void (*nvnc_damage_fn)(struct pixman_region16* damage, void* userdata);
|
2020-01-25 15:35:14 +00:00
|
|
|
typedef bool (*nvnc_auth_fn)(const char* username, const char* password,
|
|
|
|
void* userdata);
|
2020-09-16 22:10:15 +00:00
|
|
|
typedef void (*nvnc_cut_text_fn)(struct nvnc*, const char* text, uint32_t len);
|
2021-08-29 18:34:40 +00:00
|
|
|
typedef void (*nvnc_fb_release_fn)(struct nvnc_fb*, void* context);
|
2021-09-04 17:05:30 +00:00
|
|
|
typedef void (*nvnc_cleanup_fn)(void* userdata);
|
2022-06-25 15:04:58 +00:00
|
|
|
typedef void (*nvnc_log_fn)(const struct nvnc_log_data*, const char* message);
|
2019-08-28 22:46:47 +00:00
|
|
|
|
2020-07-26 11:43:00 +00:00
|
|
|
extern const char nvnc_version[];
|
|
|
|
|
2019-10-20 22:13:51 +00:00
|
|
|
struct nvnc* nvnc_open(const char* addr, uint16_t port);
|
2021-03-17 07:37:06 +00:00
|
|
|
struct nvnc* nvnc_open_unix(const char *addr);
|
2019-10-20 22:13:51 +00:00
|
|
|
void nvnc_close(struct nvnc* self);
|
2019-08-28 22:46:47 +00:00
|
|
|
|
2020-04-12 18:16:19 +00:00
|
|
|
void nvnc_add_display(struct nvnc*, struct nvnc_display*);
|
|
|
|
void nvnc_remove_display(struct nvnc*, struct nvnc_display*);
|
|
|
|
|
2021-09-04 17:05:30 +00:00
|
|
|
void nvnc_set_userdata(void* self, void* userdata, nvnc_cleanup_fn);
|
2019-10-20 22:13:51 +00:00
|
|
|
void* nvnc_get_userdata(const void* self);
|
2019-08-31 23:16:55 +00:00
|
|
|
|
2020-04-12 18:16:19 +00:00
|
|
|
struct nvnc* nvnc_client_get_server(const struct nvnc_client* client);
|
2022-07-28 10:34:24 +00:00
|
|
|
bool nvnc_client_supports_cursor(const struct nvnc_client* client);
|
2020-04-07 22:21:11 +00:00
|
|
|
|
2019-10-20 22:13:51 +00:00
|
|
|
void nvnc_set_name(struct nvnc* self, const char* name);
|
2019-08-28 22:46:47 +00:00
|
|
|
|
2019-10-20 22:13:51 +00:00
|
|
|
void nvnc_set_key_fn(struct nvnc* self, nvnc_key_fn);
|
2020-11-29 17:35:06 +00:00
|
|
|
void nvnc_set_key_code_fn(struct nvnc* self, nvnc_key_fn);
|
2019-10-20 22:13:51 +00:00
|
|
|
void nvnc_set_pointer_fn(struct nvnc* self, nvnc_pointer_fn);
|
|
|
|
void nvnc_set_fb_req_fn(struct nvnc* self, nvnc_fb_req_fn);
|
|
|
|
void nvnc_set_new_client_fn(struct nvnc* self, nvnc_client_fn);
|
|
|
|
void nvnc_set_client_cleanup_fn(struct nvnc_client* self, nvnc_client_fn fn);
|
2020-09-16 22:10:15 +00:00
|
|
|
void nvnc_set_cut_text_receive_fn(struct nvnc* self, nvnc_cut_text_fn fn);
|
2019-08-28 22:46:47 +00:00
|
|
|
|
2020-01-25 15:35:14 +00:00
|
|
|
bool nvnc_has_auth(void);
|
|
|
|
int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
|
|
|
|
const char* cert_path, nvnc_auth_fn, void* userdata);
|
|
|
|
|
2019-10-07 17:39:54 +00:00
|
|
|
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
|
2021-09-04 23:53:30 +00:00
|
|
|
uint32_t fourcc_format, uint16_t stride);
|
2021-09-05 00:39:35 +00:00
|
|
|
struct nvnc_fb* nvnc_fb_from_buffer(void* buffer, uint16_t width,
|
2021-09-12 18:01:58 +00:00
|
|
|
uint16_t height, uint32_t fourcc_format,
|
|
|
|
int32_t stride);
|
|
|
|
struct nvnc_fb* nvnc_fb_from_gbm_bo(struct gbm_bo* bo);
|
2019-10-07 17:39:54 +00:00
|
|
|
|
|
|
|
void nvnc_fb_ref(struct nvnc_fb* fb);
|
|
|
|
void nvnc_fb_unref(struct nvnc_fb* fb);
|
|
|
|
|
2021-08-29 14:26:12 +00:00
|
|
|
void nvnc_fb_set_release_fn(struct nvnc_fb* fb, nvnc_fb_release_fn fn,
|
2021-08-29 18:34:40 +00:00
|
|
|
void* context);
|
2021-09-19 19:56:56 +00:00
|
|
|
void nvnc_fb_set_transform(struct nvnc_fb* fb, enum nvnc_transform);
|
2020-04-04 14:00:03 +00:00
|
|
|
|
2022-04-14 16:56:41 +00:00
|
|
|
void nvnc_fb_set_pts(struct nvnc_fb* fb, uint64_t pts);
|
|
|
|
|
2019-10-07 17:39:54 +00:00
|
|
|
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_height(const struct nvnc_fb* fb);
|
|
|
|
uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb);
|
2021-09-04 23:53:30 +00:00
|
|
|
int32_t nvnc_fb_get_stride(const struct nvnc_fb* fb);
|
2021-09-05 00:20:05 +00:00
|
|
|
int nvnc_fb_get_pixel_size(const struct nvnc_fb* fb);
|
2021-09-12 18:01:58 +00:00
|
|
|
struct gbm_bo* nvnc_fb_get_gbm_bo(const struct nvnc_fb* fb);
|
2021-09-19 19:56:56 +00:00
|
|
|
enum nvnc_transform nvnc_fb_get_transform(const struct nvnc_fb* fb);
|
2021-12-24 15:17:20 +00:00
|
|
|
enum nvnc_fb_type nvnc_fb_get_type(const struct nvnc_fb* fb);
|
2022-04-14 16:56:41 +00:00
|
|
|
uint64_t nvnc_fb_get_pts(const struct nvnc_fb* fb);
|
2019-10-07 17:39:54 +00:00
|
|
|
|
2021-08-29 16:30:00 +00:00
|
|
|
struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height,
|
2021-09-04 23:53:30 +00:00
|
|
|
uint32_t fourcc_format, uint16_t stride);
|
2021-09-04 20:00:02 +00:00
|
|
|
bool nvnc_fb_pool_resize(struct nvnc_fb_pool*, uint16_t width, uint16_t height,
|
2021-09-04 23:53:30 +00:00
|
|
|
uint32_t fourcc_format, uint16_t stride);
|
2021-08-29 16:30:00 +00:00
|
|
|
|
|
|
|
void nvnc_fb_pool_ref(struct nvnc_fb_pool*);
|
|
|
|
void nvnc_fb_pool_unref(struct nvnc_fb_pool*);
|
|
|
|
|
|
|
|
struct nvnc_fb* nvnc_fb_pool_acquire(struct nvnc_fb_pool*);
|
|
|
|
void nvnc_fb_pool_release(struct nvnc_fb_pool*, struct nvnc_fb*);
|
|
|
|
|
2020-04-12 18:16:19 +00:00
|
|
|
struct nvnc_display* nvnc_display_new(uint16_t x_pos, uint16_t y_pos);
|
|
|
|
void nvnc_display_ref(struct nvnc_display*);
|
|
|
|
void nvnc_display_unref(struct nvnc_display*);
|
|
|
|
|
|
|
|
struct nvnc* nvnc_display_get_server(const struct nvnc_display*);
|
|
|
|
|
2021-09-19 20:12:30 +00:00
|
|
|
void nvnc_display_feed_buffer(struct nvnc_display*, struct nvnc_fb*,
|
|
|
|
struct pixman_region16* damage);
|
2019-09-15 20:44:49 +00:00
|
|
|
|
2020-09-16 22:10:15 +00:00
|
|
|
void nvnc_send_cut_text(struct nvnc*, const char* text, uint32_t len);
|
2022-02-06 15:43:45 +00:00
|
|
|
|
2022-02-19 23:06:15 +00:00
|
|
|
void nvnc_set_cursor(struct nvnc*, struct nvnc_fb*, uint16_t width,
|
2022-02-21 21:38:44 +00:00
|
|
|
uint16_t height, uint16_t hotspot_x, uint16_t hotspot_y,
|
|
|
|
bool is_damaged);
|
2022-06-25 15:04:58 +00:00
|
|
|
|
|
|
|
void nvnc_set_log_fn(nvnc_log_fn);
|
|
|
|
void nvnc_set_log_level(enum nvnc_log_level);
|
|
|
|
void nvnc__log(const struct nvnc_log_data*, const char* fmt, ...);
|