[PATCH x11spice v3 2/3] Create separate shm_segment_t struct for SHM segments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Brendan Shanks <bshanks@xxxxxxxxxxxxxxx>
---
 doc/spice_indent |  1 +
 src/display.c    | 30 +++++++++++++++---------------
 src/display.h    |  8 ++++++--
 src/scan.c       |  2 +-
 src/session.c    |  2 +-
 src/spice.c      |  2 +-
 6 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/doc/spice_indent b/doc/spice_indent
index 6abd1a0..ce5c82c 100755
--- a/doc/spice_indent
+++ b/doc/spice_indent
@@ -83,4 +83,5 @@ indent "$fname" \
   -T x11spice_server_t \
   -T test_t \
   -T Bool \
+  -T shm_segment_t \
   "$@"
diff --git a/src/display.c b/src/display.c
index 3294f83..a2a18b8 100644
--- a/src/display.c
+++ b/src/display.c
@@ -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;
     imgsize = shmi->bytes_per_line * shmi->h;
 
-    shmi->shmid = shmget(IPC_PRIVATE, imgsize, IPC_CREAT | 0700);
-    if (shmi->shmid != -1)
-        shmi->shmaddr = shmat(shmi->shmid, 0, 0);
-    if (shmi->shmid == -1 || shmi->shmaddr == (void *) -1) {
+    shmi->segment.shmid = shmget(IPC_PRIVATE, imgsize, IPC_CREAT | 0700);
+    if (shmi->segment.shmid != -1)
+        shmi->segment.shmaddr = shmat(shmi->segment.shmid, 0, 0);
+    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);
         free(shmi);
         return NULL;
     }
     /* We tell shmctl to detach now; that prevents us from holding this
        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);
-    cookie = xcb_shm_attach_checked(d->c, shmi->shmseg, shmi->shmid, 0);
+    shmi->segment.shmseg = xcb_generate_id(d->c);
+    cookie = xcb_shm_attach_checked(d->c, shmi->segment.shmseg, shmi->segment.shmid, 0);
     error = xcb_request_check(d->c, cookie);
     if (error) {
         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)
     xcb_shm_get_image_reply_t *reply;
 
     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);
     if (e) {
@@ -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);
     ret = read_shm_image(d, d->scanline, 0, row);
     if (ret == 0) {
-        uint32_t *old = ((uint32_t *) d->fullscreen->shmaddr) + row * d->fullscreen->w;
-        uint32_t *new = ((uint32_t *) d->scanline->shmaddr);
+        uint32_t *old = ((uint32_t *) d->fullscreen->segment.shmaddr) + row * d->fullscreen->w;
+        uint32_t *new = ((uint32_t *) d->scanline->segment.shmaddr);
         if (memcmp(old, new, sizeof(*old) * d->scanline->w) == 0)
             return 0;
 
@@ -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)
 {
-    uint32_t *to = ((uint32_t *) d->fullscreen->shmaddr) + (y * d->fullscreen->w) + x;
-    uint32_t *from = ((uint32_t *) shmi->shmaddr);
+    uint32_t *to = ((uint32_t *) d->fullscreen->segment.shmaddr) + (y * d->fullscreen->w) + x;
+    uint32_t *from = ((uint32_t *) shmi->segment.shmaddr);
     int i;
 
     /* 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,
 
 void destroy_shm_image(display_t *d, shm_image_t *shmi)
 {
-    xcb_shm_detach(d->c, shmi->shmseg);
-    shmdt(shmi->shmaddr);
-    shmctl(shmi->shmid, IPC_RMID, NULL);
+    xcb_shm_detach(d->c, shmi->segment.shmseg);
+    shmdt(shmi->segment.shmaddr);
+    shmctl(shmi->segment.shmid, IPC_RMID, NULL);
     if (shmi->drawable_ptr)
         free(shmi->drawable_ptr);
     free(shmi);
diff --git a/src/display.h b/src/display.h
index 07ac3c0..da1b991 100644
--- a/src/display.h
+++ b/src/display.h
@@ -33,11 +33,15 @@ struct session_struct;
 **--------------------------------------------------------------------------*/
 typedef struct {
     int shmid;
+    xcb_shm_seg_t shmseg;
+    void *shmaddr;
+} shm_segment_t;
+
+typedef struct {
+    shm_segment_t segment;
     unsigned int w;
     unsigned int h;
     unsigned int bytes_per_line;
-    xcb_shm_seg_t shmseg;
-    void *shmaddr;
     void *drawable_ptr;
 } shm_image_t;
 
diff --git a/src/scan.c b/src/scan.c
index aa10a07..6ee399c 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -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.stride = shmi->bytes_per_line;
     qxl_image->bitmap.palette = 0;
-    qxl_image->bitmap.data = (uintptr_t) shmi->shmaddr;
+    qxl_image->bitmap.data = (uintptr_t) shmi->segment.shmaddr;
 
     return drawable;
 }
diff --git a/src/session.c b/src/session.c
index 4d72e14..bdd550d 100644
--- a/src/session.c
+++ b/src/session.c
@@ -353,7 +353,7 @@ int session_recreate_primary(session_t *s)
     rc = display_create_screen_images(&s->display);
     if (rc == 0) {
         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);
diff --git a/src/spice.c b/src/spice.c
index cf7118f..08a5d09 100644
--- a/src/spice.c
+++ b/src/spice.c
@@ -679,7 +679,7 @@ int spice_start(spice_t *s, options_t *options, shm_image_t *primary)
     spice_server_vm_start(s->server);
 
     rc = spice_create_primary(s, primary->w, primary->h,
-                              primary->bytes_per_line, primary->shmaddr);
+                              primary->bytes_per_line, primary->segment.shmaddr);
 
     return rc;
 }
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]