ba5ead2
From 6497eeeb1a6552315132340565a3901d4db2144c Mon Sep 17 00:00:00 2001
ba5ead2
From: Boris-Barboris <ismailsiege@gmail.com>
ba5ead2
Date: Tue, 22 Jun 2021 00:51:08 +0300
ba5ead2
Subject: [PATCH] Don't hardcode fps for fake screen
ba5ead2
ba5ead2
Currently, when main hardware screen is powered-off,
ba5ead2
X server initializes fake screen's timer with
ba5ead2
1 second update interval.
ba5ead2
ba5ead2
Streaming software like Nomachine or Vnc, as well as
ba5ead2
desktop input automation suffers from it, since it
ba5ead2
will forever be stuck on 1 fps until the display is
ba5ead2
turned back on.
ba5ead2
ba5ead2
This commit adds command line option -fakescreenfps <int>
ba5ead2
that allows the user to change the default fake screen
ba5ead2
timer.
ba5ead2
ba5ead2
Signed-off-by: Baranin Alexander <ismailsiege@gmail.com>
ba5ead2
---
ba5ead2
 man/Xserver.man        |  3 +++
ba5ead2
 os/utils.c             | 12 ++++++++++++
ba5ead2
 present/present.h      |  2 ++
ba5ead2
 present/present_fake.c | 28 ++++++++++++++++++----------
ba5ead2
 4 files changed, 35 insertions(+), 10 deletions(-)
ba5ead2
ba5ead2
diff --git a/man/Xserver.man b/man/Xserver.man
ba5ead2
index 31ffb8c..b1a3f40 100644
ba5ead2
--- a/man/Xserver.man
ba5ead2
+++ b/man/Xserver.man
ba5ead2
@@ -169,6 +169,9 @@ sets default cursor font.
ba5ead2
 .B \-fn \fIfont\fP
ba5ead2
 sets the default font.
ba5ead2
 .TP 8
ba5ead2
+.B \-fakescreenfps \fFps\fP
ba5ead2
+sets fake presenter screen default fps (allowable range: 1-600).
ba5ead2
+.TP 8
ba5ead2
 .B \-fp \fIfontPath\fP
ba5ead2
 sets the search path for fonts.  This path is a comma separated list
ba5ead2
 of directories which the X server searches for font databases.
ba5ead2
diff --git a/os/utils.c b/os/utils.c
ba5ead2
index 2ba1c80..721d4e9 100644
ba5ead2
--- a/os/utils.c
ba5ead2
+++ b/os/utils.c
ba5ead2
@@ -110,6 +110,8 @@ __stdcall unsigned long GetTickCount(void);
ba5ead2
 
ba5ead2
 #include "picture.h"
ba5ead2
 
ba5ead2
+#include "present.h"
ba5ead2
+
ba5ead2
 Bool noTestExtensions;
ba5ead2
 
ba5ead2
 #ifdef COMPOSITE
ba5ead2
@@ -526,6 +528,7 @@ UseMsg(void)
ba5ead2
     ErrorF
ba5ead2
         ("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n");
ba5ead2
     ErrorF("-f #                   bell base (0-100)\n");
ba5ead2
+    ErrorF("-fakescreenfps #       fake screen default fps (1-600)\n");
ba5ead2
     ErrorF("-fc string             cursor font\n");
ba5ead2
     ErrorF("-fn string             default font name\n");
ba5ead2
     ErrorF("-fp string             default font path\n");
ba5ead2
@@ -776,6 +779,15 @@ ProcessCommandLine(int argc, char *argv[])
ba5ead2
             else
ba5ead2
                 UseMsg();
ba5ead2
         }
ba5ead2
+        else if (strcmp(argv[i], "-fakescreenfps") == 0) {
ba5ead2
+            if (++i < argc) {
ba5ead2
+                FakeScreenFps = (uint32_t) atoi(argv[i]);
ba5ead2
+                if (FakeScreenFps < 1 || FakeScreenFps > 600)
ba5ead2
+                    FatalError("fakescreenfps must be an integer in [1;600] range\n");
ba5ead2
+            }
ba5ead2
+            else
ba5ead2
+                UseMsg();
ba5ead2
+        }
ba5ead2
         else if (strcmp(argv[i], "-fc") == 0) {
ba5ead2
             if (++i < argc)
ba5ead2
                 defaultCursorFont = argv[i];
ba5ead2
diff --git a/present/present.h b/present/present.h
ba5ead2
index 3d0b972..e7cc50d 100644
ba5ead2
--- a/present/present.h
ba5ead2
+++ b/present/present.h
ba5ead2
@@ -190,4 +190,6 @@ present_register_complete_notify(present_complete_notify_proc proc);
ba5ead2
 extern _X_EXPORT Bool
ba5ead2
 present_can_window_flip(WindowPtr window);
ba5ead2
 
ba5ead2
+extern _X_EXPORT uint32_t FakeScreenFps;
ba5ead2
+
ba5ead2
 #endif /* _PRESENT_H_ */
ba5ead2
diff --git a/present/present_fake.c b/present/present_fake.c
ba5ead2
index 2350638..d9ac598 100644
ba5ead2
--- a/present/present_fake.c
ba5ead2
+++ b/present/present_fake.c
ba5ead2
@@ -117,21 +117,29 @@ present_fake_queue_vblank(ScreenPtr     screen,
ba5ead2
     return Success;
ba5ead2
 }
ba5ead2
 
ba5ead2
+uint32_t FakeScreenFps = 0;
ba5ead2
+
ba5ead2
 void
ba5ead2
 present_fake_screen_init(ScreenPtr screen)
ba5ead2
 {
ba5ead2
+    uint32_t                fake_fps;
ba5ead2
     present_screen_priv_ptr screen_priv = present_screen_priv(screen);
ba5ead2
 
ba5ead2
-    /* For screens with hardware vblank support, the fake code
ba5ead2
-     * will be used for off-screen windows and while screens are blanked,
ba5ead2
-     * in which case we want a slow interval here
ba5ead2
-     *
ba5ead2
-     * Otherwise, pretend that the screen runs at 60Hz
ba5ead2
-     */
ba5ead2
-    if (screen_priv->info && screen_priv->info->get_crtc)
ba5ead2
-        screen_priv->fake_interval = 1000000;
ba5ead2
-    else
ba5ead2
-        screen_priv->fake_interval = 16667;
ba5ead2
+    if (FakeScreenFps)
ba5ead2
+        fake_fps = FakeScreenFps;
ba5ead2
+    else {
ba5ead2
+        /* For screens with hardware vblank support, the fake code
ba5ead2
+        * will be used for off-screen windows and while screens are blanked,
ba5ead2
+        * in which case we want a large interval here: 1Hz
ba5ead2
+        *
ba5ead2
+        * Otherwise, pretend that the screen runs at 60Hz
ba5ead2
+        */
ba5ead2
+        if (screen_priv->info && screen_priv->info->get_crtc)
ba5ead2
+            fake_fps = 1;
ba5ead2
+        else
ba5ead2
+            fake_fps = 60;
ba5ead2
+    }
ba5ead2
+    screen_priv->fake_interval = 1000000 / fake_fps;
ba5ead2
 }
ba5ead2
 
ba5ead2
 void
ba5ead2
-- 
ba5ead2
2.34.1
ba5ead2