[gnome-remote-desktop] rdp/rdpgfx: Adapt to RDPGFX frame controller



commit cc790574b45e4778f220c8916b26dee6622f7a5b
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Fri Feb 11 11:52:42 2022 +0100

    rdp/rdpgfx: Adapt to RDPGFX frame controller
    
    Remove the frame controller functionality from the GFX surface class
    and use a frame controller instance instead.
    Frame controllers are optional, so check for the frame controller
    instance, before attempting to submit new RTT values.

 src/grd-rdp-gfx-surface.c       | 290 ++--------------------------------------
 src/grd-rdp-gfx-surface.h       |  20 +--
 src/grd-rdp-graphics-pipeline.c |  69 +++++++---
 3 files changed, 61 insertions(+), 318 deletions(-)
---
diff --git a/src/grd-rdp-gfx-surface.c b/src/grd-rdp-gfx-surface.c
index a5b97efe..de3cd0c7 100644
--- a/src/grd-rdp-gfx-surface.c
+++ b/src/grd-rdp-gfx-surface.c
@@ -21,27 +21,14 @@
 
 #include "grd-rdp-gfx-surface.h"
 
-#include "grd-rdp-gfx-frame-log.h"
 #include "grd-rdp-graphics-pipeline.h"
 #include "grd-rdp-surface.h"
-#include "grd-session-rdp.h"
-
-#define ACTIVATE_THROTTLING_TH_DEFAULT 2
-#define DEACTIVATE_THROTTLING_TH_DEFAULT 1
-
-typedef enum _ThrottlingState
-{
-  THROTTLING_STATE_INACTIVE,
-  THROTTLING_STATE_ACTIVE,
-  THROTTLING_STATE_ACTIVE_LOWERING_LATENCY,
-} ThrottlingState;
 
 struct _GrdRdpGfxSurface
 {
   GObject parent;
 
   GrdRdpGraphicsPipeline *graphics_pipeline;
-  GrdSessionRdp *session_rdp;
   GrdRdpSurface *rdp_surface;
   gboolean created;
 
@@ -49,17 +36,7 @@ struct _GrdRdpGfxSurface
   uint32_t codec_context_id;
   uint32_t serial;
 
-  GSource *pending_encode_source;
-
-  GrdRdpGfxFrameLog *frame_log;
-
-  int64_t nw_auto_last_rtt_us;
-
-  ThrottlingState throttling_state;
-  /* Throttling triggers on >= activate_throttling_th */
-  uint32_t activate_throttling_th;
-  /* Throttling triggers on <= deactivate_throttling_th */
-  uint32_t deactivate_throttling_th;
+  GrdRdpGfxFrameController *frame_controller;
 };
 
 G_DEFINE_TYPE (GrdRdpGfxSurface, grd_rdp_gfx_surface, G_TYPE_OBJECT)
@@ -88,250 +65,23 @@ grd_rdp_gfx_surface_get_rdp_surface (GrdRdpGfxSurface *gfx_surface)
   return gfx_surface->rdp_surface;
 }
 
-static uint32_t
-get_activate_throttling_th_from_rtt (GrdRdpGfxSurface *gfx_surface,
-                                     int64_t           rtt_us)
-{
-  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
-  int64_t refresh_rate = rdp_surface->refresh_rate;
-  uint32_t activate_throttling_th;
-  uint32_t delayed_frames;
-
-  delayed_frames = rtt_us * refresh_rate / G_USEC_PER_SEC;
-
-  activate_throttling_th = MAX (2, MIN (delayed_frames + 2, refresh_rate));
-  g_assert (activate_throttling_th > gfx_surface->deactivate_throttling_th);
-
-  return activate_throttling_th;
-}
-
-void
-grd_rdp_gfx_surface_unack_frame (GrdRdpGfxSurface *gfx_surface,
-                                 uint32_t          frame_id,
-                                 int64_t           enc_time_us)
-{
-  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
-  GrdRdpGfxFrameLog *frame_log = gfx_surface->frame_log;
-  uint32_t current_activate_throttling_th;
-  uint32_t n_unacked_frames;
-  uint32_t enc_rate = 0;
-  uint32_t ack_rate = 0;
-
-  grd_rdp_gfx_frame_log_track_frame (frame_log, frame_id, enc_time_us);
-
-  n_unacked_frames = grd_rdp_gfx_frame_log_get_unacked_frames_count (frame_log);
-  grd_rdp_gfx_frame_log_update_rates (frame_log, &enc_rate, &ack_rate);
-
-  switch (gfx_surface->throttling_state)
-    {
-    case THROTTLING_STATE_INACTIVE:
-      gfx_surface->activate_throttling_th = get_activate_throttling_th_from_rtt (
-        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
-
-      if (n_unacked_frames >= gfx_surface->activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE;
-          rdp_surface->encoding_suspended = TRUE;
-        }
-      break;
-    case THROTTLING_STATE_ACTIVE:
-      current_activate_throttling_th = get_activate_throttling_th_from_rtt (
-        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
-
-      if (current_activate_throttling_th < gfx_surface->activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE_LOWERING_LATENCY;
-          rdp_surface->encoding_suspended = TRUE;
-        }
-      else
-        {
-          gfx_surface->activate_throttling_th = current_activate_throttling_th;
-          rdp_surface->encoding_suspended = enc_rate > ack_rate + 1;
-        }
-      break;
-    case THROTTLING_STATE_ACTIVE_LOWERING_LATENCY:
-      g_assert (rdp_surface->encoding_suspended);
-      break;
-    }
-}
-
-void
-grd_rdp_gfx_surface_ack_frame (GrdRdpGfxSurface *gfx_surface,
-                               uint32_t          frame_id,
-                               int64_t           ack_time_us)
-{
-  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
-  GrdRdpGfxFrameLog *frame_log = gfx_surface->frame_log;
-  gboolean encoding_was_suspended;
-  uint32_t current_activate_throttling_th;
-  uint32_t n_unacked_frames;
-  uint32_t enc_rate = 0;
-  uint32_t ack_rate = 0;
-
-  grd_rdp_gfx_frame_log_ack_tracked_frame (frame_log, frame_id, ack_time_us);
-
-  encoding_was_suspended = rdp_surface->encoding_suspended;
-  n_unacked_frames = grd_rdp_gfx_frame_log_get_unacked_frames_count (frame_log);
-  grd_rdp_gfx_frame_log_update_rates (frame_log, &enc_rate, &ack_rate);
-
-  switch (gfx_surface->throttling_state)
-    {
-    case THROTTLING_STATE_INACTIVE:
-      break;
-    case THROTTLING_STATE_ACTIVE:
-      if (n_unacked_frames <= gfx_surface->deactivate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_INACTIVE;
-          rdp_surface->encoding_suspended = FALSE;
-          break;
-        }
-
-      current_activate_throttling_th = get_activate_throttling_th_from_rtt (
-        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
-      if (current_activate_throttling_th < gfx_surface->activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE_LOWERING_LATENCY;
-          rdp_surface->encoding_suspended = TRUE;
-        }
-      else
-        {
-          gfx_surface->activate_throttling_th = current_activate_throttling_th;
-          rdp_surface->encoding_suspended = enc_rate > ack_rate;
-        }
-      break;
-    case THROTTLING_STATE_ACTIVE_LOWERING_LATENCY:
-      current_activate_throttling_th = get_activate_throttling_th_from_rtt (
-        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
-
-      if (n_unacked_frames < current_activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_INACTIVE;
-          rdp_surface->encoding_suspended = FALSE;
-        }
-      else if (n_unacked_frames == current_activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE;
-          rdp_surface->encoding_suspended = enc_rate > ack_rate;
-        }
-      else if (n_unacked_frames > current_activate_throttling_th)
-        {
-          g_assert (rdp_surface->encoding_suspended);
-        }
-      else
-        {
-          g_assert_not_reached ();
-        }
-      break;
-    }
-
-  if (encoding_was_suspended && !rdp_surface->encoding_suspended)
-    g_source_set_ready_time (gfx_surface->pending_encode_source, 0);
-}
-
-static void
-reevaluate_encoding_suspension_state (GrdRdpGfxSurface *gfx_surface)
-{
-  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
-  GrdRdpGfxFrameLog *frame_log = gfx_surface->frame_log;
-  uint32_t n_unacked_frames;
-  uint32_t enc_rate = 0;
-  uint32_t ack_rate = 0;
-
-  n_unacked_frames = grd_rdp_gfx_frame_log_get_unacked_frames_count (frame_log);
-  grd_rdp_gfx_frame_log_update_rates (frame_log, &enc_rate, &ack_rate);
-
-  switch (gfx_surface->throttling_state)
-    {
-    case THROTTLING_STATE_INACTIVE:
-      gfx_surface->activate_throttling_th = get_activate_throttling_th_from_rtt (
-        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
-
-      if (n_unacked_frames >= gfx_surface->activate_throttling_th)
-        {
-          gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE;
-          rdp_surface->encoding_suspended = TRUE;
-        }
-      break;
-    case THROTTLING_STATE_ACTIVE:
-      g_assert (gfx_surface->activate_throttling_th >
-                gfx_surface->deactivate_throttling_th);
-      g_assert (n_unacked_frames > gfx_surface->deactivate_throttling_th);
-      g_assert (rdp_surface->encoding_suspended);
-      break;
-    case THROTTLING_STATE_ACTIVE_LOWERING_LATENCY:
-      /*
-       * While the graphics pipeline rewrites the frame history, the RTT
-       * detection mechanism cannot submit a new round trip time.
-       */
-      g_assert_not_reached ();
-      break;
-    }
-}
-
-void
-grd_rdp_gfx_surface_unack_last_acked_frame (GrdRdpGfxSurface *gfx_surface,
-                                            uint32_t          frame_id,
-                                            int64_t           enc_ack_time_us)
+GrdRdpGfxFrameController *
+grd_rdp_gfx_surface_get_frame_controller (GrdRdpGfxSurface *gfx_surface)
 {
-  grd_rdp_gfx_frame_log_unack_last_acked_frame (gfx_surface->frame_log, frame_id,
-                                                enc_ack_time_us);
-  reevaluate_encoding_suspension_state (gfx_surface);
+  return gfx_surface->frame_controller;
 }
 
 void
-grd_rdp_gfx_surface_clear_all_unacked_frames (GrdRdpGfxSurface *gfx_surface)
+grd_rdp_gfx_surface_attach_frame_controller (GrdRdpGfxSurface         *gfx_surface,
+                                             GrdRdpGfxFrameController *frame_controller)
 {
-  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
-  gboolean encoding_was_suspended;
-
-  grd_rdp_gfx_frame_log_clear (gfx_surface->frame_log);
-
-  encoding_was_suspended = rdp_surface->encoding_suspended;
+  g_assert (!gfx_surface->frame_controller);
 
-  gfx_surface->throttling_state = THROTTLING_STATE_INACTIVE;
-  rdp_surface->encoding_suspended = FALSE;
-
-  if (encoding_was_suspended)
-    g_source_set_ready_time (gfx_surface->pending_encode_source, 0);
+  gfx_surface->frame_controller = frame_controller;
 }
 
-void
-grd_rdp_gfx_surface_notify_new_round_trip_time (GrdRdpGfxSurface *gfx_surface,
-                                                int64_t           round_trip_time_us)
-{
-  gfx_surface->nw_auto_last_rtt_us = round_trip_time_us;
-}
-
-static gboolean
-maybe_encode_pending_frame (gpointer user_data)
-{
-  GrdRdpGfxSurface *gfx_surface = user_data;
-
-  grd_session_rdp_maybe_encode_pending_frame (gfx_surface->session_rdp,
-                                              gfx_surface->rdp_surface);
-
-  return G_SOURCE_CONTINUE;
-}
-
-static gboolean
-pending_encode_source_dispatch (GSource     *source,
-                                GSourceFunc  callback,
-                                gpointer     user_data)
-{
-  g_source_set_ready_time (source, -1);
-
-  return callback (user_data);
-}
-
-static GSourceFuncs pending_encode_source_funcs =
-{
-  .dispatch = pending_encode_source_dispatch,
-};
-
 GrdRdpGfxSurface *
 grd_rdp_gfx_surface_new (GrdRdpGraphicsPipeline *graphics_pipeline,
-                         GrdSessionRdp          *session_rdp,
-                         GMainContext           *pipeline_context,
                          GrdRdpSurface          *rdp_surface,
                          uint16_t                surface_id,
                          uint32_t                serial)
@@ -340,7 +90,6 @@ grd_rdp_gfx_surface_new (GrdRdpGraphicsPipeline *graphics_pipeline,
 
   gfx_surface = g_object_new (GRD_TYPE_RDP_GFX_SURFACE, NULL);
   gfx_surface->graphics_pipeline = graphics_pipeline;
-  gfx_surface->session_rdp = session_rdp;
   gfx_surface->rdp_surface = rdp_surface;
   gfx_surface->surface_id = surface_id;
   gfx_surface->serial = serial;
@@ -353,13 +102,6 @@ grd_rdp_gfx_surface_new (GrdRdpGraphicsPipeline *graphics_pipeline,
   grd_rdp_graphics_pipeline_create_surface (graphics_pipeline, gfx_surface);
   gfx_surface->created = TRUE;
 
-  gfx_surface->pending_encode_source = g_source_new (&pending_encode_source_funcs,
-                                                     sizeof (GSource));
-  g_source_set_callback (gfx_surface->pending_encode_source,
-                         maybe_encode_pending_frame, gfx_surface, NULL);
-  g_source_set_ready_time (gfx_surface->pending_encode_source, -1);
-  g_source_attach (gfx_surface->pending_encode_source, pipeline_context);
-
   return gfx_surface;
 }
 
@@ -368,11 +110,7 @@ grd_rdp_gfx_surface_dispose (GObject *object)
 {
   GrdRdpGfxSurface *gfx_surface = GRD_RDP_GFX_SURFACE (object);
 
-  if (gfx_surface->pending_encode_source)
-    {
-      g_source_destroy (gfx_surface->pending_encode_source);
-      g_clear_pointer (&gfx_surface->pending_encode_source, g_source_unref);
-    }
+  g_clear_object (&gfx_surface->frame_controller);
 
   if (gfx_surface->created)
     {
@@ -381,22 +119,12 @@ grd_rdp_gfx_surface_dispose (GObject *object)
       gfx_surface->created = FALSE;
     }
 
-  g_clear_object (&gfx_surface->frame_log);
-
   G_OBJECT_CLASS (grd_rdp_gfx_surface_parent_class)->dispose (object);
 }
 
 static void
 grd_rdp_gfx_surface_init (GrdRdpGfxSurface *gfx_surface)
 {
-  gfx_surface->throttling_state = THROTTLING_STATE_INACTIVE;
-  gfx_surface->activate_throttling_th = ACTIVATE_THROTTLING_TH_DEFAULT;
-  gfx_surface->deactivate_throttling_th = DEACTIVATE_THROTTLING_TH_DEFAULT;
-
-  g_assert (gfx_surface->activate_throttling_th >
-            gfx_surface->deactivate_throttling_th);
-
-  gfx_surface->frame_log = grd_rdp_gfx_frame_log_new ();
 }
 
 static void
diff --git a/src/grd-rdp-gfx-surface.h b/src/grd-rdp-gfx-surface.h
index 7e05fa36..85f43d67 100644
--- a/src/grd-rdp-gfx-surface.h
+++ b/src/grd-rdp-gfx-surface.h
@@ -30,8 +30,6 @@ G_DECLARE_FINAL_TYPE (GrdRdpGfxSurface, grd_rdp_gfx_surface,
                       GRD, RDP_GFX_SURFACE, GObject)
 
 GrdRdpGfxSurface *grd_rdp_gfx_surface_new (GrdRdpGraphicsPipeline *graphics_pipeline,
-                                           GrdSessionRdp          *session_rdp,
-                                           GMainContext           *pipeline_context,
                                            GrdRdpSurface          *rdp_surface,
                                            uint16_t                surface_id,
                                            uint32_t                serial);
@@ -44,21 +42,9 @@ uint32_t grd_rdp_gfx_surface_get_serial (GrdRdpGfxSurface *gfx_surface);
 
 GrdRdpSurface *grd_rdp_gfx_surface_get_rdp_surface (GrdRdpGfxSurface *gfx_surface);
 
-void grd_rdp_gfx_surface_unack_frame (GrdRdpGfxSurface *gfx_surface,
-                                      uint32_t          frame_id,
-                                      int64_t           enc_time_us);
+GrdRdpGfxFrameController *grd_rdp_gfx_surface_get_frame_controller (GrdRdpGfxSurface *gfx_surface);
 
-void grd_rdp_gfx_surface_ack_frame (GrdRdpGfxSurface *gfx_surface,
-                                    uint32_t          frame_id,
-                                    int64_t           ack_time_us);
-
-void grd_rdp_gfx_surface_unack_last_acked_frame (GrdRdpGfxSurface *gfx_surface,
-                                                 uint32_t          frame_id,
-                                                 int64_t           enc_ack_time_us);
-
-void grd_rdp_gfx_surface_clear_all_unacked_frames (GrdRdpGfxSurface *gfx_surface);
-
-void grd_rdp_gfx_surface_notify_new_round_trip_time (GrdRdpGfxSurface *gfx_surface,
-                                                     int64_t           round_trip_time_us);
+void grd_rdp_gfx_surface_attach_frame_controller (GrdRdpGfxSurface         *gfx_surface,
+                                                  GrdRdpGfxFrameController *frame_controller);
 
 #endif /* GRD_RDP_GFX_SURFACE_H */
diff --git a/src/grd-rdp-graphics-pipeline.c b/src/grd-rdp-graphics-pipeline.c
index ce4b75da..36163dc5 100644
--- a/src/grd-rdp-graphics-pipeline.c
+++ b/src/grd-rdp-graphics-pipeline.c
@@ -28,6 +28,7 @@
 #include "grd-rdp-buffer.h"
 #include "grd-rdp-damage-detector.h"
 #include "grd-rdp-frame-info.h"
+#include "grd-rdp-gfx-frame-controller.h"
 #include "grd-rdp-gfx-surface.h"
 #include "grd-rdp-network-autodetection.h"
 #include "grd-rdp-surface.h"
@@ -288,12 +289,20 @@ grd_rdp_graphics_pipeline_notify_new_round_trip_time (GrdRdpGraphicsPipeline *gr
                                                       uint64_t                round_trip_time_us)
 {
   GrdRdpGfxSurface *gfx_surface;
+  GrdRdpGfxFrameController *frame_controller;
   GHashTableIter iter;
 
   g_mutex_lock (&graphics_pipeline->gfx_mutex);
   g_hash_table_iter_init (&iter, graphics_pipeline->surface_table);
   while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &gfx_surface))
-    grd_rdp_gfx_surface_notify_new_round_trip_time (gfx_surface, round_trip_time_us);
+    {
+      frame_controller = grd_rdp_gfx_surface_get_frame_controller (gfx_surface);
+      if (!frame_controller)
+        continue;
+
+      grd_rdp_gfx_frame_controller_notify_new_round_trip_time (frame_controller,
+                                                               round_trip_time_us);
+    }
   g_mutex_unlock (&graphics_pipeline->gfx_mutex);
 }
 
@@ -401,6 +410,8 @@ refresh_gfx_surface_avc420 (GrdRdpGraphicsPipeline *graphics_pipeline,
 {
   RdpgfxServerContext *rdpgfx_context = graphics_pipeline->rdpgfx_context;
   GrdRdpGfxSurface *gfx_surface = rdp_surface->gfx_surface;
+  GrdRdpGfxFrameController *frame_controller =
+    grd_rdp_gfx_surface_get_frame_controller (gfx_surface);
   RDPGFX_SURFACE_COMMAND cmd = {0};
   RDPGFX_START_FRAME_PDU cmd_start = {0};
   RDPGFX_END_FRAME_PDU cmd_end = {0};
@@ -496,8 +507,8 @@ refresh_gfx_surface_avc420 (GrdRdpGraphicsPipeline *graphics_pipeline,
 
   g_mutex_lock (&graphics_pipeline->gfx_mutex);
   enc_ack_time_us = g_get_monotonic_time ();
-  grd_rdp_gfx_surface_unack_frame (gfx_surface, cmd_start.frameId,
-                                   enc_ack_time_us);
+  grd_rdp_gfx_frame_controller_unack_frame (frame_controller, cmd_start.frameId,
+                                            enc_ack_time_us);
 
   surface_serial = grd_rdp_gfx_surface_get_serial (gfx_surface);
   g_hash_table_insert (graphics_pipeline->frame_serial_table,
@@ -508,8 +519,8 @@ refresh_gfx_surface_avc420 (GrdRdpGraphicsPipeline *graphics_pipeline,
 
   if (graphics_pipeline->frame_acks_suspended)
     {
-      grd_rdp_gfx_surface_ack_frame (gfx_surface, cmd_start.frameId,
-                                     enc_ack_time_us);
+      grd_rdp_gfx_frame_controller_ack_frame (frame_controller, cmd_start.frameId,
+                                              enc_ack_time_us);
       enqueue_tracked_frame_info (graphics_pipeline, surface_serial,
                                   cmd_start.frameId, enc_ack_time_us);
     }
@@ -668,6 +679,8 @@ refresh_gfx_surface_rfx_progressive (GrdRdpGraphicsPipeline *graphics_pipeline,
   RdpgfxServerContext *rdpgfx_context = graphics_pipeline->rdpgfx_context;
   GrdSessionRdp *session_rdp = graphics_pipeline->session_rdp;
   GrdRdpGfxSurface *gfx_surface = rdp_surface->gfx_surface;
+  GrdRdpGfxFrameController *frame_controller =
+    grd_rdp_gfx_surface_get_frame_controller (gfx_surface);
   uint32_t src_stride = grd_session_rdp_get_stride_for_width (session_rdp,
                                                               rdp_surface->width);
   RDPGFX_SURFACE_COMMAND cmd = {0};
@@ -766,8 +779,8 @@ refresh_gfx_surface_rfx_progressive (GrdRdpGraphicsPipeline *graphics_pipeline,
     }
 
   enc_ack_time_us = g_get_monotonic_time ();
-  grd_rdp_gfx_surface_unack_frame (gfx_surface, cmd_start.frameId,
-                                   enc_ack_time_us);
+  grd_rdp_gfx_frame_controller_unack_frame (frame_controller, cmd_start.frameId,
+                                            enc_ack_time_us);
 
   surface_serial = grd_rdp_gfx_surface_get_serial (gfx_surface);
   g_hash_table_insert (graphics_pipeline->frame_serial_table,
@@ -778,8 +791,8 @@ refresh_gfx_surface_rfx_progressive (GrdRdpGraphicsPipeline *graphics_pipeline,
 
   if (graphics_pipeline->frame_acks_suspended)
     {
-      grd_rdp_gfx_surface_ack_frame (gfx_surface, cmd_start.frameId,
-                                     enc_ack_time_us);
+      grd_rdp_gfx_frame_controller_ack_frame (frame_controller, cmd_start.frameId,
+                                              enc_ack_time_us);
       enqueue_tracked_frame_info (graphics_pipeline, surface_serial,
                                   cmd_start.frameId, enc_ack_time_us);
     }
@@ -933,10 +946,18 @@ grd_rdp_graphics_pipeline_refresh_gfx (GrdRdpGraphicsPipeline *graphics_pipeline
     g_clear_object (&rdp_surface->gfx_surface);
   if (!rdp_surface->gfx_surface)
     {
-      rdp_surface->gfx_surface = grd_rdp_gfx_surface_new (
-        graphics_pipeline, session_rdp, graphics_pipeline->pipeline_context,
-        rdp_surface, get_next_free_surface_id (graphics_pipeline),
-        get_next_free_serial (graphics_pipeline));
+      g_autoptr (GrdRdpGfxFrameController) frame_controller = NULL;
+
+      rdp_surface->gfx_surface =
+        grd_rdp_gfx_surface_new (graphics_pipeline, rdp_surface,
+                                 get_next_free_surface_id (graphics_pipeline),
+                                 get_next_free_serial (graphics_pipeline));
+      frame_controller =
+        grd_rdp_gfx_frame_controller_new (session_rdp,
+                                          graphics_pipeline->pipeline_context,
+                                          rdp_surface);
+      grd_rdp_gfx_surface_attach_frame_controller (rdp_surface->gfx_surface,
+                                                   g_steal_pointer (&frame_controller));
       map_surface_to_output (graphics_pipeline, rdp_surface->gfx_surface);
     }
 
@@ -1141,9 +1162,12 @@ maybe_rewrite_frame_history (GrdRdpGraphicsPipeline *graphics_pipeline,
 
       if (surface_context->gfx_surface)
         {
-          grd_rdp_gfx_surface_unack_last_acked_frame (surface_context->gfx_surface,
-                                                      frame_info->frame_id,
-                                                      frame_info->enc_time_us);
+          GrdRdpGfxFrameController *frame_controller =
+            grd_rdp_gfx_surface_get_frame_controller (surface_context->gfx_surface);
+
+          grd_rdp_gfx_frame_controller_unack_last_acked_frame (frame_controller,
+                                                               frame_info->frame_id,
+                                                               frame_info->enc_time_us);
         }
 
       g_free (gfx_frame_info);
@@ -1156,8 +1180,10 @@ clear_all_unacked_frames_in_gfx_surface (gpointer key,
                                          gpointer user_data)
 {
   GrdRdpGfxSurface *gfx_surface = value;
+  GrdRdpGfxFrameController *frame_controller =
+    grd_rdp_gfx_surface_get_frame_controller (gfx_surface);
 
-  grd_rdp_gfx_surface_clear_all_unacked_frames (gfx_surface);
+  grd_rdp_gfx_frame_controller_clear_all_unacked_frames (frame_controller);
 }
 
 static gboolean
@@ -1219,9 +1245,12 @@ handle_frame_ack_event (GrdRdpGraphicsPipeline             *graphics_pipeline,
 
       if (surface_context->gfx_surface)
         {
-          grd_rdp_gfx_surface_ack_frame (surface_context->gfx_surface,
-                                         frame_acknowledge->frameId,
-                                         g_get_monotonic_time ());
+          GrdRdpGfxFrameController *frame_controller =
+            grd_rdp_gfx_surface_get_frame_controller (surface_context->gfx_surface);
+
+          grd_rdp_gfx_frame_controller_ack_frame (frame_controller,
+                                                  frame_acknowledge->frameId,
+                                                  g_get_monotonic_time ());
         }
 
       surface_serial_unref (graphics_pipeline, surface_serial);


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