Compare commits

..
2 changed files with 124 additions and 1 deletions

No files matched your search

@@ -334,7 +334,8 @@ extern void droiddeck_on_overlay_planes(int planes);
static int g_overlay_planes_told = -1;
static void tell_overlay_planes(void) {
const int planes = (g_zero_copy && g_display_buffer_driver) ? (sc_layer_overlay_affordable() ? 1 : 0) : -1;
const int composing = g_overlay_planes_told == 0 && vkp_surface_rotation_degrees() > 0;
const int planes = (g_zero_copy && g_display_buffer_driver) ? (sc_layer_overlay_affordable() && !composing ? 1 : 0) : -1;
if (planes == g_overlay_planes_told) return;
g_overlay_planes_told = planes;
droiddeck_on_overlay_planes(planes);
+122
View File
@@ -0,0 +1,122 @@
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
from tools.tests.test_vk_pending_completion import function
SRC = Path(__file__).resolve().parents[2] / "app/src/main/cpp/waylandcomp/src"
HARNESS = r'''
#include <assert.h>
static int g_zero_copy;
static int g_display_buffer_driver;
static int rotation;
static int game_scaled;
static int overlay_above;
static int hint;
static int hint_changes;
static int nested_composes(void) {
return overlay_above && hint == 0;
}
static int sc_layer_overlay_affordable(void) {
if (rotation <= 0) return 1;
if (nested_composes()) return 1;
return !game_scaled;
}
static int vkp_surface_rotation_degrees(void) { return rotation; }
static void droiddeck_on_overlay_planes(int planes) {
hint = planes;
hint_changes++;
}
static int g_overlay_planes_told = -1;
%(tell)s
static void frames(int n) {
for (int i = 0; i < n; i++) tell_overlay_planes();
}
static void reset(int rot, int scaled, int overlay) {
g_zero_copy = 1;
g_display_buffer_driver = 1;
rotation = rot;
game_scaled = scaled;
overlay_above = overlay;
hint = -1;
hint_changes = 0;
g_overlay_planes_told = -1;
}
int main(void) {
reset(90, 1, 1);
frames(60);
assert(hint == 0);
assert(hint_changes == 1);
overlay_above = 0;
frames(10);
overlay_above = 1;
frames(30);
assert(hint == 0);
assert(hint_changes == 1);
rotation = 0;
frames(5);
assert(hint == 1);
rotation = 90;
game_scaled = 0;
frames(30);
assert(hint == 1);
assert(hint_changes == 2);
reset(0, 1, 1);
frames(60);
assert(hint == 1 && hint_changes == 1);
reset(90, 0, 1);
frames(60);
assert(hint == 1 && hint_changes == 1);
reset(90, 1, 1);
frames(5);
assert(hint == 0);
g_zero_copy = 0;
frames(5);
assert(hint == -1);
g_zero_copy = 1;
game_scaled = 0;
frames(5);
assert(hint == 1);
return 0;
}
'''
class OverlayPlanesHintTest(unittest.TestCase):
def test_the_nested_compositor_keeps_composing_while_the_rotated_display_still_needs_it(self):
compiler = shutil.which(os.environ.get("CC", "cc"))
if not compiler:
self.fail("A C compiler is required for the overlay planes hint test")
body = function((SRC / "compositor.c").read_text(), "tell_overlay_planes")
with tempfile.TemporaryDirectory(prefix="droiddeck-overlay-planes-") as tmp:
source = Path(tmp) / "overlay_planes_hint_test.c"
source.write_text(HARNESS % {"tell": body})
program = Path(tmp) / "overlay-planes-hint"
built = subprocess.run([compiler, "-std=c11", "-Wall", "-Wextra", "-Werror", "-UNDEBUG", str(source),
"-o", str(program)], capture_output=True, text=True)
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
if __name__ == "__main__":
unittest.main()