neatvnc/src/display.c

103 lines
2.4 KiB
C
Raw Normal View History

/*
2021-09-19 20:12:30 +00:00
* Copyright (c) 2020 - 2021 Andri Yngvason
*
* 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.
*/
#include "display.h"
#include "neatvnc.h"
#include "common.h"
2021-08-29 14:41:57 +00:00
#include "fb.h"
#include "resampler.h"
#include <assert.h>
#include <stdlib.h>
#define EXPORT __attribute__((visibility("default")))
static void nvnc_display__on_resampler_done(struct nvnc_fb* fb,
struct pixman_region16* damage, void* userdata)
2021-09-19 20:12:30 +00:00
{
struct nvnc_display* self = userdata;
2021-09-19 20:12:30 +00:00
if (self->buffer) {
nvnc_fb_release(self->buffer);
nvnc_fb_unref(self->buffer);
}
self->buffer = fb;
nvnc_fb_ref(fb);
nvnc_fb_hold(fb);
// TODO: Shift according to display position
assert(self->server);
nvnc__damage_region(self->server, damage);
}
EXPORT
struct nvnc_display* nvnc_display_new(uint16_t x_pos, uint16_t y_pos)
{
struct nvnc_display* self = calloc(1, sizeof(*self));
if (!self)
return NULL;
self->resampler = resampler_create();
if (!self->resampler) {
2021-09-19 20:12:30 +00:00
free(self);
return NULL;
}
self->ref = 1;
self->x_pos = x_pos;
self->y_pos = y_pos;
return self;
}
static void nvnc__display_free(struct nvnc_display* self)
{
if (self->buffer) {
nvnc_fb_release(self->buffer);
nvnc_fb_unref(self->buffer);
}
resampler_destroy(self->resampler);
free(self);
}
EXPORT
void nvnc_display_ref(struct nvnc_display* self)
{
self->ref++;
}
EXPORT
void nvnc_display_unref(struct nvnc_display* self)
{
if (--self->ref == 0)
nvnc__display_free(self);
}
EXPORT
struct nvnc* nvnc_display_get_server(const struct nvnc_display* self)
{
return self->server;
}
EXPORT
2021-09-19 20:12:30 +00:00
void nvnc_display_feed_buffer(struct nvnc_display* self, struct nvnc_fb* fb,
struct pixman_region16* damage)
{
resampler_feed(self->resampler, fb, damage,
nvnc_display__on_resampler_done, self);
}