fix: draw the guest cursor into the glasses picture (#1925)

This commit is contained in:
Moroni Granja authored and GitHub committed 2026-11-01 00:26:14 -04:00
1 parent 3fc80a03d9
commit dbf114a0f2
9 files changed
+369 -12

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#include <assert.h>
#include <stdio.h>
#include "cursor_constants.inc"
#include "cursor_scene_positions.inc"
#include "cursor_clip_to_eye.inc"
int main(void) {
int out[2];
int dx, sx, dw;
assert(cursor_scene_positions(1920, CARDBOARD_SOURCE_SCREEN, 100, 0, out) == 1);
assert(out[0] == 100);
assert(cursor_scene_positions(1920, CARDBOARD_SOURCE_FLAT, 100, 0, out) == 1);
assert(out[0] == 100);
assert(cursor_scene_positions(1, CARDBOARD_SOURCE_SBS, 0, 0, out) == 1);
assert(cursor_scene_positions(3840, CARDBOARD_SOURCE_SBS, 100, 0, out) == 2);
assert(out[0] == 100 && out[1] == 2020);
assert(cursor_scene_positions(3840, CARDBOARD_SOURCE_SBS, 2000, 0, out) == 2);
assert(out[0] == 2000 && out[1] == 80);
assert(cursor_scene_positions(3840, CARDBOARD_SOURCE_SBS, 1919, 0, out) == 2);
assert(out[0] == 1919 && out[1] == 3839);
assert(cursor_scene_positions(3840, CARDBOARD_SOURCE_SBS, 1920, 0, out) == 2);
assert(out[0] == 1920 && out[1] == 0);
/* A hotspot that pushes the image across the seam must not move the mirror to the
* other eye: the pointer decides the eye, the hotspot only shifts the image. */
assert(cursor_scene_positions(1920, CARDBOARD_SOURCE_SBS, 960, 32, out) == 2);
assert(out[0] == 928 && out[1] == -32);
assert(cursor_scene_positions(1920, CARDBOARD_SOURCE_SBS, 959, 32, out) == 2);
assert(out[0] == 927 && out[1] == 1887);
/* Each copy is cropped to its own eye, so nothing bleeds into the other eye's half. */
assert(cursor_clip_to_eye(1920, -1, 100, 32, &dx, &sx, &dw) == 1);
assert(dx == 100 && sx == 0 && dw == 32);
assert(cursor_clip_to_eye(1920, 0, 100, 32, &dx, &sx, &dw) == 1);
assert(dx == 100 && sx == 0 && dw == 32);
assert(cursor_clip_to_eye(1920, 0, 950, 32, &dx, &sx, &dw) == 1);
assert(dx == 950 && sx == 0 && dw == 10);
assert(cursor_clip_to_eye(1920, 1, 950, 32, &dx, &sx, &dw) == 1);
assert(dx == 960 && sx == 10 && dw == 22);
assert(cursor_clip_to_eye(1920, 1, 960, 32, &dx, &sx, &dw) == 1);
assert(dx == 960 && sx == 0 && dw == 32);
assert(cursor_clip_to_eye(1920, 0, 928, 32, &dx, &sx, &dw) == 1);
assert(dx == 928 && sx == 0 && dw == 32);
assert(cursor_clip_to_eye(1920, 1, 928, 32, &dx, &sx, &dw) == 0);
assert(cursor_clip_to_eye(1920, 0, -32, 32, &dx, &sx, &dw) == 0);
puts("PASS: cursor stereo placement");
return 0;
}
+54
View File
@@ -0,0 +1,54 @@
"""Exercise the compositor's real cursor placement rule for glasses output."""
import os
from pathlib import Path
import re
import shutil
import subprocess
import tempfile
import unittest
REPO = Path(__file__).resolve().parents[2]
class CursorCompositeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which(os.environ.get('CC', 'cc'))
if compiler is None:
raise unittest.SkipTest('A host C compiler is required')
header = (REPO / 'app/src/main/cpp/waylandcomp/src/cardboard.h').read_text()
sources = dict(re.findall(r'CARDBOARD_SOURCE_(SCREEN|SBS|FLAT)\s*=\s*(\d+)', header))
for name in ('SCREEN', 'SBS', 'FLAT'):
if name not in sources:
raise AssertionError(f'cardboard.h no longer defines CARDBOARD_SOURCE_{name}')
if sources['SBS'] != '1':
raise AssertionError(f'CARDBOARD_SOURCE_SBS is {sources["SBS"]}, expected 1')
source = (REPO / 'app/src/main/cpp/waylandcomp/src/compositor.c').read_text()
start = source.index('static int cursor_scene_positions(int scene_w, int source, int ptr_x, int hx, int out[2]) {')
end = source.index('\n}\n', start) + 3
cls.temp = tempfile.TemporaryDirectory(prefix='droiddeck-cursor-composite-')
cls.addClassCleanup(cls.temp.cleanup)
folder = Path(cls.temp.name)
(folder / 'cursor_scene_positions.inc').write_text(source[start:end])
start = source.index('static int cursor_clip_to_eye(int scene_w, int eye, int x0, int w, int *dx, int *sx, int *dw) {')
end = source.index('\n}\n', start) + 3
(folder / 'cursor_clip_to_eye.inc').write_text(source[start:end])
(folder / 'cursor_constants.inc').write_text(
f'#define CARDBOARD_SOURCE_SCREEN {sources["SCREEN"]}\n'
f'#define CARDBOARD_SOURCE_SBS {sources["SBS"]}\n'
f'#define CARDBOARD_SOURCE_FLAT {sources["FLAT"]}\n')
cls.binary = folder / 'cursor-composite-test'
subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', '-Werror', '-I', str(folder),
str(REPO / 'tools/tests/cursor_composite_harness.c'),
'-o', str(cls.binary)], check=True, capture_output=True, text=True)
def test_cursor_is_drawn_once_for_one_eye_and_mirrored_for_sbs(self):
result = subprocess.run([str(self.binary)], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn('PASS: cursor stereo placement', result.stdout)
if __name__ == '__main__':
unittest.main()