resampler: Make resampler object opaque
parent
3b24dbd6a4
commit
943bd33993
|
@ -17,18 +17,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "neatvnc.h"
|
#include "neatvnc.h"
|
||||||
#include "resampler.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <pixels.h>
|
#include <pixels.h>
|
||||||
|
|
||||||
struct nvnc;
|
struct nvnc;
|
||||||
struct nvnc_fb;
|
struct nvnc_fb;
|
||||||
|
struct resampler;
|
||||||
|
|
||||||
struct nvnc_display {
|
struct nvnc_display {
|
||||||
int ref;
|
int ref;
|
||||||
struct nvnc* server;
|
struct nvnc* server;
|
||||||
uint16_t x_pos, y_pos;
|
uint16_t x_pos, y_pos;
|
||||||
struct nvnc_fb* buffer;
|
struct nvnc_fb* buffer;
|
||||||
struct resampler resampler;
|
struct resampler* resampler;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct nvnc_fb;
|
struct nvnc_fb;
|
||||||
struct nvnc_fb_pool;
|
|
||||||
struct pixman_region16;
|
struct pixman_region16;
|
||||||
|
|
||||||
struct resampler {
|
struct resampler;
|
||||||
struct nvnc_fb_pool *pool;
|
|
||||||
void (*on_done)(struct resampler*, struct nvnc_fb*,
|
|
||||||
struct pixman_region16* damage);
|
|
||||||
};
|
|
||||||
|
|
||||||
int resampler_init(struct resampler*);
|
typedef void (*resampler_fn)(struct nvnc_fb*, struct pixman_region16* damage,
|
||||||
|
void* userdata);
|
||||||
|
|
||||||
|
struct resampler* resampler_create(void);
|
||||||
void resampler_destroy(struct resampler*);
|
void resampler_destroy(struct resampler*);
|
||||||
|
|
||||||
int resampler_feed(struct resampler*, struct nvnc_fb* fb,
|
int resampler_feed(struct resampler*, struct nvnc_fb* fb,
|
||||||
struct pixman_region16* damage);
|
struct pixman_region16* damage, resampler_fn on_done,
|
||||||
|
void* userdata);
|
||||||
|
|
|
@ -18,18 +18,17 @@
|
||||||
#include "neatvnc.h"
|
#include "neatvnc.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fb.h"
|
#include "fb.h"
|
||||||
#include "type-macros.h"
|
#include "resampler.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define EXPORT __attribute__((visibility("default")))
|
#define EXPORT __attribute__((visibility("default")))
|
||||||
|
|
||||||
static void nvnc_display__on_resampler_done(struct resampler* resampler,
|
static void nvnc_display__on_resampler_done(struct nvnc_fb* fb,
|
||||||
struct nvnc_fb* fb, struct pixman_region16* damage)
|
struct pixman_region16* damage, void* userdata)
|
||||||
{
|
{
|
||||||
struct nvnc_display* self = container_of(resampler, struct nvnc_display,
|
struct nvnc_display* self = userdata;
|
||||||
resampler);
|
|
||||||
|
|
||||||
if (self->buffer) {
|
if (self->buffer) {
|
||||||
nvnc_fb_release(self->buffer);
|
nvnc_fb_release(self->buffer);
|
||||||
|
@ -52,7 +51,8 @@ struct nvnc_display* nvnc_display_new(uint16_t x_pos, uint16_t y_pos)
|
||||||
if (!self)
|
if (!self)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (resampler_init(&self->resampler) < 0) {
|
self->resampler = resampler_create();
|
||||||
|
if (!self->resampler) {
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ struct nvnc_display* nvnc_display_new(uint16_t x_pos, uint16_t y_pos)
|
||||||
self->ref = 1;
|
self->ref = 1;
|
||||||
self->x_pos = x_pos;
|
self->x_pos = x_pos;
|
||||||
self->y_pos = y_pos;
|
self->y_pos = y_pos;
|
||||||
self->resampler.on_done = nvnc_display__on_resampler_done;
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +70,7 @@ static void nvnc__display_free(struct nvnc_display* self)
|
||||||
nvnc_fb_release(self->buffer);
|
nvnc_fb_release(self->buffer);
|
||||||
nvnc_fb_unref(self->buffer);
|
nvnc_fb_unref(self->buffer);
|
||||||
}
|
}
|
||||||
resampler_destroy(&self->resampler);
|
resampler_destroy(self->resampler);
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,5 +97,6 @@ EXPORT
|
||||||
void nvnc_display_feed_buffer(struct nvnc_display* self, struct nvnc_fb* fb,
|
void nvnc_display_feed_buffer(struct nvnc_display* self, struct nvnc_fb* fb,
|
||||||
struct pixman_region16* damage)
|
struct pixman_region16* damage)
|
||||||
{
|
{
|
||||||
resampler_feed(&self->resampler, fb, damage);
|
resampler_feed(self->resampler, fb, damage,
|
||||||
|
nvnc_display__on_resampler_done, self);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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 "resampler.h"
|
#include "resampler.h"
|
||||||
#include "neatvnc.h"
|
#include "neatvnc.h"
|
||||||
#include "fb.h"
|
#include "fb.h"
|
||||||
|
@ -10,11 +26,16 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libdrm/drm_fourcc.h>
|
#include <libdrm/drm_fourcc.h>
|
||||||
|
|
||||||
|
struct resampler {
|
||||||
|
struct nvnc_fb_pool *pool;
|
||||||
|
};
|
||||||
|
|
||||||
struct resampler_work {
|
struct resampler_work {
|
||||||
struct pixman_region16 damage;
|
struct pixman_region16 damage;
|
||||||
struct nvnc_fb* src;
|
struct nvnc_fb* src;
|
||||||
struct nvnc_fb* dst;
|
struct nvnc_fb* dst;
|
||||||
struct resampler* resampler;
|
resampler_fn on_done;
|
||||||
|
void* userdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void resampler_work_free(void* userdata)
|
static void resampler_work_free(void* userdata)
|
||||||
|
@ -31,15 +52,25 @@ static void resampler_work_free(void* userdata)
|
||||||
free(work);
|
free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resampler_init(struct resampler* self)
|
struct resampler* resampler_create(void)
|
||||||
{
|
{
|
||||||
|
struct resampler* self = calloc(1, sizeof(*self));
|
||||||
|
if (!self)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
self->pool = nvnc_fb_pool_new(0, 0, DRM_FORMAT_INVALID, 0);
|
self->pool = nvnc_fb_pool_new(0, 0, DRM_FORMAT_INVALID, 0);
|
||||||
return self->pool ? 0 : -1;
|
if (!self->pool) {
|
||||||
|
free(self);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_destroy(struct resampler* self)
|
void resampler_destroy(struct resampler* self)
|
||||||
{
|
{
|
||||||
nvnc_fb_pool_unref(self->pool);
|
nvnc_fb_pool_unref(self->pool);
|
||||||
|
free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_work(void* handle)
|
static void do_work(void* handle)
|
||||||
|
@ -93,14 +124,15 @@ static void on_work_done(void* handle)
|
||||||
struct aml_work* work = handle;
|
struct aml_work* work = handle;
|
||||||
struct resampler_work* ctx = aml_get_userdata(work);
|
struct resampler_work* ctx = aml_get_userdata(work);
|
||||||
|
|
||||||
ctx->resampler->on_done(ctx->resampler, ctx->dst, &ctx->damage);
|
ctx->on_done(ctx->dst, &ctx->damage, ctx->userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resampler_feed(struct resampler* self, struct nvnc_fb* fb,
|
int resampler_feed(struct resampler* self, struct nvnc_fb* fb,
|
||||||
struct pixman_region16* damage)
|
struct pixman_region16* damage, resampler_fn on_done,
|
||||||
|
void* userdata)
|
||||||
{
|
{
|
||||||
if (fb->transform == NVNC_TRANSFORM_NORMAL) {
|
if (fb->transform == NVNC_TRANSFORM_NORMAL) {
|
||||||
self->on_done(self, fb, damage);
|
on_done(fb, damage, userdata);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +159,8 @@ int resampler_feed(struct resampler* self, struct nvnc_fb* fb,
|
||||||
nvnc_fb_ref(fb);
|
nvnc_fb_ref(fb);
|
||||||
nvnc_fb_hold(fb);
|
nvnc_fb_hold(fb);
|
||||||
|
|
||||||
ctx->resampler = self;
|
ctx->on_done = on_done;
|
||||||
|
ctx->userdata = userdata;
|
||||||
|
|
||||||
struct aml_work* work = aml_work_new(do_work, on_work_done, ctx,
|
struct aml_work* work = aml_work_new(do_work, on_work_done, ctx,
|
||||||
resampler_work_free);
|
resampler_work_free);
|
||||||
|
|
Loading…
Reference in New Issue