Use display_channel_surface_has_canvas() instead of free coding it

Submitted by Francois Gouget on March 21, 2019, 10:20 a.m.

Details

Message ID E1h6uoK-0005e9-06@amboise
State New
Headers show
Series "Use display_channel_surface_has_canvas() instead of free coding it" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget March 21, 2019, 10:20 a.m.
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 server/dcc.c             |  2 +-
 server/display-channel.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/dcc.c b/server/dcc.c
index ae7b4380f..a05b6e59e 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -579,7 +579,7 @@  void dcc_start(DisplayChannelClient *dcc)
         return;
 
     red_channel_client_ack_zero_messages_window(rcc);
-    if (display->priv->surfaces[0].context.canvas) {
+    if (display_channel_surface_has_canvas(display, 0)) {
         display_channel_current_flush(display, 0);
         red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE);
         dcc_create_surface(dcc, 0);
diff --git a/server/display-channel.c b/server/display-channel.c
index e179abfd3..cf12e99bf 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -108,7 +108,7 @@  display_channel_finalize(GObject *object)
         spice_assert(ring_is_empty(&self->priv->streams));
 
         for (count = 0; count < NUM_SURFACES; ++count) {
-            spice_assert(self->priv->surfaces[count].context.canvas == NULL);
+            spice_assert(!display_channel_surface_has_canvas(self, count));
         }
     }
 
@@ -1498,7 +1498,7 @@  void display_channel_flush_all_surfaces(DisplayChannel *display)
     int x;
 
     for (x = 0; x < NUM_SURFACES; ++x) {
-        if (display->priv->surfaces[x].context.canvas) {
+        if (display_channel_surface_has_canvas(display, x)) {
             display_channel_current_flush(display, x);
         }
     }
@@ -2072,7 +2072,7 @@  void display_channel_destroy_surface_wait(DisplayChannel *display, uint32_t surf
 {
     if (!display_channel_validate_surface(display, surface_id))
         return;
-    if (!display->priv->surfaces[surface_id].context.canvas)
+    if (!display_channel_surface_has_canvas(display, surface_id))
         return;
 
     draw_depend_on_me(display, surface_id);
@@ -2092,12 +2092,12 @@  void display_channel_destroy_surfaces(DisplayChannel *display)
     spice_debug("trace");
     //to handle better
     for (i = 0; i < NUM_SURFACES; ++i) {
-        if (display->priv->surfaces[i].context.canvas) {
+        if (display_channel_surface_has_canvas(display, i)) {
             display_channel_destroy_surface_wait(display, i);
-            if (display->priv->surfaces[i].context.canvas) {
+            if (display_channel_surface_has_canvas(display, i)) {
                 display_channel_surface_unref(display, i);
             }
-            spice_assert(!display->priv->surfaces[i].context.canvas);
+            spice_assert(!display_channel_surface_has_canvas(display, i));
         }
     }
     spice_warn_if_fail(ring_is_empty(&display->priv->streams));
@@ -2424,7 +2424,7 @@  gboolean display_channel_validate_surface(DisplayChannel *display, uint32_t surf
         spice_warning("invalid surface_id %u", surface_id);
         return FALSE;
     }
-    if (!display->priv->surfaces[surface_id].context.canvas) {
+    if (!display_channel_surface_has_canvas(display, surface_id)) {
         spice_warning("canvas address is %p for %d (and is NULL)",
                    &(display->priv->surfaces[surface_id].context.canvas), surface_id);
         spice_warning("failed on %d", surface_id);
@@ -2462,7 +2462,7 @@  void display_channel_set_monitors_config_to_primary(DisplayChannel *display)
     QXLHead head = { 0, };
     uint16_t old_max = 1;
 
-    spice_return_if_fail(display->priv->surfaces[0].context.canvas);
+    spice_return_if_fail(display_channel_surface_has_canvas(display, 0));
 
     if (display->priv->monitors_config) {
         old_max = display->priv->monitors_config->max_allowed;

Comments

> 
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
> ---
>  server/dcc.c             |  2 +-
>  server/display-channel.c | 16 ++++++++--------
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/server/dcc.c b/server/dcc.c
> index ae7b4380f..a05b6e59e 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -579,7 +579,7 @@ void dcc_start(DisplayChannelClient *dcc)
>          return;
>  
>      red_channel_client_ack_zero_messages_window(rcc);
> -    if (display->priv->surfaces[0].context.canvas) {
> +    if (display_channel_surface_has_canvas(display, 0)) {
>          display_channel_current_flush(display, 0);
>          red_channel_client_pipe_add_type(rcc,
>          RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE);
>          dcc_create_surface(dcc, 0);
> diff --git a/server/display-channel.c b/server/display-channel.c
> index e179abfd3..cf12e99bf 100644
> --- a/server/display-channel.c
> +++ b/server/display-channel.c
> @@ -108,7 +108,7 @@ display_channel_finalize(GObject *object)
>          spice_assert(ring_is_empty(&self->priv->streams));
>  
>          for (count = 0; count < NUM_SURFACES; ++count) {
> -            spice_assert(self->priv->surfaces[count].context.canvas ==
> NULL);
> +            spice_assert(!display_channel_surface_has_canvas(self, count));
>          }
>      }
>  
> @@ -1498,7 +1498,7 @@ void display_channel_flush_all_surfaces(DisplayChannel
> *display)
>      int x;
>  
>      for (x = 0; x < NUM_SURFACES; ++x) {
> -        if (display->priv->surfaces[x].context.canvas) {
> +        if (display_channel_surface_has_canvas(display, x)) {
>              display_channel_current_flush(display, x);
>          }
>      }
> @@ -2072,7 +2072,7 @@ void
> display_channel_destroy_surface_wait(DisplayChannel *display, uint32_t surf
>  {
>      if (!display_channel_validate_surface(display, surface_id))
>          return;
> -    if (!display->priv->surfaces[surface_id].context.canvas)
> +    if (!display_channel_surface_has_canvas(display, surface_id))
>          return;
>  
>      draw_depend_on_me(display, surface_id);
> @@ -2092,12 +2092,12 @@ void display_channel_destroy_surfaces(DisplayChannel
> *display)
>      spice_debug("trace");
>      //to handle better
>      for (i = 0; i < NUM_SURFACES; ++i) {
> -        if (display->priv->surfaces[i].context.canvas) {
> +        if (display_channel_surface_has_canvas(display, i)) {
>              display_channel_destroy_surface_wait(display, i);
> -            if (display->priv->surfaces[i].context.canvas) {
> +            if (display_channel_surface_has_canvas(display, i)) {
>                  display_channel_surface_unref(display, i);
>              }
> -            spice_assert(!display->priv->surfaces[i].context.canvas);
> +            spice_assert(!display_channel_surface_has_canvas(display, i));
>          }
>      }
>      spice_warn_if_fail(ring_is_empty(&display->priv->streams));
> @@ -2424,7 +2424,7 @@ gboolean
> display_channel_validate_surface(DisplayChannel *display, uint32_t surf
>          spice_warning("invalid surface_id %u", surface_id);
>          return FALSE;
>      }
> -    if (!display->priv->surfaces[surface_id].context.canvas) {
> +    if (!display_channel_surface_has_canvas(display, surface_id)) {
>          spice_warning("canvas address is %p for %d (and is NULL)",
>                     &(display->priv->surfaces[surface_id].context.canvas),
>                     surface_id);
>          spice_warning("failed on %d", surface_id);
> @@ -2462,7 +2462,7 @@ void
> display_channel_set_monitors_config_to_primary(DisplayChannel *display)
>      QXLHead head = { 0, };
>      uint16_t old_max = 1;
>  
> -    spice_return_if_fail(display->priv->surfaces[0].context.canvas);
> +    spice_return_if_fail(display_channel_surface_has_canvas(display, 0));
>  
>      if (display->priv->monitors_config) {
>          old_max = display->priv->monitors_config->max_allowed;

My paranoia level is saying that this function should be inlined, on the other
hand is also used in red-worker.c where can't be inlined.

Frediano