Skip to content

Commit

Permalink
move to posix shm
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorg71 committed Aug 13, 2023
1 parent 67c297d commit 4b1482b
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
6 changes: 6 additions & 0 deletions xrdp/xrdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ server_set_pointer_large(struct xrdp_mod *mod, int x, int y,
char *data, char *mask, int bpp,
int width, int height);
int
server_paint_rects_ex(struct xrdp_mod *mod, int num_drects, short *drects,
int num_crects, short *crects,
char *data, int left, int top,
int width, int height,
int flags, int frame_id);
int
server_palette(struct xrdp_mod *mod, int *palette);
int
server_msg(struct xrdp_mod *mod, const char *msg, int code);
Expand Down
2 changes: 2 additions & 0 deletions xrdp/xrdp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct xrdp_enc_data
int num_crects;
short *crects; /* 4 * num_crects */
char *data;
int left;
int top;
int width;
int height;
int flags;
Expand Down
14 changes: 14 additions & 0 deletions xrdp/xrdp_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ xrdp_mm_setup_mod1(struct xrdp_mm *self)
self->mod->server_paint_rects = server_paint_rects;
self->mod->server_session_info = server_session_info;
self->mod->server_set_pointer_large = server_set_pointer_large;
self->mod->server_paint_rects_ex = server_paint_rects_ex;
self->mod->si = &(self->wm->session->si);
}
}
Expand Down Expand Up @@ -3357,6 +3358,17 @@ int
server_paint_rects(struct xrdp_mod *mod, int num_drects, short *drects,
int num_crects, short *crects, char *data, int width,
int height, int flags, int frame_id)
{
return server_paint_rects_ex(mod, num_drects, drects, num_crects, crects,
data, 0, 0, width, height, flags, frame_id);
}

/*****************************************************************************/
int
server_paint_rects_ex(struct xrdp_mod *mod, int num_drects, short *drects,
int num_crects, short *crects, char *data,
int left, int top, int width, int height,
int flags, int frame_id)
{
struct xrdp_wm *wm;
struct xrdp_mm *mm;
Expand Down Expand Up @@ -3404,6 +3416,8 @@ server_paint_rects(struct xrdp_mod *mod, int num_drects, short *drects,
enc_data->num_drects = num_drects;
enc_data->num_crects = num_crects;
enc_data->data = data;
enc_data->left = left;
enc_data->top = top;
enc_data->width = width;
enc_data->height = height;
enc_data->flags = flags;
Expand Down
8 changes: 7 additions & 1 deletion xrdp/xrdp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ struct xrdp_mod
int (*server_set_pointer_large)(struct xrdp_mod *v, int x, int y,
char *data, char *mask, int bpp,
int width, int height);
tintptr server_dumby[100 - 47]; /* align, 100 minus the number of server
int (*server_paint_rects_ex)(struct xrdp_mod *v,
int num_drects, short *drects,
int num_crects, short *crects,
char *data, int left, int top,
int width, int height,
int flags, int frame_id);
tintptr server_dumby[100 - 48]; /* align, 100 minus the number of server
functions above */
/* common */
tintptr handle; /* pointer to self as int */
Expand Down
99 changes: 99 additions & 0 deletions xup/xup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,102 @@ process_server_set_pointer_shmfd(struct mod *amod, struct stream *s)
return rv;
}

/******************************************************************************/
/* return error */
static int
process_server_paint_rect_shmfd(struct mod *amod, struct stream *s)
{
int num_drects;
int num_crects;
int flags;
int frame_id;
int shmem_bytes;
int shmem_offset;
int left;
int top;
int width;
int height;
int index;
int rv;
int16_t *ldrects;
int16_t *ldrects1;
int16_t *lcrects;
int16_t *lcrects1;
char *bmpdata;
int fd;
int recv_bytes;
unsigned int num_fds;
void *shmem_ptr;
char msg[4];

/* dirty pixels */
in_uint16_le(s, num_drects);
ldrects = g_new(int16_t, 2 * 4 * num_drects);
ldrects1 = ldrects;
for (index = 0; index < num_drects; index++)
{
in_sint16_le(s, ldrects1[0]);
in_sint16_le(s, ldrects1[1]);
in_sint16_le(s, ldrects1[2]);
in_sint16_le(s, ldrects1[3]);
ldrects1 += 4;
}

/* copied pixels */
in_uint16_le(s, num_crects);
lcrects = g_new(int16_t, 2 * 4 * num_crects);
lcrects1 = lcrects;
for (index = 0; index < num_crects; index++)
{
in_sint16_le(s, lcrects1[0]);
in_sint16_le(s, lcrects1[1]);
in_sint16_le(s, lcrects1[2]);
in_sint16_le(s, lcrects1[3]);
lcrects1 += 4;
}

in_uint32_le(s, flags);
in_uint32_le(s, frame_id);
in_uint32_le(s, shmem_bytes);
in_uint32_le(s, shmem_offset);

in_uint16_le(s, left);
in_uint16_le(s, top);
in_uint16_le(s, width);
in_uint16_le(s, height);

if (g_tcp_can_recv(amod->trans->sck, 5000) == 0)
{
g_free(ldrects);
g_free(lcrects);
return 1;
}
rv = 1;
recv_bytes = g_sck_recv_fd_set(amod->trans->sck, msg, 4, &fd, 1, &num_fds);
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_server_paint_rect_shmfd: "
"g_sck_recv_fd_set rv %d fd %d", recv_bytes, fd);
if (recv_bytes == 4)
{
if (num_fds == 1)
{
if (g_file_map(fd, 1, 1, shmem_bytes, &shmem_ptr) == 0)
{
bmpdata = (char *)shmem_ptr;
bmpdata += shmem_offset;
rv = amod->server_paint_rects_ex(amod, num_drects, ldrects,
num_crects, lcrects, bmpdata,
left, top, width, height,
flags, frame_id);
g_munmap(shmem_ptr, shmem_bytes);
}
g_file_close(fd);
}
}
g_free(ldrects);
g_free(lcrects);
return rv;
}

/******************************************************************************/
/* return error */
static int
Expand Down Expand Up @@ -1532,6 +1628,9 @@ lib_mod_process_orders(struct mod *mod, int type, struct stream *s)
case 63: /* server_set_pointer_shmfd */
rv = process_server_set_pointer_shmfd(mod, s);
break;
case 64: /* server_paint_rect_shmfd */
rv = process_server_paint_rect_shmfd(mod, s);
break;
default:
LOG_DEVEL(LOG_LEVEL_WARNING,
"lib_mod_process_orders: unknown order type %d", type);
Expand Down
8 changes: 7 additions & 1 deletion xup/xup.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ struct mod
int (*server_set_pointer_large)(struct mod *v, int x, int y,
char *data, char *mask, int bpp,
int width, int height);
tintptr server_dumby[100 - 47]; /* align, 100 minus the number of server
int (*server_paint_rects_ex)(struct mod *v,
int num_drects, short *drects,
int num_crects, short *crects,
char *data, int left, int top,
int width, int height,
int flags, int frame_id);
tintptr server_dumby[100 - 48]; /* align, 100 minus the number of server
functions above */
/* common */
tintptr handle; /* pointer to self as long */
Expand Down

0 comments on commit 4b1482b

Please sign in to comment.