asslayer 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. {asslayer-0.1.0 → asslayer-0.2.0}/.github/workflows/publish.yml +1 -1
  2. {asslayer-0.1.0 → asslayer-0.2.0}/.gitignore +1 -0
  3. asslayer-0.2.0/PKG-INFO +135 -0
  4. asslayer-0.2.0/README.md +125 -0
  5. {asslayer-0.1.0 → asslayer-0.2.0}/asslayer.pyi +15 -0
  6. {asslayer-0.1.0 → asslayer-0.2.0}/core/app/Application.cpp +166 -10
  7. {asslayer-0.1.0 → asslayer-0.2.0}/core/app/Application.hpp +17 -1
  8. {asslayer-0.1.0 → asslayer-0.2.0}/core/app/ApplicationController.cpp +86 -5
  9. {asslayer-0.1.0 → asslayer-0.2.0}/core/app/ApplicationController.hpp +18 -2
  10. {asslayer-0.1.0 → asslayer-0.2.0}/core/binding.cpp +95 -1
  11. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/AssRenderer.cpp +3 -0
  12. asslayer-0.2.0/core/renderer/HookRenderer.cpp +326 -0
  13. asslayer-0.2.0/core/renderer/HookRenderer.hpp +60 -0
  14. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/RenderManager.cpp +21 -0
  15. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/RenderManager.hpp +3 -0
  16. asslayer-0.2.0/core/renderer/ShaderRenderer.cpp +463 -0
  17. asslayer-0.2.0/core/renderer/ShaderRenderer.hpp +69 -0
  18. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/VulkanContext.cpp +122 -57
  19. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/VulkanContext.hpp +20 -3
  20. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/shaders/subtitle.frag +7 -7
  21. {asslayer-0.1.0 → asslayer-0.2.0}/meson.build +13 -1
  22. {asslayer-0.1.0 → asslayer-0.2.0}/pyproject.toml +1 -1
  23. asslayer-0.2.0/scripts/play-shader-scene.py +140 -0
  24. asslayer-0.2.0/tests/hook_render_test.cpp +117 -0
  25. asslayer-0.1.0/PKG-INFO +0 -72
  26. asslayer-0.1.0/README.md +0 -62
  27. {asslayer-0.1.0 → asslayer-0.2.0}/.clang-format +0 -0
  28. {asslayer-0.1.0 → asslayer-0.2.0}/LICENSE +0 -0
  29. {asslayer-0.1.0 → asslayer-0.2.0}/Makefile +0 -0
  30. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/CursorManager.cpp +0 -0
  31. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/CursorManager.hpp +0 -0
  32. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/CursorTracker.cpp +0 -0
  33. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/CursorTracker.hpp +0 -0
  34. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/DamageGrid.cpp +0 -0
  35. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/DamageGrid.hpp +0 -0
  36. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/DragManager.cpp +0 -0
  37. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/DragManager.hpp +0 -0
  38. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/InputManager.cpp +0 -0
  39. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/InputManager.hpp +0 -0
  40. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/KeyboardManager.cpp +0 -0
  41. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/KeyboardManager.hpp +0 -0
  42. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/RegionManager.cpp +0 -0
  43. {asslayer-0.1.0 → asslayer-0.2.0}/core/input/RegionManager.hpp +0 -0
  44. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/AssRenderer.hpp +0 -0
  45. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/IRenderer.hpp +0 -0
  46. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/Transition.cpp +0 -0
  47. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/Transition.hpp +0 -0
  48. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/shaders/imgui.frag +0 -0
  49. {asslayer-0.1.0 → asslayer-0.2.0}/core/renderer/shaders/subtitle.vert +0 -0
  50. {asslayer-0.1.0 → asslayer-0.2.0}/core/types/Common.hpp +0 -0
  51. {asslayer-0.1.0 → asslayer-0.2.0}/core/ui/UIManager.cpp +0 -0
  52. {asslayer-0.1.0 → asslayer-0.2.0}/core/ui/UIManager.hpp +0 -0
  53. {asslayer-0.1.0 → asslayer-0.2.0}/core/utils/FrameRateLimiter.cpp +0 -0
  54. {asslayer-0.1.0 → asslayer-0.2.0}/core/utils/FrameRateLimiter.hpp +0 -0
  55. {asslayer-0.1.0 → asslayer-0.2.0}/core/utils/Logger.hpp +0 -0
  56. {asslayer-0.1.0 → asslayer-0.2.0}/core/wayland/LayerShellProtocol.hpp +0 -0
  57. {asslayer-0.1.0 → asslayer-0.2.0}/core/wayland/LayerSurface.cpp +0 -0
  58. {asslayer-0.1.0 → asslayer-0.2.0}/core/wayland/LayerSurface.hpp +0 -0
  59. {asslayer-0.1.0 → asslayer-0.2.0}/core/wayland/WaylandContext.cpp +0 -0
  60. {asslayer-0.1.0 → asslayer-0.2.0}/core/wayland/WaylandContext.hpp +0 -0
  61. {asslayer-0.1.0 → asslayer-0.2.0}/protocol/wlr-layer-shell-unstable-v1.xml +0 -0
  62. {asslayer-0.1.0 → asslayer-0.2.0}/protocol/xdg-shell.xml +0 -0
  63. {asslayer-0.1.0 → asslayer-0.2.0}/scripts/fix_wayland_header.py +0 -0
  64. {asslayer-0.1.0 → asslayer-0.2.0}/scripts/test-wayland.sh +0 -0
  65. {asslayer-0.1.0 → asslayer-0.2.0}/tests/ass_render_test.cpp +0 -0
  66. {asslayer-0.1.0 → asslayer-0.2.0}/tests/test_wayland_state.py +0 -0
  67. {asslayer-0.1.0 → asslayer-0.2.0}/tests/transition_test.cpp +0 -0
  68. {asslayer-0.1.0 → asslayer-0.2.0}/tests/ui_menu_test.cpp +0 -0
  69. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/LICENSE.txt +0 -0
  70. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/backends/imgui_impl_vulkan.cpp +0 -0
  71. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/backends/imgui_impl_vulkan.h +0 -0
  72. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imconfig.h +0 -0
  73. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui.cpp +0 -0
  74. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui.h +0 -0
  75. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui_draw.cpp +0 -0
  76. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui_internal.h +0 -0
  77. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui_tables.cpp +0 -0
  78. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imgui_widgets.cpp +0 -0
  79. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imstb_rectpack.h +0 -0
  80. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imstb_textedit.h +0 -0
  81. {asslayer-0.1.0 → asslayer-0.2.0}/vendor/imgui/imstb_truetype.h +0 -0
@@ -41,7 +41,7 @@ jobs:
41
41
  - name: Install system build dependencies
42
42
  run: |
43
43
  sudo apt-get update
44
- sudo apt-get install -y g++ pkg-config ninja-build libwayland-dev libvulkan-dev glslc libass-dev libfontconfig1-dev
44
+ sudo apt-get install -y g++ pkg-config ninja-build libwayland-dev libvulkan-dev glslc libass-dev libfontconfig1-dev libplacebo-dev
45
45
  - name: Install Python build tools
46
46
  run: python -m pip install build twine
47
47
  - name: Build source distribution
@@ -7,3 +7,4 @@ __pycache__/
7
7
  .ruff_cache/
8
8
  .pytest_cache/
9
9
  /AGENTS.md
10
+ /docs/releasing.md
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.1
2
+ Name: asslayer
3
+ Version: 0.2.0
4
+ Summary: ASS subtitle desktop overlay for Wayland, rendered with libass and Vulkan
5
+ License: GPL-3.0-only
6
+ Project-URL: Repository, https://github.com/sitiyou/asslayer
7
+ Project-URL: Issues, https://github.com/sitiyou/asslayer/issues
8
+ Requires-Python: >=3.14
9
+ Description-Content-Type: text/markdown
10
+
11
+ # asslayer
12
+
13
+ Wayland desktop overlays for ASS subtitles and mpv shader Hooks, rendered with libass, libplacebo and Vulkan.
14
+ Python applications can supply ASS content, control playback and visibility,
15
+ and provide interactive menus. Requires a compositor supporting wlr-layer-shell.
16
+
17
+ ## Install
18
+
19
+ Requires Python 3.14+, a C++20 compiler, Meson 1.3+, Ninja, pkg-config,
20
+ Wayland (including wayland-scanner), Vulkan headers and loader, shaderc
21
+ (including glslc), libass, libplacebo 6.338 or later with Vulkan support, and fontconfig. Install the development headers
22
+ for these libraries when building from source.
23
+
24
+ From a source checkout:
25
+
26
+ ```bash
27
+ uv venv
28
+ uv pip install --group dev
29
+ uv pip install .
30
+ ```
31
+
32
+ ## Use
33
+
34
+ ```python
35
+ import time
36
+ from pathlib import Path
37
+
38
+ from asslayer import ApplicationController
39
+
40
+ ctrl = ApplicationController(namespace="my-subtitles")
41
+ try:
42
+ ctrl.set_ass_input(Path("subtitles.ass").read_text())
43
+ ctrl.set_status(start_time_ms=int(time.monotonic() * 1000))
44
+ ctrl.start()
45
+ input("Press Enter to stop\n")
46
+ finally:
47
+ ctrl.stop()
48
+ ctrl.join()
49
+ ```
50
+
51
+ Create controllers in a running Wayland session. The keyword-only `namespace`
52
+ defaults to `asslayer` and must be non-empty without NUL bytes. It identifies
53
+ the layer surface for compositor rules and cannot be changed after construction.
54
+ Run separate processes with different namespaces to distinguish overlays;
55
+ use a shared namespace when the same rules should apply to several overlays.
56
+ Concurrent controllers within one process are not supported.
57
+
58
+ `set_status` controls `paused`, `hidden`, `locked`, `start_time_ms`, and
59
+ `target_fps`. Read `state` for the current state and drag offsets.
60
+ Commands are asynchronous. `set_ass_input` accepts ASS text rather than a path.
61
+ `set_animation` configures visibility transitions, and `reset_drag` clears
62
+ position offsets.
63
+
64
+ Supply menus with `set_ui_menu`, using dictionaries with `label`, optional
65
+ `action`, and optional `children`. Read application actions with
66
+ `poll_ui_events` and keyboard events with `poll_key_events`.
67
+
68
+ Set `ASSLAYER_DEBUG=1` before importing asslayer to enable engine debug logs.
69
+ Unset it or set it to `0` to disable debug logs.
70
+
71
+ Call `ctrl.clear_input()` on a track change to clear ASS or shader lyrics while awaiting the next input. Playback and drag state carry over.
72
+
73
+ ## Play a single mpv Hook
74
+
75
+ Pass a complete Hook as bytes or text. Embedded shaders and textures are loaded
76
+ once. For a Hook declaring `//!PARAM PTS` with `//!TYPE DYNAMIC float`, asslayer
77
+ updates the absolute media time in seconds on each redraw, including a paused
78
+ seek. Pass `playback_time` to install a new Hook at a specific time. Omitting
79
+ it continues the current overlay clock.
80
+
81
+ ```python
82
+ from pathlib import Path
83
+ from asslayer import ApplicationController
84
+
85
+ ctrl = ApplicationController()
86
+ try:
87
+ ctrl.set_status(paused=True)
88
+ ctrl.set_hook_input(Path("song.hook").read_bytes(), playback_time=76.5)
89
+ ctrl.start()
90
+ input("Press Enter to play\n")
91
+ ctrl.set_status(paused=False)
92
+ input("Press Enter to close\n")
93
+ finally:
94
+ ctrl.stop()
95
+ ctrl.join()
96
+ ```
97
+
98
+ From this checkout, run `python scripts/play-shader-scene.py song.hook`.
99
+ Type a time in seconds to seek, `p` to play or pause, and `q` to quit.
100
+ A self-contained overlay Hook can declare its conservative drawing bounds with six dynamic float parameters. Initialize `OVERLAY_LEFT/TOP/RIGHT/BOTTOM` (four separate parameters) to normalized canvas edges and `OVERLAY_CANVAS_W/H` to zero. When cropping, asslayer sets the canvas dimensions in pixels and replaces left/top with the aligned crop origin in normalized units. The Hook maps local pixels back to full-canvas coordinates for drawing. Without these parameters asslayer renders the full surface.
101
+
102
+ Hook playback requires a libplacebo-compatible Vulkan device. The input is a
103
+ transparent RGBA canvas at the overlay's dimensions. Hooks that draw their own
104
+ content can overlay any desktop application. Hooks that sample the background
105
+ see transparent black. The rendered texture uses premultiplied alpha for
106
+ compositing. Unlocked Hooks support dragging and the context menu over tiles containing
107
+ visible pixels. Transparent tiles pass clicks through to the desktop.
108
+
109
+ ## Continuous shader overlays
110
+
111
+ Open a resource directory from kara-templater's `Scene.export_resources` with
112
+ `python scripts/play-shader-scene.py chorus-resources`. Enter an absolute song time
113
+ in seconds to seek, or enter `p` to toggle playback. The same pipeline and
114
+ textures serve every time in the exported interval.
115
+
116
+ To evaluate Python callbacks at each requested timestamp, put a zero-argument Scene
117
+ factory in a Python file and run it in an environment with kara-templater and
118
+ asslayer installed:
119
+
120
+ ```sh
121
+ python scripts/play-shader-scene.py song_scene.py --factory build_scene --fps 60
122
+ ```
123
+
124
+ The producer queries the factory's prepared Scene at the requested media time.
125
+ During playback it uses a monotonic clock and skips expired samples when
126
+ evaluation takes longer than a refresh interval. Each sample is submitted with
127
+ `set_shader_input(..., playback_time=seconds)` so the render thread presents
128
+ the matching resources and clock together. The renderer can reuse unchanged
129
+ SPIR-V and textures across samples. Portable scenes can seek directly with
130
+ `set_playback_time(seconds)`.
131
+
132
+ ## License
133
+
134
+ GPL-3.0-only. See LICENSE. Vendored Dear ImGui retains its own license in
135
+ `vendor/imgui/LICENSE.txt`.
@@ -0,0 +1,125 @@
1
+ # asslayer
2
+
3
+ Wayland desktop overlays for ASS subtitles and mpv shader Hooks, rendered with libass, libplacebo and Vulkan.
4
+ Python applications can supply ASS content, control playback and visibility,
5
+ and provide interactive menus. Requires a compositor supporting wlr-layer-shell.
6
+
7
+ ## Install
8
+
9
+ Requires Python 3.14+, a C++20 compiler, Meson 1.3+, Ninja, pkg-config,
10
+ Wayland (including wayland-scanner), Vulkan headers and loader, shaderc
11
+ (including glslc), libass, libplacebo 6.338 or later with Vulkan support, and fontconfig. Install the development headers
12
+ for these libraries when building from source.
13
+
14
+ From a source checkout:
15
+
16
+ ```bash
17
+ uv venv
18
+ uv pip install --group dev
19
+ uv pip install .
20
+ ```
21
+
22
+ ## Use
23
+
24
+ ```python
25
+ import time
26
+ from pathlib import Path
27
+
28
+ from asslayer import ApplicationController
29
+
30
+ ctrl = ApplicationController(namespace="my-subtitles")
31
+ try:
32
+ ctrl.set_ass_input(Path("subtitles.ass").read_text())
33
+ ctrl.set_status(start_time_ms=int(time.monotonic() * 1000))
34
+ ctrl.start()
35
+ input("Press Enter to stop\n")
36
+ finally:
37
+ ctrl.stop()
38
+ ctrl.join()
39
+ ```
40
+
41
+ Create controllers in a running Wayland session. The keyword-only `namespace`
42
+ defaults to `asslayer` and must be non-empty without NUL bytes. It identifies
43
+ the layer surface for compositor rules and cannot be changed after construction.
44
+ Run separate processes with different namespaces to distinguish overlays;
45
+ use a shared namespace when the same rules should apply to several overlays.
46
+ Concurrent controllers within one process are not supported.
47
+
48
+ `set_status` controls `paused`, `hidden`, `locked`, `start_time_ms`, and
49
+ `target_fps`. Read `state` for the current state and drag offsets.
50
+ Commands are asynchronous. `set_ass_input` accepts ASS text rather than a path.
51
+ `set_animation` configures visibility transitions, and `reset_drag` clears
52
+ position offsets.
53
+
54
+ Supply menus with `set_ui_menu`, using dictionaries with `label`, optional
55
+ `action`, and optional `children`. Read application actions with
56
+ `poll_ui_events` and keyboard events with `poll_key_events`.
57
+
58
+ Set `ASSLAYER_DEBUG=1` before importing asslayer to enable engine debug logs.
59
+ Unset it or set it to `0` to disable debug logs.
60
+
61
+ Call `ctrl.clear_input()` on a track change to clear ASS or shader lyrics while awaiting the next input. Playback and drag state carry over.
62
+
63
+ ## Play a single mpv Hook
64
+
65
+ Pass a complete Hook as bytes or text. Embedded shaders and textures are loaded
66
+ once. For a Hook declaring `//!PARAM PTS` with `//!TYPE DYNAMIC float`, asslayer
67
+ updates the absolute media time in seconds on each redraw, including a paused
68
+ seek. Pass `playback_time` to install a new Hook at a specific time. Omitting
69
+ it continues the current overlay clock.
70
+
71
+ ```python
72
+ from pathlib import Path
73
+ from asslayer import ApplicationController
74
+
75
+ ctrl = ApplicationController()
76
+ try:
77
+ ctrl.set_status(paused=True)
78
+ ctrl.set_hook_input(Path("song.hook").read_bytes(), playback_time=76.5)
79
+ ctrl.start()
80
+ input("Press Enter to play\n")
81
+ ctrl.set_status(paused=False)
82
+ input("Press Enter to close\n")
83
+ finally:
84
+ ctrl.stop()
85
+ ctrl.join()
86
+ ```
87
+
88
+ From this checkout, run `python scripts/play-shader-scene.py song.hook`.
89
+ Type a time in seconds to seek, `p` to play or pause, and `q` to quit.
90
+ A self-contained overlay Hook can declare its conservative drawing bounds with six dynamic float parameters. Initialize `OVERLAY_LEFT/TOP/RIGHT/BOTTOM` (four separate parameters) to normalized canvas edges and `OVERLAY_CANVAS_W/H` to zero. When cropping, asslayer sets the canvas dimensions in pixels and replaces left/top with the aligned crop origin in normalized units. The Hook maps local pixels back to full-canvas coordinates for drawing. Without these parameters asslayer renders the full surface.
91
+
92
+ Hook playback requires a libplacebo-compatible Vulkan device. The input is a
93
+ transparent RGBA canvas at the overlay's dimensions. Hooks that draw their own
94
+ content can overlay any desktop application. Hooks that sample the background
95
+ see transparent black. The rendered texture uses premultiplied alpha for
96
+ compositing. Unlocked Hooks support dragging and the context menu over tiles containing
97
+ visible pixels. Transparent tiles pass clicks through to the desktop.
98
+
99
+ ## Continuous shader overlays
100
+
101
+ Open a resource directory from kara-templater's `Scene.export_resources` with
102
+ `python scripts/play-shader-scene.py chorus-resources`. Enter an absolute song time
103
+ in seconds to seek, or enter `p` to toggle playback. The same pipeline and
104
+ textures serve every time in the exported interval.
105
+
106
+ To evaluate Python callbacks at each requested timestamp, put a zero-argument Scene
107
+ factory in a Python file and run it in an environment with kara-templater and
108
+ asslayer installed:
109
+
110
+ ```sh
111
+ python scripts/play-shader-scene.py song_scene.py --factory build_scene --fps 60
112
+ ```
113
+
114
+ The producer queries the factory's prepared Scene at the requested media time.
115
+ During playback it uses a monotonic clock and skips expired samples when
116
+ evaluation takes longer than a refresh interval. Each sample is submitted with
117
+ `set_shader_input(..., playback_time=seconds)` so the render thread presents
118
+ the matching resources and clock together. The renderer can reuse unchanged
119
+ SPIR-V and textures across samples. Portable scenes can seek directly with
120
+ `set_playback_time(seconds)`.
121
+
122
+ ## License
123
+
124
+ GPL-3.0-only. See LICENSE. Vendored Dear ImGui retains its own license in
125
+ `vendor/imgui/LICENSE.txt`.
@@ -12,7 +12,22 @@ class ApplicationController:
12
12
  def start(self) -> None: ...
13
13
  def stop(self) -> None: ...
14
14
  def join(self) -> None: ...
15
+ def clear_input(self) -> None: ...
15
16
  def set_ass_input(self, content: str) -> None: ...
17
+ def set_hook_input(self, content: bytes | str, *, playback_time: float | None = None) -> None: ...
18
+ def set_shader_input(
19
+ self,
20
+ *,
21
+ vertex: bytes,
22
+ fragment: bytes,
23
+ mask: bytes,
24
+ mask_size: tuple[int, int],
25
+ records: bytes,
26
+ record_size: tuple[int, int],
27
+ material_inputs: list[float] = ...,
28
+ playback_time: float | None = None,
29
+ ) -> None: ...
30
+ def set_playback_time(self, seconds: float) -> None: ...
16
31
  def set_animation(
17
32
  self,
18
33
  effect: str,
@@ -1,5 +1,7 @@
1
1
  #include "core/app/Application.hpp"
2
2
  #include "core/renderer/AssRenderer.hpp"
3
+ #include "core/renderer/HookRenderer.hpp"
4
+ #include "core/renderer/ShaderRenderer.hpp"
3
5
  #include "core/utils/Logger.hpp"
4
6
  #include "core/wayland/LayerShellProtocol.hpp"
5
7
  #include "wlr-layer-shell-unstable-v1-cpp.h"
@@ -15,6 +17,7 @@
15
17
  #include <linux/input-event-codes.h>
16
18
  #include <poll.h>
17
19
  #include <stdexcept>
20
+ #include <sys/eventfd.h>
18
21
  #include <unistd.h>
19
22
 
20
23
  static const wl_callback_listener frameListener = {Application::frameDone};
@@ -26,6 +29,12 @@ static int64_t nowMs() {
26
29
  return static_cast<int64_t>(ts.tv_sec) * 1000 + ts.tv_nsec / 1000000;
27
30
  }
28
31
 
32
+ static double nowSeconds() {
33
+ struct timespec ts;
34
+ clock_gettime(CLOCK_MONOTONIC, &ts);
35
+ return static_cast<double>(ts.tv_sec) + ts.tv_nsec * 1e-9;
36
+ }
37
+
29
38
  Application::Application(const std::string &surfaceNamespace)
30
39
  : m_namespace(surfaceNamespace) {
31
40
  if (m_namespace.empty() || m_namespace.find('\0') != std::string::npos) {
@@ -41,12 +50,22 @@ Application::Application(const std::string &surfaceNamespace)
41
50
  if (!initRenderer()) {
42
51
  throw std::runtime_error("Failed to initialize ASS renderer");
43
52
  }
53
+ m_commandFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
54
+ if (m_commandFd < 0) {
55
+ LAY_ERR("Command wakeup unavailable: %s", strerror(errno));
56
+ }
44
57
  LAY_LOG("application initialized");
45
58
  }
46
59
 
47
60
  Application::~Application() {
48
61
  LAY_LOG("application shutting down");
62
+ if (m_commandFd >= 0) {
63
+ close(m_commandFd);
64
+ }
49
65
  cancelFrameCallback();
66
+ if (m_vk.device()) {
67
+ vkDeviceWaitIdle(m_vk.device());
68
+ }
50
69
  }
51
70
 
52
71
  void Application::run() {
@@ -77,6 +96,13 @@ void Application::run() {
77
96
  }
78
97
 
79
98
  bool Application::initWayland() {
99
+ const bool reinitialize = m_vk.device() != VK_NULL_HANDLE;
100
+ if (reinitialize) {
101
+ vkDeviceWaitIdle(m_vk.device());
102
+ m_uiMgr.shutdown();
103
+ m_renderMgr.shutdown();
104
+ m_vk.shutdown();
105
+ }
80
106
  wl_output *output = nullptr;
81
107
  if (!m_waylandCtx.outputs.empty()) {
82
108
  output = m_waylandCtx.outputs[0].output;
@@ -103,6 +129,13 @@ bool Application::initWayland() {
103
129
  return false;
104
130
  }
105
131
 
132
+ if (reinitialize) {
133
+ if (!m_renderMgr.initialize(m_vk) || !m_uiMgr.initialize(m_vk)) {
134
+ return false;
135
+ }
136
+ m_renderMgr.setSize(m_vk.width(), m_vk.height());
137
+ m_renderMgr.reset();
138
+ }
106
139
  m_damageGrid.setSurfaceSize(m_surface.width(), m_surface.height());
107
140
 
108
141
  m_surface.setConfigureCallback(
@@ -187,11 +220,9 @@ void Application::mainLoop() {
187
220
  }
188
221
  m_waylandCtx.flush();
189
222
 
190
- struct pollfd fd = {};
191
- fd.fd = m_waylandCtx.displayFd();
192
- fd.events = POLLIN;
193
-
194
- int ret = poll(&fd, 1, 16);
223
+ pollfd fds[] = {{m_waylandCtx.displayFd(), POLLIN, 0},
224
+ {m_commandFd, POLLIN, 0}};
225
+ int ret = poll(fds, 2, 16);
195
226
  if (ret < 0) {
196
227
  if (errno == EINTR) {
197
228
  m_waylandCtx.cancelRead();
@@ -203,7 +234,12 @@ void Application::mainLoop() {
203
234
  break;
204
235
  }
205
236
 
206
- if (fd.revents & POLLIN) {
237
+ if (fds[1].revents & POLLIN) {
238
+ eventfd_t count;
239
+ while (eventfd_read(m_commandFd, &count) < 0 && errno == EINTR) {
240
+ }
241
+ }
242
+ if (fds[0].revents & POLLIN) {
207
243
  if (m_waylandCtx.readEvents() < 0) {
208
244
  LAY_ERR("Wayland read events error");
209
245
  m_running = false;
@@ -214,9 +250,9 @@ void Application::mainLoop() {
214
250
  m_running = false;
215
251
  break;
216
252
  }
217
- } else if (fd.revents) {
253
+ } else if (fds[0].revents) {
218
254
  // POLLERR/POLLHUP/POLLNVAL: connection lost
219
- LAY_ERR("Wayland connection lost (revents=0x%x)", fd.revents);
255
+ LAY_ERR("Wayland connection lost (revents=0x%x)", fds[0].revents);
220
256
  m_waylandCtx.cancelRead();
221
257
  m_running = false;
222
258
  break;
@@ -253,10 +289,23 @@ void Application::processState() {
253
289
  m_hideFinalized = false;
254
290
  m_introPlayed = true;
255
291
  }
292
+ const double currentSeconds = nowSeconds();
256
293
  if (m_state.paused && !prevPaused) {
257
294
  m_freezeTimestampMs = nowMs() - m_state.startTimeMs;
295
+ m_shaderFreeze = currentSeconds -
296
+ m_shaderEpoch.value_or(m_state.startTimeMs / 1000.0);
297
+ }
298
+ if (!m_state.paused && prevPaused && (m_shaderEpoch || m_hookRenderer) &&
299
+ !m_pendingShaderTime) {
300
+ m_shaderEpoch = currentSeconds - m_shaderFreeze;
301
+ }
302
+ if (m_pendingShaderTime) {
303
+ m_shaderFreeze = *m_pendingShaderTime;
304
+ m_shaderEpoch = currentSeconds - *m_pendingShaderTime;
305
+ m_pendingShaderTime.reset();
258
306
  }
259
307
  if (m_state.locked != prevLocked) {
308
+ m_renderMgr.reset();
260
309
  if (m_state.locked) {
261
310
  m_uiMgr.closeNow();
262
311
  }
@@ -306,6 +355,8 @@ bool Application::isFrameNeeded() const {
306
355
  return m_running && m_surface.isConfigured() && m_vk.isReady() &&
307
356
  (!m_state.hidden || m_transition.isActive() || m_uiMgr.isActive()) &&
308
357
  (!m_state.paused || !m_renderMgr.hasRendered() ||
358
+ (!m_state.hidden && m_shaderRenderer &&
359
+ m_shaderRenderer->needsUpload()) ||
309
360
  m_dragMgr.isDragging() || m_renderMgr.hasOffsetChanged() ||
310
361
  m_uiMgr.isActive() || m_transition.isActive());
311
362
  }
@@ -322,6 +373,18 @@ void Application::produceFrame(int64_t timestampMs) {
322
373
 
323
374
  bool showLyrics = !m_state.hidden || m_transition.isActive();
324
375
  if (showLyrics) {
376
+ if (m_shaderRenderer || m_hookRenderer) {
377
+ const double seconds =
378
+ m_state.paused
379
+ ? m_shaderFreeze
380
+ : nowSeconds() -
381
+ m_shaderEpoch.value_or(m_state.startTimeMs / 1000.0);
382
+ if (m_hookRenderer) {
383
+ m_hookRenderer->setHitTesting(!m_state.locked && !m_state.hidden);
384
+ m_hookRenderer->setPlaybackTime(seconds);
385
+ } else
386
+ m_shaderRenderer->setPlaybackTime(seconds);
387
+ }
325
388
  m_renderMgr.prepare(timestampMs);
326
389
  }
327
390
  // Glyphs appearing for the first time animate in; this must be decided
@@ -418,7 +481,13 @@ void Application::updateInputRegion() {
418
481
 
419
482
  std::vector<RenderRect> regions;
420
483
  if (!m_state.locked && !m_state.hidden) {
421
- if (m_renderMgr.hasContentChanged()) {
484
+ if (m_hookRenderer) {
485
+ for (auto rect : m_hookRenderer->hitRegions()) {
486
+ rect.x += static_cast<int>(m_state.dragOffsetX);
487
+ rect.y += static_cast<int>(m_state.dragOffsetY);
488
+ regions.push_back(rect);
489
+ }
490
+ } else if (m_renderMgr.hasContentChanged()) {
422
491
  // Grid cells were populated in produceFrame (before the present).
423
492
  regions = m_damageGrid.buildRegions();
424
493
  } else {
@@ -490,12 +559,87 @@ void Application::setInputInteractive(bool on) {
490
559
  LAY_DEBUG("keyboard interactivity -> %s", on ? "ON_DEMAND" : "NONE");
491
560
  }
492
561
 
562
+ void Application::removeOverlay() {
563
+ if (m_hookRenderer || m_shaderRenderer) {
564
+ vkDeviceWaitIdle(m_vk.device());
565
+ if (m_hookRenderer)
566
+ m_renderMgr.removeRenderer(m_hookRenderer);
567
+ if (m_shaderRenderer)
568
+ m_renderMgr.removeRenderer(m_shaderRenderer);
569
+ m_hookRenderer = nullptr;
570
+ m_shaderRenderer = nullptr;
571
+ }
572
+ }
573
+
574
+ bool Application::loadHookContent(std::string content) {
575
+ auto hook = std::make_unique<HookRenderer>(std::move(content));
576
+ if (!hook->initialize(m_vk)) {
577
+ LAY_ERR("Failed to load libplacebo Hook; check shader syntax and "
578
+ "Vulkan device features");
579
+ return false;
580
+ }
581
+ removeOverlay();
582
+ m_assRenderer->loadContent("");
583
+ if (!m_shaderEpoch && !m_state.startTimeMs && !m_pendingShaderTime)
584
+ setPlaybackTime(0.0);
585
+ m_hookRenderer = hook.get();
586
+ m_renderMgr.addRenderer(std::move(hook));
587
+ m_renderMgr.reset();
588
+ LAY_LOG("Loaded libplacebo Hook");
589
+ return true;
590
+ }
591
+
592
+ void Application::clearInput() {
593
+ // Present before retiring GPU resources or preparing the next input.
594
+ cancelFrameCallback();
595
+ if (!m_state.hidden && !m_uiMgr.isActive())
596
+ clearDisplay();
597
+ removeOverlay();
598
+ m_assRenderer->loadContent("");
599
+ m_renderMgr.reset();
600
+ }
601
+
493
602
  void Application::loadAssContent(const std::string &content) {
603
+ removeOverlay();
494
604
  m_assRenderer->loadContent(content);
495
605
  m_renderMgr.reset();
496
606
  LAY_LOG("Loaded ASS content (%zu bytes)", content.size());
497
607
  }
498
608
 
609
+ bool Application::loadShaderContent(ShaderScene scene) {
610
+ auto renderer = std::make_unique<ShaderRenderer>(std::move(scene));
611
+ if (m_shaderRenderer && m_shaderRenderer->updateResources(*renderer)) {
612
+ m_renderMgr.reset();
613
+ return true;
614
+ }
615
+ if (!renderer->initializeReplacing(m_vk, m_shaderRenderer)) {
616
+ LAY_ERR("Failed to initialize shader overlay scene");
617
+ return false;
618
+ }
619
+ removeOverlay();
620
+ m_assRenderer->loadContent("");
621
+ m_shaderRenderer = renderer.get();
622
+ m_renderMgr.addRenderer(std::move(renderer));
623
+ m_renderMgr.reset();
624
+ return true;
625
+ }
626
+
627
+ void Application::setStartTime(int64_t value) {
628
+ m_state.startTimeMs = value;
629
+ m_shaderEpoch.reset();
630
+ m_shaderFreeze = nowSeconds() - value / 1000.0;
631
+ if (m_shaderRenderer || m_hookRenderer) {
632
+ m_renderMgr.reset();
633
+ }
634
+ }
635
+
636
+ void Application::setPlaybackTime(double value) {
637
+ m_pendingShaderTime = value;
638
+ if (m_shaderRenderer || m_hookRenderer) {
639
+ m_renderMgr.reset();
640
+ }
641
+ }
642
+
499
643
  void Application::setUiMenuItems(std::vector<UiMenuItem> items) {
500
644
  m_uiMgr.setMenuItems(std::move(items));
501
645
  LAY_DEBUG("UI menu items updated");
@@ -519,7 +663,19 @@ void Application::resetDrag() {
519
663
  LAY_DEBUG("drag offset reset");
520
664
  }
521
665
 
522
- void Application::requestStop() { m_running = false; }
666
+ void Application::wakeForCommands() const {
667
+ // A single read drains all notifications. A full counter is already
668
+ // readable.
669
+ if (m_commandFd >= 0) {
670
+ while (eventfd_write(m_commandFd, 1) < 0 && errno == EINTR) {
671
+ }
672
+ }
673
+ }
674
+
675
+ void Application::requestStop() {
676
+ m_running = false;
677
+ wakeForCommands();
678
+ }
523
679
 
524
680
  void Application::setTargetFps(int fps) {
525
681
  m_state.targetFps = fps;
@@ -4,6 +4,7 @@
4
4
  #include <cstdint>
5
5
  #include <functional>
6
6
  #include <memory>
7
+ #include <optional>
7
8
  #include <string>
8
9
 
9
10
  #include "core/input/CursorManager.hpp"
@@ -23,6 +24,9 @@
23
24
 
24
25
  struct wl_callback;
25
26
  class AssRenderer;
27
+ class ShaderRenderer;
28
+ class HookRenderer;
29
+ struct ShaderScene;
26
30
 
27
31
  class ApplicationController;
28
32
 
@@ -38,7 +42,11 @@ class Application {
38
42
 
39
43
  void run();
40
44
 
45
+ void clearInput();
41
46
  void loadAssContent(const std::string &content);
47
+ bool loadHookContent(std::string content);
48
+ bool loadShaderContent(ShaderScene scene);
49
+ void setPlaybackTime(double seconds);
42
50
  void requestStop();
43
51
  void setUiMenuItems(std::vector<UiMenuItem> items);
44
52
  // Queue a menu open at surface coordinates (tray ContextMenu); consumed by
@@ -49,7 +57,7 @@ class Application {
49
57
  void setPaused(bool v) { m_state.paused = v; }
50
58
  void setHidden(bool v) { m_state.hidden = v; }
51
59
  void setLocked(bool v) { m_state.locked = v; }
52
- void setStartTime(int64_t v) { m_state.startTimeMs = v; }
60
+ void setStartTime(int64_t v);
53
61
  void setTargetFps(int v);
54
62
  void setTransitionConfig(TransitionEffect effect, int durationMs,
55
63
  int amplitude);
@@ -87,9 +95,17 @@ class Application {
87
95
  // pointer is inside the input region, NONE otherwise.
88
96
  bool m_keyboardInteractive = false;
89
97
 
98
+ int m_commandFd = -1;
99
+ void wakeForCommands() const;
90
100
  std::atomic<bool> m_running{false};
91
101
  wl_callback *m_frameCallback = nullptr;
92
102
  AssRenderer *m_assRenderer = nullptr;
103
+ void removeOverlay();
104
+ HookRenderer *m_hookRenderer = nullptr;
105
+ ShaderRenderer *m_shaderRenderer = nullptr;
106
+ std::optional<double> m_shaderEpoch;
107
+ std::optional<double> m_pendingShaderTime;
108
+ double m_shaderFreeze = 0.0;
93
109
  std::function<void()> m_processCommands;
94
110
  std::function<void(const KeyEvent &)> m_keyEventSink;
95
111
  std::function<void(const std::string &)> m_uiEventSink;