mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9396818fe4 | ||
|
|
dc14c9823a |
No files matched your search
@@ -0,0 +1,28 @@
|
||||
name: Build verified producer acquire Gamescope artifact
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [build/verified-producer-acquire-gamescope]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-24.04-arm
|
||||
timeout-minutes: 120
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Build in Arch Linux ARM
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker run --rm -v "$PWD:/work" -w /work menci/archlinuxarm:base-devel bash tools/gamescope/build-in-arch.sh
|
||||
sudo chown -R "$(id -u):$(id -g)" .
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gamescope-patched
|
||||
path: |
|
||||
gamescope.tzst
|
||||
gamescope.tzst.sha256
|
||||
@@ -307,9 +307,6 @@ jobs:
|
||||
aarch64-linux-gnu-gcc -O2 -Wall -o "$D/usr/local/bin/droiddeck-glprobe" tools/venus/glprobe.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/usr/local/bin/droiddeck-glprobe"
|
||||
|
||||
- name: Build the LSE atomics emulator for ARMv8.0 CPUs
|
||||
run: bash tools/linuxfs/lse-emu/build.sh app/src/main/assets/linuxfs
|
||||
|
||||
- name: Check the preloads
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -955,7 +952,6 @@ jobs:
|
||||
with:
|
||||
artifact: droiddeck-signed
|
||||
variant: standard
|
||||
fail_on_detection: true
|
||||
secrets: inherit
|
||||
|
||||
packs:
|
||||
|
||||
@@ -178,10 +178,8 @@ jobs:
|
||||
PY
|
||||
after=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l)
|
||||
[ "$after" -gt "${ROBOLECTRIC_JARS_BEFORE:-0}" ] && echo "save=true" >> "$GITHUB_OUTPUT" || true
|
||||
# A pull request's cache is visible only to that pull request, and each copy is hundreds of megabytes against the
|
||||
# repository's 10 GB cache limit. Only main saves, so every pull request restores main's set.
|
||||
- name: Store Robolectric's Android jars
|
||||
if: always() && github.event_name != 'pull_request' && steps.robolectric-jars-final.outputs.save == 'true'
|
||||
if: always() && steps.robolectric-jars-final.outputs.save == 'true'
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: ${{ steps.robolectric-jars.outputs.path }}
|
||||
|
||||
@@ -68,7 +68,6 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
|
||||
- Runtime, shim, input and controller work build on WinNative and Bannerlator by maxjivi05.
|
||||
- mmap ring buffer controller input by ribbit384 ([WinNative #345](https://github.com/WinNative-Emu/WinNative/pull/345)).
|
||||
- [FEX](https://github.com/FEX-Emu/FEX) (MIT) runs x86 code. DroidDeck's build puts the platform name under `AT_PLATFORM` so [sharun](https://github.com/VHSgunzo/sharun) AppImages by VHSgunzo (MIT) start through its [userland-execve](https://crates.io/crates/userland-execve) loader (MIT), and its GL thunk hands X errors to the program's own error handler. FEX's code disk cache was checked in its source. The fix for host stack left behind when a program leaves a signal handler without returning follows the approach suggested in [FEX-Emu/FEX#2487](https://github.com/FEX-Emu/FEX/issues/2487). The host stack fix for system calls that end a block is a backport of Ryan Houdek's [FEX-Emu/FEX#6122](https://github.com/FEX-Emu/FEX/pull/6122).
|
||||
- Anti-cheat support under FEX is the work of [StonkGuy](https://github.com/StonkGuy): the x86-64 ptrace, seccomp and `/proc` emulation from his [FEX fork](https://github.com/StonkGuy/FEX) (`eac-2611` branch, MIT) is carried as build patch 0021 with his authorship, patches 0022 to 0029 build on it, and his `eac-tests` regression suite verifies them.
|
||||
- x86-64 programs on Wayland reach the GPU through FEX's Wayland client, wayland-egl and EGL thunks. The guest `wl_list` and `wl_array` helpers follow [libwayland](https://gitlab.freedesktop.org/wayland/wayland)'s `src/wayland-util.c` (MIT). The EGL extension table comes from the [Khronos EGL registry](https://github.com/KhronosGroup/EGL-Registry) (Apache-2.0) and Mesa's `egl_other.xml` (MIT).
|
||||
- x86 AppImages, and arm64 ones whose runtime can't unpack on Android, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence.
|
||||
- DwarFS AppImages are unpacked without proot by `dwarfsextract` from [DwarFS](https://github.com/mhx/dwarfs) by Marcus Holland-Moritz (MIT), the release binary uruntime embeds, taken out of its self-extracting wrapper and shipped with its licence.
|
||||
@@ -114,7 +113,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
|
||||
- Steam audio goes through [@The412Banner](https://github.com/The412Banner)'s [DirectAudio](https://github.com/The412Banner/directaudio) PulseAudio sink (LGPL-2.1-or-later), built from `tools/directaudio/sink`.
|
||||
- The DroidDeck HUD is [@The412Banner](https://github.com/The412Banner)'s [FusionHUD](https://github.com/The412Banner/FusionHUD) (GPL-3.0 with an attribution term). Its readings match Valve's [MangoHud](https://github.com/flightlessmango/MangoHud) build (MIT), with frame times from gamescope patch 0125.
|
||||
- The HUD's CPU, GPU load, thermal and battery readers come from [@xXJSONDeruloXx](https://github.com/xXJSONDeruloXx)'s work.
|
||||
- LSFG frame generation comes from Camille LaVey and the [Eden](https://eden-emu.dev) project, following [lsfg-vk](https://github.com/PancakeTAS/lsfg-vk), ported by [@maxjivi05](https://github.com/maxjivi05). It requires [Lossless Scaling](https://store.steampowered.com/app/993090/) installed through Steam and ships none of its shaders.
|
||||
- LSFG frame generation comes from Camille LaVey and the [Eden](https://eden-emu.dev) project, following [lsfg-vk](https://github.com/PancakeTAS/lsfg-vk), ported by [@maxjivi05](https://github.com/maxjivi05). It needs your own copy of [Lossless Scaling](https://store.steampowered.com/app/993090/) and ships none of its shaders.
|
||||
- Black frame insertion follows the design of [@artzox](https://github.com/artzox)'s [BFI Presenter](https://github.com/artzox/BFI-Presenter) (GPL-3.0): the strobe runs on the display's refresh clock and the game is paced to the lit refresh. Both build on [Blur Busters](https://blurbusters.com)' research on MPRT and motion blur. No BFI Presenter code is used.
|
||||
- Remote Play decodes through Android's MediaCodec or the [FFmpeg](https://ffmpeg.org) (LGPL-2.1-or-later) in Steam's runtime. Qualcomm low latency settings follow [Moonlight](https://github.com/moonlight-stream/moonlight-android) (GPL-3.0).
|
||||
- [PipeWire](https://gitlab.freedesktop.org/pipewire/pipewire) (MIT) sockets use the settings in its `module-access.c`, and [WirePlumber](https://gitlab.freedesktop.org/pipewire/wireplumber) (MIT) keeps those clients at full permissions.
|
||||
@@ -157,13 +156,6 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Setup and tools</b></summary>
|
||||
|
||||
- The wireless debugging pairing keypad was inspired by Ryan Retro’s Handheld Toolkit.
|
||||
|
||||
</details>
|
||||
|
||||
## Star history
|
||||
|
||||
<a href="https://www.star-history.com/#Droid-Deck/DroidDeck&Date">
|
||||
|
||||
@@ -59,7 +59,7 @@ internal fun sampleState(
|
||||
internal val sampleActions: FrontEndActions = FrontEndActions(
|
||||
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {}, onRom = {}, onResume = {},
|
||||
onSteamSettings = {}, onDesktopSettings = {}, onInstallPackage = {}, onRemovePackage = {}, onRuntime = {},
|
||||
onFrameGenPick = {}, onProtons = {}, onComponents = {}, onPerformance = {}, onRoms = {},
|
||||
onFrameGenPick = {}, onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {}, onRoms = {},
|
||||
onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
)
|
||||
@@ -82,7 +82,7 @@ internal fun sampleDrawerActions(
|
||||
secondScreenDisplays = listOfNotNull(secondScreen?.let { SecondScreenDisplay(2, "Built-in · 1240×1080") }),
|
||||
selectedSecondScreenDisplay = if (secondScreen != null) 2 else -1, onSecondScreenDisplay = {},
|
||||
gameSwapAvailable = secondScreen != null, dashboardAvailable = secondScreen != null,
|
||||
onKeyboard = {}, onHardwareKeyboard = {},
|
||||
onImportLossless = {}, onKeyboard = {}, onHardwareKeyboard = {},
|
||||
onSteamMenu = if (steam) ({}) else null, onQam = if (steam) ({}) else null,
|
||||
onLaunchAndroidApp = { _, _ -> }, onBackground = {}, onShareLogs = {}, onStop = {}, onClose = {},
|
||||
)
|
||||
@@ -40,8 +40,6 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
|
||||
|
||||
@@ -28,19 +28,6 @@ float_code() {
|
||||
[ "$result" = ok ]
|
||||
}
|
||||
|
||||
# git pushes through gh's sign-in and commits as the signed-in account, with its no-reply address.
|
||||
configure_git() {
|
||||
gh auth setup-git || return 1
|
||||
[ -n "$(git config --global user.name)" ] && [ -n "$(git config --global user.email)" ] && return 0
|
||||
local user id login name
|
||||
user=$(gh api user -q '"\(.id) \(.login) \(.name // .login)"') || return 1
|
||||
read -r id login name <<<"$user"
|
||||
[ -n "$id" ] && [ -n "$login" ] || return 1
|
||||
[ -n "$(git config --global user.name)" ] || git config --global user.name "${name:-$login}"
|
||||
[ -n "$(git config --global user.email)" ] || git config --global user.email "$id+$login@users.noreply.github.com"
|
||||
}
|
||||
if [ "${1:-}" = --git ]; then configure_git; exit; fi
|
||||
|
||||
coproc GH { BROWSER=true gh auth login --hostname github.com --git-protocol https --web 2>&1; }
|
||||
gh_pid=$GH_PID
|
||||
exec {ghout}<&"${GH[0]}" {ghin}>&"${GH[1]}"
|
||||
@@ -61,9 +48,5 @@ while IFS= read -r line <&"$ghout"; do
|
||||
done
|
||||
wait "$gh_pid"
|
||||
status=$?
|
||||
if [ $status = 0 ] && ! configure_git; then
|
||||
echo "Signed in, but git could not be set up: run dd-gh-login --git"
|
||||
status=1
|
||||
fi
|
||||
[ -n "$shown" ] && [ -n "$inbox" ] && [ -d "$inbox" ] && : > "$inbox/device-code"
|
||||
exit $status
|
||||
@@ -10,17 +10,6 @@ add_subdirectory(adrenotools)
|
||||
|
||||
add_subdirectory(thirdparty/dxbc)
|
||||
|
||||
# Pin ZeroFG to a fixed revision instead of vendoring thousands of generated shader lines.
|
||||
include(FetchContent)
|
||||
set(ZEROFG_VULKAN_HEADERS_DIR "${CMAKE_SYSROOT}/usr/include" CACHE PATH "" FORCE)
|
||||
set(ZEROFG_PREBUILT_SHADERS ON CACHE STRING "" FORCE)
|
||||
FetchContent_Declare(zerofg
|
||||
GIT_REPOSITORY https://github.com/hy300leosquizz-ctrl/ZeroFG.git
|
||||
GIT_TAG e6ca7ef9f9765db89847b6d8eed352e458f1a8bb
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
FetchContent_MakeAvailable(zerofg)
|
||||
|
||||
set(DDFG_UPSTREAM "v0.3.0")
|
||||
set(DDFG_CHAIN_SRC
|
||||
framegen/ddfg/framegen.cpp
|
||||
|
||||
@@ -329,28 +329,16 @@ static constexpr int kWatchedFds = 1 << 16;
|
||||
static constexpr int kWatchedBits = sizeof(unsigned long) * 8;
|
||||
static std::atomic<unsigned long> watched_fds[kWatchedFds / kWatchedBits];
|
||||
static std::atomic<bool> watched_beyond{false};
|
||||
static std::atomic<int> watched_count{0};
|
||||
|
||||
static void watch_fd(int fd) {
|
||||
if (fd < 0) return;
|
||||
if (fd >= kWatchedFds) {
|
||||
watched_beyond.store(true, std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
const unsigned long bit = 1UL << (fd % kWatchedBits);
|
||||
if (!(watched_fds[fd / kWatchedBits].fetch_or(bit, std::memory_order_acq_rel) & bit))
|
||||
watched_count.fetch_add(1, std::memory_order_acq_rel);
|
||||
if (fd >= kWatchedFds) watched_beyond.store(true, std::memory_order_release);
|
||||
else watched_fds[fd / kWatchedBits].fetch_or(1UL << (fd % kWatchedBits), std::memory_order_release);
|
||||
}
|
||||
|
||||
static void unwatch_fd(int fd) {
|
||||
if (fd < 0 || fd >= kWatchedFds) return;
|
||||
const unsigned long bit = 1UL << (fd % kWatchedBits);
|
||||
if (watched_fds[fd / kWatchedBits].fetch_and(~bit, std::memory_order_acq_rel) & bit)
|
||||
watched_count.fetch_sub(1, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
static bool any_watched() {
|
||||
return watched_count.load(std::memory_order_acquire) > 0 || watched_beyond.load(std::memory_order_acquire);
|
||||
if (fd >= 0 && fd < kWatchedFds)
|
||||
watched_fds[fd / kWatchedBits].fetch_and(~(1UL << (fd % kWatchedBits)), std::memory_order_release);
|
||||
}
|
||||
|
||||
static bool watched(int fd) {
|
||||
@@ -4281,7 +4269,7 @@ static int poll_fake(struct pollfd *fds, nfds_t nfds, int timeout,
|
||||
const auto my_poll = next_symbol<decltype(&::poll)>(Next::poll);
|
||||
const auto my_ppoll = next_symbol<decltype(&::ppoll)>(Next::ppoll);
|
||||
|
||||
nfds_t first = any_watched() ? 0 : nfds;
|
||||
nfds_t first = 0;
|
||||
while (first < nfds && !watched(fds[first].fd)) first++;
|
||||
bool has_fake_fds = false;
|
||||
std::vector<struct pollfd> real_fds;
|
||||
@@ -4384,12 +4372,12 @@ EXPORT int poll(struct pollfd *fds, nfds_t nfds, int timeout) {
|
||||
EXPORT int ppoll(struct pollfd *fds, nfds_t nfds,
|
||||
const struct timespec *timeout, const sigset_t *sigmask) {
|
||||
const auto my_ppoll = next_symbol<decltype(&::ppoll)>(Next::ppoll);
|
||||
for (nfds_t i = 0; any_watched() && i < nfds; ++i) {
|
||||
if (timeout && (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
for (nfds_t i = 0; i < nfds; ++i) {
|
||||
if (!is_fake_input_fd(fds[i].fd)) continue;
|
||||
if (timeout && (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!sigmask)
|
||||
return poll_fake(fds, nfds, static_cast<int>(timespec_to_ms(timeout)), nullptr);
|
||||
sigset_t all_signals, original_mask;
|
||||
@@ -4422,8 +4410,6 @@ EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *t
|
||||
EXPORT int select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
fd_set *exceptfds, struct timeval *timeout) {
|
||||
const auto my_select = next_symbol<decltype(&::select)>(Next::select);
|
||||
if (!any_watched())
|
||||
return my_select ? my_select(nfds, readfds, writefds, exceptfds, timeout) : -1;
|
||||
|
||||
fd_set original_readfds;
|
||||
fd_set original_writefds;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <jni.h>
|
||||
#include <limits.h>
|
||||
#include <linux/futex.h>
|
||||
@@ -28,16 +27,3 @@ Java_com_droiddeck_launcher_session_ThreadSignals_tgkill(JNIEnv *env, jclass cla
|
||||
(void)clazz;
|
||||
return syscall(SYS_tgkill, tgid, tid, signal) == 0 ? 0 : errno;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_session_PageCacheNative_fadviseDontNeed(JNIEnv *env, jclass clazz, jstring path) {
|
||||
(void)clazz;
|
||||
const char *chars = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
if (!chars) return ENOMEM;
|
||||
int fd = open(chars, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
|
||||
(*env)->ReleaseStringUTFChars(env, path, chars);
|
||||
if (fd < 0) return errno;
|
||||
int rc = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
|
||||
close(fd);
|
||||
return rc;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -124,33 +124,3 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
SMAA (Enhanced Subpixel Morphological Antialiasing)
|
||||
---------------------------------------------------
|
||||
SMAA.hlsl and the lookup tables in smaa_tables.h are from the authors' reference
|
||||
implementation (github.com/iryoku/smaa).
|
||||
|
||||
Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com)
|
||||
Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com)
|
||||
Copyright (C) 2013 Belen Masia (bmasia@unizar.es)
|
||||
Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com)
|
||||
Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software. As clarification, there is no
|
||||
requirement that the copyright notice and permission be included in binary
|
||||
distributions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,5 +1,4 @@
|
||||
#version 450
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
layout(location = 0) in vec2 fragTexCoord;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
@@ -7,16 +6,25 @@ layout(set = 0, binding = 0) uniform sampler2D InputTexture;
|
||||
layout(set = 1, binding = 0) uniform sampler2D WeightTexture;
|
||||
layout(push_constant) uniform Constants {
|
||||
vec4 ndc;
|
||||
vec4 metrics; // 1/width, 1/height, width, height
|
||||
vec2 resolution;
|
||||
float extra;
|
||||
float pad;
|
||||
} pc;
|
||||
|
||||
#define SMAA_RT_METRICS pc.metrics
|
||||
#define SMAA_GLSL_4
|
||||
#define SMAA_PRESET_HIGH
|
||||
#include "SMAA.hlsl"
|
||||
|
||||
void main() {
|
||||
vec4 offset;
|
||||
SMAANeighborhoodBlendingVS(fragTexCoord, offset);
|
||||
outColor = SMAANeighborhoodBlendingPS(fragTexCoord, offset, InputTexture, WeightTexture);
|
||||
vec2 px = 1.0 / max(pc.resolution, vec2(1.0));
|
||||
vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5);
|
||||
vec4 center = texture(InputTexture, uv);
|
||||
vec4 weights = texture(WeightTexture, uv);
|
||||
float weight = clamp(weights.r, 0.0, 0.42);
|
||||
|
||||
if (weight <= 0.001) {
|
||||
outColor = center;
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 normal = weights.gb * 2.0 - 1.0;
|
||||
vec2 acrossUv = clamp(uv + normal * px, px * 0.5, vec2(1.0) - px * 0.5);
|
||||
vec3 across = texture(InputTexture, acrossUv).rgb;
|
||||
outColor = vec4(mix(center.rgb, across, weight), center.a);
|
||||
}
|
||||
@@ -1,204 +1,88 @@
|
||||
// 1116.6.0
|
||||
// 1116.3.0
|
||||
#pragma once
|
||||
const uint32_t smaa_blend_code[] = {
|
||||
0x07230203,0x00010000,0x0008000b,0x000000f8,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x07230203,0x00010000,0x0008000b,0x0000006b,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000e8,0x000000f0,0x00030010,
|
||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f,
|
||||
0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004,
|
||||
0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005,
|
||||
0x00000004,0x6e69616d,0x00000000,0x00080005,0x00000010,0x41414d53,0x63766f4d,0x32627628,
|
||||
0x3266763b,0x3266763b,0x0000003b,0x00040005,0x0000000d,0x646e6f63,0x00000000,0x00050005,
|
||||
0x0000000e,0x69726176,0x656c6261,0x00000000,0x00040005,0x0000000f,0x756c6176,0x00000065,
|
||||
0x00080005,0x0000001a,0x41414d53,0x63766f4d,0x34627628,0x3466763b,0x3466763b,0x0000003b,
|
||||
0x00040005,0x00000017,0x646e6f63,0x00000000,0x00050005,0x00000018,0x69726176,0x656c6261,
|
||||
0x00000000,0x00040005,0x00000019,0x756c6176,0x00000065,0x000b0005,0x0000001f,0x41414d53,
|
||||
0x6769654e,0x726f6268,0x646f6f68,0x6e656c42,0x676e6964,0x76285356,0x763b3266,0x003b3466,
|
||||
0x00050005,0x0000001d,0x63786574,0x64726f6f,0x00000000,0x00040005,0x0000001e,0x7366666f,
|
||||
0x00007465,0x000d0005,0x00000029,0x41414d53,0x6769654e,0x726f6268,0x646f6f68,0x6e656c42,
|
||||
0x676e6964,0x76285350,0x763b3266,0x733b3466,0x733b3132,0x003b3132,0x00050005,0x00000025,
|
||||
0x63786574,0x64726f6f,0x00000000,0x00040005,0x00000026,0x7366666f,0x00007465,0x00050005,
|
||||
0x00000027,0x6f6c6f63,0x78655472,0x00000000,0x00050005,0x00000028,0x6e656c62,0x78655464,
|
||||
0x00000000,0x00040005,0x0000003e,0x61726170,0x0000006d,0x00040005,0x00000041,0x61726170,
|
||||
0x0000006d,0x00040005,0x00000044,0x61726170,0x0000006d,0x00040005,0x0000004d,0x61726170,
|
||||
0x0000006d,0x00040005,0x00000050,0x61726170,0x0000006d,0x00040005,0x00000053,0x61726170,
|
||||
0x0000006d,0x00050005,0x0000005e,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x0000005e,
|
||||
0x00000000,0x0063646e,0x00050006,0x0000005e,0x00000001,0x7274656d,0x00736369,0x00030005,
|
||||
0x00000060,0x00006370,0x00030005,0x0000006d,0x00000061,0x00040005,0x00000089,0x6f6c6f63,
|
||||
0x00000072,0x00030005,0x00000090,0x00000068,0x00060005,0x0000009c,0x6e656c62,0x676e6964,
|
||||
0x7366664f,0x00007465,0x00060005,0x000000a2,0x6e656c62,0x676e6964,0x67696557,0x00007468,
|
||||
0x00040005,0x000000ac,0x61726170,0x0000006d,0x00040005,0x000000ad,0x61726170,0x0000006d,
|
||||
0x00040005,0x000000af,0x61726170,0x0000006d,0x00040005,0x000000b4,0x61726170,0x0000006d,
|
||||
0x00040005,0x000000b5,0x61726170,0x0000006d,0x00040005,0x000000b7,0x61726170,0x0000006d,
|
||||
0x00060005,0x000000c2,0x6e656c62,0x676e6964,0x726f6f43,0x00000064,0x00040005,0x000000d3,
|
||||
0x6f6c6f63,0x00000072,0x00060005,0x000000e8,0x67617266,0x43786554,0x64726f6f,0x00000000,
|
||||
0x00040005,0x000000e9,0x7366666f,0x00007465,0x00040005,0x000000ea,0x61726170,0x0000006d,
|
||||
0x00040005,0x000000ec,0x61726170,0x0000006d,0x00050005,0x000000f0,0x4374756f,0x726f6c6f,
|
||||
0x00000000,0x00060005,0x000000f1,0x75706e49,0x78655474,0x65727574,0x00000000,0x00060005,
|
||||
0x000000f2,0x67696557,0x65547468,0x72757478,0x00000065,0x00040005,0x000000f3,0x61726170,
|
||||
0x0000006d,0x00040005,0x000000f5,0x61726170,0x0000006d,0x00030047,0x0000005e,0x00000002,
|
||||
0x00050048,0x0000005e,0x00000000,0x00000023,0x00000000,0x00050048,0x0000005e,0x00000001,
|
||||
0x00000023,0x00000010,0x00040047,0x000000e8,0x0000001e,0x00000000,0x00040047,0x000000f0,
|
||||
0x0000001e,0x00000000,0x00040047,0x000000f1,0x00000021,0x00000000,0x00040047,0x000000f1,
|
||||
0x00000022,0x00000000,0x00040047,0x000000f2,0x00000021,0x00000000,0x00040047,0x000000f2,
|
||||
0x00000022,0x00000001,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00020014,
|
||||
0x00000006,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,
|
||||
0x00000007,0x00030016,0x00000009,0x00000020,0x00040017,0x0000000a,0x00000009,0x00000002,
|
||||
0x00040020,0x0000000b,0x00000007,0x0000000a,0x00060021,0x0000000c,0x00000002,0x00000008,
|
||||
0x0000000b,0x0000000b,0x00040017,0x00000012,0x00000006,0x00000004,0x00040020,0x00000013,
|
||||
0x00000007,0x00000012,0x00040017,0x00000014,0x00000009,0x00000004,0x00040020,0x00000015,
|
||||
0x00000007,0x00000014,0x00060021,0x00000016,0x00000002,0x00000013,0x00000015,0x00000015,
|
||||
0x00050021,0x0000001c,0x00000002,0x0000000b,0x00000015,0x00090019,0x00000021,0x00000009,
|
||||
0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000022,
|
||||
0x00000021,0x00040020,0x00000023,0x00000000,0x00000022,0x00070021,0x00000024,0x00000014,
|
||||
0x0000000b,0x00000015,0x00000023,0x00000023,0x00040015,0x0000002b,0x00000020,0x00000000,
|
||||
0x0004002b,0x0000002b,0x0000002c,0x00000000,0x00040020,0x0000002d,0x00000007,0x00000006,
|
||||
0x00040020,0x00000032,0x00000007,0x00000009,0x0004002b,0x0000002b,0x00000036,0x00000001,
|
||||
0x0004002b,0x0000002b,0x00000058,0x00000002,0x0004002b,0x0000002b,0x0000005b,0x00000003,
|
||||
0x0004001e,0x0000005e,0x00000014,0x00000014,0x00040020,0x0000005f,0x00000009,0x0000005e,
|
||||
0x0004003b,0x0000005f,0x00000060,0x00000009,0x00040015,0x00000061,0x00000020,0x00000001,
|
||||
0x0004002b,0x00000061,0x00000062,0x00000001,0x00040020,0x00000063,0x00000009,0x00000014,
|
||||
0x0004002b,0x00000009,0x00000067,0x3f800000,0x0004002b,0x00000009,0x00000068,0x00000000,
|
||||
0x0007002c,0x00000014,0x00000069,0x00000067,0x00000068,0x00000068,0x00000067,0x0007002c,
|
||||
0x00000014,0x00000083,0x00000067,0x00000067,0x00000067,0x00000067,0x0004002b,0x00000009,
|
||||
0x00000085,0x3727c5ac,0x0005002c,0x0000000a,0x000000bd,0x00000067,0x00000067,0x00040020,
|
||||
0x000000e7,0x00000001,0x0000000a,0x0004003b,0x000000e7,0x000000e8,0x00000001,0x00040020,
|
||||
0x000000ef,0x00000003,0x00000014,0x0004003b,0x000000ef,0x000000f0,0x00000003,0x0004003b,
|
||||
0x00000023,0x000000f1,0x00000000,0x0004003b,0x00000023,0x000000f2,0x00000000,0x00050036,
|
||||
0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000015,
|
||||
0x000000e9,0x00000007,0x0004003b,0x0000000b,0x000000ea,0x00000007,0x0004003b,0x00000015,
|
||||
0x000000ec,0x00000007,0x0004003b,0x0000000b,0x000000f3,0x00000007,0x0004003b,0x00000015,
|
||||
0x000000f5,0x00000007,0x0004003d,0x0000000a,0x000000eb,0x000000e8,0x0003003e,0x000000ea,
|
||||
0x000000eb,0x00060039,0x00000002,0x000000ed,0x0000001f,0x000000ea,0x000000ec,0x0004003d,
|
||||
0x00000014,0x000000ee,0x000000ec,0x0003003e,0x000000e9,0x000000ee,0x0004003d,0x0000000a,
|
||||
0x000000f4,0x000000e8,0x0003003e,0x000000f3,0x000000f4,0x0004003d,0x00000014,0x000000f6,
|
||||
0x000000e9,0x0003003e,0x000000f5,0x000000f6,0x00080039,0x00000014,0x000000f7,0x00000029,
|
||||
0x000000f3,0x000000f5,0x000000f1,0x000000f2,0x0003003e,0x000000f0,0x000000f7,0x000100fd,
|
||||
0x00010038,0x00050036,0x00000002,0x00000010,0x00000000,0x0000000c,0x00030037,0x00000008,
|
||||
0x0000000d,0x00030037,0x0000000b,0x0000000e,0x00030037,0x0000000b,0x0000000f,0x000200f8,
|
||||
0x00000011,0x00050041,0x0000002d,0x0000002e,0x0000000d,0x0000002c,0x0004003d,0x00000006,
|
||||
0x0000002f,0x0000002e,0x000300f7,0x00000031,0x00000000,0x000400fa,0x0000002f,0x00000030,
|
||||
0x00000031,0x000200f8,0x00000030,0x00050041,0x00000032,0x00000033,0x0000000f,0x0000002c,
|
||||
0x0004003d,0x00000009,0x00000034,0x00000033,0x00050041,0x00000032,0x00000035,0x0000000e,
|
||||
0x0000002c,0x0003003e,0x00000035,0x00000034,0x000200f9,0x00000031,0x000200f8,0x00000031,
|
||||
0x00050041,0x0000002d,0x00000037,0x0000000d,0x00000036,0x0004003d,0x00000006,0x00000038,
|
||||
0x00000037,0x000300f7,0x0000003a,0x00000000,0x000400fa,0x00000038,0x00000039,0x0000003a,
|
||||
0x000200f8,0x00000039,0x00050041,0x00000032,0x0000003b,0x0000000f,0x00000036,0x0004003d,
|
||||
0x00000009,0x0000003c,0x0000003b,0x00050041,0x00000032,0x0000003d,0x0000000e,0x00000036,
|
||||
0x0003003e,0x0000003d,0x0000003c,0x000200f9,0x0000003a,0x000200f8,0x0000003a,0x000100fd,
|
||||
0x00010038,0x00050036,0x00000002,0x0000001a,0x00000000,0x00000016,0x00030037,0x00000013,
|
||||
0x00000017,0x00030037,0x00000015,0x00000018,0x00030037,0x00000015,0x00000019,0x000200f8,
|
||||
0x0000001b,0x0004003b,0x00000008,0x0000003e,0x00000007,0x0004003b,0x0000000b,0x00000041,
|
||||
0x00000007,0x0004003b,0x0000000b,0x00000044,0x00000007,0x0004003b,0x00000008,0x0000004d,
|
||||
0x00000007,0x0004003b,0x0000000b,0x00000050,0x00000007,0x0004003b,0x0000000b,0x00000053,
|
||||
0x00000007,0x0004003d,0x00000012,0x0000003f,0x00000017,0x0007004f,0x00000007,0x00000040,
|
||||
0x0000003f,0x0000003f,0x00000000,0x00000001,0x0003003e,0x0000003e,0x00000040,0x0004003d,
|
||||
0x00000014,0x00000042,0x00000018,0x0007004f,0x0000000a,0x00000043,0x00000042,0x00000042,
|
||||
0x00000000,0x00000001,0x0003003e,0x00000041,0x00000043,0x0004003d,0x00000014,0x00000045,
|
||||
0x00000019,0x0007004f,0x0000000a,0x00000046,0x00000045,0x00000045,0x00000000,0x00000001,
|
||||
0x0003003e,0x00000044,0x00000046,0x00070039,0x00000002,0x00000047,0x00000010,0x0000003e,
|
||||
0x00000041,0x00000044,0x0004003d,0x0000000a,0x00000048,0x00000041,0x00050041,0x00000032,
|
||||
0x00000049,0x00000018,0x0000002c,0x00050051,0x00000009,0x0000004a,0x00000048,0x00000000,
|
||||
0x0003003e,0x00000049,0x0000004a,0x00050041,0x00000032,0x0000004b,0x00000018,0x00000036,
|
||||
0x00050051,0x00000009,0x0000004c,0x00000048,0x00000001,0x0003003e,0x0000004b,0x0000004c,
|
||||
0x0004003d,0x00000012,0x0000004e,0x00000017,0x0007004f,0x00000007,0x0000004f,0x0000004e,
|
||||
0x0000004e,0x00000002,0x00000003,0x0003003e,0x0000004d,0x0000004f,0x0004003d,0x00000014,
|
||||
0x00000051,0x00000018,0x0007004f,0x0000000a,0x00000052,0x00000051,0x00000051,0x00000002,
|
||||
0x00000003,0x0003003e,0x00000050,0x00000052,0x0004003d,0x00000014,0x00000054,0x00000019,
|
||||
0x0007004f,0x0000000a,0x00000055,0x00000054,0x00000054,0x00000002,0x00000003,0x0003003e,
|
||||
0x00000053,0x00000055,0x00070039,0x00000002,0x00000056,0x00000010,0x0000004d,0x00000050,
|
||||
0x00000053,0x0004003d,0x0000000a,0x00000057,0x00000050,0x00050041,0x00000032,0x00000059,
|
||||
0x00000018,0x00000058,0x00050051,0x00000009,0x0000005a,0x00000057,0x00000000,0x0003003e,
|
||||
0x00000059,0x0000005a,0x00050041,0x00000032,0x0000005c,0x00000018,0x0000005b,0x00050051,
|
||||
0x00000009,0x0000005d,0x00000057,0x00000001,0x0003003e,0x0000005c,0x0000005d,0x000100fd,
|
||||
0x00010038,0x00050036,0x00000002,0x0000001f,0x00000000,0x0000001c,0x00030037,0x0000000b,
|
||||
0x0000001d,0x00030037,0x00000015,0x0000001e,0x000200f8,0x00000020,0x00050041,0x00000063,
|
||||
0x00000064,0x00000060,0x00000062,0x0004003d,0x00000014,0x00000065,0x00000064,0x0009004f,
|
||||
0x00000014,0x00000066,0x00000065,0x00000065,0x00000000,0x00000001,0x00000000,0x00000001,
|
||||
0x0004003d,0x0000000a,0x0000006a,0x0000001d,0x0009004f,0x00000014,0x0000006b,0x0000006a,
|
||||
0x0000006a,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000014,0x0000006c,
|
||||
0x00000001,0x00000032,0x00000066,0x00000069,0x0000006b,0x0003003e,0x0000001e,0x0000006c,
|
||||
0x000100fd,0x00010038,0x00050036,0x00000014,0x00000029,0x00000000,0x00000024,0x00030037,
|
||||
0x0000000b,0x00000025,0x00030037,0x00000015,0x00000026,0x00030037,0x00000023,0x00000027,
|
||||
0x00030037,0x00000023,0x00000028,0x000200f8,0x0000002a,0x0004003b,0x00000015,0x0000006d,
|
||||
0x00000007,0x0004003b,0x00000015,0x00000089,0x00000007,0x0004003b,0x0000002d,0x00000090,
|
||||
0x00000007,0x0004003b,0x00000015,0x0000009c,0x00000007,0x0004003b,0x0000000b,0x000000a2,
|
||||
0x00000007,0x0004003b,0x00000013,0x000000ac,0x00000007,0x0004003b,0x00000015,0x000000ad,
|
||||
0x00000007,0x0004003b,0x00000015,0x000000af,0x00000007,0x0004003b,0x00000008,0x000000b4,
|
||||
0x00000007,0x0004003b,0x0000000b,0x000000b5,0x00000007,0x0004003b,0x0000000b,0x000000b7,
|
||||
0x00000007,0x0004003b,0x00000015,0x000000c2,0x00000007,0x0004003b,0x00000015,0x000000d3,
|
||||
0x00000007,0x0004003d,0x00000022,0x0000006e,0x00000028,0x0004003d,0x00000014,0x0000006f,
|
||||
0x00000026,0x0007004f,0x0000000a,0x00000070,0x0000006f,0x0000006f,0x00000000,0x00000001,
|
||||
0x00050057,0x00000014,0x00000071,0x0000006e,0x00000070,0x00050051,0x00000009,0x00000072,
|
||||
0x00000071,0x00000003,0x00050041,0x00000032,0x00000073,0x0000006d,0x0000002c,0x0003003e,
|
||||
0x00000073,0x00000072,0x0004003d,0x00000022,0x00000074,0x00000028,0x0004003d,0x00000014,
|
||||
0x00000075,0x00000026,0x0007004f,0x0000000a,0x00000076,0x00000075,0x00000075,0x00000002,
|
||||
0x00000003,0x00050057,0x00000014,0x00000077,0x00000074,0x00000076,0x00050051,0x00000009,
|
||||
0x00000078,0x00000077,0x00000001,0x00050041,0x00000032,0x00000079,0x0000006d,0x00000036,
|
||||
0x0003003e,0x00000079,0x00000078,0x0004003d,0x00000022,0x0000007a,0x00000028,0x0004003d,
|
||||
0x0000000a,0x0000007b,0x00000025,0x00050057,0x00000014,0x0000007c,0x0000007a,0x0000007b,
|
||||
0x0007004f,0x0000000a,0x0000007d,0x0000007c,0x0000007c,0x00000000,0x00000002,0x00050041,
|
||||
0x00000032,0x0000007e,0x0000006d,0x0000005b,0x00050051,0x00000009,0x0000007f,0x0000007d,
|
||||
0x00000000,0x0003003e,0x0000007e,0x0000007f,0x00050041,0x00000032,0x00000080,0x0000006d,
|
||||
0x00000058,0x00050051,0x00000009,0x00000081,0x0000007d,0x00000001,0x0003003e,0x00000080,
|
||||
0x00000081,0x0004003d,0x00000014,0x00000082,0x0000006d,0x00050094,0x00000009,0x00000084,
|
||||
0x00000082,0x00000083,0x000500b8,0x00000006,0x00000086,0x00000084,0x00000085,0x000300f7,
|
||||
0x00000088,0x00000000,0x000400fa,0x00000086,0x00000087,0x0000008f,0x000200f8,0x00000087,
|
||||
0x0004003d,0x00000022,0x0000008a,0x00000027,0x0004003d,0x0000000a,0x0000008b,0x00000025,
|
||||
0x00070058,0x00000014,0x0000008c,0x0000008a,0x0000008b,0x00000002,0x00000068,0x0003003e,
|
||||
0x00000089,0x0000008c,0x0004003d,0x00000014,0x0000008d,0x00000089,0x000200fe,0x0000008d,
|
||||
0x000200f8,0x0000008f,0x00050041,0x00000032,0x00000091,0x0000006d,0x0000002c,0x0004003d,
|
||||
0x00000009,0x00000092,0x00000091,0x00050041,0x00000032,0x00000093,0x0000006d,0x00000058,
|
||||
0x0004003d,0x00000009,0x00000094,0x00000093,0x0007000c,0x00000009,0x00000095,0x00000001,
|
||||
0x00000028,0x00000092,0x00000094,0x00050041,0x00000032,0x00000096,0x0000006d,0x00000036,
|
||||
0x0004003d,0x00000009,0x00000097,0x00000096,0x00050041,0x00000032,0x00000098,0x0000006d,
|
||||
0x0000005b,0x0004003d,0x00000009,0x00000099,0x00000098,0x0007000c,0x00000009,0x0000009a,
|
||||
0x00000001,0x00000028,0x00000097,0x00000099,0x000500ba,0x00000006,0x0000009b,0x00000095,
|
||||
0x0000009a,0x0003003e,0x00000090,0x0000009b,0x00050041,0x00000032,0x0000009d,0x0000006d,
|
||||
0x00000036,0x0004003d,0x00000009,0x0000009e,0x0000009d,0x00050041,0x00000032,0x0000009f,
|
||||
0x0000006d,0x0000005b,0x0004003d,0x00000009,0x000000a0,0x0000009f,0x00070050,0x00000014,
|
||||
0x000000a1,0x00000068,0x0000009e,0x00000068,0x000000a0,0x0003003e,0x0000009c,0x000000a1,
|
||||
0x0004003d,0x00000014,0x000000a3,0x0000006d,0x0007004f,0x0000000a,0x000000a4,0x000000a3,
|
||||
0x000000a3,0x00000001,0x00000003,0x0003003e,0x000000a2,0x000000a4,0x0004003d,0x00000006,
|
||||
0x000000a5,0x00000090,0x00070050,0x00000012,0x000000a6,0x000000a5,0x000000a5,0x000000a5,
|
||||
0x000000a5,0x00050041,0x00000032,0x000000a7,0x0000006d,0x0000002c,0x0004003d,0x00000009,
|
||||
0x000000a8,0x000000a7,0x00050041,0x00000032,0x000000a9,0x0000006d,0x00000058,0x0004003d,
|
||||
0x00000009,0x000000aa,0x000000a9,0x00070050,0x00000014,0x000000ab,0x000000a8,0x00000068,
|
||||
0x000000aa,0x00000068,0x0003003e,0x000000ac,0x000000a6,0x0004003d,0x00000014,0x000000ae,
|
||||
0x0000009c,0x0003003e,0x000000ad,0x000000ae,0x0003003e,0x000000af,0x000000ab,0x00070039,
|
||||
0x00000002,0x000000b0,0x0000001a,0x000000ac,0x000000ad,0x000000af,0x0004003d,0x00000014,
|
||||
0x000000b1,0x000000ad,0x0003003e,0x0000009c,0x000000b1,0x0004003d,0x00000006,0x000000b2,
|
||||
0x00000090,0x00050050,0x00000007,0x000000b3,0x000000b2,0x000000b2,0x0003003e,0x000000b4,
|
||||
0x000000b3,0x0004003d,0x0000000a,0x000000b6,0x000000a2,0x0003003e,0x000000b5,0x000000b6,
|
||||
0x0004003d,0x00000014,0x000000b8,0x0000006d,0x0007004f,0x0000000a,0x000000b9,0x000000b8,
|
||||
0x000000b8,0x00000000,0x00000002,0x0003003e,0x000000b7,0x000000b9,0x00070039,0x00000002,
|
||||
0x000000ba,0x00000010,0x000000b4,0x000000b5,0x000000b7,0x0004003d,0x0000000a,0x000000bb,
|
||||
0x000000b5,0x0003003e,0x000000a2,0x000000bb,0x0004003d,0x0000000a,0x000000bc,0x000000a2,
|
||||
0x00050094,0x00000009,0x000000be,0x000000bc,0x000000bd,0x0004003d,0x0000000a,0x000000bf,
|
||||
0x000000a2,0x00050050,0x0000000a,0x000000c0,0x000000be,0x000000be,0x00050088,0x0000000a,
|
||||
0x000000c1,0x000000bf,0x000000c0,0x0003003e,0x000000a2,0x000000c1,0x0004003d,0x00000014,
|
||||
0x000000c3,0x0000009c,0x00050041,0x00000063,0x000000c4,0x00000060,0x00000062,0x0004003d,
|
||||
0x00000014,0x000000c5,0x000000c4,0x0007004f,0x0000000a,0x000000c6,0x000000c5,0x000000c5,
|
||||
0x00000000,0x00000001,0x00050041,0x00000063,0x000000c7,0x00000060,0x00000062,0x0004003d,
|
||||
0x00000014,0x000000c8,0x000000c7,0x0007004f,0x0000000a,0x000000c9,0x000000c8,0x000000c8,
|
||||
0x00000000,0x00000001,0x0004007f,0x0000000a,0x000000ca,0x000000c9,0x00050051,0x00000009,
|
||||
0x000000cb,0x000000c6,0x00000000,0x00050051,0x00000009,0x000000cc,0x000000c6,0x00000001,
|
||||
0x00050051,0x00000009,0x000000cd,0x000000ca,0x00000000,0x00050051,0x00000009,0x000000ce,
|
||||
0x000000ca,0x00000001,0x00070050,0x00000014,0x000000cf,0x000000cb,0x000000cc,0x000000cd,
|
||||
0x000000ce,0x0004003d,0x0000000a,0x000000d0,0x00000025,0x0009004f,0x00000014,0x000000d1,
|
||||
0x000000d0,0x000000d0,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000014,
|
||||
0x000000d2,0x00000001,0x00000032,0x000000c3,0x000000cf,0x000000d1,0x0003003e,0x000000c2,
|
||||
0x000000d2,0x00050041,0x00000032,0x000000d4,0x000000a2,0x0000002c,0x0004003d,0x00000009,
|
||||
0x000000d5,0x000000d4,0x0004003d,0x00000022,0x000000d6,0x00000027,0x0004003d,0x00000014,
|
||||
0x000000d7,0x000000c2,0x0007004f,0x0000000a,0x000000d8,0x000000d7,0x000000d7,0x00000000,
|
||||
0x00000001,0x00070058,0x00000014,0x000000d9,0x000000d6,0x000000d8,0x00000002,0x00000068,
|
||||
0x0005008e,0x00000014,0x000000da,0x000000d9,0x000000d5,0x0003003e,0x000000d3,0x000000da,
|
||||
0x00050041,0x00000032,0x000000db,0x000000a2,0x00000036,0x0004003d,0x00000009,0x000000dc,
|
||||
0x000000db,0x0004003d,0x00000022,0x000000dd,0x00000027,0x0004003d,0x00000014,0x000000de,
|
||||
0x000000c2,0x0007004f,0x0000000a,0x000000df,0x000000de,0x000000de,0x00000002,0x00000003,
|
||||
0x00070058,0x00000014,0x000000e0,0x000000dd,0x000000df,0x00000002,0x00000068,0x0005008e,
|
||||
0x00000014,0x000000e1,0x000000e0,0x000000dc,0x0004003d,0x00000014,0x000000e2,0x000000d3,
|
||||
0x00050081,0x00000014,0x000000e3,0x000000e2,0x000000e1,0x0003003e,0x000000d3,0x000000e3,
|
||||
0x0004003d,0x00000014,0x000000e4,0x000000d3,0x000200fe,0x000000e4,0x000200f8,0x00000088,
|
||||
0x000100ff,0x00010038
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000001a,0x00000041,0x00030010,
|
||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
||||
0x00000000,0x00030005,0x00000009,0x00007870,0x00050005,0x0000000c,0x736e6f43,0x746e6174,
|
||||
0x00000073,0x00040006,0x0000000c,0x00000000,0x0063646e,0x00060006,0x0000000c,0x00000001,
|
||||
0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x0000000c,0x00000002,0x72747865,0x00000061,
|
||||
0x00040006,0x0000000c,0x00000003,0x00646170,0x00030005,0x0000000e,0x00006370,0x00030005,
|
||||
0x00000018,0x00007675,0x00060005,0x0000001a,0x67617266,0x43786554,0x64726f6f,0x00000000,
|
||||
0x00040005,0x00000024,0x746e6563,0x00007265,0x00060005,0x00000028,0x75706e49,0x78655474,
|
||||
0x65727574,0x00000000,0x00040005,0x0000002c,0x67696577,0x00737468,0x00060005,0x0000002d,
|
||||
0x67696557,0x65547468,0x72757478,0x00000065,0x00040005,0x00000032,0x67696577,0x00007468,
|
||||
0x00050005,0x00000041,0x4374756f,0x726f6c6f,0x00000000,0x00040005,0x00000044,0x6d726f6e,
|
||||
0x00006c61,0x00050005,0x0000004b,0x6f726361,0x76557373,0x00000000,0x00040005,0x00000059,
|
||||
0x6f726361,0x00007373,0x00030047,0x0000000c,0x00000002,0x00050048,0x0000000c,0x00000000,
|
||||
0x00000023,0x00000000,0x00050048,0x0000000c,0x00000001,0x00000023,0x00000010,0x00050048,
|
||||
0x0000000c,0x00000002,0x00000023,0x00000018,0x00050048,0x0000000c,0x00000003,0x00000023,
|
||||
0x0000001c,0x00040047,0x0000001a,0x0000001e,0x00000000,0x00040047,0x00000028,0x00000021,
|
||||
0x00000000,0x00040047,0x00000028,0x00000022,0x00000000,0x00040047,0x0000002d,0x00000021,
|
||||
0x00000000,0x00040047,0x0000002d,0x00000022,0x00000001,0x00040047,0x00000041,0x0000001e,
|
||||
0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
|
||||
0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,
|
||||
0x00000007,0x0004002b,0x00000006,0x0000000a,0x3f800000,0x00040017,0x0000000b,0x00000006,
|
||||
0x00000004,0x0006001e,0x0000000c,0x0000000b,0x00000007,0x00000006,0x00000006,0x00040020,
|
||||
0x0000000d,0x00000009,0x0000000c,0x0004003b,0x0000000d,0x0000000e,0x00000009,0x00040015,
|
||||
0x0000000f,0x00000020,0x00000001,0x0004002b,0x0000000f,0x00000010,0x00000001,0x00040020,
|
||||
0x00000011,0x00000009,0x00000007,0x0005002c,0x00000007,0x00000014,0x0000000a,0x0000000a,
|
||||
0x00040020,0x00000019,0x00000001,0x00000007,0x0004003b,0x00000019,0x0000001a,0x00000001,
|
||||
0x0004002b,0x00000006,0x0000001d,0x3f000000,0x00040020,0x00000023,0x00000007,0x0000000b,
|
||||
0x00090019,0x00000025,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,
|
||||
0x00000000,0x0003001b,0x00000026,0x00000025,0x00040020,0x00000027,0x00000000,0x00000026,
|
||||
0x0004003b,0x00000027,0x00000028,0x00000000,0x0004003b,0x00000027,0x0000002d,0x00000000,
|
||||
0x00040020,0x00000031,0x00000007,0x00000006,0x00040015,0x00000033,0x00000020,0x00000000,
|
||||
0x0004002b,0x00000033,0x00000034,0x00000000,0x0004002b,0x00000006,0x00000037,0x00000000,
|
||||
0x0004002b,0x00000006,0x00000038,0x3ed70a3d,0x0004002b,0x00000006,0x0000003b,0x3a83126f,
|
||||
0x00020014,0x0000003c,0x00040020,0x00000040,0x00000003,0x0000000b,0x0004003b,0x00000040,
|
||||
0x00000041,0x00000003,0x0004002b,0x00000006,0x00000047,0x40000000,0x00040017,0x00000057,
|
||||
0x00000006,0x00000003,0x00040020,0x00000058,0x00000007,0x00000057,0x0004002b,0x00000033,
|
||||
0x00000064,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
|
||||
0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x00000008,0x00000018,
|
||||
0x00000007,0x0004003b,0x00000023,0x00000024,0x00000007,0x0004003b,0x00000023,0x0000002c,
|
||||
0x00000007,0x0004003b,0x00000031,0x00000032,0x00000007,0x0004003b,0x00000008,0x00000044,
|
||||
0x00000007,0x0004003b,0x00000008,0x0000004b,0x00000007,0x0004003b,0x00000058,0x00000059,
|
||||
0x00000007,0x00050041,0x00000011,0x00000012,0x0000000e,0x00000010,0x0004003d,0x00000007,
|
||||
0x00000013,0x00000012,0x0007000c,0x00000007,0x00000015,0x00000001,0x00000028,0x00000013,
|
||||
0x00000014,0x00050050,0x00000007,0x00000016,0x0000000a,0x0000000a,0x00050088,0x00000007,
|
||||
0x00000017,0x00000016,0x00000015,0x0003003e,0x00000009,0x00000017,0x0004003d,0x00000007,
|
||||
0x0000001b,0x0000001a,0x0004003d,0x00000007,0x0000001c,0x00000009,0x0005008e,0x00000007,
|
||||
0x0000001e,0x0000001c,0x0000001d,0x0004003d,0x00000007,0x0000001f,0x00000009,0x0005008e,
|
||||
0x00000007,0x00000020,0x0000001f,0x0000001d,0x00050083,0x00000007,0x00000021,0x00000014,
|
||||
0x00000020,0x0008000c,0x00000007,0x00000022,0x00000001,0x0000002b,0x0000001b,0x0000001e,
|
||||
0x00000021,0x0003003e,0x00000018,0x00000022,0x0004003d,0x00000026,0x00000029,0x00000028,
|
||||
0x0004003d,0x00000007,0x0000002a,0x00000018,0x00050057,0x0000000b,0x0000002b,0x00000029,
|
||||
0x0000002a,0x0003003e,0x00000024,0x0000002b,0x0004003d,0x00000026,0x0000002e,0x0000002d,
|
||||
0x0004003d,0x00000007,0x0000002f,0x00000018,0x00050057,0x0000000b,0x00000030,0x0000002e,
|
||||
0x0000002f,0x0003003e,0x0000002c,0x00000030,0x00050041,0x00000031,0x00000035,0x0000002c,
|
||||
0x00000034,0x0004003d,0x00000006,0x00000036,0x00000035,0x0008000c,0x00000006,0x00000039,
|
||||
0x00000001,0x0000002b,0x00000036,0x00000037,0x00000038,0x0003003e,0x00000032,0x00000039,
|
||||
0x0004003d,0x00000006,0x0000003a,0x00000032,0x000500bc,0x0000003c,0x0000003d,0x0000003a,
|
||||
0x0000003b,0x000300f7,0x0000003f,0x00000000,0x000400fa,0x0000003d,0x0000003e,0x0000003f,
|
||||
0x000200f8,0x0000003e,0x0004003d,0x0000000b,0x00000042,0x00000024,0x0003003e,0x00000041,
|
||||
0x00000042,0x000100fd,0x000200f8,0x0000003f,0x0004003d,0x0000000b,0x00000045,0x0000002c,
|
||||
0x0007004f,0x00000007,0x00000046,0x00000045,0x00000045,0x00000001,0x00000002,0x0005008e,
|
||||
0x00000007,0x00000048,0x00000046,0x00000047,0x00050050,0x00000007,0x00000049,0x0000000a,
|
||||
0x0000000a,0x00050083,0x00000007,0x0000004a,0x00000048,0x00000049,0x0003003e,0x00000044,
|
||||
0x0000004a,0x0004003d,0x00000007,0x0000004c,0x00000018,0x0004003d,0x00000007,0x0000004d,
|
||||
0x00000044,0x0004003d,0x00000007,0x0000004e,0x00000009,0x00050085,0x00000007,0x0000004f,
|
||||
0x0000004d,0x0000004e,0x00050081,0x00000007,0x00000050,0x0000004c,0x0000004f,0x0004003d,
|
||||
0x00000007,0x00000051,0x00000009,0x0005008e,0x00000007,0x00000052,0x00000051,0x0000001d,
|
||||
0x0004003d,0x00000007,0x00000053,0x00000009,0x0005008e,0x00000007,0x00000054,0x00000053,
|
||||
0x0000001d,0x00050083,0x00000007,0x00000055,0x00000014,0x00000054,0x0008000c,0x00000007,
|
||||
0x00000056,0x00000001,0x0000002b,0x00000050,0x00000052,0x00000055,0x0003003e,0x0000004b,
|
||||
0x00000056,0x0004003d,0x00000026,0x0000005a,0x00000028,0x0004003d,0x00000007,0x0000005b,
|
||||
0x0000004b,0x00050057,0x0000000b,0x0000005c,0x0000005a,0x0000005b,0x0008004f,0x00000057,
|
||||
0x0000005d,0x0000005c,0x0000005c,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000059,
|
||||
0x0000005d,0x0004003d,0x0000000b,0x0000005e,0x00000024,0x0008004f,0x00000057,0x0000005f,
|
||||
0x0000005e,0x0000005e,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000057,0x00000060,
|
||||
0x00000059,0x0004003d,0x00000006,0x00000061,0x00000032,0x00060050,0x00000057,0x00000062,
|
||||
0x00000061,0x00000061,0x00000061,0x0008000c,0x00000057,0x00000063,0x00000001,0x0000002e,
|
||||
0x0000005f,0x00000060,0x00000062,0x00050041,0x00000031,0x00000065,0x00000024,0x00000064,
|
||||
0x0004003d,0x00000006,0x00000066,0x00000065,0x00050051,0x00000006,0x00000067,0x00000063,
|
||||
0x00000000,0x00050051,0x00000006,0x00000068,0x00000063,0x00000001,0x00050051,0x00000006,
|
||||
0x00000069,0x00000063,0x00000002,0x00070050,0x0000000b,0x0000006a,0x00000067,0x00000068,
|
||||
0x00000069,0x00000066,0x0003003e,0x00000041,0x0000006a,0x000100fd,0x00010038
|
||||
};
|
||||
@@ -1,21 +1,29 @@
|
||||
#version 450
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
layout(location = 0) in vec2 fragTexCoord;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(set = 0, binding = 0) uniform sampler2D InputTexture;
|
||||
layout(push_constant) uniform Constants {
|
||||
vec4 ndc;
|
||||
vec4 metrics; // 1/width, 1/height, width, height
|
||||
vec2 resolution;
|
||||
float extra;
|
||||
float pad;
|
||||
} pc;
|
||||
|
||||
#define SMAA_RT_METRICS pc.metrics
|
||||
#define SMAA_GLSL_4
|
||||
#define SMAA_PRESET_HIGH
|
||||
#include "SMAA.hlsl"
|
||||
float luma(vec3 c) {
|
||||
return dot(c, vec3(0.2126, 0.7152, 0.0722));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 offset[3];
|
||||
SMAAEdgeDetectionVS(fragTexCoord, offset);
|
||||
outColor = vec4(SMAALumaEdgeDetectionPS(fragTexCoord, offset, InputTexture), 0.0, 0.0);
|
||||
vec2 px = 1.0 / max(pc.resolution, vec2(1.0));
|
||||
vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5);
|
||||
float center = luma(texture(InputTexture, uv).rgb);
|
||||
float left = luma(texture(InputTexture, uv - vec2(px.x, 0.0)).rgb);
|
||||
float right = luma(texture(InputTexture, uv + vec2(px.x, 0.0)).rgb);
|
||||
float up = luma(texture(InputTexture, uv - vec2(0.0, px.y)).rgb);
|
||||
float down = luma(texture(InputTexture, uv + vec2(0.0, px.y)).rgb);
|
||||
|
||||
// Store directional edge strengths for the weight pass.
|
||||
outColor = vec4(abs(center - left), abs(center - right),
|
||||
abs(center - up), abs(center - down));
|
||||
}
|
||||
@@ -1,185 +1,102 @@
|
||||
// 1116.6.0
|
||||
// 1116.3.0
|
||||
#pragma once
|
||||
const uint32_t smaa_edge_code[] = {
|
||||
0x07230203,0x00010000,0x0008000b,0x000000eb,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x07230203,0x00010000,0x0008000b,0x00000080,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000d9,0x000000e1,0x00030010,
|
||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f,
|
||||
0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004,
|
||||
0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005,
|
||||
0x00000004,0x6e69616d,0x00000000,0x000a0005,0x00000011,0x41414d53,0x65676445,0x65746544,
|
||||
0x6f697463,0x2853566e,0x3b326676,0x5b346676,0x003b5d33,0x00050005,0x0000000f,0x63786574,
|
||||
0x64726f6f,0x00000000,0x00040005,0x00000010,0x7366666f,0x00007465,0x000c0005,0x0000001a,
|
||||
0x41414d53,0x616d754c,0x65676445,0x65746544,0x6f697463,0x2853506e,0x3b326676,0x5b346676,
|
||||
0x733b5d33,0x003b3132,0x00050005,0x00000017,0x63786574,0x64726f6f,0x00000000,0x00040005,
|
||||
0x00000018,0x7366666f,0x00007465,0x00050005,0x00000019,0x6f6c6f63,0x78655472,0x00000000,
|
||||
0x00050005,0x0000001e,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x0000001e,0x00000000,
|
||||
0x0063646e,0x00050006,0x0000001e,0x00000001,0x7274656d,0x00736369,0x00030005,0x00000020,
|
||||
0x00006370,0x00050005,0x00000041,0x65726874,0x6c6f6873,0x00000064,0x00040005,0x00000046,
|
||||
0x67696577,0x00737468,0x00030005,0x0000004c,0x0000004c,0x00040005,0x00000053,0x66656c4c,
|
||||
0x00000074,0x00040005,0x0000005c,0x706f744c,0x00000000,0x00040005,0x00000065,0x746c6564,
|
||||
0x00000061,0x00040005,0x00000073,0x65676465,0x00000073,0x00040005,0x00000080,0x6769724c,
|
||||
0x00007468,0x00040005,0x00000089,0x746f624c,0x006d6f74,0x00050005,0x0000009e,0x4478616d,
|
||||
0x61746c65,0x00000000,0x00050005,0x000000a4,0x66656c4c,0x66656c74,0x00000074,0x00040005,
|
||||
0x000000ad,0x706f744c,0x00706f74,0x00050005,0x000000c6,0x616e6966,0x6c65446c,0x00006174,
|
||||
0x00060005,0x000000d9,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040005,0x000000da,
|
||||
0x7366666f,0x00007465,0x00040005,0x000000db,0x61726170,0x0000006d,0x00040005,0x000000dd,
|
||||
0x61726170,0x0000006d,0x00050005,0x000000e1,0x4374756f,0x726f6c6f,0x00000000,0x00060005,
|
||||
0x000000e2,0x75706e49,0x78655474,0x65727574,0x00000000,0x00040005,0x000000e3,0x61726170,
|
||||
0x0000006d,0x00040005,0x000000e5,0x61726170,0x0000006d,0x00030047,0x0000001e,0x00000002,
|
||||
0x00050048,0x0000001e,0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,
|
||||
0x00000023,0x00000010,0x00040047,0x000000d9,0x0000001e,0x00000000,0x00040047,0x000000e1,
|
||||
0x0000001e,0x00000000,0x00040047,0x000000e2,0x00000021,0x00000000,0x00040047,0x000000e2,
|
||||
0x00000022,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,
|
||||
0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,
|
||||
0x00000007,0x00000007,0x00040017,0x00000009,0x00000006,0x00000004,0x00040015,0x0000000a,
|
||||
0x00000020,0x00000000,0x0004002b,0x0000000a,0x0000000b,0x00000003,0x0004001c,0x0000000c,
|
||||
0x00000009,0x0000000b,0x00040020,0x0000000d,0x00000007,0x0000000c,0x00050021,0x0000000e,
|
||||
0x00000002,0x00000008,0x0000000d,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,
|
||||
0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,
|
||||
0x00000015,0x00000000,0x00000014,0x00060021,0x00000016,0x00000007,0x00000008,0x0000000d,
|
||||
0x00000015,0x00040015,0x0000001c,0x00000020,0x00000001,0x0004002b,0x0000001c,0x0000001d,
|
||||
0x00000000,0x0004001e,0x0000001e,0x00000009,0x00000009,0x00040020,0x0000001f,0x00000009,
|
||||
0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x0004002b,0x0000001c,0x00000021,
|
||||
0x00000001,0x00040020,0x00000022,0x00000009,0x00000009,0x0004002b,0x00000006,0x00000026,
|
||||
0xbf800000,0x0004002b,0x00000006,0x00000027,0x00000000,0x0007002c,0x00000009,0x00000028,
|
||||
0x00000026,0x00000027,0x00000027,0x00000026,0x00040020,0x0000002c,0x00000007,0x00000009,
|
||||
0x0004002b,0x00000006,0x00000031,0x3f800000,0x0007002c,0x00000009,0x00000032,0x00000031,
|
||||
0x00000027,0x00000027,0x00000031,0x0004002b,0x0000001c,0x00000037,0x00000002,0x0004002b,
|
||||
0x00000006,0x0000003b,0xc0000000,0x0007002c,0x00000009,0x0000003c,0x0000003b,0x00000027,
|
||||
0x00000027,0x0000003b,0x0004002b,0x00000006,0x00000042,0x3dcccccd,0x0005002c,0x00000007,
|
||||
0x00000043,0x00000042,0x00000042,0x00040017,0x00000044,0x00000006,0x00000003,0x00040020,
|
||||
0x00000045,0x00000007,0x00000044,0x0004002b,0x00000006,0x00000047,0x3e59b3d0,0x0004002b,
|
||||
0x00000006,0x00000048,0x3f371759,0x0004002b,0x00000006,0x00000049,0x3d93dd98,0x0006002c,
|
||||
0x00000044,0x0000004a,0x00000047,0x00000048,0x00000049,0x00040020,0x0000004b,0x00000007,
|
||||
0x00000006,0x0004002b,0x0000000a,0x0000006d,0x00000000,0x0004002b,0x0000000a,0x00000070,
|
||||
0x00000001,0x0005002c,0x00000007,0x00000079,0x00000031,0x00000031,0x00020014,0x0000007b,
|
||||
0x0004002b,0x0000000a,0x00000099,0x00000002,0x0004002b,0x00000006,0x000000cd,0x40000000,
|
||||
0x00040020,0x000000d8,0x00000001,0x00000007,0x0004003b,0x000000d8,0x000000d9,0x00000001,
|
||||
0x00040020,0x000000e0,0x00000003,0x00000009,0x0004003b,0x000000e0,0x000000e1,0x00000003,
|
||||
0x0004003b,0x00000015,0x000000e2,0x00000000,0x00050036,0x00000002,0x00000004,0x00000000,
|
||||
0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000000d,0x000000da,0x00000007,0x0004003b,
|
||||
0x00000008,0x000000db,0x00000007,0x0004003b,0x0000000d,0x000000dd,0x00000007,0x0004003b,
|
||||
0x00000008,0x000000e3,0x00000007,0x0004003b,0x0000000d,0x000000e5,0x00000007,0x0004003d,
|
||||
0x00000007,0x000000dc,0x000000d9,0x0003003e,0x000000db,0x000000dc,0x00060039,0x00000002,
|
||||
0x000000de,0x00000011,0x000000db,0x000000dd,0x0004003d,0x0000000c,0x000000df,0x000000dd,
|
||||
0x0003003e,0x000000da,0x000000df,0x0004003d,0x00000007,0x000000e4,0x000000d9,0x0003003e,
|
||||
0x000000e3,0x000000e4,0x0004003d,0x0000000c,0x000000e6,0x000000da,0x0003003e,0x000000e5,
|
||||
0x000000e6,0x00070039,0x00000007,0x000000e7,0x0000001a,0x000000e3,0x000000e5,0x000000e2,
|
||||
0x00050051,0x00000006,0x000000e8,0x000000e7,0x00000000,0x00050051,0x00000006,0x000000e9,
|
||||
0x000000e7,0x00000001,0x00070050,0x00000009,0x000000ea,0x000000e8,0x000000e9,0x00000027,
|
||||
0x00000027,0x0003003e,0x000000e1,0x000000ea,0x000100fd,0x00010038,0x00050036,0x00000002,
|
||||
0x00000011,0x00000000,0x0000000e,0x00030037,0x00000008,0x0000000f,0x00030037,0x0000000d,
|
||||
0x00000010,0x000200f8,0x00000012,0x00050041,0x00000022,0x00000023,0x00000020,0x00000021,
|
||||
0x0004003d,0x00000009,0x00000024,0x00000023,0x0009004f,0x00000009,0x00000025,0x00000024,
|
||||
0x00000024,0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x00000029,
|
||||
0x0000000f,0x0009004f,0x00000009,0x0000002a,0x00000029,0x00000029,0x00000000,0x00000001,
|
||||
0x00000000,0x00000001,0x0008000c,0x00000009,0x0000002b,0x00000001,0x00000032,0x00000025,
|
||||
0x00000028,0x0000002a,0x00050041,0x0000002c,0x0000002d,0x00000010,0x0000001d,0x0003003e,
|
||||
0x0000002d,0x0000002b,0x00050041,0x00000022,0x0000002e,0x00000020,0x00000021,0x0004003d,
|
||||
0x00000009,0x0000002f,0x0000002e,0x0009004f,0x00000009,0x00000030,0x0000002f,0x0000002f,
|
||||
0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x00000033,0x0000000f,
|
||||
0x0009004f,0x00000009,0x00000034,0x00000033,0x00000033,0x00000000,0x00000001,0x00000000,
|
||||
0x00000001,0x0008000c,0x00000009,0x00000035,0x00000001,0x00000032,0x00000030,0x00000032,
|
||||
0x00000034,0x00050041,0x0000002c,0x00000036,0x00000010,0x00000021,0x0003003e,0x00000036,
|
||||
0x00000035,0x00050041,0x00000022,0x00000038,0x00000020,0x00000021,0x0004003d,0x00000009,
|
||||
0x00000039,0x00000038,0x0009004f,0x00000009,0x0000003a,0x00000039,0x00000039,0x00000000,
|
||||
0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x0000003d,0x0000000f,0x0009004f,
|
||||
0x00000009,0x0000003e,0x0000003d,0x0000003d,0x00000000,0x00000001,0x00000000,0x00000001,
|
||||
0x0008000c,0x00000009,0x0000003f,0x00000001,0x00000032,0x0000003a,0x0000003c,0x0000003e,
|
||||
0x00050041,0x0000002c,0x00000040,0x00000010,0x00000037,0x0003003e,0x00000040,0x0000003f,
|
||||
0x000100fd,0x00010038,0x00050036,0x00000007,0x0000001a,0x00000000,0x00000016,0x00030037,
|
||||
0x00000008,0x00000017,0x00030037,0x0000000d,0x00000018,0x00030037,0x00000015,0x00000019,
|
||||
0x000200f8,0x0000001b,0x0004003b,0x00000008,0x00000041,0x00000007,0x0004003b,0x00000045,
|
||||
0x00000046,0x00000007,0x0004003b,0x0000004b,0x0000004c,0x00000007,0x0004003b,0x0000004b,
|
||||
0x00000053,0x00000007,0x0004003b,0x0000004b,0x0000005c,0x00000007,0x0004003b,0x0000002c,
|
||||
0x00000065,0x00000007,0x0004003b,0x00000008,0x00000073,0x00000007,0x0004003b,0x0000004b,
|
||||
0x00000080,0x00000007,0x0004003b,0x0000004b,0x00000089,0x00000007,0x0004003b,0x00000008,
|
||||
0x0000009e,0x00000007,0x0004003b,0x0000004b,0x000000a4,0x00000007,0x0004003b,0x0000004b,
|
||||
0x000000ad,0x00000007,0x0004003b,0x0000004b,0x000000c6,0x00000007,0x0003003e,0x00000041,
|
||||
0x00000043,0x0003003e,0x00000046,0x0000004a,0x0004003d,0x00000014,0x0000004d,0x00000019,
|
||||
0x0004003d,0x00000007,0x0000004e,0x00000017,0x00050057,0x00000009,0x0000004f,0x0000004d,
|
||||
0x0000004e,0x0008004f,0x00000044,0x00000050,0x0000004f,0x0000004f,0x00000000,0x00000001,
|
||||
0x00000002,0x0004003d,0x00000044,0x00000051,0x00000046,0x00050094,0x00000006,0x00000052,
|
||||
0x00000050,0x00000051,0x0003003e,0x0000004c,0x00000052,0x0004003d,0x00000014,0x00000054,
|
||||
0x00000019,0x00050041,0x0000002c,0x00000055,0x00000018,0x0000001d,0x0004003d,0x00000009,
|
||||
0x00000056,0x00000055,0x0007004f,0x00000007,0x00000057,0x00000056,0x00000056,0x00000000,
|
||||
0x00000001,0x00050057,0x00000009,0x00000058,0x00000054,0x00000057,0x0008004f,0x00000044,
|
||||
0x00000059,0x00000058,0x00000058,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,
|
||||
0x0000005a,0x00000046,0x00050094,0x00000006,0x0000005b,0x00000059,0x0000005a,0x0003003e,
|
||||
0x00000053,0x0000005b,0x0004003d,0x00000014,0x0000005d,0x00000019,0x00050041,0x0000002c,
|
||||
0x0000005e,0x00000018,0x0000001d,0x0004003d,0x00000009,0x0000005f,0x0000005e,0x0007004f,
|
||||
0x00000007,0x00000060,0x0000005f,0x0000005f,0x00000002,0x00000003,0x00050057,0x00000009,
|
||||
0x00000061,0x0000005d,0x00000060,0x0008004f,0x00000044,0x00000062,0x00000061,0x00000061,
|
||||
0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x00000063,0x00000046,0x00050094,
|
||||
0x00000006,0x00000064,0x00000062,0x00000063,0x0003003e,0x0000005c,0x00000064,0x0004003d,
|
||||
0x00000006,0x00000066,0x0000004c,0x0004003d,0x00000006,0x00000067,0x00000053,0x0004003d,
|
||||
0x00000006,0x00000068,0x0000005c,0x00050050,0x00000007,0x00000069,0x00000067,0x00000068,
|
||||
0x00050050,0x00000007,0x0000006a,0x00000066,0x00000066,0x00050083,0x00000007,0x0000006b,
|
||||
0x0000006a,0x00000069,0x0006000c,0x00000007,0x0000006c,0x00000001,0x00000004,0x0000006b,
|
||||
0x00050041,0x0000004b,0x0000006e,0x00000065,0x0000006d,0x00050051,0x00000006,0x0000006f,
|
||||
0x0000006c,0x00000000,0x0003003e,0x0000006e,0x0000006f,0x00050041,0x0000004b,0x00000071,
|
||||
0x00000065,0x00000070,0x00050051,0x00000006,0x00000072,0x0000006c,0x00000001,0x0003003e,
|
||||
0x00000071,0x00000072,0x0004003d,0x00000007,0x00000074,0x00000041,0x0004003d,0x00000009,
|
||||
0x00000075,0x00000065,0x0007004f,0x00000007,0x00000076,0x00000075,0x00000075,0x00000000,
|
||||
0x00000001,0x0007000c,0x00000007,0x00000077,0x00000001,0x00000030,0x00000074,0x00000076,
|
||||
0x0003003e,0x00000073,0x00000077,0x0004003d,0x00000007,0x00000078,0x00000073,0x00050094,
|
||||
0x00000006,0x0000007a,0x00000078,0x00000079,0x000500b4,0x0000007b,0x0000007c,0x0000007a,
|
||||
0x00000027,0x000300f7,0x0000007e,0x00000000,0x000400fa,0x0000007c,0x0000007d,0x0000007e,
|
||||
0x000200f8,0x0000007d,0x000100fc,0x000200f8,0x0000007e,0x0004003d,0x00000014,0x00000081,
|
||||
0x00000019,0x00050041,0x0000002c,0x00000082,0x00000018,0x00000021,0x0004003d,0x00000009,
|
||||
0x00000083,0x00000082,0x0007004f,0x00000007,0x00000084,0x00000083,0x00000083,0x00000000,
|
||||
0x00000001,0x00050057,0x00000009,0x00000085,0x00000081,0x00000084,0x0008004f,0x00000044,
|
||||
0x00000086,0x00000085,0x00000085,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,
|
||||
0x00000087,0x00000046,0x00050094,0x00000006,0x00000088,0x00000086,0x00000087,0x0003003e,
|
||||
0x00000080,0x00000088,0x0004003d,0x00000014,0x0000008a,0x00000019,0x00050041,0x0000002c,
|
||||
0x0000008b,0x00000018,0x00000021,0x0004003d,0x00000009,0x0000008c,0x0000008b,0x0007004f,
|
||||
0x00000007,0x0000008d,0x0000008c,0x0000008c,0x00000002,0x00000003,0x00050057,0x00000009,
|
||||
0x0000008e,0x0000008a,0x0000008d,0x0008004f,0x00000044,0x0000008f,0x0000008e,0x0000008e,
|
||||
0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x00000090,0x00000046,0x00050094,
|
||||
0x00000006,0x00000091,0x0000008f,0x00000090,0x0003003e,0x00000089,0x00000091,0x0004003d,
|
||||
0x00000006,0x00000092,0x0000004c,0x0004003d,0x00000006,0x00000093,0x00000080,0x0004003d,
|
||||
0x00000006,0x00000094,0x00000089,0x00050050,0x00000007,0x00000095,0x00000093,0x00000094,
|
||||
0x00050050,0x00000007,0x00000096,0x00000092,0x00000092,0x00050083,0x00000007,0x00000097,
|
||||
0x00000096,0x00000095,0x0006000c,0x00000007,0x00000098,0x00000001,0x00000004,0x00000097,
|
||||
0x00050041,0x0000004b,0x0000009a,0x00000065,0x00000099,0x00050051,0x00000006,0x0000009b,
|
||||
0x00000098,0x00000000,0x0003003e,0x0000009a,0x0000009b,0x00050041,0x0000004b,0x0000009c,
|
||||
0x00000065,0x0000000b,0x00050051,0x00000006,0x0000009d,0x00000098,0x00000001,0x0003003e,
|
||||
0x0000009c,0x0000009d,0x0004003d,0x00000009,0x0000009f,0x00000065,0x0007004f,0x00000007,
|
||||
0x000000a0,0x0000009f,0x0000009f,0x00000000,0x00000001,0x0004003d,0x00000009,0x000000a1,
|
||||
0x00000065,0x0007004f,0x00000007,0x000000a2,0x000000a1,0x000000a1,0x00000002,0x00000003,
|
||||
0x0007000c,0x00000007,0x000000a3,0x00000001,0x00000028,0x000000a0,0x000000a2,0x0003003e,
|
||||
0x0000009e,0x000000a3,0x0004003d,0x00000014,0x000000a5,0x00000019,0x00050041,0x0000002c,
|
||||
0x000000a6,0x00000018,0x00000037,0x0004003d,0x00000009,0x000000a7,0x000000a6,0x0007004f,
|
||||
0x00000007,0x000000a8,0x000000a7,0x000000a7,0x00000000,0x00000001,0x00050057,0x00000009,
|
||||
0x000000a9,0x000000a5,0x000000a8,0x0008004f,0x00000044,0x000000aa,0x000000a9,0x000000a9,
|
||||
0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x000000ab,0x00000046,0x00050094,
|
||||
0x00000006,0x000000ac,0x000000aa,0x000000ab,0x0003003e,0x000000a4,0x000000ac,0x0004003d,
|
||||
0x00000014,0x000000ae,0x00000019,0x00050041,0x0000002c,0x000000af,0x00000018,0x00000037,
|
||||
0x0004003d,0x00000009,0x000000b0,0x000000af,0x0007004f,0x00000007,0x000000b1,0x000000b0,
|
||||
0x000000b0,0x00000002,0x00000003,0x00050057,0x00000009,0x000000b2,0x000000ae,0x000000b1,
|
||||
0x0008004f,0x00000044,0x000000b3,0x000000b2,0x000000b2,0x00000000,0x00000001,0x00000002,
|
||||
0x0004003d,0x00000044,0x000000b4,0x00000046,0x00050094,0x00000006,0x000000b5,0x000000b3,
|
||||
0x000000b4,0x0003003e,0x000000ad,0x000000b5,0x0004003d,0x00000006,0x000000b6,0x00000053,
|
||||
0x0004003d,0x00000006,0x000000b7,0x0000005c,0x00050050,0x00000007,0x000000b8,0x000000b6,
|
||||
0x000000b7,0x0004003d,0x00000006,0x000000b9,0x000000a4,0x0004003d,0x00000006,0x000000ba,
|
||||
0x000000ad,0x00050050,0x00000007,0x000000bb,0x000000b9,0x000000ba,0x00050083,0x00000007,
|
||||
0x000000bc,0x000000b8,0x000000bb,0x0006000c,0x00000007,0x000000bd,0x00000001,0x00000004,
|
||||
0x000000bc,0x00050041,0x0000004b,0x000000be,0x00000065,0x00000099,0x00050051,0x00000006,
|
||||
0x000000bf,0x000000bd,0x00000000,0x0003003e,0x000000be,0x000000bf,0x00050041,0x0000004b,
|
||||
0x000000c0,0x00000065,0x0000000b,0x00050051,0x00000006,0x000000c1,0x000000bd,0x00000001,
|
||||
0x0003003e,0x000000c0,0x000000c1,0x0004003d,0x00000007,0x000000c2,0x0000009e,0x0004003d,
|
||||
0x00000009,0x000000c3,0x00000065,0x0007004f,0x00000007,0x000000c4,0x000000c3,0x000000c3,
|
||||
0x00000002,0x00000003,0x0007000c,0x00000007,0x000000c5,0x00000001,0x00000028,0x000000c2,
|
||||
0x000000c4,0x0003003e,0x0000009e,0x000000c5,0x00050041,0x0000004b,0x000000c7,0x0000009e,
|
||||
0x0000006d,0x0004003d,0x00000006,0x000000c8,0x000000c7,0x00050041,0x0000004b,0x000000c9,
|
||||
0x0000009e,0x00000070,0x0004003d,0x00000006,0x000000ca,0x000000c9,0x0007000c,0x00000006,
|
||||
0x000000cb,0x00000001,0x00000028,0x000000c8,0x000000ca,0x0003003e,0x000000c6,0x000000cb,
|
||||
0x0004003d,0x00000006,0x000000cc,0x000000c6,0x0004003d,0x00000009,0x000000ce,0x00000065,
|
||||
0x0007004f,0x00000007,0x000000cf,0x000000ce,0x000000ce,0x00000000,0x00000001,0x0005008e,
|
||||
0x00000007,0x000000d0,0x000000cf,0x000000cd,0x00050050,0x00000007,0x000000d1,0x000000cc,
|
||||
0x000000cc,0x0007000c,0x00000007,0x000000d2,0x00000001,0x00000030,0x000000d1,0x000000d0,
|
||||
0x0004003d,0x00000007,0x000000d3,0x00000073,0x00050085,0x00000007,0x000000d4,0x000000d3,
|
||||
0x000000d2,0x0003003e,0x00000073,0x000000d4,0x0004003d,0x00000007,0x000000d5,0x00000073,
|
||||
0x000200fe,0x000000d5,0x00010038
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000028,0x0000006e,0x00030010,
|
||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
||||
0x00000000,0x00050005,0x0000000b,0x616d756c,0x33667628,0x0000003b,0x00030005,0x0000000a,
|
||||
0x00000063,0x00030005,0x00000017,0x00007870,0x00050005,0x0000001a,0x736e6f43,0x746e6174,
|
||||
0x00000073,0x00040006,0x0000001a,0x00000000,0x0063646e,0x00060006,0x0000001a,0x00000001,
|
||||
0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x0000001a,0x00000002,0x72747865,0x00000061,
|
||||
0x00040006,0x0000001a,0x00000003,0x00646170,0x00030005,0x0000001c,0x00006370,0x00030005,
|
||||
0x00000026,0x00007675,0x00060005,0x00000028,0x67617266,0x43786554,0x64726f6f,0x00000000,
|
||||
0x00040005,0x00000032,0x746e6563,0x00007265,0x00060005,0x00000036,0x75706e49,0x78655474,
|
||||
0x65727574,0x00000000,0x00040005,0x0000003a,0x61726170,0x0000006d,0x00040005,0x0000003d,
|
||||
0x7466656c,0x00000000,0x00040005,0x00000048,0x61726170,0x0000006d,0x00040005,0x0000004b,
|
||||
0x68676972,0x00000074,0x00040005,0x00000053,0x61726170,0x0000006d,0x00030005,0x00000056,
|
||||
0x00007075,0x00040005,0x0000005f,0x61726170,0x0000006d,0x00040005,0x00000062,0x6e776f64,
|
||||
0x00000000,0x00040005,0x0000006a,0x61726170,0x0000006d,0x00050005,0x0000006e,0x4374756f,
|
||||
0x726f6c6f,0x00000000,0x00030047,0x0000001a,0x00000002,0x00050048,0x0000001a,0x00000000,
|
||||
0x00000023,0x00000000,0x00050048,0x0000001a,0x00000001,0x00000023,0x00000010,0x00050048,
|
||||
0x0000001a,0x00000002,0x00000023,0x00000018,0x00050048,0x0000001a,0x00000003,0x00000023,
|
||||
0x0000001c,0x00040047,0x00000028,0x0000001e,0x00000000,0x00040047,0x00000036,0x00000021,
|
||||
0x00000000,0x00040047,0x00000036,0x00000022,0x00000000,0x00040047,0x0000006e,0x0000001e,
|
||||
0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
|
||||
0x00000020,0x00040017,0x00000007,0x00000006,0x00000003,0x00040020,0x00000008,0x00000007,
|
||||
0x00000007,0x00040021,0x00000009,0x00000006,0x00000008,0x0004002b,0x00000006,0x0000000e,
|
||||
0x3e59b3d0,0x0004002b,0x00000006,0x0000000f,0x3f371759,0x0004002b,0x00000006,0x00000010,
|
||||
0x3d93dd98,0x0006002c,0x00000007,0x00000011,0x0000000e,0x0000000f,0x00000010,0x00040017,
|
||||
0x00000015,0x00000006,0x00000002,0x00040020,0x00000016,0x00000007,0x00000015,0x0004002b,
|
||||
0x00000006,0x00000018,0x3f800000,0x00040017,0x00000019,0x00000006,0x00000004,0x0006001e,
|
||||
0x0000001a,0x00000019,0x00000015,0x00000006,0x00000006,0x00040020,0x0000001b,0x00000009,
|
||||
0x0000001a,0x0004003b,0x0000001b,0x0000001c,0x00000009,0x00040015,0x0000001d,0x00000020,
|
||||
0x00000001,0x0004002b,0x0000001d,0x0000001e,0x00000001,0x00040020,0x0000001f,0x00000009,
|
||||
0x00000015,0x0005002c,0x00000015,0x00000022,0x00000018,0x00000018,0x00040020,0x00000027,
|
||||
0x00000001,0x00000015,0x0004003b,0x00000027,0x00000028,0x00000001,0x0004002b,0x00000006,
|
||||
0x0000002b,0x3f000000,0x00040020,0x00000031,0x00000007,0x00000006,0x00090019,0x00000033,
|
||||
0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,
|
||||
0x00000034,0x00000033,0x00040020,0x00000035,0x00000000,0x00000034,0x0004003b,0x00000035,
|
||||
0x00000036,0x00000000,0x00040015,0x00000040,0x00000020,0x00000000,0x0004002b,0x00000040,
|
||||
0x00000041,0x00000000,0x0004002b,0x00000006,0x00000044,0x00000000,0x0004002b,0x00000040,
|
||||
0x00000059,0x00000001,0x00040020,0x0000006d,0x00000003,0x00000019,0x0004003b,0x0000006d,
|
||||
0x0000006e,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
|
||||
0x00000005,0x0004003b,0x00000016,0x00000017,0x00000007,0x0004003b,0x00000016,0x00000026,
|
||||
0x00000007,0x0004003b,0x00000031,0x00000032,0x00000007,0x0004003b,0x00000008,0x0000003a,
|
||||
0x00000007,0x0004003b,0x00000031,0x0000003d,0x00000007,0x0004003b,0x00000008,0x00000048,
|
||||
0x00000007,0x0004003b,0x00000031,0x0000004b,0x00000007,0x0004003b,0x00000008,0x00000053,
|
||||
0x00000007,0x0004003b,0x00000031,0x00000056,0x00000007,0x0004003b,0x00000008,0x0000005f,
|
||||
0x00000007,0x0004003b,0x00000031,0x00000062,0x00000007,0x0004003b,0x00000008,0x0000006a,
|
||||
0x00000007,0x00050041,0x0000001f,0x00000020,0x0000001c,0x0000001e,0x0004003d,0x00000015,
|
||||
0x00000021,0x00000020,0x0007000c,0x00000015,0x00000023,0x00000001,0x00000028,0x00000021,
|
||||
0x00000022,0x00050050,0x00000015,0x00000024,0x00000018,0x00000018,0x00050088,0x00000015,
|
||||
0x00000025,0x00000024,0x00000023,0x0003003e,0x00000017,0x00000025,0x0004003d,0x00000015,
|
||||
0x00000029,0x00000028,0x0004003d,0x00000015,0x0000002a,0x00000017,0x0005008e,0x00000015,
|
||||
0x0000002c,0x0000002a,0x0000002b,0x0004003d,0x00000015,0x0000002d,0x00000017,0x0005008e,
|
||||
0x00000015,0x0000002e,0x0000002d,0x0000002b,0x00050083,0x00000015,0x0000002f,0x00000022,
|
||||
0x0000002e,0x0008000c,0x00000015,0x00000030,0x00000001,0x0000002b,0x00000029,0x0000002c,
|
||||
0x0000002f,0x0003003e,0x00000026,0x00000030,0x0004003d,0x00000034,0x00000037,0x00000036,
|
||||
0x0004003d,0x00000015,0x00000038,0x00000026,0x00050057,0x00000019,0x00000039,0x00000037,
|
||||
0x00000038,0x0008004f,0x00000007,0x0000003b,0x00000039,0x00000039,0x00000000,0x00000001,
|
||||
0x00000002,0x0003003e,0x0000003a,0x0000003b,0x00050039,0x00000006,0x0000003c,0x0000000b,
|
||||
0x0000003a,0x0003003e,0x00000032,0x0000003c,0x0004003d,0x00000034,0x0000003e,0x00000036,
|
||||
0x0004003d,0x00000015,0x0000003f,0x00000026,0x00050041,0x00000031,0x00000042,0x00000017,
|
||||
0x00000041,0x0004003d,0x00000006,0x00000043,0x00000042,0x00050050,0x00000015,0x00000045,
|
||||
0x00000043,0x00000044,0x00050083,0x00000015,0x00000046,0x0000003f,0x00000045,0x00050057,
|
||||
0x00000019,0x00000047,0x0000003e,0x00000046,0x0008004f,0x00000007,0x00000049,0x00000047,
|
||||
0x00000047,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000048,0x00000049,0x00050039,
|
||||
0x00000006,0x0000004a,0x0000000b,0x00000048,0x0003003e,0x0000003d,0x0000004a,0x0004003d,
|
||||
0x00000034,0x0000004c,0x00000036,0x0004003d,0x00000015,0x0000004d,0x00000026,0x00050041,
|
||||
0x00000031,0x0000004e,0x00000017,0x00000041,0x0004003d,0x00000006,0x0000004f,0x0000004e,
|
||||
0x00050050,0x00000015,0x00000050,0x0000004f,0x00000044,0x00050081,0x00000015,0x00000051,
|
||||
0x0000004d,0x00000050,0x00050057,0x00000019,0x00000052,0x0000004c,0x00000051,0x0008004f,
|
||||
0x00000007,0x00000054,0x00000052,0x00000052,0x00000000,0x00000001,0x00000002,0x0003003e,
|
||||
0x00000053,0x00000054,0x00050039,0x00000006,0x00000055,0x0000000b,0x00000053,0x0003003e,
|
||||
0x0000004b,0x00000055,0x0004003d,0x00000034,0x00000057,0x00000036,0x0004003d,0x00000015,
|
||||
0x00000058,0x00000026,0x00050041,0x00000031,0x0000005a,0x00000017,0x00000059,0x0004003d,
|
||||
0x00000006,0x0000005b,0x0000005a,0x00050050,0x00000015,0x0000005c,0x00000044,0x0000005b,
|
||||
0x00050083,0x00000015,0x0000005d,0x00000058,0x0000005c,0x00050057,0x00000019,0x0000005e,
|
||||
0x00000057,0x0000005d,0x0008004f,0x00000007,0x00000060,0x0000005e,0x0000005e,0x00000000,
|
||||
0x00000001,0x00000002,0x0003003e,0x0000005f,0x00000060,0x00050039,0x00000006,0x00000061,
|
||||
0x0000000b,0x0000005f,0x0003003e,0x00000056,0x00000061,0x0004003d,0x00000034,0x00000063,
|
||||
0x00000036,0x0004003d,0x00000015,0x00000064,0x00000026,0x00050041,0x00000031,0x00000065,
|
||||
0x00000017,0x00000059,0x0004003d,0x00000006,0x00000066,0x00000065,0x00050050,0x00000015,
|
||||
0x00000067,0x00000044,0x00000066,0x00050081,0x00000015,0x00000068,0x00000064,0x00000067,
|
||||
0x00050057,0x00000019,0x00000069,0x00000063,0x00000068,0x0008004f,0x00000007,0x0000006b,
|
||||
0x00000069,0x00000069,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000006a,0x0000006b,
|
||||
0x00050039,0x00000006,0x0000006c,0x0000000b,0x0000006a,0x0003003e,0x00000062,0x0000006c,
|
||||
0x0004003d,0x00000006,0x0000006f,0x00000032,0x0004003d,0x00000006,0x00000070,0x0000003d,
|
||||
0x00050083,0x00000006,0x00000071,0x0000006f,0x00000070,0x0006000c,0x00000006,0x00000072,
|
||||
0x00000001,0x00000004,0x00000071,0x0004003d,0x00000006,0x00000073,0x00000032,0x0004003d,
|
||||
0x00000006,0x00000074,0x0000004b,0x00050083,0x00000006,0x00000075,0x00000073,0x00000074,
|
||||
0x0006000c,0x00000006,0x00000076,0x00000001,0x00000004,0x00000075,0x0004003d,0x00000006,
|
||||
0x00000077,0x00000032,0x0004003d,0x00000006,0x00000078,0x00000056,0x00050083,0x00000006,
|
||||
0x00000079,0x00000077,0x00000078,0x0006000c,0x00000006,0x0000007a,0x00000001,0x00000004,
|
||||
0x00000079,0x0004003d,0x00000006,0x0000007b,0x00000032,0x0004003d,0x00000006,0x0000007c,
|
||||
0x00000062,0x00050083,0x00000006,0x0000007d,0x0000007b,0x0000007c,0x0006000c,0x00000006,
|
||||
0x0000007e,0x00000001,0x00000004,0x0000007d,0x00070050,0x00000019,0x0000007f,0x00000072,
|
||||
0x00000076,0x0000007a,0x0000007e,0x0003003e,0x0000006e,0x0000007f,0x000100fd,0x00010038,
|
||||
0x00050036,0x00000006,0x0000000b,0x00000000,0x00000009,0x00030037,0x00000008,0x0000000a,
|
||||
0x000200f8,0x0000000c,0x0004003d,0x00000007,0x0000000d,0x0000000a,0x00050094,0x00000006,
|
||||
0x00000012,0x0000000d,0x00000011,0x000200fe,0x00000012,0x00010038
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,25 +1,153 @@
|
||||
#version 450
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
layout(location = 0) in vec2 fragTexCoord;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(set = 0, binding = 0) uniform sampler2D EdgeTexture;
|
||||
layout(set = 1, binding = 0) uniform sampler2D AreaTexture;
|
||||
layout(set = 2, binding = 0) uniform sampler2D SearchTexture;
|
||||
layout(push_constant) uniform Constants {
|
||||
vec4 ndc;
|
||||
vec4 metrics; // 1/width, 1/height, width, height
|
||||
vec2 resolution;
|
||||
float extra;
|
||||
float pad;
|
||||
} pc;
|
||||
|
||||
#define SMAA_RT_METRICS pc.metrics
|
||||
#define SMAA_GLSL_4
|
||||
#define SMAA_PRESET_HIGH
|
||||
#include "SMAA.hlsl"
|
||||
vec4 edgeAt(vec2 uv, vec2 px) {
|
||||
vec2 edgeUV = clamp(uv, px * 0.5, vec2(1.0) - px * 0.5);
|
||||
vec4 e = textureLod(EdgeTexture, edgeUV, 0.0);
|
||||
e.a = edgeUV.y >= 1.0 - px.y ? 0.0 : e.a;
|
||||
return e;
|
||||
}
|
||||
|
||||
float verticalEdge(vec2 uv, vec2 px) {
|
||||
vec4 e = edgeAt(uv, px);
|
||||
return max(e.r, e.g);
|
||||
}
|
||||
|
||||
float horizontalEdge(vec2 uv, vec2 px) {
|
||||
vec4 e = edgeAt(uv, px);
|
||||
return max(e.b, e.a);
|
||||
}
|
||||
|
||||
float measureRun(vec2 origin, vec2 texel, vec2 tangent,
|
||||
bool verticalLine, float limit, bool positive) {
|
||||
float run = 0.0;
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
vec2 probe = origin + tangent * float(i) * (positive ? 1.0 : -1.0);
|
||||
ivec2 index = ivec2(floor(probe * pc.resolution));
|
||||
ivec2 size = ivec2(pc.resolution);
|
||||
if (any(lessThan(index, ivec2(0))) ||
|
||||
any(greaterThanEqual(index, size))) {
|
||||
break;
|
||||
}
|
||||
float edge = verticalLine
|
||||
? verticalEdge(probe, texel)
|
||||
: horizontalEdge(probe, texel);
|
||||
if (edge <= limit * 0.65) {
|
||||
break;
|
||||
}
|
||||
run = float(i);
|
||||
}
|
||||
return run;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 pixcoord;
|
||||
vec4 offset[3];
|
||||
SMAABlendingWeightCalculationVS(fragTexCoord, pixcoord, offset);
|
||||
outColor = SMAABlendingWeightCalculationPS(fragTexCoord, pixcoord, offset, EdgeTexture,
|
||||
AreaTexture, SearchTexture, vec4(0.0));
|
||||
vec2 px = 1.0 / max(pc.resolution, vec2(1.0));
|
||||
vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5);
|
||||
vec4 e = edgeAt(uv, px);
|
||||
|
||||
float dL = e.r;
|
||||
float dR = e.g;
|
||||
float dU = e.b;
|
||||
float dD = e.a;
|
||||
float vertical = max(dL, dR);
|
||||
float horizontal = max(dU, dD);
|
||||
float strongest = max(vertical, horizontal);
|
||||
float threshold = max(0.045, strongest * 0.12);
|
||||
|
||||
if (strongest <= threshold) {
|
||||
outColor = vec4(0.0, 0.5, 0.5, 0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
bool verticalLine;
|
||||
float negativeRun = 0.0;
|
||||
float positiveRun = 0.0;
|
||||
bool runsMeasured = false;
|
||||
|
||||
if (vertical > horizontal) {
|
||||
verticalLine = true;
|
||||
} else if (horizontal > vertical) {
|
||||
verticalLine = false;
|
||||
} else {
|
||||
float vNeg = measureRun(uv, px, vec2(0.0, px.y), true, threshold, false);
|
||||
float vPos = measureRun(uv, px, vec2(0.0, px.y), true, threshold, true);
|
||||
float hNeg = measureRun(uv, px, vec2(px.x, 0.0), false, threshold, false);
|
||||
float hPos = measureRun(uv, px, vec2(px.x, 0.0), false, threshold, true);
|
||||
verticalLine = (vNeg + vPos) >= (hNeg + hPos);
|
||||
negativeRun = verticalLine ? vNeg : hNeg;
|
||||
positiveRun = verticalLine ? vPos : hPos;
|
||||
runsMeasured = true;
|
||||
}
|
||||
|
||||
vec2 tangent = verticalLine ? vec2(0.0, px.y) : vec2(px.x, 0.0);
|
||||
vec2 normal = verticalLine
|
||||
? vec2(dL >= dR ? -1.0 : 1.0, 0.0)
|
||||
: vec2(0.0, dU >= dD ? -1.0 : 1.0);
|
||||
|
||||
if (!runsMeasured) {
|
||||
negativeRun = measureRun(uv, px, tangent, verticalLine, threshold, false);
|
||||
positiveRun = measureRun(uv, px, tangent, verticalLine, threshold, true);
|
||||
}
|
||||
|
||||
float span = negativeRun + positiveRun;
|
||||
float edgeConfidence = smoothstep(threshold, threshold * 2.5, strongest);
|
||||
|
||||
vec4 nw = edgeAt(uv + vec2(-px.x, -px.y), px);
|
||||
vec4 ne = edgeAt(uv + vec2(px.x, -px.y), px);
|
||||
vec4 sw = edgeAt(uv + vec2(-px.x, px.y), px);
|
||||
vec4 se = edgeAt(uv + vec2(px.x, px.y), px);
|
||||
|
||||
float runEndpointPattern = clamp(
|
||||
abs(negativeRun - positiveRun) / max(span, 1.0), 0.0, 1.0);
|
||||
float crossingA = verticalLine
|
||||
? abs(nw.a - ne.a)
|
||||
: abs(nw.g - sw.g);
|
||||
float crossingB = verticalLine
|
||||
? abs(sw.b - se.b)
|
||||
: abs(ne.r - se.r);
|
||||
float crossingContrast = abs(crossingA - crossingB);
|
||||
float crossingPattern = smoothstep(threshold, threshold * 2.5, crossingContrast);
|
||||
vec4 edgeMin = min(min(nw, ne), min(sw, se));
|
||||
vec4 edgeMax = max(max(nw, ne), max(sw, se));
|
||||
float edgeVariation = max(
|
||||
max(edgeMax.r - edgeMin.r, edgeMax.g - edgeMin.g),
|
||||
max(edgeMax.b - edgeMin.b, edgeMax.a - edgeMin.a));
|
||||
float balancedCrossing = edgeVariation > 0.01
|
||||
? smoothstep(threshold, threshold * 2.5, min(crossingA, crossingB))
|
||||
: 0.0;
|
||||
float endpointPattern = runEndpointPattern > 0.01
|
||||
? max(runEndpointPattern, balancedCrossing)
|
||||
: runEndpointPattern;
|
||||
float endpointArea = endpointPattern / (1.0 + span * 0.055);
|
||||
float areaWeight = 0.38 * crossingPattern * clamp(span / 4.0, 0.0, 1.0);
|
||||
float diagonalContrast = max(
|
||||
max(max(abs(nw.r - se.r), abs(nw.g - se.g)),
|
||||
max(abs(nw.b - se.b), abs(nw.a - se.a))),
|
||||
max(max(abs(ne.r - sw.r), abs(ne.g - sw.g)),
|
||||
max(abs(ne.b - sw.b), abs(ne.a - sw.a))));
|
||||
float cornerFactor = 1.0 - 0.35 * smoothstep(threshold, threshold * 3.0, diagonalContrast);
|
||||
float baseWeight = areaWeight * endpointArea * edgeConfidence * cornerFactor;
|
||||
|
||||
float diagonalStrength = min(vertical, horizontal);
|
||||
float diagonalPattern = smoothstep(threshold, threshold * 2.5, diagonalStrength);
|
||||
float diagonalContinuity = smoothstep(1.0, 3.0, span);
|
||||
float shortDiagonalFallback =
|
||||
(span > 0.0 && span <= 1.0 && crossingContrast <= threshold && diagonalStrength > threshold)
|
||||
? 1.0 : 0.0;
|
||||
float diagonalFallback = 0.16 * diagonalPattern * edgeConfidence
|
||||
* cornerFactor * max(
|
||||
diagonalContinuity * max(crossingPattern, balancedCrossing),
|
||||
shortDiagonalFallback);
|
||||
|
||||
float weight = clamp(max(baseWeight, diagonalFallback), 0.0, 0.42);
|
||||
outColor = vec4(weight, normal.x * 0.5 + 0.5, normal.y * 0.5 + 0.5, 1.0);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1 +0,0 @@
|
||||
ZeroFG is fetched by CMake from hy300leosquizz-ctrl/ZeroFG (the upstream repository) at pinned commit e6ca7ef9f9765db89847b6d8eed352e458f1a8bb. DroidDeck keeps ownership of presentation; the independent presenter is not used. License: Apache-2.0 OR GPL-2.0-or-later; see the fetched ZeroFG source tree for the license text.
|
||||
@@ -42,11 +42,6 @@ add_library(droiddeckwayland SHARED
|
||||
src/hudframes.c
|
||||
src/hudframes_jni.c
|
||||
)
|
||||
option(DROIDDECK_FRAME_ACQUIRE_PROBE "Build opt-in signaled producer acquire protocol support" ON)
|
||||
if (DROIDDECK_FRAME_ACQUIRE_PROBE)
|
||||
target_sources(droiddeckwayland PRIVATE generated/droiddeck-frame-acquire-v1-protocol.c)
|
||||
target_compile_definitions(droiddeckwayland PRIVATE DROIDDECK_FRAME_ACQUIRE_PROBE=1)
|
||||
endif()
|
||||
target_compile_options(droiddeckwayland PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers>)
|
||||
target_include_directories(droiddeckwayland PRIVATE
|
||||
@@ -64,7 +59,6 @@ if (TARGET dxbc AND EXISTS ${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp
|
||||
message(STATUS "droiddeckwayland: frame-generation engines built in (LSFG Native, DD-FG Native)")
|
||||
target_sources(droiddeckwayland PRIVATE
|
||||
src/framegen_engine.cpp
|
||||
src/framegen_zerofg.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_probe.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_dll.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_dxbc.cpp
|
||||
@@ -91,12 +85,12 @@ if (TARGET dxbc AND EXISTS ${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../framegen
|
||||
)
|
||||
target_compile_options(droiddeckwayland PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=c++20 -fvisibility=hidden>)
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=c++17 -fvisibility=hidden>)
|
||||
target_compile_definitions(droiddeckwayland PRIVATE
|
||||
DDFG_UPSTREAM="${DDFG_UPSTREAM}"
|
||||
DDFG_CHAIN_HASH="${DDFG_CHAIN_HASH}"
|
||||
)
|
||||
target_link_libraries(droiddeckwayland dxbc atomic zerofg::zerofg)
|
||||
target_link_libraries(droiddeckwayland dxbc atomic)
|
||||
else()
|
||||
message(STATUS "droiddeckwayland: frame-generation engines NOT built in (standalone build): stub")
|
||||
target_sources(droiddeckwayland PRIVATE src/framegen_engine_stub.c)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/* Generated by wayland-scanner 1.22.0 */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "wayland-util.h"
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
|
||||
#endif
|
||||
|
||||
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
|
||||
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
|
||||
#else
|
||||
#define WL_PRIVATE
|
||||
#endif
|
||||
|
||||
extern const struct wl_interface wl_buffer_interface;
|
||||
extern const struct wl_interface wl_surface_interface;
|
||||
|
||||
static const struct wl_interface *droiddeck_frame_acquire_v1_types[] = {
|
||||
&wl_surface_interface,
|
||||
&wl_buffer_interface,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct wl_message droiddeck_frame_acquire_v1_requests[] = {
|
||||
{ "destroy", "", droiddeck_frame_acquire_v1_types + 0 },
|
||||
{ "set_acquire_fence", "ooh", droiddeck_frame_acquire_v1_types + 0 },
|
||||
};
|
||||
|
||||
WL_PRIVATE const struct wl_interface droiddeck_frame_acquire_v1_interface = {
|
||||
"droiddeck_frame_acquire_v1", 1,
|
||||
2, droiddeck_frame_acquire_v1_requests,
|
||||
0, NULL,
|
||||
};
|
||||
@@ -1,128 +0,0 @@
|
||||
/* Generated by wayland-scanner 1.22.0 */
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "wayland-server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wl_client;
|
||||
struct wl_resource;
|
||||
|
||||
/**
|
||||
* @page page_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 protocol
|
||||
* @section page_ifaces_droiddeck_frame_acquire_v1 Interfaces
|
||||
* - @subpage page_iface_droiddeck_frame_acquire_v1 - DroidDeck producer write completion for a single Wayland attachment
|
||||
*/
|
||||
struct droiddeck_frame_acquire_v1;
|
||||
struct wl_buffer;
|
||||
struct wl_surface;
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_droiddeck_frame_acquire_v1 droiddeck_frame_acquire_v1
|
||||
* @section page_iface_droiddeck_frame_acquire_v1_desc Description
|
||||
*
|
||||
* Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
* allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
* release or existing synchronization protocols. The server advertises it
|
||||
* only when it implements all semantics for the selected display path.
|
||||
* @section page_iface_droiddeck_frame_acquire_v1_api API
|
||||
* See @ref iface_droiddeck_frame_acquire_v1.
|
||||
*/
|
||||
/**
|
||||
* @defgroup iface_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 interface
|
||||
*
|
||||
* Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
* allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
* release or existing synchronization protocols. The server advertises it
|
||||
* only when it implements all semantics for the selected display path.
|
||||
*/
|
||||
extern const struct wl_interface droiddeck_frame_acquire_v1_interface;
|
||||
#endif
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
|
||||
enum droiddeck_frame_acquire_v1_error {
|
||||
/**
|
||||
* not the same client's pending DMA-BUF attachment
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_ATTACHMENT = 0,
|
||||
/**
|
||||
* that attachment already has an acquire fence
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_DUPLICATE_FENCE = 1,
|
||||
/**
|
||||
* not a real successfully signaled Linux sync_file
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_FENCE = 2,
|
||||
/**
|
||||
* not the paired test peer
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_UNAUTHORIZED_PEER = 3,
|
||||
};
|
||||
#endif /* DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM */
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
* @struct droiddeck_frame_acquire_v1_interface
|
||||
*/
|
||||
struct droiddeck_frame_acquire_v1_interface {
|
||||
/**
|
||||
*/
|
||||
void (*destroy)(struct wl_client *client,
|
||||
struct wl_resource *resource);
|
||||
/**
|
||||
* set a one-shot kernel sync_file for the pending attachment
|
||||
*
|
||||
* After wl_surface.attach of a non-null buffer, and before its
|
||||
* next wl_surface.commit, send the producer's final writer fence
|
||||
* for that exact attachment. This outer probe requires that fence
|
||||
* to have already successfully signaled. The fence must be a real
|
||||
* Linux sync_file, not a dma-buf, eventfd, or Vulkan OPAQUE_FD.
|
||||
* The server consumes its received descriptor once for that
|
||||
* attachment; the caller closes its local FD after marshalling.
|
||||
*
|
||||
* The receiver validates the matching pending surface and buffer
|
||||
* and validates the descriptor. A duplicate, invalid, pending or
|
||||
* mismatched request is a protocol error; it is never downgraded
|
||||
* to implicit sync. Another attach (even the same wl_buffer),
|
||||
* detach, surface/resource loss or supersession makes the old
|
||||
* proof inapplicable. Metadata-only commits may amend
|
||||
* receiver-side still-pending state but cannot introduce or re-use
|
||||
* a fence themselves. If no request was made, the receiver keeps
|
||||
* its established safe path. If a valid fence has been accepted
|
||||
* and later the layer is ineligible, the buffer must not be
|
||||
* copied/read before that fence is satisfied or imported as the
|
||||
* source dependency. Transport never implies readiness on missed
|
||||
* deadlines and never changes release/retirement requirements.
|
||||
* @param fence producer's native acquire sync_file
|
||||
*/
|
||||
void (*set_acquire_fence)(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *surface,
|
||||
struct wl_resource *buffer,
|
||||
int32_t fence);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
*/
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_DESTROY_SINCE_VERSION 1
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
*/
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_SET_ACQUIRE_FENCE_SINCE_VERSION 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="droiddeck_frame_acquire_v1">
|
||||
<interface name="droiddeck_frame_acquire_v1" version="1">
|
||||
<description summary="DroidDeck producer write completion for a single Wayland attachment">
|
||||
Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
release or existing synchronization protocols. The server advertises it
|
||||
only when it implements all semantics for the selected display path and
|
||||
only to the test fixture's app-authorized Gamescope worker.
|
||||
</description>
|
||||
<request name="destroy" type="destructor"/>
|
||||
<enum name="error">
|
||||
<entry name="invalid_attachment" value="0" summary="not the same client's pending DMA-BUF attachment"/>
|
||||
<entry name="duplicate_fence" value="1" summary="that attachment already has an acquire fence"/>
|
||||
<entry name="invalid_fence" value="2" summary="not a real successfully signaled Linux sync_file"/>
|
||||
<entry name="unauthorized_peer" value="3" summary="not the paired test peer"/>
|
||||
</enum>
|
||||
<request name="set_acquire_fence">
|
||||
<description summary="set a one-shot kernel sync_file for the pending attachment">
|
||||
After wl_surface.attach of a non-null buffer, and before its next
|
||||
wl_surface.commit, send the producer's final writer fence for that
|
||||
exact attachment. This outer probe requires that fence to have already
|
||||
successfully signaled. The fence must be a real Linux sync_file, not a
|
||||
dma-buf, eventfd, or Vulkan OPAQUE_FD. The server consumes its received
|
||||
descriptor once for that attachment; the caller closes its local FD
|
||||
after marshalling.
|
||||
|
||||
The receiver validates the matching pending surface and buffer and
|
||||
validates the descriptor. A duplicate, invalid, pending or mismatched
|
||||
request is a protocol error; it is never downgraded to implicit sync. Another attach (even the same
|
||||
wl_buffer), detach, surface/resource loss or supersession makes the
|
||||
old proof inapplicable. Metadata-only commits may amend receiver-side
|
||||
still-pending state but cannot introduce or re-use a fence themselves.
|
||||
If no request was made, the receiver keeps its established safe path.
|
||||
If a valid fence has been accepted and later the layer is ineligible,
|
||||
the buffer must not be copied/read before that fence is satisfied or
|
||||
imported as the source dependency. Transport never implies readiness
|
||||
on missed deadlines and never changes release/retirement requirements.
|
||||
</description>
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
<arg name="buffer" type="object" interface="wl_buffer"/>
|
||||
<arg name="fence" type="fd" summary="producer's native acquire sync_file"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
||||
@@ -54,7 +54,6 @@ static struct wl_list g_clients;
|
||||
static uint64_t g_next_id = 1;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static unsigned g_stat_zero_copy;
|
||||
static unsigned g_stat_producer_fence;
|
||||
static int g_export_failed_logged, g_import_failed_logged;
|
||||
static int g_advertised;
|
||||
static int g_mode_sent = -1;
|
||||
@@ -202,47 +201,31 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot(b) : NULL;
|
||||
if (!ab) return -1;
|
||||
int dmabuf_fd = droiddeck_dmabuf_fd(b);
|
||||
int acquire = droiddeck_surface_dup_acquire(s, b);
|
||||
if (acquire == -2) return -1;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
const int explicit_acquire = acquire >= 0;
|
||||
#endif
|
||||
if (acquire < 0) {
|
||||
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
|
||||
acquire = exp.fd;
|
||||
} else {
|
||||
if (!g_export_failed_logged) {
|
||||
g_export_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
|
||||
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
|
||||
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
|
||||
}
|
||||
if (dmabuf_fd >= 0) {
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
}
|
||||
if (draw) return -1;
|
||||
int acquire = -1;
|
||||
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
|
||||
acquire = exp.fd;
|
||||
} else {
|
||||
if (!g_export_failed_logged) {
|
||||
g_export_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
|
||||
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
|
||||
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
|
||||
}
|
||||
if (dmabuf_fd >= 0) {
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
}
|
||||
if (draw) return -1;
|
||||
}
|
||||
int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, draw,
|
||||
s ? droiddeck_surface_color(s) : NULL, ab->format);
|
||||
if (r < 0) return -1;
|
||||
if (r == 1) return 0;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
static int explicit_logged;
|
||||
if (explicit_acquire && !explicit_logged) {
|
||||
explicit_logged = 1;
|
||||
droiddeck_log("layer", "probe: SurfaceControl accepted a verified producer acquire fence");
|
||||
}
|
||||
#endif
|
||||
if (!ab->on_layer) {
|
||||
ab->on_layer = 1;
|
||||
g_stat_zero_copy++;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
if (explicit_acquire) g_stat_producer_fence++;
|
||||
#endif
|
||||
g_last_zero_copy_ns = now_ns();
|
||||
}
|
||||
if (s && g_announced != s) {
|
||||
@@ -282,12 +265,6 @@ unsigned ahb_swapchain_stats_take(void) {
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned ahb_swapchain_producer_fence_stats_take(void) {
|
||||
unsigned n = g_stat_producer_fence;
|
||||
g_stat_producer_fence = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
int ahb_swapchain_advertised(void) { return g_advertised; }
|
||||
|
||||
uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b) {
|
||||
|
||||
@@ -20,9 +20,7 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buffer, struct surface *s, int paced);
|
||||
void ahb_swapchain_surface_gone(struct surface *s);
|
||||
unsigned ahb_swapchain_stats_take(void);
|
||||
unsigned ahb_swapchain_producer_fence_stats_take(void);
|
||||
int ahb_swapchain_advertised(void);
|
||||
int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b);
|
||||
uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b);
|
||||
|
||||
void ahb_swapchain_layer_released(void *token, int release_fd);
|
||||
|
||||
@@ -24,14 +24,6 @@
|
||||
#include "linux-dmabuf-v1-server-protocol.h"
|
||||
#include "sc_layer.h"
|
||||
#include "ahb_swapchain.h"
|
||||
#include "frame_acquire.h"
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
#include "droiddeck-frame-acquire-v1-server-protocol.h"
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
#include "frame_worker_peer.h"
|
||||
#endif
|
||||
#include "display_buffers.h"
|
||||
#include "viewporter-server-protocol.h"
|
||||
#include "droiddeck-desktop-v1-server-protocol.h"
|
||||
@@ -219,7 +211,6 @@ struct surface {
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_resource *pending_buffer;
|
||||
struct dd_frame_acquire pending_frame_acquire, frame_acquire;
|
||||
struct wl_listener pending_buffer_destroy;
|
||||
int pending_attach;
|
||||
int pending_src_set, pending_dst_set;
|
||||
@@ -343,7 +334,6 @@ volatile int g_hide_shell;
|
||||
|
||||
volatile int g_zero_copy;
|
||||
static int g_zero_copy_paused;
|
||||
static int g_mirror_capture;
|
||||
extern volatile int g_display_buffer_driver;
|
||||
extern void droiddeck_on_overlay_planes(int planes);
|
||||
static int g_overlay_planes_told = -1;
|
||||
@@ -837,7 +827,6 @@ static void unmap_toplevel(struct surface *s) {
|
||||
}
|
||||
|
||||
static void drop_dmabuf(struct surface *s, int paced) {
|
||||
dd_frame_acquire_clear(&s->frame_acquire);
|
||||
if (s->dmabuf) {
|
||||
wl_list_remove(&s->dmabuf_destroy.link);
|
||||
if (buffer_shown_elsewhere(s->dmabuf, s)) {
|
||||
@@ -853,21 +842,18 @@ static void drop_dmabuf(struct surface *s, int paced) {
|
||||
|
||||
static void on_dmabuf_destroyed(struct wl_listener *l, void *data) {
|
||||
struct surface *s = wl_container_of(l, s, dmabuf_destroy);
|
||||
dd_frame_acquire_clear(&s->frame_acquire);
|
||||
wl_list_remove(&s->dmabuf_destroy.link);
|
||||
s->dmabuf = NULL;
|
||||
}
|
||||
|
||||
static void on_pending_buffer_destroyed(struct wl_listener *l, void *data) {
|
||||
struct surface *s = wl_container_of(l, s, pending_buffer_destroy);
|
||||
dd_frame_acquire_clear(&s->pending_frame_acquire);
|
||||
wl_list_remove(&s->pending_buffer_destroy.link);
|
||||
wl_list_init(&s->pending_buffer_destroy.link);
|
||||
s->pending_buffer = NULL;
|
||||
}
|
||||
|
||||
struct surface_state {
|
||||
struct dd_frame_acquire frame_acquire;
|
||||
struct wl_resource *buffer;
|
||||
struct wl_listener buffer_destroy;
|
||||
int attach;
|
||||
@@ -880,7 +866,6 @@ struct surface_state {
|
||||
|
||||
static void on_state_buffer_destroyed(struct wl_listener *l, void *data) {
|
||||
struct surface_state *st = wl_container_of(l, st, buffer_destroy);
|
||||
dd_frame_acquire_clear(&st->frame_acquire);
|
||||
wl_list_remove(&st->buffer_destroy.link);
|
||||
wl_list_init(&st->buffer_destroy.link);
|
||||
st->buffer = NULL;
|
||||
@@ -889,8 +874,6 @@ static void on_state_buffer_destroyed(struct wl_listener *l, void *data) {
|
||||
|
||||
static void surface_state_take(struct surface *s, struct surface_state *st) {
|
||||
st->attach = s->pending_attach;
|
||||
st->frame_acquire = s->pending_frame_acquire;
|
||||
s->pending_frame_acquire.fd_plus_one = 0;
|
||||
st->buffer = s->pending_buffer;
|
||||
wl_list_init(&st->buffer_destroy.link);
|
||||
if (st->buffer) {
|
||||
@@ -1203,7 +1186,6 @@ static void surface_attach(struct wl_client *c, struct wl_resource *r,
|
||||
if (s->pending_buffer) wl_list_remove(&s->pending_buffer_destroy.link);
|
||||
wl_list_init(&s->pending_buffer_destroy.link);
|
||||
s->pending_buffer = buffer;
|
||||
dd_frame_acquire_clear(&s->pending_frame_acquire);
|
||||
s->pending_attach = 1;
|
||||
if (buffer) {
|
||||
s->pending_buffer_destroy.notify = on_pending_buffer_destroyed;
|
||||
@@ -1469,7 +1451,6 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
|
||||
|
||||
surface_drop_idle(s);
|
||||
buf_trace_attach(buffer);
|
||||
dd_frame_acquire_clear(&s->frame_acquire);
|
||||
if (s->role == ROLE_CURSOR) {
|
||||
if (!buffer) {
|
||||
cursor_publish_hidden();
|
||||
@@ -1481,8 +1462,6 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
|
||||
if (buffer) surface_hold_idle(s, buffer);
|
||||
} else if (db) {
|
||||
take_dmabuf(s, db, buffer);
|
||||
s->frame_acquire = st->frame_acquire;
|
||||
st->frame_acquire.fd_plus_one = 0;
|
||||
} else if (shm) {
|
||||
drop_dmabuf(s, 1);
|
||||
take_shm(s, shm, buffer);
|
||||
@@ -1495,7 +1474,6 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
|
||||
if (buffer) send_buffer_release(buffer);
|
||||
}
|
||||
}
|
||||
dd_frame_acquire_clear(&st->frame_acquire);
|
||||
pending_releases_apply(s);
|
||||
|
||||
wl_list_for_each(child, &s->children, child_link) {
|
||||
@@ -1560,7 +1538,6 @@ static void settle_unwaited(void) {
|
||||
}
|
||||
|
||||
static void surface_state_discard(struct surface_state *st) {
|
||||
dd_frame_acquire_clear(&st->frame_acquire);
|
||||
struct wl_resource *cb, *tmp;
|
||||
wl_list_remove(&st->buffer_destroy.link);
|
||||
wl_resource_for_each_safe(cb, tmp, &st->frames) wl_resource_destroy(cb);
|
||||
@@ -1572,8 +1549,6 @@ static void surface_state_merge(struct surface_state *older, struct surface_stat
|
||||
if (older->attach && !newer->attach) {
|
||||
newer->attach = 1;
|
||||
newer->buffer = older->buffer;
|
||||
newer->frame_acquire = older->frame_acquire;
|
||||
older->frame_acquire.fd_plus_one = 0;
|
||||
wl_list_remove(&older->buffer_destroy.link);
|
||||
wl_list_init(&older->buffer_destroy.link);
|
||||
if (newer->buffer) {
|
||||
@@ -1725,210 +1700,6 @@ static const struct wl_surface_interface surface_impl = {
|
||||
.offset = surface_offset,
|
||||
};
|
||||
|
||||
int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b) {
|
||||
return s && s->dmabuf && s->dmabuf_buf == b ? dd_frame_acquire_dup(&s->frame_acquire) : -1;
|
||||
}
|
||||
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
// Private signed fixture: only the app-owned worker decision may issue a grant.
|
||||
static pthread_mutex_t frame_worker_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static char frame_worker_file[PATH_MAX];
|
||||
static struct dd_worker_grant frame_worker_grant;
|
||||
static int frame_worker_pidfd = -1;
|
||||
static bool frame_worker_map_reported;
|
||||
|
||||
static enum dd_worker_stat_result frame_worker_starttime(pid_t pid, uint64_t *out) {
|
||||
char proc[64], line[4096];
|
||||
snprintf(proc, sizeof(proc), "/proc/%d/stat", pid);
|
||||
FILE *f = fopen(proc, "re");
|
||||
if (!f) return dd_worker_open_failure(errno);
|
||||
// Proc writes one bounded line; truncation is a read failure, not invisibility.
|
||||
bool read = fgets(line, sizeof(line), f) != NULL && strchr(line, '\n') != NULL;
|
||||
fclose(f);
|
||||
return read ? dd_worker_parse_start(line, out) : DD_WORKER_STAT_READ;
|
||||
}
|
||||
|
||||
void droiddeck_frame_worker_revoke(int owner, int pid) {
|
||||
pthread_mutex_lock(&frame_worker_lock);
|
||||
if (frame_worker_grant.owner == (uint32_t)owner &&
|
||||
(!pid || frame_worker_grant.pid == (uint32_t)pid)) {
|
||||
if (frame_worker_pidfd >= 0) close(frame_worker_pidfd);
|
||||
frame_worker_pidfd = -1;
|
||||
frame_worker_grant = (struct dd_worker_grant){0};
|
||||
}
|
||||
pthread_mutex_unlock(&frame_worker_lock);
|
||||
}
|
||||
|
||||
int droiddeck_frame_worker_grant(int owner, pid_t pid, uint64_t expires, const char *path,
|
||||
uint64_t expected_dev, uint64_t expected_ino, uint64_t receipt) {
|
||||
struct stat st;
|
||||
if (owner <= 0 || pid <= 1 || !receipt || !path ||
|
||||
strlen(path) >= sizeof(frame_worker_file) || lstat(path, &st) < 0 || !S_ISREG(st.st_mode) ||
|
||||
(uint64_t)st.st_dev != expected_dev || (uint64_t)st.st_ino != expected_ino ||
|
||||
st.st_uid != getuid()) {
|
||||
droiddeck_log("probe", "worker_admission=NATIVE_FILE");
|
||||
return 0;
|
||||
}
|
||||
int pidfd = syscall(__NR_pidfd_open, pid, 0);
|
||||
if (pidfd < 0) {
|
||||
droiddeck_log("probe", "worker_admission=NATIVE_PIDFD");
|
||||
return 0; // No fallback to a recyclable PID.
|
||||
}
|
||||
struct pollfd alive = {.fd = pidfd, .events = POLLIN};
|
||||
uint64_t raw_start = 0;
|
||||
enum dd_worker_stat_result stat = frame_worker_starttime(pid, &raw_start);
|
||||
switch (stat) {
|
||||
case DD_WORKER_STAT_OK:
|
||||
if (raw_start != receipt) droiddeck_log("probe", "worker_admission=NATIVE_STAT_MISMATCH");
|
||||
break;
|
||||
case DD_WORKER_STAT_DENIED: droiddeck_log("probe", "worker_admission=NATIVE_STAT_OPEN_DENIED"); break;
|
||||
case DD_WORKER_STAT_HIDDEN: droiddeck_log("probe", "worker_admission=NATIVE_STAT_OPEN_HIDDEN"); break;
|
||||
case DD_WORKER_STAT_OPEN: droiddeck_log("probe", "worker_admission=NATIVE_STAT_OPEN_OTHER"); break;
|
||||
case DD_WORKER_STAT_READ: droiddeck_log("probe", "worker_admission=NATIVE_STAT_READ"); break;
|
||||
case DD_WORKER_STAT_PARSE: droiddeck_log("probe", "worker_admission=NATIVE_STAT_PARSE"); break;
|
||||
case DD_WORKER_STAT_ZERO: droiddeck_log("probe", "worker_admission=NATIVE_STAT_ZERO"); break;
|
||||
}
|
||||
if (!dd_worker_receipt_allows_reserve(stat, raw_start, receipt)) { close(pidfd); return 0; }
|
||||
if (poll(&alive, 1, 0) != 0) {
|
||||
droiddeck_log("probe", "worker_admission=NATIVE_PIDFD_NOT_LIVE");
|
||||
close(pidfd);
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_lock(&frame_worker_lock);
|
||||
if (frame_worker_pidfd < 0) {
|
||||
strcpy(frame_worker_file, path);
|
||||
frame_worker_grant = (struct dd_worker_grant){
|
||||
.owner = owner, .uid = getuid(), .pid = pid, .start_ticks = receipt, .expires = expires,
|
||||
.dev_major = major(st.st_dev), .dev_minor = minor(st.st_dev), .ino = st.st_ino,
|
||||
.canonical_file = frame_worker_file, .app_launch_verified = true, .final_go = true,
|
||||
};
|
||||
frame_worker_map_reported = false;
|
||||
frame_worker_pidfd = pidfd;
|
||||
pidfd = -1;
|
||||
}
|
||||
pthread_mutex_unlock(&frame_worker_lock);
|
||||
if (pidfd >= 0) {
|
||||
droiddeck_log("probe", "worker_admission=NATIVE_ALREADY_RESERVED");
|
||||
close(pidfd);
|
||||
return 0;
|
||||
}
|
||||
droiddeck_log("probe", "frame acquire reserved one app-verified worker");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool frame_worker_verified_exec_locked(const struct dd_worker_grant *g, uint64_t now) {
|
||||
char proc[64], line[PATH_MAX + 128];
|
||||
const char *failure = "worker_admission=MAP_STARTTIME";
|
||||
uint64_t raw_start = 0;
|
||||
if (frame_worker_starttime(g->pid, &raw_start) != DD_WORKER_STAT_OK || raw_start != g->start_ticks)
|
||||
goto reject;
|
||||
snprintf(proc, sizeof(proc), "/proc/%u/maps", g->pid);
|
||||
FILE *f = fopen(proc, "re");
|
||||
failure = "worker_admission=MAP_OPEN";
|
||||
if (!f) goto reject;
|
||||
bool matched = false;
|
||||
size_t budget = 2 * 1024 * 1024;
|
||||
while (budget && fgets(line, sizeof(line), f)) {
|
||||
size_t n = strlen(line);
|
||||
if (!n || line[n - 1] != '\n' || n > budget) break;
|
||||
budget -= n;
|
||||
if (dd_worker_grant_matches(g, g->owner, g->uid, g->pid, raw_start, now, line)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
if (matched) return true;
|
||||
failure = "worker_admission=MAP_IDENTITY";
|
||||
reject:
|
||||
if (!frame_worker_map_reported) {
|
||||
frame_worker_map_reported = true;
|
||||
droiddeck_log("probe", "%s", failure);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int frame_acquire_peer_allowed(const struct wl_client *client, bool verify_exec, bool bind) {
|
||||
pid_t pid = 0;
|
||||
uid_t uid = (uid_t)-1;
|
||||
wl_client_get_credentials(client, &pid, &uid, NULL);
|
||||
struct timespec t;
|
||||
if (clock_gettime(CLOCK_BOOTTIME, &t) < 0) return 0;
|
||||
uint64_t now = (uint64_t)t.tv_sec * 1000 + (uint64_t)t.tv_nsec / 1000000;
|
||||
pthread_mutex_lock(&frame_worker_lock);
|
||||
const struct dd_worker_grant *g = &frame_worker_grant;
|
||||
struct pollfd alive = {.fd = frame_worker_pidfd, .events = POLLIN};
|
||||
bool allowed = frame_worker_pidfd >= 0 && uid == getuid() && pid > 1 &&
|
||||
g->pid == (uint32_t)pid && g->uid == uid && now < g->expires &&
|
||||
poll(&alive, 1, 0) == 0 && (!verify_exec ||
|
||||
(frame_worker_verified_exec_locked(g, now) && poll(&alive, 1, 0) == 0));
|
||||
// The short startup authorization may not be renewed by registry enumeration.
|
||||
// Only an authenticated bind activates the grant for the lifetime of this live,
|
||||
// unreplaced worker; session teardown revokes it independently of process exit.
|
||||
if (allowed && bind) frame_worker_grant.expires = UINT64_MAX;
|
||||
pthread_mutex_unlock(&frame_worker_lock);
|
||||
return allowed;
|
||||
}
|
||||
|
||||
static bool frame_acquire_global_filter(const struct wl_client *client, const struct wl_global *global, void *data) {
|
||||
return wl_global_get_interface(global) != &droiddeck_frame_acquire_v1_interface ||
|
||||
frame_acquire_peer_allowed(client, true, false);
|
||||
}
|
||||
|
||||
static void frame_acquire_destroy(struct wl_client *client, struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void frame_acquire_set(struct wl_client *client, struct wl_resource *resource,
|
||||
struct wl_resource *surface, struct wl_resource *buffer, int32_t fd) {
|
||||
if (!frame_acquire_peer_allowed(client, false, false)) {
|
||||
close(fd);
|
||||
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_UNAUTHORIZED_PEER,
|
||||
"paired capture peer is not authorized");
|
||||
return;
|
||||
}
|
||||
struct surface *s = NULL;
|
||||
if (surface && buffer && wl_resource_get_client(surface) == client &&
|
||||
wl_resource_get_client(buffer) == client &&
|
||||
wl_resource_instance_of(surface, &wl_surface_interface, &surface_impl) &&
|
||||
get_dmabuf(buffer))
|
||||
s = wl_resource_get_user_data(surface);
|
||||
if (!s || !s->pending_attach || s->pending_buffer != buffer) {
|
||||
close(fd);
|
||||
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_ATTACHMENT,
|
||||
"fence does not match pending DMA-BUF attachment");
|
||||
return;
|
||||
}
|
||||
enum dd_frame_acquire_result result = dd_frame_acquire_set(&s->pending_frame_acquire, fd);
|
||||
if (result == DD_ACQUIRE_DUPLICATE)
|
||||
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_DUPLICATE_FENCE,
|
||||
"pending attachment already has a fence");
|
||||
else if (result == DD_ACQUIRE_INVALID)
|
||||
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_FENCE,
|
||||
"expected an already signaled Linux sync_file");
|
||||
}
|
||||
|
||||
static const struct droiddeck_frame_acquire_v1_interface frame_acquire_impl = {
|
||||
.destroy = frame_acquire_destroy,
|
||||
.set_acquire_fence = frame_acquire_set,
|
||||
};
|
||||
|
||||
static void bind_frame_acquire(struct wl_client *client, void *data, uint32_t version, uint32_t id) {
|
||||
if (!frame_acquire_peer_allowed(client, true, true)) {
|
||||
wl_client_post_implementation_error(client, "paired capture peer is not authorized");
|
||||
return;
|
||||
}
|
||||
struct wl_resource *resource =
|
||||
wl_resource_create(client, &droiddeck_frame_acquire_v1_interface, 1, id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &frame_acquire_impl, NULL, NULL);
|
||||
droiddeck_log("probe", "frame acquire bound to app-issued worker and exact executable map");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void detach_from_parent(struct surface *s) {
|
||||
if (!s->parent) return;
|
||||
wl_list_remove(&s->child_link);
|
||||
@@ -1938,7 +1709,6 @@ static void detach_from_parent(struct surface *s) {
|
||||
|
||||
static void surface_resource_destroy(struct wl_resource *r) {
|
||||
struct surface *s = wl_resource_get_user_data(r);
|
||||
dd_frame_acquire_clear(&s->pending_frame_acquire);
|
||||
struct surface *child, *tmp;
|
||||
struct wl_resource *cb, *cbtmp;
|
||||
|
||||
@@ -2962,7 +2732,7 @@ static void hdr_note_route(int route, const struct hdr_scene *hs) {
|
||||
static int said = -1, said_tm = -1;
|
||||
static const char *said_why;
|
||||
const int tm = route != 0 && !droiddeck_color_output();
|
||||
if (route == said && tm == said_tm && (route < 1 || route > 2 || hs->why == said_why)) return;
|
||||
if (route == said && tm == said_tm && (route != 1 || hs->why == said_why)) return;
|
||||
int was = said;
|
||||
said = route; said_why = hs->why; said_tm = tm;
|
||||
char name[160] = "the HDR game";
|
||||
@@ -2979,10 +2749,6 @@ static void hdr_note_route(int route, const struct hdr_scene *hs) {
|
||||
"BT2020_PQ", name, hs->why ? hs->why : "?", droiddeck_color_sdr_white());
|
||||
break;
|
||||
case 2:
|
||||
if (g_mirror_capture) {
|
||||
droiddeck_log("color", "Mirror: %s is composed through the screen swapchain", name);
|
||||
break;
|
||||
}
|
||||
if (tm)
|
||||
droiddeck_log("color", "HDR with frame generation for %s, HDR output switched off: the scene is tone-mapped to "
|
||||
"SDR and presented through an SDR screen swapchain", name);
|
||||
@@ -3203,11 +2969,6 @@ static void render_scene(void) {
|
||||
const int cardboard = vkp_cardboard_active();
|
||||
struct hdr_scene hs;
|
||||
int hdr_route = hdr_plan(&dl, w, h, fx_on, framegen, &hs);
|
||||
/* Mirror's PixelCopy cannot see the separate game layer. Keep unimportable frames visible on top. */
|
||||
if (g_mirror_capture && hdr_route != 3 && hs.n_hdr > 0) {
|
||||
hdr_route = 2;
|
||||
hs.why = "Mirror needs the screen swapchain";
|
||||
}
|
||||
const char *hdr_copy = NULL;
|
||||
if (droiddeck_color_hdr_open()) {
|
||||
hdr_note_route(hdr_route, &hs);
|
||||
@@ -3273,16 +3034,16 @@ static void render_scene(void) {
|
||||
else if (rendered && how == 2) droiddeck_color_frame_shown(hs.color, DROIDDECK_HDR_TONEMAPPED, 0);
|
||||
else if (rendered) hdr_copy = "the HDR composition pass is unavailable on this driver";
|
||||
}
|
||||
if (hdr_route == 0 && !g_mirror_capture && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on &&
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on &&
|
||||
!ahb_only) {
|
||||
settle_unwaited();
|
||||
rendered = vkp_render(w, h, dl.d, dl.n) == 0;
|
||||
} else if (hdr_route == 0 || hdr_route == 3) {
|
||||
const int pass_on = fx_on || framegen;
|
||||
tell_overlay_planes();
|
||||
const int fg_layer = framegen && !g_mirror_capture && hdr_route == 0 && framegen_fits_layer();
|
||||
const int fg_layer = framegen && hdr_route == 0 && framegen_fits_layer();
|
||||
g_framegen_layer = fg_layer;
|
||||
int li = (g_zero_copy && !g_mirror_capture && (!framegen || fg_layer) && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1;
|
||||
int li = (g_zero_copy && (!framegen || fg_layer) && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1;
|
||||
int over = li >= 0 ? dl.n - 1 - li : 0;
|
||||
const int fx_blocks = (li >= 0 && fx_on && over > 0);
|
||||
if (fx_blocks) { li = -1; over = 0; }
|
||||
@@ -5012,12 +4773,6 @@ const char *droiddeck_client_name(struct wl_client *client) { return client_name
|
||||
struct wl_display *droiddeck_get_display(void) { return g_display; }
|
||||
void droiddeck_request_redraw(void) { schedule_render(); }
|
||||
|
||||
void droiddeck_set_mirror_capture(int on) {
|
||||
if (g_mirror_capture == on) return;
|
||||
g_mirror_capture = on;
|
||||
schedule_render();
|
||||
}
|
||||
|
||||
struct wl_resource *droiddeck_ime_target(void) {
|
||||
struct surface *s;
|
||||
if (g_ime_click && g_ime_click->mapped) return g_ime_click->resource;
|
||||
@@ -5049,7 +4804,6 @@ static int on_stats_timer(void *data) {
|
||||
struct surface *s;
|
||||
wl_list_for_each(s, &g_toplevels, toplevel_link) windows++;
|
||||
unsigned zero_copy = ahb_swapchain_stats_take();
|
||||
unsigned verified = ahb_swapchain_producer_fence_stats_take();
|
||||
unsigned layer_frames = sc_layer_frames_take();
|
||||
g_zero_copy_last = zero_copy;
|
||||
unsigned generated = vkp_framegen_stats_take();
|
||||
@@ -5058,8 +4812,7 @@ static int on_stats_timer(void *data) {
|
||||
int off = 0;
|
||||
if (g_zero_copy || zero_copy) off += snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u zero-copy frames", zero_copy);
|
||||
if (layer_frames) off += snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u layer frames", layer_frames);
|
||||
if (generated) off += snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u generated frames", generated);
|
||||
if (verified) snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u verified acquire frames", verified);
|
||||
if (generated) snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u generated frames", generated);
|
||||
droiddeck_log("stats", "last 10 s: %u frames on screen (%.1f fps) | %u GPU frames from games | %u window redraws | %d windows open%s",
|
||||
g_stat_frames + generated, (g_stat_frames + generated) / 10.0, g_stat_dmabuf, g_stat_shm, windows, extra);
|
||||
}
|
||||
@@ -5260,12 +5013,6 @@ int droiddeck_wayland_run(void) {
|
||||
wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, 1, NULL, bind_relative_pointer_manager);
|
||||
droiddeck_ext_init(display);
|
||||
ahb_swapchain_init(display);
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
if (ahb_swapchain_advertised()) {
|
||||
wl_display_set_global_filter(display, frame_acquire_global_filter, NULL);
|
||||
wl_global_create(display, &droiddeck_frame_acquire_v1_interface, 1, NULL, bind_frame_acquire);
|
||||
}
|
||||
#endif
|
||||
display_buffers_init(display);
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ahb_swapchain.h"
|
||||
#include "droiddeck_color.h"
|
||||
|
||||
enum host_kind { HOST_CLIPBOARD = 1, HOST_TEXT_COMMIT, HOST_TEXT_PREEDIT, HOST_TEXT_DELETE, HOST_ZERO_COPY, HOST_HDR_OUTPUT, HOST_KEY, HOST_SELECT_GAME_FIELD, HOST_MIRROR_CAPTURE };
|
||||
enum host_kind { HOST_CLIPBOARD = 1, HOST_TEXT_COMMIT, HOST_TEXT_PREEDIT, HOST_TEXT_DELETE, HOST_ZERO_COPY, HOST_HDR_OUTPUT, HOST_KEY, HOST_SELECT_GAME_FIELD };
|
||||
|
||||
struct host_msg {
|
||||
enum host_kind kind;
|
||||
@@ -91,9 +91,6 @@ void droiddeck_host_text_delete(int before, int after) {
|
||||
void droiddeck_host_zero_copy(int on, int live) {
|
||||
host_post(HOST_ZERO_COPY, NULL, 0, on, live);
|
||||
}
|
||||
void droiddeck_host_mirror_capture(int on) {
|
||||
host_post(HOST_MIRROR_CAPTURE, NULL, 0, on, 0);
|
||||
}
|
||||
void droiddeck_host_hdr_output(int on) {
|
||||
host_post(HOST_HDR_OUTPUT, NULL, 0, on, 0);
|
||||
}
|
||||
@@ -274,9 +271,6 @@ static int on_wake(int fd, uint32_t mask, void *data) {
|
||||
case HOST_ZERO_COPY:
|
||||
ahb_swapchain_set_mode(m->a, m->b);
|
||||
break;
|
||||
case HOST_MIRROR_CAPTURE:
|
||||
droiddeck_set_mirror_capture(m->a);
|
||||
break;
|
||||
case HOST_HDR_OUTPUT:
|
||||
droiddeck_color_set_output(m->a);
|
||||
break;
|
||||
|
||||
@@ -29,8 +29,6 @@ void droiddeck_host_text_commit_and_submit(const char *utf8, int len);
|
||||
void droiddeck_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end);
|
||||
void droiddeck_host_text_delete(int before, int after);
|
||||
void droiddeck_host_zero_copy(int on, int live);
|
||||
void droiddeck_host_mirror_capture(int on);
|
||||
void droiddeck_set_mirror_capture(int on);
|
||||
void droiddeck_host_hdr_output(int on);
|
||||
void droiddeck_host_key(int evdev, int state);
|
||||
void droiddeck_host_select_game_field(int copy);
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "smaa_edge_frag.h"
|
||||
#include "smaa_weights_frag.h"
|
||||
#include "smaa_blend_frag.h"
|
||||
#include "smaa_tables.h"
|
||||
#include "toon_frag.h"
|
||||
#include "toon_color_frag.h"
|
||||
#include "hdr_frag.h"
|
||||
@@ -197,7 +196,6 @@ struct pc_sgsr { float ndc[4]; float vp[4]; float edge; };
|
||||
struct pc_easu { float ndc[4]; uint32_t con0[4], con1[4], con2[4], con3[4]; float outW, outH; };
|
||||
struct pc_rcas { float ndc[4]; uint32_t con[4]; float outW, outH; };
|
||||
struct pc_res { float ndc[4]; float res[2]; float extra; float pad; };
|
||||
struct pc_smaa { float ndc[4]; float metrics[4]; };
|
||||
struct pc_color { float ndc[4]; float b, c, g, s; };
|
||||
struct pc_toon_color {
|
||||
float ndc[4]; float res[2]; float b, c, g, s;
|
||||
@@ -232,7 +230,7 @@ static VkDevice g_dev;
|
||||
static VkPhysicalDevice g_pd;
|
||||
static VkPhysicalDeviceMemoryProperties g_mp;
|
||||
static int g_ready;
|
||||
static VkRenderPass g_rp, g_smaa_edge_rp, g_smaa_weights_rp;
|
||||
static VkRenderPass g_rp, g_smaa_rp;
|
||||
static VkDescriptorSetLayout g_dsl;
|
||||
static VkPipelineLayout g_pl;
|
||||
static VkDescriptorPool g_dpool;
|
||||
@@ -249,9 +247,7 @@ static int g_context;
|
||||
#define g_t (g_contexts[g_context].targets)
|
||||
#define g_mid (g_contexts[g_context].mid)
|
||||
#define g_nissrc (g_contexts[g_context].nissrc)
|
||||
static struct fx_target g_smaa_edges, g_smaa_weights, g_smaa_area, g_smaa_search;
|
||||
static VkBuffer g_smaa_buf;
|
||||
static VkDeviceMemory g_smaa_mem;
|
||||
static struct fx_target g_smaa_edges, g_smaa_weights;
|
||||
/* Half set: NIS = nis_luma prepass (scene rgb + luma in alpha, scene size) into g_nissrc, then
|
||||
* nis3 gathers its luma from that alpha, its coefficient banks (nis_coef.h) in a uniform buffer
|
||||
* at descriptor set 1 (g_pl_nis = {g_dsl, g_coef_dsl}, same push-constant range as g_pl).
|
||||
@@ -315,7 +311,6 @@ static void target_destroy(struct fx_target *t) {
|
||||
#define FX_TARGET_USAGE (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | \
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)
|
||||
#define FX_SCRATCH_USAGE (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)
|
||||
#define SMAA_EDGE_FORMAT VK_FORMAT_R8G8_UNORM
|
||||
|
||||
static int target_ensure_format(struct fx_target *t, int w, int h,
|
||||
VkImageUsageFlags usage, const char *what,
|
||||
@@ -323,9 +318,8 @@ static int target_ensure_format(struct fx_target *t, int w, int h,
|
||||
if (t->img && t->w == w && t->h == h) return 0;
|
||||
target_destroy(t);
|
||||
VkImageCreateInfo ii = {.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||
/* SMAA's own images need no views in other formats, and the GPU is faster without the flag. */
|
||||
.flags = render_pass == g_rp ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0,
|
||||
.imageType = VK_IMAGE_TYPE_2D, .format = format, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1,
|
||||
.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, .imageType = VK_IMAGE_TYPE_2D,
|
||||
.format = format, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1,
|
||||
.arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = usage,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
|
||||
@@ -343,16 +337,12 @@ static int target_ensure_format(struct fx_target *t, int w, int h,
|
||||
(unsigned long long)req.size, (int)r);
|
||||
target_destroy(t); return -1;
|
||||
}
|
||||
r = g_vk.BindImageMemory(g_dev, t->img, t->mem, 0);
|
||||
if (r != VK_SUCCESS) {
|
||||
droiddeck_log("error", "effects: %s image %dx%d: vkBindImageMemory %d", what, w, h, (int)r);
|
||||
target_destroy(t); return -1;
|
||||
}
|
||||
g_vk.BindImageMemory(g_dev, t->img, t->mem, 0);
|
||||
if (!(t->view = make_view(t->img, format))) { target_destroy(t); return -1; }
|
||||
VkFramebufferCreateInfo fi = {.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .renderPass = render_pass,
|
||||
.attachmentCount = 1, .pAttachments = &t->view, .width = (uint32_t)w,
|
||||
.height = (uint32_t)h, .layers = 1};
|
||||
if (render_pass && g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; }
|
||||
if (g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; }
|
||||
if (!(t->ds = alloc_ds(t->view))) { target_destroy(t); return -1; }
|
||||
t->w = w; t->h = h;
|
||||
return 0;
|
||||
@@ -376,44 +366,6 @@ void vkp_effects_forget_image(VkImage img) {
|
||||
g_context = saved;
|
||||
}
|
||||
|
||||
VkImageView vkp_effects_framegen_image_view(VkImage img, int w, int h, VkFormat fmt) {
|
||||
if (!g_dev || !img || w <= 0 || h <= 0 || fmt == VK_FORMAT_UNDEFINED) return VK_NULL_HANDLE;
|
||||
|
||||
for (int i = 0; i < FX_CONTEXTS; ++i) {
|
||||
struct fx_context *ctx = &g_contexts[i];
|
||||
if (ctx->scene.img == img && ctx->scene.view) return ctx->scene.view;
|
||||
for (int j = 0; j < 2; ++j)
|
||||
if (ctx->targets[j].img == img && ctx->targets[j].view) return ctx->targets[j].view;
|
||||
if (ctx->mid.img == img && ctx->mid.view) return ctx->mid.view;
|
||||
if (ctx->nissrc.img == img && ctx->nissrc.view) return ctx->nissrc.view;
|
||||
}
|
||||
if (g_smaa_edges.img == img && g_smaa_edges.view) return g_smaa_edges.view;
|
||||
if (g_smaa_weights.img == img && g_smaa_weights.view) return g_smaa_weights.view;
|
||||
|
||||
/* The effects chain can bypass every pass and return the compositor's scene image
|
||||
* directly. Keep a view for that image in the existing per-context cache so the
|
||||
* normal image-forget path destroys it before the image itself. */
|
||||
int saved = g_context;
|
||||
g_context = 0;
|
||||
if (g_scene.img != img || g_scene.view == VK_NULL_HANDLE ||
|
||||
g_scene.w != w || g_scene.h != h) {
|
||||
scene_release();
|
||||
VkImageView view = make_view(img, fmt);
|
||||
if (!view) {
|
||||
g_context = saved;
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
g_scene.img = img;
|
||||
g_scene.view = view;
|
||||
g_scene.w = w;
|
||||
g_scene.h = h;
|
||||
g_scene.ds = VK_NULL_HANDLE;
|
||||
}
|
||||
VkImageView result = g_scene.view;
|
||||
g_context = saved;
|
||||
return result;
|
||||
}
|
||||
|
||||
void vkp_effects_release_generated_sources(void) {
|
||||
for (g_context = 1; g_context < FX_CONTEXTS; g_context++) scene_release();
|
||||
g_context = 0;
|
||||
@@ -471,22 +423,6 @@ static VkPipeline post_pipeline_for_renderpass(VkShaderModule vert,
|
||||
return p;
|
||||
}
|
||||
|
||||
/* The mapped memory of a new host-visible buffer. On failure: NULL, and the caller frees what there is. */
|
||||
static void *host_buffer(VkDeviceSize size, VkBufferUsageFlags usage, VkBuffer *buf, VkDeviceMemory *mem) {
|
||||
VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = size,
|
||||
.usage = usage, .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
||||
if (g_vk.CreateBuffer(g_dev, &bci, NULL, buf) != VK_SUCCESS) return NULL;
|
||||
VkMemoryRequirements req;
|
||||
g_vk.GetBufferMemoryRequirements(g_dev, *buf, &req);
|
||||
int idx = memtype(req.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
if (idx < 0) return NULL;
|
||||
VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx};
|
||||
if (g_vk.AllocateMemory(g_dev, &mai, NULL, mem) != VK_SUCCESS) return NULL;
|
||||
if (g_vk.BindBufferMemory(g_dev, *buf, *mem, 0) != VK_SUCCESS) return NULL;
|
||||
void *p = NULL;
|
||||
return g_vk.MapMemory(g_dev, *mem, 0, size, 0, &p) == VK_SUCCESS ? p : NULL;
|
||||
}
|
||||
|
||||
static void coef_destroy(void) {
|
||||
if (g_coef_pool) g_vk.DestroyDescriptorPool(g_dev, g_coef_pool, NULL); /* frees g_coef_ds */
|
||||
if (g_coef_buf) g_vk.DestroyBuffer(g_dev, g_coef_buf, NULL);
|
||||
@@ -508,8 +444,18 @@ static int coef_create(void) {
|
||||
VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = sets,
|
||||
.pushConstantRangeCount = 1, .pPushConstantRanges = &pcr};
|
||||
if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl_nis) != VK_SUCCESS) goto fail;
|
||||
void *p = host_buffer(4096, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, &g_coef_buf, &g_coef_mem);
|
||||
if (!p) goto fail;
|
||||
VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = 4096,
|
||||
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
||||
if (g_vk.CreateBuffer(g_dev, &bci, NULL, &g_coef_buf) != VK_SUCCESS) goto fail;
|
||||
VkMemoryRequirements req;
|
||||
g_vk.GetBufferMemoryRequirements(g_dev, g_coef_buf, &req);
|
||||
int idx = memtype(req.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
if (idx < 0) goto fail;
|
||||
VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx};
|
||||
if (g_vk.AllocateMemory(g_dev, &mai, NULL, &g_coef_mem) != VK_SUCCESS) goto fail;
|
||||
if (g_vk.BindBufferMemory(g_dev, g_coef_buf, g_coef_mem, 0) != VK_SUCCESS) goto fail;
|
||||
void *p = NULL;
|
||||
if (g_vk.MapMemory(g_dev, g_coef_mem, 0, 4096, 0, &p) != VK_SUCCESS || !p) goto fail;
|
||||
memcpy(p, kNisCoefScale, sizeof(kNisCoefScale));
|
||||
memcpy((char *)p + sizeof(kNisCoefScale), kNisCoefUsm, sizeof(kNisCoefUsm));
|
||||
g_vk.UnmapMemory(g_dev, g_coef_mem);
|
||||
@@ -529,29 +475,6 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void smaa_tables_destroy(void) {
|
||||
target_destroy(&g_smaa_area); target_destroy(&g_smaa_search);
|
||||
if (g_smaa_buf) g_vk.DestroyBuffer(g_dev, g_smaa_buf, NULL);
|
||||
if (g_smaa_mem) g_vk.FreeMemory(g_dev, g_smaa_mem, NULL);
|
||||
g_smaa_buf = VK_NULL_HANDLE; g_smaa_mem = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
static int smaa_tables_ensure(void) {
|
||||
if (g_smaa_buf) return 0;
|
||||
const VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
unsigned char *p = NULL;
|
||||
if (target_ensure_format(&g_smaa_area, SMAA_AREA_W, SMAA_AREA_H, usage, "SMAA area table",
|
||||
VK_FORMAT_R8G8_UNORM, VK_NULL_HANDLE) == 0 &&
|
||||
target_ensure_format(&g_smaa_search, SMAA_SEARCH_W, SMAA_SEARCH_H, usage, "SMAA search table",
|
||||
VK_FORMAT_R8_UNORM, VK_NULL_HANDLE) == 0)
|
||||
p = host_buffer(sizeof(kSmaaArea) + sizeof(kSmaaSearch), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &g_smaa_buf, &g_smaa_mem);
|
||||
if (!p) { smaa_tables_destroy(); return -1; }
|
||||
memcpy(p, kSmaaArea, sizeof(kSmaaArea));
|
||||
memcpy(p + sizeof(kSmaaArea), kSmaaSearch, sizeof(kSmaaSearch));
|
||||
g_vk.UnmapMemory(g_dev, g_smaa_mem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* nis_luma keeps luma in the target's alpha: only formats with at least 8 alpha bits (not the
|
||||
* 2-bit alpha of the 10-bit HDR composition format) can hold it. */
|
||||
static int fx_alpha_holds_luma(VkFormat f) {
|
||||
@@ -579,19 +502,16 @@ static void objects_destroy(void) {
|
||||
}
|
||||
g_context = saved;
|
||||
target_destroy(&g_smaa_edges); target_destroy(&g_smaa_weights);
|
||||
smaa_tables_destroy();
|
||||
for (int i = 0; i < P_COUNT; i++) { if (g_pipe[i]) g_vk.DestroyPipeline(g_dev, g_pipe[i], NULL); g_pipe[i] = VK_NULL_HANDLE; }
|
||||
if (g_dpool) g_vk.DestroyDescriptorPool(g_dev, g_dpool, NULL);
|
||||
if (g_pl) g_vk.DestroyPipelineLayout(g_dev, g_pl, NULL);
|
||||
coef_destroy();
|
||||
if (g_dsl) g_vk.DestroyDescriptorSetLayout(g_dev, g_dsl, NULL);
|
||||
if (g_sampler) g_vk.DestroySampler(g_dev, g_sampler, NULL);
|
||||
if (g_smaa_edge_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_edge_rp, NULL);
|
||||
if (g_smaa_weights_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_weights_rp, NULL);
|
||||
if (g_smaa_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_rp, NULL);
|
||||
if (g_rp) g_vk.DestroyRenderPass(g_dev, g_rp, NULL);
|
||||
g_dpool = VK_NULL_HANDLE; g_pl = VK_NULL_HANDLE; g_dsl = VK_NULL_HANDLE;
|
||||
g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE;
|
||||
g_smaa_edge_rp = VK_NULL_HANDLE; g_smaa_weights_rp = VK_NULL_HANDLE;
|
||||
g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE; g_smaa_rp = VK_NULL_HANDLE;
|
||||
g_nis_fast = 0; g_nis_attempted = 0; g_upscale_half = 0;
|
||||
g_ready = 0;
|
||||
}
|
||||
@@ -645,12 +565,9 @@ static int objects_ensure(void) {
|
||||
|
||||
VkAttachmentDescription smaa_att = att;
|
||||
smaa_att.format = FX_FORMAT;
|
||||
smaa_att.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; /* SMAA.hlsl discards pixels without an edge */
|
||||
VkRenderPassCreateInfo smaa_rci = rci;
|
||||
smaa_rci.pAttachments = &smaa_att;
|
||||
if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_weights_rp) != VK_SUCCESS) goto fail;
|
||||
smaa_att.format = SMAA_EDGE_FORMAT;
|
||||
if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_edge_rp) != VK_SUCCESS) goto fail;
|
||||
if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_rp) != VK_SUCCESS) goto fail;
|
||||
|
||||
VkSamplerCreateInfo sci = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .magFilter = VK_FILTER_LINEAR,
|
||||
.minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||
@@ -664,13 +581,13 @@ static int objects_ensure(void) {
|
||||
VkDescriptorSetLayoutCreateInfo dli = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .bindingCount = 1, .pBindings = &b};
|
||||
if (g_vk.CreateDescriptorSetLayout(g_dev, &dli, NULL, &g_dsl) != VK_SUCCESS) goto fail;
|
||||
VkPushConstantRange pcr = {.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, .offset = 0, .size = PC_MAX_SIZE};
|
||||
VkDescriptorSetLayout set_layouts[3] = {g_dsl, g_dsl, g_dsl};
|
||||
VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 3, .pSetLayouts = set_layouts,
|
||||
VkDescriptorSetLayout set_layouts[2] = {g_dsl, g_dsl};
|
||||
VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = set_layouts,
|
||||
.pushConstantRangeCount = 1, .pPushConstantRanges = &pcr};
|
||||
if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl) != VK_SUCCESS) goto fail;
|
||||
VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 4};
|
||||
VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 2};
|
||||
VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 4,
|
||||
.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 2,
|
||||
.poolSizeCount = 1, .pPoolSizes = &ps};
|
||||
if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail;
|
||||
|
||||
@@ -757,8 +674,8 @@ static int pipelines_ensure(int spatial, const struct fx_settings *s) {
|
||||
if (s->color_on && !(s->toon && g_fx_fmt == FX_FORMAT)) MK(1, P_COLOR, color_code, "color");
|
||||
if (s->aa_mode == 1 || s->aa_mode == 2) MK(1, P_FXAA, fxaa_code, "fxaa");
|
||||
if (s->aa_mode == 2) {
|
||||
MKL(1, P_SMAA_EDGE, smaa_edge_code, "smaa_edge", g_smaa_edge_rp, g_pl);
|
||||
MKL(1, P_SMAA_WEIGHTS, smaa_weights_code, "smaa_weights", g_smaa_weights_rp, g_pl);
|
||||
MKL(1, P_SMAA_EDGE, smaa_edge_code, "smaa_edge", g_smaa_rp, g_pl);
|
||||
MKL(1, P_SMAA_WEIGHTS, smaa_weights_code, "smaa_weights", g_smaa_rp, g_pl);
|
||||
MK(1, P_SMAA_BLEND, smaa_blend_code, "smaa_blend");
|
||||
}
|
||||
if (s->toon && s->color_on && g_fx_fmt == FX_FORMAT) MK(1, P_TOON_COLOR, toon_color_code, "toon_color");
|
||||
@@ -787,32 +704,14 @@ static void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImag
|
||||
g_vk.CmdPipelineBarrier(cmd, src_stage, dst_stage, 0, 0, NULL, 0, NULL, 1, &b);
|
||||
}
|
||||
|
||||
/* The tables are copied into place in every frame: a recorded frame can be dropped before it is submitted. */
|
||||
static void smaa_tables_copy(VkCommandBuffer cmd) {
|
||||
const VkBufferImageCopy area = {.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageExtent = {SMAA_AREA_W, SMAA_AREA_ROWS, 1}};
|
||||
const VkBufferImageCopy search = {.bufferOffset = sizeof(kSmaaArea), .imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageExtent = {SMAA_SEARCH_W, SMAA_SEARCH_H, 1}};
|
||||
const struct { VkImage img; const VkBufferImageCopy *copy; } t[2] = {{g_smaa_area.img, &area}, {g_smaa_search.img, &search}};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
barrier(cmd, t[i].img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
g_vk.CmdCopyBufferToImage(cmd, g_smaa_buf, t[i].img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, t[i].copy);
|
||||
barrier(cmd, t[i].img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void pass_sets(VkCommandBuffer cmd, VkRenderPass render_pass, VkPipeline p, struct fx_target *dst,
|
||||
const VkDescriptorSet *src, uint32_t count, const void *pc, uint32_t pcsz) {
|
||||
const VkClearValue clear = {0};
|
||||
static void pass_renderpass(VkCommandBuffer cmd, VkRenderPass render_pass,
|
||||
VkPipeline p, struct fx_target *dst, VkDescriptorSet src,
|
||||
const void *pc, uint32_t pcsz) {
|
||||
VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = render_pass, .framebuffer = dst->fb,
|
||||
.renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}},
|
||||
.clearValueCount = 1, .pClearValues = &clear};
|
||||
.renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}};
|
||||
g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE);
|
||||
g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p);
|
||||
g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, count, src, 0, NULL);
|
||||
g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 1, &src, 0, NULL);
|
||||
if (g_nis_fast && p == g_pipe[P_NIS] && g_coef_ds) /* nis3: coefficient banks at set 1 */
|
||||
g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl_nis, 1, 1, &g_coef_ds, 0, NULL);
|
||||
g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, pcsz, pc);
|
||||
@@ -822,7 +721,21 @@ static void pass_sets(VkCommandBuffer cmd, VkRenderPass render_pass, VkPipeline
|
||||
|
||||
static void pass(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst,
|
||||
VkDescriptorSet src, const void *pc, uint32_t pcsz) {
|
||||
pass_sets(cmd, g_rp, p, dst, &src, 1, pc, pcsz);
|
||||
pass_renderpass(cmd, g_rp, p, dst, src, pc, pcsz);
|
||||
}
|
||||
|
||||
static void pass_dual(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst,
|
||||
VkDescriptorSet src, VkDescriptorSet second,
|
||||
const void *pc, uint32_t pcsz) {
|
||||
VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_rp, .framebuffer = dst->fb,
|
||||
.renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}};
|
||||
VkDescriptorSet sets[2] = {src, second};
|
||||
g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE);
|
||||
g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p);
|
||||
g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 2, sets, 0, NULL);
|
||||
g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, pcsz, pc);
|
||||
g_vk.CmdDraw(cmd, 4, 1, 0, 0);
|
||||
g_vk.CmdEndRenderPass(cmd);
|
||||
}
|
||||
|
||||
static const float FULL_NDC[4] = {-1.0f, -1.0f, 1.0f, 1.0f};
|
||||
@@ -834,12 +747,6 @@ struct fx_source_state {
|
||||
VkAccessFlags access;
|
||||
};
|
||||
|
||||
/* NIS here is the SDR implementation and is documented for <=2x upscales: other outputs run FSR instead. */
|
||||
static int nis_falls_back(int scene_w, int scene_h, int cw, int ch) {
|
||||
return g_scene_is_pq || cw < scene_w || ch < scene_h || (double)cw > (double)scene_w * 2.0 ||
|
||||
(double)ch > (double)scene_h * 2.0;
|
||||
}
|
||||
|
||||
static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h,
|
||||
VkImageLayout input_layout, const struct fx_settings *frozen,
|
||||
@@ -865,7 +772,11 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int
|
||||
const int upscaling = cw > scene_w || ch > scene_h;
|
||||
int spatial = 0;
|
||||
if (spatial_mode(s->scaling) && (s->scaling == 6 || upscaling)) spatial = s->scaling;
|
||||
const int nis_fallback = spatial == 7 && nis_falls_back(scene_w, scene_h, cw, ch);
|
||||
/* NIS here is the SDR implementation and is documented for <=2x upscales. */
|
||||
const int nis_fallback = spatial == 7 &&
|
||||
(g_scene_is_pq || cw < scene_w || ch < scene_h ||
|
||||
(double)cw > (double)scene_w * 2.0 ||
|
||||
(double)ch > (double)scene_h * 2.0);
|
||||
static int last_nis_fallback = 0;
|
||||
const int was_nis_fallback =
|
||||
__atomic_exchange_n(&last_nis_fallback, nis_fallback, __ATOMIC_RELAXED);
|
||||
@@ -890,10 +801,9 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int
|
||||
target_ensure(&g_mid, cw, ch, FX_SCRATCH_USAGE, "EASU") == 0)) {
|
||||
if (s->aa_mode == 2 &&
|
||||
(target_ensure_format(&g_smaa_edges, cw, ch, FX_SCRATCH_USAGE,
|
||||
"SMAA edges", SMAA_EDGE_FORMAT, g_smaa_edge_rp) != 0 ||
|
||||
"SMAA edges", FX_FORMAT, g_smaa_rp) != 0 ||
|
||||
target_ensure_format(&g_smaa_weights, cw, ch, FX_SCRATCH_USAGE,
|
||||
"SMAA weights", FX_FORMAT, g_smaa_weights_rp) != 0 ||
|
||||
smaa_tables_ensure() != 0)) {
|
||||
"SMAA weights", FX_FORMAT, g_smaa_rp) != 0)) {
|
||||
droiddeck_log("error", "effects: SMAA scratch allocation failed; falling back to FXAA");
|
||||
snapshot.aa_mode = 1;
|
||||
s = &snapshot;
|
||||
@@ -1021,17 +931,14 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int
|
||||
switch (order[i]) {
|
||||
case FX_FXAA: pass(cmd, g_pipe[P_FXAA], dst, cur_ds, &pr, sizeof(pr)); break;
|
||||
case FX_FXAA_TOON: pass(cmd, g_pipe[P_FXAA_TOON], dst, cur_ds, &pr, sizeof(pr)); break;
|
||||
case FX_SMAA: {
|
||||
struct pc_smaa pc = {.metrics = {1.0f / (float)cw, 1.0f / (float)ch, (float)cw, (float)ch}};
|
||||
const VkDescriptorSet weigh[3] = {g_smaa_edges.ds, g_smaa_area.ds, g_smaa_search.ds};
|
||||
const VkDescriptorSet blend[2] = {cur_ds, g_smaa_weights.ds};
|
||||
SET_NDC(pc);
|
||||
smaa_tables_copy(cmd);
|
||||
pass_sets(cmd, g_smaa_edge_rp, g_pipe[P_SMAA_EDGE], &g_smaa_edges, &cur_ds, 1, &pc, sizeof(pc));
|
||||
pass_sets(cmd, g_smaa_weights_rp, g_pipe[P_SMAA_WEIGHTS], &g_smaa_weights, weigh, 3, &pc, sizeof(pc));
|
||||
pass_sets(cmd, g_rp, g_pipe[P_SMAA_BLEND], dst, blend, 2, &pc, sizeof(pc));
|
||||
case FX_SMAA:
|
||||
pass_renderpass(cmd, g_smaa_rp, g_pipe[P_SMAA_EDGE],
|
||||
&g_smaa_edges, cur_ds, &pr, sizeof(pr));
|
||||
pass_renderpass(cmd, g_smaa_rp, g_pipe[P_SMAA_WEIGHTS],
|
||||
&g_smaa_weights, g_smaa_edges.ds, &pr, sizeof(pr));
|
||||
pass_dual(cmd, g_pipe[P_SMAA_BLEND], dst, cur_ds,
|
||||
g_smaa_weights.ds, &pr, sizeof(pr));
|
||||
break;
|
||||
}
|
||||
case FX_TOON: pass(cmd, g_pipe[P_TOON], dst, cur_ds, &pr, sizeof(pr)); break;
|
||||
case FX_TOON_COLOR: {
|
||||
struct pc_toon_color pc = {0};
|
||||
@@ -1092,23 +999,13 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL, NULL);
|
||||
}
|
||||
|
||||
int vkp_effects_prepare_generated(int in_w, int in_h, int out_w, int out_h) {
|
||||
int vkp_effects_prepare_generated(void) {
|
||||
vkp_effects_sync();
|
||||
pthread_mutex_lock(&g_lock);
|
||||
g_generated_settings = g_cur;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
int spatial = g_generated_settings.scaling;
|
||||
if (!spatial_mode(spatial) || spatial == 6 || effect_count(&g_generated_settings) != 0) return 0;
|
||||
/* Build the spatial filter's pipelines now, before frame generation records commands that sample the
|
||||
* chain's views: one failing later in the same pass would tear the chain down (chain_failed) under a
|
||||
* recorded command buffer. Build only what effects_run will use for this output, as it decides it:
|
||||
* NIS on an output it hands to FSR builds FSR, so a NIS that cannot build here costs nothing. */
|
||||
int cw = out_w > FX_MAX_DIM ? FX_MAX_DIM : out_w < 1 ? 1 : out_w;
|
||||
int ch = out_h > FX_MAX_DIM ? FX_MAX_DIM : out_h < 1 ? 1 : out_h;
|
||||
if (cw <= in_w && ch <= in_h) return 1; /* clamped, it no longer upscales: effects_run builds no filter */
|
||||
if (spatial == 7 && nis_falls_back(in_w, in_h, cw, ch)) spatial = 4;
|
||||
if (objects_ensure() != 0 || pipelines_ensure(spatial, &g_generated_settings) != 0) return 0;
|
||||
return 1;
|
||||
return spatial_mode(g_generated_settings.scaling) && g_generated_settings.scaling != 6 &&
|
||||
effect_count(&g_generated_settings) == 0;
|
||||
}
|
||||
|
||||
VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h,
|
||||
@@ -1129,18 +1026,13 @@ VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_
|
||||
struct fx_source_state source_state = {0};
|
||||
VkImage result = effects_run(cmd, scene, scene_w, scene_h, out_w, out_h, res_w, res_h,
|
||||
VK_IMAGE_LAYOUT_GENERAL, &g_generated_settings, &source_state);
|
||||
if (result != scene) {
|
||||
barrier(cmd, result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
barrier(cmd, result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
if (result != scene)
|
||||
barrier(cmd, scene, source_state.layout, VK_IMAGE_LAYOUT_GENERAL,
|
||||
source_state.stage, source_state.access,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
|
||||
} else if (source_state.layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
}
|
||||
g_context = 0;
|
||||
return result;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ VkFilter vkp_effects_blit_filter(void);
|
||||
|
||||
VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h);
|
||||
int vkp_effects_prepare_generated(int in_w, int in_h, int out_w, int out_h);
|
||||
int vkp_effects_prepare_generated(void);
|
||||
void vkp_effects_release_generated_sources(void);
|
||||
VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h,
|
||||
int *res_w, int *res_h);
|
||||
@@ -28,7 +28,6 @@ VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_
|
||||
void vkp_effects_destroy(void);
|
||||
|
||||
void vkp_effects_forget_image(VkImage img);
|
||||
VkImageView vkp_effects_framegen_image_view(VkImage img, int w, int h, VkFormat fmt);
|
||||
|
||||
void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt, int scene_is_pq);
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef DD_FRAME_ACQUIRE_H
|
||||
#define DD_FRAME_ACQUIRE_H
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <linux/sync_file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* A zero-initialized slot owns no descriptor. Only an already successful
|
||||
* sync_file can enter this slot; display-side release ownership is separate. */
|
||||
struct dd_frame_acquire { int fd_plus_one; };
|
||||
enum dd_frame_acquire_result { DD_ACQUIRE_OK, DD_ACQUIRE_DUPLICATE, DD_ACQUIRE_INVALID };
|
||||
|
||||
static inline void dd_frame_acquire_clear(struct dd_frame_acquire *f) {
|
||||
if (f->fd_plus_one) close(f->fd_plus_one - 1);
|
||||
f->fd_plus_one = 0;
|
||||
}
|
||||
|
||||
static inline enum dd_frame_acquire_result
|
||||
dd_frame_acquire_set(struct dd_frame_acquire *f, int fd) {
|
||||
enum dd_frame_acquire_result result;
|
||||
struct sync_file_info info = {0};
|
||||
if (f->fd_plus_one) result = DD_ACQUIRE_DUPLICATE;
|
||||
else if (fd < 0 || fd == INT_MAX || ioctl(fd, SYNC_IOC_FILE_INFO, &info) != 0 ||
|
||||
info.status != 1 || info.num_fences == 0) result = DD_ACQUIRE_INVALID;
|
||||
else {
|
||||
f->fd_plus_one = fd + 1;
|
||||
return DD_ACQUIRE_OK;
|
||||
}
|
||||
if (fd >= 0) close(fd);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int dd_frame_acquire_dup(const struct dd_frame_acquire *f) {
|
||||
if (!f->fd_plus_one) return -1; /* Legacy: no explicit attachment proof. */
|
||||
int fd = fcntl(f->fd_plus_one - 1, F_DUPFD_CLOEXEC, 0);
|
||||
return fd < 0 ? -2 : fd; /* Do not re-enter the legacy direct path. */
|
||||
}
|
||||
#endif
|
||||
@@ -1,81 +0,0 @@
|
||||
#ifndef DD_WORKER_PEER_H
|
||||
#define DD_WORKER_PEER_H
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Model of one app-issued, session-bound authorization record. No callers,
|
||||
* property access, proc traversal, or authorization is installed by this file. */
|
||||
struct dd_worker_grant {
|
||||
uint32_t owner, uid, pid, dev_major, dev_minor;
|
||||
uint64_t start_ticks, ino, expires;
|
||||
const char *canonical_file;
|
||||
bool app_launch_verified, final_go;
|
||||
};
|
||||
|
||||
enum dd_worker_stat_result {
|
||||
DD_WORKER_STAT_OK, DD_WORKER_STAT_DENIED, DD_WORKER_STAT_HIDDEN, DD_WORKER_STAT_OPEN,
|
||||
DD_WORKER_STAT_READ, DD_WORKER_STAT_PARSE, DD_WORKER_STAT_ZERO,
|
||||
};
|
||||
|
||||
static inline enum dd_worker_stat_result dd_worker_parse_start(const char *line, uint64_t *out) {
|
||||
const char *p = strrchr(line, ')');
|
||||
if (!p || p[1] != ' ' || !p[2] || p[3] != ' ') return DD_WORKER_STAT_PARSE;
|
||||
p += 2;
|
||||
// State is field 3. The starttime (22) is always followed by vsize (23).
|
||||
for (int field = 3; field < 22; ++field) {
|
||||
p = strchr(p, ' ');
|
||||
if (!p) return DD_WORKER_STAT_PARSE;
|
||||
while (*p == ' ') ++p;
|
||||
}
|
||||
char *end;
|
||||
if (*p < '0' || *p > '9') return DD_WORKER_STAT_PARSE;
|
||||
errno = 0;
|
||||
uint64_t value = strtoull(p, &end, 10);
|
||||
if (errno || end == p || *end != ' ') return DD_WORKER_STAT_PARSE;
|
||||
if (!value) return DD_WORKER_STAT_ZERO;
|
||||
*out = value;
|
||||
return DD_WORKER_STAT_OK;
|
||||
}
|
||||
|
||||
static inline enum dd_worker_stat_result dd_worker_open_failure(int error) {
|
||||
if (error == EACCES || error == EPERM) return DD_WORKER_STAT_DENIED;
|
||||
if (error == ENOENT || error == ESRCH) return DD_WORKER_STAT_HIDDEN;
|
||||
return DD_WORKER_STAT_OPEN;
|
||||
}
|
||||
|
||||
static inline bool dd_worker_receipt_allows_reserve(enum dd_worker_stat_result stat,
|
||||
uint64_t raw, uint64_t receipt) {
|
||||
if (!receipt) return false;
|
||||
if (stat == DD_WORKER_STAT_OK) return raw == receipt;
|
||||
// Only a visibility denial can defer the broker-side stat check, not any
|
||||
// bad read, malformed record, mismatched timestamp, or other open error.
|
||||
return stat == DD_WORKER_STAT_DENIED || stat == DD_WORKER_STAT_HIDDEN;
|
||||
}
|
||||
|
||||
static inline bool dd_worker_map_matches(const struct dd_worker_grant *g, const char *line) {
|
||||
unsigned major, minor;
|
||||
uint64_t lo, hi, off, ino;
|
||||
int prefix = 0;
|
||||
char mode[5];
|
||||
if (!g->canonical_file || !*g->canonical_file ||
|
||||
sscanf(line, "%" SCNx64 "-%" SCNx64 " %4s %" SCNx64 " %x:%x %" SCNu64 " %n",
|
||||
&lo,&hi,mode,&off,&major,&minor,&ino,&prefix)!=7 ||
|
||||
prefix <= 0 || hi <= lo || strlen(mode)!=4 || mode[2]!='x' ||
|
||||
major!=g->dev_major || minor!=g->dev_minor || !ino || ino!=g->ino)
|
||||
return false;
|
||||
size_t path_len=strcspn(line+prefix,"\r\n");
|
||||
return strlen(g->canonical_file)==path_len && !memcmp(line+prefix,g->canonical_file,path_len);
|
||||
}
|
||||
|
||||
static inline bool dd_worker_grant_matches(const struct dd_worker_grant *g, uint32_t owner,
|
||||
uint32_t uid, uint32_t pid, uint64_t start, uint64_t now, const char *executable_map) {
|
||||
return g && g->app_launch_verified && g->final_go && owner && owner==g->owner &&
|
||||
uid==g->uid && pid>1 && pid==g->pid && start && start==g->start_ticks &&
|
||||
now<g->expires && executable_map && dd_worker_map_matches(g,executable_map);
|
||||
}
|
||||
#endif
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "framegen_engine.h"
|
||||
#include "effects_chain.h"
|
||||
#include "vk_loader.h"
|
||||
#include "sc_layer.h"
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
@@ -37,7 +36,7 @@ static VkQueue g_queue;
|
||||
static uint32_t g_qfam;
|
||||
static _Atomic int g_dev_ready, g_dev_lost;
|
||||
static int g_features_enabled;
|
||||
static _Atomic int g_caps_lsfg_ok, g_caps_ddfg_ok, g_caps_zero_ok;
|
||||
static _Atomic int g_caps_lsfg_ok, g_caps_ddfg_ok;
|
||||
static VkPhysicalDeviceMemoryProperties g_memprops;
|
||||
static struct {
|
||||
PFN_vkCreateImage CreateImage;
|
||||
@@ -79,24 +78,6 @@ static int format_refused(VkFormat f) {
|
||||
|
||||
static _Atomic unsigned g_stat_generated;
|
||||
static uint64_t g_total_generated;
|
||||
|
||||
#define FG_PROVEN_FRAMES 120
|
||||
#define FG_HANG_STRIKES 2
|
||||
static _Atomic int g_hang_strikes;
|
||||
static int g_submitted_since_ready;
|
||||
static uint64_t g_generated_at_ready;
|
||||
|
||||
// A driver that hangs on the engine's shaders loses the device on its first generated frame after every
|
||||
// recovery, so the compositor would recover and hang again for as long as frame generation stays armed.
|
||||
static int framegen_loss_strike(int submitted, uint64_t completed_since_ready) {
|
||||
if (!submitted || completed_since_ready >= FG_PROVEN_FRAMES) {
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
return 0;
|
||||
}
|
||||
if (atomic_fetch_add(&g_hang_strikes, 1) + 1 < FG_HANG_STRIKES) return 0;
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
return 1;
|
||||
}
|
||||
static float g_presented_rate, g_source_rate;
|
||||
static uint32_t g_present_accum, g_source_accum;
|
||||
static int64_t g_window_start_ns;
|
||||
@@ -106,49 +87,12 @@ static int64_t now_ns(void) {
|
||||
return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
}
|
||||
|
||||
/* The pair the last run made, for the display probe and the pacer: when its real frame reached the
|
||||
* compositor, the game moment each generated frame shows, and the refresh the pacer timed each for. */
|
||||
static _Atomic int g_pacer_on;
|
||||
static int g_layer_path;
|
||||
static int g_out_gens;
|
||||
static int64_t g_out_planned[VKP_FG_MAX_GENERATIONS + 1];
|
||||
static int64_t g_completion_issue;
|
||||
static int g_paced_route = 1;
|
||||
|
||||
void vkp_framegen_set_pacer(int on) {
|
||||
if (atomic_exchange(&g_pacer_on, on ? 1 : 0) != (on ? 1 : 0)) {
|
||||
fge_pacer_reset();
|
||||
FGLOG("ZeroFG pacer %s", on ? "on: frame generation times its frames itself" : "off: the display layer times them");
|
||||
}
|
||||
}
|
||||
|
||||
static int pacer_wanted(void) { return atomic_load(&g_pacer_on); }
|
||||
|
||||
void vkp_framegen_pacer_abort(void) {
|
||||
g_completion_issue = 0;
|
||||
fge_pacer_reset();
|
||||
}
|
||||
|
||||
void vkp_framegen_output_planned(int k, int gens, int64_t *planned) {
|
||||
*planned = (k < 0 || k >= gens || k >= g_out_gens)
|
||||
? g_out_planned[g_out_gens] : g_out_planned[k];
|
||||
}
|
||||
|
||||
void vkp_framegen_completed(void) {
|
||||
if (!g_completion_issue) return;
|
||||
fge_pacer_completed(g_completion_issue, now_ns());
|
||||
g_completion_issue = 0;
|
||||
}
|
||||
|
||||
void vkp_framegen_real_shown(int64_t planned_ns, int64_t shown_ns) { fge_pacer_shown(planned_ns, shown_ns); }
|
||||
|
||||
|
||||
void vkp_framegen_set_engine(int kind) {
|
||||
if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_DDFG && kind != VKP_FG_ENGINE_ZEROFG) kind = VKP_FG_ENGINE_LSFG;
|
||||
if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_DDFG) kind = VKP_FG_ENGINE_LSFG;
|
||||
atomic_store(&g_kind, kind);
|
||||
atomic_store(&g_failed_kind, -1);
|
||||
atomic_store(&g_cfg_dirty, 1);
|
||||
atomic_store(&g_hang_strikes, 0);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_armed(int armed, int multiplier, int target_fps) {
|
||||
@@ -174,22 +118,6 @@ void vkp_framegen_set_lsfg_cache_path(const char *path) {
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_layer_timing(int layer) {
|
||||
g_layer_path = layer;
|
||||
fge_set_layer_timing(layer);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_paced_route(int composed) {
|
||||
composed = composed != 0;
|
||||
if (composed == g_paced_route) return;
|
||||
g_paced_route = composed;
|
||||
if (atomic_load(&g_pacer_on)) {
|
||||
fge_pacer_reset();
|
||||
FGLOG("ZeroPacer %s", composed ? "times the layer's frames again (composed route)"
|
||||
: "waits: the direct route presents the real frame on its own timing");
|
||||
}
|
||||
}
|
||||
|
||||
void vkp_framegen_set_tuning(float flow_scale, float refresh_hz) {
|
||||
if (flow_scale < 0.25f) flow_scale = 0.25f;
|
||||
if (flow_scale > 1.0f) flow_scale = 1.0f;
|
||||
@@ -218,15 +146,15 @@ static void mark_failed(int kind) {
|
||||
int vkp_framegen_problem(void) {
|
||||
if (!atomic_load(&g_dev_ready)) return -1;
|
||||
int kind = atomic_load(&g_kind);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_ZEROFG ? atomic_load(&g_caps_zero_ok) :
|
||||
kind == VKP_FG_ENGINE_DDFG ? atomic_load(&g_caps_ddfg_ok) :
|
||||
atomic_load(&g_caps_lsfg_ok);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_DDFG
|
||||
? atomic_load(&g_caps_ddfg_ok)
|
||||
: atomic_load(&g_caps_lsfg_ok);
|
||||
if (!caps_ok) return 1;
|
||||
if (start_failed_for(kind)) return 2;
|
||||
if (g_engine_ok && g_engine_kind == kind && fge_unavailable()) return 2;
|
||||
return 0;
|
||||
}
|
||||
const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(atomic_load(&g_kind)); }
|
||||
const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(); }
|
||||
|
||||
void vkp_framegen_stats(float out[6]) {
|
||||
float accepted = 0.0f, src = 0.0f, thermal = -1.0f;
|
||||
@@ -259,33 +187,16 @@ void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int f
|
||||
fge_device_ready(g_gipa, g_inst, g_pd, dev, queue, qfam, features_enabled);
|
||||
atomic_store(&g_caps_lsfg_ok, fge_caps_ok(VKP_FG_ENGINE_LSFG));
|
||||
atomic_store(&g_caps_ddfg_ok, fge_caps_ok(VKP_FG_ENGINE_DDFG));
|
||||
atomic_store(&g_caps_zero_ok, fge_caps_ok(VKP_FG_ENGINE_ZEROFG));
|
||||
atomic_store(&g_dev_lost, 0);
|
||||
g_submitted_since_ready = 0;
|
||||
g_generated_at_ready = g_total_generated;
|
||||
atomic_store(&g_dev_ready,
|
||||
vk.CreateImage && vk.CreateImageView && vk.CmdPipelineBarrier);
|
||||
FGLOG("engines ready on compositor device: LSFG %s, DD-FG %s, ZeroFG %s",
|
||||
fge_caps_ok(VKP_FG_ENGINE_LSFG) ? "available" : "unavailable",
|
||||
fge_caps_ok(VKP_FG_ENGINE_DDFG) ? "available" : "unavailable",
|
||||
fge_caps_ok(VKP_FG_ENGINE_ZEROFG) ? "available" : "unavailable");
|
||||
}
|
||||
|
||||
// The compositor reports one loss twice: when it happens and again while releasing the lost device.
|
||||
static int framegen_count_loss(void) {
|
||||
if (atomic_exchange(&g_dev_lost, 1)) return 0;
|
||||
int failed = framegen_loss_strike(g_submitted_since_ready, g_total_generated - g_generated_at_ready);
|
||||
g_submitted_since_ready = 0;
|
||||
return failed;
|
||||
FGLOG("engines ready on the compositor's device: LSFG Native %s (%s), DD-FG Native %s",
|
||||
fge_caps_ok(VKP_FG_ENGINE_LSFG) ? "available" : "unavailable", fge_caps_reason(),
|
||||
fge_caps_ok(VKP_FG_ENGINE_DDFG) ? "available" : "unavailable");
|
||||
}
|
||||
|
||||
void vkp_framegen_device_lost(void) {
|
||||
if (framegen_count_loss()) {
|
||||
int kind = atomic_load(&g_kind);
|
||||
mark_failed(kind);
|
||||
FGLOG("%s lost the GPU %d times in a row before its frames completed; frame generation stays off "
|
||||
"until it is set again", fge_engine_name(kind), FG_HANG_STRIKES);
|
||||
}
|
||||
atomic_store(&g_dev_lost, 1);
|
||||
atomic_store(&g_dev_ready, 0);
|
||||
fge_device_lost();
|
||||
if (g_dev) {
|
||||
@@ -372,18 +283,16 @@ static int engine_usable(void) {
|
||||
int kind = atomic_load(&g_kind);
|
||||
int ready = atomic_load(&g_dev_ready);
|
||||
int lost = atomic_load(&g_dev_lost);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_ZEROFG ? atomic_load(&g_caps_zero_ok) :
|
||||
kind == VKP_FG_ENGINE_DDFG ? atomic_load(&g_caps_ddfg_ok) :
|
||||
atomic_load(&g_caps_lsfg_ok);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_DDFG
|
||||
? atomic_load(&g_caps_ddfg_ok)
|
||||
: atomic_load(&g_caps_lsfg_ok);
|
||||
return ready && !lost && caps_ok && !start_failed_for(kind);
|
||||
}
|
||||
|
||||
int vkp_framegen_format_ok(VkFormat fmt) {
|
||||
if (!g_dev_ready || g_dev_lost || format_refused(fmt)) return 0;
|
||||
int kind = atomic_load(&g_kind);
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG) return fge_format_ok(VKP_FG_ENGINE_ZEROFG, fmt);
|
||||
if (fmt == VK_FORMAT_R8G8B8A8_UNORM) return 1;
|
||||
return fge_format_ok(kind, fmt);
|
||||
if (!g_dev_ready || g_dev_lost || format_refused(fmt)) return 0;
|
||||
return fge_format_ok(fmt);
|
||||
}
|
||||
|
||||
static void refuse_format(VkFormat fmt, int kind, int w, int h, const char *what) {
|
||||
@@ -468,14 +377,11 @@ static void log_arm_transition(int armed, int kind, int mult) {
|
||||
|
||||
int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h,
|
||||
VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]) {
|
||||
(void)scene_view;
|
||||
int kind = atomic_load(&g_kind);
|
||||
int armed = atomic_load(&g_armed);
|
||||
int mult = atomic_load(&g_mult);
|
||||
g_planned = 0;
|
||||
const int64_t issue = now_ns();
|
||||
g_out_gens = 0;
|
||||
memset(g_out_planned, 0, sizeof(g_out_planned));
|
||||
g_completion_issue = 0;
|
||||
if (!armed || !engine_usable() || w <= 0 || h <= 0) { log_arm_transition(0, kind, mult); return 0; }
|
||||
if (!ensure_engine(kind)) { log_arm_transition(0, kind, mult); return 0; }
|
||||
log_arm_transition(1, kind, mult);
|
||||
@@ -517,31 +423,8 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
|
||||
++g_source_frames;
|
||||
const uint64_t game_frames = droiddeck_game_frames();
|
||||
const uint64_t planning_sequence = game_frames ? game_frames : g_source_frames;
|
||||
uint32_t n_gen = fge_plan(g_ring_n, planning_sequence, g_presented_rate);
|
||||
uint32_t n_gen = fge_plan(g_ring_n, game_frames ? game_frames : g_source_frames, g_presented_rate);
|
||||
if (n_gen > g_ring_n) n_gen = g_ring_n;
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG && n_gen > 0 && !scene_view) {
|
||||
scene_view = vkp_effects_framegen_image_view(scene, w, h, fmt);
|
||||
if (!scene_view) {
|
||||
static int view_warning;
|
||||
if (!view_warning++) FGLOG("ZeroFG could not create a view for the source image; showing real frames only");
|
||||
n_gen = 0;
|
||||
}
|
||||
}
|
||||
fge_set_phases(NULL, 0);
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG && pacer_wanted() && g_layer_path && g_paced_route) {
|
||||
int64_t vsync = 0, period = 0;
|
||||
sc_layer_timeline(&vsync, &period);
|
||||
int64_t planned[VKP_FG_MAX_GENERATIONS + 1];
|
||||
float phases[VKP_FG_MAX_GENERATIONS + 1];
|
||||
const uint32_t count = period > 0
|
||||
? fge_pacer_plan((uint32_t)mult, period, vsync, issue, n_gen, planned, phases) : 0;
|
||||
if (count >= 1 && count - 1 <= n_gen) {
|
||||
n_gen = count - 1;
|
||||
for (uint32_t i = 0; i < count; i++) g_out_planned[i] = planned[i];
|
||||
fge_set_phases(phases, n_gen);
|
||||
}
|
||||
}
|
||||
g_planned = n_gen;
|
||||
|
||||
VkImageMemoryBarrier bars[1 + VKP_FG_MAX_GENERATIONS];
|
||||
@@ -569,26 +452,21 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, NULL, 0, NULL, nb, bars);
|
||||
|
||||
if (n_gen) g_submitted_since_ready = 1;
|
||||
fge_process(cmd, scene, scene_view, (uint32_t)w, (uint32_t)h, fmt, planning_sequence, n_gen);
|
||||
fge_process(cmd, scene, (uint32_t)w, (uint32_t)h, n_gen);
|
||||
for (uint32_t g = 0; g < n_gen; g++) {
|
||||
fge_generate(cmd, g, n_gen, g_ring[g].img, g_ring[g].view, (uint32_t)w, (uint32_t)h);
|
||||
gens[g] = g_ring[g].img;
|
||||
}
|
||||
if (n_gen) {
|
||||
nb = 0;
|
||||
const VkAccessFlags generated_access = kind == VKP_FG_ENGINE_ZEROFG
|
||||
? VK_ACCESS_MEMORY_WRITE_BIT : VK_ACCESS_SHADER_WRITE_BIT;
|
||||
const VkPipelineStageFlags generated_stage = kind == VKP_FG_ENGINE_ZEROFG
|
||||
? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT : VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
||||
for (uint32_t g = 0; g < n_gen; g++)
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.srcAccessMask = generated_access, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = g_ring[g].img, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
|
||||
vk.CmdPipelineBarrier(cmd, generated_stage, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, nb, bars);
|
||||
if (!g_generating_logged) {
|
||||
g_generating_logged = 1;
|
||||
@@ -598,8 +476,6 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? ", FP16: the HDR picture" : "");
|
||||
}
|
||||
}
|
||||
g_out_gens = (int)n_gen;
|
||||
if (n_gen > 0) g_completion_issue = issue;
|
||||
return (int)n_gen;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1, VKP_FG_ENGINE_ZEROFG = 2 };
|
||||
enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1 };
|
||||
#define VKP_FG_MAX_GENERATIONS 3
|
||||
|
||||
void vkp_framegen_set_engine(int kind);
|
||||
@@ -26,21 +26,6 @@ void vkp_framegen_device_lost(void);
|
||||
|
||||
int vkp_framegen_active(void);
|
||||
int vkp_framegen_extra_images(void);
|
||||
/* 1 when the next run's frames are shown through the scene layer's timed group, 0 through the swapchain's FIFO. */
|
||||
void vkp_framegen_set_layer_timing(int layer);
|
||||
/* ZeroFG's pacer (include/zerofg/inline_pacer.h) times the layer's frames instead of the layer's own spacing. */
|
||||
void vkp_framegen_set_pacer(int on);
|
||||
/* 1 when the layer pass presents the real frame itself after its generated frames (the composed route): only
|
||||
* then can the pacer time the whole group. The direct route keeps the layer's own timing. */
|
||||
void vkp_framegen_set_paced_route(int composed);
|
||||
/* Reset pacing history when a planned real-frame pair is aborted before presentation. */
|
||||
void vkp_framegen_pacer_abort(void);
|
||||
/* Refresh planned for output k of the last run (k == gens: its real frame; 0: use layer timing). */
|
||||
void vkp_framegen_output_planned(int k, int gens, int64_t *planned);
|
||||
/* The last run's GPU work finished (the compositor's fence signalled). */
|
||||
void vkp_framegen_completed(void);
|
||||
/* A real frame the pacer timed for planned_ns was shown at shown_ns. */
|
||||
void vkp_framegen_real_shown(int64_t planned_ns, int64_t shown_ns);
|
||||
int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h,
|
||||
VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]);
|
||||
void vkp_framegen_presented(int generated);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -14,9 +13,6 @@
|
||||
#include "lsfg/lsfg_probe.h"
|
||||
#include "lsfg/lsfg_vkd.h"
|
||||
#include "ddfg/ddfg_engine.h"
|
||||
#include "framegen_zerofg.h"
|
||||
|
||||
#include <zerofg/inline_pacer.h>
|
||||
|
||||
#define ELOG(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", "framegen: " __VA_ARGS__)
|
||||
#define ELOGE(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", "framegen: " __VA_ARGS__)
|
||||
@@ -26,17 +22,12 @@ namespace {
|
||||
VkTable g_table{};
|
||||
lsfg::Caps g_caps{};
|
||||
VkPhysicalDeviceVulkan12Features g_v12{};
|
||||
VkPhysicalDeviceVulkan13Features g_v13{};
|
||||
VkPhysicalDeviceFeatures2 g_f2{};
|
||||
VkPhysicalDevice g_pd = VK_NULL_HANDLE;
|
||||
VkDevice g_dev = VK_NULL_HANDLE;
|
||||
VkQueue g_queue = VK_NULL_HANDLE;
|
||||
uint32_t g_qfam = 0;
|
||||
bool g_probed = false, g_ready = false;
|
||||
bool g_zero_supported = false, g_zero_enabled = false;
|
||||
zerofg::InlinePacer g_pacer;
|
||||
zerofg::InlineReadiness g_readiness;
|
||||
std::mutex g_pacer_mutex;
|
||||
|
||||
std::unique_ptr<lsfg::Engine> g_lsfg;
|
||||
std::unique_ptr<ddfg::Engine> g_ddfg;
|
||||
@@ -97,57 +88,30 @@ const void *fge_probe(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
if (n) enumExts(pd, nullptr, &n, exts.data());
|
||||
}
|
||||
g_caps = lsfg::Caps{};
|
||||
g_caps.features = lsfg::queryFeatures(g_table, pd, exts, false);
|
||||
|
||||
|
||||
g_caps.features = lsfg::queryFeatures(g_table, pd, exts, false);
|
||||
g_caps.probedFormat = ring_fmt;
|
||||
g_caps.storageOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties
|
||||
? lsfg::probeStorageFormat(g_table, pd, ring_fmt) : false;
|
||||
g_caps.linearBlitOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties
|
||||
? lsfg::probeLinearBlit(g_table, pd, ring_fmt) : false;
|
||||
g_probed = true;
|
||||
|
||||
VkPhysicalDeviceProperties props{};
|
||||
if (g_table.GetPhysicalDeviceProperties) g_table.GetPhysicalDeviceProperties(pd, &props);
|
||||
VkPhysicalDeviceVulkan13Features supported13{};
|
||||
supported13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
|
||||
VkPhysicalDeviceFeatures2 supported2{};
|
||||
supported2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
if (props.apiVersion >= VK_API_VERSION_1_3) supported2.pNext = &supported13;
|
||||
if (g_table.GetPhysicalDeviceFeatures2) g_table.GetPhysicalDeviceFeatures2(pd, &supported2);
|
||||
g_zero_supported = props.apiVersion >= VK_API_VERSION_1_3 &&
|
||||
supported13.synchronization2 == VK_TRUE &&
|
||||
supported2.features.shaderStorageImageExtendedFormats == VK_TRUE;
|
||||
g_zero_enabled = false;
|
||||
|
||||
const bool lsfg_supported = g_caps.features.deviceGatesPass();
|
||||
if (!lsfg_supported) {
|
||||
if (!g_caps.features.deviceGatesPass()) {
|
||||
lsfg::explain(g_caps);
|
||||
ELOG("device gates for the LSFG chain fail: %s", g_caps.reason);
|
||||
}
|
||||
if (!lsfg_supported && !g_zero_supported) {
|
||||
g_v12 = {};
|
||||
g_v13 = {};
|
||||
g_f2 = {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
g_v12 = VkPhysicalDeviceVulkan12Features{};
|
||||
g_v12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
|
||||
g_v12.vulkanMemoryModel =
|
||||
g_caps.features.vulkanMemoryModel ? VK_TRUE : VK_FALSE;
|
||||
g_v12.vulkanMemoryModel = VK_TRUE;
|
||||
g_v12.vulkanMemoryModelDeviceScope =
|
||||
g_caps.features.vulkanMemoryModelDeviceScope ? VK_TRUE : VK_FALSE;
|
||||
g_v13 = VkPhysicalDeviceVulkan13Features{};
|
||||
g_v13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
|
||||
g_v13.synchronization2 = g_zero_supported ? VK_TRUE : VK_FALSE;
|
||||
if (g_zero_supported) g_v12.pNext = &g_v13;
|
||||
|
||||
g_f2 = VkPhysicalDeviceFeatures2{};
|
||||
g_f2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
g_f2.pNext = &g_v12;
|
||||
g_f2.features.shaderStorageImageWriteWithoutFormat =
|
||||
supported2.features.shaderStorageImageWriteWithoutFormat ? VK_TRUE : VK_FALSE;
|
||||
g_f2.features.shaderStorageImageExtendedFormats =
|
||||
supported2.features.shaderStorageImageExtendedFormats ? VK_TRUE : VK_FALSE;
|
||||
g_f2.features.shaderStorageImageWriteWithoutFormat = VK_TRUE;
|
||||
g_f2.features.shaderStorageImageExtendedFormats = VK_TRUE;
|
||||
return &g_f2;
|
||||
}
|
||||
|
||||
@@ -158,17 +122,9 @@ void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
fill_device(dev);
|
||||
g_caps.featuresEnabled = features_enabled != 0;
|
||||
lsfg::explain(g_caps);
|
||||
VkPhysicalDeviceProperties props{};
|
||||
if (g_table.GetPhysicalDeviceProperties) g_table.GetPhysicalDeviceProperties(pd, &props);
|
||||
g_zero_enabled = g_zero_supported && features_enabled != 0;
|
||||
zfg_device_ready(gipa, inst, pd, dev,
|
||||
props.apiVersion > VK_API_VERSION_1_3 ? VK_API_VERSION_1_3 : props.apiVersion,
|
||||
g_zero_enabled,
|
||||
g_zero_enabled && g_f2.features.shaderStorageImageExtendedFormats == VK_TRUE);
|
||||
g_ready = true;
|
||||
ELOG("device ready: lsfg caps '%s', storage on ring format %d, ZeroFG %s",
|
||||
g_caps.reason, (int)g_caps.storageOnSwapchainFormat,
|
||||
g_zero_enabled ? "available" : "unavailable");
|
||||
ELOG("device ready: lsfg caps '%s', storage on ring format %d", g_caps.reason,
|
||||
(int)g_caps.storageOnSwapchainFormat);
|
||||
}
|
||||
|
||||
void fge_device_lost(void) {
|
||||
@@ -193,45 +149,24 @@ void fge_device_lost(void) {
|
||||
g_v12 = {};
|
||||
g_f2 = {};
|
||||
g_build[0] = 0;
|
||||
g_zero_supported = g_zero_enabled = false;
|
||||
zfg_device_lost();
|
||||
}
|
||||
|
||||
int fge_caps_ok(int kind) {
|
||||
if (!g_ready) return 0;
|
||||
if (kind == 2) return g_zero_enabled && zfg_caps_ok();
|
||||
if (kind == 1) return g_caps.storageOnSwapchainFormat ? 1 : 0;
|
||||
return g_caps.supported() ? 1 : 0;
|
||||
}
|
||||
|
||||
int fge_engine_available(int kind) { return fge_caps_ok(kind); }
|
||||
const char *fge_caps_reason(void) { return g_caps.reason; }
|
||||
|
||||
const char *fge_caps_reason(int kind) {
|
||||
if (kind == 2 && !g_zero_enabled)
|
||||
return "ZeroFG requires Vulkan 1.3, synchronization2 and extended storage-image formats";
|
||||
if (kind == 2) return zfg_caps_reason();
|
||||
return g_caps.reason;
|
||||
}
|
||||
|
||||
int fge_format_ok(int kind, VkFormat fmt) {
|
||||
if (kind == 2) return zfg_format_ok(fmt);
|
||||
int fge_format_ok(VkFormat fmt) {
|
||||
if (!g_ready || !g_table.GetPhysicalDeviceFormatProperties || fmt == VK_FORMAT_UNDEFINED) return 0;
|
||||
return lsfg::probeStorageFormat(g_table, g_pd, fmt) && lsfg::probeLinearBlit(g_table, g_pd, fmt) ? 1 : 0;
|
||||
}
|
||||
|
||||
int fge_start(int kind, const char *cache_path) {
|
||||
fge_stop();
|
||||
fge_pacer_reset();
|
||||
if (!g_ready) return -1;
|
||||
if (kind == 2) {
|
||||
if (!g_zero_enabled || !zfg_start()) {
|
||||
ELOGE("ZeroFG engine init failed");
|
||||
return -1;
|
||||
}
|
||||
g_kind = 2;
|
||||
std::snprintf(g_build, sizeof(g_build), "ZeroFG ReallyZero, Vulkan 1.3 Compat");
|
||||
return 0;
|
||||
}
|
||||
if (kind == 1) {
|
||||
auto e = std::make_unique<ddfg::Engine>();
|
||||
if (!e->init(g_table, g_pd, g_dev, g_qfam, g_queue)) {
|
||||
@@ -266,16 +201,14 @@ int fge_start(int kind, const char *cache_path) {
|
||||
}
|
||||
|
||||
void fge_stop(void) {
|
||||
if ((g_kind == 0 || g_kind == 2) && g_table.DeviceWaitIdle && g_dev)
|
||||
g_table.DeviceWaitIdle(g_dev);
|
||||
|
||||
g_lsfg.reset();
|
||||
|
||||
if (g_lsfg) {
|
||||
if (g_table.DeviceWaitIdle && g_dev) g_table.DeviceWaitIdle(g_dev);
|
||||
g_lsfg.reset();
|
||||
}
|
||||
for (auto it = g_retained_ddfg.begin(); it != g_retained_ddfg.end();) {
|
||||
if ((*it)->destroy()) it = g_retained_ddfg.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
|
||||
if (g_ddfg) {
|
||||
if (g_ddfg->destroy()) g_ddfg.reset();
|
||||
else {
|
||||
@@ -283,13 +216,10 @@ void fge_stop(void) {
|
||||
g_retained_ddfg.push_back(std::move(g_ddfg));
|
||||
}
|
||||
}
|
||||
|
||||
zfg_stop();
|
||||
g_kind = -1;
|
||||
}
|
||||
|
||||
int fge_unavailable(void) {
|
||||
if (g_kind == 2) return zfg_unavailable();
|
||||
if (g_kind == 1) return g_ddfg && g_ddfg->unavailable() ? 1 : 0;
|
||||
return g_lsfg && g_lsfg->unavailable() ? 1 : 0;
|
||||
}
|
||||
@@ -297,13 +227,11 @@ int fge_unavailable(void) {
|
||||
void fge_configure(uint32_t multiplier, uint32_t target_fps, float flow_scale, float refresh_hz,
|
||||
int model, int perf_preset) {
|
||||
if (multiplier < 2) multiplier = 2;
|
||||
if (g_kind == 2) { zfg_configure(multiplier, refresh_hz); return; }
|
||||
if (g_kind == 1 && g_ddfg) g_ddfg->configure(multiplier, model, perf_preset, flow_scale);
|
||||
else if (g_lsfg) g_lsfg->configure(multiplier, target_fps, flow_scale, refresh_hz);
|
||||
}
|
||||
|
||||
int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) {
|
||||
if (g_kind == 2) return zfg_prepare(w, h, fmt);
|
||||
if (g_kind == 1) return g_ddfg && g_ddfg->prepare(w, h, fmt) ? 1 : 0;
|
||||
if (!g_lsfg) return 0;
|
||||
g_lsfg->setGuestExtent(w, h);
|
||||
@@ -311,74 +239,24 @@ int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) {
|
||||
}
|
||||
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) {
|
||||
if (g_kind == 2) return zfg_plan(capacity, source_frames);
|
||||
if (g_kind == 1) return g_ddfg ? g_ddfg->plan(capacity) : 0;
|
||||
if (!g_lsfg) return 0;
|
||||
g_lsfg->setPresentedRate(presented_rate);
|
||||
return g_lsfg->plan(capacity, source_frames);
|
||||
}
|
||||
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t w, uint32_t h, VkFormat fmt, uint64_t sequence, uint32_t gens) {
|
||||
if (g_kind == 2) {
|
||||
zfg_process(cmd, source, source_view, w, h, fmt, sequence, gens);
|
||||
return;
|
||||
}
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) {
|
||||
if (g_kind == 1) { if (g_ddfg) g_ddfg->process(cmd, source, w, h, gens); return; }
|
||||
if (g_lsfg) g_lsfg->process(cmd, source, w, h, gens);
|
||||
}
|
||||
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h) {
|
||||
if (g_kind == 2) { zfg_generate(cmd, g, count, img, view, w, h); return; }
|
||||
if (g_kind == 1) { if (g_ddfg) g_ddfg->generateInto(cmd, g, count, img, view, w, h); return; }
|
||||
if (g_lsfg) g_lsfg->generateInto(cmd, g, g, img, view, w, h);
|
||||
}
|
||||
|
||||
void fge_set_layer_timing(int layer) { zfg_set_layer_timing(layer); }
|
||||
|
||||
void fge_set_phases(const float *phases, uint32_t count) { zfg_set_phases(phases, count); }
|
||||
|
||||
float fge_phase(uint32_t index, uint32_t count) {
|
||||
if (g_kind == 2) return zfg_phase(index, count);
|
||||
return static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
}
|
||||
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases) {
|
||||
if (period_ns <= 0 || issue_ns <= 0) return 0;
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
g_pacer.SetMultiplier(multiplier);
|
||||
g_pacer.ObserveVsync(static_cast<uint64_t>(period_ns), static_cast<uint64_t>(vsync_ns > 0 ? vsync_ns : 0));
|
||||
const uint64_t issue = static_cast<uint64_t>(issue_ns);
|
||||
const zerofg::InlinePacer::Plan plan =
|
||||
g_pacer.PlanPair(issue, issue + g_readiness.MarginNs(static_cast<uint64_t>(period_ns)), max_generated + 1);
|
||||
for (uint32_t i = 0; i < plan.count; i++) {
|
||||
present_ns[i] = static_cast<int64_t>(plan.outputs[i].present_ns);
|
||||
phases[i] = plan.outputs[i].phase;
|
||||
}
|
||||
return plan.count;
|
||||
}
|
||||
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
if (issue_ns > 0 && done_ns > issue_ns)
|
||||
g_readiness.ObserveCompleted(static_cast<uint64_t>(issue_ns), static_cast<uint64_t>(done_ns));
|
||||
}
|
||||
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
if (planned_ns > 0 && shown_ns > 0)
|
||||
g_pacer.ObserveRealShown(static_cast<uint64_t>(planned_ns), static_cast<uint64_t>(shown_ns));
|
||||
}
|
||||
|
||||
void fge_pacer_reset(void) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
g_pacer.Reset();
|
||||
}
|
||||
|
||||
void fge_forget_targets(void) {
|
||||
if (g_kind == 2) { zfg_forget_targets(); return; }
|
||||
if (g_lsfg) g_lsfg->forgetTargets();
|
||||
}
|
||||
|
||||
@@ -388,14 +266,10 @@ void fge_telemetry(float *accepted, float *source_rate, float *thermal) {
|
||||
*accepted = (float)g_lsfg->acceptedGenerations();
|
||||
*source_rate = g_lsfg->sourceRate();
|
||||
*thermal = (float)g_lsfg->thermalStatus();
|
||||
} else if (g_kind == 2) {
|
||||
zfg_telemetry(accepted, source_rate);
|
||||
}
|
||||
}
|
||||
|
||||
const char *fge_engine_name(int kind) {
|
||||
return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native";
|
||||
}
|
||||
const char *fge_engine_name(int kind) { return kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_build_info(void) { return g_build; }
|
||||
|
||||
}
|
||||
@@ -16,9 +16,8 @@ void fge_device_lost(void);
|
||||
void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd,
|
||||
VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled);
|
||||
int fge_caps_ok(int kind);
|
||||
const char *fge_caps_reason(int kind);
|
||||
int fge_format_ok(int kind, VkFormat fmt);
|
||||
int fge_engine_available(int kind);
|
||||
const char *fge_caps_reason(void);
|
||||
int fge_format_ok(VkFormat fmt);
|
||||
|
||||
int fge_start(int kind, const char *cache_path);
|
||||
void fge_stop(void);
|
||||
@@ -27,22 +26,10 @@ void fge_configure(uint32_t multiplier, uint32_t target_fps, float flow_scale, f
|
||||
int model, int perf_preset);
|
||||
int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt);
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate);
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t w, uint32_t h, VkFormat fmt, uint64_t sequence, uint32_t gens);
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens);
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h);
|
||||
void fge_forget_targets(void);
|
||||
void fge_set_layer_timing(int layer);
|
||||
/* The phases the pacer chose for the next pair's generated frames (engines that can take any phase). */
|
||||
void fge_set_phases(const float *phases, uint32_t count);
|
||||
/* The phase generated frame [index] of [count] shows. */
|
||||
float fge_phase(uint32_t index, uint32_t count);
|
||||
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases);
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns);
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns);
|
||||
void fge_pacer_reset(void);
|
||||
void fge_telemetry(float *accepted, float *source_rate, float *thermal);
|
||||
const char *fge_engine_name(int kind);
|
||||
const char *fge_build_info(void);
|
||||
|
||||
@@ -10,12 +10,9 @@ void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
(void)gipa; (void)inst; (void)pd; (void)dev; (void)queue; (void)qfam; (void)features_enabled;
|
||||
}
|
||||
void fge_device_lost(void) {}
|
||||
void zfg_discard_history_update(void) {}
|
||||
void zfg_commit_history_update(void) {}
|
||||
int fge_caps_ok(int kind) { (void)kind; return 0; }
|
||||
const char *fge_caps_reason(int kind) { (void)kind; return "frame-generation engines not built into this compositor"; }
|
||||
int fge_format_ok(int kind, VkFormat fmt) { (void)kind; (void)fmt; return 0; }
|
||||
int fge_engine_available(int kind) { (void)kind; return 0; }
|
||||
const char *fge_caps_reason(void) { return "frame-generation engines not built into this compositor"; }
|
||||
int fge_format_ok(VkFormat fmt) { (void)fmt; return 0; }
|
||||
int fge_start(int kind, const char *cache_path) { (void)kind; (void)cache_path; return -1; }
|
||||
void fge_stop(void) {}
|
||||
int fge_unavailable(void) { return 1; }
|
||||
@@ -27,28 +24,16 @@ int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) { (void)w; (void)h; (void)
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) {
|
||||
(void)capacity; (void)source_frames; (void)presented_rate; return 0;
|
||||
}
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view, uint32_t w, uint32_t h,
|
||||
VkFormat fmt, uint64_t sequence, uint32_t gens) {
|
||||
(void)cmd; (void)source; (void)source_view; (void)w; (void)h; (void)fmt; (void)sequence; (void)gens;
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) {
|
||||
(void)cmd; (void)source; (void)w; (void)h; (void)gens;
|
||||
}
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h) {
|
||||
(void)cmd; (void)g; (void)count; (void)img; (void)view; (void)w; (void)h;
|
||||
}
|
||||
void fge_forget_targets(void) {}
|
||||
void fge_set_layer_timing(int layer) { (void)layer; }
|
||||
void fge_set_phases(const float *phases, uint32_t count) { (void)phases; (void)count; }
|
||||
float fge_phase(uint32_t index, uint32_t count) { return (float)(index + 1) / (float)(count + 1); }
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases) {
|
||||
(void)multiplier; (void)period_ns; (void)vsync_ns; (void)issue_ns; (void)max_generated; (void)present_ns; (void)phases;
|
||||
return 0;
|
||||
}
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns) { (void)issue_ns; (void)done_ns; }
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns) { (void)planned_ns; (void)shown_ns; }
|
||||
void fge_pacer_reset(void) {}
|
||||
void fge_telemetry(float *accepted, float *source_rate, float *thermal) {
|
||||
*accepted = 0.0f; *source_rate = 0.0f; *thermal = -1.0f;
|
||||
}
|
||||
const char *fge_engine_name(int kind) { return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_engine_name(int kind) { return kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_build_info(void) { return "stub"; }
|
||||
@@ -14,12 +14,6 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFrameGenArmed(JNI
|
||||
vkp_framegen_set_armed(armed ? 1 : 0, (int)multiplier, (int)targetFps);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFrameGenPacer(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
(void)env; (void)clazz;
|
||||
vkp_framegen_set_pacer(on ? 1 : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetLsfgCachePath(JNIEnv *env, jclass clazz, jstring path) {
|
||||
(void)clazz;
|
||||
|
||||
@@ -1,624 +0,0 @@
|
||||
#include "framegen_zerofg.h"
|
||||
#include "sc_layer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <zerofg/zerofg.h>
|
||||
|
||||
#define ZFG_LOG(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", "ZeroFG: " __VA_ARGS__)
|
||||
#define ZFG_ERR(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", "ZeroFG: " __VA_ARGS__)
|
||||
|
||||
namespace {
|
||||
PFN_vkGetInstanceProcAddr g_gipa = nullptr;
|
||||
PFN_vkGetDeviceProcAddr g_gdpa = nullptr;
|
||||
VkInstance g_instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice g_physical = VK_NULL_HANDLE;
|
||||
VkDevice g_device = VK_NULL_HANDLE;
|
||||
uint32_t g_api_version = VK_API_VERSION_1_0;
|
||||
bool g_synchronization2 = false, g_extended_formats = false;
|
||||
bool g_ready = false, g_supported = false, g_failed = false;
|
||||
char g_reason[160] = "device has not been checked";
|
||||
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties g_GetPhysicalDeviceMemoryProperties = nullptr;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties g_GetPhysicalDeviceFormatProperties = nullptr;
|
||||
PFN_vkCreateImage g_CreateImage = nullptr;
|
||||
PFN_vkDestroyImage g_DestroyImage = nullptr;
|
||||
PFN_vkCreateImageView g_CreateImageView = nullptr;
|
||||
PFN_vkDestroyImageView g_DestroyImageView = nullptr;
|
||||
PFN_vkGetImageMemoryRequirements g_GetImageMemoryRequirements = nullptr;
|
||||
PFN_vkAllocateMemory g_AllocateMemory = nullptr;
|
||||
PFN_vkFreeMemory g_FreeMemory = nullptr;
|
||||
PFN_vkBindImageMemory g_BindImageMemory = nullptr;
|
||||
PFN_vkCmdPipelineBarrier g_CmdPipelineBarrier = nullptr;
|
||||
PFN_vkCmdCopyImage g_CmdCopyImage = nullptr;
|
||||
PFN_vkDeviceWaitIdle g_DeviceWaitIdle = nullptr;
|
||||
VkPhysicalDeviceMemoryProperties g_memory_properties{};
|
||||
|
||||
std::unique_ptr<zerofg::Interpolator> g_interpolator;
|
||||
VkImage g_history = VK_NULL_HANDLE;
|
||||
VkImageView g_history_view = VK_NULL_HANDLE;
|
||||
VkDeviceMemory g_history_memory = VK_NULL_HANDLE;
|
||||
uint32_t g_width = 0, g_height = 0;
|
||||
VkFormat g_format = VK_FORMAT_UNDEFINED;
|
||||
bool g_history_layout_defined = false, g_history_valid = false;
|
||||
uint64_t g_history_sequence = 0;
|
||||
bool g_history_recorded_pending = false;
|
||||
uint64_t g_history_recorded_sequence = 0;
|
||||
std::array<bool, 4> g_fallback_outputs{};
|
||||
VkImage g_current = VK_NULL_HANDLE;
|
||||
VkImageView g_current_view = VK_NULL_HANDLE;
|
||||
uint64_t g_current_sequence = 0;
|
||||
bool g_pair_pending = false;
|
||||
// The interpolator keeps per-pair work and the prepared Real by sequence. A pass dropped after recording
|
||||
// Interpolate never ran on the GPU, so the next pair's A gets a fresh identity no record has seen: nothing the
|
||||
// dropped pass would have prepared is reused, nor its flow start. The identity is stable for the whole pair, so
|
||||
// its phases still share their work (and ReallyZero sees one pair, not a first picture per phase).
|
||||
bool g_interpolate_uncommitted = false;
|
||||
bool g_record_stale = false;
|
||||
uint64_t g_pair_anonymous = 0; // the recovery pair's A identity, 0 for an ordinary pair
|
||||
uint64_t g_anonymous_count = 0;
|
||||
constexpr uint64_t kAnonymousSequence = 1ull << 63; // above any frame sequence the compositor hands out
|
||||
|
||||
// Pacing. The compositor presents a pair's generated frames and its real frame back to back in FIFO,
|
||||
// so they reach the panel on consecutive refreshes right after the tick that drew them.
|
||||
constexpr uint64_t kBreakNs = 250000000ull;
|
||||
constexpr size_t kIntervalWindow = 8;
|
||||
constexpr size_t kMinIntervals = 4;
|
||||
constexpr double kSlotTolerance = 0.15;
|
||||
uint32_t g_multiplier = 2;
|
||||
float g_refresh_hz = 0.0f;
|
||||
bool g_layer_timing = false;
|
||||
// The phases the pacer chose for this pair (count 0: none, the timing above decides).
|
||||
std::array<float, 4> g_external_phases{};
|
||||
uint32_t g_external_count = 0;
|
||||
uint64_t g_last_sequence = 0;
|
||||
uint64_t g_last_issue_ns = 0;
|
||||
uint64_t g_pair_interval_ns = 0;
|
||||
uint32_t g_prev_count = 0, g_pair_count = 0;
|
||||
std::array<uint64_t, kIntervalWindow> g_intervals{};
|
||||
size_t g_interval_count = 0, g_interval_next = 0;
|
||||
|
||||
uint64_t now_ns() {
|
||||
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
void reset_pacing() {
|
||||
g_last_issue_ns = 0;
|
||||
g_pair_interval_ns = 0;
|
||||
g_prev_count = g_pair_count = 0;
|
||||
g_interval_count = g_interval_next = 0;
|
||||
}
|
||||
|
||||
uint64_t period_ns() {
|
||||
return g_refresh_hz > 1.0f ? static_cast<uint64_t>(1e9 / static_cast<double>(g_refresh_hz)) : 0;
|
||||
}
|
||||
|
||||
uint64_t typical_interval_ns() {
|
||||
if (g_interval_count < kMinIntervals) return 0;
|
||||
std::array<uint64_t, kIntervalWindow> sorted = g_intervals;
|
||||
std::sort(sorted.begin(), sorted.begin() + g_interval_count);
|
||||
return sorted[g_interval_count / 2];
|
||||
}
|
||||
|
||||
void note_sequence(uint64_t sequence) {
|
||||
if (sequence == g_last_sequence) return;
|
||||
const uint64_t now = now_ns();
|
||||
if (sequence < g_last_sequence) {
|
||||
// The frame counter changed source (game frames vs compositor scenes): no pair across it.
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
reset_pacing();
|
||||
} else if (g_last_issue_ns && now > g_last_issue_ns) {
|
||||
const uint64_t interval = now - g_last_issue_ns;
|
||||
if (interval > kBreakNs) {
|
||||
reset_pacing();
|
||||
} else {
|
||||
g_pair_interval_ns = interval;
|
||||
g_intervals[g_interval_next] = interval;
|
||||
g_interval_next = (g_interval_next + 1) % kIntervalWindow;
|
||||
g_interval_count = std::min(g_interval_count + 1, kIntervalWindow);
|
||||
}
|
||||
}
|
||||
g_last_sequence = sequence;
|
||||
g_last_issue_ns = now;
|
||||
}
|
||||
|
||||
// Generated frames a pair can show without its presents queueing past the next game frame:
|
||||
// one refresh each, the real frame one more, all inside the game's typical frame interval.
|
||||
uint32_t pair_capacity(uint32_t wanted) {
|
||||
const uint64_t period = period_ns();
|
||||
const uint64_t typical = typical_interval_ns();
|
||||
if (!period || !typical) return wanted;
|
||||
const double slots = std::floor(static_cast<double>(typical) / static_cast<double>(period) + kSlotTolerance);
|
||||
return slots < 2.0 ? 0u : std::min<uint32_t>(wanted, static_cast<uint32_t>(slots) - 1u);
|
||||
}
|
||||
|
||||
// The scene layer (sc_layer.c) shows a group of [count] generated frames and then B, frame k of the group
|
||||
// max(k, round(k * gap / (count + 1))) refreshes after the first, a group every game frame interval.
|
||||
float layer_phase(uint32_t index, uint32_t count, uint64_t period) {
|
||||
const float even = static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
int64_t cadence_gap = 0;
|
||||
int cadence_frames = 0;
|
||||
sc_layer_cadence_info(&cadence_gap, &cadence_frames);
|
||||
const uint64_t gap = cadence_gap > 0 ? static_cast<uint64_t>(cadence_gap) : typical_interval_ns();
|
||||
const uint32_t group_frames = cadence_frames > static_cast<int>(count)
|
||||
? static_cast<uint32_t>(cadence_frames) : count + 1;
|
||||
if (!gap) return even;
|
||||
const int64_t slots = static_cast<int64_t>((gap + period / 2) / period);
|
||||
if (slots < static_cast<int64_t>(group_frames)) return even;
|
||||
const auto step = [&](uint32_t k) {
|
||||
const int64_t s = static_cast<int64_t>((static_cast<uint64_t>(k) * gap / group_frames + period / 2) / period);
|
||||
return std::max<int64_t>(s, k);
|
||||
};
|
||||
const double phase = static_cast<double>(step(index) - step(count) + slots) / static_cast<double>(slots);
|
||||
return static_cast<float>(std::clamp(phase, 0.05, 0.95));
|
||||
}
|
||||
|
||||
// FIFO presents the generated group and B back-to-back; phase uses the measured real-frame span.
|
||||
float pair_phase(uint32_t index, uint32_t count) {
|
||||
if (g_external_count == count && index < count) return std::clamp(g_external_phases[index], 0.01f, 0.99f);
|
||||
const float even = static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
const uint64_t period = period_ns();
|
||||
if (!period) return even;
|
||||
if (g_layer_timing) return layer_phase(index, count, period);
|
||||
if (!g_pair_interval_ns) return even;
|
||||
const double span = static_cast<double>(g_pair_interval_ns) +
|
||||
(static_cast<double>(count) - static_cast<double>(g_prev_count)) * static_cast<double>(period);
|
||||
if (span <= static_cast<double>(period) * (count + 1)) return even;
|
||||
const double phase = 1.0 - static_cast<double>(count - index) * static_cast<double>(period) / span;
|
||||
return static_cast<float>(std::clamp(phase, 0.05, 0.95));
|
||||
}
|
||||
|
||||
void load_device_functions() {
|
||||
if (g_gipa && g_instance) {
|
||||
g_GetPhysicalDeviceMemoryProperties =
|
||||
reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(
|
||||
g_gipa(g_instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
g_GetPhysicalDeviceFormatProperties =
|
||||
reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(
|
||||
g_gipa(g_instance, "vkGetPhysicalDeviceFormatProperties"));
|
||||
}
|
||||
if (!g_gdpa || !g_device) return;
|
||||
#define LOAD(name) g_##name = reinterpret_cast<PFN_vk##name>(g_gdpa(g_device, "vk" #name))
|
||||
LOAD(CreateImage);
|
||||
LOAD(DestroyImage);
|
||||
LOAD(CreateImageView);
|
||||
LOAD(DestroyImageView);
|
||||
LOAD(GetImageMemoryRequirements);
|
||||
LOAD(AllocateMemory);
|
||||
LOAD(FreeMemory);
|
||||
LOAD(BindImageMemory);
|
||||
LOAD(CmdPipelineBarrier);
|
||||
LOAD(CmdCopyImage);
|
||||
LOAD(DeviceWaitIdle);
|
||||
#undef LOAD
|
||||
}
|
||||
|
||||
void clear_history_state() {
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
g_pair_pending = false;
|
||||
g_current = VK_NULL_HANDLE;
|
||||
g_current_view = VK_NULL_HANDLE;
|
||||
g_current_sequence = 0;
|
||||
}
|
||||
|
||||
void destroy_history() {
|
||||
if (g_device) {
|
||||
if (g_history_view && g_DestroyImageView) g_DestroyImageView(g_device, g_history_view, nullptr);
|
||||
if (g_history && g_DestroyImage) g_DestroyImage(g_device, g_history, nullptr);
|
||||
if (g_history_memory && g_FreeMemory) g_FreeMemory(g_device, g_history_memory, nullptr);
|
||||
}
|
||||
g_history = VK_NULL_HANDLE;
|
||||
g_history_view = VK_NULL_HANDLE;
|
||||
g_history_memory = VK_NULL_HANDLE;
|
||||
g_width = g_height = 0;
|
||||
g_format = VK_FORMAT_UNDEFINED;
|
||||
g_history_layout_defined = false;
|
||||
clear_history_state();
|
||||
}
|
||||
|
||||
uint32_t find_memory_type(uint32_t bits) {
|
||||
uint32_t fallback = UINT32_MAX;
|
||||
for (uint32_t i = 0; i < g_memory_properties.memoryTypeCount; ++i) {
|
||||
if ((bits & (1u << i)) == 0) continue;
|
||||
const auto flags = g_memory_properties.memoryTypes[i].propertyFlags;
|
||||
if (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) return i;
|
||||
if (fallback == UINT32_MAX) fallback = i;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
bool make_history(uint32_t width, uint32_t height, VkFormat format) {
|
||||
if (!g_CreateImage || !g_GetImageMemoryRequirements || !g_AllocateMemory ||
|
||||
!g_BindImageMemory || !g_CreateImageView || !g_GetPhysicalDeviceMemoryProperties) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "Vulkan image functions unavailable");
|
||||
return false;
|
||||
}
|
||||
VkImageCreateInfo image_info{};
|
||||
image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
image_info.imageType = VK_IMAGE_TYPE_2D;
|
||||
image_info.format = format;
|
||||
image_info.extent = {width, height, 1};
|
||||
image_info.mipLevels = 1;
|
||||
image_info.arrayLayers = 1;
|
||||
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
if (g_CreateImage(g_device, &image_info, nullptr, &g_history) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not create temporal history image");
|
||||
return false;
|
||||
}
|
||||
|
||||
VkMemoryRequirements requirements{};
|
||||
g_GetImageMemoryRequirements(g_device, g_history, &requirements);
|
||||
const uint32_t memory_index = find_memory_type(requirements.memoryTypeBits);
|
||||
if (memory_index == UINT32_MAX) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "no compatible memory for temporal history");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
VkMemoryAllocateInfo allocation{};
|
||||
allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
allocation.allocationSize = requirements.size;
|
||||
allocation.memoryTypeIndex = memory_index;
|
||||
if (g_AllocateMemory(g_device, &allocation, nullptr, &g_history_memory) != VK_SUCCESS ||
|
||||
g_BindImageMemory(g_device, g_history, g_history_memory, 0) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not allocate temporal history memory");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo view_info{};
|
||||
view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
view_info.image = g_history;
|
||||
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
view_info.format = format;
|
||||
view_info.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
if (g_CreateImageView(g_device, &view_info, nullptr, &g_history_view) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not create temporal history view");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
g_width = width;
|
||||
g_height = height;
|
||||
g_format = format;
|
||||
g_history_layout_defined = false;
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
clear_history_state();
|
||||
return true;
|
||||
}
|
||||
|
||||
void copy_current_to_history(VkCommandBuffer cmd, VkImage source,
|
||||
uint32_t width, uint32_t height, uint64_t sequence) {
|
||||
if (!g_history || !source || !g_CmdPipelineBarrier || !g_CmdCopyImage) return;
|
||||
VkImageMemoryBarrier before{};
|
||||
before.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
const bool layout_defined = g_history_layout_defined || g_history_recorded_pending;
|
||||
before.srcAccessMask = layout_defined ? VK_ACCESS_SHADER_READ_BIT : 0;
|
||||
before.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
before.oldLayout = layout_defined ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
before.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
before.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.image = g_history;
|
||||
before.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd,
|
||||
layout_defined ? VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &before);
|
||||
|
||||
VkImageCopy region{};
|
||||
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.extent = {width, height, 1};
|
||||
g_CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_GENERAL, g_history, VK_IMAGE_LAYOUT_GENERAL, 1, ®ion);
|
||||
|
||||
VkImageMemoryBarrier after{};
|
||||
after.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
after.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
after.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.image = g_history;
|
||||
after.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &after);
|
||||
g_history_recorded_pending = true;
|
||||
g_history_recorded_sequence = sequence;
|
||||
g_pair_pending = false;
|
||||
}
|
||||
|
||||
void copy_current_to_output(VkCommandBuffer cmd, VkImage output, uint32_t width, uint32_t height) {
|
||||
if (!g_current || !output || !g_CmdPipelineBarrier || !g_CmdCopyImage) return;
|
||||
VkImageMemoryBarrier before{};
|
||||
before.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
before.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
|
||||
before.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
before.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
before.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
before.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.image = output;
|
||||
before.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &before);
|
||||
VkImageCopy region{};
|
||||
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.extent = {width, height, 1};
|
||||
g_CmdCopyImage(cmd, g_current, VK_IMAGE_LAYOUT_GENERAL,
|
||||
output, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||
VkImageMemoryBarrier after{};
|
||||
after.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
after.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT;
|
||||
after.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
after.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.image = output;
|
||||
after.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &after);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
void zfg_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance instance,
|
||||
VkPhysicalDevice physical_device, VkDevice device,
|
||||
uint32_t api_version, int synchronization2_enabled,
|
||||
int extended_storage_formats_enabled) {
|
||||
g_gipa = gipa;
|
||||
g_instance = instance;
|
||||
g_physical = physical_device;
|
||||
g_device = device;
|
||||
g_api_version = api_version;
|
||||
g_synchronization2 = synchronization2_enabled != 0;
|
||||
g_extended_formats = extended_storage_formats_enabled != 0;
|
||||
g_gdpa = g_gipa && g_instance
|
||||
? reinterpret_cast<PFN_vkGetDeviceProcAddr>(g_gipa(g_instance, "vkGetDeviceProcAddr"))
|
||||
: nullptr;
|
||||
load_device_functions();
|
||||
if (g_GetPhysicalDeviceMemoryProperties && g_physical)
|
||||
g_GetPhysicalDeviceMemoryProperties(g_physical, &g_memory_properties);
|
||||
g_ready = g_device != VK_NULL_HANDLE;
|
||||
g_supported = g_ready && g_api_version >= VK_API_VERSION_1_3 &&
|
||||
g_synchronization2 && g_extended_formats;
|
||||
g_failed = false;
|
||||
std::snprintf(g_reason, sizeof(g_reason), "%s", g_supported ? "available" :
|
||||
"requires Vulkan 1.3, synchronization2 and shaderStorageImageExtendedFormats");
|
||||
}
|
||||
|
||||
void zfg_device_lost(void) {
|
||||
g_interpolator.reset();
|
||||
destroy_history();
|
||||
g_gipa = nullptr; g_gdpa = nullptr;
|
||||
g_instance = VK_NULL_HANDLE; g_physical = VK_NULL_HANDLE; g_device = VK_NULL_HANDLE;
|
||||
g_ready = g_supported = g_failed = false;
|
||||
g_synchronization2 = g_extended_formats = false;
|
||||
g_api_version = VK_API_VERSION_1_0;
|
||||
g_GetPhysicalDeviceMemoryProperties = nullptr;
|
||||
g_GetPhysicalDeviceFormatProperties = nullptr;
|
||||
g_CreateImage = nullptr; g_DestroyImage = nullptr;
|
||||
g_CreateImageView = nullptr; g_DestroyImageView = nullptr;
|
||||
g_GetImageMemoryRequirements = nullptr; g_AllocateMemory = nullptr;
|
||||
g_FreeMemory = nullptr; g_BindImageMemory = nullptr;
|
||||
g_CmdPipelineBarrier = nullptr; g_CmdCopyImage = nullptr; g_DeviceWaitIdle = nullptr;
|
||||
g_memory_properties = {};
|
||||
std::snprintf(g_reason, sizeof(g_reason), "device lost");
|
||||
}
|
||||
|
||||
int zfg_caps_ok(void) { return g_supported ? 1 : 0; }
|
||||
const char *zfg_caps_reason(void) { return g_reason; }
|
||||
|
||||
int zfg_start(void) {
|
||||
if (!g_supported || !g_ready) return 0;
|
||||
if (g_interpolator) return 1;
|
||||
zerofg::CreateInfo info{};
|
||||
info.vulkan.instance = g_instance;
|
||||
info.vulkan.physical_device = g_physical;
|
||||
info.vulkan.device = g_device;
|
||||
info.vulkan.get_instance_proc_addr = g_gipa;
|
||||
info.mode = zerofg::Mode::kReallyZero;
|
||||
info.backend = zerofg::Backend::kCompat;
|
||||
info.frame_context_count = 4;
|
||||
info.capabilities.effective_api_version = g_api_version;
|
||||
info.capabilities.synchronization2_enabled = g_synchronization2;
|
||||
info.capabilities.shader_storage_image_extended_formats_enabled = g_extended_formats;
|
||||
zerofg::Status status = zerofg::Status::kSuccess;
|
||||
g_interpolator = zerofg::Interpolator::Create(info, &status);
|
||||
if (!g_interpolator) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "interpolator creation failed (%d)", (int)status);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
g_failed = false;
|
||||
ZFG_LOG("ReallyZero engine ready (Compat backend)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void zfg_stop(void) {
|
||||
g_interpolator.reset();
|
||||
destroy_history();
|
||||
reset_pacing();
|
||||
g_last_sequence = 0;
|
||||
g_failed = false;
|
||||
}
|
||||
int zfg_unavailable(void) { return g_failed || !g_interpolator ? 1 : 0; }
|
||||
|
||||
int zfg_format_ok(VkFormat format) {
|
||||
if (!g_supported || !g_GetPhysicalDeviceFormatProperties || format == VK_FORMAT_UNDEFINED) return 0;
|
||||
VkFormatProperties input{};
|
||||
g_GetPhysicalDeviceFormatProperties(g_physical, format, &input);
|
||||
const VkFormatFeatureFlags sampled =
|
||||
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
if ((input.optimalTilingFeatures & sampled) != sampled) return 0;
|
||||
if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
|
||||
return (input.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0;
|
||||
VkFormatProperties internal{};
|
||||
g_GetPhysicalDeviceFormatProperties(g_physical, VK_FORMAT_A2B10G10R10_UNORM_PACK32, &internal);
|
||||
const VkFormatFeatureFlags needed = VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT;
|
||||
return (input.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT) != 0 &&
|
||||
(internal.optimalTilingFeatures & needed) == needed;
|
||||
}
|
||||
|
||||
int zfg_prepare(uint32_t width, uint32_t height, VkFormat format) {
|
||||
if (!g_interpolator || g_failed || !width || !height) return 0;
|
||||
if (!zfg_format_ok(format)) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "unsupported input/output format %d", (int)format);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
if (g_width == width && g_height == height && g_format == format && g_history) return 1;
|
||||
// ReallyZero's Resize accepts 64..16384 per side: refuse this frame only, before touching the
|
||||
// engine's state, so a supported size later still generates.
|
||||
if (width < 64 || height < 64 || width > 16384 || height > 16384) return 0;
|
||||
if (g_DeviceWaitIdle) g_DeviceWaitIdle(g_device);
|
||||
destroy_history();
|
||||
const zerofg::Status resized = g_interpolator->Resize(width, height, format, format);
|
||||
if (resized != zerofg::Status::kSuccess) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "resize failed (%d)", (int)resized);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
if (!make_history(width, height, format)) {
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
ZFG_LOG("prepared %ux%u format %d", width, height, (int)format);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void zfg_configure(uint32_t multiplier, float refresh_hz) {
|
||||
g_multiplier = std::clamp<uint32_t>(multiplier, 2, 4);
|
||||
g_refresh_hz = refresh_hz > 1.0f ? refresh_hz : 0.0f;
|
||||
}
|
||||
|
||||
void zfg_set_layer_timing(int layer) { g_layer_timing = layer != 0; }
|
||||
|
||||
void zfg_set_phases(const float *phases, uint32_t count) {
|
||||
g_external_count = phases ? std::min<uint32_t>(count, static_cast<uint32_t>(g_external_phases.size())) : 0;
|
||||
for (uint32_t i = 0; i < g_external_count; i++) g_external_phases[i] = phases[i];
|
||||
}
|
||||
|
||||
float zfg_phase(uint32_t index, uint32_t count) { return pair_phase(index, count); }
|
||||
|
||||
uint32_t zfg_plan(uint32_t capacity, uint64_t sequence) {
|
||||
if (!g_interpolator || g_failed) return 0;
|
||||
note_sequence(sequence);
|
||||
if (!g_history_valid || sequence <= g_history_sequence || !g_pair_interval_ns) return 0;
|
||||
return pair_capacity(std::min<uint32_t>({capacity, 3u, g_multiplier - 1}));
|
||||
}
|
||||
|
||||
void zfg_telemetry(float *generated, float *source_rate) {
|
||||
const uint64_t typical = typical_interval_ns();
|
||||
*generated = static_cast<float>(g_pair_count);
|
||||
*source_rate = typical ? static_cast<float>(1e9 / static_cast<double>(typical)) : 0.0f;
|
||||
}
|
||||
|
||||
void zfg_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t width, uint32_t height, VkFormat format,
|
||||
uint64_t sequence, uint32_t generations) {
|
||||
g_pair_pending = false;
|
||||
g_fallback_outputs.fill(false);
|
||||
if (!g_interpolator || g_failed || !source || !g_history ||
|
||||
format != g_format || width != g_width || height != g_height) return;
|
||||
if (sequence > g_history_sequence) {
|
||||
g_prev_count = g_pair_count;
|
||||
g_pair_count = generations;
|
||||
}
|
||||
if (generations == 0 || !g_history_valid || sequence <= g_history_sequence) {
|
||||
copy_current_to_history(cmd, source, width, height, sequence);
|
||||
return;
|
||||
}
|
||||
if (!source_view) return;
|
||||
g_current = source;
|
||||
g_current_view = source_view;
|
||||
g_current_sequence = sequence;
|
||||
g_pair_pending = true;
|
||||
g_pair_anonymous = g_record_stale ? (kAnonymousSequence | ++g_anonymous_count) : 0;
|
||||
g_record_stale = false;
|
||||
}
|
||||
|
||||
void zfg_generate(VkCommandBuffer cmd, uint32_t index, uint32_t count,
|
||||
VkImage output, VkImageView output_view, uint32_t width, uint32_t height) {
|
||||
if (!g_pair_pending || !g_interpolator || !g_history_valid || index >= count || !output || !output_view) return;
|
||||
const float phase = pair_phase(index, count);
|
||||
zerofg::Image previous{};
|
||||
previous.image = g_history; previous.view = g_history_view;
|
||||
previous.layout = VK_IMAGE_LAYOUT_GENERAL; previous.format = g_format;
|
||||
previous.width = g_width; previous.height = g_height;
|
||||
previous.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
previous.sequence = g_history_sequence;
|
||||
zerofg::Image current{};
|
||||
current.image = g_current; current.view = g_current_view;
|
||||
current.layout = VK_IMAGE_LAYOUT_GENERAL; current.format = g_format;
|
||||
current.width = g_width; current.height = g_height;
|
||||
current.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
current.sequence = g_current_sequence;
|
||||
zerofg::Image result{};
|
||||
result.image = output; result.view = output_view;
|
||||
result.layout = VK_IMAGE_LAYOUT_GENERAL; result.format = g_format;
|
||||
result.width = width; result.height = height;
|
||||
result.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
if (g_pair_anonymous) previous.sequence = g_pair_anonymous;
|
||||
g_interpolate_uncommitted = true;
|
||||
|
||||
const zerofg::Status status =
|
||||
g_interpolator->Interpolate(cmd, index, previous, current, phase, result);
|
||||
if (status != zerofg::Status::kSuccess) {
|
||||
ZFG_ERR("interpolation status %d; copying the real frame as fallback", (int)status);
|
||||
g_fallback_outputs[index] = true;
|
||||
copy_current_to_output(cmd, output, width, height);
|
||||
}
|
||||
if (index + 1 >= count) {
|
||||
copy_current_to_history(cmd, g_current, width, height, g_current_sequence);
|
||||
g_pair_pending = false;
|
||||
}
|
||||
}
|
||||
|
||||
void zfg_commit_history_update(void) {
|
||||
g_interpolate_uncommitted = false;
|
||||
if (!g_history_recorded_pending) return;
|
||||
g_history_layout_defined = true;
|
||||
g_history_valid = true;
|
||||
g_history_sequence = g_history_recorded_sequence;
|
||||
g_history_recorded_pending = false;
|
||||
}
|
||||
|
||||
void zfg_discard_history_update(void) {
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
if (g_interpolate_uncommitted) g_record_stale = true;
|
||||
g_interpolate_uncommitted = false;
|
||||
g_pair_pending = false;
|
||||
}
|
||||
|
||||
void zfg_forget_targets(void) {
|
||||
g_pair_pending = false;
|
||||
if (g_interpolate_uncommitted) g_record_stale = true;
|
||||
g_interpolate_uncommitted = false;
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
reset_pacing();
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef FRAMEGEN_ZEROFG_H
|
||||
#define FRAMEGEN_ZEROFG_H
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void zfg_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance instance,
|
||||
VkPhysicalDevice physical_device, VkDevice device,
|
||||
uint32_t api_version, int synchronization2_enabled,
|
||||
int extended_storage_formats_enabled);
|
||||
void zfg_device_lost(void);
|
||||
int zfg_caps_ok(void);
|
||||
const char *zfg_caps_reason(void);
|
||||
int zfg_start(void);
|
||||
void zfg_stop(void);
|
||||
int zfg_unavailable(void);
|
||||
int zfg_format_ok(VkFormat format);
|
||||
int zfg_prepare(uint32_t width, uint32_t height, VkFormat format);
|
||||
void zfg_configure(uint32_t multiplier, float refresh_hz);
|
||||
void zfg_set_layer_timing(int layer);
|
||||
void zfg_set_phases(const float *phases, uint32_t count);
|
||||
float zfg_phase(uint32_t index, uint32_t count);
|
||||
uint32_t zfg_plan(uint32_t capacity, uint64_t sequence);
|
||||
void zfg_telemetry(float *generated, float *source_rate);
|
||||
void zfg_process(VkCommandBuffer command_buffer, VkImage source, VkImageView source_view,
|
||||
uint32_t width, uint32_t height, VkFormat format,
|
||||
uint64_t sequence, uint32_t generations);
|
||||
void zfg_generate(VkCommandBuffer command_buffer, uint32_t index, uint32_t count,
|
||||
VkImage output, VkImageView output_view,
|
||||
uint32_t width, uint32_t height);
|
||||
void zfg_forget_targets(void);
|
||||
void zfg_commit_history_update(void);
|
||||
void zfg_discard_history_update(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -58,7 +58,6 @@ static struct {
|
||||
void (*reparent)(ASurfaceTransaction *, ASurfaceControl *, ASurfaceControl *);
|
||||
void (*setOnComplete)(ASurfaceTransaction *, void *, sc_complete_fn);
|
||||
int (*prevReleaseFence)(ASurfaceTransactionStats *, ASurfaceControl *);
|
||||
int (*presentFence)(ASurfaceTransactionStats *);
|
||||
void (*setFrameRate)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t);
|
||||
void (*setFrameRateStrategy)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t, int8_t);
|
||||
void (*setBufferDataSpace)(ASurfaceTransaction *, ASurfaceControl *, int32_t);
|
||||
@@ -103,7 +102,6 @@ static int load_api(void) {
|
||||
SYM(reparent, "ASurfaceTransaction_reparent");
|
||||
SYM(setOnComplete, "ASurfaceTransaction_setOnComplete");
|
||||
SYM(prevReleaseFence, "ASurfaceTransactionStats_getPreviousReleaseFenceFd");
|
||||
SYM(presentFence, "ASurfaceTransactionStats_getPresentFenceFd");
|
||||
SYM(setFrameRate, "ASurfaceTransaction_setFrameRate");
|
||||
SYM(setFrameRateStrategy, "ASurfaceTransaction_setFrameRateWithChangeStrategy");
|
||||
SYM(setBufferDataSpace, "ASurfaceTransaction_setBufferDataSpace");
|
||||
@@ -267,33 +265,7 @@ static int64_t cadence_target(int64_t now, int64_t earliest, int64_t period) {
|
||||
return target;
|
||||
}
|
||||
|
||||
static int64_t g_planned_next_ns;
|
||||
|
||||
void sc_layer_set_planned(int64_t present_ns) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
g_planned_next_ns = present_ns;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
void sc_layer_timeline(int64_t *present_ns, int64_t *period_ns) {
|
||||
pthread_mutex_lock(&g_timeline_lock);
|
||||
*present_ns = g_timeline_present_ns;
|
||||
*period_ns = g_timeline_period_ns;
|
||||
pthread_mutex_unlock(&g_timeline_lock);
|
||||
}
|
||||
|
||||
void sc_layer_cadence_info(int64_t *gap_ns, int *group_frames) {
|
||||
if (gap_ns) *gap_ns = g_cadence_gap_ns;
|
||||
if (group_frames) *group_frames = g_group_frames;
|
||||
}
|
||||
|
||||
static void apply_present_time(ASurfaceTransaction *tx, int game) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
const int64_t planned = game ? g_planned_next_ns : 0;
|
||||
if (game) {
|
||||
g_planned_next_ns = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (!api.setDesiredPresentTime) return;
|
||||
pthread_mutex_lock(&g_timeline_lock);
|
||||
const int64_t present = g_timeline_present_ns, deadline = g_timeline_deadline_ns, period = g_timeline_period_ns;
|
||||
@@ -313,9 +285,6 @@ static void apply_present_time(ASurfaceTransaction *tx, int game) {
|
||||
target = cadence_target(now, target, period);
|
||||
}
|
||||
if (game && g_group_frames > 1 && ++g_group_index >= g_group_frames) { g_group_index = 0; g_group_frames = 1; }
|
||||
if (planned > 0) {
|
||||
target = planned;
|
||||
}
|
||||
api.setDesiredPresentTime(tx, target - period / 2);
|
||||
}
|
||||
|
||||
@@ -924,9 +893,7 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d
|
||||
int translucent) {
|
||||
struct slot *s = &l->slots[idx];
|
||||
ASurfaceTransaction *tx = api.txCreate();
|
||||
if (!tx) {
|
||||
return -1;
|
||||
}
|
||||
if (!tx) return -1;
|
||||
const int was_shown = l->shown;
|
||||
const int32_t ds_applied = l->ds_applied;
|
||||
const uint32_t md_applied = l->md_applied;
|
||||
@@ -1138,7 +1105,6 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
const int deep = hf && !hf->tonemap;
|
||||
if (hf) composed = 1;
|
||||
vkp_framegen_set_paced_route(composed);
|
||||
if (hf && hf->tonemap) color = NULL;
|
||||
int n = vkp_pass_begin_generate(scene_w, scene_h, draws, n_draws, hf, &rw, &rh);
|
||||
if (n < 0) return -1;
|
||||
@@ -1148,7 +1114,7 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
if (!mapped) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
idx[VKP_FG_MAX_GENERATIONS] = deep ? take_hdr_slot(l, rw, rh, &first_fd)
|
||||
: take_free_slot(l, rw, rh, AHB_RGBA8, &first_fd);
|
||||
if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); vkp_framegen_pacer_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
pthread_mutex_lock(&g_lock);
|
||||
l->slots[idx[VKP_FG_MAX_GENERATIONS]].busy = 1;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
@@ -1170,18 +1136,13 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
if (!have_fd) { first_fd = fd; have_fd = 1; }
|
||||
}
|
||||
if (vkp_pass_copy_generated(dst, m, real, first_fd) != 0) {
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, 0, m);
|
||||
if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
return -1;
|
||||
}
|
||||
g_group_frames = m + 1;
|
||||
for (int k = 0; k < m; k++) {
|
||||
int64_t planned;
|
||||
vkp_framegen_output_planned(k, m, &planned);
|
||||
sc_layer_set_planned(planned);
|
||||
if (present_slot(l, idx[k], r, color, 0) == 0) continue;
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, k, m);
|
||||
if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
g_group_index = 0;
|
||||
@@ -1190,11 +1151,7 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
}
|
||||
vkp_framegen_presented(m);
|
||||
if (real) {
|
||||
int64_t planned;
|
||||
vkp_framegen_output_planned(m, m, &planned);
|
||||
sc_layer_set_planned(planned);
|
||||
if (present_slot(l, idx[VKP_FG_MAX_GENERATIONS], r, color, 0) != 0) {
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
g_group_index = 0;
|
||||
g_group_frames = 1;
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
#include <stdint.h>
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct vkp_image;
|
||||
struct vkp_draw;
|
||||
struct droiddeck_color;
|
||||
@@ -55,16 +51,7 @@ void sc_layer_window_gone(void);
|
||||
|
||||
void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns);
|
||||
void sc_layer_aim_take(unsigned *next, unsigned *later, unsigned *even);
|
||||
/* The refresh the next game-layer frame is timed for, instead of the layer's own spacing (0: the layer's). */
|
||||
void sc_layer_set_planned(int64_t present_ns);
|
||||
/* The display's frame timeline: the next expected present and the refresh period (0 until known). */
|
||||
void sc_layer_timeline(int64_t *present_ns, int64_t *period_ns);
|
||||
void sc_layer_cadence_info(int64_t *gap_ns, int *group_frames);
|
||||
unsigned sc_layer_frames_take(void);
|
||||
unsigned sc_layer_drops_take(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "effects_chain.h"
|
||||
#include "cardboard.h"
|
||||
#include "framegen_bridge.h"
|
||||
#include "framegen_zerofg.h"
|
||||
#include "hdr_compose.h"
|
||||
#include "blend_pass.h"
|
||||
#include "gpu_busy.h"
|
||||
@@ -605,10 +604,6 @@ static void update_map(int scene_w, int scene_h) {
|
||||
float min_y = (float)g_map.ry + g_map.rh - image_h;
|
||||
if (g_map.off_y < min_y) g_map.off_y = min_y;
|
||||
if (g_map.off_y > g_map.ry) g_map.off_y = (float)g_map.ry;
|
||||
} else if (align == VKP_ALIGN_PICTURE_TOP) {
|
||||
g_map.off_y = 0;
|
||||
} else if (align == VKP_ALIGN_PICTURE_BOTTOM) {
|
||||
g_map.off_y = H - image_h;
|
||||
} else {
|
||||
g_map.off_y = (float)g_map.ry + (g_map.rh - image_h) * 0.5f;
|
||||
}
|
||||
@@ -2769,8 +2764,8 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
const int upscale_w = (int)(scene_w * g_map.kx + 0.5f);
|
||||
const int upscale_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
const int post_upscale = fx && fg && !hf && !cb && vkp_effects_upscaling() &&
|
||||
(upscale_w > input_w || upscale_h > input_h) &&
|
||||
vkp_effects_prepare_generated(input_w, input_h, upscale_w, upscale_h);
|
||||
vkp_effects_prepare_generated() &&
|
||||
(upscale_w > input_w || upscale_h > input_h);
|
||||
if (post_upscale) {
|
||||
static int last_input_w, last_input_h, last_output_w, last_output_h;
|
||||
if (input_w != last_input_w || input_h != last_input_h ||
|
||||
@@ -2900,7 +2895,6 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
|
||||
if (!(pass && fx)) release_external_client_draws(cmd, draws, n);
|
||||
int ngen = 0;
|
||||
int history_staged = 0;
|
||||
VkImage gens[VKP_FG_MAX_GENERATIONS] = {VK_NULL_HANDLE};
|
||||
VkImage result = scene_img;
|
||||
int rw = input_w, rh = input_h;
|
||||
@@ -2939,8 +2933,6 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
0, 0, NULL, 0, NULL, 1, &b_general);
|
||||
|
||||
if (fg) {
|
||||
vkp_framegen_set_layer_timing(0);
|
||||
history_staged = 1;
|
||||
ngen = vkp_framegen_run(cmd, result, VK_NULL_HANDLE, rw, rh, scene_fmt, gens);
|
||||
if (ngen < 0) ngen = 0;
|
||||
if (ngen > VKP_FG_MAX_GENERATIONS) ngen = VKP_FG_MAX_GENERATIONS;
|
||||
@@ -2966,10 +2958,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
/* Teardown may have retained this frame's pending work, or
|
||||
* acquire may have reported real device loss. Neither permits
|
||||
* a completion-marker submit or another fence wait. */
|
||||
if (g_dev_state != 1) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
if (g_dev_state != 1) return -1;
|
||||
droiddeck_log("framegen", "present %d/%d: no swapchain image; the frame ends early", k + 1, presents);
|
||||
pr = VK_ERROR_OUT_OF_DATE_KHR;
|
||||
break;
|
||||
@@ -2993,7 +2982,6 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
if (img >= g_rnd_count || !g_rnds[img]) {
|
||||
droiddeck_log("error", "present: image index %u exceeds semaphore count %u",
|
||||
img, g_rnd_count);
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
destroy_swapchain();
|
||||
return -1;
|
||||
}
|
||||
@@ -3002,17 +2990,12 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
.pCommandBuffers = &g_cmds[k], .signalSemaphoreCount = 1, .pSignalSemaphores = &g_rnds[img]};
|
||||
VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, last ? g_fence : VK_NULL_HANDLE);
|
||||
if (qr != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
if (qr == VK_ERROR_DEVICE_LOST) device_lost("submit");
|
||||
else LOGE("present: submit %d/%d failed (%d)", k + 1, presents, (int)qr);
|
||||
if (g_dev_state != -2) destroy_swapchain();
|
||||
return -1;
|
||||
}
|
||||
fence_submitted = last;
|
||||
if (k == 0 && history_staged) {
|
||||
zfg_commit_history_update();
|
||||
history_staged = 0;
|
||||
}
|
||||
VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &g_rnds[img], .swapchainCount = 1,
|
||||
.pSwapchains = &g_swapchain, .pImageIndices = &img};
|
||||
@@ -3020,37 +3003,21 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
pr = g_vk.QueuePresentKHR(g_queue, &pi);
|
||||
perf_add(&g_perf.present_ns, &g_perf.present_max_ns, &g_perf.presents, perf_now() - t_pres);
|
||||
if (k < ngen) presented_gen++;
|
||||
if (pr == VK_ERROR_DEVICE_LOST) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
device_lost("present");
|
||||
return -1;
|
||||
}
|
||||
if (pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; }
|
||||
if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) break;
|
||||
}
|
||||
if (!fence_submitted) {
|
||||
VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
VkResult marker = g_vk.QueueSubmit(g_queue, 1, &si, g_fence);
|
||||
if (marker != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
if (marker == VK_ERROR_DEVICE_LOST) device_lost("frame completion submit");
|
||||
else quarantine_pending_work(marker, "frame completion submit");
|
||||
return -1; /* no fence was submitted; never wait on its unsignalled state */
|
||||
}
|
||||
if (history_staged) {
|
||||
zfg_discard_history_update();
|
||||
history_staged = 0;
|
||||
}
|
||||
}
|
||||
VkResult fr = timed_wait(g_fence, UINT64_MAX);
|
||||
if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
device_lost("present");
|
||||
return -1;
|
||||
}
|
||||
if (fr != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; }
|
||||
if (fr != VK_SUCCESS) return -1;
|
||||
vkp_effects_release_generated_sources();
|
||||
if (fg) vkp_framegen_presented(presented_gen);
|
||||
if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) {
|
||||
@@ -3402,9 +3369,6 @@ static struct {
|
||||
int active;
|
||||
VkImage result;
|
||||
int rw, rh;
|
||||
/* The layer buffers' size: rw x rh, or the spatial filter's output when it runs on each frame after generation. */
|
||||
int ow, oh;
|
||||
int post_upscale;
|
||||
int ngen;
|
||||
VkImage gens[VKP_FG_MAX_GENERATIONS];
|
||||
} g_pass;
|
||||
@@ -3544,30 +3508,10 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
}
|
||||
|
||||
int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
g_pass.post_upscale = generate && !hf && vkp_effects_active() && vkp_effects_upscaling() &&
|
||||
(mapped_w > input_w || mapped_h > input_h) &&
|
||||
vkp_effects_prepare_generated(input_w, input_h, mapped_w, mapped_h);
|
||||
if (g_pass.post_upscale) {
|
||||
static int last_input_w, last_input_h, last_output_w, last_output_h;
|
||||
if (input_w != last_input_w || input_h != last_input_h || mapped_w != last_output_w || mapped_h != last_output_h) {
|
||||
droiddeck_log("framegen", "post-upscale on the display layer: interpolate %dx%d, spatial filter each "
|
||||
"frame to %dx%d", input_w, input_h, mapped_w, mapped_h);
|
||||
last_input_w = input_w; last_input_h = input_h;
|
||||
last_output_w = mapped_w; last_output_h = mapped_h;
|
||||
}
|
||||
}
|
||||
if (generate && !vkp_effects_sharpening()) { mapped_w = scene_w; mapped_h = scene_h; }
|
||||
g_pass.rw = input_w; g_pass.rh = input_h;
|
||||
if (g_pass.post_upscale) {
|
||||
g_pass.ow = (int)(scene_w * g_map.kx + 0.5f);
|
||||
g_pass.oh = (int)(scene_h * g_map.ky + 0.5f);
|
||||
g_pass.result = vkp_effects_run_before_generated(cmd, scene_img, input_w, input_h, &g_pass.rw, &g_pass.rh);
|
||||
} else {
|
||||
g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h,
|
||||
&g_pass.rw, &g_pass.rh);
|
||||
g_pass.ow = g_pass.rw;
|
||||
g_pass.oh = g_pass.rh;
|
||||
}
|
||||
g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h,
|
||||
&g_pass.rw, &g_pass.rh);
|
||||
effects_overlay_draws(cmd, g_pass.result, g_pass.rw, g_pass.rh, scene_w, scene_h,
|
||||
draws ? draws + overlay_start : NULL, n - overlay_start);
|
||||
release_external_client_draws(cmd, draws, n);
|
||||
@@ -3582,45 +3526,38 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &b);
|
||||
vkp_framegen_set_layer_timing(1);
|
||||
int ngen = vkp_framegen_run(cmd, g_pass.result, VK_NULL_HANDLE, g_pass.rw, g_pass.rh, scene_fmt, g_pass.gens);
|
||||
if (ngen < 0) ngen = 0;
|
||||
g_pass.ngen = ngen > VKP_FG_MAX_GENERATIONS ? VKP_FG_MAX_GENERATIONS : ngen;
|
||||
}
|
||||
g_pass.active = 1;
|
||||
if (rw) *rw = g_pass.ow;
|
||||
if (rh) *rh = g_pass.oh;
|
||||
if (rw) *rw = g_pass.rw;
|
||||
if (rh) *rh = g_pass.rh;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pass_finish(const VkImage *srcs, VkImageLayout src_layout, struct vkp_image *const *dsts, int n,
|
||||
int wait_fd) {
|
||||
if (!g_pass.active) { zfg_discard_history_update(); if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
if (!g_pass.active) { if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
g_pass.active = 0;
|
||||
if (g_dev_state != 1) { zfg_discard_history_update(); if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
VkCommandBuffer cmd = g_cmds[0];
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (dsts[i] && dsts[i]->blit_dst) continue;
|
||||
if (wait_fd >= 0) close(wait_fd);
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
const int gpu_wait = take_wait_fd(wait_fd);
|
||||
if (gpu_wait < 0) { zfg_discard_history_update(); g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
const int post_upscale = g_pass.post_upscale && src_layout == VK_IMAGE_LAYOUT_GENERAL;
|
||||
if (gpu_wait < 0) { g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct vkp_image *dst = dsts[i];
|
||||
VkImage src = srcs[i];
|
||||
int sw = g_pass.rw, sh = g_pass.rh;
|
||||
if (post_upscale)
|
||||
src = vkp_effects_run_generated(cmd, src, g_pass.rw, g_pass.rh, g_pass.ow, g_pass.oh, i, &sw, &sh);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {sw, sh, 1}},
|
||||
.srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}};
|
||||
blit_to_layer(cmd, src, src_layout, dst, &blit,
|
||||
(sw == dst->w && sh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
blit_to_layer(cmd, srcs[i], src_layout, dst, &blit,
|
||||
(g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
}
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
|
||||
@@ -3631,17 +3568,13 @@ static int pass_finish(const VkImage *srcs, VkImageLayout src_layout, struct vkp
|
||||
g_vk.ResetFences(g_dev, 1, &g_fence);
|
||||
VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, g_fence);
|
||||
if (qr != VK_SUCCESS) {
|
||||
zfg_discard_history_update();
|
||||
if (qr == VK_ERROR_DEVICE_LOST) device_lost("layer pass");
|
||||
else LOGE("layer: effects pass submit failed (%d)", (int)qr);
|
||||
return -1;
|
||||
}
|
||||
zfg_commit_history_update();
|
||||
VkResult fr = timed_wait(g_fence, 1000000000ULL);
|
||||
if (fr == VK_ERROR_DEVICE_LOST) { device_lost("layer pass"); return -1; }
|
||||
if (fr != VK_SUCCESS) { LOGE("layer: effects pass fence wait -> %s", vk_result_name(fr)); return -1; }
|
||||
if (post_upscale) vkp_effects_release_generated_sources();
|
||||
vkp_framegen_completed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3659,7 +3592,6 @@ int vkp_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_ima
|
||||
}
|
||||
|
||||
void vkp_pass_abort(void) {
|
||||
zfg_discard_history_update();
|
||||
if (!g_pass.active) return;
|
||||
g_pass.active = 0;
|
||||
if (g_dev_state == 1)
|
||||
|
||||
@@ -461,11 +461,6 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetZeroCopy(JNIEnv *
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "zero-copy layer mode %s%s", on ? "on" : "off", live ? " (live)" : "");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetMirrorCapture(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
droiddeck_host_mirror_capture(on ? 1 : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetDisplayBufferDriver(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
g_display_buffer_driver = on ? 1 : 0;
|
||||
@@ -921,42 +916,3 @@ JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeStreamFrames(JNIEnv *env, jclass clazz) {
|
||||
return (jint)droiddeck_stream_frames();
|
||||
}
|
||||
|
||||
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
extern int droiddeck_frame_worker_grant(int owner, pid_t pid, uint64_t expires, const char *path,
|
||||
uint64_t dev, uint64_t ino, uint64_t receipt);
|
||||
extern void droiddeck_frame_worker_revoke(int owner, int pid);
|
||||
#endif
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeEnabled(JNIEnv *env, jclass c) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
return JNI_TRUE;
|
||||
#else
|
||||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeGrant(JNIEnv *env, jclass c,
|
||||
jint owner, jint pid, jlong expires, jstring path, jlong dev, jlong ino, jlong start_ticks) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
if (!path || expires <= 0 || ino <= 0 || start_ticks <= 0) return JNI_FALSE;
|
||||
const char *name = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
if (!name) return JNI_FALSE;
|
||||
int granted = droiddeck_frame_worker_grant(owner, pid, (uint64_t)expires, name, (uint64_t)dev, (uint64_t)ino, (uint64_t)start_ticks);
|
||||
(*env)->ReleaseStringUTFChars(env, path, name);
|
||||
return granted ? JNI_TRUE : JNI_FALSE;
|
||||
#else
|
||||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeRevoke(JNIEnv *env, jclass c,
|
||||
jint owner, jint pid) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
droiddeck_frame_worker_revoke(owner, pid);
|
||||
#endif
|
||||
}
|
||||
@@ -52,7 +52,6 @@ import com.droiddeck.launcher.ui.ComponentsPage
|
||||
import com.droiddeck.launcher.session.GameSaves
|
||||
import com.droiddeck.launcher.session.SessionLogShare
|
||||
import com.droiddeck.launcher.session.SessionPaths
|
||||
import com.droiddeck.launcher.session.FullscreenMode
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SteamRepair
|
||||
import com.droiddeck.launcher.session.LaunchCoordinator
|
||||
@@ -191,6 +190,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var gamescopeRealtime by mutableStateOf(false)
|
||||
private var paceCores by mutableStateOf(true)
|
||||
private var gpuClockPin by mutableStateOf(false)
|
||||
private var prootNoSeccomp by mutableStateOf(false)
|
||||
private var prootFastPath by mutableStateOf(true)
|
||||
private var nativeUserland by mutableStateOf(true)
|
||||
private var desktopAsUser by mutableStateOf(false)
|
||||
private var cursorComposite by mutableStateOf(true)
|
||||
private var guestHostname by mutableStateOf(SessionPrefs.DEFAULT_GUEST_HOSTNAME)
|
||||
@@ -198,16 +200,14 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var phantomProcessStatus by mutableStateOf(PhantomProcessStatus.NOT_APPLICABLE)
|
||||
private var showPhantomGate by mutableStateOf(false)
|
||||
private var directAudio by mutableStateOf(false)
|
||||
private var picturePositionLandscape by mutableStateOf("center")
|
||||
private var picturePositionPortrait by mutableStateOf("top")
|
||||
private var picturePosition by mutableStateOf("center")
|
||||
private var integerScaling by mutableStateOf(false)
|
||||
private var stretch16x9 by mutableStateOf(false)
|
||||
private var avoidNotch by mutableStateOf(false)
|
||||
private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
||||
private var launcherOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER)
|
||||
private var homePage by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.HOME_PAGE_STEAM)
|
||||
private var launcherFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS)
|
||||
private var sessionFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS)
|
||||
private var launcherFullscreen by mutableStateOf(true)
|
||||
private var launcherFrost by mutableStateOf(false)
|
||||
private var frostWallpaper by mutableStateOf(true)
|
||||
private var frostCards by mutableStateOf(true)
|
||||
@@ -304,6 +304,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
protons.installExperimental { progress -> com.droiddeck.launcher.session.ExperimentalProtons.installFromFile(this, zip, progress) }
|
||||
}
|
||||
}
|
||||
private val pickLossless = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { importLossless(it) }
|
||||
}
|
||||
private val pickSaveZip = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
val then = onSavePicked.also { onSavePicked = null } ?: return@registerForActivityResult
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let(then)
|
||||
@@ -514,6 +517,17 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
bootMovieCustomName = com.droiddeck.launcher.session.BootMovie.customName(this)
|
||||
}
|
||||
|
||||
private fun importLossless(dll: File) {
|
||||
Thread({
|
||||
val message = Lossless.message(this, Lossless.import(this, dll))
|
||||
val state = Lossless.state(this)
|
||||
ui.post {
|
||||
lossless = state
|
||||
android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}, "lossless-import").start()
|
||||
}
|
||||
|
||||
private fun importSaves(name: String, game: () -> GameSaves.Game) {
|
||||
if (SessionState.running) {
|
||||
android.widget.Toast.makeText(this, R.string.main_saves_close_session, android.widget.Toast.LENGTH_LONG).show()
|
||||
@@ -611,7 +625,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var appScale by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.DEFAULT_SCALE)
|
||||
private var hdrOn by mutableStateOf(false)
|
||||
private var zeroCopyOn by mutableStateOf(true)
|
||||
private var producerAcquireFences by mutableStateOf(false)
|
||||
private var upscaler by mutableStateOf(0)
|
||||
private var upscaleSharpness by mutableStateOf(75)
|
||||
private var hdrReason by mutableStateOf<String?>(null)
|
||||
@@ -1087,7 +1100,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
} else {
|
||||
putExtra(SessionService.EXTRA_STEAM_URL,
|
||||
com.droiddeck.launcher.frontend.GameLaunchLink.steamUrl(game.gameIdString))
|
||||
putExtra(SessionService.EXTRA_FRONTEND_STEAM_GAME, true)
|
||||
}
|
||||
}
|
||||
.playing(game), steamSession = true)
|
||||
@@ -1365,12 +1377,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
orientation = SessionPrefs.orientation(this)
|
||||
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
|
||||
requestedOrientation = launcherOrientation
|
||||
launcherFullscreenMode = SessionPrefs.launcherFullscreenMode(this)
|
||||
sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this)
|
||||
applyLauncherFullscreen()
|
||||
homePage = com.droiddeck.launcher.core.AppUiPrefs.homePage(this)
|
||||
launcherFullscreenMode = SessionPrefs.launcherFullscreenMode(this)
|
||||
sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this)
|
||||
launcherFullscreen = SessionPrefs.launcherFullscreen(this)
|
||||
launcherFrost = SessionPrefs.launcherFrost(this)
|
||||
frostWallpaper = SessionPrefs.frostWallpaper(this)
|
||||
frostCards = SessionPrefs.frostCards(this)
|
||||
@@ -1485,8 +1493,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
orientation = orientation,
|
||||
launcherOrientation = launcherOrientation,
|
||||
homePage = homePage,
|
||||
launcherFullscreenMode = launcherFullscreenMode,
|
||||
sessionFullscreenMode = sessionFullscreenMode,
|
||||
launcherFullscreen = launcherFullscreen,
|
||||
launcherFrost = launcherFrost,
|
||||
frostWallpaper = frostWallpaper,
|
||||
frostCards = frostCards,
|
||||
@@ -1651,6 +1658,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
FrameGen.set(this, mode)
|
||||
frameGenLabel = FrameGen.label(this)
|
||||
},
|
||||
onImportLossless = {
|
||||
pickLossless.launch(InAppFilePicker.buildIntent(this, listOf("dll"), getString(R.string.lsfg_pick_title)))
|
||||
},
|
||||
onProtons = { openProtons() },
|
||||
onComponents = { focusContent -> openComponents(focusContent) },
|
||||
onGameComponents = { game -> openComponents(gameKey = game.profileKey) },
|
||||
@@ -1762,14 +1772,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
}, "delete-session-logs").start()
|
||||
},
|
||||
onClearLogs = { done ->
|
||||
onClearLogs = {
|
||||
Thread({
|
||||
val cleared = runCatching { SessionArtifacts.clearAll(this) }.getOrDefault(0)
|
||||
ui.post {
|
||||
android.widget.Toast.makeText(this,
|
||||
if (cleared == 0) getString(R.string.main_no_logs_to_clear) else resources.getQuantityString(R.plurals.main_logs_cleared, cleared, cleared),
|
||||
android.widget.Toast.LENGTH_SHORT).show()
|
||||
done()
|
||||
}
|
||||
}, "clear-logs").start()
|
||||
},
|
||||
@@ -1821,15 +1830,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
homePage = value
|
||||
},
|
||||
onControllerHaptics = { on -> SessionPrefs.setControllerHaptics(this, on); controllerHaptics = on },
|
||||
onLauncherFullscreenMode = { mode ->
|
||||
SessionPrefs.setLauncherFullscreenMode(this, mode)
|
||||
launcherFullscreenMode = mode
|
||||
onLauncherFullscreen = { on ->
|
||||
SessionPrefs.setLauncherFullscreen(this, on)
|
||||
launcherFullscreen = on
|
||||
applyLauncherFullscreen()
|
||||
},
|
||||
onSessionFullscreenMode = { mode ->
|
||||
SessionPrefs.setSessionFullscreenMode(this, mode)
|
||||
sessionFullscreenMode = mode
|
||||
},
|
||||
onLauncherFrost = { on ->
|
||||
SessionPrefs.setLauncherFrost(this, on)
|
||||
launcherFrost = on
|
||||
@@ -2161,13 +2166,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private fun frostShown(): Boolean =
|
||||
launcherFrost && frostWallpaper && frost.prepared && frost.available && theme != com.droiddeck.launcher.ui.Themes.TRUE_BLACK
|
||||
|
||||
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
applyLauncherFullscreen(newConfig)
|
||||
}
|
||||
|
||||
private fun applyLauncherFullscreen(config: android.content.res.Configuration = resources.configuration) {
|
||||
val launcherFullscreen = launcherFullscreenMode.hidesSystemBars(config.orientation)
|
||||
private fun applyLauncherFullscreen() {
|
||||
@Suppress("DEPRECATION")
|
||||
window.decorView.systemUiVisibility = if (launcherFullscreen) {
|
||||
(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
@@ -2381,10 +2380,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
refreshHomeAppState()
|
||||
}
|
||||
if (settingsMode == SessionService.MODE_STEAM) refreshFoundSteamLibraries()
|
||||
settingsMode?.let { mode ->
|
||||
hdrOn = SessionPrefs.hdr(this, mode)
|
||||
if (mode == SessionService.MODE_STEAM) loadPicturePositions()
|
||||
}
|
||||
settingsMode?.let { hdrOn = SessionPrefs.hdr(this, it) }
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false)
|
||||
@@ -2925,10 +2921,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
mode = mode, resolution = resolution, resolutionPortrait = resolutionPortrait,
|
||||
panelSize = com.droiddeck.launcher.session.SessionDisplay.panelSize(this),
|
||||
hdr = hdrOn, hdrReason = hdrReason, hdrDisplay = hdrDisplay, zeroCopy = zeroCopyOn,
|
||||
producerAcquireFences = producerAcquireFences.takeIf {
|
||||
mode == SessionService.MODE_STEAM &&
|
||||
com.droiddeck.launcher.runtime.FrameAcquireWorkerProbe.available(this)
|
||||
},
|
||||
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
|
||||
gpuDrivers = drivers.summary(),
|
||||
touchMode = touchMode,
|
||||
@@ -2943,8 +2935,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
backHold = backHold,
|
||||
backActionsInverted = backActionsInverted,
|
||||
directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null,
|
||||
picturePositionLandscape = picturePositionLandscape.takeIf { mode == SessionService.MODE_STEAM },
|
||||
picturePositionPortrait = picturePositionPortrait.takeIf { mode == SessionService.MODE_STEAM },
|
||||
picturePosition = if (mode == SessionService.MODE_STEAM) picturePosition else null,
|
||||
integerScaling = if (mode == SessionService.MODE_STEAM) integerScaling else null,
|
||||
stretch16x9 = if (mode == SessionService.MODE_STEAM) stretch16x9 else null,
|
||||
avoidNotch = if (mode == SessionService.MODE_STEAM) avoidNotch else null,
|
||||
@@ -2994,10 +2985,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
SessionPrefs.prefMode(SessionState.mode) == SessionPrefs.prefMode(mode))
|
||||
com.droiddeck.launcher.wayland.WaylandCompositor.nativeSetZeroCopy(on)
|
||||
},
|
||||
onProducerAcquireFences = {
|
||||
SessionPrefs.setProducerAcquireFences(this, it)
|
||||
producerAcquireFences = it
|
||||
},
|
||||
onGpuDrivers = { openComponents(focusContent = true, tab = com.droiddeck.launcher.ui.GPU_TAB) },
|
||||
onUpscaler = { m -> SessionPrefs.setUpscaler(this, m); upscaler = m },
|
||||
onUpscaleSharpness = { pct -> SessionPrefs.setUpscaleSharpness(this, pct); upscaleSharpness = pct },
|
||||
@@ -3021,10 +3008,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
backActionsInverted = inverted
|
||||
},
|
||||
onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on },
|
||||
onPicturePosition = { portrait, value ->
|
||||
SessionPrefs.setPicturePosition(this, portrait, value)
|
||||
if (portrait) picturePositionPortrait = value else picturePositionLandscape = value
|
||||
},
|
||||
onPicturePosition = { value -> SessionPrefs.setPicturePosition(this, value); picturePosition = value },
|
||||
onIntegerScaling = { on -> SessionPrefs.setIntegerScaling(this, on); integerScaling = on },
|
||||
onStretch16x9 = { on -> SessionPrefs.setStretch16x9(this, on); stretch16x9 = on },
|
||||
onAvoidNotch = { on -> SessionPrefs.setAvoidNotch(this, on); avoidNotch = on },
|
||||
@@ -3122,7 +3106,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
fsyncFirst = fsyncFirst,
|
||||
gamescopeRealtime = gamescopeRealtime,
|
||||
gpuClockPin = gpuClockPin,
|
||||
nativeDesktopAvailable = com.droiddeck.launcher.runtime.NativeGuest.nextSession(this), desktopAsUser = desktopAsUser, cursorComposite = cursorComposite,
|
||||
prootNoSeccomp = prootNoSeccomp, prootFastPath = prootFastPath, nativeUserland = nativeUserland, desktopAsUser = desktopAsUser, cursorComposite = cursorComposite,
|
||||
guestHostname = guestHostname, phantomWarning = phantomWarning,
|
||||
onClientOverride = { on -> SessionPrefs.setClientCpusOverride(this, on); clientOverride = on },
|
||||
onPaceCores = { on -> SessionPrefs.setPaceCores(this, on); paceCores = on },
|
||||
@@ -3136,6 +3120,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
onFsyncFirst = { on -> SessionPrefs.setFsyncFirst(this, on); fsyncFirst = on },
|
||||
onGamescopeRealtime = { on -> SessionPrefs.setGamescopeRealtime(this, on); gamescopeRealtime = on },
|
||||
onGpuClockPin = { on -> SessionPrefs.setGpuClockPin(this, on); gpuClockPin = on },
|
||||
onProotNoSeccomp = { on -> SessionPrefs.setProotNoSeccomp(this, on); prootNoSeccomp = on },
|
||||
onProotFastPath = { on -> SessionPrefs.setProotFastPath(this, on); prootFastPath = on },
|
||||
onNativeUserland = { on -> SessionPrefs.setNativeUserland(this, on); nativeUserland = on },
|
||||
onDesktopAsUser = { on -> SessionPrefs.setDesktopAsUser(this, on); desktopAsUser = on },
|
||||
onCursorComposite = { on -> SessionPrefs.setCursorComposite(this, on); cursorComposite = on },
|
||||
onGuestHostname = { name -> SessionPrefs.setGuestHostname(this, name) },
|
||||
@@ -3338,11 +3325,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
resolutionPortrait = SessionPrefs.resolutionStored(this, mode, panel, true)
|
||||
}
|
||||
|
||||
private fun loadPicturePositions() {
|
||||
picturePositionLandscape = SessionPrefs.picturePosition(this, portrait = false)
|
||||
picturePositionPortrait = SessionPrefs.picturePosition(this, portrait = true)
|
||||
}
|
||||
|
||||
private fun loadModeSettings(mode: String) {
|
||||
pipAutoEnter = SessionPrefs.pipAutoEnter(this)
|
||||
unfoldedControls = SessionPrefs.unfoldedControls(this)
|
||||
@@ -3364,7 +3346,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
loadBootMovie()
|
||||
hdrOn = SessionPrefs.hdr(this, mode)
|
||||
zeroCopyOn = SessionPrefs.zeroCopy(this, mode)
|
||||
producerAcquireFences = SessionPrefs.producerAcquireFences(this)
|
||||
upscaler = SessionPrefs.upscaler(this)
|
||||
upscaleSharpness = SessionPrefs.upscaleSharpness(this)
|
||||
hdrReason = com.droiddeck.launcher.wayland.HdrSupport.blocked(this)
|
||||
@@ -3378,7 +3359,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
backHold = SessionPrefs.backHold(this)
|
||||
backActionsInverted = SessionPrefs.backActionsInverted(this)
|
||||
directAudio = SessionPrefs.directAudio(this)
|
||||
loadPicturePositions()
|
||||
picturePosition = SessionPrefs.picturePosition(this)
|
||||
integerScaling = SessionPrefs.integerScaling(this)
|
||||
stretch16x9 = SessionPrefs.stretch16x9(this)
|
||||
avoidNotch = SessionPrefs.avoidNotch(this)
|
||||
@@ -3458,6 +3439,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
gamescopeRealtime = SessionPrefs.gamescopeRealtime(this)
|
||||
paceCores = SessionPrefs.paceCores(this)
|
||||
gpuClockPin = SessionPrefs.gpuClockPin(this)
|
||||
prootNoSeccomp = SessionPrefs.prootNoSeccomp(this)
|
||||
prootFastPath = SessionPrefs.prootFastPath(this)
|
||||
nativeUserland = SessionPrefs.nativeUserland(this)
|
||||
desktopAsUser = SessionPrefs.desktopAsUser(this)
|
||||
cursorComposite = SessionPrefs.cursorComposite(this)
|
||||
guestHostname = SessionPrefs.guestHostname(this)
|
||||
|
||||
@@ -45,7 +45,6 @@ internal class ProtonMenu(
|
||||
var experimentalReleases by Operation.experimentalReleases
|
||||
companion object {
|
||||
const val EXPERIMENTAL = "experimental"
|
||||
private val REMEMBERED = setOf(ProtonExtras.OWN, ProtonExtras.ANTICHEAT)
|
||||
}
|
||||
@VisibleForTesting internal var latestCheck: (Boolean) -> Boolean = { force -> ProtonExtras.checkLatest(activity, force) }
|
||||
@VisibleForTesting internal var experimentalRefresh: () -> List<ExperimentalProtons.Release>? = { ExperimentalProtons.refresh(activity) }
|
||||
@@ -67,7 +66,7 @@ internal class ProtonMenu(
|
||||
ui.post { protonStage = label; protonPercent = value }
|
||||
}
|
||||
}.getOrElse { it.message ?: it.javaClass.simpleName }
|
||||
if (problem == null && !automatic && tool.id in REMEMBERED) ProtonExtras.setDeclined(activity, false, tool.id)
|
||||
if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false)
|
||||
if (tool.id == ProtonExtras.OWN) {
|
||||
if (problem == null) Onboarding.finish(Onboarding.Step.PROTON) else Onboarding.fail(Onboarding.Step.PROTON, problem)
|
||||
Onboarding.recheck(activity)
|
||||
@@ -97,7 +96,7 @@ internal class ProtonMenu(
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
if (older) ProtonExtras.removeOlder(activity, tool) else ProtonExtras.remove(activity, tool, dir)
|
||||
if (tool.id in REMEMBERED && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true, tool.id)
|
||||
if (tool.id == ProtonExtras.OWN && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
@@ -159,7 +158,7 @@ internal class ProtonMenu(
|
||||
refreshExperimental()
|
||||
protonRows = ProtonExtras.offered(activity).map {
|
||||
val all = ProtonExtras.installedAll(activity, it)
|
||||
ProtonRow(it.id, if (it.label != 0) activity.getString(it.label) else it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it))
|
||||
ProtonRow(it.id, it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,12 +100,6 @@ import com.droiddeck.launcher.input.SteamControllerBle
|
||||
import com.droiddeck.launcher.input.DirectTouchHold
|
||||
import com.droiddeck.launcher.input.GestureTouchStreamGate
|
||||
import com.droiddeck.launcher.input.PenRouter
|
||||
import com.droiddeck.launcher.input.AirTrigger
|
||||
import com.droiddeck.launcher.input.AirTriggerButtons
|
||||
import com.droiddeck.launcher.input.AirTriggerInput
|
||||
import com.droiddeck.launcher.input.AirTriggerPrefs
|
||||
import com.droiddeck.launcher.input.AirTriggerSetup
|
||||
import com.droiddeck.launcher.input.RedMagicAirTriggers
|
||||
import com.droiddeck.launcher.input.PenStream
|
||||
import com.droiddeck.launcher.input.PointerGestures
|
||||
import com.droiddeck.launcher.input.PointerSpace
|
||||
@@ -128,7 +122,6 @@ import com.droiddeck.launcher.session.GpuClockPin
|
||||
import com.droiddeck.launcher.session.GameProfileFollowState
|
||||
import com.droiddeck.launcher.session.GameProfileInventoryCache
|
||||
import com.droiddeck.launcher.session.GameProfileRefreshState
|
||||
import com.droiddeck.launcher.session.FullscreenMode
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionEvents
|
||||
import com.droiddeck.launcher.session.SessionArtifacts
|
||||
@@ -187,9 +180,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var adaptiveSticks by mutableStateOf<Boolean?>(null)
|
||||
private var quickButtons by mutableStateOf<Map<InputCommand, Boolean>>(emptyMap())
|
||||
private var picturePosition by mutableStateOf("center")
|
||||
|
||||
private fun picturePortrait(config: android.content.res.Configuration = resources.configuration): Boolean =
|
||||
config.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT
|
||||
private var integerScaling by mutableStateOf(false)
|
||||
private var gameZoom by mutableStateOf(SessionState.gameZoom)
|
||||
private var avoidNotch = false
|
||||
@@ -240,7 +230,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
private var unfoldedPanel by mutableStateOf<OnScreenControls?>(null)
|
||||
private var unfoldedColumn: android.widget.LinearLayout? = null
|
||||
private var unfoldedKeys: View? = null
|
||||
private var unfoldedDeckSurface: com.droiddeck.launcher.ui.InputSurfaceView? = null
|
||||
private var swappedInputSurface: com.droiddeck.launcher.ui.InputSurfaceView? = null
|
||||
private var unfoldedDeckPanel by mutableStateOf<com.droiddeck.launcher.input.DeckPanel?>(null)
|
||||
@@ -248,10 +237,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private lateinit var sessionRoot: FrameLayout
|
||||
private var inputRouter: InputRouter? = null
|
||||
private var physicalInputBindings: com.droiddeck.launcher.input.PhysicalInputBindings? = null
|
||||
private var airTriggerInput: AirTriggerInput? = null
|
||||
private var airTriggersOpen = false
|
||||
private var airTriggerMenu by mutableStateOf<com.droiddeck.launcher.ui.AirTriggerMenu?>(null)
|
||||
private var airTriggerGlow: com.droiddeck.launcher.ui.AirTriggerGlow? = null
|
||||
private var inputSettingsOpen by mutableStateOf(false)
|
||||
@Volatile private var inputUsesLocalActions = false
|
||||
private var inputUsesPointer = false
|
||||
@@ -644,7 +629,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var drawerControllerActive by mutableStateOf(false)
|
||||
private var backHold by mutableStateOf(true)
|
||||
private var dockedMenuController by mutableStateOf(false)
|
||||
private var sessionFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS)
|
||||
private var sessionOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
||||
private var dualScreenSessionMode by mutableStateOf(com.droiddeck.launcher.input.DualScreen.MODE_AUTO)
|
||||
private var backActionsInverted by mutableStateOf(false)
|
||||
@@ -673,7 +657,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var effects by mutableStateOf(ScreenEffects.OFF)
|
||||
private var observedScreenEffectsProfileId by mutableStateOf<String?>(null)
|
||||
private var screenEffectsTarget by mutableStateOf(SCREEN_EFFECTS_TARGET_AUTO)
|
||||
private var screenEffectsProfileRevision by mutableIntStateOf(0)
|
||||
private var cardboard by mutableStateOf(Cardboard.OFF)
|
||||
private var headTracker: HeadTracker? = null
|
||||
private var steamVrStatus by mutableStateOf<SteamVr.Status?>(null)
|
||||
@@ -734,6 +717,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var drawerTextureAnisotropy by mutableStateOf<Int?>(null)
|
||||
private var drawerTextureLodBias by mutableStateOf<String?>(null)
|
||||
private var lossless by mutableStateOf(Lossless.State.NONE)
|
||||
private val pickLossless = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { importLossless(it) }
|
||||
}
|
||||
private var frameGen by mutableStateOf(FrameGen.Mode.OFF)
|
||||
private var frameGenActiveGameId by mutableStateOf<Long?>(null)
|
||||
private var frameGenActiveGameName by mutableStateOf<String?>(null)
|
||||
@@ -942,8 +928,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
applyFollowChoice()
|
||||
applyFollowOrientation(resources.configuration)
|
||||
sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this)
|
||||
applySessionFullscreen()
|
||||
goFullscreen()
|
||||
volumeControlStream = android.media.AudioManager.STREAM_MUSIC
|
||||
displayManager = getSystemService(DISPLAY_SERVICE) as DisplayManager
|
||||
refreshSecondScreenDisplays()
|
||||
@@ -987,10 +972,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
bridge.setBuiltinPad(SessionState.mode != SessionService.MODE_STEAM || SessionPrefs.builtinPad(this))
|
||||
padBridge = bridge
|
||||
inputRouter = InputRouter(inputOutput).also { bridge.setInputRouter(it); DeckControls.setRouter(it); physicalInputBindings = com.droiddeck.launcher.input.PhysicalInputBindings(it) }
|
||||
if (RedMagicAirTriggers.supported(this)) {
|
||||
airTriggerInput = AirTriggerInput(bridge, ::holdOnScreen, ::airTriggerTouched)
|
||||
RedMagicAirTriggers.restore(this)
|
||||
}
|
||||
refreshInputProfile()
|
||||
bridge.setOnChordInput(backQamInput::onChordInput)
|
||||
SessionState.padBridge = bridge
|
||||
@@ -1014,7 +995,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
openDeckRing("activity created")
|
||||
bridge.setOnPlayerInput(::onPadInput)
|
||||
onScreenControls = OnScreenControls(this, bridge).also { controls ->
|
||||
controls.alpha = onScreenOpacityAlpha()
|
||||
controls.updateLayout(primaryInputLayout)
|
||||
controls.onTouchMiss = miss@{ event ->
|
||||
if (!gestureTouchStreamGate.accepts(GestureTouchStreamGate.Source.ON_SCREEN_CONTROLS, event)) return@miss
|
||||
@@ -1116,7 +1096,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
override fun onResolvePointerIcon(event: MotionEvent, pointerIndex: Int): android.view.PointerIcon? =
|
||||
if (platformPointerShown == true) super.onResolvePointerIcon(event, pointerIndex) else null
|
||||
}.apply { addView(sessionOverlay) })
|
||||
if (airTriggerInput != null) airTriggerGlow = com.droiddeck.launcher.ui.AirTriggerGlow(this).also { root.addView(it) }
|
||||
setContentView(root)
|
||||
glassesScope.launch { Glasses.state.collect {
|
||||
glasses = it
|
||||
@@ -1401,7 +1380,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
LaunchedEffect(drawerOpen, menuOwnsController, pcKeyboardOpen, achievementsOpen, gestureSettingsOpen, inputSettingsOpen, pipUi, SessionState.suspended, resumed, appTextFocus) {
|
||||
updateOnScreenControls()
|
||||
refreshAirTriggers()
|
||||
padBridge?.setInputEnabled(resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen && !pipUi && !appTextFocus && !SessionState.suspended)
|
||||
if (!drawerOpen && backTapOpenedDrawer) {
|
||||
backTaps.cancel()
|
||||
@@ -1661,11 +1639,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
effects = effects,
|
||||
screenEffectsTarget = screenEffectsTarget,
|
||||
screenEffectsTargets = screenEffectsTargetOptions(),
|
||||
screenEffectsCanDelete = screenEffectsProfileRevision.let {
|
||||
screenEffectsProfileIdForTarget(screenEffectsTarget)?.let {
|
||||
SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it) ||
|
||||
SessionPrefs.hasScreenEffectsUpscalerOverride(this@SessionActivity, it)
|
||||
}
|
||||
screenEffectsCanDelete = screenEffectsProfileIdForTarget(screenEffectsTarget)?.let {
|
||||
SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it)
|
||||
} == true,
|
||||
cardboard = cardboard,
|
||||
cardboardSensor = hasRotationSensor,
|
||||
@@ -1743,11 +1718,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
SessionState.gameZoom = gameZoom
|
||||
runCatching { WaylandCompositor.nativeSetZoom(gameZoom) }
|
||||
},
|
||||
picturePosition = picturePosition,
|
||||
onPicturePosition = { position ->
|
||||
SessionPrefs.setPicturePosition(this@SessionActivity, picturePortrait(), position)
|
||||
picturePosition = position
|
||||
},
|
||||
integerScaling = integerScaling,
|
||||
onIntegerScaling = { enabled ->
|
||||
SessionPrefs.setIntegerScaling(this@SessionActivity, enabled)
|
||||
@@ -1771,7 +1741,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
} else {
|
||||
val profileId = screenEffectsProfileIdForTarget(target)
|
||||
SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m)
|
||||
screenEffectsProfileRevision++
|
||||
|
||||
if (target == screenEffectsTarget) {
|
||||
upscaler = m
|
||||
@@ -1807,7 +1776,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
} else {
|
||||
val profileId = screenEffectsProfileIdForTarget(target)
|
||||
SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m)
|
||||
screenEffectsProfileRevision++
|
||||
if (target == screenEffectsTarget) {
|
||||
upscaler = m
|
||||
if (screenEffectsUpscalerTargetAppliesToLiveOutput(target)) {
|
||||
@@ -1854,22 +1822,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val profileId = screenEffectsProfileIdForTarget(editorTarget)
|
||||
SessionPrefs.setScreenEffects(this@SessionActivity, profileId, e)
|
||||
effects = e
|
||||
if (screenEffectsTargetAppliesToLiveOutput(editorTarget)) {
|
||||
val upscalerAppliesToLiveOutput =
|
||||
screenEffectsUpscalerTargetAppliesToLiveOutput(editorTarget)
|
||||
val liveUpscaler = if (upscalerAppliesToLiveOutput) {
|
||||
SessionPrefs.screenEffectsUpscaler(
|
||||
this@SessionActivity,
|
||||
screenEffectsProfileIdForTarget(editorTarget)
|
||||
)
|
||||
} else {
|
||||
SessionPrefs.screenEffectsUpscaler(
|
||||
this@SessionActivity,
|
||||
currentScreenEffectsProfileId()
|
||||
)
|
||||
}
|
||||
e.push(liveUpscaler)
|
||||
}
|
||||
if (screenEffectsTargetAppliesToLiveOutput(editorTarget)) e.push(upscaler)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1926,7 +1879,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onBlackFrameInsertion = { on ->
|
||||
SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on)
|
||||
blackFrameInsertion = on
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit(), outputFpsLimit())
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit())
|
||||
},
|
||||
hdr = hdrWanted,
|
||||
hdrAvailable = hdrAvailable,
|
||||
@@ -1949,39 +1902,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
readPrefs()
|
||||
applyFrameGen(force = true)
|
||||
},
|
||||
onImportLossless = {
|
||||
pickLossless.launch(InAppFilePicker.buildIntent(
|
||||
this@SessionActivity, listOf("dll"), getString(R.string.lsfg_pick_title)))
|
||||
},
|
||||
onKeyboard = { drawerOpen = false; pcKeyboardOpen = false; togglePrimaryKeyboard() },
|
||||
onHardwareKeyboard = ::togglePcKeyboard,
|
||||
wowChatShown = com.droiddeck.launcher.ui.WowChat.isWow(AgentGuest.gameProgram),
|
||||
wowChat = wowChat.remembered,
|
||||
onWowChat = wowChat::choose,
|
||||
controller = controllerSettings,
|
||||
airTriggers = airTriggerMenu,
|
||||
onAirTriggers = { on -> AirTriggerPrefs.setEnabled(this@SessionActivity, on); refreshAirTriggers() },
|
||||
onAirTriggerButton = { trigger, id ->
|
||||
AirTriggerPrefs.setButton(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, id)
|
||||
refreshAirTriggers()
|
||||
},
|
||||
onAirTriggerAction = { trigger, action ->
|
||||
AirTriggerPrefs.setAction(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, action)
|
||||
refreshAirTriggers()
|
||||
},
|
||||
onAirTriggerRate = { trigger, rate ->
|
||||
AirTriggerPrefs.setRate(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, rate)
|
||||
refreshAirTriggers()
|
||||
},
|
||||
onAirTriggerVibration = { on -> AirTriggerPrefs.setVibration(this@SessionActivity, on); refreshAirTriggers() },
|
||||
onAirTriggerScreenLight = { on -> AirTriggerPrefs.setScreenLight(this@SessionActivity, on); refreshAirTriggers() },
|
||||
onAirTriggerLed = { led ->
|
||||
AirTriggerPrefs.setLed(this@SessionActivity, led)
|
||||
if (airTriggersOpen) RedMagicAirTriggers.open(this@SessionActivity)
|
||||
refreshAirTriggers()
|
||||
},
|
||||
onControllerSize = { percent -> updateControllerPrefs { ControllerPrefs.setSize(this@SessionActivity, percent) } },
|
||||
onControllerOpacity = { percent ->
|
||||
ControllerPrefs.setOnScreenOpacity(this@SessionActivity, percent)
|
||||
controllerSettings = ControllerPrefs.read(this@SessionActivity)
|
||||
applyOnScreenOpacity()
|
||||
},
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
@@ -2106,12 +2037,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onPause = ::pauseNow,
|
||||
paused = SessionState.suspended || SessionState.manualPause,
|
||||
onResume = { SessionService.resume(this@SessionActivity) },
|
||||
fullscreenMode = sessionFullscreenMode,
|
||||
onFullscreenMode = { mode ->
|
||||
SessionPrefs.setSessionFullscreenMode(this@SessionActivity, mode)
|
||||
sessionFullscreenMode = mode
|
||||
applySessionFullscreen()
|
||||
},
|
||||
orientation = sessionOrientation,
|
||||
onOrientation = { value ->
|
||||
when (SessionState.mode) {
|
||||
@@ -2131,8 +2056,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
},
|
||||
unfoldedControls = unfoldedControls,
|
||||
onUnfoldedControls = ::chooseUnfoldedControls,
|
||||
deckPanel = unfoldedDeckPanel,
|
||||
onDeckPanel = ::selectDeckPanel,
|
||||
adaptiveSticks = adaptiveSticks.takeIf {
|
||||
unfoldedPanel != null || oscMode != SessionPrefs.OSC_NEVER && oscMode != SessionPrefs.OSC_STEAM_QAM && !steamTouchInUse
|
||||
},
|
||||
@@ -2346,18 +2269,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (fieldKeyboardOnPrimary) hidePrimaryKeyboard()
|
||||
}
|
||||
|
||||
private fun onScreenOpacityAlpha() = ControllerPrefs.onScreenOpacity(this) / 100f
|
||||
|
||||
private fun applyOnScreenOpacity() {
|
||||
val alpha = onScreenOpacityAlpha()
|
||||
onScreenControls?.alpha = alpha
|
||||
bottomInputControls?.alpha = alpha
|
||||
unfoldedColumn?.alpha = alpha
|
||||
swappedInputSurface?.alpha = alpha
|
||||
secondScreenPresentation?.controlsView?.alpha = alpha
|
||||
steamTouchControls?.let { it.alpha = if (it.isEditing) 1f else alpha }
|
||||
}
|
||||
|
||||
private fun updateControllerPrefs(change: () -> Unit) {
|
||||
change()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
@@ -2715,21 +2626,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val targetUpscaler = SessionPrefs.screenEffectsUpscaler(this, profileId)
|
||||
effects = targetEffects
|
||||
upscaler = targetUpscaler
|
||||
val upscalerAppliesToLiveOutput = screenEffectsUpscalerTargetAppliesToLiveOutput(target)
|
||||
val liveUpscaler = if (upscalerAppliesToLiveOutput) {
|
||||
targetUpscaler
|
||||
} else {
|
||||
SessionPrefs.screenEffectsUpscaler(this, currentScreenEffectsProfileId())
|
||||
}
|
||||
if (upscalerAppliesToLiveOutput) {
|
||||
WaylandCompositor.nativeSetUpscaler(liveUpscaler)
|
||||
}
|
||||
if (screenEffectsTargetAppliesToLiveOutput(target)) {
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(targetEffects, liveUpscaler)?.name)
|
||||
targetEffects.push(liveUpscaler)
|
||||
} else if (upscalerAppliesToLiveOutput) {
|
||||
val liveEffects = SessionPrefs.screenEffects(this, currentScreenEffectsProfileId())
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(liveEffects, liveUpscaler)?.name)
|
||||
WaylandCompositor.nativeSetUpscaler(targetUpscaler)
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(targetEffects, targetUpscaler)?.name)
|
||||
targetEffects.push(targetUpscaler)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2742,7 +2642,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun resetScreenEffectsTarget(target: String) {
|
||||
if (target != screenEffectsTarget) return
|
||||
SessionPrefs.resetScreenEffectsProfile(this, screenEffectsProfileIdForTarget(target))
|
||||
screenEffectsProfileRevision++
|
||||
syncScreenEffectsTarget(target)
|
||||
}
|
||||
|
||||
@@ -2750,7 +2649,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (target != screenEffectsTarget) return
|
||||
val profileId = screenEffectsProfileIdForTarget(target) ?: return
|
||||
SessionPrefs.deleteScreenEffectsProfile(this, profileId)
|
||||
screenEffectsProfileRevision++
|
||||
syncScreenEffectsTarget(target)
|
||||
}
|
||||
|
||||
@@ -2881,7 +2779,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
pipAutoEnter = SessionPrefs.pipAutoEnter(this)
|
||||
unfoldedControls = SessionPrefs.unfoldedControls(this)
|
||||
unfoldedControlsWithController = SessionPrefs.unfoldedControlsWithController(this)
|
||||
picturePosition = SessionPrefs.picturePosition(this, picturePortrait())
|
||||
picturePosition = SessionPrefs.picturePosition(this)
|
||||
integerScaling = SessionPrefs.integerScaling(this)
|
||||
avoidNotch = SessionPrefs.avoidNotch(this)
|
||||
applyNotchInset()
|
||||
@@ -3203,7 +3101,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
CompositorHost.startOrAttach(
|
||||
this, holder.surface, runtimeDir.path,
|
||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(), outputFpsLimit(),
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(),
|
||||
)
|
||||
onOutputAttached(holder)
|
||||
if (SessionState.running && size != previous) {
|
||||
@@ -3221,7 +3119,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
intent.getStringArrayExtra(SessionService.EXTRA_PROGRAM_ARGS),
|
||||
intent.getStringExtra(SessionService.EXTRA_GAME_ID),
|
||||
sessionActivityDisplayId,
|
||||
frontendSteamGame = intent.getBooleanExtra(SessionService.EXTRA_FRONTEND_STEAM_GAME, false),
|
||||
)
|
||||
intent.getStringExtra(EXTRA_PLAYED_GAME)?.let { com.droiddeck.launcher.frontend.Library.recordPlayed(this, it) }
|
||||
}
|
||||
@@ -3318,8 +3215,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
if (!pipUi && !isInPictureInPictureMode) applySessionFullscreen(newConfig)
|
||||
picturePosition = SessionPrefs.picturePosition(this, picturePortrait(newConfig))
|
||||
if (refreshActivityDisplayId() && started) {
|
||||
SessionService.setActivityDisplay(this, sessionActivityDisplayId)
|
||||
}
|
||||
@@ -3479,7 +3374,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
)
|
||||
val hz = refreshHz()
|
||||
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
||||
CompositorHost.updatePacing(hz, compositorFpsLimit(), outputFpsLimit())
|
||||
CompositorHost.updatePacing(hz, compositorFpsLimit())
|
||||
pushCardboard(activeCardboard)
|
||||
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
||||
}
|
||||
@@ -3692,6 +3587,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}, "lossless-sync").start()
|
||||
}
|
||||
|
||||
private fun importLossless(dll: File) {
|
||||
Thread({
|
||||
val result = Lossless.import(this, dll)
|
||||
val message = Lossless.message(this, result)
|
||||
val state = Lossless.state(this)
|
||||
runOnUiThread {
|
||||
lossless = state
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||
applyFrameGen(force = result == Lossless.ImportResult.UPDATED)
|
||||
}
|
||||
}, "lossless-import").start()
|
||||
}
|
||||
|
||||
|
||||
private fun watchSession() {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
@@ -3727,7 +3635,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun onSessionEnded(status: Int) {
|
||||
ended = true
|
||||
runOnUiThread { refreshAirTriggers() }
|
||||
++steamVrRequestGeneration
|
||||
if (isInPictureInPictureMode) {
|
||||
runOnUiThread { finish() }
|
||||
@@ -3785,7 +3692,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun releasePads(keepBackTap: Boolean = false) {
|
||||
inputMotion.stop()
|
||||
physicalInputBindings?.release()
|
||||
airTriggerInput?.release()
|
||||
com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this)
|
||||
backQamInput.cancel(keepTap = keepBackTap)
|
||||
padBridge?.releaseAll()
|
||||
@@ -3862,6 +3768,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
presentationFaultHint()?.let { return it }
|
||||
if (log == null || !log.isFile) return null
|
||||
return try {
|
||||
var enosys = 0
|
||||
var fexMissing = false
|
||||
val size = log.length()
|
||||
val text = java.io.RandomAccessFile(log, "r").use { f ->
|
||||
@@ -3872,6 +3779,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
String(bytes, Charsets.ISO_8859_1)
|
||||
}
|
||||
text.lineSequence().forEach { line ->
|
||||
if (line.contains("Function not implemented")) enosys++
|
||||
if (line.contains(FEX_MISSING)) fexMissing = true
|
||||
}
|
||||
val steamSetup = com.droiddeck.launcher.session.SteamClientSetupFailure.find(text.lineSequence())
|
||||
@@ -3893,6 +3801,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
} else if (fexMissing) {
|
||||
val what = com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_end_program)
|
||||
EndHint(getString(R.string.session_end_fex_missing, what), evenOnSuccess = true)
|
||||
} else if (enosys >= 8) {
|
||||
EndHint(resources.getQuantityString(R.plurals.session_hint_enosys, enosys, enosys,
|
||||
getString(R.string.perf_title), getString(R.string.perf_seccomp), getString(R.string.perf_xalia)))
|
||||
} else null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
@@ -3913,9 +3824,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
return dispatchSessionKeyEvent(normalized, orderedImeKey)
|
||||
}
|
||||
|
||||
private fun physicalInputAccepted() = resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen &&
|
||||
!inputSettingsOpen && !gestureSettingsOpen && !SessionState.suspended && !loading.visible
|
||||
|
||||
private fun dispatchSessionKeyEvent(event: KeyEvent, orderedImeKey: Boolean): Boolean {
|
||||
if (com.droiddeck.launcher.ui.AgentPet.handleBack(this, event)) return true
|
||||
when (event.keyCode) {
|
||||
@@ -3935,10 +3843,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
if (penStream.holdsKey(event) || (penSettings.mode != SessionPrefs.PEN_TOUCH && PenStream.isPenKey(event))) return penStream.onKey(event)
|
||||
if (airTriggerInput?.onKey(event) { physicalInputAccepted() && !pipUi && !appTextFocus } == true) return true
|
||||
if (appTextFocus) return super.dispatchKeyEvent(event)
|
||||
if (!pipUi) {
|
||||
if (physicalInputBindings?.onKey(event, physicalInputAccepted()) == true) return true
|
||||
if (physicalInputBindings?.onKey(event, resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen &&
|
||||
!inputSettingsOpen && !gestureSettingsOpen && !SessionState.suspended && !loading.visible) == true) return true
|
||||
if (physicalShortcuts.onKey(
|
||||
event,
|
||||
enabled = resumed && SessionState.running && !SessionState.suspended &&
|
||||
@@ -4169,7 +4077,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
steamTouchControls?.let { takes(it, it::takesTouchAt) } == true ||
|
||||
unfoldedPanel?.let { takes(it, it::takesTouchAt) } == true ||
|
||||
unfoldedDeckSurface?.let { takes(it, it::takesTouchAt) } == true ||
|
||||
unfoldedKeys?.let { takes(it) { _, _ -> true } } == true
|
||||
unfoldedColumn?.getChildAt(0)?.let { takes(it) { _, _ -> true } } == true
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
@@ -5163,7 +5071,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|| inputProfile.keys.any { it.action is InputAction.MouseButton }
|
||||
physicalInputBindings?.configure(inputProfile.keys)
|
||||
padBridge?.setInputProfile(inputProfile)
|
||||
refreshAirTriggers()
|
||||
DeckControls.refresh()
|
||||
onScreenControls?.updateLayout(primaryInputLayout)
|
||||
bottomInputControls?.updateLayout(primaryInputLayout)
|
||||
@@ -5174,32 +5081,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
secondScreenPresentation?.refreshControls()
|
||||
}
|
||||
|
||||
private fun refreshAirTriggers() {
|
||||
val input = airTriggerInput ?: return
|
||||
val layout = primaryInputLayout
|
||||
val layoutId = layout?.id.orEmpty()
|
||||
val enabled = AirTriggerPrefs.enabled(this)
|
||||
val chosen = AirTrigger.entries.associateWith {
|
||||
AirTriggerSetup(AirTriggerButtons.resolve(layout, it, AirTriggerPrefs.button(this, layoutId, it)),
|
||||
AirTriggerPrefs.action(this, layoutId, it), AirTriggerPrefs.rate(this, layoutId, it))
|
||||
}
|
||||
val active = enabled && resumed && !ended && !SessionState.suspended
|
||||
input.configure(if (active) chosen else emptyMap())
|
||||
if (active != airTriggersOpen) {
|
||||
airTriggersOpen = active
|
||||
if (active) RedMagicAirTriggers.open(this) else RedMagicAirTriggers.restore(this)
|
||||
}
|
||||
airTriggerMenu = com.droiddeck.launcher.ui.AirTriggerMenu(enabled, chosen.mapValues { it.value.element.id },
|
||||
AirTriggerButtons.options(layout).map { it.id to it.name }, AirTriggerPrefs.vibration(this), AirTriggerPrefs.screenLight(this),
|
||||
AirTriggerPrefs.led(this), chosen.mapValues { it.value.action }, chosen.mapValues { it.value.rate })
|
||||
}
|
||||
|
||||
private fun airTriggerTouched(trigger: AirTrigger, down: Boolean) {
|
||||
RedMagicAirTriggers.light(if (down) trigger.pressLight else trigger.releaseLight)
|
||||
if (down && AirTriggerPrefs.vibration(this)) com.droiddeck.launcher.ui.ControllerHaptics.click(this)
|
||||
airTriggerGlow?.show(trigger, down && AirTriggerPrefs.screenLight(this))
|
||||
}
|
||||
|
||||
private fun tapQam() {
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) padBridge?.triggerQam()
|
||||
}
|
||||
@@ -5240,9 +5121,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val width = rootContentWidth()
|
||||
val height = rootContentHeight()
|
||||
val wanted = controlsBelowWanted()
|
||||
val tabRow = unfoldedColumn?.getChildAt(0)?.height?.let {
|
||||
it - (com.droiddeck.launcher.ui.BAR_HEIGHT.value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
} ?: 0
|
||||
val outputAspect = if (!wanted || SessionState.followScreen) 0f
|
||||
else outputSize().let { it.first.toFloat() / it.second.coerceAtLeast(1) }
|
||||
val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height, aspect = outputAspect)
|
||||
val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height, tabRow, outputAspect)
|
||||
else FrameLayout.LayoutParams.MATCH_PARENT
|
||||
val params = surfaceView.layoutParams as FrameLayout.LayoutParams
|
||||
if (params.height != gameHeight) {
|
||||
@@ -5259,7 +5143,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (panel != null && (!wanted || panel.dock != dock)) {
|
||||
sessionRoot.removeView(unfoldedColumn)
|
||||
unfoldedColumn = null
|
||||
unfoldedKeys = null
|
||||
unfoldedDeckSurface = null
|
||||
unfoldedDeckPanel = null
|
||||
unfoldedPanel = null
|
||||
@@ -5270,16 +5153,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (panel == null) {
|
||||
panel = OnScreenControls(this, padBridge, dock).also { it.updateLayout(primaryInputLayout) }
|
||||
val column = android.widget.LinearLayout(this).apply {
|
||||
alpha = onScreenOpacityAlpha()
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
addView(unfoldedBar().apply {
|
||||
addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
if (bottom - top != oldBottom - oldTop) post { applyUnfoldedControls() }
|
||||
}
|
||||
}, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT))
|
||||
addView(panel, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f))
|
||||
unfoldedKeys = com.droiddeck.launcher.ui.padKeysView(
|
||||
this@SessionActivity, SessionState.mode == SessionService.MODE_STEAM,
|
||||
{ releasePads(); drawerOpen = true }, ::tapSteamButton, ::tapQam,
|
||||
).also {
|
||||
addView(it, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT))
|
||||
}
|
||||
}
|
||||
sessionRoot.addView(column, sessionRoot.indexOfChild(surfaceView) + 1)
|
||||
unfoldedColumn = column
|
||||
@@ -5290,6 +5171,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
unfoldedColumn?.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height - gameHeight, Gravity.BOTTOM)
|
||||
}
|
||||
|
||||
private fun unfoldedBar(): View = com.droiddeck.launcher.ui.bottomScreenBarView(this) {
|
||||
val deck = unfoldedDeckPanel
|
||||
com.droiddeck.launcher.ui.sessionBarModel(getString(if (deck != null) R.string.second_mode_deck_controls else R.string.deck_tab_gamepad),
|
||||
{ chooseUnfoldedControls(false) }, { drawerOpen = true }, ::tapSteamButton, ::tapQam,
|
||||
tabs = deck?.let { com.droiddeck.launcher.ui.deckPanelTabs(this, it, ::selectDeckPanel) })
|
||||
}
|
||||
|
||||
private fun showUnfoldedDeckPanel() {
|
||||
val column = unfoldedColumn
|
||||
val panel = unfoldedPanel
|
||||
@@ -5305,7 +5193,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
panel.visibility = View.GONE
|
||||
unfoldedDeckSurface = com.droiddeck.launcher.ui.InputSurfaceView(this, padBridge, layout.elements, InputRole.PRIMARY, layout.style, haptics = true).also {
|
||||
it.tag = layout
|
||||
column.addView(it, column.indexOfChild(panel) + 1, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f))
|
||||
column.addView(it, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5656,20 +5544,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var sessionTouchDown = false
|
||||
private var screenTapsClick = true
|
||||
|
||||
private fun inputSurfaces() = listOfNotNull(
|
||||
private fun onScreenLeftMouseButtonShown(): Boolean = listOfNotNull(
|
||||
onScreenControls?.inputSurface, bottomInputControls?.inputSurface, unfoldedPanel?.inputSurface, unfoldedDeckSurface,
|
||||
secondScreenPresentation?.controlsView, swappedInputSurface,
|
||||
)
|
||||
|
||||
private fun onScreenLeftMouseButtonShown(): Boolean =
|
||||
inputSurfaces().any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) }
|
||||
|
||||
private fun holdOnScreen(elementId: String, trigger: AirTrigger, held: Boolean, cancelled: Boolean): Boolean {
|
||||
val surfaces = inputSurfaces().filter { it.inputRole == InputRole.PRIMARY }
|
||||
if (held) return surfaces.any { it.isShown && it.hold(elementId, trigger.ordinal, true) }
|
||||
surfaces.forEach { it.hold(elementId, trigger.ordinal, false, cancelled) }
|
||||
return true
|
||||
}
|
||||
).any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) }
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean = inSurfaceSpace(event) { handleTouch(event) }
|
||||
|
||||
@@ -6126,11 +6004,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val view = com.droiddeck.launcher.input.SteamTouchControls(this, device,
|
||||
onMenu = { drawerOpen = true }, onKeyboard = ::togglePcKeyboard)
|
||||
view.visibility = View.GONE
|
||||
view.alpha = onScreenOpacityAlpha()
|
||||
view.onEditingChanged = { editing ->
|
||||
view.alpha = if (editing) 1f else onScreenOpacityAlpha()
|
||||
touchEditorChanged()
|
||||
}
|
||||
view.onEditingChanged = { touchEditorChanged() }
|
||||
view.onOptions = { options ->
|
||||
steamTouchOptions = options
|
||||
applyTouchRouting()
|
||||
@@ -6235,7 +6109,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (bottom?.parent !== bottomRoot) {
|
||||
(bottom?.parent as? android.view.ViewGroup)?.removeView(bottom)
|
||||
bottom = OnScreenControls(bottomRoot.context, padBridge).also { view ->
|
||||
view.alpha = onScreenOpacityAlpha()
|
||||
view.onTouchMiss = { event -> onBottomGameTouch(event) }
|
||||
bottomRoot.addView(view, android.view.ViewGroup.LayoutParams(-1, -1))
|
||||
}
|
||||
@@ -6466,12 +6339,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun holdComposedOutput(hold: Boolean) {
|
||||
val wasHeld = composedHolds > 0
|
||||
composedHolds = (composedHolds + if (hold) 1 else -1).coerceAtLeast(0)
|
||||
val held = composedHolds > 0
|
||||
if (held == wasHeld) return
|
||||
WaylandCompositor.nativeSetMirrorCapture(held)
|
||||
// Importable HDR is redirected by the compositor hold. Keep its layer-only fallback available.
|
||||
if (zeroCopyActive()) WaylandCompositor.nativeSetZeroCopy(composedOutputFree())
|
||||
}
|
||||
|
||||
@@ -6618,13 +6486,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
displayManager.unregisterDisplayListener(displayListener)
|
||||
com.droiddeck.launcher.input.DualScreen.unwatchTaken(bottomScreenListener)
|
||||
contentResolver.unregisterContentObserver(refreshSettingObserver)
|
||||
// Closing the presentation removes the docked Agent page and unregisters its picker.
|
||||
if (com.droiddeck.launcher.session.SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
|
||||
screenOff = screenIsOff(),
|
||||
dockedDrawerOpen = menuShownOnBottom(),
|
||||
attachmentPickerOpen = com.droiddeck.launcher.agent.AgentAttachments.picking,
|
||||
)
|
||||
) closeSecondScreen(reset = false)
|
||||
if (!screenIsOff()) closeSecondScreen(reset = false)
|
||||
sessionTextInput.stop()
|
||||
startedScreens = (startedScreens - 1).coerceAtLeast(0)
|
||||
updateGlassesScreen()
|
||||
@@ -6661,7 +6523,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
com.droiddeck.launcher.agent.AgentAttachments.picking = false
|
||||
drawerGameInventoryRevision++
|
||||
com.droiddeck.launcher.input.SystemKeyCapture.attach(this, { hasWindowFocus() && !appUiOwnsPointer() && CompositorHost.isStarted }) { event ->
|
||||
com.droiddeck.launcher.input.GuestKeys.send(event) { code, down -> sendGuestKey(code, down, 8) }
|
||||
@@ -6674,8 +6535,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
uiHandler.removeCallbacks(questSteamVrRequest)
|
||||
if (com.droiddeck.launcher.session.QuestExperimental.isSupported()) uiHandler.post(questSteamVrRequest)
|
||||
if (runtimeRemovalBlocked) return
|
||||
sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this)
|
||||
if (!pipUi && !isInPictureInPictureMode) applySessionFullscreen()
|
||||
if (!SessionState.suspended) pausedFrame = null
|
||||
com.droiddeck.launcher.ui.Motion.refresh(this)
|
||||
refreshHomeApp()
|
||||
@@ -6693,7 +6552,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
joyConVr?.refresh()
|
||||
onScreenControls?.reload()
|
||||
controllerSettings = ControllerPrefs.read(this)
|
||||
applyOnScreenOpacity()
|
||||
resumed = true
|
||||
boostGpuClock(panelOverGame)
|
||||
updateKeyboardRoute()
|
||||
@@ -6777,7 +6635,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
heldButtons.clear()
|
||||
if (!screenOff) {
|
||||
val menuUp = menuShownOnBottom()
|
||||
if (!com.droiddeck.launcher.agent.AgentAttachments.picking) drawerOpen = false
|
||||
drawerOpen = false
|
||||
if (menuUp) SessionState.bottomMenu = true
|
||||
pcKeyboardOpen = false
|
||||
achievementsOpen = false
|
||||
@@ -6789,7 +6647,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (::scrollTouch.isInitialized) scrollTouch.cancel()
|
||||
if (::padMouse.isInitialized) padMouse.reset()
|
||||
resumed = false
|
||||
refreshAirTriggers()
|
||||
boostGpuClock(false)
|
||||
updateKeyboardRoute()
|
||||
updatePointerCapture()
|
||||
@@ -7203,10 +7060,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
androidx.compose.runtime.key(profileLayout) {
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context -> com.droiddeck.launcher.ui.InputSurfaceView(context, padBridge, profileLayout?.elements.orEmpty(),
|
||||
surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also {
|
||||
it.alpha = onScreenOpacityAlpha()
|
||||
swappedInputSurface = it
|
||||
} },
|
||||
surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also { swappedInputSurface = it } },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
onRelease = { if (swappedInputSurface === it) swappedInputSurface = null },
|
||||
)
|
||||
@@ -7383,13 +7237,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (!hasFocus) {
|
||||
cancelTouchGestures()
|
||||
releaseHeldGuestInput()
|
||||
airTriggerInput?.release()
|
||||
}
|
||||
// Game Space clears the distribute state when the launcher or Game Space itself comes to the front.
|
||||
if (hasFocus && airTriggersOpen) RedMagicAirTriggers.open(this)
|
||||
if (hasFocus && !pipUi) {
|
||||
retryFieldKeyboard(true)
|
||||
applySessionFullscreen()
|
||||
goFullscreen()
|
||||
refreshClipboard()
|
||||
}
|
||||
updatePointerCapture()
|
||||
@@ -7399,24 +7250,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (resumed) sessionClipboard.refresh()
|
||||
}
|
||||
|
||||
private fun applySessionFullscreen(config: android.content.res.Configuration = resources.configuration) {
|
||||
val fullscreen = sessionFullscreenMode.hidesSystemBars(config.orientation)
|
||||
if (fullscreen) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
private fun goFullscreen() {
|
||||
@Suppress("DEPRECATION")
|
||||
window.decorView.systemUiVisibility = if (fullscreen) (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) else View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
window.attributes = window.attributes.apply {
|
||||
layoutInDisplayCutoutMode = when {
|
||||
!fullscreen -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
||||
Build.VERSION.SDK_INT >= 30 -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
else -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
layoutInDisplayCutoutMode = if (Build.VERSION.SDK_INT >= 30)
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
else WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7479,9 +7325,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
inputMotion.stop()
|
||||
padBridge?.setInputEnabled(false)
|
||||
physicalInputBindings?.close()
|
||||
airTriggerInput?.close()
|
||||
airTriggerInput = null
|
||||
if (airTriggersOpen) RedMagicAirTriggers.restore(this)
|
||||
padBridge?.stop()
|
||||
DeckControls.clearRouter(inputRouter)
|
||||
inputRouter = null
|
||||
|
||||
@@ -23,7 +23,7 @@ object AgentAccess {
|
||||
fun requireCommands(context: Context) {
|
||||
if (!commandsAllowed(context)) throw AgentException(
|
||||
"AGENT_COMMANDS_DISABLED",
|
||||
"droiddeckctl is off: turn on Setup > Developer > droiddeckctl on the device",
|
||||
"Debugging tools are off: turn on Setup > Developer > Debugging tools on the device",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,15 +19,6 @@ object AgentAttachments {
|
||||
/** Guest paths waiting to go with the next message. */
|
||||
val pending = mutableStateListOf<String>()
|
||||
|
||||
/** True while the file picker is open over a session: it answers the drawer's agent page, so the drawer must stay. */
|
||||
@Volatile var picking = false
|
||||
|
||||
/** Launches a system screen that answers the agent page, keeping the drawer for it; the result callback clears [picking]. */
|
||||
fun pick(launch: () -> Unit) {
|
||||
picking = true
|
||||
if (runCatching(launch).isFailure) picking = false
|
||||
}
|
||||
|
||||
private const val NEW = "new"
|
||||
private const val GUEST_DIR = "/root/.cache/droiddeck/attachments"
|
||||
private val IMAGE = setOf("png", "jpg", "jpeg", "webp", "gif", "bmp")
|
||||
@@ -44,17 +35,14 @@ object AgentAttachments {
|
||||
val folder = chat ?: NEW
|
||||
val dir = File(hostDir(app), folder).apply { mkdirs() }
|
||||
return uris.mapNotNull { uri ->
|
||||
var target: File? = null
|
||||
runCatching {
|
||||
val name = displayName(app, uri).replace(Regex("[^A-Za-z0-9._-]"), "_").ifEmpty { "file" }
|
||||
var candidate = File(dir, name)
|
||||
var target = File(dir, name)
|
||||
var n = 1
|
||||
// Created atomically, so copies running side by side never pick the same name.
|
||||
while (!candidate.createNewFile()) candidate = File(dir, "${name.substringBeforeLast('.')}-${n++}${name.substringAfterLast('.', "").let { if (it.isEmpty()) "" else ".$it" }}")
|
||||
target = candidate
|
||||
app.contentResolver.openInputStream(uri)!!.use { input -> candidate.outputStream().use { input.copyTo(it) } }
|
||||
"$GUEST_DIR/$folder/${candidate.name}"
|
||||
}.onFailure { target?.delete() }.getOrNull()
|
||||
while (target.exists()) target = File(dir, "${name.substringBeforeLast('.')}-${n++}${name.substringAfterLast('.', "").let { if (it.isEmpty()) "" else ".$it" }}")
|
||||
app.contentResolver.openInputStream(uri)!!.use { input -> target.outputStream().use { input.copyTo(it) } }
|
||||
"$GUEST_DIR/$folder/${target.name}"
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,9 +75,7 @@ object AgentHost {
|
||||
"Never kill by a command-line pattern (pkill -f, pgrep -f piped to kill): your own command line holds the user's message, so the pattern matches you. " +
|
||||
"Files the user attaches are listed at the end of their message, under /root/.cache/droiddeck/attachments. " +
|
||||
"To have the user pick between options, end your reply with a fenced code block whose language is choices, one short option per line, " +
|
||||
"and end your turn: DroidDeck shows them as buttons and sends the one picked as the next message. " +
|
||||
"To show the user an image (a screenshot, a mockup, a chart), put  on a line of its own: " +
|
||||
"DroidDeck draws the file in the chat."
|
||||
"and end your turn: DroidDeck shows them as buttons and sends the one picked as the next message."
|
||||
|
||||
val entries = mutableStateListOf<Entry>()
|
||||
val queue = mutableStateListOf<Queued>()
|
||||
@@ -571,6 +569,7 @@ object AgentHost {
|
||||
remove("LD_PRELOAD"); remove("LD_AUDIT"); remove("LD_LIBRARY_PATH")
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(app).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(app).path)
|
||||
if (SessionPrefs.prootNoSeccomp(app)) put("PROOT_NO_SECCOMP", "1")
|
||||
LinuxRuntime.prootLibraryPath(app).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ object AgentNative {
|
||||
fun run(context: Context, request: JSONObject, timeoutMs: Long): JSONObject {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
com.droiddeck.launcher.session.SessionFiles.stage(context, root)
|
||||
// with the setting off, staging leaves the rootfs as proot wants it
|
||||
if (!com.droiddeck.launcher.session.SessionPrefs.nativeUserland(context)) NativeGuest.prepare(context, root)
|
||||
if (!NativeGuest.available(root)) throw AgentException("NATIVE_UNAVAILABLE", "The rootfs has no native hook or glibc loader yet; start a session once")
|
||||
val argvJson = request.optJSONArray("argv") ?: throw AgentException("INVALID_REQUEST", "argv is required")
|
||||
val argv = (0 until argvJson.length()).map { argvJson.getString(it) }
|
||||
|
||||
@@ -226,18 +226,7 @@ object AgentSetup {
|
||||
/** The whole output of a step's last run; the card shows only its last line. */
|
||||
fun logFile(app: Context, step: Step) = File(app.filesDir, "agent/setup-${step.name.lowercase()}.log")
|
||||
|
||||
/**
|
||||
* An install set up before setup wrote the Gradle init script gets the step again, but only
|
||||
* once the checkout's setup writes it: the step runs that script, and an older one never would.
|
||||
*/
|
||||
fun buildToolsInstalled(app: Context) = AgentHost.guestFileExists(app, "/root/aapt2/aapt2") && AgentHost.guestFileExists(app, "$CHECKOUT/.git") &&
|
||||
(AgentHost.guestFileExists(app, GRADLE_INIT) || !setupWritesGradleInit(app))
|
||||
|
||||
private const val GRADLE_INIT = "/root/.gradle/init.d/droiddeck-device.gradle"
|
||||
|
||||
private fun setupWritesGradleInit(app: Context) = runCatching {
|
||||
File(LinuxRuntime.rootDir(app), "$CHECKOUT/tools/agent/setup".removePrefix("/")).readText().contains(GRADLE_INIT.substringAfterLast('/'))
|
||||
}.getOrDefault(false)
|
||||
fun buildToolsInstalled(app: Context) = AgentHost.guestFileExists(app, "/root/aapt2/aapt2") && AgentHost.guestFileExists(app, "$CHECKOUT/.git")
|
||||
|
||||
/** dd-lab-build compiled this install's commit, so a Lab build compiles only what changed. */
|
||||
private fun prepared(app: Context) = runCatching {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import java.io.File
|
||||
|
||||
object CpuFeatures {
|
||||
internal fun lacksAtomics(cpuInfo: String): Boolean {
|
||||
val cores = cpuInfo.lineSequence()
|
||||
.filter { it.substringBefore(':').trim() == "Features" }
|
||||
.map { it.substringAfter(':').trim().split(Regex("\\s+")) }
|
||||
.toList()
|
||||
return cores.isNotEmpty() && cores.any { "atomics" !in it }
|
||||
}
|
||||
|
||||
val lacksAtomics: Boolean by lazy {
|
||||
runCatching { lacksAtomics(File("/proc/cpuinfo").readText()) }.getOrDefault(false)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
object DeviceReport {
|
||||
private const val TAG = "DeviceReport"
|
||||
@@ -37,10 +36,6 @@ object DeviceReport {
|
||||
.map { it.substringAfter(':').trim().split(Regex("\\s+")).filter(String::isNotEmpty).joinToString(" ") }
|
||||
.filter(String::isNotEmpty).distinct().joinToString(" | ").ifEmpty { "not reported" }
|
||||
|
||||
internal fun buildDate(millis: Long): String? = millis.takeIf { it > 0 }?.let {
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm 'UTC'", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }.format(Date(it))
|
||||
}
|
||||
|
||||
fun write(context: Context, target: File, mode: String) {
|
||||
try {
|
||||
target.writeText(build(context, mode))
|
||||
@@ -134,7 +129,6 @@ object DeviceReport {
|
||||
k("Android", "${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})")
|
||||
k("Security patch", Build.VERSION.SECURITY_PATCH)
|
||||
k("Build", Build.DISPLAY)
|
||||
k("Build date", buildDate(Build.TIME))
|
||||
k("Fingerprint", Build.FINGERPRINT)
|
||||
k("Kernel", System.getProperty("os.version"))
|
||||
k("ABIs", Build.SUPPORTED_ABIS.joinToString(", "))
|
||||
@@ -192,7 +186,6 @@ object DeviceReport {
|
||||
val fs = StatFs(Environment.getExternalStorageDirectory().path)
|
||||
k("Shared storage free", FileUtils.sizeToString(fs.availableBlocksLong * fs.blockSizeLong))
|
||||
}
|
||||
k("All files access", runCatching { com.droiddeck.launcher.files.AllFilesAccess.state() }.getOrNull())
|
||||
|
||||
h("GPU")
|
||||
k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model"))
|
||||
@@ -291,12 +284,9 @@ object DeviceReport {
|
||||
k("Linux x86 (FEX)", if (com.droiddeck.launcher.runtime.LinuxFex.ready(context)) "ready" else "not set up")
|
||||
k("gamescope realtime", SessionPrefs.gamescopeRealtime(context))
|
||||
k("pace cores", SessionPrefs.paceCores(context))
|
||||
k("guest runtime policy", "native preferred with PRoot fallback")
|
||||
k("guest runtime", when (com.droiddeck.launcher.runtime.NativeGuest.sessionMode) {
|
||||
true -> "native"
|
||||
false -> "PRoot"
|
||||
null -> if (com.droiddeck.launcher.runtime.NativeGuest.enabled(context)) "native available" else "native unavailable"
|
||||
})
|
||||
k("proot without seccomp", SessionPrefs.prootNoSeccomp(context))
|
||||
k("native userland (no proot)", SessionPrefs.nativeUserland(context))
|
||||
k("proot fast path", SessionPrefs.prootFastPath(context))
|
||||
k("proot binary", LinuxRuntime.prootSource(context) + " " + LinuxRuntime.prootBinary(context).path)
|
||||
k("proot fast path (eligible)", com.droiddeck.launcher.runtime.ProotFastPath.enabled(context))
|
||||
k("Guest host name", SessionPrefs.guestHostname(context))
|
||||
|
||||
@@ -119,7 +119,7 @@ object WirelessAdbFix {
|
||||
* socket table, and mDNS often advertises nothing, so the ephemeral range Linux gives adbd is
|
||||
* scanned on loopback (closed ports refuse at once) and the open ports are tried with our key.
|
||||
*/
|
||||
private fun loopbackAdbPort(app: Context, exclude: Int? = null): Int? {
|
||||
private fun loopbackAdbPort(app: Context): Int? {
|
||||
val open = java.util.concurrent.ConcurrentLinkedQueue<Int>()
|
||||
val workers = 32
|
||||
val range = EPHEMERAL_PORTS
|
||||
@@ -127,7 +127,7 @@ object WirelessAdbFix {
|
||||
Thread {
|
||||
var port = range.first + worker
|
||||
while (port <= range.last) {
|
||||
if (port != exclude && answers(LOOPBACK, port, 150)) open += port
|
||||
if (answers(LOOPBACK, port, 150)) open += port
|
||||
port += workers
|
||||
}
|
||||
}.apply { start() }
|
||||
@@ -162,28 +162,8 @@ object WirelessAdbFix {
|
||||
}.getOrDefault(address is Inet4Address)
|
||||
|
||||
fun localConnectPort(context: Context): Int? =
|
||||
discoverConnectPort(context, LOOPBACK)
|
||||
|
||||
private fun discoverConnectPort(context: Context, host: String, exclude: Int? = null): Int? =
|
||||
chooseConnectPort(host, exclude,
|
||||
property = ::tlsPortProperty,
|
||||
advertised = { acceptable -> findConnectPort(context, host, accept = acceptable) },
|
||||
answers = { port -> answers(host, port) },
|
||||
// Some local devices never advertise their connect port. Try only
|
||||
// loopback and require the app's existing paired key to authenticate.
|
||||
authenticatedLocal = { loopbackAdbPort(context.applicationContext, exclude) },
|
||||
)
|
||||
|
||||
internal fun chooseConnectPort(
|
||||
host: String, exclude: Int?,
|
||||
property: () -> Int?, advertised: ((Int) -> Boolean) -> Int?,
|
||||
answers: (Int) -> Boolean, authenticatedLocal: () -> Int?,
|
||||
): Int? {
|
||||
val local = host == LOOPBACK
|
||||
val acceptable: (Int) -> Boolean = { port -> port != exclude && (!local || answers(port)) }
|
||||
val propertyPort = if (local) property()?.takeIf(acceptable) else null
|
||||
return propertyPort ?: advertised(acceptable) ?: if (local) authenticatedLocal() else null
|
||||
}
|
||||
tlsPortProperty()
|
||||
?: findConnectPort(context, LOOPBACK)
|
||||
|
||||
private fun tlsPortProperty(): Int? = runCatching {
|
||||
Class.forName("android.os.SystemProperties").getMethod("get", String::class.java)
|
||||
@@ -321,14 +301,14 @@ object WirelessAdbFix {
|
||||
if (cachedPort != null) {
|
||||
val cachedResult = runCatching { action(appContext, saved.host, cachedPort) }
|
||||
if (cachedResult.isSuccess) return
|
||||
val discoveredPort = discoverConnectPort(appContext, saved.host, exclude = cachedPort)
|
||||
val discoveredPort = findConnectPort(appContext, saved.host)
|
||||
if (discoveredPort != null && discoveredPort != cachedPort) {
|
||||
action(appContext, saved.host, discoveredPort)
|
||||
} else {
|
||||
cachedResult.getOrThrow()
|
||||
}
|
||||
} else {
|
||||
val discoveredPort = discoverConnectPort(appContext, saved.host)
|
||||
val discoveredPort = findConnectPort(appContext, saved.host)
|
||||
?: error(appContext.getString(R.string.adbfix_enter_address))
|
||||
action(appContext, saved.host, discoveredPort)
|
||||
}
|
||||
|
||||
@@ -4,23 +4,20 @@ import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.RemoteInput
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.net.nsd.NsdManager
|
||||
import android.net.nsd.NsdServiceInfo
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.util.TypedValue
|
||||
import android.widget.RemoteViews
|
||||
import com.droiddeck.launcher.FrontEndActivity
|
||||
import com.droiddeck.launcher.R
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
|
||||
class WirelessAdbPairingService : Service() {
|
||||
override fun attachBaseContext(newBase: android.content.Context) =
|
||||
@@ -40,8 +37,6 @@ class WirelessAdbPairingService : Service() {
|
||||
private var discovery: NsdManager.DiscoveryListener? = null
|
||||
private var pairingHost: String? = null
|
||||
private var pairingPort: Int? = null
|
||||
private val keypad = WirelessPairingKeypad()
|
||||
private var keypadToken = UUID.randomUUID().toString()
|
||||
@Volatile private var working = false
|
||||
@Volatile private var limitEnabled = false
|
||||
@Volatile private var session = 0
|
||||
@@ -51,21 +46,13 @@ class WirelessAdbPairingService : Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
when (intent?.action) {
|
||||
ACTION_KEYPAD -> {
|
||||
if (intent.data?.host == keypadToken && current.value is Stage.CodeNeeded && !working) {
|
||||
val key = intent.data?.lastPathSegment?.toIntOrNull()
|
||||
if (key == WirelessPairingKeypad.SUBMIT) {
|
||||
if (keypad.ready && pairingPort != null) onCode(keypad.digits)
|
||||
} else if (key != null && keypad.press(key)) {
|
||||
show(current.value, quietUpdate = true)
|
||||
}
|
||||
} else if (current.value == Stage.Idle) {
|
||||
stopSelf(startId)
|
||||
}
|
||||
ACTION_CODE -> {
|
||||
val code = RemoteInput.getResultsFromIntent(intent)?.getCharSequence(KEY_CODE)
|
||||
?.filter(Char::isDigit)?.toString().orEmpty()
|
||||
onCode(code)
|
||||
}
|
||||
ACTION_CANCEL -> finish(Stage.Idle)
|
||||
null -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true)
|
||||
else -> if (discovery == null && !working) stopSelf(startId)
|
||||
else -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true)
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
@@ -73,13 +60,11 @@ class WirelessAdbPairingService : Service() {
|
||||
private fun begin(enableLimit: Boolean) {
|
||||
if (working) return
|
||||
session++
|
||||
resetKeypad()
|
||||
limitEnabled = enableLimit
|
||||
pairingHost = null
|
||||
pairingPort = null
|
||||
working = false
|
||||
publish(Stage.Waiting)
|
||||
getSystemService(NotificationManager::class.java)?.cancel(KEYPAD_NOTIFICATION_ID)
|
||||
startForeground(NOTIFICATION_ID, notification(Stage.Waiting))
|
||||
startDiscovery()
|
||||
main.removeCallbacks(timeout)
|
||||
@@ -116,13 +101,9 @@ class WirelessAdbPairingService : Service() {
|
||||
if (!WirelessAdbFix.isLocalAddress(address)) return
|
||||
main.post {
|
||||
if (owner != session || working || current.value == Stage.Done) return@post
|
||||
val endpointChanged = pairingHost != address.hostAddress || pairingPort != serviceInfo.port
|
||||
pairingHost = address.hostAddress
|
||||
pairingPort = serviceInfo.port
|
||||
if (endpointChanged) {
|
||||
resetKeypad()
|
||||
show(Stage.CodeNeeded())
|
||||
}
|
||||
if (current.value !is Stage.CodeNeeded) show(Stage.CodeNeeded())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,12 +117,11 @@ class WirelessAdbPairingService : Service() {
|
||||
show(Stage.Waiting)
|
||||
return
|
||||
}
|
||||
if (code.length != WirelessPairingKeypad.LENGTH) {
|
||||
if (code.length != 6) {
|
||||
show(Stage.CodeNeeded(getString(R.string.adbpair_six_digits)))
|
||||
return
|
||||
}
|
||||
working = true
|
||||
resetKeypad()
|
||||
val owner = session
|
||||
val enable = limitEnabled
|
||||
show(Stage.Working(getString(R.string.adbpair_pairing)))
|
||||
@@ -175,34 +155,17 @@ class WirelessAdbPairingService : Service() {
|
||||
}, "wireless-adb-pairing").start()
|
||||
}
|
||||
|
||||
private fun show(stage: Stage, quietUpdate: Boolean = false) {
|
||||
private fun show(stage: Stage) {
|
||||
publish(stage)
|
||||
val manager = getSystemService(NotificationManager::class.java) ?: return
|
||||
if (stage is Stage.CodeNeeded) {
|
||||
// A new high-priority notification can pop over Settings. Updating the
|
||||
// quiet foreground-service notification can leave the keypad in the shade.
|
||||
// End any previous indeterminate progress even if this is a code retry.
|
||||
if (!quietUpdate) manager.notify(NOTIFICATION_ID, notification(stage, foregroundCodeEntry = true))
|
||||
manager.notify(KEYPAD_NOTIFICATION_ID, notification(stage, quietUpdate))
|
||||
} else {
|
||||
manager.cancel(KEYPAD_NOTIFICATION_ID)
|
||||
manager.notify(NOTIFICATION_ID, notification(stage, quietUpdate))
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetKeypad() {
|
||||
keypad.clear()
|
||||
keypadToken = UUID.randomUUID().toString()
|
||||
getSystemService(NotificationManager::class.java)?.notify(NOTIFICATION_ID, notification(stage))
|
||||
}
|
||||
|
||||
private fun finish(stage: Stage) {
|
||||
session++
|
||||
resetKeypad()
|
||||
main.removeCallbacks(timeout)
|
||||
stopDiscovery()
|
||||
publish(stage)
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
manager?.cancel(KEYPAD_NOTIFICATION_ID)
|
||||
if (stage is Stage.Done || stage is Stage.Failed) {
|
||||
manager?.notify(NOTIFICATION_ID, notification(stage))
|
||||
stopForeground(STOP_FOREGROUND_DETACH)
|
||||
@@ -220,16 +183,13 @@ class WirelessAdbPairingService : Service() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
getSystemService(NotificationManager::class.java)?.cancel(KEYPAD_NOTIFICATION_ID)
|
||||
main.removeCallbacks(timeout)
|
||||
stopDiscovery()
|
||||
if (current.value.let { it is Stage.Waiting || it is Stage.CodeNeeded || it is Stage.Working }) publish(Stage.Idle)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun notification(
|
||||
stage: Stage, quietUpdate: Boolean = false, foregroundCodeEntry: Boolean = false,
|
||||
): Notification {
|
||||
private fun notification(stage: Stage): Notification {
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
manager?.createNotificationChannel(NotificationChannel(CHANNEL_ID, getString(R.string.adbpair_channel_name),
|
||||
NotificationManager.IMPORTANCE_HIGH).apply {
|
||||
@@ -245,7 +205,7 @@ class WirelessAdbPairingService : Service() {
|
||||
PendingIntent.FLAG_IMMUTABLE)
|
||||
val cancel = PendingIntent.getService(this, 1,
|
||||
Intent(this, WirelessAdbPairingService::class.java).setAction(ACTION_CANCEL), PendingIntent.FLAG_IMMUTABLE)
|
||||
val quiet = foregroundCodeEntry || stage == Stage.Waiting || stage == Stage.Idle || stage is Stage.Working
|
||||
val quiet = stage == Stage.Waiting || stage == Stage.Idle || stage is Stage.Working
|
||||
val builder = Notification.Builder(this, if (quiet) PROGRESS_CHANNEL_ID else CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_stat_session)
|
||||
.setContentIntent(open)
|
||||
@@ -260,31 +220,19 @@ class WirelessAdbPairingService : Service() {
|
||||
.setOnlyAlertOnce(true)
|
||||
.addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build())
|
||||
is Stage.CodeNeeded -> {
|
||||
val reply = PendingIntent.getService(this, 2,
|
||||
Intent(this, WirelessAdbPairingService::class.java).setAction(ACTION_CODE),
|
||||
if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
else PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val input = RemoteInput.Builder(KEY_CODE).setLabel(getString(R.string.adbpair_code_label)).build()
|
||||
val text = stage.error ?: getString(R.string.adbpair_code_hint)
|
||||
builder
|
||||
.setContentTitle(getString(if (foregroundCodeEntry) R.string.adbpair_title_pair
|
||||
else if (stage.error == null) R.string.adbpair_title_code else R.string.adbpair_title_retry))
|
||||
.setContentIntent(null)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setLocalOnly(true)
|
||||
.setContentTitle(getString(if (stage.error == null) R.string.adbpair_title_code else R.string.adbpair_title_retry))
|
||||
.setContentText(text)
|
||||
.setStyle(Notification.BigTextStyle().bigText(text))
|
||||
.setOngoing(true)
|
||||
.setOnlyAlertOnce(foregroundCodeEntry || quietUpdate)
|
||||
if (!foregroundCodeEntry) {
|
||||
// Keep the keypad separate from status/install notifications. Android owns
|
||||
// the heads-up timeout; the drawer remains usable without expanding a group.
|
||||
builder.setGroup(KEYPAD_GROUP)
|
||||
.addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build())
|
||||
if (stage.error != null && pairingPort == null) {
|
||||
builder.setContentText(stage.error)
|
||||
.setStyle(Notification.BigTextStyle().bigText(stage.error))
|
||||
} else {
|
||||
builder.setStyle(Notification.DecoratedCustomViewStyle())
|
||||
.setCustomBigContentView(pairingKeypad())
|
||||
.setCustomHeadsUpContentView(pairingKeypad(keyHeightDp = 24))
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
builder.setCustomContentView(pairingKeypad(keyHeightDp = 21))
|
||||
}
|
||||
}
|
||||
}
|
||||
.addAction(Notification.Action.Builder(null, getString(R.string.adbpair_enter_code), reply).addRemoteInput(input).build())
|
||||
.addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build())
|
||||
}
|
||||
is Stage.Working -> builder
|
||||
.setContentTitle(getString(R.string.adbpair_title_working))
|
||||
@@ -306,39 +254,14 @@ class WirelessAdbPairingService : Service() {
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private fun pairingKeypad(keyHeightDp: Int? = null): RemoteViews = RemoteViews(packageName, R.layout.wireless_pairing_keypad).apply {
|
||||
val ids = intArrayOf(R.id.pair_key_0, R.id.pair_key_1, R.id.pair_key_2, R.id.pair_key_3, R.id.pair_key_4,
|
||||
R.id.pair_key_5, R.id.pair_key_6, R.id.pair_key_7, R.id.pair_key_8, R.id.pair_key_9,
|
||||
R.id.pair_key_delete, R.id.pair_key_submit)
|
||||
ids.forEachIndexed { key, id ->
|
||||
if (keyHeightDp != null && Build.VERSION.SDK_INT >= 31) {
|
||||
// Fit both rows inside the system template's heads-up or collapsed height.
|
||||
setViewLayoutHeight(id, keyHeightDp.toFloat(), TypedValue.COMPLEX_UNIT_DIP)
|
||||
setViewLayoutMargin(id, RemoteViews.MARGIN_TOP, 1f, TypedValue.COMPLEX_UNIT_DIP)
|
||||
setViewLayoutMargin(id, RemoteViews.MARGIN_BOTTOM, 1f, TypedValue.COMPLEX_UNIT_DIP)
|
||||
setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, if (keyHeightDp < 24) 14f else 15f)
|
||||
}
|
||||
val intent = Intent(this@WirelessAdbPairingService, WirelessAdbPairingService::class.java)
|
||||
.setAction(ACTION_KEYPAD)
|
||||
.setData(Uri.Builder().scheme("droiddeck-pairing").authority(keypadToken).appendPath(key.toString()).build())
|
||||
val press = PendingIntent.getService(this@WirelessAdbPairingService, key, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
setOnClickPendingIntent(id, press)
|
||||
}
|
||||
setTextViewText(R.id.pair_key_code, keypad.display)
|
||||
setContentDescription(R.id.pair_key_code, getString(R.string.adbpair_keypad_entered, keypad.digits.length))
|
||||
setBoolean(R.id.pair_key_delete, "setEnabled", keypad.digits.isNotEmpty())
|
||||
setBoolean(R.id.pair_key_submit, "setEnabled", keypad.ready && pairingPort != null)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CHANNEL_ID = "wireless-adb-pairing"
|
||||
private const val PROGRESS_CHANNEL_ID = "wireless-adb-pairing-progress"
|
||||
private const val NOTIFICATION_ID = 3
|
||||
private const val KEYPAD_NOTIFICATION_ID = 3403
|
||||
private const val KEYPAD_GROUP = "wireless-adb-keypad"
|
||||
private const val PAIRING_TYPE = "_adb-tls-pairing._tcp"
|
||||
private const val ACTION_KEYPAD = "com.droiddeck.launcher.action.WIRELESS_ADB_KEYPAD"
|
||||
private const val ACTION_CODE = "com.droiddeck.launcher.action.WIRELESS_ADB_CODE"
|
||||
private const val ACTION_CANCEL = "com.droiddeck.launcher.action.WIRELESS_ADB_CANCEL"
|
||||
private const val KEY_CODE = "code"
|
||||
private const val EXTRA_ENABLE_LIMIT = "enable_limit"
|
||||
private const val TIMEOUT_MS = 5 * 60_000L
|
||||
|
||||
@@ -365,7 +288,7 @@ class WirelessAdbPairingService : Service() {
|
||||
fun notificationsEnabled(context: Context): Boolean =
|
||||
context.getSystemService(NotificationManager::class.java)?.areNotificationsEnabled() != false && !channelBlocked(context)
|
||||
|
||||
/** Pairing needs this notification channel to show the keypad over Android Settings. */
|
||||
/** The code is typed into a notification on this channel; a channel the user switched off leaves pairing with nothing to type into. */
|
||||
fun channelBlocked(context: Context): Boolean =
|
||||
context.getSystemService(NotificationManager::class.java)?.getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
internal class WirelessPairingKeypad {
|
||||
var digits = ""
|
||||
private set
|
||||
val ready: Boolean get() = digits.length == LENGTH
|
||||
val display: String get() = digits.padEnd(LENGTH, '–')
|
||||
|
||||
fun press(key: Int): Boolean {
|
||||
val next = when {
|
||||
key == DELETE -> digits.dropLast(1)
|
||||
key in 0..9 && !ready -> digits + key
|
||||
else -> digits
|
||||
}
|
||||
if (next == digits) return false
|
||||
digits = next
|
||||
return true
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
digits = ""
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LENGTH = 6
|
||||
const val DELETE = 10
|
||||
const val SUBMIT = 11
|
||||
}
|
||||
}
|
||||
@@ -14,15 +14,6 @@ object AllFilesAccess {
|
||||
fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
|
||||
sdk >= Build.VERSION_CODES.R && !granted()
|
||||
|
||||
fun state(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): String = when {
|
||||
sdk < Build.VERSION_CODES.R -> "not needed"
|
||||
granted() -> "granted"
|
||||
else -> "missing"
|
||||
}
|
||||
|
||||
fun mayHideFilesIn(path: String, sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
|
||||
covers(path) && missing(sdk, granted)
|
||||
|
||||
/** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */
|
||||
fun covers(path: String): Boolean {
|
||||
val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false
|
||||
|
||||
@@ -10,13 +10,11 @@ object FrameGen {
|
||||
const val ENGINE_DDFG = "ddfg"
|
||||
private const val LEGACY_ENGINE_WINFG = "winfg"
|
||||
const val ENGINE_LSFG = "lsfg"
|
||||
const val ENGINE_ZEROFG = "zerofg"
|
||||
|
||||
private const val DDFG_PERF_PRESET = 2
|
||||
private const val DDFG_MODEL = 4
|
||||
private const val FLOW_SCALE_DDFG = 0.60f
|
||||
private const val FLOW_SCALE_LSFG = 0.80f
|
||||
private const val FLOW_SCALE_ZEROFG = 1.0f
|
||||
|
||||
val ADAPTIVE_TARGETS = listOf(120, 90, 60)
|
||||
|
||||
@@ -71,14 +69,6 @@ object FrameGen {
|
||||
.putString("engine", mode.engine).putInt("multiplier", mode.multiplier).putInt("target", mode.target).apply()
|
||||
}
|
||||
|
||||
fun pacerEnabled(context: Context): Boolean =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean("pacer", false)
|
||||
|
||||
fun setPacer(context: Context, enabled: Boolean) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean("pacer", enabled).apply()
|
||||
WaylandCompositor.nativeSetFrameGenPacer(enabled)
|
||||
}
|
||||
|
||||
fun clearGlobal(context: Context) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
||||
.remove("engine").remove("multiplier").remove("target").apply()
|
||||
@@ -90,7 +80,6 @@ object FrameGen {
|
||||
mode.engine == ENGINE_DDFG -> context.getString(R.string.frame_gen_ddfg, mode.multiplier)
|
||||
mode.engine == ENGINE_LSFG && mode.target > 0 -> context.getString(R.string.frame_gen_lsfg_adaptive, mode.target)
|
||||
mode.engine == ENGINE_LSFG -> context.getString(R.string.frame_gen_lsfg, mode.multiplier)
|
||||
mode.engine == ENGINE_ZEROFG -> context.getString(R.string.frame_gen_zerofg, mode.multiplier)
|
||||
else -> context.getString(R.string.frame_gen_off)
|
||||
}
|
||||
|
||||
@@ -115,7 +104,6 @@ object FrameGen {
|
||||
|
||||
fun applyPrepared(context: Context, prepared: PreparedApply, refreshHz: Float): String? {
|
||||
val mode = prepared.mode
|
||||
WaylandCompositor.nativeSetFrameGenPacer(pacerEnabled(context))
|
||||
when (mode.engine) {
|
||||
ENGINE_LSFG -> {
|
||||
val status = prepared.lsfgStatus ?: LsfgNative.STATUS_NOT_INSTALLED
|
||||
@@ -123,7 +111,7 @@ object FrameGen {
|
||||
if (status != LsfgNative.STATUS_OK || cachePath == null) {
|
||||
WaylandCompositor.nativeSetFrameGenArmed(false, 0, 0)
|
||||
val problem = context.getString(
|
||||
if (status == LsfgNative.STATUS_NOT_INSTALLED) R.string.lsfg_needs_steam else R.string.lsfg_problem_failed,
|
||||
if (status == LsfgNative.STATUS_NOT_INSTALLED) R.string.lsfg_problem_missing else R.string.lsfg_problem_failed,
|
||||
)
|
||||
Log.w(TAG, "$problem (status $status)")
|
||||
return problem
|
||||
@@ -139,11 +127,6 @@ object FrameGen {
|
||||
WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_DDFG, refreshHz)
|
||||
WaylandCompositor.nativeSetFrameGenArmed(true, mode.multiplier, 0)
|
||||
}
|
||||
ENGINE_ZEROFG -> {
|
||||
WaylandCompositor.nativeSetFrameGenEngine(WaylandCompositor.FG_ENGINE_ZEROFG)
|
||||
WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_ZEROFG, refreshHz)
|
||||
WaylandCompositor.nativeSetFrameGenArmed(true, mode.multiplier, 0)
|
||||
}
|
||||
else -> WaylandCompositor.nativeSetFrameGenArmed(false, 0, 0)
|
||||
}
|
||||
Log.i(TAG, "frame generation: $mode at ${refreshHz}Hz")
|
||||
|
||||
@@ -2,16 +2,22 @@ package com.droiddeck.launcher.gpu
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.GameStorage
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import java.io.File
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
object Lossless {
|
||||
data class State(val owned: Boolean, val ready: Boolean) {
|
||||
enum class Source { NONE, STEAM, IMPORT }
|
||||
|
||||
enum class ImportResult { UPDATED, UNCHANGED, NOT_OWNED, INVALID, FAILED }
|
||||
|
||||
data class State(val owned: Boolean, val ready: Boolean, val source: Source) {
|
||||
companion object {
|
||||
val NONE = State(owned = false, ready = false)
|
||||
val NONE = State(owned = false, ready = false, source = Source.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +26,15 @@ object Lossless {
|
||||
private const val KEY_OWNED = "owned"
|
||||
private const val KEY_ID = "id"
|
||||
private const val KEY_SOURCE = "source"
|
||||
private const val SOURCE_STEAM = "STEAM"
|
||||
private const val KEY_STEAM_STAMP = "steamStamp"
|
||||
private const val STEAM_MANIFEST = "steamapps/appmanifest_993090.acf"
|
||||
private const val STEAM_DLL = "steamapps/common/Lossless Scaling/Lossless.dll"
|
||||
private const val UNCHANGED = -1
|
||||
|
||||
fun state(context: Context) = State(owned(context), cacheFile(context)?.isFile == true)
|
||||
fun state(context: Context): State {
|
||||
val source = prefs(context).getString(KEY_SOURCE, null)
|
||||
?.let { name -> Source.entries.firstOrNull { it.name == name } } ?: Source.NONE
|
||||
return State(owned(context), cacheFile(context)?.isFile == true, source)
|
||||
}
|
||||
|
||||
fun owned(context: Context): Boolean {
|
||||
if (prefs(context).getBoolean(KEY_OWNED, false)) return true
|
||||
@@ -35,46 +43,61 @@ object Lossless {
|
||||
return true
|
||||
}
|
||||
|
||||
fun cacheFile(context: Context): File? = steamCacheId(context)?.let { cacheFor(context, it) }
|
||||
|
||||
private fun steamCacheId(context: Context): String? = prefs(context).let {
|
||||
if (it.getString(KEY_SOURCE, null) == SOURCE_STEAM) it.getString(KEY_ID, null) else null
|
||||
}
|
||||
fun cacheFile(context: Context): File? = prefs(context).getString(KEY_ID, null)?.let { cacheFor(context, it) }
|
||||
|
||||
@Synchronized
|
||||
fun sync(context: Context): Int {
|
||||
val settings = prefs(context)
|
||||
if (steamCacheId(context) == null && settings.contains(KEY_ID)) {
|
||||
settings.edit().remove(KEY_ID).remove(KEY_SOURCE).remove(KEY_STEAM_STAMP).apply()
|
||||
}
|
||||
val steam = steamDll(context)
|
||||
if (steam != null) {
|
||||
markOwned(context)
|
||||
val stamp = "${steam.length()}:${steam.lastModified()}"
|
||||
if (stamp != settings.getString(KEY_STEAM_STAMP, null)) {
|
||||
val status = adoptSteamDll(context, steam)
|
||||
if (stamp != prefs(context).getString(KEY_STEAM_STAMP, null)) {
|
||||
val status = adopt(context, steam, Source.STEAM)
|
||||
if (status != LsfgNative.STATUS_OK && status != UNCHANGED) {
|
||||
Log.w(TAG, "Steam copy $steam not taken: ${statusName(status)}")
|
||||
}
|
||||
settings.edit().putString(KEY_STEAM_STAMP, stamp).apply()
|
||||
prefs(context).edit().putString(KEY_STEAM_STAMP, stamp).apply()
|
||||
}
|
||||
}
|
||||
return ensureBuilt(context)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun import(context: Context, dll: File): ImportResult {
|
||||
if (!owned(context)) return ImportResult.NOT_OWNED
|
||||
return when (adopt(context, dll, Source.IMPORT)) {
|
||||
UNCHANGED -> ImportResult.UNCHANGED
|
||||
LsfgNative.STATUS_OK -> ImportResult.UPDATED
|
||||
LsfgNative.STATUS_UNREADABLE_FILE, LsfgNative.STATUS_NOT_PORTABLE_EXECUTABLE,
|
||||
LsfgNative.STATUS_MISSING_SHADERS -> ImportResult.INVALID
|
||||
else -> ImportResult.FAILED
|
||||
}
|
||||
}
|
||||
|
||||
fun message(context: Context, result: ImportResult): String = context.getString(
|
||||
when (result) {
|
||||
ImportResult.UPDATED -> R.string.lsfg_imported
|
||||
ImportResult.UNCHANGED -> R.string.lsfg_import_unchanged
|
||||
ImportResult.NOT_OWNED -> R.string.lsfg_import_not_owned
|
||||
ImportResult.INVALID -> R.string.lsfg_import_invalid
|
||||
ImportResult.FAILED -> R.string.lsfg_import_failed
|
||||
},
|
||||
)
|
||||
|
||||
private fun ensureBuilt(context: Context): Int {
|
||||
val cache = cacheFile(context) ?: return LsfgNative.STATUS_NOT_INSTALLED
|
||||
val id = prefs(context).getString(KEY_ID, null) ?: return LsfgNative.STATUS_NOT_INSTALLED
|
||||
val cache = cacheFor(context, id)
|
||||
if (usable(cache)) return LsfgNative.STATUS_OK
|
||||
val dll = storedDll(context)
|
||||
if (!dll.isFile) return LsfgNative.STATUS_NOT_INSTALLED
|
||||
return build(dll, cache)
|
||||
}
|
||||
|
||||
private fun adoptSteamDll(context: Context, source: File): Int {
|
||||
private fun adopt(context: Context, source: File, from: Source): Int {
|
||||
val staged = File(dir(context).apply { mkdirs() }, "Lossless.dll.staged")
|
||||
try {
|
||||
val id = copyHashing(source, staged)
|
||||
if (id == steamCacheId(context) && usable(cacheFor(context, id))) return UNCHANGED
|
||||
if (id == prefs(context).getString(KEY_ID, null) && usable(cacheFor(context, id))) return UNCHANGED
|
||||
val cache = cacheFor(context, id)
|
||||
var status = LsfgNative.nativeValidateDll(staged.path)
|
||||
if (status == LsfgNative.STATUS_OK) status = build(staged, cache)
|
||||
@@ -86,9 +109,9 @@ object Lossless {
|
||||
cache.delete()
|
||||
return LsfgNative.STATUS_CACHE_UNUSABLE
|
||||
}
|
||||
prefs(context).edit().putString(KEY_ID, id).putString(KEY_SOURCE, SOURCE_STEAM).apply()
|
||||
prefs(context).edit().putString(KEY_ID, id).putString(KEY_SOURCE, from.name).apply()
|
||||
removeStale(context, id)
|
||||
Log.i(TAG, "Steam Lossless.dll from $source ready as $id")
|
||||
Log.i(TAG, "Lossless.dll from $source ($from) ready as $id")
|
||||
return LsfgNative.STATUS_OK
|
||||
} catch (e: java.io.IOException) {
|
||||
Log.w(TAG, "could not copy $source", e)
|
||||
@@ -135,13 +158,9 @@ object Lossless {
|
||||
GameStorage.effective(context)?.path?.let(::File),
|
||||
GameStorage.x64CardLibrary(context),
|
||||
) + com.droiddeck.launcher.frontend.AddedGames.roots(context).map { it.host }
|
||||
return installedSteamDll(libraries)
|
||||
return libraries.map { File(it, STEAM_DLL) }.filter { it.isFile }.maxByOrNull { it.lastModified() }
|
||||
}
|
||||
|
||||
internal fun installedSteamDll(libraries: List<File>): File? =
|
||||
libraries.asSequence().filter { File(it, STEAM_MANIFEST).isFile }
|
||||
.map { File(it, STEAM_DLL) }.filter { it.isFile }.maxByOrNull { it.lastModified() }
|
||||
|
||||
private fun markOwned(context: Context) {
|
||||
if (!prefs(context).getBoolean(KEY_OWNED, false)) prefs(context).edit().putBoolean(KEY_OWNED, true).apply()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ internal object DroidDeckHudConfig {
|
||||
"showPerCore" to "1", "showTemp" to "1", "showBatteryTemp" to "1", "showGpuTemp" to "0",
|
||||
"showVram" to "1", "showRAM" to "1", "showSwap" to "1", "showBattery" to "0", "showBatteryTime" to "0", "showPower" to "1",
|
||||
"showFPS" to "1", "showFPSGraph" to "1", "fpsDecimal" to "1",
|
||||
"showLatency" to "1", "showAvg" to "1", "showLow1" to "1", "showLow01" to "0", "showLow001" to "0",
|
||||
"showLatency" to "1", "showAvg" to "1", "showLow1" to "1", "showLow01" to "1", "showLow001" to "1",
|
||||
"showEngine" to "1", "showRenderer" to "1",
|
||||
"showDisplay" to "1", "showHdr" to "1", "showNet" to "1", "showResolution" to "1",
|
||||
"showProton" to "1", "showSession" to "1", "showClock" to "1", "hudOrder" to "",
|
||||
|
||||
@@ -40,8 +40,7 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
|
||||
PILL("pill", "Pill"),
|
||||
MINIMAL("minimal", "Minimal"),
|
||||
MEGA("mega", "Mega"),
|
||||
STRIP("strip", "Strip"),
|
||||
SIDE_STRIP("side_strip", "Side strip");
|
||||
STRIP("strip", "Strip");
|
||||
|
||||
fun next(): DroidDeckHudSize {
|
||||
val all = values()
|
||||
@@ -97,11 +96,6 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
|
||||
"showCPUUsage", "showTemp", "showVram", "showRAM", "showBattery", "showBatteryTemp", "showBatteryTime",
|
||||
"showPower", "showDisplay", "showHdr", "showGpuModel",
|
||||
),
|
||||
SIDE_STRIP to listOf(
|
||||
"showFPS", "showFPSGraph", "showAvg", "showLow1",
|
||||
"showGPULoad", "showGpuTemp", "showCPUUsage", "showTemp", "showRAM", "showVram",
|
||||
"showPower", "showBattery", "showBatteryTemp", "showBatteryTime",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -116,7 +110,6 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
|
||||
MEGA to DroidDeckHudStyle(row = 11.5f, unit = 11.5f * 0.62f, pad = 10f, lineGap = 3.5f, labelGap = 7f,
|
||||
band = 9.5f, gutter = 16f),
|
||||
STRIP to DroidDeckHudStyle(row = 11.5f, unit = 11.5f * 0.8f, pad = 10f, lineGap = 0f, labelGap = 13f),
|
||||
SIDE_STRIP to DroidDeckHudStyle(row = 11.5f, unit = 9f, pad = 8f, lineGap = 4f, labelGap = 4f, key = 9f),
|
||||
)
|
||||
|
||||
fun rowsFor(size: DroidDeckHudSize, values: Map<String, String>): List<String> =
|
||||
|
||||
@@ -92,8 +92,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
private var showBatteryTemp = false
|
||||
private var showGraph = false
|
||||
private var showLow1 = true
|
||||
private var showLow01 = false
|
||||
private var showLow001 = false
|
||||
private var showLow01 = true
|
||||
private var showLow001 = true
|
||||
private var fpsDecimal = true
|
||||
private var showClockTime = true
|
||||
private var showLatency = true
|
||||
@@ -187,12 +187,6 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
private var graphRect: RectF? = null
|
||||
private var contentW = 0f
|
||||
private var contentH = 0f
|
||||
private var viewportW = Float.POSITIVE_INFINITY
|
||||
private var viewportH = Float.POSITIVE_INFINITY
|
||||
|
||||
private val panelFit: Float
|
||||
get() = if (dPanel == null || contentW <= 0f || contentH <= 0f) 1f
|
||||
else minOf(1f, viewportW / contentW, viewportH / contentH)
|
||||
|
||||
private var onMovedListener: BiConsumer<Float, Float>? = null
|
||||
private var onSizeCycledListener: Consumer<String>? = null
|
||||
@@ -573,7 +567,6 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
if (s == null) { contentW = 0f; contentH = 0f; return }
|
||||
if (dock != DroidDeckHudDock.NONE) { buildDockTab(); return }
|
||||
if (size == DroidDeckHudSize.STRIP) { buildStrip(s); return }
|
||||
if (size == DroidDeckHudSize.SIDE_STRIP) { buildSideStrip(s); return }
|
||||
buildRows(s)
|
||||
if (contentW <= 0f || contentH <= 0f) return
|
||||
if (size == DroidDeckHudSize.PILL) addSubtleClock(sp(10f), leftAligned = true)
|
||||
@@ -685,8 +678,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
finishPanel(panel, halfRound = halfRound)
|
||||
}
|
||||
|
||||
private fun finishPanel(panel: RectF, halfRound: Boolean, maxRadius: Float = sp(56f), inset: Float = panelInset()) {
|
||||
val r = if (halfRound) panel.height() / 2f else min(panel.height() / 2f, maxRadius)
|
||||
private fun finishPanel(panel: RectF, halfRound: Boolean) {
|
||||
val r = if (halfRound) panel.height() / 2f else min(panel.height() / 2f, sp(56f))
|
||||
val margin = outlineWidth() + sp(4f)
|
||||
fun curveIn(top: Float, bottom: Float): Float {
|
||||
val d = max(max(panel.top + r - top, bottom - (panel.bottom - r)), 0f)
|
||||
@@ -704,8 +697,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
for (t in tileRects) right = max(right, t.right + curveIn(t.top, t.bottom) + margin)
|
||||
panel.right = max(right, panel.left + sp(6f) + r)
|
||||
dPanel = panel; dRadius = r
|
||||
contentW = panel.right + inset
|
||||
contentH = panel.bottom + inset
|
||||
contentW = panel.right + panelInset()
|
||||
contentH = panel.bottom + panelInset()
|
||||
}
|
||||
|
||||
private fun clockTimeString(): String = DateFormat.getTimeFormat(context).format(Date())
|
||||
@@ -937,58 +930,6 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildSideStrip(s: HudMetrics.Snapshot) {
|
||||
val style = size.style
|
||||
val inset = sp(5f)
|
||||
val panelWidth = sp(86f)
|
||||
val pad = sp(style.pad)
|
||||
val left = inset + pad
|
||||
val right = inset + panelWidth - pad
|
||||
val markHeight = sp(12f)
|
||||
val markTop = inset + sp(6f)
|
||||
val markLeft = left - DroidDeckMark.inkLeftFor(markHeight)
|
||||
headerMark = RectF(markLeft, markTop, markLeft + DroidDeckMark.widthFor(markHeight), markTop + markHeight)
|
||||
dDividerTop = markTop + markHeight + sp(6f)
|
||||
|
||||
if (showClockTime) {
|
||||
val clock = clockTimeString()
|
||||
val clockPx = sp(8.5f)
|
||||
val clockWidth = measure(clock, clockPx)
|
||||
if (right - clockWidth >= markLeft + DroidDeckMark.inkRightFor(markHeight) + sp(4f)) {
|
||||
val baseline = markTop + (markHeight + capHeight(clockPx)) / 2f
|
||||
glyphs.add(Glyph(right - clockWidth, baseline, clock, blend(colDim), clockPx))
|
||||
}
|
||||
}
|
||||
|
||||
val labelPx = sp(style.key)
|
||||
val rowPx = sp(style.row)
|
||||
val unitPx = sp(style.unit)
|
||||
val lineGap = sp(style.lineGap)
|
||||
var y = dDividerTop + sp(6f)
|
||||
for (key in size.rowsIn(storedOrder)) {
|
||||
if (!switchOn(key)) continue
|
||||
if (key == "showFPSGraph") {
|
||||
val height = sp(15f)
|
||||
graphRect = RectF(left, y, right, y + height)
|
||||
y += height + lineGap
|
||||
continue
|
||||
}
|
||||
|
||||
val valuePx = if (key == "showFPS") sp(16f) else rowPx
|
||||
val row = reading(key, s, labelPx, valuePx, unitPx)
|
||||
val available = right - left - measure(row.label.text, labelPx) - sp(style.labelGap)
|
||||
val fit = (available / runWidth(row.vals)).coerceIn(0f, 1f)
|
||||
val values = row.vals.map { Span(it.text, it.color, it.sizePx * fit, it.glow) }
|
||||
val baseline = y - ascent(valuePx)
|
||||
placeRun(left, baseline, listOf(row.label))
|
||||
placeRun(right - runWidth(values), baseline, values)
|
||||
y += lineH(valuePx) + lineGap
|
||||
}
|
||||
|
||||
val panel = RectF(inset, inset, inset + panelWidth, y + sp(7f))
|
||||
finishPanel(panel, halfRound = false, maxRadius = sp(11f), inset = inset)
|
||||
}
|
||||
|
||||
private fun buildStrip(s: HudMetrics.Snapshot) {
|
||||
val rowPx = sp(11.5f); val unitPx = rowPx * 0.8f; val fpsPx = sp(15f)
|
||||
val padX = sp(10f); val groupGap = sp(13f)
|
||||
@@ -1052,20 +993,13 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
viewportW = viewportLimit(widthMeasureSpec)
|
||||
viewportH = viewportLimit(heightMeasureSpec)
|
||||
if (stripRect != null) { setMeasuredDimension(contentW.roundToInt(), resolveSize(contentH.roundToInt(), heightMeasureSpec)); return }
|
||||
val fit = panelFit
|
||||
setMeasuredDimension(
|
||||
resolveSize((contentW * fit).roundToInt(), widthMeasureSpec),
|
||||
resolveSize((contentH * fit).roundToInt(), heightMeasureSpec),
|
||||
resolveSize(contentW.roundToInt(), widthMeasureSpec),
|
||||
resolveSize(contentH.roundToInt(), heightMeasureSpec),
|
||||
)
|
||||
}
|
||||
|
||||
private fun viewportLimit(spec: Int): Float =
|
||||
if (MeasureSpec.getMode(spec) == MeasureSpec.UNSPECIFIED) Float.POSITIVE_INFINITY
|
||||
else MeasureSpec.getSize(spec).toFloat()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (contentW <= 0f || contentH <= 0f) { lockController.drawBadge(canvas); return }
|
||||
val blend = if (dock == DroidDeckHudDock.NONE && previewEdge != DroidDeckHudDock.NONE) previewBlend else 0f
|
||||
@@ -1100,10 +1034,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
private fun drawContent(canvas: Canvas) {
|
||||
val fit = panelFit
|
||||
dPanel?.let { panel -> panelFrame(panel, fit)?.let { canvas.drawBitmap(it, 0f, 0f, null) } }
|
||||
val saved = canvas.save()
|
||||
if (fit != 1f) canvas.scale(fit, fit)
|
||||
|
||||
dPanel?.let { panel -> panelFrame(panel)?.let { canvas.drawBitmap(it, 0f, 0f, null) } }
|
||||
|
||||
if (tileRects.isNotEmpty()) {
|
||||
tilePaint.color = Color.argb((14 * bgOpacity).roundToInt().coerceIn(8, 40), 255, 255, 255)
|
||||
@@ -1133,7 +1065,6 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
if (stripRect != null && layerType != LAYER_TYPE_SOFTWARE) drawCachedGraph(canvas, it) else drawGraph(canvas, it)
|
||||
}
|
||||
|
||||
canvas.restoreToCount(saved)
|
||||
lockController.drawBadge(canvas)
|
||||
}
|
||||
|
||||
@@ -1246,14 +1177,13 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
return if (dy <= 0f) p.right - stroke else if (dy >= r) cx else cx + sqrt(r * r - dy * dy)
|
||||
}
|
||||
|
||||
private fun panelFrame(panel: RectF, fit: Float): Bitmap? {
|
||||
private fun panelFrame(panel: RectF): Bitmap? {
|
||||
if (width <= 0 || height <= 0) return null
|
||||
val stroke = outlineWidth()
|
||||
val key = "$width,$height,$fit,$panel,$dRadius,$dDividerTop,$stroke,$accent,$surfaceRgb,$bgOpacity,${outlineColor()}"
|
||||
val key = "$width,$height,$panel,$dRadius,$dDividerTop,$stroke,$accent,$surfaceRgb,$bgOpacity,${outlineColor()}"
|
||||
if (key == dFrameKey) dFrame?.let { return it }
|
||||
val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val c = Canvas(bmp)
|
||||
c.scale(fit, fit)
|
||||
val corner = sp(6f)
|
||||
val body = dShape(panel.left, panel.top, panel.right, panel.bottom, dRadius, corner)
|
||||
bgPaint.color = panelColor()
|
||||
@@ -1326,8 +1256,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
|
||||
internal val isStrip: Boolean get() = stripRect != null
|
||||
|
||||
internal val contentWidth: Float get() = contentW * panelFit
|
||||
internal val contentHeight: Float get() = contentH * panelFit
|
||||
internal val contentWidth: Float get() = contentW
|
||||
internal val contentHeight: Float get() = contentH
|
||||
|
||||
internal val isDragging: Boolean get() = lockController.isDragging() || tabDragging
|
||||
|
||||
|
||||
@@ -46,14 +46,7 @@ internal class ControllerPortraitGeometry(
|
||||
}
|
||||
row(shoulders, top + pad + buttonHeight / 2f, buttonHeight, 4f * unit)
|
||||
var bodyTop = top + pad + buttonHeight + gap
|
||||
if (presented.any { it.control in REAR && isStock(it) } && docked) {
|
||||
val chipHeight = 36f * unit
|
||||
val cell = (w - 2f * pad - 5f * gap) / 6f
|
||||
listOf(0, 1, 4, 5).zip(REAR).forEach { (index, control) ->
|
||||
put(control, Box(safe.left + pad + cell / 2f + index * (cell + gap), bodyTop + chipHeight / 2f, cell, chipHeight))
|
||||
}
|
||||
bodyTop += chipHeight + gap
|
||||
} else if (presented.any { it.control in REAR && isStock(it) }) {
|
||||
if (presented.any { it.control in REAR && isStock(it) }) {
|
||||
val rearHeight = min(56f * unit, (panel - bodyTop + top) * .12f).coerceAtLeast(buttonHeight)
|
||||
row(REAR, bodyTop + rearHeight / 2f, rearHeight, gap)
|
||||
bodyTop += rearHeight + gap
|
||||
|
||||
@@ -19,7 +19,6 @@ object ControllerPrefs {
|
||||
)
|
||||
|
||||
val opacities = listOf(40, 60, 80, 100)
|
||||
val onScreenOpacityRange = 10..100
|
||||
|
||||
val sizes = listOf(80, 85, 90, 95, 100, 105, 110, 115, 120, 125)
|
||||
|
||||
@@ -46,7 +45,6 @@ object ControllerPrefs {
|
||||
val size: Int,
|
||||
val stickClick: Boolean,
|
||||
val adaptiveSticks: Boolean,
|
||||
val onScreenOpacity: Int,
|
||||
val rumble: Boolean,
|
||||
val steamButton: Boolean,
|
||||
val qamButton: Boolean,
|
||||
@@ -68,8 +66,7 @@ object ControllerPrefs {
|
||||
opacity = p.getInt("opacity", 100).takeIf { it in opacities } ?: 100,
|
||||
size = p.getInt("size", 100).takeIf { it in sizes } ?: 100,
|
||||
stickClick = p.getBoolean("stickClick", true),
|
||||
adaptiveSticks = p.getBoolean("adaptiveSticks", false),
|
||||
onScreenOpacity = onScreenOpacity(context),
|
||||
adaptiveSticks = p.getBoolean("adaptiveSticks", true),
|
||||
rumble = rumbleEnabled(context),
|
||||
steamButton = p.getBoolean("steamButton", true),
|
||||
qamButton = p.getBoolean("qamButton", true),
|
||||
@@ -106,13 +103,6 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("stickClick", on).apply()
|
||||
}
|
||||
|
||||
fun onScreenOpacity(context: Context): Int =
|
||||
prefs(context).getInt("onScreenOpacity", 100).coerceIn(onScreenOpacityRange)
|
||||
|
||||
fun setOnScreenOpacity(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("onScreenOpacity", percent.coerceIn(onScreenOpacityRange)).apply()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("adaptiveSticks", on).apply()
|
||||
}
|
||||
|
||||
@@ -36,13 +36,6 @@ object OnScreenLayout {
|
||||
fun elements(context: Context, saved: SavedInputLayout?, width: Int, height: Int, safe: Rect,
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null, rearButtons: Boolean? = null,
|
||||
trackpads: Boolean? = null): List<InputSurfaceElement> {
|
||||
val placed = placeElements(context, saved, width, height, safe, buttonsOnly, dock, rearButtons, trackpads)
|
||||
// Below the game a stick covers nothing, so it keeps its base in view instead of appearing only under the thumb.
|
||||
return if (dock == null) placed else placed.map { if (it.kind == InputElementKind.STICK) it.copy(hideWhenIdle = false) else it }
|
||||
}
|
||||
|
||||
private fun placeElements(context: Context, saved: SavedInputLayout?, width: Int, height: Int, safe: Rect,
|
||||
buttonsOnly: Boolean, dock: Dock?, rearButtons: Boolean?, trackpads: Boolean?): List<InputSurfaceElement> {
|
||||
if (saved == null) return emptyList()
|
||||
if (width <= 0 || height <= 0) return saved.elements
|
||||
val layout = oriented(saved, dock?.portrait ?: (height > width))
|
||||
|
||||
@@ -1,324 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.os.Parcel
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyEvent
|
||||
import java.util.EnumMap
|
||||
import java.util.EnumSet
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.ThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.json.JSONObject
|
||||
|
||||
enum class AirTrigger(val keyCode: Int, val control: InputControl, val pressLight: Int, val releaseLight: Int) {
|
||||
LEFT(KeyEvent.KEYCODE_F7, InputControl.LT, 106, 107), RIGHT(KeyEvent.KEYCODE_F8, InputControl.RT, 108, 109);
|
||||
|
||||
companion object {
|
||||
private const val DEVICE_PREFIX = "nubia_tgk"
|
||||
|
||||
internal fun isTriggerDevice(device: InputDevice?): Boolean {
|
||||
if (device == null) return false
|
||||
if (device.name.startsWith(DEVICE_PREFIX)) return true
|
||||
// Some RedMagic firmware merges the trigger sensors with an unnamed built-in keyboard.
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
device.name.isEmpty() && !device.isVirtual && !device.isExternal &&
|
||||
device.supportsSource(InputDevice.SOURCE_KEYBOARD) &&
|
||||
device.hasKeys(LEFT.keyCode, RIGHT.keyCode).all { it }
|
||||
}
|
||||
|
||||
internal fun of(keyCode: Int, device: InputDevice?): AirTrigger? =
|
||||
entries.firstOrNull { it.keyCode == keyCode }?.takeIf { isTriggerDevice(device) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Game Space's single tap holds the button while the trigger is touched; its long press latches it until the next touch. */
|
||||
enum class AirTriggerAction { TAP, LATCH, RAPID }
|
||||
|
||||
/** Game Space's rapid fire counts for its low, normal and high click frequency. */
|
||||
enum class RapidFireRate(val clicksPerSecond: Int) { LOW(2), NORMAL(5), HIGH(10) }
|
||||
|
||||
/** Game Space's touch atmosphere lamp cases, by their name in RedMagic's shoulder light settings. */
|
||||
enum class AirTriggerLed(val effect: String, val fallback: String) {
|
||||
OFF("close", "02000000"), STEADY("steady", "02101000"), PULSE("pulse", "02102000")
|
||||
}
|
||||
|
||||
data class AirTriggerSetup(
|
||||
val element: InputSurfaceElement,
|
||||
val action: AirTriggerAction = AirTriggerAction.TAP,
|
||||
val rate: RapidFireRate = RapidFireRate.NORMAL,
|
||||
) {
|
||||
/** Long press and rapid fire decide when the button is let go, so they press a toggle button as a plain one. */
|
||||
internal val target get() = if (action != AirTriggerAction.TAP && element.toggle) element.copy(toggle = false) else element
|
||||
}
|
||||
|
||||
object AirTriggerButtons {
|
||||
fun options(layout: SavedInputLayout?): List<InputSurfaceElement> {
|
||||
val placed = layout?.let { (it.elements + it.rotated).distinctBy { element -> element.id } }.orEmpty()
|
||||
.filter { it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER }
|
||||
return placed + AirTrigger.entries.filter { trigger -> placed.none { it.control == trigger.control } }
|
||||
.map { InputSurfaceElement(it.control, 0f, 0f, 0f, 0f) }
|
||||
}
|
||||
|
||||
fun resolve(layout: SavedInputLayout?, trigger: AirTrigger, chosen: String?): InputSurfaceElement {
|
||||
val options = options(layout)
|
||||
return chosen?.let { id -> options.firstOrNull { it.id == id } } ?: options.first { it.control == trigger.control }
|
||||
}
|
||||
}
|
||||
|
||||
object AirTriggerPrefs {
|
||||
private const val FILE = "redmagic-air-triggers"
|
||||
private const val ENABLED = "enabled"
|
||||
private const val VIBRATION = "vibration"
|
||||
private const val SCREEN_LIGHT = "screen-light"
|
||||
private const val LED = "led"
|
||||
internal const val OWNED = "distribute-owned"
|
||||
|
||||
fun prefs(context: Context): SharedPreferences = context.getSharedPreferences(FILE, Context.MODE_PRIVATE)
|
||||
fun enabled(context: Context) = prefs(context).getBoolean(ENABLED, false)
|
||||
fun setEnabled(context: Context, on: Boolean) = prefs(context).edit().putBoolean(ENABLED, on).apply()
|
||||
fun button(context: Context, layoutId: String, trigger: AirTrigger): String? = prefs(context).getString(key(layoutId, trigger), null)
|
||||
fun setButton(context: Context, layoutId: String, trigger: AirTrigger, elementId: String) =
|
||||
prefs(context).edit().putString(key(layoutId, trigger), elementId).apply()
|
||||
fun action(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "action"), AirTriggerAction.TAP)
|
||||
fun setAction(context: Context, layoutId: String, trigger: AirTrigger, action: AirTriggerAction) =
|
||||
prefs(context).edit().putString(key(layoutId, trigger, "action"), action.name).apply()
|
||||
fun rate(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "rate"), RapidFireRate.NORMAL)
|
||||
fun setRate(context: Context, layoutId: String, trigger: AirTrigger, rate: RapidFireRate) =
|
||||
prefs(context).edit().putString(key(layoutId, trigger, "rate"), rate.name).apply()
|
||||
fun vibration(context: Context) = prefs(context).getBoolean(VIBRATION, false)
|
||||
fun setVibration(context: Context, on: Boolean) = prefs(context).edit().putBoolean(VIBRATION, on).apply()
|
||||
fun screenLight(context: Context) = prefs(context).getBoolean(SCREEN_LIGHT, false)
|
||||
fun setScreenLight(context: Context, on: Boolean) = prefs(context).edit().putBoolean(SCREEN_LIGHT, on).apply()
|
||||
fun led(context: Context) = read(context, LED, AirTriggerLed.STEADY)
|
||||
fun setLed(context: Context, led: AirTriggerLed) = prefs(context).edit().putString(LED, led.name).apply()
|
||||
|
||||
private inline fun <reified E : Enum<E>> read(context: Context, key: String, default: E): E =
|
||||
prefs(context).getString(key, null)?.let { name -> enumValues<E>().firstOrNull { it.name == name } } ?: default
|
||||
|
||||
private fun key(layoutId: String, trigger: AirTrigger, setting: String? = null) =
|
||||
listOfNotNull(trigger.name.lowercase(), setting).joinToString("-") + ".$layoutId"
|
||||
}
|
||||
|
||||
/** Game Space's exported provider switches the triggers to plain F7/F8 keys without its panel, and needs no permission. */
|
||||
object RedMagicAirTriggers {
|
||||
private const val TAG = "AirTriggers"
|
||||
private const val AUTHORITY = "cn.nubia.tgk.data.TgkDataProvider"
|
||||
private val URI = Uri.parse("content://$AUTHORITY")
|
||||
private const val OPEN = "openTouchGameKeyDistribute"
|
||||
private const val CLOSE = "closeTouchGameKeyDistribute"
|
||||
private const val SHOULDER_LIGHT_ON = 110
|
||||
private const val SHOULDER_LIGHT_OFF = 111
|
||||
private const val SHOULDER_SETTINGS = "lighting_shoulder_config_json"
|
||||
private val REAPPLY_MS = longArrayOf(1_000, 5_000)
|
||||
internal var worker: Executor = ThreadPoolExecutor(0, 1, 10, TimeUnit.SECONDS, LinkedBlockingQueue()) { Thread(it, "air-triggers") }
|
||||
internal var lights: TriggerLights = ColorfulLights
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
private var reapply: Runnable? = null
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun supported(context: Context) = context.packageManager.resolveContentProvider(AUTHORITY, 0) != null &&
|
||||
InputDevice.getDeviceIds().any { AirTrigger.isTriggerDevice(InputDevice.getDevice(it)) }
|
||||
|
||||
/** Call on the main thread. */
|
||||
fun open(context: Context) {
|
||||
val app = context.applicationContext
|
||||
cancelReapply()
|
||||
worker.execute { apply(app) }
|
||||
// Game Space runs its own trigger setup for the app that comes to the front, which switches the trigger keys and lights off again.
|
||||
val again = Runnable { worker.execute { apply(app) } }
|
||||
reapply = again
|
||||
REAPPLY_MS.forEach { main.postDelayed(again, it) }
|
||||
}
|
||||
|
||||
private fun apply(app: Context) {
|
||||
val prefs = AirTriggerPrefs.prefs(app)
|
||||
if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false) && Settings.Global.getInt(app.contentResolver, OPEN, 0) != 1)
|
||||
prefs.edit().putBoolean(AirTriggerPrefs.OWNED, true).commit()
|
||||
call(app, OPEN)
|
||||
if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false)) return
|
||||
lights.request(SHOULDER_LIGHT_ON)
|
||||
// The light service drops every trigger light until an effect is set, which Game Space only does from its own view.
|
||||
lights.setEffect(shoulderEffect(Settings.Global.getString(app.contentResolver, SHOULDER_SETTINGS), AirTriggerPrefs.led(app)))
|
||||
// Entering the scene turns the lights off; the release actions show the idle light picked in RedMagic's lighting settings.
|
||||
AirTrigger.entries.forEach { lights.request(it.releaseLight) }
|
||||
}
|
||||
|
||||
/** The code RedMagic's shoulder light settings give the effect, such as "02101000" for steady. */
|
||||
internal fun shoulderEffect(settings: String?, led: AirTriggerLed): String = settings
|
||||
?.let { runCatching { JSONObject(it).optJSONObject("shoulder_effects")?.optString(led.effect) }.getOrNull() }
|
||||
?.takeIf { it.length == 8 } ?: led.fallback
|
||||
|
||||
/** Closes only what this app opened, so a distribute another app turned on stays on. Call on the main thread. */
|
||||
fun restore(context: Context) {
|
||||
val app = context.applicationContext
|
||||
cancelReapply()
|
||||
worker.execute {
|
||||
val prefs = AirTriggerPrefs.prefs(app)
|
||||
if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false)) return@execute
|
||||
lights.request(SHOULDER_LIGHT_OFF)
|
||||
if (call(app, CLOSE)) prefs.edit().remove(AirTriggerPrefs.OWNED).commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun light(code: Int) = worker.execute { lights.request(code) }
|
||||
|
||||
private fun cancelReapply() {
|
||||
reapply?.let(main::removeCallbacks)
|
||||
reapply = null
|
||||
}
|
||||
|
||||
private fun call(context: Context, method: String) = runCatching { context.contentResolver.call(URI, method, null, null) != null }
|
||||
.onFailure { Log.w(TAG, "$method failed", it) }.getOrDefault(false)
|
||||
}
|
||||
|
||||
internal interface TriggerLights {
|
||||
fun request(action: Int)
|
||||
fun setEffect(effect: String)
|
||||
}
|
||||
|
||||
private object ColorfulLights : TriggerLights {
|
||||
private const val TAG = "AirTriggers"
|
||||
private const val SERVICE = "ColorfulLightService"
|
||||
private const val INTERFACE = "com.zte.hardware.IColorfulLightManager"
|
||||
// IColorfulLightManager transaction codes; its ColorfulLightManager wrapper is a blocked hidden API.
|
||||
private const val REQUEST_LIGHT = IBinder.FIRST_CALL_TRANSACTION
|
||||
private const val SET_SHOULDER_EFFECT = IBinder.FIRST_CALL_TRANSACTION + 2
|
||||
private val binder: IBinder? by lazy {
|
||||
runCatching { Class.forName("android.os.ServiceManager").getMethod("getService", String::class.java).invoke(null, SERVICE) as IBinder? }
|
||||
.getOrNull()?.takeIf { runCatching { it.interfaceDescriptor }.getOrNull() == INTERFACE }
|
||||
}
|
||||
|
||||
override fun request(action: Int) = transact(REQUEST_LIGHT) { writeInt(action) }
|
||||
override fun setEffect(effect: String) = transact(SET_SHOULDER_EFFECT) { writeString(effect) }
|
||||
|
||||
private fun transact(code: Int, write: Parcel.() -> Unit) {
|
||||
val binder = binder ?: return
|
||||
val data = Parcel.obtain()
|
||||
val reply = Parcel.obtain()
|
||||
try {
|
||||
data.writeInterfaceToken(INTERFACE)
|
||||
data.write()
|
||||
binder.transact(code, data, reply, 0)
|
||||
reply.readException()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "light call $code failed", e)
|
||||
} finally {
|
||||
data.recycle()
|
||||
reply.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Presses the chosen button on screen when it is shown, so it animates and keeps one toggle state; otherwise uses a source of its own. */
|
||||
class AirTriggerInput(
|
||||
private val pad: PadBridge,
|
||||
private val onScreen: (elementId: String, trigger: AirTrigger, held: Boolean, cancelled: Boolean) -> Boolean = { _, _, _, _ -> false },
|
||||
private val touched: (AirTrigger, Boolean) -> Unit = { _, _ -> },
|
||||
private val handler: Handler = Handler(Looper.getMainLooper()),
|
||||
) {
|
||||
private val sources = EnumMap<AirTrigger, InputSurfaceSource>(AirTrigger::class.java)
|
||||
private val setups = EnumMap<AirTrigger, AirTriggerSetup>(AirTrigger::class.java)
|
||||
private val held = EnumSet.noneOf(AirTrigger::class.java)
|
||||
private val pressed = EnumSet.noneOf(AirTrigger::class.java)
|
||||
private val heldOnScreen = EnumMap<AirTrigger, String>(AirTrigger::class.java)
|
||||
private val timers = EnumMap<AirTrigger, Runnable>(AirTrigger::class.java)
|
||||
|
||||
fun configure(setups: Map<AirTrigger, AirTriggerSetup>) {
|
||||
for (trigger in AirTrigger.entries) {
|
||||
val setup = setups[trigger]
|
||||
if (this.setups[trigger] == setup) continue
|
||||
stop(trigger)
|
||||
if (sources[trigger]?.element != setup?.target) {
|
||||
pressed.remove(trigger)
|
||||
heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, true) }
|
||||
sources.remove(trigger)?.close()
|
||||
if (setup != null) sources[trigger] = InputSurfaceSource(pad, InputRole.PRIMARY, setup.target)
|
||||
} else if (trigger in pressed) unpress(trigger, cancelled = true)
|
||||
if (setup != null) this.setups[trigger] = setup else this.setups.remove(trigger)
|
||||
}
|
||||
}
|
||||
|
||||
fun onKey(event: KeyEvent, enabled: () -> Boolean): Boolean {
|
||||
if (event.keyCode != AirTrigger.LEFT.keyCode && event.keyCode != AirTrigger.RIGHT.keyCode) return false
|
||||
val trigger = AirTrigger.of(event.keyCode, event.device) ?: return false
|
||||
return onKey(trigger, event.action, event.repeatCount, event.action == KeyEvent.ACTION_DOWN && enabled())
|
||||
}
|
||||
|
||||
fun onKey(trigger: AirTrigger, action: Int, repeatCount: Int, enabled: Boolean): Boolean {
|
||||
val source = sources[trigger]
|
||||
when (action) {
|
||||
KeyEvent.ACTION_DOWN -> if (source != null && enabled && repeatCount == 0 && held.add(trigger)) {
|
||||
touched(trigger, true)
|
||||
val setup = setups[trigger]
|
||||
if (setup?.action == AirTriggerAction.LATCH && trigger in pressed) unpress(trigger, cancelled = false)
|
||||
else if (trigger !in pressed) {
|
||||
press(trigger, source)
|
||||
if (setup?.action == AirTriggerAction.RAPID) rapid(trigger, 500L / setup.rate.clicksPerSecond)
|
||||
}
|
||||
}
|
||||
KeyEvent.ACTION_UP -> if (held.remove(trigger)) {
|
||||
touched(trigger, false)
|
||||
if (setups[trigger]?.action != AirTriggerAction.LATCH) {
|
||||
stop(trigger)
|
||||
if (trigger in pressed) unpress(trigger, cancelled = false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return source != null
|
||||
}
|
||||
|
||||
private fun rapid(trigger: AirTrigger, halfPeriod: Long) {
|
||||
val tick = object : Runnable {
|
||||
override fun run() {
|
||||
if (trigger in pressed) unpress(trigger, cancelled = false) else sources[trigger]?.let { press(trigger, it) }
|
||||
handler.postDelayed(this, halfPeriod)
|
||||
}
|
||||
}
|
||||
timers[trigger] = tick
|
||||
handler.postDelayed(tick, halfPeriod)
|
||||
}
|
||||
|
||||
private fun stop(trigger: AirTrigger) {
|
||||
timers.remove(trigger)?.let(handler::removeCallbacks)
|
||||
}
|
||||
|
||||
private fun press(trigger: AirTrigger, source: InputSurfaceSource) {
|
||||
pressed += trigger
|
||||
if (source.element == setups[trigger]?.element && onScreen(source.element.id, trigger, true, false)) {
|
||||
heldOnScreen[trigger] = source.element.id
|
||||
// The router counts held keys, so a toggle latched while its button was hidden is released before the button takes over.
|
||||
if (source.latched) source.release()
|
||||
} else source.update(1f)
|
||||
}
|
||||
|
||||
private fun unpress(trigger: AirTrigger, cancelled: Boolean) {
|
||||
pressed -= trigger
|
||||
heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, cancelled) }
|
||||
?: sources[trigger]?.let { if (cancelled) it.cancel() else it.update(0f) }
|
||||
}
|
||||
|
||||
fun release() {
|
||||
AirTrigger.entries.forEach(::stop)
|
||||
held.toList().forEach { held.remove(it); touched(it, false) }
|
||||
pressed.toList().forEach { unpress(it, cancelled = true) }
|
||||
sources.values.forEach { it.release() }
|
||||
}
|
||||
|
||||
fun close() {
|
||||
release()
|
||||
sources.values.forEach { it.close() }
|
||||
sources.clear()
|
||||
setups.clear()
|
||||
}
|
||||
}
|
||||
@@ -288,26 +288,12 @@ object BwrapSpawner {
|
||||
}
|
||||
|
||||
private fun preload(session: List<Bind>, rootfs: String, env: MutableMap<String, String>): List<Bind> {
|
||||
val configured = FileUtils.readString(File(rootfs, "etc/ld.so.preload"))?.lines()
|
||||
?.map { it.trim() }?.filter { it.startsWith("/") && File(rootfs + it).isFile } ?: emptyList()
|
||||
val lseDisabled = env["LSE_EMU"] == "0"
|
||||
val libs = configured.filterNot { lseDisabled && it.endsWith("/liblse_emu.so") }
|
||||
val inherited = env["LD_PRELOAD"]?.split(Regex("[\\s:]+"))
|
||||
?.filter { it.isNotEmpty() && !(lseDisabled && it.substringAfterLast('/') == "liblse_emu.so") }
|
||||
?: emptyList()
|
||||
if (libs.isEmpty()) {
|
||||
if (lseDisabled) {
|
||||
if (inherited.isEmpty()) env.remove("LD_PRELOAD")
|
||||
else env["LD_PRELOAD"] = inherited.joinToString(":")
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
val libs = FileUtils.readString(File(rootfs, "etc/ld.so.preload"))?.lines()
|
||||
?.map { it.trim() }?.filter { it.startsWith("/") && File(rootfs + it).isFile } ?: return emptyList()
|
||||
if (libs.isEmpty()) return emptyList()
|
||||
val binds = ArrayList<Bind>()
|
||||
val paths = libs.map { lib -> "$PRELOAD_DIR/${lib.substringAfterLast('/')}".also { binds.add(Bind(rootfs + lib, it)) } }
|
||||
env["LD_PRELOAD"] = (paths + inherited).joinToString(":")
|
||||
if (libs.any { it.endsWith("/liblse_emu.so") }) {
|
||||
env.putIfAbsent("LSE_EMU", "1")
|
||||
}
|
||||
env["LD_PRELOAD"] = (paths + listOfNotNull(env["LD_PRELOAD"]?.takeIf { it.isNotBlank() })).joinToString(":")
|
||||
File(rootfs, NET_LINK).takeIf { it.isFile }?.let { binds.add(Bind(it.path, "/$NET_LINK")) }
|
||||
env["FAKE_EVDEV_DIR"]?.let { File(it).parent }?.let { dev ->
|
||||
binds.addAll(bindsFor(session, rootfs, dev, dev))
|
||||
@@ -577,15 +563,12 @@ object BwrapSpawner {
|
||||
|
||||
private fun run(context: Context, plan: Plan, client: LocalSocket, out: DataOutputStream, id: Int) {
|
||||
val verbose = plan.env["DROIDDECK_PROOT_VERBOSE"]?.toIntOrNull()
|
||||
val nativeSession = NativeGuest.forSession(context)
|
||||
val native = if (nativeSession) nativeLaunch(context, plan) else null
|
||||
val native = if (NativeGuest.forSession(context)) nativeLaunch(context, plan) else null
|
||||
val builder = if (native != null) {
|
||||
ProcessBuilder(native.first).redirectErrorStream(true)
|
||||
.directory(File(hostPath(plan.binds, plan.root.path, plan.cwd)).takeIf { it.isDirectory } ?: plan.root)
|
||||
.also { b -> b.environment().apply { clear(); putAll(native.second) } }
|
||||
} else {
|
||||
val reason = if (nativeSession) "sandbox native launch unavailable" else "parent guest uses PRoot"
|
||||
Log.i(TAG, "Flatpak: using PRoot ($reason)")
|
||||
val cmd = LinuxRuntime.prootPrefix(context, plan.root, plan.cwd)
|
||||
if (verbose != null) { cmd.add("-v"); cmd.add(verbose.toString()) }
|
||||
plan.binds.forEach { cmd.add("-b"); cmd.add(it.spec) }
|
||||
@@ -602,6 +585,7 @@ object BwrapSpawner {
|
||||
putAll(prootEnvironment(plan, envTool))
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(context).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(context).path)
|
||||
if (SessionPrefs.prootNoSeccomp(context)) put("PROOT_NO_SECCOMP", "1")
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import android.content.Context
|
||||
import android.os.SystemClock
|
||||
import android.system.Os
|
||||
import android.system.OsConstants
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.LinkOption.NOFOLLOW_LINKS
|
||||
import java.security.MessageDigest
|
||||
|
||||
/** One app-issued Steam session and one attested Gamescope worker. This is not an
|
||||
* isolation boundary against arbitrary code already running as the Android app UID. */
|
||||
internal object FrameAcquireWorkerProbe {
|
||||
private const val SESSION_SCRIPT = "/usr/local/bin/droiddeck-session"
|
||||
private const val PATH = "/usr/local/bin/gamescope"
|
||||
private const val CAPABILITY = "linuxfs/usr/local/share/droiddeck/gamescope-producer-acquire-v1"
|
||||
internal const val GAMESCOPE_ENABLE = "GAMESCOPE_DROIDDECK_PRODUCER_ACQUIRE=1"
|
||||
internal const val GAME_ENABLE = "DROIDDECK_GAME_DROIDDECK_GAME_FRAME_ACQUIRE=1"
|
||||
private const val MAX_BINARY_BYTES = 32L * 1024L * 1024L
|
||||
internal const val RECEIPT_TAG = 0x44445046
|
||||
internal const val RECEIPT_BYTES = Int.SIZE_BYTES + Long.SIZE_BYTES
|
||||
private const val TTL_MS = 90_000L
|
||||
|
||||
internal data class Ticket(
|
||||
val owner: Int, val root: File, val configuredRoot: File, val binary: File,
|
||||
val expected: ByteArray, val expires: Long, val steamGameUrl: String?,
|
||||
)
|
||||
internal data class Qualified(val ticket: Ticket, val dev: Long, val ino: Long, val mtime: Long, val ctime: Long)
|
||||
private var intent: Ticket? = null
|
||||
private var nativeOwner = 0
|
||||
private var nativePid = 0
|
||||
|
||||
private enum class Stage { ARM, MATCH, PUBLISH }
|
||||
private enum class Reason {
|
||||
ENABLED, MATCH_ACK, MATCH_OWNER, MATCH_EXPIRED, MATCH_PATH, MATCH_ROOT,
|
||||
MATCH_ARGV, MATCH_FILE, MATCH_DIGEST, QUALIFIED, PUBLISH_TICKET, PUBLISH_RESTAT,
|
||||
PUBLISH_NATIVE, PUBLISH_RECEIPT, RESERVED
|
||||
}
|
||||
private val reported = mutableSetOf<Stage>()
|
||||
@Synchronized private fun breadcrumb(stage: Stage, reason: Reason) {
|
||||
if (reported.add(stage)) Log.i("FrameAcquireWorkerProbe", "worker_admission=" + reason.name)
|
||||
}
|
||||
|
||||
internal fun validEnvironment(agentEnvironment: List<String>, customEnvironment: List<String>): Boolean {
|
||||
// AgentEnv supplies a replacement PATH whenever any executable override is staged.
|
||||
// Custom env is user-editable, including names not known to this build; it is not a trust root.
|
||||
return agentEnvironment.isEmpty() && customEnvironment.isEmpty()
|
||||
}
|
||||
|
||||
fun available(context: Context): Boolean =
|
||||
android.os.Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.core.DeviceSupport.adreno() &&
|
||||
runCatching { context.assets.open(CAPABILITY).use { it.readBytes().decodeToString() } }
|
||||
.getOrNull() == "droiddeck-producer-acquire-v1\n"
|
||||
|
||||
private fun digest(input: InputStream, maxBytes: Long): ByteArray {
|
||||
val out = MessageDigest.getInstance("SHA-256")
|
||||
val buffer = ByteArray(64 * 1024)
|
||||
var size = 0L
|
||||
while (true) {
|
||||
val n = input.read(buffer)
|
||||
if (n == -1) break
|
||||
require(n > 0)
|
||||
size += n
|
||||
require(size <= maxBytes)
|
||||
out.update(buffer, 0, n)
|
||||
}
|
||||
require(size > 0)
|
||||
return out.digest()
|
||||
}
|
||||
|
||||
// Compute asset identity outside SessionService's stop lock and before a worker
|
||||
// exists. The resulting ticket still has to be assigned to that exact owner.
|
||||
private const val STEAM_RUN_PREFIX = "steam://rungameid/"
|
||||
|
||||
internal fun permittedLaunch(url: String?, frontendGame: Boolean): Boolean =
|
||||
if (url == null) !frontendGame else frontendGame && url.startsWith(STEAM_RUN_PREFIX) &&
|
||||
com.droiddeck.launcher.frontend.GameLaunchLink.validId(url.removePrefix(STEAM_RUN_PREFIX))
|
||||
|
||||
internal fun prepare(context: Context, steamGameUrl: String?, frontendGame: Boolean): Ticket? {
|
||||
if (!permittedLaunch(steamGameUrl, frontendGame) ||
|
||||
!available(context) || !WaylandCompositor.frameWorkerProbeEnabled()) return null
|
||||
return runCatching {
|
||||
val configuredRoot = LinuxRuntime.rootDir(context).absoluteFile
|
||||
val root = configuredRoot.canonicalFile
|
||||
val file = File(root.path + PATH)
|
||||
require(file.canonicalFile == file && Files.isRegularFile(file.toPath(), NOFOLLOW_LINKS))
|
||||
val script = File(root.path + SESSION_SCRIPT)
|
||||
require(exactSteamScript(SESSION_SCRIPT, root, configuredRoot))
|
||||
val stagedScript = script.inputStream().use { digest(it, 1024L * 1024L) }
|
||||
val signedScript = context.assets.open("linuxfs" + SESSION_SCRIPT).use { digest(it, 1024L * 1024L) }
|
||||
require(MessageDigest.isEqual(stagedScript, signedScript))
|
||||
val expected = context.assets.open("linuxfs" + PATH).use { digest(it, MAX_BINARY_BYTES) }
|
||||
Ticket(0, root, configuredRoot, file, expected, SystemClock.elapsedRealtime() + TTL_MS, steamGameUrl)
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
@Synchronized fun arm(owner: Int, prepared: Ticket): Boolean {
|
||||
if (owner <= 0 || SystemClock.elapsedRealtime() >= prepared.expires) return false
|
||||
reported.clear()
|
||||
intent = prepared.copy(owner = owner)
|
||||
breadcrumb(Stage.ARM, Reason.ENABLED)
|
||||
return true
|
||||
}
|
||||
|
||||
/** Native shebang handling can give Bash the staged host filename as its $0. */
|
||||
internal fun exactSteamScript(token: String, root: File, configuredRoot: File): Boolean {
|
||||
if (token != SESSION_SCRIPT && token != root.path + SESSION_SCRIPT &&
|
||||
token != configuredRoot.path + SESSION_SCRIPT) return false
|
||||
return runCatching {
|
||||
val expected = File(root.path + SESSION_SCRIPT)
|
||||
val supplied = if (token == SESSION_SCRIPT) expected else File(token)
|
||||
// Reject symlinks within the authorized root, including a symlink replacing the script.
|
||||
// Android's configured root itself may be an alias of its app-issued canonical root.
|
||||
require(configuredRoot.canonicalFile == root && expected.canonicalFile == expected &&
|
||||
supplied.canonicalFile == expected &&
|
||||
Files.isRegularFile(expected.toPath(), NOFOLLOW_LINKS) &&
|
||||
Files.isRegularFile(supplied.toPath(), NOFOLLOW_LINKS))
|
||||
Files.isSameFile(supplied.toPath(), expected.toPath())
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
internal fun exactGamescopeArgs(
|
||||
argv: List<String>, steamGameUrl: String? = null, script: (String) -> Boolean,
|
||||
): Boolean {
|
||||
if (argv.firstOrNull() !in listOf("gamescope", PATH)) return false
|
||||
val delimiter = argv.indexOf("--")
|
||||
val tailSize = if (steamGameUrl == null) 3 else 4
|
||||
if (delimiter < 4 || argv.size != delimiter + tailSize || argv[delimiter + 2] != "steam" ||
|
||||
!script(argv[delimiter + 1]) ||
|
||||
(steamGameUrl != null && (!permittedLaunch(steamGameUrl, true) || argv.last() != steamGameUrl))) return false
|
||||
val opts = argv.subList(1, delimiter)
|
||||
if (opts.take(4) != listOf("--backend", "wayland", "--expose-wayland", "-f")) return false
|
||||
val dimensions = setOf("-W", "-H", "-w", "-h")
|
||||
val seen = mutableSetOf<String>()
|
||||
var i = 4
|
||||
while (i < opts.size) {
|
||||
val option = opts[i++]
|
||||
if (!seen.add(option)) return false
|
||||
when (option) {
|
||||
"-e", "--hdr-enabled", "--mangoapp" -> Unit
|
||||
"-S" -> if (opts.getOrNull(i++) != "stretch") return false
|
||||
"--default-touch-mode" -> if (opts.getOrNull(i++) != "4") return false
|
||||
"-W", "-H", "-w", "-h", "-r", "--xwayland-count" -> {
|
||||
val value = opts.getOrNull(i++) ?: return false
|
||||
if (value.length !in 1..6 || value.any { it !in '0'..'9' } ||
|
||||
value.toIntOrNull()?.let { it > 0 } != true) return false
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
return seen.containsAll(dimensions)
|
||||
}
|
||||
|
||||
fun match(owner: Int, root: File, file: String, argv: List<String>, ack: Boolean): Qualified? {
|
||||
val t = synchronized(this) { intent } ?: return null
|
||||
// Startup's --version worker and unrelated workers must not consume the one diagnostic.
|
||||
val candidate = "--version" !in argv && (file.substringAfterLast('/') == "gamescope" ||
|
||||
argv.firstOrNull()?.substringAfterLast('/') == "gamescope")
|
||||
val rejection = when {
|
||||
!ack -> Reason.MATCH_ACK
|
||||
t.owner != owner -> Reason.MATCH_OWNER
|
||||
SystemClock.elapsedRealtime() >= t.expires -> Reason.MATCH_EXPIRED
|
||||
file != PATH -> Reason.MATCH_PATH
|
||||
runCatching { root.canonicalFile }.getOrNull() != t.root -> Reason.MATCH_ROOT
|
||||
!exactGamescopeArgs(argv, t.steamGameUrl) { exactSteamScript(it, t.root, t.configuredRoot) } -> Reason.MATCH_ARGV
|
||||
else -> null
|
||||
}
|
||||
if (rejection != null) {
|
||||
if (candidate) breadcrumb(Stage.MATCH, rejection)
|
||||
return null
|
||||
}
|
||||
// Hash an actual descriptor rather than two pathname opens. Check both the
|
||||
// descriptor and pathname identity; a race or substituted executable denies the grant.
|
||||
val qualified = runCatching {
|
||||
require(t.binary.canonicalFile == t.binary)
|
||||
val before = Os.lstat(t.binary.path)
|
||||
require(OsConstants.S_ISREG(before.st_mode) && before.st_size in 1..MAX_BINARY_BYTES)
|
||||
val fd = Os.open(t.binary.path, OsConstants.O_RDONLY or OsConstants.O_NOFOLLOW or OsConstants.O_CLOEXEC, 0)
|
||||
val sum = try {
|
||||
require(stillSame(before, Os.fstat(fd)))
|
||||
android.os.ParcelFileDescriptor.AutoCloseInputStream(android.os.ParcelFileDescriptor.dup(fd)).use {
|
||||
digest(it, MAX_BINARY_BYTES)
|
||||
}.also { require(stillSame(before, Os.fstat(fd))) }
|
||||
} finally {
|
||||
Os.close(fd)
|
||||
}
|
||||
val after = Os.lstat(t.binary.path)
|
||||
require(stillSame(before, after))
|
||||
if (!MessageDigest.isEqual(sum, t.expected)) {
|
||||
breadcrumb(Stage.MATCH, Reason.MATCH_DIGEST)
|
||||
return null
|
||||
}
|
||||
Qualified(t, after.st_dev, after.st_ino, after.st_mtime, after.st_ctime)
|
||||
}.getOrNull()
|
||||
breadcrumb(Stage.MATCH, if (qualified == null) Reason.MATCH_FILE else Reason.QUALIFIED)
|
||||
return qualified
|
||||
}
|
||||
|
||||
private fun stillSame(a: android.system.StructStat, b: android.system.StructStat): Boolean =
|
||||
a.st_dev == b.st_dev && a.st_ino == b.st_ino && a.st_size == b.st_size &&
|
||||
a.st_mtime == b.st_mtime && a.st_ctime == b.st_ctime &&
|
||||
OsConstants.S_ISREG(b.st_mode)
|
||||
|
||||
internal fun validReceipt(pid: Int, workerPid: Int, ticks: Long, bytes: Int): Long =
|
||||
if (pid > 1 && pid == workerPid && ticks > 0 && bytes == RECEIPT_BYTES) ticks else 0L
|
||||
|
||||
internal fun parseSelfStat(stat: String, pid: Int): Long {
|
||||
if (pid <= 1 || !stat.startsWith("$pid (")) return 0L
|
||||
val comm = stat.lastIndexOf(')')
|
||||
if (comm < 3 || stat.getOrNull(comm + 1) != ' ') return 0L
|
||||
val fields = stat.substring(comm + 2).split(' ').filter { it.isNotEmpty() }
|
||||
if (fields.firstOrNull()?.length != 1 || fields.size < 21) return 0L
|
||||
val value = fields[19] // field 22 from field 3 (the single-character task state).
|
||||
return value.takeIf { it.isNotEmpty() && it.all { ch -> ch in '0'..'9' } }
|
||||
?.toLongOrNull()?.takeIf { it > 0 } ?: 0L
|
||||
}
|
||||
|
||||
internal fun selfStartTicks(pid: Int): Long = runCatching {
|
||||
File("/proc/self/stat").inputStream().use { input ->
|
||||
val bytes = ByteArray(4096)
|
||||
var used = 0
|
||||
while (used < bytes.size) {
|
||||
val n = input.read(bytes, used, bytes.size - used)
|
||||
if (n < 0) break
|
||||
if (n == 0) return@runCatching 0L
|
||||
used += n
|
||||
}
|
||||
if (used == bytes.size || used == 0 || bytes[used-1] != '\n'.code.toByte()) 0L
|
||||
else parseSelfStat(String(bytes, 0, used, Charsets.US_ASCII), pid)
|
||||
}
|
||||
}.getOrDefault(0L)
|
||||
|
||||
/** Runs just before the final GO byte. Failure never changes ordinary launch. */
|
||||
@Synchronized fun publish(q: Qualified, pid: Int, startTicks: Long) {
|
||||
val t = q.ticket
|
||||
if (intent !== t || pid <= 1 || SystemClock.elapsedRealtime() >= t.expires) {
|
||||
if (intent === t) breadcrumb(Stage.PUBLISH, Reason.PUBLISH_TICKET)
|
||||
return
|
||||
}
|
||||
intent = null // At most one candidate per explicitly armed session.
|
||||
if (startTicks <= 0L) {
|
||||
breadcrumb(Stage.PUBLISH, Reason.PUBLISH_RECEIPT)
|
||||
return
|
||||
}
|
||||
val status = runCatching {
|
||||
val st = Os.lstat(t.binary.path)
|
||||
require(OsConstants.S_ISREG(st.st_mode) && st.st_dev == q.dev && st.st_ino == q.ino &&
|
||||
st.st_mtime == q.mtime && st.st_ctime == q.ctime)
|
||||
if (WaylandCompositor.frameWorkerProbeGrant(t.owner, pid, t.expires, t.binary.path, st.st_dev, st.st_ino, startTicks)) {
|
||||
nativeOwner = t.owner
|
||||
nativePid = pid
|
||||
Reason.RESERVED
|
||||
} else Reason.PUBLISH_NATIVE
|
||||
}.getOrDefault(Reason.PUBLISH_RESTAT)
|
||||
breadcrumb(Stage.PUBLISH, status)
|
||||
}
|
||||
|
||||
@Synchronized fun revoke(owner: Int, pid: Int = 0) {
|
||||
if (owner <= 0) return
|
||||
if (pid == 0 && intent?.owner == owner) intent = null
|
||||
if (nativeOwner == owner && (pid == 0 || pid == nativePid)) {
|
||||
WaylandCompositor.frameWorkerProbeRevoke(owner, pid)
|
||||
nativeOwner = 0
|
||||
nativePid = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.droiddeck.launcher.core.HostProcess
|
||||
import com.droiddeck.launcher.session.OrphanReaper
|
||||
import com.droiddeck.launcher.session.SessionFiles
|
||||
import com.droiddeck.launcher.session.SessionPaths
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@@ -66,6 +67,7 @@ object GuestCommand {
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(context).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(context).path)
|
||||
if (linkDir != null) put("PROOT_L2S_DIR", linkDir.path)
|
||||
if (SessionPrefs.prootNoSeccomp(context)) put("PROOT_NO_SECCOMP", "1")
|
||||
fastPathKey?.let { ProotFastPath.hostEnv(it).let { (k, v) -> put(k, v) } }
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
|
||||
@@ -45,16 +45,7 @@ open class GuestWorker : Service() {
|
||||
val fillBinderFd = data.readInt() != 0
|
||||
val go = data.readFileDescriptor()
|
||||
val nice = data.readInt()
|
||||
val pid = Process.myPid()
|
||||
reply?.writeInt(pid)
|
||||
// Optional fixed-size receipt, on the exact local, non-exported worker's Binder.
|
||||
// Nothing in the guest socket request populates these fields.
|
||||
if (reply != null &&
|
||||
Binder.getCallingUid() == Process.myUid() &&
|
||||
data.dataAvail() == Int.SIZE_BYTES && data.readInt() == FrameAcquireWorkerProbe.RECEIPT_TAG) {
|
||||
reply.writeInt(pid)
|
||||
reply.writeLong(FrameAcquireWorkerProbe.selfStartTicks(pid))
|
||||
}
|
||||
reply?.writeInt(Process.myPid())
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
// The app writes a byte once it has the reply and has taken the launch on: an exec
|
||||
// before then would end this process with the reply undelivered, and with none (the
|
||||
@@ -446,8 +437,7 @@ object GuestWorkers {
|
||||
private fun start(context: Context, argv: List<String>, env: List<String>, fds: List<ParcelFileDescriptor>, targets: IntArray,
|
||||
guest: Boolean, onExit: (Int) -> Unit, commit: (Int) -> Boolean = { true },
|
||||
confirmed: () -> Boolean = { true }, owner: Int = session,
|
||||
nice: Int = Process.getThreadPriority(Process.myTid()),
|
||||
testWorker: FrameAcquireWorkerProbe.Qualified? = null): Int {
|
||||
nice: Int = Process.getThreadPriority(Process.myTid())): Int {
|
||||
val app = context.applicationContext
|
||||
if (guest && owner <= stopped) {
|
||||
Log.w(TAG, (if (owner == 0) "a request naming no session" else "session $owner is stopping") +
|
||||
@@ -483,21 +473,13 @@ object GuestWorkers {
|
||||
data.writeInt(if (guest) 0 else 1)
|
||||
data.writeFileDescriptor(go[0].fileDescriptor)
|
||||
data.writeInt(nice)
|
||||
val service = checkNotNull(slot.service)
|
||||
if (testWorker != null) data.writeInt(FrameAcquireWorkerProbe.RECEIPT_TAG)
|
||||
check(service.transact(GuestWorker.RUN, data, reply, 0))
|
||||
slot.service!!.transact(GuestWorker.RUN, data, reply, 0)
|
||||
// The worker has its own copy: with ours closed (and the request's, which holds one too),
|
||||
// a worker that gave up leaves no reader
|
||||
data.recycle()
|
||||
data = null
|
||||
go[0].close()
|
||||
val pid = reply.readInt()
|
||||
val startTicks = if (testWorker != null) {
|
||||
val size = reply.dataAvail()
|
||||
if (size == FrameAcquireWorkerProbe.RECEIPT_BYTES)
|
||||
FrameAcquireWorkerProbe.validReceipt(pid, reply.readInt(), reply.readLong(), size)
|
||||
else 0L
|
||||
} else 0L
|
||||
// Once a session's teardown has begun (stopGuests), none of its programs may start: it
|
||||
// would not find them.
|
||||
val stopping = { guest && owner <= stopped }
|
||||
@@ -526,12 +508,7 @@ object GuestWorkers {
|
||||
// launching slot), or never.
|
||||
val answered = Os.poll(arrayOf(answer), ANSWER_TIMEOUT_MS) > 0 && Os.read(go[1].fileDescriptor, ByteArray(1), 0, 1) == 1
|
||||
val accepted = answered && synchronized(authorizing) {
|
||||
if (stopping() || !confirmed()) false
|
||||
else {
|
||||
if (testWorker != null) FrameAcquireWorkerProbe.publish(testWorker, pid,
|
||||
if (slot.service === service) startTicks else 0L)
|
||||
Os.write(go[1].fileDescriptor, byteArrayOf(1), 0, 1) == 1
|
||||
}
|
||||
!stopping() && confirmed() && Os.write(go[1].fileDescriptor, byteArrayOf(1), 0, 1) == 1
|
||||
}
|
||||
val endedRunning = synchronized(slots) {
|
||||
slot.launching = false
|
||||
@@ -708,7 +685,6 @@ object GuestWorkers {
|
||||
}
|
||||
}
|
||||
context?.let { app -> drained.forEach { release(app, it) } }
|
||||
FrameAcquireWorkerProbe.revoke(of)
|
||||
val pids = guestPids(of)
|
||||
if (pids.isEmpty()) return
|
||||
pids.forEach { Process.sendSignal(it, OsConstants.SIGTERM) }
|
||||
@@ -926,19 +902,16 @@ object GuestWorkers {
|
||||
val owner = request.optInt("session", 0).coerceAtLeast(0)
|
||||
// The sender is the forked child (or droiddeck-spawn): its priority is the one the program would inherit
|
||||
val nice = runCatching { Process.getThreadPriority(client.peerCredentials.pid) }.getOrDefault(Process.THREAD_PRIORITY_DEFAULT)
|
||||
val testWorker = FrameAcquireWorkerProbe.match(owner, root, file, argv, ack)
|
||||
val pid = start(app, command, env.map { (k, v) -> "$k=$v" }, programFds, targets, true, owner = owner, nice = nice, onExit = { code ->
|
||||
if (testWorker != null && worker > 1) FrameAcquireWorkerProbe.revoke(owner, worker)
|
||||
status = code
|
||||
if (table != null && slot >= 0) reportExit(table, slot, code, parent, child, worker)
|
||||
exited.countDown()
|
||||
}, confirmed = {
|
||||
val confirmed = !ack || runCatching {
|
||||
!ack || runCatching {
|
||||
out.write("ok\n".toByteArray())
|
||||
out.flush()
|
||||
confirmedToHook = true
|
||||
}.isSuccess
|
||||
confirmed
|
||||
}, commit = { started ->
|
||||
worker = started
|
||||
if (!ack) return@start true
|
||||
@@ -957,8 +930,7 @@ object GuestWorkers {
|
||||
}
|
||||
ended && line.toString() == "go"
|
||||
}.getOrDefault(false)
|
||||
}, testWorker = testWorker)
|
||||
if (pid <= 0 && testWorker != null && worker > 1) FrameAcquireWorkerProbe.revoke(owner, worker)
|
||||
})
|
||||
handedOver = true
|
||||
programFds.filter { it !== table }.forEach { runCatching { it.close() } }
|
||||
if (pid <= 0) table?.let { runCatching { it.close() } }
|
||||
|
||||
@@ -22,15 +22,15 @@ object NativeGuest {
|
||||
}
|
||||
|
||||
fun enabled(context: Context): Boolean =
|
||||
available(LinuxRuntime.rootDir(context))
|
||||
SessionPrefs.nativeUserland(context) && available(LinuxRuntime.rootDir(context))
|
||||
|
||||
/**
|
||||
* Whether the next session will start natively. The session stages the hook from the APK before
|
||||
* it starts, so the rootfs's loader decides, and a runtime still to be
|
||||
* it starts, so only the setting and the rootfs's loader decide, and a runtime still to be
|
||||
* installed will have one.
|
||||
*/
|
||||
fun nextSession(context: Context): Boolean =
|
||||
willRun(LinuxRuntime.rootDir(context), LinuxRuntime.isInstalled(context))
|
||||
SessionPrefs.nativeUserland(context) && willRun(LinuxRuntime.rootDir(context), LinuxRuntime.isInstalled(context))
|
||||
|
||||
internal fun willRun(root: File, installed: Boolean): Boolean = !installed || loader(root) != null
|
||||
|
||||
@@ -39,7 +39,7 @@ object NativeGuest {
|
||||
|
||||
/**
|
||||
* Whether a session's helpers (root commands, Flatpak sandboxes, installers) run natively: the
|
||||
* session's own mode while one runs, as the rootfs is only
|
||||
* session's own mode while one runs, as the setting can change under it and the rootfs is only
|
||||
* prepared for native programs at a session's start.
|
||||
*/
|
||||
fun forSession(context: Context): Boolean = sessionMode ?: enabled(context)
|
||||
@@ -104,11 +104,8 @@ object NativeGuest {
|
||||
private fun hostProgram(root: File, program: String): File = File(root, program.removePrefix("/"))
|
||||
|
||||
/** The environment of the session process: the hook's root, the mounts proot used to make, the preload list. */
|
||||
fun sessionEnvironment(
|
||||
root: File, binds: List<String>, program: String, hostname: String? = null, lseEmu: String? = null,
|
||||
): Map<String, String> {
|
||||
val preload = preloadList(root).filterNot { lseEmu == "0" && it.substringAfterLast('/') == "liblse_emu.so" }
|
||||
val lse = lseEmu ?: "1".takeIf { preload.any { it.substringAfterLast('/') == "liblse_emu.so" } }
|
||||
fun sessionEnvironment(root: File, binds: List<String>, program: String, hostname: String? = null): Map<String, String> {
|
||||
val preload = preloadList(root)
|
||||
return linkedMapOf(
|
||||
"DDNATV_ROOT" to root.path,
|
||||
"DDNATV_EXEC" to execLoader.orEmpty(),
|
||||
@@ -116,7 +113,6 @@ object NativeGuest {
|
||||
"DDNATV_HOSTNAME" to hostname.orEmpty(),
|
||||
"DDNATV_BINDS" to binds.joinToString("|") { if (it.contains(':')) it else "$it:$it" },
|
||||
"DDNATV_PRELOAD" to preload.joinToString(":"),
|
||||
"LSE_EMU" to lse.orEmpty(),
|
||||
"LD_PRELOAD" to (preload.map { File(root, it.removePrefix("/")).path } + hook(root).path).joinToString(":"),
|
||||
).filterValues { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.runtime
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
|
||||
@@ -11,14 +12,17 @@ object ProotFastPath {
|
||||
const val LIBRARY = "/usr/local/lib/libddfastpath.so"
|
||||
const val MAX_BINDS = 256
|
||||
|
||||
internal fun allows(source: String, native: Boolean): Boolean =
|
||||
!native && source == LinuxRuntime.PROOT_PACK
|
||||
fun allows(preference: Boolean, noSeccomp: Boolean, source: String, nativeUserland: Boolean = false): Boolean =
|
||||
preference && !noSeccomp && !nativeUserland && source == LinuxRuntime.PROOT_PACK
|
||||
|
||||
fun enabled(context: Context, native: Boolean = NativeGuest.forSession(context)): Boolean {
|
||||
if (native) return false
|
||||
fun enabled(context: Context): Boolean {
|
||||
val preference = SessionPrefs.prootFastPath(context)
|
||||
val noSeccomp = SessionPrefs.prootNoSeccomp(context)
|
||||
val nativeUserland = SessionPrefs.nativeUserland(context)
|
||||
val source = LinuxRuntime.prootSource(context)
|
||||
val on = allows(source, native)
|
||||
if (!on) Log.i(TAG, "proot: fast path off - binary is $source, not the patched proot")
|
||||
val on = allows(preference, noSeccomp, source, nativeUserland)
|
||||
if (preference && !noSeccomp && !nativeUserland && !on)
|
||||
Log.i(TAG, "proot: fast path off - binary is $source, not the patched proot")
|
||||
return on
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.os.Process
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.core.HostProcess
|
||||
import com.droiddeck.launcher.session.OrphanReaper
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.json.JSONObject
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
@@ -127,6 +128,7 @@ object RootSpawner {
|
||||
clear()
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(context).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(context).path)
|
||||
if (SessionPrefs.prootNoSeccomp(context)) put("PROOT_NO_SECCOMP", "1")
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,8 +343,7 @@ object BottomDesktop {
|
||||
LinuxRuntime.commandWithBinds(context, current.root, binds, guest)
|
||||
}
|
||||
val environment = if (current.nativeUserland) {
|
||||
val lseEmu = current.guest.lastOrNull { it.startsWith("LSE_EMU=") }?.substringAfter('=')
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(current.root, binds, guest.first(), SessionPrefs.guestHostname(context), lseEmu)
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(current.root, binds, guest.first(), SessionPrefs.guestHostname(context))
|
||||
.map { (k, v) -> "$k=$v" }.toTypedArray()
|
||||
} else current.hostEnvironment
|
||||
val line = command.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") }
|
||||
|
||||
@@ -30,8 +30,6 @@ object ComponentsManager {
|
||||
private const val DD_COMPONENTS = "Droid-Deck/DroidDeck-Components"
|
||||
internal const val DD_NIGHTLY = "linux-nightly"
|
||||
internal const val DD_BIONIC = "bionic-stable"
|
||||
/** FEX for original Xbox games on DroidDeck-Bionic: kept apart from [DD_BIONIC] so automatic FEX updates never pick it. */
|
||||
internal const val DD_XBOX = "bionic-xbox"
|
||||
private val RELEASES = linkedMapOf(
|
||||
"FexCore-Linux" to "fex",
|
||||
"Dxvk-Linux" to "dxvk",
|
||||
@@ -40,8 +38,7 @@ object ComponentsManager {
|
||||
"Vkd3d-proton-Linux" to "vkd3d",
|
||||
)
|
||||
private val NIGHTLY_PREFIXES = linkedMapOf("DD-dxvk-" to "dxvk", "DD-vkd3d-proton-" to "vkd3d", "DD-FEXCore-" to "fex")
|
||||
private val SOURCES = RELEASES.keys.map { NIGHTLIES to it } + (DD_COMPONENTS to DD_NIGHTLY) + (DD_COMPONENTS to DD_BIONIC) +
|
||||
(DD_COMPONENTS to DD_XBOX)
|
||||
private val SOURCES = RELEASES.keys.map { NIGHTLIES to it } + (DD_COMPONENTS to DD_NIGHTLY) + (DD_COMPONENTS to DD_BIONIC)
|
||||
private val DOWNLOAD_REPOS = listOf(NIGHTLIES, DD_COMPONENTS)
|
||||
private val TYPES = mapOf("FEXCore-Linux" to "fex", "FEXCore-Bionic" to "fex", "DXVK-Linux" to "dxvk", "VKD3D-Linux" to "vkd3d")
|
||||
private val TYPE_OF = mapOf("fex" to "FEXCore-Linux", "dxvk" to "DXVK-Linux", "vkd3d" to "VKD3D-Linux")
|
||||
@@ -256,28 +253,6 @@ object ComponentsManager {
|
||||
saveState(context, state)
|
||||
}
|
||||
|
||||
internal enum class Assigned { SET, NOT_LISTED, CHANGED }
|
||||
|
||||
/**
|
||||
* Sets a game's component to a listed package, fetching it first when it is not stored. [expected] is the component
|
||||
* the caller read when it decided: if the game's component is something else once the package is ready (the player
|
||||
* chose one during the download), nothing is written. [onSet] runs under the same lock as the write.
|
||||
*/
|
||||
internal fun assignGameComponent(context: Context, scope: String, comp: String, file: String, release: String,
|
||||
expected: String?, onSet: () -> Unit = {}): Assigned {
|
||||
val wcp = File(packagesDir(context), safeName(file))
|
||||
if (!wcp.isFile || runCatching { packageInfo(context, wcp) }.isFailure) {
|
||||
wcp.delete()
|
||||
download(context, catalogItem(context, file, release) ?: return Assigned.NOT_LISTED) {}
|
||||
}
|
||||
synchronized(lock) {
|
||||
if (gameComponents(context, scope)[comp] != expected) return Assigned.CHANGED
|
||||
setGameComponent(context, scope, comp, file) { runtimeManaged(context, it) }
|
||||
onSet()
|
||||
}
|
||||
return Assigned.SET
|
||||
}
|
||||
|
||||
fun clearGameComponents(context: Context, scope: String) = synchronized(lock) {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
val state = loadState(context)
|
||||
@@ -1149,7 +1124,7 @@ object ComponentsManager {
|
||||
|
||||
internal fun assetComp(release: String, name: String): String? = RELEASES[release] ?: when (release) {
|
||||
DD_NIGHTLY -> NIGHTLY_PREFIXES.entries.firstOrNull { name.startsWith(it.key) }?.value
|
||||
DD_BIONIC, DD_XBOX -> "fex"
|
||||
DD_BIONIC -> "fex"
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.os.ParcelFileDescriptor
|
||||
import android.system.Os
|
||||
import android.system.OsConstants
|
||||
import com.droiddeck.launcher.core.LogRedactor
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.runtime.BattleNet
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.json.JSONArray
|
||||
@@ -26,7 +25,6 @@ import java.nio.channels.SeekableByteChannel
|
||||
import java.nio.file.FileVisitResult
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.LinkOption
|
||||
import java.nio.file.NoSuchFileException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.SimpleFileVisitor
|
||||
import java.nio.file.StandardOpenOption
|
||||
@@ -223,7 +221,7 @@ internal object EnhancedSessionLogShare {
|
||||
Category.values().map { category ->
|
||||
val budget = budgets.getValue(category)
|
||||
val records = ArrayList<Record>()
|
||||
val selected = candidates.filter { it.category == category }.sortedBy(::sharePriority)
|
||||
val selected = candidates.filter { it.category == category }
|
||||
val zip = File(out, "DroidDeck-${folder.name}-${category.suffix}.zip")
|
||||
ZipOutputStream(zip.outputStream().buffered()).use { archive ->
|
||||
val names = HashSet<String>()
|
||||
@@ -270,7 +268,7 @@ internal object EnhancedSessionLogShare {
|
||||
val out = outputDirectory.apply { deleteRecursively(); mkdirs() }
|
||||
val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context))
|
||||
val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true)
|
||||
val candidates = discovery.candidates.filter { it.linePrefix == null }.sortedBy(::sharePriority)
|
||||
val candidates = discovery.candidates.filter { it.linePrefix == null }
|
||||
if (candidates.isEmpty()) {
|
||||
out.deleteRecursively()
|
||||
return null
|
||||
@@ -618,8 +616,7 @@ internal object EnhancedSessionLogShare {
|
||||
redactionLearningComplete: Boolean,
|
||||
) {
|
||||
val entries = JSONArray()
|
||||
val (discovery, rest) = records.partition { it.origin == "discovery" }
|
||||
(discovery + rest).take(MAX_MANIFEST_RECORDS).forEach { record ->
|
||||
records.take(MAX_MANIFEST_RECORDS).forEach { record ->
|
||||
entries.put(JSONObject().apply {
|
||||
put("entry", record.entry)
|
||||
put("origin", record.origin)
|
||||
@@ -683,15 +680,6 @@ internal object EnhancedSessionLogShare {
|
||||
categoryCounts[category] = (categoryCounts[category] ?: 0) + 1
|
||||
}
|
||||
}
|
||||
fun addRecentLogs(root: File, entryPrefix: String, origin: String) {
|
||||
val scan = walk(root, remaining(maxFiles, out.size))
|
||||
truncated = truncated || scan.truncated
|
||||
partial = partial || scan.partial
|
||||
val base = root.toPath().toAbsolutePath().normalize()
|
||||
scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) }.forEach { file ->
|
||||
add(file, root, "$entryPrefix/${base.relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/")}", origin)
|
||||
}
|
||||
}
|
||||
CRITICAL_SESSION_FILES.forEach { name ->
|
||||
File(folder, name).takeIf { it.exists() }?.let { add(it, folder, "${folder.name}/$name", "session-critical") }
|
||||
}
|
||||
@@ -709,6 +697,15 @@ internal object EnhancedSessionLogShare {
|
||||
Category.GAMES, "DROIDDECK_DIAGNOSTICS event=game_",
|
||||
)
|
||||
}
|
||||
if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) {
|
||||
val steam = File(SessionPrefs.activeSteamRoot(context), "logs")
|
||||
val scan = directFiles(steam, remaining(maxFiles, out.size))
|
||||
truncated = truncated || scan.truncated
|
||||
partial = partial || scan.partial
|
||||
scan.files.forEach {
|
||||
add(it, steam, "${folder.name}/steam/${it.name}", "live-steam")
|
||||
}
|
||||
}
|
||||
val logs = LinuxRuntime.logDir(context)
|
||||
for ((name, root) in listOf(SessionLogShare.STORES_DIR to File(logs, SessionLogShare.STORES_DIR), SessionPaths.TOOLS_DIR to File(logs, SessionPaths.TOOLS_DIR))) {
|
||||
val scan = directFiles(root, STORE_LOG_SCAN)
|
||||
@@ -725,7 +722,16 @@ internal object EnhancedSessionLogShare {
|
||||
add(source.file, source.root, source.entry, "battlenet")
|
||||
}
|
||||
} else {
|
||||
battleNetRoots(context).forEach { (prefix, root) -> addRecentLogs(root, "battlenet/$prefix", "battlenet") }
|
||||
battleNetRoots(context).forEach { (prefix, root) ->
|
||||
val scan = walk(root, remaining(maxFiles, out.size))
|
||||
truncated = truncated || scan.truncated
|
||||
partial = partial || scan.partial
|
||||
scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) }
|
||||
.forEach { file ->
|
||||
val relative = root.toPath().toAbsolutePath().normalize().relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/")
|
||||
add(file, root, "battlenet/$prefix/$relative", "battlenet")
|
||||
}
|
||||
}
|
||||
}
|
||||
val sessionScan = walk(folder, remaining(maxFiles, out.size))
|
||||
truncated = truncated || sessionScan.truncated
|
||||
@@ -736,28 +742,9 @@ internal object EnhancedSessionLogShare {
|
||||
if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach
|
||||
add(file, folder, "${folder.name}/$relative", "session")
|
||||
}
|
||||
val antiCheat = antiCheatRoots(context)
|
||||
partial = partial || antiCheat.partial
|
||||
antiCheat.roots.forEach { (appId, root) -> addRecentLogs(root, "anticheat/$appId", "anticheat") }
|
||||
if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) {
|
||||
val steam = File(SessionPrefs.activeSteamRoot(context), "logs")
|
||||
val scan = directFiles(steam, remaining(maxFiles, out.size))
|
||||
truncated = truncated || scan.truncated
|
||||
partial = partial || scan.partial
|
||||
scan.files.forEach {
|
||||
add(it, steam, "${folder.name}/steam/${it.name}", "live-steam")
|
||||
}
|
||||
}
|
||||
return CollectionResult(out.values.toList(), truncated, partial)
|
||||
}
|
||||
|
||||
private fun sharePriority(candidate: Candidate): Int = when {
|
||||
candidate.origin == "session-critical" -> 0
|
||||
candidate.origin == "session" && candidate.category == Category.GAMES -> 1
|
||||
candidate.origin == "anticheat" -> 2
|
||||
else -> 3
|
||||
}
|
||||
|
||||
private fun remaining(maxFiles: Int, found: Int): Int = (maxFiles - found + 1).coerceAtLeast(0)
|
||||
|
||||
private fun walk(root: File, limit: Int): ScanResult {
|
||||
@@ -829,39 +816,6 @@ internal object EnhancedSessionLogShare {
|
||||
return ScanResult(files, truncated, partial)
|
||||
}
|
||||
|
||||
private class AntiCheatRoots(val roots: List<Pair<String, File>>, val partial: Boolean)
|
||||
|
||||
private fun antiCheatRoots(context: Context): AntiCheatRoots {
|
||||
var partial = false
|
||||
val seen = HashSet<String>()
|
||||
val dirs = runCatching { Library.compatdataDirs(context) }.getOrElse { partial = true; emptyList() }
|
||||
val roots = dirs.flatMapIndexed { library, compatdata ->
|
||||
val prefixes = compatdata.listFiles() ?: run { partial = true; emptyArray() }
|
||||
prefixes.filter { !Files.isSymbolicLink(it.toPath()) }.mapNotNull { prefix ->
|
||||
val appId = steamAppId(prefix.name) ?: return@mapNotNull null
|
||||
val root = File(prefix, EAC_LOG_DIR)
|
||||
val directory = try {
|
||||
Files.readAttributes(root.toPath(), BasicFileAttributes::class.java, LinkOption.NOFOLLOW_LINKS).isDirectory
|
||||
} catch (_: NoSuchFileException) {
|
||||
false
|
||||
} catch (_: Exception) {
|
||||
partial = true
|
||||
false
|
||||
}
|
||||
if (!directory) return@mapNotNull null
|
||||
val base = "$appId/library${library + 1}"
|
||||
val key = base.takeIf { seen.add(it) } ?: "$base-${prefix.name}".takeIf { seen.add(it) }
|
||||
if (key != null) key to root else { partial = true; null }
|
||||
}
|
||||
}
|
||||
return AntiCheatRoots(roots, partial)
|
||||
}
|
||||
|
||||
private fun steamAppId(name: String): String? =
|
||||
name.takeIf { SIGNED_APP_ID.matches(it) }?.toLongOrNull()
|
||||
?.takeIf { it in Int.MIN_VALUE.toLong()..0xffffffffL }
|
||||
?.let { (it and 0xffffffffL).toString() }
|
||||
|
||||
private fun battleNetRoots(context: Context): List<Pair<String, File>> {
|
||||
val drive = File(BattleNet.prefix(context), "pfx/drive_c")
|
||||
val data = File(drive, "ProgramData/Battle.net")
|
||||
@@ -968,9 +922,7 @@ internal object EnhancedSessionLogShare {
|
||||
val normalized = name.replace('\\', '/').trimStart('/')
|
||||
val parts = normalized.split('/')
|
||||
if (normalized.isEmpty() || parts.any { it.isEmpty() || it == "." || it == ".." }) return null
|
||||
return parts.mapIndexed { index, part ->
|
||||
if (index == 1 && parts[0] == "anticheat" && APP_ID.matches(part)) part else safeComponent(part)
|
||||
}.joinToString("/")
|
||||
return parts.joinToString("/") { safeComponent(it) }
|
||||
}
|
||||
|
||||
private fun safeComponent(value: String): String {
|
||||
@@ -983,7 +935,7 @@ internal object EnhancedSessionLogShare {
|
||||
|
||||
private fun category(entry: String): Category {
|
||||
val value = entry.lowercase(Locale.US)
|
||||
if (value.startsWith("battlenet/") || value.startsWith("anticheat/") || value.startsWith("stores/") || value.startsWith("tools/") || value.startsWith("rpcs3/") ||
|
||||
if (value.startsWith("battlenet/") || value.startsWith("stores/") || value.startsWith("tools/") || value.startsWith("rpcs3/") ||
|
||||
value.contains("droiddeck-esync/") || GAME_LOG.matches(value.substringAfterLast('/')) ||
|
||||
listOf("proton", "wine", "dxvk", "vkd3d", "battle.net", "game-debug", "bionic").any(value::contains)) return Category.GAMES
|
||||
if (listOf("wayland", "gamescope", "xwayland", "vulkan", "gpu", "mesa", "egl", "glx", "drm", "compositor", "frame-trace").any(value::contains)) return Category.GRAPHICS
|
||||
@@ -992,7 +944,7 @@ internal object EnhancedSessionLogShare {
|
||||
|
||||
private val GAME_LOG = Regex("steam-[0-9]+\\.(log|txt)")
|
||||
private val KNOWN_COMPONENTS = setOf(
|
||||
"steam", "graphics", "games", "battlenet", "anticheat", "anticheatlauncher.log", "client", "agent", "setup", "stores", "tools",
|
||||
"steam", "graphics", "games", "battlenet", "client", "agent", "setup", "stores", "tools",
|
||||
"droiddeck", "droiddeck-esync", "session.log", "app.log", "wayland.log", "audio.log",
|
||||
"device.txt", "network.txt", "events.jsonl", "memory.csv", "capture.json", "crash.log",
|
||||
"frame-trace.log", "process-trace.log", "game-lifecycle.log", "launches.log", "tools.tsv", "wanted.tsv", "prefixes.json",
|
||||
@@ -1003,15 +955,11 @@ internal object EnhancedSessionLogShare {
|
||||
private val KNOWN_COMPONENT_PATTERNS = listOf(
|
||||
Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,}-[a-z0-9-]{1,24}"),
|
||||
Regex("steam-[0-9]+\\.(?:log|txt)"),
|
||||
Regex("library[0-9]+(?:--?[0-9]{1,10})?"),
|
||||
Regex("(?:battle\\.net-[0-9]+|battle\\.net-setup-[0-9]+|Agent-[0-9]+)\\.log"),
|
||||
Regex("(?:Agent\\.[0-9]+|bna_[0-9]+)"),
|
||||
Regex("stores-[0-9]{4}-[0-9]{2}-[0-9]{2}\\.log"),
|
||||
Regex("library[0-9]{1,3}"),
|
||||
Regex("entry-[0-9a-f]{16}(?:\\.[a-z0-9]{1,8})?"),
|
||||
)
|
||||
private val APP_ID = Regex("[0-9]{1,10}")
|
||||
private val SIGNED_APP_ID = Regex("-?[0-9]{1,10}")
|
||||
private val SAFE_SUFFIX = Regex("\\.[A-Za-z0-9]{1,8}$")
|
||||
private val CRITICAL_SESSION_FILES = listOf(
|
||||
"session.log", "app.log", "wayland.log", "audio.log", "device.txt", "network.txt",
|
||||
@@ -1019,7 +967,6 @@ internal object EnhancedSessionLogShare {
|
||||
)
|
||||
private const val RECENT_MILLIS = 7L * 24 * 60 * 60 * 1000
|
||||
private const val STORE_LOG_SCAN = 512
|
||||
private const val EAC_LOG_DIR = "pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat"
|
||||
private const val COPY_BUFFER_BYTES = 64 * 1024
|
||||
private const val TRACE_SCAN_BYTES = 16L * 1024 * 1024
|
||||
private const val LEGACY_LOG_MAX_BYTES = 8L * 1024 * 1024
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.annotation.StringRes
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
enum class FullscreenMode(@StringRes val label: Int) {
|
||||
ALWAYS(R.string.widgets_on),
|
||||
LANDSCAPE_ONLY(R.string.setup_fullscreen_landscape_only),
|
||||
OFF(R.string.widgets_off);
|
||||
|
||||
fun hidesSystemBars(orientation: Int): Boolean =
|
||||
this == ALWAYS || (this == LANDSCAPE_ONLY && orientation == Configuration.ORIENTATION_LANDSCAPE)
|
||||
|
||||
companion object {
|
||||
fun fromStored(value: String?): FullscreenMode? = entries.firstOrNull { it.name == value }
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
|
||||
internal object PageCacheTrim {
|
||||
private const val TAG = "PageCacheTrim"
|
||||
private const val MIN_FILE_BYTES = 8L shl 20
|
||||
private const val POLL_MS = 3000L
|
||||
private const val RESCAN_MS = 120_000L
|
||||
|
||||
data class Mem(val freeKb: Long, val fileKb: Long)
|
||||
|
||||
fun parse(meminfo: String): Mem? {
|
||||
fun field(name: String) = Regex("""(?m)^$name:\s+(\d+) kB""").find(meminfo)?.groupValues?.get(1)?.toLongOrNull()
|
||||
val free = field("MemFree") ?: return null
|
||||
val file = (field("Active\\(file\\)") ?: return null) + (field("Inactive\\(file\\)") ?: return null)
|
||||
return Mem(free, file)
|
||||
}
|
||||
|
||||
fun shouldTrim(mem: Mem, baselineFileKb: Long): Boolean {
|
||||
val built = mem.fileKb - baselineFileKb
|
||||
return (mem.freeKb < 2560 * 1024 && built >= 768 * 1024) ||
|
||||
(mem.freeKb < 1024 * 1024 && built >= 128 * 1024)
|
||||
}
|
||||
|
||||
fun start(roots: () -> List<File>, alive: () -> Boolean) {
|
||||
Thread({
|
||||
var baseline = 0L
|
||||
var files = emptyList<File>()
|
||||
var scanned = 0L
|
||||
var trims = 0
|
||||
var failureLogged = false
|
||||
while (alive()) {
|
||||
runCatching {
|
||||
val mem = parse(File("/proc/meminfo").readText())
|
||||
if (mem != null && shouldTrim(mem, baseline)) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - scanned > RESCAN_MS) {
|
||||
files = roots().flatMap { root -> root.walkTopDown().onEnter { !java.nio.file.Files.isSymbolicLink(it.toPath()) }.filter { it.isFile && it.length() >= MIN_FILE_BYTES }.toList() }
|
||||
scanned = now
|
||||
}
|
||||
val began = System.nanoTime()
|
||||
files.forEach(::drop)
|
||||
val after = parse(File("/proc/meminfo").readText())
|
||||
baseline = after?.fileKb ?: mem.fileKb
|
||||
trims++
|
||||
Log.i(TAG, "trim #$trims: free ${mem.freeKb / 1024} -> ${after?.freeKb?.div(1024)} MB, file cache ${mem.fileKb / 1024} -> ${after?.fileKb?.div(1024)} MB, ${files.size} files, ${(System.nanoTime() - began) / 1_000_000} ms")
|
||||
}
|
||||
}.onFailure {
|
||||
if (!failureLogged) Log.w(TAG, "trim failed: $it")
|
||||
failureLogged = true
|
||||
}
|
||||
Thread.sleep(POLL_MS)
|
||||
}
|
||||
}, "page-cache-trim").apply { isDaemon = true }.start()
|
||||
}
|
||||
|
||||
private fun drop(file: File) {
|
||||
PageCacheNative.fadviseDontNeed(file.path)
|
||||
}
|
||||
}
|
||||
|
||||
internal object PageCacheNative {
|
||||
init {
|
||||
System.loadLibrary("sdnative")
|
||||
}
|
||||
|
||||
@JvmStatic external fun fadviseDontNeed(path: String): Int
|
||||
}
|
||||
@@ -9,8 +9,6 @@ import com.droiddeck.launcher.core.Downloader
|
||||
import com.droiddeck.launcher.core.FileUtils
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.runtime.NativeGuest
|
||||
import com.droiddeck.launcher.storage.SteamStorage
|
||||
import com.droiddeck.launcher.stores.steam.SteamClient
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import org.json.JSONArray
|
||||
@@ -36,9 +34,7 @@ object ProtonExtras {
|
||||
private var replacing = false
|
||||
|
||||
class Tool(val id: String, val name: String, val prefix: String, val repo: String, val assetPattern: Regex,
|
||||
val prereleases: Boolean = false, val x86_64: Boolean = false, val label: Int = 0) {
|
||||
val arch: String get() = if (x86_64) "x86-64" else "ARM64"
|
||||
}
|
||||
val prereleases: Boolean = false)
|
||||
|
||||
internal data class Asset(val tag: String, val name: String, val url: String, val sha512: String?, val size: Long,
|
||||
val sha256: String? = null, val releaseName: String = tag)
|
||||
@@ -46,13 +42,11 @@ object ProtonExtras {
|
||||
|
||||
const val OWN = "droiddeck"
|
||||
const val BIONIC = "bionic"
|
||||
const val ANTICHEAT = "anticheat"
|
||||
|
||||
val tools = listOf(
|
||||
Tool("ge", "GE-Proton", "GE-Proton", "GloriousEggroll/proton-ge-custom", Regex("aarch64\\.tar\\.(gz|xz)$")),
|
||||
Tool("cachyos", "proton-cachyos", "proton-cachyos", "CachyOS/proton-cachyos", Regex("arm64\\.tar\\.(gz|xz)$")),
|
||||
Tool("droiddeck", "DroidDeck-Proton", "DroidDeck-Proton", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Proton-.*aarch64\\.tar\\.(gz|xz)$")),
|
||||
Tool(ANTICHEAT, "DroidDeck-Proton x86-64", "DroidDeck-Proton", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Proton-.*x86_64\\.tar\\.(gz|xz)$"), x86_64 = true, label = R.string.pextra_anticheat),
|
||||
// Bionic (Android libc) Proton started outside the Linux userland; test builds are prereleases. No-proot only.
|
||||
Tool(BIONIC, "DroidDeck-Bionic", "DroidDeck-Bionic", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Bionic-.*aarch64\\.tar\\.(gz|xz)$"), prereleases = true),
|
||||
)
|
||||
@@ -72,14 +66,11 @@ object ProtonExtras {
|
||||
|
||||
internal fun installedIn(dir: File, tool: Tool): List<String> =
|
||||
dir.listFiles()
|
||||
?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && x86_64Build(it) == tool.x86_64 && usable(it) }
|
||||
?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && usable(it) }
|
||||
?.map { it.name }
|
||||
?.sortedWith { a, b -> compareVersions(a, b) }
|
||||
?: emptyList()
|
||||
|
||||
internal fun x86_64Build(dir: File): Boolean =
|
||||
File(dir, "files/lib/wine/x86_64-unix").isDirectory && !File(dir, "files/bin-arm64").isDirectory
|
||||
|
||||
private fun usable(dir: File): Boolean {
|
||||
val manifest = runCatching { File(dir, "toolmanifest.vdf").readText() }.getOrNull() ?: return false
|
||||
val command = Regex("\\\"commandline\\\"\\s+\\\"/?([^\\\" ]+)").find(manifest)?.groupValues?.getOrNull(1) ?: return false
|
||||
@@ -117,31 +108,15 @@ object ProtonExtras {
|
||||
|
||||
fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool))
|
||||
|
||||
fun missing(context: Context, tool: Tool): String? = missing(context, tool) { antiCheatRuntimeInstalled(context) }
|
||||
|
||||
internal fun missing(context: Context, tool: Tool, antiCheat: () -> Boolean): String? = when {
|
||||
declined(context, tool.id) || installedAll(context, tool).isNotEmpty() -> null
|
||||
tool.id == OWN || tool.id == ANTICHEAT && antiCheat() -> cachedLatest(context, tool)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun antiCheatRuntimeInstalled(context: Context): Boolean =
|
||||
antiCheatRuntimeIn(listOf("arm64", SteamClient.X86_64).flatMap { arch ->
|
||||
runCatching { SteamClient.libraries(context, arch).map { it.host } }.getOrDefault(emptyList())
|
||||
} + listOfNotNull(GameStorage.effective(context)?.let { File(it.path) }, GameStorage.x64CardLibrary(context)))
|
||||
|
||||
internal fun antiCheatRuntimeIn(libraries: List<File>): Boolean = libraries.any { library ->
|
||||
ANTICHEAT_RUNTIMES.any { File(library, "steamapps/appmanifest_$it.acf").isFile }
|
||||
}
|
||||
|
||||
private val ANTICHEAT_RUNTIMES = listOf(SteamStorage.EAC_RUNTIME, SteamStorage.BATTLEYE_RUNTIME)
|
||||
fun missing(context: Context, tool: Tool): String? =
|
||||
if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null
|
||||
|
||||
private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE)
|
||||
|
||||
fun declined(context: Context, id: String = OWN): Boolean = choices(context).getBoolean("$id.declined", false)
|
||||
fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false)
|
||||
|
||||
fun setDeclined(context: Context, declined: Boolean, id: String = OWN) {
|
||||
choices(context).edit().putBoolean("$id.declined", declined).apply()
|
||||
fun setDeclined(context: Context, declined: Boolean) {
|
||||
choices(context).edit().putBoolean("$OWN.declined", declined).apply()
|
||||
}
|
||||
|
||||
fun cachedLatest(context: Context, tool: Tool): String? =
|
||||
@@ -245,8 +220,8 @@ object ProtonExtras {
|
||||
if (runCatching { ComponentsManager.carryOver(context, old, newest) }.onFailure { Log.w(TAG, "components of $old", it) }.isFailure) continue
|
||||
if (runCatching { keepUserSettings(context, old, newest) }.onFailure { Log.w(TAG, "user settings of $old", it) }.isFailure) continue
|
||||
if (runCatching { ProtonDefault.moveGames(context, setOf(old), newest) }.onFailure { Log.w(TAG, "per-game picks of $old", it) }.isFailure) continue
|
||||
// DroidDeck-Bionic and the x86-64 build: the guest finds no default for a deleted build and falls back to DroidDeck-Proton
|
||||
if ((tool.id == BIONIC || tool.id == ANTICHEAT) && runCatching { ProtonDefault.moveDefault(context, setOf(old), newest) }.onFailure { Log.w(TAG, "default pick of $old", it) }.isFailure) continue
|
||||
// DroidDeck-Bionic only: the guest finds no default for a deleted Bionic build and falls back to DroidDeck-Proton
|
||||
if (tool.id == BIONIC && runCatching { ProtonDefault.moveDefault(context, setOf(old), newest) }.onFailure { Log.w(TAG, "default pick of $old", it) }.isFailure) continue
|
||||
if (deleteTool(context, old)) ComponentsManager.forgetProton(context, old)
|
||||
else Log.w(TAG, "could not remove $old")
|
||||
}
|
||||
@@ -313,7 +288,7 @@ object ProtonExtras {
|
||||
}
|
||||
|
||||
private fun prefetchNow(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch)
|
||||
val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name)
|
||||
val downloads = File(context.filesDir, "proton-downloads").apply { mkdirs() }
|
||||
val archive = File(downloads, "${tool.id}-${asset.name}")
|
||||
if (asset.size > 0 && archive.length() > asset.size) archive.delete()
|
||||
@@ -330,7 +305,7 @@ object ProtonExtras {
|
||||
if (SessionState.running) return context.getString(R.string.pextra_stop_session)
|
||||
if (!LinuxRuntime.isInstalled(context)) return context.getString(R.string.user_apps_runtime_required)
|
||||
|
||||
val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch)
|
||||
val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name)
|
||||
val downloads = File(context.filesDir, "proton-downloads").apply { mkdirs() }
|
||||
val archive = File(downloads, "${tool.id}-${asset.name}")
|
||||
if (asset.size > 0 && archive.length() > asset.size) archive.delete()
|
||||
@@ -399,7 +374,7 @@ object ProtonExtras {
|
||||
archive.delete()
|
||||
unqueue(context, tool)
|
||||
record(context, tool, placed, asset.tag)
|
||||
if (tool.id == OWN || tool.id == BIONIC || tool.id == ANTICHEAT) replaceOlder(context, tool)
|
||||
if (tool.id == OWN || tool.id == BIONIC) replaceOlder(context, tool)
|
||||
if (EsyncPacks.enabled(context)) {
|
||||
onProgress(context.getString(R.string.esync_fetching), -1)
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,6 @@ object SessionDisplay {
|
||||
const val LINK_PORTRAIT = "link/portrait"
|
||||
|
||||
const val DEFAULT_RESOLUTION = "720p"
|
||||
const val DEFAULT_STEAM_PORTRAIT_RESOLUTION = "1280x800"
|
||||
private val PRESET_HEIGHTS = listOf(720, 900, 1080)
|
||||
|
||||
fun presetHeight(choice: String): Int? =
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.core.CpuFeatures
|
||||
import com.droiddeck.launcher.core.FileUtils
|
||||
import com.droiddeck.launcher.runtime.BwrapSpawner
|
||||
import com.droiddeck.launcher.runtime.DesktopCatalog
|
||||
@@ -23,10 +22,6 @@ object SessionFiles {
|
||||
private const val NO_PAD_SWITCH = "Download/droiddeck-no-pad"
|
||||
const val DIRECTAUDIO_DIR = "usr/local/lib/directaudio"
|
||||
private const val STAGED_LEDGER = "usr/local/.droiddeck-staged"
|
||||
internal const val LSE_EMU = "usr/local/lib/droiddeck-lse/liblse_emu.so"
|
||||
|
||||
internal fun lsePreload(lacksAtomics: Boolean, staged: Boolean, lseEmu: String? = null): String =
|
||||
if (lacksAtomics && staged && lseEmu != "0") "/$LSE_EMU\n" else ""
|
||||
private const val IME_MANIFEST = "usr/local/share/droiddeck/ime-files.json"
|
||||
private const val IME_DEFAULT_MODE = 420
|
||||
val DIRECTAUDIO_SETS = arrayOf("linux-wine11", "linux-wine11-systhread")
|
||||
@@ -107,23 +102,10 @@ object SessionFiles {
|
||||
}
|
||||
|
||||
private val STAGE_LOCK = Any()
|
||||
@Volatile private var activeSessionLseEmu: String? = null
|
||||
|
||||
fun stage(context: Context, root: File, startsSession: Boolean = false) =
|
||||
stage(context, root, startsSession, lseEmu = null)
|
||||
fun stage(context: Context, root: File, startsSession: Boolean = false) = synchronized(STAGE_LOCK) { stageNow(context, root, startsSession) }
|
||||
|
||||
fun stage(context: Context, root: File, startsSession: Boolean, lseEmu: String?) =
|
||||
synchronized(STAGE_LOCK) {
|
||||
val selection = if (startsSession) {
|
||||
activeSessionLseEmu = lseEmu
|
||||
lseEmu
|
||||
} else {
|
||||
lseEmu ?: activeSessionLseEmu
|
||||
}
|
||||
stageNow(context, root, startsSession, selection)
|
||||
}
|
||||
|
||||
private fun stageNow(context: Context, root: File, startsSession: Boolean, lseEmu: String?) {
|
||||
private fun stageNow(context: Context, root: File, startsSession: Boolean) {
|
||||
if (DesktopCatalog.desktopInstalled(root) && !DesktopCatalog.desktopFromPack(root)) try { DesktopCatalog.cleanLegacy(context) }
|
||||
catch (e: Exception) { Log.w(TAG, "LXQt cleanup will retry next session", e) }
|
||||
GameEnvironmentStore.publish(context)
|
||||
@@ -299,7 +281,6 @@ object SessionFiles {
|
||||
"usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst",
|
||||
"usr/local/share/licenses/dwarfs/LICENSE" to "usr/local/share/licenses/dwarfs/LICENSE",
|
||||
"usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE",
|
||||
LSE_EMU to LSE_EMU,
|
||||
) + mangoapp + xclipse.map { it to it } + maliCompat + msitools.map { it to it } + vr + gpuLoad + fexPreloads).filter { (asset, _) ->
|
||||
val dir = asset.substringBeforeLast('/')
|
||||
runCatching { context.assets.list("linuxfs/$dir")?.contains(asset.substringAfterLast('/')) == true }.getOrDefault(false)
|
||||
@@ -362,22 +343,20 @@ object SessionFiles {
|
||||
stageImeFiles(context, root, ledger)
|
||||
ledger.save()
|
||||
for (old in arrayOf("aarch64-unix", "aarch64-windows", "i386-windows")) File(root, "$DIRECTAUDIO_DIR/lib/wine/$old").deleteRecursively()
|
||||
val preload = StringBuilder(lsePreload(CpuFeatures.lacksAtomics, File(root, LSE_EMU).isFile, lseEmu))
|
||||
preload.append("/usr/local/lib/libddsession.so\n")
|
||||
val preload = StringBuilder("/usr/local/lib/libddsession.so\n")
|
||||
if (!File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()) {
|
||||
preload.append("/usr/local/lib/libfakeinput.so\n")
|
||||
}
|
||||
com.droiddeck.launcher.runtime.NativeGuest.prepare(context, root)
|
||||
val native = com.droiddeck.launcher.runtime.NativeGuest.available(root)
|
||||
val nativePreload = preload.toString()
|
||||
if (ProotFastPath.enabled(context, native)) {
|
||||
val nativeUserland = SessionPrefs.nativeUserland(context)
|
||||
if (nativeUserland) com.droiddeck.launcher.runtime.NativeGuest.prepare(context, root)
|
||||
if (ProotFastPath.enabled(context)) {
|
||||
val library = com.droiddeck.launcher.agent.AgentEnv.fastPathLibrary(context)
|
||||
preload.append(library + "\n")
|
||||
if (startsSession && library != ProotFastPath.LIBRARY) Log.i(TAG, "fast path preload: $library (debugging override)")
|
||||
}
|
||||
val etc = File(root, "etc").apply { mkdirs() }
|
||||
File(etc, "droiddeck").mkdirs()
|
||||
FileUtils.writeString(File(etc, "droiddeck/native-preload"), nativePreload)
|
||||
FileUtils.writeString(File(etc, "droiddeck/native-preload"), preload.toString())
|
||||
val staged = File(etc, "ld.so.preload.staged")
|
||||
if (!FileUtils.writeString(staged, preload.toString())
|
||||
|| !staged.renameTo(File(etc, "ld.so.preload"))) {
|
||||
|
||||
@@ -112,21 +112,10 @@ object SessionPrefs {
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun launcherFullscreenMode(context: Context): FullscreenMode {
|
||||
val preferences = prefs(context)
|
||||
return FullscreenMode.fromStored(preferences.getString("launcherFullscreenMode", null))
|
||||
?: if (preferences.getBoolean("launcherFullscreen", true)) FullscreenMode.ALWAYS else FullscreenMode.OFF
|
||||
}
|
||||
fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true)
|
||||
|
||||
fun setLauncherFullscreenMode(context: Context, mode: FullscreenMode) {
|
||||
prefs(context).edit().putString("launcherFullscreenMode", mode.name).apply()
|
||||
}
|
||||
|
||||
fun sessionFullscreenMode(context: Context): FullscreenMode =
|
||||
FullscreenMode.fromStored(prefs(context).getString("sessionFullscreenMode", null)) ?: FullscreenMode.ALWAYS
|
||||
|
||||
fun setSessionFullscreenMode(context: Context, mode: FullscreenMode) {
|
||||
prefs(context).edit().putString("sessionFullscreenMode", mode.name).apply()
|
||||
fun setLauncherFullscreen(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("launcherFullscreen", on).apply()
|
||||
}
|
||||
|
||||
fun launcherFrost(context: Context): Boolean = prefs(context).getBoolean("launcherFrost", false)
|
||||
@@ -375,13 +364,13 @@ object SessionPrefs {
|
||||
prefs(context).edit().putInt("libraryCardLevel", level).apply()
|
||||
}
|
||||
|
||||
fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", false)
|
||||
fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", true)
|
||||
|
||||
fun setLibraryShowTitle(context: Context, show: Boolean) {
|
||||
prefs(context).edit().putBoolean("libraryShowTitle", show).apply()
|
||||
}
|
||||
|
||||
fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", false)
|
||||
fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", true)
|
||||
|
||||
fun setLibraryShowSize(context: Context, show: Boolean) {
|
||||
prefs(context).edit().putBoolean("libraryShowSize", show).apply()
|
||||
@@ -957,21 +946,13 @@ object SessionPrefs {
|
||||
}
|
||||
|
||||
|
||||
private val picturePositions = setOf("center", "top", "bottom", "left", "right")
|
||||
fun picturePosition(context: Context): String =
|
||||
prefs(context).getString("picturePosition", "center")
|
||||
?.takeIf { it in listOf("top", "bottom", "left", "right", "center") } ?: "center"
|
||||
|
||||
private fun picturePositionKey(portrait: Boolean) =
|
||||
if (portrait) "picturePosition.portrait" else "picturePosition.landscape"
|
||||
|
||||
fun picturePosition(context: Context, portrait: Boolean): String {
|
||||
val preferences = prefs(context)
|
||||
return preferences.getString(picturePositionKey(portrait), null)?.takeIf { it in picturePositions }
|
||||
?: preferences.getString("picturePosition", null)?.takeIf { it in picturePositions }
|
||||
?: if (portrait) "top" else "center"
|
||||
}
|
||||
|
||||
fun setPicturePosition(context: Context, portrait: Boolean, position: String) {
|
||||
require(position in picturePositions)
|
||||
prefs(context).edit().putString(picturePositionKey(portrait), position).apply()
|
||||
fun setPicturePosition(context: Context, position: String) {
|
||||
prefs(context).edit().putString("picturePosition",
|
||||
position.takeIf { it in listOf("top", "bottom", "left", "right", "center") } ?: "center").apply()
|
||||
}
|
||||
|
||||
fun integerScaling(context: Context): Boolean =
|
||||
@@ -1181,9 +1162,21 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("mountSharedStorage", on).apply()
|
||||
}
|
||||
|
||||
fun prootNoSeccomp(context: Context): Boolean = prefs(context).getBoolean("prootNoSeccomp", false)
|
||||
|
||||
fun setProotNoSeccomp(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("prootNoSeccomp", on).apply()
|
||||
}
|
||||
|
||||
fun nativeUserland(context: Context): Boolean = prefs(context).getBoolean("nativeUserland", true)
|
||||
|
||||
/** The session's long-lived programs run in worker processes Android does not count (GuestWorkers). */
|
||||
fun childProcessHandoff(context: Context): Boolean = prefs(context).getBoolean("childProcessHandoff", true)
|
||||
|
||||
fun setNativeUserland(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("nativeUserland", on).apply()
|
||||
}
|
||||
|
||||
/** Whether the Plasma desktop, and so its apps and shells, runs as an ordinary user instead of root (native userland only). */
|
||||
fun desktopAsUser(context: Context): Boolean = prefs(context).getBoolean("desktopAsUser", false)
|
||||
|
||||
@@ -1191,6 +1184,12 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("desktopAsUser", on).apply()
|
||||
}
|
||||
|
||||
fun prootFastPath(context: Context): Boolean = prefs(context).getBoolean("prootFastPath", true)
|
||||
|
||||
fun setProotFastPath(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("prootFastPath", on).apply()
|
||||
}
|
||||
|
||||
fun cursorComposite(context: Context): Boolean = prefs(context).getBoolean("cursorComposite", true)
|
||||
|
||||
fun setCursorComposite(context: Context, on: Boolean) {
|
||||
@@ -1514,12 +1513,10 @@ object SessionPrefs {
|
||||
|
||||
fun resolutionStored(context: Context, mode: String, panel: Pair<Int, Int>, portrait: Boolean): String {
|
||||
if (!portrait) return landscapeResolutionStored(context, mode, panel)
|
||||
val fallback = if (mode == SessionService.MODE_STEAM) SessionDisplay.DEFAULT_STEAM_PORTRAIT_RESOLUTION
|
||||
else SessionDisplay.LINK_LANDSCAPE
|
||||
val value = prefs(context).getString("displayResolution.portrait.$mode", null) ?: return fallback
|
||||
val value = prefs(context).getString("displayResolution.portrait.$mode", null) ?: return SessionDisplay.LINK_LANDSCAPE
|
||||
if (value == SessionDisplay.LINK_LANDSCAPE || value == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(value) ||
|
||||
SessionDisplay.presetHeight(value) != null) return value
|
||||
return parseOrientedResolution(value)?.let { "${it.first}x${it.second}" } ?: fallback
|
||||
return parseOrientedResolution(value)?.let { "${it.first}x${it.second}" } ?: SessionDisplay.LINK_LANDSCAPE
|
||||
}
|
||||
|
||||
fun parseOrientedResolution(text: String): Pair<Int, Int>? =
|
||||
@@ -1781,9 +1778,6 @@ object SessionPrefs {
|
||||
name.removeSuffix(from) + to to moved
|
||||
}
|
||||
|
||||
fun storedAddedGameAppId(context: Context, folderPath: String): Long? =
|
||||
prefs(context).getLong("addedAppId:$folderPath", 0L).takeIf { it != 0L }
|
||||
|
||||
fun addedGameAppId(context: Context, folderPath: String, first: Long): Long = synchronized(addedGameLock) {
|
||||
val p = prefs(context)
|
||||
p.getLong("addedAppId:$folderPath", 0L).takeIf { it != 0L }
|
||||
@@ -1880,13 +1874,6 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean(hdrKey(mode), on).apply()
|
||||
}
|
||||
|
||||
/** Restart-scoped opt-in; not inferred from Zero-copy (which defaults on). */
|
||||
fun producerAcquireFences(context: Context): Boolean = prefs(context).getBoolean("producerAcquireFences", false)
|
||||
|
||||
fun setProducerAcquireFences(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("producerAcquireFences", on).apply()
|
||||
}
|
||||
|
||||
fun zeroCopy(context: Context, mode: String): Boolean = prefs(context).getBoolean("zeroCopy.${prefMode(mode)}", true)
|
||||
|
||||
fun setZeroCopy(context: Context, mode: String, on: Boolean) {
|
||||
@@ -1905,9 +1892,6 @@ object SessionPrefs {
|
||||
return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit
|
||||
}
|
||||
|
||||
fun layerFrameRate(ownLimit: Int, refreshHz: Float, blackFrameInsertion: Boolean): Float =
|
||||
if (ownLimit > 0 && !blackFrameInsertion) ownLimit.toFloat() else refreshHz
|
||||
|
||||
/** The per-app rate Android holds this window to (Game Mode's FPS override), or 0 when the panel's rate applies. */
|
||||
fun hostFrameCap(overrideHz: Float, panelHz: Float): Int =
|
||||
if (overrideHz > 1f && panelHz - overrideHz > 1f) Math.round(overrideHz) else 0
|
||||
@@ -2007,84 +1991,24 @@ object SessionPrefs {
|
||||
sessionPrefs.edit().putString(SCREEN_EFFECTS_PROFILES_KEY, profiles.toString()).apply()
|
||||
}
|
||||
|
||||
private const val GAME_UPSCALER_OVERRIDES_KEY = "upscaler.gameOverrides"
|
||||
|
||||
private fun gameUpscalerOverrides(context: Context): JSONObject = runCatching {
|
||||
JSONObject(prefs(context).getString(GAME_UPSCALER_OVERRIDES_KEY, null) ?: "{}")
|
||||
}.getOrDefault(JSONObject())
|
||||
|
||||
private fun legacyScreenEffectsUpscaler(context: Context, profileId: String): Int? =
|
||||
runCatching {
|
||||
val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
val profile = profiles.optJSONObject(profileId)
|
||||
if (profile?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true) {
|
||||
profile.optInt(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY, -1).takeIf { it >= 0 }
|
||||
} else null
|
||||
}.getOrNull()?.let(::canonicalUpscaler)
|
||||
|
||||
private fun clearLegacyScreenEffectsUpscaler(context: Context, profileId: String) {
|
||||
val sessionPrefs = prefs(context)
|
||||
val profiles = runCatching {
|
||||
JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
}.getOrNull() ?: return
|
||||
val profile = profiles.optJSONObject(profileId) ?: return
|
||||
if (!profile.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY)) return
|
||||
profile.remove(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY)
|
||||
if (profile.length() == 0) profiles.remove(profileId)
|
||||
sessionPrefs.edit().apply {
|
||||
if (profiles.length() == 0) remove(SCREEN_EFFECTS_PROFILES_KEY)
|
||||
else putString(SCREEN_EFFECTS_PROFILES_KEY, profiles.toString())
|
||||
}.apply()
|
||||
}
|
||||
|
||||
fun hasGameUpscalerOverride(context: Context, gameId: String): Boolean {
|
||||
if (gameId.isBlank()) return false
|
||||
val stored = gameUpscalerOverrides(context)
|
||||
return (stored.has(gameId) && stored.optInt(gameId, -1) >= 0) ||
|
||||
legacyScreenEffectsUpscaler(context, "game:$gameId") != null
|
||||
}
|
||||
|
||||
fun setGameUpscaler(context: Context, gameId: String, mode: Int) {
|
||||
if (gameId.isBlank()) return
|
||||
val overrides = gameUpscalerOverrides(context)
|
||||
overrides.put(gameId, canonicalUpscaler(mode))
|
||||
prefs(context).edit().putString(GAME_UPSCALER_OVERRIDES_KEY, overrides.toString()).apply()
|
||||
clearLegacyScreenEffectsUpscaler(context, "game:$gameId")
|
||||
}
|
||||
|
||||
fun clearGameUpscaler(context: Context, gameId: String) {
|
||||
if (gameId.isBlank()) return
|
||||
val sessionPrefs = prefs(context)
|
||||
val overrides = gameUpscalerOverrides(context)
|
||||
if (overrides.has(gameId)) {
|
||||
overrides.remove(gameId)
|
||||
sessionPrefs.edit().apply {
|
||||
if (overrides.length() == 0) remove(GAME_UPSCALER_OVERRIDES_KEY)
|
||||
else putString(GAME_UPSCALER_OVERRIDES_KEY, overrides.toString())
|
||||
}.apply()
|
||||
}
|
||||
clearLegacyScreenEffectsUpscaler(context, "game:$gameId")
|
||||
}
|
||||
|
||||
fun hasScreenEffectsUpscalerOverride(context: Context, profileId: String?): Boolean {
|
||||
if (profileId.isNullOrBlank()) return false
|
||||
if (profileId.startsWith("game:")) {
|
||||
return hasGameUpscalerOverride(context, profileId.removePrefix("game:"))
|
||||
}
|
||||
return legacyScreenEffectsUpscaler(context, profileId) != null
|
||||
return runCatching {
|
||||
val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
profiles.optJSONObject(profileId)?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
fun screenEffectsUpscaler(context: Context, profileId: String?): Int {
|
||||
if (profileId.isNullOrBlank()) return upscaler(context)
|
||||
if (profileId.startsWith("game:")) {
|
||||
val gameId = profileId.removePrefix("game:")
|
||||
val overrides = gameUpscalerOverrides(context)
|
||||
if (overrides.has(gameId)) {
|
||||
val stored = overrides.optInt(gameId, -1)
|
||||
if (stored >= 0) return canonicalUpscaler(stored)
|
||||
}
|
||||
}
|
||||
return legacyScreenEffectsUpscaler(context, profileId) ?: upscaler(context)
|
||||
val stored = runCatching {
|
||||
val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
val profile = profiles.optJSONObject(profileId)
|
||||
if (profile?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true) {
|
||||
profile.optInt(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY, -1)
|
||||
} else -1
|
||||
}.getOrDefault(-1)
|
||||
return if (stored >= 0) canonicalUpscaler(stored) else upscaler(context)
|
||||
}
|
||||
|
||||
fun setScreenEffectsUpscaler(context: Context, profileId: String?, mode: Int) {
|
||||
@@ -2092,10 +2016,6 @@ object SessionPrefs {
|
||||
setUpscaler(context, mode)
|
||||
return
|
||||
}
|
||||
if (profileId.startsWith("game:")) {
|
||||
setGameUpscaler(context, profileId.removePrefix("game:"), mode)
|
||||
return
|
||||
}
|
||||
val sessionPrefs = prefs(context)
|
||||
val profiles = runCatching {
|
||||
JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
@@ -2132,7 +2052,6 @@ object SessionPrefs {
|
||||
val profiles = runCatching {
|
||||
JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}")
|
||||
}.getOrElse { JSONObject() }
|
||||
if (profileId.startsWith("game:")) clearGameUpscaler(context, profileId.removePrefix("game:"))
|
||||
if (!profiles.has(profileId)) return
|
||||
profiles.remove(profileId)
|
||||
sessionPrefs.edit().apply {
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.droiddeck.launcher.input.SteamControllerBle
|
||||
import com.droiddeck.launcher.runtime.BwrapSpawner
|
||||
import com.droiddeck.launcher.runtime.LinuxNetworkLinkComponent
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.runtime.NativeGuest
|
||||
import com.droiddeck.launcher.runtime.ProotFastPath
|
||||
import com.droiddeck.launcher.runtime.UserApps
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
@@ -395,10 +394,8 @@ class SessionService : Service() {
|
||||
SessionState.program = intent?.getStringExtra(EXTRA_PROGRAM)
|
||||
SessionState.programArgs = intent?.getStringArrayExtra(EXTRA_PROGRAM_ARGS)?.toList().orEmpty()
|
||||
SessionState.steamUi = intent?.getStringExtra(EXTRA_STEAM_UI)
|
||||
val launchSteamUrl = intent?.getStringExtra(EXTRA_STEAM_URL)
|
||||
val frontendSteamGame = intent?.getBooleanExtra(EXTRA_FRONTEND_STEAM_GAME, false) == true
|
||||
SessionState.steamUrl = launchSteamUrl
|
||||
val steamUrlGameId = launchSteamUrl
|
||||
SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL)
|
||||
val steamUrlGameId = SessionState.steamUrl
|
||||
?.let { url ->
|
||||
when {
|
||||
url.startsWith(GAME_URL_PREFIX) ->
|
||||
@@ -429,11 +426,6 @@ class SessionService : Service() {
|
||||
++sessionGen
|
||||
}
|
||||
}
|
||||
val trimGen = gen
|
||||
PageCacheTrim.start(
|
||||
roots = { listOfNotNull(File(filesDir, "linuxfs"), GameStorage.effective(applicationContext)?.let { File(it.path) }).filter(File::isDirectory) },
|
||||
alive = { SessionState.running && sessionGen == trimGen },
|
||||
)
|
||||
if (SessionState.stopRequested) {
|
||||
stopSession(0)
|
||||
return START_NOT_STICKY
|
||||
@@ -455,7 +447,7 @@ class SessionService : Service() {
|
||||
Thread({
|
||||
OrphanReaper.reap("session starting")
|
||||
ProtonExtras.awaitReplacement(120_000)
|
||||
runSession(gen, launchSteamUrl, frontendSteamGame)
|
||||
runSession(gen)
|
||||
}, "session-start").start()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
@@ -508,7 +500,7 @@ class SessionService : Service() {
|
||||
}
|
||||
|
||||
|
||||
private fun runSession(gen: Int, launchSteamUrl: String?, frontendSteamGame: Boolean) {
|
||||
private fun runSession(gen: Int) {
|
||||
SessionPrefs.ensurePowerVrAutoDriversAfterGpuQuery(this)
|
||||
if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) {
|
||||
com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) }
|
||||
@@ -563,11 +555,9 @@ class SessionService : Service() {
|
||||
return
|
||||
}
|
||||
}
|
||||
val nextAgentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) }
|
||||
val agentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) }
|
||||
.onFailure { Log.w(TAG, "agent environment skipped", it) }
|
||||
val agentEnvironment = nextAgentEnvironment.getOrDefault(emptyList())
|
||||
val customEnvironment = extraEnv()
|
||||
val lseEmu = (customEnvironment + agentEnvironment).lastOrNull { it.startsWith("LSE_EMU=") }?.substringAfter('=')
|
||||
.getOrDefault(emptyList())
|
||||
try {
|
||||
if (systemVulkan) {
|
||||
SystemVulkanDriver.prepare(this)
|
||||
@@ -577,7 +567,7 @@ class SessionService : Service() {
|
||||
}
|
||||
pruneSystemVulkanRuntime()
|
||||
}
|
||||
SessionFiles.stage(this, root, startsSession = true, lseEmu = lseEmu)
|
||||
SessionFiles.stage(this, root, startsSession = true)
|
||||
} catch (error: Exception) {
|
||||
Log.e(TAG, "Could not prepare the session graphics runtime", error)
|
||||
failSession(gen, "GRAPHICS_RUNTIME_FAILED", getString(R.string.session_graphics_runtime_failed), -1)
|
||||
@@ -624,9 +614,6 @@ class SessionService : Service() {
|
||||
val size = SessionState.outputSize
|
||||
val guest = ArrayList<String>()
|
||||
val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP
|
||||
runCatching { SessionEvents.step("components-xbox") { XboxBackCompatComponents.ensure(this) } }
|
||||
.onSuccess { if (it != null) Log.i(TAG, it) }
|
||||
.onFailure { Log.w(TAG, "original Xbox components", it) }
|
||||
runCatching { SessionEvents.step("components-republish") { ComponentsManager.republish(this) } }
|
||||
.onSuccess { if (it) Log.i(TAG, "component selections published for the installed Proton builds") }
|
||||
.onFailure { Log.w(TAG, "component selections", it) }
|
||||
@@ -636,7 +623,7 @@ class SessionService : Service() {
|
||||
.onFailure { Log.w(TAG, "forced components", it) }
|
||||
}
|
||||
try {
|
||||
SessionEvents.step("client-environment") { addClientEnvironment(guest, steamHere, agentEnvironment, customEnvironment) }
|
||||
SessionEvents.step("client-environment") { addClientEnvironment(guest, steamHere, agentEnvironment) }
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.e(TAG, "Could not resolve the selected Linux Vulkan driver", e)
|
||||
failSession(gen, "VULKAN_DRIVER_UNAVAILABLE", e.message ?: "Selected Linux Vulkan driver is unavailable", -1)
|
||||
@@ -721,28 +708,15 @@ class SessionService : Service() {
|
||||
// this session's worker number: the shared field may be a newer session's by the time it is used
|
||||
var ownWorkers = 0
|
||||
if (com.droiddeck.launcher.runtime.GuestWorkers.enabled(this)) {
|
||||
val fenceWorker = com.droiddeck.launcher.runtime.FrameAcquireWorkerProbe
|
||||
val preparedFence = if (steamHere && !systemVulkan && !VenusComponent.wanted(this) &&
|
||||
SessionPrefs.zeroCopy(this, MODE_STEAM) && SessionPrefs.producerAcquireFences(this) &&
|
||||
nextAgentEnvironment.isSuccess && fenceWorker.validEnvironment(agentEnvironment, customEnvironment)
|
||||
) fenceWorker.prepare(this, launchSteamUrl, frontendSteamGame) else null
|
||||
var fenceArmed = false
|
||||
// Under the lock a stop takes its number with: a stop either comes first (and this session
|
||||
// starts no workers) or owns them
|
||||
ownWorkers = synchronized(stopLock) {
|
||||
if (gen != sessionGen || !SessionState.running) 0
|
||||
else com.droiddeck.launcher.runtime.GuestWorkers.serve(this).also {
|
||||
guestWorkerSession = it
|
||||
if (preparedFence != null) fenceArmed = fenceWorker.arm(it, preparedFence)
|
||||
}
|
||||
else com.droiddeck.launcher.runtime.GuestWorkers.serve(this).also { guestWorkerSession = it }
|
||||
}
|
||||
if (ownWorkers > 0) {
|
||||
guest.add("DD_SPAWN=" + com.droiddeck.launcher.runtime.GuestWorkers.socketName(this))
|
||||
guest.add("DD_SPAWN_SESSION=$ownWorkers")
|
||||
if (fenceArmed) {
|
||||
guest.add(fenceWorker.GAMESCOPE_ENABLE)
|
||||
guest.add(fenceWorker.GAME_ENABLE)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Proton builds up to 11.12 report X11 text fields under this name.
|
||||
@@ -764,7 +738,7 @@ class SessionService : Service() {
|
||||
val desktopGuest = ArrayList(guest)
|
||||
guest.add(LinuxRuntime.SESSION_SCRIPT)
|
||||
guest.add(SessionState.mode)
|
||||
if (SessionState.mode == MODE_STEAM) launchSteamUrl?.takeIf { it.startsWith("steam://") }?.let {
|
||||
if (SessionState.mode == MODE_STEAM) SessionState.steamUrl?.takeIf { it.startsWith("steam://") }?.let {
|
||||
guest.add(it)
|
||||
Log.i(TAG, "steam: handing the client $it")
|
||||
}
|
||||
@@ -785,13 +759,12 @@ class SessionService : Service() {
|
||||
SessionEvents.step("shm-clear") { FileUtils.clear(File(LinuxRuntime.liveDir(this), "shm")) }
|
||||
|
||||
val sharedStorage = LinuxRuntime.sharedStorage(this)
|
||||
val nativeUserland = NativeGuest.enabled(this)
|
||||
val fastPath = ProotFastPath.enabled(this, nativeUserland)
|
||||
val binds = sessionBinds(controllersOn, fakeInputDir, sessionDir, guest, sessionRoot, runtimeDir, sharedStorage, fastPath)
|
||||
val binds = sessionBinds(controllersOn, fakeInputDir, sessionDir, guest, sessionRoot, runtimeDir, sharedStorage)
|
||||
val nativeUserland = com.droiddeck.launcher.runtime.NativeGuest.enabled(this)
|
||||
synchronized(stopLock) {
|
||||
if (gen == sessionGen && SessionState.running) com.droiddeck.launcher.runtime.NativeGuest.sessionMode = nativeUserland
|
||||
}
|
||||
val fastPathKey = if (fastPath) {
|
||||
val fastPathKey = if (ProotFastPath.enabled(this)) {
|
||||
val prootBinds = LinuxRuntime.binds(
|
||||
this, sessionRoot, runtimeDir, sharedStorage, binds,
|
||||
)
|
||||
@@ -812,14 +785,16 @@ class SessionService : Service() {
|
||||
LinuxRuntime.rememberSessionBinds(sessionBindSpecs)
|
||||
com.droiddeck.launcher.runtime.NativeGuest.command(root, guest.first(), guest.drop(1))
|
||||
} else {
|
||||
val reason = if (NativeGuest.loader(root) == null) "missing glibc loader" else "missing native hook"
|
||||
Log.i(TAG, "guest runtime: using PRoot ($reason)")
|
||||
LinuxRuntime.command(this, sessionRoot, runtimeDir, sharedStorage, binds, guest)
|
||||
}
|
||||
|
||||
val prootEnv = HostEnvironment()
|
||||
prootEnv["PROOT_LOADER"] = LinuxRuntime.prootLoader(this).path
|
||||
prootEnv["PROOT_TMP_DIR"] = LinuxRuntime.prootTempDir(this).path
|
||||
if (SessionPrefs.prootNoSeccomp(this)) {
|
||||
prootEnv["PROOT_NO_SECCOMP"] = "1"
|
||||
if (!nativeUserland) Log.i(TAG, "proot: seccomp acceleration off by request")
|
||||
}
|
||||
fastPathKey?.let { ProotFastPath.hostEnv(it).let { (k, v) -> prootEnv[k] = v } }
|
||||
for (key in listOf("PROOT_PROFILE", "PROOT_PROFILE_SLOW_US")) {
|
||||
guest.lastOrNull { it.startsWith("$key=") }?.substringAfter('=')?.let { prootEnv[key] = it }
|
||||
@@ -831,7 +806,7 @@ class SessionService : Service() {
|
||||
if (drives > 0) Log.i(TAG, "$drives Wine drive links given their guest paths back")
|
||||
val hostEnv = if (nativeUserland) HostEnvironment().also { env ->
|
||||
Log.i(TAG, "native userland: no proot (${sessionBindSpecs.size} mounts)")
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(root, sessionBindSpecs, guest.first(), SessionPrefs.guestHostname(this), lseEmu)
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(root, sessionBindSpecs, guest.first(), SessionPrefs.guestHostname(this))
|
||||
.forEach { (k, v) -> env[k] = v }
|
||||
} else prootEnv
|
||||
|
||||
@@ -946,15 +921,11 @@ class SessionService : Service() {
|
||||
return
|
||||
}
|
||||
if (gen == sessionGen && SessionState.running) {
|
||||
val workers = ownWorkers
|
||||
suspendController = SessionSuspendController(
|
||||
sessionRoot = { sessionPid },
|
||||
// Programs handed off to worker processes are not descendants of the session root, and
|
||||
// the clock shift applied at resume would move their monotonic time backwards.
|
||||
helperRoots = {
|
||||
components.mapNotNull { it.suspendPid().takeIf { pid -> pid > 1 } } +
|
||||
listOfNotNull(BottomDesktop.suspendPid.takeIf { it > 1 }) +
|
||||
(if (workers > 0) com.droiddeck.launcher.runtime.GuestWorkers.guestPids(workers) else emptyList())
|
||||
listOfNotNull(BottomDesktop.suspendPid.takeIf { it > 1 })
|
||||
},
|
||||
suspendAudio = {
|
||||
if (!pulse.setSinkSuspended(true)) Log.w(TAG, "could not suspend audio sink")
|
||||
@@ -1046,8 +1017,7 @@ class SessionService : Service() {
|
||||
return com.droiddeck.launcher.input.GesturePrefs.read(this, game).relativeMouseMode
|
||||
}
|
||||
|
||||
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean,
|
||||
agentEnvironment: List<String>, customEnvironment: List<String>) {
|
||||
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean, agentEnvironment: List<String>) {
|
||||
guest.add("/usr/bin/env")
|
||||
guest.add("-i")
|
||||
guest.add("DROIDDECK_BWRAP_SOCKET=" + com.droiddeck.launcher.runtime.BwrapSpawner.socket(this))
|
||||
@@ -1165,7 +1135,7 @@ class SessionService : Service() {
|
||||
guest.add("DD_ZRAM=1")
|
||||
}
|
||||
guest.add("AUDIO_DIRECT_DECAY=0")
|
||||
val extra = customEnvironment + agentEnvironment
|
||||
val extra = extraEnv() + agentEnvironment
|
||||
guest.addAll(TurnipEnvironment.gameEnvironment(tuOverride, tuDriver, SessionPrefs.tuSysmem(this), extra))
|
||||
if (extra.none { it.startsWith("MESA_NO_ERROR=") }) guest.add("${GAME_PREFIX}MESA_NO_ERROR=")
|
||||
extra.forEach { guest.add(it) }
|
||||
@@ -1313,7 +1283,6 @@ class SessionService : Service() {
|
||||
sessionRoot: File,
|
||||
runtimeDir: File,
|
||||
sharedStorage: File?,
|
||||
fastPath: Boolean,
|
||||
): ArrayList<String> {
|
||||
val binds = ArrayList<String>()
|
||||
if (controllersOn) binds.add(fakeInputDir.path + ":/dev/input")
|
||||
@@ -1357,17 +1326,10 @@ class SessionService : Service() {
|
||||
if (controllersOn) components.add(RumbleComponent().also { it.attach(this) })
|
||||
val home = File(LinuxRuntime.rootDir(this), "root")
|
||||
File(home, "Storage").mkdirs()
|
||||
val addedExeFolders = com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path }
|
||||
val addedGameRoots = com.droiddeck.launcher.frontend.AddedGames.roots(this)
|
||||
val addedFolders = (addedExeFolders + addedGameRoots.map { it.host }).distinctBy { it.path }
|
||||
for (folder in addedFolders) {
|
||||
if (com.droiddeck.launcher.files.AllFilesAccess.mayHideFilesIn(folder.path))
|
||||
Log.w(TAG, "added games: Android may hide .exe files in $folder because All files access is missing")
|
||||
}
|
||||
if (sharedStorage != null) {
|
||||
binds.add(sharedStorage.path + ":/root/Storage")
|
||||
} else {
|
||||
for (folder in addedExeFolders) {
|
||||
for (folder in com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path }) {
|
||||
val guest = com.droiddeck.launcher.frontend.AddedGames.guestPath(this, folder) ?: continue
|
||||
if (!guest.startsWith("/root/Storage/") || !folder.isDirectory) continue
|
||||
File(LinuxRuntime.rootDir(this), guest.removePrefix("/")).mkdirs()
|
||||
@@ -1418,7 +1380,7 @@ class SessionService : Service() {
|
||||
Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only")
|
||||
}
|
||||
}
|
||||
for (root in addedGameRoots) {
|
||||
for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) {
|
||||
if (root.host.isDirectory && root.host.canRead()) {
|
||||
File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs()
|
||||
binds.add(root.host.path + ":" + root.guest)
|
||||
@@ -1447,7 +1409,7 @@ class SessionService : Service() {
|
||||
if (storageDiagnosticLibrary != null && library != null) libraries.add(SecondaryLibrary.CARD_GUESTS[0] to library.label)
|
||||
val gamesLibraries = GameStorage.gamesFolderLibraries(this)
|
||||
if (gamesLibraries.isNotEmpty()) {
|
||||
var room = if (fastPath) {
|
||||
var room = if (ProotFastPath.enabled(this)) {
|
||||
ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size
|
||||
} else Int.MAX_VALUE
|
||||
for (games in gamesLibraries) {
|
||||
@@ -1489,7 +1451,7 @@ class SessionService : Service() {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
val room = if (fastPath) {
|
||||
val room = if (ProotFastPath.enabled(this)) {
|
||||
ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size
|
||||
} else Int.MAX_VALUE
|
||||
val content = SecondaryLibrary.contentPath(entry.host)
|
||||
@@ -1518,7 +1480,7 @@ class SessionService : Service() {
|
||||
if (problem != null) {
|
||||
Log.w(TAG, "x86-64 steam library: $problem")
|
||||
} else try {
|
||||
val room = if (fastPath) {
|
||||
val room = if (ProotFastPath.enabled(this)) {
|
||||
ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size
|
||||
} else Int.MAX_VALUE
|
||||
val extra = SecondaryLibrary.binds(filesDir, x64, listOf(GameStorage.X64_CARD_GUEST)).drop(1)
|
||||
@@ -1540,7 +1502,7 @@ class SessionService : Service() {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
val room = if (fastPath) {
|
||||
val room = if (ProotFastPath.enabled(this)) {
|
||||
ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size
|
||||
} else Int.MAX_VALUE
|
||||
val extra = SecondaryLibrary.binds(filesDir, entry.x64Host, listOf(entry.x64Guest)).drop(1)
|
||||
@@ -1576,7 +1538,7 @@ class SessionService : Service() {
|
||||
try {
|
||||
val listing = File(filesDir, "session/desktop-volumes.json").apply { parentFile?.mkdirs() }
|
||||
val volumes = org.json.JSONArray()
|
||||
var room = if (fastPath) {
|
||||
var room = if (ProotFastPath.enabled(this)) {
|
||||
ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size
|
||||
} else Int.MAX_VALUE
|
||||
for (root in com.droiddeck.launcher.files.StorageRoots.list(this)) {
|
||||
@@ -2793,9 +2755,6 @@ class SessionService : Service() {
|
||||
const val EXTRA_PROGRAM_ARGS = "programArgs"
|
||||
const val EXTRA_STEAM_UI = "steamUi"
|
||||
const val EXTRA_STEAM_URL = "steamUrl"
|
||||
// Set by the first-party Library play action on the private SessionActivity/Service path.
|
||||
// Never copied from an exported intent or Agent command.
|
||||
internal const val EXTRA_FRONTEND_STEAM_GAME = "com.droiddeck.launcher.FRONTEND_STEAM_GAME"
|
||||
const val EXTRA_GAME_ID = "gameId"
|
||||
|
||||
fun start(
|
||||
@@ -2803,7 +2762,6 @@ class SessionService : Service() {
|
||||
steamUi: String? = null, steamUrl: String? = null, programArgs: Array<String>? = null,
|
||||
gameId: String? = null,
|
||||
displayId: Int = Display.DEFAULT_DISPLAY,
|
||||
frontendSteamGame: Boolean = false,
|
||||
) {
|
||||
SteamClientPrefetch.cancel()
|
||||
SessionState.activityDisplayId = displayId
|
||||
@@ -2814,7 +2772,6 @@ class SessionService : Service() {
|
||||
if (programArgs != null) intent.putExtra(EXTRA_PROGRAM_ARGS, programArgs)
|
||||
if (steamUi != null) intent.putExtra(EXTRA_STEAM_UI, steamUi)
|
||||
if (steamUrl != null) intent.putExtra(EXTRA_STEAM_URL, steamUrl)
|
||||
if (frontendSteamGame) intent.putExtra(EXTRA_FRONTEND_STEAM_GAME, true)
|
||||
if (gameId != null) intent.putExtra(EXTRA_GAME_ID, gameId)
|
||||
if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent)
|
||||
else context.startService(intent)
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
internal object SessionVisibilityPolicy {
|
||||
fun shouldCloseSecondScreenOnStop(
|
||||
screenOff: Boolean,
|
||||
dockedDrawerOpen: Boolean,
|
||||
attachmentPickerOpen: Boolean,
|
||||
): Boolean = !screenOff && !(dockedDrawerOpen && attachmentPickerOpen)
|
||||
|
||||
fun isHidden(
|
||||
activityStarted: Boolean,
|
||||
defaultDisplayOn: Boolean,
|
||||
|
||||
@@ -12,15 +12,15 @@ object SettingsReset {
|
||||
private const val TAG = "SettingsReset"
|
||||
|
||||
internal val SESSION_KEYS = setOf(
|
||||
"orientation", "launcherFullscreen", "launcherFullscreenMode", "sessionFullscreenMode", "launcherFrost", "frostWallpaper", "frostCards", "frostTransparency", "frostCardTransparency", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt",
|
||||
"orientation", "launcherFullscreen", "launcherFrost", "frostWallpaper", "frostCards", "frostTransparency", "frostCardTransparency", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt",
|
||||
"drawerWidthDp", "dualScreenMode", "dualScreenSessionMode", "dualScreenLauncher", "dualScreenSessionControls", "androidTextFieldKeyboard",
|
||||
"soundtracksIngame", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "dockedMenuController", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController",
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "avoidNotch", "picturePosition", "picturePosition.portrait", "picturePosition.landscape", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "drawerPageOrder", "drawerPageHidden", "drawerSections", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"stretch16x9", "avoidNotch", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "drawerPageOrder", "drawerPageHidden", "drawerSections", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "producerAcquireFences", "paceCores",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
"noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "nativeUserland", "cursorComposite", "mountSharedStorage",
|
||||
"guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics", "buildWatermark",
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.gpu.GpuInfo
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import com.droiddeck.launcher.stores.xbox.XboxManifest
|
||||
|
||||
/**
|
||||
* Microsoft's original Xbox releases for PC run its emulator, which needs FEX and VKD3D-Proton builds with fixes of
|
||||
* their own (each off unless droiddeck-game-env turns it on for these games) and a newer DXVK than some Protons carry.
|
||||
* Each installed one gets them as its game components. A component the player chose for the game is never replaced;
|
||||
* one set here follows this list, so a newer build replaces it, and one the player cleared stays cleared.
|
||||
*/
|
||||
internal object XboxBackCompatComponents {
|
||||
private const val TAG = "XboxBackCompat"
|
||||
private const val PREFS = "xbox-backcompat-components"
|
||||
|
||||
internal data class Wanted(val comp: String, val file: String, val release: String)
|
||||
|
||||
internal fun wanted(family: GpuInfo.Family?): List<Wanted> = listOf(
|
||||
Wanted("fex", "FEXCore-2611.1-xbox-bionic.wcp", ComponentsManager.DD_XBOX),
|
||||
Wanted("vkd3d", "vkd3d-proton-arm64ec-3.1-xbox-linux.wcp", "Vkd3d-proton-Linux"),
|
||||
Wanted("dxvk", if (family == GpuInfo.Family.A6XX) "dxvk-gplasync-3.2-a6xx-1-linux.wcp" else "dxvk-gplasync-3.2-1-linux.wcp",
|
||||
"Dxvk-gplasync-Linux"),
|
||||
)
|
||||
|
||||
/** The file to set for one component of a game, or null to leave it as it is. */
|
||||
internal fun decide(current: String?, assigned: String?, wanted: String): String? = when {
|
||||
current == null && assigned == null -> wanted
|
||||
current != null && current == assigned && current != wanted -> wanted
|
||||
else -> null
|
||||
}
|
||||
|
||||
internal class Game(val scope: String, val title: String)
|
||||
|
||||
internal fun installed(context: Context): List<Game> = StoreInstallRoot.gameFolders(context).mapNotNull { folder ->
|
||||
val sidecar = StoreGameSidecar.read(folder)?.takeIf { it.store == Store.XBOX && it.isInstalled } ?: return@mapNotNull null
|
||||
if (!XboxManifest.backCompat(folder)) return@mapNotNull null
|
||||
val appId = SessionPrefs.storedAddedGameAppId(context, folder.path) ?: return@mapNotNull null
|
||||
Game(appId.toString(), sidecar.title)
|
||||
}
|
||||
|
||||
fun ensure(context: Context): String? {
|
||||
val games = installed(context)
|
||||
if (games.isEmpty()) return null
|
||||
val marks = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
val wanted = wanted(runCatching { GpuInfo.detect().family }.getOrNull())
|
||||
val lines = mutableListOf<String>()
|
||||
for (game in games) {
|
||||
val current = ComponentsManager.gameComponents(context, game.scope)
|
||||
for (w in wanted) {
|
||||
val key = "${game.scope}/${w.comp}"
|
||||
val file = decide(current[w.comp], marks.getString(key, null), w.file) ?: continue
|
||||
val label = ComponentsManager.LABEL[w.comp]
|
||||
runCatching {
|
||||
ComponentsManager.assignGameComponent(context, game.scope, w.comp, file, w.release, expected = current[w.comp]) {
|
||||
marks.edit().putString(key, file).apply()
|
||||
}
|
||||
}
|
||||
.onSuccess { result ->
|
||||
lines += when (result) {
|
||||
ComponentsManager.Assigned.SET -> "${game.title}: $label ${file.removeSuffix(".wcp")}"
|
||||
ComponentsManager.Assigned.NOT_LISTED -> "${game.title}: $file is not listed; $label unchanged"
|
||||
ComponentsManager.Assigned.CHANGED -> "${game.title}: $label was chosen during the download; kept"
|
||||
}
|
||||
}
|
||||
.onFailure { e ->
|
||||
Log.w(TAG, "${game.title}: $file", e)
|
||||
lines += "${game.title}: $label unchanged (${e.message ?: e.javaClass.simpleName})"
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines.joinToString("; ").ifEmpty { null }
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,9 @@ internal object WebCookies {
|
||||
}
|
||||
}
|
||||
|
||||
fun scopes(url: String, paths: List<String>): List<String> {
|
||||
val segments = runCatching { java.net.URI(url).path }.getOrNull().orEmpty().split('/').filter { it.isNotEmpty() }
|
||||
return (paths + segments.indices.map { i -> "/" + segments.take(i + 1).joinToString("/") }).distinct()
|
||||
}
|
||||
|
||||
fun expire(urls: List<String>, domain: String, paths: List<String>, done: (Int) -> Unit) {
|
||||
val cookies = CookieManager.getInstance()
|
||||
val lines = urls.flatMap { url -> expired(cookies.getCookie(url), domain, scopes(url, paths), Uri.parse(url).host).map { url to it } }
|
||||
val lines = urls.flatMap { url -> expired(cookies.getCookie(url), domain, paths, Uri.parse(url).host).map { url to it } }
|
||||
if (lines.isEmpty()) {
|
||||
done(0)
|
||||
return
|
||||
|
||||
@@ -44,7 +44,7 @@ object EaBackend : StoreBackend {
|
||||
signOuts.incrementAndGet()
|
||||
StoresState.post { StoresState.shelves.remove(store) }
|
||||
EaUpdates.available.clear()
|
||||
EaLogin.forget {}
|
||||
runCatching { WebCookies.expire(EaLogin.SIGN_IN_URLS, ".ea.com", listOf("/")) {} }
|
||||
}
|
||||
|
||||
override fun syncLibrary(context: Context, force: Boolean) {
|
||||
@@ -100,7 +100,9 @@ internal class EaLogin(private val pending: EaAuth.Pending, override val userAge
|
||||
|
||||
override fun isRedirect(url: String): Boolean = url.startsWith("qrc:", ignoreCase = true)
|
||||
|
||||
override fun forgetSignIn(done: () -> Unit) = forget(done)
|
||||
override fun forgetSignIn(done: () -> Unit) {
|
||||
runCatching { WebCookies.expire(SIGN_IN_URLS, ".ea.com", listOf("/")) { done() } }.onFailure { done() }
|
||||
}
|
||||
|
||||
override fun finish(activity: StoreLoginActivity, view: WebView, url: String): String? {
|
||||
val code = EaAuth.redirectValue(url, "code") ?: return activity.getString(R.string.stores_login_error_verification)
|
||||
@@ -114,11 +116,7 @@ internal class EaLogin(private val pending: EaAuth.Pending, override val userAge
|
||||
}
|
||||
|
||||
companion object {
|
||||
val SIGN_IN_URLS = listOf(EaAuth.AUTH_URL, "https://signin.ea.com/p/juno/login", "https://www.ea.com")
|
||||
|
||||
fun forget(done: () -> Unit) {
|
||||
runCatching { WebCookies.expire(SIGN_IN_URLS, ".ea.com", listOf("/")) { done() } }.onFailure { done() }
|
||||
}
|
||||
val SIGN_IN_URLS = listOf("https://accounts.ea.com", "https://signin.ea.com", "https://www.ea.com")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.core.AddonPack
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.SessionEvents
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.AchievementNotifications
|
||||
@@ -148,6 +149,7 @@ object GogComet {
|
||||
remove("LD_PRELOAD"); remove("LD_AUDIT"); remove("LD_LIBRARY_PATH")
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(context).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(context).path)
|
||||
if (SessionPrefs.prootNoSeccomp(context)) put("PROOT_NO_SECCOMP", "1")
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@ import org.json.JSONObject
|
||||
import java.time.Instant
|
||||
|
||||
internal object XboxCatalog {
|
||||
/** Package identity prefix of Microsoft's original Xbox releases for PC. */
|
||||
internal const val BACK_COMPAT_IDENTITY = "Xbox360BackwardCompatibil"
|
||||
|
||||
private val productId = Regex("[A-Z0-9]{12}")
|
||||
private val plans = setOf("CFQ7TTC0KGQ8", "CFQ7TTC0KHS0", "CFQ7TTC0P85B", "CFQ7TTC0K5DJ", "CFQ7TTC0K6L8", "CFQ7TTC10QFD")
|
||||
private val pcPlans = mapOf(
|
||||
@@ -151,13 +148,6 @@ internal object XboxCatalog {
|
||||
.flatMap { objects(it.optJSONArray("Packages")) }
|
||||
val pc = packages.filter { pkg -> objects(pkg.optJSONArray("PlatformDependencies")).any { it.optString("PlatformName") == "Windows.Desktop" } }
|
||||
val installable = pc.any { installableFormat(it.optString("PackageFormat")) }
|
||||
// An original Xbox game: its PC package is only Microsoft's emulator and an
|
||||
// index; the game data comes from the console package, so that is its size.
|
||||
val backCompat = pc.any { it.optString("PackageFamilyName").startsWith(BACK_COMPAT_IDENTITY, ignoreCase = true) }
|
||||
val console = packages.filter { pkg ->
|
||||
pkg.optString("PackageFormat").equals("XVC", true) ||
|
||||
objects(pkg.optJSONArray("PlatformDependencies")).any { it.optString("PlatformName") == "Windows.Xbox" }
|
||||
}
|
||||
// The installer needs the format, not just the fact that one exists: a
|
||||
// legacy container takes a different subcommand from a streamed package.
|
||||
val format = pc.firstOrNull { installableFormat(it.optString("PackageFormat")) }?.optString("PackageFormat").orEmpty()
|
||||
@@ -182,8 +172,7 @@ internal object XboxCatalog {
|
||||
storeUrl = "https://www.xbox.com/games/store/$id",
|
||||
publisher = localized.optString("PublisherName"), developer = localized.optString("DeveloperName"),
|
||||
description = localized.optString("ProductDescription"),
|
||||
sizeBytes = if (!installable) 0L else (if (backCompat) console.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } else null)
|
||||
?.takeIf { it > 0 } ?: pc.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } ?: 0L,
|
||||
sizeBytes = if (installable) pc.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } ?: 0L else 0L,
|
||||
extra = mapOf("market" to Xodus.market(), "access" to kind.orEmpty(), "pc" to flag(installable),
|
||||
"cloud" to flag(streams), "format" to format),
|
||||
)
|
||||
|
||||
@@ -106,7 +106,7 @@ private fun PanelContent(
|
||||
onChange(settings.copy(frameGen = it))
|
||||
}
|
||||
Text("Native engine (experimental): Google's WebRTC and DroidDeck's own compositor, so DroidDeck frame generation " +
|
||||
"(DDFG) or LSFG can add frames. LSFG requires Lossless Scaling installed through Steam. Screen effects " +
|
||||
"(DDFG) or LSFG can add frames. LSFG uses the Lossless.dll DroidDeck already uses for games. Screen effects " +
|
||||
"apply to the web engine.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(start = 8.dp, bottom = 6.dp))
|
||||
}
|
||||
|
||||
@@ -80,10 +80,6 @@ internal object XboxManifest {
|
||||
dependencies.singleOrNull().orEmpty(), ids, entries, entry.singleOrNull().orEmpty(), behavior.singleOrNull().orEmpty())
|
||||
}
|
||||
|
||||
/** Microsoft's original Xbox releases for PC, which run its emulator. */
|
||||
fun backCompat(folder: File): Boolean =
|
||||
runCatching { read(folder).name.startsWith(XboxCatalog.BACK_COMPAT_IDENTITY, ignoreCase = true) }.getOrDefault(false)
|
||||
|
||||
/**
|
||||
* A full trust package starts its executable directly. Anything else is activated
|
||||
* through the Windows app model, which this runtime has no host for, so starting
|
||||
|
||||
@@ -623,11 +623,11 @@ class XboxNativePlayerActivity : ComponentActivity() {
|
||||
XboxMenuEntry((if (current.frameGen == mode) "✓ " else "") + fgName(mode), when (mode) {
|
||||
XboxNativeVideo.FG_DDFG -> "DroidDeck's own frame generation (DDFG); doubles the shown frame rate"
|
||||
XboxNativeVideo.FG_LSFG, XboxNativeVideo.FG_LSFG3, XboxNativeVideo.FG_LSFG4 ->
|
||||
"Lossless Scaling frame generation from the Steam installation; the frame-rate target caps the output"
|
||||
"Lossless Scaling frame generation (the Lossless.dll DroidDeck uses for games); the frame-rate target caps the output"
|
||||
else -> "Show the stream's own frames only"
|
||||
}, choices[i]) { current = current.copy(frameGen = mode); setFrameGen(mode) }
|
||||
}
|
||||
if (!lsfg) androidx.compose.material3.Text("LSFG appears here once Lossless Scaling is installed through Steam.",
|
||||
if (!lsfg) androidx.compose.material3.Text("LSFG appears here once DroidDeck has the Lossless.dll (frame generation settings).",
|
||||
style = androidx.compose.material3.MaterialTheme.typography.bodySmall, color = cs.onSurfaceVariant,
|
||||
modifier = androidx.compose.ui.Modifier.padding(horizontal = 16.dp, vertical = 8.dp))
|
||||
if (current.zeroCopy) androidx.compose.material3.Text(
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.droiddeck.launcher.core.AddonPack
|
||||
import com.droiddeck.launcher.runtime.LinuxNetworkLinkComponent
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.runtime.ProotFastPath
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import org.json.JSONObject
|
||||
import java.io.Closeable
|
||||
@@ -106,6 +107,7 @@ internal object Xodus {
|
||||
remove("LD_PRELOAD"); remove("LD_AUDIT"); remove("LD_LIBRARY_PATH")
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(app).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(app).path)
|
||||
if (SessionPrefs.prootNoSeccomp(app)) put("PROOT_NO_SECCOMP", "1")
|
||||
fastPathKey?.let { ProotFastPath.hostEnv(it).let { (key, value) -> put(key, value) } }
|
||||
LinuxRuntime.prootLibraryPath(app).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ internal fun AgentEntry(
|
||||
is Entry.Said -> {
|
||||
val reply = remember(entry.text) { choices(entry.text) }
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (reply.text.isNotBlank()) SelectionContainer { AgentReply(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) }
|
||||
if (reply.text.isNotBlank()) SelectionContainer { AgentMarkdown(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) }
|
||||
if (reply.options.isNotEmpty()) AgentChoices(reply.options, answerable, onSent)
|
||||
}
|
||||
}
|
||||
@@ -377,11 +377,10 @@ private fun CodeBox(label: String, text: String, color: Color) {
|
||||
internal fun AttachmentChip(path: String, onRemove: (() -> Unit)?) {
|
||||
val context = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
var viewing by remember(path) { mutableStateOf(false) }
|
||||
Box {
|
||||
if (AgentAttachments.isImage(path)) AsyncImage(
|
||||
model = AgentAttachments.host(context, path), contentDescription = path.substringAfterLast('/'), contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(72.dp).clip(Shape12).background(pal.surfaceVariant).clickable { viewing = true },
|
||||
modifier = Modifier.size(72.dp).clip(Shape12).background(pal.surfaceVariant),
|
||||
) else Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.heightIn(min = 40.dp).clip(Shape12).background(pal.surfaceVariant).padding(horizontal = 10.dp, vertical = 8.dp),
|
||||
@@ -397,5 +396,4 @@ internal fun AttachmentChip(path: String, onRemove: (() -> Unit)?) {
|
||||
Icon(Icons.Outlined.Close, stringResource(R.string.agent_remove_attachment), tint = pal.onSurfaceVariant, modifier = Modifier.size(14.dp))
|
||||
}
|
||||
}
|
||||
if (viewing) PictureViewer(AgentAttachments.host(context, path), path.substringAfterLast('/')) { viewing = false }
|
||||
}
|
||||
@@ -37,106 +37,6 @@ import org.commonmark.ext.gfm.tables.TableRow
|
||||
import org.commonmark.node.AbstractVisitor
|
||||
import org.commonmark.node.CustomNode
|
||||
import org.commonmark.node.Node
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
|
||||
/** Part of an agent's reply: Markdown text, or an image the agent named on a line of its own. */
|
||||
internal sealed interface ReplyPart {
|
||||
data class Prose(val text: String) : ReplyPart
|
||||
data class Picture(val alt: String, val path: String) : ReplyPart
|
||||
}
|
||||
|
||||
private val PICTURE_LINE = Regex("""^\s*!\[([^\]]*)]\(\s*(?:<(?:file://)?(/[^>]*)>|(?:file://)?(/[^)<>]*?))\s*\)\s*$""")
|
||||
private val FENCE = Regex("""^ {0,3}(`{3,}|~{3,})(.*)$""")
|
||||
|
||||
/** Splits [text] at lines that hold only an image of a local absolute path, outside code fences. */
|
||||
internal fun replyParts(text: String): List<ReplyPart> {
|
||||
val parts = mutableListOf<ReplyPart>()
|
||||
val prose = StringBuilder()
|
||||
fun flush() {
|
||||
if (prose.isNotBlank()) parts += ReplyPart.Prose(prose.toString().trimEnd('\n'))
|
||||
prose.clear()
|
||||
}
|
||||
var fence: String? = null
|
||||
for (line in text.lines()) {
|
||||
val marker = FENCE.matchEntire(line)
|
||||
val picture = if (fence == null) PICTURE_LINE.matchEntire(line) else null
|
||||
val open = fence
|
||||
when {
|
||||
picture != null -> {
|
||||
flush()
|
||||
val path = picture.groupValues[2].ifEmpty { picture.groupValues[3] }
|
||||
parts += ReplyPart.Picture(picture.groupValues[1].trim(), path.trim())
|
||||
continue
|
||||
}
|
||||
marker == null -> Unit
|
||||
open == null -> fence = marker.groupValues[1]
|
||||
marker.groupValues[1].let { it[0] == open[0] && it.length >= open.length } && marker.groupValues[2].isBlank() -> fence = null
|
||||
}
|
||||
prose.append(line).append('\n')
|
||||
}
|
||||
flush()
|
||||
return parts
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the app reads a file the agent named by its guest path: the app's own folders and shared
|
||||
* storage are bound at the same paths in the guest, everything else lives in the rootfs.
|
||||
*/
|
||||
internal fun agentHostFile(context: Context, guestPath: String): File {
|
||||
val app = context.applicationContext
|
||||
val same = listOfNotNull(app.filesDir.path, app.cacheDir.path, LinuxRuntime.sharedStorage(app)?.path)
|
||||
return if (same.any { guestPath == it || guestPath.startsWith("$it/") }) File(guestPath)
|
||||
else File(LinuxRuntime.rootDir(app), guestPath.removePrefix("/"))
|
||||
}
|
||||
|
||||
/** An agent's reply, with the images it names shown in place. */
|
||||
@Composable
|
||||
internal fun AgentReply(text: String, modifier: Modifier) {
|
||||
val parts = remember(text) { replyParts(text) }
|
||||
if (parts.size == 1 && parts[0] is ReplyPart.Prose) {
|
||||
AgentMarkdown(text, modifier)
|
||||
return
|
||||
}
|
||||
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
parts.forEach { part ->
|
||||
when (part) {
|
||||
is ReplyPart.Prose -> AgentMarkdown(part.text, Modifier)
|
||||
is ReplyPart.Picture -> AgentPicture(part)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AgentPicture(picture: ReplyPart.Picture) {
|
||||
val context = LocalContext.current
|
||||
val file = remember(picture.path) { agentHostFile(context, picture.path) }
|
||||
var viewing by remember(picture.path) { mutableStateOf(false) }
|
||||
if (!file.isFile) {
|
||||
Text(stringResource(R.string.agent_image_missing, picture.alt.ifBlank { picture.path }), color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
return
|
||||
}
|
||||
AsyncImage(
|
||||
model = file, contentDescription = picture.alt.ifBlank { file.name }, contentScale = ContentScale.Fit,
|
||||
modifier = Modifier.widthIn(max = 560.dp).heightIn(max = 420.dp).clip(Shape12).clickable { viewing = true },
|
||||
)
|
||||
if (viewing) PictureViewer(file, picture.alt.ifBlank { file.name }) { viewing = false }
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AgentMarkdown(text: String, modifier: Modifier) {
|
||||
|
||||
@@ -5,9 +5,7 @@ import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import android.view.KeyEvent
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.LocalActivityResultRegistryOwner
|
||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.expandVertically
|
||||
@@ -52,12 +50,12 @@ import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.Send
|
||||
import androidx.compose.material.icons.outlined.Extension
|
||||
import androidx.compose.material.icons.outlined.PhotoCamera
|
||||
import androidx.compose.material.icons.outlined.MicOff
|
||||
import androidx.compose.material.icons.outlined.Mic
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.ArrowDownward
|
||||
import androidx.compose.material.icons.outlined.AttachFile
|
||||
import androidx.compose.material.icons.outlined.Keyboard
|
||||
import androidx.compose.material.icons.outlined.Terminal
|
||||
import androidx.compose.material.icons.outlined.Build
|
||||
import androidx.compose.material.icons.outlined.Close
|
||||
@@ -81,7 +79,6 @@ import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
@@ -111,7 +108,6 @@ import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.platform.testTag
|
||||
@@ -305,7 +301,7 @@ private fun AgentPageContent(
|
||||
readingBack = false
|
||||
scope.launch { list.scrollToItem(maxOf(0, list.layoutInfo.totalItemsCount - 1), Int.MAX_VALUE / 2) }
|
||||
}
|
||||
val hidden = !composer.focused && !composer.tray && !composer.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() &&
|
||||
val hidden = !composer.focused && !composer.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() &&
|
||||
AgentHost.approvals.isEmpty()
|
||||
var listHeight by remember { mutableIntStateOf(0) }
|
||||
Box(
|
||||
@@ -323,7 +319,6 @@ private fun AgentPageContent(
|
||||
awaitEachGesture {
|
||||
awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial)
|
||||
if (panel == AgentPanel.MODEL || panel == AgentPanel.USAGE) panel = AgentPanel.NONE
|
||||
composer.tray = false
|
||||
// Forced: the unforced path walks the focus chain and throws ("ActiveParent with no focused child") when a tap lands while focus is moving.
|
||||
if (composer.focused) focusManager.clearFocus(force = true)
|
||||
}
|
||||
@@ -349,12 +344,6 @@ private fun AgentPageContent(
|
||||
@Stable
|
||||
private class ComposerState {
|
||||
var focused by mutableStateOf(false)
|
||||
/** The photo tray stands in for the keyboard, at the height the keyboard last had. */
|
||||
var tray by mutableStateOf(false)
|
||||
var keyboardHeight by mutableStateOf(0.dp)
|
||||
/** Tray photos copied, or being copied, for this conversation, so reopening the tray keeps their marks and copies nothing twice. */
|
||||
val photoCopies = mutableStateMapOf<android.net.Uri, String>()
|
||||
val photosCopying = mutableStateMapOf<android.net.Uri, Any>()
|
||||
var focusRequests by mutableIntStateOf(0)
|
||||
private set
|
||||
private var consumedFocusRequests by mutableIntStateOf(0)
|
||||
@@ -401,7 +390,7 @@ private fun ModelChip(panel: AgentPanel, onPanel: (AgentPanel) -> Unit, firstCon
|
||||
.clickable { onPanel(AgentPanel.MODEL) }.padding(horizontal = 8.dp).testTag("agent-model"),
|
||||
) {
|
||||
val mode = AgentHost.harness.permissions.drop(1).firstOrNull { it.id == AgentHost.permission }?.let { stringResource(it.label) }
|
||||
val parts = if (compact) listOf(model)
|
||||
val parts = if (compact) listOfNotNull(mode ?: model)
|
||||
else listOfNotNull(
|
||||
AgentHost.harness.name, model, AgentHost.effort, mode,
|
||||
stringResource(R.string.agent_plan_short).takeIf { AgentHost.plan && AgentHost.harness.plans },
|
||||
@@ -543,7 +532,7 @@ private fun AgentLive() {
|
||||
val pal = LocalPalette.current
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (AgentHost.liveThinking.isNotBlank()) AgentThought(AgentHost.liveThinking, live = true)
|
||||
if (AgentHost.live.isNotBlank()) AgentReply(AgentHost.live, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp))
|
||||
if (AgentHost.live.isNotBlank()) AgentMarkdown(AgentHost.live, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp))
|
||||
val running = AgentHost.running()
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(4.dp)) {
|
||||
CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp, color = pal.primary)
|
||||
@@ -759,8 +748,6 @@ private fun AgentComposer(
|
||||
if (text.isEmpty() && AgentAttachments.pending.isEmpty()) return@send
|
||||
AgentHost.send(context, text, AgentAttachments.pending.toList())
|
||||
AgentAttachments.pending.clear()
|
||||
composer.photosCopying.clear()
|
||||
composer.tray = false
|
||||
onSent()
|
||||
}
|
||||
}
|
||||
@@ -826,34 +813,7 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState<String
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val field = remember { FocusRequester() }
|
||||
LaunchedEffect(composer.focusRequests) { if (composer.hasUnconsumedFocusRequest()) runCatching { field.requestFocus() } }
|
||||
val picks = LocalActivityResultRegistryOwner.current != null
|
||||
val density = LocalDensity.current
|
||||
val imeHeight = WindowInsets.ime.getBottom(density)
|
||||
LaunchedEffect(imeHeight) {
|
||||
val height = with(density) { imeHeight.toDp() }
|
||||
if (height > composer.keyboardHeight) composer.keyboardHeight = height
|
||||
}
|
||||
LaunchedEffect(hideAttach) { if (hideAttach) composer.tray = false }
|
||||
LaunchedEffect(AgentHost.chat) {
|
||||
composer.photoCopies.clear()
|
||||
composer.photosCopying.clear()
|
||||
}
|
||||
// BackHandler throws where the host provides no back dispatcher: the front end and the floating pet.
|
||||
if (LocalOnBackPressedDispatcherOwner.current != null) BackHandler(composer.tray) { composer.tray = false }
|
||||
val focusManager = LocalFocusManager.current
|
||||
val files = if (picks) rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) {
|
||||
AgentAttachments.picking = false
|
||||
attachUris(context, it)
|
||||
} else null
|
||||
val toggleTray = {
|
||||
if (composer.tray) {
|
||||
composer.tray = false
|
||||
composer.open()
|
||||
} else {
|
||||
focusManager.clearFocus(force = true)
|
||||
composer.tray = true
|
||||
}
|
||||
}
|
||||
val attach = LocalActivityResultRegistryOwner.current != null
|
||||
BoxWithConstraints(
|
||||
Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape16).background(colors.surface)
|
||||
.border(if (focused) 2.dp else 1.dp, if (focused) pal.primary else pal.line, Shape16).padding(6.dp),
|
||||
@@ -881,7 +841,6 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState<String
|
||||
Modifier.fillMaxWidth().focusRequester(field).onFocusChanged {
|
||||
focused = it.isFocused
|
||||
composer.focused = it.isFocused
|
||||
if (it.isFocused) composer.tray = false
|
||||
if (it.isFocused) composer.consumeFocusRequest()
|
||||
}.testTag("agent-input"),
|
||||
textStyle = TextStyle(fontSize = 16.sp, color = colors.onSurface),
|
||||
@@ -907,22 +866,19 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState<String
|
||||
if (stacked) Column {
|
||||
text(Modifier.fillMaxWidth())
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
||||
AnimatedVisibility(!hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { AttachButton(composer.tray, toggleTray) }
|
||||
AnimatedVisibility(attach && !hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { AttachButton() }
|
||||
AnimatedVisibility(AgentAttachments.gameFrame != null && !hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { GameFrameButton() }
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.weight(1f).height(42.dp).horizontalScroll(rememberScrollState(), reverseScrolling = true)) { if (controls != null && !focused) controls() }
|
||||
actions()
|
||||
}
|
||||
} else Row(verticalAlignment = Alignment.Bottom) {
|
||||
AnimatedVisibility(!hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { AttachButton(composer.tray, toggleTray) }
|
||||
AnimatedVisibility(attach && !hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { AttachButton() }
|
||||
AnimatedVisibility(AgentAttachments.gameFrame != null && !hideAttach, enter = expandHorizontally() + fadeIn(), exit = shrinkHorizontally() + fadeOut()) { GameFrameButton() }
|
||||
text(Modifier.weight(1f))
|
||||
if (controls != null && !focused) Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.height(42.dp)) { controls() }
|
||||
actions()
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(composer.tray, enter = expandVertically() + fadeIn(), exit = shrinkVertically() + fadeOut()) {
|
||||
val most = LocalConfiguration.current.screenHeightDp.dp * 0.45f
|
||||
val height = (if (composer.keyboardHeight > 0.dp) composer.keyboardHeight else 280.dp).coerceAtLeast(160.dp).coerceAtMost(most)
|
||||
AgentPhotoTray(height, composer.photoCopies, composer.photosCopying, files?.let { { AgentAttachments.pick { it.launch(arrayOf("*/*")) } } })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1018,15 +974,51 @@ private fun VoiceButton(voice: AgentVoice, onStart: () -> Unit, onSend: () -> Un
|
||||
}
|
||||
}
|
||||
|
||||
/** Opens the photo tray in place of the keyboard; while it is open, brings the keyboard back. */
|
||||
/** Attaches what the running game shows, taken from its own surface so nothing drawn over it is in the picture. */
|
||||
@Composable
|
||||
private fun AttachButton(trayOpen: Boolean, onClick: () -> Unit) {
|
||||
private fun GameFrameButton() {
|
||||
val context = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
RoundButton(
|
||||
if (trayOpen) Icons.Outlined.Keyboard else Icons.Outlined.AttachFile,
|
||||
stringResource(if (trayOpen) R.string.agent_keyboard else R.string.agent_attach),
|
||||
if (trayOpen) pal.primary else pal.surfaceVariant, if (trayOpen) pal.onPrimary else pal.onBackground, "agent-attach", onClick = onClick,
|
||||
)
|
||||
RoundButton(Icons.Outlined.PhotoCamera, stringResource(R.string.agent_attach_game), pal.surfaceVariant, pal.onBackground, "agent-game-frame") {
|
||||
val grab = AgentAttachments.gameFrame ?: return@RoundButton
|
||||
val chat = AgentHost.chat
|
||||
grab frame@{ frame ->
|
||||
if (frame == null) {
|
||||
android.widget.Toast.makeText(context, R.string.agent_attach_game_failed, android.widget.Toast.LENGTH_SHORT).show()
|
||||
return@frame
|
||||
}
|
||||
Thread({
|
||||
val path = AgentAttachments.saveFrame(context, chat, frame)
|
||||
frame.recycle()
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||
when {
|
||||
path == null -> android.widget.Toast.makeText(context, R.string.agent_attach_game_failed, android.widget.Toast.LENGTH_SHORT).show()
|
||||
AgentHost.chat == chat -> AgentAttachments.pending.add(path)
|
||||
else -> AgentAttachments.discard(context, listOf(path))
|
||||
}
|
||||
}
|
||||
}, "agent-game-frame").start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AttachButton() {
|
||||
val context = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
val picker = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
|
||||
if (uris.isEmpty()) return@rememberLauncherForActivityResult
|
||||
val chat = AgentHost.chat
|
||||
Thread({
|
||||
val paths = AgentAttachments.copy(context, chat, uris)
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||
if (AgentHost.chat == chat) AgentAttachments.pending.addAll(paths) else AgentAttachments.discard(context, paths)
|
||||
}
|
||||
}, "agent-attach").start()
|
||||
}
|
||||
RoundButton(Icons.Outlined.AttachFile, stringResource(R.string.agent_attach), pal.surfaceVariant, pal.onBackground, "agent-attach") {
|
||||
runCatching { picker.launch(arrayOf("*/*")) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -67,18 +67,13 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
private fun agentPanelFrame(): Modifier =
|
||||
Modifier.fillMaxWidth().clip(Shape14).background(MaterialTheme.colorScheme.surface)
|
||||
.border(1.dp, LocalPalette.current.line, Shape14).padding(horizontal = 14.dp, vertical = 10.dp)
|
||||
|
||||
/** The model, reasoning effort, permissions and plan mode for the next turns; a conversation keeps going with whatever is chosen. */
|
||||
@Composable
|
||||
internal fun AgentModelPicker() {
|
||||
val context = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
val models = remember(AgentHost.harness) { AgentHost.models(context) }
|
||||
Column(agentPanelFrame(), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Column(Modifier.fillMaxWidth().padding(bottom = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.horizontalScroll(rememberScrollState())) {
|
||||
val choices = listOf(AgentHarness.Model("", stringResource(R.string.agent_model_default))) + models
|
||||
for (choice in choices) {
|
||||
@@ -274,8 +269,12 @@ internal fun AgentProcessList(modifier: Modifier) {
|
||||
@Composable
|
||||
internal fun AgentUsage() {
|
||||
val context = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
Column(agentPanelFrame(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(Shape14).background(colors.surface).border(1.dp, pal.line, Shape14).padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
if (AgentHost.window > 0) UsageRow(
|
||||
stringResource(R.string.agent_usage_context),
|
||||
stringResource(R.string.agent_usage_of, tokens(AgentHost.context), tokens(AgentHost.window)),
|
||||
|
||||
Loaded 100 of 351 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user