Add example that draws a png
parent
fd6f47c93c
commit
d222caffc2
16
Makefile
16
Makefile
|
@ -1,4 +1,4 @@
|
|||
all: libneatvnc.so.0.0
|
||||
all: libneatvnc.so
|
||||
|
||||
DEPENDENCIES := pixman-1 libpng libuv
|
||||
|
||||
|
@ -10,19 +10,31 @@ LDFLAGS := $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --libs $(dep)))
|
|||
libneatvnc.so.0.0: src/server.o src/util.o src/vec.o src/zrle.o src/pngfb.o
|
||||
$(CC) -fPIC -shared $^ $(LDFLAGS) -o $@
|
||||
|
||||
libneatvnc.so.0: libneatvnc.so.0.0
|
||||
ln -s $^ $@
|
||||
|
||||
libneatvnc.so: libneatvnc.so.0
|
||||
ln -s $^ $@
|
||||
|
||||
zrle-bench: bench/zrle-bench.o src/server.o src/util.o src/vec.o src/zrle.o \
|
||||
src/pngfb.o
|
||||
$(CC) $^ $(LDFLAGS) -o $@
|
||||
|
||||
examples/png-server: examples/png-server.o src/pngfb.o libneatvnc.so
|
||||
$(CC) $^ $(LDFLAGS) -L. -lneatvnc -Wl,-rpath=$(shell pwd) -o $@
|
||||
|
||||
src/%.o: src/%.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $@.deps
|
||||
|
||||
bench/%.o: bench/%.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $@.deps
|
||||
|
||||
examples/%.o: examples/%.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $@.deps
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f libneatvnc.so.0.0
|
||||
rm -f libneatvnc.so*
|
||||
rm -f src/*.o src/*.deps bench/*.o bench/*.deps
|
||||
|
||||
-include src/*.deps
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#include "neatvnc.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <uv.h>
|
||||
#include <assert.h>
|
||||
#include <pixman.h>
|
||||
|
||||
int read_png_file(struct nvnc_fb* fb, const char *filename);
|
||||
|
||||
void on_fb_req(struct nvnc *nvnc, bool incremental, uint16_t x, uint16_t y,
|
||||
uint16_t width, uint16_t height)
|
||||
{
|
||||
if (incremental)
|
||||
return;
|
||||
|
||||
struct nvnc_fb *fb = nvnc_get_userdata(nvnc);
|
||||
assert(fb);
|
||||
|
||||
struct pixman_region16 region;
|
||||
pixman_region_init_rect(®ion, 0, 0, fb->width, fb->height);
|
||||
nvnc_update_fb(nvnc, fb, ®ion);
|
||||
pixman_region_fini(®ion);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *file = argv[1];
|
||||
|
||||
if (!file) {
|
||||
printf("Missing argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct nvnc_fb fb;
|
||||
if (read_png_file(&fb, file) < 0) {
|
||||
printf("Failed to read png file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct nvnc *server = nvnc_open("127.0.0.1", 5900);
|
||||
|
||||
nvnc_set_dimensions(server, fb.width, fb.height, fb.fourcc_format);
|
||||
nvnc_set_name(server, file);
|
||||
nvnc_set_fb_req_fn(server, on_fb_req);
|
||||
nvnc_set_userdata(server, &fb);
|
||||
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
nvnc_close(server);
|
||||
}
|
Loading…
Reference in New Issue