2019-08-31 20:45:10 +00:00
|
|
|
#include "neatvnc.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <uv.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <pixman.h>
|
|
|
|
#include <libdrm/drm_fourcc.h>
|
|
|
|
|
|
|
|
struct draw {
|
|
|
|
struct nvnc_fb fb;
|
|
|
|
};
|
|
|
|
|
2019-08-31 23:16:55 +00:00
|
|
|
void on_fb_req(struct nvnc_client *client, bool incremental, uint16_t x, uint16_t y,
|
2019-08-31 20:45:10 +00:00
|
|
|
uint16_t width, uint16_t height)
|
|
|
|
{
|
|
|
|
if (incremental)
|
|
|
|
return;
|
|
|
|
|
2019-08-31 23:16:55 +00:00
|
|
|
struct nvnc* server = nvnc_get_server(client);
|
|
|
|
assert(server);
|
|
|
|
|
|
|
|
struct draw *draw = nvnc_get_userdata(server);
|
2019-08-31 20:45:10 +00:00
|
|
|
assert(draw);
|
|
|
|
|
|
|
|
struct pixman_region16 region;
|
|
|
|
pixman_region_init_rect(®ion, 0, 0, draw->fb.width,
|
|
|
|
draw->fb.height);
|
2019-08-31 23:16:55 +00:00
|
|
|
nvnc_update_fb(server, &draw->fb, ®ion);
|
2019-08-31 20:45:10 +00:00
|
|
|
pixman_region_fini(®ion);
|
|
|
|
}
|
|
|
|
|
2019-08-31 23:16:55 +00:00
|
|
|
void on_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y,
|
2019-08-31 20:45:10 +00:00
|
|
|
enum nvnc_button_mask buttons)
|
|
|
|
{
|
|
|
|
if (!(buttons & NVNC_BUTTON_LEFT))
|
|
|
|
return;
|
|
|
|
|
2019-08-31 23:16:55 +00:00
|
|
|
struct nvnc *server = nvnc_get_server(client);
|
|
|
|
assert(server);
|
|
|
|
|
|
|
|
struct draw *draw = nvnc_get_userdata(server);
|
2019-08-31 20:45:10 +00:00
|
|
|
assert(draw);
|
|
|
|
|
|
|
|
uint32_t *image = draw->fb.addr;
|
|
|
|
|
|
|
|
image[x + y * draw->fb.width] = 0;
|
|
|
|
|
|
|
|
struct pixman_region16 region;
|
|
|
|
pixman_region_init_rect(®ion, 0, 0, draw->fb.width,
|
|
|
|
draw->fb.height);
|
|
|
|
// pixman_region_init_rect(®ion, x, y, 1, 1);
|
2019-08-31 23:16:55 +00:00
|
|
|
nvnc_update_fb(server, &draw->fb, ®ion);
|
2019-08-31 20:45:10 +00:00
|
|
|
pixman_region_fini(®ion);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct draw draw;
|
|
|
|
|
|
|
|
draw.fb.width = 500;
|
|
|
|
draw.fb.height = 500;
|
|
|
|
draw.fb.size = draw.fb.width * draw.fb.height * 4;
|
|
|
|
draw.fb.fourcc_format = DRM_FORMAT_RGBX8888;
|
|
|
|
draw.fb.fourcc_modifier = DRM_FORMAT_MOD_LINEAR;
|
|
|
|
|
|
|
|
draw.fb.addr = malloc(draw.fb.size);
|
|
|
|
assert(draw.fb.addr);
|
|
|
|
|
|
|
|
memset(draw.fb.addr, 0xff, draw.fb.size);
|
|
|
|
|
|
|
|
struct nvnc *server = nvnc_open("127.0.0.1", 5900);
|
|
|
|
|
|
|
|
nvnc_set_dimensions(server, draw.fb.width, draw.fb.height,
|
|
|
|
draw.fb.fourcc_format);
|
|
|
|
nvnc_set_name(server, "Draw");
|
|
|
|
nvnc_set_fb_req_fn(server, on_fb_req);
|
|
|
|
nvnc_set_pointer_fn(server, on_pointer_event);
|
|
|
|
nvnc_set_userdata(server, &draw);
|
|
|
|
|
|
|
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
|
|
|
|
|
|
|
nvnc_close(server);
|
|
|
|
}
|