[Spice-devel] [PATCH 13/15] worker: move shadow_new() and container_new()

Frediano Ziglio fziglio at redhat.com
Wed Nov 4 04:35:14 PST 2015


Updated proposed patch


[PATCH] worker: move shadow_new() and container_new()

---
 server/red_worker.c | 49 +++++++------------------------------------------
 server/tree.c       | 39 +++++++++++++++++++++++++++++++++++++++
 server/tree.h       |  9 +++++++++
 3 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index ced6c16..4424269 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -1617,24 +1617,6 @@ static void exclude_region(RedWorker *worker, Ring *ring, RingItem *ring_item, Q
     }
 }
 
-static inline Container *__new_container(RedWorker *worker, DrawItem *item)
-{
-    Container *container = spice_new(Container, 1);
-    worker->containers_count++;
-    container->base.type = TREE_ITEM_TYPE_CONTAINER;
-    container->base.container = item->base.container;
-    item->base.container = container;
-    item->container_root = TRUE;
-    region_clone(&container->base.rgn, &item->base.rgn);
-    ring_item_init(&container->base.siblings_link);
-    ring_add_after(&container->base.siblings_link, &item->base.siblings_link);
-    ring_remove(&item->base.siblings_link);
-    ring_init(&container->items);
-    ring_add(&container->items, &item->base.siblings_link);
-
-    return container;
-}
-
 static inline int is_opaque_item(TreeItem *item)
 {
     return item->type == TREE_ITEM_TYPE_CONTAINER ||
@@ -2942,8 +2924,8 @@ static inline int red_current_add(RedWorker *worker, Ring *ring, Drawable *drawa
                     continue;
                 }
                 spice_assert(IS_DRAW_ITEM(sibling));
-                if (!((DrawItem *)sibling)->container_root) {
-                    container = __new_container(worker, (DrawItem *)sibling);
+                if (!DRAW_ITEM(sibling)->container_root) {
+                    container = container_new(DRAW_ITEM(sibling));
                     if (!container) {
                         spice_warning("create new container failed");
                         region_destroy(&exclude_rgn);
@@ -2977,7 +2959,7 @@ static inline int red_current_add(RedWorker *worker, Ring *ring, Drawable *drawa
          * before calling red_detach_streams_behind
          */
         __current_add_drawable(worker, drawable, ring);
-        if (drawable->surface_id == 0) {
+        if (is_primary_surface(worker, drawable->surface_id)) {
             red_detach_streams_behind(worker, &drawable->tree_item.base.rgn, drawable);
         }
     }
@@ -2995,25 +2977,6 @@ static void add_clip_rects(QRegion *rgn, SpiceClipRects *data)
     }
 }
 
-static inline Shadow *__new_shadow(RedWorker *worker, Drawable *item, SpicePoint *delta)
-{
-    if (!delta->x && !delta->y) {
-        return NULL;
-    }
-
-    Shadow *shadow = spice_new(Shadow, 1);
-    worker->shadows_count++;
-    shadow->base.type = TREE_ITEM_TYPE_SHADOW;
-    shadow->base.container = NULL;
-    shadow->owner = &item->tree_item;
-    region_clone(&shadow->base.rgn, &item->tree_item.base.rgn);
-    region_offset(&shadow->base.rgn, delta->x, delta->y);
-    ring_item_init(&shadow->base.siblings_link);
-    region_init(&shadow->on_hold);
-    item->tree_item.shadow = shadow;
-    return shadow;
-}
-
 static inline int red_current_add_with_shadow(RedWorker *worker, Ring *ring, Drawable *item)
 {
 #ifdef RED_WORKER_STAT
@@ -3027,11 +2990,12 @@ static inline int red_current_add_with_shadow(RedWorker *worker, Ring *ring, Dra
         .y = red_drawable->u.copy_bits.src_pos.y - red_drawable->bbox.top
     };
 
-    Shadow *shadow = __new_shadow(worker, item, &delta);
+    Shadow *shadow = shadow_new(&item->tree_item, &delta);
     if (!shadow) {
         stat_add(&worker->add_stat, start_time);
         return FALSE;
     }
+    worker->shadows_count++;
     // item and his shadow must initially be placed in the same container.
     // for now putting them on root.
 
@@ -3039,6 +3003,7 @@ static inline int red_current_add_with_shadow(RedWorker *worker, Ring *ring, Dra
     if (is_primary_surface(worker, item->surface_id)) {
         red_detach_streams_behind(worker, &shadow->base.rgn, NULL);
     }
+
     ring_add(ring, &shadow->base.siblings_link);
     __current_add_drawable(worker, item, ring);
     if (item->tree_item.effect == QXL_EFFECT_OPAQUE) {
@@ -3048,7 +3013,7 @@ static inline int red_current_add_with_shadow(RedWorker *worker, Ring *ring, Dra
         region_destroy(&exclude_rgn);
         red_streams_update_visible_region(worker, item);
     } else {
-        if (item->surface_id == 0) {
+        if (is_primary_surface(worker, item->surface_id)) {
             red_detach_streams_behind(worker, &item->tree_item.base.rgn, item);
         }
     }
diff --git a/server/tree.c b/server/tree.c
index ed7d39a..64fa6db 100644
--- a/server/tree.c
+++ b/server/tree.c
@@ -180,3 +180,42 @@ void tree_item_dump(TreeItem *item)
     spice_return_if_fail(item != NULL);
     tree_foreach(item, dump_item, &di);
 }
+
+Shadow* shadow_new(DrawItem *item, const SpicePoint *delta)
+{
+    spice_return_val_if_fail(item->shadow == NULL, NULL);
+    if (!delta->x && !delta->y) {
+        return NULL;
+    }
+
+    Shadow *shadow = spice_new(Shadow, 1);
+
+    shadow->base.type = TREE_ITEM_TYPE_SHADOW;
+    shadow->base.container = NULL;
+    shadow->owner = item;
+    region_clone(&shadow->base.rgn, &item->base.rgn);
+    region_offset(&shadow->base.rgn, delta->x, delta->y);
+    ring_item_init(&shadow->base.siblings_link);
+    region_init(&shadow->on_hold);
+    item->shadow = shadow;
+
+    return shadow;
+}
+
+Container* container_new(DrawItem *item)
+{
+    Container *container = spice_new(Container, 1);
+
+    container->base.type = TREE_ITEM_TYPE_CONTAINER;
+    container->base.container = item->base.container;
+    item->base.container = container;
+    item->container_root = TRUE;
+    region_clone(&container->base.rgn, &item->base.rgn);
+    ring_item_init(&container->base.siblings_link);
+    ring_add_after(&container->base.siblings_link, &item->base.siblings_link);
+    ring_remove(&item->base.siblings_link);
+    ring_init(&container->items);
+    ring_add(&container->items, &item->base.siblings_link);
+
+    return container;
+}
diff --git a/server/tree.h b/server/tree.h
index e10fa1c..1b334b0 100644
--- a/server/tree.h
+++ b/server/tree.h
@@ -52,11 +52,17 @@ struct Shadow {
     DrawItem* owner;
 };
 
+#define IS_SHADOW(item) ((item)->type == TREE_ITEM_TYPE_SHADOW)
+#define SHADOW(item) ((Shadow*)(item))
+
 struct Container {
     TreeItem base;
     Ring items;
 };
 
+#define IS_CONTAINER(item) ((item)->type == TREE_ITEM_TYPE_CONTAINER)
+#define CONTAINER(item) ((Container*)(item))
+
 struct DrawItem {
     TreeItem base;
     uint8_t effect;
@@ -65,6 +71,7 @@ struct DrawItem {
 };
 
 #define IS_DRAW_ITEM(item) ((item)->type == TREE_ITEM_TYPE_DRAWABLE)
+#define DRAW_ITEM(item) ((DrawItem*)(item))
 
 typedef struct DependItem {
     Drawable *drawable;
@@ -101,5 +108,7 @@ struct Drawable {
 };
 
 void       tree_item_dump                           (TreeItem *item);
+Shadow*    shadow_new                               (DrawItem *item, const SpicePoint *delta);
+Container* container_new                            (DrawItem *item);
 
 #endif /* TREE_H_ */
-- 
2.4.3


More information about the Spice-devel mailing list