Commit 2e348e39 authored by Brendan Shanks's avatar Brendan Shanks Committed by Jeremy White
Browse files

Create separate shm_segment_t struct for SHM segments


Signed-off-by: Brendan Shanks's avatarBrendan Shanks <bshanks@codeweavers.com>
Acked-by: Jeremy White's avatarJeremy White <jwhite@codeweavers.com>
parent 80030410
...@@ -83,4 +83,5 @@ indent "$fname" \ ...@@ -83,4 +83,5 @@ indent "$fname" \
-T x11spice_server_t \ -T x11spice_server_t \
-T test_t \ -T test_t \
-T Bool \ -T Bool \
-T shm_segment_t \
"$@" "$@"
...@@ -349,20 +349,20 @@ shm_image_t *create_shm_image(display_t *d, unsigned int w, unsigned int h) ...@@ -349,20 +349,20 @@ shm_image_t *create_shm_image(display_t *d, unsigned int w, unsigned int h)
shmi->bytes_per_line = (bits_per_pixel(d) / 8) * shmi->w; shmi->bytes_per_line = (bits_per_pixel(d) / 8) * shmi->w;
imgsize = shmi->bytes_per_line * shmi->h; imgsize = shmi->bytes_per_line * shmi->h;
shmi->shmid = shmget(IPC_PRIVATE, imgsize, IPC_CREAT | 0700); shmi->segment.shmid = shmget(IPC_PRIVATE, imgsize, IPC_CREAT | 0700);
if (shmi->shmid != -1) if (shmi->segment.shmid != -1)
shmi->shmaddr = shmat(shmi->shmid, 0, 0); shmi->segment.shmaddr = shmat(shmi->segment.shmid, 0, 0);
if (shmi->shmid == -1 || shmi->shmaddr == (void *) -1) { if (shmi->segment.shmid == -1 || shmi->segment.shmaddr == (void *) -1) {
g_warning("Cannot get shared memory of size %" G_GSIZE_FORMAT "; errno %d", imgsize, errno); g_warning("Cannot get shared memory of size %" G_GSIZE_FORMAT "; errno %d", imgsize, errno);
free(shmi); free(shmi);
return NULL; return NULL;
} }
/* We tell shmctl to detach now; that prevents us from holding this /* We tell shmctl to detach now; that prevents us from holding this
shared memory segment forever in case of abnormal process exit. */ shared memory segment forever in case of abnormal process exit. */
shmctl(shmi->shmid, IPC_RMID, NULL); shmctl(shmi->segment.shmid, IPC_RMID, NULL);
shmi->shmseg = xcb_generate_id(d->c); shmi->segment.shmseg = xcb_generate_id(d->c);
cookie = xcb_shm_attach_checked(d->c, shmi->shmseg, shmi->shmid, 0); cookie = xcb_shm_attach_checked(d->c, shmi->segment.shmseg, shmi->segment.shmid, 0);
error = xcb_request_check(d->c, cookie); error = xcb_request_check(d->c, cookie);
if (error) { if (error) {
g_warning("Could not attach; type %d; code %d; major %d; minor %d\n", g_warning("Could not attach; type %d; code %d; major %d; minor %d\n",
...@@ -380,7 +380,7 @@ int read_shm_image(display_t *d, shm_image_t *shmi, int x, int y) ...@@ -380,7 +380,7 @@ int read_shm_image(display_t *d, shm_image_t *shmi, int x, int y)
xcb_shm_get_image_reply_t *reply; xcb_shm_get_image_reply_t *reply;
cookie = xcb_shm_get_image(d->c, d->root, x, y, shmi->w, shmi->h, cookie = xcb_shm_get_image(d->c, d->root, x, y, shmi->w, shmi->h,
~0, XCB_IMAGE_FORMAT_Z_PIXMAP, shmi->shmseg, 0); ~0, XCB_IMAGE_FORMAT_Z_PIXMAP, shmi->segment.shmseg, 0);
reply = xcb_shm_get_image_reply(d->c, cookie, &e); reply = xcb_shm_get_image_reply(d->c, cookie, &e);
if (e) { if (e) {
...@@ -401,8 +401,8 @@ int display_find_changed_tiles(display_t *d, int row, int *tiles, int tiles_acro ...@@ -401,8 +401,8 @@ int display_find_changed_tiles(display_t *d, int row, int *tiles, int tiles_acro
memset(tiles, 0, sizeof(*tiles) * tiles_across); memset(tiles, 0, sizeof(*tiles) * tiles_across);
ret = read_shm_image(d, d->scanline, 0, row); ret = read_shm_image(d, d->scanline, 0, row);
if (ret == 0) { if (ret == 0) {
uint32_t *old = ((uint32_t *) d->fullscreen->shmaddr) + row * d->fullscreen->w; uint32_t *old = ((uint32_t *) d->fullscreen->segment.shmaddr) + row * d->fullscreen->w;
uint32_t *new = ((uint32_t *) d->scanline->shmaddr); uint32_t *new = ((uint32_t *) d->scanline->segment.shmaddr);
if (memcmp(old, new, sizeof(*old) * d->scanline->w) == 0) if (memcmp(old, new, sizeof(*old) * d->scanline->w) == 0)
return 0; return 0;
...@@ -430,8 +430,8 @@ int display_find_changed_tiles(display_t *d, int row, int *tiles, int tiles_acro ...@@ -430,8 +430,8 @@ int display_find_changed_tiles(display_t *d, int row, int *tiles, int tiles_acro
void display_copy_image_into_fullscreen(display_t *d, shm_image_t *shmi, int x, int y) void display_copy_image_into_fullscreen(display_t *d, shm_image_t *shmi, int x, int y)
{ {
uint32_t *to = ((uint32_t *) d->fullscreen->shmaddr) + (y * d->fullscreen->w) + x; uint32_t *to = ((uint32_t *) d->fullscreen->segment.shmaddr) + (y * d->fullscreen->w) + x;
uint32_t *from = ((uint32_t *) shmi->shmaddr); uint32_t *from = ((uint32_t *) shmi->segment.shmaddr);
int i; int i;
/* Ignore invalid draws. This can happen if the screen is resized after a scan /* Ignore invalid draws. This can happen if the screen is resized after a scan
...@@ -451,9 +451,9 @@ void display_copy_image_into_fullscreen(display_t *d, shm_image_t *shmi, int x, ...@@ -451,9 +451,9 @@ void display_copy_image_into_fullscreen(display_t *d, shm_image_t *shmi, int x,
void destroy_shm_image(display_t *d, shm_image_t *shmi) void destroy_shm_image(display_t *d, shm_image_t *shmi)
{ {
xcb_shm_detach(d->c, shmi->shmseg); xcb_shm_detach(d->c, shmi->segment.shmseg);
shmdt(shmi->shmaddr); shmdt(shmi->segment.shmaddr);
shmctl(shmi->shmid, IPC_RMID, NULL); shmctl(shmi->segment.shmid, IPC_RMID, NULL);
if (shmi->drawable_ptr) if (shmi->drawable_ptr)
free(shmi->drawable_ptr); free(shmi->drawable_ptr);
free(shmi); free(shmi);
......
...@@ -33,11 +33,15 @@ struct session_struct; ...@@ -33,11 +33,15 @@ struct session_struct;
**--------------------------------------------------------------------------*/ **--------------------------------------------------------------------------*/
typedef struct { typedef struct {
int shmid; int shmid;
xcb_shm_seg_t shmseg;
void *shmaddr;
} shm_segment_t;
typedef struct {
shm_segment_t segment;
unsigned int w; unsigned int w;
unsigned int h; unsigned int h;
unsigned int bytes_per_line; unsigned int bytes_per_line;
xcb_shm_seg_t shmseg;
void *shmaddr;
void *drawable_ptr; void *drawable_ptr;
} shm_image_t; } shm_image_t;
......
...@@ -106,7 +106,7 @@ static QXLDrawable *shm_image_to_drawable(spice_t *s, shm_image_t *shmi, int x, ...@@ -106,7 +106,7 @@ static QXLDrawable *shm_image_to_drawable(spice_t *s, shm_image_t *shmi, int x,
qxl_image->bitmap.y = shmi->h; qxl_image->bitmap.y = shmi->h;
qxl_image->bitmap.stride = shmi->bytes_per_line; qxl_image->bitmap.stride = shmi->bytes_per_line;
qxl_image->bitmap.palette = 0; qxl_image->bitmap.palette = 0;
qxl_image->bitmap.data = (uintptr_t) shmi->shmaddr; qxl_image->bitmap.data = (uintptr_t) shmi->segment.shmaddr;
return drawable; return drawable;
} }
......
...@@ -353,7 +353,7 @@ int session_recreate_primary(session_t *s) ...@@ -353,7 +353,7 @@ int session_recreate_primary(session_t *s)
rc = display_create_screen_images(&s->display); rc = display_create_screen_images(&s->display);
if (rc == 0) { if (rc == 0) {
shm_image_t *f = s->display.primary; shm_image_t *f = s->display.primary;
rc = spice_create_primary(&s->spice, f->w, f->h, f->bytes_per_line, f->shmaddr); rc = spice_create_primary(&s->spice, f->w, f->h, f->bytes_per_line, f->segment.shmaddr);
} }
g_mutex_unlock(s->lock); g_mutex_unlock(s->lock);
......
...@@ -679,7 +679,7 @@ int spice_start(spice_t *s, options_t *options, shm_image_t *primary) ...@@ -679,7 +679,7 @@ int spice_start(spice_t *s, options_t *options, shm_image_t *primary)
spice_server_vm_start(s->server); spice_server_vm_start(s->server);
rc = spice_create_primary(s, primary->w, primary->h, rc = spice_create_primary(s, primary->w, primary->h,
primary->bytes_per_line, primary->shmaddr); primary->bytes_per_line, primary->segment.shmaddr);
return rc; return rc;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment