2020-04-12 18:16:19 +00:00
|
|
|
/*
|
2021-09-19 20:12:30 +00:00
|
|
|
* Copyright (c) 2020 - 2021 Andri Yngvason
|
2020-04-12 18:16:19 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
#include "neatvnc.h"
|
|
|
|
#include "common.h"
|
2021-08-29 14:41:57 +00:00
|
|
|
#include "fb.h"
|
2021-09-19 21:42:16 +00:00
|
|
|
#include "resampler.h"
|
2021-09-20 21:15:32 +00:00
|
|
|
#include "transform-util.h"
|
2021-12-24 16:29:37 +00:00
|
|
|
#include "encoder.h"
|
2022-06-26 13:52:45 +00:00
|
|
|
#include "usdt.h"
|
2020-04-12 18:16:19 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define EXPORT __attribute__((visibility("default")))
|
|
|
|
|
2021-09-19 21:42:16 +00:00
|
|
|
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
|
|
|
{
|
2021-09-19 21:42:16 +00:00
|
|
|
struct nvnc_display* self = userdata;
|
2021-09-19 20:12:30 +00:00
|
|
|
|
2022-06-26 13:52:45 +00:00
|
|
|
DTRACE_PROBE2(neatvnc, nvnc_display__on_resampler_done, self, fb->pts);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
assert(self->server);
|
2021-12-24 16:29:37 +00:00
|
|
|
|
|
|
|
// TODO: Shift according to display position
|
2021-09-19 20:12:30 +00:00
|
|
|
nvnc__damage_region(self->server, damage);
|
|
|
|
}
|
|
|
|
|
2020-04-12 18:16:19 +00:00
|
|
|
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;
|
|
|
|
|
2021-09-19 21:42:16 +00:00
|
|
|
self->resampler = resampler_create();
|
2021-09-20 21:15:32 +00:00
|
|
|
if (!self->resampler)
|
|
|
|
goto resampler_failure;
|
|
|
|
|
|
|
|
if (damage_refinery_init(&self->damage_refinery, 0, 0) < 0)
|
|
|
|
goto refinery_failure;
|
2021-09-19 20:12:30 +00:00
|
|
|
|
2020-04-12 18:16:19 +00:00
|
|
|
self->ref = 1;
|
|
|
|
self->x_pos = x_pos;
|
|
|
|
self->y_pos = y_pos;
|
|
|
|
|
|
|
|
return self;
|
2021-09-20 21:15:32 +00:00
|
|
|
|
|
|
|
refinery_failure:
|
|
|
|
resampler_destroy(self->resampler);
|
|
|
|
resampler_failure:
|
|
|
|
free(self);
|
|
|
|
|
|
|
|
return NULL;
|
2020-04-12 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 23:42:55 +00:00
|
|
|
static void nvnc__display_free(struct nvnc_display* self)
|
2020-04-12 18:16:19 +00:00
|
|
|
{
|
2021-09-04 20:46:48 +00:00
|
|
|
if (self->buffer) {
|
|
|
|
nvnc_fb_release(self->buffer);
|
2020-04-12 18:16:19 +00:00
|
|
|
nvnc_fb_unref(self->buffer);
|
2021-09-04 20:46:48 +00:00
|
|
|
}
|
2021-09-20 21:15:32 +00:00
|
|
|
damage_refinery_destroy(&self->damage_refinery);
|
2021-09-19 21:42:16 +00:00
|
|
|
resampler_destroy(self->resampler);
|
2020-04-12 18:16:19 +00:00
|
|
|
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)
|
2020-04-12 18:16:19 +00:00
|
|
|
{
|
2022-06-26 13:52:45 +00:00
|
|
|
DTRACE_PROBE2(neatvnc, nvnc_display_feed_buffer, self, fb->pts);
|
|
|
|
|
2021-12-25 16:03:18 +00:00
|
|
|
struct nvnc* server = self->server;
|
|
|
|
assert(server);
|
2021-09-20 21:15:32 +00:00
|
|
|
|
|
|
|
struct pixman_region16 refined_damage;
|
|
|
|
pixman_region_init(&refined_damage);
|
2021-12-25 16:03:18 +00:00
|
|
|
|
|
|
|
if (server->n_damage_clients != 0) {
|
|
|
|
damage_refinery_resize(&self->damage_refinery, fb->width,
|
|
|
|
fb->height);
|
|
|
|
|
|
|
|
// TODO: Run the refinery in a worker thread?
|
|
|
|
damage_refine(&self->damage_refinery, &refined_damage, damage, fb);
|
|
|
|
damage = &refined_damage;
|
|
|
|
} else {
|
|
|
|
// Resizing to zero causes the damage refinery to be reset when
|
|
|
|
// it's needed.
|
|
|
|
damage_refinery_resize(&self->damage_refinery, 0, 0);
|
|
|
|
}
|
2021-09-20 21:15:32 +00:00
|
|
|
|
|
|
|
struct pixman_region16 transformed_damage;
|
|
|
|
pixman_region_init(&transformed_damage);
|
2021-12-25 16:03:18 +00:00
|
|
|
nvnc_transform_region(&transformed_damage, damage, fb->transform,
|
|
|
|
fb->width, fb->height);
|
2021-09-20 21:15:32 +00:00
|
|
|
|
|
|
|
resampler_feed(self->resampler, fb, &transformed_damage,
|
2021-09-19 21:42:16 +00:00
|
|
|
nvnc_display__on_resampler_done, self);
|
2021-09-20 21:15:32 +00:00
|
|
|
|
2021-12-11 20:58:14 +00:00
|
|
|
pixman_region_fini(&transformed_damage);
|
2021-09-20 21:15:32 +00:00
|
|
|
pixman_region_fini(&refined_damage);
|
2020-04-12 18:16:19 +00:00
|
|
|
}
|