[Spice-commits] server/dcc.cpp server/display-channel.cpp server/reds.cpp server/sound.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun May 23 09:39:00 UTC 2021


 server/dcc.cpp             |   34 ++++++++++------------------------
 server/display-channel.cpp |   27 ++++++++-------------------
 server/reds.cpp            |    7 +------
 server/sound.cpp           |   14 +++++---------
 4 files changed, 24 insertions(+), 58 deletions(-)

New commits:
commit 8104fc34565d8a6d03e6db3bf3b327b07bf4a7f9
Author: Rosen Penev <rosenp at gmail.com>
Date:   Sat May 8 15:14:58 2021 -0700

    Manual algorithm changes
    
    Signed-off-by: Rosen Penev <rosenp at gmail.com>
    Acked-by: Frediano Ziglio <freddy77 at gmail.com>

diff --git a/server/dcc.cpp b/server/dcc.cpp
index e733ce48..ef98af3b 100644
--- a/server/dcc.cpp
+++ b/server/dcc.cpp
@@ -105,8 +105,6 @@ bool dcc_drawable_is_in_pipe(DisplayChannelClient *dcc, Drawable *drawable)
 bool dcc_clear_surface_drawables_from_pipe(DisplayChannelClient *dcc, int surface_id,
                                            int wait_if_used)
 {
-    int x;
-
     spice_return_val_if_fail(dcc != nullptr, TRUE);
     /* removing the newest drawables that their destination is surface_id and
        no other drawable depends on them */
@@ -115,7 +113,6 @@ bool dcc_clear_surface_drawables_from_pipe(DisplayChannelClient *dcc, int surfac
     for (auto l = pipe.begin(); l != pipe.end(); ) {
         Drawable *drawable;
         RedDrawablePipeItem *dpi = nullptr;
-        int depend_found = FALSE;
         RedPipeItem *item = l->get();
         auto item_pos = l;
 
@@ -134,13 +131,9 @@ bool dcc_clear_surface_drawables_from_pipe(DisplayChannelClient *dcc, int surfac
             continue;
         }
 
-        for (x = 0; x < 3; ++x) {
-            if (drawable->surface_deps[x] == surface_id) {
-                depend_found = TRUE;
-                break;
-            }
-        }
-
+        auto depend_found =
+            std::find(std::begin(drawable->surface_deps), std::end(drawable->surface_deps),
+                      surface_id) != std::end(drawable->surface_deps);
         if (depend_found) {
             spice_debug("surface %d dependent item found %p, %p", surface_id, drawable, item);
             if (!wait_if_used) {
@@ -271,12 +264,8 @@ void dcc_push_surface_image(DisplayChannelClient *dcc, int surface_id)
 static void add_drawable_surface_images(DisplayChannelClient *dcc, Drawable *drawable)
 {
     DisplayChannel *display = DCC_TO_DC(dcc);
-    int x;
 
-    for (x = 0; x < 3; ++x) {
-        int surface_id;
-
-        surface_id = drawable->surface_deps[x];
+    for (const auto surface_id : drawable->surface_deps) {
         if (surface_id != -1) {
             if (dcc->priv->surface_client_created[surface_id]) {
                 continue;
@@ -442,15 +431,12 @@ void dcc_start(DisplayChannelClient *dcc)
 
 static void dcc_destroy_stream_agents(DisplayChannelClient *dcc)
 {
-    int i;
-
-    for (i = 0; i < NUM_STREAMS; i++) {
-        VideoStreamAgent *agent = &dcc->priv->stream_agents[i];
-        region_destroy(&agent->vis_region);
-        region_destroy(&agent->clip);
-        if (agent->video_encoder) {
-            agent->video_encoder->destroy(agent->video_encoder);
-            agent->video_encoder = nullptr;
+    for (auto& agent : dcc->priv->stream_agents) {
+        region_destroy(&agent.vis_region);
+        region_destroy(&agent.clip);
+        if (agent.video_encoder) {
+            agent.video_encoder->destroy(agent.video_encoder);
+            agent.video_encoder = nullptr;
         }
     }
 }
diff --git a/server/display-channel.cpp b/server/display-channel.cpp
index 1d1e71e2..9eac7463 100644
--- a/server/display-channel.cpp
+++ b/server/display-channel.cpp
@@ -1114,12 +1114,9 @@ static void display_channel_print_stats(DisplayChannel *display)
 
 static void drawable_ref_surface_deps(DisplayChannel *display, Drawable *drawable)
 {
-    int x;
-    int surface_id;
     RedSurface *surface;
 
-    for (x = 0; x < 3; ++x) {
-        surface_id = drawable->surface_deps[x];
+    for (const auto surface_id : drawable->surface_deps) {
         if (surface_id == -1) {
             continue;
         }
@@ -1287,7 +1284,6 @@ static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t e
                                               uint32_t process_commands_generation)
 {
     Drawable *drawable;
-    int x;
 
     /* Validate all surface ids before updating counters
      * to avoid invalid updates if we find an invalid id.
@@ -1295,9 +1291,8 @@ static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t e
     if (!validate_drawable_bbox(display, red_drawable)) {
         return nullptr;
     }
-    for (x = 0; x < 3; ++x) {
-        if (red_drawable->surface_deps[x] != -1
-            && !display_channel_validate_surface(display, red_drawable->surface_deps[x])) {
+    for (const auto surface_id : red_drawable->surface_deps) {
+        if (surface_id != -1 && !display_channel_validate_surface(display, surface_id)) {
             return nullptr;
         }
     }
@@ -1545,11 +1540,9 @@ static void drawable_free(DisplayChannel *display, Drawable *drawable)
 
 static void drawables_init(DisplayChannel *display)
 {
-    int i;
-
     display->priv->free_drawables = nullptr;
-    for (i = 0; i < NUM_DRAWABLES; i++) {
-        drawable_free(display, &display->priv->drawables[i].u.drawable);
+    for (auto& drawable : display->priv->drawables) {
+        drawable_free(display, &drawable.u.drawable);
     }
 }
 
@@ -1610,11 +1603,7 @@ static void drawable_remove_dependencies(Drawable *drawable)
 
 static void drawable_unref_surface_deps(DisplayChannel *display, Drawable *drawable)
 {
-    int x;
-    int surface_id;
-
-    for (x = 0; x < 3; ++x) {
-        surface_id = drawable->surface_deps[x];
+    for (const auto surface_id : drawable->surface_deps) {
         if (surface_id == -1) {
             continue;
         }
@@ -2445,11 +2434,11 @@ static void guest_set_client_capabilities(DisplayChannel *display)
         red_qxl_set_client_capabilities(display->priv->qxl, FALSE, caps);
     } else {
         // Take least common denominator
-        for (auto &&cap : caps_available) {
+        for (const auto cap : caps_available) {
             SET_CAP(caps, cap);
         }
         FOREACH_CLIENT(display, rcc) {
-            for (auto &&cap : caps_available) {
+            for (const auto cap : caps_available) {
                 if (!rcc->test_remote_cap(cap)) {
                     CLEAR_CAP(caps, cap);
                 }
diff --git a/server/reds.cpp b/server/reds.cpp
index 3aecbdb1..1bf62fc7 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -1695,12 +1695,7 @@ static void reds_mig_target_client_disconnect_all(RedsState *reds)
 
 static bool reds_find_client(RedsState *reds, RedClient *client)
 {
-    for (auto list_client: reds->clients) {
-        if (list_client == client) {
-            return TRUE;
-        }
-    }
-    return FALSE;
+    return std::find(reds->clients.begin(), reds->clients.end(), client) != reds->clients.end();
 }
 
 /* should be used only when there is one client */
diff --git a/server/sound.cpp b/server/sound.cpp
index 68b890c8..d976992e 100644
--- a/server/sound.cpp
+++ b/server/sound.cpp
@@ -975,11 +975,9 @@ static int snd_desired_audio_mode(bool playback_compression, int frequency,
 
 PlaybackChannelClient::~PlaybackChannelClient()
 {
-    int i;
-
     // free frames, unref them
-    for (i = 0; i < NUM_AUDIO_FRAMES; ++i) {
-        frames->items[i].client = nullptr;
+    for (auto& item : frames->items) {
+        item.client = nullptr;
     }
     if (--frames->refs == 0) {
         g_free(frames);
@@ -1298,12 +1296,10 @@ void snd_set_playback_compression(bool on)
 
 static void snd_playback_alloc_frames(PlaybackChannelClient *playback)
 {
-    int i;
-
     playback->frames = g_new0(AudioFrameContainer, 1);
     playback->frames->refs = 1;
-    for (i = 0; i < NUM_AUDIO_FRAMES; ++i) {
-        playback->frames->items[i].container = playback->frames;
-        snd_playback_free_frame(playback, &playback->frames->items[i]);
+    for (auto& item : playback->frames->items) {
+        item.container = playback->frames;
+        snd_playback_free_frame(playback, &item);
     }
 }


More information about the Spice-commits mailing list