diff --git a/.github/workflows/authorship.yml b/.github/workflows/authorship.yml index 615267b6c0..857fb68023 100644 --- a/.github/workflows/authorship.yml +++ b/.github/workflows/authorship.yml @@ -7,7 +7,7 @@ on: push: branches: [main] workflow_run: - workflows: [Build APK] + workflows: [Build APK, Unit tests] types: [completed] workflow_dispatch: inputs: @@ -21,6 +21,12 @@ permissions: pull-requests: read statuses: write +# Build APK and Unit tests each trigger a validation, and the last one to post sets the status. Queued runs for a +# commit wait, so the newest one reads both results and posts last. +concurrency: + group: build-validation-${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha || inputs.pr_number || github.sha }} + cancel-in-progress: false + jobs: validate: name: Validate source and build result diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b32d1b442..41845e8506 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ name: Build APK -run-name: ${{ github.event_name == 'pull_request' && format('building pr {0} on {1}', github.event.pull_request.number, github.event.pull_request.head.sha) || format('building {0} on {1}', github.ref_name, github.sha) }} +run-name: ${{ github.event_name == 'pull_request' && format('building pr {0} on {1} against {2}', github.event.pull_request.number, github.event.pull_request.head.sha, github.event.pull_request.base.sha) || format('building {0} on {1}', github.ref_name, github.sha) }} on: push: @@ -57,15 +57,18 @@ jobs: - name: Pin and merge the APK source id: merge if: github.event_name == 'pull_request' + env: + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | set -euo pipefail - git fetch --no-tags origin main - echo "base-sha=$(git rev-parse origin/main)" >> "$GITHUB_OUTPUT" + # Unit tests uses the same event snapshot, including when either workflow is rerun. + git fetch --no-tags origin "$PR_BASE_SHA" + echo "base-sha=$PR_BASE_SHA" >> "$GITHUB_OUTPUT" git config user.name "ci" git config user.email "ci@users.noreply.github.com" # Partial clone: a merged blob that only exists in a fork's history can't be lazily fetched (GitHub: "not our ref"); merge-tree writes it locally first. - git merge-tree --write-tree HEAD origin/main >/dev/null || true - git merge --no-ff --no-edit origin/main + git merge-tree --write-tree HEAD FETCH_HEAD >/dev/null || true + git merge --no-ff --no-edit FETCH_HEAD - name: Resolve trusted manifest base id: trusted if: github.event_name != 'pull_request' @@ -304,6 +307,9 @@ 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 @@ -349,7 +355,7 @@ jobs: build: needs: [source, components, xbox, build-runner] - name: Compile APK and Android tests + name: Compile APK if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} runs-on: ${{ fromJSON(needs.build-runner.outputs.labels) }} timeout-minutes: 45 @@ -507,23 +513,7 @@ jobs: PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} BUILD_REF: ${{ github.ref_name }} BUILD_SHA: ${{ github.sha }} - run: | - if [[ -n "$(git status --porcelain)" ]]; then - tree_state=dirty - else - tree_state=clean - fi - echo "DROIDDECK_BUILD_TREE_STATE=$tree_state" >> "$GITHUB_ENV" - if [[ -n "$PR_NUMBER" ]]; then - label="pr${PR_NUMBER} at ${PR_HEAD_SHA:0:7}" - else - label="${BUILD_REF} at ${BUILD_SHA:0:7}" - fi - echo "label=$label" >> "$GITHUB_OUTPUT" - echo "DROIDDECK_SOURCE_COMMIT=${PR_HEAD_SHA:-$BUILD_SHA}" >> "$GITHUB_ENV" - echo "DROIDDECK_PR_NUMBER=${PR_NUMBER:-0}" >> "$GITHUB_ENV" - echo "DROIDDECK_PR_TITLE=${PR_TITLE//$'\n'/ }" >> "$GITHUB_ENV" - echo "Build: \`$label\`" >> "$GITHUB_STEP_SUMMARY" + run: bash tools/ci/build-label.sh - name: Rust toolchain for the store engines (aarch64-linux-android) id: rust @@ -734,89 +724,6 @@ jobs: if-no-files-found: ignore overwrite: true - - name: Resolve the Robolectric version - id: robolectric - run: | - echo "version=$(grep -o "org.robolectric:robolectric:[0-9.]*" app/build.gradle | cut -d: -f3)" >> "$GITHUB_OUTPUT" - # Robolectric downloads these from Maven Central on first use without retrying, and 429s fail whole test classes. - # The cache path sits beside the workspace because runner homes are at different depths from it, and - # actions/cache stores paths relative to the workspace. Runners that keep their own ~/.m2 skip the cache. - - name: Place Robolectric's Android jars beside the workspace - id: robolectric-jars - run: | - set -euo pipefail - jars="$GITHUB_WORKSPACE/../robolectric-jars" - m2="$HOME/.m2/repository/org/robolectric/android-all-instrumented" - if [ -d "$m2" ] && [ ! -L "$m2" ]; then - echo "cache=false" >> "$GITHUB_OUTPUT" - else - mkdir -p "$jars" "$(dirname "$m2")" - ln -sfn "$(cd "$jars" && pwd)" "$m2" - echo "cache=true" >> "$GITHUB_OUTPUT" - fi - - name: Restore Robolectric's Android jars - id: robolectric-cache - if: steps.robolectric-jars.outputs.cache == 'true' - uses: actions/cache/restore@v4 - with: - path: ../robolectric-jars - key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} - restore-keys: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}- - - name: Count the restored Robolectric jars - if: steps.robolectric-jars.outputs.cache == 'true' - run: echo "ROBOLECTRIC_JARS_BEFORE=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l)" >> "$GITHUB_ENV" - - name: Unit tests - id: unit-tests - env: - DROIDDECK_BUILD_LABEL: ${{ steps.build-label.outputs.label }} - SGDB_API_KEY: ${{ secrets.SGDB_API_KEY }} - run: | - set -o pipefail - mkdir -p app/build - ./gradlew testReleaseUnitTest --console=plain --info --stacktrace -Drobolectric.logging=stderr -PndkVersion="$NDK_VERSION" 2>&1 | tee app/build/unit-tests.log - - # actions/cache only saves when the job succeeds, so a run whose tests died on a Maven 429 never filled the cache. - # Save the complete jars even after a failed test step, when this run added some; a partial download is dropped first. - - name: Save Robolectric's Android jars - id: robolectric-jars-final - if: always() && steps.robolectric-jars.outputs.cache == 'true' - run: | - python3 - <<'PY' - import glob, os, zipfile - root = os.path.join(os.environ['GITHUB_WORKSPACE'], '..', 'robolectric-jars') - for f in glob.glob(os.path.join(root, '**', '*'), recursive=True): - if not os.path.isfile(f): - continue - try: - ok = f.endswith('.jar') and zipfile.ZipFile(f).testzip() is None - except Exception: - ok = False - if not ok: - os.remove(f) - PY - after=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l) - [ "$after" -gt "${ROBOLECTRIC_JARS_BEFORE:-0}" ] && echo "save=true" >> "$GITHUB_OUTPUT" || true - - name: Store Robolectric's Android jars - if: always() && steps.robolectric-jars-final.outputs.save == 'true' - uses: actions/cache/save@v4 - with: - path: ../robolectric-jars - key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} - - - name: Upload unit test diagnostics - id: unit-test-diagnostics - if: always() && steps.unit-tests.outcome != 'skipped' - uses: actions/upload-artifact@v4 - with: - name: unit-test-results - path: | - app/build/unit-tests.log - app/build/test-results/testReleaseUnitTest/ - app/build/reports/tests/testReleaseUnitTest/ - if-no-files-found: ignore - retention-days: 14 - overwrite: true - - name: Sign with the testkey (v1 + v2 + v3) run: | set -euo pipefail @@ -872,8 +779,6 @@ jobs: PR: ${{ github.event.pull_request.number }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} BUILD_OUTCOME: ${{ steps.build.outcome }} - UNIT_TEST_OUTCOME: ${{ steps.unit-tests.outcome }} - TEST_DIAGNOSTICS_URL: ${{ steps.unit-test-diagnostics.outputs.artifact-url }} APK_OUTCOME: ${{ steps.apk-upload.outcome }} run: bash tools/release/report-build.sh @@ -1050,6 +955,7 @@ jobs: with: artifact: droiddeck-signed variant: standard + fail_on_detection: true secrets: inherit packs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eabc77a358..24fd2ffa9a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,6 +47,13 @@ jobs: echo "::error::main ${GITHUB_SHA::7} has no successful Build APK run yet: wait for it, then release" exit 1 fi + tests=$(gh run list -R "$GITHUB_REPOSITORY" --workflow unit-tests.yml --branch main --commit "$GITHUB_SHA" \ + --json conclusion,event,headSha -L 20 | + jq -r --arg sha "$GITHUB_SHA" '[.[] | select(.headSha == $sha and (.event == "push" or .event == "workflow_dispatch"))][0].conclusion // empty') + if [ "$tests" != success ]; then + echo "::error::main ${GITHUB_SHA::7} has no passing Unit tests run (${tests:-none yet}): fix or wait for it, then release" + exit 1 + fi variants=$(awk '!/^#/ && NF { print $1 }' tools/release/variants.txt | jq -R . | jq -sc .) echo "run_id=$id" >> "$GITHUB_OUTPUT" echo "variants=$variants" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000000..663bd30e6a --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,202 @@ +name: Unit tests +run-name: ${{ github.event_name == 'pull_request' && format('unit tests for pr {0} on {1} against {2}', github.event.pull_request.number, github.event.pull_request.head.sha, github.event.pull_request.base.sha) || format('unit tests for {0} on {1}', github.ref_name, github.sha) }} + +# Runs beside Build APK rather than inside it, so a test build is published as soon as the APK compiles. +# Build validation folds this workflow's result into the "Build APK" commit status, and Release APKs requires it. +on: + push: + branches: [ main ] + paths-ignore: + - '**/*.md' + - 'LICENSE' + - '.gitignore' + - 'docs/**' + - '.github/ISSUE_TEMPLATE/**' + pull_request: + branches: [ main ] + types: [ opened, synchronize, reopened, ready_for_review ] + paths-ignore: + - '**/*.md' + - 'LICENSE' + - '.gitignore' + - 'docs/**' + - '.github/ISSUE_TEMPLATE/**' + workflow_dispatch: + +permissions: + contents: read + actions: read + +concurrency: + group: unit-tests-${{ github.event.pull_request.number || (github.event_name == 'push' && 'main') || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} + +jobs: + unit-tests: + name: Unit tests + if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} + runs-on: ubuntu-24.04 + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + fetch-depth: 0 + sparse-checkout: | + /* + !/docs/releases/media/ + sparse-checkout-cone-mode: false + persist-credentials: false + + - name: Merge the pinned APK base + if: github.event_name == 'pull_request' + env: + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: | + set -euo pipefail + git config user.name "ci" + git config user.email "ci@users.noreply.github.com" + git fetch --no-tags origin "$PR_BASE_SHA" + git merge-tree --write-tree HEAD FETCH_HEAD >/dev/null || true + git merge --no-ff --no-edit FETCH_HEAD || { echo "::error::the pull request conflicts with main; Build APK lists the files"; exit 1; } + + - name: Check out MaliBridge + run: git submodule update --init external/MaliBridge + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }} + cache-cleanup: ${{ github.event_name == 'pull_request' && 'never' || 'on-success' }} + + - name: Resolve the pinned Android NDK + run: bash tools/ci/resolve-ndk.sh + + - name: Set the APK build label + id: build-label + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + BUILD_REF: ${{ github.ref_name }} + BUILD_SHA: ${{ github.sha }} + run: bash tools/ci/build-label.sh + + - name: Resolve the Robolectric version + id: robolectric + run: | + echo "version=$(grep -o "org.robolectric:robolectric:[0-9.]*" app/build.gradle | cut -d: -f3)" >> "$GITHUB_OUTPUT" + # Robolectric downloads these from Maven Central on first use without retrying, and 429s fail whole test classes. + # The cache path sits beside the workspace because runner homes are at different depths from it, and + # actions/cache stores paths relative to the workspace. It is passed as an absolute path: the save action rejects + # "..". Runners that keep their own ~/.m2 skip the cache. + - name: Place Robolectric's Android jars beside the workspace + id: robolectric-jars + run: | + set -euo pipefail + jars="$GITHUB_WORKSPACE/../robolectric-jars" + m2="$HOME/.m2/repository/org/robolectric/android-all-instrumented" + if [ -d "$m2" ] && [ ! -L "$m2" ]; then + echo "cache=false" >> "$GITHUB_OUTPUT" + else + mkdir -p "$jars" "$(dirname "$m2")" + jars=$(cd "$jars" && pwd) + ln -sfn "$jars" "$m2" + echo "path=$jars" >> "$GITHUB_OUTPUT" + echo "cache=true" >> "$GITHUB_OUTPUT" + fi + - name: Restore Robolectric's Android jars + id: robolectric-cache + if: steps.robolectric-jars.outputs.cache == 'true' + uses: actions/cache/restore@v4 + with: + path: ${{ steps.robolectric-jars.outputs.path }} + key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} + restore-keys: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}- + - name: Count the restored Robolectric jars + if: steps.robolectric-jars.outputs.cache == 'true' + run: echo "ROBOLECTRIC_JARS_BEFORE=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l)" >> "$GITHUB_ENV" + - name: Unit tests + id: unit-tests + env: + DROIDDECK_BUILD_LABEL: ${{ steps.build-label.outputs.label }} + SGDB_API_KEY: ${{ secrets.SGDB_API_KEY }} + run: | + set -o pipefail + mkdir -p app/build + log=app/build/unit-tests.log + attempt_log=app/build/unit-tests-attempt.log + : > "$log" + mirror=() + central='https://(repo1\.maven\.org|repo\.maven\.apache\.org)/maven2/org/robolectric/' + gradle_error='((Caused by: )?org\.gradle\.internal\.resource\.transport\.http\.HttpErrorStatusCodeException: |>[[:space:]]+)?' + java_error='((Caused by: )?java\.io\.IOException: )?' + # A Maven 429 fails every test class that needs the missing jar. The jars an attempt did get stay for the next. + for wait in 60 180 0; do + status=0 + ./gradlew testReleaseUnitTest --console=plain --info --stacktrace -Drobolectric.logging=stderr -PskipRust=true -PunitTestsOnly=true -PndkVersion="$NDK_VERSION" "${mirror[@]}" 2>&1 | tee "$attempt_log" || status=$? + cat "$attempt_log" >> "$log" + if [ "$status" = 0 ] || [ "$wait" = 0 ]; then + exit "$status" + fi + if [ "${#mirror[@]}" = 0 ] && grep -qE \ + -e "^[[:space:]]*${gradle_error}Could not (GET|HEAD) '?${central}[^'[:space:]]+'?\. Received status code 429([[:space:]]|$)" \ + -e "^[[:space:]]*${java_error}Server returned HTTP response code: 429 for URL: ${central}[^[:space:]]+" "$attempt_log"; then + mirror=(-ProbolectricMavenMirror=https://maven-central.storage-download.googleapis.com/maven2) + echo "::notice::Maven Central rate limited Robolectric. Retrying unit tests with the Google Cloud mirror." | tee -a "$log" + continue + fi + if ! grep -Eq '^[[:space:]]*(Caused by: org\.gradle\.internal\.resource\.transport\.http\.HttpErrorStatusCodeException: Could not GET .*https://(repo\.maven\.apache\.org|repo1\.maven\.org)/.*Received status code 429 from server|Caused by: java\.io\.IOException: Server returned HTTP response code: 429 for URL: https://(repo\.maven\.apache\.org|repo1\.maven\.org)/)' "$attempt_log"; then + exit "$status" + fi + echo "::warning::Maven Central answered 429; running the unit tests again in ${wait}s" | tee -a "$log" + sleep "$wait" + done + + # actions/cache only saves when the job succeeds, so a run whose tests died on a Maven 429 never filled the cache. + # Save the complete jars even after a failed test step, when this run added some; a partial download is dropped first. + - name: Save Robolectric's Android jars + id: robolectric-jars-final + if: always() && steps.robolectric-jars.outputs.cache == 'true' + run: | + python3 - <<'PY' + import glob, os, zipfile + root = os.path.join(os.environ['GITHUB_WORKSPACE'], '..', 'robolectric-jars') + for f in glob.glob(os.path.join(root, '**', '*'), recursive=True): + if not os.path.isfile(f): + continue + try: + ok = f.endswith('.jar') and zipfile.ZipFile(f).testzip() is None + except Exception: + ok = False + if not ok: + os.remove(f) + 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' + uses: actions/cache/save@v4 + with: + path: ${{ steps.robolectric-jars.outputs.path }} + key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} + + - name: Upload unit test diagnostics + id: unit-test-diagnostics + if: always() && steps.unit-tests.outcome != 'skipped' + uses: actions/upload-artifact@v4 + with: + name: unit-test-results + path: | + app/build/unit-tests.log + app/build/test-results/testReleaseUnitTest/ + app/build/reports/tests/testReleaseUnitTest/ + if-no-files-found: ignore + retention-days: 14 + overwrite: true diff --git a/AGENTS.md b/AGENTS.md index 97930d6563..d89bdf632c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ - For an install-and-look iteration, use `tools/quick_deploy.sh` (build without lint, sign, install, about 30 s). Run `tools/build_local.sh` once to prepare the runtime and again only before a PR. It is not a per-change step. - `tools/build_local.sh` reuses the components a main CI run prepared when every recipe identity matches the local tree (it prints `components: … reusing`). It builds them locally when no usable CI artifact matches (after you change their inputs, or when the lookup fails) or with `DROIDDECK_CI_COMPONENTS=0`. - Helper scripts (`tools/linuxfs/overlay`, `tools/linuxfs/desktop`) are staged on every Gradle build, so editing them needs no `build_local.sh`. After preloads or other runtime components change, the fast loop warns and reuses the old binaries; run `tools/build_local.sh` when those matter. "Missing or changed runtime input" means the prepared files themselves changed: run `tools/build_local.sh` once. Do not revert scripts or copy `app/build` between checkouts; `tools/seed_worktree.sh` seeds a new worktree from the main checkout. -- Every build defaults to the NDK in `tools/ci/toolchains.env`, as CI does. CI runs `testReleaseUnitTest`; when a test fails only in CI, run the release variant locally. +- Every build defaults to the NDK in `tools/ci/toolchains.env`, as CI does. CI runs `testReleaseUnitTest` in the `Unit tests` workflow, beside Build APK; when a test fails only in CI, run the release variant locally. - Run the tests that cover what you changed, including unchanged tests of code you edited: `./gradlew -PskipRust=true :app:testDebugUnitTest --tests ''` and `python3 -m unittest discover -s tools/tests -p 'test_*.py'`. The full Python suite takes about 9 minutes, and some preload tests fail on any host without zram/ntsync. Leave full runs to CI. - For UI screenshots without a device, run `./gradlew -PskipRust=true :app:testDebugUnitTest --tests '*PreviewRenderTest'` and read `app/build/preview-renders/{handheld,portrait}/`. Add cases per `docs/compose-previews.md`. Check portrait, not just landscape. - After changing `SettingsIndex`, regenerate the doc: `UPDATE_SETTINGS_MAP=1 ./gradlew -PskipRust=true :app:testDebugUnitTest --tests '*SettingsMapTest*'`. @@ -31,7 +31,7 @@ - CI builds the PR merged onto `main`. Before pushing, merge or rebase onto `origin/main` and compile: most "works locally" Kotlin failures come from that merge. - Before a PR that touches strings or resources, run `./gradlew :app:lintVitalRelease`. The fast loop skips lint, and lint catches `ExtraTranslation` and missing-locale errors. - Commit messages and PR bodies must not carry `Co-Authored-By` or other bot trailers. `tools/release/check_authorship.py` fails the build on them. -- `gh run view --log-failed` truncates the unit-test log, so the failing test may not show. Read the whole job log with `gh api repos/Droid-Deck/DroidDeck/actions/jobs//logs`, or `gh run download -n unit-test-results`. Don't call a failure a runner problem until you have read it. +- `gh run view --log-failed` truncates the unit-test log, so the failing test may not show. Read the whole job log with `gh api repos/Droid-Deck/DroidDeck/actions/jobs//logs`, or `gh run download -n unit-test-results` from the `Unit tests` workflow run. Don't call a failure a runner problem until you have read it. - Only these are known flakes worth a `gh run rerun --failed`: `ProtonMenuAutoTest` "Proton work did not finish", Robolectric `HTTP response code: 429` from Maven, `Gradle Test Executor N finished with non-zero exit value 2`, apt mirror and GitHub API rate-limit errors. Treat any other failure as real. - A workflow step that names a script your branch lacks means the branch predates a CI change. Rebase onto `main`. diff --git a/README.md b/README.md index 576cf61c59..d6616b1ab7 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ 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. @@ -113,7 +114,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 needs your own copy of [Lossless Scaling](https://store.steampowered.com/app/993090/) 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 requires [Lossless Scaling](https://store.steampowered.com/app/993090/) installed through Steam 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. @@ -156,6 +157,13 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V +
+Setup and tools + +- The wireless debugging pairing keypad was inspired by Ryan Retro’s Handheld Toolkit. + +
+ ## Star history diff --git a/app/build.gradle b/app/build.gradle index 70336a0472..513fdef6aa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,6 +82,8 @@ def buildBranch = providers.environmentVariable('GITHUB_HEAD_REF').getOrNull()?. ?: gitValue(['branch', '--show-current']) ?: '' def escapeJava = { String value -> value.replace('\\', '\\\\').replace('"', '\\"').replace('\n', ' ').replace('\r', ' ') } def ciBuild = providers.environmentVariable('GITHUB_ACTIONS').getOrNull() == 'true' +// The Unit tests workflow compiles no APK, so it has no add-on packs to pin. +def unitTestsOnly = project.findProperty('unitTestsOnly')?.toString()?.toBoolean() ?: false def releaseSigner = rootProject.file('keystore/release-signer.sha256').text.trim() def commitTime = (gitValue(['show', '-s', '--format=%ct', '--end-of-options', sourceCommit]) ?: '0').with { it.isLong() ? it : '0' } def desktopKde = rootProject.file('tools/desktop-kde/release.env').readLines() @@ -96,10 +98,12 @@ def prootPackPin = rootProject.file('tools/packs/proot/release.env').readLines() def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt', 'epic'].collectEntries { name -> def pack = file("build/packs/${name}.tar.zst") if (!pack.isFile()) { - if (ciBuild) throw new GradleException("Add-on pack ${pack} is missing: run tools/packs/build.sh app/build/packs") + if (ciBuild && !unitTestsOnly) throw new GradleException("Add-on pack ${pack} is missing: run tools/packs/build.sh app/build/packs") if (name == 'proot' && prootPackPin.PROOT_PACK_SHA256) { return [(name): [sha256: prootPackPin.PROOT_PACK_SHA256, size: (prootPackPin.PROOT_PACK_SIZE ?: '0') as long]] } + // A CI APK pins every pack, and CI_BUILD code assumes that, so the tests see a placeholder pin. + if (unitTestsOnly) return [(name): [sha256: '0' * 64, size: 0L]] return [(name): [sha256: '', size: 0L]] } def digest = java.security.MessageDigest.getInstance('SHA-256') @@ -238,6 +242,9 @@ android { doFirst { jvmTemp.mkdirs() } def logTarget = providers.systemProperty('robolectric.logging').orNull if (logTarget != null) systemProperty 'robolectric.logging', logTarget + // Robolectric resolves Android SDK jars inside the test JVM independently of Gradle. + def robolectricMirror = providers.gradleProperty('robolectricMavenMirror').orNull + if (robolectricMirror) systemProperty 'robolectric.dependency.repo.url', robolectricMirror } } diff --git a/app/src/debug/java/com/droiddeck/launcher/ui/LauncherPreviews.kt b/app/src/debug/java/com/droiddeck/launcher/ui/LauncherPreviews.kt index 0ab0ab8216..05d9559271 100644 --- a/app/src/debug/java/com/droiddeck/launcher/ui/LauncherPreviews.kt +++ b/app/src/debug/java/com/droiddeck/launcher/ui/LauncherPreviews.kt @@ -1,13 +1,17 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.material.icons.filled.Settings import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import com.droiddeck.launcher.R import com.droiddeck.launcher.input.SecondScreenMode @@ -26,6 +30,50 @@ private fun Launcher(tab: String, games: List Unit) = + DroidDeckTheme(frost = FrostChoice(transparency, cards, cardTransparency)) { + val wallpaper = Brush.linearGradient(listOf(Color(0xFFE2725B), Color(0xFF7A4BC2), Color(0xFF2A9D8F))) + Box(Modifier.fillMaxSize().background(wallpaper).background(LocalFrost.current ?: Color.Transparent)) { content() } + } + +@Composable +private fun FrostedLauncher(tab: String, transparency: Int = FROST_WALLPAPER_DEFAULT, cards: Boolean = false, cardTransparency: Int = FROST_DEFAULT) = + Frosted(transparency, cards, cardTransparency) { FrontEndScreen(sampleState(navigate = tab), sampleActions) } + +/** A settings step opened over frosted page text with see-through cards: the step is solid, so none of the text shows through it. */ +@Composable +private fun FrostedStepOut() = Frosted(cards = true) { + val text: @Composable (Int) -> String = { androidx.compose.ui.res.stringResource(it) } + Column(Modifier.padding(24.dp)) { + val line = List(8) { text(R.string.stores_shelf_new) }.joinToString(" ") + repeat(14) { androidx.compose.material3.Text(line, fontSize = 24.sp, color = LocalPalette.current.onBackground, maxLines = 1, softWrap = false) } + } + androidx.compose.foundation.layout.BoxWithConstraints(Modifier.fillMaxSize()) { + val pill = with(androidx.compose.ui.platform.LocalDensity.current) { + androidx.compose.ui.geometry.Rect(androidx.compose.ui.geometry.Offset((maxWidth - 68.dp).toPx(), 16.dp.toPx()), androidx.compose.ui.geometry.Size(44.dp.toPx(), 44.dp.toPx())) + } + val accent = LocalPalette.current.signal + StepOut( + open = true, pill = pill, preferredSide = StepSide.Left, accent = accent, onDismiss = {}, onClosed = {}, items = 2, maxWidth = 440.dp, + handle = { androidx.compose.material3.Icon(androidx.compose.material.icons.Icons.Filled.Settings, null, tint = accent, modifier = Modifier.size(20.dp)) }, + ) { + StepTitle(text(R.string.stores_settings_eyebrow)) + Column(Modifier.stepItem(1)) { + SettingsRow(text(R.string.stores_show_mature), null) { ToggleSwitch(true, label = text(R.string.stores_show_mature)) {} } + SettingsRow(text(R.string.gog_achievements), text(R.string.gog_achievements_hint)) { ToggleSwitch(false, label = text(R.string.gog_achievements)) {} } + } + } + } +} + +@DroidDeckPreviews @Composable private fun FrostedSteamTabPreview() = FrostedLauncher("steam") +@DroidDeckPreviews @Composable private fun FrostedLibraryPreview() = FrostedLauncher("games") +@DroidDeckPreviews @Composable private fun FrostedSettingsCardsPreview() = FrostedLauncher("setup", cards = true) +@DroidDeckPreviews @Composable private fun FrostedSettingsClearestPreview() = FrostedLauncher("setup", transparency = FROST_MAX, cards = true, cardTransparency = FROST_MAX) +@DroidDeckPreviews @Composable private fun FrostedStepOutPreview() = FrostedStepOut() + /** The in-game menu on one page, as a session shows it. */ @Composable private fun SessionMenu(page: SessionDrawerPage, steam: Boolean = true, desktop: Boolean = false) = PreviewHost { @@ -72,6 +120,11 @@ internal val previewCases: List = listOf( PreviewCase("downloads") { Launcher("downloads") }, PreviewCase("settings") { Launcher("setup") }, PreviewCase("runtime-missing") { Launcher("setup", ready = false) }, + PreviewCase("frosted-steam-tab") { FrostedLauncher("steam") }, + PreviewCase("frosted-library", storesLoaded) { FrostedLauncher("games") }, + PreviewCase("frosted-settings-cards") { FrostedLauncher("setup", cards = true) }, + PreviewCase("frosted-settings-clearest") { FrostedLauncher("setup", transparency = FROST_MAX, cards = true, cardTransparency = FROST_MAX) }, + PreviewCase("frosted-step-out") { FrostedStepOut() }, PreviewCase("session-menu-controller") { SessionMenu(SessionDrawerPage.CONTROLLER) }, PreviewCase("session-menu-display") { SessionMenu(SessionDrawerPage.DISPLAY) }, PreviewCase("session-menu-hud") { SessionMenu(SessionDrawerPage.HUD) }, diff --git a/app/src/debug/java/com/droiddeck/launcher/ui/PreviewSupport.kt b/app/src/debug/java/com/droiddeck/launcher/ui/PreviewSupport.kt index 96a958e719..8a7da4c5d0 100644 --- a/app/src/debug/java/com/droiddeck/launcher/ui/PreviewSupport.kt +++ b/app/src/debug/java/com/droiddeck/launcher/ui/PreviewSupport.kt @@ -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 = {}, onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {}, onRoms = {}, + onFrameGenPick = {}, 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, - onImportLossless = {}, onKeyboard = {}, onHardwareKeyboard = {}, + onKeyboard = {}, onHardwareKeyboard = {}, onSteamMenu = if (steam) ({}) else null, onQam = if (steam) ({}) else null, onLaunchAndroidApp = { _, _ -> }, onBackground = {}, onShareLogs = {}, onStop = {}, onClose = {}, ) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 55b75d36df..4211f6bbc5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,10 +33,15 @@ + + + + @@ -274,6 +279,17 @@ android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|density" android:theme="@style/AppTheme" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/assets/agent/dd-gh-login b/app/src/main/assets/agent/dd-gh-login index f9b0b7734a..e02054ffc1 100644 --- a/app/src/main/assets/agent/dd-gh-login +++ b/app/src/main/assets/agent/dd-gh-login @@ -28,6 +28,19 @@ 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]}" @@ -48,5 +61,9 @@ 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 diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index a33cf37e49..01ae9fd830 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -10,6 +10,17 @@ 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 diff --git a/app/src/main/cpp/fakeinput_steam.cpp b/app/src/main/cpp/fakeinput_steam.cpp index 2e0aaa927d..4c592ded09 100644 --- a/app/src/main/cpp/fakeinput_steam.cpp +++ b/app/src/main/cpp/fakeinput_steam.cpp @@ -329,16 +329,28 @@ static constexpr int kWatchedFds = 1 << 16; static constexpr int kWatchedBits = sizeof(unsigned long) * 8; static std::atomic watched_fds[kWatchedFds / kWatchedBits]; static std::atomic watched_beyond{false}; +static std::atomic watched_count{0}; static void watch_fd(int fd) { if (fd < 0) return; - 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); + 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); } static void unwatch_fd(int fd) { - if (fd >= 0 && fd < kWatchedFds) - watched_fds[fd / kWatchedBits].fetch_and(~(1UL << (fd % kWatchedBits)), std::memory_order_release); + 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); } static bool watched(int fd) { @@ -4130,6 +4142,24 @@ EXPORT ssize_t read(int fd, void *buf, size_t count) { return read_input(fd, buf, count); } +// glibc's fortify failure; bionic (DroidDeck-Bionic preloads this library into its Wine processes) has no +// __chk_fail, and a library naming it there cannot be loaded, which stops every Wine program from starting. +#if defined(__BIONIC__) +[[noreturn]] static void fakeinput_chk_fail(void) { abort(); } +#else +extern "C" [[noreturn]] void __chk_fail(void); +[[noreturn]] static void fakeinput_chk_fail(void) { __chk_fail(); } +#endif + +/* Programs built with _FORTIFY_SOURCE (Flatpak runtimes among them) call these instead of read, poll + * and ppoll, and glibc's versions go straight to the kernel. */ +EXPORT ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen) { + static auto next_read_chk = reinterpret_cast(dlsym(RTLD_NEXT, "__read_chk")); + if (count > buflen) fakeinput_chk_fail(); + if (next_read_chk && !is_fake_input_fd(fd)) return next_read_chk(fd, buf, count, buflen); + return read_input(fd, buf, count); +} + EXPORT ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { if (!is_fake_input_fd(fd)) return syscall(SYS_readv, fd, iov, iovcnt); if (iovcnt < 0 || iovcnt > IOV_MAX) { @@ -4251,7 +4281,7 @@ static int poll_fake(struct pollfd *fds, nfds_t nfds, int timeout, const auto my_poll = next_symbol(Next::poll); const auto my_ppoll = next_symbol(Next::ppoll); - nfds_t first = 0; + nfds_t first = any_watched() ? 0 : nfds; while (first < nfds && !watched(fds[first].fd)) first++; bool has_fake_fds = false; std::vector real_fds; @@ -4354,12 +4384,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(Next::ppoll); - 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) { + for (nfds_t i = 0; any_watched() && 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(timespec_to_ms(timeout)), nullptr); sigset_t all_signals, original_mask; @@ -4378,9 +4408,22 @@ EXPORT int ppoll(struct pollfd *fds, nfds_t nfds, return my_ppoll(fds, nfds, timeout, sigmask); } +EXPORT int __poll_chk(struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen) { + if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail(); + return poll(fds, nfds, timeout); +} + +EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, + const sigset_t *sigmask, size_t fdslen) { + if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail(); + return ppoll(fds, nfds, timeout, sigmask); +} + EXPORT int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { const auto my_select = next_symbol(Next::select); + if (!any_watched()) + return my_select ? my_select(nfds, readfds, writefds, exceptfds, timeout) : -1; fd_set original_readfds; fd_set original_writefds; diff --git a/app/src/main/cpp/framegen/ddfg/ddfg_engine.cpp b/app/src/main/cpp/framegen/ddfg/ddfg_engine.cpp index 6e87890b3f..034f2c4d55 100644 --- a/app/src/main/cpp/framegen/ddfg/ddfg_engine.cpp +++ b/app/src/main/cpp/framegen/ddfg/ddfg_engine.cpp @@ -27,7 +27,31 @@ VkImageMemoryBarrier bar(VkImage img, VkImageLayout from, VkImageLayout to, } Engine::Engine() = default; -Engine::~Engine() { destroyRing(); fg_.destroy(); } +Engine::~Engine() { (void)destroy(); } + +bool Engine::destroy() { + if (!fg_.destroy()) { + DDFG_LOGE("native: retaining the input ring because GPU completion is unknown"); + return false; + } + if (!destroyRing(true)) { + DDFG_LOGE("native: could not release the input ring during teardown"); + return false; + } + dev_ = VK_NULL_HANDLE; + unavailable_ = true; + return true; +} + +void Engine::abandon() { + fg_.abandon(); + ring_[0] = Slot{}; + ring_[1] = Slot{}; + dev_ = VK_NULL_HANDLE; + queue_ = VK_NULL_HANDLE; + phys_ = VK_NULL_HANDLE; + unavailable_ = true; +} bool Engine::init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue) { @@ -59,15 +83,29 @@ bool Engine::prepare(uint32_t w, uint32_t h, VkFormat fmt) { if (unavailable_ || w == 0 || h == 0 || fmt == VK_FORMAT_UNDEFINED) return false; if (builtW_ == w && builtH_ == h && builtFmt_ == fmt && fg_.valid()) return true; - - if (!fg_.onResize(VkExtent2D{w, h}, fmt, false)) { + const bool formatChanged = fmt != builtFmt_; + if (!fg_.onResize(VkExtent2D{w, h}, fmt, formatChanged)) { DDFG_LOGE("native: onResize %ux%u failed; frame generation unavailable", w, h); unavailable_ = true; return false; } - destroyRing(); + bool deviceLost = false; + if (!destroyRing(false, &deviceLost)) { + DDFG_LOGE("native: could not safely release the previous input ring"); + unavailable_ = true; + return false; + } + if (deviceLost) { + DDFG_LOGE("native: device lost while releasing the input ring"); + unavailable_ = true; + return false; + } for (Slot& s : ring_) { - if (!makeSlot(s, w, h, fmt)) { destroyRing(); unavailable_ = true; return false; } + if (!makeSlot(s, w, h, fmt)) { + destroyRing(true); + unavailable_ = true; + return false; + } } builtW_ = w; builtH_ = h; builtFmt_ = fmt; history_ = 0; curr_ = 0; frames_ = 0; @@ -178,11 +216,37 @@ void Engine::destroySlot(Slot& s) { s = Slot{}; } -void Engine::destroyRing() { - if (dev_ == VK_NULL_HANDLE || !dd_.DeviceWaitIdle) return; - if (ring_[0].img || ring_[1].img) dd_.DeviceWaitIdle(dev_); - destroySlot(ring_[0]); destroySlot(ring_[1]); +bool Engine::destroyRing(bool deviceIdleConfirmed, bool* deviceLost) { + if (deviceLost) *deviceLost = false; + const bool hasResources = ring_[0].img || ring_[0].mem || ring_[0].view || + ring_[1].img || ring_[1].mem || ring_[1].view; + if (!hasResources) { + history_ = 0; + return true; + } + if (dev_ == VK_NULL_HANDLE) { + DDFG_LOGE("native: cannot release the input ring without a valid device"); + return false; + } + if (!deviceIdleConfirmed) { + if (!dd_.DeviceWaitIdle) { + DDFG_LOGE("native: cannot release the input ring without vkDeviceWaitIdle"); + return false; + } + const VkResult result = dd_.DeviceWaitIdle(dev_); + if (result == VK_ERROR_DEVICE_LOST) { + if (deviceLost) *deviceLost = true; + unavailable_ = true; + } else if (result != VK_SUCCESS) { + DDFG_LOGE("native: DeviceWaitIdle failed (%d); retaining the input ring", (int)result); + unavailable_ = true; + return false; + } + } + destroySlot(ring_[0]); + destroySlot(ring_[1]); history_ = 0; + return true; } } diff --git a/app/src/main/cpp/framegen/ddfg/ddfg_engine.h b/app/src/main/cpp/framegen/ddfg/ddfg_engine.h index 55c1ef8fa0..aff10a9033 100644 --- a/app/src/main/cpp/framegen/ddfg/ddfg_engine.h +++ b/app/src/main/cpp/framegen/ddfg/ddfg_engine.h @@ -36,13 +36,15 @@ public: uint32_t width, uint32_t height); void reset(); + bool destroy(); + void abandon(); private: struct Slot { VkImage img = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE; VkImageView view = VK_NULL_HANDLE; bool valid = false; }; bool makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt); void destroySlot(Slot& s); - void destroyRing(); + bool destroyRing(bool deviceIdleConfirmed = false, bool* deviceLost = nullptr); uint32_t memType(uint32_t bits, VkMemoryPropertyFlags props) const; DeviceDispatch dd_{}; diff --git a/app/src/main/cpp/framegen/ddfg/embedded_shaders.hpp b/app/src/main/cpp/framegen/ddfg/embedded_shaders.hpp index 61f5c154c7..af09e777d6 100644 --- a/app/src/main/cpp/framegen/ddfg/embedded_shaders.hpp +++ b/app/src/main/cpp/framegen/ddfg/embedded_shaders.hpp @@ -6,8 +6,216 @@ static const uint32_t OF3_LUMA_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00 static const size_t OF3_LUMA_LEN = 481; static const uint32_t OF3_DOWNSAMPLE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x0000008au,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00040005u,0x00000030u,0x44637273u,0x00006d69u,0x00040005u,0x00000034u,0x63725375u,0x00000000u,0x00040005u,0x0000003au,0x65736162u,0x00000000u,0x00030005u,0x00000044u,0x00000068u,0x00030005u,0x0000004au,0x00000061u,0x00030005u,0x00000059u,0x00000062u,0x00030005u,0x00000065u,0x00000063u,0x00030005u,0x00000071u,0x00000064u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00040047u,0x00000034u,0x00000021u,0x00000020u,0x00040047u,0x00000034u,0x00000022u,0x00000000u,0x00040047u,0x00000089u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x00090019u,0x00000031u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000032u,0x00000031u,0x00040020u,0x00000033u,0x00000000u,0x00000032u,0x0004003bu,0x00000033u,0x00000034u,0x00000000u,0x0004002bu,0x00000006u,0x00000036u,0x00000000u,0x0004002bu,0x00000013u,0x0000003du,0x40000000u,0x0004002bu,0x00000013u,0x0000003fu,0x3f800000u,0x0004002bu,0x00000013u,0x00000045u,0x3f000000u,0x00040020u,0x00000049u,0x00000007u,0x00000013u,0x0004002bu,0x00000013u,0x00000055u,0x00000000u,0x00040017u,0x00000056u,0x00000013u,0x00000004u,0x0004002bu,0x00000013u,0x00000085u,0x3e800000u,0x0004002bu,0x0000000au,0x00000088u,0x00000010u,0x0006002cu,0x0000000bu,0x00000089u,0x00000088u,0x00000088u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003au,0x00000007u,0x0004003bu,0x0000002fu,0x00000044u,0x00000007u,0x0004003bu,0x00000049u,0x0000004au,0x00000007u,0x0004003bu,0x00000049u,0x00000059u,0x00000007u,0x0004003bu,0x00000049u,0x00000065u,0x00000007u,0x0004003bu,0x00000049u,0x00000071u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000032u,0x00000035u,0x00000034u,0x00040064u,0x00000031u,0x00000037u,0x00000035u,0x00050067u,0x00000007u,0x00000038u,0x00000037u,0x00000036u,0x0004006fu,0x0000002eu,0x00000039u,0x00000038u,0x0003003eu,0x00000030u,0x00000039u,0x0004003du,0x00000007u,0x0000003bu,0x00000009u,0x0004006fu,0x0000002eu,0x0000003cu,0x0000003bu,0x0005008eu,0x0000002eu,0x0000003eu,0x0000003cu,0x0000003du,0x00050050u,0x0000002eu,0x00000040u,0x0000003fu,0x0000003fu,0x00050081u,0x0000002eu,0x00000041u,0x0000003eu,0x00000040u,0x0004003du,0x0000002eu,0x00000042u,0x00000030u,0x00050088u,0x0000002eu,0x00000043u,0x00000041u,0x00000042u,0x0003003eu,0x0000003au,0x00000043u,0x0004003du,0x0000002eu,0x00000046u,0x00000030u,0x00050050u,0x0000002eu,0x00000047u,0x00000045u,0x00000045u,0x00050088u,0x0000002eu,0x00000048u,0x00000047u,0x00000046u,0x0003003eu,0x00000044u,0x00000048u,0x0004003du,0x00000032u,0x0000004bu,0x00000034u,0x0004003du,0x0000002eu,0x0000004cu,0x0000003au,0x00050041u,0x00000049u,0x0000004du,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x0000004eu,0x0000004du,0x0004007fu,0x00000013u,0x0000004fu,0x0000004eu,0x00050041u,0x00000049u,0x00000050u,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x00000051u,0x00000050u,0x0004007fu,0x00000013u,0x00000052u,0x00000051u,0x00050050u,0x0000002eu,0x00000053u,0x0000004fu,0x00000052u,0x00050081u,0x0000002eu,0x00000054u,0x0000004cu,0x00000053u,0x00070058u,0x00000056u,0x00000057u,0x0000004bu,0x00000054u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000058u,0x00000057u,0x00000000u,0x0003003eu,0x0000004au,0x00000058u,0x0004003du,0x00000032u,0x0000005au,0x00000034u,0x0004003du,0x0000002eu,0x0000005bu,0x0000003au,0x00050041u,0x00000049u,0x0000005cu,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x0000005du,0x0000005cu,0x00050041u,0x00000049u,0x0000005eu,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x0000005fu,0x0000005eu,0x0004007fu,0x00000013u,0x00000060u,0x0000005fu,0x00050050u,0x0000002eu,0x00000061u,0x0000005du,0x00000060u,0x00050081u,0x0000002eu,0x00000062u,0x0000005bu,0x00000061u,0x00070058u,0x00000056u,0x00000063u,0x0000005au,0x00000062u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000064u,0x00000063u,0x00000000u,0x0003003eu,0x00000059u,0x00000064u,0x0004003du,0x00000032u,0x00000066u,0x00000034u,0x0004003du,0x0000002eu,0x00000067u,0x0000003au,0x00050041u,0x00000049u,0x00000068u,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x00000069u,0x00000068u,0x0004007fu,0x00000013u,0x0000006au,0x00000069u,0x00050041u,0x00000049u,0x0000006bu,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x0000006cu,0x0000006bu,0x00050050u,0x0000002eu,0x0000006du,0x0000006au,0x0000006cu,0x00050081u,0x0000002eu,0x0000006eu,0x00000067u,0x0000006du,0x00070058u,0x00000056u,0x0000006fu,0x00000066u,0x0000006eu,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000070u,0x0000006fu,0x00000000u,0x0003003eu,0x00000065u,0x00000070u,0x0004003du,0x00000032u,0x00000072u,0x00000034u,0x0004003du,0x0000002eu,0x00000073u,0x0000003au,0x00050041u,0x00000049u,0x00000074u,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x00000075u,0x00000074u,0x00050041u,0x00000049u,0x00000076u,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x00000077u,0x00000076u,0x00050050u,0x0000002eu,0x00000078u,0x00000075u,0x00000077u,0x00050081u,0x0000002eu,0x00000079u,0x00000073u,0x00000078u,0x00070058u,0x00000056u,0x0000007au,0x00000072u,0x00000079u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x0000007bu,0x0000007au,0x00000000u,0x0003003eu,0x00000071u,0x0000007bu,0x0004003du,0x00000014u,0x0000007cu,0x00000016u,0x0004003du,0x00000007u,0x0000007du,0x00000009u,0x0004003du,0x00000013u,0x0000007eu,0x0000004au,0x0004003du,0x00000013u,0x0000007fu,0x00000059u,0x00050081u,0x00000013u,0x00000080u,0x0000007eu,0x0000007fu,0x0004003du,0x00000013u,0x00000081u,0x00000065u,0x00050081u,0x00000013u,0x00000082u,0x00000080u,0x00000081u,0x0004003du,0x00000013u,0x00000083u,0x00000071u,0x00050081u,0x00000013u,0x00000084u,0x00000082u,0x00000083u,0x00050085u,0x00000013u,0x00000086u,0x00000084u,0x00000085u,0x00070050u,0x00000056u,0x00000087u,0x00000086u,0x00000055u,0x00000055u,0x00000055u,0x00040063u,0x0000007cu,0x0000007du,0x00000087u,0x000100fdu,0x00010038u}; static const size_t OF3_DOWNSAMPLE_LEN = 753; -static const uint32_t OF3_FLOW_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000185u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x6f6c4675u,0x00000077u,0x00040005u,0x00000030u,0x44766e69u,0x00006d69u,0x00030005u,0x00000036u,0x00007675u,0x00040005u,0x0000003fu,0x654c6f74u,0x006c6576u,0x00030005u,0x00000040u,0x00000055u,0x00060006u,0x00000040u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000040u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000040u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000040u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000042u,0x00000000u,0x00050005u,0x0000004au,0x64657270u,0x6c6c7546u,0x00000000u,0x00050005u,0x0000004eu,0x65725075u,0x74636964u,0x0000726fu,0x00050005u,0x00000055u,0x64657270u,0x6576654cu,0x0000006cu,0x00040005u,0x00000059u,0x74736562u,0x00646153u,0x00050005u,0x0000005bu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x0000005du,0x00007973u,0x00030005u,0x00000067u,0x00007873u,0x00040005u,0x0000006fu,0x646e6163u,0x00000000u,0x00030005u,0x00000077u,0x00646173u,0x00030005u,0x00000078u,0x00007962u,0x00030005u,0x00000081u,0x00007862u,0x00030005u,0x00000089u,0x00006f62u,0x00030005u,0x0000008fu,0x00000070u,0x00050005u,0x00000090u,0x6d754c75u,0x65725061u,0x00000076u,0x00030005u,0x00000099u,0x00000063u,0x00050005u,0x0000009au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x000000cau,0x43646173u,0x00000000u,0x00040005u,0x000000ccu,0x58646173u,0x0000006du,0x00040005u,0x000000cdu,0x58646173u,0x00000070u,0x00040005u,0x000000ceu,0x59646173u,0x0000006du,0x00040005u,0x000000cfu,0x59646173u,0x00000070u,0x00030005u,0x000000d0u,0x00007962u,0x00030005u,0x000000d8u,0x00007862u,0x00030005u,0x000000e0u,0x00006f62u,0x00030005u,0x000000e6u,0x00000070u,0x00040005u,0x000000efu,0x646e6163u,0x00006d58u,0x00040005u,0x000000f4u,0x646e6163u,0x00007058u,0x00040005u,0x000000f8u,0x646e6163u,0x00006d59u,0x00040005u,0x000000fcu,0x646e6163u,0x00007059u,0x00030005u,0x00000148u,0x00007864u,0x00030005u,0x00000149u,0x00007964u,0x00040005u,0x0000014au,0x6f6e6564u,0x0000586du,0x00040005u,0x00000152u,0x6f6e6564u,0x0000596du,0x00050005u,0x00000176u,0x776f6c66u,0x6c6c7546u,0x00000000u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x00000040u,0x00000002u,0x00050048u,0x00000040u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000040u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000040u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000040u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000042u,0x00000021u,0x00000000u,0x00040047u,0x00000042u,0x00000022u,0x00000000u,0x00040047u,0x0000004eu,0x00000021u,0x00000022u,0x00040047u,0x0000004eu,0x00000022u,0x00000000u,0x00040047u,0x00000090u,0x00000021u,0x00000020u,0x00040047u,0x00000090u,0x00000022u,0x00000000u,0x00040047u,0x0000009au,0x00000021u,0x00000021u,0x00040047u,0x0000009au,0x00000022u,0x00000000u,0x00040047u,0x00000184u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000031u,0x3f800000u,0x0004002bu,0x00000013u,0x00000039u,0x3f000000u,0x00040020u,0x0000003eu,0x00000007u,0x00000013u,0x0006001eu,0x00000040u,0x00000013u,0x0000000au,0x0000000au,0x0000000au,0x00040020u,0x00000041u,0x00000002u,0x00000040u,0x0004003bu,0x00000041u,0x00000042u,0x00000002u,0x0004002bu,0x00000006u,0x00000043u,0x00000001u,0x00040020u,0x00000044u,0x00000002u,0x0000000au,0x00090019u,0x0000004bu,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000004cu,0x0000004bu,0x00040020u,0x0000004du,0x00000000u,0x0000004cu,0x0004003bu,0x0000004du,0x0000004eu,0x00000000u,0x0004002bu,0x00000013u,0x00000051u,0x00000000u,0x00040017u,0x00000052u,0x00000013u,0x00000004u,0x0004002bu,0x00000013u,0x0000005au,0x7f7fffffu,0x0004002bu,0x00000006u,0x0000005eu,0xfffffffdu,0x0004002bu,0x00000006u,0x00000065u,0x00000003u,0x0004002bu,0x00000006u,0x00000079u,0xffffffffu,0x0004003bu,0x0000004du,0x00000090u,0x00000000u,0x0004003bu,0x0000004du,0x0000009au,0x00000000u,0x0004002bu,0x00000013u,0x000000afu,0x3bc49ba6u,0x0004002bu,0x00000013u,0x000000f1u,0xbf800000u,0x0005002cu,0x0000002eu,0x000000f2u,0x000000f1u,0x00000051u,0x0005002cu,0x0000002eu,0x000000f6u,0x00000031u,0x00000051u,0x0005002cu,0x0000002eu,0x000000fau,0x00000051u,0x000000f1u,0x0005002cu,0x0000002eu,0x000000feu,0x00000051u,0x00000031u,0x0004002bu,0x00000013u,0x0000014cu,0x40000000u,0x0004002bu,0x00000013u,0x0000015au,0x358637bdu,0x0004002bu,0x00000013u,0x00000164u,0xbf000000u,0x0004002bu,0x0000000au,0x00000183u,0x00000010u,0x0006002cu,0x0000000bu,0x00000184u,0x00000183u,0x00000183u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000036u,0x00000007u,0x0004003bu,0x0000003eu,0x0000003fu,0x00000007u,0x0004003bu,0x0000002fu,0x0000004au,0x00000007u,0x0004003bu,0x0000002fu,0x00000055u,0x00000007u,0x0004003bu,0x0000003eu,0x00000059u,0x00000007u,0x0004003bu,0x0000002fu,0x0000005bu,0x00000007u,0x0004003bu,0x0000001bu,0x0000005du,0x00000007u,0x0004003bu,0x0000001bu,0x00000067u,0x00000007u,0x0004003bu,0x0000002fu,0x0000006fu,0x00000007u,0x0004003bu,0x0000003eu,0x00000077u,0x00000007u,0x0004003bu,0x0000001bu,0x00000078u,0x00000007u,0x0004003bu,0x0000001bu,0x00000081u,0x00000007u,0x0004003bu,0x0000002fu,0x00000089u,0x00000007u,0x0004003bu,0x0000003eu,0x0000008fu,0x00000007u,0x0004003bu,0x0000003eu,0x00000099u,0x00000007u,0x0004003bu,0x0000003eu,0x000000cau,0x00000007u,0x0004003bu,0x0000003eu,0x000000ccu,0x00000007u,0x0004003bu,0x0000003eu,0x000000cdu,0x00000007u,0x0004003bu,0x0000003eu,0x000000ceu,0x00000007u,0x0004003bu,0x0000003eu,0x000000cfu,0x00000007u,0x0004003bu,0x0000001bu,0x000000d0u,0x00000007u,0x0004003bu,0x0000001bu,0x000000d8u,0x00000007u,0x0004003bu,0x0000002fu,0x000000e0u,0x00000007u,0x0004003bu,0x0000003eu,0x000000e6u,0x00000007u,0x0004003bu,0x0000002fu,0x000000efu,0x00000007u,0x0004003bu,0x0000002fu,0x000000f4u,0x00000007u,0x0004003bu,0x0000002fu,0x000000f8u,0x00000007u,0x0004003bu,0x0000002fu,0x000000fcu,0x00000007u,0x0004003bu,0x0000003eu,0x00000148u,0x00000007u,0x0004003bu,0x0000003eu,0x00000149u,0x00000007u,0x0004003bu,0x0000003eu,0x0000014au,0x00000007u,0x0004003bu,0x0000003eu,0x00000152u,0x00000007u,0x0004003bu,0x0000002fu,0x00000176u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000032u,0x00000012u,0x0004006fu,0x0000002eu,0x00000033u,0x00000032u,0x00050050u,0x0000002eu,0x00000034u,0x00000031u,0x00000031u,0x00050088u,0x0000002eu,0x00000035u,0x00000034u,0x00000033u,0x0003003eu,0x00000030u,0x00000035u,0x0004003du,0x00000007u,0x00000037u,0x00000009u,0x0004006fu,0x0000002eu,0x00000038u,0x00000037u,0x00050050u,0x0000002eu,0x0000003au,0x00000039u,0x00000039u,0x00050081u,0x0000002eu,0x0000003bu,0x00000038u,0x0000003au,0x0004003du,0x0000002eu,0x0000003cu,0x00000030u,0x00050085u,0x0000002eu,0x0000003du,0x0000003bu,0x0000003cu,0x0003003eu,0x00000036u,0x0000003du,0x00050041u,0x00000044u,0x00000045u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x00000046u,0x00000045u,0x00040070u,0x00000013u,0x00000047u,0x00000046u,0x0004007fu,0x00000013u,0x00000048u,0x00000047u,0x0006000cu,0x00000013u,0x00000049u,0x00000001u,0x0000001du,0x00000048u,0x0003003eu,0x0000003fu,0x00000049u,0x0004003du,0x0000004cu,0x0000004fu,0x0000004eu,0x0004003du,0x0000002eu,0x00000050u,0x00000036u,0x00070058u,0x00000052u,0x00000053u,0x0000004fu,0x00000050u,0x00000002u,0x00000051u,0x0007004fu,0x0000002eu,0x00000054u,0x00000053u,0x00000053u,0x00000000u,0x00000001u,0x0003003eu,0x0000004au,0x00000054u,0x0004003du,0x0000002eu,0x00000056u,0x0000004au,0x0004003du,0x00000013u,0x00000057u,0x0000003fu,0x0005008eu,0x0000002eu,0x00000058u,0x00000056u,0x00000057u,0x0003003eu,0x00000055u,0x00000058u,0x0003003eu,0x00000059u,0x0000005au,0x0004003du,0x0000002eu,0x0000005cu,0x00000055u,0x0003003eu,0x0000005bu,0x0000005cu,0x0003003eu,0x0000005du,0x0000005eu,0x000200f9u,0x0000005fu,0x000200f8u,0x0000005fu,0x000400f6u,0x00000061u,0x00000062u,0x00000000u,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x0004003du,0x00000006u,0x00000064u,0x0000005du,0x000500b3u,0x00000019u,0x00000066u,0x00000064u,0x00000065u,0x000400fau,0x00000066u,0x00000060u,0x00000061u,0x000200f8u,0x00000060u,0x0003003eu,0x00000067u,0x0000005eu,0x000200f9u,0x00000068u,0x000200f8u,0x00000068u,0x000400f6u,0x0000006au,0x0000006bu,0x00000000u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006cu,0x0004003du,0x00000006u,0x0000006du,0x00000067u,0x000500b3u,0x00000019u,0x0000006eu,0x0000006du,0x00000065u,0x000400fau,0x0000006eu,0x00000069u,0x0000006au,0x000200f8u,0x00000069u,0x0004003du,0x0000002eu,0x00000070u,0x00000055u,0x0004003du,0x00000006u,0x00000071u,0x00000067u,0x0004006fu,0x00000013u,0x00000072u,0x00000071u,0x0004003du,0x00000006u,0x00000073u,0x0000005du,0x0004006fu,0x00000013u,0x00000074u,0x00000073u,0x00050050u,0x0000002eu,0x00000075u,0x00000072u,0x00000074u,0x00050081u,0x0000002eu,0x00000076u,0x00000070u,0x00000075u,0x0003003eu,0x0000006fu,0x00000076u,0x0003003eu,0x00000077u,0x00000051u,0x0003003eu,0x00000078u,0x00000079u,0x000200f9u,0x0000007au,0x000200f8u,0x0000007au,0x000400f6u,0x0000007cu,0x0000007du,0x00000000u,0x000200f9u,0x0000007eu,0x000200f8u,0x0000007eu,0x0004003du,0x00000006u,0x0000007fu,0x00000078u,0x000500b3u,0x00000019u,0x00000080u,0x0000007fu,0x00000043u,0x000400fau,0x00000080u,0x0000007bu,0x0000007cu,0x000200f8u,0x0000007bu,0x0003003eu,0x00000081u,0x00000079u,0x000200f9u,0x00000082u,0x000200f8u,0x00000082u,0x000400f6u,0x00000084u,0x00000085u,0x00000000u,0x000200f9u,0x00000086u,0x000200f8u,0x00000086u,0x0004003du,0x00000006u,0x00000087u,0x00000081u,0x000500b3u,0x00000019u,0x00000088u,0x00000087u,0x00000043u,0x000400fau,0x00000088u,0x00000083u,0x00000084u,0x000200f8u,0x00000083u,0x0004003du,0x00000006u,0x0000008au,0x00000081u,0x0004006fu,0x00000013u,0x0000008bu,0x0000008au,0x0004003du,0x00000006u,0x0000008cu,0x00000078u,0x0004006fu,0x00000013u,0x0000008du,0x0000008cu,0x00050050u,0x0000002eu,0x0000008eu,0x0000008bu,0x0000008du,0x0003003eu,0x00000089u,0x0000008eu,0x0004003du,0x0000004cu,0x00000091u,0x00000090u,0x0004003du,0x0000002eu,0x00000092u,0x00000036u,0x0004003du,0x0000002eu,0x00000093u,0x00000089u,0x0004003du,0x0000002eu,0x00000094u,0x00000030u,0x00050085u,0x0000002eu,0x00000095u,0x00000093u,0x00000094u,0x00050081u,0x0000002eu,0x00000096u,0x00000092u,0x00000095u,0x00070058u,0x00000052u,0x00000097u,0x00000091u,0x00000096u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000098u,0x00000097u,0x00000000u,0x0003003eu,0x0000008fu,0x00000098u,0x0004003du,0x0000004cu,0x0000009bu,0x0000009au,0x0004003du,0x0000002eu,0x0000009cu,0x00000036u,0x0004003du,0x0000002eu,0x0000009du,0x00000089u,0x0004003du,0x0000002eu,0x0000009eu,0x0000006fu,0x00050081u,0x0000002eu,0x0000009fu,0x0000009du,0x0000009eu,0x0004003du,0x0000002eu,0x000000a0u,0x00000030u,0x00050085u,0x0000002eu,0x000000a1u,0x0000009fu,0x000000a0u,0x00050081u,0x0000002eu,0x000000a2u,0x0000009cu,0x000000a1u,0x00070058u,0x00000052u,0x000000a3u,0x0000009bu,0x000000a2u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x000000a4u,0x000000a3u,0x00000000u,0x0003003eu,0x00000099u,0x000000a4u,0x0004003du,0x00000013u,0x000000a5u,0x0000008fu,0x0004003du,0x00000013u,0x000000a6u,0x00000099u,0x00050083u,0x00000013u,0x000000a7u,0x000000a5u,0x000000a6u,0x0006000cu,0x00000013u,0x000000a8u,0x00000001u,0x00000004u,0x000000a7u,0x0004003du,0x00000013u,0x000000a9u,0x00000077u,0x00050081u,0x00000013u,0x000000aau,0x000000a9u,0x000000a8u,0x0003003eu,0x00000077u,0x000000aau,0x000200f9u,0x00000085u,0x000200f8u,0x00000085u,0x0004003du,0x00000006u,0x000000abu,0x00000081u,0x00050080u,0x00000006u,0x000000acu,0x000000abu,0x00000043u,0x0003003eu,0x00000081u,0x000000acu,0x000200f9u,0x00000082u,0x000200f8u,0x00000084u,0x000200f9u,0x0000007du,0x000200f8u,0x0000007du,0x0004003du,0x00000006u,0x000000adu,0x00000078u,0x00050080u,0x00000006u,0x000000aeu,0x000000adu,0x00000043u,0x0003003eu,0x00000078u,0x000000aeu,0x000200f9u,0x0000007au,0x000200f8u,0x0000007cu,0x0004003du,0x00000006u,0x000000b0u,0x00000067u,0x0004006fu,0x00000013u,0x000000b1u,0x000000b0u,0x0006000cu,0x00000013u,0x000000b2u,0x00000001u,0x00000004u,0x000000b1u,0x0004003du,0x00000006u,0x000000b3u,0x0000005du,0x0004006fu,0x00000013u,0x000000b4u,0x000000b3u,0x0006000cu,0x00000013u,0x000000b5u,0x00000001u,0x00000004u,0x000000b4u,0x00050081u,0x00000013u,0x000000b6u,0x000000b2u,0x000000b5u,0x00050085u,0x00000013u,0x000000b7u,0x000000afu,0x000000b6u,0x0004003du,0x00000013u,0x000000b8u,0x00000077u,0x00050081u,0x00000013u,0x000000b9u,0x000000b8u,0x000000b7u,0x0003003eu,0x00000077u,0x000000b9u,0x0004003du,0x00000013u,0x000000bau,0x00000077u,0x0004003du,0x00000013u,0x000000bbu,0x00000059u,0x000500b8u,0x00000019u,0x000000bcu,0x000000bau,0x000000bbu,0x000300f7u,0x000000beu,0x00000000u,0x000400fau,0x000000bcu,0x000000bdu,0x000000beu,0x000200f8u,0x000000bdu,0x0004003du,0x00000013u,0x000000bfu,0x00000077u,0x0003003eu,0x00000059u,0x000000bfu,0x0004003du,0x0000002eu,0x000000c0u,0x0000006fu,0x0003003eu,0x0000005bu,0x000000c0u,0x000200f9u,0x000000beu,0x000200f8u,0x000000beu,0x000200f9u,0x0000006bu,0x000200f8u,0x0000006bu,0x0004003du,0x00000006u,0x000000c1u,0x00000067u,0x00050080u,0x00000006u,0x000000c2u,0x000000c1u,0x00000043u,0x0003003eu,0x00000067u,0x000000c2u,0x000200f9u,0x00000068u,0x000200f8u,0x0000006au,0x000200f9u,0x00000062u,0x000200f8u,0x00000062u,0x0004003du,0x00000006u,0x000000c3u,0x0000005du,0x00050080u,0x00000006u,0x000000c4u,0x000000c3u,0x00000043u,0x0003003eu,0x0000005du,0x000000c4u,0x000200f9u,0x0000005fu,0x000200f8u,0x00000061u,0x00050041u,0x00000044u,0x000000c5u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x000000c6u,0x000000c5u,0x000500aau,0x00000019u,0x000000c7u,0x000000c6u,0x0000001au,0x000300f7u,0x000000c9u,0x00000000u,0x000400fau,0x000000c7u,0x000000c8u,0x000000c9u,0x000200f8u,0x000000c8u,0x0004003du,0x00000013u,0x000000cbu,0x00000059u,0x0003003eu,0x000000cau,0x000000cbu,0x0003003eu,0x000000ccu,0x00000051u,0x0003003eu,0x000000cdu,0x00000051u,0x0003003eu,0x000000ceu,0x00000051u,0x0003003eu,0x000000cfu,0x00000051u,0x0003003eu,0x000000d0u,0x00000079u,0x000200f9u,0x000000d1u,0x000200f8u,0x000000d1u,0x000400f6u,0x000000d3u,0x000000d4u,0x00000000u,0x000200f9u,0x000000d5u,0x000200f8u,0x000000d5u,0x0004003du,0x00000006u,0x000000d6u,0x000000d0u,0x000500b3u,0x00000019u,0x000000d7u,0x000000d6u,0x00000043u,0x000400fau,0x000000d7u,0x000000d2u,0x000000d3u,0x000200f8u,0x000000d2u,0x0003003eu,0x000000d8u,0x00000079u,0x000200f9u,0x000000d9u,0x000200f8u,0x000000d9u,0x000400f6u,0x000000dbu,0x000000dcu,0x00000000u,0x000200f9u,0x000000ddu,0x000200f8u,0x000000ddu,0x0004003du,0x00000006u,0x000000deu,0x000000d8u,0x000500b3u,0x00000019u,0x000000dfu,0x000000deu,0x00000043u,0x000400fau,0x000000dfu,0x000000dau,0x000000dbu,0x000200f8u,0x000000dau,0x0004003du,0x00000006u,0x000000e1u,0x000000d8u,0x0004006fu,0x00000013u,0x000000e2u,0x000000e1u,0x0004003du,0x00000006u,0x000000e3u,0x000000d0u,0x0004006fu,0x00000013u,0x000000e4u,0x000000e3u,0x00050050u,0x0000002eu,0x000000e5u,0x000000e2u,0x000000e4u,0x0003003eu,0x000000e0u,0x000000e5u,0x0004003du,0x0000004cu,0x000000e7u,0x00000090u,0x0004003du,0x0000002eu,0x000000e8u,0x00000036u,0x0004003du,0x0000002eu,0x000000e9u,0x000000e0u,0x0004003du,0x0000002eu,0x000000eau,0x00000030u,0x00050085u,0x0000002eu,0x000000ebu,0x000000e9u,0x000000eau,0x00050081u,0x0000002eu,0x000000ecu,0x000000e8u,0x000000ebu,0x00070058u,0x00000052u,0x000000edu,0x000000e7u,0x000000ecu,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x000000eeu,0x000000edu,0x00000000u,0x0003003eu,0x000000e6u,0x000000eeu,0x0004003du,0x0000002eu,0x000000f0u,0x0000005bu,0x00050081u,0x0000002eu,0x000000f3u,0x000000f0u,0x000000f2u,0x0003003eu,0x000000efu,0x000000f3u,0x0004003du,0x0000002eu,0x000000f5u,0x0000005bu,0x00050081u,0x0000002eu,0x000000f7u,0x000000f5u,0x000000f6u,0x0003003eu,0x000000f4u,0x000000f7u,0x0004003du,0x0000002eu,0x000000f9u,0x0000005bu,0x00050081u,0x0000002eu,0x000000fbu,0x000000f9u,0x000000fau,0x0003003eu,0x000000f8u,0x000000fbu,0x0004003du,0x0000002eu,0x000000fdu,0x0000005bu,0x00050081u,0x0000002eu,0x000000ffu,0x000000fdu,0x000000feu,0x0003003eu,0x000000fcu,0x000000ffu,0x0004003du,0x00000013u,0x00000100u,0x000000e6u,0x0004003du,0x0000004cu,0x00000101u,0x0000009au,0x0004003du,0x0000002eu,0x00000102u,0x00000036u,0x0004003du,0x0000002eu,0x00000103u,0x000000e0u,0x0004003du,0x0000002eu,0x00000104u,0x000000efu,0x00050081u,0x0000002eu,0x00000105u,0x00000103u,0x00000104u,0x0004003du,0x0000002eu,0x00000106u,0x00000030u,0x00050085u,0x0000002eu,0x00000107u,0x00000105u,0x00000106u,0x00050081u,0x0000002eu,0x00000108u,0x00000102u,0x00000107u,0x00070058u,0x00000052u,0x00000109u,0x00000101u,0x00000108u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x0000010au,0x00000109u,0x00000000u,0x00050083u,0x00000013u,0x0000010bu,0x00000100u,0x0000010au,0x0006000cu,0x00000013u,0x0000010cu,0x00000001u,0x00000004u,0x0000010bu,0x0004003du,0x00000013u,0x0000010du,0x000000ccu,0x00050081u,0x00000013u,0x0000010eu,0x0000010du,0x0000010cu,0x0003003eu,0x000000ccu,0x0000010eu,0x0004003du,0x00000013u,0x0000010fu,0x000000e6u,0x0004003du,0x0000004cu,0x00000110u,0x0000009au,0x0004003du,0x0000002eu,0x00000111u,0x00000036u,0x0004003du,0x0000002eu,0x00000112u,0x000000e0u,0x0004003du,0x0000002eu,0x00000113u,0x000000f4u,0x00050081u,0x0000002eu,0x00000114u,0x00000112u,0x00000113u,0x0004003du,0x0000002eu,0x00000115u,0x00000030u,0x00050085u,0x0000002eu,0x00000116u,0x00000114u,0x00000115u,0x00050081u,0x0000002eu,0x00000117u,0x00000111u,0x00000116u,0x00070058u,0x00000052u,0x00000118u,0x00000110u,0x00000117u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000119u,0x00000118u,0x00000000u,0x00050083u,0x00000013u,0x0000011au,0x0000010fu,0x00000119u,0x0006000cu,0x00000013u,0x0000011bu,0x00000001u,0x00000004u,0x0000011au,0x0004003du,0x00000013u,0x0000011cu,0x000000cdu,0x00050081u,0x00000013u,0x0000011du,0x0000011cu,0x0000011bu,0x0003003eu,0x000000cdu,0x0000011du,0x0004003du,0x00000013u,0x0000011eu,0x000000e6u,0x0004003du,0x0000004cu,0x0000011fu,0x0000009au,0x0004003du,0x0000002eu,0x00000120u,0x00000036u,0x0004003du,0x0000002eu,0x00000121u,0x000000e0u,0x0004003du,0x0000002eu,0x00000122u,0x000000f8u,0x00050081u,0x0000002eu,0x00000123u,0x00000121u,0x00000122u,0x0004003du,0x0000002eu,0x00000124u,0x00000030u,0x00050085u,0x0000002eu,0x00000125u,0x00000123u,0x00000124u,0x00050081u,0x0000002eu,0x00000126u,0x00000120u,0x00000125u,0x00070058u,0x00000052u,0x00000127u,0x0000011fu,0x00000126u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000128u,0x00000127u,0x00000000u,0x00050083u,0x00000013u,0x00000129u,0x0000011eu,0x00000128u,0x0006000cu,0x00000013u,0x0000012au,0x00000001u,0x00000004u,0x00000129u,0x0004003du,0x00000013u,0x0000012bu,0x000000ceu,0x00050081u,0x00000013u,0x0000012cu,0x0000012bu,0x0000012au,0x0003003eu,0x000000ceu,0x0000012cu,0x0004003du,0x00000013u,0x0000012du,0x000000e6u,0x0004003du,0x0000004cu,0x0000012eu,0x0000009au,0x0004003du,0x0000002eu,0x0000012fu,0x00000036u,0x0004003du,0x0000002eu,0x00000130u,0x000000e0u,0x0004003du,0x0000002eu,0x00000131u,0x000000fcu,0x00050081u,0x0000002eu,0x00000132u,0x00000130u,0x00000131u,0x0004003du,0x0000002eu,0x00000133u,0x00000030u,0x00050085u,0x0000002eu,0x00000134u,0x00000132u,0x00000133u,0x00050081u,0x0000002eu,0x00000135u,0x0000012fu,0x00000134u,0x00070058u,0x00000052u,0x00000136u,0x0000012eu,0x00000135u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000137u,0x00000136u,0x00000000u,0x00050083u,0x00000013u,0x00000138u,0x0000012du,0x00000137u,0x0006000cu,0x00000013u,0x00000139u,0x00000001u,0x00000004u,0x00000138u,0x0004003du,0x00000013u,0x0000013au,0x000000cfu,0x00050081u,0x00000013u,0x0000013bu,0x0000013au,0x00000139u,0x0003003eu,0x000000cfu,0x0000013bu,0x000200f9u,0x000000dcu,0x000200f8u,0x000000dcu,0x0004003du,0x00000006u,0x0000013cu,0x000000d8u,0x00050080u,0x00000006u,0x0000013du,0x0000013cu,0x00000043u,0x0003003eu,0x000000d8u,0x0000013du,0x000200f9u,0x000000d9u,0x000200f8u,0x000000dbu,0x000200f9u,0x000000d4u,0x000200f8u,0x000000d4u,0x0004003du,0x00000006u,0x0000013eu,0x000000d0u,0x00050080u,0x00000006u,0x0000013fu,0x0000013eu,0x00000043u,0x0003003eu,0x000000d0u,0x0000013fu,0x000200f9u,0x000000d1u,0x000200f8u,0x000000d3u,0x0004003du,0x00000013u,0x00000140u,0x000000ccu,0x00050081u,0x00000013u,0x00000141u,0x00000140u,0x000000afu,0x0003003eu,0x000000ccu,0x00000141u,0x0004003du,0x00000013u,0x00000142u,0x000000cdu,0x00050081u,0x00000013u,0x00000143u,0x00000142u,0x000000afu,0x0003003eu,0x000000cdu,0x00000143u,0x0004003du,0x00000013u,0x00000144u,0x000000ceu,0x00050081u,0x00000013u,0x00000145u,0x00000144u,0x000000afu,0x0003003eu,0x000000ceu,0x00000145u,0x0004003du,0x00000013u,0x00000146u,0x000000cfu,0x00050081u,0x00000013u,0x00000147u,0x00000146u,0x000000afu,0x0003003eu,0x000000cfu,0x00000147u,0x0003003eu,0x00000148u,0x00000051u,0x0003003eu,0x00000149u,0x00000051u,0x0004003du,0x00000013u,0x0000014bu,0x000000ccu,0x0004003du,0x00000013u,0x0000014du,0x000000cau,0x00050085u,0x00000013u,0x0000014eu,0x0000014cu,0x0000014du,0x00050083u,0x00000013u,0x0000014fu,0x0000014bu,0x0000014eu,0x0004003du,0x00000013u,0x00000150u,0x000000cdu,0x00050081u,0x00000013u,0x00000151u,0x0000014fu,0x00000150u,0x0003003eu,0x0000014au,0x00000151u,0x0004003du,0x00000013u,0x00000153u,0x000000ceu,0x0004003du,0x00000013u,0x00000154u,0x000000cau,0x00050085u,0x00000013u,0x00000155u,0x0000014cu,0x00000154u,0x00050083u,0x00000013u,0x00000156u,0x00000153u,0x00000155u,0x0004003du,0x00000013u,0x00000157u,0x000000cfu,0x00050081u,0x00000013u,0x00000158u,0x00000156u,0x00000157u,0x0003003eu,0x00000152u,0x00000158u,0x0004003du,0x00000013u,0x00000159u,0x0000014au,0x000500bau,0x00000019u,0x0000015bu,0x00000159u,0x0000015au,0x000300f7u,0x0000015du,0x00000000u,0x000400fau,0x0000015bu,0x0000015cu,0x0000015du,0x000200f8u,0x0000015cu,0x0004003du,0x00000013u,0x0000015eu,0x000000ccu,0x0004003du,0x00000013u,0x0000015fu,0x000000cdu,0x00050083u,0x00000013u,0x00000160u,0x0000015eu,0x0000015fu,0x00050085u,0x00000013u,0x00000161u,0x00000039u,0x00000160u,0x0004003du,0x00000013u,0x00000162u,0x0000014au,0x00050088u,0x00000013u,0x00000163u,0x00000161u,0x00000162u,0x0008000cu,0x00000013u,0x00000165u,0x00000001u,0x0000002bu,0x00000163u,0x00000164u,0x00000039u,0x0003003eu,0x00000148u,0x00000165u,0x000200f9u,0x0000015du,0x000200f8u,0x0000015du,0x0004003du,0x00000013u,0x00000166u,0x00000152u,0x000500bau,0x00000019u,0x00000167u,0x00000166u,0x0000015au,0x000300f7u,0x00000169u,0x00000000u,0x000400fau,0x00000167u,0x00000168u,0x00000169u,0x000200f8u,0x00000168u,0x0004003du,0x00000013u,0x0000016au,0x000000ceu,0x0004003du,0x00000013u,0x0000016bu,0x000000cfu,0x00050083u,0x00000013u,0x0000016cu,0x0000016au,0x0000016bu,0x00050085u,0x00000013u,0x0000016du,0x00000039u,0x0000016cu,0x0004003du,0x00000013u,0x0000016eu,0x00000152u,0x00050088u,0x00000013u,0x0000016fu,0x0000016du,0x0000016eu,0x0008000cu,0x00000013u,0x00000170u,0x00000001u,0x0000002bu,0x0000016fu,0x00000164u,0x00000039u,0x0003003eu,0x00000149u,0x00000170u,0x000200f9u,0x00000169u,0x000200f8u,0x00000169u,0x0004003du,0x00000013u,0x00000171u,0x00000148u,0x0004003du,0x00000013u,0x00000172u,0x00000149u,0x00050050u,0x0000002eu,0x00000173u,0x00000171u,0x00000172u,0x0004003du,0x0000002eu,0x00000174u,0x0000005bu,0x00050081u,0x0000002eu,0x00000175u,0x00000174u,0x00000173u,0x0003003eu,0x0000005bu,0x00000175u,0x000200f9u,0x000000c9u,0x000200f8u,0x000000c9u,0x0004003du,0x0000002eu,0x00000177u,0x0000005bu,0x00050041u,0x00000044u,0x00000178u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x00000179u,0x00000178u,0x00040070u,0x00000013u,0x0000017au,0x00000179u,0x0006000cu,0x00000013u,0x0000017bu,0x00000001u,0x0000001du,0x0000017au,0x0005008eu,0x0000002eu,0x0000017cu,0x00000177u,0x0000017bu,0x0003003eu,0x00000176u,0x0000017cu,0x0004003du,0x00000014u,0x0000017du,0x00000016u,0x0004003du,0x00000007u,0x0000017eu,0x00000009u,0x0004003du,0x0000002eu,0x0000017fu,0x00000176u,0x00050051u,0x00000013u,0x00000180u,0x0000017fu,0x00000000u,0x00050051u,0x00000013u,0x00000181u,0x0000017fu,0x00000001u,0x00070050u,0x00000052u,0x00000182u,0x00000180u,0x00000181u,0x00000051u,0x00000051u,0x00040063u,0x0000017du,0x0000017eu,0x00000182u,0x000100fdu,0x00010038u}; -static const size_t OF3_FLOW_LEN = 2253; +static const uint32_t OF3_FLOW_SPV[] = { + 0x07230203u,0x00010300u,0x0008000bu,0x000001feu,0x00000000u,0x00020011u,0x00000001u,0x00020011u, + 0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu, + 0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du, + 0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u, + 0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000du,0x475f6c67u, + 0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00040005u,0x00000016u,0x6f6c4675u, + 0x00000077u,0x00030005u,0x00000040u,0x00000055u,0x00060006u,0x00000040u,0x00000000u,0x776f6c66u, + 0x6c616353u,0x00000065u,0x00050006u,0x00000040u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u, + 0x00000040u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000040u,0x00000003u,0x31646170u, + 0x00000000u,0x00030005u,0x00000042u,0x00000000u,0x00050005u,0x0000004eu,0x65725075u,0x74636964u, + 0x0000726fu,0x00050005u,0x0000007bu,0x76657270u,0x63746150u,0x00000068u,0x00050005u,0x0000007du, + 0x6d754c75u,0x65725061u,0x00000076u,0x00050005u,0x000000c9u,0x6d754c75u,0x72754361u,0x00000072u, + 0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u, + 0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u, + 0x00000040u,0x00000002u,0x00050048u,0x00000040u,0x00000000u,0x00000023u,0x00000000u,0x00050048u, + 0x00000040u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000040u,0x00000002u,0x00000023u, + 0x00000008u,0x00050048u,0x00000040u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000042u, + 0x00000021u,0x00000000u,0x00040047u,0x00000042u,0x00000022u,0x00000000u,0x00040047u,0x0000004eu, + 0x00000021u,0x00000022u,0x00040047u,0x0000004eu,0x00000022u,0x00000000u,0x00040047u,0x0000007du, + 0x00000021u,0x00000020u,0x00040047u,0x0000007du,0x00000022u,0x00000000u,0x00040047u,0x000000c9u, + 0x00000021u,0x00000021u,0x00040047u,0x000000c9u,0x00000022u,0x00000000u,0x00040047u,0x000001b3u, + 0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u, + 0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040015u, + 0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u, + 0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u, + 0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u, + 0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u, + 0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u, + 0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x0004002bu,0x0000000au,0x00000024u, + 0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x0004002bu,0x00000013u,0x00000031u, + 0x3f800000u,0x0004002bu,0x00000013u,0x00000039u,0x3f000000u,0x00040020u,0x0000003eu,0x00000007u, + 0x00000013u,0x0006001eu,0x00000040u,0x00000013u,0x0000000au,0x0000000au,0x0000000au,0x00040020u, + 0x00000041u,0x00000002u,0x00000040u,0x0004003bu,0x00000041u,0x00000042u,0x00000002u,0x0004002bu, + 0x00000006u,0x00000043u,0x00000001u,0x00040020u,0x00000044u,0x00000002u,0x0000000au,0x00090019u, + 0x0000004bu,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u, + 0x0003001bu,0x0000004cu,0x0000004bu,0x00040020u,0x0000004du,0x00000000u,0x0000004cu,0x0004003bu, + 0x0000004du,0x0000004eu,0x00000000u,0x0004002bu,0x00000013u,0x00000051u,0x00000000u,0x00040017u, + 0x00000052u,0x00000013u,0x00000004u,0x0004002bu,0x00000006u,0x0000005au,0xffffffffu,0x0004002bu, + 0x00000006u,0x0000006du,0x00000003u,0x0004002bu,0x0000000au,0x00000078u,0x00000009u,0x0004001cu, + 0x00000079u,0x00000013u,0x00000078u,0x00040020u,0x0000007au,0x00000007u,0x00000079u,0x0004003bu, + 0x0000004du,0x0000007du,0x00000000u,0x0004002bu,0x00000013u,0x0000008cu,0x7f7fffffu,0x0004002bu, + 0x00000006u,0x00000090u,0xfffffffdu,0x0004003bu,0x0000004du,0x000000c9u,0x00000000u,0x0004002bu, + 0x00000013u,0x000000deu,0x3bc49ba6u,0x0004002bu,0x00000013u,0x00000120u,0xbf800000u,0x0005002cu, + 0x0000002eu,0x00000121u,0x00000120u,0x00000051u,0x0005002cu,0x0000002eu,0x00000125u,0x00000031u, + 0x00000051u,0x0005002cu,0x0000002eu,0x00000129u,0x00000051u,0x00000120u,0x0005002cu,0x0000002eu, + 0x0000012du,0x00000051u,0x00000031u,0x0004002bu,0x00000013u,0x0000017bu,0x40000000u,0x0004002bu, + 0x00000013u,0x00000189u,0x358637bdu,0x0004002bu,0x00000013u,0x00000193u,0xbf000000u,0x0004002bu, + 0x0000000au,0x000001b2u,0x00000010u,0x0006002cu,0x0000000bu,0x000001b3u,0x000001b2u,0x000001b2u, + 0x00000024u,0x0005002cu,0x0000002eu,0x000001efu,0x00000031u,0x00000031u,0x0005002cu,0x0000002eu, + 0x000001f0u,0x00000039u,0x00000039u,0x00040017u,0x000001fbu,0x00000019u,0x00000002u,0x00050036u, + 0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x0000007au, + 0x0000007bu,0x00000007u,0x000300f7u,0x000001b4u,0x00000000u,0x000300fbu,0x0000001au,0x000001b5u, + 0x000200f8u,0x000001b5u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu, + 0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u, + 0x00000010u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u, + 0x00000017u,0x00050051u,0x00000006u,0x0000001du,0x00000011u,0x00000000u,0x00050051u,0x00000006u, + 0x0000001fu,0x00000018u,0x00000000u,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu, + 0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau, + 0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050051u,0x00000006u,0x00000026u, + 0x00000011u,0x00000001u,0x00050051u,0x00000006u,0x00000028u,0x00000018u,0x00000001u,0x000500afu, + 0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u, + 0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x000001b5u,0x00000029u,0x00000022u,0x000300f7u, + 0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu, + 0x000200f9u,0x000001b4u,0x000200f8u,0x0000002cu,0x0004006fu,0x0000002eu,0x00000033u,0x00000018u, + 0x00050088u,0x0000002eu,0x00000035u,0x000001efu,0x00000033u,0x0004006fu,0x0000002eu,0x00000038u, + 0x00000011u,0x00050081u,0x0000002eu,0x0000003bu,0x00000038u,0x000001f0u,0x00050085u,0x0000002eu, + 0x0000003du,0x0000003bu,0x00000035u,0x00050041u,0x00000044u,0x00000045u,0x00000042u,0x00000043u, + 0x0004003du,0x0000000au,0x00000046u,0x00000045u,0x00040070u,0x00000013u,0x00000047u,0x00000046u, + 0x0004007fu,0x00000013u,0x00000048u,0x00000047u,0x0006000cu,0x00000013u,0x00000049u,0x00000001u, + 0x0000001du,0x00000048u,0x0004003du,0x0000004cu,0x0000004fu,0x0000004eu,0x00070058u,0x00000052u, + 0x00000053u,0x0000004fu,0x0000003du,0x00000002u,0x00000051u,0x0007004fu,0x0000002eu,0x00000054u, + 0x00000053u,0x00000053u,0x00000000u,0x00000001u,0x0005008eu,0x0000002eu,0x00000058u,0x00000054u, + 0x00000049u,0x000200f9u,0x0000005bu,0x000200f8u,0x0000005bu,0x000700f5u,0x00000006u,0x000001beu, + 0x0000005au,0x0000002cu,0x0000008au,0x0000005eu,0x000500b3u,0x00000019u,0x00000061u,0x000001beu, + 0x00000043u,0x000400f6u,0x0000005du,0x0000005eu,0x00000000u,0x000400fau,0x00000061u,0x0000005cu, + 0x0000005du,0x000200f8u,0x0000005cu,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x000700f5u, + 0x00000006u,0x000001e4u,0x0000005au,0x0000005cu,0x00000070u,0x00000064u,0x000500b3u,0x00000019u, + 0x00000069u,0x000001e4u,0x00000043u,0x000400f6u,0x00000065u,0x00000064u,0x00000000u,0x000400fau, + 0x00000069u,0x00000064u,0x00000065u,0x000200f8u,0x00000064u,0x00050080u,0x00000006u,0x0000006cu, + 0x000001beu,0x00000043u,0x00050084u,0x00000006u,0x0000006eu,0x0000006cu,0x0000006du,0x00050080u, + 0x00000006u,0x00000070u,0x000001e4u,0x00000043u,0x00050080u,0x00000006u,0x00000071u,0x0000006eu, + 0x00000070u,0x0004006fu,0x00000013u,0x00000074u,0x000001e4u,0x0004006fu,0x00000013u,0x00000076u, + 0x000001beu,0x00050050u,0x0000002eu,0x00000077u,0x00000074u,0x00000076u,0x0004003du,0x0000004cu, + 0x0000007eu,0x0000007du,0x00050085u,0x0000002eu,0x00000082u,0x00000077u,0x00000035u,0x00050081u, + 0x0000002eu,0x00000083u,0x0000003du,0x00000082u,0x00070058u,0x00000052u,0x00000084u,0x0000007eu, + 0x00000083u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000085u,0x00000084u,0x00000000u, + 0x00050041u,0x0000003eu,0x00000086u,0x0000007bu,0x00000071u,0x0003003eu,0x00000086u,0x00000085u, + 0x000200f9u,0x00000063u,0x000200f8u,0x00000065u,0x000200f9u,0x0000005eu,0x000200f8u,0x0000005eu, + 0x00050080u,0x00000006u,0x0000008au,0x000001beu,0x00000043u,0x000200f9u,0x0000005bu,0x000200f8u, + 0x0000005du,0x000200f9u,0x00000091u,0x000200f8u,0x00000091u,0x000700f5u,0x0000002eu,0x000001cfu, + 0x00000058u,0x0000005du,0x000001e6u,0x00000094u,0x000700f5u,0x00000013u,0x000001c0u,0x0000008cu, + 0x0000005du,0x000001dfu,0x00000094u,0x000700f5u,0x00000006u,0x000001bfu,0x00000090u,0x0000005du, + 0x000000f3u,0x00000094u,0x000500b3u,0x00000019u,0x00000097u,0x000001bfu,0x0000006du,0x000400f6u, + 0x00000093u,0x00000094u,0x00000000u,0x000400fau,0x00000097u,0x00000092u,0x00000093u,0x000200f8u, + 0x00000092u,0x000200f9u,0x00000099u,0x000200f8u,0x00000099u,0x000700f5u,0x00000013u,0x000001dfu, + 0x000001c0u,0x00000092u,0x000001fau,0x0000009cu,0x000700f5u,0x00000006u,0x000001d8u,0x00000090u, + 0x00000092u,0x000000f1u,0x0000009cu,0x000700f5u,0x0000002eu,0x000001e6u,0x000001cfu,0x00000092u, + 0x000001fdu,0x0000009cu,0x000500b3u,0x00000019u,0x0000009fu,0x000001d8u,0x0000006du,0x000400f6u, + 0x0000009bu,0x0000009cu,0x00000000u,0x000400fau,0x0000009fu,0x0000009au,0x0000009bu,0x000200f8u, + 0x0000009au,0x0004006fu,0x00000013u,0x000000a3u,0x000001d8u,0x0004006fu,0x00000013u,0x000000a5u, + 0x000001bfu,0x00050050u,0x0000002eu,0x000000a6u,0x000000a3u,0x000000a5u,0x00050081u,0x0000002eu, + 0x000000a7u,0x00000058u,0x000000a6u,0x000200f9u,0x000000aau,0x000200f8u,0x000000aau,0x000700f5u, + 0x00000013u,0x000001ddu,0x00000051u,0x0000009au,0x000001e3u,0x000000adu,0x000700f5u,0x00000006u, + 0x000001dau,0x0000005au,0x0000009au,0x000000ddu,0x000000adu,0x000500b3u,0x00000019u,0x000000b0u, + 0x000001dau,0x00000043u,0x000400f6u,0x000000acu,0x000000adu,0x00000000u,0x000400fau,0x000000b0u, + 0x000000abu,0x000000acu,0x000200f8u,0x000000abu,0x000200f9u,0x000000b2u,0x000200f8u,0x000000b2u, + 0x000700f5u,0x00000013u,0x000001e3u,0x000001ddu,0x000000abu,0x000000d9u,0x000000b3u,0x000700f5u, + 0x00000006u,0x000001e1u,0x0000005au,0x000000abu,0x000000c4u,0x000000b3u,0x000500b3u,0x00000019u, + 0x000000b8u,0x000001e1u,0x00000043u,0x000400f6u,0x000000b4u,0x000000b3u,0x00000000u,0x000400fau, + 0x000000b8u,0x000000b3u,0x000000b4u,0x000200f8u,0x000000b3u,0x0004006fu,0x00000013u,0x000000bbu, + 0x000001e1u,0x0004006fu,0x00000013u,0x000000bdu,0x000001dau,0x00050050u,0x0000002eu,0x000000beu, + 0x000000bbu,0x000000bdu,0x00050080u,0x00000006u,0x000000c1u,0x000001dau,0x00000043u,0x00050084u, + 0x00000006u,0x000000c2u,0x000000c1u,0x0000006du,0x00050080u,0x00000006u,0x000000c4u,0x000001e1u, + 0x00000043u,0x00050080u,0x00000006u,0x000000c5u,0x000000c2u,0x000000c4u,0x00050041u,0x0000003eu, + 0x000000c6u,0x0000007bu,0x000000c5u,0x0004003du,0x00000013u,0x000000c7u,0x000000c6u,0x0004003du, + 0x0000004cu,0x000000cau,0x000000c9u,0x00050081u,0x0000002eu,0x000000ceu,0x000000beu,0x000000a7u, + 0x00050085u,0x0000002eu,0x000000d0u,0x000000ceu,0x00000035u,0x00050081u,0x0000002eu,0x000000d1u, + 0x0000003du,0x000000d0u,0x00070058u,0x00000052u,0x000000d2u,0x000000cau,0x000000d1u,0x00000002u, + 0x00000051u,0x00050051u,0x00000013u,0x000000d3u,0x000000d2u,0x00000000u,0x00050083u,0x00000013u, + 0x000000d6u,0x000000c7u,0x000000d3u,0x0006000cu,0x00000013u,0x000000d7u,0x00000001u,0x00000004u, + 0x000000d6u,0x00050081u,0x00000013u,0x000000d9u,0x000001e3u,0x000000d7u,0x000200f9u,0x000000b2u, + 0x000200f8u,0x000000b4u,0x000200f9u,0x000000adu,0x000200f8u,0x000000adu,0x00050080u,0x00000006u, + 0x000000ddu,0x000001dau,0x00000043u,0x000200f9u,0x000000aau,0x000200f8u,0x000000acu,0x0006000cu, + 0x00000013u,0x000000e1u,0x00000001u,0x00000004u,0x000000a3u,0x0006000cu,0x00000013u,0x000000e4u, + 0x00000001u,0x00000004u,0x000000a5u,0x00050081u,0x00000013u,0x000000e5u,0x000000e1u,0x000000e4u, + 0x00050085u,0x00000013u,0x000000e6u,0x000000deu,0x000000e5u,0x00050081u,0x00000013u,0x000000e8u, + 0x000001ddu,0x000000e6u,0x000500b8u,0x00000019u,0x000000ebu,0x000000e8u,0x000001dfu,0x000600a9u, + 0x00000013u,0x000001fau,0x000000ebu,0x000000e8u,0x000001dfu,0x00050050u,0x000001fbu,0x000001fcu, + 0x000000ebu,0x000000ebu,0x000600a9u,0x0000002eu,0x000001fdu,0x000001fcu,0x000000a7u,0x000001e6u, + 0x000200f9u,0x0000009cu,0x000200f8u,0x0000009cu,0x00050080u,0x00000006u,0x000000f1u,0x000001d8u, + 0x00000043u,0x000200f9u,0x00000099u,0x000200f8u,0x0000009bu,0x000200f9u,0x00000094u,0x000200f8u, + 0x00000094u,0x00050080u,0x00000006u,0x000000f3u,0x000001bfu,0x00000043u,0x000200f9u,0x00000091u, + 0x000200f8u,0x00000093u,0x000500aau,0x00000019u,0x000000f6u,0x00000046u,0x0000001au,0x000300f7u, + 0x000000f8u,0x00000000u,0x000400fau,0x000000f6u,0x000000f7u,0x000000f8u,0x000200f8u,0x000000f7u, + 0x000200f9u,0x00000100u,0x000200f8u,0x00000100u,0x000700f5u,0x00000013u,0x000001c5u,0x00000051u, + 0x000000f7u,0x000001d7u,0x00000103u,0x000700f5u,0x00000013u,0x000001c4u,0x00000051u,0x000000f7u, + 0x000001d6u,0x00000103u,0x000700f5u,0x00000013u,0x000001c3u,0x00000051u,0x000000f7u,0x000001d5u, + 0x00000103u,0x000700f5u,0x00000013u,0x000001c2u,0x00000051u,0x000000f7u,0x000001d4u,0x00000103u, + 0x000700f5u,0x00000006u,0x000001c1u,0x0000005au,0x000000f7u,0x0000016eu,0x00000103u,0x000500b3u, + 0x00000019u,0x00000106u,0x000001c1u,0x00000043u,0x000400f6u,0x00000102u,0x00000103u,0x00000000u, + 0x000400fau,0x00000106u,0x00000101u,0x00000102u,0x000200f8u,0x00000101u,0x000200f9u,0x00000108u, + 0x000200f8u,0x00000108u,0x000700f5u,0x00000013u,0x000001d7u,0x000001c5u,0x00000101u,0x0000016au, + 0x00000109u,0x000700f5u,0x00000013u,0x000001d6u,0x000001c4u,0x00000101u,0x0000015bu,0x00000109u, + 0x000700f5u,0x00000013u,0x000001d5u,0x000001c3u,0x00000101u,0x0000014cu,0x00000109u,0x000700f5u, + 0x00000013u,0x000001d4u,0x000001c2u,0x00000101u,0x0000013du,0x00000109u,0x000700f5u,0x00000006u, + 0x000001d1u,0x0000005au,0x00000101u,0x0000011au,0x00000109u,0x000500b3u,0x00000019u,0x0000010eu, + 0x000001d1u,0x00000043u,0x000400f6u,0x0000010au,0x00000109u,0x00000000u,0x000400fau,0x0000010eu, + 0x00000109u,0x0000010au,0x000200f8u,0x00000109u,0x0004006fu,0x00000013u,0x00000111u,0x000001d1u, + 0x0004006fu,0x00000013u,0x00000113u,0x000001c1u,0x00050050u,0x0000002eu,0x00000114u,0x00000111u, + 0x00000113u,0x00050080u,0x00000006u,0x00000117u,0x000001c1u,0x00000043u,0x00050084u,0x00000006u, + 0x00000118u,0x00000117u,0x0000006du,0x00050080u,0x00000006u,0x0000011au,0x000001d1u,0x00000043u, + 0x00050080u,0x00000006u,0x0000011bu,0x00000118u,0x0000011au,0x00050041u,0x0000003eu,0x0000011cu, + 0x0000007bu,0x0000011bu,0x0004003du,0x00000013u,0x0000011du,0x0000011cu,0x00050081u,0x0000002eu, + 0x00000122u,0x000001cfu,0x00000121u,0x00050081u,0x0000002eu,0x00000126u,0x000001cfu,0x00000125u, + 0x00050081u,0x0000002eu,0x0000012au,0x000001cfu,0x00000129u,0x00050081u,0x0000002eu,0x0000012eu, + 0x000001cfu,0x0000012du,0x0004003du,0x0000004cu,0x00000130u,0x000000c9u,0x00050081u,0x0000002eu, + 0x00000134u,0x00000114u,0x00000122u,0x00050085u,0x0000002eu,0x00000136u,0x00000134u,0x00000035u, + 0x00050081u,0x0000002eu,0x00000137u,0x0000003du,0x00000136u,0x00070058u,0x00000052u,0x00000138u, + 0x00000130u,0x00000137u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000139u,0x00000138u, + 0x00000000u,0x00050083u,0x00000013u,0x0000013au,0x0000011du,0x00000139u,0x0006000cu,0x00000013u, + 0x0000013bu,0x00000001u,0x00000004u,0x0000013au,0x00050081u,0x00000013u,0x0000013du,0x000001d4u, + 0x0000013bu,0x0004003du,0x0000004cu,0x0000013fu,0x000000c9u,0x00050081u,0x0000002eu,0x00000143u, + 0x00000114u,0x00000126u,0x00050085u,0x0000002eu,0x00000145u,0x00000143u,0x00000035u,0x00050081u, + 0x0000002eu,0x00000146u,0x0000003du,0x00000145u,0x00070058u,0x00000052u,0x00000147u,0x0000013fu, + 0x00000146u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000148u,0x00000147u,0x00000000u, + 0x00050083u,0x00000013u,0x00000149u,0x0000011du,0x00000148u,0x0006000cu,0x00000013u,0x0000014au, + 0x00000001u,0x00000004u,0x00000149u,0x00050081u,0x00000013u,0x0000014cu,0x000001d5u,0x0000014au, + 0x0004003du,0x0000004cu,0x0000014eu,0x000000c9u,0x00050081u,0x0000002eu,0x00000152u,0x00000114u, + 0x0000012au,0x00050085u,0x0000002eu,0x00000154u,0x00000152u,0x00000035u,0x00050081u,0x0000002eu, + 0x00000155u,0x0000003du,0x00000154u,0x00070058u,0x00000052u,0x00000156u,0x0000014eu,0x00000155u, + 0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000157u,0x00000156u,0x00000000u,0x00050083u, + 0x00000013u,0x00000158u,0x0000011du,0x00000157u,0x0006000cu,0x00000013u,0x00000159u,0x00000001u, + 0x00000004u,0x00000158u,0x00050081u,0x00000013u,0x0000015bu,0x000001d6u,0x00000159u,0x0004003du, + 0x0000004cu,0x0000015du,0x000000c9u,0x00050081u,0x0000002eu,0x00000161u,0x00000114u,0x0000012eu, + 0x00050085u,0x0000002eu,0x00000163u,0x00000161u,0x00000035u,0x00050081u,0x0000002eu,0x00000164u, + 0x0000003du,0x00000163u,0x00070058u,0x00000052u,0x00000165u,0x0000015du,0x00000164u,0x00000002u, + 0x00000051u,0x00050051u,0x00000013u,0x00000166u,0x00000165u,0x00000000u,0x00050083u,0x00000013u, + 0x00000167u,0x0000011du,0x00000166u,0x0006000cu,0x00000013u,0x00000168u,0x00000001u,0x00000004u, + 0x00000167u,0x00050081u,0x00000013u,0x0000016au,0x000001d7u,0x00000168u,0x000200f9u,0x00000108u, + 0x000200f8u,0x0000010au,0x000200f9u,0x00000103u,0x000200f8u,0x00000103u,0x00050080u,0x00000006u, + 0x0000016eu,0x000001c1u,0x00000043u,0x000200f9u,0x00000100u,0x000200f8u,0x00000102u,0x00050081u, + 0x00000013u,0x00000170u,0x000001c2u,0x000000deu,0x00050081u,0x00000013u,0x00000172u,0x000001c3u, + 0x000000deu,0x00050081u,0x00000013u,0x00000174u,0x000001c4u,0x000000deu,0x00050081u,0x00000013u, + 0x00000176u,0x000001c5u,0x000000deu,0x00050085u,0x00000013u,0x0000017du,0x0000017bu,0x000001c0u, + 0x00050083u,0x00000013u,0x0000017eu,0x00000170u,0x0000017du,0x00050081u,0x00000013u,0x00000180u, + 0x0000017eu,0x00000172u,0x00050083u,0x00000013u,0x00000185u,0x00000174u,0x0000017du,0x00050081u, + 0x00000013u,0x00000187u,0x00000185u,0x00000176u,0x000500bau,0x00000019u,0x0000018au,0x00000180u, + 0x00000189u,0x000300f7u,0x0000018cu,0x00000000u,0x000400fau,0x0000018au,0x0000018bu,0x0000018cu, + 0x000200f8u,0x0000018bu,0x00050083u,0x00000013u,0x000001f8u,0x000001c2u,0x000001c3u,0x00050085u, + 0x00000013u,0x00000190u,0x00000039u,0x000001f8u,0x00050088u,0x00000013u,0x00000192u,0x00000190u, + 0x00000180u,0x0008000cu,0x00000013u,0x00000194u,0x00000001u,0x0000002bu,0x00000192u,0x00000193u, + 0x00000039u,0x000200f9u,0x0000018cu,0x000200f8u,0x0000018cu,0x000700f5u,0x00000013u,0x000001c9u, + 0x00000051u,0x00000102u,0x00000194u,0x0000018bu,0x000500bau,0x00000019u,0x00000196u,0x00000187u, + 0x00000189u,0x000300f7u,0x00000198u,0x00000000u,0x000400fau,0x00000196u,0x00000197u,0x00000198u, + 0x000200f8u,0x00000197u,0x00050083u,0x00000013u,0x000001f9u,0x000001c4u,0x000001c5u,0x00050085u, + 0x00000013u,0x0000019cu,0x00000039u,0x000001f9u,0x00050088u,0x00000013u,0x0000019eu,0x0000019cu, + 0x00000187u,0x0008000cu,0x00000013u,0x0000019fu,0x00000001u,0x0000002bu,0x0000019eu,0x00000193u, + 0x00000039u,0x000200f9u,0x00000198u,0x000200f8u,0x00000198u,0x000700f5u,0x00000013u,0x000001cau, + 0x00000051u,0x0000018cu,0x0000019fu,0x00000197u,0x00050050u,0x0000002eu,0x000001a2u,0x000001c9u, + 0x000001cau,0x00050081u,0x0000002eu,0x000001a4u,0x000001cfu,0x000001a2u,0x000200f9u,0x000000f8u, + 0x000200f8u,0x000000f8u,0x000700f5u,0x0000002eu,0x000001d0u,0x000001cfu,0x00000093u,0x000001a4u, + 0x00000198u,0x0006000cu,0x00000013u,0x000001aau,0x00000001u,0x0000001du,0x00000047u,0x0005008eu, + 0x0000002eu,0x000001abu,0x000001d0u,0x000001aau,0x0004003du,0x00000014u,0x000001acu,0x00000016u, + 0x00050051u,0x00000013u,0x000001afu,0x000001abu,0x00000000u,0x00050051u,0x00000013u,0x000001b0u, + 0x000001abu,0x00000001u,0x00070050u,0x00000052u,0x000001b1u,0x000001afu,0x000001b0u,0x00000051u, + 0x00000051u,0x00040063u,0x000001acu,0x00000011u,0x000001b1u,0x000200f9u,0x000001b4u,0x000200f8u, + 0x000001b4u,0x000100fdu,0x00010038u +}; +static const size_t OF3_FLOW_LEN = sizeof(OF3_FLOW_SPV) / sizeof(OF3_FLOW_SPV[0]); static const uint32_t OF3_EXPAND_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000124u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000049u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000eu,0x3564656du,0x3b316628u,0x663b3166u,0x31663b31u,0x3b31663bu,0x00000000u,0x00030005u,0x00000009u,0x00000061u,0x00030005u,0x0000000au,0x00000062u,0x00030005u,0x0000000bu,0x00000063u,0x00030005u,0x0000000cu,0x00000064u,0x00030005u,0x0000000du,0x00000065u,0x00030005u,0x00000010u,0x00000078u,0x00030005u,0x00000034u,0x00000079u,0x00030005u,0x00000045u,0x00646967u,0x00080005u,0x00000049u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000004eu,0x006d6964u,0x00040005u,0x00000051u,0x64774675u,0x00000000u,0x00030005u,0x0000006bu,0x00007675u,0x00030005u,0x00000074u,0x00007366u,0x00050005u,0x00000079u,0x6f6c4675u,0x6e694677u,0x00000065u,0x00030005u,0x00000081u,0x00000063u,0x00030005u,0x00000088u,0x00006d78u,0x00030005u,0x00000091u,0x00007078u,0x00030005u,0x0000009au,0x00006d79u,0x00030005u,0x000000a3u,0x00007079u,0x00030005u,0x000000acu,0x00000064u,0x00040005u,0x000000adu,0x61726170u,0x0000006du,0x00040005u,0x000000b0u,0x61726170u,0x0000006du,0x00040005u,0x000000b3u,0x61726170u,0x0000006du,0x00040005u,0x000000b6u,0x61726170u,0x0000006du,0x00040005u,0x000000b9u,0x61726170u,0x0000006du,0x00040005u,0x000000bdu,0x61726170u,0x0000006du,0x00040005u,0x000000c0u,0x61726170u,0x0000006du,0x00040005u,0x000000c3u,0x61726170u,0x0000006du,0x00040005u,0x000000c6u,0x61726170u,0x0000006du,0x00040005u,0x000000c9u,0x61726170u,0x0000006du,0x00030005u,0x000000ceu,0x00000071u,0x00030005u,0x000000d2u,0x00787067u,0x00030005u,0x000000d3u,0x00004d47u,0x00050006u,0x000000d3u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x000000d3u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x000000d3u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x000000d3u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x000000d5u,0x00000000u,0x00030005u,0x000000fdu,0x00003241u,0x00040005u,0x0000010bu,0x6c6c7566u,0x00000000u,0x00040005u,0x00000117u,0x64774275u,0x00000000u,0x00030005u,0x00000121u,0x00000055u,0x00060006u,0x00000121u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000121u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000121u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000121u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000123u,0x00000000u,0x00040047u,0x00000049u,0x0000000bu,0x0000001cu,0x00030047u,0x00000051u,0x00000019u,0x00040047u,0x00000051u,0x00000021u,0x00000030u,0x00040047u,0x00000051u,0x00000022u,0x00000000u,0x00040047u,0x00000079u,0x00000021u,0x00000020u,0x00040047u,0x00000079u,0x00000022u,0x00000000u,0x00030047u,0x000000d3u,0x00000002u,0x00050048u,0x000000d3u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x000000d3u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x000000d3u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x000000d3u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x000000d5u,0x00000021u,0x00000001u,0x00040047u,0x000000d5u,0x00000022u,0x00000000u,0x00030047u,0x00000117u,0x00000019u,0x00040047u,0x00000117u,0x00000021u,0x00000031u,0x00040047u,0x00000117u,0x00000022u,0x00000000u,0x00040047u,0x00000120u,0x0000000bu,0x00000019u,0x00030047u,0x00000121u,0x00000002u,0x00050048u,0x00000121u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000121u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000121u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000121u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000123u,0x00000021u,0x00000000u,0x00040047u,0x00000123u,0x00000022u,0x00000000u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00080021u,0x00000008u,0x00000006u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00040015u,0x00000042u,0x00000020u,0x00000001u,0x00040017u,0x00000043u,0x00000042u,0x00000002u,0x00040020u,0x00000044u,0x00000007u,0x00000043u,0x00040015u,0x00000046u,0x00000020u,0x00000000u,0x00040017u,0x00000047u,0x00000046u,0x00000003u,0x00040020u,0x00000048u,0x00000001u,0x00000047u,0x0004003bu,0x00000048u,0x00000049u,0x00000001u,0x00040017u,0x0000004au,0x00000046u,0x00000002u,0x00090019u,0x0000004fu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000050u,0x00000000u,0x0000004fu,0x0004003bu,0x00000050u,0x00000051u,0x00000000u,0x00020014u,0x00000054u,0x0004002bu,0x00000046u,0x00000055u,0x00000000u,0x00040020u,0x00000056u,0x00000007u,0x00000042u,0x0004002bu,0x00000046u,0x0000005fu,0x00000001u,0x00040017u,0x00000069u,0x00000006u,0x00000002u,0x00040020u,0x0000006au,0x00000007u,0x00000069u,0x0004002bu,0x00000006u,0x0000006eu,0x3f000000u,0x0004002bu,0x00000006u,0x00000075u,0x3f800000u,0x00090019u,0x00000076u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000077u,0x00000076u,0x00040020u,0x00000078u,0x00000000u,0x00000077u,0x0004003bu,0x00000078u,0x00000079u,0x00000000u,0x0004002bu,0x00000042u,0x0000007bu,0x00000000u,0x0004002bu,0x00000006u,0x00000084u,0x00000000u,0x00040017u,0x00000085u,0x00000006u,0x00000004u,0x0006001eu,0x000000d3u,0x00000085u,0x00000085u,0x00000085u,0x00000085u,0x00040020u,0x000000d4u,0x00000002u,0x000000d3u,0x0004003bu,0x000000d4u,0x000000d5u,0x00000002u,0x0004002bu,0x00000042u,0x000000d6u,0x00000002u,0x00040020u,0x000000d7u,0x00000002u,0x00000006u,0x0004002bu,0x00000046u,0x000000ddu,0x00000002u,0x0004002bu,0x00000042u,0x000000e4u,0x00000003u,0x0004002bu,0x00000046u,0x000000edu,0x00000003u,0x00040018u,0x000000fbu,0x00000069u,0x00000002u,0x00040020u,0x000000fcu,0x00000007u,0x000000fbu,0x0004003bu,0x00000050u,0x00000117u,0x00000000u,0x0004002bu,0x00000046u,0x0000011fu,0x00000010u,0x0006002cu,0x00000047u,0x00000120u,0x0000011fu,0x0000011fu,0x0000005fu,0x0006001eu,0x00000121u,0x00000006u,0x00000046u,0x00000046u,0x00000046u,0x00040020u,0x00000122u,0x00000002u,0x00000121u,0x0004003bu,0x00000122u,0x00000123u,0x00000002u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000044u,0x00000045u,0x00000007u,0x0004003bu,0x00000044u,0x0000004eu,0x00000007u,0x0004003bu,0x0000006au,0x0000006bu,0x00000007u,0x0004003bu,0x0000006au,0x00000074u,0x00000007u,0x0004003bu,0x0000006au,0x00000081u,0x00000007u,0x0004003bu,0x0000006au,0x00000088u,0x00000007u,0x0004003bu,0x0000006au,0x00000091u,0x00000007u,0x0004003bu,0x0000006au,0x0000009au,0x00000007u,0x0004003bu,0x0000006au,0x000000a3u,0x00000007u,0x0004003bu,0x0000006au,0x000000acu,0x00000007u,0x0004003bu,0x00000007u,0x000000adu,0x00000007u,0x0004003bu,0x00000007u,0x000000b0u,0x00000007u,0x0004003bu,0x00000007u,0x000000b3u,0x00000007u,0x0004003bu,0x00000007u,0x000000b6u,0x00000007u,0x0004003bu,0x00000007u,0x000000b9u,0x00000007u,0x0004003bu,0x00000007u,0x000000bdu,0x00000007u,0x0004003bu,0x00000007u,0x000000c0u,0x00000007u,0x0004003bu,0x00000007u,0x000000c3u,0x00000007u,0x0004003bu,0x00000007u,0x000000c6u,0x00000007u,0x0004003bu,0x00000007u,0x000000c9u,0x00000007u,0x0004003bu,0x0000006au,0x000000ceu,0x00000007u,0x0004003bu,0x0000006au,0x000000d2u,0x00000007u,0x0004003bu,0x000000fcu,0x000000fdu,0x00000007u,0x0004003bu,0x0000006au,0x0000010bu,0x00000007u,0x0004003du,0x00000047u,0x0000004bu,0x00000049u,0x0007004fu,0x0000004au,0x0000004cu,0x0000004bu,0x0000004bu,0x00000000u,0x00000001u,0x0004007cu,0x00000043u,0x0000004du,0x0000004cu,0x0003003eu,0x00000045u,0x0000004du,0x0004003du,0x0000004fu,0x00000052u,0x00000051u,0x00040068u,0x00000043u,0x00000053u,0x00000052u,0x0003003eu,0x0000004eu,0x00000053u,0x00050041u,0x00000056u,0x00000057u,0x00000045u,0x00000055u,0x0004003du,0x00000042u,0x00000058u,0x00000057u,0x00050041u,0x00000056u,0x00000059u,0x0000004eu,0x00000055u,0x0004003du,0x00000042u,0x0000005au,0x00000059u,0x000500afu,0x00000054u,0x0000005bu,0x00000058u,0x0000005au,0x000400a8u,0x00000054u,0x0000005cu,0x0000005bu,0x000300f7u,0x0000005eu,0x00000000u,0x000400fau,0x0000005cu,0x0000005du,0x0000005eu,0x000200f8u,0x0000005du,0x00050041u,0x00000056u,0x00000060u,0x00000045u,0x0000005fu,0x0004003du,0x00000042u,0x00000061u,0x00000060u,0x00050041u,0x00000056u,0x00000062u,0x0000004eu,0x0000005fu,0x0004003du,0x00000042u,0x00000063u,0x00000062u,0x000500afu,0x00000054u,0x00000064u,0x00000061u,0x00000063u,0x000200f9u,0x0000005eu,0x000200f8u,0x0000005eu,0x000700f5u,0x00000054u,0x00000065u,0x0000005bu,0x00000005u,0x00000064u,0x0000005du,0x000300f7u,0x00000067u,0x00000000u,0x000400fau,0x00000065u,0x00000066u,0x00000067u,0x000200f8u,0x00000066u,0x000100fdu,0x000200f8u,0x00000067u,0x0004003du,0x00000043u,0x0000006cu,0x00000045u,0x0004006fu,0x00000069u,0x0000006du,0x0000006cu,0x00050050u,0x00000069u,0x0000006fu,0x0000006eu,0x0000006eu,0x00050081u,0x00000069u,0x00000070u,0x0000006du,0x0000006fu,0x0004003du,0x00000043u,0x00000071u,0x0000004eu,0x0004006fu,0x00000069u,0x00000072u,0x00000071u,0x00050088u,0x00000069u,0x00000073u,0x00000070u,0x00000072u,0x0003003eu,0x0000006bu,0x00000073u,0x0004003du,0x00000077u,0x0000007au,0x00000079u,0x00040064u,0x00000076u,0x0000007cu,0x0000007au,0x00050067u,0x00000043u,0x0000007du,0x0000007cu,0x0000007bu,0x0004006fu,0x00000069u,0x0000007eu,0x0000007du,0x00050050u,0x00000069u,0x0000007fu,0x00000075u,0x00000075u,0x00050088u,0x00000069u,0x00000080u,0x0000007fu,0x0000007eu,0x0003003eu,0x00000074u,0x00000080u,0x0004003du,0x00000077u,0x00000082u,0x00000079u,0x0004003du,0x00000069u,0x00000083u,0x0000006bu,0x00070058u,0x00000085u,0x00000086u,0x00000082u,0x00000083u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000087u,0x00000086u,0x00000086u,0x00000000u,0x00000001u,0x0003003eu,0x00000081u,0x00000087u,0x0004003du,0x00000077u,0x00000089u,0x00000079u,0x0004003du,0x00000069u,0x0000008au,0x0000006bu,0x00050041u,0x00000007u,0x0000008bu,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x0000008cu,0x0000008bu,0x00050050u,0x00000069u,0x0000008du,0x0000008cu,0x00000084u,0x00050083u,0x00000069u,0x0000008eu,0x0000008au,0x0000008du,0x00070058u,0x00000085u,0x0000008fu,0x00000089u,0x0000008eu,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000090u,0x0000008fu,0x0000008fu,0x00000000u,0x00000001u,0x0003003eu,0x00000088u,0x00000090u,0x0004003du,0x00000077u,0x00000092u,0x00000079u,0x0004003du,0x00000069u,0x00000093u,0x0000006bu,0x00050041u,0x00000007u,0x00000094u,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x00000095u,0x00000094u,0x00050050u,0x00000069u,0x00000096u,0x00000095u,0x00000084u,0x00050081u,0x00000069u,0x00000097u,0x00000093u,0x00000096u,0x00070058u,0x00000085u,0x00000098u,0x00000092u,0x00000097u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000099u,0x00000098u,0x00000098u,0x00000000u,0x00000001u,0x0003003eu,0x00000091u,0x00000099u,0x0004003du,0x00000077u,0x0000009bu,0x00000079u,0x0004003du,0x00000069u,0x0000009cu,0x0000006bu,0x00050041u,0x00000007u,0x0000009du,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x0000009eu,0x0000009du,0x00050050u,0x00000069u,0x0000009fu,0x00000084u,0x0000009eu,0x00050083u,0x00000069u,0x000000a0u,0x0000009cu,0x0000009fu,0x00070058u,0x00000085u,0x000000a1u,0x0000009bu,0x000000a0u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x000000a2u,0x000000a1u,0x000000a1u,0x00000000u,0x00000001u,0x0003003eu,0x0000009au,0x000000a2u,0x0004003du,0x00000077u,0x000000a4u,0x00000079u,0x0004003du,0x00000069u,0x000000a5u,0x0000006bu,0x00050041u,0x00000007u,0x000000a6u,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x000000a7u,0x000000a6u,0x00050050u,0x00000069u,0x000000a8u,0x00000084u,0x000000a7u,0x00050081u,0x00000069u,0x000000a9u,0x000000a5u,0x000000a8u,0x00070058u,0x00000085u,0x000000aau,0x000000a4u,0x000000a9u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x000000abu,0x000000aau,0x000000aau,0x00000000u,0x00000001u,0x0003003eu,0x000000a3u,0x000000abu,0x00050041u,0x00000007u,0x000000aeu,0x00000081u,0x00000055u,0x0004003du,0x00000006u,0x000000afu,0x000000aeu,0x0003003eu,0x000000adu,0x000000afu,0x00050041u,0x00000007u,0x000000b1u,0x00000088u,0x00000055u,0x0004003du,0x00000006u,0x000000b2u,0x000000b1u,0x0003003eu,0x000000b0u,0x000000b2u,0x00050041u,0x00000007u,0x000000b4u,0x00000091u,0x00000055u,0x0004003du,0x00000006u,0x000000b5u,0x000000b4u,0x0003003eu,0x000000b3u,0x000000b5u,0x00050041u,0x00000007u,0x000000b7u,0x0000009au,0x00000055u,0x0004003du,0x00000006u,0x000000b8u,0x000000b7u,0x0003003eu,0x000000b6u,0x000000b8u,0x00050041u,0x00000007u,0x000000bau,0x000000a3u,0x00000055u,0x0004003du,0x00000006u,0x000000bbu,0x000000bau,0x0003003eu,0x000000b9u,0x000000bbu,0x00090039u,0x00000006u,0x000000bcu,0x0000000eu,0x000000adu,0x000000b0u,0x000000b3u,0x000000b6u,0x000000b9u,0x00050041u,0x00000007u,0x000000beu,0x00000081u,0x0000005fu,0x0004003du,0x00000006u,0x000000bfu,0x000000beu,0x0003003eu,0x000000bdu,0x000000bfu,0x00050041u,0x00000007u,0x000000c1u,0x00000088u,0x0000005fu,0x0004003du,0x00000006u,0x000000c2u,0x000000c1u,0x0003003eu,0x000000c0u,0x000000c2u,0x00050041u,0x00000007u,0x000000c4u,0x00000091u,0x0000005fu,0x0004003du,0x00000006u,0x000000c5u,0x000000c4u,0x0003003eu,0x000000c3u,0x000000c5u,0x00050041u,0x00000007u,0x000000c7u,0x0000009au,0x0000005fu,0x0004003du,0x00000006u,0x000000c8u,0x000000c7u,0x0003003eu,0x000000c6u,0x000000c8u,0x00050041u,0x00000007u,0x000000cau,0x000000a3u,0x0000005fu,0x0004003du,0x00000006u,0x000000cbu,0x000000cau,0x0003003eu,0x000000c9u,0x000000cbu,0x00090039u,0x00000006u,0x000000ccu,0x0000000eu,0x000000bdu,0x000000c0u,0x000000c3u,0x000000c6u,0x000000c9u,0x00050050u,0x00000069u,0x000000cdu,0x000000bcu,0x000000ccu,0x0003003eu,0x000000acu,0x000000cdu,0x0004003du,0x00000069u,0x000000cfu,0x0000006bu,0x00050050u,0x00000069u,0x000000d0u,0x0000006eu,0x0000006eu,0x00050083u,0x00000069u,0x000000d1u,0x000000cfu,0x000000d0u,0x0003003eu,0x000000ceu,0x000000d1u,0x00060041u,0x000000d7u,0x000000d8u,0x000000d5u,0x000000d6u,0x00000055u,0x0004003du,0x00000006u,0x000000d9u,0x000000d8u,0x00050041u,0x00000007u,0x000000dau,0x000000ceu,0x00000055u,0x0004003du,0x00000006u,0x000000dbu,0x000000dau,0x00050085u,0x00000006u,0x000000dcu,0x000000d9u,0x000000dbu,0x00060041u,0x000000d7u,0x000000deu,0x000000d5u,0x000000d6u,0x000000ddu,0x0004003du,0x00000006u,0x000000dfu,0x000000deu,0x00050041u,0x00000007u,0x000000e0u,0x000000ceu,0x0000005fu,0x0004003du,0x00000006u,0x000000e1u,0x000000e0u,0x00050085u,0x00000006u,0x000000e2u,0x000000dfu,0x000000e1u,0x00050081u,0x00000006u,0x000000e3u,0x000000dcu,0x000000e2u,0x00060041u,0x000000d7u,0x000000e5u,0x000000d5u,0x000000e4u,0x00000055u,0x0004003du,0x00000006u,0x000000e6u,0x000000e5u,0x00050081u,0x00000006u,0x000000e7u,0x000000e3u,0x000000e6u,0x00060041u,0x000000d7u,0x000000e8u,0x000000d5u,0x000000d6u,0x0000005fu,0x0004003du,0x00000006u,0x000000e9u,0x000000e8u,0x00050041u,0x00000007u,0x000000eau,0x000000ceu,0x00000055u,0x0004003du,0x00000006u,0x000000ebu,0x000000eau,0x00050085u,0x00000006u,0x000000ecu,0x000000e9u,0x000000ebu,0x00060041u,0x000000d7u,0x000000eeu,0x000000d5u,0x000000d6u,0x000000edu,0x0004003du,0x00000006u,0x000000efu,0x000000eeu,0x00050041u,0x00000007u,0x000000f0u,0x000000ceu,0x0000005fu,0x0004003du,0x00000006u,0x000000f1u,0x000000f0u,0x00050085u,0x00000006u,0x000000f2u,0x000000efu,0x000000f1u,0x00050081u,0x00000006u,0x000000f3u,0x000000ecu,0x000000f2u,0x00060041u,0x000000d7u,0x000000f4u,0x000000d5u,0x000000e4u,0x0000005fu,0x0004003du,0x00000006u,0x000000f5u,0x000000f4u,0x00050081u,0x00000006u,0x000000f6u,0x000000f3u,0x000000f5u,0x00050050u,0x00000069u,0x000000f7u,0x000000e7u,0x000000f6u,0x0004003du,0x00000043u,0x000000f8u,0x0000004eu,0x0004006fu,0x00000069u,0x000000f9u,0x000000f8u,0x00050085u,0x00000069u,0x000000fau,0x000000f7u,0x000000f9u,0x0003003eu,0x000000d2u,0x000000fau,0x00060041u,0x000000d7u,0x000000feu,0x000000d5u,0x000000d6u,0x00000055u,0x0004003du,0x00000006u,0x000000ffu,0x000000feu,0x00050081u,0x00000006u,0x00000100u,0x00000075u,0x000000ffu,0x00060041u,0x000000d7u,0x00000101u,0x000000d5u,0x000000d6u,0x0000005fu,0x0004003du,0x00000006u,0x00000102u,0x00000101u,0x00060041u,0x000000d7u,0x00000103u,0x000000d5u,0x000000d6u,0x000000ddu,0x0004003du,0x00000006u,0x00000104u,0x00000103u,0x00060041u,0x000000d7u,0x00000105u,0x000000d5u,0x000000d6u,0x000000edu,0x0004003du,0x00000006u,0x00000106u,0x00000105u,0x00050081u,0x00000006u,0x00000107u,0x00000075u,0x00000106u,0x00050050u,0x00000069u,0x00000108u,0x00000100u,0x00000102u,0x00050050u,0x00000069u,0x00000109u,0x00000104u,0x00000107u,0x00050050u,0x000000fbu,0x0000010au,0x00000108u,0x00000109u,0x0003003eu,0x000000fdu,0x0000010au,0x0004003du,0x00000069u,0x0000010cu,0x000000d2u,0x0004003du,0x000000fbu,0x0000010du,0x000000fdu,0x0004003du,0x00000069u,0x0000010eu,0x000000acu,0x00050091u,0x00000069u,0x0000010fu,0x0000010du,0x0000010eu,0x00050081u,0x00000069u,0x00000110u,0x0000010cu,0x0000010fu,0x0003003eu,0x0000010bu,0x00000110u,0x0004003du,0x0000004fu,0x00000111u,0x00000051u,0x0004003du,0x00000043u,0x00000112u,0x00000045u,0x0004003du,0x00000069u,0x00000113u,0x0000010bu,0x00050051u,0x00000006u,0x00000114u,0x00000113u,0x00000000u,0x00050051u,0x00000006u,0x00000115u,0x00000113u,0x00000001u,0x00070050u,0x00000085u,0x00000116u,0x00000114u,0x00000115u,0x00000084u,0x00000075u,0x00040063u,0x00000111u,0x00000112u,0x00000116u,0x0004003du,0x0000004fu,0x00000118u,0x00000117u,0x0004003du,0x00000043u,0x00000119u,0x00000045u,0x0004003du,0x00000069u,0x0000011au,0x0000010bu,0x0004007fu,0x00000069u,0x0000011bu,0x0000011au,0x00050051u,0x00000006u,0x0000011cu,0x0000011bu,0x00000000u,0x00050051u,0x00000006u,0x0000011du,0x0000011bu,0x00000001u,0x00070050u,0x00000085u,0x0000011eu,0x0000011cu,0x0000011du,0x00000084u,0x00000075u,0x00040063u,0x00000118u,0x00000119u,0x0000011eu,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x0000000eu,0x00000000u,0x00000008u,0x00030037u,0x00000007u,0x00000009u,0x00030037u,0x00000007u,0x0000000au,0x00030037u,0x00000007u,0x0000000bu,0x00030037u,0x00000007u,0x0000000cu,0x00030037u,0x00000007u,0x0000000du,0x000200f8u,0x0000000fu,0x0004003bu,0x00000007u,0x00000010u,0x00000007u,0x0004003bu,0x00000007u,0x00000034u,0x00000007u,0x0004003du,0x00000006u,0x00000011u,0x00000009u,0x0004003du,0x00000006u,0x00000012u,0x0000000au,0x0007000cu,0x00000006u,0x00000013u,0x00000001u,0x00000025u,0x00000011u,0x00000012u,0x0003003eu,0x00000010u,0x00000013u,0x0004003du,0x00000006u,0x00000014u,0x00000009u,0x0004003du,0x00000006u,0x00000015u,0x0000000au,0x0007000cu,0x00000006u,0x00000016u,0x00000001u,0x00000028u,0x00000014u,0x00000015u,0x0003003eu,0x00000009u,0x00000016u,0x0004003du,0x00000006u,0x00000017u,0x00000010u,0x0003003eu,0x0000000au,0x00000017u,0x0004003du,0x00000006u,0x00000018u,0x0000000bu,0x0004003du,0x00000006u,0x00000019u,0x0000000cu,0x0007000cu,0x00000006u,0x0000001au,0x00000001u,0x00000025u,0x00000018u,0x00000019u,0x0003003eu,0x00000010u,0x0000001au,0x0004003du,0x00000006u,0x0000001bu,0x0000000bu,0x0004003du,0x00000006u,0x0000001cu,0x0000000cu,0x0007000cu,0x00000006u,0x0000001du,0x00000001u,0x00000028u,0x0000001bu,0x0000001cu,0x0003003eu,0x0000000bu,0x0000001du,0x0004003du,0x00000006u,0x0000001eu,0x00000010u,0x0003003eu,0x0000000cu,0x0000001eu,0x0004003du,0x00000006u,0x0000001fu,0x00000009u,0x0004003du,0x00000006u,0x00000020u,0x0000000bu,0x0007000cu,0x00000006u,0x00000021u,0x00000001u,0x00000025u,0x0000001fu,0x00000020u,0x0003003eu,0x00000010u,0x00000021u,0x0004003du,0x00000006u,0x00000022u,0x00000009u,0x0004003du,0x00000006u,0x00000023u,0x0000000bu,0x0007000cu,0x00000006u,0x00000024u,0x00000001u,0x00000028u,0x00000022u,0x00000023u,0x0003003eu,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000025u,0x00000010u,0x0003003eu,0x0000000bu,0x00000025u,0x0004003du,0x00000006u,0x00000026u,0x0000000au,0x0004003du,0x00000006u,0x00000027u,0x0000000cu,0x0007000cu,0x00000006u,0x00000028u,0x00000001u,0x00000025u,0x00000026u,0x00000027u,0x0003003eu,0x00000010u,0x00000028u,0x0004003du,0x00000006u,0x00000029u,0x0000000au,0x0004003du,0x00000006u,0x0000002au,0x0000000cu,0x0007000cu,0x00000006u,0x0000002bu,0x00000001u,0x00000028u,0x00000029u,0x0000002au,0x0003003eu,0x0000000au,0x0000002bu,0x0004003du,0x00000006u,0x0000002cu,0x00000010u,0x0003003eu,0x0000000cu,0x0000002cu,0x0004003du,0x00000006u,0x0000002du,0x0000000au,0x0004003du,0x00000006u,0x0000002eu,0x0000000bu,0x0007000cu,0x00000006u,0x0000002fu,0x00000001u,0x00000025u,0x0000002du,0x0000002eu,0x0003003eu,0x00000010u,0x0000002fu,0x0004003du,0x00000006u,0x00000030u,0x0000000au,0x0004003du,0x00000006u,0x00000031u,0x0000000bu,0x0007000cu,0x00000006u,0x00000032u,0x00000001u,0x00000028u,0x00000030u,0x00000031u,0x0003003eu,0x0000000au,0x00000032u,0x0004003du,0x00000006u,0x00000033u,0x00000010u,0x0003003eu,0x0000000bu,0x00000033u,0x0004003du,0x00000006u,0x00000035u,0x0000000au,0x0004003du,0x00000006u,0x00000036u,0x0000000du,0x0007000cu,0x00000006u,0x00000037u,0x00000001u,0x00000025u,0x00000035u,0x00000036u,0x0003003eu,0x00000034u,0x00000037u,0x0004003du,0x00000006u,0x00000038u,0x0000000au,0x0004003du,0x00000006u,0x00000039u,0x0000000du,0x0007000cu,0x00000006u,0x0000003au,0x00000001u,0x00000028u,0x00000038u,0x00000039u,0x0003003eu,0x00000010u,0x0000003au,0x0004003du,0x00000006u,0x0000003bu,0x00000034u,0x0004003du,0x00000006u,0x0000003cu,0x0000000bu,0x0007000cu,0x00000006u,0x0000003du,0x00000001u,0x00000028u,0x0000003bu,0x0000003cu,0x0004003du,0x00000006u,0x0000003eu,0x00000010u,0x0007000cu,0x00000006u,0x0000003fu,0x00000001u,0x00000025u,0x0000003du,0x0000003eu,0x000200feu,0x0000003fu,0x00010038u}; static const size_t OF3_EXPAND_LEN = 1798; static const uint32_t OF3_FLOW_M4_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000151u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x000000f6u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x00000010u,0x636f6c62u,0x6461536bu,0x31327328u,0x3132733bu,0x3266763bu,0x0000003bu,0x00030005u,0x0000000du,0x00000061u,0x00030005u,0x0000000eu,0x00000062u,0x00040005u,0x0000000fu,0x646e6163u,0x00000000u,0x00070005u,0x00000016u,0x766c6f73u,0x32732865u,0x32733b31u,0x66763b31u,0x00003b32u,0x00030005u,0x00000013u,0x00000061u,0x00030005u,0x00000014u,0x00000062u,0x00040005u,0x00000015u,0x64657270u,0x00000000u,0x00030005u,0x00000019u,0x00646173u,0x00030005u,0x0000001du,0x00007962u,0x00030005u,0x00000028u,0x00007862u,0x00030005u,0x00000030u,0x00006f62u,0x00030005u,0x00000036u,0x00006170u,0x00030005u,0x00000039u,0x00765567u,0x00050005u,0x0000003cu,0x766e4967u,0x616d754cu,0x00000000u,0x00030005u,0x00000045u,0x00006270u,0x00040005u,0x0000005du,0x74736562u,0x00646153u,0x00050005u,0x0000005fu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x00000061u,0x00007973u,0x00030005u,0x0000006bu,0x00007873u,0x00040005u,0x00000073u,0x646e6163u,0x00000000u,0x00030005u,0x0000007bu,0x00646173u,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x00000095u,0x00000055u,0x00060006u,0x00000095u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000095u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000095u,0x00000002u,0x6c63636fu,0x00006f4cu,0x00050006u,0x00000095u,0x00000003u,0x6c63636fu,0x00006948u,0x00030005u,0x00000097u,0x00000000u,0x00040005u,0x0000009eu,0x43646173u,0x00000000u,0x00040005u,0x000000a1u,0x58646173u,0x0000006du,0x00040005u,0x000000a6u,0x61726170u,0x0000006du,0x00040005u,0x000000a9u,0x58646173u,0x00000070u,0x00040005u,0x000000aeu,0x61726170u,0x0000006du,0x00040005u,0x000000b1u,0x59646173u,0x0000006du,0x00040005u,0x000000b5u,0x61726170u,0x0000006du,0x00040005u,0x000000b8u,0x59646173u,0x00000070u,0x00040005u,0x000000bcu,0x61726170u,0x0000006du,0x00030005u,0x000000bfu,0x00007864u,0x00030005u,0x000000c0u,0x00007964u,0x00040005u,0x000000c1u,0x6f6e6564u,0x0000586du,0x00040005u,0x000000c9u,0x6f6e6564u,0x0000596du,0x00030005u,0x000000f3u,0x00646967u,0x00080005u,0x000000f6u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x000000fbu,0x006d6964u,0x00040005u,0x000000feu,0x6f6c4675u,0x00000077u,0x00050005u,0x0000011au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x00000122u,0x654c6f74u,0x006c6576u,0x00040005u,0x00000129u,0x64657270u,0x00000000u,0x00050005u,0x0000012au,0x65725075u,0x74636964u,0x0000726fu,0x00030005u,0x0000012eu,0x00647766u,0x00050005u,0x0000012fu,0x6d754c75u,0x65725061u,0x00000076u,0x00040005u,0x00000134u,0x61726170u,0x0000006du,0x00030005u,0x00000136u,0x00647762u,0x00040005u,0x0000013bu,0x61726170u,0x0000006du,0x00040005u,0x0000013du,0x75466f74u,0x00006c6cu,0x00030047u,0x00000095u,0x00000002u,0x00050048u,0x00000095u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000095u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000095u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000095u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000097u,0x00000021u,0x00000000u,0x00040047u,0x00000097u,0x00000022u,0x00000000u,0x00040047u,0x000000f6u,0x0000000bu,0x0000001cu,0x00030047u,0x000000feu,0x00000019u,0x00040047u,0x000000feu,0x00000021u,0x00000030u,0x00040047u,0x000000feu,0x00000022u,0x00000000u,0x00040047u,0x0000011au,0x00000021u,0x00000021u,0x00040047u,0x0000011au,0x00000022u,0x00000000u,0x00040047u,0x0000012au,0x00000021u,0x00000022u,0x00040047u,0x0000012au,0x00000022u,0x00000000u,0x00040047u,0x0000012fu,0x00000021u,0x00000020u,0x00040047u,0x0000012fu,0x00000022u,0x00000000u,0x00040047u,0x00000150u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00090019u,0x00000007u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000008u,0x00000007u,0x00040020u,0x00000009u,0x00000000u,0x00000008u,0x00040017u,0x0000000au,0x00000006u,0x00000002u,0x00040020u,0x0000000bu,0x00000007u,0x0000000au,0x00060021u,0x0000000cu,0x00000006u,0x00000009u,0x00000009u,0x0000000bu,0x00060021u,0x00000012u,0x0000000au,0x00000009u,0x00000009u,0x0000000bu,0x00040020u,0x00000018u,0x00000007u,0x00000006u,0x0004002bu,0x00000006u,0x0000001au,0x00000000u,0x00040015u,0x0000001bu,0x00000020u,0x00000001u,0x00040020u,0x0000001cu,0x00000007u,0x0000001bu,0x0004002bu,0x0000001bu,0x0000001eu,0xffffffffu,0x0004002bu,0x0000001bu,0x00000025u,0x00000001u,0x00020014u,0x00000026u,0x00040020u,0x00000038u,0x00000006u,0x0000000au,0x0004003bu,0x00000038u,0x00000039u,0x00000006u,0x0004003bu,0x00000038u,0x0000003cu,0x00000006u,0x00040017u,0x00000040u,0x00000006u,0x00000004u,0x00040015u,0x00000042u,0x00000020u,0x00000000u,0x0004002bu,0x00000042u,0x00000043u,0x00000000u,0x0004002bu,0x00000006u,0x0000005eu,0x7f7fffffu,0x0004002bu,0x0000001bu,0x00000062u,0xfffffffdu,0x0004002bu,0x0000001bu,0x00000069u,0x00000003u,0x0004002bu,0x00000006u,0x0000007fu,0x3b03126fu,0x0006001eu,0x00000095u,0x00000006u,0x00000042u,0x00000006u,0x00000006u,0x00040020u,0x00000096u,0x00000002u,0x00000095u,0x0004003bu,0x00000096u,0x00000097u,0x00000002u,0x00040020u,0x00000098u,0x00000002u,0x00000042u,0x0004002bu,0x00000006u,0x000000a3u,0xbf800000u,0x0005002cu,0x0000000au,0x000000a4u,0x000000a3u,0x0000001au,0x0004002bu,0x00000006u,0x000000abu,0x3f800000u,0x0005002cu,0x0000000au,0x000000acu,0x000000abu,0x0000001au,0x0005002cu,0x0000000au,0x000000b3u,0x0000001au,0x000000a3u,0x0005002cu,0x0000000au,0x000000bau,0x0000001au,0x000000abu,0x0004002bu,0x00000006u,0x000000c3u,0x40000000u,0x0004002bu,0x00000006u,0x000000d1u,0x358637bdu,0x0004002bu,0x00000006u,0x000000d5u,0x3f000000u,0x0004002bu,0x00000006u,0x000000dcu,0xbf000000u,0x00040017u,0x000000f1u,0x0000001bu,0x00000002u,0x00040020u,0x000000f2u,0x00000007u,0x000000f1u,0x00040017u,0x000000f4u,0x00000042u,0x00000003u,0x00040020u,0x000000f5u,0x00000001u,0x000000f4u,0x0004003bu,0x000000f5u,0x000000f6u,0x00000001u,0x00040017u,0x000000f7u,0x00000042u,0x00000002u,0x00090019u,0x000000fcu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x000000fdu,0x00000000u,0x000000fcu,0x0004003bu,0x000000fdu,0x000000feu,0x00000000u,0x0004002bu,0x00000042u,0x00000109u,0x00000001u,0x0004003bu,0x00000009u,0x0000011au,0x00000000u,0x0004002bu,0x0000001bu,0x0000011cu,0x00000000u,0x00040020u,0x00000128u,0x00000007u,0x00000040u,0x0004003bu,0x00000009u,0x0000012au,0x00000000u,0x0004003bu,0x00000009u,0x0000012fu,0x00000000u,0x0004002bu,0x00000042u,0x0000014fu,0x00000010u,0x0006002cu,0x000000f4u,0x00000150u,0x0000014fu,0x0000014fu,0x00000109u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x000000f2u,0x000000f3u,0x00000007u,0x0004003bu,0x000000f2u,0x000000fbu,0x00000007u,0x0004003bu,0x00000018u,0x00000122u,0x00000007u,0x0004003bu,0x00000128u,0x00000129u,0x00000007u,0x0004003bu,0x0000000bu,0x0000012eu,0x00000007u,0x0004003bu,0x0000000bu,0x00000134u,0x00000007u,0x0004003bu,0x0000000bu,0x00000136u,0x00000007u,0x0004003bu,0x0000000bu,0x0000013bu,0x00000007u,0x0004003bu,0x00000018u,0x0000013du,0x00000007u,0x0004003du,0x000000f4u,0x000000f8u,0x000000f6u,0x0007004fu,0x000000f7u,0x000000f9u,0x000000f8u,0x000000f8u,0x00000000u,0x00000001u,0x0004007cu,0x000000f1u,0x000000fau,0x000000f9u,0x0003003eu,0x000000f3u,0x000000fau,0x0004003du,0x000000fcu,0x000000ffu,0x000000feu,0x00040068u,0x000000f1u,0x00000100u,0x000000ffu,0x0003003eu,0x000000fbu,0x00000100u,0x00050041u,0x0000001cu,0x00000101u,0x000000f3u,0x00000043u,0x0004003du,0x0000001bu,0x00000102u,0x00000101u,0x00050041u,0x0000001cu,0x00000103u,0x000000fbu,0x00000043u,0x0004003du,0x0000001bu,0x00000104u,0x00000103u,0x000500afu,0x00000026u,0x00000105u,0x00000102u,0x00000104u,0x000400a8u,0x00000026u,0x00000106u,0x00000105u,0x000300f7u,0x00000108u,0x00000000u,0x000400fau,0x00000106u,0x00000107u,0x00000108u,0x000200f8u,0x00000107u,0x00050041u,0x0000001cu,0x0000010au,0x000000f3u,0x00000109u,0x0004003du,0x0000001bu,0x0000010bu,0x0000010au,0x00050041u,0x0000001cu,0x0000010cu,0x000000fbu,0x00000109u,0x0004003du,0x0000001bu,0x0000010du,0x0000010cu,0x000500afu,0x00000026u,0x0000010eu,0x0000010bu,0x0000010du,0x000200f9u,0x00000108u,0x000200f8u,0x00000108u,0x000700f5u,0x00000026u,0x0000010fu,0x00000105u,0x00000005u,0x0000010eu,0x00000107u,0x000300f7u,0x00000111u,0x00000000u,0x000400fau,0x0000010fu,0x00000110u,0x00000111u,0x000200f8u,0x00000110u,0x000100fdu,0x000200f8u,0x00000111u,0x0004003du,0x000000f1u,0x00000113u,0x000000f3u,0x0004006fu,0x0000000au,0x00000114u,0x00000113u,0x00050050u,0x0000000au,0x00000115u,0x000000d5u,0x000000d5u,0x00050081u,0x0000000au,0x00000116u,0x00000114u,0x00000115u,0x0004003du,0x000000f1u,0x00000117u,0x000000fbu,0x0004006fu,0x0000000au,0x00000118u,0x00000117u,0x00050088u,0x0000000au,0x00000119u,0x00000116u,0x00000118u,0x0003003eu,0x00000039u,0x00000119u,0x0004003du,0x00000008u,0x0000011bu,0x0000011au,0x00040064u,0x00000007u,0x0000011du,0x0000011bu,0x00050067u,0x000000f1u,0x0000011eu,0x0000011du,0x0000011cu,0x0004006fu,0x0000000au,0x0000011fu,0x0000011eu,0x00050050u,0x0000000au,0x00000120u,0x000000abu,0x000000abu,0x00050088u,0x0000000au,0x00000121u,0x00000120u,0x0000011fu,0x0003003eu,0x0000003cu,0x00000121u,0x00050041u,0x00000098u,0x00000123u,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x00000124u,0x00000123u,0x00040070u,0x00000006u,0x00000125u,0x00000124u,0x0004007fu,0x00000006u,0x00000126u,0x00000125u,0x0006000cu,0x00000006u,0x00000127u,0x00000001u,0x0000001du,0x00000126u,0x0003003eu,0x00000122u,0x00000127u,0x0004003du,0x00000008u,0x0000012bu,0x0000012au,0x0004003du,0x0000000au,0x0000012cu,0x00000039u,0x00070058u,0x00000040u,0x0000012du,0x0000012bu,0x0000012cu,0x00000002u,0x0000001au,0x0003003eu,0x00000129u,0x0000012du,0x0004003du,0x00000040u,0x00000130u,0x00000129u,0x0007004fu,0x0000000au,0x00000131u,0x00000130u,0x00000130u,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x00000132u,0x00000122u,0x0005008eu,0x0000000au,0x00000133u,0x00000131u,0x00000132u,0x0003003eu,0x00000134u,0x00000133u,0x00070039u,0x0000000au,0x00000135u,0x00000016u,0x0000012fu,0x0000011au,0x00000134u,0x0003003eu,0x0000012eu,0x00000135u,0x0004003du,0x00000040u,0x00000137u,0x00000129u,0x0007004fu,0x0000000au,0x00000138u,0x00000137u,0x00000137u,0x00000002u,0x00000003u,0x0004003du,0x00000006u,0x00000139u,0x00000122u,0x0005008eu,0x0000000au,0x0000013au,0x00000138u,0x00000139u,0x0003003eu,0x0000013bu,0x0000013au,0x00070039u,0x0000000au,0x0000013cu,0x00000016u,0x0000011au,0x0000012fu,0x0000013bu,0x0003003eu,0x00000136u,0x0000013cu,0x00050041u,0x00000098u,0x0000013eu,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x0000013fu,0x0000013eu,0x00040070u,0x00000006u,0x00000140u,0x0000013fu,0x0006000cu,0x00000006u,0x00000141u,0x00000001u,0x0000001du,0x00000140u,0x0003003eu,0x0000013du,0x00000141u,0x0004003du,0x000000fcu,0x00000142u,0x000000feu,0x0004003du,0x000000f1u,0x00000143u,0x000000f3u,0x0004003du,0x0000000au,0x00000144u,0x0000012eu,0x0004003du,0x00000006u,0x00000145u,0x0000013du,0x0005008eu,0x0000000au,0x00000146u,0x00000144u,0x00000145u,0x0004003du,0x0000000au,0x00000147u,0x00000136u,0x0004003du,0x00000006u,0x00000148u,0x0000013du,0x0005008eu,0x0000000au,0x00000149u,0x00000147u,0x00000148u,0x00050051u,0x00000006u,0x0000014au,0x00000146u,0x00000000u,0x00050051u,0x00000006u,0x0000014bu,0x00000146u,0x00000001u,0x00050051u,0x00000006u,0x0000014cu,0x00000149u,0x00000000u,0x00050051u,0x00000006u,0x0000014du,0x00000149u,0x00000001u,0x00070050u,0x00000040u,0x0000014eu,0x0000014au,0x0000014bu,0x0000014cu,0x0000014du,0x00040063u,0x00000142u,0x00000143u,0x0000014eu,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x00000010u,0x00000000u,0x0000000cu,0x00030037u,0x00000009u,0x0000000du,0x00030037u,0x00000009u,0x0000000eu,0x00030037u,0x0000000bu,0x0000000fu,0x000200f8u,0x00000011u,0x0004003bu,0x00000018u,0x00000019u,0x00000007u,0x0004003bu,0x0000001cu,0x0000001du,0x00000007u,0x0004003bu,0x0000001cu,0x00000028u,0x00000007u,0x0004003bu,0x0000000bu,0x00000030u,0x00000007u,0x0004003bu,0x00000018u,0x00000036u,0x00000007u,0x0004003bu,0x00000018u,0x00000045u,0x00000007u,0x0003003eu,0x00000019u,0x0000001au,0x0003003eu,0x0000001du,0x0000001eu,0x000200f9u,0x0000001fu,0x000200f8u,0x0000001fu,0x000400f6u,0x00000021u,0x00000022u,0x00000000u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x0004003du,0x0000001bu,0x00000024u,0x0000001du,0x000500b3u,0x00000026u,0x00000027u,0x00000024u,0x00000025u,0x000400fau,0x00000027u,0x00000020u,0x00000021u,0x000200f8u,0x00000020u,0x0003003eu,0x00000028u,0x0000001eu,0x000200f9u,0x00000029u,0x000200f8u,0x00000029u,0x000400f6u,0x0000002bu,0x0000002cu,0x00000000u,0x000200f9u,0x0000002du,0x000200f8u,0x0000002du,0x0004003du,0x0000001bu,0x0000002eu,0x00000028u,0x000500b3u,0x00000026u,0x0000002fu,0x0000002eu,0x00000025u,0x000400fau,0x0000002fu,0x0000002au,0x0000002bu,0x000200f8u,0x0000002au,0x0004003du,0x0000001bu,0x00000031u,0x00000028u,0x0004006fu,0x00000006u,0x00000032u,0x00000031u,0x0004003du,0x0000001bu,0x00000033u,0x0000001du,0x0004006fu,0x00000006u,0x00000034u,0x00000033u,0x00050050u,0x0000000au,0x00000035u,0x00000032u,0x00000034u,0x0003003eu,0x00000030u,0x00000035u,0x0004003du,0x00000008u,0x00000037u,0x0000000du,0x0004003du,0x0000000au,0x0000003au,0x00000039u,0x0004003du,0x0000000au,0x0000003bu,0x00000030u,0x0004003du,0x0000000au,0x0000003du,0x0000003cu,0x00050085u,0x0000000au,0x0000003eu,0x0000003bu,0x0000003du,0x00050081u,0x0000000au,0x0000003fu,0x0000003au,0x0000003eu,0x00070058u,0x00000040u,0x00000041u,0x00000037u,0x0000003fu,0x00000002u,0x0000001au,0x00050051u,0x00000006u,0x00000044u,0x00000041u,0x00000000u,0x0003003eu,0x00000036u,0x00000044u,0x0004003du,0x00000008u,0x00000046u,0x0000000eu,0x0004003du,0x0000000au,0x00000047u,0x00000039u,0x0004003du,0x0000000au,0x00000048u,0x00000030u,0x0004003du,0x0000000au,0x00000049u,0x0000000fu,0x00050081u,0x0000000au,0x0000004au,0x00000048u,0x00000049u,0x0004003du,0x0000000au,0x0000004bu,0x0000003cu,0x00050085u,0x0000000au,0x0000004cu,0x0000004au,0x0000004bu,0x00050081u,0x0000000au,0x0000004du,0x00000047u,0x0000004cu,0x00070058u,0x00000040u,0x0000004eu,0x00000046u,0x0000004du,0x00000002u,0x0000001au,0x00050051u,0x00000006u,0x0000004fu,0x0000004eu,0x00000000u,0x0003003eu,0x00000045u,0x0000004fu,0x0004003du,0x00000006u,0x00000050u,0x00000036u,0x0004003du,0x00000006u,0x00000051u,0x00000045u,0x00050083u,0x00000006u,0x00000052u,0x00000050u,0x00000051u,0x0006000cu,0x00000006u,0x00000053u,0x00000001u,0x00000004u,0x00000052u,0x0004003du,0x00000006u,0x00000054u,0x00000019u,0x00050081u,0x00000006u,0x00000055u,0x00000054u,0x00000053u,0x0003003eu,0x00000019u,0x00000055u,0x000200f9u,0x0000002cu,0x000200f8u,0x0000002cu,0x0004003du,0x0000001bu,0x00000056u,0x00000028u,0x00050080u,0x0000001bu,0x00000057u,0x00000056u,0x00000025u,0x0003003eu,0x00000028u,0x00000057u,0x000200f9u,0x00000029u,0x000200f8u,0x0000002bu,0x000200f9u,0x00000022u,0x000200f8u,0x00000022u,0x0004003du,0x0000001bu,0x00000058u,0x0000001du,0x00050080u,0x0000001bu,0x00000059u,0x00000058u,0x00000025u,0x0003003eu,0x0000001du,0x00000059u,0x000200f9u,0x0000001fu,0x000200f8u,0x00000021u,0x0004003du,0x00000006u,0x0000005au,0x00000019u,0x000200feu,0x0000005au,0x00010038u,0x00050036u,0x0000000au,0x00000016u,0x00000000u,0x00000012u,0x00030037u,0x00000009u,0x00000013u,0x00030037u,0x00000009u,0x00000014u,0x00030037u,0x0000000bu,0x00000015u,0x000200f8u,0x00000017u,0x0004003bu,0x00000018u,0x0000005du,0x00000007u,0x0004003bu,0x0000000bu,0x0000005fu,0x00000007u,0x0004003bu,0x0000001cu,0x00000061u,0x00000007u,0x0004003bu,0x0000001cu,0x0000006bu,0x00000007u,0x0004003bu,0x0000000bu,0x00000073u,0x00000007u,0x0004003bu,0x00000018u,0x0000007bu,0x00000007u,0x0004003bu,0x0000000bu,0x0000007cu,0x00000007u,0x0004003bu,0x00000018u,0x0000009eu,0x00000007u,0x0004003bu,0x00000018u,0x000000a1u,0x00000007u,0x0004003bu,0x0000000bu,0x000000a6u,0x00000007u,0x0004003bu,0x00000018u,0x000000a9u,0x00000007u,0x0004003bu,0x0000000bu,0x000000aeu,0x00000007u,0x0004003bu,0x00000018u,0x000000b1u,0x00000007u,0x0004003bu,0x0000000bu,0x000000b5u,0x00000007u,0x0004003bu,0x00000018u,0x000000b8u,0x00000007u,0x0004003bu,0x0000000bu,0x000000bcu,0x00000007u,0x0004003bu,0x00000018u,0x000000bfu,0x00000007u,0x0004003bu,0x00000018u,0x000000c0u,0x00000007u,0x0004003bu,0x00000018u,0x000000c1u,0x00000007u,0x0004003bu,0x00000018u,0x000000c9u,0x00000007u,0x0003003eu,0x0000005du,0x0000005eu,0x0004003du,0x0000000au,0x00000060u,0x00000015u,0x0003003eu,0x0000005fu,0x00000060u,0x0003003eu,0x00000061u,0x00000062u,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x000400f6u,0x00000065u,0x00000066u,0x00000000u,0x000200f9u,0x00000067u,0x000200f8u,0x00000067u,0x0004003du,0x0000001bu,0x00000068u,0x00000061u,0x000500b3u,0x00000026u,0x0000006au,0x00000068u,0x00000069u,0x000400fau,0x0000006au,0x00000064u,0x00000065u,0x000200f8u,0x00000064u,0x0003003eu,0x0000006bu,0x00000062u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006cu,0x000400f6u,0x0000006eu,0x0000006fu,0x00000000u,0x000200f9u,0x00000070u,0x000200f8u,0x00000070u,0x0004003du,0x0000001bu,0x00000071u,0x0000006bu,0x000500b3u,0x00000026u,0x00000072u,0x00000071u,0x00000069u,0x000400fau,0x00000072u,0x0000006du,0x0000006eu,0x000200f8u,0x0000006du,0x0004003du,0x0000000au,0x00000074u,0x00000015u,0x0004003du,0x0000001bu,0x00000075u,0x0000006bu,0x0004006fu,0x00000006u,0x00000076u,0x00000075u,0x0004003du,0x0000001bu,0x00000077u,0x00000061u,0x0004006fu,0x00000006u,0x00000078u,0x00000077u,0x00050050u,0x0000000au,0x00000079u,0x00000076u,0x00000078u,0x00050081u,0x0000000au,0x0000007au,0x00000074u,0x00000079u,0x0003003eu,0x00000073u,0x0000007au,0x0004003du,0x0000000au,0x0000007du,0x00000073u,0x0003003eu,0x0000007cu,0x0000007du,0x00070039u,0x00000006u,0x0000007eu,0x00000010u,0x00000013u,0x00000014u,0x0000007cu,0x0003003eu,0x0000007bu,0x0000007eu,0x0004003du,0x0000001bu,0x00000080u,0x0000006bu,0x0004006fu,0x00000006u,0x00000081u,0x00000080u,0x0006000cu,0x00000006u,0x00000082u,0x00000001u,0x00000004u,0x00000081u,0x0004003du,0x0000001bu,0x00000083u,0x00000061u,0x0004006fu,0x00000006u,0x00000084u,0x00000083u,0x0006000cu,0x00000006u,0x00000085u,0x00000001u,0x00000004u,0x00000084u,0x00050081u,0x00000006u,0x00000086u,0x00000082u,0x00000085u,0x00050085u,0x00000006u,0x00000087u,0x0000007fu,0x00000086u,0x0004003du,0x00000006u,0x00000088u,0x0000007bu,0x00050081u,0x00000006u,0x00000089u,0x00000088u,0x00000087u,0x0003003eu,0x0000007bu,0x00000089u,0x0004003du,0x00000006u,0x0000008au,0x0000007bu,0x0004003du,0x00000006u,0x0000008bu,0x0000005du,0x000500b8u,0x00000026u,0x0000008cu,0x0000008au,0x0000008bu,0x000300f7u,0x0000008eu,0x00000000u,0x000400fau,0x0000008cu,0x0000008du,0x0000008eu,0x000200f8u,0x0000008du,0x0004003du,0x00000006u,0x0000008fu,0x0000007bu,0x0003003eu,0x0000005du,0x0000008fu,0x0004003du,0x0000000au,0x00000090u,0x00000073u,0x0003003eu,0x0000005fu,0x00000090u,0x000200f9u,0x0000008eu,0x000200f8u,0x0000008eu,0x000200f9u,0x0000006fu,0x000200f8u,0x0000006fu,0x0004003du,0x0000001bu,0x00000091u,0x0000006bu,0x00050080u,0x0000001bu,0x00000092u,0x00000091u,0x00000025u,0x0003003eu,0x0000006bu,0x00000092u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006eu,0x000200f9u,0x00000066u,0x000200f8u,0x00000066u,0x0004003du,0x0000001bu,0x00000093u,0x00000061u,0x00050080u,0x0000001bu,0x00000094u,0x00000093u,0x00000025u,0x0003003eu,0x00000061u,0x00000094u,0x000200f9u,0x00000063u,0x000200f8u,0x00000065u,0x00050041u,0x00000098u,0x00000099u,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x0000009au,0x00000099u,0x000500aau,0x00000026u,0x0000009bu,0x0000009au,0x00000043u,0x000300f7u,0x0000009du,0x00000000u,0x000400fau,0x0000009bu,0x0000009cu,0x0000009du,0x000200f8u,0x0000009cu,0x0004003du,0x00000006u,0x0000009fu,0x0000005du,0x00050083u,0x00000006u,0x000000a0u,0x0000009fu,0x0000001au,0x0003003eu,0x0000009eu,0x000000a0u,0x0004003du,0x0000000au,0x000000a2u,0x0000005fu,0x00050081u,0x0000000au,0x000000a5u,0x000000a2u,0x000000a4u,0x0003003eu,0x000000a6u,0x000000a5u,0x00070039u,0x00000006u,0x000000a7u,0x00000010u,0x00000013u,0x00000014u,0x000000a6u,0x00050081u,0x00000006u,0x000000a8u,0x000000a7u,0x0000007fu,0x0003003eu,0x000000a1u,0x000000a8u,0x0004003du,0x0000000au,0x000000aau,0x0000005fu,0x00050081u,0x0000000au,0x000000adu,0x000000aau,0x000000acu,0x0003003eu,0x000000aeu,0x000000adu,0x00070039u,0x00000006u,0x000000afu,0x00000010u,0x00000013u,0x00000014u,0x000000aeu,0x00050081u,0x00000006u,0x000000b0u,0x000000afu,0x0000007fu,0x0003003eu,0x000000a9u,0x000000b0u,0x0004003du,0x0000000au,0x000000b2u,0x0000005fu,0x00050081u,0x0000000au,0x000000b4u,0x000000b2u,0x000000b3u,0x0003003eu,0x000000b5u,0x000000b4u,0x00070039u,0x00000006u,0x000000b6u,0x00000010u,0x00000013u,0x00000014u,0x000000b5u,0x00050081u,0x00000006u,0x000000b7u,0x000000b6u,0x0000007fu,0x0003003eu,0x000000b1u,0x000000b7u,0x0004003du,0x0000000au,0x000000b9u,0x0000005fu,0x00050081u,0x0000000au,0x000000bbu,0x000000b9u,0x000000bau,0x0003003eu,0x000000bcu,0x000000bbu,0x00070039u,0x00000006u,0x000000bdu,0x00000010u,0x00000013u,0x00000014u,0x000000bcu,0x00050081u,0x00000006u,0x000000beu,0x000000bdu,0x0000007fu,0x0003003eu,0x000000b8u,0x000000beu,0x0003003eu,0x000000bfu,0x0000001au,0x0003003eu,0x000000c0u,0x0000001au,0x0004003du,0x00000006u,0x000000c2u,0x000000a1u,0x0004003du,0x00000006u,0x000000c4u,0x0000009eu,0x00050085u,0x00000006u,0x000000c5u,0x000000c3u,0x000000c4u,0x00050083u,0x00000006u,0x000000c6u,0x000000c2u,0x000000c5u,0x0004003du,0x00000006u,0x000000c7u,0x000000a9u,0x00050081u,0x00000006u,0x000000c8u,0x000000c6u,0x000000c7u,0x0003003eu,0x000000c1u,0x000000c8u,0x0004003du,0x00000006u,0x000000cau,0x000000b1u,0x0004003du,0x00000006u,0x000000cbu,0x0000009eu,0x00050085u,0x00000006u,0x000000ccu,0x000000c3u,0x000000cbu,0x00050083u,0x00000006u,0x000000cdu,0x000000cau,0x000000ccu,0x0004003du,0x00000006u,0x000000ceu,0x000000b8u,0x00050081u,0x00000006u,0x000000cfu,0x000000cdu,0x000000ceu,0x0003003eu,0x000000c9u,0x000000cfu,0x0004003du,0x00000006u,0x000000d0u,0x000000c1u,0x000500bau,0x00000026u,0x000000d2u,0x000000d0u,0x000000d1u,0x000300f7u,0x000000d4u,0x00000000u,0x000400fau,0x000000d2u,0x000000d3u,0x000000d4u,0x000200f8u,0x000000d3u,0x0004003du,0x00000006u,0x000000d6u,0x000000a1u,0x0004003du,0x00000006u,0x000000d7u,0x000000a9u,0x00050083u,0x00000006u,0x000000d8u,0x000000d6u,0x000000d7u,0x00050085u,0x00000006u,0x000000d9u,0x000000d5u,0x000000d8u,0x0004003du,0x00000006u,0x000000dau,0x000000c1u,0x00050088u,0x00000006u,0x000000dbu,0x000000d9u,0x000000dau,0x0008000cu,0x00000006u,0x000000ddu,0x00000001u,0x0000002bu,0x000000dbu,0x000000dcu,0x000000d5u,0x0003003eu,0x000000bfu,0x000000ddu,0x000200f9u,0x000000d4u,0x000200f8u,0x000000d4u,0x0004003du,0x00000006u,0x000000deu,0x000000c9u,0x000500bau,0x00000026u,0x000000dfu,0x000000deu,0x000000d1u,0x000300f7u,0x000000e1u,0x00000000u,0x000400fau,0x000000dfu,0x000000e0u,0x000000e1u,0x000200f8u,0x000000e0u,0x0004003du,0x00000006u,0x000000e2u,0x000000b1u,0x0004003du,0x00000006u,0x000000e3u,0x000000b8u,0x00050083u,0x00000006u,0x000000e4u,0x000000e2u,0x000000e3u,0x00050085u,0x00000006u,0x000000e5u,0x000000d5u,0x000000e4u,0x0004003du,0x00000006u,0x000000e6u,0x000000c9u,0x00050088u,0x00000006u,0x000000e7u,0x000000e5u,0x000000e6u,0x0008000cu,0x00000006u,0x000000e8u,0x00000001u,0x0000002bu,0x000000e7u,0x000000dcu,0x000000d5u,0x0003003eu,0x000000c0u,0x000000e8u,0x000200f9u,0x000000e1u,0x000200f8u,0x000000e1u,0x0004003du,0x00000006u,0x000000e9u,0x000000bfu,0x0004003du,0x00000006u,0x000000eau,0x000000c0u,0x00050050u,0x0000000au,0x000000ebu,0x000000e9u,0x000000eau,0x0004003du,0x0000000au,0x000000ecu,0x0000005fu,0x00050081u,0x0000000au,0x000000edu,0x000000ecu,0x000000ebu,0x0003003eu,0x0000005fu,0x000000edu,0x000200f9u,0x0000009du,0x000200f8u,0x0000009du,0x0004003du,0x0000000au,0x000000eeu,0x0000005fu,0x000200feu,0x000000eeu,0x00010038u}; @@ -18,8 +226,8 @@ static const uint32_t OF3_GM_REDUCE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu static const size_t OF3_GM_REDUCE_LEN = 2584; static const uint32_t OF3_GM_PREWARP_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000074u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00030005u,0x00000030u,0x00007675u,0x00030005u,0x00000039u,0x00000071u,0x00040005u,0x0000003du,0x6c6f6370u,0x00000030u,0x00030005u,0x0000003fu,0x00004d47u,0x00050006u,0x0000003fu,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x0000003fu,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x0000003fu,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x0000003fu,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x00000041u,0x00000000u,0x00040005u,0x00000049u,0x6c6f6370u,0x00000031u,0x00040005u,0x00000051u,0x72537675u,0x00000063u,0x00030005u,0x00000064u,0x00000076u,0x00040005u,0x00000068u,0x72754375u,0x00000072u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x0000003fu,0x00000002u,0x00050048u,0x0000003fu,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000003fu,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x0000003fu,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x0000003fu,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x00000041u,0x00000021u,0x00000001u,0x00040047u,0x00000041u,0x00000022u,0x00000000u,0x00040047u,0x00000068u,0x00000021u,0x00000020u,0x00040047u,0x00000068u,0x00000022u,0x00000000u,0x00040047u,0x00000073u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000033u,0x3f000000u,0x00040017u,0x0000003eu,0x00000013u,0x00000004u,0x0006001eu,0x0000003fu,0x0000003eu,0x0000003eu,0x0000003eu,0x0000003eu,0x00040020u,0x00000040u,0x00000002u,0x0000003fu,0x0004003bu,0x00000040u,0x00000041u,0x00000002u,0x0004002bu,0x00000006u,0x00000042u,0x00000002u,0x00040020u,0x00000043u,0x00000002u,0x00000013u,0x0004002bu,0x0000000au,0x0000004au,0x00000002u,0x0004002bu,0x0000000au,0x0000004du,0x00000003u,0x00040020u,0x00000054u,0x00000007u,0x00000013u,0x0004002bu,0x00000006u,0x0000005eu,0x00000003u,0x00040020u,0x0000005fu,0x00000002u,0x0000003eu,0x00090019u,0x00000065u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000066u,0x00000065u,0x00040020u,0x00000067u,0x00000000u,0x00000066u,0x0004003bu,0x00000067u,0x00000068u,0x00000000u,0x0004002bu,0x00000013u,0x0000006bu,0x00000000u,0x0004002bu,0x0000000au,0x00000072u,0x00000010u,0x0006002cu,0x0000000bu,0x00000073u,0x00000072u,0x00000072u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000039u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003du,0x00000007u,0x0004003bu,0x0000002fu,0x00000049u,0x00000007u,0x0004003bu,0x0000002fu,0x00000051u,0x00000007u,0x0004003bu,0x00000054u,0x00000064u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000031u,0x00000009u,0x0004006fu,0x0000002eu,0x00000032u,0x00000031u,0x00050050u,0x0000002eu,0x00000034u,0x00000033u,0x00000033u,0x00050081u,0x0000002eu,0x00000035u,0x00000032u,0x00000034u,0x0004003du,0x00000007u,0x00000036u,0x00000012u,0x0004006fu,0x0000002eu,0x00000037u,0x00000036u,0x00050088u,0x0000002eu,0x00000038u,0x00000035u,0x00000037u,0x0003003eu,0x00000030u,0x00000038u,0x0004003du,0x0000002eu,0x0000003au,0x00000030u,0x00050050u,0x0000002eu,0x0000003bu,0x00000033u,0x00000033u,0x00050083u,0x0000002eu,0x0000003cu,0x0000003au,0x0000003bu,0x0003003eu,0x00000039u,0x0000003cu,0x00060041u,0x00000043u,0x00000044u,0x00000041u,0x00000042u,0x0000001au,0x0004003du,0x00000013u,0x00000045u,0x00000044u,0x00060041u,0x00000043u,0x00000046u,0x00000041u,0x00000042u,0x00000024u,0x0004003du,0x00000013u,0x00000047u,0x00000046u,0x00050050u,0x0000002eu,0x00000048u,0x00000045u,0x00000047u,0x0003003eu,0x0000003du,0x00000048u,0x00060041u,0x00000043u,0x0000004bu,0x00000041u,0x00000042u,0x0000004au,0x0004003du,0x00000013u,0x0000004cu,0x0000004bu,0x00060041u,0x00000043u,0x0000004eu,0x00000041u,0x00000042u,0x0000004du,0x0004003du,0x00000013u,0x0000004fu,0x0000004eu,0x00050050u,0x0000002eu,0x00000050u,0x0000004cu,0x0000004fu,0x0003003eu,0x00000049u,0x00000050u,0x0004003du,0x0000002eu,0x00000052u,0x00000030u,0x0004003du,0x0000002eu,0x00000053u,0x0000003du,0x00050041u,0x00000054u,0x00000055u,0x00000039u,0x0000001au,0x0004003du,0x00000013u,0x00000056u,0x00000055u,0x0005008eu,0x0000002eu,0x00000057u,0x00000053u,0x00000056u,0x00050081u,0x0000002eu,0x00000058u,0x00000052u,0x00000057u,0x0004003du,0x0000002eu,0x00000059u,0x00000049u,0x00050041u,0x00000054u,0x0000005au,0x00000039u,0x00000024u,0x0004003du,0x00000013u,0x0000005bu,0x0000005au,0x0005008eu,0x0000002eu,0x0000005cu,0x00000059u,0x0000005bu,0x00050081u,0x0000002eu,0x0000005du,0x00000058u,0x0000005cu,0x00050041u,0x0000005fu,0x00000060u,0x00000041u,0x0000005eu,0x0004003du,0x0000003eu,0x00000061u,0x00000060u,0x0007004fu,0x0000002eu,0x00000062u,0x00000061u,0x00000061u,0x00000000u,0x00000001u,0x00050081u,0x0000002eu,0x00000063u,0x0000005du,0x00000062u,0x0003003eu,0x00000051u,0x00000063u,0x0004003du,0x00000066u,0x00000069u,0x00000068u,0x0004003du,0x0000002eu,0x0000006au,0x00000051u,0x00070058u,0x0000003eu,0x0000006cu,0x00000069u,0x0000006au,0x00000002u,0x0000006bu,0x00050051u,0x00000013u,0x0000006du,0x0000006cu,0x00000000u,0x0003003eu,0x00000064u,0x0000006du,0x0004003du,0x00000014u,0x0000006eu,0x00000016u,0x0004003du,0x00000007u,0x0000006fu,0x00000009u,0x0004003du,0x00000013u,0x00000070u,0x00000064u,0x00070050u,0x0000003eu,0x00000071u,0x00000070u,0x0000006bu,0x0000006bu,0x0000006bu,0x00040063u,0x0000006eu,0x0000006fu,0x00000071u,0x000100fdu,0x00010038u}; static const size_t OF3_GM_PREWARP_LEN = 706; -static const uint32_t OF3_FLOWREG_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000144u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000037u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00060005u,0x0000000eu,0x63746566u,0x76285568u,0x763b3269u,0x003b3269u,0x00030005u,0x0000000cu,0x00000070u,0x00030005u,0x0000000du,0x006d6964u,0x00060005u,0x00000013u,0x63746566u,0x76284c68u,0x763b3269u,0x003b3269u,0x00030005u,0x00000011u,0x00000070u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000018u,0x6f6c4675u,0x006e4977u,0x00040005u,0x00000026u,0x6d754c75u,0x00000061u,0x00030005u,0x00000034u,0x00646967u,0x00080005u,0x00000037u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000003cu,0x006d6964u,0x00030005u,0x00000055u,0x00007464u,0x00030005u,0x00000056u,0x00000055u,0x00050006u,0x00000056u,0x00000000u,0x61726170u,0x0000736du,0x00030005u,0x00000058u,0x00000000u,0x00040005u,0x0000005cu,0x626d616cu,0x00006164u,0x00050005u,0x0000005fu,0x65676465u,0x68706c41u,0x00000061u,0x00040005u,0x00000063u,0x54737065u,0x00000056u,0x00030005u,0x00000068u,0x00004375u,0x00040005u,0x00000069u,0x61726170u,0x0000006du,0x00040005u,0x0000006bu,0x61726170u,0x0000006du,0x00030005u,0x0000006eu,0x00004c75u,0x00040005u,0x00000073u,0x61726170u,0x0000006du,0x00040005u,0x00000074u,0x61726170u,0x0000006du,0x00030005u,0x00000077u,0x00005275u,0x00040005u,0x0000007bu,0x61726170u,0x0000006du,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x0000007fu,0x00005575u,0x00040005u,0x00000083u,0x61726170u,0x0000006du,0x00040005u,0x00000084u,0x61726170u,0x0000006du,0x00030005u,0x00000087u,0x00004475u,0x00040005u,0x0000008bu,0x61726170u,0x0000006du,0x00040005u,0x0000008cu,0x61726170u,0x0000006du,0x00040005u,0x0000008fu,0x6d69646cu,0x00000000u,0x00030005u,0x00000093u,0x00004c6cu,0x00040005u,0x00000096u,0x61726170u,0x0000006du,0x00040005u,0x00000097u,0x61726170u,0x0000006du,0x00030005u,0x0000009au,0x0000526cu,0x00040005u,0x0000009du,0x61726170u,0x0000006du,0x00040005u,0x0000009eu,0x61726170u,0x0000006du,0x00030005u,0x000000a1u,0x0000556cu,0x00040005u,0x000000a4u,0x61726170u,0x0000006du,0x00040005u,0x000000a5u,0x61726170u,0x0000006du,0x00030005u,0x000000a8u,0x0000446cu,0x00040005u,0x000000abu,0x61726170u,0x0000006du,0x00040005u,0x000000acu,0x61726170u,0x0000006du,0x00040005u,0x000000afu,0x67616d67u,0x00000000u,0x00030005u,0x000000bbu,0x00000067u,0x00030005u,0x000000c4u,0x00004c64u,0x00030005u,0x000000c8u,0x00005264u,0x00030005u,0x000000ccu,0x00005564u,0x00030005u,0x000000d0u,0x00004464u,0x00030005u,0x000000d4u,0x00003265u,0x00030005u,0x000000d8u,0x00004c77u,0x00030005u,0x000000e1u,0x00005277u,0x00030005u,0x000000eau,0x00005577u,0x00030005u,0x000000f3u,0x00004477u,0x00040005u,0x000000fcu,0x576d7573u,0x00000000u,0x00040005u,0x00000104u,0x576d7573u,0x00000055u,0x00040005u,0x00000114u,0x66694475u,0x00000066u,0x00030005u,0x00000120u,0x00003066u,0x00050005u,0x00000121u,0x6f6c4675u,0x73624f77u,0x00000000u,0x00040005u,0x0000012au,0x74656874u,0x00000061u,0x00030005u,0x0000012eu,0x00000072u,0x00040005u,0x00000132u,0x77654e75u,0x00000000u,0x00050005u,0x0000013eu,0x6f6c4675u,0x74754f77u,0x00000000u,0x00040047u,0x00000018u,0x00000021u,0x00000020u,0x00040047u,0x00000018u,0x00000022u,0x00000000u,0x00040047u,0x00000026u,0x00000021u,0x00000022u,0x00040047u,0x00000026u,0x00000022u,0x00000000u,0x00040047u,0x00000037u,0x0000000bu,0x0000001cu,0x00030047u,0x00000056u,0x00000002u,0x00050048u,0x00000056u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x00000058u,0x00000021u,0x00000000u,0x00040047u,0x00000058u,0x00000022u,0x00000000u,0x00040047u,0x00000121u,0x00000021u,0x00000021u,0x00040047u,0x00000121u,0x00000022u,0x00000000u,0x00030047u,0x0000013eu,0x00000019u,0x00040047u,0x0000013eu,0x00000021u,0x00000030u,0x00040047u,0x0000013eu,0x00000022u,0x00000000u,0x00040047u,0x00000143u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00030016u,0x00000009u,0x00000020u,0x00040017u,0x0000000au,0x00000009u,0x00000004u,0x00050021u,0x0000000bu,0x0000000au,0x00000008u,0x00000008u,0x00050021u,0x00000010u,0x00000009u,0x00000008u,0x00000008u,0x00090019u,0x00000015u,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000016u,0x00000015u,0x00040020u,0x00000017u,0x00000000u,0x00000016u,0x0004003bu,0x00000017u,0x00000018u,0x00000000u,0x0004002bu,0x00000006u,0x0000001bu,0x00000000u,0x0005002cu,0x00000007u,0x0000001cu,0x0000001bu,0x0000001bu,0x0004002bu,0x00000006u,0x0000001eu,0x00000001u,0x0004003bu,0x00000017u,0x00000026u,0x00000000u,0x00040015u,0x0000002fu,0x00000020u,0x00000000u,0x0004002bu,0x0000002fu,0x00000030u,0x00000000u,0x00040017u,0x00000035u,0x0000002fu,0x00000003u,0x00040020u,0x00000036u,0x00000001u,0x00000035u,0x0004003bu,0x00000036u,0x00000037u,0x00000001u,0x00040017u,0x00000038u,0x0000002fu,0x00000002u,0x00020014u,0x00000040u,0x00040020u,0x00000041u,0x00000007u,0x00000006u,0x0004002bu,0x0000002fu,0x0000004au,0x00000001u,0x00040020u,0x00000054u,0x00000007u,0x00000009u,0x0003001eu,0x00000056u,0x0000000au,0x00040020u,0x00000057u,0x00000002u,0x00000056u,0x0004003bu,0x00000057u,0x00000058u,0x00000002u,0x00040020u,0x00000059u,0x00000002u,0x00000009u,0x0004002bu,0x0000002fu,0x00000060u,0x00000002u,0x0004002bu,0x0000002fu,0x00000064u,0x00000003u,0x00040020u,0x00000067u,0x00000007u,0x0000000au,0x0004002bu,0x00000006u,0x00000070u,0xffffffffu,0x0005002cu,0x00000007u,0x00000071u,0x00000070u,0x0000001bu,0x0005002cu,0x00000007u,0x00000079u,0x0000001eu,0x0000001bu,0x0005002cu,0x00000007u,0x00000081u,0x0000001bu,0x00000070u,0x0005002cu,0x00000007u,0x00000089u,0x0000001bu,0x0000001eu,0x0004002bu,0x00000009u,0x000000b0u,0x3f000000u,0x00040017u,0x000000b7u,0x00000009u,0x00000002u,0x0004002bu,0x00000009u,0x000000c1u,0x3d4ccccdu,0x0004002bu,0x00000009u,0x000000c2u,0x3f800000u,0x0004003bu,0x00000017u,0x00000121u,0x00000000u,0x00090019u,0x0000013cu,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x0000013du,0x00000000u,0x0000013cu,0x0004003bu,0x0000013du,0x0000013eu,0x00000000u,0x0004002bu,0x0000002fu,0x00000142u,0x00000010u,0x0006002cu,0x00000035u,0x00000143u,0x00000142u,0x00000142u,0x0000004au,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000034u,0x00000007u,0x0004003bu,0x00000008u,0x0000003cu,0x00000007u,0x0004003bu,0x00000054u,0x00000055u,0x00000007u,0x0004003bu,0x00000054u,0x0000005cu,0x00000007u,0x0004003bu,0x00000054u,0x0000005fu,0x00000007u,0x0004003bu,0x00000054u,0x00000063u,0x00000007u,0x0004003bu,0x00000067u,0x00000068u,0x00000007u,0x0004003bu,0x00000008u,0x00000069u,0x00000007u,0x0004003bu,0x00000008u,0x0000006bu,0x00000007u,0x0004003bu,0x00000067u,0x0000006eu,0x00000007u,0x0004003bu,0x00000008u,0x00000073u,0x00000007u,0x0004003bu,0x00000008u,0x00000074u,0x00000007u,0x0004003bu,0x00000067u,0x00000077u,0x00000007u,0x0004003bu,0x00000008u,0x0000007bu,0x00000007u,0x0004003bu,0x00000008u,0x0000007cu,0x00000007u,0x0004003bu,0x00000067u,0x0000007fu,0x00000007u,0x0004003bu,0x00000008u,0x00000083u,0x00000007u,0x0004003bu,0x00000008u,0x00000084u,0x00000007u,0x0004003bu,0x00000067u,0x00000087u,0x00000007u,0x0004003bu,0x00000008u,0x0000008bu,0x00000007u,0x0004003bu,0x00000008u,0x0000008cu,0x00000007u,0x0004003bu,0x00000008u,0x0000008fu,0x00000007u,0x0004003bu,0x00000054u,0x00000093u,0x00000007u,0x0004003bu,0x00000008u,0x00000096u,0x00000007u,0x0004003bu,0x00000008u,0x00000097u,0x00000007u,0x0004003bu,0x00000054u,0x0000009au,0x00000007u,0x0004003bu,0x00000008u,0x0000009du,0x00000007u,0x0004003bu,0x00000008u,0x0000009eu,0x00000007u,0x0004003bu,0x00000054u,0x000000a1u,0x00000007u,0x0004003bu,0x00000008u,0x000000a4u,0x00000007u,0x0004003bu,0x00000008u,0x000000a5u,0x00000007u,0x0004003bu,0x00000054u,0x000000a8u,0x00000007u,0x0004003bu,0x00000008u,0x000000abu,0x00000007u,0x0004003bu,0x00000008u,0x000000acu,0x00000007u,0x0004003bu,0x00000054u,0x000000afu,0x00000007u,0x0004003bu,0x00000054u,0x000000bbu,0x00000007u,0x0004003bu,0x00000067u,0x000000c4u,0x00000007u,0x0004003bu,0x00000067u,0x000000c8u,0x00000007u,0x0004003bu,0x00000067u,0x000000ccu,0x00000007u,0x0004003bu,0x00000067u,0x000000d0u,0x00000007u,0x0004003bu,0x00000054u,0x000000d4u,0x00000007u,0x0004003bu,0x00000054u,0x000000d8u,0x00000007u,0x0004003bu,0x00000054u,0x000000e1u,0x00000007u,0x0004003bu,0x00000054u,0x000000eau,0x00000007u,0x0004003bu,0x00000054u,0x000000f3u,0x00000007u,0x0004003bu,0x00000054u,0x000000fcu,0x00000007u,0x0004003bu,0x00000067u,0x00000104u,0x00000007u,0x0004003bu,0x00000067u,0x00000114u,0x00000007u,0x0004003bu,0x00000067u,0x00000120u,0x00000007u,0x0004003bu,0x00000054u,0x0000012au,0x00000007u,0x0004003bu,0x00000067u,0x0000012eu,0x00000007u,0x0004003bu,0x00000067u,0x00000132u,0x00000007u,0x0004003du,0x00000035u,0x00000039u,0x00000037u,0x0007004fu,0x00000038u,0x0000003au,0x00000039u,0x00000039u,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x0000003bu,0x0000003au,0x0003003eu,0x00000034u,0x0000003bu,0x0004003du,0x00000016u,0x0000003du,0x00000018u,0x00040064u,0x00000015u,0x0000003eu,0x0000003du,0x00050067u,0x00000007u,0x0000003fu,0x0000003eu,0x0000001bu,0x0003003eu,0x0000003cu,0x0000003fu,0x00050041u,0x00000041u,0x00000042u,0x00000034u,0x00000030u,0x0004003du,0x00000006u,0x00000043u,0x00000042u,0x00050041u,0x00000041u,0x00000044u,0x0000003cu,0x00000030u,0x0004003du,0x00000006u,0x00000045u,0x00000044u,0x000500afu,0x00000040u,0x00000046u,0x00000043u,0x00000045u,0x000400a8u,0x00000040u,0x00000047u,0x00000046u,0x000300f7u,0x00000049u,0x00000000u,0x000400fau,0x00000047u,0x00000048u,0x00000049u,0x000200f8u,0x00000048u,0x00050041u,0x00000041u,0x0000004bu,0x00000034u,0x0000004au,0x0004003du,0x00000006u,0x0000004cu,0x0000004bu,0x00050041u,0x00000041u,0x0000004du,0x0000003cu,0x0000004au,0x0004003du,0x00000006u,0x0000004eu,0x0000004du,0x000500afu,0x00000040u,0x0000004fu,0x0000004cu,0x0000004eu,0x000200f9u,0x00000049u,0x000200f8u,0x00000049u,0x000700f5u,0x00000040u,0x00000050u,0x00000046u,0x00000005u,0x0000004fu,0x00000048u,0x000300f7u,0x00000052u,0x00000000u,0x000400fau,0x00000050u,0x00000051u,0x00000052u,0x000200f8u,0x00000051u,0x000100fdu,0x000200f8u,0x00000052u,0x00060041u,0x00000059u,0x0000005au,0x00000058u,0x0000001bu,0x00000030u,0x0004003du,0x00000009u,0x0000005bu,0x0000005au,0x0003003eu,0x00000055u,0x0000005bu,0x00060041u,0x00000059u,0x0000005du,0x00000058u,0x0000001bu,0x0000004au,0x0004003du,0x00000009u,0x0000005eu,0x0000005du,0x0003003eu,0x0000005cu,0x0000005eu,0x00060041u,0x00000059u,0x00000061u,0x00000058u,0x0000001bu,0x00000060u,0x0004003du,0x00000009u,0x00000062u,0x00000061u,0x0003003eu,0x0000005fu,0x00000062u,0x00060041u,0x00000059u,0x00000065u,0x00000058u,0x0000001bu,0x00000064u,0x0004003du,0x00000009u,0x00000066u,0x00000065u,0x0003003eu,0x00000063u,0x00000066u,0x0004003du,0x00000007u,0x0000006au,0x00000034u,0x0003003eu,0x00000069u,0x0000006au,0x0004003du,0x00000007u,0x0000006cu,0x0000003cu,0x0003003eu,0x0000006bu,0x0000006cu,0x00060039u,0x0000000au,0x0000006du,0x0000000eu,0x00000069u,0x0000006bu,0x0003003eu,0x00000068u,0x0000006du,0x0004003du,0x00000007u,0x0000006fu,0x00000034u,0x00050080u,0x00000007u,0x00000072u,0x0000006fu,0x00000071u,0x0003003eu,0x00000073u,0x00000072u,0x0004003du,0x00000007u,0x00000075u,0x0000003cu,0x0003003eu,0x00000074u,0x00000075u,0x00060039u,0x0000000au,0x00000076u,0x0000000eu,0x00000073u,0x00000074u,0x0003003eu,0x0000006eu,0x00000076u,0x0004003du,0x00000007u,0x00000078u,0x00000034u,0x00050080u,0x00000007u,0x0000007au,0x00000078u,0x00000079u,0x0003003eu,0x0000007bu,0x0000007au,0x0004003du,0x00000007u,0x0000007du,0x0000003cu,0x0003003eu,0x0000007cu,0x0000007du,0x00060039u,0x0000000au,0x0000007eu,0x0000000eu,0x0000007bu,0x0000007cu,0x0003003eu,0x00000077u,0x0000007eu,0x0004003du,0x00000007u,0x00000080u,0x00000034u,0x00050080u,0x00000007u,0x00000082u,0x00000080u,0x00000081u,0x0003003eu,0x00000083u,0x00000082u,0x0004003du,0x00000007u,0x00000085u,0x0000003cu,0x0003003eu,0x00000084u,0x00000085u,0x00060039u,0x0000000au,0x00000086u,0x0000000eu,0x00000083u,0x00000084u,0x0003003eu,0x0000007fu,0x00000086u,0x0004003du,0x00000007u,0x00000088u,0x00000034u,0x00050080u,0x00000007u,0x0000008au,0x00000088u,0x00000089u,0x0003003eu,0x0000008bu,0x0000008au,0x0004003du,0x00000007u,0x0000008du,0x0000003cu,0x0003003eu,0x0000008cu,0x0000008du,0x00060039u,0x0000000au,0x0000008eu,0x0000000eu,0x0000008bu,0x0000008cu,0x0003003eu,0x00000087u,0x0000008eu,0x0004003du,0x00000016u,0x00000090u,0x00000026u,0x00040064u,0x00000015u,0x00000091u,0x00000090u,0x00050067u,0x00000007u,0x00000092u,0x00000091u,0x0000001bu,0x0003003eu,0x0000008fu,0x00000092u,0x0004003du,0x00000007u,0x00000094u,0x00000034u,0x00050080u,0x00000007u,0x00000095u,0x00000094u,0x00000071u,0x0003003eu,0x00000096u,0x00000095u,0x0004003du,0x00000007u,0x00000098u,0x0000008fu,0x0003003eu,0x00000097u,0x00000098u,0x00060039u,0x00000009u,0x00000099u,0x00000013u,0x00000096u,0x00000097u,0x0003003eu,0x00000093u,0x00000099u,0x0004003du,0x00000007u,0x0000009bu,0x00000034u,0x00050080u,0x00000007u,0x0000009cu,0x0000009bu,0x00000079u,0x0003003eu,0x0000009du,0x0000009cu,0x0004003du,0x00000007u,0x0000009fu,0x0000008fu,0x0003003eu,0x0000009eu,0x0000009fu,0x00060039u,0x00000009u,0x000000a0u,0x00000013u,0x0000009du,0x0000009eu,0x0003003eu,0x0000009au,0x000000a0u,0x0004003du,0x00000007u,0x000000a2u,0x00000034u,0x00050080u,0x00000007u,0x000000a3u,0x000000a2u,0x00000081u,0x0003003eu,0x000000a4u,0x000000a3u,0x0004003du,0x00000007u,0x000000a6u,0x0000008fu,0x0003003eu,0x000000a5u,0x000000a6u,0x00060039u,0x00000009u,0x000000a7u,0x00000013u,0x000000a4u,0x000000a5u,0x0003003eu,0x000000a1u,0x000000a7u,0x0004003du,0x00000007u,0x000000a9u,0x00000034u,0x00050080u,0x00000007u,0x000000aau,0x000000a9u,0x00000089u,0x0003003eu,0x000000abu,0x000000aau,0x0004003du,0x00000007u,0x000000adu,0x0000008fu,0x0003003eu,0x000000acu,0x000000adu,0x00060039u,0x00000009u,0x000000aeu,0x00000013u,0x000000abu,0x000000acu,0x0003003eu,0x000000a8u,0x000000aeu,0x0004003du,0x00000009u,0x000000b1u,0x0000009au,0x0004003du,0x00000009u,0x000000b2u,0x00000093u,0x00050083u,0x00000009u,0x000000b3u,0x000000b1u,0x000000b2u,0x0004003du,0x00000009u,0x000000b4u,0x000000a8u,0x0004003du,0x00000009u,0x000000b5u,0x000000a1u,0x00050083u,0x00000009u,0x000000b6u,0x000000b4u,0x000000b5u,0x00050050u,0x000000b7u,0x000000b8u,0x000000b3u,0x000000b6u,0x0006000cu,0x00000009u,0x000000b9u,0x00000001u,0x00000042u,0x000000b8u,0x00050085u,0x00000009u,0x000000bau,0x000000b0u,0x000000b9u,0x0003003eu,0x000000afu,0x000000bau,0x0004003du,0x00000009u,0x000000bcu,0x0000005fu,0x0004007fu,0x00000009u,0x000000bdu,0x000000bcu,0x0004003du,0x00000009u,0x000000beu,0x000000afu,0x00050085u,0x00000009u,0x000000bfu,0x000000bdu,0x000000beu,0x0006000cu,0x00000009u,0x000000c0u,0x00000001u,0x0000001bu,0x000000bfu,0x0008000cu,0x00000009u,0x000000c3u,0x00000001u,0x0000002bu,0x000000c0u,0x000000c1u,0x000000c2u,0x0003003eu,0x000000bbu,0x000000c3u,0x0004003du,0x0000000au,0x000000c5u,0x0000006eu,0x0004003du,0x0000000au,0x000000c6u,0x00000068u,0x00050083u,0x0000000au,0x000000c7u,0x000000c5u,0x000000c6u,0x0003003eu,0x000000c4u,0x000000c7u,0x0004003du,0x0000000au,0x000000c9u,0x00000077u,0x0004003du,0x0000000au,0x000000cau,0x00000068u,0x00050083u,0x0000000au,0x000000cbu,0x000000c9u,0x000000cau,0x0003003eu,0x000000c8u,0x000000cbu,0x0004003du,0x0000000au,0x000000cdu,0x0000007fu,0x0004003du,0x0000000au,0x000000ceu,0x00000068u,0x00050083u,0x0000000au,0x000000cfu,0x000000cdu,0x000000ceu,0x0003003eu,0x000000ccu,0x000000cfu,0x0004003du,0x0000000au,0x000000d1u,0x00000087u,0x0004003du,0x0000000au,0x000000d2u,0x00000068u,0x00050083u,0x0000000au,0x000000d3u,0x000000d1u,0x000000d2u,0x0003003eu,0x000000d0u,0x000000d3u,0x0004003du,0x00000009u,0x000000d5u,0x00000063u,0x0004003du,0x00000009u,0x000000d6u,0x00000063u,0x00050085u,0x00000009u,0x000000d7u,0x000000d5u,0x000000d6u,0x0003003eu,0x000000d4u,0x000000d7u,0x0004003du,0x00000009u,0x000000d9u,0x000000bbu,0x0004003du,0x0000000au,0x000000dau,0x000000c4u,0x0004003du,0x0000000au,0x000000dbu,0x000000c4u,0x00050094u,0x00000009u,0x000000dcu,0x000000dau,0x000000dbu,0x0004003du,0x00000009u,0x000000ddu,0x000000d4u,0x00050081u,0x00000009u,0x000000deu,0x000000dcu,0x000000ddu,0x0006000cu,0x00000009u,0x000000dfu,0x00000001u,0x00000020u,0x000000deu,0x00050085u,0x00000009u,0x000000e0u,0x000000d9u,0x000000dfu,0x0003003eu,0x000000d8u,0x000000e0u,0x0004003du,0x00000009u,0x000000e2u,0x000000bbu,0x0004003du,0x0000000au,0x000000e3u,0x000000c8u,0x0004003du,0x0000000au,0x000000e4u,0x000000c8u,0x00050094u,0x00000009u,0x000000e5u,0x000000e3u,0x000000e4u,0x0004003du,0x00000009u,0x000000e6u,0x000000d4u,0x00050081u,0x00000009u,0x000000e7u,0x000000e5u,0x000000e6u,0x0006000cu,0x00000009u,0x000000e8u,0x00000001u,0x00000020u,0x000000e7u,0x00050085u,0x00000009u,0x000000e9u,0x000000e2u,0x000000e8u,0x0003003eu,0x000000e1u,0x000000e9u,0x0004003du,0x00000009u,0x000000ebu,0x000000bbu,0x0004003du,0x0000000au,0x000000ecu,0x000000ccu,0x0004003du,0x0000000au,0x000000edu,0x000000ccu,0x00050094u,0x00000009u,0x000000eeu,0x000000ecu,0x000000edu,0x0004003du,0x00000009u,0x000000efu,0x000000d4u,0x00050081u,0x00000009u,0x000000f0u,0x000000eeu,0x000000efu,0x0006000cu,0x00000009u,0x000000f1u,0x00000001u,0x00000020u,0x000000f0u,0x00050085u,0x00000009u,0x000000f2u,0x000000ebu,0x000000f1u,0x0003003eu,0x000000eau,0x000000f2u,0x0004003du,0x00000009u,0x000000f4u,0x000000bbu,0x0004003du,0x0000000au,0x000000f5u,0x000000d0u,0x0004003du,0x0000000au,0x000000f6u,0x000000d0u,0x00050094u,0x00000009u,0x000000f7u,0x000000f5u,0x000000f6u,0x0004003du,0x00000009u,0x000000f8u,0x000000d4u,0x00050081u,0x00000009u,0x000000f9u,0x000000f7u,0x000000f8u,0x0006000cu,0x00000009u,0x000000fau,0x00000001u,0x00000020u,0x000000f9u,0x00050085u,0x00000009u,0x000000fbu,0x000000f4u,0x000000fau,0x0003003eu,0x000000f3u,0x000000fbu,0x0004003du,0x00000009u,0x000000fdu,0x000000d8u,0x0004003du,0x00000009u,0x000000feu,0x000000e1u,0x00050081u,0x00000009u,0x000000ffu,0x000000fdu,0x000000feu,0x0004003du,0x00000009u,0x00000100u,0x000000eau,0x00050081u,0x00000009u,0x00000101u,0x000000ffu,0x00000100u,0x0004003du,0x00000009u,0x00000102u,0x000000f3u,0x00050081u,0x00000009u,0x00000103u,0x00000101u,0x00000102u,0x0003003eu,0x000000fcu,0x00000103u,0x0004003du,0x00000009u,0x00000105u,0x000000d8u,0x0004003du,0x0000000au,0x00000106u,0x0000006eu,0x0005008eu,0x0000000au,0x00000107u,0x00000106u,0x00000105u,0x0004003du,0x00000009u,0x00000108u,0x000000e1u,0x0004003du,0x0000000au,0x00000109u,0x00000077u,0x0005008eu,0x0000000au,0x0000010au,0x00000109u,0x00000108u,0x00050081u,0x0000000au,0x0000010bu,0x00000107u,0x0000010au,0x0004003du,0x00000009u,0x0000010cu,0x000000eau,0x0004003du,0x0000000au,0x0000010du,0x0000007fu,0x0005008eu,0x0000000au,0x0000010eu,0x0000010du,0x0000010cu,0x00050081u,0x0000000au,0x0000010fu,0x0000010bu,0x0000010eu,0x0004003du,0x00000009u,0x00000110u,0x000000f3u,0x0004003du,0x0000000au,0x00000111u,0x00000087u,0x0005008eu,0x0000000au,0x00000112u,0x00000111u,0x00000110u,0x00050081u,0x0000000au,0x00000113u,0x0000010fu,0x00000112u,0x0003003eu,0x00000104u,0x00000113u,0x0004003du,0x0000000au,0x00000115u,0x00000068u,0x0004003du,0x00000009u,0x00000116u,0x00000055u,0x0004003du,0x0000000au,0x00000117u,0x00000104u,0x0005008eu,0x0000000au,0x00000118u,0x00000117u,0x00000116u,0x00050081u,0x0000000au,0x00000119u,0x00000115u,0x00000118u,0x0004003du,0x00000009u,0x0000011au,0x00000055u,0x0004003du,0x00000009u,0x0000011bu,0x000000fcu,0x00050085u,0x00000009u,0x0000011cu,0x0000011au,0x0000011bu,0x00050081u,0x00000009u,0x0000011du,0x000000c2u,0x0000011cu,0x00070050u,0x0000000au,0x0000011eu,0x0000011du,0x0000011du,0x0000011du,0x0000011du,0x00050088u,0x0000000au,0x0000011fu,0x00000119u,0x0000011eu,0x0003003eu,0x00000114u,0x0000011fu,0x0004003du,0x00000016u,0x00000122u,0x00000121u,0x0004003du,0x00000007u,0x00000123u,0x00000034u,0x0004003du,0x00000007u,0x00000124u,0x0000003cu,0x00050050u,0x00000007u,0x00000125u,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x00000126u,0x00000124u,0x00000125u,0x0008000cu,0x00000007u,0x00000127u,0x00000001u,0x0000002du,0x00000123u,0x0000001cu,0x00000126u,0x00040064u,0x00000015u,0x00000128u,0x00000122u,0x0007005fu,0x0000000au,0x00000129u,0x00000128u,0x00000127u,0x00000002u,0x0000001bu,0x0003003eu,0x00000120u,0x00000129u,0x0004003du,0x00000009u,0x0000012bu,0x00000055u,0x0004003du,0x00000009u,0x0000012cu,0x0000005cu,0x00050085u,0x00000009u,0x0000012du,0x0000012bu,0x0000012cu,0x0003003eu,0x0000012au,0x0000012du,0x0004003du,0x0000000au,0x0000012fu,0x00000114u,0x0004003du,0x0000000au,0x00000130u,0x00000120u,0x00050083u,0x0000000au,0x00000131u,0x0000012fu,0x00000130u,0x0003003eu,0x0000012eu,0x00000131u,0x0004003du,0x0000000au,0x00000133u,0x00000114u,0x0004003du,0x0000000au,0x00000134u,0x0000012eu,0x0004003du,0x00000009u,0x00000135u,0x0000012au,0x0004007fu,0x00000009u,0x00000136u,0x00000135u,0x00070050u,0x0000000au,0x00000137u,0x00000136u,0x00000136u,0x00000136u,0x00000136u,0x0004003du,0x00000009u,0x00000138u,0x0000012au,0x00070050u,0x0000000au,0x00000139u,0x00000138u,0x00000138u,0x00000138u,0x00000138u,0x0008000cu,0x0000000au,0x0000013au,0x00000001u,0x0000002bu,0x00000134u,0x00000137u,0x00000139u,0x00050083u,0x0000000au,0x0000013bu,0x00000133u,0x0000013au,0x0003003eu,0x00000132u,0x0000013bu,0x0004003du,0x0000013cu,0x0000013fu,0x0000013eu,0x0004003du,0x00000007u,0x00000140u,0x00000034u,0x0004003du,0x0000000au,0x00000141u,0x00000132u,0x00040063u,0x0000013fu,0x00000140u,0x00000141u,0x000100fdu,0x00010038u,0x00050036u,0x0000000au,0x0000000eu,0x00000000u,0x0000000bu,0x00030037u,0x00000008u,0x0000000cu,0x00030037u,0x00000008u,0x0000000du,0x000200f8u,0x0000000fu,0x0004003du,0x00000016u,0x00000019u,0x00000018u,0x0004003du,0x00000007u,0x0000001au,0x0000000cu,0x0004003du,0x00000007u,0x0000001du,0x0000000du,0x00050050u,0x00000007u,0x0000001fu,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x00000020u,0x0000001du,0x0000001fu,0x0008000cu,0x00000007u,0x00000021u,0x00000001u,0x0000002du,0x0000001au,0x0000001cu,0x00000020u,0x00040064u,0x00000015u,0x00000022u,0x00000019u,0x0007005fu,0x0000000au,0x00000023u,0x00000022u,0x00000021u,0x00000002u,0x0000001bu,0x000200feu,0x00000023u,0x00010038u,0x00050036u,0x00000009u,0x00000013u,0x00000000u,0x00000010u,0x00030037u,0x00000008u,0x00000011u,0x00030037u,0x00000008u,0x00000012u,0x000200f8u,0x00000014u,0x0004003du,0x00000016u,0x00000027u,0x00000026u,0x0004003du,0x00000007u,0x00000028u,0x00000011u,0x0004003du,0x00000007u,0x00000029u,0x00000012u,0x00050050u,0x00000007u,0x0000002au,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x0000002bu,0x00000029u,0x0000002au,0x0008000cu,0x00000007u,0x0000002cu,0x00000001u,0x0000002du,0x00000028u,0x0000001cu,0x0000002bu,0x00040064u,0x00000015u,0x0000002du,0x00000027u,0x0007005fu,0x0000000au,0x0000002eu,0x0000002du,0x0000002cu,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x00000031u,0x0000002eu,0x00000000u,0x000200feu,0x00000031u,0x00010038u}; -static const size_t OF3_FLOWREG_LEN = 1936; +static const uint32_t OF3_FLOWREG_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000196u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000037u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00040005u,0x00000018u,0x6f6c4675u,0x006e4977u,0x00040005u,0x00000026u,0x6d754c75u,0x00000061u,0x00080005u,0x00000037u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000056u,0x00000055u,0x00050006u,0x00000056u,0x00000000u,0x61726170u,0x0000736du,0x00030005u,0x00000058u,0x00000000u,0x00050005u,0x00000118u,0x6f6c4675u,0x73624f77u,0x00000000u,0x00050005u,0x00000131u,0x6f6c4675u,0x74754f77u,0x00000000u,0x00040047u,0x00000018u,0x00000021u,0x00000020u,0x00040047u,0x00000018u,0x00000022u,0x00000000u,0x00040047u,0x00000026u,0x00000021u,0x00000022u,0x00040047u,0x00000026u,0x00000022u,0x00000000u,0x00040047u,0x00000037u,0x0000000bu,0x0000001cu,0x00030047u,0x00000056u,0x00000002u,0x00050048u,0x00000056u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x00000058u,0x00000021u,0x00000000u,0x00040047u,0x00000058u,0x00000022u,0x00000000u,0x00040047u,0x00000118u,0x00000021u,0x00000021u,0x00040047u,0x00000118u,0x00000022u,0x00000000u,0x00030047u,0x00000131u,0x00000019u,0x00040047u,0x00000131u,0x00000021u,0x00000030u,0x00040047u,0x00000131u,0x00000022u,0x00000000u,0x00040047u,0x00000136u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00030016u,0x00000009u,0x00000020u,0x00040017u,0x0000000au,0x00000009u,0x00000004u,0x00090019u,0x00000015u,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000016u,0x00000015u,0x00040020u,0x00000017u,0x00000000u,0x00000016u,0x0004003bu,0x00000017u,0x00000018u,0x00000000u,0x0004002bu,0x00000006u,0x0000001bu,0x00000000u,0x0005002cu,0x00000007u,0x0000001cu,0x0000001bu,0x0000001bu,0x0004002bu,0x00000006u,0x0000001eu,0x00000001u,0x0004003bu,0x00000017u,0x00000026u,0x00000000u,0x00040015u,0x0000002fu,0x00000020u,0x00000000u,0x0004002bu,0x0000002fu,0x00000030u,0x00000000u,0x00040017u,0x00000035u,0x0000002fu,0x00000003u,0x00040020u,0x00000036u,0x00000001u,0x00000035u,0x0004003bu,0x00000036u,0x00000037u,0x00000001u,0x00040017u,0x00000038u,0x0000002fu,0x00000002u,0x00020014u,0x00000040u,0x0004002bu,0x0000002fu,0x0000004au,0x00000001u,0x0003001eu,0x00000056u,0x0000000au,0x00040020u,0x00000057u,0x00000002u,0x00000056u,0x0004003bu,0x00000057u,0x00000058u,0x00000002u,0x00040020u,0x00000059u,0x00000002u,0x00000009u,0x0004002bu,0x0000002fu,0x00000060u,0x00000002u,0x0004002bu,0x0000002fu,0x00000064u,0x00000003u,0x0004002bu,0x00000006u,0x0000006fu,0xffffffffu,0x0005002cu,0x00000007u,0x00000070u,0x0000006fu,0x0000001bu,0x0005002cu,0x00000007u,0x00000078u,0x0000001eu,0x0000001bu,0x0005002cu,0x00000007u,0x00000080u,0x0000001bu,0x0000006fu,0x0005002cu,0x00000007u,0x00000088u,0x0000001bu,0x0000001eu,0x0004002bu,0x00000009u,0x000000abu,0x3f000000u,0x00040017u,0x000000b2u,0x00000009u,0x00000002u,0x0004002bu,0x00000009u,0x000000bcu,0x3d4ccccdu,0x0004002bu,0x00000009u,0x000000bdu,0x3f800000u,0x0004003bu,0x00000017u,0x00000118u,0x00000000u,0x00090019u,0x0000012fu,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000130u,0x00000000u,0x0000012fu,0x0004003bu,0x00000130u,0x00000131u,0x00000000u,0x0004002bu,0x0000002fu,0x00000135u,0x00000010u,0x0006002cu,0x00000035u,0x00000136u,0x00000135u,0x00000135u,0x0000004au,0x0005002cu,0x00000007u,0x00000195u,0x0000001eu,0x0000001eu,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x000300f7u,0x00000137u,0x00000000u,0x000300fbu,0x00000030u,0x00000138u,0x000200f8u,0x00000138u,0x0004003du,0x00000035u,0x00000039u,0x00000037u,0x0007004fu,0x00000038u,0x0000003au,0x00000039u,0x00000039u,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x0000003bu,0x0000003au,0x0004003du,0x00000016u,0x0000003du,0x00000018u,0x00040064u,0x00000015u,0x0000003eu,0x0000003du,0x00050067u,0x00000007u,0x0000003fu,0x0000003eu,0x0000001bu,0x00050051u,0x00000006u,0x00000043u,0x0000003bu,0x00000000u,0x00050051u,0x00000006u,0x00000045u,0x0000003fu,0x00000000u,0x000500afu,0x00000040u,0x00000046u,0x00000043u,0x00000045u,0x000400a8u,0x00000040u,0x00000047u,0x00000046u,0x000300f7u,0x00000049u,0x00000000u,0x000400fau,0x00000047u,0x00000048u,0x00000049u,0x000200f8u,0x00000048u,0x00050051u,0x00000006u,0x0000004cu,0x0000003bu,0x00000001u,0x00050051u,0x00000006u,0x0000004eu,0x0000003fu,0x00000001u,0x000500afu,0x00000040u,0x0000004fu,0x0000004cu,0x0000004eu,0x000200f9u,0x00000049u,0x000200f8u,0x00000049u,0x000700f5u,0x00000040u,0x00000050u,0x00000046u,0x00000138u,0x0000004fu,0x00000048u,0x000300f7u,0x00000052u,0x00000000u,0x000400fau,0x00000050u,0x00000051u,0x00000052u,0x000200f8u,0x00000051u,0x000200f9u,0x00000137u,0x000200f8u,0x00000052u,0x00060041u,0x00000059u,0x0000005au,0x00000058u,0x0000001bu,0x00000030u,0x0004003du,0x00000009u,0x0000005bu,0x0000005au,0x00060041u,0x00000059u,0x0000005du,0x00000058u,0x0000001bu,0x0000004au,0x0004003du,0x00000009u,0x0000005eu,0x0000005du,0x00060041u,0x00000059u,0x00000061u,0x00000058u,0x0000001bu,0x00000060u,0x0004003du,0x00000009u,0x00000062u,0x00000061u,0x00060041u,0x00000059u,0x00000065u,0x00000058u,0x0000001bu,0x00000064u,0x0004003du,0x00000009u,0x00000066u,0x00000065u,0x0004003du,0x00000016u,0x00000069u,0x00000018u,0x00040064u,0x00000015u,0x0000006bu,0x00000069u,0x0007005fu,0x0000000au,0x0000006cu,0x0000006bu,0x0000003bu,0x00000002u,0x0000001bu,0x00050080u,0x00000007u,0x00000071u,0x0000003bu,0x00000070u,0x0004003du,0x00000016u,0x0000013fu,0x00000018u,0x00050082u,0x00000007u,0x00000143u,0x0000003fu,0x00000195u,0x0008000cu,0x00000007u,0x00000144u,0x00000001u,0x0000002du,0x00000071u,0x0000001cu,0x00000143u,0x00040064u,0x00000015u,0x00000145u,0x0000013fu,0x0007005fu,0x0000000au,0x00000146u,0x00000145u,0x00000144u,0x00000002u,0x0000001bu,0x00050080u,0x00000007u,0x00000079u,0x0000003bu,0x00000078u,0x0004003du,0x00000016u,0x00000149u,0x00000018u,0x0008000cu,0x00000007u,0x0000014eu,0x00000001u,0x0000002du,0x00000079u,0x0000001cu,0x00000143u,0x00040064u,0x00000015u,0x0000014fu,0x00000149u,0x0007005fu,0x0000000au,0x00000150u,0x0000014fu,0x0000014eu,0x00000002u,0x0000001bu,0x00050080u,0x00000007u,0x00000081u,0x0000003bu,0x00000080u,0x0004003du,0x00000016u,0x00000153u,0x00000018u,0x0008000cu,0x00000007u,0x00000158u,0x00000001u,0x0000002du,0x00000081u,0x0000001cu,0x00000143u,0x00040064u,0x00000015u,0x00000159u,0x00000153u,0x0007005fu,0x0000000au,0x0000015au,0x00000159u,0x00000158u,0x00000002u,0x0000001bu,0x00050080u,0x00000007u,0x00000089u,0x0000003bu,0x00000088u,0x0004003du,0x00000016u,0x0000015du,0x00000018u,0x0008000cu,0x00000007u,0x00000162u,0x00000001u,0x0000002du,0x00000089u,0x0000001cu,0x00000143u,0x00040064u,0x00000015u,0x00000163u,0x0000015du,0x0007005fu,0x0000000au,0x00000164u,0x00000163u,0x00000162u,0x00000002u,0x0000001bu,0x0004003du,0x00000016u,0x00000167u,0x00000026u,0x00040064u,0x00000015u,0x0000016du,0x00000167u,0x0007005fu,0x0000000au,0x0000016eu,0x0000016du,0x00000144u,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x0000016fu,0x0000016eu,0x00000000u,0x0004003du,0x00000016u,0x00000172u,0x00000026u,0x00040064u,0x00000015u,0x00000178u,0x00000172u,0x0007005fu,0x0000000au,0x00000179u,0x00000178u,0x0000014eu,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x0000017au,0x00000179u,0x00000000u,0x0004003du,0x00000016u,0x0000017du,0x00000026u,0x00040064u,0x00000015u,0x00000183u,0x0000017du,0x0007005fu,0x0000000au,0x00000184u,0x00000183u,0x00000158u,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x00000185u,0x00000184u,0x00000000u,0x0004003du,0x00000016u,0x00000188u,0x00000026u,0x00040064u,0x00000015u,0x0000018eu,0x00000188u,0x0007005fu,0x0000000au,0x0000018fu,0x0000018eu,0x00000162u,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x00000190u,0x0000018fu,0x00000000u,0x00050083u,0x00000009u,0x000000aeu,0x0000017au,0x0000016fu,0x00050083u,0x00000009u,0x000000b1u,0x00000190u,0x00000185u,0x00050050u,0x000000b2u,0x000000b3u,0x000000aeu,0x000000b1u,0x0006000cu,0x00000009u,0x000000b4u,0x00000001u,0x00000042u,0x000000b3u,0x00050085u,0x00000009u,0x000000b5u,0x000000abu,0x000000b4u,0x0004007fu,0x00000009u,0x000000b8u,0x00000062u,0x00050085u,0x00000009u,0x000000bau,0x000000b8u,0x000000b5u,0x0006000cu,0x00000009u,0x000000bbu,0x00000001u,0x0000001bu,0x000000bau,0x0008000cu,0x00000009u,0x000000beu,0x00000001u,0x0000002bu,0x000000bbu,0x000000bcu,0x000000bdu,0x00050083u,0x0000000au,0x000000c2u,0x00000146u,0x0000006cu,0x00050083u,0x0000000au,0x000000c6u,0x00000150u,0x0000006cu,0x00050083u,0x0000000au,0x000000cau,0x0000015au,0x0000006cu,0x00050083u,0x0000000au,0x000000ceu,0x00000164u,0x0000006cu,0x00050085u,0x00000009u,0x000000d2u,0x00000066u,0x00000066u,0x00050094u,0x00000009u,0x000000d6u,0x000000c2u,0x000000c2u,0x00050081u,0x00000009u,0x000000d8u,0x000000d6u,0x000000d2u,0x0006000cu,0x00000009u,0x000000d9u,0x00000001u,0x00000020u,0x000000d8u,0x00050094u,0x00000009u,0x000000ddu,0x000000c6u,0x000000c6u,0x00050081u,0x00000009u,0x000000dfu,0x000000ddu,0x000000d2u,0x0006000cu,0x00000009u,0x000000e0u,0x00000001u,0x00000020u,0x000000dfu,0x00050094u,0x00000009u,0x000000e4u,0x000000cau,0x000000cau,0x00050081u,0x00000009u,0x000000e6u,0x000000e4u,0x000000d2u,0x0006000cu,0x00000009u,0x000000e7u,0x00000001u,0x00000020u,0x000000e6u,0x00050094u,0x00000009u,0x000000ebu,0x000000ceu,0x000000ceu,0x00050081u,0x00000009u,0x000000edu,0x000000ebu,0x000000d2u,0x0006000cu,0x00000009u,0x000000eeu,0x00000001u,0x00000020u,0x000000edu,0x00050081u,0x00000009u,0x000000f3u,0x000000d9u,0x000000e0u,0x00050081u,0x00000009u,0x000000f5u,0x000000f3u,0x000000e7u,0x00050081u,0x00000009u,0x000000f7u,0x000000f5u,0x000000eeu,0x00050085u,0x00000009u,0x000000f8u,0x000000beu,0x000000f7u,0x0005008eu,0x0000000au,0x000000fdu,0x00000146u,0x000000d9u,0x0005008eu,0x0000000au,0x00000100u,0x00000150u,0x000000e0u,0x00050081u,0x0000000au,0x00000101u,0x000000fdu,0x00000100u,0x0005008eu,0x0000000au,0x00000104u,0x0000015au,0x000000e7u,0x00050081u,0x0000000au,0x00000105u,0x00000101u,0x00000104u,0x0005008eu,0x0000000au,0x00000108u,0x00000164u,0x000000eeu,0x00050081u,0x0000000au,0x00000109u,0x00000105u,0x00000108u,0x0005008eu,0x0000000au,0x0000010au,0x00000109u,0x000000beu,0x0005008eu,0x0000000au,0x0000010fu,0x0000010au,0x0000005bu,0x00050081u,0x0000000au,0x00000110u,0x0000006cu,0x0000010fu,0x00050085u,0x00000009u,0x00000113u,0x0000005bu,0x000000f8u,0x00050081u,0x00000009u,0x00000114u,0x000000bdu,0x00000113u,0x00070050u,0x0000000au,0x00000115u,0x00000114u,0x00000114u,0x00000114u,0x00000114u,0x00050088u,0x0000000au,0x00000116u,0x00000110u,0x00000115u,0x0004003du,0x00000016u,0x00000119u,0x00000118u,0x00040064u,0x00000015u,0x0000011bu,0x00000119u,0x0007005fu,0x0000000au,0x0000011cu,0x0000011bu,0x0000003bu,0x00000002u,0x0000001bu,0x00050085u,0x00000009u,0x00000120u,0x0000005bu,0x0000005eu,0x00050083u,0x0000000au,0x00000124u,0x00000116u,0x0000011cu,0x0004007fu,0x00000009u,0x00000129u,0x00000120u,0x00070050u,0x0000000au,0x0000012au,0x00000129u,0x00000129u,0x00000129u,0x00000129u,0x00070050u,0x0000000au,0x0000012cu,0x00000120u,0x00000120u,0x00000120u,0x00000120u,0x0008000cu,0x0000000au,0x0000012du,0x00000001u,0x0000002bu,0x00000124u,0x0000012au,0x0000012cu,0x00050083u,0x0000000au,0x0000012eu,0x00000116u,0x0000012du,0x0004003du,0x0000012fu,0x00000132u,0x00000131u,0x00040063u,0x00000132u,0x0000003bu,0x0000012eu,0x000200f9u,0x00000137u,0x000200f8u,0x00000137u,0x000100fdu,0x00010038u}; +static const size_t OF3_FLOWREG_LEN = 981; static const uint32_t DDFG_SYNTH_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000208u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000001cu,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00050005u,0x0000000bu,0x616d756cu,0x33667628u,0x0000003bu,0x00030005u,0x0000000au,0x00000063u,0x00030005u,0x00000018u,0x00646967u,0x00080005u,0x0000001cu,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000021u,0x006d6964u,0x00040005u,0x00000024u,0x74754f75u,0x00000000u,0x00040005u,0x0000003eu,0x44766e69u,0x00006d69u,0x00030005u,0x00000044u,0x00007675u,0x00030005u,0x0000004du,0x00000055u,0x00060006u,0x0000004du,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x0000004du,0x00000001u,0x68706c61u,0x00000061u,0x00050006u,0x0000004du,0x00000002u,0x61746562u,0x00000000u,0x00050006u,0x0000004du,0x00000003u,0x626d616cu,0x00006164u,0x00050006u,0x0000004du,0x00000004u,0x69737065u,0x006e6f6cu,0x00060006u,0x0000004du,0x00000005u,0x746f6870u,0x6163536fu,0x0000656cu,0x00050006u,0x0000004du,0x00000006u,0x30646170u,0x00000000u,0x00050006u,0x0000004du,0x00000007u,0x31646170u,0x00000000u,0x00050006u,0x0000004du,0x00000008u,0x52647568u,0x00746365u,0x00030005u,0x0000004fu,0x00000000u,0x00040005u,0x0000008cu,0x72754375u,0x00000072u,0x00030005u,0x00000098u,0x00676264u,0x00030005u,0x0000009fu,0x00007366u,0x00040005u,0x000000a9u,0x64774273u,0x00000000u,0x00050005u,0x000000aau,0x6f6c4675u,0x64774277u,0x00000000u,0x00040005u,0x000000aeu,0x64774673u,0x00000000u,0x00050005u,0x000000afu,0x6f6c4675u,0x64774677u,0x00000000u,0x00030005u,0x000000b3u,0x00313046u,0x00030005u,0x000000bau,0x00303146u,0x00040005u,0x000000c1u,0x31306663u,0x00000000u,0x00040005u,0x000000c5u,0x30316663u,0x00000000u,0x00030005u,0x000000c9u,0x0031306du,0x00030005u,0x000000d5u,0x0030316du,0x00030005u,0x000000e0u,0x00004170u,0x00030005u,0x000000e8u,0x00004270u,0x00030005u,0x000000f0u,0x00003043u,0x00040005u,0x000000f1u,0x65725075u,0x00000076u,0x00030005u,0x000000f6u,0x00003143u,0x00030005u,0x000000fbu,0x00004165u,0x00040005u,0x000000fcu,0x61726170u,0x0000006du,0x00040005u,0x0000010cu,0x61726170u,0x0000006du,0x00030005u,0x00000111u,0x00004265u,0x00040005u,0x00000112u,0x61726170u,0x0000006du,0x00040005u,0x00000122u,0x61726170u,0x0000006du,0x00040005u,0x00000127u,0x76556266u,0x00000000u,0x00040005u,0x0000012bu,0x65526266u,0x00646973u,0x00040005u,0x00000138u,0x736e6f63u,0x00747369u,0x00030005u,0x00000149u,0x0000305au,0x00030005u,0x00000157u,0x0000315au,0x00040005u,0x00000163u,0x30756174u,0x00000000u,0x00040005u,0x00000167u,0x31756174u,0x00000000u,0x00040005u,0x0000016au,0x78616d7au,0x00000000u,0x00030005u,0x0000016eu,0x00003057u,0x00030005u,0x00000179u,0x00003157u,0x00040005u,0x00000183u,0x6d757357u,0x00000000u,0x00040005u,0x00000187u,0x70726177u,0x00006465u,0x00050005u,0x000001a0u,0x736f7263u,0x64616673u,0x00000065u,0x00050005u,0x000001adu,0x746f6870u,0x7272456fu,0x00000000u,0x00050005u,0x000001b1u,0x746f6870u,0x7572546fu,0x00007473u,0x00040005u,0x000001b7u,0x73757274u,0x00000074u,0x00040005u,0x000001c3u,0x76657270u,0x00000043u,0x00040005u,0x000001c8u,0x72727563u,0x00000043u,0x00050005u,0x000001cdu,0x746e6f63u,0x44746e65u,0x00666669u,0x00050005u,0x000001d2u,0x72746e75u,0x65747375u,0x00000064u,0x00040005u,0x000001d7u,0x44676962u,0x00666669u,0x00050005u,0x000001dcu,0x70616e73u,0x75436f54u,0x00007272u,0x00040005u,0x000001e5u,0x6374756fu,0x00000000u,0x00030005u,0x000001eeu,0x0067616du,0x00030005u,0x000001f2u,0x0000006eu,0x00030005u,0x000001f6u,0x00746173u,0x00040047u,0x0000001cu,0x0000000bu,0x0000001cu,0x00030047u,0x00000024u,0x00000019u,0x00040047u,0x00000024u,0x00000021u,0x00000030u,0x00040047u,0x00000024u,0x00000022u,0x00000000u,0x00030047u,0x0000004du,0x00000002u,0x00050048u,0x0000004du,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000004du,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x0000004du,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x0000004du,0x00000003u,0x00000023u,0x0000000cu,0x00050048u,0x0000004du,0x00000004u,0x00000023u,0x00000010u,0x00050048u,0x0000004du,0x00000005u,0x00000023u,0x00000014u,0x00050048u,0x0000004du,0x00000006u,0x00000023u,0x00000018u,0x00050048u,0x0000004du,0x00000007u,0x00000023u,0x0000001cu,0x00050048u,0x0000004du,0x00000008u,0x00000023u,0x00000020u,0x00040047u,0x0000004fu,0x00000021u,0x00000000u,0x00040047u,0x0000004fu,0x00000022u,0x00000000u,0x00040047u,0x0000008cu,0x00000021u,0x00000021u,0x00040047u,0x0000008cu,0x00000022u,0x00000000u,0x00040047u,0x000000aau,0x00000021u,0x00000023u,0x00040047u,0x000000aau,0x00000022u,0x00000000u,0x00040047u,0x000000afu,0x00000021u,0x00000022u,0x00040047u,0x000000afu,0x00000022u,0x00000000u,0x00040047u,0x000000f1u,0x00000021u,0x00000020u,0x00040047u,0x000000f1u,0x00000022u,0x00000000u,0x00040047u,0x00000207u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040017u,0x00000007u,0x00000006u,0x00000003u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040021u,0x00000009u,0x00000006u,0x00000008u,0x0004002bu,0x00000006u,0x0000000eu,0x3e59b3d0u,0x0004002bu,0x00000006u,0x0000000fu,0x3f371759u,0x0004002bu,0x00000006u,0x00000010u,0x3d93dd98u,0x0006002cu,0x00000007u,0x00000011u,0x0000000eu,0x0000000fu,0x00000010u,0x00040015u,0x00000015u,0x00000020u,0x00000001u,0x00040017u,0x00000016u,0x00000015u,0x00000002u,0x00040020u,0x00000017u,0x00000007u,0x00000016u,0x00040015u,0x00000019u,0x00000020u,0x00000000u,0x00040017u,0x0000001au,0x00000019u,0x00000003u,0x00040020u,0x0000001bu,0x00000001u,0x0000001au,0x0004003bu,0x0000001bu,0x0000001cu,0x00000001u,0x00040017u,0x0000001du,0x00000019u,0x00000002u,0x00090019u,0x00000022u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000004u,0x00040020u,0x00000023u,0x00000000u,0x00000022u,0x0004003bu,0x00000023u,0x00000024u,0x00000000u,0x00020014u,0x00000027u,0x0004002bu,0x00000019u,0x00000028u,0x00000000u,0x00040020u,0x00000029u,0x00000007u,0x00000015u,0x0004002bu,0x00000019u,0x00000032u,0x00000001u,0x00040017u,0x0000003cu,0x00000006u,0x00000002u,0x00040020u,0x0000003du,0x00000007u,0x0000003cu,0x0004002bu,0x00000006u,0x0000003fu,0x3f800000u,0x0004002bu,0x00000006u,0x00000047u,0x3f000000u,0x00040017u,0x0000004cu,0x00000006u,0x00000004u,0x000b001eu,0x0000004du,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x0000004cu,0x00040020u,0x0000004eu,0x00000002u,0x0000004du,0x0004003bu,0x0000004eu,0x0000004fu,0x00000002u,0x0004002bu,0x00000015u,0x00000050u,0x00000008u,0x00040020u,0x00000051u,0x00000002u,0x00000006u,0x0004002bu,0x00000019u,0x00000054u,0x00000002u,0x0004002bu,0x00000019u,0x0000005cu,0x00000003u,0x00090019u,0x00000089u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000008au,0x00000089u,0x00040020u,0x0000008bu,0x00000000u,0x0000008au,0x0004003bu,0x0000008bu,0x0000008cu,0x00000000u,0x0004002bu,0x00000006u,0x0000008fu,0x00000000u,0x00040020u,0x00000097u,0x00000007u,0x00000027u,0x0004002bu,0x00000015u,0x00000099u,0x00000000u,0x0004002bu,0x00000006u,0x0000009cu,0x40600000u,0x00040020u,0x0000009eu,0x00000007u,0x00000006u,0x00040020u,0x000000a8u,0x00000007u,0x0000004cu,0x0004003bu,0x0000008bu,0x000000aau,0x00000000u,0x0004003bu,0x0000008bu,0x000000afu,0x00000000u,0x0004002bu,0x00000006u,0x000000cdu,0x3dcccccdu,0x0004002bu,0x00000015u,0x000000e2u,0x00000001u,0x0004003bu,0x0000008bu,0x000000f1u,0x00000000u,0x0004002bu,0x00000015u,0x0000014au,0x00000005u,0x0004002bu,0x00000015u,0x0000014fu,0x00000003u,0x0004002bu,0x00000015u,0x00000170u,0x00000002u,0x0004002bu,0x00000006u,0x00000189u,0x322bcc77u,0x0004002bu,0x00000006u,0x000001b2u,0x3d23d70au,0x0004002bu,0x00000006u,0x000001b3u,0x3e3851ecu,0x0004002bu,0x00000015u,0x000001bcu,0x00000004u,0x0004002bu,0x00000006u,0x000001d3u,0x3e800000u,0x0004002bu,0x00000006u,0x000001d8u,0x3e4ccccdu,0x0004002bu,0x00000006u,0x000001d9u,0x3ecccccdu,0x0004002bu,0x00000019u,0x00000206u,0x00000010u,0x0006002cu,0x0000001au,0x00000207u,0x00000206u,0x00000206u,0x00000032u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000017u,0x00000018u,0x00000007u,0x0004003bu,0x00000017u,0x00000021u,0x00000007u,0x0004003bu,0x0000003du,0x0000003eu,0x00000007u,0x0004003bu,0x0000003du,0x00000044u,0x00000007u,0x0004003bu,0x00000097u,0x00000098u,0x00000007u,0x0004003bu,0x0000009eu,0x0000009fu,0x00000007u,0x0004003bu,0x0000009eu,0x000000a1u,0x00000007u,0x0004003bu,0x000000a8u,0x000000a9u,0x00000007u,0x0004003bu,0x000000a8u,0x000000aeu,0x00000007u,0x0004003bu,0x0000003du,0x000000b3u,0x00000007u,0x0004003bu,0x0000003du,0x000000bau,0x00000007u,0x0004003bu,0x0000009eu,0x000000c1u,0x00000007u,0x0004003bu,0x0000009eu,0x000000c5u,0x00000007u,0x0004003bu,0x0000009eu,0x000000c9u,0x00000007u,0x0004003bu,0x0000009eu,0x000000d5u,0x00000007u,0x0004003bu,0x0000003du,0x000000e0u,0x00000007u,0x0004003bu,0x0000003du,0x000000e8u,0x00000007u,0x0004003bu,0x00000008u,0x000000f0u,0x00000007u,0x0004003bu,0x00000008u,0x000000f6u,0x00000007u,0x0004003bu,0x0000009eu,0x000000fbu,0x00000007u,0x0004003bu,0x00000008u,0x000000fcu,0x00000007u,0x0004003bu,0x00000008u,0x0000010cu,0x00000007u,0x0004003bu,0x0000009eu,0x00000111u,0x00000007u,0x0004003bu,0x00000008u,0x00000112u,0x00000007u,0x0004003bu,0x00000008u,0x00000122u,0x00000007u,0x0004003bu,0x0000003du,0x00000127u,0x00000007u,0x0004003bu,0x0000009eu,0x0000012bu,0x00000007u,0x0004003bu,0x0000009eu,0x00000138u,0x00000007u,0x0004003bu,0x0000009eu,0x00000149u,0x00000007u,0x0004003bu,0x0000009eu,0x00000157u,0x00000007u,0x0004003bu,0x0000009eu,0x00000163u,0x00000007u,0x0004003bu,0x0000009eu,0x00000167u,0x00000007u,0x0004003bu,0x0000009eu,0x0000016au,0x00000007u,0x0004003bu,0x0000009eu,0x0000016eu,0x00000007u,0x0004003bu,0x0000009eu,0x00000179u,0x00000007u,0x0004003bu,0x0000009eu,0x00000183u,0x00000007u,0x0004003bu,0x00000008u,0x00000187u,0x00000007u,0x0004003bu,0x00000008u,0x0000018bu,0x00000007u,0x0004003bu,0x00000008u,0x000001a0u,0x00000007u,0x0004003bu,0x0000009eu,0x000001adu,0x00000007u,0x0004003bu,0x0000009eu,0x000001b1u,0x00000007u,0x0004003bu,0x0000009eu,0x000001b7u,0x00000007u,0x0004003bu,0x00000008u,0x000001c3u,0x00000007u,0x0004003bu,0x00000008u,0x000001c8u,0x00000007u,0x0004003bu,0x0000009eu,0x000001cdu,0x00000007u,0x0004003bu,0x0000009eu,0x000001d2u,0x00000007u,0x0004003bu,0x0000009eu,0x000001d7u,0x00000007u,0x0004003bu,0x0000009eu,0x000001dcu,0x00000007u,0x0004003bu,0x00000008u,0x000001e5u,0x00000007u,0x0004003bu,0x0000009eu,0x000001eeu,0x00000007u,0x0004003bu,0x0000009eu,0x000001f2u,0x00000007u,0x0004003bu,0x0000009eu,0x000001f6u,0x00000007u,0x0004003du,0x0000001au,0x0000001eu,0x0000001cu,0x0007004fu,0x0000001du,0x0000001fu,0x0000001eu,0x0000001eu,0x00000000u,0x00000001u,0x0004007cu,0x00000016u,0x00000020u,0x0000001fu,0x0003003eu,0x00000018u,0x00000020u,0x0004003du,0x00000022u,0x00000025u,0x00000024u,0x00040068u,0x00000016u,0x00000026u,0x00000025u,0x0003003eu,0x00000021u,0x00000026u,0x00050041u,0x00000029u,0x0000002au,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x0000002bu,0x0000002au,0x00050041u,0x00000029u,0x0000002cu,0x00000021u,0x00000028u,0x0004003du,0x00000015u,0x0000002du,0x0000002cu,0x000500afu,0x00000027u,0x0000002eu,0x0000002bu,0x0000002du,0x000400a8u,0x00000027u,0x0000002fu,0x0000002eu,0x000300f7u,0x00000031u,0x00000000u,0x000400fau,0x0000002fu,0x00000030u,0x00000031u,0x000200f8u,0x00000030u,0x00050041u,0x00000029u,0x00000033u,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x00000034u,0x00000033u,0x00050041u,0x00000029u,0x00000035u,0x00000021u,0x00000032u,0x0004003du,0x00000015u,0x00000036u,0x00000035u,0x000500afu,0x00000027u,0x00000037u,0x00000034u,0x00000036u,0x000200f9u,0x00000031u,0x000200f8u,0x00000031u,0x000700f5u,0x00000027u,0x00000038u,0x0000002eu,0x00000005u,0x00000037u,0x00000030u,0x000300f7u,0x0000003au,0x00000000u,0x000400fau,0x00000038u,0x00000039u,0x0000003au,0x000200f8u,0x00000039u,0x000100fdu,0x000200f8u,0x0000003au,0x0004003du,0x00000016u,0x00000040u,0x00000021u,0x0004006fu,0x0000003cu,0x00000041u,0x00000040u,0x00050050u,0x0000003cu,0x00000042u,0x0000003fu,0x0000003fu,0x00050088u,0x0000003cu,0x00000043u,0x00000042u,0x00000041u,0x0003003eu,0x0000003eu,0x00000043u,0x0004003du,0x00000016u,0x00000045u,0x00000018u,0x0004006fu,0x0000003cu,0x00000046u,0x00000045u,0x00050050u,0x0000003cu,0x00000048u,0x00000047u,0x00000047u,0x00050081u,0x0000003cu,0x00000049u,0x00000046u,0x00000048u,0x0004003du,0x0000003cu,0x0000004au,0x0000003eu,0x00050085u,0x0000003cu,0x0000004bu,0x00000049u,0x0000004au,0x0003003eu,0x00000044u,0x0000004bu,0x00060041u,0x00000051u,0x00000052u,0x0000004fu,0x00000050u,0x00000028u,0x0004003du,0x00000006u,0x00000053u,0x00000052u,0x00060041u,0x00000051u,0x00000055u,0x0000004fu,0x00000050u,0x00000054u,0x0004003du,0x00000006u,0x00000056u,0x00000055u,0x000500b8u,0x00000027u,0x00000057u,0x00000053u,0x00000056u,0x000300f7u,0x00000059u,0x00000000u,0x000400fau,0x00000057u,0x00000058u,0x00000059u,0x000200f8u,0x00000058u,0x00060041u,0x00000051u,0x0000005au,0x0000004fu,0x00000050u,0x00000032u,0x0004003du,0x00000006u,0x0000005bu,0x0000005au,0x00060041u,0x00000051u,0x0000005du,0x0000004fu,0x00000050u,0x0000005cu,0x0004003du,0x00000006u,0x0000005eu,0x0000005du,0x000500b8u,0x00000027u,0x0000005fu,0x0000005bu,0x0000005eu,0x000200f9u,0x00000059u,0x000200f8u,0x00000059u,0x000700f5u,0x00000027u,0x00000060u,0x00000057u,0x0000003au,0x0000005fu,0x00000058u,0x000300f7u,0x00000062u,0x00000000u,0x000400fau,0x00000060u,0x00000061u,0x00000062u,0x000200f8u,0x00000061u,0x00050041u,0x00000029u,0x00000063u,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x00000064u,0x00000063u,0x0004006fu,0x00000006u,0x00000065u,0x00000064u,0x00060041u,0x00000051u,0x00000066u,0x0000004fu,0x00000050u,0x00000028u,0x0004003du,0x00000006u,0x00000067u,0x00000066u,0x000500beu,0x00000027u,0x00000068u,0x00000065u,0x00000067u,0x000200f9u,0x00000062u,0x000200f8u,0x00000062u,0x000700f5u,0x00000027u,0x00000069u,0x00000060u,0x00000059u,0x00000068u,0x00000061u,0x000300f7u,0x0000006bu,0x00000000u,0x000400fau,0x00000069u,0x0000006au,0x0000006bu,0x000200f8u,0x0000006au,0x00050041u,0x00000029u,0x0000006cu,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x0000006du,0x0000006cu,0x0004006fu,0x00000006u,0x0000006eu,0x0000006du,0x00060041u,0x00000051u,0x0000006fu,0x0000004fu,0x00000050u,0x00000054u,0x0004003du,0x00000006u,0x00000070u,0x0000006fu,0x000500b8u,0x00000027u,0x00000071u,0x0000006eu,0x00000070u,0x000200f9u,0x0000006bu,0x000200f8u,0x0000006bu,0x000700f5u,0x00000027u,0x00000072u,0x00000069u,0x00000062u,0x00000071u,0x0000006au,0x000300f7u,0x00000074u,0x00000000u,0x000400fau,0x00000072u,0x00000073u,0x00000074u,0x000200f8u,0x00000073u,0x00050041u,0x00000029u,0x00000075u,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x00000076u,0x00000075u,0x0004006fu,0x00000006u,0x00000077u,0x00000076u,0x00060041u,0x00000051u,0x00000078u,0x0000004fu,0x00000050u,0x00000032u,0x0004003du,0x00000006u,0x00000079u,0x00000078u,0x000500beu,0x00000027u,0x0000007au,0x00000077u,0x00000079u,0x000200f9u,0x00000074u,0x000200f8u,0x00000074u,0x000700f5u,0x00000027u,0x0000007bu,0x00000072u,0x0000006bu,0x0000007au,0x00000073u,0x000300f7u,0x0000007du,0x00000000u,0x000400fau,0x0000007bu,0x0000007cu,0x0000007du,0x000200f8u,0x0000007cu,0x00050041u,0x00000029u,0x0000007eu,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x0000007fu,0x0000007eu,0x0004006fu,0x00000006u,0x00000080u,0x0000007fu,0x00060041u,0x00000051u,0x00000081u,0x0000004fu,0x00000050u,0x0000005cu,0x0004003du,0x00000006u,0x00000082u,0x00000081u,0x000500b8u,0x00000027u,0x00000083u,0x00000080u,0x00000082u,0x000200f9u,0x0000007du,0x000200f8u,0x0000007du,0x000700f5u,0x00000027u,0x00000084u,0x0000007bu,0x00000074u,0x00000083u,0x0000007cu,0x000300f7u,0x00000086u,0x00000000u,0x000400fau,0x00000084u,0x00000085u,0x00000086u,0x000200f8u,0x00000085u,0x0004003du,0x00000022u,0x00000087u,0x00000024u,0x0004003du,0x00000016u,0x00000088u,0x00000018u,0x0004003du,0x0000008au,0x0000008du,0x0000008cu,0x0004003du,0x0000003cu,0x0000008eu,0x00000044u,0x00070058u,0x0000004cu,0x00000090u,0x0000008du,0x0000008eu,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x00000091u,0x00000090u,0x00000090u,0x00000000u,0x00000001u,0x00000002u,0x00050051u,0x00000006u,0x00000092u,0x00000091u,0x00000000u,0x00050051u,0x00000006u,0x00000093u,0x00000091u,0x00000001u,0x00050051u,0x00000006u,0x00000094u,0x00000091u,0x00000002u,0x00070050u,0x0000004cu,0x00000095u,0x00000092u,0x00000093u,0x00000094u,0x0000003fu,0x00040063u,0x00000087u,0x00000088u,0x00000095u,0x000100fdu,0x000200f8u,0x00000086u,0x00050041u,0x00000051u,0x0000009au,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x0000009bu,0x0000009au,0x000500bau,0x00000027u,0x0000009du,0x0000009bu,0x0000009cu,0x0003003eu,0x00000098u,0x0000009du,0x0004003du,0x00000027u,0x000000a0u,0x00000098u,0x000300f7u,0x000000a3u,0x00000000u,0x000400fau,0x000000a0u,0x000000a2u,0x000000a4u,0x000200f8u,0x000000a2u,0x0003003eu,0x000000a1u,0x0000003fu,0x000200f9u,0x000000a3u,0x000200f8u,0x000000a4u,0x00050041u,0x00000051u,0x000000a5u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x000000a6u,0x000000a5u,0x0003003eu,0x000000a1u,0x000000a6u,0x000200f9u,0x000000a3u,0x000200f8u,0x000000a3u,0x0004003du,0x00000006u,0x000000a7u,0x000000a1u,0x0003003eu,0x0000009fu,0x000000a7u,0x0004003du,0x0000008au,0x000000abu,0x000000aau,0x0004003du,0x0000003cu,0x000000acu,0x00000044u,0x00070058u,0x0000004cu,0x000000adu,0x000000abu,0x000000acu,0x00000002u,0x0000008fu,0x0003003eu,0x000000a9u,0x000000adu,0x0004003du,0x0000008au,0x000000b0u,0x000000afu,0x0004003du,0x0000003cu,0x000000b1u,0x00000044u,0x00070058u,0x0000004cu,0x000000b2u,0x000000b0u,0x000000b1u,0x00000002u,0x0000008fu,0x0003003eu,0x000000aeu,0x000000b2u,0x0004003du,0x0000004cu,0x000000b4u,0x000000a9u,0x0007004fu,0x0000003cu,0x000000b5u,0x000000b4u,0x000000b4u,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x000000b6u,0x0000009fu,0x0005008eu,0x0000003cu,0x000000b7u,0x000000b5u,0x000000b6u,0x0004003du,0x0000003cu,0x000000b8u,0x0000003eu,0x00050085u,0x0000003cu,0x000000b9u,0x000000b7u,0x000000b8u,0x0003003eu,0x000000b3u,0x000000b9u,0x0004003du,0x0000004cu,0x000000bbu,0x000000aeu,0x0007004fu,0x0000003cu,0x000000bcu,0x000000bbu,0x000000bbu,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x000000bdu,0x0000009fu,0x0005008eu,0x0000003cu,0x000000beu,0x000000bcu,0x000000bdu,0x0004003du,0x0000003cu,0x000000bfu,0x0000003eu,0x00050085u,0x0000003cu,0x000000c0u,0x000000beu,0x000000bfu,0x0003003eu,0x000000bau,0x000000c0u,0x00050041u,0x0000009eu,0x000000c2u,0x000000a9u,0x0000005cu,0x0004003du,0x00000006u,0x000000c3u,0x000000c2u,0x0008000cu,0x00000006u,0x000000c4u,0x00000001u,0x0000002bu,0x000000c3u,0x0000008fu,0x0000003fu,0x0003003eu,0x000000c1u,0x000000c4u,0x00050041u,0x0000009eu,0x000000c6u,0x000000aeu,0x0000005cu,0x0004003du,0x00000006u,0x000000c7u,0x000000c6u,0x0008000cu,0x00000006u,0x000000c8u,0x00000001u,0x0000002bu,0x000000c7u,0x0000008fu,0x0000003fu,0x0003003eu,0x000000c5u,0x000000c8u,0x0004003du,0x0000003cu,0x000000cau,0x000000b3u,0x0006000cu,0x00000006u,0x000000cbu,0x00000001u,0x00000042u,0x000000cau,0x0003003eu,0x000000c9u,0x000000cbu,0x0004003du,0x00000006u,0x000000ccu,0x000000c9u,0x000500bau,0x00000027u,0x000000ceu,0x000000ccu,0x000000cdu,0x000300f7u,0x000000d0u,0x00000000u,0x000400fau,0x000000ceu,0x000000cfu,0x000000d0u,0x000200f8u,0x000000cfu,0x0004003du,0x00000006u,0x000000d1u,0x000000c9u,0x00050088u,0x00000006u,0x000000d2u,0x000000cdu,0x000000d1u,0x0004003du,0x0000003cu,0x000000d3u,0x000000b3u,0x0005008eu,0x0000003cu,0x000000d4u,0x000000d3u,0x000000d2u,0x0003003eu,0x000000b3u,0x000000d4u,0x000200f9u,0x000000d0u,0x000200f8u,0x000000d0u,0x0004003du,0x0000003cu,0x000000d6u,0x000000bau,0x0006000cu,0x00000006u,0x000000d7u,0x00000001u,0x00000042u,0x000000d6u,0x0003003eu,0x000000d5u,0x000000d7u,0x0004003du,0x00000006u,0x000000d8u,0x000000d5u,0x000500bau,0x00000027u,0x000000d9u,0x000000d8u,0x000000cdu,0x000300f7u,0x000000dbu,0x00000000u,0x000400fau,0x000000d9u,0x000000dau,0x000000dbu,0x000200f8u,0x000000dau,0x0004003du,0x00000006u,0x000000dcu,0x000000d5u,0x00050088u,0x00000006u,0x000000ddu,0x000000cdu,0x000000dcu,0x0004003du,0x0000003cu,0x000000deu,0x000000bau,0x0005008eu,0x0000003cu,0x000000dfu,0x000000deu,0x000000ddu,0x0003003eu,0x000000bau,0x000000dfu,0x000200f9u,0x000000dbu,0x000200f8u,0x000000dbu,0x0004003du,0x0000003cu,0x000000e1u,0x00000044u,0x00050041u,0x00000051u,0x000000e3u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000000e4u,0x000000e3u,0x0004003du,0x0000003cu,0x000000e5u,0x000000b3u,0x0005008eu,0x0000003cu,0x000000e6u,0x000000e5u,0x000000e4u,0x00050083u,0x0000003cu,0x000000e7u,0x000000e1u,0x000000e6u,0x0003003eu,0x000000e0u,0x000000e7u,0x0004003du,0x0000003cu,0x000000e9u,0x00000044u,0x00050041u,0x00000051u,0x000000eau,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000000ebu,0x000000eau,0x00050083u,0x00000006u,0x000000ecu,0x0000003fu,0x000000ebu,0x0004003du,0x0000003cu,0x000000edu,0x000000bau,0x0005008eu,0x0000003cu,0x000000eeu,0x000000edu,0x000000ecu,0x00050083u,0x0000003cu,0x000000efu,0x000000e9u,0x000000eeu,0x0003003eu,0x000000e8u,0x000000efu,0x0004003du,0x0000008au,0x000000f2u,0x000000f1u,0x0004003du,0x0000003cu,0x000000f3u,0x000000e0u,0x00070058u,0x0000004cu,0x000000f4u,0x000000f2u,0x000000f3u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000000f5u,0x000000f4u,0x000000f4u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000000f0u,0x000000f5u,0x0004003du,0x0000008au,0x000000f7u,0x0000008cu,0x0004003du,0x0000003cu,0x000000f8u,0x000000e8u,0x00070058u,0x0000004cu,0x000000f9u,0x000000f7u,0x000000f8u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000000fau,0x000000f9u,0x000000f9u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000000f6u,0x000000fau,0x0004003du,0x00000007u,0x000000fdu,0x000000f0u,0x0003003eu,0x000000fcu,0x000000fdu,0x00050039u,0x00000006u,0x000000feu,0x0000000bu,0x000000fcu,0x0004003du,0x0000008au,0x000000ffu,0x0000008cu,0x0004003du,0x0000003cu,0x00000100u,0x000000e0u,0x0004003du,0x0000008au,0x00000101u,0x000000aau,0x0004003du,0x0000003cu,0x00000102u,0x000000e0u,0x00070058u,0x0000004cu,0x00000103u,0x00000101u,0x00000102u,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x00000104u,0x00000103u,0x00000103u,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x00000105u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x00000106u,0x00000105u,0x0005008eu,0x0000003cu,0x00000107u,0x00000104u,0x00000106u,0x0004003du,0x0000003cu,0x00000108u,0x0000003eu,0x00050085u,0x0000003cu,0x00000109u,0x00000107u,0x00000108u,0x00050081u,0x0000003cu,0x0000010au,0x00000100u,0x00000109u,0x00070058u,0x0000004cu,0x0000010bu,0x000000ffu,0x0000010au,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x0000010du,0x0000010bu,0x0000010bu,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x0000010cu,0x0000010du,0x00050039u,0x00000006u,0x0000010eu,0x0000000bu,0x0000010cu,0x00050083u,0x00000006u,0x0000010fu,0x000000feu,0x0000010eu,0x0006000cu,0x00000006u,0x00000110u,0x00000001u,0x00000004u,0x0000010fu,0x0003003eu,0x000000fbu,0x00000110u,0x0004003du,0x00000007u,0x00000113u,0x000000f6u,0x0003003eu,0x00000112u,0x00000113u,0x00050039u,0x00000006u,0x00000114u,0x0000000bu,0x00000112u,0x0004003du,0x0000008au,0x00000115u,0x000000f1u,0x0004003du,0x0000003cu,0x00000116u,0x000000e8u,0x0004003du,0x0000008au,0x00000117u,0x000000afu,0x0004003du,0x0000003cu,0x00000118u,0x000000e8u,0x00070058u,0x0000004cu,0x00000119u,0x00000117u,0x00000118u,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x0000011au,0x00000119u,0x00000119u,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x0000011bu,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x0000011cu,0x0000011bu,0x0005008eu,0x0000003cu,0x0000011du,0x0000011au,0x0000011cu,0x0004003du,0x0000003cu,0x0000011eu,0x0000003eu,0x00050085u,0x0000003cu,0x0000011fu,0x0000011du,0x0000011eu,0x00050081u,0x0000003cu,0x00000120u,0x00000116u,0x0000011fu,0x00070058u,0x0000004cu,0x00000121u,0x00000115u,0x00000120u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x00000123u,0x00000121u,0x00000121u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x00000122u,0x00000123u,0x00050039u,0x00000006u,0x00000124u,0x0000000bu,0x00000122u,0x00050083u,0x00000006u,0x00000125u,0x00000114u,0x00000124u,0x0006000cu,0x00000006u,0x00000126u,0x00000001u,0x00000004u,0x00000125u,0x0003003eu,0x00000111u,0x00000126u,0x0004003du,0x0000003cu,0x00000128u,0x00000044u,0x0004003du,0x0000003cu,0x00000129u,0x000000b3u,0x00050081u,0x0000003cu,0x0000012au,0x00000128u,0x00000129u,0x0003003eu,0x00000127u,0x0000012au,0x0004003du,0x0000003cu,0x0000012cu,0x000000b3u,0x0004003du,0x0000008au,0x0000012du,0x000000afu,0x0004003du,0x0000003cu,0x0000012eu,0x00000127u,0x00070058u,0x0000004cu,0x0000012fu,0x0000012du,0x0000012eu,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x00000130u,0x0000012fu,0x0000012fu,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x00000131u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x00000132u,0x00000131u,0x0005008eu,0x0000003cu,0x00000133u,0x00000130u,0x00000132u,0x0004003du,0x0000003cu,0x00000134u,0x0000003eu,0x00050085u,0x0000003cu,0x00000135u,0x00000133u,0x00000134u,0x00050081u,0x0000003cu,0x00000136u,0x0000012cu,0x00000135u,0x0006000cu,0x00000006u,0x00000137u,0x00000001u,0x00000042u,0x00000136u,0x0003003eu,0x0000012bu,0x00000137u,0x0004003du,0x00000006u,0x00000139u,0x000000c1u,0x0004003du,0x00000006u,0x0000013au,0x000000c5u,0x0007000cu,0x00000006u,0x0000013bu,0x00000001u,0x00000025u,0x00000139u,0x0000013au,0x0004003du,0x00000006u,0x0000013cu,0x0000012bu,0x0004007fu,0x00000006u,0x0000013du,0x0000013cu,0x0004003du,0x0000003cu,0x0000013eu,0x000000b3u,0x0006000cu,0x00000006u,0x0000013fu,0x00000001u,0x00000042u,0x0000013eu,0x0004003du,0x0000003cu,0x00000140u,0x000000bau,0x0006000cu,0x00000006u,0x00000141u,0x00000001u,0x00000042u,0x00000140u,0x00050081u,0x00000006u,0x00000142u,0x0000013fu,0x00000141u,0x00050041u,0x0000009eu,0x00000143u,0x0000003eu,0x00000028u,0x0004003du,0x00000006u,0x00000144u,0x00000143u,0x00050081u,0x00000006u,0x00000145u,0x00000142u,0x00000144u,0x00050088u,0x00000006u,0x00000146u,0x0000013du,0x00000145u,0x0006000cu,0x00000006u,0x00000147u,0x00000001u,0x0000001bu,0x00000146u,0x00050085u,0x00000006u,0x00000148u,0x0000013bu,0x00000147u,0x0003003eu,0x00000138u,0x00000148u,0x00050041u,0x00000051u,0x0000014bu,0x0000004fu,0x0000014au,0x0004003du,0x00000006u,0x0000014cu,0x0000014bu,0x0004003du,0x00000006u,0x0000014du,0x000000fbu,0x00050085u,0x00000006u,0x0000014eu,0x0000014cu,0x0000014du,0x00050041u,0x00000051u,0x00000150u,0x0000004fu,0x0000014fu,0x0004003du,0x00000006u,0x00000151u,0x00000150u,0x0004003du,0x00000006u,0x00000152u,0x00000138u,0x00050083u,0x00000006u,0x00000153u,0x0000003fu,0x00000152u,0x00050085u,0x00000006u,0x00000154u,0x00000151u,0x00000153u,0x00050081u,0x00000006u,0x00000155u,0x0000014eu,0x00000154u,0x0004007fu,0x00000006u,0x00000156u,0x00000155u,0x0003003eu,0x00000149u,0x00000156u,0x00050041u,0x00000051u,0x00000158u,0x0000004fu,0x0000014au,0x0004003du,0x00000006u,0x00000159u,0x00000158u,0x0004003du,0x00000006u,0x0000015au,0x00000111u,0x00050085u,0x00000006u,0x0000015bu,0x00000159u,0x0000015au,0x00050041u,0x00000051u,0x0000015cu,0x0000004fu,0x0000014fu,0x0004003du,0x00000006u,0x0000015du,0x0000015cu,0x0004003du,0x00000006u,0x0000015eu,0x00000138u,0x00050083u,0x00000006u,0x0000015fu,0x0000003fu,0x0000015eu,0x00050085u,0x00000006u,0x00000160u,0x0000015du,0x0000015fu,0x00050081u,0x00000006u,0x00000161u,0x0000015bu,0x00000160u,0x0004007fu,0x00000006u,0x00000162u,0x00000161u,0x0003003eu,0x00000157u,0x00000162u,0x00050041u,0x00000051u,0x00000164u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x00000165u,0x00000164u,0x00050083u,0x00000006u,0x00000166u,0x0000003fu,0x00000165u,0x0003003eu,0x00000163u,0x00000166u,0x00050041u,0x00000051u,0x00000168u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x00000169u,0x00000168u,0x0003003eu,0x00000167u,0x00000169u,0x0004003du,0x00000006u,0x0000016bu,0x00000149u,0x0004003du,0x00000006u,0x0000016cu,0x00000157u,0x0007000cu,0x00000006u,0x0000016du,0x00000001u,0x00000028u,0x0000016bu,0x0000016cu,0x0003003eu,0x0000016au,0x0000016du,0x0004003du,0x00000006u,0x0000016fu,0x00000163u,0x00050041u,0x00000051u,0x00000171u,0x0000004fu,0x00000170u,0x0004003du,0x00000006u,0x00000172u,0x00000171u,0x0004003du,0x00000006u,0x00000173u,0x00000149u,0x0004003du,0x00000006u,0x00000174u,0x0000016au,0x00050083u,0x00000006u,0x00000175u,0x00000173u,0x00000174u,0x00050085u,0x00000006u,0x00000176u,0x00000172u,0x00000175u,0x0006000cu,0x00000006u,0x00000177u,0x00000001u,0x0000001bu,0x00000176u,0x00050085u,0x00000006u,0x00000178u,0x0000016fu,0x00000177u,0x0003003eu,0x0000016eu,0x00000178u,0x0004003du,0x00000006u,0x0000017au,0x00000167u,0x00050041u,0x00000051u,0x0000017bu,0x0000004fu,0x00000170u,0x0004003du,0x00000006u,0x0000017cu,0x0000017bu,0x0004003du,0x00000006u,0x0000017du,0x00000157u,0x0004003du,0x00000006u,0x0000017eu,0x0000016au,0x00050083u,0x00000006u,0x0000017fu,0x0000017du,0x0000017eu,0x00050085u,0x00000006u,0x00000180u,0x0000017cu,0x0000017fu,0x0006000cu,0x00000006u,0x00000181u,0x00000001u,0x0000001bu,0x00000180u,0x00050085u,0x00000006u,0x00000182u,0x0000017au,0x00000181u,0x0003003eu,0x00000179u,0x00000182u,0x0004003du,0x00000006u,0x00000184u,0x0000016eu,0x0004003du,0x00000006u,0x00000185u,0x00000179u,0x00050081u,0x00000006u,0x00000186u,0x00000184u,0x00000185u,0x0003003eu,0x00000183u,0x00000186u,0x0004003du,0x00000006u,0x00000188u,0x00000183u,0x000500bau,0x00000027u,0x0000018au,0x00000188u,0x00000189u,0x000300f7u,0x0000018du,0x00000000u,0x000400fau,0x0000018au,0x0000018cu,0x00000198u,0x000200f8u,0x0000018cu,0x0004003du,0x00000006u,0x0000018eu,0x0000016eu,0x0004003du,0x00000007u,0x0000018fu,0x000000f0u,0x0005008eu,0x00000007u,0x00000190u,0x0000018fu,0x0000018eu,0x0004003du,0x00000006u,0x00000191u,0x00000179u,0x0004003du,0x00000007u,0x00000192u,0x000000f6u,0x0005008eu,0x00000007u,0x00000193u,0x00000192u,0x00000191u,0x00050081u,0x00000007u,0x00000194u,0x00000190u,0x00000193u,0x0004003du,0x00000006u,0x00000195u,0x00000183u,0x00060050u,0x00000007u,0x00000196u,0x00000195u,0x00000195u,0x00000195u,0x00050088u,0x00000007u,0x00000197u,0x00000194u,0x00000196u,0x0003003eu,0x0000018bu,0x00000197u,0x000200f9u,0x0000018du,0x000200f8u,0x00000198u,0x0004003du,0x00000007u,0x00000199u,0x000000f0u,0x0004003du,0x00000007u,0x0000019au,0x000000f6u,0x00050041u,0x00000051u,0x0000019bu,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x0000019cu,0x0000019bu,0x00060050u,0x00000007u,0x0000019du,0x0000019cu,0x0000019cu,0x0000019cu,0x0008000cu,0x00000007u,0x0000019eu,0x00000001u,0x0000002eu,0x00000199u,0x0000019au,0x0000019du,0x0003003eu,0x0000018bu,0x0000019eu,0x000200f9u,0x0000018du,0x000200f8u,0x0000018du,0x0004003du,0x00000007u,0x0000019fu,0x0000018bu,0x0003003eu,0x00000187u,0x0000019fu,0x0004003du,0x0000008au,0x000001a1u,0x000000f1u,0x0004003du,0x0000003cu,0x000001a2u,0x00000044u,0x00070058u,0x0000004cu,0x000001a3u,0x000001a1u,0x000001a2u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001a4u,0x000001a3u,0x000001a3u,0x00000000u,0x00000001u,0x00000002u,0x0004003du,0x0000008au,0x000001a5u,0x0000008cu,0x0004003du,0x0000003cu,0x000001a6u,0x00000044u,0x00070058u,0x0000004cu,0x000001a7u,0x000001a5u,0x000001a6u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001a8u,0x000001a7u,0x000001a7u,0x00000000u,0x00000001u,0x00000002u,0x00050041u,0x00000051u,0x000001a9u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000001aau,0x000001a9u,0x00060050u,0x00000007u,0x000001abu,0x000001aau,0x000001aau,0x000001aau,0x0008000cu,0x00000007u,0x000001acu,0x00000001u,0x0000002eu,0x000001a4u,0x000001a8u,0x000001abu,0x0003003eu,0x000001a0u,0x000001acu,0x0004003du,0x00000006u,0x000001aeu,0x000000fbu,0x0004003du,0x00000006u,0x000001afu,0x00000111u,0x0007000cu,0x00000006u,0x000001b0u,0x00000001u,0x00000025u,0x000001aeu,0x000001afu,0x0003003eu,0x000001adu,0x000001b0u,0x0004003du,0x00000006u,0x000001b4u,0x000001adu,0x0008000cu,0x00000006u,0x000001b5u,0x00000001u,0x00000031u,0x000001b2u,0x000001b3u,0x000001b4u,0x00050083u,0x00000006u,0x000001b6u,0x0000003fu,0x000001b5u,0x0003003eu,0x000001b1u,0x000001b6u,0x0004003du,0x00000006u,0x000001b8u,0x00000138u,0x0008000cu,0x00000006u,0x000001b9u,0x00000001u,0x0000002bu,0x000001b8u,0x0000008fu,0x0000003fu,0x0004003du,0x00000006u,0x000001bau,0x000001b1u,0x00050085u,0x00000006u,0x000001bbu,0x000001b9u,0x000001bau,0x0003003eu,0x000001b7u,0x000001bbu,0x00050041u,0x00000051u,0x000001bdu,0x0000004fu,0x000001bcu,0x0004003du,0x00000006u,0x000001beu,0x000001bdu,0x0004003du,0x00000006u,0x000001bfu,0x00000183u,0x0008000cu,0x00000006u,0x000001c0u,0x00000001u,0x00000031u,0x0000008fu,0x000001beu,0x000001bfu,0x0004003du,0x00000006u,0x000001c1u,0x000001b7u,0x00050085u,0x00000006u,0x000001c2u,0x000001c1u,0x000001c0u,0x0003003eu,0x000001b7u,0x000001c2u,0x0004003du,0x0000008au,0x000001c4u,0x000000f1u,0x0004003du,0x0000003cu,0x000001c5u,0x00000044u,0x00070058u,0x0000004cu,0x000001c6u,0x000001c4u,0x000001c5u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001c7u,0x000001c6u,0x000001c6u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000001c3u,0x000001c7u,0x0004003du,0x0000008au,0x000001c9u,0x0000008cu,0x0004003du,0x0000003cu,0x000001cau,0x00000044u,0x00070058u,0x0000004cu,0x000001cbu,0x000001c9u,0x000001cau,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001ccu,0x000001cbu,0x000001cbu,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000001c8u,0x000001ccu,0x0004003du,0x00000007u,0x000001ceu,0x000001c8u,0x0004003du,0x00000007u,0x000001cfu,0x000001c3u,0x00050083u,0x00000007u,0x000001d0u,0x000001ceu,0x000001cfu,0x0006000cu,0x00000006u,0x000001d1u,0x00000001u,0x00000042u,0x000001d0u,0x0003003eu,0x000001cdu,0x000001d1u,0x0004003du,0x00000006u,0x000001d4u,0x000001b7u,0x0008000cu,0x00000006u,0x000001d5u,0x00000001u,0x00000031u,0x000000cdu,0x000001d3u,0x000001d4u,0x00050083u,0x00000006u,0x000001d6u,0x0000003fu,0x000001d5u,0x0003003eu,0x000001d2u,0x000001d6u,0x0004003du,0x00000006u,0x000001dau,0x000001cdu,0x0008000cu,0x00000006u,0x000001dbu,0x00000001u,0x00000031u,0x000001d8u,0x000001d9u,0x000001dau,0x0003003eu,0x000001d7u,0x000001dbu,0x0004003du,0x00000006u,0x000001ddu,0x000001d2u,0x0004003du,0x00000006u,0x000001deu,0x000001d7u,0x00050085u,0x00000006u,0x000001dfu,0x000001ddu,0x000001deu,0x0003003eu,0x000001dcu,0x000001dfu,0x0004003du,0x00000007u,0x000001e0u,0x000001a0u,0x0004003du,0x00000007u,0x000001e1u,0x000001c8u,0x0004003du,0x00000006u,0x000001e2u,0x000001dcu,0x00060050u,0x00000007u,0x000001e3u,0x000001e2u,0x000001e2u,0x000001e2u,0x0008000cu,0x00000007u,0x000001e4u,0x00000001u,0x0000002eu,0x000001e0u,0x000001e1u,0x000001e3u,0x0003003eu,0x000001a0u,0x000001e4u,0x0004003du,0x00000007u,0x000001e6u,0x000001a0u,0x0004003du,0x00000007u,0x000001e7u,0x00000187u,0x0004003du,0x00000006u,0x000001e8u,0x000001b7u,0x00060050u,0x00000007u,0x000001e9u,0x000001e8u,0x000001e8u,0x000001e8u,0x0008000cu,0x00000007u,0x000001eau,0x00000001u,0x0000002eu,0x000001e6u,0x000001e7u,0x000001e9u,0x0003003eu,0x000001e5u,0x000001eau,0x0004003du,0x00000027u,0x000001ebu,0x00000098u,0x000300f7u,0x000001edu,0x00000000u,0x000400fau,0x000001ebu,0x000001ecu,0x000001edu,0x000200f8u,0x000001ecu,0x0004003du,0x00000006u,0x000001efu,0x000000c9u,0x0004003du,0x00000006u,0x000001f0u,0x000000d5u,0x0007000cu,0x00000006u,0x000001f1u,0x00000001u,0x00000028u,0x000001efu,0x000001f0u,0x0003003eu,0x000001eeu,0x000001f1u,0x0004003du,0x00000006u,0x000001f3u,0x000001eeu,0x00050088u,0x00000006u,0x000001f4u,0x000001f3u,0x000000cdu,0x0008000cu,0x00000006u,0x000001f5u,0x00000001u,0x0000002bu,0x000001f4u,0x0000008fu,0x0000003fu,0x0003003eu,0x000001f2u,0x000001f5u,0x0004003du,0x00000006u,0x000001f7u,0x000001eeu,0x0007000cu,0x00000006u,0x000001f8u,0x00000001u,0x00000030u,0x000000cdu,0x000001f7u,0x0003003eu,0x000001f6u,0x000001f8u,0x0004003du,0x00000022u,0x000001f9u,0x00000024u,0x0004003du,0x00000016u,0x000001fau,0x00000018u,0x0004003du,0x00000006u,0x000001fbu,0x000001f6u,0x0004003du,0x00000006u,0x000001fcu,0x000001f2u,0x00070050u,0x0000004cu,0x000001fdu,0x000001fbu,0x000001fcu,0x0000008fu,0x0000003fu,0x00040063u,0x000001f9u,0x000001fau,0x000001fdu,0x000100fdu,0x000200f8u,0x000001edu,0x0004003du,0x00000022u,0x000001ffu,0x00000024u,0x0004003du,0x00000016u,0x00000200u,0x00000018u,0x0004003du,0x00000007u,0x00000201u,0x000001e5u,0x00050051u,0x00000006u,0x00000202u,0x00000201u,0x00000000u,0x00050051u,0x00000006u,0x00000203u,0x00000201u,0x00000001u,0x00050051u,0x00000006u,0x00000204u,0x00000201u,0x00000002u,0x00070050u,0x0000004cu,0x00000205u,0x00000202u,0x00000203u,0x00000204u,0x0000003fu,0x00040063u,0x000001ffu,0x00000200u,0x00000205u,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x0000000bu,0x00000000u,0x00000009u,0x00030037u,0x00000008u,0x0000000au,0x000200f8u,0x0000000cu,0x0004003du,0x00000007u,0x0000000du,0x0000000au,0x00050094u,0x00000006u,0x00000012u,0x0000000du,0x00000011u,0x000200feu,0x00000012u,0x00010038u}; static const size_t DDFG_SYNTH_LEN = 3082; struct Blob { const uint32_t* code; size_t words; }; diff --git a/app/src/main/cpp/framegen/ddfg/framegen.cpp b/app/src/main/cpp/framegen/ddfg/framegen.cpp index 5200f6b094..20cc5e2d4a 100644 --- a/app/src/main/cpp/framegen/ddfg/framegen.cpp +++ b/app/src/main/cpp/framegen/ddfg/framegen.cpp @@ -3,9 +3,35 @@ #include "log.hpp" #include #include +#include namespace ddfg { +struct ScratchState { + VkDevice ownerDevice = VK_NULL_HANDLE; + VkBuffer synthUbo[ddfg::FrameGen::kSynthSlots]{}; + VkDeviceMemory synthUboMem[ddfg::FrameGen::kSynthSlots]{}; + void* synthUboPtr[ddfg::FrameGen::kSynthSlots]{}; + std::vector flowUbo; std::vector flowUboMem; std::vector flowUboPtr; + VkBuffer expandUbo = VK_NULL_HANDLE; VkDeviceMemory expandUboMem = VK_NULL_HANDLE; void* expandUboPtr = nullptr; + VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr; + VkBuffer gmUbo[ddfg::FrameGen::kGmSlots]{}; + VkDeviceMemory gmUboMem[ddfg::FrameGen::kGmSlots]{}; + void* gmUboPtr[ddfg::FrameGen::kGmSlots]{}; + VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE; + std::vector sDownA, sDownB, sFlow; + VkDescriptorSet sExpand[ddfg::FrameGen::kGmSlots]{}; + VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE; + VkDescriptorSet sSynth[ddfg::FrameGen::kSynthSlots]{}; + VkDescriptorSet sGmReduce[ddfg::FrameGen::kGmSlots]{}; + std::vector sGmPrewarp[ddfg::FrameGen::kGmSlots]; + VkExtent2D builtFor{0,0}; + uint64_t builtGeneration = 0; + bool built = false; + bool flowInited = false; + bool flowReady = false; +}; + #define VKOK(x) do { if ((x) != VK_SUCCESS) { DDFG_LOGE("vk fail: %s", #x); return false; } } while (0) uint32_t FrameGen::findMemType(uint32_t bits, VkMemoryPropertyFlags props) const { @@ -107,6 +133,10 @@ static bool buildSetLayout(const DeviceDispatch* dd, VkDevice dev, bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id, VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue) { + if (device_ || completionUnknown_ || deviceLost_) { + DDFG_LOGE("framegen: refusing to initialize an instance that still owns device resources"); + return false; + } dd_ = dd; id_ = id; phys_ = phys; device_ = dev; queueFamily_ = queueFamily; queue_ = queue; id_->GetPhysicalDeviceMemoryProperties(phys_, &memProps_); @@ -165,16 +195,37 @@ static VkExtent2D levelExtent(VkExtent2D e, int l) { } bool FrameGen::onResize(VkExtent2D extent, VkFormat , bool force) { - - + if (completionUnknown_ || deviceLost_) return false; + if (!device_) { + DDFG_LOGE("framegen: cannot resize before device initialization"); + return false; + } if (!force && ready_ && extent.width == extent_.width && extent.height == extent_.height) return true; + if (ready_ && !waitIdle("resize")) return false; + if (scratch_ && scratch_->ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) { + DDFG_LOGE("framegen resize: scratch cleanup failed; retaining the previous image set"); + return false; + } + + ready_ = false; + ++imageGeneration_; for (auto& i : pyrA_) destroyImage(i); pyrA_.clear(); for (auto& i : pyrB_) destroyImage(i); pyrB_.clear(); for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear(); for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear(); destroyImage(flowExpA_); destroyImage(flowExpB_); destroyImage(flowRegA_); destroyImage(flowRegB_); - extent_ = extent; ready_ = false; + extent_ = extent; + + for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0; + for (int s = 0; s < kGmSlots; ++s) { + gmSlotValid_[s] = false; + for (int i = 0; i < 6; ++i) gmLinAt_[s][i] = 0.0; + } + gmHaveEst_ = false; + gmEngaged_ = false; + gmStableCount_ = 0; + gmLastTransPx_ = 0.0f; const VkImageUsageFlags lumaUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; const VkImageUsageFlags flowUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; @@ -211,10 +262,51 @@ void FrameGen::barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkI VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); } +void FrameGen::initializeImage(VkCommandBuffer cmd, VkImage img, VkImageLayout to) { + VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; + b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + b.newLayout = to; + b.srcAccessMask = 0; + b.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + b.image = img; + b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); +} -void FrameGen::destroy() { - if (!device_) return; - dd_->DeviceWaitIdle(device_); + +bool FrameGen::destroy() { + if (!device_) return true; + if (!deviceLost_) { + // A previous wait failure leaves completion unknown, but a later + // teardown attempt may safely retry the wait before releasing resources. + if (!dd_ || !dd_->DeviceWaitIdle) { + ready_ = false; + completionUnknown_ = true; + DDFG_LOGE("framegen destroy: vkDeviceWaitIdle is unavailable; preserving GPU resources"); + return false; + } + const VkResult idleResult = dd_->DeviceWaitIdle(device_); + if (idleResult == VK_SUCCESS) completionUnknown_ = false; + if (idleResult != VK_SUCCESS) { + ready_ = false; + if (idleResult == VK_ERROR_DEVICE_LOST) { + deviceLost_ = true; + DDFG_LOGE("framegen destroy: device lost; releasing owned resources without waiting"); + } else { + completionUnknown_ = true; + DDFG_LOGE("framegen destroy: DeviceWaitIdle failed (%d); preserving resources because GPU completion is unknown", + (int)idleResult); + return false; + } + } + } + + ready_ = false; + if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr); + descPool_ = VK_NULL_HANDLE; + releaseScratch(); for (auto& i : pyrA_) destroyImage(i); pyrA_.clear(); for (auto& i : pyrB_) destroyImage(i); pyrB_.clear(); for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear(); @@ -226,15 +318,45 @@ void FrameGen::destroy() { destroyPipe(pGmReduce_); destroyPipe(pGmPrewarp_); destroyPipe(pFlowReg_); for (int s = 0; s < kGmSlots; ++s) { - if (gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]); + if (gmSsboPtr_[s] && gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]); if (gmSsbo_[s]) dd_->DestroyBuffer(device_, gmSsbo_[s], nullptr); if (gmSsboMem_[s]) dd_->FreeMemory(device_, gmSsboMem_[s], nullptr); gmSsbo_[s] = VK_NULL_HANDLE; gmSsboMem_[s] = VK_NULL_HANDLE; gmSsboPtr_[s] = nullptr; } gmBuffersReady_ = false; - if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr); if (linear_) dd_->DestroySampler(device_, linear_, nullptr); - descPool_ = VK_NULL_HANDLE; linear_ = VK_NULL_HANDLE; device_ = VK_NULL_HANDLE; ready_ = false; + linear_ = VK_NULL_HANDLE; + device_ = VK_NULL_HANDLE; + ready_ = false; + deviceLost_ = false; + return true; +} + +void FrameGen::abandon() { + device_ = VK_NULL_HANDLE; + dd_ = nullptr; + id_ = nullptr; + phys_ = VK_NULL_HANDLE; + queue_ = VK_NULL_HANDLE; + linear_ = VK_NULL_HANDLE; + descPool_ = VK_NULL_HANDLE; + scratch_.reset(); + pyrA_.clear(); pyrB_.clear(); pyrAs_.clear(); flowLvl_.clear(); + flowExpA_ = Img{}; flowExpB_ = Img{}; + flowRegA_ = Img{}; flowRegB_ = Img{}; + pLuma_ = Pipe{}; pDown_ = Pipe{}; pFlow_ = Pipe{}; pFlowM4_ = Pipe{}; + pExpand_ = Pipe{}; pExpandM4_ = Pipe{}; pSynth_ = Pipe{}; + pGmReduce_ = Pipe{}; pGmPrewarp_ = Pipe{}; pFlowReg_ = Pipe{}; + for (int s = 0; s < kGmSlots; ++s) { + gmSsbo_[s] = VK_NULL_HANDLE; + gmSsboMem_[s] = VK_NULL_HANDLE; + gmSsboPtr_[s] = nullptr; + gmSlotValid_[s] = false; + } + gmBuffersReady_ = false; + ready_ = false; + completionUnknown_ = false; + deviceLost_ = false; } } diff --git a/app/src/main/cpp/framegen/ddfg/framegen.hpp b/app/src/main/cpp/framegen/ddfg/framegen.hpp index 70719e7963..bba77480c7 100644 --- a/app/src/main/cpp/framegen/ddfg/framegen.hpp +++ b/app/src/main/cpp/framegen/ddfg/framegen.hpp @@ -1,12 +1,20 @@ #pragma once #include "vk_dispatch.hpp" #include "config.hpp" +#include #include namespace ddfg { +struct ScratchState; + class FrameGen { public: + FrameGen(); + ~FrameGen(); + FrameGen(const FrameGen&) = delete; + FrameGen& operator=(const FrameGen&) = delete; + bool init(const DeviceDispatch* dd, const InstanceDispatch* id, VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue); void configure(const Config& c); @@ -14,7 +22,8 @@ public: void record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView, VkImageView outView, float alpha, uint32_t gmSlot = 0, uint32_t synthSlot = 0, bool reuseFlow = false); - void destroy(); + bool destroy(); + void abandon(); bool valid() const { return device_ != VK_NULL_HANDLE && ready_; } const Config& config() const { return cfg_; } @@ -63,6 +72,10 @@ private: const std::vector& bindings); void destroyPipe(Pipe& p); void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to); + void initializeImage(VkCommandBuffer cmd, VkImage img, VkImageLayout to); + bool waitIdle(const char* operation); + bool destroyScratchResources(bool resetPool = true); + void releaseScratch(); const DeviceDispatch* dd_ = nullptr; const InstanceDispatch* id_ = nullptr; @@ -76,8 +89,12 @@ private: Config cfg_; VkExtent2D extent_{}; + uint64_t imageGeneration_ = 0; bool ready_ = false; + bool completionUnknown_ = false; + bool deviceLost_ = false; int flowFinest_ = kFlowFinestDefault; + std::unique_ptr scratch_; Pipe pLuma_, pDown_, pFlow_, pFlowM4_, pExpand_, pExpandM4_, pSynth_; Pipe pGmReduce_, pGmPrewarp_; diff --git a/app/src/main/cpp/framegen/ddfg/record_impl.inc b/app/src/main/cpp/framegen/ddfg/record_impl.inc index f366d9a9c4..3922db391b 100644 --- a/app/src/main/cpp/framegen/ddfg/record_impl.inc +++ b/app/src/main/cpp/framegen/ddfg/record_impl.inc @@ -1,31 +1,7 @@ -namespace { -struct ScratchState { - VkBuffer synthUbo[ddfg::FrameGen::kSynthSlots]{}; - VkDeviceMemory synthUboMem[ddfg::FrameGen::kSynthSlots]{}; - void* synthUboPtr[ddfg::FrameGen::kSynthSlots]{}; - std::vector flowUbo; std::vector flowUboMem; std::vector flowUboPtr; - VkBuffer expandUbo = VK_NULL_HANDLE; VkDeviceMemory expandUboMem = VK_NULL_HANDLE; void* expandUboPtr = nullptr; - VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr; - VkBuffer gmUbo[ddfg::FrameGen::kGmSlots]{}; - VkDeviceMemory gmUboMem[ddfg::FrameGen::kGmSlots]{}; - void* gmUboPtr[ddfg::FrameGen::kGmSlots]{}; - VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE; - std::vector sDownA, sDownB, sFlow; - VkDescriptorSet sExpand[ddfg::FrameGen::kGmSlots]{}; - - - - VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE; - VkDescriptorSet sSynth[ddfg::FrameGen::kSynthSlots]{}; - VkDescriptorSet sGmReduce[ddfg::FrameGen::kGmSlots]{}; - std::vector sGmPrewarp[ddfg::FrameGen::kGmSlots]; - VkExtent2D builtFor{0,0}; - bool built = false; - bool flowInited = false; - bool flowReady = false; -}; -ScratchState g_scratch; +namespace ddfg { +FrameGen::FrameGen() : scratch_(std::make_unique()) {} +FrameGen::~FrameGen() { (void)destroy(); } } static bool makeUbo(const ddfg::DeviceDispatch* dd, VkDevice dev, @@ -58,6 +34,26 @@ static void wImg(const ddfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet s w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1; w.descriptorType = type; w.pImageInfo = ⅈ dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr); } +static void wImgBatch(const ddfg::DeviceDispatch* dd, VkDevice dev, + const VkDescriptorSet* sets, const uint32_t* bindings, + const VkDescriptorType* types, const VkImageView* views, + const VkSampler* samplers, const VkImageLayout* layouts, + uint32_t count) { + VkDescriptorImageInfo infos[3]{}; + VkWriteDescriptorSet writes[3]{}; + for (uint32_t i = 0; i < count; ++i) { + infos[i].imageView = views[i]; + infos[i].sampler = samplers[i]; + infos[i].imageLayout = layouts[i]; + writes[i] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; + writes[i].dstSet = sets[i]; + writes[i].dstBinding = bindings[i]; + writes[i].descriptorCount = 1; + writes[i].descriptorType = types[i]; + writes[i].pImageInfo = &infos[i]; + } + dd->UpdateDescriptorSets(dev, count, writes, 0, nullptr); +} static void wUbo(const ddfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding, VkBuffer buf, VkDeviceSize range) { VkDescriptorBufferInfo bi{}; bi.buffer = buf; bi.range = range; @@ -122,7 +118,7 @@ static void mulAff(const double A[3][3], const double B[3][3], double out[3][3]) namespace ddfg { -static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, +static bool ensureScratch(ScratchState& S, FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool, VkSampler samp, VkExtent2D ext, std::vector& pyrA, std::vector& pyrB, @@ -133,58 +129,123 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce, const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg, FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo, - int kLevels, const Config& cfg); + int kLevels, const Config& cfg, uint64_t imageGeneration); -static void destroyScratch(const DeviceDispatch* dd, VkDevice dev, VkDescriptorPool pool) { +bool FrameGen::waitIdle(const char* operation) { + if (completionUnknown_ || deviceLost_ || !device_) return false; + if (!dd_ || !dd_->DeviceWaitIdle) { + completionUnknown_ = true; + ready_ = false; + DDFG_LOGE("framegen: %s cannot confirm GPU completion; this instance is stopped and its resources are retained", + operation); + return false; + } + const VkResult result = dd_->DeviceWaitIdle(device_); + if (result == VK_SUCCESS) return true; + ready_ = false; + if (result == VK_ERROR_DEVICE_LOST) { + deviceLost_ = true; + DDFG_LOGE("framegen: %s reported device loss; cleanup will skip further waits", operation); + } else { + completionUnknown_ = true; + DDFG_LOGE("framegen: %s vkDeviceWaitIdle failed (%d); this instance is stopped and its GPU resources retained", + operation, (int)result); + } + return false; +} + +bool FrameGen::destroyScratchResources(bool resetPool) { + if (!scratch_) return true; + if (resetPool && descPool_ && !deviceLost_) { + if (!dd_ || !dd_->ResetDescriptorPool) { + ready_ = false; + DDFG_LOGE("framegen: descriptor-pool reset is unavailable; retaining scratch resources"); + return false; + } + const VkResult result = dd_->ResetDescriptorPool(device_, descPool_, 0); + if (result != VK_SUCCESS) { + ready_ = false; + if (result == VK_ERROR_DEVICE_LOST) deviceLost_ = true; + DDFG_LOGE("framegen: descriptor-pool reset failed (%d); retaining scratch resources", + (int)result); + return false; + } + } + releaseScratch(); + return true; +} + +void FrameGen::releaseScratch() { + if (!scratch_) return; + auto& S = *scratch_; auto freeUbo = [&](VkBuffer& b, VkDeviceMemory& m, void*& p) { - if (m) dd->UnmapMemory(dev, m); - if (b) dd->DestroyBuffer(dev, b, nullptr); - if (m) dd->FreeMemory(dev, m, nullptr); - b = VK_NULL_HANDLE; m = VK_NULL_HANDLE; p = nullptr; + if (p && m) dd_->UnmapMemory(device_, m); + if (b) dd_->DestroyBuffer(device_, b, nullptr); + if (m) dd_->FreeMemory(device_, m, nullptr); + b = VK_NULL_HANDLE; + m = VK_NULL_HANDLE; + p = nullptr; }; - auto& S = g_scratch; for (int s = 0; s < FrameGen::kSynthSlots; ++s) freeUbo(S.synthUbo[s], S.synthUboMem[s], S.synthUboPtr[s]); - freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr); + freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr); freeUbo(S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr); for (size_t i = 0; i < S.flowUbo.size(); ++i) freeUbo(S.flowUbo[i], S.flowUboMem[i], S.flowUboPtr[i]); for (int s = 0; s < FrameGen::kGmSlots; ++s) freeUbo(S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]); - if (pool && dd->ResetDescriptorPool) dd->ResetDescriptorPool(dev, pool, 0); S = ScratchState{}; } + void FrameGen::configure(const Config& c) { - cfg_ = c; cfg_.sanitize(); - int want = flowFinestForPreset(cfg_.perfPreset); + if (completionUnknown_ || deviceLost_) return; + Config nextCfg = c; + nextCfg.sanitize(); + int want = flowFinestForPreset(nextCfg.perfPreset); const int maxFinest = kLevels - 2; if (want > maxFinest) { DDFG_LOGE("perf-preset=%d wants kFlowFinest=%d but only %d pyramid levels exist " - "(need >=2 solved) - clamping to %d", cfg_.perfPreset, want, kLevels, maxFinest); + "(need >=2 solved) - clamping to %d", nextCfg.perfPreset, want, kLevels, maxFinest); want = maxFinest; } if (want < 1) want = 1; const int prevFinest = flowFinest_; - flowFinest_ = want; - const bool live = (flowFinest_ != prevFinest) && ready_; + const bool live = (want != prevFinest) && ready_; DDFG_LOGI("perf-preset=%d -> kFlowFinest=%d (was %d) live-rebuild=%d ready=%d", - cfg_.perfPreset, flowFinest_, prevFinest, live ? 1 : 0, ready_ ? 1 : 0); + nextCfg.perfPreset, want, prevFinest, live ? 1 : 0, ready_ ? 1 : 0); - if (!live) return; + if (!live) { + cfg_ = nextCfg; + flowFinest_ = want; + return; + } + if (!waitIdle("live preset rebuild")) return; + if (scratch_ && scratch_->ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) { + DDFG_LOGE("perf-preset live rebuild: scratch cleanup failed; keeping the previous configuration"); + return; + } - - - dd_->DeviceWaitIdle(device_); - destroyScratch(dd_, device_, descPool_); - if (!onResize(extent_, VK_FORMAT_UNDEFINED, true)) - DDFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u - FG disabled until next resize", - extent_.width, extent_.height); for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0; - for (int s = 0; s < kGmSlots; ++s) { gmSlotValid_[s] = false; for (int i = 0; i < 6; ++i) gmLinAt_[s][i] = 0.0; } - gmHaveEst_ = false; gmEngaged_ = false; gmStableCount_ = 0; gmLastTransPx_ = 0.0f; + for (int s = 0; s < kGmSlots; ++s) { + gmSlotValid_[s] = false; + for (int i = 0; i < 6; ++i) gmLinAt_[s][i] = 0.0; + } + gmHaveEst_ = false; + gmEngaged_ = false; + gmStableCount_ = 0; + gmLastTransPx_ = 0.0f; + + cfg_ = nextCfg; + flowFinest_ = want; + ready_ = false; + if (!onResize(extent_, VK_FORMAT_UNDEFINED, true)) { + ready_ = false; + DDFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u - frame generation unavailable", + extent_.width, extent_.height); + return; + } DDFG_LOGI("perf-preset live rebuild DONE (kFlowFinest=%d, flow predictor reset)", flowFinest_); } - bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) { ++gmFrames_; if (!gmBuffersReady_ || cfg_.gmMode == 2 ) { @@ -199,10 +260,10 @@ bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) { bool good = false; if (gmSlotValid_[gmSlot]) { const float* pt = (const float*)gmSsboPtr_[gmSlot]; - double sums[32]; for (int k = 0; k < 32; ++k) sums[k] = 0.0; + double sums[28]{}; for (int t = 0; t < kGmThreads; ++t) { const float* row = pt + (size_t)t * kGmStride; - for (int k = 0; k < kGmStride; ++k) sums[k] += (double)row[k]; + for (int k = 0; k < 28; ++k) sums[k] += (double)row[k]; } double coverage = sums[27]; double lvlpx = double((fullExtent.width >> kGmLevel) * (fullExtent.height >> kGmLevel)); @@ -254,23 +315,33 @@ bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) { void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView, VkImageView outView, float alpha, uint32_t gmSlot, uint32_t synthSlot, bool reuseFlow) { if (!valid()) return; + auto& S = *scratch_; if (gmSlot >= (uint32_t)kGmSlots) gmSlot = 0; if (synthSlot >= (uint32_t)kSynthSlots) synthSlot = 0; const bool m4 = (cfg_.model == 4); const Pipe& flowP = m4 ? pFlowM4_ : pFlow_; const Pipe& expandP = m4 ? pExpandM4_ : pExpand_; - if (!g_scratch.built || g_scratch.builtFor.width != extent_.width || g_scratch.builtFor.height != extent_.height) { - ensureScratch(this, dd_, device_, memProps_, descPool_, linear_, extent_, - pyrA_, pyrB_, pyrAs_, flowLvl_, flowExpA_, flowExpB_, - pLuma_, pDown_, flowP, expandP, pSynth_, pGmReduce_, pGmPrewarp_, - pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_); + if (!S.built || S.builtFor.width != extent_.width || + S.builtFor.height != extent_.height || + S.builtGeneration != imageGeneration_) { + if (S.built && !waitIdle("scratch rebuild")) return; + if (S.ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) { + DDFG_LOGE("framegen record: scratch cleanup failed; skipping this frame"); + return; + } + if (!ensureScratch(S, this, dd_, device_, memProps_, descPool_, linear_, extent_, + pyrA_, pyrB_, pyrAs_, flowLvl_, flowExpA_, flowExpB_, + pLuma_, pDown_, flowP, expandP, pSynth_, pGmReduce_, pGmPrewarp_, + pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_, imageGeneration_)) + return; } - if (reuseFlow && !g_scratch.flowReady) return; + if (S.ownerDevice != device_) return; + if (reuseFlow && !S.flowReady) return; if (!reuseFlow) { bool gmEngaged = updateGlobalMotion(gmSlot, extent_); - if (g_scratch.gmUboPtr[gmSlot]) { + if (S.gmUboPtr[gmSlot]) { GMUBO g{}; g.lin[0]=(float)gmRun_[0]; g.lin[1]=(float)gmRun_[1]; g.lin[2]=(float)gmRun_[2]; g.lin[3]=(float)gmRun_[3]; g.linT[0]=(float)gmRun_[4]; g.linT[1]=(float)gmRun_[5]; g.linT[2]=gmEngaged?1.0f:0.0f; g.linT[3]=0.0f; @@ -278,7 +349,7 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur g.app[0]=(float)gmRun_[0]; g.app[1]=(float)gmRun_[1]; g.app[2]=(float)gmRun_[2]; g.app[3]=(float)gmRun_[3]; g.appT[0]=(float)gmRun_[4]; g.appT[1]=(float)gmRun_[5]; } - std::memcpy(g_scratch.gmUboPtr[gmSlot], &g, sizeof(g)); + std::memcpy(S.gmUboPtr[gmSlot], &g, sizeof(g)); } { static int lastEng = -1; @@ -289,18 +360,37 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur } } - wImg(dd_, device_, g_scratch.sLumaCurr, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - wImg(dd_, device_, g_scratch.sLumaPrev, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + const VkDescriptorSet lumaSets[] = {S.sLumaCurr, S.sLumaPrev}; + const uint32_t lumaBindings[] = {32, 32}; + const VkDescriptorType lumaTypes[] = { + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}; + const VkImageView lumaViews[] = {currView, prevView}; + const VkSampler lumaSamplers[] = {linear_, linear_}; + const VkImageLayout lumaLayouts[] = { + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}; + wImgBatch(dd_, device_, lumaSets, lumaBindings, lumaTypes, lumaViews, + lumaSamplers, lumaLayouts, 2); } SynthUBO su{cfg_.flowScale, alpha, cfg_.beta, cfg_.lambda, cfg_.epsilon, cfg_.photoScale, 0, 0, cfg_.hudX0, cfg_.hudY0, cfg_.hudX1, cfg_.hudY1}; - if (g_scratch.synthUboPtr[synthSlot]) std::memcpy(g_scratch.synthUboPtr[synthSlot], &su, sizeof(su)); + if (S.synthUboPtr[synthSlot]) std::memcpy(S.synthUboPtr[synthSlot], &su, sizeof(su)); - const VkDescriptorSet synthSet = g_scratch.sSynth[synthSlot]; - wImg(dd_, device_, synthSet, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - wImg(dd_, device_, synthSet, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - wImg(dd_, device_, synthSet, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, outView, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_GENERAL); + const VkDescriptorSet synthSet = S.sSynth[synthSlot]; + const VkDescriptorSet synthSets[] = {synthSet, synthSet, synthSet}; + const uint32_t synthBindings[] = {32, 33, 48}; + const VkDescriptorType synthTypes[] = { + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}; + const VkImageView synthViews[] = {prevView, currView, outView}; + const VkSampler synthSamplers[] = {linear_, linear_, VK_NULL_HANDLE}; + const VkImageLayout synthLayouts[] = { + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_GENERAL}; + wImgBatch(dd_, device_, synthSets, synthBindings, synthTypes, synthViews, + synthSamplers, synthLayouts, 3); auto disp = [&](const Pipe& p, VkDescriptorSet set, VkExtent2D e) { dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, p.pipeline); @@ -308,43 +398,94 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur dd_->CmdDispatch(cmd, (e.width + 15) / 16, (e.height + 15) / 16, 1); }; auto bar = [&](FrameGen::Img& i){ barrier(cmd, i.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL); }; + auto barPair = [&](FrameGen::Img& a, FrameGen::Img& b) { + VkImageMemoryBarrier barriers[2]{}; + FrameGen::Img* images[] = {&a, &b}; + for (uint32_t i = 0; i < 2; ++i) { + barriers[i].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[i].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + barriers[i].dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + barriers[i].oldLayout = VK_IMAGE_LAYOUT_GENERAL; + barriers[i].newLayout = VK_IMAGE_LAYOUT_GENERAL; + barriers[i].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[i].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[i].image = images[i]->image; + barriers[i].subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + } + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, + 0, nullptr, 2, barriers); + }; + const bool frEngaged = (cfg_.frMode != 2) && (cfg_.frIters > 0); if (!reuseFlow) { - for (auto& i : pyrA_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - for (auto& i : pyrB_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - for (int l = flowFinest_; l < kLevels; ++l) barrier(cmd, pyrAs_[l].image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - barrier(cmd, flowExpA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - barrier(cmd, flowExpB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - barrier(cmd, flowRegA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); - barrier(cmd, flowRegB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + // Batch fresh-image transitions that share the same stage and access masks. + std::array initBarriers{}; + size_t initBarrierCount = 0; + auto addInitBarrier = [&](VkImage image) { + VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; + b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + b.newLayout = VK_IMAGE_LAYOUT_GENERAL; + b.srcAccessMask = 0; + b.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + b.image = image; + b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + initBarriers[initBarrierCount++] = b; + }; + for (auto& i : pyrA_) addInitBarrier(i.image); + for (auto& i : pyrB_) addInitBarrier(i.image); + for (int l = flowFinest_; l < kLevels; ++l) addInitBarrier(pyrAs_[l].image); + addInitBarrier(flowExpA_.image); + addInitBarrier(flowExpB_.image); + if (frEngaged) { + addInitBarrier(flowRegA_.image); + addInitBarrier(flowRegB_.image); + } + // The final flow level is cleared through TRANSFER_DST_OPTIMAL below; + // the other levels can use the common initialization barrier. + for (int l = flowFinest_; l < kLevels - 1; ++l) addInitBarrier(flowLvl_[l].image); + if (initBarrierCount != 0) { + dd_->CmdPipelineBarrier(cmd, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, + 0, nullptr, static_cast(initBarrierCount), initBarriers.data()); + } { VkClearColorValue zero{}; VkImageSubresourceRange rng{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; - for (int l = flowFinest_; l < kLevels; ++l) { - VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; - b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - b.srcAccessMask = 0; b.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - b.image = flowLvl_[l].image; b.subresourceRange = rng; - b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); - dd_->CmdClearColorImage(cmd, flowLvl_[l].image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &zero, 1, &rng); - b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; b.newLayout = VK_IMAGE_LAYOUT_GENERAL; - b.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; - dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); - } + VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; + b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + b.srcAccessMask = 0; + b.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + b.image = flowLvl_[kLevels - 1].image; + b.subresourceRange = rng; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + dd_->CmdPipelineBarrier(cmd, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); + dd_->CmdClearColorImage(cmd, flowLvl_[kLevels - 1].image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &zero, 1, &rng); + b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + b.newLayout = VK_IMAGE_LAYOUT_GENERAL; + b.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); } - disp(pLuma_, g_scratch.sLumaCurr, levelExtent(extent_, 0)); - disp(pLuma_, g_scratch.sLumaPrev, levelExtent(extent_, 0)); - bar(pyrA_[0]); bar(pyrB_[0]); + disp(pLuma_, S.sLumaCurr, levelExtent(extent_, 0)); + disp(pLuma_, S.sLumaPrev, levelExtent(extent_, 0)); + barPair(pyrA_[0], pyrB_[0]); for (int l = 1; l < kLevels; ++l) { - disp(pDown_, g_scratch.sDownA[l - 1], levelExtent(extent_, l)); - disp(pDown_, g_scratch.sDownB[l - 1], levelExtent(extent_, l)); - bar(pyrA_[l]); bar(pyrB_[l]); + disp(pDown_, S.sDownA[l - 1], levelExtent(extent_, l)); + disp(pDown_, S.sDownB[l - 1], levelExtent(extent_, l)); + barPair(pyrA_[l], pyrB_[l]); } - if (gmBuffersReady_ && g_scratch.sGmReduce[gmSlot]) { + if (gmBuffersReady_ && S.sGmReduce[gmSlot]) { dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.pipeline); - dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &g_scratch.sGmReduce[gmSlot], 0, nullptr); + dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &S.sGmReduce[gmSlot], 0, nullptr); dd_->CmdDispatch(cmd, (uint32_t)(kGmThreads / 64), 1, 1); VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; mb.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; mb.dstAccessMask = VK_ACCESS_HOST_READ_BIT; @@ -352,32 +493,31 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur 0, 1, &mb, 0, nullptr, 0, nullptr); } for (int l = flowFinest_; l < kLevels; ++l) { - disp(pGmPrewarp_, g_scratch.sGmPrewarp[gmSlot][l], levelExtent(extent_, l)); + disp(pGmPrewarp_, S.sGmPrewarp[gmSlot][l], levelExtent(extent_, l)); bar(pyrAs_[l]); } for (int l = kLevels - 1; l >= flowFinest_; --l) { - disp(flowP, g_scratch.sFlow[l], levelExtent(extent_, l)); + disp(flowP, S.sFlow[l], levelExtent(extent_, l)); bar(flowLvl_[l]); } - const bool frEngaged = (cfg_.frMode != 2) && (cfg_.frIters > 0); if (frEngaged) { const int F = flowFinest_; const VkExtent2D fe = levelExtent(extent_, F); - if (g_scratch.flowRegUboPtr) { + if (S.flowRegUboPtr) { FlowRegUBO fu{cfg_.frDt, cfg_.frLambda, cfg_.frEdge, cfg_.frEps}; - std::memcpy(g_scratch.flowRegUboPtr, &fu, sizeof(fu)); + std::memcpy(S.flowRegUboPtr, &fu, sizeof(fu)); } FrameGen::Img* last = nullptr; for (int it = 0; it < cfg_.frIters; ++it) { VkDescriptorSet set; FrameGen::Img* outImg; - if (it == 0) { set = g_scratch.sFlowReg0; outImg = &flowRegA_; } - else if (it % 2 == 1) { set = g_scratch.sFlowRegAB; outImg = &flowRegB_; } - else { set = g_scratch.sFlowRegBA; outImg = &flowRegA_; } + if (it == 0) { set = S.sFlowReg0; outImg = &flowRegA_; } + else if (it % 2 == 1) { set = S.sFlowRegAB; outImg = &flowRegB_; } + else { set = S.sFlowRegBA; outImg = &flowRegA_; } dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.pipeline); dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.layout, 0, 1, &set, 0, nullptr); dd_->CmdDispatch(cmd, (fe.width + 15) / 16, (fe.height + 15) / 16, 1); - bar(*outImg); + if (it + 1 < cfg_.frIters) bar(*outImg); last = outImg; } VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; @@ -407,14 +547,14 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur } } - disp(expandP, g_scratch.sExpand[gmSlot], levelExtent(extent_, 0)); - bar(flowExpA_); bar(flowExpB_); - g_scratch.flowReady = true; + disp(expandP, S.sExpand[gmSlot], levelExtent(extent_, 0)); + barPair(flowExpA_, flowExpB_); + S.flowReady = true; } disp(pSynth_, synthSet, levelExtent(extent_, 0)); } -static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, +static bool ensureScratch(ScratchState& S, FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool, VkSampler samp, VkExtent2D ext, std::vector& pyrA, std::vector& pyrB, @@ -425,9 +565,10 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce, const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg, FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo, - int kLevels, const Config& cfg) { - auto& S = g_scratch; + int kLevels, const Config& cfg, uint64_t imageGeneration) { + if (S.ownerDevice != VK_NULL_HANDLE && S.ownerDevice != dev) return false; S = ScratchState{}; + S.ownerDevice = dev; const auto GEN = VK_IMAGE_LAYOUT_GENERAL; for (int s = 0; s < FrameGen::kSynthSlots; ++s) @@ -528,7 +669,7 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, wImg(dd, dev, S.sSynth[s], 35, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, expB.view, samp, GEN); } - S.builtFor = ext; S.built = true; + S.builtFor = ext; S.builtGeneration = imageGeneration; S.ownerDevice = dev; S.built = true; return true; } diff --git a/app/src/main/cpp/questxr/CMakeLists.txt b/app/src/main/cpp/questxr/CMakeLists.txt index c23558bb0b..dd7ccc3599 100644 --- a/app/src/main/cpp/questxr/CMakeLists.txt +++ b/app/src/main/cpp/questxr/CMakeLists.txt @@ -8,6 +8,6 @@ target_compile_features(droiddeckxr PRIVATE cxx_std_17) target_compile_definitions(droiddeckxr PRIVATE XR_USE_PLATFORM_ANDROID XR_USE_GRAPHICS_API_OPENGL_ES XR_USE_TIMESPEC) target_compile_options(droiddeckxr PRIVATE -Wall -Wextra -Wno-missing-field-initializers -Werror=return-type) target_link_options(droiddeckxr PRIVATE -Wl,-z,max-page-size=16384 -uANativeActivity_onCreate) -target_link_libraries(droiddeckxr PRIVATE droiddeckxr_glue OpenXR::openxr_loader EGL GLESv3 android log) +target_link_libraries(droiddeckxr PRIVATE droiddeckxr_glue OpenXR::openxr_loader EGL GLESv3 android jnigraphics log) target_include_directories(droiddeckxr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../tools/vr/src) diff --git a/app/src/main/cpp/questxr/quest_xr.cpp b/app/src/main/cpp/questxr/quest_xr.cpp index 09423c7d1a..7f0237b097 100644 --- a/app/src/main/cpp/questxr/quest_xr.cpp +++ b/app/src/main/cpp/questxr/quest_xr.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -22,10 +23,14 @@ #include #include #include +#include +#include #include "xr_tracking.h" #include "xr_frame_channel.h" #include "xr_frame_math.h" #include "gpu_frames.h" +#include "xr_host.h" +#include "xr_overlay.h" static void check(XrResult result, const char *operation) { if (XR_FAILED(result)) throw std::runtime_error(std::string(operation) + ": " + std::to_string(result)); @@ -37,6 +42,15 @@ struct Eye { std::vector images; }; +struct SurfaceLayer { + XrSwapchain swapchain = XR_NULL_HANDLE; + jobject surface = nullptr; + int width = 0, height = 0; +}; + +class QuestXR; +static QuestXR *g_runtime = nullptr; + class QuestXR { public: explicit QuestXR(android_app *app) : app_(app) {} @@ -76,21 +90,74 @@ public: "\"headPosition\":[%.6f,%.6f,%.6f],\"controllersActive\":[%s,%s]," "\"periodNs\":%lld,\"surfaceSwapchain\":%s,\"source\":\"%s\",\"guestFrames\":%lld,\"steamvrState\":%d," "\"receivedFrames\":%llu,\"rejectedFrames\":%llu,\"uploadedFrames\":%llu,\"sourceFrameId\":%llu," - "\"gpuReceivedFrames\":%llu,\"gpuDroppedFrames\":%llu,\"gpuVerifiedFrameId\":%llu,\"gpuChecksum\":%u,\"error\":\"%s\"}\n", + "\"gpuReceivedFrames\":%llu,\"gpuDroppedFrames\":%llu,\"gpuVerifiedFrameId\":%llu,\"gpuChecksum\":%u," + "\"hostVersion\":%u,\"visibleLayers\":%d,\"overlay\":%s,\"error\":\"%s\"}\n", (unsigned long long)frames_, (unsigned long long)rendered_, state_, (unsigned long long)head_.locationFlags, head_.pose.position.x, head_.pose.position.y, head_.pose.position.z, handActive_[0] ? "true" : "false", handActive_[1] ? "true" : "false", - (long long)period_, "false", "frames", + (long long)period_, surfaceSupported_ ? "true" : "false", "frames", 0LL, steamvrState, (unsigned long long)(receiver_.Received() + gpuFrames_.Received()), (unsigned long long)(receiver_.Rejected() + gpuFrames_.Rejected()), (unsigned long long)uploadedFrames_, (unsigned long long)sourceHeader_.frame_id, (unsigned long long)gpuFrames_.Received(), (unsigned long long)gpuFrames_.Dropped(), - (unsigned long long)verifiedFrame_, gpuChecksum_, error); + (unsigned long long)verifiedFrame_, gpuChecksum_, + hostBuffers_ ? DROIDDECK_XR_HOST_VERSION : 0u, visibleLayers_, + XrOverlay::active(hostControl_) ? "true" : "false", error); std::fclose(file); std::rename(temp.c_str(), path.c_str()); } + bool onXrThread() const { return pthread_equal(pthread_self(), xrThread_); } + + int createLayer(JNIEnv *env, int width, int height) { + if (!onXrThread() || !createSurfaceSwapchain_ || session_ == XR_NULL_HANDLE || width <= 0 || height <= 0) return -1; + for (int index = 0; index < DROIDDECK_XR_HOST_LAYERS; index++) { + SurfaceLayer &layer = layers_[index]; + if (layer.swapchain) continue; + XrSwapchainCreateInfo create{XR_TYPE_SWAPCHAIN_CREATE_INFO}; + create.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; + create.width = width; create.height = height; + jobject surface = nullptr; + XrResult result = createSurfaceSwapchain_(session_, &create, &layer.swapchain, &surface); + if (XR_FAILED(result) || !surface) { + __android_log_print(ANDROID_LOG_ERROR, "DroidDeckXR", "surface layer %dx%d failed: %d", width, height, result); + if (layer.swapchain) xrDestroySwapchain(layer.swapchain); + layer = {}; + return -1; + } + layer.surface = env->NewGlobalRef(surface); + layer.width = width; layer.height = height; + __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "surface layer %d created %dx%d", index, width, height); + return index; + } + return -1; + } + + jobject layerSurface(JNIEnv *env, int index) { + if (!onXrThread() || index < 0 || index >= DROIDDECK_XR_HOST_LAYERS || !layers_[index].surface) return nullptr; + return env->NewLocalRef(layers_[index].surface); + } + + void setOrbImage(JNIEnv *env, jobject bitmap) { + if (!onXrThread() || !bitmap) return; + AndroidBitmapInfo info{}; + void *pixels = nullptr; + if (AndroidBitmap_getInfo(env, bitmap, &info) != ANDROID_BITMAP_RESULT_SUCCESS + || info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) return; + if (AndroidBitmap_lockPixels(env, bitmap, &pixels) != ANDROID_BITMAP_RESULT_SUCCESS) return; + overlay_.setLogo(pixels, (int)info.width, (int)info.height, (int)info.stride); + AndroidBitmap_unlockPixels(env, bitmap); + } + + void destroyLayer(JNIEnv *env, int index) { + if (!onXrThread() || index < 0 || index >= DROIDDECK_XR_HOST_LAYERS) return; + SurfaceLayer &layer = layers_[index]; + if (layer.swapchain) xrDestroySwapchain(layer.swapchain); + if (layer.surface) env->DeleteGlobalRef(layer.surface); + layer = {}; + } + private: android_app *app_; JNIEnv *env_ = nullptr; @@ -104,6 +171,20 @@ private: XrAction primary_ = XR_NULL_HANDLE, secondary_ = XR_NULL_HANDLE, menu_ = XR_NULL_HANDLE; XrAction triggerTouch_ = XR_NULL_HANDLE, stickTouch_ = XR_NULL_HANDLE, primaryTouch_ = XR_NULL_HANDLE; XrAction secondaryTouch_ = XR_NULL_HANDLE, thumbrestTouch_ = XR_NULL_HANDLE; + PFN_xrCreateSwapchainAndroidSurfaceKHR createSurfaceSwapchain_ = nullptr; + bool surfaceSupported_ = false; + bool imageLayoutSupported_ = false; + pthread_t xrThread_{}; + SurfaceLayer layers_[DROIDDECK_XR_HOST_LAYERS]; + DroidDeckXrHostState hostState_{}; + DroidDeckXrHostControl hostControl_{}; + bool hostBuffers_ = false; + jmethodID hostFrameCallback_ = nullptr; + uint64_t hostPulse_[2]{}; + int visibleLayers_ = 0; + XrOverlay overlay_; + Eye overlayEyes_[2]; + GLuint overlayDepth_[2]{}; DroidDeckXrHand inputs_[2]{}; PFN_xrConvertTimeToTimespecTimeKHR convertTime_ = nullptr; bool timespecSupported_ = false; @@ -220,6 +301,8 @@ private: void initialize() { app_->userData = this; + xrThread_ = pthread_self(); + g_runtime = this; app_->onInputEvent = [](android_app *app, AInputEvent *event) -> int32_t { if (AInputEvent_getType(event) != AINPUT_EVENT_TYPE_KEY || AKeyEvent_getKeyCode(event) != AKEYCODE_BACK || AKeyEvent_getAction(event) != AKEY_EVENT_ACTION_UP) return 0; @@ -244,6 +327,10 @@ private: frameCallback_ = env_->GetMethodID(activityClass, "onXrFrame", "(J)V"); statusCallback_ = env_->GetMethodID(activityClass, "onXrStatus", "()I"); if (env_->ExceptionCheck()) { env_->ExceptionClear(); throw std::runtime_error("XR activity bridge methods unavailable"); } + hostFrameCallback_ = env_->GetMethodID(activityClass, "onXrHostFrame", "()V"); + jmethodID hostBuffersCallback = hostFrameCallback_ ? + env_->GetMethodID(activityClass, "onXrHostBuffers", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)V") : nullptr; + if (env_->ExceptionCheck()) { env_->ExceptionClear(); hostFrameCallback_ = nullptr; hostBuffersCallback = nullptr; } env_->DeleteLocalRef(intentClass); env_->DeleteLocalRef(intent); env_->DeleteLocalRef(activityClass); PFN_xrInitializeLoaderKHR initializeLoader = nullptr; check(xrGetInstanceProcAddr(XR_NULL_HANDLE, "xrInitializeLoaderKHR", @@ -261,10 +348,21 @@ private: timespecSupported_ = true; if (!std::strcmp(extension.extensionName, XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME)) performanceSupported_ = true; + if (!std::strcmp(extension.extensionName, XR_KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME)) + surfaceSupported_ = true; + if (!std::strcmp(extension.extensionName, XR_FB_COMPOSITION_LAYER_IMAGE_LAYOUT_EXTENSION_NAME)) + imageLayoutSupported_ = true; } + __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "surface swapchain available=%d image layout=%d", + surfaceSupported_, imageLayoutSupported_); + // A surface swapchain's image arrives upside down, and a quad's back face is not drawn, so + // panels need the layout flag to flip it. + surfaceSupported_ = surfaceSupported_ && imageLayoutSupported_; std::vector enabled{XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME, XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME}; if (timespecSupported_) enabled.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME); if (performanceSupported_) enabled.push_back(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME); + if (surfaceSupported_) enabled.push_back(XR_KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME); + if (surfaceSupported_) enabled.push_back(XR_FB_COMPOSITION_LAYER_IMAGE_LAYOUT_EXTENSION_NAME); XrInstanceCreateInfoAndroidKHR androidInfo{XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR}; androidInfo.applicationVM = app_->activity->vm; androidInfo.applicationActivity = app_->activity->clazz; @@ -281,6 +379,11 @@ private: reinterpret_cast(&setPerformance_)); if (XR_FAILED(result)) setPerformance_ = nullptr; } + if (surfaceSupported_ && XR_FAILED(xrGetInstanceProcAddr(instance_, "xrCreateSwapchainAndroidSurfaceKHR", + reinterpret_cast(&createSurfaceSwapchain_)))) { + createSurfaceSwapchain_ = nullptr; + surfaceSupported_ = false; + } if (timespecSupported_) check(xrGetInstanceProcAddr(instance_, "xrConvertTimeToTimespecTimeKHR", reinterpret_cast(&convertTime_)), "time conversion entrypoint"); XrSystemGetInfo systemInfo{XR_TYPE_SYSTEM_GET_INFO}; @@ -334,6 +437,16 @@ private: bool gpu = !verifyPixels_ && gpuFrames_.Start(std::string(app_->activity->internalDataPath) + "/.wayland-rt/" DROIDDECK_XR_GPU_SOCKET, display_); __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "GPU frame channel available=%d", gpu); } + overlay_.initialize(); + hostState_.version = DROIDDECK_XR_HOST_VERSION; + if (hostBuffersCallback) { + jobject state = env_->NewDirectByteBuffer(&hostState_, sizeof(hostState_)); + jobject control = env_->NewDirectByteBuffer(&hostControl_, sizeof(hostControl_)); + env_->CallVoidMethod(app_->activity->clazz, hostBuffersCallback, state, control); + if (env_->ExceptionCheck()) { env_->ExceptionDescribe(); env_->ExceptionClear(); hostFrameCallback_ = nullptr; } + else hostBuffers_ = true; + env_->DeleteLocalRef(state); env_->DeleteLocalRef(control); + } health(); } @@ -422,6 +535,13 @@ private: target.images.resize(count, {XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR}); check(xrEnumerateSwapchainImages(target.swapchain, count, &count, reinterpret_cast(target.images.data())), "images"); + Eye &overlay = overlayEyes_[eye]; + overlay.width = target.width; overlay.height = target.height; + check(xrCreateSwapchain(session_, &create, &overlay.swapchain), "overlay swapchain"); + check(xrEnumerateSwapchainImages(overlay.swapchain, 0, &count, nullptr), "overlay image count"); + overlay.images.resize(count, {XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR}); + check(xrEnumerateSwapchainImages(overlay.swapchain, count, &count, + reinterpret_cast(overlay.images.data())), "overlay images"); } } @@ -530,6 +650,12 @@ private: void initializeGraphics() { glGenFramebuffers(1, &framebuffer_); + glGenRenderbuffers(2, overlayDepth_); + for (int eye = 0; eye < 2; eye++) { + glBindRenderbuffer(GL_RENDERBUFFER, overlayDepth_[eye]); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, overlayEyes_[eye].width, overlayEyes_[eye].height); + } + glBindRenderbuffer(GL_RENDERBUFFER, 0); glGenVertexArrays(1, &vertexArray_); GLuint vertex = shader(GL_VERTEX_SHADER, "#version 300 es\nout vec2 uv; uniform float eye; void main(){vec2 coordinate=vec2(float((gl_VertexID<<1)&2),float(gl_VertexID&2));uv=vec2(coordinate.x*0.5+eye*0.5,1.0-coordinate.y);gl_Position=vec4(coordinate*2.0-1.0,0.0,1.0);}"); @@ -584,24 +710,46 @@ private: if (verifyPixels_ || uploadedFrames_ % 72 == 1) health(); } - void render(Eye &eye, uint32_t image) { + void render(Eye &eye, uint32_t image, bool source, const XrPosef &pose, const XrFovf &fov, float seconds) { glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eye.images[image].image, 0); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) throw std::runtime_error("Incomplete eye framebuffer"); - { - glViewport(0, 0, eye.width, eye.height); glDisable(GL_DEPTH_TEST); + glViewport(0, 0, eye.width, eye.height); glDisable(GL_DEPTH_TEST); + if (source) { glUseProgram(sourceProgram_); glBindVertexArray(vertexArray_); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sourceTexture_); glUniform1i(glGetUniformLocation(sourceProgram_, "source"), 0); glUniform1f(glGetUniformLocation(sourceProgram_, "eye"), &eye == &eyes_[1] ? 1.f : 0.f); glDrawArrays(GL_TRIANGLES, 0, 3); + } else { + glClearColor(0.f, 0.f, 0.f, 1.f); + glClear(GL_COLOR_BUFFER_BIT); } glBindFramebuffer(GL_FRAMEBUFFER, 0); if (glGetError() != GL_NO_ERROR) throw std::runtime_error("OpenGL render error"); glFlush(); } + // Lasers and the orb go in their own layer above the panels, which only the panels' depth hides. + void renderOverlay(int index, uint32_t image, const XrPosef &pose, const XrFovf &fov, float seconds) { + Eye &eye = overlayEyes_[index]; + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eye.images[image].image, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, overlayDepth_[index]); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + throw std::runtime_error("Incomplete overlay framebuffer"); + glViewport(0, 0, eye.width, eye.height); + glClearColor(0.f, 0.f, 0.f, 0.f); glClearDepthf(1.f); + glDepthMask(GL_TRUE); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + overlay_.draw(pose, fov, hostControl_, hostState_, seconds); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + if (glGetError() != GL_NO_ERROR) throw std::runtime_error("OpenGL overlay error"); + glFlush(); + } + void pollEvents() { XrEventDataBuffer event{XR_TYPE_EVENT_DATA_BUFFER}; XrResult result; @@ -614,10 +762,13 @@ private: XrSessionBeginInfo begin{XR_TYPE_SESSION_BEGIN_INFO}; begin.primaryViewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO; check(xrBeginSession(session_, &begin), "xrBeginSession"); running_ = true; + // Meta's clock governor scales clocks by the DroidDeck process's overall load and cannot see + // SteamVR missing refreshes inside the guest; holding the top level kept it at 72 Hz. if (setPerformance_) { for (auto domain : {XR_PERF_SETTINGS_DOMAIN_CPU_EXT, XR_PERF_SETTINGS_DOMAIN_GPU_EXT}) { - XrResult request = setPerformance_(session_, domain, XR_PERF_SETTINGS_LEVEL_SUSTAINED_HIGH_EXT); - __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "sustained performance domain=%d result=%d", domain, request); + XrResult request = setPerformance_(session_, domain, XR_PERF_SETTINGS_LEVEL_BOOST_EXT); + if (XR_FAILED(request)) request = setPerformance_(session_, domain, XR_PERF_SETTINGS_LEVEL_SUSTAINED_HIGH_EXT); + __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "performance domain=%d result=%d", domain, request); } } } else if (state_ == XR_SESSION_STATE_STOPPING) { @@ -682,6 +833,7 @@ private: XrViewState viewState{XR_TYPE_VIEW_STATE}; uint32_t count = 0; XrView views[2]{{XR_TYPE_VIEW}, {XR_TYPE_VIEW}}; check(xrLocateViews(session_, &locate, &viewState, 2, &count, views), "xrLocateViews"); + hostFrame(frameState.predictedDisplayTime); publishTracking(views, frameState.predictedDisplayTime); if (guestAttached_) { timespec now{}; clock_gettime(CLOCK_MONOTONIC, &now); @@ -689,29 +841,34 @@ private: if (env_->ExceptionCheck()) { env_->ExceptionClear(); throw std::runtime_error("Guest frame callback failed"); } } XrCompositionLayerProjectionView projection[2]{{XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}, {XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}}; - bool valid = frameState.shouldRender && count == 2 && + const bool viewsValid = frameState.shouldRender && count == 2 && (viewState.viewStateFlags & (XR_VIEW_STATE_ORIENTATION_VALID_BIT | XR_VIEW_STATE_POSITION_VALID_BIT)) == (XR_VIEW_STATE_ORIENTATION_VALID_BIT | XR_VIEW_STATE_POSITION_VALID_BIT); - { - valid = valid && sourceHeader_.frame_id && xr_frame_now() - sourceHeader_.captured_ns < 500000000LL; - if (valid) for (int eye = 0; eye < 2; eye++) { - auto source = xr_frame_view(sourceHeader_, eye); - views[eye].pose.orientation = {source.orientation[0], source.orientation[1], source.orientation[2], source.orientation[3]}; - views[eye].pose.position = {source.position[0], source.position[1], source.position[2]}; - views[eye].fov = {source.fov[0], source.fov[1], source.fov[2], source.fov[3]}; - } + bool valid = viewsValid && sourceHeader_.frame_id && xr_frame_now() - sourceHeader_.captured_ns < 500000000LL; + if (valid) for (int eye = 0; eye < 2; eye++) { + auto source = xr_frame_view(sourceHeader_, eye); + views[eye].pose.orientation = {source.orientation[0], source.orientation[1], source.orientation[2], source.orientation[3]}; + views[eye].pose.position = {source.position[0], source.position[1], source.position[2]}; + views[eye].fov = {source.fov[0], source.fov[1], source.fov[2], source.fov[3]}; } + std::vector quads; + std::vector layouts; + if (viewsValid) collectQuads(quads, layouts); + const bool uiOnly = !valid && viewsValid && !quads.empty(); + const bool draw = valid || uiOnly; const std::string capture = captureRequest(); bool captured = valid; if (!capture.empty() && valid) captured = captureTexture(sourceTexture_, sourceHeader_.width, sourceHeader_.height, "source"); - if (valid) for (int eye = 0; eye < 2; eye++) { + timespec clock{}; clock_gettime(CLOCK_MONOTONIC, &clock); + const float seconds = (float)(clock.tv_sec % 3600) + clock.tv_nsec * 1e-9f; + if (draw) for (int eye = 0; eye < 2; eye++) { uint32_t image = 0; XrSwapchainImageAcquireInfo acquire{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO}; check(xrAcquireSwapchainImage(eyes_[eye].swapchain, &acquire, &image), "acquire image"); XrSwapchainImageWaitInfo imageWait{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO}; imageWait.timeout = XR_INFINITE_DURATION; check(xrWaitSwapchainImage(eyes_[eye].swapchain, &imageWait), "wait image"); - render(eyes_[eye], image); + render(eyes_[eye], image, valid, views[eye].pose, views[eye].fov, seconds); if (!capture.empty()) captured = captureTexture(eyes_[eye].images[image].image, eyes_[eye].width, eyes_[eye].height, eye ? "right" : "left") && captured; XrSwapchainImageReleaseInfo release{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO}; check(xrReleaseSwapchainImage(eyes_[eye].swapchain, &release), "release image"); @@ -719,19 +876,143 @@ private: projection[eye].subImage.swapchain = eyes_[eye].swapchain; projection[eye].subImage.imageRect.extent = {eyes_[eye].width, eyes_[eye].height}; } + const bool overlay = viewsValid && hostBuffers_ && XrOverlay::active(hostControl_); + XrCompositionLayerProjectionView overlayViews[2]{{XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}, {XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}}; + if (overlay) for (int eye = 0; eye < 2; eye++) { + uint32_t image = 0; + XrSwapchainImageAcquireInfo acquire{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO}; + check(xrAcquireSwapchainImage(overlayEyes_[eye].swapchain, &acquire, &image), "acquire overlay image"); + XrSwapchainImageWaitInfo imageWait{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO}; imageWait.timeout = XR_INFINITE_DURATION; + check(xrWaitSwapchainImage(overlayEyes_[eye].swapchain, &imageWait), "wait overlay image"); + renderOverlay(eye, image, views[eye].pose, views[eye].fov, seconds); + XrSwapchainImageReleaseInfo release{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO}; + check(xrReleaseSwapchainImage(overlayEyes_[eye].swapchain, &release), "release overlay image"); + overlayViews[eye].pose = views[eye].pose; overlayViews[eye].fov = views[eye].fov; + overlayViews[eye].subImage.swapchain = overlayEyes_[eye].swapchain; + overlayViews[eye].subImage.imageRect.extent = {overlayEyes_[eye].width, overlayEyes_[eye].height}; + } XrCompositionLayerProjection layer{XR_TYPE_COMPOSITION_LAYER_PROJECTION}; layer.space = world_; layer.viewCount = 2; layer.views = projection; - const XrCompositionLayerBaseHeader *layers[] = {reinterpret_cast(&layer)}; + XrCompositionLayerProjection overlayLayer{XR_TYPE_COMPOSITION_LAYER_PROJECTION}; + overlayLayer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT; + overlayLayer.space = world_; overlayLayer.viewCount = 2; overlayLayer.views = overlayViews; + std::vector layers; + if (draw) layers.push_back(reinterpret_cast(&layer)); + for (auto &quad : quads) layers.push_back(reinterpret_cast(&quad)); + if (overlay) layers.push_back(reinterpret_cast(&overlayLayer)); + visibleLayers_ = (int)quads.size(); XrFrameEndInfo end{XR_TYPE_FRAME_END_INFO}; end.displayTime = frameState.predictedDisplayTime; - end.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; end.layerCount = valid ? 1 : 0; end.layers = layers; + end.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; + end.layerCount = (uint32_t)layers.size(); end.layers = layers.data(); check(xrEndFrame(session_, &end), "xrEndFrame"); if (!capture.empty()) captureResult(capture, captured, valid, projection, frameState.predictedDisplayTime); frames_++; if (valid) rendered_++; if (frames_ % 72 == 0) { health(); - __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "frames=%llu rendered=%llu head=%llu hands=%d,%d period=%lld", + __android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "frames=%llu rendered=%llu head=%llu hands=%d,%d period=%lld layers=%d", (unsigned long long)frames_, (unsigned long long)rendered_, (unsigned long long)head_.locationFlags, - handActive_[0], handActive_[1], (long long)period_); + handActive_[0], handActive_[1], (long long)period_, visibleLayers_); + } + } + + // Android surfaces are stored top row first, while OpenXR samples images bottom row first. + void collectQuads(std::vector &quads, std::vector &layouts) { + if (!hostBuffers_) return; + quads.reserve(DROIDDECK_XR_HOST_LAYERS); + layouts.reserve(DROIDDECK_XR_HOST_LAYERS); + const DroidDeckXrHostLayer *ordered[DROIDDECK_XR_HOST_LAYERS]; + int visible = 0; + for (const auto &layer : hostControl_.layers) { + if (!layer.visible || layer.id < 0 || layer.id >= DROIDDECK_XR_HOST_LAYERS || !layers_[layer.id].swapchain) continue; + if (!(layer.width > 0.f) || !(layer.height > 0.f)) continue; + ordered[visible++] = &layer; + } + std::sort(ordered, ordered + visible, [](const DroidDeckXrHostLayer *a, const DroidDeckXrHostLayer *b) { return a->order < b->order; }); + for (int index = 0; index < visible; index++) { + const auto &layer = *ordered[index]; + const SurfaceLayer &surface = layers_[layer.id]; + XrCompositionLayerQuad quad{XR_TYPE_COMPOSITION_LAYER_QUAD}; + quad.layerFlags = (layer.flags & DROIDDECK_XR_HOST_LAYER_ALPHA) ? XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT : 0; + quad.space = (layer.flags & DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED) ? view_ : world_; + quad.eyeVisibility = XR_EYE_VISIBILITY_BOTH; + quad.subImage.swapchain = surface.swapchain; + quad.subImage.imageRect.extent = {surface.width, surface.height}; + quad.pose.orientation = {layer.pose.orientation[0], layer.pose.orientation[1], layer.pose.orientation[2], layer.pose.orientation[3]}; + quad.pose.position = {layer.pose.position[0], layer.pose.position[1], layer.pose.position[2]}; + quad.size = {layer.width, layer.height}; + layouts.push_back({XR_TYPE_COMPOSITION_LAYER_IMAGE_LAYOUT_FB, nullptr, XR_COMPOSITION_LAYER_IMAGE_LAYOUT_VERTICAL_FLIP_BIT_FB}); + quad.next = &layouts.back(); + quads.push_back(quad); + } + } + + // SteamVR draws its laser from the "tip" of the Quest Touch render model the driver names + // (resources/rendermodels/oculus_quest_plus_controller_*), placed on the raw grip pose; panels + // use the same ray so there is one laser per controller. + static DroidDeckXrPose steamVrPointer(const XrSpaceLocation &grip, int hand) { + const float q[4] = {grip.pose.orientation.x, grip.pose.orientation.y, grip.pose.orientation.z, grip.pose.orientation.w}; + const XrVec3 tip{hand == 0 ? 0.016694f : -0.016694f, -0.02522f, 0.024687f}; + const XrVec3 at = XrVec3{grip.pose.position.x, grip.pose.position.y, grip.pose.position.z} + rotate(q, tip); + const float tx = -0.320613f, tw = 0.947210f; + DroidDeckXrPose pose{}; + pose.orientation[0] = q[3] * tx + q[0] * tw; + pose.orientation[1] = q[1] * tw + q[2] * tx; + pose.orientation[2] = q[2] * tw - q[1] * tx; + pose.orientation[3] = q[3] * tw - q[0] * tx; + pose.position[0] = at.x; pose.position[1] = at.y; pose.position[2] = at.z; + pose.flags = (uint32_t)grip.locationFlags; + return pose; + } + + void hostFrame(XrTime predicted) { + if (!hostBuffers_ || !hostFrameCallback_) return; + hostState_.version = DROIDDECK_XR_HOST_VERSION; + hostState_.session_state = state_; + hostState_.flags = (surfaceSupported_ ? DROIDDECK_XR_HOST_SURFACE_SWAPCHAIN : 0u) | + (state_ == XR_SESSION_STATE_FOCUSED ? DROIDDECK_XR_HOST_FOCUSED : 0u); + hostState_.frame = (int64_t)frames_; + hostState_.display_time_ns = 0; + if (convertTime_) { + timespec displayTime{}; + if (XR_SUCCEEDED(convertTime_(instance_, predicted, &displayTime))) + hostState_.display_time_ns = (int64_t)displayTime.tv_sec * 1000000000LL + displayTime.tv_nsec; + } + hostState_.head = posePacket(head_.pose, head_.locationFlags); + const XrSpaceLocationFlags tracked = XR_SPACE_LOCATION_ORIENTATION_VALID_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT; + for (int hand = 0; hand < 2; hand++) { + auto &out = hostState_.hands[hand]; + out.grip = posePacket(handLocations_[hand].pose, handLocations_[hand].locationFlags); + out.aim = steamVrPointer(handLocations_[hand], hand); + out.trigger = inputs_[hand].trigger; out.squeeze = inputs_[hand].squeeze; + out.stick[0] = inputs_[hand].stick[0]; out.stick[1] = inputs_[hand].stick[1]; + out.buttons = inputs_[hand].buttons; + out.active = handActive_[hand] && (handLocations_[hand].locationFlags & tracked) == tracked; + } + env_->CallVoidMethod(app_->activity->clazz, hostFrameCallback_); + if (env_->ExceptionCheck()) { + env_->ExceptionDescribe(); env_->ExceptionClear(); + hostControl_ = {}; + return; + } + if (hostControl_.version != DROIDDECK_XR_HOST_VERSION) { hostControl_ = {}; return; } + for (int hand = 0; hand < 2; hand++) { + const auto &control = hostControl_.hands[hand]; + if (control.mask & DROIDDECK_XR_HOST_MASK_INPUT) { + inputs_[hand].trigger = 0; inputs_[hand].squeeze = 0; + inputs_[hand].stick[0] = inputs_[hand].stick[1] = 0; + inputs_[hand].buttons = 0; + } + const auto &pulse = control.haptic; + if (pulse.id == hostPulse_[hand]) continue; + hostPulse_[hand] = pulse.id; + if (state_ != XR_SESSION_STATE_FOCUSED || !handActive_[hand] + || pulse.duration_ns < 1000000 || pulse.duration_ns > 1000000000 + || !std::isfinite(pulse.amplitude) || pulse.amplitude < 0 || pulse.amplitude > 1 + || !std::isfinite(pulse.frequency) || pulse.frequency < 0) continue; + XrHapticActionInfo info{XR_TYPE_HAPTIC_ACTION_INFO}; info.action = vibration_; info.subactionPath = hands_[hand]; + XrHapticVibration vibration{XR_TYPE_HAPTIC_VIBRATION}; + vibration.duration = pulse.duration_ns; vibration.amplitude = pulse.amplitude; vibration.frequency = pulse.frequency; + check(xrApplyHapticFeedback(session_, &info, reinterpret_cast(&vibration)), "host haptics"); } } @@ -746,11 +1027,17 @@ private: munmap(tracking_, sizeof(DroidDeckXrTracking)); } if (haptics_) munmap(haptics_, sizeof(DroidDeckXrHaptics)); + g_runtime = nullptr; + hostBuffers_ = false; if (display_ != EGL_NO_DISPLAY && context_ != EGL_NO_CONTEXT) { glDeleteFramebuffers(1, &framebuffer_); glDeleteVertexArrays(1, &vertexArray_); glDeleteTextures(1, &cpuTexture_); glDeleteProgram(sourceProgram_); + glDeleteRenderbuffers(2, overlayDepth_); + overlay_.destroy(); } + if (env_) for (int index = 0; index < DROIDDECK_XR_HOST_LAYERS; index++) destroyLayer(env_, index); for (auto &eye : eyes_) if (eye.swapchain) xrDestroySwapchain(eye.swapchain); + for (auto &eye : overlayEyes_) if (eye.swapchain) xrDestroySwapchain(eye.swapchain); for (auto space : handSpaces_) if (space) xrDestroySpace(space); if (view_) xrDestroySpace(view_); if (world_) xrDestroySpace(world_); if (session_) xrDestroySession(session_); @@ -766,6 +1053,26 @@ private: } }; +extern "C" JNIEXPORT jint JNICALL +Java_com_droiddeck_launcher_QuestXrActivity_nativeCreateLayer(JNIEnv *env, jobject, jint width, jint height) { + return g_runtime ? g_runtime->createLayer(env, width, height) : -1; +} + +extern "C" JNIEXPORT jobject JNICALL +Java_com_droiddeck_launcher_QuestXrActivity_nativeLayerSurface(JNIEnv *env, jobject, jint index) { + return g_runtime ? g_runtime->layerSurface(env, index) : nullptr; +} + +extern "C" JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_QuestXrActivity_nativeDestroyLayer(JNIEnv *env, jobject, jint index) { + if (g_runtime) g_runtime->destroyLayer(env, index); +} + +extern "C" JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_QuestXrActivity_nativeSetOrbImage(JNIEnv *env, jobject, jobject bitmap) { + if (g_runtime) g_runtime->setOrbImage(env, bitmap); +} + void android_main(android_app *app) { QuestXR runtime(app); try { runtime.run(); } diff --git a/app/src/main/cpp/questxr/xr_host.h b/app/src/main/cpp/questxr/xr_host.h new file mode 100644 index 0000000000..9f08c32537 --- /dev/null +++ b/app/src/main/cpp/questxr/xr_host.h @@ -0,0 +1,91 @@ +#pragma once +#include +#include +#include "xr_tracking.h" + +// Shared with com.droiddeck.launcher.session.xr.XrHost, which reads and writes these through direct +// ByteBuffers by fixed offset: any layout change must bump the version and update both sides. +#define DROIDDECK_XR_HOST_VERSION 1u +#define DROIDDECK_XR_HOST_LAYERS 6 + +#define DROIDDECK_XR_HOST_SURFACE_SWAPCHAIN (1u << 0) +#define DROIDDECK_XR_HOST_FOCUSED (1u << 1) + +#define DROIDDECK_XR_HOST_MASK_INPUT (1u << 0) + +#define DROIDDECK_XR_HOST_LAYER_ALPHA (1u << 0) +#define DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED (1u << 1) + +struct DroidDeckXrHostHand { + DroidDeckXrPose grip; + DroidDeckXrPose aim; + float trigger, squeeze, stick[2]; + uint32_t buttons, active; + uint32_t reserved[2]; +}; + +struct DroidDeckXrHostState { + uint32_t version, session_state, flags, reserved0; + int64_t frame, display_time_ns; + DroidDeckXrPose head; + DroidDeckXrHostHand hands[2]; + uint32_t reserved[8]; +}; + +struct DroidDeckXrHostHaptic { + uint64_t id; + int64_t duration_ns; + float amplitude, frequency; +}; + +struct DroidDeckXrHostHandControl { + uint32_t mask; + float laser; + DroidDeckXrHostHaptic haptic; + uint32_t reserved[2]; +}; + +struct DroidDeckXrHostOrb { + uint32_t visible; + float progress, burst, radius; + DroidDeckXrPose pose; +}; + +struct DroidDeckXrHostLayer { + int32_t id; + uint32_t visible, flags; + int32_t order; + DroidDeckXrPose pose; + float width, height; + uint32_t reserved[2]; +}; + +struct DroidDeckXrHostControl { + uint32_t version, reserved0; + DroidDeckXrHostHandControl hands[2]; + DroidDeckXrHostOrb orb; + DroidDeckXrHostLayer layers[DROIDDECK_XR_HOST_LAYERS]; + uint32_t reserved[8]; +}; + +static_assert(sizeof(DroidDeckXrHostHand) == 96, "XR host hand layout"); +static_assert(offsetof(DroidDeckXrHostHand, aim) == 32 && offsetof(DroidDeckXrHostHand, trigger) == 64 && + offsetof(DroidDeckXrHostHand, stick) == 72 && offsetof(DroidDeckXrHostHand, buttons) == 80 && + offsetof(DroidDeckXrHostHand, active) == 84, "XR host hand layout"); +static_assert(offsetof(DroidDeckXrHostState, flags) == 8 && offsetof(DroidDeckXrHostState, frame) == 16 && + offsetof(DroidDeckXrHostState, head) == 32, "XR host state layout"); +static_assert(offsetof(DroidDeckXrHostHandControl, laser) == 4 && offsetof(DroidDeckXrHostHandControl, haptic) == 8, + "XR host hand control layout"); +static_assert(offsetof(DroidDeckXrHostHaptic, duration_ns) == 8 && offsetof(DroidDeckXrHostHaptic, amplitude) == 16, + "XR host haptic layout"); +static_assert(offsetof(DroidDeckXrHostOrb, progress) == 4 && offsetof(DroidDeckXrHostOrb, pose) == 16, "XR host orb layout"); +static_assert(offsetof(DroidDeckXrHostLayer, order) == 12 && offsetof(DroidDeckXrHostLayer, pose) == 16 && + offsetof(DroidDeckXrHostLayer, width) == 48, "XR host layer layout"); +static_assert(sizeof(DroidDeckXrHostState) == 288, "XR host state layout"); +static_assert(offsetof(DroidDeckXrHostState, hands) == 64, "XR host state layout"); +static_assert(sizeof(DroidDeckXrHostHandControl) == 40, "XR host hand control layout"); +static_assert(sizeof(DroidDeckXrHostOrb) == 48, "XR host orb layout"); +static_assert(sizeof(DroidDeckXrHostLayer) == 64, "XR host layer layout"); +static_assert(offsetof(DroidDeckXrHostControl, orb) == 88, "XR host control layout"); +static_assert(offsetof(DroidDeckXrHostControl, layers) == 136, "XR host control layout"); +static_assert(sizeof(DroidDeckXrHostControl) == 552, "XR host control layout"); diff --git a/app/src/main/cpp/questxr/xr_overlay.h b/app/src/main/cpp/questxr/xr_overlay.h new file mode 100644 index 0000000000..5078e27b16 --- /dev/null +++ b/app/src/main/cpp/questxr/xr_overlay.h @@ -0,0 +1,229 @@ +#pragma once +#include +#include +#include +#include +#include +#include "xr_host.h" + +struct XrVec3 { float x, y, z; }; + +static inline XrVec3 xrv(float x, float y, float z) { return {x, y, z}; } +static inline XrVec3 operator+(XrVec3 a, XrVec3 b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; } +static inline XrVec3 operator-(XrVec3 a, XrVec3 b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; } +static inline XrVec3 operator*(XrVec3 a, float s) { return {a.x * s, a.y * s, a.z * s}; } +static inline float dot(XrVec3 a, XrVec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } +static inline XrVec3 cross(XrVec3 a, XrVec3 b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; } +static inline XrVec3 normalized(XrVec3 a) { + float length = std::sqrt(dot(a, a)); + return length > 1e-6f ? a * (1.f / length) : xrv(0, 0, 0); +} + +static inline XrVec3 rotate(const float q[4], XrVec3 v) { + XrVec3 u{q[0], q[1], q[2]}; + float s = q[3]; + return u * (2.f * dot(u, v)) + v * (s * s - dot(u, u)) + cross(u, v) * (2.f * s); +} + +class XrOverlay { +public: + void initialize() { + GLuint vertex = compile(GL_VERTEX_SHADER, + "#version 300 es\nlayout(location=0) in vec3 position; layout(location=1) in vec2 coordinate;" + "uniform mat4 viewProjection; out vec2 uv;" + "void main(){uv=coordinate;gl_Position=viewProjection*vec4(position,1.0);}"); + GLuint fragment = compile(GL_FRAGMENT_SHADER, + "#version 300 es\nprecision highp float; in vec2 uv; uniform int mode; uniform float progress, burst, time;" + "uniform vec3 color; uniform sampler2D logo; uniform int hasLogo; out vec4 outputColor;" + "void main(){" + " if(mode==0){float across=1.0-abs(uv.y); float a=smoothstep(0.0,0.7,across)*mix(0.95,0.35,uv.x);" + " outputColor=vec4(color*a,a);return;}" + " if(mode==1){float r=length(uv); float a=1.0-smoothstep(0.55,1.0,r); outputColor=vec4(vec3(1.0)*a,a);return;}" + " float r=length(uv); vec3 c=vec3(0.0); float a=0.0;" + " float pulse=0.5+0.5*sin(time*6.0);" + " float glow=exp(-pow(max(r-0.45,0.0)*6.0,2.0))*(0.25+0.2*pulse)*step(0.5,r); c+=color*glow; a=max(a,glow*0.7);" + " if(hasLogo==1&&r<0.52){vec4 l=texture(logo,vec2(0.5+uv.x/1.04,0.5-uv.y/1.04)); c=c*(1.0-l.a)+l.rgb; a=a*(1.0-l.a)+l.a;}" + " else if(r<0.5){float core=1.0-smoothstep(0.46,0.5,r); c+=color*core; a=max(a,core);}" + " float angle=atan(uv.x,uv.y); float sweep=(angle<0.0?angle+6.2831853:angle)/6.2831853;" + " float band=1.0-smoothstep(0.0,0.03,abs(r-0.64));" + " float track=band*0.25; float fill=band*step(sweep,progress);" + " c+=vec3(1.0)*track+color*fill*1.4; a=max(a,max(track,fill));" + " if(burst>0.0){float ring=(1.0-smoothstep(0.0,0.06,abs(r-(0.64+burst*0.3))))*(1.0-burst); c+=color*ring*2.0; a=max(a,ring);}" + " a=clamp(a,0.0,1.0); outputColor=vec4(c*a,a);" + "}"); + program_ = glCreateProgram(); + glAttachShader(program_, vertex); glAttachShader(program_, fragment); + glLinkProgram(program_); glDeleteShader(vertex); glDeleteShader(fragment); + GLint linked = 0; glGetProgramiv(program_, GL_LINK_STATUS, &linked); + if (!linked) throw std::runtime_error("Overlay shader link failed"); + viewProjection_ = glGetUniformLocation(program_, "viewProjection"); + mode_ = glGetUniformLocation(program_, "mode"); + progress_ = glGetUniformLocation(program_, "progress"); + burst_ = glGetUniformLocation(program_, "burst"); + time_ = glGetUniformLocation(program_, "time"); + color_ = glGetUniformLocation(program_, "color"); + logoSampler_ = glGetUniformLocation(program_, "logo"); + hasLogo_ = glGetUniformLocation(program_, "hasLogo"); + glGenVertexArrays(1, &vertexArray_); + glGenBuffers(1, &buffer_); + glBindVertexArray(vertexArray_); + glBindBuffer(GL_ARRAY_BUFFER, buffer_); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 5 * 6, nullptr, GL_DYNAMIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, nullptr); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, reinterpret_cast(sizeof(float) * 3)); + glBindVertexArray(0); + } + + /** [pixels] are premultiplied RGBA rows, top row first, as an Android ARGB_8888 bitmap holds them. */ + void setLogo(const void *pixels, int width, int height, int stride) { + if (!logo_) glGenTextures(1, &logo_); + glBindTexture(GL_TEXTURE_2D, logo_); + glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / 4); + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + + void destroy() { + if (logo_) glDeleteTextures(1, &logo_); + logo_ = 0; + if (program_) glDeleteProgram(program_); + if (buffer_) glDeleteBuffers(1, &buffer_); + if (vertexArray_) glDeleteVertexArrays(1, &vertexArray_); + program_ = buffer_ = vertexArray_ = 0; + } + + static bool active(const DroidDeckXrHostControl &control) { + return control.orb.visible || control.hands[0].laser > 0.f || control.hands[1].laser > 0.f; + } + + void draw(const XrPosef &eye, const XrFovf &fov, const DroidDeckXrHostControl &control, + const DroidDeckXrHostState &state, float seconds) { + if (!active(control)) return; + float matrix[16]; + viewProjectionOf(eye, fov, matrix); + const float eyeOrientation[4] = {eye.orientation.x, eye.orientation.y, eye.orientation.z, eye.orientation.w}; + const XrVec3 eyePosition{eye.position.x, eye.position.y, eye.position.z}; + glUseProgram(program_); + glUniformMatrix4fv(viewProjection_, 1, GL_FALSE, matrix); + glUniform3f(color_, 0.12f, 0.62f, 1.0f); + glUniform1f(time_, seconds); + glBindVertexArray(vertexArray_); + glBindBuffer(GL_ARRAY_BUFFER, buffer_); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glDepthMask(GL_TRUE); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDisable(GL_BLEND); + glUniform1i(mode_, 0); + for (const auto &layer : control.layers) { + if (!layer.visible || !(layer.width > 0.f) || !(layer.height > 0.f)) continue; + if (layer.flags & DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED) continue; + XrVec3 center{layer.pose.position[0], layer.pose.position[1], layer.pose.position[2]}; + XrVec3 right = rotate(layer.pose.orientation, xrv(layer.width / 2.f, 0, 0)); + XrVec3 up = rotate(layer.pose.orientation, xrv(0, layer.height / 2.f, 0)); + quad(center - right - up, center + right - up, center - right + up, center + right + up, 0.f, 1.f); + } + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthMask(GL_FALSE); + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + for (int hand = 0; hand < 2; hand++) { + float length = control.hands[hand].laser; + if (!(length > 0.f) || !state.hands[hand].active) continue; + const auto &aim = state.hands[hand].aim; + XrVec3 start{aim.position[0], aim.position[1], aim.position[2]}; + XrVec3 direction = normalized(rotate(aim.orientation, xrv(0, 0, -1))); + XrVec3 end = start + direction * std::max(length - 0.004f, 0.f); + XrVec3 side = normalized(cross(direction, eyePosition - start)) * 0.0022f; + glUniform1i(mode_, 0); + quad(start - side, start + side, end - side, end + side, 0.f, 1.f); + XrVec3 right = rotate(eyeOrientation, xrv(1, 0, 0)) * 0.007f; + XrVec3 up = rotate(eyeOrientation, xrv(0, 1, 0)) * 0.007f; + glUniform1i(mode_, 1); + billboard(end + normalized(eyePosition - end) * 0.008f, right, up); + } + if (control.orb.visible) { + const auto &pose = control.orb.pose; + XrVec3 center{pose.position[0], pose.position[1], pose.position[2]}; + float size = control.orb.radius * 1.25f; + XrVec3 right = rotate(eyeOrientation, xrv(1, 0, 0)) * size; + XrVec3 up = rotate(eyeOrientation, xrv(0, 1, 0)) * size; + glUniform1i(mode_, 2); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, logo_); + glUniform1i(logoSampler_, 0); + glUniform1i(hasLogo_, logo_ ? 1 : 0); + glUniform1f(progress_, control.orb.progress); + glUniform1f(burst_, control.orb.burst); + billboard(center, right, up); + } + glBindVertexArray(0); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + } + +private: + GLuint program_ = 0, buffer_ = 0, vertexArray_ = 0, logo_ = 0; + GLint viewProjection_ = -1, mode_ = -1, progress_ = -1, burst_ = -1, time_ = -1, color_ = -1; + GLint logoSampler_ = -1, hasLogo_ = -1; + + static GLuint compile(GLenum type, const char *text) { + GLuint handle = glCreateShader(type); + glShaderSource(handle, 1, &text, nullptr); glCompileShader(handle); + GLint success = 0; glGetShaderiv(handle, GL_COMPILE_STATUS, &success); + if (!success) { glDeleteShader(handle); throw std::runtime_error("Overlay shader compile failed"); } + return handle; + } + + void billboard(XrVec3 center, XrVec3 right, XrVec3 up) { + quadUv(center - right - up, center + right - up, center - right + up, center + right + up); + } + + void quad(XrVec3 a0, XrVec3 a1, XrVec3 b0, XrVec3 b1, float from, float to) { + const float vertices[] = { + a0.x, a0.y, a0.z, from, -1, a1.x, a1.y, a1.z, from, 1, b0.x, b0.y, b0.z, to, -1, + b0.x, b0.y, b0.z, to, -1, a1.x, a1.y, a1.z, from, 1, b1.x, b1.y, b1.z, to, 1}; + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + + void quadUv(XrVec3 bottomLeft, XrVec3 bottomRight, XrVec3 topLeft, XrVec3 topRight) { + const float vertices[] = { + bottomLeft.x, bottomLeft.y, bottomLeft.z, -1, -1, bottomRight.x, bottomRight.y, bottomRight.z, 1, -1, + topLeft.x, topLeft.y, topLeft.z, -1, 1, topLeft.x, topLeft.y, topLeft.z, -1, 1, + bottomRight.x, bottomRight.y, bottomRight.z, 1, -1, topRight.x, topRight.y, topRight.z, 1, 1}; + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + + static void viewProjectionOf(const XrPosef &pose, const XrFovf &fov, float out[16]) { + const float q[4] = {pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w}; + XrVec3 xAxis = rotate(q, xrv(1, 0, 0)), yAxis = rotate(q, xrv(0, 1, 0)), zAxis = rotate(q, xrv(0, 0, 1)); + XrVec3 position{pose.position.x, pose.position.y, pose.position.z}; + float view[16] = { + xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, + -dot(xAxis, position), -dot(yAxis, position), -dot(zAxis, position), 1}; + const float nearZ = 0.05f, farZ = 100.f; + float left = std::tan(fov.angleLeft), right = std::tan(fov.angleRight); + float up = std::tan(fov.angleUp), down = std::tan(fov.angleDown); + float width = right - left, height = up - down; + float projection[16] = { + 2.f / width, 0, 0, 0, 0, 2.f / height, 0, 0, + (right + left) / width, (up + down) / height, -(farZ + nearZ) / (farZ - nearZ), -1, + 0, 0, -2.f * farZ * nearZ / (farZ - nearZ), 0}; + for (int column = 0; column < 4; column++) + for (int row = 0; row < 4; row++) { + float sum = 0; + for (int k = 0; k < 4; k++) sum += projection[k * 4 + row] * view[column * 4 + k]; + out[column * 4 + row] = sum; + } + } +}; diff --git a/app/src/main/cpp/sdnative/sdnative.c b/app/src/main/cpp/sdnative/sdnative.c index 3e4ef71b41..8482f38d33 100644 --- a/app/src/main/cpp/sdnative/sdnative.c +++ b/app/src/main/cpp/sdnative/sdnative.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -27,3 +28,16 @@ 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; +} diff --git a/app/src/main/cpp/shaders/SMAA.hlsl b/app/src/main/cpp/shaders/SMAA.hlsl new file mode 100644 index 0000000000..d955d52401 --- /dev/null +++ b/app/src/main/cpp/shaders/SMAA.hlsl @@ -0,0 +1,1361 @@ +/** + * 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. + */ + + +/** + * _______ ___ ___ ___ ___ + * / || \/ | / \ / \ + * | (---- | \ / | / ^ \ / ^ \ + * \ \ | |\/| | / /_\ \ / /_\ \ + * ----) | | | | | / _____ \ / _____ \ + * |_______/ |__| |__| /__/ \__\ /__/ \__\ + * + * E N H A N C E D + * S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G + * + * http://www.iryoku.com/smaa/ + * + * Hi, welcome aboard! + * + * Here you'll find instructions to get the shader up and running as fast as + * possible. + * + * IMPORTANTE NOTICE: when updating, remember to update both this file and the + * precomputed textures! They may change from version to version. + * + * The shader has three passes, chained together as follows: + * + * |input|------------------· + * v | + * [ SMAA*EdgeDetection ] | + * v | + * |edgesTex| | + * v | + * [ SMAABlendingWeightCalculation ] | + * v | + * |blendTex| | + * v | + * [ SMAANeighborhoodBlending ] <------· + * v + * |output| + * + * Note that each [pass] has its own vertex and pixel shader. Remember to use + * oversized triangles instead of quads to avoid overshading along the + * diagonal. + * + * You've three edge detection methods to choose from: luma, color or depth. + * They represent different quality/performance and anti-aliasing/sharpness + * tradeoffs, so our recommendation is for you to choose the one that best + * suits your particular scenario: + * + * - Depth edge detection is usually the fastest but it may miss some edges. + * + * - Luma edge detection is usually more expensive than depth edge detection, + * but catches visible edges that depth edge detection can miss. + * + * - Color edge detection is usually the most expensive one but catches + * chroma-only edges. + * + * For quickstarters: just use luma edge detection. + * + * The general advice is to not rush the integration process and ensure each + * step is done correctly (don't try to integrate SMAA T2x with predicated edge + * detection from the start!). Ok then, let's go! + * + * 1. The first step is to create two RGBA temporal render targets for holding + * |edgesTex| and |blendTex|. + * + * In DX10 or DX11, you can use a RG render target for the edges texture. + * In the case of NVIDIA GPUs, using RG render targets seems to actually be + * slower. + * + * On the Xbox 360, you can use the same render target for resolving both + * |edgesTex| and |blendTex|, as they aren't needed simultaneously. + * + * 2. Both temporal render targets |edgesTex| and |blendTex| must be cleared + * each frame. Do not forget to clear the alpha channel! + * + * 3. The next step is loading the two supporting precalculated textures, + * 'areaTex' and 'searchTex'. You'll find them in the 'Textures' folder as + * C++ headers, and also as regular DDS files. They'll be needed for the + * 'SMAABlendingWeightCalculation' pass. + * + * If you use the C++ headers, be sure to load them in the format specified + * inside of them. + * + * You can also compress 'areaTex' and 'searchTex' using BC5 and BC4 + * respectively, if you have that option in your content processor pipeline. + * When compressing then, you get a non-perceptible quality decrease, and a + * marginal performance increase. + * + * 4. All samplers must be set to linear filtering and clamp. + * + * After you get the technique working, remember that 64-bit inputs have + * half-rate linear filtering on GCN. + * + * If SMAA is applied to 64-bit color buffers, switching to point filtering + * when accesing them will increase the performance. Search for + * 'SMAASamplePoint' to see which textures may benefit from point + * filtering, and where (which is basically the color input in the edge + * detection and resolve passes). + * + * 5. All texture reads and buffer writes must be non-sRGB, with the exception + * of the input read and the output write in + * 'SMAANeighborhoodBlending' (and only in this pass!). If sRGB reads in + * this last pass are not possible, the technique will work anyway, but + * will perform antialiasing in gamma space. + * + * IMPORTANT: for best results the input read for the color/luma edge + * detection should *NOT* be sRGB. + * + * 6. Before including SMAA.h you'll have to setup the render target metrics, + * the target and any optional configuration defines. Optionally you can + * use a preset. + * + * You have the following targets available: + * SMAA_HLSL_3 + * SMAA_HLSL_4 + * SMAA_HLSL_4_1 + * SMAA_GLSL_3 * + * SMAA_GLSL_4 * + * + * * (See SMAA_INCLUDE_VS and SMAA_INCLUDE_PS below). + * + * And four presets: + * SMAA_PRESET_LOW (%60 of the quality) + * SMAA_PRESET_MEDIUM (%80 of the quality) + * SMAA_PRESET_HIGH (%95 of the quality) + * SMAA_PRESET_ULTRA (%99 of the quality) + * + * For example: + * #define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0) + * #define SMAA_HLSL_4 + * #define SMAA_PRESET_HIGH + * #include "SMAA.h" + * + * Note that SMAA_RT_METRICS doesn't need to be a macro, it can be a + * uniform variable. The code is designed to minimize the impact of not + * using a constant value, but it is still better to hardcode it. + * + * Depending on how you encoded 'areaTex' and 'searchTex', you may have to + * add (and customize) the following defines before including SMAA.h: + * #define SMAA_AREATEX_SELECT(sample) sample.rg + * #define SMAA_SEARCHTEX_SELECT(sample) sample.r + * + * If your engine is already using porting macros, you can define + * SMAA_CUSTOM_SL, and define the porting functions by yourself. + * + * 7. Then, you'll have to setup the passes as indicated in the scheme above. + * You can take a look into SMAA.fx, to see how we did it for our demo. + * Checkout the function wrappers, you may want to copy-paste them! + * + * 8. It's recommended to validate the produced |edgesTex| and |blendTex|. + * You can use a screenshot from your engine to compare the |edgesTex| + * and |blendTex| produced inside of the engine with the results obtained + * with the reference demo. + * + * 9. After you get the last pass to work, it's time to optimize. You'll have + * to initialize a stencil buffer in the first pass (discard is already in + * the code), then mask execution by using it the second pass. The last + * pass should be executed in all pixels. + * + * + * After this point you can choose to enable predicated thresholding, + * temporal supersampling and motion blur integration: + * + * a) If you want to use predicated thresholding, take a look into + * SMAA_PREDICATION; you'll need to pass an extra texture in the edge + * detection pass. + * + * b) If you want to enable temporal supersampling (SMAA T2x): + * + * 1. The first step is to render using subpixel jitters. I won't go into + * detail, but it's as simple as moving each vertex position in the + * vertex shader, you can check how we do it in our DX10 demo. + * + * 2. Then, you must setup the temporal resolve. You may want to take a look + * into SMAAResolve for resolving 2x modes. After you get it working, you'll + * probably see ghosting everywhere. But fear not, you can enable the + * CryENGINE temporal reprojection by setting the SMAA_REPROJECTION macro. + * Check out SMAA_DECODE_VELOCITY if your velocity buffer is encoded. + * + * 3. The next step is to apply SMAA to each subpixel jittered frame, just as + * done for 1x. + * + * 4. At this point you should already have something usable, but for best + * results the proper area textures must be set depending on current jitter. + * For this, the parameter 'subsampleIndices' of + * 'SMAABlendingWeightCalculationPS' must be set as follows, for our T2x + * mode: + * + * @SUBSAMPLE_INDICES + * + * | S# | Camera Jitter | subsampleIndices | + * +----+------------------+---------------------+ + * | 0 | ( 0.25, -0.25) | float4(1, 1, 1, 0) | + * | 1 | (-0.25, 0.25) | float4(2, 2, 2, 0) | + * + * These jitter positions assume a bottom-to-top y axis. S# stands for the + * sample number. + * + * More information about temporal supersampling here: + * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf + * + * c) If you want to enable spatial multisampling (SMAA S2x): + * + * 1. The scene must be rendered using MSAA 2x. The MSAA 2x buffer must be + * created with: + * - DX10: see below (*) + * - DX10.1: D3D10_STANDARD_MULTISAMPLE_PATTERN or + * - DX11: D3D11_STANDARD_MULTISAMPLE_PATTERN + * + * This allows to ensure that the subsample order matches the table in + * @SUBSAMPLE_INDICES. + * + * (*) In the case of DX10, we refer the reader to: + * - SMAA::detectMSAAOrder and + * - SMAA::msaaReorder + * + * These functions allow to match the standard multisample patterns by + * detecting the subsample order for a specific GPU, and reordering + * them appropriately. + * + * 2. A shader must be run to output each subsample into a separate buffer + * (DX10 is required). You can use SMAASeparate for this purpose, or just do + * it in an existing pass (for example, in the tone mapping pass, which has + * the advantage of feeding tone mapped subsamples to SMAA, which will yield + * better results). + * + * 3. The full SMAA 1x pipeline must be run for each separated buffer, storing + * the results in the final buffer. The second run should alpha blend with + * the existing final buffer using a blending factor of 0.5. + * 'subsampleIndices' must be adjusted as in the SMAA T2x case (see point + * b). + * + * d) If you want to enable temporal supersampling on top of SMAA S2x + * (which actually is SMAA 4x): + * + * 1. SMAA 4x consists on temporally jittering SMAA S2x, so the first step is + * to calculate SMAA S2x for current frame. In this case, 'subsampleIndices' + * must be set as follows: + * + * | F# | S# | Camera Jitter | Net Jitter | subsampleIndices | + * +----+----+--------------------+-------------------+----------------------+ + * | 0 | 0 | ( 0.125, 0.125) | ( 0.375, -0.125) | float4(5, 3, 1, 3) | + * | 0 | 1 | ( 0.125, 0.125) | (-0.125, 0.375) | float4(4, 6, 2, 3) | + * +----+----+--------------------+-------------------+----------------------+ + * | 1 | 2 | (-0.125, -0.125) | ( 0.125, -0.375) | float4(3, 5, 1, 4) | + * | 1 | 3 | (-0.125, -0.125) | (-0.375, 0.125) | float4(6, 4, 2, 4) | + * + * These jitter positions assume a bottom-to-top y axis. F# stands for the + * frame number. S# stands for the sample number. + * + * 2. After calculating SMAA S2x for current frame (with the new subsample + * indices), previous frame must be reprojected as in SMAA T2x mode (see + * point b). + * + * e) If motion blur is used, you may want to do the edge detection pass + * together with motion blur. This has two advantages: + * + * 1. Pixels under heavy motion can be omitted from the edge detection process. + * For these pixels we can just store "no edge", as motion blur will take + * care of them. + * 2. The center pixel tap is reused. + * + * Note that in this case depth testing should be used instead of stenciling, + * as we have to write all the pixels in the motion blur pass. + * + * That's it! + */ + +//----------------------------------------------------------------------------- +// SMAA Presets + +/** + * Note that if you use one of these presets, the following configuration + * macros will be ignored if set in the "Configurable Defines" section. + */ + +#if defined(SMAA_PRESET_LOW) +#define SMAA_THRESHOLD 0.15 +#define SMAA_MAX_SEARCH_STEPS 4 +#define SMAA_DISABLE_DIAG_DETECTION +#define SMAA_DISABLE_CORNER_DETECTION +#elif defined(SMAA_PRESET_MEDIUM) +#define SMAA_THRESHOLD 0.1 +#define SMAA_MAX_SEARCH_STEPS 8 +#define SMAA_DISABLE_DIAG_DETECTION +#define SMAA_DISABLE_CORNER_DETECTION +#elif defined(SMAA_PRESET_HIGH) +#define SMAA_THRESHOLD 0.1 +#define SMAA_MAX_SEARCH_STEPS 16 +#define SMAA_MAX_SEARCH_STEPS_DIAG 8 +#define SMAA_CORNER_ROUNDING 25 +#elif defined(SMAA_PRESET_ULTRA) +#define SMAA_THRESHOLD 0.05 +#define SMAA_MAX_SEARCH_STEPS 32 +#define SMAA_MAX_SEARCH_STEPS_DIAG 16 +#define SMAA_CORNER_ROUNDING 25 +#endif + +//----------------------------------------------------------------------------- +// Configurable Defines + +/** + * SMAA_THRESHOLD specifies the threshold or sensitivity to edges. + * Lowering this value you will be able to detect more edges at the expense of + * performance. + * + * Range: [0, 0.5] + * 0.1 is a reasonable value, and allows to catch most visible edges. + * 0.05 is a rather overkill value, that allows to catch 'em all. + * + * If temporal supersampling is used, 0.2 could be a reasonable value, as low + * contrast edges are properly filtered by just 2x. + */ +#ifndef SMAA_THRESHOLD +#define SMAA_THRESHOLD 0.1 +#endif + +/** + * SMAA_DEPTH_THRESHOLD specifies the threshold for depth edge detection. + * + * Range: depends on the depth range of the scene. + */ +#ifndef SMAA_DEPTH_THRESHOLD +#define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD) +#endif + +/** + * SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the + * horizontal/vertical pattern searches, at each side of the pixel. + * + * In number of pixels, it's actually the double. So the maximum line length + * perfectly handled by, for example 16, is 64 (by perfectly, we meant that + * longer lines won't look as good, but still antialiased). + * + * Range: [0, 112] + */ +#ifndef SMAA_MAX_SEARCH_STEPS +#define SMAA_MAX_SEARCH_STEPS 16 +#endif + +/** + * SMAA_MAX_SEARCH_STEPS_DIAG specifies the maximum steps performed in the + * diagonal pattern searches, at each side of the pixel. In this case we jump + * one pixel at time, instead of two. + * + * Range: [0, 20] + * + * On high-end machines it is cheap (between a 0.8x and 0.9x slower for 16 + * steps), but it can have a significant impact on older machines. + * + * Define SMAA_DISABLE_DIAG_DETECTION to disable diagonal processing. + */ +#ifndef SMAA_MAX_SEARCH_STEPS_DIAG +#define SMAA_MAX_SEARCH_STEPS_DIAG 8 +#endif + +/** + * SMAA_CORNER_ROUNDING specifies how much sharp corners will be rounded. + * + * Range: [0, 100] + * + * Define SMAA_DISABLE_CORNER_DETECTION to disable corner processing. + */ +#ifndef SMAA_CORNER_ROUNDING +#define SMAA_CORNER_ROUNDING 25 +#endif + +/** + * If there is an neighbor edge that has SMAA_LOCAL_CONTRAST_FACTOR times + * bigger contrast than current edge, current edge will be discarded. + * + * This allows to eliminate spurious crossing edges, and is based on the fact + * that, if there is too much contrast in a direction, that will hide + * perceptually contrast in the other neighbors. + */ +#ifndef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR +#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0 +#endif + +/** + * Predicated thresholding allows to better preserve texture details and to + * improve performance, by decreasing the number of detected edges using an + * additional buffer like the light accumulation buffer, object ids or even the + * depth buffer (the depth buffer usage may be limited to indoor or short range + * scenes). + * + * It locally decreases the luma or color threshold if an edge is found in an + * additional buffer (so the global threshold can be higher). + * + * This method was developed by Playstation EDGE MLAA team, and used in + * Killzone 3, by using the light accumulation buffer. More information here: + * http://iryoku.com/aacourse/downloads/06-MLAA-on-PS3.pptx + */ +#ifndef SMAA_PREDICATION +#define SMAA_PREDICATION 0 +#endif + +/** + * Threshold to be used in the additional predication buffer. + * + * Range: depends on the input, so you'll have to find the magic number that + * works for you. + */ +#ifndef SMAA_PREDICATION_THRESHOLD +#define SMAA_PREDICATION_THRESHOLD 0.01 +#endif + +/** + * How much to scale the global threshold used for luma or color edge + * detection when using predication. + * + * Range: [1, 5] + */ +#ifndef SMAA_PREDICATION_SCALE +#define SMAA_PREDICATION_SCALE 2.0 +#endif + +/** + * How much to locally decrease the threshold. + * + * Range: [0, 1] + */ +#ifndef SMAA_PREDICATION_STRENGTH +#define SMAA_PREDICATION_STRENGTH 0.4 +#endif + +/** + * Temporal reprojection allows to remove ghosting artifacts when using + * temporal supersampling. We use the CryEngine 3 method which also introduces + * velocity weighting. This feature is of extreme importance for totally + * removing ghosting. More information here: + * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf + * + * Note that you'll need to setup a velocity buffer for enabling reprojection. + * For static geometry, saving the previous depth buffer is a viable + * alternative. + */ +#ifndef SMAA_REPROJECTION +#define SMAA_REPROJECTION 0 +#endif + +/** + * SMAA_REPROJECTION_WEIGHT_SCALE controls the velocity weighting. It allows to + * remove ghosting trails behind the moving object, which are not removed by + * just using reprojection. Using low values will exhibit ghosting, while using + * high values will disable temporal supersampling under motion. + * + * Behind the scenes, velocity weighting removes temporal supersampling when + * the velocity of the subsamples differs (meaning they are different objects). + * + * Range: [0, 80] + */ +#ifndef SMAA_REPROJECTION_WEIGHT_SCALE +#define SMAA_REPROJECTION_WEIGHT_SCALE 30.0 +#endif + +/** + * On some compilers, discard cannot be used in vertex shaders. Thus, they need + * to be compiled separately. + */ +#ifndef SMAA_INCLUDE_VS +#define SMAA_INCLUDE_VS 1 +#endif +#ifndef SMAA_INCLUDE_PS +#define SMAA_INCLUDE_PS 1 +#endif + +//----------------------------------------------------------------------------- +// Texture Access Defines + +#ifndef SMAA_AREATEX_SELECT +#if defined(SMAA_HLSL_3) +#define SMAA_AREATEX_SELECT(sample) sample.ra +#else +#define SMAA_AREATEX_SELECT(sample) sample.rg +#endif +#endif + +#ifndef SMAA_SEARCHTEX_SELECT +#define SMAA_SEARCHTEX_SELECT(sample) sample.r +#endif + +#ifndef SMAA_DECODE_VELOCITY +#define SMAA_DECODE_VELOCITY(sample) sample.rg +#endif + +//----------------------------------------------------------------------------- +// Non-Configurable Defines + +#define SMAA_AREATEX_MAX_DISTANCE 16 +#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20 +#define SMAA_AREATEX_PIXEL_SIZE (1.0 / float2(160.0, 560.0)) +#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0) +#define SMAA_SEARCHTEX_SIZE float2(66.0, 33.0) +#define SMAA_SEARCHTEX_PACKED_SIZE float2(64.0, 16.0) +#define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0) + +//----------------------------------------------------------------------------- +// Porting Functions + +#if defined(SMAA_HLSL_3) +#define SMAATexture2D(tex) sampler2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0)) +#define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0)) +#define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0)) +#define SMAASample(tex, coord) tex2D(tex, coord) +#define SMAASamplePoint(tex, coord) tex2D(tex, coord) +#define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy) +#define SMAA_FLATTEN [flatten] +#define SMAA_BRANCH [branch] +#endif +#if defined(SMAA_HLSL_4) || defined(SMAA_HLSL_4_1) +SamplerState LinearSampler { Filter = MIN_MAG_LINEAR_MIP_POINT; AddressU = Clamp; AddressV = Clamp; }; +SamplerState PointSampler { Filter = MIN_MAG_MIP_POINT; AddressU = Clamp; AddressV = Clamp; }; +#define SMAATexture2D(tex) Texture2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) tex.SampleLevel(LinearSampler, coord, 0) +#define SMAASampleLevelZeroPoint(tex, coord) tex.SampleLevel(PointSampler, coord, 0) +#define SMAASampleLevelZeroOffset(tex, coord, offset) tex.SampleLevel(LinearSampler, coord, 0, offset) +#define SMAASample(tex, coord) tex.Sample(LinearSampler, coord) +#define SMAASamplePoint(tex, coord) tex.Sample(PointSampler, coord) +#define SMAASampleOffset(tex, coord, offset) tex.Sample(LinearSampler, coord, offset) +#define SMAA_FLATTEN [flatten] +#define SMAA_BRANCH [branch] +#define SMAATexture2DMS2(tex) Texture2DMS tex +#define SMAALoad(tex, pos, sample) tex.Load(pos, sample) +#if defined(SMAA_HLSL_4_1) +#define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0) +#endif +#endif +#if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4) +#define SMAATexture2D(tex) sampler2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) +#define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0) +#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset) +#define SMAASample(tex, coord) texture(tex, coord) +#define SMAASamplePoint(tex, coord) texture(tex, coord) +#define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset) +#define SMAA_FLATTEN +#define SMAA_BRANCH +#define lerp(a, b, t) mix(a, b, t) +#define saturate(a) clamp(a, 0.0, 1.0) +#if defined(SMAA_GLSL_4) +#define mad(a, b, c) fma(a, b, c) +#define SMAAGather(tex, coord) textureGather(tex, coord) +#else +#define mad(a, b, c) (a * b + c) +#endif +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#endif + +#if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL) +#error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL +#endif + +//----------------------------------------------------------------------------- +// Misc functions + +/** + * Gathers current pixel, and the top-left neighbors. + */ +float3 SMAAGatherNeighbours(float2 texcoord, + float4 offset[3], + SMAATexture2D(tex)) { + #ifdef SMAAGather + return SMAAGather(tex, texcoord + SMAA_RT_METRICS.xy * float2(-0.5, -0.5)).grb; + #else + float P = SMAASamplePoint(tex, texcoord).r; + float Pleft = SMAASamplePoint(tex, offset[0].xy).r; + float Ptop = SMAASamplePoint(tex, offset[0].zw).r; + return float3(P, Pleft, Ptop); + #endif +} + +/** + * Adjusts the threshold by means of predication. + */ +float2 SMAACalculatePredicatedThreshold(float2 texcoord, + float4 offset[3], + SMAATexture2D(predicationTex)) { + float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(predicationTex)); + float2 delta = abs(neighbours.xx - neighbours.yz); + float2 edges = step(SMAA_PREDICATION_THRESHOLD, delta); + return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges); +} + +/** + * Conditional move: + */ +void SMAAMovc(bool2 cond, inout float2 variable, float2 value) { + SMAA_FLATTEN if (cond.x) variable.x = value.x; + SMAA_FLATTEN if (cond.y) variable.y = value.y; +} + +void SMAAMovc(bool4 cond, inout float4 variable, float4 value) { + SMAAMovc(cond.xy, variable.xy, value.xy); + SMAAMovc(cond.zw, variable.zw, value.zw); +} + + +#if SMAA_INCLUDE_VS +//----------------------------------------------------------------------------- +// Vertex Shaders + +/** + * Edge Detection Vertex Shader + */ +void SMAAEdgeDetectionVS(float2 texcoord, + out float4 offset[3]) { + offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy); + offset[1] = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); + offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy); +} + +/** + * Blend Weight Calculation Vertex Shader + */ +void SMAABlendingWeightCalculationVS(float2 texcoord, + out float2 pixcoord, + out float4 offset[3]) { + pixcoord = texcoord * SMAA_RT_METRICS.zw; + + // We will use these offsets for the searches later on (see @PSEUDO_GATHER4): + offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy); + offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy); + + // And these for the searches, they indicate the ends of the loops: + offset[2] = mad(SMAA_RT_METRICS.xxyy, + float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS), + float4(offset[0].xz, offset[1].yw)); +} + +/** + * Neighborhood Blending Vertex Shader + */ +void SMAANeighborhoodBlendingVS(float2 texcoord, + out float4 offset) { + offset = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); +} +#endif // SMAA_INCLUDE_VS + +#if SMAA_INCLUDE_PS +//----------------------------------------------------------------------------- +// Edge Detection Pixel Shaders (First Pass) + +/** + * Luma Edge Detection + * + * IMPORTANT NOTICE: luma edge detection requires gamma-corrected colors, and + * thus 'colorTex' should be a non-sRGB texture. + */ +float2 SMAALumaEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(colorTex) + #if SMAA_PREDICATION + , SMAATexture2D(predicationTex) + #endif + ) { + // Calculate the threshold: + #if SMAA_PREDICATION + float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, SMAATexturePass2D(predicationTex)); + #else + float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD); + #endif + + // Calculate lumas: + float3 weights = float3(0.2126, 0.7152, 0.0722); + float L = dot(SMAASamplePoint(colorTex, texcoord).rgb, weights); + + float Lleft = dot(SMAASamplePoint(colorTex, offset[0].xy).rgb, weights); + float Ltop = dot(SMAASamplePoint(colorTex, offset[0].zw).rgb, weights); + + // We do the usual threshold: + float4 delta; + delta.xy = abs(L - float2(Lleft, Ltop)); + float2 edges = step(threshold, delta.xy); + + // Then discard if there is no edge: + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + // Calculate right and bottom deltas: + float Lright = dot(SMAASamplePoint(colorTex, offset[1].xy).rgb, weights); + float Lbottom = dot(SMAASamplePoint(colorTex, offset[1].zw).rgb, weights); + delta.zw = abs(L - float2(Lright, Lbottom)); + + // Calculate the maximum delta in the direct neighborhood: + float2 maxDelta = max(delta.xy, delta.zw); + + // Calculate left-left and top-top deltas: + float Lleftleft = dot(SMAASamplePoint(colorTex, offset[2].xy).rgb, weights); + float Ltoptop = dot(SMAASamplePoint(colorTex, offset[2].zw).rgb, weights); + delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop)); + + // Calculate the final maximum delta: + maxDelta = max(maxDelta.xy, delta.zw); + float finalDelta = max(maxDelta.x, maxDelta.y); + + // Local contrast adaptation: + edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); + + return edges; +} + +/** + * Color Edge Detection + * + * IMPORTANT NOTICE: color edge detection requires gamma-corrected colors, and + * thus 'colorTex' should be a non-sRGB texture. + */ +float2 SMAAColorEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(colorTex) + #if SMAA_PREDICATION + , SMAATexture2D(predicationTex) + #endif + ) { + // Calculate the threshold: + #if SMAA_PREDICATION + float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex); + #else + float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD); + #endif + + // Calculate color deltas: + float4 delta; + float3 C = SMAASamplePoint(colorTex, texcoord).rgb; + + float3 Cleft = SMAASamplePoint(colorTex, offset[0].xy).rgb; + float3 t = abs(C - Cleft); + delta.x = max(max(t.r, t.g), t.b); + + float3 Ctop = SMAASamplePoint(colorTex, offset[0].zw).rgb; + t = abs(C - Ctop); + delta.y = max(max(t.r, t.g), t.b); + + // We do the usual threshold: + float2 edges = step(threshold, delta.xy); + + // Then discard if there is no edge: + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + // Calculate right and bottom deltas: + float3 Cright = SMAASamplePoint(colorTex, offset[1].xy).rgb; + t = abs(C - Cright); + delta.z = max(max(t.r, t.g), t.b); + + float3 Cbottom = SMAASamplePoint(colorTex, offset[1].zw).rgb; + t = abs(C - Cbottom); + delta.w = max(max(t.r, t.g), t.b); + + // Calculate the maximum delta in the direct neighborhood: + float2 maxDelta = max(delta.xy, delta.zw); + + // Calculate left-left and top-top deltas: + float3 Cleftleft = SMAASamplePoint(colorTex, offset[2].xy).rgb; + t = abs(C - Cleftleft); + delta.z = max(max(t.r, t.g), t.b); + + float3 Ctoptop = SMAASamplePoint(colorTex, offset[2].zw).rgb; + t = abs(C - Ctoptop); + delta.w = max(max(t.r, t.g), t.b); + + // Calculate the final maximum delta: + maxDelta = max(maxDelta.xy, delta.zw); + float finalDelta = max(maxDelta.x, maxDelta.y); + + // Local contrast adaptation: + edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); + + return edges; +} + +/** + * Depth Edge Detection + */ +float2 SMAADepthEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(depthTex)) { + float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(depthTex)); + float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z)); + float2 edges = step(SMAA_DEPTH_THRESHOLD, delta); + + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + return edges; +} + +//----------------------------------------------------------------------------- +// Diagonal Search Functions + +#if !defined(SMAA_DISABLE_DIAG_DETECTION) + +/** + * Allows to decode two binary values from a bilinear-filtered access. + */ +float2 SMAADecodeDiagBilinearAccess(float2 e) { + // Bilinear access for fetching 'e' have a 0.25 offset, and we are + // interested in the R and G edges: + // + // +---G---+-------+ + // | x o R x | + // +-------+-------+ + // + // Then, if one of these edge is enabled: + // Red: (0.75 * X + 0.25 * 1) => 0.25 or 1.0 + // Green: (0.75 * 1 + 0.25 * X) => 0.75 or 1.0 + // + // This function will unpack the values (mad + mul + round): + // wolframalpha.com: round(x * abs(5 * x - 5 * 0.75)) plot 0 to 1 + e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75); + return round(e); +} + +float4 SMAADecodeDiagBilinearAccess(float4 e) { + e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75); + return round(e); +} + +/** + * These functions allows to perform diagonal pattern searches. + */ +float2 SMAASearchDiag1(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) { + float4 coord = float4(texcoord, -1.0, 1.0); + float3 t = float3(SMAA_RT_METRICS.xy, 1.0); + while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && + coord.w > 0.9) { + coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); + e = SMAASampleLevelZero(edgesTex, coord.xy).rg; + coord.w = dot(e, float2(0.5, 0.5)); + } + return coord.zw; +} + +float2 SMAASearchDiag2(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) { + float4 coord = float4(texcoord, -1.0, 1.0); + coord.x += 0.25 * SMAA_RT_METRICS.x; // See @SearchDiag2Optimization + float3 t = float3(SMAA_RT_METRICS.xy, 1.0); + while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && + coord.w > 0.9) { + coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); + + // @SearchDiag2Optimization + // Fetch both edges at once using bilinear filtering: + e = SMAASampleLevelZero(edgesTex, coord.xy).rg; + e = SMAADecodeDiagBilinearAccess(e); + + // Non-optimized version: + // e.g = SMAASampleLevelZero(edgesTex, coord.xy).g; + // e.r = SMAASampleLevelZeroOffset(edgesTex, coord.xy, int2(1, 0)).r; + + coord.w = dot(e, float2(0.5, 0.5)); + } + return coord.zw; +} + +/** + * Similar to SMAAArea, this calculates the area corresponding to a certain + * diagonal distance and crossing edges 'e'. + */ +float2 SMAAAreaDiag(SMAATexture2D(areaTex), float2 dist, float2 e, float offset) { + float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist); + + // We do a scale and bias for mapping to texel space: + texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE); + + // Diagonal areas are on the second half of the texture: + texcoord.x += 0.5; + + // Move to proper place, according to the subpixel offset: + texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset; + + // Do it! + return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord)); +} + +/** + * This searches for diagonal patterns and returns the corresponding weights. + */ +float2 SMAACalculateDiagWeights(SMAATexture2D(edgesTex), SMAATexture2D(areaTex), float2 texcoord, float2 e, float4 subsampleIndices) { + float2 weights = float2(0.0, 0.0); + + // Search for the line ends: + float4 d; + float2 end; + if (e.r > 0.0) { + d.xz = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, 1.0), end); + d.x += float(end.y > 0.9); + } else + d.xz = float2(0.0, 0.0); + d.yw = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, -1.0), end); + + SMAA_BRANCH + if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3 + // Fetch the crossing edges: + float4 coords = mad(float4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + float4 c; + c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).rg; + c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).rg; + c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw); + + // Non-optimized version: + // float4 coords = mad(float4(-d.x, d.x, d.y, -d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + // float4 c; + // c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g; + // c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, 0)).r; + // c.z = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).g; + // c.w = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, -1)).r; + + // Merge crossing edges at each side into a single value: + float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw); + + // Remove the crossing edge if we didn't found the end of the line: + SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0)); + + // Fetch the areas for this line: + weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.z); + } + + // Search for the line ends: + d.xz = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, -1.0), end); + if (SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r > 0.0) { + d.yw = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, 1.0), end); + d.y += float(end.y > 0.9); + } else + d.yw = float2(0.0, 0.0); + + SMAA_BRANCH + if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3 + // Fetch the crossing edges: + float4 coords = mad(float4(-d.x, -d.x, d.y, d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + float4 c; + c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g; + c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, -1)).r; + c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).gr; + float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw); + + // Remove the crossing edge if we didn't found the end of the line: + SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0)); + + // Fetch the areas for this line: + weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.w).gr; + } + + return weights; +} +#endif + +//----------------------------------------------------------------------------- +// Horizontal/Vertical Search Functions + +/** + * This allows to determine how much length should we add in the last step + * of the searches. It takes the bilinearly interpolated edge (see + * @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and + * crossing edges are active. + */ +float SMAASearchLength(SMAATexture2D(searchTex), float2 e, float offset) { + // The texture is flipped vertically, with left and right cases taking half + // of the space horizontally: + float2 scale = SMAA_SEARCHTEX_SIZE * float2(0.5, -1.0); + float2 bias = SMAA_SEARCHTEX_SIZE * float2(offset, 1.0); + + // Scale and bias to access texel centers: + scale += float2(-1.0, 1.0); + bias += float2( 0.5, -0.5); + + // Convert from pixel coordinates to texcoords: + // (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped) + scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; + bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; + + // Lookup the search texture: + return SMAA_SEARCHTEX_SELECT(SMAASampleLevelZero(searchTex, mad(scale, e, bias))); +} + +/** + * Horizontal/vertical search functions for the 2nd pass. + */ +float SMAASearchXLeft(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + /** + * @PSEUDO_GATHER4 + * This texcoord has been offset by (-0.25, -0.125) in the vertex shader to + * sample between edge, thus fetching four edges in a row. + * Sampling with different offsets in each direction allows to disambiguate + * which edges are active from the four fetched ones. + */ + float2 e = float2(0.0, 1.0); + while (texcoord.x > end && + e.g > 0.8281 && // Is there some edge not activated? + e.r == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(-float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); + } + + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0), 3.25); + return mad(SMAA_RT_METRICS.x, offset, texcoord.x); + + // Non-optimized version: + // We correct the previous (-0.25, -0.125) offset we applied: + // texcoord.x += 0.25 * SMAA_RT_METRICS.x; + + // The searches are bias by 1, so adjust the coords accordingly: + // texcoord.x += SMAA_RT_METRICS.x; + + // Disambiguate the length added by the last step: + // texcoord.x += 2.0 * SMAA_RT_METRICS.x; // Undo last step + // texcoord.x -= SMAA_RT_METRICS.x * (255.0 / 127.0) * SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0); + // return mad(SMAA_RT_METRICS.x, offset, texcoord.x); +} + +float SMAASearchXRight(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(0.0, 1.0); + while (texcoord.x < end && + e.g > 0.8281 && // Is there some edge not activated? + e.r == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.5), 3.25); + return mad(-SMAA_RT_METRICS.x, offset, texcoord.x); +} + +float SMAASearchYUp(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(1.0, 0.0); + while (texcoord.y > end && + e.r > 0.8281 && // Is there some edge not activated? + e.g == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(-float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.0), 3.25); + return mad(SMAA_RT_METRICS.y, offset, texcoord.y); +} + +float SMAASearchYDown(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(1.0, 0.0); + while (texcoord.y < end && + e.r > 0.8281 && // Is there some edge not activated? + e.g == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.5), 3.25); + return mad(-SMAA_RT_METRICS.y, offset, texcoord.y); +} + +/** + * Ok, we have the distance and both crossing edges. So, what are the areas + * at each side of current edge? + */ +float2 SMAAArea(SMAATexture2D(areaTex), float2 dist, float e1, float e2, float offset) { + // Rounding prevents precision errors of bilinear filtering: + float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * float2(e1, e2)), dist); + + // We do a scale and bias for mapping to texel space: + texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE); + + // Move to proper place, according to the subpixel offset: + texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y); + + // Do it! + return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord)); +} + +//----------------------------------------------------------------------------- +// Corner Detection Functions + +void SMAADetectHorizontalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) { + #if !defined(SMAA_DISABLE_CORNER_DETECTION) + float2 leftRight = step(d.xy, d.yx); + float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; + + rounding /= leftRight.x + leftRight.y; // Reduce blending for pixels in the center of a line. + + float2 factor = float2(1.0, 1.0); + factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, 1)).r; + factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, 1)).r; + factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, -2)).r; + factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, -2)).r; + + weights *= saturate(factor); + #endif +} + +void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) { + #if !defined(SMAA_DISABLE_CORNER_DETECTION) + float2 leftRight = step(d.xy, d.yx); + float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; + + rounding /= leftRight.x + leftRight.y; + + float2 factor = float2(1.0, 1.0); + factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2( 1, 0)).g; + factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2( 1, 1)).g; + factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(-2, 0)).g; + factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(-2, 1)).g; + + weights *= saturate(factor); + #endif +} + +//----------------------------------------------------------------------------- +// Blending Weight Calculation Pixel Shader (Second Pass) + +float4 SMAABlendingWeightCalculationPS(float2 texcoord, + float2 pixcoord, + float4 offset[3], + SMAATexture2D(edgesTex), + SMAATexture2D(areaTex), + SMAATexture2D(searchTex), + float4 subsampleIndices) { // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES. + float4 weights = float4(0.0, 0.0, 0.0, 0.0); + + float2 e = SMAASample(edgesTex, texcoord).rg; + + SMAA_BRANCH + if (e.g > 0.0) { // Edge at north + #if !defined(SMAA_DISABLE_DIAG_DETECTION) + // Diagonals have both north and west edges, so searching for them in + // one of the boundaries is enough. + weights.rg = SMAACalculateDiagWeights(SMAATexturePass2D(edgesTex), SMAATexturePass2D(areaTex), texcoord, e, subsampleIndices); + + // We give priority to diagonals, so if we find a diagonal we skip + // horizontal/vertical processing. + SMAA_BRANCH + if (weights.r == -weights.g) { // weights.r + weights.g == 0.0 + #endif + + float2 d; + + // Find the distance to the left: + float3 coords; + coords.x = SMAASearchXLeft(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].xy, offset[2].x); + coords.y = offset[1].y; // offset[1].y = texcoord.y - 0.25 * SMAA_RT_METRICS.y (@CROSSING_OFFSET) + d.x = coords.x; + + // Now fetch the left crossing edges, two at a time using bilinear + // filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to + // discern what value each edge has: + float e1 = SMAASampleLevelZero(edgesTex, coords.xy).r; + + // Find the distance to the right: + coords.z = SMAASearchXRight(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].zw, offset[2].y); + d.y = coords.z; + + // We want the distances to be in pixel units (doing this here allow to + // better interleave arithmetic and memory accesses): + d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx))); + + // SMAAArea below needs a sqrt, as the areas texture is compressed + // quadratically: + float2 sqrt_d = sqrt(d); + + // Fetch the right crossing edges: + float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, int2(1, 0)).r; + + // Ok, we know how this pattern looks like, now it is time for getting + // the actual area: + weights.rg = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.y); + + // Fix corners: + coords.y = texcoord.y; + SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d); + + #if !defined(SMAA_DISABLE_DIAG_DETECTION) + } else + e.r = 0.0; // Skip vertical processing. + #endif + } + + SMAA_BRANCH + if (e.r > 0.0) { // Edge at west + float2 d; + + // Find the distance to the top: + float3 coords; + coords.y = SMAASearchYUp(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].xy, offset[2].z); + coords.x = offset[0].x; // offset[1].x = texcoord.x - 0.25 * SMAA_RT_METRICS.x; + d.x = coords.y; + + // Fetch the top crossing edges: + float e1 = SMAASampleLevelZero(edgesTex, coords.xy).g; + + // Find the distance to the bottom: + coords.z = SMAASearchYDown(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].zw, offset[2].w); + d.y = coords.z; + + // We want the distances to be in pixel units: + d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy))); + + // SMAAArea below needs a sqrt, as the areas texture is compressed + // quadratically: + float2 sqrt_d = sqrt(d); + + // Fetch the bottom crossing edges: + float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g; + + // Get the area for this direction: + weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x); + + // Fix corners: + coords.x = texcoord.x; + SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d); + } + + return weights; +} + +//----------------------------------------------------------------------------- +// Neighborhood Blending Pixel Shader (Third Pass) + +float4 SMAANeighborhoodBlendingPS(float2 texcoord, + float4 offset, + SMAATexture2D(colorTex), + SMAATexture2D(blendTex) + #if SMAA_REPROJECTION + , SMAATexture2D(velocityTex) + #endif + ) { + // Fetch the blending weights for current pixel: + float4 a; + a.x = SMAASample(blendTex, offset.xy).a; // Right + a.y = SMAASample(blendTex, offset.zw).g; // Top + a.wz = SMAASample(blendTex, texcoord).xz; // Bottom / Left + + // Is there any blending weight with a value greater than 0.0? + SMAA_BRANCH + if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5) { + float4 color = SMAASampleLevelZero(colorTex, texcoord); + + #if SMAA_REPROJECTION + float2 velocity = SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, texcoord)); + + // Pack velocity into the alpha channel: + color.a = sqrt(5.0 * length(velocity)); + #endif + + return color; + } else { + bool h = max(a.x, a.z) > max(a.y, a.w); // max(horizontal) > max(vertical) + + // Calculate the blending offsets: + float4 blendingOffset = float4(0.0, a.y, 0.0, a.w); + float2 blendingWeight = a.yw; + SMAAMovc(bool4(h, h, h, h), blendingOffset, float4(a.x, 0.0, a.z, 0.0)); + SMAAMovc(bool2(h, h), blendingWeight, a.xz); + blendingWeight /= dot(blendingWeight, float2(1.0, 1.0)); + + // Calculate the texture coordinates: + float4 blendingCoord = mad(blendingOffset, float4(SMAA_RT_METRICS.xy, -SMAA_RT_METRICS.xy), texcoord.xyxy); + + // We exploit bilinear filtering to mix current pixel with the chosen + // neighbor: + float4 color = blendingWeight.x * SMAASampleLevelZero(colorTex, blendingCoord.xy); + color += blendingWeight.y * SMAASampleLevelZero(colorTex, blendingCoord.zw); + + #if SMAA_REPROJECTION + // Antialias velocity for proper reprojection in a later stage: + float2 velocity = blendingWeight.x * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.xy)); + velocity += blendingWeight.y * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.zw)); + + // Pack velocity into the alpha channel: + color.a = sqrt(5.0 * length(velocity)); + #endif + + return color; + } +} + +//----------------------------------------------------------------------------- +// Temporal Resolve Pixel Shader (Optional Pass) + +float4 SMAAResolvePS(float2 texcoord, + SMAATexture2D(currentColorTex), + SMAATexture2D(previousColorTex) + #if SMAA_REPROJECTION + , SMAATexture2D(velocityTex) + #endif + ) { + #if SMAA_REPROJECTION + // Velocity is assumed to be calculated for motion blur, so we need to + // inverse it for reprojection: + float2 velocity = -SMAA_DECODE_VELOCITY(SMAASamplePoint(velocityTex, texcoord).rg); + + // Fetch current pixel: + float4 current = SMAASamplePoint(currentColorTex, texcoord); + + // Reproject current coordinates and fetch previous pixel: + float4 previous = SMAASamplePoint(previousColorTex, texcoord + velocity); + + // Attenuate the previous pixel if the velocity is different: + float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0; + float weight = 0.5 * saturate(1.0 - sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE); + + // Blend the pixels according to the calculated weight: + return lerp(current, previous, weight); + #else + // Just blend the pixels: + float4 current = SMAASamplePoint(currentColorTex, texcoord); + float4 previous = SMAASamplePoint(previousColorTex, texcoord); + return lerp(current, previous, 0.5); + #endif +} + +//----------------------------------------------------------------------------- +// Separate Multisamples Pixel Shader (Optional Pass) + +#ifdef SMAALoad +void SMAASeparatePS(float4 position, + float2 texcoord, + out float4 target0, + out float4 target1, + SMAATexture2DMS2(colorTexMS)) { + int2 pos = int2(position.xy); + target0 = SMAALoad(colorTexMS, pos, 0); + target1 = SMAALoad(colorTexMS, pos, 1); +} +#endif + +//----------------------------------------------------------------------------- +#endif // SMAA_INCLUDE_PS diff --git a/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt b/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt index 761743c464..ffbc6b370b 100644 --- a/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt +++ b/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt @@ -124,3 +124,33 @@ 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. diff --git a/app/src/main/cpp/shaders/cas_ffx.frag b/app/src/main/cpp/shaders/cas_ffx.frag index 9e0b68a1f4..fff26a9fcf 100644 --- a/app/src/main/cpp/shaders/cas_ffx.frag +++ b/app/src/main/cpp/shaders/cas_ffx.frag @@ -39,7 +39,7 @@ // - Same push constants as cas.frag: ndc, input size, sharpness [0..1]. // CasSetup's const1.x = -1 / lerp(8, 5, sharpness) is computed here. // - The input is the effect chain's previous target at the same size, so the -// output pixel reads the input pixel 1:1 (texelFetch, edges clamped). +// output pixel reads the input pixel 1:1 (texel centres, edges clamped). // ============================================================================= // DD_HALF is set for the *_half_frag.h build (gen_shaders.sh): colour and @@ -64,8 +64,8 @@ layout(location = 0) in highp vec2 fragTexCoord; layout(location = 0) out vec4 outColor; vec3 CasLoad(ivec2 p) { - ivec2 sz = textureSize(InputTexture, 0); - return texelFetch(InputTexture, clamp(p, ivec2(0), sz - ivec2(1)), 0).rgb; + highp vec2 uv = (vec2(p) + 0.5) / pc.resolution; + return textureLod(InputTexture, uv, 0.0).rgb; } float AMin3F1(float x, float y, float z) { return min(x, min(y, z)); } diff --git a/app/src/main/cpp/shaders/cas_ffx_half_frag.h b/app/src/main/cpp/shaders/cas_ffx_half_frag.h index 22fbf6119b..2ba56158cc 100644 --- a/app/src/main/cpp/shaders/cas_ffx_half_frag.h +++ b/app/src/main/cpp/shaders/cas_ffx_half_frag.h @@ -1,214 +1,213 @@ - // 1116.2.0 + // 1115.1.0 #pragma once const uint32_t cas_ffx_half_code[] = { - 0x07230203,0x00010000,0x0008000b,0x000000d7,0x00000000,0x00020011,0x00000001,0x00020011, - 0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e, - 0x00000000,0x00000001,0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000043, - 0x000000d1,0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005, - 0x00000004,0x6e69616d,0x00000000,0x00060005,0x0000000d,0x4c736143,0x2864616f,0x3b326976, - 0x00000000,0x00030005,0x0000000c,0x00000070,0x00070005,0x00000014,0x6e694d41,0x28314633, - 0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000011,0x00000078,0x00030005,0x00000012, - 0x00000079,0x00030005,0x00000013,0x0000007a,0x00070005,0x00000019,0x78614d41,0x28314633, - 0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000016,0x00000078,0x00030005,0x00000017, - 0x00000079,0x00030005,0x00000018,0x0000007a,0x00030005,0x0000001b,0x00007a73,0x00060005, - 0x0000001f,0x75706e49,0x78655474,0x65727574,0x00000000,0x00030005,0x00000040,0x00007073, - 0x00060005,0x00000043,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x00000045, - 0x00004350,0x00040006,0x00000045,0x00000000,0x0063646e,0x00060006,0x00000045,0x00000001, - 0x6f736572,0x6974756c,0x00006e6f,0x00060006,0x00000045,0x00000002,0x72616873,0x73656e70, - 0x00000073,0x00030005,0x00000047,0x00006370,0x00040005,0x0000004d,0x6b616570,0x00000000, - 0x00030005,0x0000005b,0x00000062,0x00040005,0x00000060,0x61726170,0x0000006d,0x00030005, - 0x00000062,0x00000064,0x00040005,0x00000066,0x61726170,0x0000006d,0x00030005,0x00000068, - 0x00000065,0x00040005,0x00000069,0x61726170,0x0000006d,0x00030005,0x0000006c,0x00000066, - 0x00040005,0x00000070,0x61726170,0x0000006d,0x00030005,0x00000072,0x00000068,0x00040005, - 0x00000076,0x61726170,0x0000006d,0x00030005,0x00000078,0x00476e6d,0x00040005,0x00000079, - 0x61726170,0x0000006d,0x00040005,0x0000007e,0x61726170,0x0000006d,0x00040005,0x00000081, - 0x61726170,0x0000006d,0x00040005,0x00000085,0x61726170,0x0000006d,0x00040005,0x00000086, - 0x61726170,0x0000006d,0x00040005,0x00000089,0x61726170,0x0000006d,0x00030005,0x0000008d, - 0x0047786d,0x00040005,0x0000008e,0x61726170,0x0000006d,0x00040005,0x00000091,0x61726170, - 0x0000006d,0x00040005,0x00000094,0x61726170,0x0000006d,0x00040005,0x00000098,0x61726170, - 0x0000006d,0x00040005,0x00000099,0x61726170,0x0000006d,0x00040005,0x0000009c,0x61726170, - 0x0000006d,0x00040005,0x000000a0,0x4d706372,0x00000047,0x00040005,0x000000a5,0x47706d61, - 0x00000000,0x00030005,0x000000af,0x00004777,0x00050005,0x000000b3,0x57706372,0x68676965, - 0x00000074,0x00030005,0x000000b9,0x00786970,0x00050005,0x000000d1,0x4374756f,0x726f6c6f, - 0x00000000,0x00030047,0x0000000d,0x00000000,0x00030047,0x00000011,0x00000000,0x00030047, - 0x00000012,0x00000000,0x00030047,0x00000013,0x00000000,0x00030047,0x00000014,0x00000000, - 0x00030047,0x00000016,0x00000000,0x00030047,0x00000017,0x00000000,0x00030047,0x00000018, - 0x00000000,0x00030047,0x00000019,0x00000000,0x00030047,0x0000001f,0x00000000,0x00040047, - 0x0000001f,0x00000021,0x00000000,0x00040047,0x0000001f,0x00000022,0x00000000,0x00030047, - 0x00000020,0x00000000,0x00030047,0x00000024,0x00000000,0x00030047,0x0000002e,0x00000000, - 0x00030047,0x0000002f,0x00000000,0x00030047,0x00000032,0x00000000,0x00030047,0x00000033, - 0x00000000,0x00030047,0x00000034,0x00000000,0x00030047,0x00000035,0x00000000,0x00030047, - 0x00000036,0x00000000,0x00030047,0x00000039,0x00000000,0x00030047,0x0000003a,0x00000000, - 0x00030047,0x0000003b,0x00000000,0x00030047,0x0000003c,0x00000000,0x00030047,0x0000003d, - 0x00000000,0x00040047,0x00000043,0x0000001e,0x00000000,0x00030047,0x00000045,0x00000002, - 0x00050048,0x00000045,0x00000000,0x00000023,0x00000000,0x00050048,0x00000045,0x00000001, - 0x00000023,0x00000010,0x00040048,0x00000045,0x00000002,0x00000000,0x00050048,0x00000045, - 0x00000002,0x00000023,0x00000018,0x00030047,0x0000004d,0x00000000,0x00030047,0x00000054, - 0x00000000,0x00030047,0x00000057,0x00000000,0x00030047,0x00000058,0x00000000,0x00030047, - 0x00000059,0x00000000,0x00030047,0x0000005b,0x00000000,0x00030047,0x00000061,0x00000000, - 0x00030047,0x00000062,0x00000000,0x00030047,0x00000067,0x00000000,0x00030047,0x00000068, - 0x00000000,0x00030047,0x0000006b,0x00000000,0x00030047,0x0000006c,0x00000000,0x00030047, - 0x00000071,0x00000000,0x00030047,0x00000072,0x00000000,0x00030047,0x00000077,0x00000000, - 0x00030047,0x00000078,0x00000000,0x00030047,0x00000079,0x00000000,0x00030047,0x0000007d, - 0x00000000,0x00030047,0x0000007e,0x00000000,0x00030047,0x00000080,0x00000000,0x00030047, - 0x00000081,0x00000000,0x00030047,0x00000083,0x00000000,0x00030047,0x00000084,0x00000000, - 0x00030047,0x00000085,0x00000000,0x00030047,0x00000086,0x00000000,0x00030047,0x00000088, - 0x00000000,0x00030047,0x00000089,0x00000000,0x00030047,0x0000008b,0x00000000,0x00030047, - 0x0000008c,0x00000000,0x00030047,0x0000008d,0x00000000,0x00030047,0x0000008e,0x00000000, - 0x00030047,0x00000090,0x00000000,0x00030047,0x00000091,0x00000000,0x00030047,0x00000093, - 0x00000000,0x00030047,0x00000094,0x00000000,0x00030047,0x00000096,0x00000000,0x00030047, - 0x00000097,0x00000000,0x00030047,0x00000098,0x00000000,0x00030047,0x00000099,0x00000000, - 0x00030047,0x0000009b,0x00000000,0x00030047,0x0000009c,0x00000000,0x00030047,0x0000009e, - 0x00000000,0x00030047,0x0000009f,0x00000000,0x00030047,0x000000a0,0x00000000,0x00030047, - 0x000000a1,0x00000000,0x00030047,0x000000a3,0x00000000,0x00030047,0x000000a4,0x00000000, - 0x00030047,0x000000a5,0x00000000,0x00030047,0x000000a6,0x00000000,0x00030047,0x000000a7, - 0x00000000,0x00030047,0x000000a8,0x00000000,0x00030047,0x000000a9,0x00000000,0x00030047, - 0x000000aa,0x00000000,0x00030047,0x000000ab,0x00000000,0x00030047,0x000000ac,0x00000000, - 0x00030047,0x000000ad,0x00000000,0x00030047,0x000000ae,0x00000000,0x00030047,0x000000af, - 0x00000000,0x00030047,0x000000b0,0x00000000,0x00030047,0x000000b1,0x00000000,0x00030047, - 0x000000b2,0x00000000,0x00030047,0x000000b3,0x00000000,0x00030047,0x000000b5,0x00000000, - 0x00030047,0x000000b6,0x00000000,0x00030047,0x000000b7,0x00000000,0x00030047,0x000000b8, - 0x00000000,0x00030047,0x000000b9,0x00000000,0x00030047,0x000000ba,0x00000000,0x00030047, - 0x000000bb,0x00000000,0x00030047,0x000000bc,0x00000000,0x00030047,0x000000bd,0x00000000, - 0x00030047,0x000000be,0x00000000,0x00030047,0x000000bf,0x00000000,0x00030047,0x000000c0, - 0x00000000,0x00030047,0x000000c1,0x00000000,0x00030047,0x000000c2,0x00000000,0x00030047, - 0x000000c3,0x00000000,0x00030047,0x000000c4,0x00000000,0x00030047,0x000000c5,0x00000000, - 0x00030047,0x000000c6,0x00000000,0x00030047,0x000000c7,0x00000000,0x00030047,0x000000c8, - 0x00000000,0x00030047,0x000000c9,0x00000000,0x00030047,0x000000ca,0x00000000,0x00030047, - 0x000000cb,0x00000000,0x00030047,0x000000cc,0x00000000,0x00030047,0x000000cd,0x00000000, - 0x00030047,0x000000ce,0x00000000,0x00030047,0x000000cf,0x00000000,0x00030047,0x000000d1, - 0x00000000,0x00040047,0x000000d1,0x0000001e,0x00000000,0x00030047,0x000000d2,0x00000000, - 0x00030047,0x000000d3,0x00000000,0x00030047,0x000000d4,0x00000000,0x00030047,0x000000d5, - 0x00000000,0x00030047,0x000000d6,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003, - 0x00000002,0x00040015,0x00000006,0x00000020,0x00000001,0x00040017,0x00000007,0x00000006, - 0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00030016,0x00000009,0x00000020, - 0x00040017,0x0000000a,0x00000009,0x00000003,0x00040021,0x0000000b,0x0000000a,0x00000008, - 0x00040020,0x0000000f,0x00000007,0x00000009,0x00060021,0x00000010,0x00000009,0x0000000f, - 0x0000000f,0x0000000f,0x00090019,0x0000001c,0x00000009,0x00000001,0x00000000,0x00000000, - 0x00000000,0x00000001,0x00000000,0x0003001b,0x0000001d,0x0000001c,0x00040020,0x0000001e, - 0x00000000,0x0000001d,0x0004003b,0x0000001e,0x0000001f,0x00000000,0x0004002b,0x00000006, - 0x00000021,0x00000000,0x0005002c,0x00000007,0x00000026,0x00000021,0x00000021,0x0004002b, - 0x00000006,0x00000028,0x00000001,0x0005002c,0x00000007,0x00000029,0x00000028,0x00000028, - 0x00040017,0x0000002d,0x00000009,0x00000004,0x00040017,0x00000041,0x00000009,0x00000002, - 0x00040020,0x00000042,0x00000001,0x00000041,0x0004003b,0x00000042,0x00000043,0x00000001, - 0x0005001e,0x00000045,0x0000002d,0x00000041,0x00000009,0x00040020,0x00000046,0x00000009, - 0x00000045,0x0004003b,0x00000046,0x00000047,0x00000009,0x00040020,0x00000048,0x00000009, - 0x00000041,0x0004002b,0x00000009,0x0000004e,0xbf800000,0x0004002b,0x00000009,0x0000004f, - 0x41000000,0x0004002b,0x00000009,0x00000050,0x40a00000,0x0004002b,0x00000006,0x00000051, - 0x00000002,0x00040020,0x00000052,0x00000009,0x00000009,0x0004002b,0x00000009,0x00000055, - 0x00000000,0x0004002b,0x00000009,0x00000056,0x3f800000,0x00040020,0x0000005a,0x00000007, - 0x0000000a,0x0004002b,0x00000006,0x0000005d,0xffffffff,0x0005002c,0x00000007,0x0000005e, - 0x00000021,0x0000005d,0x0005002c,0x00000007,0x00000064,0x0000005d,0x00000021,0x0005002c, - 0x00000007,0x0000006e,0x00000028,0x00000021,0x0005002c,0x00000007,0x00000074,0x00000021, - 0x00000028,0x00040015,0x0000007a,0x00000020,0x00000000,0x0004002b,0x0000007a,0x0000007b, - 0x00000001,0x0004002b,0x00000009,0x000000a2,0x3a800000,0x0004002b,0x00000009,0x000000b4, - 0x40800000,0x00040020,0x000000d0,0x00000003,0x0000002d,0x0004003b,0x000000d0,0x000000d1, - 0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005, - 0x0004003b,0x00000008,0x00000040,0x00000007,0x0004003b,0x0000000f,0x0000004d,0x00000007, - 0x0004003b,0x0000005a,0x0000005b,0x00000007,0x0004003b,0x00000008,0x00000060,0x00000007, - 0x0004003b,0x0000005a,0x00000062,0x00000007,0x0004003b,0x00000008,0x00000066,0x00000007, - 0x0004003b,0x0000005a,0x00000068,0x00000007,0x0004003b,0x00000008,0x00000069,0x00000007, - 0x0004003b,0x0000005a,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000070,0x00000007, - 0x0004003b,0x0000005a,0x00000072,0x00000007,0x0004003b,0x00000008,0x00000076,0x00000007, - 0x0004003b,0x0000000f,0x00000078,0x00000007,0x0004003b,0x0000000f,0x00000079,0x00000007, - 0x0004003b,0x0000000f,0x0000007e,0x00000007,0x0004003b,0x0000000f,0x00000081,0x00000007, - 0x0004003b,0x0000000f,0x00000085,0x00000007,0x0004003b,0x0000000f,0x00000086,0x00000007, - 0x0004003b,0x0000000f,0x00000089,0x00000007,0x0004003b,0x0000000f,0x0000008d,0x00000007, - 0x0004003b,0x0000000f,0x0000008e,0x00000007,0x0004003b,0x0000000f,0x00000091,0x00000007, - 0x0004003b,0x0000000f,0x00000094,0x00000007,0x0004003b,0x0000000f,0x00000098,0x00000007, - 0x0004003b,0x0000000f,0x00000099,0x00000007,0x0004003b,0x0000000f,0x0000009c,0x00000007, - 0x0004003b,0x0000000f,0x000000a0,0x00000007,0x0004003b,0x0000000f,0x000000a5,0x00000007, - 0x0004003b,0x0000000f,0x000000af,0x00000007,0x0004003b,0x0000000f,0x000000b3,0x00000007, - 0x0004003b,0x0000005a,0x000000b9,0x00000007,0x0004003d,0x00000041,0x00000044,0x00000043, - 0x00050041,0x00000048,0x00000049,0x00000047,0x00000028,0x0004003d,0x00000041,0x0000004a, - 0x00000049,0x00050085,0x00000041,0x0000004b,0x00000044,0x0000004a,0x0004006e,0x00000007, - 0x0000004c,0x0000004b,0x0003003e,0x00000040,0x0000004c,0x00050041,0x00000052,0x00000053, - 0x00000047,0x00000051,0x0004003d,0x00000009,0x00000054,0x00000053,0x0008000c,0x00000009, - 0x00000057,0x00000001,0x0000002b,0x00000054,0x00000055,0x00000056,0x0008000c,0x00000009, - 0x00000058,0x00000001,0x0000002e,0x0000004f,0x00000050,0x00000057,0x00050088,0x00000009, - 0x00000059,0x0000004e,0x00000058,0x0003003e,0x0000004d,0x00000059,0x0004003d,0x00000007, - 0x0000005c,0x00000040,0x00050080,0x00000007,0x0000005f,0x0000005c,0x0000005e,0x0003003e, - 0x00000060,0x0000005f,0x00050039,0x0000000a,0x00000061,0x0000000d,0x00000060,0x0003003e, - 0x0000005b,0x00000061,0x0004003d,0x00000007,0x00000063,0x00000040,0x00050080,0x00000007, - 0x00000065,0x00000063,0x00000064,0x0003003e,0x00000066,0x00000065,0x00050039,0x0000000a, - 0x00000067,0x0000000d,0x00000066,0x0003003e,0x00000062,0x00000067,0x0004003d,0x00000007, - 0x0000006a,0x00000040,0x0003003e,0x00000069,0x0000006a,0x00050039,0x0000000a,0x0000006b, - 0x0000000d,0x00000069,0x0003003e,0x00000068,0x0000006b,0x0004003d,0x00000007,0x0000006d, - 0x00000040,0x00050080,0x00000007,0x0000006f,0x0000006d,0x0000006e,0x0003003e,0x00000070, - 0x0000006f,0x00050039,0x0000000a,0x00000071,0x0000000d,0x00000070,0x0003003e,0x0000006c, - 0x00000071,0x0004003d,0x00000007,0x00000073,0x00000040,0x00050080,0x00000007,0x00000075, - 0x00000073,0x00000074,0x0003003e,0x00000076,0x00000075,0x00050039,0x0000000a,0x00000077, - 0x0000000d,0x00000076,0x0003003e,0x00000072,0x00000077,0x00050041,0x0000000f,0x0000007c, - 0x00000062,0x0000007b,0x0004003d,0x00000009,0x0000007d,0x0000007c,0x0003003e,0x00000079, - 0x0000007d,0x00050041,0x0000000f,0x0000007f,0x00000068,0x0000007b,0x0004003d,0x00000009, - 0x00000080,0x0000007f,0x0003003e,0x0000007e,0x00000080,0x00050041,0x0000000f,0x00000082, - 0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000083,0x00000082,0x0003003e,0x00000081, - 0x00000083,0x00070039,0x00000009,0x00000084,0x00000014,0x00000079,0x0000007e,0x00000081, - 0x0003003e,0x00000085,0x00000084,0x00050041,0x0000000f,0x00000087,0x0000005b,0x0000007b, - 0x0004003d,0x00000009,0x00000088,0x00000087,0x0003003e,0x00000086,0x00000088,0x00050041, - 0x0000000f,0x0000008a,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000008b,0x0000008a, - 0x0003003e,0x00000089,0x0000008b,0x00070039,0x00000009,0x0000008c,0x00000014,0x00000085, - 0x00000086,0x00000089,0x0003003e,0x00000078,0x0000008c,0x00050041,0x0000000f,0x0000008f, - 0x00000062,0x0000007b,0x0004003d,0x00000009,0x00000090,0x0000008f,0x0003003e,0x0000008e, - 0x00000090,0x00050041,0x0000000f,0x00000092,0x00000068,0x0000007b,0x0004003d,0x00000009, - 0x00000093,0x00000092,0x0003003e,0x00000091,0x00000093,0x00050041,0x0000000f,0x00000095, - 0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000096,0x00000095,0x0003003e,0x00000094, - 0x00000096,0x00070039,0x00000009,0x00000097,0x00000019,0x0000008e,0x00000091,0x00000094, - 0x0003003e,0x00000098,0x00000097,0x00050041,0x0000000f,0x0000009a,0x0000005b,0x0000007b, - 0x0004003d,0x00000009,0x0000009b,0x0000009a,0x0003003e,0x00000099,0x0000009b,0x00050041, - 0x0000000f,0x0000009d,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000009e,0x0000009d, - 0x0003003e,0x0000009c,0x0000009e,0x00070039,0x00000009,0x0000009f,0x00000019,0x00000098, - 0x00000099,0x0000009c,0x0003003e,0x0000008d,0x0000009f,0x0004003d,0x00000009,0x000000a1, - 0x0000008d,0x0007000c,0x00000009,0x000000a3,0x00000001,0x00000028,0x000000a1,0x000000a2, - 0x00050088,0x00000009,0x000000a4,0x00000056,0x000000a3,0x0003003e,0x000000a0,0x000000a4, - 0x0004003d,0x00000009,0x000000a6,0x00000078,0x0004003d,0x00000009,0x000000a7,0x0000008d, - 0x00050083,0x00000009,0x000000a8,0x00000056,0x000000a7,0x0007000c,0x00000009,0x000000a9, - 0x00000001,0x00000025,0x000000a6,0x000000a8,0x0004003d,0x00000009,0x000000aa,0x000000a0, - 0x00050085,0x00000009,0x000000ab,0x000000a9,0x000000aa,0x0008000c,0x00000009,0x000000ac, - 0x00000001,0x0000002b,0x000000ab,0x00000055,0x00000056,0x0003003e,0x000000a5,0x000000ac, - 0x0004003d,0x00000009,0x000000ad,0x000000a5,0x0006000c,0x00000009,0x000000ae,0x00000001, - 0x0000001f,0x000000ad,0x0003003e,0x000000a5,0x000000ae,0x0004003d,0x00000009,0x000000b0, - 0x000000a5,0x0004003d,0x00000009,0x000000b1,0x0000004d,0x00050085,0x00000009,0x000000b2, - 0x000000b0,0x000000b1,0x0003003e,0x000000af,0x000000b2,0x0004003d,0x00000009,0x000000b5, - 0x000000af,0x00050085,0x00000009,0x000000b6,0x000000b4,0x000000b5,0x00050081,0x00000009, - 0x000000b7,0x00000056,0x000000b6,0x00050088,0x00000009,0x000000b8,0x00000056,0x000000b7, - 0x0003003e,0x000000b3,0x000000b8,0x0004003d,0x0000000a,0x000000ba,0x0000005b,0x0004003d, - 0x00000009,0x000000bb,0x000000af,0x0005008e,0x0000000a,0x000000bc,0x000000ba,0x000000bb, - 0x0004003d,0x0000000a,0x000000bd,0x00000062,0x0004003d,0x00000009,0x000000be,0x000000af, - 0x0005008e,0x0000000a,0x000000bf,0x000000bd,0x000000be,0x00050081,0x0000000a,0x000000c0, - 0x000000bc,0x000000bf,0x0004003d,0x0000000a,0x000000c1,0x0000006c,0x0004003d,0x00000009, - 0x000000c2,0x000000af,0x0005008e,0x0000000a,0x000000c3,0x000000c1,0x000000c2,0x00050081, - 0x0000000a,0x000000c4,0x000000c0,0x000000c3,0x0004003d,0x0000000a,0x000000c5,0x00000072, - 0x0004003d,0x00000009,0x000000c6,0x000000af,0x0005008e,0x0000000a,0x000000c7,0x000000c5, - 0x000000c6,0x00050081,0x0000000a,0x000000c8,0x000000c4,0x000000c7,0x0004003d,0x0000000a, - 0x000000c9,0x00000068,0x00050081,0x0000000a,0x000000ca,0x000000c8,0x000000c9,0x0004003d, - 0x00000009,0x000000cb,0x000000b3,0x0005008e,0x0000000a,0x000000cc,0x000000ca,0x000000cb, - 0x00060050,0x0000000a,0x000000cd,0x00000055,0x00000055,0x00000055,0x00060050,0x0000000a, - 0x000000ce,0x00000056,0x00000056,0x00000056,0x0008000c,0x0000000a,0x000000cf,0x00000001, - 0x0000002b,0x000000cc,0x000000cd,0x000000ce,0x0003003e,0x000000b9,0x000000cf,0x0004003d, - 0x0000000a,0x000000d2,0x000000b9,0x00050051,0x00000009,0x000000d3,0x000000d2,0x00000000, - 0x00050051,0x00000009,0x000000d4,0x000000d2,0x00000001,0x00050051,0x00000009,0x000000d5, - 0x000000d2,0x00000002,0x00070050,0x0000002d,0x000000d6,0x000000d3,0x000000d4,0x000000d5, - 0x00000056,0x0003003e,0x000000d1,0x000000d6,0x000100fd,0x00010038,0x00050036,0x0000000a, - 0x0000000d,0x00000000,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8,0x0000000e, - 0x0004003b,0x00000008,0x0000001b,0x00000007,0x0004003d,0x0000001d,0x00000020,0x0000001f, - 0x00040064,0x0000001c,0x00000022,0x00000020,0x00050067,0x00000007,0x00000023,0x00000022, - 0x00000021,0x0003003e,0x0000001b,0x00000023,0x0004003d,0x0000001d,0x00000024,0x0000001f, - 0x0004003d,0x00000007,0x00000025,0x0000000c,0x0004003d,0x00000007,0x00000027,0x0000001b, - 0x00050082,0x00000007,0x0000002a,0x00000027,0x00000029,0x0008000c,0x00000007,0x0000002b, - 0x00000001,0x0000002d,0x00000025,0x00000026,0x0000002a,0x00040064,0x0000001c,0x0000002c, - 0x00000024,0x0007005f,0x0000002d,0x0000002e,0x0000002c,0x0000002b,0x00000002,0x00000021, - 0x0008004f,0x0000000a,0x0000002f,0x0000002e,0x0000002e,0x00000000,0x00000001,0x00000002, - 0x000200fe,0x0000002f,0x00010038,0x00050036,0x00000009,0x00000014,0x00000000,0x00000010, - 0x00030037,0x0000000f,0x00000011,0x00030037,0x0000000f,0x00000012,0x00030037,0x0000000f, - 0x00000013,0x000200f8,0x00000015,0x0004003d,0x00000009,0x00000032,0x00000011,0x0004003d, - 0x00000009,0x00000033,0x00000012,0x0004003d,0x00000009,0x00000034,0x00000013,0x0007000c, - 0x00000009,0x00000035,0x00000001,0x00000025,0x00000033,0x00000034,0x0007000c,0x00000009, - 0x00000036,0x00000001,0x00000025,0x00000032,0x00000035,0x000200fe,0x00000036,0x00010038, - 0x00050036,0x00000009,0x00000019,0x00000000,0x00000010,0x00030037,0x0000000f,0x00000016, - 0x00030037,0x0000000f,0x00000017,0x00030037,0x0000000f,0x00000018,0x000200f8,0x0000001a, - 0x0004003d,0x00000009,0x00000039,0x00000016,0x0004003d,0x00000009,0x0000003a,0x00000017, - 0x0004003d,0x00000009,0x0000003b,0x00000018,0x0007000c,0x00000009,0x0000003c,0x00000001, - 0x00000028,0x0000003a,0x0000003b,0x0007000c,0x00000009,0x0000003d,0x00000001,0x00000028, - 0x00000039,0x0000003c,0x000200fe,0x0000003d,0x00010038 + 0x07230203,0x00010000,0x0008000b,0x000000d7,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000047,0x000000d1,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00060005,0x0000000d,0x4c736143,0x2864616f,0x3b326976,0x00000000,0x00030005, + 0x0000000c,0x00000070,0x00070005,0x00000014,0x6e694d41,0x28314633,0x663b3166,0x31663b31, + 0x0000003b,0x00030005,0x00000011,0x00000078,0x00030005,0x00000012,0x00000079,0x00030005, + 0x00000013,0x0000007a,0x00070005,0x00000019,0x78614d41,0x28314633,0x663b3166,0x31663b31, + 0x0000003b,0x00030005,0x00000016,0x00000078,0x00030005,0x00000017,0x00000079,0x00030005, + 0x00000018,0x0000007a,0x00030005,0x0000001d,0x00007675,0x00030005,0x00000024,0x00004350, + 0x00040006,0x00000024,0x00000000,0x0063646e,0x00060006,0x00000024,0x00000001,0x6f736572, + 0x6974756c,0x00006e6f,0x00060006,0x00000024,0x00000002,0x72616873,0x73656e70,0x00000073, + 0x00030005,0x00000026,0x00006370,0x00060005,0x0000002f,0x75706e49,0x78655474,0x65727574, + 0x00000000,0x00030005,0x00000045,0x00007073,0x00060005,0x00000047,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00040005,0x0000004d,0x6b616570,0x00000000,0x00030005,0x0000005a, + 0x00000062,0x00040005,0x00000060,0x61726170,0x0000006d,0x00030005,0x00000062,0x00000064, + 0x00040005,0x00000066,0x61726170,0x0000006d,0x00030005,0x00000068,0x00000065,0x00040005, + 0x00000069,0x61726170,0x0000006d,0x00030005,0x0000006c,0x00000066,0x00040005,0x00000070, + 0x61726170,0x0000006d,0x00030005,0x00000072,0x00000068,0x00040005,0x00000076,0x61726170, + 0x0000006d,0x00030005,0x00000078,0x00476e6d,0x00040005,0x00000079,0x61726170,0x0000006d, + 0x00040005,0x0000007e,0x61726170,0x0000006d,0x00040005,0x00000081,0x61726170,0x0000006d, + 0x00040005,0x00000085,0x61726170,0x0000006d,0x00040005,0x00000086,0x61726170,0x0000006d, + 0x00040005,0x00000089,0x61726170,0x0000006d,0x00030005,0x0000008d,0x0047786d,0x00040005, + 0x0000008e,0x61726170,0x0000006d,0x00040005,0x00000091,0x61726170,0x0000006d,0x00040005, + 0x00000094,0x61726170,0x0000006d,0x00040005,0x00000098,0x61726170,0x0000006d,0x00040005, + 0x00000099,0x61726170,0x0000006d,0x00040005,0x0000009c,0x61726170,0x0000006d,0x00040005, + 0x000000a0,0x4d706372,0x00000047,0x00040005,0x000000a5,0x47706d61,0x00000000,0x00030005, + 0x000000af,0x00004777,0x00050005,0x000000b3,0x57706372,0x68676965,0x00000074,0x00030005, + 0x000000b9,0x00786970,0x00050005,0x000000d1,0x4374756f,0x726f6c6f,0x00000000,0x00030047, + 0x0000000d,0x00000000,0x00030047,0x00000011,0x00000000,0x00030047,0x00000012,0x00000000, + 0x00030047,0x00000013,0x00000000,0x00030047,0x00000014,0x00000000,0x00030047,0x00000016, + 0x00000000,0x00030047,0x00000017,0x00000000,0x00030047,0x00000018,0x00000000,0x00030047, + 0x00000019,0x00000000,0x00030047,0x00000024,0x00000002,0x00050048,0x00000024,0x00000000, + 0x00000023,0x00000000,0x00050048,0x00000024,0x00000001,0x00000023,0x00000010,0x00040048, + 0x00000024,0x00000002,0x00000000,0x00050048,0x00000024,0x00000002,0x00000023,0x00000018, + 0x00030047,0x0000002f,0x00000000,0x00040047,0x0000002f,0x00000021,0x00000000,0x00040047, + 0x0000002f,0x00000022,0x00000000,0x00030047,0x00000030,0x00000000,0x00030047,0x00000033, + 0x00000000,0x00030047,0x00000034,0x00000000,0x00030047,0x00000037,0x00000000,0x00030047, + 0x00000038,0x00000000,0x00030047,0x00000039,0x00000000,0x00030047,0x0000003a,0x00000000, + 0x00030047,0x0000003b,0x00000000,0x00030047,0x0000003e,0x00000000,0x00030047,0x0000003f, + 0x00000000,0x00030047,0x00000040,0x00000000,0x00030047,0x00000041,0x00000000,0x00030047, + 0x00000042,0x00000000,0x00040047,0x00000047,0x0000001e,0x00000000,0x00030047,0x0000004d, + 0x00000000,0x00030047,0x00000054,0x00000000,0x00030047,0x00000056,0x00000000,0x00030047, + 0x00000057,0x00000000,0x00030047,0x00000058,0x00000000,0x00030047,0x0000005a,0x00000000, + 0x00030047,0x00000061,0x00000000,0x00030047,0x00000062,0x00000000,0x00030047,0x00000067, + 0x00000000,0x00030047,0x00000068,0x00000000,0x00030047,0x0000006b,0x00000000,0x00030047, + 0x0000006c,0x00000000,0x00030047,0x00000071,0x00000000,0x00030047,0x00000072,0x00000000, + 0x00030047,0x00000077,0x00000000,0x00030047,0x00000078,0x00000000,0x00030047,0x00000079, + 0x00000000,0x00030047,0x0000007d,0x00000000,0x00030047,0x0000007e,0x00000000,0x00030047, + 0x00000080,0x00000000,0x00030047,0x00000081,0x00000000,0x00030047,0x00000083,0x00000000, + 0x00030047,0x00000084,0x00000000,0x00030047,0x00000085,0x00000000,0x00030047,0x00000086, + 0x00000000,0x00030047,0x00000088,0x00000000,0x00030047,0x00000089,0x00000000,0x00030047, + 0x0000008b,0x00000000,0x00030047,0x0000008c,0x00000000,0x00030047,0x0000008d,0x00000000, + 0x00030047,0x0000008e,0x00000000,0x00030047,0x00000090,0x00000000,0x00030047,0x00000091, + 0x00000000,0x00030047,0x00000093,0x00000000,0x00030047,0x00000094,0x00000000,0x00030047, + 0x00000096,0x00000000,0x00030047,0x00000097,0x00000000,0x00030047,0x00000098,0x00000000, + 0x00030047,0x00000099,0x00000000,0x00030047,0x0000009b,0x00000000,0x00030047,0x0000009c, + 0x00000000,0x00030047,0x0000009e,0x00000000,0x00030047,0x0000009f,0x00000000,0x00030047, + 0x000000a0,0x00000000,0x00030047,0x000000a1,0x00000000,0x00030047,0x000000a3,0x00000000, + 0x00030047,0x000000a4,0x00000000,0x00030047,0x000000a5,0x00000000,0x00030047,0x000000a6, + 0x00000000,0x00030047,0x000000a7,0x00000000,0x00030047,0x000000a8,0x00000000,0x00030047, + 0x000000a9,0x00000000,0x00030047,0x000000aa,0x00000000,0x00030047,0x000000ab,0x00000000, + 0x00030047,0x000000ac,0x00000000,0x00030047,0x000000ad,0x00000000,0x00030047,0x000000ae, + 0x00000000,0x00030047,0x000000af,0x00000000,0x00030047,0x000000b0,0x00000000,0x00030047, + 0x000000b1,0x00000000,0x00030047,0x000000b2,0x00000000,0x00030047,0x000000b3,0x00000000, + 0x00030047,0x000000b5,0x00000000,0x00030047,0x000000b6,0x00000000,0x00030047,0x000000b7, + 0x00000000,0x00030047,0x000000b8,0x00000000,0x00030047,0x000000b9,0x00000000,0x00030047, + 0x000000ba,0x00000000,0x00030047,0x000000bb,0x00000000,0x00030047,0x000000bc,0x00000000, + 0x00030047,0x000000bd,0x00000000,0x00030047,0x000000be,0x00000000,0x00030047,0x000000bf, + 0x00000000,0x00030047,0x000000c0,0x00000000,0x00030047,0x000000c1,0x00000000,0x00030047, + 0x000000c2,0x00000000,0x00030047,0x000000c3,0x00000000,0x00030047,0x000000c4,0x00000000, + 0x00030047,0x000000c5,0x00000000,0x00030047,0x000000c6,0x00000000,0x00030047,0x000000c7, + 0x00000000,0x00030047,0x000000c8,0x00000000,0x00030047,0x000000c9,0x00000000,0x00030047, + 0x000000ca,0x00000000,0x00030047,0x000000cb,0x00000000,0x00030047,0x000000cc,0x00000000, + 0x00030047,0x000000cd,0x00000000,0x00030047,0x000000ce,0x00000000,0x00030047,0x000000cf, + 0x00000000,0x00030047,0x000000d1,0x00000000,0x00040047,0x000000d1,0x0000001e,0x00000000, + 0x00030047,0x000000d2,0x00000000,0x00030047,0x000000d3,0x00000000,0x00030047,0x000000d4, + 0x00000000,0x00030047,0x000000d5,0x00000000,0x00030047,0x000000d6,0x00000000,0x00020013, + 0x00000002,0x00030021,0x00000003,0x00000002,0x00040015,0x00000006,0x00000020,0x00000001, + 0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007, + 0x00030016,0x00000009,0x00000020,0x00040017,0x0000000a,0x00000009,0x00000003,0x00040021, + 0x0000000b,0x0000000a,0x00000008,0x00040020,0x0000000f,0x00000007,0x00000009,0x00060021, + 0x00000010,0x00000009,0x0000000f,0x0000000f,0x0000000f,0x00040017,0x0000001b,0x00000009, + 0x00000002,0x00040020,0x0000001c,0x00000007,0x0000001b,0x0004002b,0x00000009,0x00000020, + 0x3f000000,0x00040017,0x00000023,0x00000009,0x00000004,0x0005001e,0x00000024,0x00000023, + 0x0000001b,0x00000009,0x00040020,0x00000025,0x00000009,0x00000024,0x0004003b,0x00000025, + 0x00000026,0x00000009,0x0004002b,0x00000006,0x00000027,0x00000001,0x00040020,0x00000028, + 0x00000009,0x0000001b,0x00090019,0x0000002c,0x00000009,0x00000001,0x00000000,0x00000000, + 0x00000000,0x00000001,0x00000000,0x0003001b,0x0000002d,0x0000002c,0x00040020,0x0000002e, + 0x00000000,0x0000002d,0x0004003b,0x0000002e,0x0000002f,0x00000000,0x0004002b,0x00000009, + 0x00000032,0x00000000,0x00040020,0x00000046,0x00000001,0x0000001b,0x0004003b,0x00000046, + 0x00000047,0x00000001,0x0004002b,0x00000009,0x0000004e,0xbf800000,0x0004002b,0x00000009, + 0x0000004f,0x41000000,0x0004002b,0x00000009,0x00000050,0x40a00000,0x0004002b,0x00000006, + 0x00000051,0x00000002,0x00040020,0x00000052,0x00000009,0x00000009,0x0004002b,0x00000009, + 0x00000055,0x3f800000,0x00040020,0x00000059,0x00000007,0x0000000a,0x0004002b,0x00000006, + 0x0000005c,0x00000000,0x0004002b,0x00000006,0x0000005d,0xffffffff,0x0005002c,0x00000007, + 0x0000005e,0x0000005c,0x0000005d,0x0005002c,0x00000007,0x00000064,0x0000005d,0x0000005c, + 0x0005002c,0x00000007,0x0000006e,0x00000027,0x0000005c,0x0005002c,0x00000007,0x00000074, + 0x0000005c,0x00000027,0x00040015,0x0000007a,0x00000020,0x00000000,0x0004002b,0x0000007a, + 0x0000007b,0x00000001,0x0004002b,0x00000009,0x000000a2,0x3a800000,0x0004002b,0x00000009, + 0x000000b4,0x40800000,0x00040020,0x000000d0,0x00000003,0x00000023,0x0004003b,0x000000d0, + 0x000000d1,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, + 0x00000005,0x0004003b,0x00000008,0x00000045,0x00000007,0x0004003b,0x0000000f,0x0000004d, + 0x00000007,0x0004003b,0x00000059,0x0000005a,0x00000007,0x0004003b,0x00000008,0x00000060, + 0x00000007,0x0004003b,0x00000059,0x00000062,0x00000007,0x0004003b,0x00000008,0x00000066, + 0x00000007,0x0004003b,0x00000059,0x00000068,0x00000007,0x0004003b,0x00000008,0x00000069, + 0x00000007,0x0004003b,0x00000059,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000070, + 0x00000007,0x0004003b,0x00000059,0x00000072,0x00000007,0x0004003b,0x00000008,0x00000076, + 0x00000007,0x0004003b,0x0000000f,0x00000078,0x00000007,0x0004003b,0x0000000f,0x00000079, + 0x00000007,0x0004003b,0x0000000f,0x0000007e,0x00000007,0x0004003b,0x0000000f,0x00000081, + 0x00000007,0x0004003b,0x0000000f,0x00000085,0x00000007,0x0004003b,0x0000000f,0x00000086, + 0x00000007,0x0004003b,0x0000000f,0x00000089,0x00000007,0x0004003b,0x0000000f,0x0000008d, + 0x00000007,0x0004003b,0x0000000f,0x0000008e,0x00000007,0x0004003b,0x0000000f,0x00000091, + 0x00000007,0x0004003b,0x0000000f,0x00000094,0x00000007,0x0004003b,0x0000000f,0x00000098, + 0x00000007,0x0004003b,0x0000000f,0x00000099,0x00000007,0x0004003b,0x0000000f,0x0000009c, + 0x00000007,0x0004003b,0x0000000f,0x000000a0,0x00000007,0x0004003b,0x0000000f,0x000000a5, + 0x00000007,0x0004003b,0x0000000f,0x000000af,0x00000007,0x0004003b,0x0000000f,0x000000b3, + 0x00000007,0x0004003b,0x00000059,0x000000b9,0x00000007,0x0004003d,0x0000001b,0x00000048, + 0x00000047,0x00050041,0x00000028,0x00000049,0x00000026,0x00000027,0x0004003d,0x0000001b, + 0x0000004a,0x00000049,0x00050085,0x0000001b,0x0000004b,0x00000048,0x0000004a,0x0004006e, + 0x00000007,0x0000004c,0x0000004b,0x0003003e,0x00000045,0x0000004c,0x00050041,0x00000052, + 0x00000053,0x00000026,0x00000051,0x0004003d,0x00000009,0x00000054,0x00000053,0x0008000c, + 0x00000009,0x00000056,0x00000001,0x0000002b,0x00000054,0x00000032,0x00000055,0x0008000c, + 0x00000009,0x00000057,0x00000001,0x0000002e,0x0000004f,0x00000050,0x00000056,0x00050088, + 0x00000009,0x00000058,0x0000004e,0x00000057,0x0003003e,0x0000004d,0x00000058,0x0004003d, + 0x00000007,0x0000005b,0x00000045,0x00050080,0x00000007,0x0000005f,0x0000005b,0x0000005e, + 0x0003003e,0x00000060,0x0000005f,0x00050039,0x0000000a,0x00000061,0x0000000d,0x00000060, + 0x0003003e,0x0000005a,0x00000061,0x0004003d,0x00000007,0x00000063,0x00000045,0x00050080, + 0x00000007,0x00000065,0x00000063,0x00000064,0x0003003e,0x00000066,0x00000065,0x00050039, + 0x0000000a,0x00000067,0x0000000d,0x00000066,0x0003003e,0x00000062,0x00000067,0x0004003d, + 0x00000007,0x0000006a,0x00000045,0x0003003e,0x00000069,0x0000006a,0x00050039,0x0000000a, + 0x0000006b,0x0000000d,0x00000069,0x0003003e,0x00000068,0x0000006b,0x0004003d,0x00000007, + 0x0000006d,0x00000045,0x00050080,0x00000007,0x0000006f,0x0000006d,0x0000006e,0x0003003e, + 0x00000070,0x0000006f,0x00050039,0x0000000a,0x00000071,0x0000000d,0x00000070,0x0003003e, + 0x0000006c,0x00000071,0x0004003d,0x00000007,0x00000073,0x00000045,0x00050080,0x00000007, + 0x00000075,0x00000073,0x00000074,0x0003003e,0x00000076,0x00000075,0x00050039,0x0000000a, + 0x00000077,0x0000000d,0x00000076,0x0003003e,0x00000072,0x00000077,0x00050041,0x0000000f, + 0x0000007c,0x00000062,0x0000007b,0x0004003d,0x00000009,0x0000007d,0x0000007c,0x0003003e, + 0x00000079,0x0000007d,0x00050041,0x0000000f,0x0000007f,0x00000068,0x0000007b,0x0004003d, + 0x00000009,0x00000080,0x0000007f,0x0003003e,0x0000007e,0x00000080,0x00050041,0x0000000f, + 0x00000082,0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000083,0x00000082,0x0003003e, + 0x00000081,0x00000083,0x00070039,0x00000009,0x00000084,0x00000014,0x00000079,0x0000007e, + 0x00000081,0x0003003e,0x00000085,0x00000084,0x00050041,0x0000000f,0x00000087,0x0000005a, + 0x0000007b,0x0004003d,0x00000009,0x00000088,0x00000087,0x0003003e,0x00000086,0x00000088, + 0x00050041,0x0000000f,0x0000008a,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000008b, + 0x0000008a,0x0003003e,0x00000089,0x0000008b,0x00070039,0x00000009,0x0000008c,0x00000014, + 0x00000085,0x00000086,0x00000089,0x0003003e,0x00000078,0x0000008c,0x00050041,0x0000000f, + 0x0000008f,0x00000062,0x0000007b,0x0004003d,0x00000009,0x00000090,0x0000008f,0x0003003e, + 0x0000008e,0x00000090,0x00050041,0x0000000f,0x00000092,0x00000068,0x0000007b,0x0004003d, + 0x00000009,0x00000093,0x00000092,0x0003003e,0x00000091,0x00000093,0x00050041,0x0000000f, + 0x00000095,0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000096,0x00000095,0x0003003e, + 0x00000094,0x00000096,0x00070039,0x00000009,0x00000097,0x00000019,0x0000008e,0x00000091, + 0x00000094,0x0003003e,0x00000098,0x00000097,0x00050041,0x0000000f,0x0000009a,0x0000005a, + 0x0000007b,0x0004003d,0x00000009,0x0000009b,0x0000009a,0x0003003e,0x00000099,0x0000009b, + 0x00050041,0x0000000f,0x0000009d,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000009e, + 0x0000009d,0x0003003e,0x0000009c,0x0000009e,0x00070039,0x00000009,0x0000009f,0x00000019, + 0x00000098,0x00000099,0x0000009c,0x0003003e,0x0000008d,0x0000009f,0x0004003d,0x00000009, + 0x000000a1,0x0000008d,0x0007000c,0x00000009,0x000000a3,0x00000001,0x00000028,0x000000a1, + 0x000000a2,0x00050088,0x00000009,0x000000a4,0x00000055,0x000000a3,0x0003003e,0x000000a0, + 0x000000a4,0x0004003d,0x00000009,0x000000a6,0x00000078,0x0004003d,0x00000009,0x000000a7, + 0x0000008d,0x00050083,0x00000009,0x000000a8,0x00000055,0x000000a7,0x0007000c,0x00000009, + 0x000000a9,0x00000001,0x00000025,0x000000a6,0x000000a8,0x0004003d,0x00000009,0x000000aa, + 0x000000a0,0x00050085,0x00000009,0x000000ab,0x000000a9,0x000000aa,0x0008000c,0x00000009, + 0x000000ac,0x00000001,0x0000002b,0x000000ab,0x00000032,0x00000055,0x0003003e,0x000000a5, + 0x000000ac,0x0004003d,0x00000009,0x000000ad,0x000000a5,0x0006000c,0x00000009,0x000000ae, + 0x00000001,0x0000001f,0x000000ad,0x0003003e,0x000000a5,0x000000ae,0x0004003d,0x00000009, + 0x000000b0,0x000000a5,0x0004003d,0x00000009,0x000000b1,0x0000004d,0x00050085,0x00000009, + 0x000000b2,0x000000b0,0x000000b1,0x0003003e,0x000000af,0x000000b2,0x0004003d,0x00000009, + 0x000000b5,0x000000af,0x00050085,0x00000009,0x000000b6,0x000000b4,0x000000b5,0x00050081, + 0x00000009,0x000000b7,0x00000055,0x000000b6,0x00050088,0x00000009,0x000000b8,0x00000055, + 0x000000b7,0x0003003e,0x000000b3,0x000000b8,0x0004003d,0x0000000a,0x000000ba,0x0000005a, + 0x0004003d,0x00000009,0x000000bb,0x000000af,0x0005008e,0x0000000a,0x000000bc,0x000000ba, + 0x000000bb,0x0004003d,0x0000000a,0x000000bd,0x00000062,0x0004003d,0x00000009,0x000000be, + 0x000000af,0x0005008e,0x0000000a,0x000000bf,0x000000bd,0x000000be,0x00050081,0x0000000a, + 0x000000c0,0x000000bc,0x000000bf,0x0004003d,0x0000000a,0x000000c1,0x0000006c,0x0004003d, + 0x00000009,0x000000c2,0x000000af,0x0005008e,0x0000000a,0x000000c3,0x000000c1,0x000000c2, + 0x00050081,0x0000000a,0x000000c4,0x000000c0,0x000000c3,0x0004003d,0x0000000a,0x000000c5, + 0x00000072,0x0004003d,0x00000009,0x000000c6,0x000000af,0x0005008e,0x0000000a,0x000000c7, + 0x000000c5,0x000000c6,0x00050081,0x0000000a,0x000000c8,0x000000c4,0x000000c7,0x0004003d, + 0x0000000a,0x000000c9,0x00000068,0x00050081,0x0000000a,0x000000ca,0x000000c8,0x000000c9, + 0x0004003d,0x00000009,0x000000cb,0x000000b3,0x0005008e,0x0000000a,0x000000cc,0x000000ca, + 0x000000cb,0x00060050,0x0000000a,0x000000cd,0x00000032,0x00000032,0x00000032,0x00060050, + 0x0000000a,0x000000ce,0x00000055,0x00000055,0x00000055,0x0008000c,0x0000000a,0x000000cf, + 0x00000001,0x0000002b,0x000000cc,0x000000cd,0x000000ce,0x0003003e,0x000000b9,0x000000cf, + 0x0004003d,0x0000000a,0x000000d2,0x000000b9,0x00050051,0x00000009,0x000000d3,0x000000d2, + 0x00000000,0x00050051,0x00000009,0x000000d4,0x000000d2,0x00000001,0x00050051,0x00000009, + 0x000000d5,0x000000d2,0x00000002,0x00070050,0x00000023,0x000000d6,0x000000d3,0x000000d4, + 0x000000d5,0x00000055,0x0003003e,0x000000d1,0x000000d6,0x000100fd,0x00010038,0x00050036, + 0x0000000a,0x0000000d,0x00000000,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8, + 0x0000000e,0x0004003b,0x0000001c,0x0000001d,0x00000007,0x0004003d,0x00000007,0x0000001e, + 0x0000000c,0x0004006f,0x0000001b,0x0000001f,0x0000001e,0x00050050,0x0000001b,0x00000021, + 0x00000020,0x00000020,0x00050081,0x0000001b,0x00000022,0x0000001f,0x00000021,0x00050041, + 0x00000028,0x00000029,0x00000026,0x00000027,0x0004003d,0x0000001b,0x0000002a,0x00000029, + 0x00050088,0x0000001b,0x0000002b,0x00000022,0x0000002a,0x0003003e,0x0000001d,0x0000002b, + 0x0004003d,0x0000002d,0x00000030,0x0000002f,0x0004003d,0x0000001b,0x00000031,0x0000001d, + 0x00070058,0x00000023,0x00000033,0x00000030,0x00000031,0x00000002,0x00000032,0x0008004f, + 0x0000000a,0x00000034,0x00000033,0x00000033,0x00000000,0x00000001,0x00000002,0x000200fe, + 0x00000034,0x00010038,0x00050036,0x00000009,0x00000014,0x00000000,0x00000010,0x00030037, + 0x0000000f,0x00000011,0x00030037,0x0000000f,0x00000012,0x00030037,0x0000000f,0x00000013, + 0x000200f8,0x00000015,0x0004003d,0x00000009,0x00000037,0x00000011,0x0004003d,0x00000009, + 0x00000038,0x00000012,0x0004003d,0x00000009,0x00000039,0x00000013,0x0007000c,0x00000009, + 0x0000003a,0x00000001,0x00000025,0x00000038,0x00000039,0x0007000c,0x00000009,0x0000003b, + 0x00000001,0x00000025,0x00000037,0x0000003a,0x000200fe,0x0000003b,0x00010038,0x00050036, + 0x00000009,0x00000019,0x00000000,0x00000010,0x00030037,0x0000000f,0x00000016,0x00030037, + 0x0000000f,0x00000017,0x00030037,0x0000000f,0x00000018,0x000200f8,0x0000001a,0x0004003d, + 0x00000009,0x0000003e,0x00000016,0x0004003d,0x00000009,0x0000003f,0x00000017,0x0004003d, + 0x00000009,0x00000040,0x00000018,0x0007000c,0x00000009,0x00000041,0x00000001,0x00000028, + 0x0000003f,0x00000040,0x0007000c,0x00000009,0x00000042,0x00000001,0x00000028,0x0000003e, + 0x00000041,0x000200fe,0x00000042,0x00010038 }; diff --git a/app/src/main/cpp/shaders/smaa_blend.frag b/app/src/main/cpp/shaders/smaa_blend.frag index cf4a2302a6..cd36894637 100644 --- a/app/src/main/cpp/shaders/smaa_blend.frag +++ b/app/src/main/cpp/shaders/smaa_blend.frag @@ -1,4 +1,5 @@ #version 450 +#extension GL_GOOGLE_include_directive : require layout(location = 0) in vec2 fragTexCoord; layout(location = 0) out vec4 outColor; @@ -6,25 +7,16 @@ layout(set = 0, binding = 0) uniform sampler2D InputTexture; layout(set = 1, binding = 0) uniform sampler2D WeightTexture; layout(push_constant) uniform Constants { vec4 ndc; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" + void main() { - 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); + vec4 offset; + SMAANeighborhoodBlendingVS(fragTexCoord, offset); + outColor = SMAANeighborhoodBlendingPS(fragTexCoord, offset, InputTexture, WeightTexture); } diff --git a/app/src/main/cpp/shaders/smaa_blend_frag.h b/app/src/main/cpp/shaders/smaa_blend_frag.h index bcb4749618..55ca213931 100644 --- a/app/src/main/cpp/shaders/smaa_blend_frag.h +++ b/app/src/main/cpp/shaders/smaa_blend_frag.h @@ -1,88 +1,204 @@ - // 1116.3.0 + // 1116.6.0 #pragma once const uint32_t smaa_blend_code[] = { - 0x07230203,0x00010000,0x0008000b,0x0000006b,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000000f8,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 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 + 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 }; diff --git a/app/src/main/cpp/shaders/smaa_edge.frag b/app/src/main/cpp/shaders/smaa_edge.frag index 44073b00c4..b4e40a9dad 100644 --- a/app/src/main/cpp/shaders/smaa_edge.frag +++ b/app/src/main/cpp/shaders/smaa_edge.frag @@ -1,29 +1,21 @@ #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; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; -float luma(vec3 c) { - return dot(c, vec3(0.2126, 0.7152, 0.0722)); -} +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" void main() { - 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)); + vec4 offset[3]; + SMAAEdgeDetectionVS(fragTexCoord, offset); + outColor = vec4(SMAALumaEdgeDetectionPS(fragTexCoord, offset, InputTexture), 0.0, 0.0); } diff --git a/app/src/main/cpp/shaders/smaa_edge_frag.h b/app/src/main/cpp/shaders/smaa_edge_frag.h index 7d133264c9..300a5ca064 100644 --- a/app/src/main/cpp/shaders/smaa_edge_frag.h +++ b/app/src/main/cpp/shaders/smaa_edge_frag.h @@ -1,102 +1,185 @@ - // 1116.3.0 + // 1116.6.0 #pragma once const uint32_t smaa_edge_code[] = { - 0x07230203,0x00010000,0x0008000b,0x00000080,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000000eb,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 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 + 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 }; diff --git a/app/src/main/cpp/shaders/smaa_tables.h b/app/src/main/cpp/shaders/smaa_tables.h new file mode 100644 index 0000000000..ebc28d815b --- /dev/null +++ b/app/src/main/cpp/shaders/smaa_tables.h @@ -0,0 +1,1375 @@ +/** + * 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. + */ + +/* SMAA's lookup tables, from Textures/AreaTex.h and Textures/SearchTex.h of github.com/iryoku/smaa. + * SMAA 1x reads only the first 80 of the area table's 560 rows; the other rows are not included. */ +#pragma once + +#define SMAA_AREA_W 160 +#define SMAA_AREA_H 560 +#define SMAA_AREA_ROWS 80 +#define SMAA_SEARCH_W 64 +#define SMAA_SEARCH_H 16 + +static const unsigned char kSmaaArea[SMAA_AREA_W * SMAA_AREA_ROWS * 2] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x44,0x7b,0x41,0x5d,0x42,0x54,0x41,0x4f,0x42,0x4b,0x42,0x49,0x42,0x48,0x41,0x47,0x42,0x46,0x42,0x45, + 0x42,0x45,0x42,0x44,0x42,0x44,0x42,0x44,0x42,0x43,0x41,0x43,0x42,0x43,0x42,0x43,0x42,0x43,0x42,0x43, + 0x04,0x7f,0x22,0x3d,0x2b,0x3d,0x30,0x3d,0x33,0x3d,0x35,0x3d,0x37,0x3d,0x38,0x3d,0x39,0x3d,0x39,0x3d, + 0x3a,0x3d,0x3a,0x3d,0x3b,0x3d,0x3b,0x3d,0x3b,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d, + 0x40,0x7f,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x62,0x20,0x4d,0x2a,0x48,0x30,0x44,0x33,0x44,0x35,0x44,0x36,0x43,0x37,0x42,0x38,0x43,0x39,0x42,0x39, + 0x42,0x3a,0x42,0x3a,0x42,0x3b,0x42,0x3b,0x42,0x3b,0x41,0x3b,0x42,0x3c,0x42,0x3c,0x42,0x3c,0x42,0x3c, + 0x00,0x5d,0x0c,0x49,0x16,0x43,0x1d,0x41,0x22,0x40,0x26,0x3f,0x29,0x3f,0x2c,0x3f,0x2e,0x3e,0x2f,0x3e, + 0x31,0x3e,0x32,0x3e,0x33,0x3e,0x33,0x3e,0x34,0x3e,0x35,0x3e,0x35,0x3e,0x36,0x3e,0x37,0x3e,0x37,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x6d,0x0b,0x57,0x16,0x4f,0x1d,0x4a,0x22,0x48,0x26,0x47,0x29,0x46,0x2b,0x44,0x2d,0x44,0x2f,0x44,0x30, + 0x44,0x31,0x44,0x32,0x43,0x33,0x43,0x34,0x43,0x34,0x42,0x35,0x43,0x36,0x42,0x36,0x42,0x37,0x42,0x37, + 0x00,0x68,0x06,0x54,0x0d,0x4b,0x14,0x47,0x19,0x44,0x1d,0x43,0x20,0x41,0x23,0x41,0x26,0x40,0x27,0x40, + 0x29,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f,0x2f,0x3f,0x30,0x3f,0x30,0x3e,0x31,0x3e,0x32,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x72,0x06,0x5f,0x0d,0x56,0x14,0x4f,0x19,0x4d,0x1d,0x4a,0x20,0x49,0x23,0x47,0x25,0x46,0x27,0x46,0x29, + 0x45,0x2a,0x45,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2f,0x43,0x30,0x44,0x30,0x44,0x31,0x43,0x32,0x43,0x33, + 0x00,0x6d,0x04,0x5b,0x09,0x51,0x0e,0x4c,0x13,0x48,0x17,0x46,0x1a,0x44,0x1d,0x43,0x1f,0x42,0x22,0x42, + 0x24,0x41,0x25,0x41,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x75,0x03,0x64,0x09,0x5a,0x0e,0x54,0x13,0x51,0x17,0x4e,0x1a,0x4c,0x1d,0x49,0x1f,0x49,0x22,0x48,0x23, + 0x47,0x25,0x46,0x26,0x46,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b,0x44,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2e, + 0x00,0x70,0x02,0x60,0x07,0x56,0x0b,0x50,0x0f,0x4c,0x12,0x49,0x16,0x47,0x18,0x46,0x1b,0x45,0x1d,0x44, + 0x1f,0x43,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x40,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x77,0x02,0x68,0x06,0x5f,0x0b,0x58,0x0f,0x54,0x12,0x51,0x15,0x4f,0x18,0x4c,0x1b,0x4b,0x1d,0x4a,0x1f, + 0x49,0x21,0x48,0x22,0x48,0x23,0x47,0x25,0x46,0x26,0x45,0x27,0x45,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b, + 0x00,0x72,0x02,0x64,0x05,0x5b,0x08,0x54,0x0c,0x50,0x0f,0x4d,0x12,0x4a,0x14,0x48,0x17,0x47,0x19,0x46, + 0x1b,0x45,0x1d,0x44,0x1f,0x44,0x20,0x42,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x41,0x27,0x40, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x78,0x02,0x6b,0x05,0x62,0x08,0x5b,0x0c,0x57,0x0f,0x54,0x12,0x51,0x14,0x4e,0x17,0x4d,0x19,0x4c,0x1b, + 0x4b,0x1d,0x4a,0x1e,0x49,0x20,0x48,0x21,0x48,0x22,0x46,0x24,0x46,0x25,0x46,0x26,0x46,0x27,0x45,0x27, + 0x00,0x74,0x01,0x66,0x04,0x5e,0x07,0x57,0x0a,0x53,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x49,0x16,0x48, + 0x18,0x46,0x1a,0x45,0x1b,0x45,0x1d,0x44,0x1e,0x44,0x20,0x43,0x21,0x42,0x22,0x42,0x23,0x42,0x24,0x41, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x79,0x01,0x6d,0x04,0x65,0x07,0x5e,0x0a,0x5a,0x0d,0x56,0x0f,0x54,0x12,0x51,0x14,0x4f,0x16,0x4e,0x18, + 0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x4a,0x1e,0x49,0x1f,0x48,0x21,0x48,0x22,0x48,0x23,0x47,0x23,0x46,0x25, + 0x00,0x75,0x01,0x69,0x03,0x61,0x06,0x5a,0x08,0x56,0x0b,0x52,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x4a, + 0x16,0x48,0x17,0x47,0x19,0x46,0x1a,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44,0x20,0x43,0x21,0x42, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7a,0x01,0x6f,0x03,0x67,0x06,0x60,0x08,0x5d,0x0b,0x59,0x0d,0x56,0x10,0x53,0x11,0x51,0x14,0x50,0x15, + 0x4e,0x17,0x4d,0x19,0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x48,0x1e,0x49,0x1f,0x49,0x20,0x48,0x21,0x48,0x22, + 0x00,0x76,0x01,0x6b,0x03,0x63,0x05,0x5d,0x07,0x58,0x09,0x54,0x0c,0x52,0x0e,0x4f,0x10,0x4d,0x11,0x4c, + 0x13,0x4a,0x15,0x49,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x01,0x71,0x02,0x69,0x05,0x63,0x07,0x5f,0x09,0x5b,0x0c,0x58,0x0e,0x55,0x10,0x53,0x11,0x52,0x13, + 0x50,0x15,0x4e,0x16,0x4e,0x18,0x4c,0x19,0x4c,0x1a,0x4a,0x1c,0x4b,0x1d,0x49,0x1e,0x49,0x1f,0x49,0x20, + 0x00,0x77,0x00,0x6c,0x02,0x65,0x04,0x5f,0x06,0x5a,0x08,0x57,0x0a,0x54,0x0c,0x51,0x0e,0x4f,0x10,0x4d, + 0x11,0x4c,0x13,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x1a,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x00,0x72,0x02,0x6b,0x04,0x64,0x06,0x61,0x08,0x5d,0x0a,0x5a,0x0c,0x56,0x0e,0x55,0x10,0x53,0x11, + 0x52,0x13,0x50,0x15,0x4f,0x16,0x4e,0x17,0x4d,0x18,0x4b,0x1a,0x4b,0x1a,0x4b,0x1c,0x4b,0x1d,0x49,0x1d, + 0x00,0x77,0x00,0x6e,0x02,0x66,0x04,0x61,0x05,0x5c,0x07,0x59,0x09,0x56,0x0b,0x53,0x0d,0x51,0x0f,0x4f, + 0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x48,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x46,0x1b,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x73,0x02,0x6c,0x03,0x66,0x05,0x63,0x07,0x5e,0x09,0x5c,0x0b,0x58,0x0c,0x57,0x0e,0x55,0x10, + 0x53,0x11,0x52,0x13,0x50,0x14,0x4f,0x15,0x4e,0x17,0x4c,0x18,0x4c,0x19,0x4c,0x1a,0x4b,0x1a,0x4b,0x1c, + 0x00,0x77,0x00,0x6f,0x02,0x68,0x03,0x63,0x05,0x5e,0x06,0x5a,0x08,0x57,0x0a,0x55,0x0b,0x53,0x0d,0x50, + 0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x19,0x46, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x74,0x02,0x6e,0x03,0x68,0x05,0x64,0x06,0x60,0x08,0x5d,0x0a,0x5a,0x0b,0x58,0x0d,0x56,0x0e, + 0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x14,0x50,0x15,0x4d,0x16,0x4e,0x18,0x4c,0x18,0x4c,0x19,0x4c,0x1a, + 0x00,0x78,0x00,0x70,0x01,0x69,0x03,0x64,0x04,0x60,0x06,0x5c,0x07,0x59,0x09,0x56,0x0b,0x54,0x0c,0x52, + 0x0d,0x50,0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x13,0x4a,0x15,0x4a,0x15,0x48,0x17,0x48,0x18,0x47, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x75,0x01,0x6f,0x02,0x69,0x04,0x65,0x06,0x62,0x07,0x5f,0x09,0x5b,0x0b,0x5a,0x0c,0x58,0x0d, + 0x56,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x13,0x4f,0x15,0x4e,0x15,0x4e,0x17,0x4d,0x18,0x4c,0x18, + 0x00,0x78,0x00,0x71,0x01,0x6a,0x03,0x66,0x04,0x61,0x05,0x5d,0x06,0x5a,0x08,0x58,0x09,0x55,0x0b,0x53, + 0x0d,0x52,0x0e,0x50,0x0f,0x4e,0x10,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4a,0x15,0x4a,0x15,0x49,0x16,0x48, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x70,0x02,0x6a,0x03,0x67,0x05,0x63,0x06,0x60,0x08,0x5d,0x09,0x5b,0x0b,0x59,0x0c, + 0x57,0x0d,0x55,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x4f,0x13,0x50,0x15,0x4f,0x15,0x4e,0x16,0x4e,0x18, + 0x00,0x79,0x00,0x71,0x01,0x6c,0x02,0x66,0x04,0x62,0x05,0x5f,0x06,0x5c,0x07,0x59,0x09,0x57,0x0a,0x55, + 0x0b,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x71,0x02,0x6c,0x03,0x68,0x05,0x64,0x06,0x61,0x07,0x5e,0x09,0x5c,0x0a,0x5a,0x0b, + 0x59,0x0c,0x57,0x0e,0x55,0x0e,0x55,0x11,0x52,0x11,0x51,0x12,0x51,0x13,0x50,0x14,0x4f,0x15,0x4e,0x15, + 0x00,0x79,0x00,0x72,0x01,0x6d,0x02,0x68,0x03,0x63,0x04,0x60,0x06,0x5d,0x07,0x5b,0x08,0x58,0x09,0x56, + 0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b,0x14,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7d,0x00,0x58,0x00,0x70,0x00,0x77, + 0x00,0x79,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x00,0x3f, + 0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x1f,0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a, + 0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x77,0x01,0x72,0x02,0x6d,0x03,0x69,0x04,0x66,0x06,0x63,0x07,0x5f,0x08,0x5e,0x09,0x5c,0x0b, + 0x5a,0x0c,0x58,0x0c,0x57,0x0e,0x55,0x0f,0x54,0x11,0x51,0x11,0x52,0x12,0x51,0x13,0x50,0x14,0x50,0x15, + 0x00,0x79,0x00,0x73,0x01,0x6d,0x02,0x69,0x03,0x65,0x04,0x61,0x05,0x5e,0x06,0x5c,0x07,0x59,0x09,0x57, + 0x0a,0x55,0x0b,0x54,0x0d,0x53,0x0d,0x51,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a, + 0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x58,0x00,0x44,0x00,0x55,0x00,0x67, + 0x00,0x6e,0x00,0x72,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d, + 0x00,0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x0a, + 0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c, + 0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x3f,0x00,0x0a,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71, + 0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x78,0x01,0x72,0x02,0x6e,0x02,0x6a,0x03,0x67,0x05,0x64,0x06,0x60,0x07,0x5f,0x09,0x5c,0x0a, + 0x5b,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0f,0x53,0x11,0x52,0x11,0x52,0x12,0x51,0x13,0x50,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6e,0x02,0x69,0x03,0x66,0x04,0x62,0x05,0x5f,0x06,0x5d,0x07,0x5b,0x08,0x58, + 0x09,0x56,0x0b,0x55,0x0b,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d,0x12,0x4c, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72, + 0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x70,0x00,0x55,0x00,0x20,0x00,0x3e, + 0x00,0x50,0x00,0x5a,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78, + 0x00,0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76, + 0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x66,0x00,0x3f,0x00,0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59, + 0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x01,0x73,0x02,0x6e,0x02,0x6b,0x03,0x68,0x05,0x65,0x06,0x61,0x07,0x5f,0x07,0x5e,0x09, + 0x5c,0x0b,0x5a,0x0b,0x59,0x0c,0x57,0x0d,0x56,0x0e,0x54,0x0f,0x54,0x11,0x52,0x11,0x52,0x12,0x51,0x13, + 0x00,0x79,0x00,0x74,0x00,0x6f,0x02,0x6a,0x03,0x66,0x04,0x63,0x05,0x60,0x05,0x5e,0x06,0x5b,0x07,0x59, + 0x09,0x58,0x09,0x55,0x0b,0x55,0x0c,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64, + 0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x77,0x00,0x67,0x00,0x3e,0x00,0x0d, + 0x00,0x28,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71, + 0x00,0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d, + 0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x72,0x00,0x5c,0x00,0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a, + 0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x00,0x74,0x01,0x6f,0x02,0x6c,0x03,0x68,0x04,0x65,0x05,0x62,0x06,0x61,0x07,0x5f,0x09, + 0x5c,0x09,0x5b,0x0b,0x5a,0x0b,0x58,0x0c,0x57,0x0d,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11,0x52,0x12, + 0x00,0x79,0x00,0x74,0x00,0x70,0x01,0x6b,0x02,0x67,0x03,0x64,0x04,0x61,0x05,0x5f,0x06,0x5d,0x07,0x5b, + 0x08,0x58,0x09,0x57,0x0a,0x55,0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54, + 0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x79,0x00,0x6e,0x00,0x50,0x00,0x28, + 0x00,0x01,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68, + 0x00,0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61, + 0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x78,0x00,0x6a,0x00,0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b, + 0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e, + 0x21,0x5d,0x0c,0x68,0x06,0x6d,0x04,0x71,0x02,0x72,0x02,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77, + 0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x7a, + 0x42,0x40,0x17,0x55,0x0c,0x60,0x08,0x66,0x05,0x6a,0x04,0x6d,0x03,0x6f,0x02,0x71,0x02,0x73,0x01,0x73, + 0x01,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x21,0x5d,0x0c,0x68,0x06,0x6d,0x04,0x71,0x02,0x72,0x02,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77, + 0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x7a, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42, + 0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x7b,0x00,0x72,0x00,0x5a,0x00,0x3a, + 0x00,0x1b,0x00,0x01,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e, + 0x00,0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53, + 0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00, + 0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65, + 0x2b,0x49,0x16,0x53,0x0d,0x5b,0x09,0x60,0x07,0x64,0x05,0x67,0x04,0x69,0x03,0x6b,0x03,0x6c,0x02,0x6e, + 0x02,0x6f,0x02,0x70,0x01,0x71,0x01,0x71,0x01,0x72,0x01,0x73,0x01,0x73,0x01,0x74,0x00,0x74,0x00,0x75, + 0x57,0x16,0x2d,0x2c,0x1b,0x3b,0x12,0x45,0x0d,0x4d,0x0b,0x53,0x08,0x57,0x07,0x5b,0x05,0x5e,0x05,0x61, + 0x04,0x63,0x04,0x65,0x03,0x67,0x02,0x68,0x02,0x69,0x02,0x6b,0x02,0x6c,0x01,0x6d,0x01,0x6e,0x01,0x6f, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x2b,0x49,0x16,0x53,0x0d,0x5b,0x09,0x60,0x07,0x64,0x05,0x67,0x04,0x69,0x03,0x6b,0x03,0x6c,0x02,0x6e, + 0x02,0x6f,0x02,0x70,0x01,0x71,0x01,0x71,0x01,0x72,0x01,0x73,0x01,0x73,0x01,0x74,0x00,0x74,0x00,0x75, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30, + 0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52, + 0x00,0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44, + 0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00, + 0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b, + 0x31,0x43,0x1d,0x4b,0x14,0x51,0x0e,0x56,0x0b,0x5b,0x08,0x5e,0x07,0x61,0x06,0x63,0x05,0x65,0x04,0x67, + 0x04,0x68,0x03,0x69,0x03,0x6a,0x03,0x6c,0x02,0x6d,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x02,0x70,0x01,0x70, + 0x61,0x0c,0x3b,0x1b,0x28,0x28,0x1d,0x32,0x16,0x3a,0x11,0x41,0x0e,0x47,0x0c,0x4b,0x0a,0x4f,0x09,0x53, + 0x07,0x55,0x06,0x58,0x05,0x5a,0x05,0x5c,0x05,0x5e,0x04,0x60,0x04,0x61,0x04,0x63,0x03,0x64,0x02,0x66, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x31,0x43,0x1d,0x4b,0x14,0x51,0x0e,0x56,0x0b,0x5b,0x08,0x5e,0x07,0x61,0x06,0x63,0x05,0x65,0x04,0x67, + 0x04,0x68,0x03,0x69,0x03,0x6a,0x03,0x6c,0x02,0x6d,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x02,0x70,0x01,0x70, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x1f, + 0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45, + 0x00,0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35, + 0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00, + 0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51, + 0x33,0x41,0x22,0x46,0x19,0x4c,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5d,0x07,0x5f,0x06,0x61, + 0x05,0x63,0x05,0x64,0x04,0x66,0x04,0x66,0x04,0x68,0x03,0x69,0x03,0x69,0x03,0x6a,0x03,0x6b,0x02,0x6c, + 0x67,0x07,0x45,0x12,0x32,0x1d,0x26,0x26,0x1e,0x2e,0x18,0x34,0x14,0x3a,0x11,0x3f,0x0f,0x44,0x0c,0x47, + 0x0b,0x4b,0x0a,0x4d,0x09,0x51,0x07,0x52,0x07,0x55,0x06,0x57,0x05,0x58,0x05,0x5a,0x05,0x5c,0x04,0x5d, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x33,0x41,0x22,0x46,0x19,0x4c,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5d,0x07,0x5f,0x06,0x61, + 0x05,0x63,0x05,0x64,0x04,0x66,0x04,0x66,0x04,0x68,0x03,0x69,0x03,0x69,0x03,0x6a,0x03,0x6b,0x02,0x6c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e, + 0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39, + 0x00,0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27, + 0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00, + 0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46, + 0x35,0x40,0x27,0x44,0x1d,0x48,0x17,0x4c,0x12,0x50,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x09,0x5a,0x08,0x5c, + 0x07,0x5e,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x65,0x04,0x66,0x04,0x66,0x04,0x67,0x03,0x68, + 0x6b,0x05,0x4d,0x0d,0x3b,0x16,0x2e,0x1e,0x25,0x25,0x1f,0x2b,0x1a,0x31,0x16,0x36,0x13,0x3a,0x10,0x3e, + 0x0f,0x42,0x0d,0x45,0x0c,0x47,0x0a,0x4a,0x0a,0x4c,0x09,0x4f,0x07,0x51,0x07,0x52,0x07,0x54,0x06,0x56, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x35,0x40,0x27,0x44,0x1d,0x48,0x17,0x4c,0x12,0x50,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x09,0x5a,0x08,0x5c, + 0x07,0x5e,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x65,0x04,0x66,0x04,0x66,0x04,0x67,0x03,0x68, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c, + 0x00,0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19, + 0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00, + 0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b, + 0x37,0x3f,0x29,0x43,0x21,0x46,0x1a,0x49,0x16,0x4d,0x12,0x50,0x10,0x52,0x0d,0x54,0x0c,0x57,0x0a,0x59, + 0x09,0x5a,0x08,0x5c,0x07,0x5d,0x06,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x64,0x04,0x65, + 0x6e,0x04,0x53,0x0a,0x41,0x11,0x34,0x18,0x2b,0x1f,0x24,0x24,0x1f,0x29,0x1b,0x2e,0x17,0x33,0x15,0x37, + 0x12,0x3a,0x10,0x3d,0x0f,0x40,0x0d,0x43,0x0c,0x45,0x0c,0x48,0x0a,0x4a,0x0a,0x4c,0x09,0x4e,0x07,0x4f, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x37,0x3f,0x29,0x43,0x21,0x46,0x1a,0x49,0x16,0x4d,0x12,0x50,0x10,0x52,0x0d,0x54,0x0c,0x57,0x0a,0x59, + 0x09,0x5a,0x08,0x5c,0x07,0x5d,0x06,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x64,0x04,0x65, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20, + 0x00,0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c, + 0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00, + 0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30, + 0x38,0x3f,0x2c,0x41,0x23,0x44,0x1d,0x47,0x19,0x4a,0x14,0x4d,0x12,0x4f,0x10,0x52,0x0e,0x54,0x0c,0x56, + 0x0b,0x57,0x0a,0x59,0x09,0x5a,0x08,0x5c,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x61,0x05,0x61,0x05,0x62, + 0x70,0x03,0x58,0x08,0x47,0x0e,0x3a,0x14,0x31,0x1a,0x29,0x1f,0x24,0x24,0x20,0x28,0x1c,0x2d,0x19,0x31, + 0x16,0x34,0x14,0x37,0x12,0x3a,0x10,0x3d,0x0f,0x3f,0x0e,0x42,0x0c,0x44,0x0c,0x46,0x0b,0x47,0x0a,0x4a, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x38,0x3f,0x2c,0x41,0x23,0x44,0x1d,0x47,0x19,0x4a,0x14,0x4d,0x12,0x4f,0x10,0x52,0x0e,0x54,0x0c,0x56, + 0x0b,0x57,0x0a,0x59,0x09,0x5a,0x08,0x5c,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x61,0x05,0x61,0x05,0x62, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x0b,0x00,0x15, + 0x00,0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00, + 0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26, + 0x39,0x3f,0x2e,0x41,0x26,0x43,0x20,0x46,0x1b,0x48,0x17,0x4b,0x14,0x4d,0x12,0x4f,0x10,0x51,0x0e,0x53, + 0x0d,0x55,0x0b,0x56,0x0b,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x60, + 0x71,0x02,0x5b,0x07,0x4c,0x0c,0x3f,0x11,0x36,0x16,0x2e,0x1b,0x29,0x20,0x24,0x23,0x20,0x28,0x1d,0x2b, + 0x19,0x2f,0x17,0x32,0x16,0x35,0x12,0x37,0x12,0x3a,0x10,0x3c,0x0f,0x3f,0x0e,0x41,0x0c,0x42,0x0c,0x45, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x39,0x3f,0x2e,0x41,0x26,0x43,0x20,0x46,0x1b,0x48,0x17,0x4b,0x14,0x4d,0x12,0x4f,0x10,0x51,0x0e,0x53, + 0x0d,0x55,0x0b,0x56,0x0b,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x60, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x0a, + 0x00,0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00, + 0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b, + 0x39,0x3e,0x2f,0x40,0x28,0x42,0x22,0x45,0x1d,0x47,0x19,0x49,0x16,0x4b,0x14,0x4d,0x11,0x4f,0x10,0x51, + 0x0f,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5c,0x07,0x5e, + 0x73,0x02,0x5e,0x05,0x4f,0x0a,0x44,0x0f,0x3a,0x13,0x33,0x18,0x2d,0x1c,0x27,0x20,0x23,0x23,0x20,0x27, + 0x1d,0x2a,0x1a,0x2d,0x18,0x30,0x16,0x33,0x14,0x35,0x12,0x38,0x12,0x3a,0x10,0x3c,0x0f,0x3e,0x0f,0x41, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x39,0x3e,0x2f,0x40,0x28,0x42,0x22,0x45,0x1d,0x47,0x19,0x49,0x16,0x4b,0x14,0x4d,0x11,0x4f,0x10,0x51, + 0x0f,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5c,0x07,0x5e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x00,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00, + 0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12, + 0x3a,0x3e,0x31,0x40,0x29,0x42,0x23,0x44,0x1f,0x46,0x1b,0x48,0x18,0x4a,0x15,0x4c,0x13,0x4d,0x11,0x4f, + 0x10,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x55,0x0b,0x56,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b, + 0x74,0x01,0x62,0x05,0x53,0x08,0x47,0x0c,0x3e,0x11,0x37,0x15,0x31,0x19,0x2b,0x1d,0x27,0x20,0x23,0x23, + 0x20,0x26,0x1d,0x2a,0x1b,0x2c,0x19,0x2f,0x16,0x31,0x16,0x34,0x13,0x35,0x12,0x38,0x12,0x3b,0x0f,0x3b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3a,0x3e,0x31,0x40,0x29,0x42,0x23,0x44,0x1f,0x46,0x1b,0x48,0x18,0x4a,0x15,0x4c,0x13,0x4d,0x11,0x4f, + 0x10,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x55,0x0b,0x56,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00, + 0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08, + 0x3a,0x3e,0x32,0x3f,0x2b,0x41,0x25,0x43,0x21,0x45,0x1d,0x46,0x1a,0x48,0x17,0x4a,0x15,0x4c,0x13,0x4e, + 0x11,0x4f,0x10,0x50,0x0f,0x52,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x56,0x0b,0x58,0x09,0x58,0x09,0x59, + 0x75,0x01,0x64,0x04,0x56,0x07,0x4b,0x0b,0x42,0x0f,0x3a,0x12,0x34,0x16,0x2f,0x19,0x2a,0x1d,0x26,0x20, + 0x23,0x23,0x21,0x26,0x1d,0x29,0x1b,0x2b,0x19,0x2e,0x18,0x30,0x16,0x32,0x15,0x35,0x12,0x35,0x12,0x38, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3a,0x3e,0x32,0x3f,0x2b,0x41,0x25,0x43,0x21,0x45,0x1d,0x46,0x1a,0x48,0x17,0x4a,0x15,0x4c,0x13,0x4e, + 0x11,0x4f,0x10,0x50,0x0f,0x52,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x56,0x0b,0x58,0x09,0x58,0x09,0x59, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00, + 0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00, + 0x3b,0x3e,0x33,0x3f,0x2c,0x41,0x27,0x42,0x22,0x44,0x1f,0x45,0x1c,0x47,0x19,0x49,0x17,0x4a,0x15,0x4c, + 0x13,0x4e,0x11,0x4f,0x10,0x50,0x0f,0x51,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x55,0x0b,0x57,0x0a,0x58, + 0x76,0x01,0x66,0x04,0x58,0x06,0x4d,0x0a,0x45,0x0d,0x3e,0x10,0x37,0x14,0x32,0x17,0x2d,0x1a,0x2a,0x1d, + 0x26,0x21,0x22,0x22,0x21,0x26,0x1d,0x28,0x1c,0x2b,0x19,0x2c,0x19,0x30,0x16,0x30,0x16,0x33,0x14,0x35, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x33,0x3f,0x2c,0x41,0x27,0x42,0x22,0x44,0x1f,0x45,0x1c,0x47,0x19,0x49,0x17,0x4a,0x15,0x4c, + 0x13,0x4e,0x11,0x4f,0x10,0x50,0x0f,0x51,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x55,0x0b,0x57,0x0a,0x58, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x3e,0x33,0x3f,0x2d,0x40,0x28,0x42,0x24,0x44,0x20,0x45,0x1d,0x46,0x1a,0x48,0x18,0x49,0x16,0x4b, + 0x14,0x4c,0x13,0x4e,0x11,0x4e,0x10,0x50,0x0f,0x51,0x0f,0x53,0x0d,0x53,0x0d,0x55,0x0b,0x55,0x0b,0x56, + 0x77,0x01,0x67,0x03,0x5a,0x05,0x51,0x09,0x48,0x0c,0x40,0x0f,0x3a,0x12,0x35,0x16,0x30,0x18,0x2c,0x1b, + 0x29,0x1d,0x26,0x21,0x22,0x22,0x21,0x26,0x1d,0x27,0x1d,0x2b,0x1a,0x2b,0x19,0x2e,0x17,0x30,0x16,0x31, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x33,0x3f,0x2d,0x40,0x28,0x42,0x24,0x44,0x20,0x45,0x1d,0x46,0x1a,0x48,0x18,0x49,0x16,0x4b, + 0x14,0x4c,0x13,0x4e,0x11,0x4e,0x10,0x50,0x0f,0x51,0x0f,0x53,0x0d,0x53,0x0d,0x55,0x0b,0x55,0x0b,0x56, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x3e,0x34,0x3f,0x2e,0x40,0x29,0x41,0x25,0x43,0x21,0x44,0x1e,0x45,0x1c,0x47,0x19,0x48,0x18,0x4a, + 0x15,0x4b,0x14,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x54,0x0c,0x55, + 0x77,0x01,0x68,0x02,0x5d,0x05,0x52,0x07,0x4a,0x0a,0x43,0x0d,0x3d,0x10,0x38,0x12,0x33,0x16,0x2f,0x19, + 0x2b,0x1b,0x28,0x1d,0x26,0x21,0x22,0x22,0x21,0x26,0x1e,0x26,0x1d,0x2a,0x1a,0x2b,0x19,0x2d,0x18,0x30, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x34,0x3f,0x2e,0x40,0x29,0x41,0x25,0x43,0x21,0x44,0x1e,0x45,0x1c,0x47,0x19,0x48,0x18,0x4a, + 0x15,0x4b,0x14,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x54,0x0c,0x55, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x35,0x3f,0x2f,0x40,0x2a,0x41,0x26,0x42,0x22,0x44,0x20,0x45,0x1d,0x46,0x1b,0x48,0x18,0x48, + 0x17,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x53, + 0x77,0x00,0x6a,0x02,0x5e,0x04,0x55,0x07,0x4c,0x0a,0x45,0x0c,0x40,0x0f,0x3a,0x12,0x35,0x14,0x31,0x16, + 0x2e,0x19,0x2b,0x1c,0x27,0x1d,0x26,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x29,0x1b,0x2b,0x19,0x2b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x35,0x3f,0x2f,0x40,0x2a,0x41,0x26,0x42,0x22,0x44,0x20,0x45,0x1d,0x46,0x1b,0x48,0x18,0x48, + 0x17,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x53, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x35,0x3f,0x30,0x3f,0x2b,0x40,0x27,0x42,0x24,0x43,0x21,0x44,0x1e,0x45,0x1c,0x46,0x1a,0x48, + 0x18,0x49,0x16,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51,0x0e,0x53, + 0x78,0x00,0x6b,0x02,0x60,0x04,0x57,0x06,0x4f,0x09,0x48,0x0c,0x42,0x0e,0x3c,0x10,0x38,0x12,0x34,0x16, + 0x30,0x18,0x2d,0x19,0x2b,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x28,0x1c,0x2b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x35,0x3f,0x30,0x3f,0x2b,0x40,0x27,0x42,0x24,0x43,0x21,0x44,0x1e,0x45,0x1c,0x46,0x1a,0x48, + 0x18,0x49,0x16,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51,0x0e,0x53, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x36,0x3f,0x30,0x3f,0x2c,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x1f,0x45,0x1d,0x46,0x1b,0x47, + 0x19,0x48,0x18,0x4a,0x15,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51, + 0x78,0x00,0x6d,0x02,0x61,0x04,0x58,0x05,0x51,0x07,0x4a,0x0a,0x44,0x0c,0x3f,0x0f,0x3a,0x12,0x35,0x14, + 0x32,0x16,0x30,0x19,0x2b,0x19,0x2a,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x27, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x36,0x3f,0x30,0x3f,0x2c,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x1f,0x45,0x1d,0x46,0x1b,0x47, + 0x19,0x48,0x18,0x4a,0x15,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x31,0x3f,0x2d,0x40,0x29,0x41,0x26,0x42,0x23,0x44,0x20,0x45,0x1e,0x45,0x1c,0x46, + 0x1a,0x48,0x18,0x48,0x17,0x4a,0x15,0x4a,0x14,0x4c,0x13,0x4c,0x12,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50, + 0x78,0x00,0x6d,0x02,0x63,0x04,0x5a,0x05,0x53,0x07,0x4c,0x0a,0x46,0x0c,0x41,0x0f,0x3c,0x0f,0x38,0x12, + 0x35,0x16,0x30,0x16,0x2e,0x19,0x2b,0x1a,0x29,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1f,0x26, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x31,0x3f,0x2d,0x40,0x29,0x41,0x26,0x42,0x23,0x44,0x20,0x45,0x1e,0x45,0x1c,0x46, + 0x1a,0x48,0x18,0x48,0x17,0x4a,0x15,0x4a,0x14,0x4c,0x13,0x4c,0x12,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x32,0x3f,0x2e,0x40,0x2a,0x41,0x27,0x42,0x24,0x43,0x21,0x44,0x1f,0x45,0x1d,0x46, + 0x1b,0x47,0x1a,0x48,0x18,0x49,0x16,0x4a,0x15,0x4b,0x14,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e,0x11,0x50, + 0x78,0x00,0x6e,0x01,0x65,0x03,0x5c,0x05,0x54,0x07,0x4e,0x09,0x48,0x0b,0x43,0x0c,0x3e,0x0f,0x3b,0x12, + 0x36,0x12,0x33,0x16,0x30,0x17,0x2d,0x19,0x2b,0x1b,0x28,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x24, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x32,0x3f,0x2e,0x40,0x2a,0x41,0x27,0x42,0x24,0x43,0x21,0x44,0x1f,0x45,0x1d,0x46, + 0x1b,0x47,0x1a,0x48,0x18,0x49,0x16,0x4a,0x15,0x4b,0x14,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e,0x11,0x50, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x33,0x3f,0x2e,0x3f,0x2b,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x20,0x45,0x1e,0x45, + 0x1c,0x46,0x1b,0x48,0x19,0x48,0x18,0x4a,0x16,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e, + 0x79,0x00,0x6f,0x01,0x66,0x02,0x5d,0x04,0x56,0x06,0x4f,0x07,0x4a,0x0a,0x45,0x0c,0x41,0x0f,0x3b,0x0f, + 0x38,0x12,0x35,0x14,0x31,0x16,0x30,0x18,0x2b,0x19,0x2b,0x1c,0x27,0x1d,0x26,0x1f,0x24,0x22,0x21,0x22, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x33,0x3f,0x2e,0x3f,0x2b,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x20,0x45,0x1e,0x45, + 0x1c,0x46,0x1b,0x48,0x19,0x48,0x18,0x4a,0x16,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x62,0x00,0x6c,0x00,0x72,0x00,0x74,0x00,0x77,0x00,0x79,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7b,0x00, + 0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x7c,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x81,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x08,0x00,0x44,0x00,0x56,0x00,0x61,0x00,0x67,0x00,0x6b,0x00,0x6e,0x00,0x70,0x00,0x71,0x00,0x73,0x00, + 0x74,0x00,0x75,0x00,0x76,0x00,0x76,0x00,0x77,0x00,0x77,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00, + 0x44,0x00,0x63,0x00,0x6c,0x00,0x71,0x00,0x75,0x00,0x77,0x00,0x79,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00, + 0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7c,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x4c,0x0b,0x57,0x06,0x5f,0x03,0x63,0x02,0x68,0x02,0x6b,0x01,0x6d,0x01,0x6e,0x01,0x71,0x00,0x72,0x00, + 0x73,0x00,0x74,0x00,0x75,0x00,0x76,0x00,0x76,0x00,0x76,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x79,0x00, + 0x82,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x40,0x17,0x17,0x2c,0x0c,0x3b,0x07,0x45,0x05,0x4d,0x04,0x53,0x03,0x57,0x02,0x5c,0x02,0x5e,0x01, + 0x61,0x01,0x63,0x01,0x66,0x01,0x67,0x01,0x68,0x00,0x69,0x00,0x6b,0x00,0x6c,0x00,0x6d,0x00,0x6e,0x00, + 0x41,0x20,0x4d,0x0b,0x58,0x06,0x5e,0x03,0x64,0x02,0x68,0x02,0x6b,0x01,0x6c,0x01,0x6f,0x01,0x71,0x00, + 0x72,0x00,0x73,0x00,0x74,0x00,0x75,0x00,0x76,0x00,0x75,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x47,0x15,0x4f,0x0d,0x56,0x09,0x59,0x06,0x5f,0x05,0x62,0x04,0x65,0x03,0x67,0x02,0x69,0x02,0x6b,0x02, + 0x6c,0x02,0x6e,0x01,0x6f,0x01,0x70,0x01,0x71,0x01,0x70,0x01,0x72,0x00,0x73,0x00,0x74,0x00,0x74,0x00, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x55,0x0c,0x2c,0x1b,0x1b,0x27,0x12,0x32,0x0d,0x3a,0x0b,0x41,0x08,0x47,0x07,0x4c,0x05,0x4f,0x05, + 0x53,0x04,0x56,0x04,0x58,0x03,0x5a,0x02,0x5d,0x02,0x5e,0x02,0x60,0x02,0x61,0x01,0x63,0x01,0x64,0x01, + 0x41,0x2a,0x47,0x16,0x4f,0x0d,0x54,0x09,0x5b,0x06,0x5f,0x05,0x62,0x04,0x64,0x03,0x67,0x02,0x69,0x02, + 0x6b,0x02,0x6c,0x02,0x6e,0x01,0x6f,0x01,0x70,0x01,0x70,0x01,0x71,0x01,0x72,0x00,0x73,0x00,0x74,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x45,0x1d,0x4a,0x14,0x50,0x0e,0x54,0x0b,0x59,0x08,0x5c,0x07,0x5f,0x06,0x60,0x05,0x64,0x04,0x65,0x03, + 0x67,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02,0x6c,0x02,0x6e,0x02,0x6f,0x01,0x70,0x01,0x70,0x01, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x60,0x08,0x3b,0x12,0x28,0x1d,0x1d,0x26,0x16,0x2e,0x11,0x34,0x0e,0x3a,0x0c,0x3f,0x0a,0x44,0x08, + 0x47,0x07,0x4b,0x06,0x4d,0x05,0x51,0x05,0x52,0x04,0x55,0x04,0x57,0x04,0x58,0x04,0x5a,0x03,0x5c,0x02, + 0x42,0x30,0x45,0x1d,0x4b,0x14,0x4f,0x0e,0x55,0x0b,0x59,0x08,0x5c,0x07,0x5e,0x06,0x61,0x05,0x64,0x04, + 0x65,0x03,0x67,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6b,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x01,0x70,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x44,0x22,0x48,0x19,0x4d,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5c,0x07,0x5f,0x06,0x61,0x05, + 0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x68,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02,0x6d,0x02, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x66,0x05,0x45,0x0d,0x32,0x16,0x26,0x1e,0x1e,0x25,0x18,0x2b,0x14,0x31,0x11,0x36,0x0f,0x3a,0x0c, + 0x3e,0x0b,0x42,0x0a,0x45,0x09,0x47,0x07,0x4a,0x07,0x4c,0x06,0x4f,0x05,0x51,0x05,0x52,0x05,0x54,0x04, + 0x41,0x33,0x44,0x22,0x48,0x19,0x4c,0x13,0x51,0x0f,0x54,0x0c,0x57,0x0a,0x59,0x08,0x5d,0x07,0x5f,0x06, + 0x61,0x05,0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x69,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x26,0x47,0x1d,0x4a,0x17,0x4d,0x12,0x51,0x0f,0x54,0x0d,0x56,0x0b,0x58,0x09,0x5b,0x08,0x5d,0x07, + 0x5f,0x06,0x60,0x06,0x62,0x05,0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x68,0x03,0x69,0x02, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6a,0x04,0x4d,0x0b,0x3a,0x11,0x2e,0x18,0x25,0x1f,0x1f,0x24,0x1a,0x29,0x16,0x2e,0x13,0x33,0x11, + 0x37,0x0f,0x3a,0x0d,0x3d,0x0c,0x40,0x0a,0x43,0x0a,0x45,0x09,0x48,0x07,0x4a,0x07,0x4c,0x07,0x4e,0x06, + 0x41,0x35,0x43,0x26,0x47,0x1d,0x49,0x17,0x4e,0x12,0x51,0x0f,0x54,0x0d,0x55,0x0b,0x59,0x09,0x5b,0x08, + 0x5d,0x07,0x5f,0x06,0x60,0x06,0x62,0x05,0x63,0x05,0x63,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x68,0x03, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x29,0x45,0x20,0x49,0x1a,0x4b,0x15,0x4f,0x12,0x51,0x0f,0x54,0x0d,0x55,0x0b,0x58,0x0a,0x5a,0x09, + 0x5b,0x08,0x5d,0x07,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x64,0x05,0x65,0x04,0x65,0x03,0x66,0x03, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6d,0x03,0x52,0x08,0x41,0x0e,0x34,0x14,0x2b,0x1a,0x24,0x1f,0x1f,0x24,0x1b,0x28,0x17,0x2d,0x15, + 0x31,0x12,0x34,0x10,0x37,0x0f,0x3a,0x0d,0x3d,0x0c,0x40,0x0b,0x42,0x0a,0x44,0x0a,0x46,0x09,0x47,0x07, + 0x41,0x36,0x43,0x29,0x46,0x20,0x48,0x1a,0x4c,0x15,0x4f,0x12,0x51,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x0a, + 0x5a,0x09,0x5b,0x08,0x5d,0x07,0x5f,0x06,0x60,0x06,0x60,0x05,0x62,0x05,0x64,0x05,0x65,0x04,0x65,0x03, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x2b,0x45,0x23,0x48,0x1d,0x49,0x18,0x4d,0x14,0x4f,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c,0x57,0x0b, + 0x59,0x0a,0x5a,0x09,0x5c,0x08,0x5d,0x07,0x5f,0x07,0x5f,0x06,0x61,0x06,0x62,0x05,0x63,0x05,0x64,0x05, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6f,0x02,0x57,0x07,0x47,0x0c,0x3a,0x11,0x31,0x16,0x29,0x1b,0x24,0x20,0x20,0x23,0x1c,0x28,0x19, + 0x2b,0x16,0x2f,0x14,0x32,0x12,0x35,0x10,0x38,0x0f,0x3a,0x0e,0x3c,0x0c,0x3f,0x0c,0x41,0x0b,0x42,0x0a, + 0x41,0x37,0x43,0x2b,0x45,0x23,0x47,0x1d,0x4a,0x18,0x4d,0x14,0x4f,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c, + 0x57,0x0b,0x59,0x0a,0x5a,0x09,0x5c,0x08,0x5d,0x07,0x5e,0x07,0x60,0x06,0x61,0x06,0x62,0x05,0x63,0x05, + 0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00, + 0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00, + 0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x58,0x00, + 0x70,0x00,0x77,0x00,0x79,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00, + 0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x43,0x2d,0x44,0x25,0x46,0x1f,0x48,0x1b,0x4b,0x17,0x4d,0x14,0x50,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c, + 0x57,0x0b,0x58,0x0b,0x5a,0x09,0x5b,0x09,0x5c,0x08,0x5c,0x07,0x5f,0x07,0x60,0x06,0x61,0x06,0x62,0x06, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x71,0x02,0x5b,0x05,0x4b,0x0a,0x3f,0x0f,0x36,0x13,0x2e,0x18,0x29,0x1c,0x23,0x20,0x20,0x23,0x1d, + 0x27,0x19,0x2a,0x17,0x2d,0x16,0x30,0x12,0x33,0x12,0x35,0x10,0x38,0x0f,0x3b,0x0e,0x3c,0x0c,0x3e,0x0c, + 0x41,0x38,0x43,0x2d,0x44,0x25,0x45,0x1f,0x49,0x1b,0x4b,0x17,0x4d,0x14,0x4f,0x11,0x51,0x10,0x53,0x0e, + 0x55,0x0c,0x57,0x0b,0x58,0x0b,0x5a,0x09,0x5b,0x09,0x5b,0x08,0x5e,0x07,0x5f,0x07,0x60,0x06,0x61,0x06, + 0x00,0x00,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00, + 0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00, + 0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00, + 0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x44,0x00, + 0x55,0x00,0x67,0x00,0x6e,0x00,0x72,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00, + 0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00, + 0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00, + 0x42,0x2f,0x44,0x27,0x46,0x22,0x47,0x1d,0x4a,0x19,0x4c,0x16,0x4e,0x13,0x4f,0x11,0x52,0x10,0x53,0x0e, + 0x55,0x0d,0x56,0x0c,0x58,0x0b,0x59,0x0a,0x5a,0x09,0x5b,0x09,0x5c,0x07,0x5e,0x07,0x5f,0x07,0x5f,0x06, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x73,0x01,0x5e,0x05,0x4f,0x08,0x44,0x0c,0x3a,0x10,0x33,0x15,0x2d,0x19,0x28,0x1d,0x23,0x20,0x20, + 0x23,0x1d,0x26,0x1a,0x2a,0x18,0x2c,0x16,0x2f,0x14,0x31,0x12,0x34,0x12,0x35,0x0f,0x38,0x0f,0x3b,0x0f, + 0x41,0x39,0x42,0x2f,0x44,0x27,0x45,0x22,0x48,0x1d,0x4a,0x19,0x4c,0x16,0x4d,0x14,0x50,0x11,0x52,0x10, + 0x53,0x0e,0x55,0x0d,0x56,0x0c,0x58,0x0b,0x59,0x0a,0x59,0x09,0x5c,0x09,0x5c,0x07,0x5e,0x07,0x5f,0x07, + 0x00,0x00,0x00,0x00,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00, + 0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00, + 0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00, + 0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x55,0x00, + 0x20,0x00,0x3e,0x00,0x50,0x00,0x5a,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00, + 0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00,0x48,0x00,0x59,0x00, + 0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00, + 0x42,0x30,0x44,0x29,0x45,0x23,0x46,0x1f,0x49,0x1b,0x4b,0x18,0x4c,0x15,0x4d,0x13,0x50,0x11,0x52,0x10, + 0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0b,0x59,0x0b,0x59,0x09,0x5b,0x09,0x5c,0x09,0x5c,0x07,0x5e,0x07, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x73,0x01,0x61,0x04,0x52,0x07,0x47,0x0b,0x3e,0x0f,0x37,0x12,0x31,0x16,0x2b,0x19,0x27,0x1d,0x23, + 0x20,0x20,0x23,0x1d,0x26,0x1b,0x29,0x19,0x2b,0x16,0x2e,0x16,0x30,0x13,0x32,0x12,0x35,0x12,0x36,0x0f, + 0x41,0x39,0x42,0x30,0x44,0x29,0x44,0x23,0x47,0x1f,0x49,0x1b,0x4b,0x18,0x4c,0x15,0x4e,0x13,0x50,0x11, + 0x52,0x10,0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0b,0x57,0x0b,0x5a,0x09,0x5b,0x09,0x5c,0x09,0x5c,0x07, + 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00, + 0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01, + 0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00, + 0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x00,0x67,0x00, + 0x3e,0x00,0x0d,0x00,0x28,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00, + 0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01,0x22,0x00,0x3a,0x00, + 0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00, + 0x42,0x32,0x44,0x2a,0x45,0x25,0x46,0x21,0x48,0x1d,0x4a,0x1a,0x4b,0x17,0x4c,0x15,0x4e,0x13,0x50,0x11, + 0x52,0x10,0x53,0x0e,0x55,0x0d,0x55,0x0c,0x57,0x0c,0x57,0x0b,0x5a,0x0a,0x5a,0x09,0x5b,0x09,0x5c,0x09, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x74,0x01,0x64,0x04,0x55,0x06,0x4a,0x0a,0x42,0x0d,0x3a,0x10,0x34,0x14,0x2f,0x17,0x2a,0x1a,0x26, + 0x1d,0x23,0x21,0x21,0x22,0x1d,0x26,0x1b,0x28,0x19,0x2b,0x18,0x2c,0x16,0x30,0x15,0x30,0x12,0x33,0x12, + 0x41,0x3a,0x42,0x32,0x44,0x2a,0x44,0x25,0x46,0x21,0x48,0x1d,0x4a,0x1a,0x4b,0x17,0x4d,0x15,0x4e,0x13, + 0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0d,0x55,0x0c,0x56,0x0c,0x58,0x0b,0x5a,0x0a,0x5a,0x09,0x5b,0x09, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00, + 0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00, + 0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0x00,0x6e,0x00, + 0x50,0x00,0x28,0x00,0x01,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00, + 0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22,0x00,0x00,0x1b,0x00, + 0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00, + 0x42,0x32,0x43,0x2c,0x44,0x26,0x45,0x22,0x48,0x1f,0x49,0x1b,0x4b,0x19,0x4c,0x16,0x4e,0x15,0x4f,0x13, + 0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x55,0x0c,0x56,0x0c,0x57,0x0b,0x59,0x0b,0x5a,0x0a,0x5a,0x09, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x75,0x01,0x65,0x03,0x58,0x05,0x4d,0x09,0x45,0x0c,0x3e,0x0f,0x37,0x12,0x32,0x16,0x2d,0x18,0x2a, + 0x1b,0x26,0x1d,0x22,0x21,0x21,0x22,0x1d,0x26,0x1c,0x27,0x19,0x2b,0x19,0x2b,0x16,0x2e,0x16,0x30,0x14, + 0x41,0x3a,0x42,0x32,0x43,0x2c,0x44,0x26,0x46,0x22,0x48,0x1f,0x49,0x1b,0x4a,0x19,0x4c,0x16,0x4e,0x15, + 0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x54,0x0c,0x57,0x0c,0x57,0x0b,0x59,0x0b,0x5a,0x0a, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00, + 0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00, + 0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7b,0x00,0x72,0x00, + 0x5a,0x00,0x3a,0x00,0x1b,0x00,0x01,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00, + 0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a,0x00,0x1b,0x00,0x00, + 0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00, + 0x42,0x33,0x43,0x2d,0x44,0x28,0x45,0x23,0x47,0x20,0x48,0x1d,0x4a,0x1a,0x4a,0x18,0x4c,0x16,0x4e,0x14, + 0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x54,0x0d,0x57,0x0c,0x57,0x0b,0x58,0x0b,0x5a,0x0b, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x76,0x01,0x67,0x02,0x5a,0x05,0x50,0x07,0x47,0x0a,0x40,0x0d,0x3a,0x10,0x35,0x12,0x30,0x16,0x2c, + 0x19,0x29,0x1b,0x26,0x1d,0x22,0x21,0x21,0x22,0x1d,0x26,0x1d,0x26,0x1a,0x2a,0x19,0x2b,0x17,0x2d,0x16, + 0x41,0x3b,0x42,0x33,0x43,0x2d,0x44,0x28,0x45,0x23,0x47,0x20,0x48,0x1d,0x49,0x1a,0x4b,0x18,0x4c,0x16, + 0x4e,0x14,0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x54,0x0e,0x55,0x0d,0x57,0x0c,0x57,0x0b,0x58,0x0b, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00, + 0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00, + 0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00, + 0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a,0x00,0x30,0x00,0x16, + 0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00, + 0x42,0x34,0x43,0x2e,0x44,0x29,0x45,0x25,0x46,0x21,0x48,0x1e,0x49,0x1b,0x4a,0x19,0x4c,0x17,0x4d,0x15, + 0x4e,0x14,0x50,0x13,0x50,0x11,0x52,0x11,0x52,0x0f,0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c,0x57,0x0b, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x68,0x02,0x5c,0x05,0x52,0x07,0x4a,0x0a,0x43,0x0c,0x3d,0x0f,0x37,0x12,0x33,0x14,0x2f, + 0x16,0x2b,0x19,0x28,0x1c,0x26,0x1d,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1a,0x29,0x19,0x2b,0x18, + 0x41,0x3b,0x42,0x34,0x43,0x2e,0x44,0x29,0x45,0x25,0x46,0x21,0x48,0x1e,0x48,0x1b,0x4b,0x19,0x4c,0x17, + 0x4d,0x15,0x4e,0x14,0x50,0x13,0x50,0x11,0x52,0x11,0x51,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00, + 0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00, + 0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00, + 0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56,0x00,0x3f,0x00,0x28, + 0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00, + 0x42,0x34,0x43,0x2f,0x44,0x2a,0x44,0x26,0x46,0x22,0x47,0x1f,0x48,0x1d,0x49,0x1a,0x4b,0x18,0x4c,0x17, + 0x4e,0x15,0x4e,0x13,0x50,0x13,0x50,0x11,0x52,0x11,0x51,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x69,0x02,0x5e,0x04,0x55,0x06,0x4c,0x09,0x45,0x0c,0x3f,0x0e,0x3a,0x10,0x35,0x12,0x31, + 0x16,0x2e,0x18,0x2b,0x19,0x27,0x1d,0x26,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1b,0x28,0x19, + 0x41,0x3b,0x42,0x34,0x43,0x2f,0x43,0x2a,0x45,0x26,0x46,0x22,0x47,0x1f,0x48,0x1d,0x4a,0x1a,0x4b,0x18, + 0x4c,0x17,0x4e,0x15,0x4e,0x13,0x50,0x13,0x50,0x11,0x51,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00, + 0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00, + 0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00, + 0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37, + 0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00, + 0x42,0x35,0x43,0x30,0x44,0x2b,0x44,0x27,0x45,0x24,0x46,0x21,0x48,0x1e,0x48,0x1c,0x4b,0x1a,0x4b,0x18, + 0x4c,0x16,0x4e,0x15,0x4e,0x13,0x50,0x12,0x50,0x11,0x51,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e,0x55,0x0c, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x6b,0x02,0x60,0x04,0x57,0x05,0x4f,0x07,0x48,0x0a,0x42,0x0c,0x3c,0x0f,0x38,0x12,0x34, + 0x14,0x30,0x16,0x2c,0x19,0x2b,0x19,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1c, + 0x41,0x3b,0x42,0x35,0x43,0x30,0x43,0x2b,0x44,0x27,0x45,0x24,0x46,0x21,0x47,0x1e,0x49,0x1c,0x4b,0x1a, + 0x4b,0x18,0x4c,0x16,0x4e,0x15,0x4e,0x13,0x50,0x12,0x50,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00, + 0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x0d,0x00,0x19,0x00, + 0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64,0x00,0x54,0x00,0x42, + 0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00, + 0x42,0x36,0x43,0x30,0x44,0x2c,0x44,0x28,0x45,0x25,0x46,0x22,0x48,0x1f,0x48,0x1d,0x49,0x1a,0x4b,0x19, + 0x4c,0x18,0x4d,0x15,0x4e,0x15,0x4f,0x13,0x50,0x12,0x50,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x6c,0x02,0x61,0x04,0x58,0x05,0x51,0x07,0x4a,0x0a,0x44,0x0c,0x3f,0x0f,0x3a,0x10,0x35, + 0x12,0x32,0x16,0x30,0x16,0x2b,0x19,0x2a,0x1a,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d, + 0x41,0x3b,0x42,0x36,0x43,0x30,0x43,0x2c,0x44,0x28,0x45,0x25,0x46,0x22,0x47,0x1f,0x49,0x1d,0x49,0x1a, + 0x4b,0x19,0x4c,0x18,0x4d,0x15,0x4e,0x15,0x4f,0x13,0x4f,0x12,0x51,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00, + 0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00, + 0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69,0x00,0x5b,0x00,0x4b, + 0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00, + 0x42,0x36,0x42,0x31,0x43,0x2d,0x44,0x29,0x45,0x26,0x46,0x23,0x47,0x20,0x47,0x1e,0x49,0x1c,0x4b,0x1a, + 0x4b,0x18,0x4c,0x17,0x4d,0x15,0x4e,0x14,0x4f,0x13,0x4f,0x12,0x51,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x78,0x00,0x6d,0x01,0x62,0x03,0x5a,0x05,0x52,0x07,0x4c,0x09,0x46,0x0b,0x41,0x0c,0x3c,0x0f,0x38, + 0x12,0x35,0x12,0x30,0x16,0x2e,0x17,0x2b,0x19,0x29,0x1b,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1f, + 0x41,0x3c,0x42,0x36,0x42,0x31,0x43,0x2d,0x44,0x29,0x45,0x26,0x46,0x23,0x46,0x20,0x48,0x1e,0x49,0x1c, + 0x4b,0x1a,0x4b,0x18,0x4c,0x17,0x4d,0x15,0x4e,0x14,0x4e,0x13,0x50,0x12,0x51,0x11,0x52,0x11,0x52,0x0f, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00, + 0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d,0x00,0x61,0x00,0x53, + 0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00, + 0x42,0x37,0x42,0x32,0x43,0x2d,0x44,0x2a,0x45,0x27,0x45,0x23,0x46,0x21,0x47,0x1f,0x49,0x1d,0x49,0x1a, + 0x4b,0x19,0x4c,0x18,0x4c,0x16,0x4e,0x15,0x4e,0x14,0x4f,0x13,0x50,0x12,0x51,0x11,0x52,0x11,0x52,0x0f, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x78,0x00,0x6e,0x01,0x64,0x02,0x5b,0x04,0x54,0x06,0x4e,0x07,0x47,0x0a,0x42,0x0c,0x3e,0x0f,0x3b, + 0x0f,0x35,0x12,0x33,0x14,0x30,0x16,0x2d,0x19,0x2b,0x19,0x28,0x1c,0x26,0x1d,0x25,0x1f,0x22,0x21,0x22, + 0x41,0x3c,0x42,0x37,0x42,0x32,0x43,0x2d,0x44,0x2a,0x45,0x27,0x45,0x23,0x46,0x21,0x48,0x1f,0x49,0x1d, + 0x49,0x1a,0x4b,0x19,0x4c,0x18,0x4c,0x16,0x4e,0x15,0x4d,0x14,0x50,0x13,0x50,0x12,0x51,0x11,0x52,0x11, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00, + 0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f,0x00,0x65,0x00,0x59, + 0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x61,0x20,0x4d,0x2a,0x48,0x30,0x44,0x33,0x44,0x35,0x44,0x36,0x43,0x37,0x42,0x38,0x43,0x39,0x42,0x39, + 0x42,0x3a,0x42,0x3a,0x42,0x3b,0x42,0x3b,0x42,0x3b,0x41,0x3b,0x42,0x3c,0x42,0x3c,0x42,0x3c,0x42,0x3c, + 0x04,0x3d,0x22,0x3d,0x2b,0x3d,0x30,0x3d,0x33,0x3d,0x35,0x3d,0x37,0x3d,0x38,0x3d,0x39,0x3d,0x39,0x3d, + 0x3a,0x3d,0x3a,0x3d,0x3b,0x3d,0x3b,0x3d,0x3b,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71,0x00,0x68,0x00,0x5e, + 0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00,0x09,0x00,0x12,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x6c,0x0b,0x57,0x16,0x4f,0x1d,0x4a,0x22,0x48,0x26,0x47,0x29,0x46,0x2b,0x44,0x2d,0x44,0x2f,0x44,0x30, + 0x44,0x31,0x44,0x32,0x43,0x33,0x43,0x34,0x43,0x34,0x42,0x35,0x43,0x36,0x42,0x36,0x42,0x37,0x42,0x37, + 0x00,0x5d,0x0c,0x49,0x16,0x43,0x1d,0x41,0x22,0x40,0x26,0x3f,0x29,0x3f,0x2c,0x3f,0x2e,0x3e,0x2f,0x3e, + 0x31,0x3e,0x32,0x3e,0x33,0x3e,0x33,0x3e,0x34,0x3e,0x35,0x3e,0x35,0x3e,0x36,0x3e,0x37,0x3e,0x37,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x08,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73,0x00,0x6b,0x00,0x62, + 0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09,0x00,0x00,0x08,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x72,0x06,0x5f,0x0d,0x56,0x14,0x4f,0x19,0x4d,0x1d,0x4a,0x20,0x49,0x23,0x47,0x25,0x46,0x27,0x46,0x29, + 0x45,0x2a,0x45,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2f,0x43,0x30,0x44,0x30,0x44,0x31,0x43,0x32,0x43,0x33, + 0x00,0x68,0x06,0x54,0x0d,0x4b,0x14,0x47,0x19,0x44,0x1d,0x43,0x20,0x41,0x23,0x41,0x26,0x40,0x27,0x40, + 0x29,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f,0x2f,0x3f,0x30,0x3f,0x30,0x3e,0x31,0x3e,0x32,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75,0x00,0x6e,0x00,0x65, + 0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12,0x00,0x08,0x00,0x00, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x75,0x03,0x64,0x09,0x5a,0x0e,0x54,0x13,0x51,0x17,0x4e,0x1a,0x4c,0x1d,0x49,0x1f,0x49,0x22,0x48,0x23, + 0x47,0x25,0x46,0x26,0x46,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b,0x44,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2e, + 0x00,0x6d,0x04,0x5b,0x09,0x51,0x0e,0x4c,0x13,0x48,0x17,0x46,0x1a,0x44,0x1d,0x43,0x1f,0x42,0x22,0x42, + 0x24,0x41,0x25,0x41,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00, + 0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x00,0x3f, + 0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x77,0x02,0x68,0x06,0x5f,0x0b,0x58,0x0f,0x54,0x12,0x51,0x15,0x4f,0x18,0x4c,0x1b,0x4b,0x1d,0x4a,0x1f, + 0x49,0x21,0x48,0x22,0x48,0x23,0x47,0x25,0x46,0x26,0x45,0x27,0x45,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b, + 0x00,0x70,0x02,0x60,0x07,0x56,0x0b,0x50,0x0f,0x4c,0x12,0x49,0x16,0x47,0x18,0x46,0x1b,0x45,0x1d,0x44, + 0x1f,0x43,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x40,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00, + 0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00, + 0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x0a, + 0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c, + 0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x78,0x02,0x6b,0x05,0x62,0x08,0x5b,0x0c,0x57,0x0f,0x54,0x12,0x51,0x14,0x4e,0x17,0x4d,0x19,0x4c,0x1b, + 0x4b,0x1d,0x4a,0x1e,0x49,0x20,0x48,0x21,0x48,0x22,0x46,0x24,0x46,0x25,0x46,0x26,0x46,0x27,0x45,0x27, + 0x00,0x72,0x02,0x64,0x05,0x5b,0x08,0x54,0x0c,0x50,0x0f,0x4d,0x12,0x4a,0x14,0x48,0x17,0x47,0x19,0x46, + 0x1b,0x45,0x1d,0x44,0x1f,0x44,0x20,0x42,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x41,0x27,0x40, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00, + 0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00, + 0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76, + 0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x79,0x01,0x6d,0x04,0x65,0x07,0x5e,0x0a,0x5a,0x0d,0x56,0x0f,0x54,0x12,0x51,0x14,0x4f,0x16,0x4e,0x18, + 0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x4a,0x1e,0x49,0x1f,0x48,0x21,0x48,0x22,0x48,0x23,0x47,0x23,0x46,0x25, + 0x00,0x74,0x01,0x66,0x04,0x5e,0x07,0x57,0x0a,0x53,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x49,0x16,0x48, + 0x18,0x46,0x1a,0x45,0x1b,0x45,0x1d,0x44,0x1e,0x44,0x20,0x43,0x21,0x42,0x22,0x42,0x23,0x42,0x24,0x41, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01, + 0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00, + 0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d, + 0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7a,0x01,0x6f,0x03,0x67,0x06,0x60,0x08,0x5d,0x0b,0x59,0x0d,0x56,0x10,0x53,0x11,0x51,0x14,0x50,0x15, + 0x4e,0x17,0x4d,0x19,0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x48,0x1e,0x49,0x1f,0x49,0x20,0x48,0x21,0x48,0x22, + 0x00,0x75,0x01,0x69,0x03,0x61,0x06,0x5a,0x08,0x56,0x0b,0x52,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x4a, + 0x16,0x48,0x17,0x47,0x19,0x46,0x1a,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44,0x20,0x43,0x21,0x42, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00, + 0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61, + 0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x01,0x71,0x02,0x69,0x05,0x62,0x07,0x5f,0x09,0x5b,0x0c,0x58,0x0e,0x55,0x10,0x53,0x11,0x52,0x13, + 0x50,0x15,0x4e,0x16,0x4e,0x18,0x4c,0x19,0x4c,0x1a,0x4a,0x1c,0x4b,0x1d,0x49,0x1e,0x49,0x1f,0x49,0x20, + 0x00,0x76,0x01,0x6b,0x03,0x63,0x05,0x5d,0x07,0x58,0x09,0x54,0x0c,0x52,0x0e,0x4f,0x10,0x4d,0x11,0x4c, + 0x13,0x4a,0x15,0x49,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00, + 0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53, + 0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x00,0x72,0x02,0x6b,0x04,0x64,0x06,0x61,0x08,0x5d,0x0a,0x5a,0x0c,0x56,0x0e,0x55,0x10,0x53,0x11, + 0x52,0x13,0x50,0x15,0x4f,0x16,0x4e,0x17,0x4d,0x18,0x4b,0x1a,0x4b,0x1a,0x4b,0x1c,0x4b,0x1d,0x49,0x1d, + 0x00,0x77,0x00,0x6c,0x02,0x65,0x04,0x5f,0x06,0x5a,0x08,0x57,0x0a,0x54,0x0c,0x51,0x0e,0x4f,0x10,0x4d, + 0x11,0x4c,0x13,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x1a,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00, + 0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44, + 0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x73,0x02,0x6c,0x03,0x66,0x05,0x63,0x07,0x5e,0x09,0x5c,0x0b,0x58,0x0c,0x57,0x0e,0x55,0x10, + 0x53,0x11,0x52,0x13,0x50,0x14,0x4f,0x15,0x4e,0x17,0x4c,0x18,0x4c,0x19,0x4c,0x1a,0x4b,0x1a,0x4b,0x1c, + 0x00,0x77,0x00,0x6e,0x02,0x66,0x04,0x61,0x05,0x5c,0x07,0x59,0x09,0x56,0x0b,0x53,0x0d,0x51,0x0f,0x4f, + 0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x48,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x46,0x1b,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00, + 0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35, + 0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x74,0x02,0x6e,0x03,0x68,0x05,0x64,0x06,0x60,0x08,0x5d,0x0a,0x5a,0x0b,0x58,0x0d,0x56,0x0e, + 0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x14,0x50,0x15,0x4d,0x16,0x4e,0x18,0x4c,0x18,0x4c,0x19,0x4c,0x1a, + 0x00,0x77,0x00,0x6f,0x02,0x68,0x03,0x63,0x05,0x5e,0x06,0x5a,0x08,0x57,0x0a,0x55,0x0b,0x53,0x0d,0x50, + 0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x19,0x46, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00, + 0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27, + 0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x75,0x01,0x6f,0x02,0x69,0x04,0x65,0x06,0x62,0x07,0x5f,0x09,0x5b,0x0b,0x5a,0x0c,0x58,0x0d, + 0x56,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x13,0x4f,0x15,0x4e,0x15,0x4e,0x17,0x4d,0x18,0x4c,0x18, + 0x00,0x78,0x00,0x70,0x01,0x69,0x03,0x64,0x04,0x60,0x06,0x5c,0x07,0x59,0x09,0x56,0x0b,0x54,0x0c,0x52, + 0x0d,0x50,0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x13,0x4a,0x15,0x4a,0x15,0x48,0x17,0x48,0x18,0x47, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00, + 0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19, + 0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x70,0x02,0x6a,0x03,0x67,0x05,0x63,0x06,0x60,0x08,0x5d,0x09,0x5b,0x0b,0x59,0x0c, + 0x57,0x0d,0x55,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x4f,0x13,0x50,0x15,0x4f,0x15,0x4e,0x16,0x4e,0x18, + 0x00,0x78,0x00,0x71,0x01,0x6a,0x03,0x66,0x04,0x61,0x05,0x5d,0x06,0x5a,0x08,0x58,0x09,0x55,0x0b,0x53, + 0x0d,0x52,0x0e,0x50,0x0f,0x4e,0x10,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4a,0x15,0x4a,0x15,0x49,0x16,0x48, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00, + 0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c, + 0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x71,0x02,0x6c,0x03,0x68,0x05,0x64,0x06,0x61,0x07,0x5e,0x09,0x5c,0x0a,0x5a,0x0b, + 0x59,0x0c,0x57,0x0e,0x55,0x0e,0x55,0x11,0x52,0x11,0x51,0x12,0x51,0x13,0x50,0x14,0x4f,0x15,0x4e,0x15, + 0x00,0x79,0x00,0x71,0x01,0x6c,0x02,0x66,0x04,0x62,0x05,0x5f,0x06,0x5c,0x07,0x59,0x09,0x57,0x0a,0x55, + 0x0b,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00, + 0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x77,0x01,0x72,0x02,0x6d,0x03,0x69,0x04,0x66,0x06,0x63,0x07,0x5f,0x08,0x5e,0x09,0x5c,0x0b, + 0x5a,0x0c,0x58,0x0c,0x57,0x0e,0x55,0x0f,0x54,0x11,0x51,0x11,0x52,0x12,0x51,0x13,0x50,0x14,0x50,0x15, + 0x00,0x79,0x00,0x72,0x01,0x6d,0x02,0x68,0x03,0x63,0x04,0x60,0x06,0x5d,0x07,0x5b,0x08,0x58,0x09,0x56, + 0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b,0x14,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00, + 0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x78,0x01,0x72,0x02,0x6e,0x02,0x6a,0x03,0x67,0x05,0x64,0x06,0x60,0x07,0x5f,0x09,0x5c,0x0a, + 0x5b,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0f,0x53,0x11,0x52,0x11,0x52,0x12,0x51,0x13,0x50,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6d,0x02,0x69,0x03,0x65,0x04,0x61,0x05,0x5e,0x06,0x5c,0x07,0x59,0x09,0x57, + 0x0a,0x55,0x0b,0x54,0x0d,0x53,0x0d,0x51,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x01,0x73,0x02,0x6e,0x02,0x6b,0x03,0x68,0x05,0x65,0x06,0x62,0x07,0x5f,0x07,0x5e,0x09, + 0x5c,0x0b,0x5a,0x0b,0x59,0x0c,0x57,0x0d,0x56,0x0e,0x54,0x0f,0x54,0x11,0x52,0x11,0x52,0x12,0x51,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6e,0x02,0x69,0x03,0x66,0x04,0x62,0x05,0x5f,0x06,0x5d,0x07,0x5b,0x08,0x58, + 0x09,0x56,0x0b,0x55,0x0b,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d,0x12,0x4c, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x00,0x74,0x01,0x6f,0x02,0x6c,0x03,0x68,0x04,0x65,0x05,0x62,0x06,0x61,0x07,0x5f,0x09, + 0x5c,0x09,0x5b,0x0b,0x5a,0x0b,0x58,0x0c,0x57,0x0d,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11,0x52,0x12, + 0x00,0x79,0x00,0x74,0x00,0x6f,0x02,0x6a,0x03,0x66,0x04,0x63,0x05,0x60,0x05,0x5e,0x06,0x5b,0x07,0x59, + 0x09,0x58,0x09,0x55,0x0b,0x55,0x0c,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x79,0x00,0x74,0x01,0x70,0x02,0x6c,0x03,0x69,0x03,0x66,0x05,0x63,0x06,0x62,0x07,0x5f,0x07, + 0x5e,0x09,0x5c,0x0a,0x5a,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11, + 0x00,0x79,0x00,0x74,0x00,0x70,0x01,0x6b,0x02,0x67,0x03,0x64,0x04,0x61,0x05,0x5f,0x06,0x5d,0x07,0x5b, + 0x08,0x58,0x09,0x57,0x0a,0x55,0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, +}; + +static const unsigned char kSmaaSearch[SMAA_SEARCH_W * SMAA_SEARCH_H] = { + 0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe, + 0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f, + 0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00, + 0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f, + 0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f, + 0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, +}; diff --git a/app/src/main/cpp/shaders/smaa_weights.frag b/app/src/main/cpp/shaders/smaa_weights.frag index 32e8b404cd..3d6bca5601 100644 --- a/app/src/main/cpp/shaders/smaa_weights.frag +++ b/app/src/main/cpp/shaders/smaa_weights.frag @@ -1,153 +1,25 @@ #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; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; -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; -} +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" void main() { - 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); + vec2 pixcoord; + vec4 offset[3]; + SMAABlendingWeightCalculationVS(fragTexCoord, pixcoord, offset); + outColor = SMAABlendingWeightCalculationPS(fragTexCoord, pixcoord, offset, EdgeTexture, + AreaTexture, SearchTexture, vec4(0.0)); } diff --git a/app/src/main/cpp/shaders/smaa_weights_frag.h b/app/src/main/cpp/shaders/smaa_weights_frag.h index be2681e8a2..5802838e6e 100644 --- a/app/src/main/cpp/shaders/smaa_weights_frag.h +++ b/app/src/main/cpp/shaders/smaa_weights_frag.h @@ -1,567 +1,986 @@ -// SPIR-V gerado -#pragma once + // 1116.6.0 + #pragma once const uint32_t smaa_weights_code[] = { - 0x07230203,0x00010000,0x0008000b,0x000002e6,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000004fe,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000cb,0x000000fd,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00060005,0x0000000d,0x65676465,0x76287441,0x763b3266,0x003b3266,0x00030005, - 0x0000000b,0x00007675,0x00030005,0x0000000c,0x00007870,0x00080005,0x00000012,0x74726576, - 0x6c616369,0x65676445,0x32667628,0x3266763b,0x0000003b,0x00030005,0x00000010,0x00007675, - 0x00030005,0x00000011,0x00007870,0x00080005,0x00000016,0x69726f68,0x746e6f7a,0x64456c61, - 0x76286567,0x763b3266,0x003b3266,0x00030005,0x00000014,0x00007675,0x00030005,0x00000015, - 0x00007870,0x000b0005,0x00000022,0x7361656d,0x52657275,0x76286e75,0x763b3266,0x763b3266, - 0x623b3266,0x31663b31,0x3b31623b,0x00000000,0x00040005,0x0000001c,0x6769726f,0x00006e69, - 0x00040005,0x0000001d,0x65786574,0x0000006c,0x00040005,0x0000001e,0x676e6174,0x00746e65, - 0x00060005,0x0000001f,0x74726576,0x6c616369,0x656e694c,0x00000000,0x00040005,0x00000020, - 0x696d696c,0x00000074,0x00050005,0x00000021,0x69736f70,0x65766974,0x00000000,0x00040005, - 0x00000024,0x65676465,0x00005655,0x00030005,0x00000030,0x00000065,0x00050005,0x00000034, - 0x65676445,0x74786554,0x00657275,0x00030005,0x0000004d,0x00000065,0x00040005,0x0000004e, - 0x61726170,0x0000006d,0x00040005,0x00000050,0x61726170,0x0000006d,0x00030005,0x0000005b, - 0x00000065,0x00040005,0x0000005c,0x61726170,0x0000006d,0x00040005,0x0000005e,0x61726170, - 0x0000006d,0x00030005,0x00000069,0x006e7572,0x00030005,0x0000006c,0x00000069,0x00040005, - 0x00000076,0x626f7270,0x00000065,0x00040005,0x00000083,0x65646e69,0x00000078,0x00050005, - 0x00000085,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x00000085,0x00000000,0x0063646e, - 0x00060006,0x00000085,0x00000001,0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x00000085, - 0x00000002,0x72747865,0x00000061,0x00040006,0x00000085,0x00000003,0x00646170,0x00030005, - 0x00000087,0x00006370,0x00040005,0x0000008e,0x657a6973,0x00000000,0x00040005,0x000000a3, - 0x65676465,0x00000000,0x00040005,0x000000a8,0x61726170,0x0000006d,0x00040005,0x000000aa, - 0x61726170,0x0000006d,0x00040005,0x000000ae,0x61726170,0x0000006d,0x00040005,0x000000b0, - 0x61726170,0x0000006d,0x00030005,0x000000c3,0x00007870,0x00030005,0x000000c9,0x00007675, - 0x00060005,0x000000cb,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x000000d3, - 0x00000065,0x00040005,0x000000d4,0x61726170,0x0000006d,0x00040005,0x000000d6,0x61726170, - 0x0000006d,0x00030005,0x000000d9,0x00004c64,0x00030005,0x000000dc,0x00005264,0x00030005, - 0x000000df,0x00005564,0x00030005,0x000000e2,0x00004464,0x00050005,0x000000e5,0x74726576, - 0x6c616369,0x00000000,0x00050005,0x000000e9,0x69726f68,0x746e6f7a,0x00006c61,0x00050005, - 0x000000ed,0x6f727473,0x7365676e,0x00000074,0x00050005,0x000000f1,0x65726874,0x6c6f6873, - 0x00000064,0x00050005,0x000000fd,0x4374756f,0x726f6c6f,0x00000000,0x00050005,0x00000100, - 0x6167656e,0x65766974,0x006e7552,0x00050005,0x00000101,0x69736f70,0x65766974,0x006e7552, - 0x00060005,0x00000102,0x736e7572,0x7361654d,0x64657275,0x00000000,0x00060005,0x00000109, - 0x74726576,0x6c616369,0x656e694c,0x00000000,0x00040005,0x00000112,0x67654e76,0x00000000, - 0x00040005,0x00000116,0x61726170,0x0000006d,0x00040005,0x00000118,0x61726170,0x0000006d, - 0x00040005,0x0000011a,0x61726170,0x0000006d,0x00040005,0x0000011b,0x61726170,0x0000006d, - 0x00040005,0x0000011c,0x61726170,0x0000006d,0x00040005,0x0000011e,0x61726170,0x0000006d, - 0x00040005,0x00000120,0x736f5076,0x00000000,0x00040005,0x00000124,0x61726170,0x0000006d, - 0x00040005,0x00000126,0x61726170,0x0000006d,0x00040005,0x00000128,0x61726170,0x0000006d, - 0x00040005,0x00000129,0x61726170,0x0000006d,0x00040005,0x0000012a,0x61726170,0x0000006d, - 0x00040005,0x0000012c,0x61726170,0x0000006d,0x00040005,0x0000012e,0x67654e68,0x00000000, - 0x00040005,0x00000132,0x61726170,0x0000006d,0x00040005,0x00000134,0x61726170,0x0000006d, - 0x00040005,0x00000136,0x61726170,0x0000006d,0x00040005,0x00000137,0x61726170,0x0000006d, - 0x00040005,0x00000138,0x61726170,0x0000006d,0x00040005,0x0000013a,0x61726170,0x0000006d, - 0x00040005,0x0000013c,0x736f5068,0x00000000,0x00040005,0x00000140,0x61726170,0x0000006d, - 0x00040005,0x00000142,0x61726170,0x0000006d,0x00040005,0x00000144,0x61726170,0x0000006d, - 0x00040005,0x00000145,0x61726170,0x0000006d,0x00040005,0x00000146,0x61726170,0x0000006d, - 0x00040005,0x00000148,0x61726170,0x0000006d,0x00040005,0x00000159,0x676e6174,0x00746e65, - 0x00040005,0x00000166,0x6d726f6e,0x00006c61,0x00040005,0x0000017b,0x61726170,0x0000006d, - 0x00040005,0x0000017d,0x61726170,0x0000006d,0x00040005,0x0000017f,0x61726170,0x0000006d, - 0x00040005,0x00000181,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170,0x0000006d, - 0x00040005,0x00000185,0x61726170,0x0000006d,0x00040005,0x00000187,0x61726170,0x0000006d, - 0x00040005,0x00000189,0x61726170,0x0000006d,0x00040005,0x0000018b,0x61726170,0x0000006d, - 0x00040005,0x0000018d,0x61726170,0x0000006d,0x00040005,0x0000018f,0x61726170,0x0000006d, - 0x00040005,0x00000191,0x61726170,0x0000006d,0x00040005,0x00000193,0x6e617073,0x00000000, - 0x00060005,0x00000197,0x65676465,0x666e6f43,0x6e656469,0x00006563,0x00030005,0x0000019e, - 0x0000776e,0x00040005,0x000001a8,0x61726170,0x0000006d,0x00040005,0x000001a9,0x61726170, - 0x0000006d,0x00030005,0x000001ac,0x0000656e,0x00040005,0x000001b5,0x61726170,0x0000006d, - 0x00040005,0x000001b6,0x61726170,0x0000006d,0x00030005,0x000001b9,0x00007773,0x00040005, - 0x000001c2,0x61726170,0x0000006d,0x00040005,0x000001c3,0x61726170,0x0000006d,0x00030005, - 0x000001c6,0x00006573,0x00040005,0x000001ce,0x61726170,0x0000006d,0x00040005,0x000001cf, - 0x61726170,0x0000006d,0x00070005,0x000001d2,0x456e7572,0x6f70646e,0x50746e69,0x65747461, - 0x00006e72,0x00050005,0x000001db,0x736f7263,0x676e6973,0x00000041,0x00050005,0x000001ee, - 0x736f7263,0x676e6973,0x00000042,0x00070005,0x00000201,0x736f7263,0x676e6973,0x746e6f43, - 0x74736172,0x00000000,0x00060005,0x00000206,0x736f7263,0x676e6973,0x74746150,0x006e7265, - 0x00040005,0x0000020c,0x65676465,0x006e694d,0x00040005,0x00000214,0x65676465,0x0078614d, - 0x00060005,0x0000021c,0x65676465,0x69726156,0x6f697461,0x0000006e,0x00070005,0x00000234, - 0x616c6162,0x6465636e,0x736f7243,0x676e6973,0x00000000,0x00060005,0x00000244,0x70646e65, - 0x746e696f,0x74746150,0x006e7265,0x00060005,0x00000250,0x70646e65,0x746e696f,0x61657241, - 0x00000000,0x00050005,0x00000257,0x61657261,0x67696557,0x00007468,0x00070005,0x00000260, - 0x67616964,0x6c616e6f,0x746e6f43,0x74736172,0x00000000,0x00060005,0x00000298,0x6e726f63, - 0x61467265,0x726f7463,0x00000000,0x00050005,0x000002a2,0x65736162,0x67696557,0x00007468, - 0x00070005,0x000002aa,0x67616964,0x6c616e6f,0x65727453,0x6874676e,0x00000000,0x00060005, - 0x000002ae,0x67616964,0x6c616e6f,0x74746150,0x006e7265,0x00070005,0x000002b4,0x67616964, - 0x6c616e6f,0x746e6f43,0x69756e69,0x00007974,0x00080005,0x000002b7,0x726f6873,0x61694474, - 0x616e6f67,0x6c61466c,0x6361626c,0x0000006b,0x00070005,0x000002c6,0x67616964,0x6c616e6f, - 0x6c6c6146,0x6b636162,0x00000000,0x00040005,0x000002d6,0x67696577,0x00007468,0x00040047, - 0x00000034,0x00000021,0x00000000,0x00040047,0x00000034,0x00000022,0x00000000,0x00030047, - 0x00000085,0x00000002,0x00050048,0x00000085,0x00000000,0x00000023,0x00000000,0x00050048, - 0x00000085,0x00000001,0x00000023,0x00000010,0x00050048,0x00000085,0x00000002,0x00000023, - 0x00000018,0x00050048,0x00000085,0x00000003,0x00000023,0x0000001c,0x00040047,0x000000cb, - 0x0000001e,0x00000000,0x00040047,0x000000fd,0x0000001e,0x00000000,0x00020013,0x00000002, - 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007, - 0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00040017,0x00000009, - 0x00000006,0x00000004,0x00050021,0x0000000a,0x00000009,0x00000008,0x00000008,0x00050021, - 0x0000000f,0x00000006,0x00000008,0x00000008,0x00020014,0x00000018,0x00040020,0x00000019, - 0x00000007,0x00000018,0x00040020,0x0000001a,0x00000007,0x00000006,0x00090021,0x0000001b, - 0x00000006,0x00000008,0x00000008,0x00000008,0x00000019,0x0000001a,0x00000019,0x0004002b, - 0x00000006,0x00000027,0x3f000000,0x0004002b,0x00000006,0x00000029,0x3f800000,0x0005002c, - 0x00000007,0x0000002a,0x00000029,0x00000029,0x00040020,0x0000002f,0x00000007,0x00000009, - 0x00090019,0x00000031,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, - 0x00000000,0x0003001b,0x00000032,0x00000031,0x00040020,0x00000033,0x00000000,0x00000032, - 0x0004003b,0x00000033,0x00000034,0x00000000,0x0004002b,0x00000006,0x00000037,0x00000000, - 0x00040015,0x00000039,0x00000020,0x00000000,0x0004002b,0x00000039,0x0000003a,0x00000001, - 0x0004002b,0x00000039,0x00000045,0x00000003,0x0004002b,0x00000039,0x00000053,0x00000000, - 0x0004002b,0x00000039,0x00000061,0x00000002,0x00040015,0x0000006a,0x00000020,0x00000001, - 0x00040020,0x0000006b,0x00000007,0x0000006a,0x0004002b,0x0000006a,0x0000006d,0x00000001, - 0x0004002b,0x0000006a,0x00000074,0x00000006,0x0004002b,0x00000006,0x0000007d,0xbf800000, - 0x00040017,0x00000081,0x0000006a,0x00000002,0x00040020,0x00000082,0x00000007,0x00000081, - 0x0006001e,0x00000085,0x00000009,0x00000007,0x00000006,0x00000006,0x00040020,0x00000086, - 0x00000009,0x00000085,0x0004003b,0x00000086,0x00000087,0x00000009,0x00040020,0x00000088, - 0x00000009,0x00000007,0x0004002b,0x0000006a,0x00000093,0x00000000,0x0005002c,0x00000081, - 0x00000094,0x00000093,0x00000093,0x00040017,0x00000095,0x00000018,0x00000002,0x0004002b, - 0x00000006,0x000000b6,0x3f266666,0x00040020,0x000000ca,0x00000001,0x00000007,0x0004003b, - 0x000000ca,0x000000cb,0x00000001,0x0004002b,0x00000006,0x000000f2,0x3d3851ec,0x0004002b, - 0x00000006,0x000000f4,0x3df5c28f,0x00040020,0x000000fc,0x00000003,0x00000009,0x0004003b, - 0x000000fc,0x000000fd,0x00000003,0x0007002c,0x00000009,0x000000fe,0x00000037,0x00000027, - 0x00000027,0x00000037,0x0003002a,0x00000018,0x00000103,0x00030029,0x00000018,0x0000010a, - 0x0004002b,0x00000006,0x0000019a,0x40200000,0x0004002b,0x00000006,0x00000236,0x3c23d70a, - 0x0004002b,0x00000006,0x00000253,0x3d6147ae,0x0004002b,0x00000006,0x00000258,0x3ec28f5c, - 0x0004002b,0x00000006,0x0000025c,0x40800000,0x0004002b,0x00000006,0x00000299,0x3eb33333, - 0x0004002b,0x00000006,0x0000029c,0x40400000,0x0004002b,0x00000006,0x000002c7,0x3e23d70a, - 0x0004002b,0x00000006,0x000002da,0x3ed70a3d,0x00050036,0x00000002,0x00000004,0x00000000, - 0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000008,0x000000c3,0x00000007,0x0004003b, - 0x00000008,0x000000c9,0x00000007,0x0004003b,0x0000002f,0x000000d3,0x00000007,0x0004003b, - 0x00000008,0x000000d4,0x00000007,0x0004003b,0x00000008,0x000000d6,0x00000007,0x0004003b, - 0x0000001a,0x000000d9,0x00000007,0x0004003b,0x0000001a,0x000000dc,0x00000007,0x0004003b, - 0x0000001a,0x000000df,0x00000007,0x0004003b,0x0000001a,0x000000e2,0x00000007,0x0004003b, - 0x0000001a,0x000000e5,0x00000007,0x0004003b,0x0000001a,0x000000e9,0x00000007,0x0004003b, - 0x0000001a,0x000000ed,0x00000007,0x0004003b,0x0000001a,0x000000f1,0x00000007,0x0004003b, - 0x0000001a,0x00000100,0x00000007,0x0004003b,0x0000001a,0x00000101,0x00000007,0x0004003b, - 0x00000019,0x00000102,0x00000007,0x0004003b,0x00000019,0x00000109,0x00000007,0x0004003b, - 0x0000001a,0x00000112,0x00000007,0x0004003b,0x00000008,0x00000116,0x00000007,0x0004003b, - 0x00000008,0x00000118,0x00000007,0x0004003b,0x00000008,0x0000011a,0x00000007,0x0004003b, - 0x00000019,0x0000011b,0x00000007,0x0004003b,0x0000001a,0x0000011c,0x00000007,0x0004003b, - 0x00000019,0x0000011e,0x00000007,0x0004003b,0x0000001a,0x00000120,0x00000007,0x0004003b, - 0x00000008,0x00000124,0x00000007,0x0004003b,0x00000008,0x00000126,0x00000007,0x0004003b, - 0x00000008,0x00000128,0x00000007,0x0004003b,0x00000019,0x00000129,0x00000007,0x0004003b, - 0x0000001a,0x0000012a,0x00000007,0x0004003b,0x00000019,0x0000012c,0x00000007,0x0004003b, - 0x0000001a,0x0000012e,0x00000007,0x0004003b,0x00000008,0x00000132,0x00000007,0x0004003b, - 0x00000008,0x00000134,0x00000007,0x0004003b,0x00000008,0x00000136,0x00000007,0x0004003b, - 0x00000019,0x00000137,0x00000007,0x0004003b,0x0000001a,0x00000138,0x00000007,0x0004003b, - 0x00000019,0x0000013a,0x00000007,0x0004003b,0x0000001a,0x0000013c,0x00000007,0x0004003b, - 0x00000008,0x00000140,0x00000007,0x0004003b,0x00000008,0x00000142,0x00000007,0x0004003b, - 0x00000008,0x00000144,0x00000007,0x0004003b,0x00000019,0x00000145,0x00000007,0x0004003b, - 0x0000001a,0x00000146,0x00000007,0x0004003b,0x00000019,0x00000148,0x00000007,0x0004003b, - 0x00000008,0x00000159,0x00000007,0x0004003b,0x00000008,0x0000015b,0x00000007,0x0004003b, - 0x00000008,0x00000166,0x00000007,0x0004003b,0x00000008,0x00000168,0x00000007,0x0004003b, - 0x00000008,0x0000017b,0x00000007,0x0004003b,0x00000008,0x0000017d,0x00000007,0x0004003b, - 0x00000008,0x0000017f,0x00000007,0x0004003b,0x00000019,0x00000181,0x00000007,0x0004003b, - 0x0000001a,0x00000183,0x00000007,0x0004003b,0x00000019,0x00000185,0x00000007,0x0004003b, - 0x00000008,0x00000187,0x00000007,0x0004003b,0x00000008,0x00000189,0x00000007,0x0004003b, - 0x00000008,0x0000018b,0x00000007,0x0004003b,0x00000019,0x0000018d,0x00000007,0x0004003b, - 0x0000001a,0x0000018f,0x00000007,0x0004003b,0x00000019,0x00000191,0x00000007,0x0004003b, - 0x0000001a,0x00000193,0x00000007,0x0004003b,0x0000001a,0x00000197,0x00000007,0x0004003b, - 0x0000002f,0x0000019e,0x00000007,0x0004003b,0x00000008,0x000001a8,0x00000007,0x0004003b, - 0x00000008,0x000001a9,0x00000007,0x0004003b,0x0000002f,0x000001ac,0x00000007,0x0004003b, - 0x00000008,0x000001b5,0x00000007,0x0004003b,0x00000008,0x000001b6,0x00000007,0x0004003b, - 0x0000002f,0x000001b9,0x00000007,0x0004003b,0x00000008,0x000001c2,0x00000007,0x0004003b, - 0x00000008,0x000001c3,0x00000007,0x0004003b,0x0000002f,0x000001c6,0x00000007,0x0004003b, - 0x00000008,0x000001ce,0x00000007,0x0004003b,0x00000008,0x000001cf,0x00000007,0x0004003b, - 0x0000001a,0x000001d2,0x00000007,0x0004003b,0x0000001a,0x000001db,0x00000007,0x0004003b, - 0x0000001a,0x000001dd,0x00000007,0x0004003b,0x0000001a,0x000001ee,0x00000007,0x0004003b, - 0x0000001a,0x000001f0,0x00000007,0x0004003b,0x0000001a,0x00000201,0x00000007,0x0004003b, - 0x0000001a,0x00000206,0x00000007,0x0004003b,0x0000002f,0x0000020c,0x00000007,0x0004003b, - 0x0000002f,0x00000214,0x00000007,0x0004003b,0x0000001a,0x0000021c,0x00000007,0x0004003b, - 0x0000001a,0x00000234,0x00000007,0x0004003b,0x0000001a,0x00000238,0x00000007,0x0004003b, - 0x0000001a,0x00000244,0x00000007,0x0004003b,0x0000001a,0x00000247,0x00000007,0x0004003b, - 0x0000001a,0x00000250,0x00000007,0x0004003b,0x0000001a,0x00000257,0x00000007,0x0004003b, - 0x0000001a,0x00000260,0x00000007,0x0004003b,0x0000001a,0x00000298,0x00000007,0x0004003b, - 0x0000001a,0x000002a2,0x00000007,0x0004003b,0x0000001a,0x000002aa,0x00000007,0x0004003b, - 0x0000001a,0x000002ae,0x00000007,0x0004003b,0x0000001a,0x000002b4,0x00000007,0x0004003b, - 0x0000001a,0x000002b7,0x00000007,0x0004003b,0x0000001a,0x000002c6,0x00000007,0x0004003b, - 0x0000001a,0x000002d6,0x00000007,0x00050041,0x00000088,0x000000c4,0x00000087,0x0000006d, - 0x0004003d,0x00000007,0x000000c5,0x000000c4,0x0007000c,0x00000007,0x000000c6,0x00000001, - 0x00000028,0x000000c5,0x0000002a,0x00050050,0x00000007,0x000000c7,0x00000029,0x00000029, - 0x00050088,0x00000007,0x000000c8,0x000000c7,0x000000c6,0x0003003e,0x000000c3,0x000000c8, - 0x0004003d,0x00000007,0x000000cc,0x000000cb,0x0004003d,0x00000007,0x000000cd,0x000000c3, - 0x0005008e,0x00000007,0x000000ce,0x000000cd,0x00000027,0x0004003d,0x00000007,0x000000cf, - 0x000000c3,0x0005008e,0x00000007,0x000000d0,0x000000cf,0x00000027,0x00050083,0x00000007, - 0x000000d1,0x0000002a,0x000000d0,0x0008000c,0x00000007,0x000000d2,0x00000001,0x0000002b, - 0x000000cc,0x000000ce,0x000000d1,0x0003003e,0x000000c9,0x000000d2,0x0004003d,0x00000007, - 0x000000d5,0x000000c9,0x0003003e,0x000000d4,0x000000d5,0x0004003d,0x00000007,0x000000d7, - 0x000000c3,0x0003003e,0x000000d6,0x000000d7,0x00060039,0x00000009,0x000000d8,0x0000000d, - 0x000000d4,0x000000d6,0x0003003e,0x000000d3,0x000000d8,0x00050041,0x0000001a,0x000000da, - 0x000000d3,0x00000053,0x0004003d,0x00000006,0x000000db,0x000000da,0x0003003e,0x000000d9, - 0x000000db,0x00050041,0x0000001a,0x000000dd,0x000000d3,0x0000003a,0x0004003d,0x00000006, - 0x000000de,0x000000dd,0x0003003e,0x000000dc,0x000000de,0x00050041,0x0000001a,0x000000e0, - 0x000000d3,0x00000061,0x0004003d,0x00000006,0x000000e1,0x000000e0,0x0003003e,0x000000df, - 0x000000e1,0x00050041,0x0000001a,0x000000e3,0x000000d3,0x00000045,0x0004003d,0x00000006, - 0x000000e4,0x000000e3,0x0003003e,0x000000e2,0x000000e4,0x0004003d,0x00000006,0x000000e6, - 0x000000d9,0x0004003d,0x00000006,0x000000e7,0x000000dc,0x0007000c,0x00000006,0x000000e8, - 0x00000001,0x00000028,0x000000e6,0x000000e7,0x0003003e,0x000000e5,0x000000e8,0x0004003d, - 0x00000006,0x000000ea,0x000000df,0x0004003d,0x00000006,0x000000eb,0x000000e2,0x0007000c, - 0x00000006,0x000000ec,0x00000001,0x00000028,0x000000ea,0x000000eb,0x0003003e,0x000000e9, - 0x000000ec,0x0004003d,0x00000006,0x000000ee,0x000000e5,0x0004003d,0x00000006,0x000000ef, - 0x000000e9,0x0007000c,0x00000006,0x000000f0,0x00000001,0x00000028,0x000000ee,0x000000ef, - 0x0003003e,0x000000ed,0x000000f0,0x0004003d,0x00000006,0x000000f3,0x000000ed,0x00050085, - 0x00000006,0x000000f5,0x000000f3,0x000000f4,0x0007000c,0x00000006,0x000000f6,0x00000001, - 0x00000028,0x000000f2,0x000000f5,0x0003003e,0x000000f1,0x000000f6,0x0004003d,0x00000006, - 0x000000f7,0x000000ed,0x0004003d,0x00000006,0x000000f8,0x000000f1,0x000500bc,0x00000018, - 0x000000f9,0x000000f7,0x000000f8,0x000300f7,0x000000fb,0x00000000,0x000400fa,0x000000f9, - 0x000000fa,0x000000fb,0x000200f8,0x000000fa,0x0003003e,0x000000fd,0x000000fe,0x000100fd, - 0x000200f8,0x000000fb,0x0003003e,0x00000100,0x00000037,0x0003003e,0x00000101,0x00000037, - 0x0003003e,0x00000102,0x00000103,0x0004003d,0x00000006,0x00000104,0x000000e5,0x0004003d, - 0x00000006,0x00000105,0x000000e9,0x000500ba,0x00000018,0x00000106,0x00000104,0x00000105, - 0x000300f7,0x00000108,0x00000000,0x000400fa,0x00000106,0x00000107,0x0000010b,0x000200f8, - 0x00000107,0x0003003e,0x00000109,0x0000010a,0x000200f9,0x00000108,0x000200f8,0x0000010b, - 0x0004003d,0x00000006,0x0000010c,0x000000e9,0x0004003d,0x00000006,0x0000010d,0x000000e5, - 0x000500ba,0x00000018,0x0000010e,0x0000010c,0x0000010d,0x000300f7,0x00000110,0x00000000, - 0x000400fa,0x0000010e,0x0000010f,0x00000111,0x000200f8,0x0000010f,0x0003003e,0x00000109, - 0x00000103,0x000200f9,0x00000110,0x000200f8,0x00000111,0x00050041,0x0000001a,0x00000113, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x00000114,0x00000113,0x00050050,0x00000007, - 0x00000115,0x00000037,0x00000114,0x0004003d,0x00000007,0x00000117,0x000000c9,0x0003003e, - 0x00000116,0x00000117,0x0004003d,0x00000007,0x00000119,0x000000c3,0x0003003e,0x00000118, - 0x00000119,0x0003003e,0x0000011a,0x00000115,0x0003003e,0x0000011b,0x0000010a,0x0004003d, - 0x00000006,0x0000011d,0x000000f1,0x0003003e,0x0000011c,0x0000011d,0x0003003e,0x0000011e, - 0x00000103,0x000a0039,0x00000006,0x0000011f,0x00000022,0x00000116,0x00000118,0x0000011a, - 0x0000011b,0x0000011c,0x0000011e,0x0003003e,0x00000112,0x0000011f,0x00050041,0x0000001a, - 0x00000121,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x00000122,0x00000121,0x00050050, - 0x00000007,0x00000123,0x00000037,0x00000122,0x0004003d,0x00000007,0x00000125,0x000000c9, - 0x0003003e,0x00000124,0x00000125,0x0004003d,0x00000007,0x00000127,0x000000c3,0x0003003e, - 0x00000126,0x00000127,0x0003003e,0x00000128,0x00000123,0x0003003e,0x00000129,0x0000010a, - 0x0004003d,0x00000006,0x0000012b,0x000000f1,0x0003003e,0x0000012a,0x0000012b,0x0003003e, - 0x0000012c,0x0000010a,0x000a0039,0x00000006,0x0000012d,0x00000022,0x00000124,0x00000126, - 0x00000128,0x00000129,0x0000012a,0x0000012c,0x0003003e,0x00000120,0x0000012d,0x00050041, - 0x0000001a,0x0000012f,0x000000c3,0x00000053,0x0004003d,0x00000006,0x00000130,0x0000012f, - 0x00050050,0x00000007,0x00000131,0x00000130,0x00000037,0x0004003d,0x00000007,0x00000133, - 0x000000c9,0x0003003e,0x00000132,0x00000133,0x0004003d,0x00000007,0x00000135,0x000000c3, - 0x0003003e,0x00000134,0x00000135,0x0003003e,0x00000136,0x00000131,0x0003003e,0x00000137, - 0x00000103,0x0004003d,0x00000006,0x00000139,0x000000f1,0x0003003e,0x00000138,0x00000139, - 0x0003003e,0x0000013a,0x00000103,0x000a0039,0x00000006,0x0000013b,0x00000022,0x00000132, - 0x00000134,0x00000136,0x00000137,0x00000138,0x0000013a,0x0003003e,0x0000012e,0x0000013b, - 0x00050041,0x0000001a,0x0000013d,0x000000c3,0x00000053,0x0004003d,0x00000006,0x0000013e, - 0x0000013d,0x00050050,0x00000007,0x0000013f,0x0000013e,0x00000037,0x0004003d,0x00000007, - 0x00000141,0x000000c9,0x0003003e,0x00000140,0x00000141,0x0004003d,0x00000007,0x00000143, - 0x000000c3,0x0003003e,0x00000142,0x00000143,0x0003003e,0x00000144,0x0000013f,0x0003003e, - 0x00000145,0x00000103,0x0004003d,0x00000006,0x00000147,0x000000f1,0x0003003e,0x00000146, - 0x00000147,0x0003003e,0x00000148,0x0000010a,0x000a0039,0x00000006,0x00000149,0x00000022, - 0x00000140,0x00000142,0x00000144,0x00000145,0x00000146,0x00000148,0x0003003e,0x0000013c, - 0x00000149,0x0004003d,0x00000006,0x0000014a,0x00000112,0x0004003d,0x00000006,0x0000014b, - 0x00000120,0x00050081,0x00000006,0x0000014c,0x0000014a,0x0000014b,0x0004003d,0x00000006, - 0x0000014d,0x0000012e,0x0004003d,0x00000006,0x0000014e,0x0000013c,0x00050081,0x00000006, - 0x0000014f,0x0000014d,0x0000014e,0x000500be,0x00000018,0x00000150,0x0000014c,0x0000014f, - 0x0003003e,0x00000109,0x00000150,0x0004003d,0x00000018,0x00000151,0x00000109,0x0004003d, - 0x00000006,0x00000152,0x00000112,0x0004003d,0x00000006,0x00000153,0x0000012e,0x000600a9, - 0x00000006,0x00000154,0x00000151,0x00000152,0x00000153,0x0003003e,0x00000100,0x00000154, - 0x0004003d,0x00000018,0x00000155,0x00000109,0x0004003d,0x00000006,0x00000156,0x00000120, - 0x0004003d,0x00000006,0x00000157,0x0000013c,0x000600a9,0x00000006,0x00000158,0x00000155, - 0x00000156,0x00000157,0x0003003e,0x00000101,0x00000158,0x0003003e,0x00000102,0x0000010a, - 0x000200f9,0x00000110,0x000200f8,0x00000110,0x000200f9,0x00000108,0x000200f8,0x00000108, - 0x0004003d,0x00000018,0x0000015a,0x00000109,0x000300f7,0x0000015d,0x00000000,0x000400fa, - 0x0000015a,0x0000015c,0x00000161,0x000200f8,0x0000015c,0x00050041,0x0000001a,0x0000015e, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x0000015f,0x0000015e,0x00050050,0x00000007, - 0x00000160,0x00000037,0x0000015f,0x0003003e,0x0000015b,0x00000160,0x000200f9,0x0000015d, - 0x000200f8,0x00000161,0x00050041,0x0000001a,0x00000162,0x000000c3,0x00000053,0x0004003d, - 0x00000006,0x00000163,0x00000162,0x00050050,0x00000007,0x00000164,0x00000163,0x00000037, - 0x0003003e,0x0000015b,0x00000164,0x000200f9,0x0000015d,0x000200f8,0x0000015d,0x0004003d, - 0x00000007,0x00000165,0x0000015b,0x0003003e,0x00000159,0x00000165,0x0004003d,0x00000018, - 0x00000167,0x00000109,0x000300f7,0x0000016a,0x00000000,0x000400fa,0x00000167,0x00000169, - 0x00000170,0x000200f8,0x00000169,0x0004003d,0x00000006,0x0000016b,0x000000d9,0x0004003d, - 0x00000006,0x0000016c,0x000000dc,0x000500be,0x00000018,0x0000016d,0x0000016b,0x0000016c, - 0x000600a9,0x00000006,0x0000016e,0x0000016d,0x0000007d,0x00000029,0x00050050,0x00000007, - 0x0000016f,0x0000016e,0x00000037,0x0003003e,0x00000168,0x0000016f,0x000200f9,0x0000016a, - 0x000200f8,0x00000170,0x0004003d,0x00000006,0x00000171,0x000000df,0x0004003d,0x00000006, - 0x00000172,0x000000e2,0x000500be,0x00000018,0x00000173,0x00000171,0x00000172,0x000600a9, - 0x00000006,0x00000174,0x00000173,0x0000007d,0x00000029,0x00050050,0x00000007,0x00000175, - 0x00000037,0x00000174,0x0003003e,0x00000168,0x00000175,0x000200f9,0x0000016a,0x000200f8, - 0x0000016a,0x0004003d,0x00000007,0x00000176,0x00000168,0x0003003e,0x00000166,0x00000176, - 0x0004003d,0x00000018,0x00000177,0x00000102,0x000400a8,0x00000018,0x00000178,0x00000177, - 0x000300f7,0x0000017a,0x00000000,0x000400fa,0x00000178,0x00000179,0x0000017a,0x000200f8, - 0x00000179,0x0004003d,0x00000007,0x0000017c,0x000000c9,0x0003003e,0x0000017b,0x0000017c, - 0x0004003d,0x00000007,0x0000017e,0x000000c3,0x0003003e,0x0000017d,0x0000017e,0x0004003d, - 0x00000007,0x00000180,0x00000159,0x0003003e,0x0000017f,0x00000180,0x0004003d,0x00000018, - 0x00000182,0x00000109,0x0003003e,0x00000181,0x00000182,0x0004003d,0x00000006,0x00000184, - 0x000000f1,0x0003003e,0x00000183,0x00000184,0x0003003e,0x00000185,0x00000103,0x000a0039, - 0x00000006,0x00000186,0x00000022,0x0000017b,0x0000017d,0x0000017f,0x00000181,0x00000183, - 0x00000185,0x0003003e,0x00000100,0x00000186,0x0004003d,0x00000007,0x00000188,0x000000c9, - 0x0003003e,0x00000187,0x00000188,0x0004003d,0x00000007,0x0000018a,0x000000c3,0x0003003e, - 0x00000189,0x0000018a,0x0004003d,0x00000007,0x0000018c,0x00000159,0x0003003e,0x0000018b, - 0x0000018c,0x0004003d,0x00000018,0x0000018e,0x00000109,0x0003003e,0x0000018d,0x0000018e, - 0x0004003d,0x00000006,0x00000190,0x000000f1,0x0003003e,0x0000018f,0x00000190,0x0003003e, - 0x00000191,0x0000010a,0x000a0039,0x00000006,0x00000192,0x00000022,0x00000187,0x00000189, - 0x0000018b,0x0000018d,0x0000018f,0x00000191,0x0003003e,0x00000101,0x00000192,0x000200f9, - 0x0000017a,0x000200f8,0x0000017a,0x0004003d,0x00000006,0x00000194,0x00000100,0x0004003d, - 0x00000006,0x00000195,0x00000101,0x00050081,0x00000006,0x00000196,0x00000194,0x00000195, - 0x0003003e,0x00000193,0x00000196,0x0004003d,0x00000006,0x00000198,0x000000f1,0x0004003d, - 0x00000006,0x00000199,0x000000f1,0x00050085,0x00000006,0x0000019b,0x00000199,0x0000019a, - 0x0004003d,0x00000006,0x0000019c,0x000000ed,0x0008000c,0x00000006,0x0000019d,0x00000001, - 0x00000031,0x00000198,0x0000019b,0x0000019c,0x0003003e,0x00000197,0x0000019d,0x0004003d, - 0x00000007,0x0000019f,0x000000c9,0x00050041,0x0000001a,0x000001a0,0x000000c3,0x00000053, - 0x0004003d,0x00000006,0x000001a1,0x000001a0,0x0004007f,0x00000006,0x000001a2,0x000001a1, - 0x00050041,0x0000001a,0x000001a3,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001a4, - 0x000001a3,0x0004007f,0x00000006,0x000001a5,0x000001a4,0x00050050,0x00000007,0x000001a6, - 0x000001a2,0x000001a5,0x00050081,0x00000007,0x000001a7,0x0000019f,0x000001a6,0x0003003e, - 0x000001a8,0x000001a7,0x0004003d,0x00000007,0x000001aa,0x000000c3,0x0003003e,0x000001a9, - 0x000001aa,0x00060039,0x00000009,0x000001ab,0x0000000d,0x000001a8,0x000001a9,0x0003003e, - 0x0000019e,0x000001ab,0x0004003d,0x00000007,0x000001ad,0x000000c9,0x00050041,0x0000001a, - 0x000001ae,0x000000c3,0x00000053,0x0004003d,0x00000006,0x000001af,0x000001ae,0x00050041, - 0x0000001a,0x000001b0,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001b1,0x000001b0, - 0x0004007f,0x00000006,0x000001b2,0x000001b1,0x00050050,0x00000007,0x000001b3,0x000001af, - 0x000001b2,0x00050081,0x00000007,0x000001b4,0x000001ad,0x000001b3,0x0003003e,0x000001b5, - 0x000001b4,0x0004003d,0x00000007,0x000001b7,0x000000c3,0x0003003e,0x000001b6,0x000001b7, - 0x00060039,0x00000009,0x000001b8,0x0000000d,0x000001b5,0x000001b6,0x0003003e,0x000001ac, - 0x000001b8,0x0004003d,0x00000007,0x000001ba,0x000000c9,0x00050041,0x0000001a,0x000001bb, - 0x000000c3,0x00000053,0x0004003d,0x00000006,0x000001bc,0x000001bb,0x0004007f,0x00000006, - 0x000001bd,0x000001bc,0x00050041,0x0000001a,0x000001be,0x000000c3,0x0000003a,0x0004003d, - 0x00000006,0x000001bf,0x000001be,0x00050050,0x00000007,0x000001c0,0x000001bd,0x000001bf, - 0x00050081,0x00000007,0x000001c1,0x000001ba,0x000001c0,0x0003003e,0x000001c2,0x000001c1, - 0x0004003d,0x00000007,0x000001c4,0x000000c3,0x0003003e,0x000001c3,0x000001c4,0x00060039, - 0x00000009,0x000001c5,0x0000000d,0x000001c2,0x000001c3,0x0003003e,0x000001b9,0x000001c5, - 0x0004003d,0x00000007,0x000001c7,0x000000c9,0x00050041,0x0000001a,0x000001c8,0x000000c3, - 0x00000053,0x0004003d,0x00000006,0x000001c9,0x000001c8,0x00050041,0x0000001a,0x000001ca, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001cb,0x000001ca,0x00050050,0x00000007, - 0x000001cc,0x000001c9,0x000001cb,0x00050081,0x00000007,0x000001cd,0x000001c7,0x000001cc, - 0x0003003e,0x000001ce,0x000001cd,0x0004003d,0x00000007,0x000001d0,0x000000c3,0x0003003e, - 0x000001cf,0x000001d0,0x00060039,0x00000009,0x000001d1,0x0000000d,0x000001ce,0x000001cf, - 0x0003003e,0x000001c6,0x000001d1,0x0004003d,0x00000006,0x000001d3,0x00000100,0x0004003d, - 0x00000006,0x000001d4,0x00000101,0x00050083,0x00000006,0x000001d5,0x000001d3,0x000001d4, - 0x0006000c,0x00000006,0x000001d6,0x00000001,0x00000004,0x000001d5,0x0004003d,0x00000006, - 0x000001d7,0x00000193,0x0007000c,0x00000006,0x000001d8,0x00000001,0x00000028,0x000001d7, - 0x00000029,0x00050088,0x00000006,0x000001d9,0x000001d6,0x000001d8,0x0008000c,0x00000006, - 0x000001da,0x00000001,0x0000002b,0x000001d9,0x00000037,0x00000029,0x0003003e,0x000001d2, - 0x000001da,0x0004003d,0x00000018,0x000001dc,0x00000109,0x000300f7,0x000001df,0x00000000, - 0x000400fa,0x000001dc,0x000001de,0x000001e6,0x000200f8,0x000001de,0x00050041,0x0000001a, - 0x000001e0,0x0000019e,0x00000045,0x0004003d,0x00000006,0x000001e1,0x000001e0,0x00050041, - 0x0000001a,0x000001e2,0x000001ac,0x00000045,0x0004003d,0x00000006,0x000001e3,0x000001e2, - 0x00050083,0x00000006,0x000001e4,0x000001e1,0x000001e3,0x0006000c,0x00000006,0x000001e5, - 0x00000001,0x00000004,0x000001e4,0x0003003e,0x000001dd,0x000001e5,0x000200f9,0x000001df, - 0x000200f8,0x000001e6,0x00050041,0x0000001a,0x000001e7,0x0000019e,0x0000003a,0x0004003d, - 0x00000006,0x000001e8,0x000001e7,0x00050041,0x0000001a,0x000001e9,0x000001b9,0x0000003a, - 0x0004003d,0x00000006,0x000001ea,0x000001e9,0x00050083,0x00000006,0x000001eb,0x000001e8, - 0x000001ea,0x0006000c,0x00000006,0x000001ec,0x00000001,0x00000004,0x000001eb,0x0003003e, - 0x000001dd,0x000001ec,0x000200f9,0x000001df,0x000200f8,0x000001df,0x0004003d,0x00000006, - 0x000001ed,0x000001dd,0x0003003e,0x000001db,0x000001ed,0x0004003d,0x00000018,0x000001ef, - 0x00000109,0x000300f7,0x000001f2,0x00000000,0x000400fa,0x000001ef,0x000001f1,0x000001f9, - 0x000200f8,0x000001f1,0x00050041,0x0000001a,0x000001f3,0x000001b9,0x00000061,0x0004003d, - 0x00000006,0x000001f4,0x000001f3,0x00050041,0x0000001a,0x000001f5,0x000001c6,0x00000061, - 0x0004003d,0x00000006,0x000001f6,0x000001f5,0x00050083,0x00000006,0x000001f7,0x000001f4, - 0x000001f6,0x0006000c,0x00000006,0x000001f8,0x00000001,0x00000004,0x000001f7,0x0003003e, - 0x000001f0,0x000001f8,0x000200f9,0x000001f2,0x000200f8,0x000001f9,0x00050041,0x0000001a, - 0x000001fa,0x000001ac,0x00000053,0x0004003d,0x00000006,0x000001fb,0x000001fa,0x00050041, - 0x0000001a,0x000001fc,0x000001c6,0x00000053,0x0004003d,0x00000006,0x000001fd,0x000001fc, - 0x00050083,0x00000006,0x000001fe,0x000001fb,0x000001fd,0x0006000c,0x00000006,0x000001ff, - 0x00000001,0x00000004,0x000001fe,0x0003003e,0x000001f0,0x000001ff,0x000200f9,0x000001f2, - 0x000200f8,0x000001f2,0x0004003d,0x00000006,0x00000200,0x000001f0,0x0003003e,0x000001ee, - 0x00000200,0x0004003d,0x00000006,0x00000202,0x000001db,0x0004003d,0x00000006,0x00000203, - 0x000001ee,0x00050083,0x00000006,0x00000204,0x00000202,0x00000203,0x0006000c,0x00000006, - 0x00000205,0x00000001,0x00000004,0x00000204,0x0003003e,0x00000201,0x00000205,0x0004003d, - 0x00000006,0x00000207,0x000000f1,0x0004003d,0x00000006,0x00000208,0x000000f1,0x00050085, - 0x00000006,0x00000209,0x00000208,0x0000019a,0x0004003d,0x00000006,0x0000020a,0x00000201, - 0x0008000c,0x00000006,0x0000020b,0x00000001,0x00000031,0x00000207,0x00000209,0x0000020a, - 0x0003003e,0x00000206,0x0000020b,0x0004003d,0x00000009,0x0000020d,0x0000019e,0x0004003d, - 0x00000009,0x0000020e,0x000001ac,0x0007000c,0x00000009,0x0000020f,0x00000001,0x00000025, - 0x0000020d,0x0000020e,0x0004003d,0x00000009,0x00000210,0x000001b9,0x0004003d,0x00000009, - 0x00000211,0x000001c6,0x0007000c,0x00000009,0x00000212,0x00000001,0x00000025,0x00000210, - 0x00000211,0x0007000c,0x00000009,0x00000213,0x00000001,0x00000025,0x0000020f,0x00000212, - 0x0003003e,0x0000020c,0x00000213,0x0004003d,0x00000009,0x00000215,0x0000019e,0x0004003d, - 0x00000009,0x00000216,0x000001ac,0x0007000c,0x00000009,0x00000217,0x00000001,0x00000028, - 0x00000215,0x00000216,0x0004003d,0x00000009,0x00000218,0x000001b9,0x0004003d,0x00000009, - 0x00000219,0x000001c6,0x0007000c,0x00000009,0x0000021a,0x00000001,0x00000028,0x00000218, - 0x00000219,0x0007000c,0x00000009,0x0000021b,0x00000001,0x00000028,0x00000217,0x0000021a, - 0x0003003e,0x00000214,0x0000021b,0x00050041,0x0000001a,0x0000021d,0x00000214,0x00000053, - 0x0004003d,0x00000006,0x0000021e,0x0000021d,0x00050041,0x0000001a,0x0000021f,0x0000020c, - 0x00000053,0x0004003d,0x00000006,0x00000220,0x0000021f,0x00050083,0x00000006,0x00000221, - 0x0000021e,0x00000220,0x00050041,0x0000001a,0x00000222,0x00000214,0x0000003a,0x0004003d, - 0x00000006,0x00000223,0x00000222,0x00050041,0x0000001a,0x00000224,0x0000020c,0x0000003a, - 0x0004003d,0x00000006,0x00000225,0x00000224,0x00050083,0x00000006,0x00000226,0x00000223, - 0x00000225,0x0007000c,0x00000006,0x00000227,0x00000001,0x00000028,0x00000221,0x00000226, - 0x00050041,0x0000001a,0x00000228,0x00000214,0x00000061,0x0004003d,0x00000006,0x00000229, - 0x00000228,0x00050041,0x0000001a,0x0000022a,0x0000020c,0x00000061,0x0004003d,0x00000006, - 0x0000022b,0x0000022a,0x00050083,0x00000006,0x0000022c,0x00000229,0x0000022b,0x00050041, - 0x0000001a,0x0000022d,0x00000214,0x00000045,0x0004003d,0x00000006,0x0000022e,0x0000022d, - 0x00050041,0x0000001a,0x0000022f,0x0000020c,0x00000045,0x0004003d,0x00000006,0x00000230, - 0x0000022f,0x00050083,0x00000006,0x00000231,0x0000022e,0x00000230,0x0007000c,0x00000006, - 0x00000232,0x00000001,0x00000028,0x0000022c,0x00000231,0x0007000c,0x00000006,0x00000233, - 0x00000001,0x00000028,0x00000227,0x00000232,0x0003003e,0x0000021c,0x00000233,0x0004003d, - 0x00000006,0x00000235,0x0000021c,0x000500ba,0x00000018,0x00000237,0x00000235,0x00000236, - 0x000300f7,0x0000023a,0x00000000,0x000400fa,0x00000237,0x00000239,0x00000242,0x000200f8, - 0x00000239,0x0004003d,0x00000006,0x0000023b,0x000000f1,0x0004003d,0x00000006,0x0000023c, - 0x000000f1,0x00050085,0x00000006,0x0000023d,0x0000023c,0x0000019a,0x0004003d,0x00000006, - 0x0000023e,0x000001db,0x0004003d,0x00000006,0x0000023f,0x000001ee,0x0007000c,0x00000006, - 0x00000240,0x00000001,0x00000025,0x0000023e,0x0000023f,0x0008000c,0x00000006,0x00000241, - 0x00000001,0x00000031,0x0000023b,0x0000023d,0x00000240,0x0003003e,0x00000238,0x00000241, - 0x000200f9,0x0000023a,0x000200f8,0x00000242,0x0003003e,0x00000238,0x00000037,0x000200f9, - 0x0000023a,0x000200f8,0x0000023a,0x0004003d,0x00000006,0x00000243,0x00000238,0x0003003e, - 0x00000234,0x00000243,0x0004003d,0x00000006,0x00000245,0x000001d2,0x000500ba,0x00000018, - 0x00000246,0x00000245,0x00000236,0x000300f7,0x00000249,0x00000000,0x000400fa,0x00000246, - 0x00000248,0x0000024d,0x000200f8,0x00000248,0x0004003d,0x00000006,0x0000024a,0x000001d2, - 0x0004003d,0x00000006,0x0000024b,0x00000234,0x0007000c,0x00000006,0x0000024c,0x00000001, - 0x00000028,0x0000024a,0x0000024b,0x0003003e,0x00000247,0x0000024c,0x000200f9,0x00000249, - 0x000200f8,0x0000024d,0x0004003d,0x00000006,0x0000024e,0x000001d2,0x0003003e,0x00000247, - 0x0000024e,0x000200f9,0x00000249,0x000200f8,0x00000249,0x0004003d,0x00000006,0x0000024f, - 0x00000247,0x0003003e,0x00000244,0x0000024f,0x0004003d,0x00000006,0x00000251,0x00000244, - 0x0004003d,0x00000006,0x00000252,0x00000193,0x00050085,0x00000006,0x00000254,0x00000252, - 0x00000253,0x00050081,0x00000006,0x00000255,0x00000029,0x00000254,0x00050088,0x00000006, - 0x00000256,0x00000251,0x00000255,0x0003003e,0x00000250,0x00000256,0x0004003d,0x00000006, - 0x00000259,0x00000206,0x00050085,0x00000006,0x0000025a,0x00000258,0x00000259,0x0004003d, - 0x00000006,0x0000025b,0x00000193,0x00050088,0x00000006,0x0000025d,0x0000025b,0x0000025c, - 0x0008000c,0x00000006,0x0000025e,0x00000001,0x0000002b,0x0000025d,0x00000037,0x00000029, - 0x00050085,0x00000006,0x0000025f,0x0000025a,0x0000025e,0x0003003e,0x00000257,0x0000025f, - 0x00050041,0x0000001a,0x00000261,0x0000019e,0x00000053,0x0004003d,0x00000006,0x00000262, - 0x00000261,0x00050041,0x0000001a,0x00000263,0x000001c6,0x00000053,0x0004003d,0x00000006, - 0x00000264,0x00000263,0x00050083,0x00000006,0x00000265,0x00000262,0x00000264,0x0006000c, - 0x00000006,0x00000266,0x00000001,0x00000004,0x00000265,0x00050041,0x0000001a,0x00000267, - 0x0000019e,0x0000003a,0x0004003d,0x00000006,0x00000268,0x00000267,0x00050041,0x0000001a, - 0x00000269,0x000001c6,0x0000003a,0x0004003d,0x00000006,0x0000026a,0x00000269,0x00050083, - 0x00000006,0x0000026b,0x00000268,0x0000026a,0x0006000c,0x00000006,0x0000026c,0x00000001, - 0x00000004,0x0000026b,0x0007000c,0x00000006,0x0000026d,0x00000001,0x00000028,0x00000266, - 0x0000026c,0x00050041,0x0000001a,0x0000026e,0x0000019e,0x00000061,0x0004003d,0x00000006, - 0x0000026f,0x0000026e,0x00050041,0x0000001a,0x00000270,0x000001c6,0x00000061,0x0004003d, - 0x00000006,0x00000271,0x00000270,0x00050083,0x00000006,0x00000272,0x0000026f,0x00000271, - 0x0006000c,0x00000006,0x00000273,0x00000001,0x00000004,0x00000272,0x00050041,0x0000001a, - 0x00000274,0x0000019e,0x00000045,0x0004003d,0x00000006,0x00000275,0x00000274,0x00050041, - 0x0000001a,0x00000276,0x000001c6,0x00000045,0x0004003d,0x00000006,0x00000277,0x00000276, - 0x00050083,0x00000006,0x00000278,0x00000275,0x00000277,0x0006000c,0x00000006,0x00000279, - 0x00000001,0x00000004,0x00000278,0x0007000c,0x00000006,0x0000027a,0x00000001,0x00000028, - 0x00000273,0x00000279,0x0007000c,0x00000006,0x0000027b,0x00000001,0x00000028,0x0000026d, - 0x0000027a,0x00050041,0x0000001a,0x0000027c,0x000001ac,0x00000053,0x0004003d,0x00000006, - 0x0000027d,0x0000027c,0x00050041,0x0000001a,0x0000027e,0x000001b9,0x00000053,0x0004003d, - 0x00000006,0x0000027f,0x0000027e,0x00050083,0x00000006,0x00000280,0x0000027d,0x0000027f, - 0x0006000c,0x00000006,0x00000281,0x00000001,0x00000004,0x00000280,0x00050041,0x0000001a, - 0x00000282,0x000001ac,0x0000003a,0x0004003d,0x00000006,0x00000283,0x00000282,0x00050041, - 0x0000001a,0x00000284,0x000001b9,0x0000003a,0x0004003d,0x00000006,0x00000285,0x00000284, - 0x00050083,0x00000006,0x00000286,0x00000283,0x00000285,0x0006000c,0x00000006,0x00000287, - 0x00000001,0x00000004,0x00000286,0x0007000c,0x00000006,0x00000288,0x00000001,0x00000028, - 0x00000281,0x00000287,0x00050041,0x0000001a,0x00000289,0x000001ac,0x00000061,0x0004003d, - 0x00000006,0x0000028a,0x00000289,0x00050041,0x0000001a,0x0000028b,0x000001b9,0x00000061, - 0x0004003d,0x00000006,0x0000028c,0x0000028b,0x00050083,0x00000006,0x0000028d,0x0000028a, - 0x0000028c,0x0006000c,0x00000006,0x0000028e,0x00000001,0x00000004,0x0000028d,0x00050041, - 0x0000001a,0x0000028f,0x000001ac,0x00000045,0x0004003d,0x00000006,0x00000290,0x0000028f, - 0x00050041,0x0000001a,0x00000291,0x000001b9,0x00000045,0x0004003d,0x00000006,0x00000292, - 0x00000291,0x00050083,0x00000006,0x00000293,0x00000290,0x00000292,0x0006000c,0x00000006, - 0x00000294,0x00000001,0x00000004,0x00000293,0x0007000c,0x00000006,0x00000295,0x00000001, - 0x00000028,0x0000028e,0x00000294,0x0007000c,0x00000006,0x00000296,0x00000001,0x00000028, - 0x00000288,0x00000295,0x0007000c,0x00000006,0x00000297,0x00000001,0x00000028,0x0000027b, - 0x00000296,0x0003003e,0x00000260,0x00000297,0x0004003d,0x00000006,0x0000029a,0x000000f1, - 0x0004003d,0x00000006,0x0000029b,0x000000f1,0x00050085,0x00000006,0x0000029d,0x0000029b, - 0x0000029c,0x0004003d,0x00000006,0x0000029e,0x00000260,0x0008000c,0x00000006,0x0000029f, - 0x00000001,0x00000031,0x0000029a,0x0000029d,0x0000029e,0x00050085,0x00000006,0x000002a0, - 0x00000299,0x0000029f,0x00050083,0x00000006,0x000002a1,0x00000029,0x000002a0,0x0003003e, - 0x00000298,0x000002a1,0x0004003d,0x00000006,0x000002a3,0x00000257,0x0004003d,0x00000006, - 0x000002a4,0x00000250,0x00050085,0x00000006,0x000002a5,0x000002a3,0x000002a4,0x0004003d, - 0x00000006,0x000002a6,0x00000197,0x00050085,0x00000006,0x000002a7,0x000002a5,0x000002a6, - 0x0004003d,0x00000006,0x000002a8,0x00000298,0x00050085,0x00000006,0x000002a9,0x000002a7, - 0x000002a8,0x0003003e,0x000002a2,0x000002a9,0x0004003d,0x00000006,0x000002ab,0x000000e5, - 0x0004003d,0x00000006,0x000002ac,0x000000e9,0x0007000c,0x00000006,0x000002ad,0x00000001, - 0x00000025,0x000002ab,0x000002ac,0x0003003e,0x000002aa,0x000002ad,0x0004003d,0x00000006, - 0x000002af,0x000000f1,0x0004003d,0x00000006,0x000002b0,0x000000f1,0x00050085,0x00000006, - 0x000002b1,0x000002b0,0x0000019a,0x0004003d,0x00000006,0x000002b2,0x000002aa,0x0008000c, - 0x00000006,0x000002b3,0x00000001,0x00000031,0x000002af,0x000002b1,0x000002b2,0x0003003e, - 0x000002ae,0x000002b3,0x0004003d,0x00000006,0x000002b5,0x00000193,0x0008000c,0x00000006, - 0x000002b6,0x00000001,0x00000031,0x00000029,0x0000029c,0x000002b5,0x0003003e,0x000002b4, - 0x000002b6,0x0004003d,0x00000006,0x000002b8,0x00000193,0x000500ba,0x00000018,0x000002b9, - 0x000002b8,0x00000037,0x0004003d,0x00000006,0x000002ba,0x00000193,0x000500bc,0x00000018, - 0x000002bb,0x000002ba,0x00000029,0x000500a7,0x00000018,0x000002bc,0x000002b9,0x000002bb, - 0x0004003d,0x00000006,0x000002bd,0x00000201,0x0004003d,0x00000006,0x000002be,0x000000f1, - 0x000500bc,0x00000018,0x000002bf,0x000002bd,0x000002be,0x000500a7,0x00000018,0x000002c0, - 0x000002bc,0x000002bf,0x0004003d,0x00000006,0x000002c1,0x000002aa,0x0004003d,0x00000006, - 0x000002c2,0x000000f1,0x000500ba,0x00000018,0x000002c3,0x000002c1,0x000002c2,0x000500a7, - 0x00000018,0x000002c4,0x000002c0,0x000002c3,0x000600a9,0x00000006,0x000002c5,0x000002c4, - 0x00000029,0x00000037,0x0003003e,0x000002b7,0x000002c5,0x0004003d,0x00000006,0x000002c8, - 0x000002ae,0x00050085,0x00000006,0x000002c9,0x000002c7,0x000002c8,0x0004003d,0x00000006, - 0x000002ca,0x00000197,0x00050085,0x00000006,0x000002cb,0x000002c9,0x000002ca,0x0004003d, - 0x00000006,0x000002cc,0x00000298,0x00050085,0x00000006,0x000002cd,0x000002cb,0x000002cc, - 0x0004003d,0x00000006,0x000002ce,0x000002b4,0x0004003d,0x00000006,0x000002cf,0x00000206, - 0x0004003d,0x00000006,0x000002d0,0x00000234,0x0007000c,0x00000006,0x000002d1,0x00000001, - 0x00000028,0x000002cf,0x000002d0,0x00050085,0x00000006,0x000002d2,0x000002ce,0x000002d1, - 0x0004003d,0x00000006,0x000002d3,0x000002b7,0x0007000c,0x00000006,0x000002d4,0x00000001, - 0x00000028,0x000002d2,0x000002d3,0x00050085,0x00000006,0x000002d5,0x000002cd,0x000002d4, - 0x0003003e,0x000002c6,0x000002d5,0x0004003d,0x00000006,0x000002d7,0x000002a2,0x0004003d, - 0x00000006,0x000002d8,0x000002c6,0x0007000c,0x00000006,0x000002d9,0x00000001,0x00000028, - 0x000002d7,0x000002d8,0x0008000c,0x00000006,0x000002db,0x00000001,0x0000002b,0x000002d9, - 0x00000037,0x000002da,0x0003003e,0x000002d6,0x000002db,0x0004003d,0x00000006,0x000002dc, - 0x000002d6,0x00050041,0x0000001a,0x000002dd,0x00000166,0x00000053,0x0004003d,0x00000006, - 0x000002de,0x000002dd,0x00050085,0x00000006,0x000002df,0x000002de,0x00000027,0x00050081, - 0x00000006,0x000002e0,0x000002df,0x00000027,0x00050041,0x0000001a,0x000002e1,0x00000166, - 0x0000003a,0x0004003d,0x00000006,0x000002e2,0x000002e1,0x00050085,0x00000006,0x000002e3, - 0x000002e2,0x00000027,0x00050081,0x00000006,0x000002e4,0x000002e3,0x00000027,0x00070050, - 0x00000009,0x000002e5,0x000002dc,0x000002e0,0x000002e4,0x00000029,0x0003003e,0x000000fd, - 0x000002e5,0x000100fd,0x00010038,0x00050036,0x00000009,0x0000000d,0x00000000,0x0000000a, - 0x00030037,0x00000008,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8,0x0000000e, - 0x0004003b,0x00000008,0x00000024,0x00000007,0x0004003b,0x0000002f,0x00000030,0x00000007, - 0x0004003b,0x0000001a,0x00000041,0x00000007,0x0004003d,0x00000007,0x00000025,0x0000000b, - 0x0004003d,0x00000007,0x00000026,0x0000000c,0x0005008e,0x00000007,0x00000028,0x00000026, - 0x00000027,0x0004003d,0x00000007,0x0000002b,0x0000000c,0x0005008e,0x00000007,0x0000002c, - 0x0000002b,0x00000027,0x00050083,0x00000007,0x0000002d,0x0000002a,0x0000002c,0x0008000c, - 0x00000007,0x0000002e,0x00000001,0x0000002b,0x00000025,0x00000028,0x0000002d,0x0003003e, - 0x00000024,0x0000002e,0x0004003d,0x00000032,0x00000035,0x00000034,0x0004003d,0x00000007, - 0x00000036,0x00000024,0x00070058,0x00000009,0x00000038,0x00000035,0x00000036,0x00000002, - 0x00000037,0x0003003e,0x00000030,0x00000038,0x00050041,0x0000001a,0x0000003b,0x00000024, - 0x0000003a,0x0004003d,0x00000006,0x0000003c,0x0000003b,0x00050041,0x0000001a,0x0000003d, - 0x0000000c,0x0000003a,0x0004003d,0x00000006,0x0000003e,0x0000003d,0x00050083,0x00000006, - 0x0000003f,0x00000029,0x0000003e,0x000500be,0x00000018,0x00000040,0x0000003c,0x0000003f, - 0x000300f7,0x00000043,0x00000000,0x000400fa,0x00000040,0x00000042,0x00000044,0x000200f8, - 0x00000042,0x0003003e,0x00000041,0x00000037,0x000200f9,0x00000043,0x000200f8,0x00000044, - 0x00050041,0x0000001a,0x00000046,0x00000030,0x00000045,0x0004003d,0x00000006,0x00000047, - 0x00000046,0x0003003e,0x00000041,0x00000047,0x000200f9,0x00000043,0x000200f8,0x00000043, - 0x0004003d,0x00000006,0x00000048,0x00000041,0x00050041,0x0000001a,0x00000049,0x00000030, - 0x00000045,0x0003003e,0x00000049,0x00000048,0x0004003d,0x00000009,0x0000004a,0x00000030, - 0x000200fe,0x0000004a,0x00010038,0x00050036,0x00000006,0x00000012,0x00000000,0x0000000f, - 0x00030037,0x00000008,0x00000010,0x00030037,0x00000008,0x00000011,0x000200f8,0x00000013, - 0x0004003b,0x0000002f,0x0000004d,0x00000007,0x0004003b,0x00000008,0x0000004e,0x00000007, - 0x0004003b,0x00000008,0x00000050,0x00000007,0x0004003d,0x00000007,0x0000004f,0x00000010, - 0x0003003e,0x0000004e,0x0000004f,0x0004003d,0x00000007,0x00000051,0x00000011,0x0003003e, - 0x00000050,0x00000051,0x00060039,0x00000009,0x00000052,0x0000000d,0x0000004e,0x00000050, - 0x0003003e,0x0000004d,0x00000052,0x00050041,0x0000001a,0x00000054,0x0000004d,0x00000053, - 0x0004003d,0x00000006,0x00000055,0x00000054,0x00050041,0x0000001a,0x00000056,0x0000004d, - 0x0000003a,0x0004003d,0x00000006,0x00000057,0x00000056,0x0007000c,0x00000006,0x00000058, - 0x00000001,0x00000028,0x00000055,0x00000057,0x000200fe,0x00000058,0x00010038,0x00050036, - 0x00000006,0x00000016,0x00000000,0x0000000f,0x00030037,0x00000008,0x00000014,0x00030037, - 0x00000008,0x00000015,0x000200f8,0x00000017,0x0004003b,0x0000002f,0x0000005b,0x00000007, - 0x0004003b,0x00000008,0x0000005c,0x00000007,0x0004003b,0x00000008,0x0000005e,0x00000007, - 0x0004003d,0x00000007,0x0000005d,0x00000014,0x0003003e,0x0000005c,0x0000005d,0x0004003d, - 0x00000007,0x0000005f,0x00000015,0x0003003e,0x0000005e,0x0000005f,0x00060039,0x00000009, - 0x00000060,0x0000000d,0x0000005c,0x0000005e,0x0003003e,0x0000005b,0x00000060,0x00050041, - 0x0000001a,0x00000062,0x0000005b,0x00000061,0x0004003d,0x00000006,0x00000063,0x00000062, - 0x00050041,0x0000001a,0x00000064,0x0000005b,0x00000045,0x0004003d,0x00000006,0x00000065, - 0x00000064,0x0007000c,0x00000006,0x00000066,0x00000001,0x00000028,0x00000063,0x00000065, - 0x000200fe,0x00000066,0x00010038,0x00050036,0x00000006,0x00000022,0x00000000,0x0000001b, - 0x00030037,0x00000008,0x0000001c,0x00030037,0x00000008,0x0000001d,0x00030037,0x00000008, - 0x0000001e,0x00030037,0x00000019,0x0000001f,0x00030037,0x0000001a,0x00000020,0x00030037, - 0x00000019,0x00000021,0x000200f8,0x00000023,0x0004003b,0x0000001a,0x00000069,0x00000007, - 0x0004003b,0x0000006b,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000076,0x00000007, - 0x0004003b,0x00000082,0x00000083,0x00000007,0x0004003b,0x00000082,0x0000008e,0x00000007, - 0x0004003b,0x0000001a,0x000000a3,0x00000007,0x0004003b,0x0000001a,0x000000a5,0x00000007, - 0x0004003b,0x00000008,0x000000a8,0x00000007,0x0004003b,0x00000008,0x000000aa,0x00000007, - 0x0004003b,0x00000008,0x000000ae,0x00000007,0x0004003b,0x00000008,0x000000b0,0x00000007, - 0x0003003e,0x00000069,0x00000037,0x0003003e,0x0000006c,0x0000006d,0x000200f9,0x0000006e, - 0x000200f8,0x0000006e,0x000400f6,0x00000070,0x00000071,0x00000000,0x000200f9,0x00000072, - 0x000200f8,0x00000072,0x0004003d,0x0000006a,0x00000073,0x0000006c,0x000500b3,0x00000018, - 0x00000075,0x00000073,0x00000074,0x000400fa,0x00000075,0x0000006f,0x00000070,0x000200f8, - 0x0000006f,0x0004003d,0x00000007,0x00000077,0x0000001c,0x0004003d,0x00000007,0x00000078, - 0x0000001e,0x0004003d,0x0000006a,0x00000079,0x0000006c,0x0004006f,0x00000006,0x0000007a, - 0x00000079,0x0005008e,0x00000007,0x0000007b,0x00000078,0x0000007a,0x0004003d,0x00000018, - 0x0000007c,0x00000021,0x000600a9,0x00000006,0x0000007e,0x0000007c,0x00000029,0x0000007d, - 0x0005008e,0x00000007,0x0000007f,0x0000007b,0x0000007e,0x00050081,0x00000007,0x00000080, - 0x00000077,0x0000007f,0x0003003e,0x00000076,0x00000080,0x0004003d,0x00000007,0x00000084, - 0x00000076,0x00050041,0x00000088,0x00000089,0x00000087,0x0000006d,0x0004003d,0x00000007, - 0x0000008a,0x00000089,0x00050085,0x00000007,0x0000008b,0x00000084,0x0000008a,0x0006000c, - 0x00000007,0x0000008c,0x00000001,0x00000008,0x0000008b,0x0004006e,0x00000081,0x0000008d, - 0x0000008c,0x0003003e,0x00000083,0x0000008d,0x00050041,0x00000088,0x0000008f,0x00000087, - 0x0000006d,0x0004003d,0x00000007,0x00000090,0x0000008f,0x0004006e,0x00000081,0x00000091, - 0x00000090,0x0003003e,0x0000008e,0x00000091,0x0004003d,0x00000081,0x00000092,0x00000083, - 0x000500b1,0x00000095,0x00000096,0x00000092,0x00000094,0x0004009a,0x00000018,0x00000097, - 0x00000096,0x000400a8,0x00000018,0x00000098,0x00000097,0x000300f7,0x0000009a,0x00000000, - 0x000400fa,0x00000098,0x00000099,0x0000009a,0x000200f8,0x00000099,0x0004003d,0x00000081, - 0x0000009b,0x00000083,0x0004003d,0x00000081,0x0000009c,0x0000008e,0x000500af,0x00000095, - 0x0000009d,0x0000009b,0x0000009c,0x0004009a,0x00000018,0x0000009e,0x0000009d,0x000200f9, - 0x0000009a,0x000200f8,0x0000009a,0x000700f5,0x00000018,0x0000009f,0x00000097,0x0000006f, - 0x0000009e,0x00000099,0x000300f7,0x000000a1,0x00000000,0x000400fa,0x0000009f,0x000000a0, - 0x000000a1,0x000200f8,0x000000a0,0x000200f9,0x00000070,0x000200f8,0x000000a1,0x0004003d, - 0x00000018,0x000000a4,0x0000001f,0x000300f7,0x000000a7,0x00000000,0x000400fa,0x000000a4, - 0x000000a6,0x000000ad,0x000200f8,0x000000a6,0x0004003d,0x00000007,0x000000a9,0x00000076, - 0x0003003e,0x000000a8,0x000000a9,0x0004003d,0x00000007,0x000000ab,0x0000001d,0x0003003e, - 0x000000aa,0x000000ab,0x00060039,0x00000006,0x000000ac,0x00000012,0x000000a8,0x000000aa, - 0x0003003e,0x000000a5,0x000000ac,0x000200f9,0x000000a7,0x000200f8,0x000000ad,0x0004003d, - 0x00000007,0x000000af,0x00000076,0x0003003e,0x000000ae,0x000000af,0x0004003d,0x00000007, - 0x000000b1,0x0000001d,0x0003003e,0x000000b0,0x000000b1,0x00060039,0x00000006,0x000000b2, - 0x00000016,0x000000ae,0x000000b0,0x0003003e,0x000000a5,0x000000b2,0x000200f9,0x000000a7, - 0x000200f8,0x000000a7,0x0004003d,0x00000006,0x000000b3,0x000000a5,0x0003003e,0x000000a3, - 0x000000b3,0x0004003d,0x00000006,0x000000b4,0x000000a3,0x0004003d,0x00000006,0x000000b5, - 0x00000020,0x00050085,0x00000006,0x000000b7,0x000000b5,0x000000b6,0x000500bc,0x00000018, - 0x000000b8,0x000000b4,0x000000b7,0x000300f7,0x000000ba,0x00000000,0x000400fa,0x000000b8, - 0x000000b9,0x000000ba,0x000200f8,0x000000b9,0x000200f9,0x00000070,0x000200f8,0x000000ba, - 0x0004003d,0x0000006a,0x000000bc,0x0000006c,0x0004006f,0x00000006,0x000000bd,0x000000bc, - 0x0003003e,0x00000069,0x000000bd,0x000200f9,0x00000071,0x000200f8,0x00000071,0x0004003d, - 0x0000006a,0x000000be,0x0000006c,0x00050080,0x0000006a,0x000000bf,0x000000be,0x0000006d, - 0x0003003e,0x0000006c,0x000000bf,0x000200f9,0x0000006e,0x000200f8,0x00000070,0x0004003d, - 0x00000006,0x000000c0,0x00000069,0x000200fe,0x000000c0,0x00010038, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000004e7,0x000004f2,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, + 0x000e0005,0x0000001b,0x41414d53,0x6e656c42,0x676e6964,0x67696557,0x61437468,0x6c75636c, + 0x6f697461,0x2853566e,0x3b326676,0x3b326676,0x5b346676,0x003b5d33,0x00050005,0x00000018, + 0x63786574,0x64726f6f,0x00000000,0x00050005,0x00000019,0x63786970,0x64726f6f,0x00000000, + 0x00040005,0x0000001a,0x7366666f,0x00007465,0x000b0005,0x0000001f,0x41414d53,0x6f636544, + 0x69446564,0x69426761,0x656e696c,0x63417261,0x73736563,0x32667628,0x0000003b,0x00030005, + 0x0000001e,0x00000065,0x000b0005,0x00000024,0x41414d53,0x6f636544,0x69446564,0x69426761, + 0x656e696c,0x63417261,0x73736563,0x34667628,0x0000003b,0x00030005,0x00000023,0x00000065, + 0x000b0005,0x0000002e,0x41414d53,0x72616553,0x69446863,0x28316761,0x3b313273,0x3b326676, + 0x3b326676,0x3b326676,0x00000000,0x00050005,0x0000002a,0x65676465,0x78655473,0x00000000, + 0x00050005,0x0000002b,0x63786574,0x64726f6f,0x00000000,0x00030005,0x0000002c,0x00726964, + 0x00030005,0x0000002d,0x00000065,0x000b0005,0x00000034,0x41414d53,0x72616553,0x69446863, + 0x28326761,0x3b313273,0x3b326676,0x3b326676,0x3b326676,0x00000000,0x00050005,0x00000030, + 0x65676465,0x78655473,0x00000000,0x00050005,0x00000031,0x63786574,0x64726f6f,0x00000000, + 0x00030005,0x00000032,0x00726964,0x00030005,0x00000033,0x00000065,0x000a0005,0x0000003c, + 0x41414d53,0x61657241,0x67616944,0x31327328,0x3266763b,0x3266763b,0x3b31663b,0x00000000, + 0x00040005,0x00000038,0x61657261,0x00786554,0x00040005,0x00000039,0x74736964,0x00000000, + 0x00030005,0x0000003a,0x00000065,0x00040005,0x0000003b,0x7366666f,0x00007465,0x000e0005, + 0x00000044,0x41414d53,0x636c6143,0x74616c75,0x61694465,0x69655767,0x73746867,0x31327328, + 0x3132733b,0x3266763b,0x3266763b,0x3466763b,0x0000003b,0x00050005,0x0000003f,0x65676465, + 0x78655473,0x00000000,0x00040005,0x00000040,0x61657261,0x00786554,0x00050005,0x00000041, + 0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000042,0x00000065,0x00070005,0x00000043, + 0x73627573,0x6c706d61,0x646e4965,0x73656369,0x00000000,0x000a0005,0x0000004a,0x41414d53, + 0x72616553,0x654c6863,0x6874676e,0x31327328,0x3266763b,0x3b31663b,0x00000000,0x00050005, + 0x00000047,0x72616573,0x65546863,0x00000078,0x00030005,0x00000048,0x00000065,0x00040005, + 0x00000049,0x7366666f,0x00007465,0x000a0005,0x00000051,0x41414d53,0x72616553,0x4c586863, + 0x28746665,0x3b313273,0x3b313273,0x3b326676,0x003b3166,0x00050005,0x0000004d,0x65676465, + 0x78655473,0x00000000,0x00050005,0x0000004e,0x72616573,0x65546863,0x00000078,0x00050005, + 0x0000004f,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000050,0x00646e65,0x000b0005, + 0x00000057,0x41414d53,0x72616553,0x52586863,0x74686769,0x31327328,0x3132733b,0x3266763b, + 0x3b31663b,0x00000000,0x00050005,0x00000053,0x65676465,0x78655473,0x00000000,0x00050005, + 0x00000054,0x72616573,0x65546863,0x00000078,0x00050005,0x00000055,0x63786574,0x64726f6f, + 0x00000000,0x00030005,0x00000056,0x00646e65,0x000a0005,0x0000005d,0x41414d53,0x72616553, + 0x55596863,0x32732870,0x32733b31,0x66763b31,0x31663b32,0x0000003b,0x00050005,0x00000059, + 0x65676465,0x78655473,0x00000000,0x00050005,0x0000005a,0x72616573,0x65546863,0x00000078, + 0x00050005,0x0000005b,0x63786574,0x64726f6f,0x00000000,0x00030005,0x0000005c,0x00646e65, + 0x000a0005,0x00000063,0x41414d53,0x72616553,0x44596863,0x286e776f,0x3b313273,0x3b313273, + 0x3b326676,0x003b3166,0x00050005,0x0000005f,0x65676465,0x78655473,0x00000000,0x00050005, + 0x00000060,0x72616573,0x65546863,0x00000078,0x00050005,0x00000061,0x63786574,0x64726f6f, + 0x00000000,0x00030005,0x00000062,0x00646e65,0x00090005,0x0000006b,0x41414d53,0x61657241, + 0x31327328,0x3266763b,0x3b31663b,0x663b3166,0x00003b31,0x00040005,0x00000066,0x61657261, + 0x00786554,0x00040005,0x00000067,0x74736964,0x00000000,0x00030005,0x00000068,0x00003165, + 0x00030005,0x00000069,0x00003265,0x00040005,0x0000006a,0x7366666f,0x00007465,0x000f0005, + 0x00000072,0x41414d53,0x65746544,0x6f487463,0x6f7a6972,0x6c61746e,0x6e726f43,0x61507265, + 0x72657474,0x3273286e,0x66763b31,0x66763b32,0x66763b34,0x00003b32,0x00050005,0x0000006e, + 0x65676465,0x78655473,0x00000000,0x00040005,0x0000006f,0x67696577,0x00737468,0x00050005, + 0x00000070,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000071,0x00000064,0x000f0005, + 0x00000078,0x41414d53,0x65746544,0x65567463,0x63697472,0x6f436c61,0x72656e72,0x74746150, + 0x286e7265,0x3b313273,0x3b326676,0x3b346676,0x3b326676,0x00000000,0x00050005,0x00000074, + 0x65676465,0x78655473,0x00000000,0x00040005,0x00000075,0x67696577,0x00737468,0x00050005, + 0x00000076,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000077,0x00000064,0x00120005, + 0x00000082,0x41414d53,0x6e656c42,0x676e6964,0x67696557,0x61437468,0x6c75636c,0x6f697461, + 0x2853506e,0x3b326676,0x3b326676,0x5b346676,0x733b5d33,0x733b3132,0x733b3132,0x763b3132, + 0x003b3466,0x00050005,0x0000007b,0x63786574,0x64726f6f,0x00000000,0x00050005,0x0000007c, + 0x63786970,0x64726f6f,0x00000000,0x00040005,0x0000007d,0x7366666f,0x00007465,0x00050005, + 0x0000007e,0x65676465,0x78655473,0x00000000,0x00040005,0x0000007f,0x61657261,0x00786554, + 0x00050005,0x00000080,0x72616573,0x65546863,0x00000078,0x00070005,0x00000081,0x73627573, + 0x6c706d61,0x646e4965,0x73656369,0x00000000,0x00050005,0x00000096,0x736e6f43,0x746e6174, + 0x00000073,0x00040006,0x00000096,0x00000000,0x0063646e,0x00050006,0x00000096,0x00000001, + 0x7274656d,0x00736369,0x00030005,0x00000098,0x00006370,0x00040005,0x000000e9,0x726f6f63, + 0x00000064,0x00030005,0x000000f2,0x00000074,0x00040005,0x00000126,0x726f6f63,0x00000064, + 0x00030005,0x00000134,0x00000074,0x00040005,0x0000015c,0x61726170,0x0000006d,0x00050005, + 0x00000166,0x63786574,0x64726f6f,0x00000000,0x00040005,0x00000185,0x67696577,0x00737468, + 0x00030005,0x0000018c,0x00000064,0x00030005,0x0000018e,0x00646e65,0x00040005,0x0000018f, + 0x61726170,0x0000006d,0x00040005,0x00000191,0x61726170,0x0000006d,0x00040005,0x00000192, + 0x61726170,0x0000006d,0x00040005,0x000001a7,0x61726170,0x0000006d,0x00040005,0x000001a9, + 0x61726170,0x0000006d,0x00040005,0x000001aa,0x61726170,0x0000006d,0x00040005,0x000001ba, + 0x726f6f63,0x00007364,0x00030005,0x000001ce,0x00000063,0x00040005,0x000001e5,0x61726170, + 0x0000006d,0x00030005,0x000001ea,0x00006363,0x00040005,0x000001f6,0x61726170,0x0000006d, + 0x00040005,0x000001f7,0x61726170,0x0000006d,0x00040005,0x000001f9,0x61726170,0x0000006d, + 0x00040005,0x000001fc,0x61726170,0x0000006d,0x00040005,0x000001ff,0x61726170,0x0000006d, + 0x00040005,0x00000201,0x61726170,0x0000006d,0x00040005,0x00000208,0x61726170,0x0000006d, + 0x00040005,0x0000020a,0x61726170,0x0000006d,0x00040005,0x0000020b,0x61726170,0x0000006d, + 0x00040005,0x0000021a,0x61726170,0x0000006d,0x00040005,0x0000021c,0x61726170,0x0000006d, + 0x00040005,0x0000021d,0x61726170,0x0000006d,0x00040005,0x00000239,0x726f6f63,0x00007364, + 0x00030005,0x0000024b,0x00000063,0x00030005,0x00000262,0x00006363,0x00040005,0x0000026d, + 0x61726170,0x0000006d,0x00040005,0x0000026e,0x61726170,0x0000006d,0x00040005,0x00000270, + 0x61726170,0x0000006d,0x00040005,0x00000273,0x61726170,0x0000006d,0x00040005,0x00000276, + 0x61726170,0x0000006d,0x00040005,0x00000278,0x61726170,0x0000006d,0x00040005,0x00000282, + 0x6c616373,0x00000065,0x00040005,0x00000286,0x73616962,0x00000000,0x00030005,0x000002a2, + 0x00000065,0x00040005,0x000002c6,0x7366666f,0x00007465,0x00040005,0x000002c8,0x61726170, + 0x0000006d,0x00040005,0x000002ca,0x61726170,0x0000006d,0x00030005,0x000002d6,0x00000065, + 0x00040005,0x000002f6,0x7366666f,0x00007465,0x00040005,0x000002f7,0x61726170,0x0000006d, + 0x00040005,0x000002f9,0x61726170,0x0000006d,0x00030005,0x00000305,0x00000065,0x00040005, + 0x00000326,0x7366666f,0x00007465,0x00040005,0x00000327,0x61726170,0x0000006d,0x00040005, + 0x0000032a,0x61726170,0x0000006d,0x00030005,0x00000335,0x00000065,0x00040005,0x00000355, + 0x7366666f,0x00007465,0x00040005,0x00000356,0x61726170,0x0000006d,0x00040005,0x00000359, + 0x61726170,0x0000006d,0x00050005,0x00000365,0x63786574,0x64726f6f,0x00000000,0x00050005, + 0x0000037d,0x7466656c,0x68676952,0x00000074,0x00050005,0x00000382,0x6e756f72,0x676e6964, + 0x00000000,0x00040005,0x0000038e,0x74636166,0x0000726f,0x00050005,0x000003ca,0x7466656c, + 0x68676952,0x00000074,0x00050005,0x000003cf,0x6e756f72,0x676e6964,0x00000000,0x00040005, + 0x000003da,0x74636166,0x0000726f,0x00040005,0x00000413,0x67696577,0x00737468,0x00030005, + 0x00000415,0x00000065,0x00040005,0x0000041f,0x61726170,0x0000006d,0x00040005,0x00000421, + 0x61726170,0x0000006d,0x00040005,0x00000423,0x61726170,0x0000006d,0x00040005,0x00000432, + 0x726f6f63,0x00007364,0x00040005,0x00000433,0x61726170,0x0000006d,0x00040005,0x00000437, + 0x61726170,0x0000006d,0x00030005,0x0000043f,0x00000064,0x00030005,0x00000443,0x00003165, + 0x00040005,0x00000449,0x61726170,0x0000006d,0x00040005,0x0000044d,0x61726170,0x0000006d, + 0x00040005,0x0000045f,0x74727173,0x0000645f,0x00030005,0x00000462,0x00003265,0x00040005, + 0x00000468,0x61726170,0x0000006d,0x00040005,0x0000046a,0x61726170,0x0000006d,0x00040005, + 0x0000046c,0x61726170,0x0000006d,0x00040005,0x0000046e,0x61726170,0x0000006d,0x00040005, + 0x00000479,0x61726170,0x0000006d,0x00040005,0x0000047c,0x61726170,0x0000006d,0x00040005, + 0x0000047f,0x61726170,0x0000006d,0x00040005,0x0000048e,0x726f6f63,0x00007364,0x00040005, + 0x0000048f,0x61726170,0x0000006d,0x00040005,0x00000493,0x61726170,0x0000006d,0x00030005, + 0x0000049b,0x00000064,0x00030005,0x0000049f,0x00003165,0x00040005,0x000004a5,0x61726170, + 0x0000006d,0x00040005,0x000004a9,0x61726170,0x0000006d,0x00040005,0x000004bb,0x74727173, + 0x0000645f,0x00030005,0x000004be,0x00003265,0x00040005,0x000004c4,0x61726170,0x0000006d, + 0x00040005,0x000004c6,0x61726170,0x0000006d,0x00040005,0x000004c8,0x61726170,0x0000006d, + 0x00040005,0x000004ca,0x61726170,0x0000006d,0x00040005,0x000004d5,0x61726170,0x0000006d, + 0x00040005,0x000004d8,0x61726170,0x0000006d,0x00040005,0x000004db,0x61726170,0x0000006d, + 0x00060005,0x000004e7,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00050005,0x000004e8, + 0x63786970,0x64726f6f,0x00000000,0x00040005,0x000004e9,0x7366666f,0x00007465,0x00040005, + 0x000004ea,0x61726170,0x0000006d,0x00040005,0x000004ec,0x61726170,0x0000006d,0x00040005, + 0x000004ed,0x61726170,0x0000006d,0x00050005,0x000004f2,0x4374756f,0x726f6c6f,0x00000000, + 0x00050005,0x000004f3,0x65676445,0x74786554,0x00657275,0x00050005,0x000004f4,0x61657241, + 0x74786554,0x00657275,0x00060005,0x000004f5,0x72616553,0x65546863,0x72757478,0x00000065, + 0x00040005,0x000004f6,0x61726170,0x0000006d,0x00040005,0x000004f8,0x61726170,0x0000006d, + 0x00040005,0x000004fa,0x61726170,0x0000006d,0x00040005,0x000004fc,0x61726170,0x0000006d, + 0x00030047,0x00000096,0x00000002,0x00050048,0x00000096,0x00000000,0x00000023,0x00000000, + 0x00050048,0x00000096,0x00000001,0x00000023,0x00000010,0x00040047,0x000004e7,0x0000001e, + 0x00000000,0x00040047,0x000004f2,0x0000001e,0x00000000,0x00040047,0x000004f3,0x00000021, + 0x00000000,0x00040047,0x000004f3,0x00000022,0x00000000,0x00040047,0x000004f4,0x00000021, + 0x00000000,0x00040047,0x000004f4,0x00000022,0x00000001,0x00040047,0x000004f5,0x00000021, + 0x00000000,0x00040047,0x000004f5,0x00000022,0x00000002,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,0x00000009, + 0x00000004,0x00040015,0x00000013,0x00000020,0x00000000,0x0004002b,0x00000013,0x00000014, + 0x00000003,0x0004001c,0x00000015,0x00000012,0x00000014,0x00040020,0x00000016,0x00000007, + 0x00000015,0x00060021,0x00000017,0x00000002,0x0000000b,0x0000000b,0x00000016,0x00040021, + 0x0000001d,0x0000000a,0x0000000b,0x00040020,0x00000021,0x00000007,0x00000012,0x00040021, + 0x00000022,0x00000012,0x00000021,0x00090019,0x00000026,0x00000009,0x00000001,0x00000000, + 0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000027,0x00000026,0x00040020, + 0x00000028,0x00000000,0x00000027,0x00070021,0x00000029,0x0000000a,0x00000028,0x0000000b, + 0x0000000b,0x0000000b,0x00040020,0x00000036,0x00000007,0x00000009,0x00070021,0x00000037, + 0x0000000a,0x00000028,0x0000000b,0x0000000b,0x00000036,0x00080021,0x0000003e,0x0000000a, + 0x00000028,0x00000028,0x0000000b,0x0000000b,0x00000021,0x00060021,0x00000046,0x00000009, + 0x00000028,0x0000000b,0x00000036,0x00070021,0x0000004c,0x00000009,0x00000028,0x00000028, + 0x0000000b,0x00000036,0x00080021,0x00000065,0x0000000a,0x00000028,0x0000000b,0x00000036, + 0x00000036,0x00000036,0x00070021,0x0000006d,0x00000002,0x00000028,0x0000000b,0x00000021, + 0x0000000b,0x000a0021,0x0000007a,0x00000012,0x0000000b,0x0000000b,0x00000016,0x00000028, + 0x00000028,0x00000028,0x00000021,0x0004002b,0x00000013,0x00000084,0x00000000,0x00040020, + 0x00000085,0x00000007,0x00000006,0x0004002b,0x00000013,0x0000008d,0x00000001,0x0004001e, + 0x00000096,0x00000012,0x00000012,0x00040020,0x00000097,0x00000009,0x00000096,0x0004003b, + 0x00000097,0x00000098,0x00000009,0x00040015,0x00000099,0x00000020,0x00000001,0x0004002b, + 0x00000099,0x0000009a,0x00000001,0x00040020,0x0000009b,0x00000009,0x00000012,0x0004002b, + 0x00000099,0x000000a0,0x00000000,0x0004002b,0x00000009,0x000000a4,0xbe800000,0x0004002b, + 0x00000009,0x000000a5,0xbe000000,0x0004002b,0x00000009,0x000000a6,0x3fa00000,0x0007002c, + 0x00000012,0x000000a7,0x000000a4,0x000000a5,0x000000a6,0x000000a5,0x0007002c,0x00000012, + 0x000000af,0x000000a5,0x000000a4,0x000000a5,0x000000a6,0x0004002b,0x00000099,0x000000b4, + 0x00000002,0x0004002b,0x00000009,0x000000b8,0xc2000000,0x0004002b,0x00000009,0x000000b9, + 0x42000000,0x0007002c,0x00000012,0x000000ba,0x000000b8,0x000000b9,0x000000b8,0x000000b9, + 0x0004002b,0x00000009,0x000000ca,0x40a00000,0x0004002b,0x00000009,0x000000ce,0x40700000, + 0x0004002b,0x00000013,0x000000e2,0x00000002,0x0004002b,0x00000009,0x000000eb,0xbf800000, + 0x0004002b,0x00000009,0x000000ec,0x3f800000,0x00040017,0x000000f0,0x00000009,0x00000003, + 0x00040020,0x000000f1,0x00000007,0x000000f0,0x0004002b,0x00000009,0x00000100,0x40e00000, + 0x0004002b,0x00000009,0x00000106,0x3f666666,0x0004002b,0x00000009,0x0000011a,0x00000000, + 0x0004002b,0x00000009,0x0000011e,0x3f000000,0x0005002c,0x0000000a,0x0000011f,0x0000011e, + 0x0000011e,0x0004002b,0x00000009,0x0000012b,0x3e800000,0x00040020,0x0000012c,0x00000009, + 0x00000009,0x0004002b,0x00000009,0x00000167,0x41a00000,0x0005002c,0x0000000a,0x00000168, + 0x00000167,0x00000167,0x0004002b,0x00000009,0x0000016c,0x3bcccccd,0x0004002b,0x00000009, + 0x0000016d,0x3aea0ea1,0x0005002c,0x0000000a,0x0000016e,0x0000016c,0x0000016d,0x0004002b, + 0x00000009,0x00000170,0x3b4ccccd,0x0004002b,0x00000009,0x00000171,0x3a6a0ea1,0x0005002c, + 0x0000000a,0x00000172,0x00000170,0x00000171,0x0004002b,0x00000009,0x00000178,0x3e124925, + 0x0005002c,0x0000000a,0x00000186,0x0000011a,0x0000011a,0x0005002c,0x0000000a,0x0000018d, + 0x000000eb,0x000000ec,0x0005002c,0x0000000a,0x000001a6,0x000000ec,0x000000eb,0x0004002b, + 0x00000009,0x000001b6,0x40000000,0x00040017,0x000001d2,0x00000099,0x00000002,0x0004002b, + 0x00000099,0x000001d3,0xffffffff,0x0005002c,0x000001d2,0x000001d4,0x000001d3,0x000000a0, + 0x0005002c,0x000001d2,0x000001de,0x0000009a,0x000000a0,0x0005002c,0x0000000a,0x000001eb, + 0x000001b6,0x000001b6,0x0005002c,0x0000000a,0x00000207,0x000000eb,0x000000eb,0x0005002c, + 0x0000000a,0x00000219,0x000000ec,0x000000ec,0x0005002c,0x000001d2,0x00000255,0x000000a0, + 0x000001d3,0x0004002b,0x00000009,0x00000283,0x42040000,0x0004002b,0x00000009,0x00000284, + 0xc2040000,0x0005002c,0x0000000a,0x00000285,0x00000283,0x00000284,0x0004002b,0x00000009, + 0x00000287,0x42840000,0x0005002c,0x0000000a,0x00000288,0x00000287,0x00000283,0x0004002b, + 0x00000009,0x0000028e,0xbf000000,0x0005002c,0x0000000a,0x0000028f,0x0000011e,0x0000028e, + 0x0004002b,0x00000009,0x00000292,0x3c800000,0x0004002b,0x00000009,0x00000293,0x3d800000, + 0x0005002c,0x0000000a,0x00000294,0x00000292,0x00000293,0x0005002c,0x0000000a,0x000002a3, + 0x0000011a,0x000000ec,0x0004002b,0x00000009,0x000002b1,0x3f53fe5d,0x0004002b,0x00000009, + 0x000002be,0xc0000000,0x0004002b,0x00000009,0x000002bf,0x80000000,0x0005002c,0x0000000a, + 0x000002c0,0x000002be,0x000002bf,0x0004002b,0x00000009,0x000002c7,0xc0008102,0x0004002b, + 0x00000009,0x000002cc,0x40500000,0x0005002c,0x0000000a,0x000002f0,0x000001b6,0x0000011a, + 0x0005002c,0x0000000a,0x00000306,0x000000ec,0x0000011a,0x0005002c,0x0000000a,0x00000320, + 0x000002bf,0x000002be,0x0005002c,0x0000000a,0x0000034f,0x0000011a,0x000001b6,0x0004002b, + 0x00000009,0x00000366,0x41800000,0x0005002c,0x0000000a,0x00000367,0x00000366,0x00000366, + 0x0004002b,0x00000009,0x00000368,0x40800000,0x0004002b,0x00000009,0x00000383,0x3f400000, + 0x0005002c,0x000001d2,0x00000394,0x000000a0,0x0000009a,0x0005002c,0x000001d2,0x000003a1, + 0x0000009a,0x0000009a,0x0004002b,0x00000099,0x000003ae,0xfffffffe,0x0005002c,0x000001d2, + 0x000003af,0x000000a0,0x000003ae,0x0005002c,0x000001d2,0x000003bc,0x0000009a,0x000003ae, + 0x0005002c,0x000001d2,0x000003f8,0x000003ae,0x000000a0,0x0005002c,0x000001d2,0x00000405, + 0x000003ae,0x0000009a,0x0007002c,0x00000012,0x00000414,0x0000011a,0x0000011a,0x0000011a, + 0x0000011a,0x00040020,0x000004e6,0x00000001,0x0000000a,0x0004003b,0x000004e6,0x000004e7, + 0x00000001,0x00040020,0x000004f1,0x00000003,0x00000012,0x0004003b,0x000004f1,0x000004f2, + 0x00000003,0x0004003b,0x00000028,0x000004f3,0x00000000,0x0004003b,0x00000028,0x000004f4, + 0x00000000,0x0004003b,0x00000028,0x000004f5,0x00000000,0x00050036,0x00000002,0x00000004, + 0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000000b,0x000004e8,0x00000007, + 0x0004003b,0x00000016,0x000004e9,0x00000007,0x0004003b,0x0000000b,0x000004ea,0x00000007, + 0x0004003b,0x0000000b,0x000004ec,0x00000007,0x0004003b,0x00000016,0x000004ed,0x00000007, + 0x0004003b,0x0000000b,0x000004f6,0x00000007,0x0004003b,0x0000000b,0x000004f8,0x00000007, + 0x0004003b,0x00000016,0x000004fa,0x00000007,0x0004003b,0x00000021,0x000004fc,0x00000007, + 0x0004003d,0x0000000a,0x000004eb,0x000004e7,0x0003003e,0x000004ea,0x000004eb,0x00070039, + 0x00000002,0x000004ee,0x0000001b,0x000004ea,0x000004ec,0x000004ed,0x0004003d,0x0000000a, + 0x000004ef,0x000004ec,0x0003003e,0x000004e8,0x000004ef,0x0004003d,0x00000015,0x000004f0, + 0x000004ed,0x0003003e,0x000004e9,0x000004f0,0x0004003d,0x0000000a,0x000004f7,0x000004e7, + 0x0003003e,0x000004f6,0x000004f7,0x0004003d,0x0000000a,0x000004f9,0x000004e8,0x0003003e, + 0x000004f8,0x000004f9,0x0004003d,0x00000015,0x000004fb,0x000004e9,0x0003003e,0x000004fa, + 0x000004fb,0x0003003e,0x000004fc,0x00000414,0x000b0039,0x00000012,0x000004fd,0x00000082, + 0x000004f6,0x000004f8,0x000004fa,0x000004f3,0x000004f4,0x000004f5,0x000004fc,0x0003003e, + 0x000004f2,0x000004fd,0x000100fd,0x00010038,0x00050036,0x00000002,0x00000010,0x00000000, + 0x0000000c,0x00030037,0x00000008,0x0000000d,0x00030037,0x0000000b,0x0000000e,0x00030037, + 0x0000000b,0x0000000f,0x000200f8,0x00000011,0x00050041,0x00000085,0x00000086,0x0000000d, + 0x00000084,0x0004003d,0x00000006,0x00000087,0x00000086,0x000300f7,0x00000089,0x00000000, + 0x000400fa,0x00000087,0x00000088,0x00000089,0x000200f8,0x00000088,0x00050041,0x00000036, + 0x0000008a,0x0000000f,0x00000084,0x0004003d,0x00000009,0x0000008b,0x0000008a,0x00050041, + 0x00000036,0x0000008c,0x0000000e,0x00000084,0x0003003e,0x0000008c,0x0000008b,0x000200f9, + 0x00000089,0x000200f8,0x00000089,0x00050041,0x00000085,0x0000008e,0x0000000d,0x0000008d, + 0x0004003d,0x00000006,0x0000008f,0x0000008e,0x000300f7,0x00000091,0x00000000,0x000400fa, + 0x0000008f,0x00000090,0x00000091,0x000200f8,0x00000090,0x00050041,0x00000036,0x00000092, + 0x0000000f,0x0000008d,0x0004003d,0x00000009,0x00000093,0x00000092,0x00050041,0x00000036, + 0x00000094,0x0000000e,0x0000008d,0x0003003e,0x00000094,0x00000093,0x000200f9,0x00000091, + 0x000200f8,0x00000091,0x000100fd,0x00010038,0x00050036,0x00000002,0x0000001b,0x00000000, + 0x00000017,0x00030037,0x0000000b,0x00000018,0x00030037,0x0000000b,0x00000019,0x00030037, + 0x00000016,0x0000001a,0x000200f8,0x0000001c,0x0004003d,0x0000000a,0x00000095,0x00000018, + 0x00050041,0x0000009b,0x0000009c,0x00000098,0x0000009a,0x0004003d,0x00000012,0x0000009d, + 0x0000009c,0x0007004f,0x0000000a,0x0000009e,0x0000009d,0x0000009d,0x00000002,0x00000003, + 0x00050085,0x0000000a,0x0000009f,0x00000095,0x0000009e,0x0003003e,0x00000019,0x0000009f, + 0x00050041,0x0000009b,0x000000a1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000a2, + 0x000000a1,0x0009004f,0x00000012,0x000000a3,0x000000a2,0x000000a2,0x00000000,0x00000001, + 0x00000000,0x00000001,0x0004003d,0x0000000a,0x000000a8,0x00000018,0x0009004f,0x00000012, + 0x000000a9,0x000000a8,0x000000a8,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c, + 0x00000012,0x000000aa,0x00000001,0x00000032,0x000000a3,0x000000a7,0x000000a9,0x00050041, + 0x00000021,0x000000ab,0x0000001a,0x000000a0,0x0003003e,0x000000ab,0x000000aa,0x00050041, + 0x0000009b,0x000000ac,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000ad,0x000000ac, + 0x0009004f,0x00000012,0x000000ae,0x000000ad,0x000000ad,0x00000000,0x00000001,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x000000b0,0x00000018,0x0009004f,0x00000012,0x000000b1, + 0x000000b0,0x000000b0,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000012, + 0x000000b2,0x00000001,0x00000032,0x000000ae,0x000000af,0x000000b1,0x00050041,0x00000021, + 0x000000b3,0x0000001a,0x0000009a,0x0003003e,0x000000b3,0x000000b2,0x00050041,0x0000009b, + 0x000000b5,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000b6,0x000000b5,0x0009004f, + 0x00000012,0x000000b7,0x000000b6,0x000000b6,0x00000000,0x00000000,0x00000001,0x00000001, + 0x00050041,0x00000021,0x000000bb,0x0000001a,0x000000a0,0x0004003d,0x00000012,0x000000bc, + 0x000000bb,0x0007004f,0x0000000a,0x000000bd,0x000000bc,0x000000bc,0x00000000,0x00000002, + 0x00050041,0x00000021,0x000000be,0x0000001a,0x0000009a,0x0004003d,0x00000012,0x000000bf, + 0x000000be,0x0007004f,0x0000000a,0x000000c0,0x000000bf,0x000000bf,0x00000001,0x00000003, + 0x00050051,0x00000009,0x000000c1,0x000000bd,0x00000000,0x00050051,0x00000009,0x000000c2, + 0x000000bd,0x00000001,0x00050051,0x00000009,0x000000c3,0x000000c0,0x00000000,0x00050051, + 0x00000009,0x000000c4,0x000000c0,0x00000001,0x00070050,0x00000012,0x000000c5,0x000000c1, + 0x000000c2,0x000000c3,0x000000c4,0x0008000c,0x00000012,0x000000c6,0x00000001,0x00000032, + 0x000000b7,0x000000ba,0x000000c5,0x00050041,0x00000021,0x000000c7,0x0000001a,0x000000b4, + 0x0003003e,0x000000c7,0x000000c6,0x000100fd,0x00010038,0x00050036,0x0000000a,0x0000001f, + 0x00000000,0x0000001d,0x00030037,0x0000000b,0x0000001e,0x000200f8,0x00000020,0x00050041, + 0x00000036,0x000000c8,0x0000001e,0x00000084,0x0004003d,0x00000009,0x000000c9,0x000000c8, + 0x00050041,0x00000036,0x000000cb,0x0000001e,0x00000084,0x0004003d,0x00000009,0x000000cc, + 0x000000cb,0x00050085,0x00000009,0x000000cd,0x000000ca,0x000000cc,0x00050083,0x00000009, + 0x000000cf,0x000000cd,0x000000ce,0x0006000c,0x00000009,0x000000d0,0x00000001,0x00000004, + 0x000000cf,0x00050085,0x00000009,0x000000d1,0x000000c9,0x000000d0,0x00050041,0x00000036, + 0x000000d2,0x0000001e,0x00000084,0x0003003e,0x000000d2,0x000000d1,0x0004003d,0x0000000a, + 0x000000d3,0x0000001e,0x0006000c,0x0000000a,0x000000d4,0x00000001,0x00000001,0x000000d3, + 0x000200fe,0x000000d4,0x00010038,0x00050036,0x00000012,0x00000024,0x00000000,0x00000022, + 0x00030037,0x00000021,0x00000023,0x000200f8,0x00000025,0x0004003d,0x00000012,0x000000d7, + 0x00000023,0x0007004f,0x0000000a,0x000000d8,0x000000d7,0x000000d7,0x00000000,0x00000002, + 0x0004003d,0x00000012,0x000000d9,0x00000023,0x0007004f,0x0000000a,0x000000da,0x000000d9, + 0x000000d9,0x00000000,0x00000002,0x0005008e,0x0000000a,0x000000db,0x000000da,0x000000ca, + 0x00050050,0x0000000a,0x000000dc,0x000000ce,0x000000ce,0x00050083,0x0000000a,0x000000dd, + 0x000000db,0x000000dc,0x0006000c,0x0000000a,0x000000de,0x00000001,0x00000004,0x000000dd, + 0x00050085,0x0000000a,0x000000df,0x000000d8,0x000000de,0x00050041,0x00000036,0x000000e0, + 0x00000023,0x00000084,0x00050051,0x00000009,0x000000e1,0x000000df,0x00000000,0x0003003e, + 0x000000e0,0x000000e1,0x00050041,0x00000036,0x000000e3,0x00000023,0x000000e2,0x00050051, + 0x00000009,0x000000e4,0x000000df,0x00000001,0x0003003e,0x000000e3,0x000000e4,0x0004003d, + 0x00000012,0x000000e5,0x00000023,0x0006000c,0x00000012,0x000000e6,0x00000001,0x00000001, + 0x000000e5,0x000200fe,0x000000e6,0x00010038,0x00050036,0x0000000a,0x0000002e,0x00000000, + 0x00000029,0x00030037,0x00000028,0x0000002a,0x00030037,0x0000000b,0x0000002b,0x00030037, + 0x0000000b,0x0000002c,0x00030037,0x0000000b,0x0000002d,0x000200f8,0x0000002f,0x0004003b, + 0x00000021,0x000000e9,0x00000007,0x0004003b,0x000000f1,0x000000f2,0x00000007,0x0004003d, + 0x0000000a,0x000000ea,0x0000002b,0x00050051,0x00000009,0x000000ed,0x000000ea,0x00000000, + 0x00050051,0x00000009,0x000000ee,0x000000ea,0x00000001,0x00070050,0x00000012,0x000000ef, + 0x000000ed,0x000000ee,0x000000eb,0x000000ec,0x0003003e,0x000000e9,0x000000ef,0x00050041, + 0x0000009b,0x000000f3,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000f4,0x000000f3, + 0x0007004f,0x0000000a,0x000000f5,0x000000f4,0x000000f4,0x00000000,0x00000001,0x00050051, + 0x00000009,0x000000f6,0x000000f5,0x00000000,0x00050051,0x00000009,0x000000f7,0x000000f5, + 0x00000001,0x00060050,0x000000f0,0x000000f8,0x000000f6,0x000000f7,0x000000ec,0x0003003e, + 0x000000f2,0x000000f8,0x000200f9,0x000000f9,0x000200f8,0x000000f9,0x000400f6,0x000000fb, + 0x000000fc,0x00000000,0x000200f9,0x000000fd,0x000200f8,0x000000fd,0x00050041,0x00000036, + 0x000000fe,0x000000e9,0x000000e2,0x0004003d,0x00000009,0x000000ff,0x000000fe,0x000500b8, + 0x00000006,0x00000101,0x000000ff,0x00000100,0x000300f7,0x00000103,0x00000000,0x000400fa, + 0x00000101,0x00000102,0x00000103,0x000200f8,0x00000102,0x00050041,0x00000036,0x00000104, + 0x000000e9,0x00000014,0x0004003d,0x00000009,0x00000105,0x00000104,0x000500ba,0x00000006, + 0x00000107,0x00000105,0x00000106,0x000200f9,0x00000103,0x000200f8,0x00000103,0x000700f5, + 0x00000006,0x00000108,0x00000101,0x000000fd,0x00000107,0x00000102,0x000400fa,0x00000108, + 0x000000fa,0x000000fb,0x000200f8,0x000000fa,0x0004003d,0x000000f0,0x00000109,0x000000f2, + 0x0004003d,0x0000000a,0x0000010a,0x0000002c,0x00050051,0x00000009,0x0000010b,0x0000010a, + 0x00000000,0x00050051,0x00000009,0x0000010c,0x0000010a,0x00000001,0x00060050,0x000000f0, + 0x0000010d,0x0000010b,0x0000010c,0x000000ec,0x0004003d,0x00000012,0x0000010e,0x000000e9, + 0x0008004f,0x000000f0,0x0000010f,0x0000010e,0x0000010e,0x00000000,0x00000001,0x00000002, + 0x0008000c,0x000000f0,0x00000110,0x00000001,0x00000032,0x00000109,0x0000010d,0x0000010f, + 0x00050041,0x00000036,0x00000111,0x000000e9,0x00000084,0x00050051,0x00000009,0x00000112, + 0x00000110,0x00000000,0x0003003e,0x00000111,0x00000112,0x00050041,0x00000036,0x00000113, + 0x000000e9,0x0000008d,0x00050051,0x00000009,0x00000114,0x00000110,0x00000001,0x0003003e, + 0x00000113,0x00000114,0x00050041,0x00000036,0x00000115,0x000000e9,0x000000e2,0x00050051, + 0x00000009,0x00000116,0x00000110,0x00000002,0x0003003e,0x00000115,0x00000116,0x0004003d, + 0x00000027,0x00000117,0x0000002a,0x0004003d,0x00000012,0x00000118,0x000000e9,0x0007004f, + 0x0000000a,0x00000119,0x00000118,0x00000118,0x00000000,0x00000001,0x00070058,0x00000012, + 0x0000011b,0x00000117,0x00000119,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000011c, + 0x0000011b,0x0000011b,0x00000000,0x00000001,0x0003003e,0x0000002d,0x0000011c,0x0004003d, + 0x0000000a,0x0000011d,0x0000002d,0x00050094,0x00000009,0x00000120,0x0000011d,0x0000011f, + 0x00050041,0x00000036,0x00000121,0x000000e9,0x00000014,0x0003003e,0x00000121,0x00000120, + 0x000200f9,0x000000fc,0x000200f8,0x000000fc,0x000200f9,0x000000f9,0x000200f8,0x000000fb, + 0x0004003d,0x00000012,0x00000122,0x000000e9,0x0007004f,0x0000000a,0x00000123,0x00000122, + 0x00000122,0x00000002,0x00000003,0x000200fe,0x00000123,0x00010038,0x00050036,0x0000000a, + 0x00000034,0x00000000,0x00000029,0x00030037,0x00000028,0x00000030,0x00030037,0x0000000b, + 0x00000031,0x00030037,0x0000000b,0x00000032,0x00030037,0x0000000b,0x00000033,0x000200f8, + 0x00000035,0x0004003b,0x00000021,0x00000126,0x00000007,0x0004003b,0x000000f1,0x00000134, + 0x00000007,0x0004003b,0x0000000b,0x0000015c,0x00000007,0x0004003d,0x0000000a,0x00000127, + 0x00000031,0x00050051,0x00000009,0x00000128,0x00000127,0x00000000,0x00050051,0x00000009, + 0x00000129,0x00000127,0x00000001,0x00070050,0x00000012,0x0000012a,0x00000128,0x00000129, + 0x000000eb,0x000000ec,0x0003003e,0x00000126,0x0000012a,0x00060041,0x0000012c,0x0000012d, + 0x00000098,0x0000009a,0x00000084,0x0004003d,0x00000009,0x0000012e,0x0000012d,0x00050085, + 0x00000009,0x0000012f,0x0000012b,0x0000012e,0x00050041,0x00000036,0x00000130,0x00000126, + 0x00000084,0x0004003d,0x00000009,0x00000131,0x00000130,0x00050081,0x00000009,0x00000132, + 0x00000131,0x0000012f,0x00050041,0x00000036,0x00000133,0x00000126,0x00000084,0x0003003e, + 0x00000133,0x00000132,0x00050041,0x0000009b,0x00000135,0x00000098,0x0000009a,0x0004003d, + 0x00000012,0x00000136,0x00000135,0x0007004f,0x0000000a,0x00000137,0x00000136,0x00000136, + 0x00000000,0x00000001,0x00050051,0x00000009,0x00000138,0x00000137,0x00000000,0x00050051, + 0x00000009,0x00000139,0x00000137,0x00000001,0x00060050,0x000000f0,0x0000013a,0x00000138, + 0x00000139,0x000000ec,0x0003003e,0x00000134,0x0000013a,0x000200f9,0x0000013b,0x000200f8, + 0x0000013b,0x000400f6,0x0000013d,0x0000013e,0x00000000,0x000200f9,0x0000013f,0x000200f8, + 0x0000013f,0x00050041,0x00000036,0x00000140,0x00000126,0x000000e2,0x0004003d,0x00000009, + 0x00000141,0x00000140,0x000500b8,0x00000006,0x00000142,0x00000141,0x00000100,0x000300f7, + 0x00000144,0x00000000,0x000400fa,0x00000142,0x00000143,0x00000144,0x000200f8,0x00000143, + 0x00050041,0x00000036,0x00000145,0x00000126,0x00000014,0x0004003d,0x00000009,0x00000146, + 0x00000145,0x000500ba,0x00000006,0x00000147,0x00000146,0x00000106,0x000200f9,0x00000144, + 0x000200f8,0x00000144,0x000700f5,0x00000006,0x00000148,0x00000142,0x0000013f,0x00000147, + 0x00000143,0x000400fa,0x00000148,0x0000013c,0x0000013d,0x000200f8,0x0000013c,0x0004003d, + 0x000000f0,0x00000149,0x00000134,0x0004003d,0x0000000a,0x0000014a,0x00000032,0x00050051, + 0x00000009,0x0000014b,0x0000014a,0x00000000,0x00050051,0x00000009,0x0000014c,0x0000014a, + 0x00000001,0x00060050,0x000000f0,0x0000014d,0x0000014b,0x0000014c,0x000000ec,0x0004003d, + 0x00000012,0x0000014e,0x00000126,0x0008004f,0x000000f0,0x0000014f,0x0000014e,0x0000014e, + 0x00000000,0x00000001,0x00000002,0x0008000c,0x000000f0,0x00000150,0x00000001,0x00000032, + 0x00000149,0x0000014d,0x0000014f,0x00050041,0x00000036,0x00000151,0x00000126,0x00000084, + 0x00050051,0x00000009,0x00000152,0x00000150,0x00000000,0x0003003e,0x00000151,0x00000152, + 0x00050041,0x00000036,0x00000153,0x00000126,0x0000008d,0x00050051,0x00000009,0x00000154, + 0x00000150,0x00000001,0x0003003e,0x00000153,0x00000154,0x00050041,0x00000036,0x00000155, + 0x00000126,0x000000e2,0x00050051,0x00000009,0x00000156,0x00000150,0x00000002,0x0003003e, + 0x00000155,0x00000156,0x0004003d,0x00000027,0x00000157,0x00000030,0x0004003d,0x00000012, + 0x00000158,0x00000126,0x0007004f,0x0000000a,0x00000159,0x00000158,0x00000158,0x00000000, + 0x00000001,0x00070058,0x00000012,0x0000015a,0x00000157,0x00000159,0x00000002,0x0000011a, + 0x0007004f,0x0000000a,0x0000015b,0x0000015a,0x0000015a,0x00000000,0x00000001,0x0003003e, + 0x00000033,0x0000015b,0x0004003d,0x0000000a,0x0000015d,0x00000033,0x0003003e,0x0000015c, + 0x0000015d,0x00050039,0x0000000a,0x0000015e,0x0000001f,0x0000015c,0x0003003e,0x00000033, + 0x0000015e,0x0004003d,0x0000000a,0x0000015f,0x00000033,0x00050094,0x00000009,0x00000160, + 0x0000015f,0x0000011f,0x00050041,0x00000036,0x00000161,0x00000126,0x00000014,0x0003003e, + 0x00000161,0x00000160,0x000200f9,0x0000013e,0x000200f8,0x0000013e,0x000200f9,0x0000013b, + 0x000200f8,0x0000013d,0x0004003d,0x00000012,0x00000162,0x00000126,0x0007004f,0x0000000a, + 0x00000163,0x00000162,0x00000162,0x00000002,0x00000003,0x000200fe,0x00000163,0x00010038, + 0x00050036,0x0000000a,0x0000003c,0x00000000,0x00000037,0x00030037,0x00000028,0x00000038, + 0x00030037,0x0000000b,0x00000039,0x00030037,0x0000000b,0x0000003a,0x00030037,0x00000036, + 0x0000003b,0x000200f8,0x0000003d,0x0004003b,0x0000000b,0x00000166,0x00000007,0x0004003d, + 0x0000000a,0x00000169,0x0000003a,0x0004003d,0x0000000a,0x0000016a,0x00000039,0x0008000c, + 0x0000000a,0x0000016b,0x00000001,0x00000032,0x00000168,0x00000169,0x0000016a,0x0003003e, + 0x00000166,0x0000016b,0x0004003d,0x0000000a,0x0000016f,0x00000166,0x0008000c,0x0000000a, + 0x00000173,0x00000001,0x00000032,0x0000016e,0x0000016f,0x00000172,0x0003003e,0x00000166, + 0x00000173,0x00050041,0x00000036,0x00000174,0x00000166,0x00000084,0x0004003d,0x00000009, + 0x00000175,0x00000174,0x00050081,0x00000009,0x00000176,0x00000175,0x0000011e,0x00050041, + 0x00000036,0x00000177,0x00000166,0x00000084,0x0003003e,0x00000177,0x00000176,0x0004003d, + 0x00000009,0x00000179,0x0000003b,0x00050085,0x00000009,0x0000017a,0x00000178,0x00000179, + 0x00050041,0x00000036,0x0000017b,0x00000166,0x0000008d,0x0004003d,0x00000009,0x0000017c, + 0x0000017b,0x00050081,0x00000009,0x0000017d,0x0000017c,0x0000017a,0x00050041,0x00000036, + 0x0000017e,0x00000166,0x0000008d,0x0003003e,0x0000017e,0x0000017d,0x0004003d,0x00000027, + 0x0000017f,0x00000038,0x0004003d,0x0000000a,0x00000180,0x00000166,0x00070058,0x00000012, + 0x00000181,0x0000017f,0x00000180,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x00000182, + 0x00000181,0x00000181,0x00000000,0x00000001,0x000200fe,0x00000182,0x00010038,0x00050036, + 0x0000000a,0x00000044,0x00000000,0x0000003e,0x00030037,0x00000028,0x0000003f,0x00030037, + 0x00000028,0x00000040,0x00030037,0x0000000b,0x00000041,0x00030037,0x0000000b,0x00000042, + 0x00030037,0x00000021,0x00000043,0x000200f8,0x00000045,0x0004003b,0x0000000b,0x00000185, + 0x00000007,0x0004003b,0x00000021,0x0000018c,0x00000007,0x0004003b,0x0000000b,0x0000018e, + 0x00000007,0x0004003b,0x0000000b,0x0000018f,0x00000007,0x0004003b,0x0000000b,0x00000191, + 0x00000007,0x0004003b,0x0000000b,0x00000192,0x00000007,0x0004003b,0x0000000b,0x000001a7, + 0x00000007,0x0004003b,0x0000000b,0x000001a9,0x00000007,0x0004003b,0x0000000b,0x000001aa, + 0x00000007,0x0004003b,0x00000021,0x000001ba,0x00000007,0x0004003b,0x00000021,0x000001ce, + 0x00000007,0x0004003b,0x00000021,0x000001e5,0x00000007,0x0004003b,0x0000000b,0x000001ea, + 0x00000007,0x0004003b,0x00000008,0x000001f6,0x00000007,0x0004003b,0x0000000b,0x000001f7, + 0x00000007,0x0004003b,0x0000000b,0x000001f9,0x00000007,0x0004003b,0x0000000b,0x000001fc, + 0x00000007,0x0004003b,0x0000000b,0x000001ff,0x00000007,0x0004003b,0x00000036,0x00000201, + 0x00000007,0x0004003b,0x0000000b,0x00000208,0x00000007,0x0004003b,0x0000000b,0x0000020a, + 0x00000007,0x0004003b,0x0000000b,0x0000020b,0x00000007,0x0004003b,0x0000000b,0x0000021a, + 0x00000007,0x0004003b,0x0000000b,0x0000021c,0x00000007,0x0004003b,0x0000000b,0x0000021d, + 0x00000007,0x0004003b,0x00000021,0x00000239,0x00000007,0x0004003b,0x00000021,0x0000024b, + 0x00000007,0x0004003b,0x0000000b,0x00000262,0x00000007,0x0004003b,0x00000008,0x0000026d, + 0x00000007,0x0004003b,0x0000000b,0x0000026e,0x00000007,0x0004003b,0x0000000b,0x00000270, + 0x00000007,0x0004003b,0x0000000b,0x00000273,0x00000007,0x0004003b,0x0000000b,0x00000276, + 0x00000007,0x0004003b,0x00000036,0x00000278,0x00000007,0x0003003e,0x00000185,0x00000186, + 0x00050041,0x00000036,0x00000187,0x00000042,0x00000084,0x0004003d,0x00000009,0x00000188, + 0x00000187,0x000500ba,0x00000006,0x00000189,0x00000188,0x0000011a,0x000300f7,0x0000018b, + 0x00000000,0x000400fa,0x00000189,0x0000018a,0x000001a1,0x000200f8,0x0000018a,0x0004003d, + 0x0000000a,0x00000190,0x00000041,0x0003003e,0x0000018f,0x00000190,0x0003003e,0x00000191, + 0x0000018d,0x00080039,0x0000000a,0x00000193,0x0000002e,0x0000003f,0x0000018f,0x00000191, + 0x00000192,0x0004003d,0x0000000a,0x00000194,0x00000192,0x0003003e,0x0000018e,0x00000194, + 0x00050041,0x00000036,0x00000195,0x0000018c,0x00000084,0x00050051,0x00000009,0x00000196, + 0x00000193,0x00000000,0x0003003e,0x00000195,0x00000196,0x00050041,0x00000036,0x00000197, + 0x0000018c,0x000000e2,0x00050051,0x00000009,0x00000198,0x00000193,0x00000001,0x0003003e, + 0x00000197,0x00000198,0x00050041,0x00000036,0x00000199,0x0000018e,0x0000008d,0x0004003d, + 0x00000009,0x0000019a,0x00000199,0x000500ba,0x00000006,0x0000019b,0x0000019a,0x00000106, + 0x000600a9,0x00000009,0x0000019c,0x0000019b,0x000000ec,0x0000011a,0x00050041,0x00000036, + 0x0000019d,0x0000018c,0x00000084,0x0004003d,0x00000009,0x0000019e,0x0000019d,0x00050081, + 0x00000009,0x0000019f,0x0000019e,0x0000019c,0x00050041,0x00000036,0x000001a0,0x0000018c, + 0x00000084,0x0003003e,0x000001a0,0x0000019f,0x000200f9,0x0000018b,0x000200f8,0x000001a1, + 0x00050041,0x00000036,0x000001a2,0x0000018c,0x00000084,0x00050051,0x00000009,0x000001a3, + 0x00000186,0x00000000,0x0003003e,0x000001a2,0x000001a3,0x00050041,0x00000036,0x000001a4, + 0x0000018c,0x000000e2,0x00050051,0x00000009,0x000001a5,0x00000186,0x00000001,0x0003003e, + 0x000001a4,0x000001a5,0x000200f9,0x0000018b,0x000200f8,0x0000018b,0x0004003d,0x0000000a, + 0x000001a8,0x00000041,0x0003003e,0x000001a7,0x000001a8,0x0003003e,0x000001a9,0x000001a6, + 0x00080039,0x0000000a,0x000001ab,0x0000002e,0x0000003f,0x000001a7,0x000001a9,0x000001aa, + 0x0004003d,0x0000000a,0x000001ac,0x000001aa,0x0003003e,0x0000018e,0x000001ac,0x00050041, + 0x00000036,0x000001ad,0x0000018c,0x0000008d,0x00050051,0x00000009,0x000001ae,0x000001ab, + 0x00000000,0x0003003e,0x000001ad,0x000001ae,0x00050041,0x00000036,0x000001af,0x0000018c, + 0x00000014,0x00050051,0x00000009,0x000001b0,0x000001ab,0x00000001,0x0003003e,0x000001af, + 0x000001b0,0x00050041,0x00000036,0x000001b1,0x0000018c,0x00000084,0x0004003d,0x00000009, + 0x000001b2,0x000001b1,0x00050041,0x00000036,0x000001b3,0x0000018c,0x0000008d,0x0004003d, + 0x00000009,0x000001b4,0x000001b3,0x00050081,0x00000009,0x000001b5,0x000001b2,0x000001b4, + 0x000500ba,0x00000006,0x000001b7,0x000001b5,0x000001b6,0x000300f7,0x000001b9,0x00000000, + 0x000400fa,0x000001b7,0x000001b8,0x000001b9,0x000200f8,0x000001b8,0x00050041,0x00000036, + 0x000001bb,0x0000018c,0x00000084,0x0004003d,0x00000009,0x000001bc,0x000001bb,0x0004007f, + 0x00000009,0x000001bd,0x000001bc,0x00050081,0x00000009,0x000001be,0x000001bd,0x0000012b, + 0x00050041,0x00000036,0x000001bf,0x0000018c,0x00000084,0x0004003d,0x00000009,0x000001c0, + 0x000001bf,0x00050041,0x00000036,0x000001c1,0x0000018c,0x0000008d,0x0004003d,0x00000009, + 0x000001c2,0x000001c1,0x00050041,0x00000036,0x000001c3,0x0000018c,0x0000008d,0x0004003d, + 0x00000009,0x000001c4,0x000001c3,0x0004007f,0x00000009,0x000001c5,0x000001c4,0x00050083, + 0x00000009,0x000001c6,0x000001c5,0x0000012b,0x00070050,0x00000012,0x000001c7,0x000001be, + 0x000001c0,0x000001c2,0x000001c6,0x00050041,0x0000009b,0x000001c8,0x00000098,0x0000009a, + 0x0004003d,0x00000012,0x000001c9,0x000001c8,0x0009004f,0x00000012,0x000001ca,0x000001c9, + 0x000001c9,0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x0000000a,0x000001cb, + 0x00000041,0x0009004f,0x00000012,0x000001cc,0x000001cb,0x000001cb,0x00000000,0x00000001, + 0x00000000,0x00000001,0x0008000c,0x00000012,0x000001cd,0x00000001,0x00000032,0x000001c7, + 0x000001ca,0x000001cc,0x0003003e,0x000001ba,0x000001cd,0x0004003d,0x00000027,0x000001cf, + 0x0000003f,0x0004003d,0x00000012,0x000001d0,0x000001ba,0x0007004f,0x0000000a,0x000001d1, + 0x000001d0,0x000001d0,0x00000000,0x00000001,0x00080058,0x00000012,0x000001d5,0x000001cf, + 0x000001d1,0x0000000a,0x0000011a,0x000001d4,0x0007004f,0x0000000a,0x000001d6,0x000001d5, + 0x000001d5,0x00000000,0x00000001,0x00050041,0x00000036,0x000001d7,0x000001ce,0x00000084, + 0x00050051,0x00000009,0x000001d8,0x000001d6,0x00000000,0x0003003e,0x000001d7,0x000001d8, + 0x00050041,0x00000036,0x000001d9,0x000001ce,0x0000008d,0x00050051,0x00000009,0x000001da, + 0x000001d6,0x00000001,0x0003003e,0x000001d9,0x000001da,0x0004003d,0x00000027,0x000001db, + 0x0000003f,0x0004003d,0x00000012,0x000001dc,0x000001ba,0x0007004f,0x0000000a,0x000001dd, + 0x000001dc,0x000001dc,0x00000002,0x00000003,0x00080058,0x00000012,0x000001df,0x000001db, + 0x000001dd,0x0000000a,0x0000011a,0x000001de,0x0007004f,0x0000000a,0x000001e0,0x000001df, + 0x000001df,0x00000000,0x00000001,0x00050041,0x00000036,0x000001e1,0x000001ce,0x000000e2, + 0x00050051,0x00000009,0x000001e2,0x000001e0,0x00000000,0x0003003e,0x000001e1,0x000001e2, + 0x00050041,0x00000036,0x000001e3,0x000001ce,0x00000014,0x00050051,0x00000009,0x000001e4, + 0x000001e0,0x00000001,0x0003003e,0x000001e3,0x000001e4,0x0004003d,0x00000012,0x000001e6, + 0x000001ce,0x0003003e,0x000001e5,0x000001e6,0x00050039,0x00000012,0x000001e7,0x00000024, + 0x000001e5,0x0004003d,0x00000012,0x000001e8,0x000001ce,0x0009004f,0x00000012,0x000001e9, + 0x000001e8,0x000001e7,0x00000005,0x00000004,0x00000007,0x00000006,0x0003003e,0x000001ce, + 0x000001e9,0x0004003d,0x00000012,0x000001ec,0x000001ce,0x0007004f,0x0000000a,0x000001ed, + 0x000001ec,0x000001ec,0x00000000,0x00000002,0x0004003d,0x00000012,0x000001ee,0x000001ce, + 0x0007004f,0x0000000a,0x000001ef,0x000001ee,0x000001ee,0x00000001,0x00000003,0x0008000c, + 0x0000000a,0x000001f0,0x00000001,0x00000032,0x000001eb,0x000001ed,0x000001ef,0x0003003e, + 0x000001ea,0x000001f0,0x0004003d,0x00000012,0x000001f1,0x0000018c,0x0007004f,0x0000000a, + 0x000001f2,0x000001f1,0x000001f1,0x00000002,0x00000003,0x00050050,0x0000000a,0x000001f3, + 0x00000106,0x00000106,0x0007000c,0x0000000a,0x000001f4,0x00000001,0x00000030,0x000001f3, + 0x000001f2,0x000500b7,0x00000007,0x000001f5,0x000001f4,0x00000186,0x0003003e,0x000001f6, + 0x000001f5,0x0004003d,0x0000000a,0x000001f8,0x000001ea,0x0003003e,0x000001f7,0x000001f8, + 0x0003003e,0x000001f9,0x00000186,0x00070039,0x00000002,0x000001fa,0x00000010,0x000001f6, + 0x000001f7,0x000001f9,0x0004003d,0x0000000a,0x000001fb,0x000001f7,0x0003003e,0x000001ea, + 0x000001fb,0x0004003d,0x00000012,0x000001fd,0x0000018c,0x0007004f,0x0000000a,0x000001fe, + 0x000001fd,0x000001fd,0x00000000,0x00000001,0x0003003e,0x000001fc,0x000001fe,0x0004003d, + 0x0000000a,0x00000200,0x000001ea,0x0003003e,0x000001ff,0x00000200,0x00050041,0x00000036, + 0x00000202,0x00000043,0x000000e2,0x0004003d,0x00000009,0x00000203,0x00000202,0x0003003e, + 0x00000201,0x00000203,0x00080039,0x0000000a,0x00000204,0x0000003c,0x00000040,0x000001fc, + 0x000001ff,0x00000201,0x0004003d,0x0000000a,0x00000205,0x00000185,0x00050081,0x0000000a, + 0x00000206,0x00000205,0x00000204,0x0003003e,0x00000185,0x00000206,0x000200f9,0x000001b9, + 0x000200f8,0x000001b9,0x0004003d,0x0000000a,0x00000209,0x00000041,0x0003003e,0x00000208, + 0x00000209,0x0003003e,0x0000020a,0x00000207,0x00080039,0x0000000a,0x0000020c,0x00000034, + 0x0000003f,0x00000208,0x0000020a,0x0000020b,0x0004003d,0x0000000a,0x0000020d,0x0000020b, + 0x0003003e,0x0000018e,0x0000020d,0x00050041,0x00000036,0x0000020e,0x0000018c,0x00000084, + 0x00050051,0x00000009,0x0000020f,0x0000020c,0x00000000,0x0003003e,0x0000020e,0x0000020f, + 0x00050041,0x00000036,0x00000210,0x0000018c,0x000000e2,0x00050051,0x00000009,0x00000211, + 0x0000020c,0x00000001,0x0003003e,0x00000210,0x00000211,0x0004003d,0x00000027,0x00000212, + 0x0000003f,0x0004003d,0x0000000a,0x00000213,0x00000041,0x00080058,0x00000012,0x00000214, + 0x00000212,0x00000213,0x0000000a,0x0000011a,0x000001de,0x00050051,0x00000009,0x00000215, + 0x00000214,0x00000000,0x000500ba,0x00000006,0x00000216,0x00000215,0x0000011a,0x000300f7, + 0x00000218,0x00000000,0x000400fa,0x00000216,0x00000217,0x0000022c,0x000200f8,0x00000217, + 0x0004003d,0x0000000a,0x0000021b,0x00000041,0x0003003e,0x0000021a,0x0000021b,0x0003003e, + 0x0000021c,0x00000219,0x00080039,0x0000000a,0x0000021e,0x00000034,0x0000003f,0x0000021a, + 0x0000021c,0x0000021d,0x0004003d,0x0000000a,0x0000021f,0x0000021d,0x0003003e,0x0000018e, + 0x0000021f,0x00050041,0x00000036,0x00000220,0x0000018c,0x0000008d,0x00050051,0x00000009, + 0x00000221,0x0000021e,0x00000000,0x0003003e,0x00000220,0x00000221,0x00050041,0x00000036, + 0x00000222,0x0000018c,0x00000014,0x00050051,0x00000009,0x00000223,0x0000021e,0x00000001, + 0x0003003e,0x00000222,0x00000223,0x00050041,0x00000036,0x00000224,0x0000018e,0x0000008d, + 0x0004003d,0x00000009,0x00000225,0x00000224,0x000500ba,0x00000006,0x00000226,0x00000225, + 0x00000106,0x000600a9,0x00000009,0x00000227,0x00000226,0x000000ec,0x0000011a,0x00050041, + 0x00000036,0x00000228,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000229,0x00000228, + 0x00050081,0x00000009,0x0000022a,0x00000229,0x00000227,0x00050041,0x00000036,0x0000022b, + 0x0000018c,0x0000008d,0x0003003e,0x0000022b,0x0000022a,0x000200f9,0x00000218,0x000200f8, + 0x0000022c,0x00050041,0x00000036,0x0000022d,0x0000018c,0x0000008d,0x00050051,0x00000009, + 0x0000022e,0x00000186,0x00000000,0x0003003e,0x0000022d,0x0000022e,0x00050041,0x00000036, + 0x0000022f,0x0000018c,0x00000014,0x00050051,0x00000009,0x00000230,0x00000186,0x00000001, + 0x0003003e,0x0000022f,0x00000230,0x000200f9,0x00000218,0x000200f8,0x00000218,0x00050041, + 0x00000036,0x00000231,0x0000018c,0x00000084,0x0004003d,0x00000009,0x00000232,0x00000231, + 0x00050041,0x00000036,0x00000233,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000234, + 0x00000233,0x00050081,0x00000009,0x00000235,0x00000232,0x00000234,0x000500ba,0x00000006, + 0x00000236,0x00000235,0x000001b6,0x000300f7,0x00000238,0x00000000,0x000400fa,0x00000236, + 0x00000237,0x00000238,0x000200f8,0x00000237,0x00050041,0x00000036,0x0000023a,0x0000018c, + 0x00000084,0x0004003d,0x00000009,0x0000023b,0x0000023a,0x0004007f,0x00000009,0x0000023c, + 0x0000023b,0x00050041,0x00000036,0x0000023d,0x0000018c,0x00000084,0x0004003d,0x00000009, + 0x0000023e,0x0000023d,0x0004007f,0x00000009,0x0000023f,0x0000023e,0x00050041,0x00000036, + 0x00000240,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000241,0x00000240,0x00050041, + 0x00000036,0x00000242,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000243,0x00000242, + 0x00070050,0x00000012,0x00000244,0x0000023c,0x0000023f,0x00000241,0x00000243,0x00050041, + 0x0000009b,0x00000245,0x00000098,0x0000009a,0x0004003d,0x00000012,0x00000246,0x00000245, + 0x0009004f,0x00000012,0x00000247,0x00000246,0x00000246,0x00000000,0x00000001,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x00000248,0x00000041,0x0009004f,0x00000012,0x00000249, + 0x00000248,0x00000248,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000012, + 0x0000024a,0x00000001,0x00000032,0x00000244,0x00000247,0x00000249,0x0003003e,0x00000239, + 0x0000024a,0x0004003d,0x00000027,0x0000024c,0x0000003f,0x0004003d,0x00000012,0x0000024d, + 0x00000239,0x0007004f,0x0000000a,0x0000024e,0x0000024d,0x0000024d,0x00000000,0x00000001, + 0x00080058,0x00000012,0x0000024f,0x0000024c,0x0000024e,0x0000000a,0x0000011a,0x000001d4, + 0x00050051,0x00000009,0x00000250,0x0000024f,0x00000001,0x00050041,0x00000036,0x00000251, + 0x0000024b,0x00000084,0x0003003e,0x00000251,0x00000250,0x0004003d,0x00000027,0x00000252, + 0x0000003f,0x0004003d,0x00000012,0x00000253,0x00000239,0x0007004f,0x0000000a,0x00000254, + 0x00000253,0x00000253,0x00000000,0x00000001,0x00080058,0x00000012,0x00000256,0x00000252, + 0x00000254,0x0000000a,0x0000011a,0x00000255,0x00050051,0x00000009,0x00000257,0x00000256, + 0x00000000,0x00050041,0x00000036,0x00000258,0x0000024b,0x0000008d,0x0003003e,0x00000258, + 0x00000257,0x0004003d,0x00000027,0x00000259,0x0000003f,0x0004003d,0x00000012,0x0000025a, + 0x00000239,0x0007004f,0x0000000a,0x0000025b,0x0000025a,0x0000025a,0x00000002,0x00000003, + 0x00080058,0x00000012,0x0000025c,0x00000259,0x0000025b,0x0000000a,0x0000011a,0x000001de, + 0x0007004f,0x0000000a,0x0000025d,0x0000025c,0x0000025c,0x00000001,0x00000000,0x00050041, + 0x00000036,0x0000025e,0x0000024b,0x000000e2,0x00050051,0x00000009,0x0000025f,0x0000025d, + 0x00000000,0x0003003e,0x0000025e,0x0000025f,0x00050041,0x00000036,0x00000260,0x0000024b, + 0x00000014,0x00050051,0x00000009,0x00000261,0x0000025d,0x00000001,0x0003003e,0x00000260, + 0x00000261,0x0004003d,0x00000012,0x00000263,0x0000024b,0x0007004f,0x0000000a,0x00000264, + 0x00000263,0x00000263,0x00000000,0x00000002,0x0004003d,0x00000012,0x00000265,0x0000024b, + 0x0007004f,0x0000000a,0x00000266,0x00000265,0x00000265,0x00000001,0x00000003,0x0008000c, + 0x0000000a,0x00000267,0x00000001,0x00000032,0x000001eb,0x00000264,0x00000266,0x0003003e, + 0x00000262,0x00000267,0x0004003d,0x00000012,0x00000268,0x0000018c,0x0007004f,0x0000000a, + 0x00000269,0x00000268,0x00000268,0x00000002,0x00000003,0x00050050,0x0000000a,0x0000026a, + 0x00000106,0x00000106,0x0007000c,0x0000000a,0x0000026b,0x00000001,0x00000030,0x0000026a, + 0x00000269,0x000500b7,0x00000007,0x0000026c,0x0000026b,0x00000186,0x0003003e,0x0000026d, + 0x0000026c,0x0004003d,0x0000000a,0x0000026f,0x00000262,0x0003003e,0x0000026e,0x0000026f, + 0x0003003e,0x00000270,0x00000186,0x00070039,0x00000002,0x00000271,0x00000010,0x0000026d, + 0x0000026e,0x00000270,0x0004003d,0x0000000a,0x00000272,0x0000026e,0x0003003e,0x00000262, + 0x00000272,0x0004003d,0x00000012,0x00000274,0x0000018c,0x0007004f,0x0000000a,0x00000275, + 0x00000274,0x00000274,0x00000000,0x00000001,0x0003003e,0x00000273,0x00000275,0x0004003d, + 0x0000000a,0x00000277,0x00000262,0x0003003e,0x00000276,0x00000277,0x00050041,0x00000036, + 0x00000279,0x00000043,0x00000014,0x0004003d,0x00000009,0x0000027a,0x00000279,0x0003003e, + 0x00000278,0x0000027a,0x00080039,0x0000000a,0x0000027b,0x0000003c,0x00000040,0x00000273, + 0x00000276,0x00000278,0x0007004f,0x0000000a,0x0000027c,0x0000027b,0x0000027b,0x00000001, + 0x00000000,0x0004003d,0x0000000a,0x0000027d,0x00000185,0x00050081,0x0000000a,0x0000027e, + 0x0000027d,0x0000027c,0x0003003e,0x00000185,0x0000027e,0x000200f9,0x00000238,0x000200f8, + 0x00000238,0x0004003d,0x0000000a,0x0000027f,0x00000185,0x000200fe,0x0000027f,0x00010038, + 0x00050036,0x00000009,0x0000004a,0x00000000,0x00000046,0x00030037,0x00000028,0x00000047, + 0x00030037,0x0000000b,0x00000048,0x00030037,0x00000036,0x00000049,0x000200f8,0x0000004b, + 0x0004003b,0x0000000b,0x00000282,0x00000007,0x0004003b,0x0000000b,0x00000286,0x00000007, + 0x0003003e,0x00000282,0x00000285,0x0004003d,0x00000009,0x00000289,0x00000049,0x00050050, + 0x0000000a,0x0000028a,0x00000289,0x000000ec,0x00050085,0x0000000a,0x0000028b,0x00000288, + 0x0000028a,0x0003003e,0x00000286,0x0000028b,0x0004003d,0x0000000a,0x0000028c,0x00000282, + 0x00050081,0x0000000a,0x0000028d,0x0000028c,0x0000018d,0x0003003e,0x00000282,0x0000028d, + 0x0004003d,0x0000000a,0x00000290,0x00000286,0x00050081,0x0000000a,0x00000291,0x00000290, + 0x0000028f,0x0003003e,0x00000286,0x00000291,0x0004003d,0x0000000a,0x00000295,0x00000282, + 0x00050085,0x0000000a,0x00000296,0x00000295,0x00000294,0x0003003e,0x00000282,0x00000296, + 0x0004003d,0x0000000a,0x00000297,0x00000286,0x00050085,0x0000000a,0x00000298,0x00000297, + 0x00000294,0x0003003e,0x00000286,0x00000298,0x0004003d,0x00000027,0x00000299,0x00000047, + 0x0004003d,0x0000000a,0x0000029a,0x00000282,0x0004003d,0x0000000a,0x0000029b,0x00000048, + 0x0004003d,0x0000000a,0x0000029c,0x00000286,0x0008000c,0x0000000a,0x0000029d,0x00000001, + 0x00000032,0x0000029a,0x0000029b,0x0000029c,0x00070058,0x00000012,0x0000029e,0x00000299, + 0x0000029d,0x00000002,0x0000011a,0x00050051,0x00000009,0x0000029f,0x0000029e,0x00000000, + 0x000200fe,0x0000029f,0x00010038,0x00050036,0x00000009,0x00000051,0x00000000,0x0000004c, + 0x00030037,0x00000028,0x0000004d,0x00030037,0x00000028,0x0000004e,0x00030037,0x0000000b, + 0x0000004f,0x00030037,0x00000036,0x00000050,0x000200f8,0x00000052,0x0004003b,0x0000000b, + 0x000002a2,0x00000007,0x0004003b,0x00000036,0x000002c6,0x00000007,0x0004003b,0x0000000b, + 0x000002c8,0x00000007,0x0004003b,0x00000036,0x000002ca,0x00000007,0x0003003e,0x000002a2, + 0x000002a3,0x000200f9,0x000002a4,0x000200f8,0x000002a4,0x000400f6,0x000002a6,0x000002a7, + 0x00000000,0x000200f9,0x000002a8,0x000200f8,0x000002a8,0x00050041,0x00000036,0x000002a9, + 0x0000004f,0x00000084,0x0004003d,0x00000009,0x000002aa,0x000002a9,0x0004003d,0x00000009, + 0x000002ab,0x00000050,0x000500ba,0x00000006,0x000002ac,0x000002aa,0x000002ab,0x000300f7, + 0x000002ae,0x00000000,0x000400fa,0x000002ac,0x000002ad,0x000002ae,0x000200f8,0x000002ad, + 0x00050041,0x00000036,0x000002af,0x000002a2,0x0000008d,0x0004003d,0x00000009,0x000002b0, + 0x000002af,0x000500ba,0x00000006,0x000002b2,0x000002b0,0x000002b1,0x000200f9,0x000002ae, + 0x000200f8,0x000002ae,0x000700f5,0x00000006,0x000002b3,0x000002ac,0x000002a8,0x000002b2, + 0x000002ad,0x000300f7,0x000002b5,0x00000000,0x000400fa,0x000002b3,0x000002b4,0x000002b5, + 0x000200f8,0x000002b4,0x00050041,0x00000036,0x000002b6,0x000002a2,0x00000084,0x0004003d, + 0x00000009,0x000002b7,0x000002b6,0x000500b4,0x00000006,0x000002b8,0x000002b7,0x0000011a, + 0x000200f9,0x000002b5,0x000200f8,0x000002b5,0x000700f5,0x00000006,0x000002b9,0x000002b3, + 0x000002ae,0x000002b8,0x000002b4,0x000400fa,0x000002b9,0x000002a5,0x000002a6,0x000200f8, + 0x000002a5,0x0004003d,0x00000027,0x000002ba,0x0000004d,0x0004003d,0x0000000a,0x000002bb, + 0x0000004f,0x00070058,0x00000012,0x000002bc,0x000002ba,0x000002bb,0x00000002,0x0000011a, + 0x0007004f,0x0000000a,0x000002bd,0x000002bc,0x000002bc,0x00000000,0x00000001,0x0003003e, + 0x000002a2,0x000002bd,0x00050041,0x0000009b,0x000002c1,0x00000098,0x0000009a,0x0004003d, + 0x00000012,0x000002c2,0x000002c1,0x0007004f,0x0000000a,0x000002c3,0x000002c2,0x000002c2, + 0x00000000,0x00000001,0x0004003d,0x0000000a,0x000002c4,0x0000004f,0x0008000c,0x0000000a, + 0x000002c5,0x00000001,0x00000032,0x000002c0,0x000002c3,0x000002c4,0x0003003e,0x0000004f, + 0x000002c5,0x000200f9,0x000002a7,0x000200f8,0x000002a7,0x000200f9,0x000002a4,0x000200f8, + 0x000002a6,0x0004003d,0x0000000a,0x000002c9,0x000002a2,0x0003003e,0x000002c8,0x000002c9, + 0x0003003e,0x000002ca,0x0000011a,0x00070039,0x00000009,0x000002cb,0x0000004a,0x0000004e, + 0x000002c8,0x000002ca,0x0008000c,0x00000009,0x000002cd,0x00000001,0x00000032,0x000002c7, + 0x000002cb,0x000002cc,0x0003003e,0x000002c6,0x000002cd,0x00060041,0x0000012c,0x000002ce, + 0x00000098,0x0000009a,0x00000084,0x0004003d,0x00000009,0x000002cf,0x000002ce,0x0004003d, + 0x00000009,0x000002d0,0x000002c6,0x00050041,0x00000036,0x000002d1,0x0000004f,0x00000084, + 0x0004003d,0x00000009,0x000002d2,0x000002d1,0x0008000c,0x00000009,0x000002d3,0x00000001, + 0x00000032,0x000002cf,0x000002d0,0x000002d2,0x000200fe,0x000002d3,0x00010038,0x00050036, + 0x00000009,0x00000057,0x00000000,0x0000004c,0x00030037,0x00000028,0x00000053,0x00030037, + 0x00000028,0x00000054,0x00030037,0x0000000b,0x00000055,0x00030037,0x00000036,0x00000056, + 0x000200f8,0x00000058,0x0004003b,0x0000000b,0x000002d6,0x00000007,0x0004003b,0x00000036, + 0x000002f6,0x00000007,0x0004003b,0x0000000b,0x000002f7,0x00000007,0x0004003b,0x00000036, + 0x000002f9,0x00000007,0x0003003e,0x000002d6,0x000002a3,0x000200f9,0x000002d7,0x000200f8, + 0x000002d7,0x000400f6,0x000002d9,0x000002da,0x00000000,0x000200f9,0x000002db,0x000200f8, + 0x000002db,0x00050041,0x00000036,0x000002dc,0x00000055,0x00000084,0x0004003d,0x00000009, + 0x000002dd,0x000002dc,0x0004003d,0x00000009,0x000002de,0x00000056,0x000500b8,0x00000006, + 0x000002df,0x000002dd,0x000002de,0x000300f7,0x000002e1,0x00000000,0x000400fa,0x000002df, + 0x000002e0,0x000002e1,0x000200f8,0x000002e0,0x00050041,0x00000036,0x000002e2,0x000002d6, + 0x0000008d,0x0004003d,0x00000009,0x000002e3,0x000002e2,0x000500ba,0x00000006,0x000002e4, + 0x000002e3,0x000002b1,0x000200f9,0x000002e1,0x000200f8,0x000002e1,0x000700f5,0x00000006, + 0x000002e5,0x000002df,0x000002db,0x000002e4,0x000002e0,0x000300f7,0x000002e7,0x00000000, + 0x000400fa,0x000002e5,0x000002e6,0x000002e7,0x000200f8,0x000002e6,0x00050041,0x00000036, + 0x000002e8,0x000002d6,0x00000084,0x0004003d,0x00000009,0x000002e9,0x000002e8,0x000500b4, + 0x00000006,0x000002ea,0x000002e9,0x0000011a,0x000200f9,0x000002e7,0x000200f8,0x000002e7, + 0x000700f5,0x00000006,0x000002eb,0x000002e5,0x000002e1,0x000002ea,0x000002e6,0x000400fa, + 0x000002eb,0x000002d8,0x000002d9,0x000200f8,0x000002d8,0x0004003d,0x00000027,0x000002ec, + 0x00000053,0x0004003d,0x0000000a,0x000002ed,0x00000055,0x00070058,0x00000012,0x000002ee, + 0x000002ec,0x000002ed,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x000002ef,0x000002ee, + 0x000002ee,0x00000000,0x00000001,0x0003003e,0x000002d6,0x000002ef,0x00050041,0x0000009b, + 0x000002f1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000002f2,0x000002f1,0x0007004f, + 0x0000000a,0x000002f3,0x000002f2,0x000002f2,0x00000000,0x00000001,0x0004003d,0x0000000a, + 0x000002f4,0x00000055,0x0008000c,0x0000000a,0x000002f5,0x00000001,0x00000032,0x000002f0, + 0x000002f3,0x000002f4,0x0003003e,0x00000055,0x000002f5,0x000200f9,0x000002da,0x000200f8, + 0x000002da,0x000200f9,0x000002d7,0x000200f8,0x000002d9,0x0004003d,0x0000000a,0x000002f8, + 0x000002d6,0x0003003e,0x000002f7,0x000002f8,0x0003003e,0x000002f9,0x0000011e,0x00070039, + 0x00000009,0x000002fa,0x0000004a,0x00000054,0x000002f7,0x000002f9,0x0008000c,0x00000009, + 0x000002fb,0x00000001,0x00000032,0x000002c7,0x000002fa,0x000002cc,0x0003003e,0x000002f6, + 0x000002fb,0x00060041,0x0000012c,0x000002fc,0x00000098,0x0000009a,0x00000084,0x0004003d, + 0x00000009,0x000002fd,0x000002fc,0x0004007f,0x00000009,0x000002fe,0x000002fd,0x0004003d, + 0x00000009,0x000002ff,0x000002f6,0x00050041,0x00000036,0x00000300,0x00000055,0x00000084, + 0x0004003d,0x00000009,0x00000301,0x00000300,0x0008000c,0x00000009,0x00000302,0x00000001, + 0x00000032,0x000002fe,0x000002ff,0x00000301,0x000200fe,0x00000302,0x00010038,0x00050036, + 0x00000009,0x0000005d,0x00000000,0x0000004c,0x00030037,0x00000028,0x00000059,0x00030037, + 0x00000028,0x0000005a,0x00030037,0x0000000b,0x0000005b,0x00030037,0x00000036,0x0000005c, + 0x000200f8,0x0000005e,0x0004003b,0x0000000b,0x00000305,0x00000007,0x0004003b,0x00000036, + 0x00000326,0x00000007,0x0004003b,0x0000000b,0x00000327,0x00000007,0x0004003b,0x00000036, + 0x0000032a,0x00000007,0x0003003e,0x00000305,0x00000306,0x000200f9,0x00000307,0x000200f8, + 0x00000307,0x000400f6,0x00000309,0x0000030a,0x00000000,0x000200f9,0x0000030b,0x000200f8, + 0x0000030b,0x00050041,0x00000036,0x0000030c,0x0000005b,0x0000008d,0x0004003d,0x00000009, + 0x0000030d,0x0000030c,0x0004003d,0x00000009,0x0000030e,0x0000005c,0x000500ba,0x00000006, + 0x0000030f,0x0000030d,0x0000030e,0x000300f7,0x00000311,0x00000000,0x000400fa,0x0000030f, + 0x00000310,0x00000311,0x000200f8,0x00000310,0x00050041,0x00000036,0x00000312,0x00000305, + 0x00000084,0x0004003d,0x00000009,0x00000313,0x00000312,0x000500ba,0x00000006,0x00000314, + 0x00000313,0x000002b1,0x000200f9,0x00000311,0x000200f8,0x00000311,0x000700f5,0x00000006, + 0x00000315,0x0000030f,0x0000030b,0x00000314,0x00000310,0x000300f7,0x00000317,0x00000000, + 0x000400fa,0x00000315,0x00000316,0x00000317,0x000200f8,0x00000316,0x00050041,0x00000036, + 0x00000318,0x00000305,0x0000008d,0x0004003d,0x00000009,0x00000319,0x00000318,0x000500b4, + 0x00000006,0x0000031a,0x00000319,0x0000011a,0x000200f9,0x00000317,0x000200f8,0x00000317, + 0x000700f5,0x00000006,0x0000031b,0x00000315,0x00000311,0x0000031a,0x00000316,0x000400fa, + 0x0000031b,0x00000308,0x00000309,0x000200f8,0x00000308,0x0004003d,0x00000027,0x0000031c, + 0x00000059,0x0004003d,0x0000000a,0x0000031d,0x0000005b,0x00070058,0x00000012,0x0000031e, + 0x0000031c,0x0000031d,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000031f,0x0000031e, + 0x0000031e,0x00000000,0x00000001,0x0003003e,0x00000305,0x0000031f,0x00050041,0x0000009b, + 0x00000321,0x00000098,0x0000009a,0x0004003d,0x00000012,0x00000322,0x00000321,0x0007004f, + 0x0000000a,0x00000323,0x00000322,0x00000322,0x00000000,0x00000001,0x0004003d,0x0000000a, + 0x00000324,0x0000005b,0x0008000c,0x0000000a,0x00000325,0x00000001,0x00000032,0x00000320, + 0x00000323,0x00000324,0x0003003e,0x0000005b,0x00000325,0x000200f9,0x0000030a,0x000200f8, + 0x0000030a,0x000200f9,0x00000307,0x000200f8,0x00000309,0x0004003d,0x0000000a,0x00000328, + 0x00000305,0x0007004f,0x0000000a,0x00000329,0x00000328,0x00000328,0x00000001,0x00000000, + 0x0003003e,0x00000327,0x00000329,0x0003003e,0x0000032a,0x0000011a,0x00070039,0x00000009, + 0x0000032b,0x0000004a,0x0000005a,0x00000327,0x0000032a,0x0008000c,0x00000009,0x0000032c, + 0x00000001,0x00000032,0x000002c7,0x0000032b,0x000002cc,0x0003003e,0x00000326,0x0000032c, + 0x00060041,0x0000012c,0x0000032d,0x00000098,0x0000009a,0x0000008d,0x0004003d,0x00000009, + 0x0000032e,0x0000032d,0x0004003d,0x00000009,0x0000032f,0x00000326,0x00050041,0x00000036, + 0x00000330,0x0000005b,0x0000008d,0x0004003d,0x00000009,0x00000331,0x00000330,0x0008000c, + 0x00000009,0x00000332,0x00000001,0x00000032,0x0000032e,0x0000032f,0x00000331,0x000200fe, + 0x00000332,0x00010038,0x00050036,0x00000009,0x00000063,0x00000000,0x0000004c,0x00030037, + 0x00000028,0x0000005f,0x00030037,0x00000028,0x00000060,0x00030037,0x0000000b,0x00000061, + 0x00030037,0x00000036,0x00000062,0x000200f8,0x00000064,0x0004003b,0x0000000b,0x00000335, + 0x00000007,0x0004003b,0x00000036,0x00000355,0x00000007,0x0004003b,0x0000000b,0x00000356, + 0x00000007,0x0004003b,0x00000036,0x00000359,0x00000007,0x0003003e,0x00000335,0x00000306, + 0x000200f9,0x00000336,0x000200f8,0x00000336,0x000400f6,0x00000338,0x00000339,0x00000000, + 0x000200f9,0x0000033a,0x000200f8,0x0000033a,0x00050041,0x00000036,0x0000033b,0x00000061, + 0x0000008d,0x0004003d,0x00000009,0x0000033c,0x0000033b,0x0004003d,0x00000009,0x0000033d, + 0x00000062,0x000500b8,0x00000006,0x0000033e,0x0000033c,0x0000033d,0x000300f7,0x00000340, + 0x00000000,0x000400fa,0x0000033e,0x0000033f,0x00000340,0x000200f8,0x0000033f,0x00050041, + 0x00000036,0x00000341,0x00000335,0x00000084,0x0004003d,0x00000009,0x00000342,0x00000341, + 0x000500ba,0x00000006,0x00000343,0x00000342,0x000002b1,0x000200f9,0x00000340,0x000200f8, + 0x00000340,0x000700f5,0x00000006,0x00000344,0x0000033e,0x0000033a,0x00000343,0x0000033f, + 0x000300f7,0x00000346,0x00000000,0x000400fa,0x00000344,0x00000345,0x00000346,0x000200f8, + 0x00000345,0x00050041,0x00000036,0x00000347,0x00000335,0x0000008d,0x0004003d,0x00000009, + 0x00000348,0x00000347,0x000500b4,0x00000006,0x00000349,0x00000348,0x0000011a,0x000200f9, + 0x00000346,0x000200f8,0x00000346,0x000700f5,0x00000006,0x0000034a,0x00000344,0x00000340, + 0x00000349,0x00000345,0x000400fa,0x0000034a,0x00000337,0x00000338,0x000200f8,0x00000337, + 0x0004003d,0x00000027,0x0000034b,0x0000005f,0x0004003d,0x0000000a,0x0000034c,0x00000061, + 0x00070058,0x00000012,0x0000034d,0x0000034b,0x0000034c,0x00000002,0x0000011a,0x0007004f, + 0x0000000a,0x0000034e,0x0000034d,0x0000034d,0x00000000,0x00000001,0x0003003e,0x00000335, + 0x0000034e,0x00050041,0x0000009b,0x00000350,0x00000098,0x0000009a,0x0004003d,0x00000012, + 0x00000351,0x00000350,0x0007004f,0x0000000a,0x00000352,0x00000351,0x00000351,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x00000353,0x00000061,0x0008000c,0x0000000a,0x00000354, + 0x00000001,0x00000032,0x0000034f,0x00000352,0x00000353,0x0003003e,0x00000061,0x00000354, + 0x000200f9,0x00000339,0x000200f8,0x00000339,0x000200f9,0x00000336,0x000200f8,0x00000338, + 0x0004003d,0x0000000a,0x00000357,0x00000335,0x0007004f,0x0000000a,0x00000358,0x00000357, + 0x00000357,0x00000001,0x00000000,0x0003003e,0x00000356,0x00000358,0x0003003e,0x00000359, + 0x0000011e,0x00070039,0x00000009,0x0000035a,0x0000004a,0x00000060,0x00000356,0x00000359, + 0x0008000c,0x00000009,0x0000035b,0x00000001,0x00000032,0x000002c7,0x0000035a,0x000002cc, + 0x0003003e,0x00000355,0x0000035b,0x00060041,0x0000012c,0x0000035c,0x00000098,0x0000009a, + 0x0000008d,0x0004003d,0x00000009,0x0000035d,0x0000035c,0x0004007f,0x00000009,0x0000035e, + 0x0000035d,0x0004003d,0x00000009,0x0000035f,0x00000355,0x00050041,0x00000036,0x00000360, + 0x00000061,0x0000008d,0x0004003d,0x00000009,0x00000361,0x00000360,0x0008000c,0x00000009, + 0x00000362,0x00000001,0x00000032,0x0000035e,0x0000035f,0x00000361,0x000200fe,0x00000362, + 0x00010038,0x00050036,0x0000000a,0x0000006b,0x00000000,0x00000065,0x00030037,0x00000028, + 0x00000066,0x00030037,0x0000000b,0x00000067,0x00030037,0x00000036,0x00000068,0x00030037, + 0x00000036,0x00000069,0x00030037,0x00000036,0x0000006a,0x000200f8,0x0000006c,0x0004003b, + 0x0000000b,0x00000365,0x00000007,0x0004003d,0x00000009,0x00000369,0x00000068,0x0004003d, + 0x00000009,0x0000036a,0x00000069,0x00050050,0x0000000a,0x0000036b,0x00000369,0x0000036a, + 0x0005008e,0x0000000a,0x0000036c,0x0000036b,0x00000368,0x0006000c,0x0000000a,0x0000036d, + 0x00000001,0x00000001,0x0000036c,0x0004003d,0x0000000a,0x0000036e,0x00000067,0x0008000c, + 0x0000000a,0x0000036f,0x00000001,0x00000032,0x00000367,0x0000036d,0x0000036e,0x0003003e, + 0x00000365,0x0000036f,0x0004003d,0x0000000a,0x00000370,0x00000365,0x0008000c,0x0000000a, + 0x00000371,0x00000001,0x00000032,0x0000016e,0x00000370,0x00000172,0x0003003e,0x00000365, + 0x00000371,0x0004003d,0x00000009,0x00000372,0x0000006a,0x00050041,0x00000036,0x00000373, + 0x00000365,0x0000008d,0x0004003d,0x00000009,0x00000374,0x00000373,0x0008000c,0x00000009, + 0x00000375,0x00000001,0x00000032,0x00000178,0x00000372,0x00000374,0x00050041,0x00000036, + 0x00000376,0x00000365,0x0000008d,0x0003003e,0x00000376,0x00000375,0x0004003d,0x00000027, + 0x00000377,0x00000066,0x0004003d,0x0000000a,0x00000378,0x00000365,0x00070058,0x00000012, + 0x00000379,0x00000377,0x00000378,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000037a, + 0x00000379,0x00000379,0x00000000,0x00000001,0x000200fe,0x0000037a,0x00010038,0x00050036, + 0x00000002,0x00000072,0x00000000,0x0000006d,0x00030037,0x00000028,0x0000006e,0x00030037, + 0x0000000b,0x0000006f,0x00030037,0x00000021,0x00000070,0x00030037,0x0000000b,0x00000071, + 0x000200f8,0x00000073,0x0004003b,0x0000000b,0x0000037d,0x00000007,0x0004003b,0x0000000b, + 0x00000382,0x00000007,0x0004003b,0x0000000b,0x0000038e,0x00000007,0x0004003d,0x0000000a, + 0x0000037e,0x00000071,0x0004003d,0x0000000a,0x0000037f,0x00000071,0x0007004f,0x0000000a, + 0x00000380,0x0000037f,0x0000037f,0x00000001,0x00000000,0x0007000c,0x0000000a,0x00000381, + 0x00000001,0x00000030,0x0000037e,0x00000380,0x0003003e,0x0000037d,0x00000381,0x0004003d, + 0x0000000a,0x00000384,0x0000037d,0x0005008e,0x0000000a,0x00000385,0x00000384,0x00000383, + 0x0003003e,0x00000382,0x00000385,0x00050041,0x00000036,0x00000386,0x0000037d,0x00000084, + 0x0004003d,0x00000009,0x00000387,0x00000386,0x00050041,0x00000036,0x00000388,0x0000037d, + 0x0000008d,0x0004003d,0x00000009,0x00000389,0x00000388,0x00050081,0x00000009,0x0000038a, + 0x00000387,0x00000389,0x0004003d,0x0000000a,0x0000038b,0x00000382,0x00050050,0x0000000a, + 0x0000038c,0x0000038a,0x0000038a,0x00050088,0x0000000a,0x0000038d,0x0000038b,0x0000038c, + 0x0003003e,0x00000382,0x0000038d,0x0003003e,0x0000038e,0x00000219,0x00050041,0x00000036, + 0x0000038f,0x00000382,0x00000084,0x0004003d,0x00000009,0x00000390,0x0000038f,0x0004003d, + 0x00000027,0x00000391,0x0000006e,0x0004003d,0x00000012,0x00000392,0x00000070,0x0007004f, + 0x0000000a,0x00000393,0x00000392,0x00000392,0x00000000,0x00000001,0x00080058,0x00000012, + 0x00000395,0x00000391,0x00000393,0x0000000a,0x0000011a,0x00000394,0x00050051,0x00000009, + 0x00000396,0x00000395,0x00000000,0x00050085,0x00000009,0x00000397,0x00000390,0x00000396, + 0x00050041,0x00000036,0x00000398,0x0000038e,0x00000084,0x0004003d,0x00000009,0x00000399, + 0x00000398,0x00050083,0x00000009,0x0000039a,0x00000399,0x00000397,0x00050041,0x00000036, + 0x0000039b,0x0000038e,0x00000084,0x0003003e,0x0000039b,0x0000039a,0x00050041,0x00000036, + 0x0000039c,0x00000382,0x0000008d,0x0004003d,0x00000009,0x0000039d,0x0000039c,0x0004003d, + 0x00000027,0x0000039e,0x0000006e,0x0004003d,0x00000012,0x0000039f,0x00000070,0x0007004f, + 0x0000000a,0x000003a0,0x0000039f,0x0000039f,0x00000002,0x00000003,0x00080058,0x00000012, + 0x000003a2,0x0000039e,0x000003a0,0x0000000a,0x0000011a,0x000003a1,0x00050051,0x00000009, + 0x000003a3,0x000003a2,0x00000000,0x00050085,0x00000009,0x000003a4,0x0000039d,0x000003a3, + 0x00050041,0x00000036,0x000003a5,0x0000038e,0x00000084,0x0004003d,0x00000009,0x000003a6, + 0x000003a5,0x00050083,0x00000009,0x000003a7,0x000003a6,0x000003a4,0x00050041,0x00000036, + 0x000003a8,0x0000038e,0x00000084,0x0003003e,0x000003a8,0x000003a7,0x00050041,0x00000036, + 0x000003a9,0x00000382,0x00000084,0x0004003d,0x00000009,0x000003aa,0x000003a9,0x0004003d, + 0x00000027,0x000003ab,0x0000006e,0x0004003d,0x00000012,0x000003ac,0x00000070,0x0007004f, + 0x0000000a,0x000003ad,0x000003ac,0x000003ac,0x00000000,0x00000001,0x00080058,0x00000012, + 0x000003b0,0x000003ab,0x000003ad,0x0000000a,0x0000011a,0x000003af,0x00050051,0x00000009, + 0x000003b1,0x000003b0,0x00000000,0x00050085,0x00000009,0x000003b2,0x000003aa,0x000003b1, + 0x00050041,0x00000036,0x000003b3,0x0000038e,0x0000008d,0x0004003d,0x00000009,0x000003b4, + 0x000003b3,0x00050083,0x00000009,0x000003b5,0x000003b4,0x000003b2,0x00050041,0x00000036, + 0x000003b6,0x0000038e,0x0000008d,0x0003003e,0x000003b6,0x000003b5,0x00050041,0x00000036, + 0x000003b7,0x00000382,0x0000008d,0x0004003d,0x00000009,0x000003b8,0x000003b7,0x0004003d, + 0x00000027,0x000003b9,0x0000006e,0x0004003d,0x00000012,0x000003ba,0x00000070,0x0007004f, + 0x0000000a,0x000003bb,0x000003ba,0x000003ba,0x00000002,0x00000003,0x00080058,0x00000012, + 0x000003bd,0x000003b9,0x000003bb,0x0000000a,0x0000011a,0x000003bc,0x00050051,0x00000009, + 0x000003be,0x000003bd,0x00000000,0x00050085,0x00000009,0x000003bf,0x000003b8,0x000003be, + 0x00050041,0x00000036,0x000003c0,0x0000038e,0x0000008d,0x0004003d,0x00000009,0x000003c1, + 0x000003c0,0x00050083,0x00000009,0x000003c2,0x000003c1,0x000003bf,0x00050041,0x00000036, + 0x000003c3,0x0000038e,0x0000008d,0x0003003e,0x000003c3,0x000003c2,0x0004003d,0x0000000a, + 0x000003c4,0x0000038e,0x00050050,0x0000000a,0x000003c5,0x0000011a,0x0000011a,0x00050050, + 0x0000000a,0x000003c6,0x000000ec,0x000000ec,0x0008000c,0x0000000a,0x000003c7,0x00000001, + 0x0000002b,0x000003c4,0x000003c5,0x000003c6,0x0004003d,0x0000000a,0x000003c8,0x0000006f, + 0x00050085,0x0000000a,0x000003c9,0x000003c8,0x000003c7,0x0003003e,0x0000006f,0x000003c9, + 0x000100fd,0x00010038,0x00050036,0x00000002,0x00000078,0x00000000,0x0000006d,0x00030037, + 0x00000028,0x00000074,0x00030037,0x0000000b,0x00000075,0x00030037,0x00000021,0x00000076, + 0x00030037,0x0000000b,0x00000077,0x000200f8,0x00000079,0x0004003b,0x0000000b,0x000003ca, + 0x00000007,0x0004003b,0x0000000b,0x000003cf,0x00000007,0x0004003b,0x0000000b,0x000003da, + 0x00000007,0x0004003d,0x0000000a,0x000003cb,0x00000077,0x0004003d,0x0000000a,0x000003cc, + 0x00000077,0x0007004f,0x0000000a,0x000003cd,0x000003cc,0x000003cc,0x00000001,0x00000000, + 0x0007000c,0x0000000a,0x000003ce,0x00000001,0x00000030,0x000003cb,0x000003cd,0x0003003e, + 0x000003ca,0x000003ce,0x0004003d,0x0000000a,0x000003d0,0x000003ca,0x0005008e,0x0000000a, + 0x000003d1,0x000003d0,0x00000383,0x0003003e,0x000003cf,0x000003d1,0x00050041,0x00000036, + 0x000003d2,0x000003ca,0x00000084,0x0004003d,0x00000009,0x000003d3,0x000003d2,0x00050041, + 0x00000036,0x000003d4,0x000003ca,0x0000008d,0x0004003d,0x00000009,0x000003d5,0x000003d4, + 0x00050081,0x00000009,0x000003d6,0x000003d3,0x000003d5,0x0004003d,0x0000000a,0x000003d7, + 0x000003cf,0x00050050,0x0000000a,0x000003d8,0x000003d6,0x000003d6,0x00050088,0x0000000a, + 0x000003d9,0x000003d7,0x000003d8,0x0003003e,0x000003cf,0x000003d9,0x0003003e,0x000003da, + 0x00000219,0x00050041,0x00000036,0x000003db,0x000003cf,0x00000084,0x0004003d,0x00000009, + 0x000003dc,0x000003db,0x0004003d,0x00000027,0x000003dd,0x00000074,0x0004003d,0x00000012, + 0x000003de,0x00000076,0x0007004f,0x0000000a,0x000003df,0x000003de,0x000003de,0x00000000, + 0x00000001,0x00080058,0x00000012,0x000003e0,0x000003dd,0x000003df,0x0000000a,0x0000011a, + 0x000001de,0x00050051,0x00000009,0x000003e1,0x000003e0,0x00000001,0x00050085,0x00000009, + 0x000003e2,0x000003dc,0x000003e1,0x00050041,0x00000036,0x000003e3,0x000003da,0x00000084, + 0x0004003d,0x00000009,0x000003e4,0x000003e3,0x00050083,0x00000009,0x000003e5,0x000003e4, + 0x000003e2,0x00050041,0x00000036,0x000003e6,0x000003da,0x00000084,0x0003003e,0x000003e6, + 0x000003e5,0x00050041,0x00000036,0x000003e7,0x000003cf,0x0000008d,0x0004003d,0x00000009, + 0x000003e8,0x000003e7,0x0004003d,0x00000027,0x000003e9,0x00000074,0x0004003d,0x00000012, + 0x000003ea,0x00000076,0x0007004f,0x0000000a,0x000003eb,0x000003ea,0x000003ea,0x00000002, + 0x00000003,0x00080058,0x00000012,0x000003ec,0x000003e9,0x000003eb,0x0000000a,0x0000011a, + 0x000003a1,0x00050051,0x00000009,0x000003ed,0x000003ec,0x00000001,0x00050085,0x00000009, + 0x000003ee,0x000003e8,0x000003ed,0x00050041,0x00000036,0x000003ef,0x000003da,0x00000084, + 0x0004003d,0x00000009,0x000003f0,0x000003ef,0x00050083,0x00000009,0x000003f1,0x000003f0, + 0x000003ee,0x00050041,0x00000036,0x000003f2,0x000003da,0x00000084,0x0003003e,0x000003f2, + 0x000003f1,0x00050041,0x00000036,0x000003f3,0x000003cf,0x00000084,0x0004003d,0x00000009, + 0x000003f4,0x000003f3,0x0004003d,0x00000027,0x000003f5,0x00000074,0x0004003d,0x00000012, + 0x000003f6,0x00000076,0x0007004f,0x0000000a,0x000003f7,0x000003f6,0x000003f6,0x00000000, + 0x00000001,0x00080058,0x00000012,0x000003f9,0x000003f5,0x000003f7,0x0000000a,0x0000011a, + 0x000003f8,0x00050051,0x00000009,0x000003fa,0x000003f9,0x00000001,0x00050085,0x00000009, + 0x000003fb,0x000003f4,0x000003fa,0x00050041,0x00000036,0x000003fc,0x000003da,0x0000008d, + 0x0004003d,0x00000009,0x000003fd,0x000003fc,0x00050083,0x00000009,0x000003fe,0x000003fd, + 0x000003fb,0x00050041,0x00000036,0x000003ff,0x000003da,0x0000008d,0x0003003e,0x000003ff, + 0x000003fe,0x00050041,0x00000036,0x00000400,0x000003cf,0x0000008d,0x0004003d,0x00000009, + 0x00000401,0x00000400,0x0004003d,0x00000027,0x00000402,0x00000074,0x0004003d,0x00000012, + 0x00000403,0x00000076,0x0007004f,0x0000000a,0x00000404,0x00000403,0x00000403,0x00000002, + 0x00000003,0x00080058,0x00000012,0x00000406,0x00000402,0x00000404,0x0000000a,0x0000011a, + 0x00000405,0x00050051,0x00000009,0x00000407,0x00000406,0x00000001,0x00050085,0x00000009, + 0x00000408,0x00000401,0x00000407,0x00050041,0x00000036,0x00000409,0x000003da,0x0000008d, + 0x0004003d,0x00000009,0x0000040a,0x00000409,0x00050083,0x00000009,0x0000040b,0x0000040a, + 0x00000408,0x00050041,0x00000036,0x0000040c,0x000003da,0x0000008d,0x0003003e,0x0000040c, + 0x0000040b,0x0004003d,0x0000000a,0x0000040d,0x000003da,0x00050050,0x0000000a,0x0000040e, + 0x0000011a,0x0000011a,0x00050050,0x0000000a,0x0000040f,0x000000ec,0x000000ec,0x0008000c, + 0x0000000a,0x00000410,0x00000001,0x0000002b,0x0000040d,0x0000040e,0x0000040f,0x0004003d, + 0x0000000a,0x00000411,0x00000075,0x00050085,0x0000000a,0x00000412,0x00000411,0x00000410, + 0x0003003e,0x00000075,0x00000412,0x000100fd,0x00010038,0x00050036,0x00000012,0x00000082, + 0x00000000,0x0000007a,0x00030037,0x0000000b,0x0000007b,0x00030037,0x0000000b,0x0000007c, + 0x00030037,0x00000016,0x0000007d,0x00030037,0x00000028,0x0000007e,0x00030037,0x00000028, + 0x0000007f,0x00030037,0x00000028,0x00000080,0x00030037,0x00000021,0x00000081,0x000200f8, + 0x00000083,0x0004003b,0x00000021,0x00000413,0x00000007,0x0004003b,0x0000000b,0x00000415, + 0x00000007,0x0004003b,0x0000000b,0x0000041f,0x00000007,0x0004003b,0x0000000b,0x00000421, + 0x00000007,0x0004003b,0x00000021,0x00000423,0x00000007,0x0004003b,0x000000f1,0x00000432, + 0x00000007,0x0004003b,0x0000000b,0x00000433,0x00000007,0x0004003b,0x00000036,0x00000437, + 0x00000007,0x0004003b,0x0000000b,0x0000043f,0x00000007,0x0004003b,0x00000036,0x00000443, + 0x00000007,0x0004003b,0x0000000b,0x00000449,0x00000007,0x0004003b,0x00000036,0x0000044d, + 0x00000007,0x0004003b,0x0000000b,0x0000045f,0x00000007,0x0004003b,0x00000036,0x00000462, + 0x00000007,0x0004003b,0x0000000b,0x00000468,0x00000007,0x0004003b,0x00000036,0x0000046a, + 0x00000007,0x0004003b,0x00000036,0x0000046c,0x00000007,0x0004003b,0x00000036,0x0000046e, + 0x00000007,0x0004003b,0x0000000b,0x00000479,0x00000007,0x0004003b,0x00000021,0x0000047c, + 0x00000007,0x0004003b,0x0000000b,0x0000047f,0x00000007,0x0004003b,0x000000f1,0x0000048e, + 0x00000007,0x0004003b,0x0000000b,0x0000048f,0x00000007,0x0004003b,0x00000036,0x00000493, + 0x00000007,0x0004003b,0x0000000b,0x0000049b,0x00000007,0x0004003b,0x00000036,0x0000049f, + 0x00000007,0x0004003b,0x0000000b,0x000004a5,0x00000007,0x0004003b,0x00000036,0x000004a9, + 0x00000007,0x0004003b,0x0000000b,0x000004bb,0x00000007,0x0004003b,0x00000036,0x000004be, + 0x00000007,0x0004003b,0x0000000b,0x000004c4,0x00000007,0x0004003b,0x00000036,0x000004c6, + 0x00000007,0x0004003b,0x00000036,0x000004c8,0x00000007,0x0004003b,0x00000036,0x000004ca, + 0x00000007,0x0004003b,0x0000000b,0x000004d5,0x00000007,0x0004003b,0x00000021,0x000004d8, + 0x00000007,0x0004003b,0x0000000b,0x000004db,0x00000007,0x0003003e,0x00000413,0x00000414, + 0x0004003d,0x00000027,0x00000416,0x0000007e,0x0004003d,0x0000000a,0x00000417,0x0000007b, + 0x00050057,0x00000012,0x00000418,0x00000416,0x00000417,0x0007004f,0x0000000a,0x00000419, + 0x00000418,0x00000418,0x00000000,0x00000001,0x0003003e,0x00000415,0x00000419,0x00050041, + 0x00000036,0x0000041a,0x00000415,0x0000008d,0x0004003d,0x00000009,0x0000041b,0x0000041a, + 0x000500ba,0x00000006,0x0000041c,0x0000041b,0x0000011a,0x000300f7,0x0000041e,0x00000000, + 0x000400fa,0x0000041c,0x0000041d,0x0000041e,0x000200f8,0x0000041d,0x0004003d,0x0000000a, + 0x00000420,0x0000007b,0x0003003e,0x0000041f,0x00000420,0x0004003d,0x0000000a,0x00000422, + 0x00000415,0x0003003e,0x00000421,0x00000422,0x0004003d,0x00000012,0x00000424,0x00000081, + 0x0003003e,0x00000423,0x00000424,0x00090039,0x0000000a,0x00000425,0x00000044,0x0000007e, + 0x0000007f,0x0000041f,0x00000421,0x00000423,0x00050041,0x00000036,0x00000426,0x00000413, + 0x00000084,0x00050051,0x00000009,0x00000427,0x00000425,0x00000000,0x0003003e,0x00000426, + 0x00000427,0x00050041,0x00000036,0x00000428,0x00000413,0x0000008d,0x00050051,0x00000009, + 0x00000429,0x00000425,0x00000001,0x0003003e,0x00000428,0x00000429,0x00050041,0x00000036, + 0x0000042a,0x00000413,0x00000084,0x0004003d,0x00000009,0x0000042b,0x0000042a,0x00050041, + 0x00000036,0x0000042c,0x00000413,0x0000008d,0x0004003d,0x00000009,0x0000042d,0x0000042c, + 0x0004007f,0x00000009,0x0000042e,0x0000042d,0x000500b4,0x00000006,0x0000042f,0x0000042b, + 0x0000042e,0x000300f7,0x00000431,0x00000000,0x000400fa,0x0000042f,0x00000430,0x00000487, + 0x000200f8,0x00000430,0x00050041,0x00000021,0x00000434,0x0000007d,0x000000a0,0x0004003d, + 0x00000012,0x00000435,0x00000434,0x0007004f,0x0000000a,0x00000436,0x00000435,0x00000435, + 0x00000000,0x00000001,0x0003003e,0x00000433,0x00000436,0x00060041,0x00000036,0x00000438, + 0x0000007d,0x000000b4,0x00000084,0x0004003d,0x00000009,0x00000439,0x00000438,0x0003003e, + 0x00000437,0x00000439,0x00080039,0x00000009,0x0000043a,0x00000051,0x0000007e,0x00000080, + 0x00000433,0x00000437,0x00050041,0x00000036,0x0000043b,0x00000432,0x00000084,0x0003003e, + 0x0000043b,0x0000043a,0x00060041,0x00000036,0x0000043c,0x0000007d,0x0000009a,0x0000008d, + 0x0004003d,0x00000009,0x0000043d,0x0000043c,0x00050041,0x00000036,0x0000043e,0x00000432, + 0x0000008d,0x0003003e,0x0000043e,0x0000043d,0x00050041,0x00000036,0x00000440,0x00000432, + 0x00000084,0x0004003d,0x00000009,0x00000441,0x00000440,0x00050041,0x00000036,0x00000442, + 0x0000043f,0x00000084,0x0003003e,0x00000442,0x00000441,0x0004003d,0x00000027,0x00000444, + 0x0000007e,0x0004003d,0x000000f0,0x00000445,0x00000432,0x0007004f,0x0000000a,0x00000446, + 0x00000445,0x00000445,0x00000000,0x00000001,0x00070058,0x00000012,0x00000447,0x00000444, + 0x00000446,0x00000002,0x0000011a,0x00050051,0x00000009,0x00000448,0x00000447,0x00000000, + 0x0003003e,0x00000443,0x00000448,0x00050041,0x00000021,0x0000044a,0x0000007d,0x000000a0, + 0x0004003d,0x00000012,0x0000044b,0x0000044a,0x0007004f,0x0000000a,0x0000044c,0x0000044b, + 0x0000044b,0x00000002,0x00000003,0x0003003e,0x00000449,0x0000044c,0x00060041,0x00000036, + 0x0000044e,0x0000007d,0x000000b4,0x0000008d,0x0004003d,0x00000009,0x0000044f,0x0000044e, + 0x0003003e,0x0000044d,0x0000044f,0x00080039,0x00000009,0x00000450,0x00000057,0x0000007e, + 0x00000080,0x00000449,0x0000044d,0x00050041,0x00000036,0x00000451,0x00000432,0x000000e2, + 0x0003003e,0x00000451,0x00000450,0x00050041,0x00000036,0x00000452,0x00000432,0x000000e2, + 0x0004003d,0x00000009,0x00000453,0x00000452,0x00050041,0x00000036,0x00000454,0x0000043f, + 0x0000008d,0x0003003e,0x00000454,0x00000453,0x00050041,0x0000009b,0x00000455,0x00000098, + 0x0000009a,0x0004003d,0x00000012,0x00000456,0x00000455,0x0007004f,0x0000000a,0x00000457, + 0x00000456,0x00000456,0x00000002,0x00000002,0x0004003d,0x0000000a,0x00000458,0x0000043f, + 0x0004003d,0x0000000a,0x00000459,0x0000007c,0x0007004f,0x0000000a,0x0000045a,0x00000459, + 0x00000459,0x00000000,0x00000000,0x0004007f,0x0000000a,0x0000045b,0x0000045a,0x0008000c, + 0x0000000a,0x0000045c,0x00000001,0x00000032,0x00000457,0x00000458,0x0000045b,0x0006000c, + 0x0000000a,0x0000045d,0x00000001,0x00000001,0x0000045c,0x0006000c,0x0000000a,0x0000045e, + 0x00000001,0x00000004,0x0000045d,0x0003003e,0x0000043f,0x0000045e,0x0004003d,0x0000000a, + 0x00000460,0x0000043f,0x0006000c,0x0000000a,0x00000461,0x00000001,0x0000001f,0x00000460, + 0x0003003e,0x0000045f,0x00000461,0x0004003d,0x00000027,0x00000463,0x0000007e,0x0004003d, + 0x000000f0,0x00000464,0x00000432,0x0007004f,0x0000000a,0x00000465,0x00000464,0x00000464, + 0x00000002,0x00000001,0x00080058,0x00000012,0x00000466,0x00000463,0x00000465,0x0000000a, + 0x0000011a,0x000001de,0x00050051,0x00000009,0x00000467,0x00000466,0x00000000,0x0003003e, + 0x00000462,0x00000467,0x0004003d,0x0000000a,0x00000469,0x0000045f,0x0003003e,0x00000468, + 0x00000469,0x0004003d,0x00000009,0x0000046b,0x00000443,0x0003003e,0x0000046a,0x0000046b, + 0x0004003d,0x00000009,0x0000046d,0x00000462,0x0003003e,0x0000046c,0x0000046d,0x00050041, + 0x00000036,0x0000046f,0x00000081,0x0000008d,0x0004003d,0x00000009,0x00000470,0x0000046f, + 0x0003003e,0x0000046e,0x00000470,0x00090039,0x0000000a,0x00000471,0x0000006b,0x0000007f, + 0x00000468,0x0000046a,0x0000046c,0x0000046e,0x00050041,0x00000036,0x00000472,0x00000413, + 0x00000084,0x00050051,0x00000009,0x00000473,0x00000471,0x00000000,0x0003003e,0x00000472, + 0x00000473,0x00050041,0x00000036,0x00000474,0x00000413,0x0000008d,0x00050051,0x00000009, + 0x00000475,0x00000471,0x00000001,0x0003003e,0x00000474,0x00000475,0x00050041,0x00000036, + 0x00000476,0x0000007b,0x0000008d,0x0004003d,0x00000009,0x00000477,0x00000476,0x00050041, + 0x00000036,0x00000478,0x00000432,0x0000008d,0x0003003e,0x00000478,0x00000477,0x0004003d, + 0x00000012,0x0000047a,0x00000413,0x0007004f,0x0000000a,0x0000047b,0x0000047a,0x0000047a, + 0x00000000,0x00000001,0x0003003e,0x00000479,0x0000047b,0x0004003d,0x000000f0,0x0000047d, + 0x00000432,0x0009004f,0x00000012,0x0000047e,0x0000047d,0x0000047d,0x00000000,0x00000001, + 0x00000002,0x00000001,0x0003003e,0x0000047c,0x0000047e,0x0004003d,0x0000000a,0x00000480, + 0x0000043f,0x0003003e,0x0000047f,0x00000480,0x00080039,0x00000002,0x00000481,0x00000072, + 0x0000007e,0x00000479,0x0000047c,0x0000047f,0x0004003d,0x0000000a,0x00000482,0x00000479, + 0x00050041,0x00000036,0x00000483,0x00000413,0x00000084,0x00050051,0x00000009,0x00000484, + 0x00000482,0x00000000,0x0003003e,0x00000483,0x00000484,0x00050041,0x00000036,0x00000485, + 0x00000413,0x0000008d,0x00050051,0x00000009,0x00000486,0x00000482,0x00000001,0x0003003e, + 0x00000485,0x00000486,0x000200f9,0x00000431,0x000200f8,0x00000487,0x00050041,0x00000036, + 0x00000488,0x00000415,0x00000084,0x0003003e,0x00000488,0x0000011a,0x000200f9,0x00000431, + 0x000200f8,0x00000431,0x000200f9,0x0000041e,0x000200f8,0x0000041e,0x00050041,0x00000036, + 0x00000489,0x00000415,0x00000084,0x0004003d,0x00000009,0x0000048a,0x00000489,0x000500ba, + 0x00000006,0x0000048b,0x0000048a,0x0000011a,0x000300f7,0x0000048d,0x00000000,0x000400fa, + 0x0000048b,0x0000048c,0x0000048d,0x000200f8,0x0000048c,0x00050041,0x00000021,0x00000490, + 0x0000007d,0x0000009a,0x0004003d,0x00000012,0x00000491,0x00000490,0x0007004f,0x0000000a, + 0x00000492,0x00000491,0x00000491,0x00000000,0x00000001,0x0003003e,0x0000048f,0x00000492, + 0x00060041,0x00000036,0x00000494,0x0000007d,0x000000b4,0x000000e2,0x0004003d,0x00000009, + 0x00000495,0x00000494,0x0003003e,0x00000493,0x00000495,0x00080039,0x00000009,0x00000496, + 0x0000005d,0x0000007e,0x00000080,0x0000048f,0x00000493,0x00050041,0x00000036,0x00000497, + 0x0000048e,0x0000008d,0x0003003e,0x00000497,0x00000496,0x00060041,0x00000036,0x00000498, + 0x0000007d,0x000000a0,0x00000084,0x0004003d,0x00000009,0x00000499,0x00000498,0x00050041, + 0x00000036,0x0000049a,0x0000048e,0x00000084,0x0003003e,0x0000049a,0x00000499,0x00050041, + 0x00000036,0x0000049c,0x0000048e,0x0000008d,0x0004003d,0x00000009,0x0000049d,0x0000049c, + 0x00050041,0x00000036,0x0000049e,0x0000049b,0x00000084,0x0003003e,0x0000049e,0x0000049d, + 0x0004003d,0x00000027,0x000004a0,0x0000007e,0x0004003d,0x000000f0,0x000004a1,0x0000048e, + 0x0007004f,0x0000000a,0x000004a2,0x000004a1,0x000004a1,0x00000000,0x00000001,0x00070058, + 0x00000012,0x000004a3,0x000004a0,0x000004a2,0x00000002,0x0000011a,0x00050051,0x00000009, + 0x000004a4,0x000004a3,0x00000001,0x0003003e,0x0000049f,0x000004a4,0x00050041,0x00000021, + 0x000004a6,0x0000007d,0x0000009a,0x0004003d,0x00000012,0x000004a7,0x000004a6,0x0007004f, + 0x0000000a,0x000004a8,0x000004a7,0x000004a7,0x00000002,0x00000003,0x0003003e,0x000004a5, + 0x000004a8,0x00060041,0x00000036,0x000004aa,0x0000007d,0x000000b4,0x00000014,0x0004003d, + 0x00000009,0x000004ab,0x000004aa,0x0003003e,0x000004a9,0x000004ab,0x00080039,0x00000009, + 0x000004ac,0x00000063,0x0000007e,0x00000080,0x000004a5,0x000004a9,0x00050041,0x00000036, + 0x000004ad,0x0000048e,0x000000e2,0x0003003e,0x000004ad,0x000004ac,0x00050041,0x00000036, + 0x000004ae,0x0000048e,0x000000e2,0x0004003d,0x00000009,0x000004af,0x000004ae,0x00050041, + 0x00000036,0x000004b0,0x0000049b,0x0000008d,0x0003003e,0x000004b0,0x000004af,0x00050041, + 0x0000009b,0x000004b1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000004b2,0x000004b1, + 0x0007004f,0x0000000a,0x000004b3,0x000004b2,0x000004b2,0x00000003,0x00000003,0x0004003d, + 0x0000000a,0x000004b4,0x0000049b,0x0004003d,0x0000000a,0x000004b5,0x0000007c,0x0007004f, + 0x0000000a,0x000004b6,0x000004b5,0x000004b5,0x00000001,0x00000001,0x0004007f,0x0000000a, + 0x000004b7,0x000004b6,0x0008000c,0x0000000a,0x000004b8,0x00000001,0x00000032,0x000004b3, + 0x000004b4,0x000004b7,0x0006000c,0x0000000a,0x000004b9,0x00000001,0x00000001,0x000004b8, + 0x0006000c,0x0000000a,0x000004ba,0x00000001,0x00000004,0x000004b9,0x0003003e,0x0000049b, + 0x000004ba,0x0004003d,0x0000000a,0x000004bc,0x0000049b,0x0006000c,0x0000000a,0x000004bd, + 0x00000001,0x0000001f,0x000004bc,0x0003003e,0x000004bb,0x000004bd,0x0004003d,0x00000027, + 0x000004bf,0x0000007e,0x0004003d,0x000000f0,0x000004c0,0x0000048e,0x0007004f,0x0000000a, + 0x000004c1,0x000004c0,0x000004c0,0x00000000,0x00000002,0x00080058,0x00000012,0x000004c2, + 0x000004bf,0x000004c1,0x0000000a,0x0000011a,0x00000394,0x00050051,0x00000009,0x000004c3, + 0x000004c2,0x00000001,0x0003003e,0x000004be,0x000004c3,0x0004003d,0x0000000a,0x000004c5, + 0x000004bb,0x0003003e,0x000004c4,0x000004c5,0x0004003d,0x00000009,0x000004c7,0x0000049f, + 0x0003003e,0x000004c6,0x000004c7,0x0004003d,0x00000009,0x000004c9,0x000004be,0x0003003e, + 0x000004c8,0x000004c9,0x00050041,0x00000036,0x000004cb,0x00000081,0x00000084,0x0004003d, + 0x00000009,0x000004cc,0x000004cb,0x0003003e,0x000004ca,0x000004cc,0x00090039,0x0000000a, + 0x000004cd,0x0000006b,0x0000007f,0x000004c4,0x000004c6,0x000004c8,0x000004ca,0x00050041, + 0x00000036,0x000004ce,0x00000413,0x000000e2,0x00050051,0x00000009,0x000004cf,0x000004cd, + 0x00000000,0x0003003e,0x000004ce,0x000004cf,0x00050041,0x00000036,0x000004d0,0x00000413, + 0x00000014,0x00050051,0x00000009,0x000004d1,0x000004cd,0x00000001,0x0003003e,0x000004d0, + 0x000004d1,0x00050041,0x00000036,0x000004d2,0x0000007b,0x00000084,0x0004003d,0x00000009, + 0x000004d3,0x000004d2,0x00050041,0x00000036,0x000004d4,0x0000048e,0x00000084,0x0003003e, + 0x000004d4,0x000004d3,0x0004003d,0x00000012,0x000004d6,0x00000413,0x0007004f,0x0000000a, + 0x000004d7,0x000004d6,0x000004d6,0x00000002,0x00000003,0x0003003e,0x000004d5,0x000004d7, + 0x0004003d,0x000000f0,0x000004d9,0x0000048e,0x0009004f,0x00000012,0x000004da,0x000004d9, + 0x000004d9,0x00000000,0x00000001,0x00000000,0x00000002,0x0003003e,0x000004d8,0x000004da, + 0x0004003d,0x0000000a,0x000004dc,0x0000049b,0x0003003e,0x000004db,0x000004dc,0x00080039, + 0x00000002,0x000004dd,0x00000078,0x0000007e,0x000004d5,0x000004d8,0x000004db,0x0004003d, + 0x0000000a,0x000004de,0x000004d5,0x00050041,0x00000036,0x000004df,0x00000413,0x000000e2, + 0x00050051,0x00000009,0x000004e0,0x000004de,0x00000000,0x0003003e,0x000004df,0x000004e0, + 0x00050041,0x00000036,0x000004e1,0x00000413,0x00000014,0x00050051,0x00000009,0x000004e2, + 0x000004de,0x00000001,0x0003003e,0x000004e1,0x000004e2,0x000200f9,0x0000048d,0x000200f8, + 0x0000048d,0x0004003d,0x00000012,0x000004e3,0x00000413,0x000200fe,0x000004e3,0x00010038 }; diff --git a/app/src/main/cpp/thirdparty/zerofg/README.DroidDeck.md b/app/src/main/cpp/thirdparty/zerofg/README.DroidDeck.md new file mode 100644 index 0000000000..0872e65ca9 --- /dev/null +++ b/app/src/main/cpp/thirdparty/zerofg/README.DroidDeck.md @@ -0,0 +1 @@ +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. diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt index 5bdc1e8385..2cd55b2761 100644 --- a/app/src/main/cpp/waylandcomp/CMakeLists.txt +++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt @@ -42,6 +42,11 @@ 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 $<$:-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers>) target_include_directories(droiddeckwayland PRIVATE @@ -59,6 +64,7 @@ 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 @@ -85,12 +91,12 @@ if (TARGET dxbc AND EXISTS ${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../framegen ) target_compile_options(droiddeckwayland PRIVATE - $<$:-std=c++17 -fvisibility=hidden>) + $<$:-std=c++20 -fvisibility=hidden>) target_compile_definitions(droiddeckwayland PRIVATE DDFG_UPSTREAM="${DDFG_UPSTREAM}" DDFG_CHAIN_HASH="${DDFG_CHAIN_HASH}" ) - target_link_libraries(droiddeckwayland dxbc atomic) + target_link_libraries(droiddeckwayland dxbc atomic zerofg::zerofg) else() message(STATUS "droiddeckwayland: frame-generation engines NOT built in (standalone build): stub") target_sources(droiddeckwayland PRIVATE src/framegen_engine_stub.c) diff --git a/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-protocol.c new file mode 100644 index 0000000000..3d32474f56 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-protocol.c @@ -0,0 +1,35 @@ +/* Generated by wayland-scanner 1.22.0 */ + +#include +#include +#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, +}; diff --git a/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-server-protocol.h new file mode 100644 index 0000000000..18f9466487 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-frame-acquire-v1-server-protocol.h @@ -0,0 +1,128 @@ +/* Generated by wayland-scanner 1.22.0 */ + +#ifndef DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H +#define DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H + +#include +#include +#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 diff --git a/app/src/main/cpp/waylandcomp/protocols/droiddeck-frame-acquire-v1.xml b/app/src/main/cpp/waylandcomp/protocols/droiddeck-frame-acquire-v1.xml new file mode 100644 index 0000000000..ae4c26535b --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/droiddeck-frame-acquire-v1.xml @@ -0,0 +1,45 @@ + + + + + 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. + + + + + + + + + + + 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. + + + + + + + diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c index c31915a45b..26618c67f6 100644 --- a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c @@ -7,6 +7,7 @@ #include "droiddeck-ahb-v1-server-protocol.h" #include #include +#include #include #include #include @@ -53,6 +54,7 @@ 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; @@ -133,10 +135,10 @@ static void handle_released(uint64_t id, int fd) { if (fd >= 0) { struct droiddeck_dma_buf_sync_file imp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = fd}; int dmabuf_fd = droiddeck_dmabuf_fd(ab->b); - if (!ab->display && dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) { + if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) { close(fd); } else { - if (!ab->display && !g_import_failed_logged) { + if (!g_import_failed_logged) { g_import_failed_logged = 1; droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_IMPORT_SYNC_FILE failed (%s): releases wait for the display's fence here instead", strerror(errno)); @@ -145,6 +147,12 @@ static void handle_released(uint64_t id, int fd) { if (poll(&p, 1, 0) > 0) { close(fd); } else { + if (ab->fence_src) { + struct sync_merge_data m = {.name = "droiddeck-release", .fd2 = fd}; + if (ioctl(ab->fence_fd, SYNC_IOC_MERGE, &m) == 0) { close(fd); fd = m.fence; } + wl_event_source_remove(ab->fence_src); + close(ab->fence_fd); + } ab->fence_fd = fd; ab->fence_src = wl_event_loop_add_fd(g_loop, fd, WL_EVENT_READABLE, on_fence_readable, ab); if (!ab->fence_src) { close(fd); ab->fence_fd = -1; } @@ -152,6 +160,7 @@ static void handle_released(uint64_t id, int fd) { } } } + if (ab->fence_src) return; send_deferred_release(ab); maybe_free(ab); } @@ -193,27 +202,47 @@ 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 = -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 (dmabuf_fd >= 0) { - if (!g_export_failed_logged) { - g_export_failed_logged = 1; - droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_EXPORT_SYNC_FILE failed (%s): waiting for each frame on the CPU instead", - strerror(errno)); + 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; } - struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN}; - int r; - do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); } 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) { @@ -253,6 +282,12 @@ 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) { diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h index 9002e6fc0a..95f1cd1418 100644 --- a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h @@ -20,7 +20,9 @@ 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); diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index c9eceed111..f17591cb16 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,14 @@ #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 +#include +#include +#include "frame_worker_peer.h" +#endif #include "display_buffers.h" #include "viewporter-server-protocol.h" #include "droiddeck-desktop-v1-server-protocol.h" @@ -210,6 +219,7 @@ 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; @@ -242,6 +252,10 @@ struct surface { enum surface_role role; struct wl_resource *idle_buffer; struct wl_listener idle_buffer_destroy; + struct surface_state *waiting; + struct wl_event_source *waiting_source, *waiting_timer; + int waiting_fd; + int64_t waiting_since_ns; uint32_t *idle_px; int idle_w, idle_h; struct wl_resource *xdg_surface, *xdg_toplevel; @@ -329,6 +343,7 @@ 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; @@ -373,6 +388,8 @@ static struct { unsigned copy_scenes; unsigned releases, releases_held; int64_t release_ns, release_max_ns; + unsigned commit_waits, commit_wait_limits; + int64_t commit_wait_ns, commit_wait_max_ns; } g_perf; static void schedule_render(void); @@ -820,6 +837,7 @@ 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)) { @@ -835,17 +853,72 @@ 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; + int src_set, dst_set, opaque_set; + float src[4]; + int dst[2], opaque[4]; + struct damage_list damage_buf, damage_local; + struct wl_list frames, feedback; +}; + +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; + st->attach = 0; +} + +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) { + wl_list_remove(&s->pending_buffer_destroy.link); + wl_list_init(&s->pending_buffer_destroy.link); + st->buffer_destroy.notify = on_state_buffer_destroyed; + wl_resource_add_destroy_listener(st->buffer, &st->buffer_destroy); + } + s->pending_buffer = NULL; + s->pending_attach = 0; + st->src_set = s->pending_src_set; + memcpy(st->src, s->pending_src, sizeof(st->src)); + st->dst_set = s->pending_dst_set; + memcpy(st->dst, s->pending_dst, sizeof(st->dst)); + st->opaque_set = s->pending_opaque_set; + memcpy(st->opaque, s->pending_opaque, sizeof(st->opaque)); + s->pending_src_set = s->pending_dst_set = s->pending_opaque_set = 0; + st->damage_buf = s->pending_damage_buf; + st->damage_local = s->pending_damage_local; + s->pending_damage_buf.n = s->pending_damage_local.n = 0; + wl_list_init(&st->frames); + wl_list_insert_list(&st->frames, &s->pending_frames); + wl_list_init(&s->pending_frames); + wl_list_init(&st->feedback); + wl_list_insert_list(&st->feedback, &s->pending_feedback); + wl_list_init(&s->pending_feedback); +} + static void fire_frames(struct wl_list *frames) { struct wl_resource *cb, *tmp; uint32_t t; @@ -1130,6 +1203,7 @@ 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; @@ -1363,35 +1437,23 @@ static void surface_drop_idle(struct surface *s) { if (buffer) send_buffer_release(buffer); } -static void surface_commit(struct wl_client *c, struct wl_resource *r) { - struct surface *s = wl_resource_get_user_data(r); +static void surface_state_apply(struct surface *s, struct surface_state *st) { struct surface *child; - if (s->xdg_toplevel && !s->toplevel_committed) { - s->toplevel_committed = 1; - send_toplevel_configure(s); + if (st->src_set) { + s->src_set = st->src[2] > 0; + memcpy(s->src, st->src, sizeof(s->src)); } + if (st->dst_set) { + s->dst_set = st->dst[0] > 0; + memcpy(s->dst, st->dst, sizeof(s->dst)); + } + if (st->opaque_set) memcpy(s->opaque, st->opaque, sizeof(s->opaque)); - if (s->pending_src_set) { - s->src_set = s->pending_src[2] > 0; - memcpy(s->src, s->pending_src, sizeof(s->src)); - s->pending_src_set = 0; - } - if (s->pending_dst_set) { - s->dst_set = s->pending_dst[0] > 0; - memcpy(s->dst, s->pending_dst, sizeof(s->dst)); - s->pending_dst_set = 0; - } - if (s->pending_opaque_set) { - memcpy(s->opaque, s->pending_opaque, sizeof(s->opaque)); - s->pending_opaque_set = 0; - } - - s->damage_buf = s->pending_damage_buf; - s->damage_local = s->pending_damage_local; - s->pending_damage_buf.n = s->pending_damage_local.n = 0; - if (s->pending_attach) { - struct wl_resource *buffer = s->pending_buffer; + s->damage_buf = st->damage_buf; + s->damage_local = st->damage_local; + if (st->attach) { + struct wl_resource *buffer = st->buffer; struct dmabuf_buffer *db = get_dmabuf(buffer); struct wl_shm_buffer *shm = buffer && !db ? wl_shm_buffer_get(buffer) : NULL; uint8_t pixel[4]; @@ -1400,15 +1462,14 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { if (!buffer) g_pace.null_attaches++; else if (!db) s->last_dmabuf = NULL; - if (buffer) { - wl_list_remove(&s->pending_buffer_destroy.link); - wl_list_init(&s->pending_buffer_destroy.link); - } - s->pending_buffer = NULL; - s->pending_attach = 0; + wl_list_remove(&st->buffer_destroy.link); + wl_list_init(&st->buffer_destroy.link); + st->buffer = NULL; + st->attach = 0; 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(); @@ -1420,6 +1481,8 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { 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); @@ -1432,6 +1495,7 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { 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) { @@ -1442,10 +1506,10 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { } } - wl_list_insert_list(s->frames.prev, &s->pending_frames); - wl_list_init(&s->pending_frames); - wl_list_insert_list(s->feedback.prev, &s->pending_feedback); - wl_list_init(&s->pending_feedback); + wl_list_insert_list(s->frames.prev, &st->frames); + wl_list_init(&st->frames); + wl_list_insert_list(s->feedback.prev, &st->feedback); + wl_list_init(&st->feedback); constraints_surface_commit(s); droiddeck_color_commit(s->resource); @@ -1455,6 +1519,189 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { } schedule_render(); } + +#define COMMIT_WAIT_LIMIT_MS 1000 + +static struct surface *g_zero_copy_shown, *g_unwaited; + +static int state_unfinished_fd(const struct surface *s, const struct surface_state *st, int *unwaited) { + struct dmabuf_buffer *db = st->attach ? get_dmabuf(st->buffer) : NULL; + int fd = -1; + *unwaited = 0; + for (int i = 0; db && fd < 0 && i < db->n_planes; i++) { + if (db->fd[i] < 0) continue; + struct pollfd p = {.fd = db->fd[i], .events = POLLIN}; + int r; + do { r = poll(&p, 1, 0); } while (r < 0 && errno == EINTR); + if (r == 0) fd = db->fd[i]; + } + if (fd >= 0 && s == g_zero_copy_shown && ahb_swapchain_has_ahb(db)) { + *unwaited = 1; + return -1; + } + return fd; +} + +static void settle_unwaited(void) { + struct surface *s = g_unwaited; + if (!s) return; + g_unwaited = NULL; + struct dmabuf_buffer *db = s->dmabuf_buf; + const int64_t deadline = now_ns() + 100000000LL; + for (int i = 0; db && i < db->n_planes; i++) { + if (db->fd[i] < 0) continue; + struct pollfd p = {.fd = db->fd[i], .events = POLLIN}; + for (;;) { + const int64_t left = deadline - now_ns(); + const int r = poll(&p, 1, left > 0 ? (int)((left + 999999) / 1000000) : 0); + if (r >= 0 || errno != EINTR || left <= 0) break; + } + } +} + +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); + feedback_discard_all(&st->feedback); + free(st); +} + +static void surface_state_merge(struct surface_state *older, struct surface_state *newer) { + 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) { + newer->buffer_destroy.notify = on_state_buffer_destroyed; + wl_resource_add_destroy_listener(newer->buffer, &newer->buffer_destroy); + } + wl_list_insert_list(&newer->feedback, &older->feedback); + wl_list_init(&older->feedback); + } else if (older->attach) { + if (older->buffer && older->buffer != newer->buffer) send_buffer_release(older->buffer); + g_pace.replaced += feedback_discard_all(&older->feedback); + } + if (older->src_set && !newer->src_set) { + newer->src_set = 1; + memcpy(newer->src, older->src, sizeof(newer->src)); + } + if (older->dst_set && !newer->dst_set) { + newer->dst_set = 1; + memcpy(newer->dst, older->dst, sizeof(newer->dst)); + } + if (older->opaque_set && !newer->opaque_set) { + newer->opaque_set = 1; + memcpy(newer->opaque, older->opaque, sizeof(newer->opaque)); + } + for (int i = 0; i < older->damage_buf.n; i++) + note_damage(&newer->damage_buf, older->damage_buf.r[i][0], older->damage_buf.r[i][1], + older->damage_buf.r[i][2], older->damage_buf.r[i][3]); + for (int i = 0; i < older->damage_local.n; i++) + note_damage(&newer->damage_local, older->damage_local.r[i][0], older->damage_local.r[i][1], + older->damage_local.r[i][2], older->damage_local.r[i][3]); + wl_list_insert_list(&newer->frames, &older->frames); + wl_list_init(&older->frames); + surface_state_discard(older); +} + +static void surface_wait_stop(struct surface *s) { + if (s->waiting_source) wl_event_source_remove(s->waiting_source); + if (s->waiting_timer) wl_event_source_remove(s->waiting_timer); + if (s->waiting_fd >= 0) close(s->waiting_fd); + s->waiting_source = s->waiting_timer = NULL; + s->waiting_fd = -1; +} + +static void surface_wait_end(struct surface *s, int over_limit) { + struct surface_state *st = s->waiting; + if (!st) return; + surface_wait_stop(s); + s->waiting = NULL; + const int64_t waited = now_ns() - s->waiting_since_ns; + g_perf.commit_waits++; + g_perf.commit_wait_ns += waited; + if (waited > g_perf.commit_wait_max_ns) g_perf.commit_wait_max_ns = waited; + if (over_limit) g_perf.commit_wait_limits++; + if (st->attach && g_unwaited == s) g_unwaited = NULL; + surface_state_apply(s, st); + free(st); +} + +static int on_commit_ready(int fd, uint32_t mask, void *data) { + surface_wait_end(data, 0); + return 0; +} + +static int on_commit_wait_limit(void *data) { + static int said; + if (!said) { + said = 1; + droiddeck_log("compositor", "a client's GPU writes ran past %d ms; its frame is shown as it is", COMMIT_WAIT_LIMIT_MS); + } + surface_wait_end(data, 1); + return 0; +} + +static int surface_wait_start(struct surface *s, int fd, int timeout_ms) { + struct wl_event_loop *loop = wl_display_get_event_loop(g_display); + s->waiting_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); + if (s->waiting_fd >= 0) { + s->waiting_source = wl_event_loop_add_fd(loop, s->waiting_fd, WL_EVENT_READABLE, on_commit_ready, s); + s->waiting_timer = wl_event_loop_add_timer(loop, on_commit_wait_limit, s); + } + if (!s->waiting_source || !s->waiting_timer || + wl_event_source_timer_update(s->waiting_timer, timeout_ms) != 0) { + surface_wait_stop(s); + return -1; + } + return 0; +} + +static void surface_commit(struct wl_client *c, struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + + if (s->xdg_toplevel && !s->toplevel_committed) { + s->toplevel_committed = 1; + send_toplevel_configure(s); + } + struct surface_state *st = calloc(1, sizeof(*st)); + if (!st) { + struct surface_state now; + surface_state_take(s, &now); + surface_state_apply(s, &now); + return; + } + surface_state_take(s, st); + const int was_waiting = s->waiting != NULL; + if (was_waiting) { + surface_wait_stop(s); + surface_state_merge(s->waiting, st); + s->waiting = NULL; + } + int unwaited; + const int fd = state_unfinished_fd(s, st, &unwaited); + if (!was_waiting) s->waiting_since_ns = now_ns(); + const int64_t left_ms = COMMIT_WAIT_LIMIT_MS - (now_ns() - s->waiting_since_ns) / 1000000; + if (fd >= 0 && left_ms > 0 && surface_wait_start(s, fd, (int)left_ms) == 0) { + s->waiting = st; + return; + } + const int attaches = st->attach; + if (was_waiting) { + s->waiting = st; + surface_wait_end(s, fd >= 0 && left_ms <= 0); + } else { + surface_state_apply(s, st); + free(st); + } + if (unwaited) g_unwaited = s; + else if (attaches && g_unwaited == s) g_unwaited = NULL; +} static void surface_set_buffer_transform(struct wl_client *c, struct wl_resource *r, int32_t t) {} static void surface_set_buffer_scale(struct wl_client *c, struct wl_resource *r, int32_t s) {} static void surface_damage_buffer(struct wl_client *c, struct wl_resource *r, @@ -1478,6 +1725,210 @@ 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); @@ -1487,6 +1938,7 @@ 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; @@ -1516,6 +1968,13 @@ static void surface_resource_destroy(struct wl_resource *r) { child->parent = NULL; } if (s->pending_buffer) wl_list_remove(&s->pending_buffer_destroy.link); + if (s->waiting) { + surface_wait_stop(s); + surface_state_discard(s->waiting); + s->waiting = NULL; + } + if (g_zero_copy_shown == s) g_zero_copy_shown = NULL; + if (g_unwaited == s) g_unwaited = NULL; pending_releases_forget_surface(s); drop_dmabuf(s, 0); ahb_swapchain_surface_gone(s); @@ -1579,6 +2038,7 @@ static void compositor_create_surface(struct wl_client *c, struct wl_resource *r wl_list_init(&s->child_link); wl_list_init(&s->toplevel_link); wl_list_init(&s->pending_buffer_destroy.link); + s->waiting_fd = -1; wl_list_init(&s->idle_buffer_destroy.link); wl_list_insert(&g_surfaces, &s->link); wl_resource_set_implementation(s->resource, &surface_impl, s, surface_resource_destroy); @@ -2043,6 +2503,69 @@ static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t struct draw_list { struct vkp_draw *d; int n, cap; }; +#define ZERO_COPY_FALLBACK_SIGNATURES 32u +enum zero_copy_fallback_reason { + ZERO_COPY_NO_SURFACE_BUFFER = 1, + ZERO_COPY_NO_GRALLOC_AHB = 2, + ZERO_COPY_AHB_PRESENT_FAILED = 3 +}; +struct zero_copy_fallback_signature { + uint32_t reason, format, stride, offset; + int width, height; + uint64_t modifier; +}; +static struct zero_copy_fallback_signature g_zero_copy_fallbacks[ZERO_COPY_FALLBACK_SIGNATURES]; +static uint32_t g_zero_copy_fallback_count; +static int g_zero_copy_fallback_limit_logged; + +static int zero_copy_fallback_should_log(const struct dmabuf_buffer *b, uint32_t reason) { + const struct zero_copy_fallback_signature key = { + .reason = reason, .format = b ? b->format : 0, + .stride = b && b->n_planes ? b->stride[0] : 0, + .offset = b && b->n_planes ? b->offset[0] : 0, + .width = b ? b->width : 0, .height = b ? b->height : 0, + .modifier = b ? b->modifier : 0}; + for (uint32_t i = 0; i < g_zero_copy_fallback_count; i++) { + const struct zero_copy_fallback_signature *seen = &g_zero_copy_fallbacks[i]; + if (seen->reason == key.reason && seen->format == key.format && seen->stride == key.stride && + seen->offset == key.offset && seen->width == key.width && seen->height == key.height && + seen->modifier == key.modifier) + return 0; + } + if (g_zero_copy_fallback_count >= ZERO_COPY_FALLBACK_SIGNATURES) { + if (!g_zero_copy_fallback_limit_logged) { + g_zero_copy_fallback_limit_logged = 1; + droiddeck_log("layer", "zero-copy: further fallback diagnostics suppressed after %u distinct buffer signatures", + ZERO_COPY_FALLBACK_SIGNATURES); + } + return 0; + } + g_zero_copy_fallbacks[g_zero_copy_fallback_count++] = key; + return 1; +} + +static void note_zero_copy_fallback(struct surface *s, const struct dmabuf_buffer *b, uint32_t reason, + int scene_w, int scene_h, int present_result) { + if (!zero_copy_fallback_should_log(b, reason)) return; + char name[160] = "unknown surface"; + if (s) describe(s, name, sizeof(name)); + if (reason == ZERO_COPY_NO_SURFACE_BUFFER) { + droiddeck_log("layer", "zero-copy: layer candidate %s has no associated Wayland surface buffer; using the layer-copy path", + name); + } else { + droiddeck_log("layer", "zero-copy: %s buffer %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx %s; " + "scene %dx%d will use the layer-copy path (direct-present result %d)", + name, b->format & 0xff, (b->format >> 8) & 0xff, (b->format >> 16) & 0xff, + (b->format >> 24) & 0xff, b->width, b->height, + b->n_planes ? b->stride[0] : 0, b->n_planes ? b->offset[0] : 0, + (unsigned long long)b->modifier, + reason == ZERO_COPY_NO_GRALLOC_AHB + ? "has no registered gralloc AHardwareBuffer" + : "has a registered gralloc AHardwareBuffer but direct presentation failed", + scene_w, scene_h, present_result); + } +} + static int add_cursor(struct draw_list *dl, int scene_w); static struct vkp_image *surface_image(struct surface *s) { @@ -2162,17 +2685,53 @@ static int black_fill_below(const struct draw_list *dl, int n) { return 1; } +#define LAYER_CANDIDATE_DIAGNOSTICS 32u +static unsigned g_layer_candidate_diag_count; +static int g_layer_candidate_diag_limit; + +static void note_layer_candidate_skip(const struct vkp_draw *d, int index, int reason, + int scene_w, int scene_h) { + static int seen[LAYER_CANDIDATE_DIAGNOSTICS][8]; + const int key[8] = {index, reason, scene_w, scene_h, d->dx, d->dy, d->dw, d->dh}; + for (unsigned i = 0; i < g_layer_candidate_diag_count; i++) + if (!memcmp(seen[i], key, sizeof(key))) return; + if (g_layer_candidate_diag_count >= LAYER_CANDIDATE_DIAGNOSTICS) { + if (!g_layer_candidate_diag_limit++) droiddeck_log("layer", "zero-copy: further candidate-rejection details suppressed after %u signatures", + LAYER_CANDIDATE_DIAGNOSTICS); + return; + } + memcpy(seen[g_layer_candidate_diag_count++], key, sizeof(key)); + const char *why = reason == 1 ? "translucent draw" : + reason == 2 ? "image is not DMA-BUF" : + reason == 3 ? "source rectangle is outside/invalid" : + reason == 4 ? "draw rectangle is outside scene or invalid" : + "not fullscreen and no black backing below"; + droiddeck_log("layer", "zero-copy: candidate draw %d rejected: %s; scene %dx%d, dst %dx%d at %d,%d, src %.2f,%.2f %.2fx%.2f, image %dx%d", + index, why, scene_w, scene_h, d->dw, d->dh, d->dx, d->dy, + d->sx, d->sy, d->sw, d->sh, vkp_image_width(d->img), vkp_image_height(d->img)); +} + static int layer_candidate(const struct draw_list *dl, int scene_w, int scene_h) { for (int i = dl->n - 1; i >= 0 && i >= dl->n - 2; i--) { const struct vkp_draw *d = &dl->d[i]; - if (d->blend) continue; - if (!vkp_image_is_dmabuf(d->img)) continue; + if (d->blend) { note_layer_candidate_skip(d, i, 1, scene_w, scene_h); continue; } + if (!vkp_image_is_dmabuf(d->img)) { note_layer_candidate_skip(d, i, 2, scene_w, scene_h); continue; } if (d->sx < 0 || d->sy < 0 || d->sw < 1.0f || d->sh < 1.0f || d->sx + d->sw >= vkp_image_width(d->img) + 1.0f || - d->sy + d->sh >= vkp_image_height(d->img) + 1.0f) continue; + d->sy + d->sh >= vkp_image_height(d->img) + 1.0f) { + note_layer_candidate_skip(d, i, 3, scene_w, scene_h); + continue; + } if (d->dx == 0 && d->dy == 0 && d->dw == scene_w && d->dh == scene_h) return i; if (d->dx < 0 || d->dy < 0 || d->dw <= 0 || d->dh <= 0 || d->dx + d->dw > scene_w || - d->dy + d->dh > scene_h || !black_fill_below(dl, i)) continue; + d->dy + d->dh > scene_h) { + note_layer_candidate_skip(d, i, 4, scene_w, scene_h); + continue; + } + if (!black_fill_below(dl, i)) { + note_layer_candidate_skip(d, i, 5, scene_w, scene_h); + continue; + } return i; } return -1; @@ -2193,6 +2752,56 @@ static void note_copy_scene(const struct draw_list *dl, int scene_w, int scene_h vkp_image_is_dmabuf(t->img) ? "GPU" : "memory", t->blend ? ", translucent" : ""); } +static struct surface *surface_for_image(const struct vkp_image *img); + +static void note_layer_candidate_rejected(const struct draw_list *dl, int scene_w, int scene_h) { + static int seen[32][14]; + static unsigned seen_count; + static int limit_logged; + static time_t window_start; + struct timespec now_ts; + const struct vkp_draw *a = dl->n > 0 ? &dl->d[dl->n - 1] : NULL; + const struct vkp_draw *b = dl->n > 1 ? &dl->d[dl->n - 2] : NULL; + struct surface *sa = a ? surface_for_image(a->img) : NULL; + struct surface *sb = b ? surface_for_image(b->img) : NULL; + const int signature[14] = { + dl->n, scene_w, scene_h, + a ? a->dw : 0, a ? a->dh : 0, + a ? vkp_image_width(a->img) : 0, a ? vkp_image_height(a->img) : 0, + a ? vkp_image_is_dmabuf(a->img) : 0, a ? a->blend : 0, sa && sa->dmabuf_buf ? 1 : 0, + b ? b->dw : 0, b ? b->dh : 0, b ? vkp_image_is_dmabuf(b->img) : 0, sb && sb->dmabuf_buf ? 1 : 0 + }; + clock_gettime(CLOCK_MONOTONIC, &now_ts); + if (!window_start || now_ts.tv_sec - window_start >= 30) { + seen_count = 0; + limit_logged = 0; + window_start = now_ts.tv_sec; + } + for (unsigned i = 0; i < seen_count; i++) + if (!memcmp(signature, seen[i], sizeof(signature))) return; + if (seen_count >= 32) { + if (!limit_logged++) droiddeck_log("layer", "zero-copy: further fullscreen-candidate rejection details suppressed after 32 signatures in 30 seconds"); + return; + } + memcpy(seen[seen_count++], signature, sizeof(signature)); + char below[48]; + if (b) + snprintf(below, sizeof(below), "%s %dx%d", + vkp_image_is_dmabuf(b->img) ? "DMA-BUF" : "non-DMA-BUF", b->dw, b->dh); + else + snprintf(below, sizeof(below), "none"); + droiddeck_log("layer", "zero-copy: no eligible fullscreen DMA-BUF layer candidate: scene %dx%d, %d draws; " + "top draw %dx%d at %d,%d image %dx%d %s%s surface=%s dmabuf=%s; " + "draw below %s", + scene_w, scene_h, dl->n, a ? a->dw : 0, a ? a->dh : 0, a ? a->dx : 0, a ? a->dy : 0, + a ? vkp_image_width(a->img) : 0, a ? vkp_image_height(a->img) : 0, + a && vkp_image_is_dmabuf(a->img) ? "DMA-BUF" : "non-DMA-BUF", + a && a->blend ? " blended" : "", + sa ? "associated" : "unassociated", + sa && sa->dmabuf_buf ? "yes" : "no", + below); +} + static struct surface *surface_for_image(const struct vkp_image *img) { struct surface *s; wl_list_for_each(s, &g_surfaces, link) @@ -2201,16 +2810,56 @@ static struct surface *surface_for_image(const struct vkp_image *img) { } static struct surface *ahb_layer_only_candidate(int scene_w, int scene_h) { + static struct { + const struct surface *surface; + int reason, scene_w, scene_h, w, h, buf_w, buf_h, x, y, src_set, dst_set, children; + } seen[32]; + static unsigned seen_count; + static int limit_logged; struct surface *s; - int w, h; + int w = 0, h = 0, reason = 0; if (wl_list_empty(&g_toplevels)) return NULL; s = wl_container_of(g_toplevels.prev, s, toplevel_link); - if (!s->dmabuf_buf || s->dmabuf_buf->img || !ahb_swapchain_has_ahb(s->dmabuf_buf)) return NULL; - if ((g_desktop && !s->placed) || s->x != 0 || s->y != 0 || s->src_set || s->dst_set) return NULL; - if (!wl_list_empty(&s->children)) return NULL; - if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) return NULL; + if (!s->dmabuf_buf) reason = 1; + else if (s->dmabuf_buf->img) reason = 2; + else if (!ahb_swapchain_has_ahb(s->dmabuf_buf)) reason = 3; + else if ((g_desktop && !s->placed) || s->x != 0 || s->y != 0 || s->src_set || s->dst_set) reason = 4; + else if (!wl_list_empty(&s->children)) reason = 5; + else if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) reason = 6; surface_size(s, &w, &h); - if (w != scene_w || h != scene_h || s->buf_w != scene_w || s->buf_h != scene_h) return NULL; + if (!reason && (w != scene_w || h != scene_h || s->buf_w != scene_w || s->buf_h != scene_h)) reason = 7; + if (reason) { + int found = 0; + for (unsigned i = 0; i < seen_count; i++) { + if (seen[i].surface == s && seen[i].reason == reason && seen[i].scene_w == scene_w && + seen[i].scene_h == scene_h && seen[i].w == w && seen[i].h == h && + seen[i].buf_w == s->buf_w && seen[i].buf_h == s->buf_h && seen[i].x == s->x && + seen[i].y == s->y && seen[i].src_set == s->src_set && seen[i].dst_set == s->dst_set && + seen[i].children == !wl_list_empty(&s->children)) { found = 1; break; } + } + if (!found && seen_count < 32) { + seen[seen_count].surface = s; seen[seen_count].reason = reason; + seen[seen_count].scene_w = scene_w; seen[seen_count].scene_h = scene_h; + seen[seen_count].w = w; seen[seen_count].h = h; seen[seen_count].buf_w = s->buf_w; seen[seen_count].buf_h = s->buf_h; + seen[seen_count].x = s->x; seen[seen_count].y = s->y; seen[seen_count].src_set = s->src_set; + seen[seen_count].dst_set = s->dst_set; seen[seen_count].children = !wl_list_empty(&s->children); + seen_count++; + const char *why = reason == 1 ? "no DMA-BUF buffer" : + reason == 2 ? "buffer is already importable by Vulkan" : + reason == 3 ? "no registered gralloc AHardwareBuffer" : + reason == 4 ? "surface is positioned/cropped/scaled" : + reason == 5 ? "surface has child surfaces" : + reason == 6 ? "hidden shell surface" : "surface or buffer dimensions differ from scene"; + char name[160]; describe(s, name, sizeof(name)); + droiddeck_log("layer", "zero-copy: AHardwareBuffer-only candidate rejected: %s; %s, scene %dx%d, surface %dx%d at %d,%d, buffer %dx%d, crop=%d destination=%d children=%d", + why, name, scene_w, scene_h, w, h, s->x, s->y, s->buf_w, s->buf_h, + s->src_set, s->dst_set, !wl_list_empty(&s->children)); + } else if (!found && !limit_logged) { + limit_logged = 1; + droiddeck_log("layer", "zero-copy: further AHardwareBuffer-only candidate diagnostics suppressed after 32 signatures"); + } + return NULL; + } return s; } @@ -2313,7 +2962,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 || hs->why == said_why)) return; + if (route == said && tm == said_tm && (route < 1 || route > 2 || hs->why == said_why)) return; int was = said; said = route; said_why = hs->why; said_tm = tm; char name[160] = "the HDR game"; @@ -2330,6 +2979,10 @@ 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); @@ -2502,7 +3155,13 @@ static int64_t scene_next_due(int64_t now, int64_t due, int limit) { static void render_scene(void) { g_scene_due_ns = scene_next_due(now_ns(), g_scene_due_ns, g_fps_limit); - if (atomic_load(&g_stream_on)) { g_dirty_since_ns = 0; render_stream(); return; } + if (atomic_load(&g_stream_on)) { + g_dirty_since_ns = 0; + g_zero_copy_shown = NULL; + settle_unwaited(); + render_stream(); + return; + } struct draw_list dl = {0}; struct surface *s; int w, h; @@ -2544,6 +3203,11 @@ 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); @@ -2576,6 +3240,8 @@ static void render_scene(void) { } else { cursor_hdr_said = 0; } + g_zero_copy_shown = NULL; + if (hdr_route == 1 || hdr_route == 2) settle_unwaited(); if (hdr_route == 1) { static int fell_back; vkp_apply_window_request(); @@ -2607,15 +3273,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 && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on && + if (hdr_route == 0 && !g_mirror_capture && 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 && hdr_route == 0 && framegen_fits_layer(); + const int fg_layer = framegen && !g_mirror_capture && hdr_route == 0 && framegen_fits_layer(); g_framegen_layer = fg_layer; - int li = (g_zero_copy && (!framegen || fg_layer) && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1; + int li = (g_zero_copy && !g_mirror_capture && (!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; } @@ -2644,7 +3311,10 @@ static void render_scene(void) { struct surface *ls = li >= 0 ? surface_for_image(dl.d[li].img) : NULL; const struct vkp_draw *ld = li >= 0 ? &dl.d[li] : NULL; if (li < 0) ls = layer_only; - if (g_zero_copy && li < 0 && !ls && !blocked && !cardboard) note_copy_scene(&dl, w, h, cursor_on); + if (g_zero_copy && li < 0 && !ls && !blocked && !cardboard) { + if (!cursor_on && !bfi) note_layer_candidate_rejected(&dl, w, h); + note_copy_scene(&dl, w, h, cursor_on); + } if (cardboard) ls = NULL; if (cursor_on) ls = NULL; if (bfi) ls = NULL; @@ -2658,6 +3328,7 @@ static void render_scene(void) { vkp_apply_window_request(); int r = -1; const int fg_pass = framegen && fx_on && li >= 0; + if (framegen && li >= 0) settle_unwaited(); const int generated = (framegen && li >= 0) ? sc_layer_present_generated(&dl.d[li], 1, NULL, w, h, fg_pass, ls ? droiddeck_surface_color(ls) : NULL) : 0; @@ -2671,16 +3342,34 @@ static void render_scene(void) { r = generated >= 0 ? 0 : -1; else if (generated >= 0 && !(fx_on && li >= 0) && ls && ls->dmabuf_buf && ahb_swapchain_has_ahb(ls->dmabuf_buf)) r = ahb_swapchain_present(ls->dmabuf_buf, ls, w, h, ld); - if (!fg_pass && generated >= 0 && r != 0 && li >= 0) - r = fx_on ? sc_layer_present_pass(&dl.d[li], 1, w, h) - : sc_layer_present(dl.d[li].img, w, h, ld, ls ? droiddeck_surface_color(ls) : NULL); + if (!fg_pass && generated >= 0 && !fx_on && !framegen && r != 0) { + if (!ls || !ls->dmabuf_buf) + note_zero_copy_fallback(ls, NULL, ZERO_COPY_NO_SURFACE_BUFFER, w, h, r); + else if (!ahb_swapchain_has_ahb(ls->dmabuf_buf)) + note_zero_copy_fallback(ls, ls->dmabuf_buf, ZERO_COPY_NO_GRALLOC_AHB, w, h, r); + else + note_zero_copy_fallback(ls, ls->dmabuf_buf, ZERO_COPY_AHB_PRESENT_FAILED, w, h, r); + } + if (r == 0 && !fg_pass) g_zero_copy_shown = ls; + else settle_unwaited(); + int ov = 0, ov_done = 0; + if (!fg_pass && generated >= 0 && r != 0 && li >= 0) { + if (fx_on) { + r = sc_layer_present_pass(&dl.d[li], 1, w, h); + } else { + r = sc_layer_present(dl.d[li].img, w, h, ld, ls ? droiddeck_surface_color(ls) : NULL, + over == 1 ? &dl.d[li + 1] : NULL, &ov); + ov_done = 1; + } + } if (r == 0) { if (ls) ls->drawn = 1; - int go[8], ov = 0; - if (over == 1 && li >= 0 && vkp_map_draw(&dl.d[li + 1], go)) + int go[8]; + if (!ov_done && over == 1 && li >= 0 && vkp_map_draw(&dl.d[li + 1], go)) ov = sc_layer_present_overlay(dl.d[li + 1].img, go, dl.d[li + 1].blend) == 0 ? 1 : -1; if (ov <= 0) sc_layer_hide_overlay(); if (ov < 0) { + settle_unwaited(); sc_layer_hide(); rendered = vkp_render(w, h, dl.d, dl.n) == 0; copy = 1; @@ -2690,12 +3379,14 @@ static void render_scene(void) { g_scene_queues = sc_layer_queues(); } } else { + settle_unwaited(); sc_layer_hide(); rendered = vkp_render(w, h, dl.d, dl.n) == 0; copy = 1; hdr_copy = "its display layer was unavailable this frame"; } } else { + settle_unwaited(); sc_layer_hide(); rendered = vkp_render(w, h, dl.d, dl.n) == 0; copy = 1; @@ -4131,11 +4822,15 @@ static void output_resized(void) { wl_display_flush_clients(g_display); } -static int on_input_readable(int fd, uint32_t mask, void *data) { +static void dispatch_input(int fd, int remaining) { struct input_msg m; int vsync = 0; int64_t vsync_ns = 0; - while (read(fd, &m, sizeof(m)) == (ssize_t)sizeof(m)) { + while (remaining != 0) { + ssize_t n = read(fd, &m, sizeof(m)); + if (n < 0 && errno == EINTR) continue; + if (n != (ssize_t)sizeof(m)) break; + if (remaining > 0) --remaining; switch (m.type) { case 1: deliver_key(&m); break; case 2: pointer_event(m.p1, m.p2, 0, 0); break; @@ -4177,9 +4872,27 @@ static int on_input_readable(int fd, uint32_t mask, void *data) { wl_display_flush_clients(g_display); } if (vsync) on_vsync(vsync_ns); +} + +static int on_input_readable(int fd, uint32_t mask, void *data) { + dispatch_input(fd, -1); return 0; } +void droiddeck_dispatch_pending_input(void) { + int fd = g_input_pipe[0]; + if (fd < 0) return; + + int bytes; + int result; + do { + result = ioctl(fd, FIONREAD, &bytes); + } while (result < 0 && errno == EINTR); + if (result == 0 && bytes >= (int)sizeof(struct input_msg)) { + dispatch_input(fd, bytes / (int)sizeof(struct input_msg)); + } +} + void droiddeck_wayland_set_scale_mode(int mode, int alignment) { if (g_input_pipe[1] < 0) { vk_present_set_scale_mode(mode, alignment); @@ -4299,6 +5012,12 @@ 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; @@ -4316,6 +5035,11 @@ void droiddeck_surface_scene_origin(struct wl_resource *surface, int *x, int *y) void droiddeck_inject_key(uint32_t evdev, int pressed) { key_event(evdev, pressed); } +int droiddeck_key_is_down(uint32_t evdev) { + return evdev < sizeof(g_keys_down) * 8 && + (g_keys_down[evdev >> 3] & (1u << (evdev & 7))) != 0; +} + static struct wl_event_source *g_stats_timer; volatile unsigned g_zero_copy_last; @@ -4325,6 +5049,7 @@ 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(); @@ -4333,7 +5058,8 @@ 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) snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u generated frames", generated); + 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); 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); } @@ -4344,11 +5070,12 @@ static int on_stats_timer(void *data) { unsigned aimed_next, aimed_later, aimed_even; sc_layer_aim_take(&aimed_next, &aimed_later, &aimed_even); #define PERF_MS(sum, n) ((n) ? (double)(sum) / 1e6 / (double)(n) : 0.0) - if (g_perf.scenes || vp.presents || g_perf.releases || drops) + if (g_perf.scenes || vp.presents || g_perf.releases || drops || g_perf.commit_waits) droiddeck_log("perf", "last 10 s: %u ticks, %u scenes, %u on screen (copy %u, zero-copy %u, layer copy %u) | " "render_scene %.2f/%.2f ms | base %u black kept, %u presented | acquire %.2f/%.2f ms | " "present %.2f/%.2f ms (%u) | fence wait %.2f/%.2f ms (%u, %u GPU release waits) | " - "release %.2f/%.2f ms (%u, %u held) | %u pool drops | layer frames timed for the next refresh %u, " + "release %.2f/%.2f ms (%u, %u held) | commits held for client writes %.2f/%.2f ms (%u, %u past the limit) | " + "%u pool drops | layer frames timed for the next refresh %u, " "the one after %u, held to an even step %u", g_perf.ticks, g_perf.scenes, g_stat_frames, g_perf.copy_scenes, zero_copy, layer_frames, PERF_MS(g_perf.scene_ns, g_perf.scenes), (double)g_perf.scene_max_ns / 1e6, @@ -4357,7 +5084,9 @@ static int on_stats_timer(void *data) { PERF_MS(vp.present_ns, vp.presents), (double)vp.present_max_ns / 1e6, vp.presents, PERF_MS(vp.wait_ns, vp.waits), (double)vp.wait_max_ns / 1e6, vp.waits, vp.gpu_release_waits, PERF_MS(g_perf.release_ns, g_perf.releases), (double)g_perf.release_max_ns / 1e6, - g_perf.releases, g_perf.releases_held, drops, aimed_next, aimed_later, aimed_even); + g_perf.releases, g_perf.releases_held, + PERF_MS(g_perf.commit_wait_ns, g_perf.commit_waits), (double)g_perf.commit_wait_max_ns / 1e6, + g_perf.commit_waits, g_perf.commit_wait_limits, drops, aimed_next, aimed_later, aimed_even); #undef PERF_MS memset(&g_perf, 0, sizeof(g_perf)); } @@ -4531,6 +5260,12 @@ 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); diff --git a/app/src/main/cpp/waylandcomp/src/display_buffers.c b/app/src/main/cpp/waylandcomp/src/display_buffers.c index 99f6993a56..f6ee1eb0d3 100644 --- a/app/src/main/cpp/waylandcomp/src/display_buffers.c +++ b/app/src/main/cpp/waylandcomp/src/display_buffers.c @@ -62,8 +62,40 @@ struct entry { static struct wl_list g_entries; static struct wl_event_loop *g_loop; static uint64_t g_next_id = 1; -static int g_refused_logged; static int g_ubwc_promised; + +#define DISPLAY_BUFFER_MISMATCH_SIGNATURES 64u +struct display_buffer_mismatch_signature { + uint32_t kind, format, stride, offset; + int width, height; + uint64_t modifier; +}; +static struct display_buffer_mismatch_signature g_mismatch_signatures[DISPLAY_BUFFER_MISMATCH_SIGNATURES]; +static uint32_t g_mismatch_signature_count; +static int g_mismatch_limit_logged; + +static int mismatch_should_log(const struct dmabuf_buffer *b, uint32_t kind) { + const struct display_buffer_mismatch_signature key = { + .kind = kind, .format = b->format, .stride = b->stride[0], .offset = b->offset[0], + .width = b->width, .height = b->height, .modifier = b->modifier}; + for (uint32_t i = 0; i < g_mismatch_signature_count; i++) { + const struct display_buffer_mismatch_signature *seen = &g_mismatch_signatures[i]; + if (seen->kind == key.kind && seen->format == key.format && seen->stride == key.stride && + seen->offset == key.offset && seen->width == key.width && seen->height == key.height && + seen->modifier == key.modifier) + return 0; + } + if (g_mismatch_signature_count >= DISPLAY_BUFFER_MISMATCH_SIGNATURES) { + if (!g_mismatch_limit_logged) { + g_mismatch_limit_logged = 1; + droiddeck_log("layer", "display buffers: further mismatch diagnostics suppressed after %u distinct buffer signatures", + DISPLAY_BUFFER_MISMATCH_SIGNATURES); + } + return 0; + } + g_mismatch_signatures[g_mismatch_signature_count++] = key; + return 1; +} static int g_ubwc_probed[2]; static uint32_t ahb_format_of(uint32_t drm, uint64_t modifier) { @@ -238,16 +270,51 @@ static void handle_alloc(struct peer *p, const struct display_buffers_request *q } else { if (ahb) AHardwareBuffer_release(ahb); fd = -1; - if (sized && wanted && (compressed || !g_refused_logged)) { - g_refused_logged = 1; - droiddeck_log(compressed ? "error" : "layer", "display buffers: no gralloc buffer matches pid %d's %ux%u " - "%c%c%c%c %s layout (stride %u bytes, pixels at %u, %llu bytes; gralloc's layout has pixels at " - "%llu, %llu bytes): %s", (int)p->pid, q->width, q->height, - q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff, - compressed ? "UBWC" : "linear", q->stride, q->offset, (unsigned long long)q->size, - (unsigned long long)(compressed ? ubwc_meta_size(q->width, q->height) : 0), - (unsigned long long)(compressed ? ubwc_size(q->width, q->height, q->stride) : q->size), - compressed ? "its compressed frames cannot be shown" : "its frames keep the copy path"); + static struct { + pid_t pid; + uint32_t width, height, format, stride, offset, reason; + uint64_t size, modifier; + } refused[32]; + static unsigned refused_count; + static int refused_limit_logged; + uint32_t reason = !sized ? 1u : !sane ? 2u : !wanted ? 3u : + !ahb_swapchain_advertised() ? 4u : + p->count >= DISPLAY_BUFFERS_MAX_PER_CLIENT ? 5u : 6u; + int seen = 0; + for (unsigned i = 0; i < refused_count; i++) { + if (refused[i].pid == p->pid && refused[i].width == q->width && refused[i].height == q->height && + refused[i].format == q->format && refused[i].stride == q->stride && refused[i].offset == q->offset && + refused[i].size == q->size && refused[i].modifier == q->modifier && refused[i].reason == reason) { + seen = 1; + break; + } + } + if (!seen && refused_count < 32) { + refused[refused_count].pid = p->pid; + refused[refused_count].width = q->width; + refused[refused_count].height = q->height; + refused[refused_count].format = q->format; + refused[refused_count].stride = q->stride; + refused[refused_count].offset = q->offset; + refused[refused_count].size = q->size; + refused[refused_count].modifier = q->modifier; + refused[refused_count].reason = reason; + refused_count++; + const char *why = reason == 1 ? "invalid dimensions, format, or stride" : + reason == 2 ? "size/offset/layout sanity check failed" : + reason == 3 ? "zero-copy or UBWC offering is disabled" : + reason == 4 ? "AHardwareBuffer swapchain is not advertised" : + reason == 5 ? "per-client allocation limit reached" : + "gralloc allocation/fd/size validation failed"; + droiddeck_log(compressed ? "error" : "layer", + "display buffers: allocation refused for pid %d: %s; request %ux%u %c%c%c%c %s stride=%u offset=%u size=%llu modifier=0x%llx (client has %d allocations)", + (int)p->pid, why, q->width, q->height, + q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff, + compressed ? "UBWC" : "linear", q->stride, q->offset, + (unsigned long long)q->size, (unsigned long long)q->modifier, p->count); + } else if (!seen && !refused_limit_logged) { + refused_limit_logged = 1; + droiddeck_log("layer", "display buffers: further allocation-refusal diagnostics suppressed after 32 signatures"); } } if (reply(p, &r, fd) != 0 && e) entry_free(e); @@ -299,9 +366,18 @@ static int on_listen(int fd, uint32_t mask, void *data) { } void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b) { + static int invalid_logged; struct stat st; struct entry *e; - if (!g_loop || wl_list_empty(&g_entries) || b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) return; + if (!g_loop || wl_list_empty(&g_entries)) return; + if (b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) { + if (!invalid_logged) { + invalid_logged = 1; + droiddeck_log("layer", "display buffers: cannot associate %s's DMA-BUF with gralloc (plane count %u; expected one plane at offset 0, or fstat failed)", + droiddeck_client_name(c), b->n_planes); + } + return; + } wl_list_for_each(e, &g_entries, link) { if (e->dev != st.st_dev || e->ino != st.st_ino) continue; AHardwareBuffer_Desc d; @@ -311,11 +387,27 @@ void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, stru (uint32_t)b->height == e->height : (b->modifier == MOD_LINEAR || b->modifier == MOD_INVALID) && e->stride == b->stride[0]; - if (laid_out && e->format == ahb_format_of(b->format, e->modifier) && b->width > 0 && b->height > 0 && - (uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height) + const uint32_t expected_format = ahb_format_of(b->format, e->modifier); + const int dimensions = b->width > 0 && b->height > 0 && + (uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height; + if (laid_out && e->format == expected_format && dimensions) { ahb_swapchain_adopt(c, buffer, b, e->ahb, e->modifier); + } else if (mismatch_should_log(b, 2)) { + droiddeck_log("layer", "display buffers: gralloc DMA-BUF identity matched but layout was rejected for %s: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; gralloc %ux%u stride %u format 0x%x, expected format 0x%x (layout %s, dimensions %s)", + droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff, + (b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height, + b->stride[0], b->offset[0], (unsigned long long)b->modifier, + e->width, e->height, e->stride, e->format, expected_format, + laid_out ? "ok" : "mismatch", dimensions ? "ok" : "mismatch"); + } return; } + if (mismatch_should_log(b, 1)) { + droiddeck_log("layer", "display buffers: no registered gralloc allocation matches %s's DMA-BUF identity: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; imported normally, copy path only", + droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff, + (b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height, + b->stride[0], b->offset[0], (unsigned long long)b->modifier); + } } void display_buffers_init(struct wl_display *display) { diff --git a/app/src/main/cpp/waylandcomp/src/droiddeck_ext.c b/app/src/main/cpp/waylandcomp/src/droiddeck_ext.c index 1172c095b0..e4ce7e201d 100644 --- a/app/src/main/cpp/waylandcomp/src/droiddeck_ext.c +++ b/app/src/main/cpp/waylandcomp/src/droiddeck_ext.c @@ -4,12 +4,14 @@ #include #include #include +#include +#include #include #include "droiddeck_ext.h" #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 }; +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 }; struct host_msg { enum host_kind kind; @@ -23,6 +25,32 @@ static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; static struct host_msg *g_head, *g_tail; static int g_wake[2] = {-1, -1}; +/* Compositor-thread-only fallback ordering state. */ +static int g_pending_token, g_pending_submit; +static int g_fallback_failed; +static int g_next_token = 1; +static struct host_msg *g_deferred_head, *g_deferred_tail; +static size_t g_deferred_count, g_deferred_bytes; +static int g_deferred_overflow; +static int g_completed_token, g_completed_result; + +#define DROIDDECK_EVDEV_KEY_MAX 768 +#define DROIDDECK_TEXT_DEFERRED_LIMIT 256 +#define DROIDDECK_TEXT_DEFERRED_BYTES (256 * 1024) +static unsigned char g_ordered_key_down[DROIDDECK_EVDEV_KEY_MAX]; + +void droiddeck_host_text_input_fallback_complete(int token, int result) { + pthread_mutex_lock(&g_mu); + g_completed_token = token; + g_completed_result = result; + pthread_mutex_unlock(&g_mu); + if (g_wake[1] >= 0) { + char c = 1; + ssize_t n = write(g_wake[1], &c, 1); + (void)n; + } +} + static void host_post(enum host_kind kind, const char *text, size_t len, int a, int b) { struct host_msg *m = calloc(1, sizeof(*m)); if (!m) return; @@ -51,6 +79,9 @@ void droiddeck_host_clipboard_text(const char *utf8, int len) { void droiddeck_host_text_commit(const char *utf8, int len) { host_post(HOST_TEXT_COMMIT, utf8, len > 0 ? (size_t)len : 0, 0, 0); } +void droiddeck_host_text_commit_and_submit(const char *utf8, int len) { + if (len > 0) host_post(HOST_TEXT_COMMIT, utf8, (size_t)len, 1, 0); +} void droiddeck_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end) { host_post(HOST_TEXT_PREEDIT, utf8, len > 0 ? (size_t)len : 0, cursor_begin, cursor_end); } @@ -60,26 +91,179 @@ 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); } +void droiddeck_host_key(int evdev, int state) { + host_post(HOST_KEY, NULL, 0, evdev, state); +} + +void droiddeck_host_select_game_field(int copy) { + host_post(HOST_SELECT_GAME_FIELD, NULL, 0, copy, 0); +} + +static void tap_unheld_key(uint32_t key) { + if (droiddeck_key_is_down(key)) return; + droiddeck_inject_key(key, 1); + droiddeck_inject_key(key, 0); +} + +static void select_game_field(int copy) { + /* Apply pending raw releases before using the compositor's held-key state. */ + droiddeck_dispatch_pending_input(); + int temporary_ctrl = !droiddeck_key_is_down(KEY_LEFTCTRL) && !droiddeck_key_is_down(KEY_RIGHTCTRL); + if (temporary_ctrl) droiddeck_inject_key(KEY_LEFTCTRL, 1); + tap_unheld_key(KEY_A); + if (copy) tap_unheld_key(KEY_C); + if (temporary_ctrl) droiddeck_inject_key(KEY_LEFTCTRL, 0); +} + +static void restore_deferred_to_front(void) { + if (g_deferred_head) { + g_deferred_tail->next = g_head; + if (!g_head) g_tail = g_deferred_tail; + g_head = g_deferred_head; + g_deferred_head = g_deferred_tail = NULL; + g_deferred_count = g_deferred_bytes = 0; + } +} + +/* Only suppress the queued submit for this commit, not a later commit or a held-key release. */ +static void discard_queued_submit(void) { + struct host_msg *prev = NULL; + struct host_msg *m = g_head; + int enter_held = g_ordered_key_down[KEY_ENTER]; + int key_pad_enter_held = g_ordered_key_down[KEY_KPENTER]; + while (m) { + int soft_submit = 0; + if (m->kind == HOST_TEXT_COMMIT) { + if (m->a || m->len == 0) break; + soft_submit = 1; + size_t i = 0; + for (; i < m->len; i++) { + char c = m->text[i]; + if (c != '\r' && c != '\n') soft_submit = 0; + if (c != '\r' && c != '\n' && c != '\b' && c != '\t' && c != 0x7f) break; + } + if (i != m->len) break; + } + struct host_msg *next = m->next; + int *held = m->a == KEY_ENTER ? &enter_held : m->a == KEY_KPENTER ? &key_pad_enter_held : NULL; + if (soft_submit || (m->kind == HOST_KEY && held && (m->b != 0 || !*held))) { + if (prev) prev->next = next; else g_head = next; + if (g_tail == m) g_tail = prev; + free(m->text); + free(m); + } else { + if (m->kind == HOST_KEY && held) *held = 0; + prev = m; + } + m = next; + } +} + +static int release_held_key(const struct host_msg *m) { + int k = m->a; + if (m->kind != HOST_KEY || m->b != 0 || k < 0 || k >= DROIDDECK_EVDEV_KEY_MAX || + !g_ordered_key_down[k]) return 0; + g_ordered_key_down[k] = 0; + droiddeck_inject_key((uint32_t)k, 0); + return 1; +} + +static void discard_deferred_input(void) { + struct host_msg *m = g_deferred_head; + while (m) { + struct host_msg *next = m->next; + release_held_key(m); + free(m->text); + free(m); + m = next; + } + g_deferred_head = g_deferred_tail = NULL; + g_deferred_count = g_deferred_bytes = 0; +} static int on_wake(int fd, uint32_t mask, void *data) { char buf[64]; while (read(fd, buf, sizeof(buf)) > 0) {} for (;;) { + int deferred = 0, submit = 0; pthread_mutex_lock(&g_mu); + if (g_pending_token != 0 && g_completed_token == g_pending_token) { + int result = g_completed_result; + g_completed_token = 0; + restore_deferred_to_front(); + if (result != DROIDDECK_TEXT_DELIVERED) discard_queued_submit(); + if (result == DROIDDECK_TEXT_UNRESOLVED) { + g_fallback_failed = 1; + } else { + if (result == DROIDDECK_TEXT_DELIVERED) submit = g_pending_submit; + g_pending_submit = 0; + g_pending_token = 0; + g_fallback_failed = 0; + g_deferred_overflow = 0; + } + } struct host_msg *m = g_head; - if (m) { g_head = m->next; if (!g_head) g_tail = NULL; } + if (m) { g_head = m->next; if (!g_head) g_tail = NULL; m->next = NULL; } pthread_mutex_unlock(&g_mu); + if (submit) tap_unheld_key(KEY_ENTER); if (!m) break; + if (g_pending_token != 0 && + (m->kind == HOST_TEXT_COMMIT || m->kind == HOST_TEXT_PREEDIT || + m->kind == HOST_TEXT_DELETE || m->kind == HOST_KEY || + m->kind == HOST_SELECT_GAME_FIELD)) { + int released_during_recovery = g_fallback_failed && release_held_key(m); + if (released_during_recovery || g_deferred_overflow || + g_deferred_count == DROIDDECK_TEXT_DEFERRED_LIMIT || + m->len > DROIDDECK_TEXT_DEFERRED_BYTES - g_deferred_bytes) { + if (!released_during_recovery) { + /* An incomplete queue could replay a submit or lose a paired release. */ + if (!g_deferred_overflow) + droiddeck_log("text-input", "deferred input exceeded the recovery queue limit"); + discard_deferred_input(); + release_held_key(m); + g_deferred_overflow = 1; + } + free(m->text); + free(m); + continue; + } + if (g_deferred_tail) g_deferred_tail->next = m; else g_deferred_head = m; + g_deferred_tail = m; + g_deferred_count++; + g_deferred_bytes += m->len; + deferred = 1; + } + if (deferred) continue; switch (m->kind) { case HOST_CLIPBOARD: clipboard_host_text(m->text, m->len); m->text = NULL; break; case HOST_TEXT_COMMIT: - text_input_host_commit(m->text ? m->text : "", m->len); + if (!text_input_host_commit(m->text ? m->text : "", m->len)) { + int token = 0; + if (g_next_token == INT_MAX) g_next_token = 1; + else g_next_token++; + token = g_next_token; + g_pending_token = 0; + if (droiddeck_on_text_input_fallback(m->text ? m->text : "", (int)m->len, token)) { + g_pending_token = token; + g_pending_submit = m->a; + } else { + droiddeck_log("text-input", "fallback had no accepting Android listener"); + pthread_mutex_lock(&g_mu); + discard_queued_submit(); + pthread_mutex_unlock(&g_mu); + } + } else if (m->a) { + tap_unheld_key(KEY_ENTER); + } break; case HOST_TEXT_PREEDIT: text_input_host_preedit(m->text ? m->text : "", m->len, m->a, m->b); @@ -90,9 +274,25 @@ 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; + case HOST_SELECT_GAME_FIELD: + select_game_field(m->a); + break; + case HOST_KEY: + if (m->b == 1) { + int k = m->a; + if (k >= 0 && k < DROIDDECK_EVDEV_KEY_MAX) g_ordered_key_down[k] = 1; + } else if (m->b == 0) { + int k = m->a; + if (k >= 0 && k < DROIDDECK_EVDEV_KEY_MAX) g_ordered_key_down[k] = 0; + } + droiddeck_inject_key((uint32_t)m->a, m->b); + break; } free(m->text); free(m); diff --git a/app/src/main/cpp/waylandcomp/src/droiddeck_ext.h b/app/src/main/cpp/waylandcomp/src/droiddeck_ext.h index ca359557e4..bc67469eff 100644 --- a/app/src/main/cpp/waylandcomp/src/droiddeck_ext.h +++ b/app/src/main/cpp/waylandcomp/src/droiddeck_ext.h @@ -15,22 +15,36 @@ struct wl_display *droiddeck_get_display(void); struct wl_resource *droiddeck_ime_target(void); void droiddeck_surface_scene_origin(struct wl_resource *surface, int *x, int *y); void droiddeck_inject_key(uint32_t evdev, int pressed); +int droiddeck_key_is_down(uint32_t evdev); +void droiddeck_dispatch_pending_input(void); void droiddeck_on_clipboard_text(const char *utf8, int len); +int droiddeck_on_text_input_fallback(const char *utf8, int len, int token); void droiddeck_on_text_input(int enabled, const char *program, int x, int y, int w, int h); void droiddeck_host_clipboard_text(const char *utf8, int len); void droiddeck_host_text_commit(const char *utf8, int len); +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); +enum droiddeck_text_input_result { + DROIDDECK_TEXT_NOT_DELIVERED = 0, + DROIDDECK_TEXT_DELIVERED = 1, + DROIDDECK_TEXT_UNRESOLVED = 2, +}; +void droiddeck_host_text_input_fallback_complete(int token, int result); void clipboard_init(struct wl_display *display); void clipboard_host_text(char *utf8, size_t len); void text_input_init(struct wl_display *display); -void text_input_host_commit(const char *utf8, size_t len); +int text_input_host_commit(const char *utf8, size_t len); void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end); void text_input_host_delete(int before, int after); void toplevel_icon_init(struct wl_display *display); diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.c b/app/src/main/cpp/waylandcomp/src/effects_chain.c index d711e565f3..90423d2441 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.c +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.c @@ -3,6 +3,7 @@ #include "blend_pass.h" #include "vk_loader.h" #include "vk_present.h" +#include "framegen_bridge.h" #include #include #include @@ -21,6 +22,7 @@ #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" @@ -69,6 +71,7 @@ static struct fx_settings g_set = { .gamma = 1.0f, .saturation = 1.0f, .s_raw = 100.0f, .look = "Off"}; static volatile int g_changed; static struct fx_settings g_cur; +static struct fx_settings g_generated_settings; static int g_cur_valid; static void set_begin(void) { pthread_mutex_lock(&g_lock); } @@ -194,6 +197,7 @@ 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; @@ -228,20 +232,33 @@ static VkDevice g_dev; static VkPhysicalDevice g_pd; static VkPhysicalDeviceMemoryProperties g_mp; static int g_ready; -static VkRenderPass g_rp, g_smaa_rp; +static VkRenderPass g_rp, g_smaa_edge_rp, g_smaa_weights_rp; static VkDescriptorSetLayout g_dsl; static VkPipelineLayout g_pl; static VkDescriptorPool g_dpool; static VkSampler g_sampler; enum { P_SGSR, P_SGSR_HQ, P_NIS, P_EASU, P_RCAS, P_CAS, P_COLOR, P_FXAA, P_FXAA_TOON, P_SMAA_EDGE, P_SMAA_WEIGHTS, P_SMAA_BLEND, P_TOON, P_TOON_COLOR, P_HDR, P_NTSC, P_CRT, P_DEBAND, P_NIS_LUMA, P_COUNT }; static VkPipeline g_pipe[P_COUNT]; -static struct fx_target g_t[2], g_mid, g_smaa_edges, g_smaa_weights; +struct fx_context { + struct fx_target targets[2], mid, nissrc; + struct { VkImage img; VkImageView view; VkDescriptorSet ds; int w, h; } scene; +}; +#define FX_CONTEXTS (VKP_FG_MAX_GENERATIONS + 2) +static struct fx_context g_contexts[FX_CONTEXTS]; +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; /* 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). * Old set (or no buffer): nis.frag on the scene, P_NIS_LUMA unused. */ -static struct fx_target g_nissrc; static int g_nis_fast; +static int g_nis_attempted; +static int g_upscale_half; static VkDescriptorSetLayout g_coef_dsl; static VkPipelineLayout g_pl_nis; static VkDescriptorPool g_coef_pool; @@ -249,7 +266,7 @@ static VkDescriptorSet g_coef_ds; static VkBuffer g_coef_buf; static VkDeviceMemory g_coef_mem; -static struct { VkImage img; VkImageView view; VkDescriptorSet ds; int w, h; } g_scene; +#define g_scene (g_contexts[g_context].scene) void vkp_effects_bind_device(VkDevice dev, VkPhysicalDevice pd, const VkPhysicalDeviceMemoryProperties *memprops) { @@ -298,6 +315,7 @@ 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, @@ -305,8 +323,9 @@ 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, - .flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, .imageType = VK_IMAGE_TYPE_2D, - .format = format, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, + /* 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, .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}; @@ -324,12 +343,16 @@ 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; } - g_vk.BindImageMemory(g_dev, t->img, t->mem, 0); + 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; + } 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 (g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; } + if (render_pass && 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; @@ -347,7 +370,53 @@ static void scene_release(void) { } void vkp_effects_forget_image(VkImage img) { - if (img && g_scene.img == img) scene_release(); + int saved = g_context; + for (g_context = 0; g_context < FX_CONTEXTS; g_context++) + if (img && g_scene.img == img) scene_release(); + 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; } static int scene_ensure(VkImage img, int w, int h) { @@ -402,6 +471,22 @@ 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); @@ -423,18 +508,8 @@ 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; - 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; + void *p = host_buffer(4096, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, &g_coef_buf, &g_coef_mem); + if (!p) goto fail; memcpy(p, kNisCoefScale, sizeof(kNisCoefScale)); memcpy((char *)p + sizeof(kNisCoefScale), kNisCoefUsm, sizeof(kNisCoefUsm)); g_vk.UnmapMemory(g_dev, g_coef_mem); @@ -454,6 +529,29 @@ 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) { @@ -473,19 +571,28 @@ static int upscale_half_set(void) { static void objects_destroy(void) { if (!g_dev) return; - scene_release(); - target_destroy(&g_t[0]); target_destroy(&g_t[1]); target_destroy(&g_mid); - target_destroy(&g_smaa_edges); target_destroy(&g_smaa_weights); target_destroy(&g_nissrc); + int saved = g_context; + for (g_context = 0; g_context < FX_CONTEXTS; g_context++) { + scene_release(); + target_destroy(&g_t[0]); target_destroy(&g_t[1]); target_destroy(&g_mid); + target_destroy(&g_nissrc); + } + 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_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_rp, 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_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_rp = 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_nis_fast = 0; g_nis_attempted = 0; g_upscale_half = 0; g_ready = 0; } @@ -505,7 +612,9 @@ void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt, int scene_ : target_fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? "the HDR picture for frame generation" : "the HDR composition's picture: PQ, or tone-mapped SDR with HDR output off"); } else if (scene_fmt != g_scene_fmt) { - scene_release(); + int saved = g_context; + for (g_context = 0; g_context < FX_CONTEXTS; g_context++) scene_release(); + g_context = saved; g_scene_fmt = scene_fmt; } } @@ -536,9 +645,12 @@ 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_rp) != VK_SUCCESS) goto fail; + 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; VkSamplerCreateInfo sci = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, @@ -552,79 +664,21 @@ 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[2] = {g_dsl, g_dsl}; - VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = set_layouts, + 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, .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, 10}; + VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 4}; VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, - .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = 10, + .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 4, .poolSizeCount = 1, .pPoolSizes = &ps}; if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail; - VkShaderModule vert = shader(upscale_vert_code, sizeof(upscale_vert_code)); - if (!vert) goto fail; -#define MKL(slot, code, name, layout) do { g_pipe[slot] = post_pipeline_for_renderpass(vert, code, sizeof(code), g_rp, name, layout); if (!g_pipe[slot]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; } } while (0) -#define MK(slot, code, name) MKL(slot, code, name, g_pl) - const int half = upscale_half_set(); + g_upscale_half = upscale_half_set(); g_nis_fast = 0; - if (half && !fx_alpha_holds_luma(g_fx_fmt)) - droiddeck_log("effects", "NIS uses nis.frag: the chain format has no 8-bit alpha for the luma prepass"); - else if (half && coef_create() != 0) - droiddeck_log("effects", "NIS coefficient buffer unavailable; NIS uses nis.frag"); - else if (half) - g_nis_fast = 1; - if (half) { - MK(P_SGSR, sgsr_half_code, "sgsr_half"); - MK(P_SGSR_HQ, sgsr_quality_half_code, "sgsr_quality_half"); - if (g_nis_fast) { - /* optional: a driver that rejects either fast NIS pipeline gets nis.frag, not a dead chain */ - g_pipe[P_NIS] = post_pipeline_for_renderpass(vert, nis3_half_code, sizeof(nis3_half_code), g_rp, "nis3_half", g_pl_nis); - g_pipe[P_NIS_LUMA] = g_pipe[P_NIS] - ? post_pipeline_for_renderpass(vert, nis_luma_half_code, sizeof(nis_luma_half_code), g_rp, "nis_luma_half", g_pl) - : VK_NULL_HANDLE; - if (!g_pipe[P_NIS] || !g_pipe[P_NIS_LUMA]) { - if (g_pipe[P_NIS]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS], NULL); - g_pipe[P_NIS] = VK_NULL_HANDLE; - coef_destroy(); - g_nis_fast = 0; - droiddeck_log("effects", "fast NIS pipelines failed to build; NIS uses nis.frag"); - } - } - if (!g_nis_fast) MK(P_NIS, nis_code, "nis"); - MK(P_EASU, fsr_easu_half_code, "fsr_easu_half"); - MK(P_RCAS, fsr_rcas_half_code, "fsr_rcas_half"); - MK(P_CAS, cas_ffx_half_code, "cas_ffx_half"); - } else { - MK(P_SGSR, sgsr_code, "sgsr"); - MK(P_SGSR_HQ, sgsr_quality_code, "sgsr_quality"); - MK(P_NIS, nis_code, "nis"); - MK(P_EASU, fsr_easu_code, "fsr_easu"); - MK(P_RCAS, fsr_rcas_code, "fsr_rcas"); - MK(P_CAS, cas_code, "cas"); - } - MK(P_COLOR, color_code, "color"); - MK(P_FXAA, fxaa_code, "fxaa"); - MK(P_FXAA_TOON, fxaa_toon_code, "fxaa_toon"); - g_pipe[P_SMAA_EDGE] = post_pipeline_for_renderpass( - vert, smaa_edge_code, sizeof(smaa_edge_code), g_smaa_rp, "smaa_edge", g_pl); - if (!g_pipe[P_SMAA_EDGE]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; } - g_pipe[P_SMAA_WEIGHTS] = post_pipeline_for_renderpass( - vert, smaa_weights_code, sizeof(smaa_weights_code), g_smaa_rp, "smaa_weights", g_pl); - if (!g_pipe[P_SMAA_WEIGHTS]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; } - MK(P_SMAA_BLEND, smaa_blend_code, "smaa_blend"); - MK(P_TOON, toon_code, "toon"); - MK(P_TOON_COLOR, toon_color_code, "toon_color"); - MK(P_HDR, hdr_code, "hdr"); - MK(P_NTSC, ntsc_code, "ntsc"); - MK(P_CRT, crt_code, "crt"); - MK(P_DEBAND, deband_code, "deband"); -#undef MK -#undef MKL - g_vk.DestroyShaderModule(g_dev, vert, NULL); + g_nis_attempted = 0; g_ready = 1; - droiddeck_log("effects", "chain ready: 16 pipelines (SGSR, SGSR HQ, NIS, FSR EASU+RCAS, CAS, colour, FXAA, SMAA edge/weights/blend, Toon, HDR, NTSC, CRT, deband), %s upscalers%s, on %s", - half ? "half-precision" : "old fp32", g_nis_fast ? " + NIS luma prepass" : "", vkp_gpu_name()); + droiddeck_log("effects", "shared resources ready on %s; effect pipelines are created when needed", vkp_gpu_name()); return 0; fail: objects_destroy(); @@ -633,6 +687,95 @@ fail: return -1; } +static int chain_failed(void) { + objects_destroy(); + g_ready = -1; + droiddeck_log("error", "effects: the screen-effect chain could not be built on this driver; effects are off for this session"); + return -1; +} + +static int pipelines_ensure(int spatial, const struct fx_settings *s) { + VkShaderModule vert = VK_NULL_HANDLE; +#define MKL(needed, slot, code, name, render_pass, layout) do { \ + if ((needed) && !g_pipe[slot]) { \ + if (!vert && !(vert = shader(upscale_vert_code, sizeof(upscale_vert_code)))) goto fail; \ + g_pipe[slot] = post_pipeline_for_renderpass(vert, code, sizeof(code), render_pass, name, layout); \ + if (!g_pipe[slot]) goto fail; \ + } \ +} while (0) +#define MK(needed, slot, code, name) MKL(needed, slot, code, name, g_rp, g_pl) + if (spatial == 3) { + if (g_upscale_half) MK(1, P_SGSR, sgsr_half_code, "sgsr_half"); + else MK(1, P_SGSR, sgsr_code, "sgsr"); + } + if (spatial == 8) { + if (g_upscale_half) MK(1, P_SGSR_HQ, sgsr_quality_half_code, "sgsr_quality_half"); + else MK(1, P_SGSR_HQ, sgsr_quality_code, "sgsr_quality"); + } + if (spatial == 4 || spatial == 5) { + if (g_upscale_half) MK(1, P_EASU, fsr_easu_half_code, "fsr_easu_half"); + else MK(1, P_EASU, fsr_easu_code, "fsr_easu"); + if (s->sharp_pct != 0) { + if (g_upscale_half) MK(1, P_RCAS, fsr_rcas_half_code, "fsr_rcas_half"); + else MK(1, P_RCAS, fsr_rcas_code, "fsr_rcas"); + } + } + if (spatial == 6) { + if (g_upscale_half) MK(1, P_RCAS, fsr_rcas_half_code, "fsr_rcas_half"); + else MK(1, P_RCAS, fsr_rcas_code, "fsr_rcas"); + } + if (spatial == 7) { + if (g_upscale_half && !g_nis_attempted) { + g_nis_attempted = 1; + if (!fx_alpha_holds_luma(g_fx_fmt)) + droiddeck_log("effects", "NIS uses nis.frag: the chain format has no 8-bit alpha for the luma prepass"); + else if (coef_create() != 0) + droiddeck_log("effects", "NIS coefficient buffer unavailable; NIS uses nis.frag"); + else { + if (!vert && !(vert = shader(upscale_vert_code, sizeof(upscale_vert_code)))) goto fail; + g_pipe[P_NIS] = post_pipeline_for_renderpass(vert, nis3_half_code, sizeof(nis3_half_code), g_rp, "nis3_half", g_pl_nis); + if (g_pipe[P_NIS]) + g_pipe[P_NIS_LUMA] = post_pipeline_for_renderpass(vert, nis_luma_half_code, sizeof(nis_luma_half_code), g_rp, "nis_luma_half", g_pl); + if (g_pipe[P_NIS] && g_pipe[P_NIS_LUMA]) g_nis_fast = 1; + else { + if (g_pipe[P_NIS]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS], NULL); + if (g_pipe[P_NIS_LUMA]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS_LUMA], NULL); + g_pipe[P_NIS] = VK_NULL_HANDLE; + g_pipe[P_NIS_LUMA] = VK_NULL_HANDLE; + coef_destroy(); + droiddeck_log("effects", "fast NIS pipelines failed to build; NIS uses nis.frag"); + } + } + } + if (!g_nis_fast) MK(1, P_NIS, nis_code, "nis"); + else if (g_upscale_half) MK(1, P_SGSR, sgsr_half_code, "sgsr_half"); + } + if (cas_active(s)) { + if (g_upscale_half) MK(1, P_CAS, cas_ffx_half_code, "cas_ffx_half"); + else MK(1, P_CAS, cas_code, "cas"); + } + 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); + 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"); + else if (s->toon) MK(1, P_TOON, toon_code, "toon"); + if (s->hdr_on) MK(1, P_HDR, hdr_code, "hdr"); + if (s->ntsc) MK(1, P_NTSC, ntsc_code, "ntsc"); + if (s->crt) MK(1, P_CRT, crt_code, "crt"); + if (deband_active(s)) MK(1, P_DEBAND, deband_code, "deband"); +#undef MK +#undef MKL + if (vert) g_vk.DestroyShaderModule(g_dev, vert, NULL); + return 0; +fail: + if (vert) g_vk.DestroyShaderModule(g_dev, vert, NULL); + return chain_failed(); +} + static void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to, VkPipelineStageFlags src_stage, VkAccessFlags src_access, @@ -644,14 +787,32 @@ 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); } -static void pass_renderpass(VkCommandBuffer cmd, VkRenderPass render_pass, - VkPipeline p, struct fx_target *dst, VkDescriptorSet src, - const void *pc, uint32_t pcsz) { +/* 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}; 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}}}; + .renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}, + .clearValueCount = 1, .pClearValues = &clear}; 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, 1, &src, 0, NULL); + g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, count, 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); @@ -661,34 +822,38 @@ static void pass_renderpass(VkCommandBuffer cmd, VkRenderPass render_pass, static void pass(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst, VkDescriptorSet src, const void *pc, uint32_t 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); + pass_sets(cmd, g_rp, p, dst, &src, 1, pc, pcsz); } static const float FULL_NDC[4] = {-1.0f, -1.0f, 1.0f, 1.0f}; #define SET_NDC(pc) memcpy((pc).ndc, FULL_NDC, sizeof(FULL_NDC)) -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) { +struct fx_source_state { + VkImageLayout layout; + VkPipelineStageFlags stage; + 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, + struct fx_source_state *source_state) { struct fx_settings snapshot; const struct fx_settings *s; - vkp_effects_sync(); - pthread_mutex_lock(&g_lock); - snapshot = g_cur; - pthread_mutex_unlock(&g_lock); + if (frozen) { + snapshot = *frozen; + } else { + vkp_effects_sync(); + pthread_mutex_lock(&g_lock); + snapshot = g_cur; + pthread_mutex_unlock(&g_lock); + } s = &snapshot; *res_w = scene_w; *res_h = scene_h; @@ -700,11 +865,7 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce const int upscaling = cw > scene_w || ch > scene_h; int spatial = 0; if (spatial_mode(s->scaling) && (s->scaling == 6 || upscaling)) spatial = s->scaling; - /* 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); + const int nis_fallback = spatial == 7 && nis_falls_back(scene_w, scene_h, cw, ch); static int last_nis_fallback = 0; const int was_nis_fallback = __atomic_exchange_n(&last_nis_fallback, nis_fallback, __ATOMIC_RELAXED); @@ -723,15 +884,16 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce effect_count(s) - (fuse_toon_color ? 1 : 0) - (fuse_fxaa_toon ? 1 : 0); - if ((spatial || nfx) && objects_ensure() == 0 && scene_ensure(scene, scene_w, scene_h) == 0 && + if ((spatial || nfx) && objects_ensure() == 0 && pipelines_ensure(spatial, s) == 0 && scene_ensure(scene, scene_w, scene_h) == 0 && target_ensure(&g_t[0], cw, ch, FX_TARGET_USAGE, "chain") == 0 && (chain_passes < 2 || target_ensure(&g_t[1], cw, ch, FX_TARGET_USAGE, "chain") == 0) && (!(spatial == 4 || spatial == 5) || s->sharp_pct == 0 || 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", FX_FORMAT, g_smaa_rp) != 0 || + "SMAA edges", SMAA_EDGE_FORMAT, g_smaa_edge_rp) != 0 || target_ensure_format(&g_smaa_weights, cw, ch, FX_SCRATCH_USAGE, - "SMAA weights", FX_FORMAT, g_smaa_rp) != 0)) { + "SMAA weights", FX_FORMAT, g_smaa_weights_rp) != 0 || + smaa_tables_ensure() != 0)) { droiddeck_log("error", "effects: SMAA scratch allocation failed; falling back to FXAA"); snapshot.aa_mode = 1; s = &snapshot; @@ -748,8 +910,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce g_vk.CmdSetScissor(cmd, 0, 1, &chain_sc); if (spatial) { - barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT}; + barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); struct fx_target *dst = FREE_TARGET(); if (spatial == 3 || spatial == 8 || spatial == 7) { @@ -809,8 +973,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce cur = dst; cur_ds = dst->ds; } else if (resize) { struct fx_target *dst = FREE_TARGET(); - barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT}; + barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); barrier(cmd, dst->img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); @@ -823,8 +989,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); cur = dst; cur_ds = dst->ds; } else { - barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT}; + barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); cur = NULL; cur_ds = g_scene.ds; } @@ -853,14 +1021,17 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce 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: - 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)); + 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)); 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}; @@ -907,8 +1078,69 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce return scene; } - barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT}; + barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); return scene; } + +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) { + return effects_run(cmd, scene, scene_w, scene_h, out_w, out_h, res_w, res_h, + 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) { + 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; +} + +VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h, + int *res_w, int *res_h) { + struct fx_settings settings = g_generated_settings; + settings.scaling = 0; + return effects_run(cmd, scene, w, h, w, h, res_w, res_h, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &settings, NULL); +} + +VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, + int out_w, int out_h, int slot, int *res_w, int *res_h) { + if (slot < 0 || slot > VKP_FG_MAX_GENERATIONS) { + *res_w = scene_w; *res_h = scene_h; + return scene; + } + g_context = slot + 1; + 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, 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; +} diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.h b/app/src/main/cpp/waylandcomp/src/effects_chain.h index 0617dd954f..b85becc0a5 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.h +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.h @@ -18,10 +18,17 @@ 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); +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); +VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, + int out_w, int out_h, int slot, int *res_w, int *res_h); 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); diff --git a/app/src/main/cpp/waylandcomp/src/frame_acquire.h b/app/src/main/cpp/waylandcomp/src/frame_acquire.h new file mode 100644 index 0000000000..44ff28333a --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/frame_acquire.h @@ -0,0 +1,39 @@ +#ifndef DD_FRAME_ACQUIRE_H +#define DD_FRAME_ACQUIRE_H +#include +#include +#include +#include +#include + +/* 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 diff --git a/app/src/main/cpp/waylandcomp/src/frame_worker_peer.h b/app/src/main/cpp/waylandcomp/src/frame_worker_peer.h new file mode 100644 index 0000000000..989e59b336 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/frame_worker_peer.h @@ -0,0 +1,81 @@ +#ifndef DD_WORKER_PEER_H +#define DD_WORKER_PEER_H +#include +#include +#include +#include +#include +#include +#include + +/* 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 && + nowexpires && executable_map && dd_worker_map_matches(g,executable_map); +} +#endif diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c index 007b2dcbde..b402dc0a8a 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c @@ -1,7 +1,9 @@ #define _POSIX_C_SOURCE 200809L #include "framegen_bridge.h" #include "framegen_engine.h" +#include "effects_chain.h" #include "vk_loader.h" +#include "sc_layer.h" #include #include #include @@ -35,7 +37,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; +static _Atomic int g_caps_lsfg_ok, g_caps_ddfg_ok, g_caps_zero_ok; static VkPhysicalDeviceMemoryProperties g_memprops; static struct { PFN_vkCreateImage CreateImage; @@ -77,6 +79,24 @@ 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; @@ -86,12 +106,49 @@ 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_LSFG; + if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_DDFG && kind != VKP_FG_ENGINE_ZEROFG) 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) { @@ -117,6 +174,22 @@ 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; @@ -145,15 +218,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_DDFG - ? atomic_load(&g_caps_ddfg_ok) - : atomic_load(&g_caps_lsfg_ok); + 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); 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(); } +const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(atomic_load(&g_kind)); } void vkp_framegen_stats(float out[6]) { float accepted = 0.0f, src = 0.0f, thermal = -1.0f; @@ -186,16 +259,33 @@ 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 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"); + 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; } void vkp_framegen_device_lost(void) { - atomic_store(&g_dev_lost, 1); + 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_ready, 0); fge_device_lost(); if (g_dev) { @@ -226,7 +316,10 @@ static void destroy_ring(void) { if (vk.DeviceWaitIdle) vk.DeviceWaitIdle(g_dev); for (uint32_t i = 0; i < g_ring_n; i++) { if (g_ring[i].view) vk.DestroyImageView(g_dev, g_ring[i].view, NULL); - if (g_ring[i].img) vk.DestroyImage(g_dev, g_ring[i].img, NULL); + if (g_ring[i].img) { + vkp_effects_forget_image(g_ring[i].img); + vk.DestroyImage(g_dev, g_ring[i].img, NULL); + } if (g_ring[i].mem) vk.FreeMemory(g_dev, g_ring[i].mem, NULL); memset(&g_ring[i], 0, sizeof(g_ring[i])); } @@ -279,16 +372,18 @@ 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_DDFG - ? atomic_load(&g_caps_ddfg_ok) - : atomic_load(&g_caps_lsfg_ok); + 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); return ready && !lost && caps_ok && !start_failed_for(kind); } int vkp_framegen_format_ok(VkFormat fmt) { - if (fmt == VK_FORMAT_R8G8B8A8_UNORM) return 1; if (!g_dev_ready || g_dev_lost || format_refused(fmt)) return 0; - return fge_format_ok(fmt); + 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); } static void refuse_format(VkFormat fmt, int kind, int w, int h, const char *what) { @@ -373,11 +468,14 @@ 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); @@ -419,8 +517,31 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, ++g_source_frames; const uint64_t game_frames = droiddeck_game_frames(); - uint32_t n_gen = fge_plan(g_ring_n, game_frames ? game_frames : g_source_frames, g_presented_rate); + 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); 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]; @@ -448,21 +569,26 @@ 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); - fge_process(cmd, scene, (uint32_t)w, (uint32_t)h, n_gen); + 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); 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 = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, + .srcAccessMask = generated_access, .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, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + vk.CmdPipelineBarrier(cmd, generated_stage, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, nb, bars); if (!g_generating_logged) { g_generating_logged = 1; @@ -472,6 +598,8 @@ 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; } diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.h b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h index 573d6fd3c6..4b7e215446 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_bridge.h +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h @@ -6,7 +6,7 @@ #endif #include -enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1 }; +enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1, VKP_FG_ENGINE_ZEROFG = 2 }; #define VKP_FG_MAX_GENERATIONS 3 void vkp_framegen_set_engine(int kind); @@ -26,6 +26,21 @@ 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); diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp b/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp index 014c7c7ec8..6f0b6db6b0 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -13,6 +14,9 @@ #include "lsfg/lsfg_probe.h" #include "lsfg/lsfg_vkd.h" #include "ddfg/ddfg_engine.h" +#include "framegen_zerofg.h" + +#include #define ELOG(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", "framegen: " __VA_ARGS__) #define ELOGE(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", "framegen: " __VA_ARGS__) @@ -22,15 +26,21 @@ 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 g_lsfg; std::unique_ptr g_ddfg; +std::vector> g_retained_ddfg; int g_kind = -1; char g_build[96] = ""; @@ -87,30 +97,57 @@ 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; - if (!g_caps.features.deviceGatesPass()) { + + 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) { 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 = VK_TRUE; + g_v12.vulkanMemoryModel = + g_caps.features.vulkanMemoryModel ? VK_TRUE : VK_FALSE; 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 = VK_TRUE; - g_f2.features.shaderStorageImageExtendedFormats = VK_TRUE; + g_f2.features.shaderStorageImageWriteWithoutFormat = + supported2.features.shaderStorageImageWriteWithoutFormat ? VK_TRUE : VK_FALSE; + g_f2.features.shaderStorageImageExtendedFormats = + supported2.features.shaderStorageImageExtendedFormats ? VK_TRUE : VK_FALSE; return &g_f2; } @@ -121,14 +158,29 @@ 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", g_caps.reason, - (int)g_caps.storageOnSwapchainFormat); + 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"); } void fge_device_lost(void) { g_lsfg.reset(); - g_ddfg.reset(); + if (g_ddfg) { + if (g_ddfg->destroy()) g_ddfg.reset(); + else g_retained_ddfg.push_back(std::move(g_ddfg)); + } + // The device is being torn down. Unknown-completion resources must not be + // passed to Vulkan destruction calls; the VkDevice teardown reclaims them. + for (auto& engine : g_retained_ddfg) engine->abandon(); + g_retained_ddfg.clear(); g_kind = -1; g_dev = VK_NULL_HANDLE; g_queue = VK_NULL_HANDLE; @@ -141,24 +193,45 @@ 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; } -const char *fge_caps_reason(void) { return g_caps.reason; } +int fge_engine_available(int kind) { return fge_caps_ok(kind); } -int fge_format_ok(VkFormat fmt) { +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); 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(); if (!e->init(g_table, g_pd, g_dev, g_qfam, g_queue)) { @@ -193,13 +266,30 @@ int fge_start(int kind, const char *cache_path) { } void fge_stop(void) { - if ((g_lsfg || g_ddfg) && g_table.DeviceWaitIdle && g_dev) g_table.DeviceWaitIdle(g_dev); + if ((g_kind == 0 || g_kind == 2) && g_table.DeviceWaitIdle && g_dev) + g_table.DeviceWaitIdle(g_dev); + g_lsfg.reset(); - g_ddfg.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 { + ELOGE("ddfg-native: retaining engine until GPU completion is known or device teardown"); + 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; } @@ -207,11 +297,13 @@ 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); @@ -219,24 +311,74 @@ 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, uint32_t w, uint32_t h, uint32_t gens) { +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; + } 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(index + 1) / static_cast(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 lock(g_pacer_mutex); + g_pacer.SetMultiplier(multiplier); + g_pacer.ObserveVsync(static_cast(period_ns), static_cast(vsync_ns > 0 ? vsync_ns : 0)); + const uint64_t issue = static_cast(issue_ns); + const zerofg::InlinePacer::Plan plan = + g_pacer.PlanPair(issue, issue + g_readiness.MarginNs(static_cast(period_ns)), max_generated + 1); + for (uint32_t i = 0; i < plan.count; i++) { + present_ns[i] = static_cast(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 lock(g_pacer_mutex); + if (issue_ns > 0 && done_ns > issue_ns) + g_readiness.ObserveCompleted(static_cast(issue_ns), static_cast(done_ns)); +} + +void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns) { + std::lock_guard lock(g_pacer_mutex); + if (planned_ns > 0 && shown_ns > 0) + g_pacer.ObserveRealShown(static_cast(planned_ns), static_cast(shown_ns)); +} + +void fge_pacer_reset(void) { + std::lock_guard 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(); } @@ -246,10 +388,14 @@ 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 == 1 ? "DD-FG Native" : "LSFG Native"; } +const char *fge_engine_name(int kind) { + return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native"; +} const char *fge_build_info(void) { return g_build; } } diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine.h b/app/src/main/cpp/waylandcomp/src/framegen_engine.h index d52ce3ffd4..8295a930f3 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_engine.h +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine.h @@ -16,8 +16,9 @@ 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(void); -int fge_format_ok(VkFormat fmt); +const char *fge_caps_reason(int kind); +int fge_format_ok(int kind, VkFormat fmt); +int fge_engine_available(int kind); int fge_start(int kind, const char *cache_path); void fge_stop(void); @@ -26,10 +27,22 @@ 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, uint32_t w, uint32_t h, uint32_t gens); +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_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); diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c b/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c index 3d11228577..6dcf3a8d5b 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c @@ -10,9 +10,12 @@ 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(void) { return "frame-generation engines not built into this compositor"; } -int fge_format_ok(VkFormat fmt) { (void)fmt; 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; } 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; } @@ -24,16 +27,28 @@ 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, uint32_t w, uint32_t h, uint32_t gens) { - (void)cmd; (void)source; (void)w; (void)h; (void)gens; +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_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 == 1 ? "DD-FG Native" : "LSFG Native"; } +const char *fge_engine_name(int kind) { return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native"; } const char *fge_build_info(void) { return "stub"; } diff --git a/app/src/main/cpp/waylandcomp/src/framegen_jni.c b/app/src/main/cpp/waylandcomp/src/framegen_jni.c index e5a51456ed..e210597b8f 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_jni.c +++ b/app/src/main/cpp/waylandcomp/src/framegen_jni.c @@ -14,6 +14,12 @@ 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; diff --git a/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp new file mode 100644 index 0000000000..b0da6b2af1 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp @@ -0,0 +1,624 @@ +#include "framegen_zerofg.h" +#include "sc_layer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#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 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 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 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 g_intervals{}; +size_t g_interval_count = 0, g_interval_next = 0; + +uint64_t now_ns() { + return static_cast(std::chrono::duration_cast( + 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(1e9 / static_cast(g_refresh_hz)) : 0; +} + +uint64_t typical_interval_ns() { + if (g_interval_count < kMinIntervals) return 0; + std::array 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(typical) / static_cast(period) + kSlotTolerance); + return slots < 2.0 ? 0u : std::min(wanted, static_cast(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(index + 1) / static_cast(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(cadence_gap) : typical_interval_ns(); + const uint32_t group_frames = cadence_frames > static_cast(count) + ? static_cast(cadence_frames) : count + 1; + if (!gap) return even; + const int64_t slots = static_cast((gap + period / 2) / period); + if (slots < static_cast(group_frames)) return even; + const auto step = [&](uint32_t k) { + const int64_t s = static_cast((static_cast(k) * gap / group_frames + period / 2) / period); + return std::max(s, k); + }; + const double phase = static_cast(step(index) - step(count) + slots) / static_cast(slots); + return static_cast(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(index + 1) / static_cast(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(g_pair_interval_ns) + + (static_cast(count) - static_cast(g_prev_count)) * static_cast(period); + if (span <= static_cast(period) * (count + 1)) return even; + const double phase = 1.0 - static_cast(count - index) * static_cast(period) / span; + return static_cast(std::clamp(phase, 0.05, 0.95)); +} + +void load_device_functions() { + if (g_gipa && g_instance) { + g_GetPhysicalDeviceMemoryProperties = + reinterpret_cast( + g_gipa(g_instance, "vkGetPhysicalDeviceMemoryProperties")); + g_GetPhysicalDeviceFormatProperties = + reinterpret_cast( + g_gipa(g_instance, "vkGetPhysicalDeviceFormatProperties")); + } + if (!g_gdpa || !g_device) return; +#define LOAD(name) g_##name = reinterpret_cast(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(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(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(count, static_cast(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({capacity, 3u, g_multiplier - 1})); +} + +void zfg_telemetry(float *generated, float *source_rate) { + const uint64_t typical = typical_interval_ns(); + *generated = static_cast(g_pair_count); + *source_rate = typical ? static_cast(1e9 / static_cast(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" diff --git a/app/src/main/cpp/waylandcomp/src/framegen_zerofg.h b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.h new file mode 100644 index 0000000000..83c9c39e24 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.h @@ -0,0 +1,38 @@ +#ifndef FRAMEGEN_ZEROFG_H +#define FRAMEGEN_ZEROFG_H +#include +#include +#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 diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.c b/app/src/main/cpp/waylandcomp/src/sc_layer.c index 74cd5d6b45..fb93305e4b 100644 --- a/app/src/main/cpp/waylandcomp/src/sc_layer.c +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.c @@ -58,6 +58,7 @@ 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); @@ -102,6 +103,7 @@ 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"); @@ -148,6 +150,7 @@ struct slot { uint32_t fmt; int release_fd; int busy; + uint64_t generation; }; struct layer { @@ -175,6 +178,7 @@ struct layer { int votes_rate; float fps_applied; int recreate_pending; + int pending_callbacks; int32_t ds_applied; @@ -185,6 +189,8 @@ struct layer { static struct layer g_layers[SC_LAYER_COUNT]; static void apply_frame_rate(ASurfaceTransaction *tx, struct layer *l); static void coverage_text(const struct layer *l, char *out, size_t n); +static int overlay_slot(struct layer *l, struct vkp_image *src, int *idx, int *wait_fd); +static int overlay_shown(struct layer *l, int idx, const int geo[8], int translucent); static int g_layers_ready; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static int g_pending_cb; @@ -222,6 +228,7 @@ struct complete_ctx { ASurfaceControl *sc; int layer; int prev_slot; + uint64_t prev_generation; void *prev_token; int retire; }; @@ -260,7 +267,33 @@ 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; @@ -280,6 +313,9 @@ 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); } @@ -288,12 +324,16 @@ static void on_complete(void *context, ASurfaceTransactionStats *stats) { pthread_mutex_lock(&g_lock); if (ctx->layer >= 0 && ctx->layer < SC_LAYER_COUNT && ctx->prev_slot >= 0 && ctx->prev_slot < POOL_MAX) { struct slot *s = &g_layers[ctx->layer].slots[ctx->prev_slot]; - int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1; - if (s->release_fd >= 0) close(s->release_fd); - s->release_fd = fd; - s->busy = 0; + if (s->generation == ctx->prev_generation) { + int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1; + if (s->release_fd >= 0) close(s->release_fd); + s->release_fd = fd; + s->busy = 0; + } } if (g_pending_cb > 0) g_pending_cb--; + if (ctx->layer >= 0 && ctx->layer < SC_LAYER_COUNT && g_layers[ctx->layer].pending_callbacks > 0) + g_layers[ctx->layer].pending_callbacks--; pthread_mutex_unlock(&g_lock); if (ctx->prev_token) { int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1; @@ -308,9 +348,15 @@ static int add_complete_on(ASurfaceTransaction *tx, struct layer *l, ASurfaceCon struct complete_ctx *ctx = calloc(1, sizeof(*ctx)); if (!ctx) return -1; ctx->sc = sc; ctx->layer = (int)(l - g_layers); ctx->prev_slot = prev_slot; + if (prev_slot >= 0 && prev_slot < POOL_MAX) { + pthread_mutex_lock(&g_lock); + ctx->prev_generation = l->slots[prev_slot].generation; + pthread_mutex_unlock(&g_lock); + } ctx->prev_token = prev_token; ctx->retire = retire; pthread_mutex_lock(&g_lock); g_pending_cb++; + l->pending_callbacks++; pthread_mutex_unlock(&g_lock); api.setOnComplete(tx, ctx, on_complete); return 0; @@ -397,12 +443,16 @@ static void retire_sc(struct layer *l) { ASurfaceTransaction *tx = api.txCreate(); if (tx) { retire_ops(tx, l->sc); - if (add_complete(tx, l, l->cur_slot, l->cur_token, 1) != 0) api.release(l->sc); + if (add_complete(tx, l, l->cur_slot, l->cur_token, 1) != 0) { + api.txDelete(tx); + droiddeck_log("layer", "%s: retirement deferred because its release callback could not be allocated", l->name); + return; + } api.txApply(tx); api.txDelete(tx); } else { - if (l->cur_token) ahb_swapchain_layer_released(l->cur_token, -1); - api.release(l->sc); + droiddeck_log("layer", "%s: retirement deferred because a transaction could not be allocated", l->name); + return; } droiddeck_log("layer", "%s: SurfaceControl retired (window %p)", l->name, (void *)l->win); l->sc = NULL; l->win = NULL; @@ -421,20 +471,28 @@ static void drain_and_free_pools(void) { if (!pending || now_ns() > deadline) break; usleep(2000); } - pthread_mutex_lock(&g_lock); for (int i = 0; i < SC_LAYER_COUNT; i++) { + struct layer *l = &g_layers[i]; + pthread_mutex_lock(&g_lock); + const int pending = l->pending_callbacks; + if (pending || l->sc) { + pthread_mutex_unlock(&g_lock); + droiddeck_log("layer", "pool drain deferred for %s (%s)", l->name, + pending ? "SurfaceControl callbacks are pending" : "SurfaceControl retirement is deferred"); + continue; + } for (int j = 0; j < POOL_MAX; j++) { - struct slot *s = &g_layers[i].slots[j]; + struct slot *s = &l->slots[j]; if (s->release_fd >= 0) { struct pollfd p = {.fd = s->release_fd, .events = POLLIN}; poll(&p, 1, 100); close(s->release_fd); } if (s->img) vkp_image_destroy(s->img); if (s->ahb) AHardwareBuffer_release(s->ahb); memset(s, 0, sizeof(*s)); s->release_fd = -1; } - g_layers[i].first_logged = 0; - g_layers[i].logged_w = g_layers[i].logged_h = 0; + l->first_logged = 0; + l->logged_w = l->logged_h = 0; + pthread_mutex_unlock(&g_lock); } - pthread_mutex_unlock(&g_lock); } static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) { @@ -612,7 +670,10 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait if (pending < 0) pending = i; } if (idx < 0) idx = pending; - if (idx >= 0) { fd = l->slots[idx].release_fd; l->slots[idx].release_fd = -1; } + if (idx >= 0) { + fd = l->slots[idx].release_fd; l->slots[idx].release_fd = -1; + l->slots[idx].generation++; + } pthread_mutex_unlock(&g_lock); if (idx < 0) return -1; if (fd >= 0 && fence_signalled(fd)) { close(fd); fd = -1; } @@ -620,7 +681,8 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait if (s->ahb && (s->w != w || s->h != h || s->fmt != fmt)) { if (fd >= 0) { close(fd); fd = -1; } vkp_image_destroy(s->img); AHardwareBuffer_release(s->ahb); - memset(s, 0, sizeof(*s)); s->release_fd = -1; + const uint64_t generation = s->generation; + memset(s, 0, sizeof(*s)); s->release_fd = -1; s->generation = generation; } if (fd >= 0 && !vkp_can_wait_sync_fd()) { if (fence_wait(fd, 100) == 0) { slot_keep_fence(s, fd); return -1; } @@ -659,7 +721,13 @@ static int ensure_sc(struct layer *l) { if (load_api() != 0) return -1; ANativeWindow *win = vkp_window(); if (!win) return -1; - if (l->sc && l->win != win) retire_sc(l); + if (l->sc && l->win != win) { + retire_sc(l); + if (l->sc) { + droiddeck_log("layer", "%s: keeping the old SurfaceControl until retirement completes", l->name); + return -1; + } + } if (!l->sc) { l->sc = api.createFromWindow(win, l->name); if (!l->sc) { droiddeck_log("error", "layer: ASurfaceControl_createFromWindow(%s) failed", l->name); return -1; } @@ -686,9 +754,15 @@ static int layer_geometry(int w, int h, int scene_w, int scene_h, const struct v static ARect g_game_src, g_game_dst; static int g_game_geo_known; +static void note_game_geometry(const int r[8]) { + g_game_src = (ARect){r[0], r[1], r[2], r[3]}; + g_game_dst = (ARect){r[4], r[5], r[6], r[7]}; + g_game_geo_known = 1; +} + static void apply_geometry(ASurfaceTransaction *tx, struct layer *l, const int r[8]) { ARect srcR = {r[0], r[1], r[2], r[3]}, dstR = {r[4], r[5], r[6], r[7]}; - if (l == &g_layers[SC_LAYER_GAME]) { g_game_src = srcR; g_game_dst = dstR; g_game_geo_known = 1; } + if (l == &g_layers[SC_LAYER_GAME]) note_game_geometry(r); if (!l->geo_valid || memcmp(&srcR, &l->geo_src, sizeof(srcR)) || memcmp(&dstR, &l->geo_dst, sizeof(dstR))) { api.setGeometry(tx, l->sc, &srcR, &dstR, 0 ); l->geo_src = srcR; l->geo_dst = dstR; l->geo_valid = 1; @@ -818,6 +892,7 @@ static ASurfaceControl *swap_sc_begin(struct layer *l) { if (!win || win != l->win) return NULL; ASurfaceControl *fresh = api.createFromWindow(win, l->name); if (!fresh) { + l->recreate_pending = 1; droiddeck_log("error", "layer: %s: composition recovery could not create a new SurfaceControl", l->name); return NULL; } @@ -832,24 +907,47 @@ static ASurfaceControl *swap_sc_begin(struct layer *l) { return old; } +static void rollback_swap_sc(struct layer *l, ASurfaceControl *old, int was_shown, + int32_t ds_applied, uint32_t md_applied, float hr_applied) { + if (!old) return; + ASurfaceControl *fresh = l->sc; + l->sc = old; + l->shown = was_shown; + l->recreate_pending = 1; + l->geo_valid = 0; + l->fps_applied = -1.0f; + l->ds_applied = ds_applied; l->md_applied = md_applied; l->hr_applied = hr_applied; + if (fresh) api.release(fresh); +} + static int present_slot(struct layer *l, int idx, const int r[8], const struct droiddeck_color *color, 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; + const float hr_applied = l->hr_applied; ASurfaceControl *old = swap_sc_begin(l); if (old) api.setZOrder(tx, l->sc, l->z); api.setBuffer(tx, l->sc, s->ahb, -1); if (api.setEnableBackPressure) api.setEnableBackPressure(tx, l->sc, true); api.setBufferTransparency(tx, l->sc, translucent ? ASC_TRANSPARENCY_TRANSLUCENT : ASC_TRANSPARENCY_OPAQUE); + if (!l->shown) api.setVisibility(tx, l->sc, ASC_VISIBILITY_SHOW); + if (old) retire_ops(tx, old); + if (add_complete_on(tx, l, old ? old : l->sc, l->cur_slot, l->cur_token, old ? 1 : 0) != 0) { + api.txDelete(tx); + rollback_swap_sc(l, old, was_shown, ds_applied, md_applied, hr_applied); + droiddeck_log("layer", "%s: frame transition skipped because its release callback could not be allocated", l->name); + return -1; + } apply_geometry(tx, l, r); apply_frame_rate(tx, l); apply_colour(tx, l, color); - if (!l->shown) api.setVisibility(tx, l->sc, ASC_VISIBILITY_SHOW); - if (old) retire_ops(tx, old); - if (add_complete_on(tx, l, old ? old : l->sc, l->cur_slot, l->cur_token, old ? 1 : 0) != 0 && old) - api.release(old); pthread_mutex_lock(&g_lock); s->busy = 1; pthread_mutex_unlock(&g_lock); @@ -904,23 +1002,27 @@ int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, voi } ASurfaceTransaction *tx = api.txCreate(); if (!tx) goto unavailable; + const int was_shown = l->shown; + const int32_t ds_applied = l->ds_applied; + const uint32_t md_applied = l->md_applied; + const float hr_applied = l->hr_applied; ASurfaceControl *old = swap_sc_begin(l); if (old) api.setZOrder(tx, l->sc, l->z); api.setBuffer(tx, l->sc, ahb, acquire_fd); if (api.setEnableBackPressure) api.setEnableBackPressure(tx, l->sc, true); api.setBufferTransparency(tx, l->sc, ASC_TRANSPARENCY_OPAQUE); - apply_geometry(tx, l, r); - apply_frame_rate(tx, l); - apply_colour(tx, l, color); if (!l->shown) api.setVisibility(tx, l->sc, ASC_VISIBILITY_SHOW); if (old) retire_ops(tx, old); if (add_complete_on(tx, l, old ? old : l->sc, l->cur_slot, l->cur_token == token ? NULL : l->cur_token, old ? 1 : 0) != 0) { api.txDelete(tx); - if (old) api.release(old); - l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; + rollback_swap_sc(l, old, was_shown, ds_applied, md_applied, hr_applied); + droiddeck_log("layer", "zero-copy: frame transition skipped because its release callback could not be allocated"); return -1; } + apply_geometry(tx, l, r); + apply_frame_rate(tx, l); + apply_colour(tx, l, color); apply_present_time(tx, 1); api.txApply(tx); api.txDelete(tx); @@ -937,19 +1039,40 @@ unavailable: } int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw, - const struct droiddeck_color *color) { + const struct droiddeck_color *color, const struct vkp_draw *over, int *over_shown) { struct layer *l = layer_of(SC_LAYER_GAME); + *over_shown = 0; if (!src || ensure_sc(l) != 0) return -1; int sw = vkp_image_width(src), sh = vkp_image_height(src); int r[8]; int g = layer_geometry(sw, sh, scene_w, scene_h, draw, r); if (g < 0) return -1; - if (g == 0) { sc_layer_hide(); return 0; } + int og[8]; + if (over && !vkp_map_draw(over, og)) over = NULL; + if (g == 0) { + sc_layer_hide(); + if (over) *over_shown = sc_layer_present_overlay(over->img, og, over->blend) == 0 ? 1 : -1; + return 0; + } - int wait_fd; - int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd); - if (idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; } - if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1; + struct vkp_blit blits[2] = {{.src = src, .wait_fd = -1}, {.src = over ? over->img : NULL, .wait_fd = -1}}; + int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &blits[0].wait_fd); + if (idx < 0) { + log_drop(l); + if (g_alloc_failed) return -1; + if (over) *over_shown = sc_layer_present_overlay(over->img, og, over->blend) == 0 ? 1 : -1; + return 0; + } + blits[0].dst = l->slots[idx].img; + struct layer *ol = layer_of(SC_LAYER_OVERLAY); + int over_idx = -1; + if (over) { + note_game_geometry(r); + const int taken = overlay_slot(ol, over->img, &over_idx, &blits[1].wait_fd); + *over_shown = taken < 0 ? -1 : 1; + if (taken > 0) blits[1].dst = ol->slots[over_idx].img; + } + if (vkp_blit_images(blits, over_idx >= 0 ? 2 : 1) != 0) return -1; if (present_slot(l, idx, r, color, 0) != 0) return -1; if (color && color->dataspace) droiddeck_color_frame_shown(color, DROIDDECK_HDR_LAYER_COPY, AHB_RGBA8); if (!l->first_logged) { @@ -959,6 +1082,7 @@ int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const stru pool_kind(l->pool_modifier), l->pool_n); } vkp_signal_first_frame(); + if (over_idx >= 0 && overlay_shown(ol, over_idx, og, over->blend) != 0) *over_shown = -1; return 0; } @@ -1014,6 +1138,7 @@ 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; @@ -1023,7 +1148,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(); log_drop(l); return g_alloc_failed ? -1 : 0; } + if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); vkp_framegen_pacer_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); @@ -1045,13 +1170,18 @@ 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; @@ -1060,7 +1190,11 @@ 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; @@ -1148,17 +1282,19 @@ int sc_layer_overlay_affordable(void) { return ok; } -int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent) { - struct layer *l = layer_of(SC_LAYER_OVERLAY); - if (!src || !geo) return -1; +static int overlay_slot(struct layer *l, struct vkp_image *src, int *idx, int *wait_fd) { + *wait_fd = -1; + if (!src) return -1; if (!sc_layer_overlay_affordable()) return -1; if (ensure_sc(l) != 0) return -1; int sw = vkp_image_width(src), sh = vkp_image_height(src); if (sw <= 0 || sh <= 0) return -1; - int wait_fd; - int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd); - if (idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; } - if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1; + *idx = take_free_slot(l, sw, sh, AHB_RGBA8, wait_fd); + if (*idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; } + return 1; +} + +static int overlay_shown(struct layer *l, int idx, const int geo[8], int translucent) { if (present_slot(l, idx, geo, NULL, translucent) != 0) return -1; if (!l->first_logged) { l->first_logged = 1; @@ -1167,15 +1303,38 @@ int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int transl return 0; } -static void hide_layer(struct layer *l) { - if (!l->sc || !l->shown || api.state != 1) return; +int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent) { + struct layer *l = layer_of(SC_LAYER_OVERLAY); + if (!geo) return -1; + int idx; + struct vkp_blit blit = {.src = src, .wait_fd = -1}; + const int taken = overlay_slot(l, src, &idx, &blit.wait_fd); + if (taken <= 0) return taken; + blit.dst = l->slots[idx].img; + if (vkp_blit_images(&blit, 1) != 0) return -1; + return overlay_shown(l, idx, geo, translucent); +} + +static int hide_layer(struct layer *l) { + if (!l->sc || !l->shown || api.state != 1) return 0; ASurfaceTransaction *tx = api.txCreate(); - if (!tx) return; - replace_with_blank(tx, l); + if (!tx) return -1; api.setVisibility(tx, l->sc, ASC_VISIBILITY_HIDE); - add_complete(tx, l, l->cur_slot, l->cur_token, 0); + if (add_complete(tx, l, l->cur_slot, l->cur_token, 0) != 0) { + /* + * Keep the current buffer attached when its release callback cannot + * be allocated. The hide can still apply without releasing the slot. + */ + api.txApply(tx); + api.txDelete(tx); + l->shown = 0; + droiddeck_log("layer", "%s: hidden; buffer release deferred because its callback could not be allocated", l->name); + return 0; + } + replace_with_blank(tx, l); api.txApply(tx); api.txDelete(tx); l->shown = 0; l->cur_slot = -1; l->cur_token = NULL; + return 0; } void sc_layer_hide(void) { @@ -1183,17 +1342,20 @@ void sc_layer_hide(void) { int said = g_layers[SC_LAYER_GAME].shown || g_layers[SC_LAYER_OVERLAY].sc; if (g_layers[SC_LAYER_OVERLAY].sc) sc_layer_hide_overlay(); if (g_layers[SC_LAYER_GAME].shown) hide_layer(&g_layers[SC_LAYER_GAME]); - if (said) droiddeck_log("layer", "layers hidden (scene is not a single fullscreen window)"); + if (said && !g_layers[SC_LAYER_GAME].shown && !g_layers[SC_LAYER_OVERLAY].shown) + droiddeck_log("layer", "layers hidden (scene is not a single fullscreen window)"); } void sc_layer_hide_overlay(void) { layers_init(); struct layer *l = &g_layers[SC_LAYER_OVERLAY]; if (!l->sc) return; - if (l->shown) hide_layer(l); + if (l->shown && hide_layer(l) != 0) return; retire_sc(l); - droiddeck_log("layer", "%s: gone (nothing is above the game any more)", l->name); - if (g_layers[SC_LAYER_GAME].sc) g_layers[SC_LAYER_GAME].recreate_pending = 1; + if (!l->sc) { + droiddeck_log("layer", "%s: gone (nothing is above the game any more)", l->name); + if (g_layers[SC_LAYER_GAME].sc) g_layers[SC_LAYER_GAME].recreate_pending = 1; + } } void sc_layer_window_gone(void) { diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.h b/app/src/main/cpp/waylandcomp/src/sc_layer.h index 24a24fc25e..a7977378fa 100644 --- a/app/src/main/cpp/waylandcomp/src/sc_layer.h +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct vkp_image; struct vkp_draw; struct droiddeck_color; @@ -22,7 +26,7 @@ void sc_layer_hdr_symbols(char *out, size_t size); int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw, - const struct droiddeck_color *color); + const struct droiddeck_color *color, const struct vkp_draw *over, int *over_shown); int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int scene_h); int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const struct vkp_hdr_frame *hf, @@ -51,7 +55,16 @@ 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 diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index 9ca0e1d7c3..8801c87286 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -7,6 +7,7 @@ #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" @@ -20,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -161,7 +164,9 @@ static uint32_t g_qfam; static VkCommandPool g_pool; #define MAX_PRESENTS (1 + VKP_FG_MAX_GENERATIONS) static VkCommandBuffer g_cmds[MAX_PRESENTS]; -static VkSemaphore g_acqs[MAX_PRESENTS], g_rnds[MAX_PRESENTS]; +static VkSemaphore g_acqs[MAX_PRESENTS]; +static VkSemaphore *g_rnds; +static uint32_t g_rnd_count; static VkFence g_fence; static int g_swap_extra; #define SCENE_FMT VK_FORMAT_R8G8B8A8_UNORM @@ -230,6 +235,16 @@ static VkResult timed_wait(VkFence fence, uint64_t timeout) { return g_dev_state == -2 ? VK_ERROR_DEVICE_LOST : VK_ERROR_UNKNOWN; int64_t t0 = perf_now(); VkResult r = g_vk.WaitForFences(g_dev, 1, &fence, VK_TRUE, timeout); + if (r == VK_TIMEOUT) { + droiddeck_log("gpu", "GPU fence delayed: retaining frame resources until completion"); + /* A scheduling delay does not invalidate the device. Keep this submission's + * resources and call stack alive, as the main render path already does. */ + do { + r = g_vk.WaitForFences(g_dev, 1, &fence, VK_TRUE, UINT64_MAX); + } while (r == VK_TIMEOUT); + if (r == VK_SUCCESS) + droiddeck_log("gpu", "GPU fence completed: continuing presentation"); + } perf_add(&g_perf.wait_ns, &g_perf.wait_max_ns, &g_perf.waits, perf_now() - t0); if (r != VK_SUCCESS && r != VK_ERROR_DEVICE_LOST) quarantine_pending_work(r, "fence wait"); @@ -323,12 +338,44 @@ static void reset_sync(void) { VkSemaphoreCreateInfo semci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; for (int k = 0; k < MAX_PRESENTS; k++) { if (g_acqs[k]) g_vk.DestroySemaphore(g_dev, g_acqs[k], NULL); - if (g_rnds[k]) g_vk.DestroySemaphore(g_dev, g_rnds[k], NULL); - g_vk.CreateSemaphore(g_dev, &semci, NULL, &g_acqs[k]); - g_vk.CreateSemaphore(g_dev, &semci, NULL, &g_rnds[k]); + g_acqs[k] = VK_NULL_HANDLE; + if (g_vk.CreateSemaphore(g_dev, &semci, NULL, &g_acqs[k]) != VK_SUCCESS) + droiddeck_log("error", "present: failed to recreate acquire semaphore %d", k); } } +static void destroy_present_semaphores(void) { + if (g_dev && g_vk.DestroySemaphore) { + for (uint32_t i = 0; i < g_rnd_count; i++) + if (g_rnds[i]) g_vk.DestroySemaphore(g_dev, g_rnds[i], NULL); + } + free(g_rnds); + g_rnds = NULL; + g_rnd_count = 0; +} + +static int create_present_semaphores(void) { + if (!g_nimg) return -1; + VkSemaphore *sems = calloc(g_nimg, sizeof(*sems)); + if (!sems) return -1; + VkSemaphoreCreateInfo semci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; + for (uint32_t i = 0; i < g_nimg; i++) { + VkResult r = g_vk.CreateSemaphore(g_dev, &semci, NULL, &sems[i]); + if (r != VK_SUCCESS) { + droiddeck_log("error", "present: failed to create image semaphore %u (%s)", + i, vk_result_name(r)); + for (uint32_t j = 0; j < i; j++) + if (sems[j]) g_vk.DestroySemaphore(g_dev, sems[j], NULL); + free(sems); + return -1; + } + } + destroy_present_semaphores(); + g_rnds = sems; + g_rnd_count = g_nimg; + return 0; +} + static void destroy_swapchain(void) { g_base_black = 0; if (g_dev_state != 1) return; @@ -338,10 +385,11 @@ static void destroy_swapchain(void) { else quarantine_pending_work(idle, "swapchain idle"); return; } - reset_sync(); for (uint32_t i = 0; i < g_nimg; i++) blendp_forget_image(g_images[i]); if (g_swapchain) g_vk.DestroySwapchainKHR(g_dev, g_swapchain, NULL); g_swapchain = VK_NULL_HANDLE; + destroy_present_semaphores(); + reset_sync(); g_swap_md_identity = 0; if (g_surface) g_vk.DestroySurfaceKHR(g_inst, g_surface, NULL); g_surface = VK_NULL_HANDLE; @@ -557,6 +605,10 @@ 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; } @@ -1365,12 +1417,35 @@ static int swap_init_locked(void) { SWLOGE("present: vkCreateSwapchainKHR failed (%d)", (int)cr); return -1; } - g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, NULL); + cr = g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, NULL); + if (cr != VK_SUCCESS || !g_nimg) { + SWLOGE("present: vkGetSwapchainImagesKHR count failed (%s)", vk_result_name(cr)); + g_nimg = 0; + return -1; + } g_images = calloc(g_nimg, sizeof(VkImage)); - g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, g_images); + if (!g_images) { + SWLOGE("present: failed to allocate swapchain image list"); + g_nimg = 0; + return -1; + } + cr = g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, g_images); + if (cr != VK_SUCCESS) { + SWLOGE("present: vkGetSwapchainImagesKHR failed (%s)", vk_result_name(cr)); + free(g_images); + g_images = NULL; + g_nimg = 0; + return -1; + } + if (create_present_semaphores() != 0) { + SWLOGE("present: failed to initialize per-image present semaphores"); + return -1; + } droiddeck_log("gpu", "screen output %ux%u, %u buffers, vsync%s", g_extent.width, g_extent.height, g_nimg, g_swap_extra ? " (frame generation: several presents per frame)" : ""); + droiddeck_log("gpu", "present synchronization: %u render-finished semaphores, one per swapchain image", + g_rnd_count); return 0; } @@ -2691,6 +2766,21 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i pass_n = 1; overlay_start = source_end; } + 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); + 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 || + upscale_w != last_output_w || upscale_h != last_output_h) { + droiddeck_log("framegen", "post-upscale: interpolate %dx%d, spatial filter each present to %dx%d", + input_w, input_h, upscale_w, upscale_h); + last_input_w = input_w; last_input_h = input_h; + last_output_w = upscale_w; last_output_h = upscale_h; + } + } const int deep = hf && n > 0 && fg && g_swap_is_hdr && !hf->tonemap && vkp_framegen_format_ok(FG_HDR_FMT) && ensure_img(&g_fgscene, scene_w, scene_h, FG_HDR_FMT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -2810,6 +2900,7 @@ 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; @@ -2826,8 +2917,11 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i if (fx) { int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); if (fg && !vkp_effects_sharpening()) { mapped_w = scene_w; mapped_h = scene_h; } + if (post_upscale) { mapped_w = input_w; mapped_h = input_h; } vkp_effects_set_formats(scene_fmt, scene_fmt, hdr_how == 1 || hdr_unconverted); - result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh); + result = post_upscale + ? vkp_effects_run_before_generated(cmd, scene_img, input_w, input_h, &rw, &rh) + : vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh); effects_overlay_draws(cmd, result, rw, rh, scene_w, scene_h, draws ? draws + overlay_start : NULL, n - overlay_start); release_external_client_draws(cmd, draws, n); @@ -2845,12 +2939,19 @@ 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; } - record_screen_blit(cmd, ngen ? gens[0] : result, rw, rh, scene_w, scene_h, img, blit_filter, cb); + VkImage screen = ngen ? gens[0] : result; + int screen_w = rw, screen_h = rh; + if (post_upscale) + screen = vkp_effects_run_generated(cmd, screen, rw, rh, upscale_w, upscale_h, + 0, &screen_w, &screen_h); + record_screen_blit(cmd, screen, screen_w, screen_h, scene_w, scene_h, img, blit_filter, cb); } g_vk.EndCommandBuffer(cmd); @@ -2865,7 +2966,10 @@ 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) return -1; + if (g_dev_state != 1) { + if (history_staged) zfg_discard_history_update(); + 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; @@ -2874,44 +2978,80 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i VkCommandBuffer ck = g_cmds[k]; g_vk.ResetCommandBuffer(ck, 0); g_vk.BeginCommandBuffer(ck, &bi); - record_screen_blit(ck, k < ngen ? gens[k] : result, rw, rh, scene_w, scene_h, img, blit_filter, cb); + VkImage screen = k < ngen ? gens[k] : result; + int screen_w = rw, screen_h = rh; + if (post_upscale) + screen = vkp_effects_run_generated(ck, screen, rw, rh, upscale_w, upscale_h, + k, &screen_w, &screen_h); + record_screen_blit(ck, screen, screen_w, screen_h, scene_w, scene_h, img, blit_filter, cb); g_vk.EndCommandBuffer(ck); } const int last = (k + 1 == presents); VkPipelineStageFlags wait = VK_PIPELINE_STAGE_TRANSFER_BIT; + /* A present-wait semaphore is reused only after this exact swapchain image + * has been acquired again; a frame-slot fence cannot prove present completion. */ + 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; + } VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .waitSemaphoreCount = 1, .pWaitSemaphores = &g_acqs[k], .pWaitDstStageMask = &wait, .commandBufferCount = 1, - .pCommandBuffers = &g_cmds[k], .signalSemaphoreCount = 1, .pSignalSemaphores = &g_rnds[k]}; + .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[k], .swapchainCount = 1, + .pWaitSemaphores = &g_rnds[img], .swapchainCount = 1, .pSwapchains = &g_swapchain, .pImageIndices = &img}; const int64_t t_pres = perf_now(); 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) { device_lost("present"); return -1; } + if (pr == VK_ERROR_DEVICE_LOST) { + if (history_staged) zfg_discard_history_update(); + 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) { device_lost("present"); return -1; } - if (fr != VK_SUCCESS) return -1; + 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; + } + 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) { droiddeck_log("gpu", "screen surface %s on present: rebuilding the swapchain", vk_result_name(pr)); @@ -3057,8 +3197,38 @@ static void blit_to_layer(VkCommandBuffer cmd, VkImage src, VkImageLayout src_la 0, 0, NULL, 0, NULL, 1, &release); } -int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { - if (!src || src->blit_dst || !dst || !dst->blit_dst || dev_init() != 0) { +static int merge_wait_fds(int a, int b) { + if (a < 0) return b; + if (b < 0) return a; + struct sync_merge_data m = {.name = "droiddeck-layer-copy", .fd2 = b}; + if (ioctl(a, SYNC_IOC_MERGE, &m) == 0) { + close(a); + close(b); + return m.fence; + } + struct pollfd p = {.fd = b, .events = POLLIN}; + int r; + do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); + close(b); + if (r != 0) return a; + p.fd = a; + do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); + close(a); + return -2; +} + +int vkp_blit_images(const struct vkp_blit *blits, int n) { + int wait_fd = -1; + for (int i = 0; i < n; i++) { + if (wait_fd == -2) { if (blits[i].wait_fd >= 0) close(blits[i].wait_fd); continue; } + wait_fd = merge_wait_fds(wait_fd, blits[i].wait_fd); + } + int valid = n > 0 && wait_fd != -2; + for (int i = 0; valid && i < n; i++) { + const struct vkp_image *src = blits[i].src, *dst = blits[i].dst; + if (!src || src->blit_dst || !dst || !dst->blit_dst) valid = 0; + } + if (!valid || dev_init() != 0) { if (wait_fd >= 0) close(wait_fd); return -1; } @@ -3071,32 +3241,35 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; g_vk.BeginCommandBuffer(g_cmd, &bi); - stage_linear_dmabuf(g_cmd, src); - struct vkp_external_client_barrier_pair src_pair; - const int src_external = vkp_external_client_barrier_pair( - src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair); - VkImageMemoryBarrier acq = src_external ? src_pair.acquire : (VkImageMemoryBarrier){ - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, - .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; - if (!src_external) { - acq.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED; - acq.newLayout = VK_IMAGE_LAYOUT_GENERAL; - acq.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; - src->in_general = 1; + for (int i = 0; i < n; i++) { + struct vkp_image *src = blits[i].src, *dst = blits[i].dst; + stage_linear_dmabuf(g_cmd, src); + struct vkp_external_client_barrier_pair src_pair; + const int src_external = vkp_external_client_barrier_pair( + src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair); + VkImageMemoryBarrier acq = src_external ? src_pair.acquire : (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + if (!src_external) { + acq.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED; + acq.newLayout = VK_IMAGE_LAYOUT_GENERAL; + acq.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + src->in_general = 1; + } + g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &acq); + int bw = src->w < dst->w ? src->w : dst->w, bh = src->h < dst->h ? src->h : dst->h; + VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{0, 0, 0}, {bw, bh, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{0, 0, 0}, {bw, bh, 1}}}; + blit_to_layer(g_cmd, src->image, src_external ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + dst, &blit, VK_FILTER_NEAREST); + release_external_client_image(g_cmd, src); } - g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &acq); - int bw = src->w < dst->w ? src->w : dst->w, bh = src->h < dst->h ? src->h : dst->h; - VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, - .srcOffsets = {{0, 0, 0}, {bw, bh, 1}}, - .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, - .dstOffsets = {{0, 0, 0}, {bw, bh, 1}}}; - blit_to_layer(g_cmd, src->image, src_external ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, - dst, &blit, VK_FILTER_NEAREST); - release_external_client_image(g_cmd, src); g_vk.EndCommandBuffer(g_cmd); VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; @@ -3229,6 +3402,9 @@ 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; @@ -3368,10 +3544,30 @@ 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; - g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, - &g_pass.rw, &g_pass.rh); + 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; + } 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); @@ -3386,38 +3582,45 @@ 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.rw; - if (rh) *rh = g_pass.rh; + if (rw) *rw = g_pass.ow; + if (rh) *rh = g_pass.oh; 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) { if (wait_fd >= 0) close(wait_fd); return -1; } + if (!g_pass.active) { zfg_discard_history_update(); if (wait_fd >= 0) close(wait_fd); return -1; } g_pass.active = 0; - if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; } + if (g_dev_state != 1) { zfg_discard_history_update(); 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) { g_vk.EndCommandBuffer(cmd); return -1; } + 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; 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}, {g_pass.rw, g_pass.rh, 1}}, + .srcOffsets = {{0, 0, 0}, {sw, sh, 1}}, .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}}; - 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); + blit_to_layer(cmd, src, src_layout, dst, &blit, + (sw == dst->w && sh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR); } g_vk.EndCommandBuffer(cmd); @@ -3428,13 +3631,17 @@ 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; } @@ -3452,6 +3659,7 @@ 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) diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h index bc35ac8b49..f7bfaf781f 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.h +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -105,7 +105,11 @@ int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int *rw, int *rh); -int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd); +struct vkp_blit { + struct vkp_image *src, *dst; + int wait_fd; +}; +int vkp_blit_images(const struct vkp_blit *blits, int n); int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px); int vkp_update_map(int scene_w, int scene_h); int vkp_map_draw(const struct vkp_draw *d, int out[8]); diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index d070b8fd6f..f22865c110 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -68,6 +68,7 @@ static jmethodID g_on_compositor_frame; static jmethodID g_on_game_program; static jmethodID g_on_pointer_lock; static jmethodID g_on_clipboard; +static jmethodID g_on_text_input_fallback; static jmethodID g_on_text_input; static jmethodID g_on_overlay_planes; static jmethodID g_on_refresh_target; @@ -92,6 +93,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); g_on_game_program = NULL; } g_on_pointer_lock = (*env)->GetStaticMethodID(env, g_compositor_cls, "onPointerLock", "(ZII)V"); g_on_clipboard = (*env)->GetStaticMethodID(env, g_compositor_cls, "onClipboardText", "([B)V"); + g_on_text_input_fallback = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInputFallback", + "([BI)Z"); g_on_text_input = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInput", "(ZLjava/lang/String;IIII)V"); g_on_overlay_planes = (*env)->GetStaticMethodID(env, g_compositor_cls, "onOverlayPlanes", "(I)V"); @@ -203,6 +206,20 @@ void droiddeck_on_clipboard_text(const char *utf8, int len) { (*env)->DeleteLocalRef(env, arr); } +int droiddeck_on_text_input_fallback(const char *utf8, int len, int token) { + JNIEnv *env; + if (len <= 0 || token <= 0 || !utf8 || !g_compositor_cls || !g_on_text_input_fallback || !(env = thread_env())) + return 0; + jbyteArray arr = (*env)->NewByteArray(env, len); + if (!arr) { (*env)->ExceptionClear(env); return 0; } + (*env)->SetByteArrayRegion(env, arr, 0, len, (const jbyte *)utf8); + jboolean accepted = (*env)->CallStaticBooleanMethod(env, g_compositor_cls, g_on_text_input_fallback, arr, + (jint)token); + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); accepted = JNI_FALSE; } + (*env)->DeleteLocalRef(env, arr); + return accepted == JNI_TRUE ? 1 : 0; +} + void droiddeck_on_text_input(int enabled, const char *program, int x, int y, int w, int h) { JNIEnv *env; if (!g_compositor_cls || !g_on_text_input || !(env = thread_env())) return; @@ -376,6 +393,18 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendKey( droiddeck_wayland_send_key(evdev, state); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendKeyOrdered( + JNIEnv *env, jclass clazz, jint evdev, jint state) { + droiddeck_host_key(evdev, state); +} + +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSelectGameField( + JNIEnv *env, jclass clazz, jboolean copy) { + droiddeck_host_select_game_field(copy); +} + JNIEXPORT jboolean JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeFocusTakesTouch( JNIEnv *env, jclass clazz) { @@ -432,6 +461,11 @@ 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; @@ -807,6 +841,15 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputCommit(JNIE free(buf); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputCommitAndSubmit( + JNIEnv *env, jclass clazz, jbyteArray utf8) { + int len; + char *buf = dup_bytes(env, utf8, &len); + if (buf && len) droiddeck_host_text_commit_and_submit(buf, len); + free(buf); +} + JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputPreedit(JNIEnv *env, jclass clazz, jbyteArray utf8, jint cursorBegin, jint cursorEnd) { @@ -821,6 +864,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputDelete(JNIE droiddeck_host_text_delete(before, after); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCompleteTextInputFallback( + JNIEnv *env, jclass clazz, jint token, jint result) { + droiddeck_host_text_input_fallback_complete(token, result); +} + extern void adrenotools_set_turbo(bool turbo); JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetGpuTurbo(JNIEnv *env, jclass clazz, jboolean on) { @@ -872,3 +921,42 @@ 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 +} diff --git a/app/src/main/cpp/waylandcomp/src/wl_text_input.c b/app/src/main/cpp/waylandcomp/src/wl_text_input.c index 8b0ade227d..aaeff2de99 100644 --- a/app/src/main/cpp/waylandcomp/src/wl_text_input.c +++ b/app/src/main/cpp/waylandcomp/src/wl_text_input.c @@ -10,6 +10,12 @@ #ifndef KEY_DELETE #define KEY_DELETE 111 #endif +#ifndef KEY_ENTER +#define KEY_ENTER 28 +#endif +#ifndef KEY_TAB +#define KEY_TAB 15 +#endif static struct wl_display *g_disp; @@ -203,16 +209,43 @@ static int32_t utf8_offset(const char *s, size_t len, int chars) { return (int32_t)i; } -void text_input_host_commit(const char *utf8, size_t len) { +static int control_evdev(unsigned char c) { + switch (c) { + case '\r': case '\n': return KEY_ENTER; + case '\b': return KEY_BACKSPACE; + case 0x7f: return KEY_DELETE; + case '\t': return KEY_TAB; + default: return -1; + } +} + +static int all_controls(const char *utf8, size_t len) { + for (size_t i = 0; i < len; i++) + if (control_evdev((unsigned char)utf8[i]) < 0) return 0; + return 1; +} + +int text_input_host_commit(const char *utf8, size_t len) { struct text_input *ti = active_input(); if (!ti) { - droiddeck_log("text-input", "typed text (%zu chars) dropped: no program accepts text input", utf8_chars(utf8, len)); - return; + droiddeck_log("text-input", "typed text (%zu chars): no program accepts Wayland text input", utf8_chars(utf8, len)); + return 0; + } + if (len > 0 && all_controls(utf8, len)) { + /* Keep editing keys on the compositor queue so they cannot overtake text commits. */ + for (size_t i = 0; i < len; i++) { + int code = control_evdev((unsigned char)utf8[i]); + droiddeck_inject_key(code, 1); + droiddeck_inject_key(code, 0); + } + droiddeck_log("text-input", "injected %zu soft control(s) to %s", len, ti_program(ti)); + return 1; } if (ti->has_preedit) { zwp_text_input_v3_send_preedit_string(ti->res, "", 0, 0); ti->has_preedit = 0; } zwp_text_input_v3_send_commit_string(ti->res, utf8); zwp_text_input_v3_send_done(ti->res, ti->serial); droiddeck_log("text-input", "committed %zu chars to %s", utf8_chars(utf8, len), ti_program(ti)); + return 1; } void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end) { diff --git a/app/src/main/java/com/droiddeck/launcher/App.kt b/app/src/main/java/com/droiddeck/launcher/App.kt index 53a0c89298..f91157dd41 100644 --- a/app/src/main/java/com/droiddeck/launcher/App.kt +++ b/app/src/main/java/com/droiddeck/launcher/App.kt @@ -20,6 +20,10 @@ class App : Application() { override fun onCreate() { super.onCreate() + if (android.os.Build.VERSION.SDK_INT >= 28 && + com.droiddeck.launcher.runtime.GuestWorker.isWorkerProcess(this, Application.getProcessName())) return + if (android.os.Build.VERSION.SDK_INT >= 28 && Application.getProcessName() == packageName) + com.droiddeck.launcher.runtime.GuestWorkers.attach(this) com.droiddeck.launcher.runtime.NativeGuest.init(this) com.droiddeck.launcher.session.Onboarding.attach(this) Thread({ runCatching { EnhancedSessionLogShare.cleanupAbandonedStages(this) } }, "diagnostic-stage-cleanup").start() diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index 925884b3c3..94b0e6c744 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -430,21 +430,28 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl */ private fun useMaliFallback(missing: String?): String { val oldVulkan = com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(activity) - val venus = oldVulkan == null && com.droiddeck.launcher.session.VenusComponent.available(activity) + val venusByUser = venusExplicit() + val venus = MaliAutoRoute.venusStandsIn( + com.droiddeck.launcher.session.VenusComponent.available(activity), oldVulkan == null, + SessionPrefs.venus(activity), venusByUser, gpu.name, + ) if (oldVulkan != null) Log.i(TAG, "auto: Mali driver reports Vulkan $oldVulkan; Venus needs 1.2, the bridge stands in") val ownership = MaliAutoRoute.fallbackOwnership( venus, SessionPrefs.vkBridge(activity), bridgeExplicit(), - SessionPrefs.venus(activity), venusExplicit(), + SessionPrefs.venus(activity), venusByUser, ) if (venus && !SessionPrefs.venus(activity)) { SessionPrefs.setVenus(activity, true) if (SessionPrefs.vkBridge(activity) && !bridgeExplicit()) SessionPrefs.setVkBridge(activity, false) SessionPrefs.setMaliFallbackByAuto(activity, ownership) - } else if (!venus && !SessionPrefs.vkBridge(activity)) { - SessionPrefs.setVkBridge(activity, true) - SessionPrefs.setMaliFallbackByAuto(activity, ownership) + } else if (!venus) { + val venusOff = SessionPrefs.venus(activity) && !venusByUser + val bridgeOn = !SessionPrefs.vkBridge(activity) + if (venusOff) SessionPrefs.clearVenus(activity) + if (bridgeOn) SessionPrefs.setVkBridge(activity, true) + if (venusOff || bridgeOn || ownership != MaliAutoRoute.NONE) SessionPrefs.setMaliFallbackByAuto(activity, ownership) } else if (ownership != MaliAutoRoute.NONE) { SessionPrefs.setMaliFallbackByAuto(activity, ownership) } @@ -467,7 +474,7 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl /** A pair is installed for this Mali: the route Auto switched on in its place goes off again. */ private fun endMaliFallback() { when (SessionPrefs.maliFallbackByAuto(activity)) { - "venus" -> SessionPrefs.setVenus(activity, false) + "venus" -> SessionPrefs.clearVenus(activity) "bridge" -> SessionPrefs.setVkBridge(activity, false) else -> return } diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 1912828781..900823e0f4 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -25,6 +25,7 @@ import android.widget.EditText import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.background import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -51,6 +52,7 @@ 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 @@ -189,23 +191,29 @@ 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) private var phantomWarning by mutableStateOf(null) private var phantomProcessStatus by mutableStateOf(PhantomProcessStatus.NOT_APPLICABLE) private var showPhantomGate by mutableStateOf(false) private var directAudio by mutableStateOf(false) - private var picturePosition by mutableStateOf("center") + private var picturePositionLandscape by mutableStateOf("center") + private var picturePositionPortrait by mutableStateOf("top") 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 launcherFullscreen by mutableStateOf(true) + private var launcherFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS) + private var sessionFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS) + private var launcherFrost by mutableStateOf(false) + private var frostWallpaper by mutableStateOf(true) + private var frostCards by mutableStateOf(true) + private var frostTransparency by mutableStateOf(com.droiddeck.launcher.ui.FROST_WALLPAPER_DEFAULT) + private var frostCardTransparency by mutableStateOf(com.droiddeck.launcher.ui.FROST_DEFAULT) + private val frost = com.droiddeck.launcher.ui.LauncherFrost(this) private var controllerHaptics by mutableStateOf(true) private var downloadSource by mutableStateOf(DownloadSource.MODE_AUTO) private var downloadMirror by mutableStateOf("") @@ -296,9 +304,6 @@ 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) @@ -509,17 +514,6 @@ 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() @@ -617,6 +611,7 @@ 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(null) @@ -1092,6 +1087,7 @@ 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) @@ -1369,8 +1365,20 @@ 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) - launcherFullscreen = SessionPrefs.launcherFullscreen(this) + launcherFullscreenMode = SessionPrefs.launcherFullscreenMode(this) + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) + launcherFrost = SessionPrefs.launcherFrost(this) + frostWallpaper = SessionPrefs.frostWallpaper(this) + frostCards = SessionPrefs.frostCards(this) + frostTransparency = SessionPrefs.frostTransparency(this) + frostCardTransparency = SessionPrefs.frostCardTransparency(this) + frost.start() + frost.prepare(launcherFrost && frostWallpaper) + frost.show(frostShown()) controllerHaptics = SessionPrefs.controllerHaptics(this) downloadSource = DownloadSource.mode(this) downloadMirror = DownloadSource.mirror(this) @@ -1395,8 +1403,14 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet } val appsTabShown = "android-apps" !in com.droiddeck.launcher.ui.NavTabs.hidden androidx.compose.runtime.LaunchedEffect(appsTabShown) { if (appsTabShown && androidApps.isEmpty()) refreshAndroidApps() } - DroidDeckTheme(theme, appScale = appScale) { - com.droiddeck.launcher.ui.FocusGlideHost(androidx.compose.ui.Modifier.fillMaxSize().exposeTestTags()) { + val frostShown = frostShown() + androidx.compose.runtime.LaunchedEffect(frostShown) { frost.show(frostShown) } + val frostChoice = if (frostShown) com.droiddeck.launcher.ui.FrostChoice(frostTransparency, frostCards, frostCardTransparency) else null + DroidDeckTheme(theme, appScale = appScale, frost = frostChoice) { + val palette = com.droiddeck.launcher.ui.LocalPalette.current + val veil = com.droiddeck.launcher.ui.LocalFrost.current + val ground = if (frost.prepared) androidx.compose.ui.Modifier.background(veil ?: palette.background) else androidx.compose.ui.Modifier + com.droiddeck.launcher.ui.FocusGlideHost(androidx.compose.ui.Modifier.fillMaxSize().then(ground).exposeTestTags()) { if (decky.deckyPendingZip != null) com.droiddeck.launcher.ui.DeckyZipWarningDialog( onConfirm = { decky.confirmPluginZip() }, onCancel = { decky.cancelPluginZip() }, ) @@ -1471,7 +1485,14 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet orientation = orientation, launcherOrientation = launcherOrientation, homePage = homePage, - launcherFullscreen = launcherFullscreen, + launcherFullscreenMode = launcherFullscreenMode, + sessionFullscreenMode = sessionFullscreenMode, + launcherFrost = launcherFrost, + frostWallpaper = frostWallpaper, + frostCards = frostCards, + frostTransparency = frostTransparency, + frostCardTransparency = frostCardTransparency, + frostSupported = frost.supported, controllerHaptics = controllerHaptics, downloadSource = downloadSource, downloadMirror = downloadMirror, @@ -1630,9 +1651,6 @@ 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) }, @@ -1744,13 +1762,14 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet } }, "delete-session-logs").start() }, - onClearLogs = { + onClearLogs = { done -> 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() }, @@ -1802,11 +1821,37 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet homePage = value }, onControllerHaptics = { on -> SessionPrefs.setControllerHaptics(this, on); controllerHaptics = on }, - onLauncherFullscreen = { on -> - SessionPrefs.setLauncherFullscreen(this, on) - launcherFullscreen = on + onLauncherFullscreenMode = { mode -> + SessionPrefs.setLauncherFullscreenMode(this, mode) + launcherFullscreenMode = mode applyLauncherFullscreen() }, + onSessionFullscreenMode = { mode -> + SessionPrefs.setSessionFullscreenMode(this, mode) + sessionFullscreenMode = mode + }, + onLauncherFrost = { on -> + SessionPrefs.setLauncherFrost(this, on) + launcherFrost = on + if (on && frostWallpaper && !frost.prepared) restartLauncher() + }, + onFrostWallpaper = { on -> + SessionPrefs.setFrostWallpaper(this, on) + frostWallpaper = on + if (on && !frost.prepared) restartLauncher() + }, + onFrostCards = { on -> + SessionPrefs.setFrostCards(this, on) + frostCards = on + }, + onFrostTransparency = { percent -> + SessionPrefs.setFrostTransparency(this, percent) + frostTransparency = SessionPrefs.frostTransparency(this) + }, + onFrostCardTransparency = { percent -> + SessionPrefs.setFrostCardTransparency(this, percent) + frostCardTransparency = SessionPrefs.frostCardTransparency(this) + }, onGameStoresSpeedTier = { tier -> SessionPrefs.setGameStoresSpeedTier(this, tier); gameStoresSpeedTier = tier }, onNavigated = { navRequest = null }, onStoresShowMature = { show -> SessionPrefs.setStoresShowMature(this, show); storesShowMature = show }, @@ -1993,11 +2038,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet } } - val askAllFiles = Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.files.AllFilesAccess.missing() && - !SessionPrefs.allFilesAsked(this) - if (savedInstanceState == null) { - if (!askAllFiles) ui.post { startSteamAtStartupIfEnabled(cold = true) } - } + if (savedInstanceState == null) ui.post { startSteamAtStartupIfEnabled(cold = true) } saved?.let { state -> restoreCompatLaunch(state) pendingSwitch = savedIntent(state, KEY_PENDING_SWITCH) @@ -2005,13 +2046,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet } val wanted = ArrayList() - if (Build.VERSION.SDK_INT >= 30) { - // From targetSdk 30, shared storage outside the app's own folders is all-files access or nothing. - if (askAllFiles) { - SessionPrefs.setAllFilesAsked(this) - com.droiddeck.launcher.files.AllFilesAccess.open(this) - } - } else if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + // From Android 11, shared storage outside the app's own folders is all-files access, which the file picker asks for when a shared drive is opened. + if (Build.VERSION.SDK_INT < 30 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { wanted.add(Manifest.permission.WRITE_EXTERNAL_STORAGE) } if (SessionPrefs.micEnabled(this) && !SessionPrefs.micAsked(this) @@ -2020,6 +2056,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet SessionPrefs.setMicAsked(this) } if (wanted.isNotEmpty()) requestPermissions(wanted.toTypedArray(), 1) + com.droiddeck.launcher.session.Onboarding.onFirstRunReady = firstRunReady Thread({ com.droiddeck.launcher.stores.StoreAccounts.encryptAll(this) }, "store-credentials").start() if (!SessionState.running) Thread({ com.droiddeck.launcher.session.LogMigration.run(this) @@ -2111,14 +2148,26 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) - if (!hasFocus) triggerKeys.cancel() + if (!hasFocus) { + triggerKeys.cancel() + stopRightStickScroll() + } if (hasFocus) { com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false) applyLauncherFullscreen() } } - private fun applyLauncherFullscreen() { + 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) @Suppress("DEPRECATION") window.decorView.systemUiVisibility = if (launcherFullscreen) { (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY @@ -2199,7 +2248,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet return true } return try { - super.dispatchKeyEvent(event) + super.dispatchKeyEvent(event) || com.droiddeck.launcher.ui.PageBumpers.handle(event) } catch (e: IllegalStateException) { if (e.message?.contains("active focus target") != true) throw e android.util.Log.w("MainActivity", "key ${event.keyCode} dropped: ${e.message}") @@ -2209,14 +2258,116 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet private val triggerKeys = com.droiddeck.launcher.input.TriggerKeys { dispatchKeyEvent(it) } + internal fun onMenuMotion(event: MotionEvent) = triggerKeys.onMotion(event) + + private val rightStickLayouts = HashMap() + private val rightStickScrollHandler = android.os.Handler(android.os.Looper.getMainLooper()) + private var rightStickScrollDeviceId = -1 + private var rightStickScrollDeflection = 0f + private var rightStickScrollScheduled = false + private var rightStickNextDispatchAt = 0L + private val rightStickScrollTick = object : Runnable { + override fun run() { + val deviceId = rightStickScrollDeviceId + if (!hasWindowFocus() || (compatLaunch != null && !compatLaunch!!.loading.ended) || + deviceId == -1 || + android.view.InputDevice.getDevice(deviceId) == null || + kotlin.math.abs(rightStickScrollDeflection) < 0.55f) { + stopRightStickScroll() + return + } + rightStickScrollScheduled = false + dispatchRightStickScroll(rightStickScrollDeflection, deviceId) + rightStickNextDispatchAt = android.os.SystemClock.uptimeMillis() + 130L + rightStickScrollHandler.postDelayed(this, 130L) + rightStickScrollScheduled = true + } + } + + private fun stopRightStickScroll() { + rightStickScrollHandler.removeCallbacks(rightStickScrollTick) + rightStickScrollDeviceId = -1 + rightStickScrollDeflection = 0f + rightStickScrollScheduled = false + } + + private fun dispatchRightStickScroll(value: Float, deviceId: Int) { + val now = android.os.SystemClock.uptimeMillis() + val root = window.decorView + if (root.width <= 0 || root.height <= 0) return + val properties = android.view.MotionEvent.PointerProperties().apply { + id = 0 + toolType = android.view.MotionEvent.TOOL_TYPE_MOUSE + } + val coordinates = android.view.MotionEvent.PointerCoords().apply { + x = root.width * 0.65f + y = root.height * 0.5f + setAxisValue(android.view.MotionEvent.AXIS_VSCROLL, -value * 3f) + } + val scroll = android.view.MotionEvent.obtain( + now, now, android.view.MotionEvent.ACTION_SCROLL, 1, + arrayOf(properties), arrayOf(coordinates), 0, 0, 1f, 1f, + deviceId, 0, android.view.InputDevice.SOURCE_MOUSE, 0, + ) + try { + super.dispatchGenericMotionEvent(scroll) + } finally { + scroll.recycle() + } + } + + private fun scrollPageWithRightStick(event: android.view.MotionEvent) { + if (event.actionMasked != android.view.MotionEvent.ACTION_MOVE || + !com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return + val device = event.device ?: return + val rxRy = com.droiddeck.launcher.input.PadBridge.rightStickUsesRxRy(event, device, rightStickLayouts) + ?: run { + if (rightStickScrollDeviceId == event.deviceId) stopRightStickScroll() + return + } + val axis = if (rxRy) android.view.MotionEvent.AXIS_RY else android.view.MotionEvent.AXIS_RZ + val value = event.getAxisValue(axis) + if (kotlin.math.abs(value) < 0.55f) { + if (rightStickScrollDeviceId == event.deviceId) stopRightStickScroll() + return + } + rightStickScrollDeviceId = event.deviceId + rightStickScrollDeflection = value + if (!rightStickScrollScheduled) { + val delay = (rightStickNextDispatchAt - android.os.SystemClock.uptimeMillis()).coerceAtLeast(0L) + rightStickScrollHandler.postDelayed(rightStickScrollTick, delay) + rightStickScrollScheduled = true + } + } + override fun dispatchGenericMotionEvent(event: android.view.MotionEvent): Boolean { if (compatLaunch != null && !compatLaunch!!.loading.ended && - com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return true + com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) { + stopRightStickScroll() + return true + } triggerKeys.onMotion(event) + scrollPageWithRightStick(event) return super.dispatchGenericMotionEvent(event) } + @Volatile private var inFront = false + private var autoSteamPending = false + + /** Runs on the worker thread that finishes setup, so the foreground state is read as setup completes, not when the UI thread gets to it. */ + private val firstRunReady: () -> Unit = { + val front = inFront + runOnUiThread { if (front) autoStartSteam() } + } + + private fun autoStartSteam() { + if (isFinishing || isDestroyed || SessionState.running || !inFront) return + if (busy) autoSteamPending = true else playSteam() + } + override fun onPause() { + inFront = false + stopRightStickScroll() compatLaunchVisible = false if (android.os.Build.VERSION.SDK_INT >= 29) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, true) super.onPause() @@ -2224,12 +2375,16 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet override fun onResume() { super.onResume() + inFront = true if (!homeChoiceOpen) { HomeApp.releaseUnusedHomeEntry(this) refreshHomeAppState() } if (settingsMode == SessionService.MODE_STEAM) refreshFoundSteamLibraries() - settingsMode?.let { hdrOn = SessionPrefs.hdr(this, it) } + settingsMode?.let { mode -> + hdrOn = SessionPrefs.hdr(this, mode) + if (mode == SessionService.MODE_STEAM) loadPicturePositions() + } compatLaunchVisible = true com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false) @@ -2359,11 +2514,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet override fun onDestroy() { // The queued launch was saved before this; a restored activity keeps its copy, and this one must not start it too. + if (com.droiddeck.launcher.session.Onboarding.onFirstRunReady === firstRunReady) com.droiddeck.launcher.session.Onboarding.onFirstRunReady = null queuedLaunchRunner.destroy() triggerKeys.cancel() launchCoordinator.cancelAll() cancelCompatLaunch() updates.unregister() + frost.stop() runCatching { unregisterReceiver(shortcutsInstallStatus) } super.onDestroy() } @@ -2768,6 +2925,10 @@ 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, @@ -2782,7 +2943,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet backHold = backHold, backActionsInverted = backActionsInverted, directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null, - picturePosition = if (mode == SessionService.MODE_STEAM) picturePosition else null, + picturePositionLandscape = picturePositionLandscape.takeIf { mode == SessionService.MODE_STEAM }, + picturePositionPortrait = picturePositionPortrait.takeIf { mode == SessionService.MODE_STEAM }, 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, @@ -2832,6 +2994,10 @@ 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 }, @@ -2855,7 +3021,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet backActionsInverted = inverted }, onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on }, - onPicturePosition = { value -> SessionPrefs.setPicturePosition(this, value); picturePosition = value }, + onPicturePosition = { portrait, value -> + SessionPrefs.setPicturePosition(this, portrait, value) + if (portrait) picturePositionPortrait = value else picturePositionLandscape = 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 }, @@ -2953,7 +3122,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet fsyncFirst = fsyncFirst, gamescopeRealtime = gamescopeRealtime, gpuClockPin = gpuClockPin, - prootNoSeccomp = prootNoSeccomp, prootFastPath = prootFastPath, nativeUserland = nativeUserland, cursorComposite = cursorComposite, + nativeDesktopAvailable = com.droiddeck.launcher.runtime.NativeGuest.nextSession(this), desktopAsUser = desktopAsUser, cursorComposite = cursorComposite, guestHostname = guestHostname, phantomWarning = phantomWarning, onClientOverride = { on -> SessionPrefs.setClientCpusOverride(this, on); clientOverride = on }, onPaceCores = { on -> SessionPrefs.setPaceCores(this, on); paceCores = on }, @@ -2967,9 +3136,7 @@ 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) }, onClientCore = { core, on -> @@ -3171,6 +3338,11 @@ 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) @@ -3192,6 +3364,7 @@ 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) @@ -3205,7 +3378,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet backHold = SessionPrefs.backHold(this) backActionsInverted = SessionPrefs.backActionsInverted(this) directAudio = SessionPrefs.directAudio(this) - picturePosition = SessionPrefs.picturePosition(this) + loadPicturePositions() integerScaling = SessionPrefs.integerScaling(this) stretch16x9 = SessionPrefs.stretch16x9(this) avoidNotch = SessionPrefs.avoidNotch(this) @@ -3285,9 +3458,7 @@ 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) refreshPhantomStatus() @@ -3658,6 +3829,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet refresh() com.droiddeck.launcher.agent.AgentHost.refresh(this) if (ok == true && LinuxRuntime.isInstalled(this)) { protons.checkUpdates(); protons.ensureSteamClient() } + if (autoSteamPending) { autoSteamPending = false; autoStartSteam() } } }, "runtime-operation").start() } diff --git a/app/src/main/java/com/droiddeck/launcher/MaliAutoRoute.kt b/app/src/main/java/com/droiddeck/launcher/MaliAutoRoute.kt index f4ebf2f0f7..1906b6aa51 100644 --- a/app/src/main/java/com/droiddeck/launcher/MaliAutoRoute.kt +++ b/app/src/main/java/com/droiddeck/launcher/MaliAutoRoute.kt @@ -26,6 +26,12 @@ internal object MaliAutoRoute { fun userChoice(keyStored: Boolean, owner: String, route: String): Boolean = keyStored && owner != route + fun venusStandsIn(available: Boolean, hostVulkanOk: Boolean, venusOn: Boolean, venusExplicit: Boolean, gpuName: String): Boolean = + available && hostVulkanOk && if (venusExplicit) venusOn else !venusStallsOn(gpuName) + + // Steam's web helper dies on its first window through Venus on these (#2879), so the bridge stands in. + fun venusStallsOn(gpuName: String): Boolean = gpuName.contains("G2-Ultra", ignoreCase = true) + fun shouldEnd(ownsRoute: String, mali: Boolean, installedPair: Boolean): Boolean = mali && installedPair && ownsRoute != NONE } diff --git a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt index 385081cc7d..b6799bd315 100644 --- a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt +++ b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt @@ -45,6 +45,7 @@ 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.refresh(activity) } @@ -66,7 +67,7 @@ internal class ProtonMenu( ui.post { protonStage = label; protonPercent = value } } }.getOrElse { it.message ?: it.javaClass.simpleName } - if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false) + if (problem == null && !automatic && tool.id in REMEMBERED) ProtonExtras.setDeclined(activity, false, tool.id) if (tool.id == ProtonExtras.OWN) { if (problem == null) Onboarding.finish(Onboarding.Step.PROTON) else Onboarding.fail(Onboarding.Step.PROTON, problem) Onboarding.recheck(activity) @@ -96,7 +97,7 @@ internal class ProtonMenu( protonPercent = -1 Thread({ if (older) ProtonExtras.removeOlder(activity, tool) else ProtonExtras.remove(activity, tool, dir) - if (tool.id == ProtonExtras.OWN && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true) + if (tool.id in REMEMBERED && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true, tool.id) ui.post { protonBusyId = null protonStage = null @@ -158,7 +159,7 @@ internal class ProtonMenu( refreshExperimental() protonRows = ProtonExtras.offered(activity).map { val all = ProtonExtras.installedAll(activity, it) - ProtonRow(it.id, it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(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)) } } diff --git a/app/src/main/java/com/droiddeck/launcher/QuestSteamVrWatch.kt b/app/src/main/java/com/droiddeck/launcher/QuestSteamVrWatch.kt new file mode 100644 index 0000000000..eab1ee2f37 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/QuestSteamVrWatch.kt @@ -0,0 +1,36 @@ +package com.droiddeck.launcher + +import com.droiddeck.launcher.gpu.SteamVr + +internal class QuestSteamVrWatch(start: Long) { + private var startupDeadline = start + STARTUP_MS + private var lastRunning: Long? = null + private var graceUntil = start + private var wasPaused = false + + // A frozen guest cannot answer the status call, so a status read during a freeze, or one that + // started before it, says nothing about SteamVR. + fun stopped(now: Long, status: SteamVr.Status, paused: Boolean): Boolean { + if (paused) { + wasPaused = true + return false + } + if (wasPaused) { + wasPaused = false + graceUntil = now + RESUME_GRACE_MS + } + if (status == SteamVr.Status.RUNNING) { + lastRunning = now + graceUntil = now + return false + } + val deadline = lastRunning?.plus(RUNNING_GRACE_MS) ?: startupDeadline + return now >= maxOf(deadline, graceUntil) + } + + companion object { + const val STARTUP_MS = 30_000L + const val RUNNING_GRACE_MS = 5_000L + const val RESUME_GRACE_MS = 15_000L + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt b/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt index 98e5a0b227..9a6db04cc5 100644 --- a/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt @@ -4,25 +4,32 @@ import android.app.NativeActivity import android.os.Bundle import android.os.SystemClock import android.util.Log +import android.view.Surface import android.widget.Toast import com.droiddeck.launcher.gpu.SteamVr import com.droiddeck.launcher.session.SessionService import com.droiddeck.launcher.session.SessionState +import com.droiddeck.launcher.session.xr.XrLayerSource +import com.droiddeck.launcher.session.xr.XrPanels import com.droiddeck.launcher.wayland.CompositorHost import com.droiddeck.launcher.wayland.WaylandCompositor -class QuestXrActivity : NativeActivity() { +class QuestXrActivity : NativeActivity(), XrLayerSource { private var steamVrStarted = false @Volatile private var closing = false @Volatile private var steamVrStatus = SteamVr.Status.UNAVAILABLE private var sessionId: String? = null override fun onCreate(savedInstanceState: Bundle?) { + // NativeActivity opens the library itself, but the layer host's JNI methods resolve only + // through a System.loadLibrary. + System.loadLibrary("droiddeckxr") sessionId = SessionState.sessionId SessionService.setXrActivityVisible(this, true) super.onCreate(savedInstanceState) } fun onXrActive(active: Boolean) { + XrPanels.setDrawing(active) if (active) { check(CompositorHost.isStarted) { "DroidDeck compositor is not running" } SessionService.resume(this) @@ -52,18 +59,17 @@ class QuestXrActivity : NativeActivity() { if (!closing) leaveXr("SteamVR start failed", sessionAlive()) return@Thread } - val startupDeadline = SystemClock.elapsedRealtime() + 30_000 - var lastRunning: Long? = null + val watch = QuestSteamVrWatch(SystemClock.elapsedRealtime()) while (!closing) { if (!sessionAlive()) { leaveXr("Steam session ended", false) break } - steamVrStatus = SteamVr.status(this) - val now = SystemClock.elapsedRealtime() - if (steamVrStatus == SteamVr.Status.RUNNING) lastRunning = now - val deadline = lastRunning?.plus(5_000) ?: startupDeadline - if (steamVrStatus != SteamVr.Status.RUNNING && now >= deadline) { + val pausedBefore = guestPaused() + val status = SteamVr.status(this) + val paused = pausedBefore || guestPaused() + if (!paused) steamVrStatus = status + if (watch.stopped(SystemClock.elapsedRealtime(), status, paused)) { leaveXr("SteamVR stopped or did not finish starting", true) break } @@ -81,6 +87,8 @@ class QuestXrActivity : NativeActivity() { } } + private fun guestPaused() = SessionState.suspending || SessionState.suspended || SessionState.resuming + private fun sessionAlive() = SessionState.running && !SessionState.stopRequested && sessionId != null && SessionState.sessionId == sessionId @@ -99,8 +107,30 @@ class QuestXrActivity : NativeActivity() { fun onXrStatus(): Int = steamVrStatus.ordinal + fun onXrHostBuffers(state: java.nio.ByteBuffer, control: java.nio.ByteBuffer) { + runOnUiThread { if (!closing) XrPanels.attach(this, state, control) } + } + + fun onXrHostFrame() = XrPanels.frame() + + override val context: android.content.Context get() = this + override fun createLayer(width: Int, height: Int) = nativeCreateLayer(width, height) + override fun layerSurface(id: Int) = nativeLayerSurface(id) + override fun destroyLayer(id: Int) = nativeDestroyLayer(id) + override fun setOrbImage(image: android.graphics.Bitmap) = nativeSetOrbImage(image) + override fun leave() { + closing = true + finish() + } + + private external fun nativeCreateLayer(width: Int, height: Int): Int + private external fun nativeLayerSurface(id: Int): Surface? + private external fun nativeDestroyLayer(id: Int) + private external fun nativeSetOrbImage(image: android.graphics.Bitmap) + override fun onDestroy() { closing = true + XrPanels.detach() SessionService.setXrActivityVisible(this, false) super.onDestroy() } diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 11fd6b86f2..3b5166bf5a 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -76,6 +76,7 @@ import com.droiddeck.launcher.input.InputSpace import com.droiddeck.launcher.input.KeyboardHost import com.droiddeck.launcher.input.ControllerPrefs import com.droiddeck.launcher.input.SessionClipboard +import com.droiddeck.launcher.input.SessionTextInput import com.droiddeck.launcher.input.OnScreenControls import com.droiddeck.launcher.input.OnScreenLayout import com.droiddeck.launcher.input.InputRouter @@ -99,6 +100,12 @@ 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 @@ -121,6 +128,7 @@ 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 @@ -162,7 +170,8 @@ import kotlin.math.abs private const val SCREEN_EFFECTS_TARGET_AUTO = "auto" private const val SCREEN_EFFECTS_TARGET_GLOBAL = "global" -class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droiddeck.launcher.ui.AgentPetHost { +class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droiddeck.launcher.ui.AgentPetHost, + com.droiddeck.launcher.session.xr.XrMenuHost { override fun attachBaseContext(newBase: android.content.Context) { super.attachBaseContext(newBase) com.droiddeck.launcher.core.AppLanguage.applyTo(this, newBase) @@ -178,6 +187,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var adaptiveSticks by mutableStateOf(null) private var quickButtons by mutableStateOf>(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 @@ -228,6 +240,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private var unfoldedPanel by mutableStateOf(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(null) @@ -235,6 +248,10 @@ 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(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 @@ -348,6 +365,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde window.decorView.hasWindowFocus() || secondScreenPresentation?.window?.decorView?.hasWindowFocus() == true } } + private val sessionTextInput by lazy { + SessionTextInput(this) { + window.decorView.hasWindowFocus() || secondScreenPresentation?.window?.decorView?.hasWindowFocus() == true + } + } private var watching = true private lateinit var touchpad: TouchpadGestures private lateinit var directTouchHold: DirectTouchHold @@ -546,6 +568,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var drawerOpenState by mutableStateOf(false) private var typingReturnMode: SecondScreenMode? = null private var drawerDocked by mutableStateOf(false) + /** The menu is open as a floating panel in the immersive Quest view instead of over this window. */ + private var drawerXr by mutableStateOf(false) private var drawerPinned by mutableStateOf(false) private var drawerLayerOpen = false private var drawerBackRequests by mutableIntStateOf(0) @@ -563,9 +587,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde drawerPinned = false if (value) { releaseHeldKeys() - drawerDocked = dockDrawer() && openDockedMenu() + drawerXr = com.droiddeck.launcher.session.xr.XrPanels.showMenu() + drawerDocked = !drawerXr && dockDrawer() && openDockedMenu() } drawerOpenState = value + if (!value && drawerXr) { + drawerXr = false + com.droiddeck.launcher.session.xr.XrPanels.hideMenu() + } if (!value && drawerDocked) closeDockedMenu() } private val dockedMenuIdle: Boolean get() = com.droiddeck.launcher.input.DualScreen.menuIdleOnBottom(drawerOpen, drawerDocked, drawerPinned, dockedMenuController) @@ -615,6 +644,7 @@ 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) @@ -643,6 +673,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var effects by mutableStateOf(ScreenEffects.OFF) private var observedScreenEffectsProfileId by mutableStateOf(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(null) @@ -703,9 +734,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var drawerTextureAnisotropy by mutableStateOf(null) private var drawerTextureLodBias by mutableStateOf(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(null) private var frameGenActiveGameName by mutableStateOf(null) @@ -807,6 +835,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private var isHomeApp by mutableStateOf(false) private var androidApps by mutableStateOf>(emptyList()) + private var padConnected by mutableStateOf(false) private val deviceListener = object : InputManager.InputDeviceListener { override fun onInputDeviceAdded(deviceId: Int) { @@ -849,6 +878,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + com.droiddeck.launcher.session.xr.XrPanels.setMenuHost(this) AgentGuest.readyListener = agentReadyListener com.droiddeck.launcher.agent.AgentAttachments.gameFrame = gameFrame if (com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isRemoving() || @@ -912,7 +942,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } applyFollowChoice() applyFollowOrientation(resources.configuration) - goFullscreen() + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) + applySessionFullscreen() volumeControlStream = android.media.AudioManager.STREAM_MUSIC displayManager = getSystemService(DISPLAY_SERVICE) as DisplayManager refreshSecondScreenDisplays() @@ -956,6 +987,10 @@ 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 @@ -979,6 +1014,7 @@ 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 @@ -987,7 +1023,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } root.addView(controls) } - keyboard = KeyboardHost(this).also { host -> + keyboard = KeyboardHost(this, sendKeyEvent = ::dispatchImeKeyEvent, sendText = WaylandCompositor::textInputCommit).also { host -> host.onImeChanged = ::onPrimaryImeChanged root.addView(host) } @@ -1080,6 +1116,7 @@ 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 @@ -1192,7 +1229,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val cursorHidden = cursorHiddenByUi() androidx.compose.runtime.SideEffect { com.droiddeck.launcher.glasses.GlassesMenuMirror.setSessionMenuVisible(this@SessionActivity, - (drawerOpen || achievementsOpen || pcKeyboardOpen) && !pipUi && steamVrStatus != SteamVr.Status.RUNNING) + (drawerOpen || achievementsOpen || pcKeyboardOpen) && !pipUi && !drawerXr && steamVrStatus != SteamVr.Status.RUNNING) } androidx.compose.runtime.SideEffect { applyPlatformPointer(uiPointer) } androidx.compose.runtime.DisposableEffect(Unit) { @@ -1262,14 +1299,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde glasses.usesSpatialControllers(glassesSettings) && glassesSettings.joyConTracking) joyConVr?.let { { it.recenter() } } else null, ) { headTracker?.recenter() } - if (!phonePanel && glasses.present && !drawerOpen && !pcKeyboardOpen && !loading.visible) com.droiddeck.launcher.ui.GlassesCornerButton(glassesSlot, + val showGlassesShortcut = com.droiddeck.launcher.ui.rememberShowGlassesShortcut() + if (!phonePanel && glasses.present && showGlassesShortcut && !drawerOpen && !pcKeyboardOpen && !loading.visible) com.droiddeck.launcher.ui.GlassesCornerButton(glassesSlot, controllerSettings?.tint ?: android.graphics.Color.rgb(90, 160, 255), controllerSettings?.opacity ?: 100) { - drawerPage = com.droiddeck.launcher.ui.SessionDrawerPage.GLASSES + drawerPage = com.droiddeck.launcher.ui.SessionDrawerPage.VR drawerOpen = true } if (!drawerOpen && !pcKeyboardOpen && !loading.visible) { com.droiddeck.launcher.ui.DrawerEntryHint(SessionState.mode == SessionService.MODE_STEAM, backActionsInverted) { drawerOpen = true } if (cornerTap) com.droiddeck.launcher.ui.DrawerCornerTap { drawerOpen = true } + if (com.droiddeck.launcher.session.QuestExperimental.isSupported()) + com.droiddeck.launcher.ui.DrawerEdgeSwipe { onBackPressedDispatcher.onBackPressed() } } if (loading.visible) LoadingOverlay( loading.step, loading.percent, loading.elapsed, loading.hint, loading.ended, @@ -1361,6 +1401,7 @@ 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() @@ -1451,7 +1492,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } } LaunchedEffect(drawerOpen, achievementsOpen, AgentGuest.focusRevision, StoreAchievements.revision) { - if (!drawerOpen && !achievementsOpen) return@LaunchedEffect + if (!drawerOpen && !achievementsOpen) { + achievementsInFront = null + return@LaunchedEffect + } val found = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { runCatching { resolveAchievementsInFront() } .onFailure { Log.w(TAG, "achievements in front: ${it.javaClass.simpleName}") }.getOrNull() @@ -1470,11 +1514,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onAndroidKeyboard = { pcKeyboardOpen = false; togglePrimaryKeyboard() }, onClose = { pcKeyboardOpen = false }, ) - if (!drawerDocked) SessionMenu( + if (!drawerDocked && !drawerXr) SessionMenu( docked = false, effectsEditorProfileId = effectsEditorProfileId, effectsEditorTarget = effectsEditorTarget, ) + if (drawerOpen && !drawerDocked && !drawerXr && com.droiddeck.launcher.session.QuestExperimental.isSupported()) + com.droiddeck.launcher.ui.DrawerEdgeSwipe { onBackPressedDispatcher.onBackPressed() } LaunchedEffect(achievementsOpen) { if (achievementsOpen) { releasePads() @@ -1523,6 +1569,74 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } } + @androidx.compose.runtime.Composable + override fun XrMenuContent() { + val activeEffectsProfileId = currentScreenEffectsProfileId() + val effectsEditorTarget = if (drawerOpen) screenEffectsTarget else null + val effectsEditorProfileId = activeEffectsProfileId.takeIf { effectsEditorTarget == SCREEN_EFFECTS_TARGET_AUTO } + androidx.compose.runtime.LaunchedEffect(effectsEditorTarget, effectsEditorProfileId) { + when (effectsEditorTarget) { + SCREEN_EFFECTS_TARGET_AUTO -> syncActiveScreenEffectsProfile() + null -> Unit + else -> syncScreenEffectsTarget(effectsEditorTarget) + } + } + SessionMenu(docked = true, effectsEditorProfileId = effectsEditorProfileId, effectsEditorTarget = effectsEditorTarget) + } + + override fun xrSetMenuOpen(open: Boolean) { + if (open != drawerOpen) drawerOpen = open + } + + /** + * In the immersive Quest view, Stop takes the user back to this window with the session still + * running, and Stop SteamVR leaves at once instead of after the stop is noticed. + */ + private fun leaveXrMenu() { + if (!drawerXr) return + drawerOpen = false + com.droiddeck.launcher.session.xr.XrPanels.leaveImmersive() + } + + override fun xrMenuBack() { + if (drawerLayerOpen) drawerBackRequests++ else drawerOpen = false + } + + override fun xrSendKey(code: Int, down: Boolean) { + if (CompositorHost.isStarted) sendGuestKey(code, down, 32) + } + + override fun xrTypeText(text: String) = xrKeys.type(text) + + override fun xrImmersiveChanged(active: Boolean) { + if (active) { + if (immersiveFlatSize == null) immersiveFlatSize = SessionState.outputSize + resizeOutputForWindow(surfaceW, surfaceH) + return + } + val flat = immersiveFlatSize + immersiveFlatSize = null + if (windowOutputSize(surfaceW, surfaceH) == null && flat != null) applyOutputSize(flat) + else resizeOutputForWindow(surfaceW, surfaceH) + } + + /** The output's size when the immersive view opened; this window may have no surface while it is up. */ + private var immersiveFlatSize: Pair? = null + + override fun xrTapKey(keyCode: Int) = xrKeys.tap(keyCode) + + /** The VR keyboard's keys go straight to the game, past the menu and pad handling a real key passes through. */ + private val xrKeys by lazy { + KeyboardHost( + this, + sendKeyEvent = { event -> + CompositorHost.isStarted && (event.action != KeyEvent.ACTION_DOWN || event.repeatCount == 0) && + com.droiddeck.launcher.input.GuestKeys.send(event) { code, pressed -> sendGuestKey(code, pressed, 16) } + }, + sendText = { text -> if (CompositorHost.isStarted) WaylandCompositor.textInputCommit(text) }, + ) + } + @androidx.compose.runtime.Composable private fun SessionMenu( docked: Boolean, @@ -1547,8 +1661,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde effects = effects, screenEffectsTarget = screenEffectsTarget, screenEffectsTargets = screenEffectsTargetOptions(), - screenEffectsCanDelete = screenEffectsProfileIdForTarget(screenEffectsTarget)?.let { - SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it) + screenEffectsCanDelete = screenEffectsProfileRevision.let { + screenEffectsProfileIdForTarget(screenEffectsTarget)?.let { + SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it) || + SessionPrefs.hasScreenEffectsUpscalerOverride(this@SessionActivity, it) + } } == true, cardboard = cardboard, cardboardSensor = hasRotationSensor, @@ -1626,6 +1743,11 @@ 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) @@ -1649,6 +1771,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } else { val profileId = screenEffectsProfileIdForTarget(target) SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m) + screenEffectsProfileRevision++ if (target == screenEffectsTarget) { upscaler = m @@ -1684,6 +1807,7 @@ 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)) { @@ -1730,7 +1854,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val profileId = screenEffectsProfileIdForTarget(editorTarget) SessionPrefs.setScreenEffects(this@SessionActivity, profileId, e) effects = e - if (screenEffectsTargetAppliesToLiveOutput(editorTarget)) e.push(upscaler) + 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) + } } } }, @@ -1787,7 +1926,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onBlackFrameInsertion = { on -> SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on) blackFrameInsertion = on - CompositorHost.setBlackFrameInsertion(on, refreshHz(), outputFpsLimit()) + CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit(), outputFpsLimit()) }, hdr = hdrWanted, hdrAvailable = hdrAvailable, @@ -1810,21 +1949,45 @@ 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, - onAchievements = achievementsInFront?.let { { drawerOpen = false; achievementsOpen = true } }, + controllerConnected = padConnected, + achievementsGame = achievementsInFront?.game, + achievementsTitle = achievementsInFront?.title, achievementsProgress = achievementsInFront?.progress, padType = if (SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad) padType else null, onPadType = { id -> @@ -1899,9 +2062,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde SessionService.suspendPolicyChanged(this@SessionActivity) }, onTouch = { v -> SessionPrefs.setTouchMode(this@SessionActivity, v); readPrefs() }, - onInputSettings = { releasePads(); drawerOpen = false; inputSettingsOpen = true }, + onInputSettings = { leaveImmersiveForDialog(); releasePads(); drawerOpen = false; inputSettingsOpen = true }, onInputSelection = { releasePads(); refreshInputProfile() }, - onGestureSettings = { drawerOpen = false; gestureSettingsOpen = true }, + onGestureSettings = { leaveImmersiveForDialog(); drawerOpen = false; gestureSettingsOpen = true }, touchActive = drawerTouchMode(), directHoldBehavior = directHoldBehavior, onDirectHoldBehavior = { value -> @@ -1943,9 +2106,21 @@ 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 -> - SessionPrefs.setOrientation(this@SessionActivity, value) + when (SessionState.mode) { + SessionService.MODE_STEAM, SessionService.MODE_RUN -> + SessionPrefs.setOrientation(this@SessionActivity, "steam", value) + SessionService.MODE_DESKTOP -> + SessionPrefs.setOrientation(this@SessionActivity, "desktop", value) + else -> SessionPrefs.setOrientation(this@SessionActivity, value) + } sessionOrientation = value applyFollowOrientation(resources.configuration) }, @@ -1956,6 +2131,8 @@ 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 }, @@ -1992,18 +2169,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onUnfoldedControlsWithController = ::chooseUnfoldedControlsWithController, onBackground = { drawerOpen = false; pip.background(); moveTaskToBack(true) }, onShareLogs = { drawerOpen = false; shareCurrentSessionLogs() }, - onStop = { drawerOpen = false; SessionService.stop(this@SessionActivity); finish() }, + onStop = { + if (drawerXr) leaveXrMenu() else { + drawerOpen = false + SessionService.stop(this@SessionActivity) + finish() + } + }, onStopFrom = { onScreen -> - drawerOpen = false - if (onScreen == null || com.droiddeck.launcher.ui.Motion.scale == 0f || quitFrom != null) { - if (quitFrom == null) { SessionService.stop(this@SessionActivity); finish() } - } else { - val at = IntArray(2).also { sessionOverlay.getLocationOnScreen(it) } - quitFrom = onScreen.translate(-at[0].toFloat(), -at[1].toFloat()) + if (drawerXr) leaveXrMenu() else { + drawerOpen = false + if (onScreen == null || com.droiddeck.launcher.ui.Motion.scale == 0f || quitFrom != null) { + if (quitFrom == null) { SessionService.stop(this@SessionActivity); finish() } + } else { + val at = IntArray(2).also { sessionOverlay.getLocationOnScreen(it) } + quitFrom = onScreen.translate(-at[0].toFloat(), -at[1].toFloat()) + } } }, onClose = { drawerOpen = false }, - onDismissScreen = if (docked) ({ selectSecondScreenMode(SecondScreenMode.NONE) }) else null, + onDismissScreen = if (docked && !drawerXr) ({ selectSecondScreenMode(SecondScreenMode.NONE) }) else null, components = drawerComponents, onComponentsRefresh = { refreshDrawerComponents() @@ -2081,7 +2266,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde }) else null, onKeyboard = { togglePrimaryKeyboard() }, onSessionMenu = { drawerOpen = true }, - onStopSteamVr = if (vr) ({ steamVrAction("stop") }) else null, + onStopSteamVr = if (vr) ({ leaveXrMenu(); steamVrAction("stop") }) else null, brightness = glasses.brightness, brightnessMax = glasses.brightnessMax, onBrightness = if (glasses.canControl && glasses.hardwareControls) Glasses::setBrightness else null, @@ -2120,6 +2305,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun togglePcKeyboard() { drawerOpen = false + if (com.droiddeck.launcher.session.xr.XrPanels.toggleGameKeyboard(pc = true)) return hidePrimaryKeyboard() onScreenControls?.releaseAll() bottomInputControls?.releaseAll() @@ -2129,12 +2315,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun showPrimaryKeyboard() { pendingFieldKeyboard = false fieldKeyboardOnPrimary = false + if (com.droiddeck.launcher.session.xr.XrPanels.showGameKeyboard(pc = false)) return keyboard?.show() } private fun togglePrimaryKeyboard() { pendingFieldKeyboard = false fieldKeyboardOnPrimary = false + if (com.droiddeck.launcher.session.xr.XrPanels.toggleGameKeyboard(pc = false)) return keyboard?.toggle() } @@ -2158,6 +2346,18 @@ 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) @@ -2515,10 +2715,21 @@ 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.nativeSetUpscaler(targetUpscaler) - WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(targetEffects, targetUpscaler)?.name) - targetEffects.push(targetUpscaler) + 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) } } @@ -2531,6 +2742,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun resetScreenEffectsTarget(target: String) { if (target != screenEffectsTarget) return SessionPrefs.resetScreenEffectsProfile(this, screenEffectsProfileIdForTarget(target)) + screenEffectsProfileRevision++ syncScreenEffectsTarget(target) } @@ -2538,6 +2750,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (target != screenEffectsTarget) return val profileId = screenEffectsProfileIdForTarget(target) ?: return SessionPrefs.deleteScreenEffectsProfile(this, profileId) + screenEffectsProfileRevision++ syncScreenEffectsTarget(target) } @@ -2668,7 +2881,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde pipAutoEnter = SessionPrefs.pipAutoEnter(this) unfoldedControls = SessionPrefs.unfoldedControls(this) unfoldedControlsWithController = SessionPrefs.unfoldedControlsWithController(this) - picturePosition = SessionPrefs.picturePosition(this) + picturePosition = SessionPrefs.picturePosition(this, picturePortrait()) integerScaling = SessionPrefs.integerScaling(this) avoidNotch = SessionPrefs.avoidNotch(this) applyNotchInset() @@ -2724,7 +2937,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde oscTrackpads = SessionPrefs.oscTrackpads(this) backHold = SessionPrefs.backHold(this) dockedMenuController = SessionPrefs.dockedMenuController(this) - sessionOrientation = SessionPrefs.orientation(this) + sessionOrientation = SessionPrefs.orientation(this, SessionState.mode) dualScreenSessionMode = SessionPrefs.dualScreenSessionMode(this) backActionsInverted = SessionPrefs.backActionsInverted(this) physicalShortcuts.bindings = PhysicalShortcuts.read(this) @@ -2916,6 +3129,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() } FileUtils.copyAsset(this, "wayland/keymap.xkb", File(runtimeDir, "keymap.xkb")) com.droiddeck.launcher.input.VrControllers.publish(this) + com.droiddeck.launcher.session.QuestSteamVrLaunch.publish(this) val turnip = TurnipDriver(this) com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "surface.driver-setup") @@ -2989,7 +3203,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), outputFpsLimit(), + applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(), outputFpsLimit(), ) onOutputAttached(holder) if (SessionState.running && size != previous) { @@ -3007,6 +3221,7 @@ 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) } } @@ -3031,6 +3246,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private fun windowOutputSize(width: Int, height: Int): Pair? { + if (com.droiddeck.launcher.session.xr.XrPanels.immersiveActive) { + val flat = immersiveFlatSize ?: SessionState.outputSize + return if (steamScreenShown()) vrOutputSize(flat) else flat + } if (width <= 0 || height <= 0 || isInPictureInPictureMode) return null if (bottomGame != null) return when { SessionState.followScreen -> @@ -3044,9 +3263,38 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde else if (glassesScreen == null) outputSize() else null } + /** These editors draw in this window, which the immersive view hides, so they open after leaving it. */ + private fun leaveImmersiveForDialog() { + if (com.droiddeck.launcher.session.xr.XrPanels.immersiveActive) com.droiddeck.launcher.session.xr.XrPanels.leaveImmersive() + } + + /** Steam's own screen is up with no game holding a window; with no focus report, a game may be running. */ + private fun steamScreenShown(): Boolean { + if (SessionState.mode != SessionService.MODE_STEAM) return false + val focus = com.droiddeck.launcher.agent.AgentGuest.focus(this) ?: return false + return com.droiddeck.launcher.session.xr.XrSteamScreen.shown( + focus.takeUnless { it.isNull("focusedApp") }?.optLong("focusedApp"), + focus.optJSONArray("focusableApps")?.let { list -> (0 until list.length()).map { list.optLong(it) } }, + ) + } + + /** + * SteamVR shows Steam's own screen as its floating Steam window, so in the headset that screen is drawn + * tall enough for the window to stay sharp. A flat game keeps the flat size, so the output keeps it + * while one is running. + */ + private fun vrOutputSize(flat: Pair): Pair { + if (flat.second >= VR_OUTPUT_HEIGHT) return flat + val width = (flat.first.toLong() * VR_OUTPUT_HEIGHT / flat.second.coerceAtLeast(1)).toInt() and 1.inv() + return width to VR_OUTPUT_HEIGHT + } + private fun resizeOutputForWindow(width: Int, height: Int) { + applyOutputSize(windowOutputSize(width, height) ?: return) + } + + private fun applyOutputSize(size: Pair) { if (!CompositorHost.isStarted) return - val size = windowOutputSize(width, height) ?: return if (size == SessionState.outputSize) return Log.i(TAG, "output resized: ${SessionState.outputSize.first}x${SessionState.outputSize.second} -> ${size.first}x${size.second}") SessionState.outputSize = size @@ -3055,7 +3303,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde WaylandCompositor.nativeResizeOutput(size.first, size.second) } - private fun followPortrait(): Boolean = glassesScreen == null && SessionPrefs.portrait(this) + private fun followPortrait(): Boolean = glassesScreen == null && SessionPrefs.portrait(this, SessionState.mode) private fun applyFollowChoice() { val scale = SessionState.followScales.let { if (followPortrait()) it.second else it.first } @@ -3064,12 +3312,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private fun applyFollowOrientation(config: android.content.res.Configuration) { - val wanted = SessionPrefs.windowOrientation(this, SessionState.followScreen, config.smallestScreenWidthDp) + val wanted = SessionPrefs.windowOrientation(this, SessionState.followScreen, config.smallestScreenWidthDp, SessionState.mode) if (requestedOrientation != wanted) requestedOrientation = wanted } 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) } @@ -3127,13 +3377,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun displayMode(): String = SessionPrefs.displayMode(this, intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM, intent.getStringExtra(SessionService.EXTRA_PROGRAM)) - private fun portraitOutput(): Boolean = SessionPrefs.portrait(this) && !controlsBelowWanted() + private fun portraitOutput(): Boolean = SessionPrefs.portrait(this, SessionState.mode) && !controlsBelowWanted() private fun outputSize(): Pair = com.droiddeck.launcher.session.SessionDisplay.resolveChoice(com.droiddeck.launcher.session.SessionDisplay.panelSize(this), resolutionChoice(), portraitOutput()) - private fun resolutionChoice(portrait: Boolean = SessionPrefs.portrait(this)): String { + private fun resolutionChoice(portrait: Boolean = SessionPrefs.portrait(this, SessionState.mode)): String { val mode = displayMode() val program = intent.getStringExtra(SessionService.EXTRA_PROGRAM) return if (intent.getStringExtra(SessionService.EXTRA_MODE) == SessionService.MODE_RUN && @@ -3180,6 +3430,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun outputFpsLimit(): Int = outputFpsLimit(pipUi) + // Android holds the window to the Game Mode override while the panel runs faster; the guest paces to the panel, + // so without this cap every frame past the override is drawn and dropped. + private fun hostFrameCap(): Int { + if (glassesScreen != null || bottomOutputActive) return 0 + val display = (if (Build.VERSION.SDK_INT >= 30) display else @Suppress("DEPRECATION") windowManager.defaultDisplay) ?: return 0 + return SessionPrefs.hostFrameCap(display.refreshRate, display.mode.refreshRate) + } + + private fun compositorFpsLimit(): Int = SessionPrefs.compositorFpsLimit( + mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pipUi, hostFrameCap(), + ) + private fun outputFpsLimit(pip: Boolean): Int = SessionPrefs.compositorFpsLimit(mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pip) @@ -3217,7 +3479,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde ) val hz = refreshHz() val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f - CompositorHost.updatePacing(hz, outputFpsLimit()) + CompositorHost.updatePacing(hz, compositorFpsLimit(), outputFpsLimit()) pushCardboard(activeCardboard) if (changed && ::surfaceView.isInitialized) applyFrameGen() } @@ -3430,19 +3692,6 @@ 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()) @@ -3478,6 +3727,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun onSessionEnded(status: Int) { ended = true + runOnUiThread { refreshAirTriggers() } ++steamVrRequestGeneration if (isInPictureInPictureMode) { runOnUiThread { finish() } @@ -3535,6 +3785,7 @@ 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() @@ -3611,7 +3862,6 @@ 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 -> @@ -3622,7 +3872,6 @@ 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()) @@ -3644,9 +3893,6 @@ 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 @@ -3654,16 +3900,23 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } - override fun dispatchKeyEvent(event: KeyEvent): Boolean { + internal fun dispatchImeKeyEvent(event: KeyEvent): Boolean = dispatchKeyEvent(event, orderedImeKey = true) + + override fun dispatchKeyEvent(event: KeyEvent): Boolean = dispatchKeyEvent(event, orderedImeKey = false) + + private fun dispatchKeyEvent(event: KeyEvent, orderedImeKey: Boolean): Boolean { val normalized = com.droiddeck.launcher.input.GuestKeys.normalizeKeyboardEscape(event) - if (normalized === event) return dispatchSessionKeyEvent(event) + if (normalized === event) return dispatchSessionKeyEvent(event, orderedImeKey) if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) { Log.i(TAG, "hardware Esc normalized from Back device=${event.deviceId} scan=${event.scanCode}") } - return dispatchSessionKeyEvent(normalized) + return dispatchSessionKeyEvent(normalized, orderedImeKey) } - private fun dispatchSessionKeyEvent(event: KeyEvent): Boolean { + 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) { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_MUTE -> { @@ -3682,10 +3935,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, resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && - !inputSettingsOpen && !gestureSettingsOpen && !SessionState.suspended && !loading.visible) == true) return true + if (physicalInputBindings?.onKey(event, physicalInputAccepted()) == true) return true if (physicalShortcuts.onKey( event, enabled = resumed && SessionState.running && !SessionState.suspended && @@ -3746,7 +3999,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde return true } val pad = com.droiddeck.launcher.input.JoyCon.normalize(event) - if (pad !== event) return dispatchKeyEvent(pad) + if (pad !== event) return dispatchKeyEvent(pad, orderedImeKey) val fromController = PadBridge.isControllerKeyEvent(event) if (fromController && (menuOwnsController || pcKeyboardOpen || achievementsOpen || inputSettingsOpen || gestureSettingsOpen || SessionState.suspended)) { padBridge?.setInputEnabled(false) @@ -3788,7 +4041,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (fromController && (event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 || event.keyCode == KeyEvent.KEYCODE_BUTTON_R1)) { if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) { // The bumpers walk the tabs on the strip; a page kept inside More counts as the More tab. - val pages = sessionDrawerPages(glasses.present) + val pages = sessionDrawerPages(achievementsInFront != null) drawerPage = pages.strip().step(pages.tabFor(drawerPage), if (event.keyCode == KeyEvent.KEYCODE_BUTTON_R1) 1 else -1) releaseDrawerDirection() } @@ -3829,7 +4082,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val down = event.action == KeyEvent.ACTION_DOWN if (down && event.repeatCount > 0) return true val owner = if (event.deviceId <= 0) 16 else 8 - if (com.droiddeck.launcher.input.GuestKeys.send(event) { code, pressed -> sendGuestKey(code, pressed, owner) }) return true + if (com.droiddeck.launcher.input.GuestKeys.send(event) { code, pressed -> sendGuestKey(code, pressed, owner, orderedImeKey) }) return true } return super.dispatchKeyEvent(event) } @@ -3916,7 +4169,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 || - unfoldedColumn?.getChildAt(0)?.let { takes(it) { _, _ -> true } } == true + unfoldedKeys?.let { takes(it) { _, _ -> true } } == true } override fun dispatchTouchEvent(event: MotionEvent): Boolean { @@ -4910,6 +5163,7 @@ 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) @@ -4920,6 +5174,32 @@ 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() } @@ -4944,6 +5224,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private fun refreshControls() { + padConnected = controllerConnected() applyUnfoldedControls() updateOnScreenControls() } @@ -4959,12 +5240,9 @@ 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, tabRow, outputAspect) + val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height, aspect = outputAspect) else FrameLayout.LayoutParams.MATCH_PARENT val params = surfaceView.layoutParams as FrameLayout.LayoutParams if (params.height != gameHeight) { @@ -4981,6 +5259,7 @@ 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 @@ -4991,14 +5270,16 @@ 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 @@ -5009,13 +5290,6 @@ 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 @@ -5031,7 +5305,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, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)) + column.addView(it, column.indexOfChild(panel) + 1, android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)) } } @@ -5122,27 +5396,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } else { endGameField() } - host.type(text) - host.tap(KeyEvent.KEYCODE_ENTER) + if (text.isEmpty()) host.tap(KeyEvent.KEYCODE_ENTER) + else WaylandCompositor.textInputCommitAndSubmit(text) uiHandler.postDelayed({ if (AgentGuest.gameTextField && com.droiddeck.launcher.ui.WowChat.isWow(AgentGuest.gameProgram)) endGameField() }, FIELD_SETTLE_MS) } private fun endGameField() { - WaylandCompositor.nativeSendKey(KEY_END, 1) - WaylandCompositor.nativeSendKey(KEY_END, 0) + orderedImeKeySender(KEY_END, true) + orderedImeKeySender(KEY_END, false) } - private fun selectGameField(vararg then: Int) { - heldKeys.set(256, KEY_LEFTCTRL, true) - try { - for (key in intArrayOf(KEY_A) + then) { - heldKeys.set(256, key, true) - heldKeys.set(256, key, false) - } - } finally { heldKeys.release(256) } - } + private fun selectGameField(copy: Boolean = false) { WaylandCompositor.nativeSelectGameField(copy) } private fun readGameField(done: (String?) -> Unit) { val opened = wowChat.request @@ -5151,7 +5417,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (text != null && stillOpen()) endGameField() done(text) } - selectGameField(KEY_C) + selectGameField(copy = true) } private fun cancelWowChat() { @@ -5390,10 +5656,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var sessionTouchDown = false private var screenTapsClick = true - private fun onScreenLeftMouseButtonShown(): Boolean = listOfNotNull( + private fun inputSurfaces() = listOfNotNull( onScreenControls?.inputSurface, bottomInputControls?.inputSurface, unfoldedPanel?.inputSurface, unfoldedDeckSurface, secondScreenPresentation?.controlsView, swappedInputSurface, - ).any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) } + ) + + 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 + } override fun onTouchEvent(event: MotionEvent): Boolean = inSurfaceSpace(event) { handleTouch(event) } @@ -5850,7 +6126,11 @@ 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.onEditingChanged = { touchEditorChanged() } + view.alpha = onScreenOpacityAlpha() + view.onEditingChanged = { editing -> + view.alpha = if (editing) 1f else onScreenOpacityAlpha() + touchEditorChanged() + } view.onOptions = { options -> steamTouchOptions = options applyTouchRouting() @@ -5955,6 +6235,7 @@ 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)) } @@ -6054,11 +6335,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde releaseHeldKeys() } - private fun sendGuestKey(key: Int, down: Boolean, owner: Int = 1) { + private fun sendGuestKey(key: Int, down: Boolean, owner: Int = 1, orderedImeKey: Boolean = false) { if (down && pipUi) return val code = if (key == KEY_RIGHTCTRL && SessionState.mode == SessionService.MODE_DESKTOP) KEY_LEFTCTRL else key if (owner == 1) { if (down) guestKeysDown.add(code) else guestKeysDown.remove(code) } - heldKeys.set(owner, code, down) + val orderedSender = if (orderedImeKey) orderedImeKeySender else null + heldKeys.set(owner, code, down, orderedSender) + } + + private val orderedImeKeySender: (Int, Boolean) -> Unit = { code, down -> + WaylandCompositor.nativeSendKeyOrdered(code, if (down) 1 else 0) } private fun capturePausedFrame(manual: Boolean = false, onDone: () -> Unit = {}) { @@ -6126,7 +6412,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val back = { if (restore.compareAndSet(false, true)) { pauseCaptures-- - if (!isDestroyed) WaylandCompositor.nativeSetZeroCopy(composedOutputFree()) + if (!isDestroyed && zeroCopyActive()) WaylandCompositor.nativeSetZeroCopy(composedOutputFree()) } } uiHandler.postDelayed({ capturePausedFrame(manual = true, onDone = back) }, ZERO_COPY_SETTLE_MS) @@ -6180,7 +6466,12 @@ 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()) } @@ -6241,6 +6532,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde heldButtons.clear() hidePrimaryKeyboard() sessionClipboard.stop() + sessionTextInput.stop() padMotion?.stop() cursorVisible = false closeSecondScreen(reset = false) @@ -6256,7 +6548,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } else if (!isFinishing && !isDestroyed) { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) updateOnScreenControls() - if (resumed) { sessionClipboard.start(); updatePadMotion() } + if (resumed) { sessionClipboard.start(); sessionTextInput.start(); updatePadMotion() } if (started) { settleDualScreenControls() refreshSecondScreenDisplays() @@ -6326,7 +6618,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde displayManager.unregisterDisplayListener(displayListener) com.droiddeck.launcher.input.DualScreen.unwatchTaken(bottomScreenListener) contentResolver.unregisterContentObserver(refreshSettingObserver) - if (!screenIsOff()) closeSecondScreen(reset = false) + // 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) + sessionTextInput.stop() startedScreens = (startedScreens - 1).coerceAtLeast(0) updateGlassesScreen() updateBottomGame() @@ -6362,6 +6661,7 @@ 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) } @@ -6371,7 +6671,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } if (CompositorHost.isStarted) applyFrameGen(force = true) applyFollowOrientation(resources.configuration) + 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() @@ -6382,12 +6686,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } (getSystemService(INPUT_SERVICE) as? InputManager) ?.registerInputDeviceListener(deviceListener, Handler(Looper.getMainLooper())) + padConnected = controllerConnected() padBridge?.setStickDeadZone(ControllerPrefs.deadZone(this)) refreshSecondScreenDisplays() if (SessionState.guestPid > 1) padBridge?.syncConnectedControllers() joyConVr?.refresh() onScreenControls?.reload() controllerSettings = ControllerPrefs.read(this) + applyOnScreenOpacity() resumed = true boostGpuClock(panelOverGame) updateKeyboardRoute() @@ -6403,7 +6709,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onCancel = { padBridge?.cancelHomeGuide() }, ) updatePointerCapture() - if (!pipUi) sessionClipboard.start() + if (!pipUi) { sessionClipboard.start(); sessionTextInput.start() } updatePadMotion() ControllerPrefs.prefs(this).registerOnSharedPreferenceChangeListener(shortcutPrefListener) SessionPrefs.sessionPrefs(this).registerOnSharedPreferenceChangeListener(screenEffectsProfilePrefListener) @@ -6430,10 +6736,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } override fun onPause() { + uiHandler.removeCallbacks(questSteamVrRequest) departureCleanup() super.onPause() } + private val questSteamVrRequest = object : Runnable { + override fun run() { + if (com.droiddeck.launcher.session.QuestSteamVrLaunch.takeRequest(this@SessionActivity) && + SessionState.running && SessionState.mode == SessionService.MODE_STEAM) steamVrAction("start") + uiHandler.postDelayed(this, 1000) + } + } + private fun departureCleanup() { com.droiddeck.launcher.input.SystemKeyCapture.detach(this) com.droiddeck.launcher.input.HomeButtonShortcuts.detach(this) @@ -6462,7 +6777,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde heldButtons.clear() if (!screenOff) { val menuUp = menuShownOnBottom() - drawerOpen = false + if (!com.droiddeck.launcher.agent.AgentAttachments.picking) drawerOpen = false if (menuUp) SessionState.bottomMenu = true pcKeyboardOpen = false achievementsOpen = false @@ -6474,6 +6789,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (::scrollTouch.isInitialized) scrollTouch.cancel() if (::padMouse.isInitialized) padMouse.reset() resumed = false + refreshAirTriggers() boostGpuClock(false) updateKeyboardRoute() updatePointerCapture() @@ -6887,7 +7203,10 @@ 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 { swappedInputSurface = it } }, + surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()).also { + it.alpha = onScreenOpacityAlpha() + swappedInputSurface = it + } }, modifier = Modifier.fillMaxWidth().weight(1f), onRelease = { if (swappedInputSurface === it) swappedInputSurface = null }, ) @@ -7064,10 +7383,13 @@ 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) - goFullscreen() + applySessionFullscreen() refreshClipboard() } updatePointerCapture() @@ -7077,19 +7399,24 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (resumed) sessionClipboard.refresh() } - private fun goFullscreen() { + 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) @Suppress("DEPRECATION") - window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + window.decorView.systemUiVisibility = if (fullscreen) (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) + or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) else View.SYSTEM_UI_FLAG_LAYOUT_STABLE if (Build.VERSION.SDK_INT >= 28) { window.attributes = window.attributes.apply { - 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 + 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 + } } } } @@ -7111,6 +7438,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } override fun onDestroy() { + com.droiddeck.launcher.session.xr.XrPanels.clearMenuHost(this) + if (drawerXr) com.droiddeck.launcher.session.xr.XrPanels.hideMenu() uiHandler.removeCallbacks(panelHeldCheck) uiHandler.removeCallbacks(panelHeldRetry) synchronized(frameGenGlobalLock) { @@ -7123,6 +7452,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde gamescopeConvarRequests.shutdownNow() backQamInput.cancel() steamVrRecovery.close() + sessionTextInput.stop() uiHandler.removeCallbacks(steamTouchRetry) uiHandler.removeCallbacks(cursorResync) uiHandler.removeCallbacks(usbMouseFallback) @@ -7149,6 +7479,9 @@ 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 @@ -7235,6 +7568,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde const val EXTRA_RETURN_HOME = "returnHome" private const val BLUETOOTH_CONNECT = "android.permission.BLUETOOTH_CONNECT" private const val REQUEST_BLUETOOTH = 31 + private const val VR_OUTPUT_HEIGHT = 1080 const val EXTRA_LINK_TASK = "linkTask" const val EXTRA_STEAMVR = "steamVr" const val EXTRA_PLAYED_GAME = "com.droiddeck.launcher.PLAYED_GAME" diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentAccess.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentAccess.kt index 2113161467..9c4659a550 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentAccess.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentAccess.kt @@ -23,7 +23,7 @@ object AgentAccess { fun requireCommands(context: Context) { if (!commandsAllowed(context)) throw AgentException( "AGENT_COMMANDS_DISABLED", - "Debugging tools are off: turn on Setup > Developer > Debugging tools on the device", + "droiddeckctl is off: turn on Setup > Developer > droiddeckctl on the device", ) } diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt index b4f9a09dff..9c9dd5c150 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt @@ -19,6 +19,15 @@ object AgentAttachments { /** Guest paths waiting to go with the next message. */ val pending = mutableStateListOf() + /** 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") @@ -35,14 +44,17 @@ 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 target = File(dir, name) + var candidate = File(dir, name) var n = 1 - 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() + // 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() } } diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentChatActivity.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentChatActivity.kt new file mode 100644 index 0000000000..02f1a84e86 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentChatActivity.kt @@ -0,0 +1,48 @@ +package com.droiddeck.launcher.agent + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.core.AppUiPrefs +import com.droiddeck.launcher.ui.AgentPage +import com.droiddeck.launcher.ui.DroidDeckTheme + +/** + * The agent's chat in a window of its own, for Quest's flat mode: opened in its own task, it is a + * separate Horizon panel the user can move, resize and close like any other. + */ +class AgentChatActivity : ComponentActivity() { + override fun attachBaseContext(newBase: Context) { + super.attachBaseContext(newBase) + com.droiddeck.launcher.core.AppLanguage.applyTo(this, newBase) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + DroidDeckTheme(appScale = AppUiPrefs.scale(this)) { + AgentPage( + Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background).padding(horizontal = 12.dp, vertical = 6.dp), + visible = true, startTyping = AgentHost.entries.isEmpty(), + ) + } + } + } + + companion object { + fun open(context: Context) { + context.startActivity( + Intent(context, AgentChatActivity::class.java) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT), + ) + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt index abe8abb3a3..c1ad86bfc3 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt @@ -19,7 +19,7 @@ import java.util.UUID object AgentGuest { private val main by lazy { Handler(Looper.getMainLooper()) } var focusRevision by mutableIntStateOf(0) - private set + @androidx.annotation.VisibleForTesting internal set var steamKeyboard by mutableStateOf(false) private set var desktopTextField by mutableStateOf(false) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt index 80667afef0..22c30a994e 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt @@ -1,7 +1,6 @@ package com.droiddeck.launcher.agent import android.content.Context -import android.os.Environment import android.os.Handler import android.os.Looper import android.os.SystemClock @@ -76,7 +75,9 @@ 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." + "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 ![what it shows](/absolute/path.png) on a line of its own: " + + "DroidDeck draws the file in the chat." val entries = mutableStateListOf() val queue = mutableStateListOf() @@ -564,13 +565,12 @@ object AgentHost { (if (connectAdb) "adb start-server >/dev/null 2>&1; adb connect \"\$ADB_SERIAL\" >/dev/null 2>&1; " else "") + "cd \"$1\" 2>/dev/null; shift; exec \"$@\"", "sh", workdir, ) - val proot = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(), null, env + shell + command, fakeRoot) + val proot = LinuxRuntime.command(app, null, null, LinuxRuntime.sharedStorage(app), null, env + shell + command, fakeRoot) return ProcessBuilder(proot).redirectErrorStream(true).apply { environment().apply { 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) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentNative.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentNative.kt index 613cbe2c39..0d2fffc73e 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentNative.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentNative.kt @@ -14,8 +14,6 @@ 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) } diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt index 4a2e07b45b..ad78dd3d44 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt @@ -8,8 +8,11 @@ import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import com.droiddeck.launcher.R +import com.droiddeck.launcher.core.WirelessAdbFix import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.session.OrphanReaper +import com.droiddeck.launcher.session.QuestExperimental import java.io.File import java.util.concurrent.TimeUnit @@ -88,6 +91,8 @@ object AgentSetup { private fun completedKey(harness: AgentHarness) = "setup_completed_${harness.id}" private val main = Handler(Looper.getMainLooper()) + /** Advanced by every Allow, so a connection check started before it cannot overwrite what it found. */ + private var connectionGeneration = 0 private const val REPO = "https://github.com/Droid-Deck/DroidDeck.git" private const val CHECKOUT = "/root/DroidDeck" private val HELPERS = listOf("android-open", "dd-gh-login", "droiddeckctl", "droiddeck-scenario") @@ -104,6 +109,7 @@ object AgentSetup { val harness = AgentHost.harness keys = harness.keys(LinuxRuntime.rootDir(app)) val probes = mutableListOf>>() + val generation = connectionGeneration for (step in Step.entries) if (status[step] != Status.WORKING) { when (step) { Step.INSTALL -> set(step, if (harness.files.all { AgentHost.guestFileExists(app, it) }) Status.DONE else Status.TODO) @@ -114,7 +120,9 @@ object AgentSetup { detail.remove(step) Thread({ val live = com.droiddeck.launcher.core.WirelessAdbFix.liveConnectAddress(app) != null - set(step, if (live) Status.DONE else Status.TODO) + main.post { + if (generation == connectionGeneration && status[step] != Status.WORKING) status[step] = if (live) Status.DONE else Status.TODO + } }, "agent-connection").start() } else probes += step to listOf("sh", "-c", "for i in 1 2 3; do adb connect \"\$ADB_SERIAL\" >/dev/null 2>&1; " + @@ -123,7 +131,7 @@ object AgentSetup { Step.GITHUB -> probes += step to listOf("gh", "auth", "status") } } - Thread({ for ((step, command) in probes) probe(app, harness, step, command) }, "agent-checks").start() + Thread({ for ((step, command) in probes) probe(app, harness, step, command, generation) }, "agent-checks").start() } /** The last failed refresh ends the script: the installs after it would run from stale indexes and could report success. */ @@ -141,6 +149,22 @@ object AgentSetup { /** Runs [step]'s action. [CONNECTION] is the app's own pairing flow, so the caller opens it. */ fun run(context: Context, step: Step) = run(context, step, null) + /** The [Step.CONNECTION] action on a Quest, which has no pairing screen; see [WirelessAdbFix.trustOnDevice]. */ + fun trustOnDevice(context: Context) { + val app = context.applicationContext + connectionGeneration++ + status[Step.CONNECTION] = Status.WORKING + detail[Step.CONNECTION] = app.getString(R.string.agent_connection_quest_waiting) + Thread({ + val ok = runCatching { WirelessAdbFix.trustOnDevice(app) }.isSuccess + main.post { + status[Step.CONNECTION] = if (ok) Status.DONE else Status.FAILED + if (ok) detail.remove(Step.CONNECTION) else detail[Step.CONNECTION] = app.getString(R.string.agent_connection_quest_failed) + if (ok) check(app) + } + }, "agent-quest-trust").start() + } + /** Opens the page where a provider's key is made, as the sign-in of a harness that takes pasted keys. */ fun openKeyPage(context: Context, page: String) = run(context, Step.SIGN_IN, listOf("/root/.local/bin/android-open", page)) @@ -202,7 +226,18 @@ 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") - fun buildToolsInstalled(app: Context) = AgentHost.guestFileExists(app, "/root/aapt2/aapt2") && AgentHost.guestFileExists(app, "$CHECKOUT/.git") + /** + * 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) /** dd-lab-build compiled this install's commit, so a Lab build compiles only what changed. */ private fun prepared(app: Context) = runCatching { @@ -216,7 +251,7 @@ object AgentSetup { detail.clear() } - private fun probe(app: Context, harness: AgentHarness, step: Step, command: List) { + private fun probe(app: Context, harness: AgentHarness, step: Step, command: List, generation: Int) { var output = "" val ok = runCatching { val child = AgentHost.guest(app, command, connectAdb = step == Step.CONNECTION).start() @@ -232,11 +267,14 @@ object AgentSetup { }.onFailure { output = it.message.orEmpty() }.getOrDefault(false) main.post { if (AgentHost.harness != harness) return@post + // A running or newer Allow owns the row, including the instructions it shows while it waits. + if (step == Step.CONNECTION && (generation != connectionGeneration || status[step] == Status.WORKING)) return@post if (status[step] != Status.WORKING) status[step] = if (ok) Status.DONE else Status.TODO val last = output.lines().lastOrNull { it.isNotBlank() && !noise(it.trim()) }?.trim()?.take(160) when { ok -> detail.remove(step) - step == Step.CONNECTION -> detail[step] = app.getString(com.droiddeck.launcher.R.string.agent_connection_off) + step == Step.CONNECTION -> detail[step] = app.getString( + if (QuestExperimental.isSupported()) R.string.agent_connection_quest_off else R.string.agent_connection_off) step.required && last != null -> detail[step] = last } if (ready) AgentHost.prefs(app).edit().putBoolean(completedKey(harness), true).apply() diff --git a/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java b/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java index 8d9ddcb1f0..f87aefaa14 100644 --- a/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java +++ b/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java @@ -89,7 +89,7 @@ public class DirectAudioRelayComponent extends SessionPart { } } final java.io.PrintWriter log = out; - pid = HostProcess.start(command.toString(), env.toArray(new String[0]), + pid = HostProcess.startUncounted(command.toString(), env.toArray(new String[0]), app().getFilesDir(), null, line -> { Log.i(TAG, line); diff --git a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java index 53a0a6aacf..300a08b5f3 100644 --- a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java @@ -12,6 +12,7 @@ import com.droiddeck.launcher.core.TarZst; import java.io.File; import java.io.InputStream; import java.net.URL; +import java.nio.file.AtomicMoveNotSupportedException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -36,9 +37,15 @@ public class PulseAudioComponent extends SessionPart { private final HostLifecycle host = new HostLifecycle(Process::killProcess); static final class HostLifecycle { + static final int MAX_STARTUP_CRASH_RESTARTS = 4; + private static final long[] STARTUP_RESTART_DELAYS_MS = {250L, 1000L, 2000L, 4000L}; + volatile int pid = -1; private long generation; private long launches; + private boolean preferStandardPerformanceMode; + private boolean sinkReady; + private int startupCrashRestarts; private final IntConsumer terminate; final ReentrantReadWriteLock commands = new ReentrantReadWriteLock(); @@ -48,6 +55,9 @@ public class PulseAudioComponent extends SessionPart { synchronized long begin() { stop(); + preferStandardPerformanceMode = false; + sinkReady = false; + startupCrashRestarts = 0; return generation; } @@ -55,6 +65,7 @@ public class PulseAudioComponent extends SessionPart { generation++; if (pid > 1) terminate.accept(pid); pid = -1; + sinkReady = false; } boolean launch(long expected, IntSupplier launch) { @@ -63,6 +74,7 @@ public class PulseAudioComponent extends SessionPart { synchronized (this) { if (expected != generation) return false; launches++; + sinkReady = false; pid = launch.getAsInt(); return true; } @@ -93,11 +105,45 @@ public class PulseAudioComponent extends SessionPart { return token == launches && pid > 1; } + synchronized boolean preferStandardPerformanceMode() { + return preferStandardPerformanceMode; + } + + synchronized void markLowLatencyFailed(long token) { + if (token == launches && pid > 1) preferStandardPerformanceMode = true; + } + + synchronized void markSinkReady(long token) { + if (token == launches && pid > 1) { + sinkReady = true; + startupCrashRestarts = 0; + } + } + synchronized boolean exited(long expected) { if (expected != generation || pid <= 1) return false; pid = -1; return true; } + + /** + * Decides whether a dead host should be restarted and after how many milliseconds. + * Returns 0 for immediate recovery of a host that had a working sink, a positive backoff + * while falling back to standard AAudio mode after a startup crash, or -1 to stop retrying. + */ + synchronized long nextRestartDelayMs(long expected) { + if (expected != generation) return -1L; + if (sinkReady) { + sinkReady = false; + startupCrashRestarts = 0; + return 0L; + } + preferStandardPerformanceMode = true; + if (startupCrashRestarts >= MAX_STARTUP_CRASH_RESTARTS) return -1L; + long delay = STARTUP_RESTART_DELAYS_MS[Math.min(startupCrashRestarts, STARTUP_RESTART_DELAYS_MS.length - 1)]; + startupCrashRestarts++; + return delay; + } } public PulseAudioComponent(Context context) { @@ -167,11 +213,14 @@ public class PulseAudioComponent extends SessionPart { if (micFifoPath != null && !micFifoPath.isEmpty()) { new File(micFifoPath).delete(); } + boolean standardMode = host.preferStandardPerformanceMode(); + String initialPerformanceMode = standardMode ? "0" : "1"; ArrayList config = new ArrayList<>(); config.add("load-module module-native-protocol-unix auth-anonymous=1 auth-cookie-enabled=0 socket=\"" + socket().getAbsolutePath() + "\""); config.add(".nofail"); - config.add("load-module module-directaudio-native-sink sink_name=DirectAudio performance_mode=1 adaptive=1 decay=0 limiter=1 watchdog=1 volume=1.0 control_dir=" + deviceControls); + config.add("load-module module-directaudio-native-sink sink_name=DirectAudio performance_mode=" + + initialPerformanceMode + " adaptive=1 decay=0 limiter=1 watchdog=1 volume=1.0 control_dir=" + deviceControls); config.add("set-default-sink DirectAudio"); config.add(".fail"); if (micFifoPath != null && !micFifoPath.isEmpty()) { @@ -186,15 +235,36 @@ public class PulseAudioComponent extends SessionPart { env.add("LD_LIBRARY_PATH=/system/lib64:" + modules + ":" + workingDir.getAbsolutePath()); env.add("HOME=" + workingDir); env.add("TMPDIR=" + workingDir); + // The daemon closes every fd at start but this one; in a worker process it is the binder + // fd whose closing Android takes for the process's death. + env.add("PULSE_PASSED_FD=" + com.droiddeck.launcher.runtime.GuestWorker.BINDER_FD_TOKEN); String command = String.join(" ", HostProcess.dataExecutable(workingDir.getAbsolutePath() + "/libpulseaudio.so")) + " --system=false --disable-shm=true --fail=false" + " -n --file=default.pa --daemonize=false --use-pid-file=false --exit-idle-time=-1" + " --log-level=info"; final java.io.PrintWriter out = openLog(); - if (!host.launch(generation, () -> HostProcess.start(command, env.toArray(new String[0]), workingDir, status -> { + if (!host.launch(generation, () -> HostProcess.startUncounted(command, env.toArray(new String[0]), workingDir, status -> { if (host.exited(generation)) { - Log.w(TAG, "audio host exited with status " + status + "; restarting"); + long delayMs = host.nextRestartDelayMs(generation); + if (delayMs < 0) { + String msg = "audio host exited with status " + status + + " before a client sink came up too many times; not restarting again in this session"; + Log.w(TAG, msg); + note(out, msg); + return; + } + Log.w(TAG, "audio host exited with status " + status + "; restarting" + + (host.preferStandardPerformanceMode() ? " with standard AAudio mode" : "") + + (delayMs > 0 ? " in " + delayMs + " ms" : "")); + if (delayMs > 0) { + try { + Thread.sleep(delayMs); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return; + } + } start(generation); } }, @@ -208,6 +278,24 @@ public class PulseAudioComponent extends SessionPart { guard.start(); } + private boolean loadDirectAudioSink(long token, String performanceMode) { + if ("0".equals(performanceMode)) pactlOk(token, "unload-module", "module-directaudio-native-sink"); + String loaded = pactlFor(token, "load-module", "module-directaudio-native-sink", "sink_name=DirectAudio", + "performance_mode=" + performanceMode, + "adaptive=1", "decay=0", "limiter=1", "watchdog=1", "volume=1.0", "control_dir=" + deviceControls); + if (loaded == null) return false; + if (pactlOk(token, "set-default-sink", "DirectAudio")) return true; + String moduleId = loaded.trim(); + pactlOk(token, "unload-module", moduleId.matches("\\d+") ? moduleId : "module-directaudio-native-sink"); + return false; + } + + private boolean loadPlainAAudioSink(long token, String performanceMode) { + return pactlOk(token, "load-module", "module-aaudio-sink", "sink_name=AAudioSink", + "performance_mode=" + performanceMode, "adaptive=1", "volume=1.0", "control_dir=" + deviceControls) + && pactlOk(token, "set-default-sink", "AAudioSink"); + } + private void ensureClientSink(java.io.PrintWriter out, long token) { try { // Nothing that may block (a sink whose AAudio open hangs: a Galaxy S24 FE (US) hung the @@ -229,27 +317,42 @@ public class PulseAudioComponent extends SessionPart { if (sinks == null) { line = "== client sink: the daemon did not answer in 30 s; no fallback attempted"; } else if (sinks.contains("\tDirectAudio\t") || sinks.startsWith("DirectAudio\t") || sinks.contains("\tDirectAudio\n") || sinks.matches("(?s).*\\bDirectAudio\\b.*")) { - line = "== client sink: DirectAudio (module-directaudio-native-sink)"; + host.markSinkReady(token); + line = "== client sink: DirectAudio (module-directaudio-native-sink" + + (host.preferStandardPerformanceMode() ? ", standard mode" : "") + ")"; } else { // AAudio can refuse the first open with AAUDIO_ERROR_DISCONNECTED while Android is - // still switching the output route as the session starts (seen on a Galaxy S24 FE): - // try DirectAudio again, then the plain sink, a few times over ten seconds. + // still switching the output route (Galaxy S24 FE) or when low-latency MMAP output + // is rejected by the HAL (Samsung One UI). Retry low-latency once if it hasn't been + // disqualified yet, then fall back to performance_mode=0 (non-MMAP) on DirectAudio + // before trying the plain AAudio sink. String loadedAs = null; for (int attempt = 1; attempt <= 5 && loadedAs == null && host.live(token); attempt++) { try { Thread.sleep(2000L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } - if (pactlOk(token, "load-module", "module-directaudio-native-sink", "sink_name=DirectAudio", "performance_mode=1", - "adaptive=1", "decay=0", "limiter=1", "watchdog=1", "volume=1.0", "control_dir=" + deviceControls) - && pactlOk(token, "set-default-sink", "DirectAudio")) { - loadedAs = "DirectAudio on attempt " + attempt; - } else if (pactlOk(token, "load-module", "module-aaudio-sink", "sink_name=AAudioSink", - "performance_mode=" + (attempt == 1 ? "1" : "0"), "adaptive=1", "volume=1.0", "control_dir=" + deviceControls) - && pactlOk(token, "set-default-sink", "AAudioSink")) { - loadedAs = "the plain AAudio sink (AAudioSink) on attempt " + attempt; + if (!host.live(token)) break; + if (attempt == 1 && !host.preferStandardPerformanceMode()) { + if (loadDirectAudioSink(token, "1")) { + loadedAs = "DirectAudio on attempt " + attempt; + break; + } + if (!host.live(token)) break; + host.markLowLatencyFailed(token); + } + if (loadDirectAudioSink(token, "0")) { + loadedAs = "DirectAudio (standard mode) on attempt " + attempt; + } else if (host.live(token) && loadPlainAAudioSink(token, "0")) { + loadedAs = "the plain AAudio sink (AAudioSink, standard mode) on attempt " + attempt; } } - line = loadedAs != null ? "== client sink: DirectAudio did not come up at start; retried and got " + loadedAs - : "== client sink: DirectAudio did not come up and the AAudio fallback failed too after 5 retries - no client sound." - + " If audio.log shows AAUDIO_ERROR_DISCONNECTED, Android refused the audio output: rebooting the phone usually fixes this"; + if (loadedAs != null) { + host.markSinkReady(token); + line = "== client sink: DirectAudio did not come up at start; retried and got " + loadedAs; + } else if (!host.live(token)) { + line = "== client sink: audio host exited during sink recovery"; + } else { + line = "== client sink: DirectAudio did not come up and the AAudio fallback failed too after 5 retries - no client sound." + + " If audio.log shows AAUDIO_ERROR_DISCONNECTED, Android refused the audio output: rebooting the phone usually fixes this"; + } Log.w(TAG, line); } Log.i(TAG, line); @@ -404,11 +507,22 @@ public class PulseAudioComponent extends SessionPart { continue; } File destination = new File(workingDir, lib); + File temp = null; try (InputStream in = resource.openStream()) { - Files.copy(in, destination.toPath(), StandardCopyOption.REPLACE_EXISTING); - FileUtils.chmod(destination, 0771); + temp = File.createTempFile(lib + ".", ".tmp", workingDir); + Files.copy(in, temp.toPath(), StandardCopyOption.REPLACE_EXISTING); + FileUtils.chmod(temp, 0771); + try { + Files.move(temp.toPath(), destination.toPath(), + StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); + } catch (AtomicMoveNotSupportedException e) { + Files.move(temp.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + temp = null; } catch (Exception e) { Log.w(TAG, "copy " + lib, e); + } finally { + if (temp != null) temp.delete(); } } } diff --git a/app/src/main/java/com/droiddeck/launcher/core/CpuFeatures.kt b/app/src/main/java/com/droiddeck/launcher/core/CpuFeatures.kt new file mode 100644 index 0000000000..e8cd318bc2 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/core/CpuFeatures.kt @@ -0,0 +1,17 @@ +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) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt index db8ab970a2..46b74fbafa 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt @@ -27,6 +27,7 @@ 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" @@ -36,6 +37,10 @@ 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)) @@ -129,6 +134,7 @@ 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(", ")) @@ -186,6 +192,7 @@ 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")) @@ -284,9 +291,12 @@ 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("proot without seccomp", SessionPrefs.prootNoSeccomp(context)) - k("native userland (no proot)", SessionPrefs.nativeUserland(context)) - k("proot fast path", SessionPrefs.prootFastPath(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 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)) diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt index 55e7e61284..711a50eca3 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt @@ -61,7 +61,19 @@ object GameEnvironment { } fun effective(config: Config, preset: String, scope: String, forceSsbs: Boolean = false): Map = - defaults(preset, forceSsbs) + config.shared + if (scope.isEmpty()) emptyMap() else config.games[scope].orEmpty() + defaults(preset, forceSsbs) + config.shared + if (scope.isEmpty()) emptyMap() else knownGames[scope].orEmpty() + config.games[scope].orEmpty() + + /** + * What some Steam games need here whatever the shared settings say; the game's own settings still win. + * GTA III dies at 0042A703 when a new game starts with FEX's reduced x87 precision, as the Rockstar store copy does. + */ + val knownGames: Map> = mapOf( + "12100" to mapOf("FEX_X87REDUCEDPRECISION" to "0"), + ) + + /** [config] with [knownGames] folded under each game's own settings, for the guest to read. */ + fun withKnownGames(config: Config): Config = + config.copy(games = config.games + knownGames.mapValues { (scope, known) -> known + config.games[scope].orEmpty() }) fun hasOverride(config: Config, scope: String, name: String): Boolean = scope.isNotEmpty() && config.entries(scope).containsKey(name) @@ -78,7 +90,7 @@ object GameEnvironment { val entries = config.games[scope].orEmpty() if (FexPreset.environmentKeys.none(entries::containsKey)) return null return FexPreset.all.firstOrNull { preset -> - val expected = FexPreset.environment(preset.id) + val expected = presetFor(scope, preset.id) FexPreset.environmentKeys.all { key -> entries.containsKey(key) && entries[key] == expected[key] } }?.id ?: CUSTOM_FEX_PRESET } @@ -88,12 +100,16 @@ object GameEnvironment { require(preset == null || FexPreset.all.any { it.id == preset }) val entries = config.entries(scope).filterKeys { it !in FexPreset.environmentKeys }.toMutableMap() if (preset != null) { - val values = FexPreset.environment(preset) + val values = presetFor(scope, preset) FexPreset.environmentKeys.forEach { key -> entries[key] = values[key] } } return config.withEntries(scope, entries) } + /** A FEX preset as a game gets it: picking one never undoes a fix the game is known to need. */ + private fun presetFor(scope: String, preset: String): Map = + FexPreset.environment(preset) + knownGames[scope].orEmpty().filterKeys { it in FexPreset.environmentKeys } + const val CUSTOM_FEX_PRESET = "__custom__" val syncBackends = listOf(SessionPrefs.SYNC_NTSYNC, SessionPrefs.SYNC_FSYNC, SessionPrefs.SYNC_ESYNC, SessionPrefs.SYNC_WINESERVER) diff --git a/app/src/main/java/com/droiddeck/launcher/core/GlobalSettings.kt b/app/src/main/java/com/droiddeck/launcher/core/GlobalSettings.kt index 3e4bb53051..1daf377fb7 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GlobalSettings.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GlobalSettings.kt @@ -1,6 +1,7 @@ package com.droiddeck.launcher.core import android.content.Context +import android.content.pm.PackageManager import android.net.Uri import android.provider.Settings @@ -19,4 +20,14 @@ object GlobalSettings { fun developerOptionsOn(context: Context): Boolean = isOn(context, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED) fun wirelessDebuggingOn(context: Context): Boolean = isOn(context, "adb_wifi_enabled") + + /** + * True when it was off and is now on. Quest only, where Settings has no switch for it; it needs + * WRITE_SECURE_SETTINGS granted over adb. + */ + fun turnOnWirelessDebugging(context: Context): Boolean { + if (!com.droiddeck.launcher.session.QuestExperimental.isSupported() || wirelessDebuggingOn(context)) return false + if (context.checkSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) != PackageManager.PERMISSION_GRANTED) return false + return runCatching { Settings.Global.putInt(context.contentResolver, "adb_wifi_enabled", 1) }.getOrDefault(false) + } } diff --git a/app/src/main/java/com/droiddeck/launcher/core/HostProcess.kt b/app/src/main/java/com/droiddeck/launcher/core/HostProcess.kt index d4a2cdc66d..d3a03036a3 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/HostProcess.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/HostProcess.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.core +import android.os.ParcelFileDescriptor import android.util.Log import java.io.File import java.util.function.Consumer @@ -7,6 +8,9 @@ import java.util.function.Consumer object HostProcess { private const val TAG = "HostProcess" private const val LINKER = "/system/bin/linker64" + // sh -c WORKER_CD sh DIR NAME=VALUE... -- PROGRAM ARGS... + private const val WORKER_CD = "cd \"\$1\" || exit 126; shift; " + + "while [ \$# -gt 0 ] && [ \"\$1\" != -- ]; do export \"\$1\"; shift; done; shift; exec \"\$@\"" /** Android 10+ refuses to execute app data files for targetSdk 29+; its linker still loads them. */ @JvmStatic @@ -65,6 +69,77 @@ object HostProcess { } } + /** + * As [start], but the program runs as the main process of one of the app's worker processes, + * which Android does not count against the app's child processes (docs/phantom-processes.md). + * Falls back to [start] when no worker is available. The exit status is the program's exit + * code, or 128 plus the signal that ended it, as Process.waitFor() reports it. + */ + @JvmStatic + @JvmOverloads + fun startUncounted(command: String, env: Array?, dir: File?, onExit: Consumer?, onLine: Consumer?, + outputFile: File? = null, onOutputComplete: Runnable? = null): Int { + val context = com.droiddeck.launcher.runtime.GuestWorkers.context + val argv = split(command) + // A missing working directory fails the launch (start() returns -1 for it), not the program + if (context == null || argv.isEmpty() || !com.droiddeck.launcher.runtime.GuestWorkers.enabled(context) || + (dir != null && !dir.isDirectory)) { + return start(command, env, dir, onExit, onLine, outputFile, onOutputComplete) + } + val environment = LinkedHashMap(System.getenv()) + env?.forEach { line -> + val eq = line.indexOf('=') + if (eq > 0) environment[line.substring(0, eq)] = line.substring(eq + 1) + } + val assignments = environment.map { (k, v) -> "$k=$v" } + // A worker cannot chdir before its exec, so Android's shell does it. The shell starts with an + // environment of its own (the program's LD_PRELOAD of glibc libraries would stop it loading) + // and exports the program's before the exec. + val launch = if (dir != null) { + listOf("/system/bin/sh", "-c", WORKER_CD, "sh", dir.path) + assignments + listOf("--") + argv + } else argv + val workerEnv = if (dir != null) listOf("PATH=/system/bin") else assignments + var input: ParcelFileDescriptor? = null + var reader: ParcelFileDescriptor? = null + var output: ParcelFileDescriptor? = null + val pid = try { + input = ParcelFileDescriptor.open(File("/dev/null"), ParcelFileDescriptor.MODE_READ_ONLY) + output = when { + onLine != null -> ParcelFileDescriptor.createPipe().let { reader = it[0]; it[1] } + outputFile != null -> ParcelFileDescriptor.open(outputFile, + ParcelFileDescriptor.MODE_WRITE_ONLY or ParcelFileDescriptor.MODE_CREATE or ParcelFileDescriptor.MODE_APPEND) + else -> ParcelFileDescriptor.open(File("/dev/null"), ParcelFileDescriptor.MODE_WRITE_ONLY) + } + com.droiddeck.launcher.runtime.GuestWorkers.start(context, launch, workerEnv, listOf(input, output, output)) { status -> + onExit?.accept(if (status < 0) -1 else if (status and 0x7f == 0) (status shr 8) and 0xff else 128 + (status and 0x7f)) + } + } catch (e: Exception) { + Log.w(TAG, "no worker for ${argv.first()}", e) + -1 + } finally { + runCatching { input?.close() } + runCatching { output?.close() } + } + if (pid <= 0) { + reader?.close() + return start(command, env, dir, onExit, onLine, outputFile, onOutputComplete) + } + Log.i(TAG, "started pid $pid outside the child-process count: ${argv.first()} (${argv.size - 1} arguments)") + reader?.let { pipe -> + Thread({ + try { + ParcelFileDescriptor.AutoCloseInputStream(pipe).bufferedReader().useLines { lines -> + lines.forEach { onLine?.accept(it) } + } + } catch (e: Exception) { + } finally { + onOutputComplete?.run() + } + }, "proc-out-$pid").apply { priority = Thread.NORM_PRIORITY - 1; isDaemon = true; start() } + } + return pid + } + @JvmStatic fun pidOf(process: Process): Int = try { val field = process.javaClass.getDeclaredField("pid") diff --git a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt index 6e67ff495d..5bcc716d1e 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt @@ -7,6 +7,8 @@ import com.droiddeck.launcher.R enum class PhantomProcessStatus { NOT_APPLICABLE, + /** The limit is on, but the session keeps its programs out of Android's count (GuestWorkers). */ + UNCOUNTED, DISABLED, ENABLED, UNSET, @@ -57,6 +59,12 @@ object PhantomProcessLimit { fun read(context: Context, sdk: Int = Build.VERSION.SDK_INT): PhantomProcessStatus { if (sdk < Build.VERSION_CODES.S) return PhantomProcessStatus.NOT_APPLICABLE + val status = readSetting(context, sdk) + return if (status != PhantomProcessStatus.DISABLED && com.droiddeck.launcher.runtime.GuestWorkers.limitHandled(context)) + PhantomProcessStatus.UNCOUNTED else status + } + + private fun readSetting(context: Context, sdk: Int): PhantomProcessStatus { if (usesDeviceConfig(sdk)) { val off = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(PREF_ANDROID_12_OFF, false) val global = try { @@ -101,7 +109,8 @@ object PhantomProcessLimit { fun hasDeveloperToggle(sdk: Int = Build.VERSION.SDK_INT): Boolean = sdk >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE fun blocksSteam(status: PhantomProcessStatus): Boolean = - status != PhantomProcessStatus.NOT_APPLICABLE && status != PhantomProcessStatus.DISABLED + status != PhantomProcessStatus.NOT_APPLICABLE && status != PhantomProcessStatus.DISABLED && + status != PhantomProcessStatus.UNCOUNTED fun title(context: Context, status: PhantomProcessStatus): String = context.getString(when (status) { PhantomProcessStatus.ENABLED -> R.string.phantom_title_on @@ -109,6 +118,7 @@ object PhantomProcessLimit { PhantomProcessStatus.UNREADABLE -> R.string.phantom_title_unreadable PhantomProcessStatus.DISABLED -> R.string.phantom_title_off PhantomProcessStatus.NOT_APPLICABLE -> R.string.phantom_title_not_required + PhantomProcessStatus.UNCOUNTED -> R.string.phantom_title_uncounted }) fun instructions(context: Context, status: PhantomProcessStatus): String = when (status) { @@ -116,6 +126,7 @@ object PhantomProcessLimit { context.getString(R.string.phantom_instructions_fix, fixSentence(context)) PhantomProcessStatus.DISABLED -> context.getString(R.string.phantom_instructions_off) PhantomProcessStatus.NOT_APPLICABLE -> context.getString(R.string.phantom_instructions_not_applicable) + PhantomProcessStatus.UNCOUNTED -> context.getString(R.string.phantom_instructions_uncounted) } fun gateInstructions(context: Context, status: PhantomProcessStatus): String = when (status) { @@ -132,5 +143,6 @@ object PhantomProcessLimit { PhantomProcessStatus.UNSET -> "not set (ROM default applies; DroidDeck requires an explicit disabled value)" PhantomProcessStatus.UNREADABLE -> "unreadable (DroidDeck could not verify the setting)" PhantomProcessStatus.NOT_APPLICABLE -> "not applicable before Android 12" + PhantomProcessStatus.UNCOUNTED -> "on, not needed (most of the session's programs run in uncounted worker processes)" } } diff --git a/app/src/main/java/com/droiddeck/launcher/core/SessionLogCapture.kt b/app/src/main/java/com/droiddeck/launcher/core/SessionLogCapture.kt index 650a6b8d4d..42524b5dcb 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/SessionLogCapture.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/SessionLogCapture.kt @@ -28,17 +28,18 @@ object SessionLogCapture { out.flush() writer = out this.target = target - pid = HostProcess.start( + pid = HostProcess.startUncounted( command(Process.myPid(), sinceMillis), null, target.parentFile, null, - ) { line -> - synchronized(this) { - try { - writer?.apply { write(line); newLine(); flush() } - } catch (e: Exception) { + onLine = { line -> + synchronized(this) { + try { + writer?.apply { write(line); newLine(); flush() } + } catch (e: Exception) { + } } - } - } + }, + ) if (pid == -1) { out.write("logcat could not be started; this ROM may not hand an app its own entries.\n") out.flush() diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt index 5c8b32f7ba..e9f8bbdfaa 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt @@ -22,6 +22,9 @@ object WirelessAdbFix { private const val HOST_FILE = "wireless-adb-host.txt" private const val CONNECTION_FILE = "wireless-adb-connection.txt" const val LOOPBACK = "127.0.0.1" + private const val TCP_PORT = 5555 + private const val WIRELESS_START_MS = 2_000L + private const val NETWORK_PROMPT_MS = 30_000L private data class SavedConnection(val host: String, val port: Int?) @@ -55,6 +58,23 @@ object WirelessAdbFix { writeAtomically(context, File(context.noBackupFilesDir, CONNECTION_FILE), ByteArray(0)) } + /** + * Quest has no pairing screen. adbd in TCP mode (`adb tcpip 5555`) asks "Allow debugging?" for an + * unknown key, and Wireless debugging accepts a key allowed there, so this stands in for pairing. + * Blocks until the prompt is answered or times out. + */ + fun trustOnDevice(context: Context) { + val app = context.applicationContext + // Already trusted, as after a reboot: Wireless debugging takes the key, and port 5555 is closed by then. + val live = if (savedConnection(app) != null) liveConnectAddress(app) else null + if (live != null && acceptsKey(app, live.substringBeforeLast(':').trim('[', ']'), live.substringAfterLast(':').toInt())) return + GlobalSettings.turnOnWirelessDebugging(app) + loadOrCreateIdentity(app) + Kadb.create(LOOPBACK, TCP_PORT, 2_000, 120_000).use { check(it.shell("true").exitCode == 0) } + writeAtomically(app, File(app.noBackupFilesDir, HOST_FILE), LOOPBACK.toByteArray()) + writeAtomically(app, File(app.noBackupFilesDir, CONNECTION_FILE), ByteArray(0)) + } + private fun savedConnection(context: Context): SavedConnection? { val directory = context.applicationContext.noBackupFilesDir if (!File(directory, CERT_FILE).isFile || !File(directory, KEY_FILE).isFile) return null @@ -78,10 +98,17 @@ object WirelessAdbFix { fun liveConnectAddress(context: Context): String? { val app = context.applicationContext val saved = savedConnection(app) ?: return null + val turnedOn = GlobalSettings.turnOnWirelessDebugging(app) val host = if (':' in saved.host) "[${saved.host}]" else saved.host - saved.port?.takeIf { answers(saved.host, it) }?.let { return "$host:$it" } + if (!turnedOn) saved.port?.takeIf { answers(saved.host, it) }?.let { return "$host:$it" } val loopback = runCatching { InetAddress.getByName(saved.host).isLoopbackAddress }.getOrDefault(false) - val port = if (loopback) loopbackAdbPort(app) else findConnectPort(app, saved.host, accept = { answers(saved.host, it) }) + // Turning it on can first ask "Allow wireless debugging on this network?", so keep looking while that is answered. + val deadline = android.os.SystemClock.elapsedRealtime() + if (turnedOn) NETWORK_PROMPT_MS else 0L + var port: Int? + do { + if (turnedOn) Thread.sleep(WIRELESS_START_MS) + port = if (loopback) loopbackAdbPort(app) else findConnectPort(app, saved.host, accept = { answers(saved.host, it) }) + } while (port == null && android.os.SystemClock.elapsedRealtime() < deadline) port ?: return null saveConnection(app, saved.host, port) return "$host:$port" @@ -92,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): Int? { + private fun loopbackAdbPort(app: Context, exclude: Int? = null): Int? { val open = java.util.concurrent.ConcurrentLinkedQueue() val workers = 32 val range = EPHEMERAL_PORTS @@ -100,15 +127,17 @@ object WirelessAdbFix { Thread { var port = range.first + worker while (port <= range.last) { - if (answers(LOOPBACK, port, 150)) open += port + if (port != exclude && answers(LOOPBACK, port, 150)) open += port port += workers } }.apply { start() } }.forEach { it.join() } + return open.sorted().firstOrNull { port -> acceptsKey(app, LOOPBACK, port) } + } + + private fun acceptsKey(app: Context, host: String, port: Int): Boolean { loadOrCreateIdentity(app) - return open.sorted().firstOrNull { port -> - runCatching { Kadb.create(LOOPBACK, port, 1_000, 3_000).use { it.shell("true").exitCode == 0 } }.getOrDefault(false) - } + return runCatching { Kadb.create(host, port, 1_000, 3_000).use { it.shell("true").exitCode == 0 } }.getOrDefault(false) } private val EPHEMERAL_PORTS = 32768..60999 @@ -133,8 +162,28 @@ object WirelessAdbFix { }.getOrDefault(address is Inet4Address) fun localConnectPort(context: Context): Int? = - tlsPortProperty() - ?: findConnectPort(context, LOOPBACK) + 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 + } private fun tlsPortProperty(): Int? = runCatching { Class.forName("android.os.SystemProperties").getMethod("get", String::class.java) @@ -272,14 +321,14 @@ object WirelessAdbFix { if (cachedPort != null) { val cachedResult = runCatching { action(appContext, saved.host, cachedPort) } if (cachedResult.isSuccess) return - val discoveredPort = findConnectPort(appContext, saved.host) + val discoveredPort = discoverConnectPort(appContext, saved.host, exclude = cachedPort) if (discoveredPort != null && discoveredPort != cachedPort) { action(appContext, saved.host, discoveredPort) } else { cachedResult.getOrThrow() } } else { - val discoveredPort = findConnectPort(appContext, saved.host) + val discoveredPort = discoverConnectPort(appContext, saved.host) ?: error(appContext.getString(R.string.adbfix_enter_address)) action(appContext, saved.host, discoveredPort) } diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt index f7097dce7c..d1e2d911e8 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt @@ -4,20 +4,23 @@ 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) = @@ -37,6 +40,8 @@ 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 @@ -46,13 +51,21 @@ class WirelessAdbPairingService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - ACTION_CODE -> { - val code = RemoteInput.getResultsFromIntent(intent)?.getCharSequence(KEY_CODE) - ?.filter(Char::isDigit)?.toString().orEmpty() - onCode(code) + 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_CANCEL -> finish(Stage.Idle) - else -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true) + null -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true) + else -> if (discovery == null && !working) stopSelf(startId) } return START_NOT_STICKY } @@ -60,11 +73,13 @@ 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) @@ -101,9 +116,13 @@ 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 (current.value !is Stage.CodeNeeded) show(Stage.CodeNeeded()) + if (endpointChanged) { + resetKeypad() + show(Stage.CodeNeeded()) + } } } } @@ -117,11 +136,12 @@ class WirelessAdbPairingService : Service() { show(Stage.Waiting) return } - if (code.length != 6) { + if (code.length != WirelessPairingKeypad.LENGTH) { 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))) @@ -155,17 +175,34 @@ class WirelessAdbPairingService : Service() { }, "wireless-adb-pairing").start() } - private fun show(stage: Stage) { + private fun show(stage: Stage, quietUpdate: Boolean = false) { publish(stage) - getSystemService(NotificationManager::class.java)?.notify(NOTIFICATION_ID, notification(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() } 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) @@ -183,13 +220,16 @@ 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): Notification { + private fun notification( + stage: Stage, quietUpdate: Boolean = false, foregroundCodeEntry: Boolean = false, + ): Notification { val manager = getSystemService(NotificationManager::class.java) manager?.createNotificationChannel(NotificationChannel(CHANNEL_ID, getString(R.string.adbpair_channel_name), NotificationManager.IMPORTANCE_HIGH).apply { @@ -205,7 +245,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 = stage == Stage.Waiting || stage == Stage.Idle || stage is Stage.Working + val quiet = foregroundCodeEntry || 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) @@ -220,19 +260,31 @@ 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 (stage.error == null) R.string.adbpair_title_code else R.string.adbpair_title_retry)) - .setContentText(text) - .setStyle(Notification.BigTextStyle().bigText(text)) + .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) .setOngoing(true) - .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()) + .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)) + } + } + } } is Stage.Working -> builder .setContentTitle(getString(R.string.adbpair_title_working)) @@ -254,14 +306,39 @@ 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_CODE = "com.droiddeck.launcher.action.WIRELESS_ADB_CODE" + private const val ACTION_KEYPAD = "com.droiddeck.launcher.action.WIRELESS_ADB_KEYPAD" 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 @@ -288,7 +365,7 @@ class WirelessAdbPairingService : Service() { fun notificationsEnabled(context: Context): Boolean = context.getSystemService(NotificationManager::class.java)?.areNotificationsEnabled() != false && !channelBlocked(context) - /** The code is typed into a notification on this channel; a channel the user switched off leaves pairing with nothing to type into. */ + /** Pairing needs this notification channel to show the keypad over Android Settings. */ fun channelBlocked(context: Context): Boolean = context.getSystemService(NotificationManager::class.java)?.getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt new file mode 100644 index 0000000000..942911a78d --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt @@ -0,0 +1,29 @@ +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 + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt b/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt index de95eea354..94ea2e33f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt +++ b/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt @@ -8,9 +8,27 @@ import android.os.Environment import android.provider.Settings object AllFilesAccess { + private val VOLUME = Regex("^(/storage/emulated/\\d+|/storage/[^/]+|/sdcard)(/.*)?$") + private val APP_FOLDERS = listOf("/Android/data", "/Android/obb") + 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 + return APP_FOLDERS.none { inside == it || inside.startsWith("$it/") } + } + fun open(context: Context) { val app = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:" + context.packageName)) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) diff --git a/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt b/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt index 7025769d87..c872096533 100644 --- a/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt @@ -504,13 +504,15 @@ fun FileManagerScreen( } val drives = remember(storageTick) { StorageRoots.list(context) } var accessDrive by remember { mutableStateOf(null) } + var accessWasMissing by remember { mutableStateOf(AllFilesAccess.missing()) } + var accessDeclined by remember { mutableStateOf(false) } fun unreadable(drive: StorageRoot) { if (AllFilesAccess.missing()) accessDrive = drive.label else Toast.makeText(context, context.getString(R.string.fm_drive_not_readable, drive.label), Toast.LENGTH_SHORT).show() } accessDrive?.let { label -> OutlinedAlertDialog( - onDismissRequest = { accessDrive = null }, + onDismissRequest = { accessDrive = null; accessDeclined = true }, title = { Text(stringResource(R.string.fm_drive_access_title, label)) }, text = { Text(stringResource(R.string.fm_drive_access_text)) }, confirmButton = { @@ -519,9 +521,17 @@ fun FileManagerScreen( AllFilesAccess.open(context) }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.upd_open_settings)) } }, - dismissButton = { TextButton(onClick = { accessDrive = null }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } }, + dismissButton = { TextButton(onClick = { accessDrive = null; accessDeclined = true }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } }, ) } + LaunchedEffect(currentDir, storageTick) { + if (!AllFilesAccess.missing()) { + if (accessWasMissing) { accessWasMissing = false; loadDirectory(currentDir, resetScroll = false, record = false) } + } else { + accessWasMissing = true + if (!accessDeclined && accessDrive == null && AllFilesAccess.covers(currentDir.path)) accessDrive = drives.firstOrNull { currentDir.path.startsWith(it.dir.path) }?.label ?: context.getString(R.string.fm_drive_internal) + } + } val linuxRoot = remember(storageTick) { com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context).takeIf { File(it, "usr").isDirectory } } diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt index 8b86eccf4e..b26c2536cc 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -499,6 +499,7 @@ object AddedGames { launchOptions = when { sidecar == null -> SessionPrefs.addedGameLaunch(context, folder.path) sidecar.store == Store.UBISOFT -> com.droiddeck.launcher.stores.ubisoft.UbisoftConnect.launchOptions(context) + sidecar.store == Store.EA -> SessionPrefs.addedGameLaunch(context, folder.path) else -> "" }, single = single != null, steamProgram = steamProgram)) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt index 25124a6a52..2ae97cfc4f 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt @@ -10,11 +10,13 @@ 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) @@ -69,6 +71,14 @@ 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() @@ -80,6 +90,7 @@ 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) } @@ -104,6 +115,7 @@ 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 @@ -111,7 +123,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_problem_missing else R.string.lsfg_problem_failed, + if (status == LsfgNative.STATUS_NOT_INSTALLED) R.string.lsfg_needs_steam else R.string.lsfg_problem_failed, ) Log.w(TAG, "$problem (status $status)") return problem @@ -127,6 +139,11 @@ 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") diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/Lossless.kt b/app/src/main/java/com/droiddeck/launcher/gpu/Lossless.kt index f78cb629ee..352885f558 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/Lossless.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/Lossless.kt @@ -2,22 +2,16 @@ 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 { - 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) { + data class State(val owned: Boolean, val ready: Boolean) { companion object { - val NONE = State(owned = false, ready = false, source = Source.NONE) + val NONE = State(owned = false, ready = false) } } @@ -26,15 +20,13 @@ 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 { - 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 state(context: Context) = State(owned(context), cacheFile(context)?.isFile == true) fun owned(context: Context): Boolean { if (prefs(context).getBoolean(KEY_OWNED, false)) return true @@ -43,61 +35,46 @@ object Lossless { return true } - fun cacheFile(context: Context): File? = prefs(context).getString(KEY_ID, null)?.let { cacheFor(context, it) } + 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 + } @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 != prefs(context).getString(KEY_STEAM_STAMP, null)) { - val status = adopt(context, steam, Source.STEAM) + if (stamp != settings.getString(KEY_STEAM_STAMP, null)) { + val status = adoptSteamDll(context, steam) if (status != LsfgNative.STATUS_OK && status != UNCHANGED) { Log.w(TAG, "Steam copy $steam not taken: ${statusName(status)}") } - prefs(context).edit().putString(KEY_STEAM_STAMP, stamp).apply() + settings.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 id = prefs(context).getString(KEY_ID, null) ?: return LsfgNative.STATUS_NOT_INSTALLED - val cache = cacheFor(context, id) + val cache = cacheFile(context) ?: return LsfgNative.STATUS_NOT_INSTALLED 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 adopt(context: Context, source: File, from: Source): Int { + private fun adoptSteamDll(context: Context, source: File): Int { val staged = File(dir(context).apply { mkdirs() }, "Lossless.dll.staged") try { val id = copyHashing(source, staged) - if (id == prefs(context).getString(KEY_ID, null) && usable(cacheFor(context, id))) return UNCHANGED + if (id == steamCacheId(context) && 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) @@ -109,9 +86,9 @@ object Lossless { cache.delete() return LsfgNative.STATUS_CACHE_UNUSABLE } - prefs(context).edit().putString(KEY_ID, id).putString(KEY_SOURCE, from.name).apply() + prefs(context).edit().putString(KEY_ID, id).putString(KEY_SOURCE, SOURCE_STEAM).apply() removeStale(context, id) - Log.i(TAG, "Lossless.dll from $source ($from) ready as $id") + Log.i(TAG, "Steam Lossless.dll from $source ready as $id") return LsfgNative.STATUS_OK } catch (e: java.io.IOException) { Log.w(TAG, "could not copy $source", e) @@ -158,9 +135,13 @@ object Lossless { GameStorage.effective(context)?.path?.let(::File), GameStorage.x64CardLibrary(context), ) + com.droiddeck.launcher.frontend.AddedGames.roots(context).map { it.host } - return libraries.map { File(it, STEAM_DLL) }.filter { it.isFile }.maxByOrNull { it.lastModified() } + return installedSteamDll(libraries) } + internal fun installedSteamDll(libraries: List): 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() } diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt index fbd14aea93..b7d95c4872 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt @@ -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 "1", "showLow001" to "1", + "showLatency" to "1", "showAvg" to "1", "showLow1" to "1", "showLow01" to "0", "showLow001" to "0", "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 "", diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt index 94bcb2920f..91ee9877f1 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt @@ -40,7 +40,8 @@ enum class DroidDeckHudSize(val token: String, val label: String) { PILL("pill", "Pill"), MINIMAL("minimal", "Minimal"), MEGA("mega", "Mega"), - STRIP("strip", "Strip"); + STRIP("strip", "Strip"), + SIDE_STRIP("side_strip", "Side strip"); fun next(): DroidDeckHudSize { val all = values() @@ -96,6 +97,11 @@ 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", + ), ) @@ -110,6 +116,7 @@ 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): List = diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt index f58320bc8e..c49ec88cdb 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt @@ -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 = true - private var showLow001 = true + private var showLow01 = false + private var showLow001 = false private var fpsDecimal = true private var showClockTime = true private var showLatency = true @@ -187,6 +187,12 @@ 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? = null private var onSizeCycledListener: Consumer? = null @@ -567,6 +573,7 @@ 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) @@ -678,8 +685,8 @@ class DroidDeckHudView(context: Context) : View(context) { finishPanel(panel, halfRound = halfRound) } - private fun finishPanel(panel: RectF, halfRound: Boolean) { - val r = if (halfRound) panel.height() / 2f else min(panel.height() / 2f, sp(56f)) + 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) 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) @@ -697,8 +704,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 + panelInset() - contentH = panel.bottom + panelInset() + contentW = panel.right + inset + contentH = panel.bottom + inset } private fun clockTimeString(): String = DateFormat.getTimeFormat(context).format(Date()) @@ -930,6 +937,58 @@ 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) @@ -993,13 +1052,20 @@ 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.roundToInt(), widthMeasureSpec), - resolveSize(contentH.roundToInt(), heightMeasureSpec), + resolveSize((contentW * fit).roundToInt(), widthMeasureSpec), + resolveSize((contentH * fit).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 @@ -1034,8 +1100,10 @@ class DroidDeckHudView(context: Context) : View(context) { } private fun drawContent(canvas: Canvas) { - - dPanel?.let { panel -> panelFrame(panel)?.let { canvas.drawBitmap(it, 0f, 0f, null) } } + 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) if (tileRects.isNotEmpty()) { tilePaint.color = Color.argb((14 * bgOpacity).roundToInt().coerceIn(8, 40), 255, 255, 255) @@ -1065,6 +1133,7 @@ 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) } @@ -1177,13 +1246,14 @@ 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): Bitmap? { + private fun panelFrame(panel: RectF, fit: Float): Bitmap? { if (width <= 0 || height <= 0) return null val stroke = outlineWidth() - val key = "$width,$height,$panel,$dRadius,$dDividerTop,$stroke,$accent,$surfaceRgb,$bgOpacity,${outlineColor()}" + val key = "$width,$height,$fit,$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() @@ -1256,8 +1326,8 @@ class DroidDeckHudView(context: Context) : View(context) { internal val isStrip: Boolean get() = stripRect != null - internal val contentWidth: Float get() = contentW - internal val contentHeight: Float get() = contentH + internal val contentWidth: Float get() = contentW * panelFit + internal val contentHeight: Float get() = contentH * panelFit internal val isDragging: Boolean get() = lockController.isDragging() || tabDragging diff --git a/app/src/main/java/com/droiddeck/launcher/input/ControllerPortraitGeometry.kt b/app/src/main/java/com/droiddeck/launcher/input/ControllerPortraitGeometry.kt index 907d71c70d..d6958f7b17 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/ControllerPortraitGeometry.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/ControllerPortraitGeometry.kt @@ -46,7 +46,14 @@ 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) }) { + 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) }) { val rearHeight = min(56f * unit, (panel - bodyTop + top) * .12f).coerceAtLeast(buttonHeight) row(REAR, bodyTop + rearHeight / 2f, rearHeight, gap) bodyTop += rearHeight + gap diff --git a/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt b/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt index 83ae4abc47..73782d7e63 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt @@ -19,6 +19,7 @@ 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) @@ -45,6 +46,7 @@ object ControllerPrefs { val size: Int, val stickClick: Boolean, val adaptiveSticks: Boolean, + val onScreenOpacity: Int, val rumble: Boolean, val steamButton: Boolean, val qamButton: Boolean, @@ -66,7 +68,8 @@ 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", true), + adaptiveSticks = p.getBoolean("adaptiveSticks", false), + onScreenOpacity = onScreenOpacity(context), rumble = rumbleEnabled(context), steamButton = p.getBoolean("steamButton", true), qamButton = p.getBoolean("qamButton", true), @@ -103,6 +106,13 @@ 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() } diff --git a/app/src/main/java/com/droiddeck/launcher/input/HeldInput.kt b/app/src/main/java/com/droiddeck/launcher/input/HeldInput.kt index 1fdb6121fc..41cf641275 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/HeldInput.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/HeldInput.kt @@ -2,14 +2,24 @@ package com.droiddeck.launcher.input class HeldInput(private val emit: (Int, Boolean) -> Unit) { private val owners = IntArray(768) + private val ordered = arrayOfNulls<(Int, Boolean) -> Unit>(768) @Synchronized - fun set(source: Int, code: Int, down: Boolean) { + fun set(source: Int, code: Int, down: Boolean, orderedEmit: ((Int, Boolean) -> Unit)? = null) { if (code !in owners.indices) return val before = owners[code] val after = if (down) before or source else before and source.inv() owners[code] = after - if ((before == 0) != (after == 0)) emit(code, after != 0) + if ((before == 0) != (after == 0)) { + if (after != 0) { + ordered[code] = orderedEmit + orderedEmit?.invoke(code, true) ?: emit(code, true) + } else { + val fn = ordered[code] + ordered[code] = null + fn?.invoke(code, false) ?: emit(code, false) + } + } } @Synchronized @@ -21,7 +31,9 @@ class HeldInput(private val emit: (Int, Boolean) -> Unit) { fun clear() { for (code in owners.indices) if (owners[code] != 0) { owners[code] = 0 - emit(code, false) + val fn = ordered[code] + ordered[code] = null + fn?.invoke(code, false) ?: emit(code, false) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/input/KeyboardHost.kt b/app/src/main/java/com/droiddeck/launcher/input/KeyboardHost.kt index 5372be6db5..a9549c9918 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/KeyboardHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/KeyboardHost.kt @@ -4,7 +4,6 @@ import android.app.Activity import android.content.Context import android.os.Build import android.text.InputType -import android.view.KeyCharacterMap import android.view.KeyEvent import android.view.View import android.view.WindowInsets @@ -12,15 +11,17 @@ import android.view.inputmethod.BaseInputConnection import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputConnection import android.view.inputmethod.InputMethodManager +import com.droiddeck.launcher.wayland.WaylandCompositor class KeyboardHost( context: Context, private val sendKeyEvent: (KeyEvent) -> Boolean, + private val sendText: (String) -> Unit, ) : View(context) { - constructor(activity: Activity) : this(activity, { activity.dispatchKeyEvent(it) }) + constructor(activity: Activity) : + this(activity, { activity.dispatchKeyEvent(it) }, { WaylandCompositor.textInputCommit(it) }) private val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - private val map: KeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD) var shown = false private set var imeShowing = false @@ -40,8 +41,7 @@ class KeyboardHost( override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? { if (!shown) return null - outAttrs.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or - InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD + outAttrs.inputType = InputType.TYPE_CLASS_TEXT outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE or EditorInfo.IME_FLAG_NO_FULLSCREEN or EditorInfo.IME_FLAG_NO_EXTRACT_UI return KeyConnection() @@ -93,45 +93,153 @@ class KeyboardHost( fun type(text: CharSequence?) { if (text.isNullOrEmpty()) return - val events = map.getEvents(text.toString().toCharArray()) - if (events != null) { - for (event in events) sendKeyEvent(event) - } else { - for (ch in text) { - val t = System.currentTimeMillis() - val down = KeyEvent(t, t, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_UNKNOWN, 0, 0, - KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, 0) - sendKeyEvent(CharKeyEvent(down, ch)) - sendKeyEvent(CharKeyEvent(KeyEvent.changeAction(down, KeyEvent.ACTION_UP), ch)) - } - } + // Text and soft editing actions share this queue to preserve IME ordering. + sendText(text.toString()) } fun tap(keyCode: Int) { + val control = softControl(keyCode) + if (control != null) { + sendText(control.toString()) + return + } val t = System.currentTimeMillis() sendKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_DOWN, keyCode, 0)) sendKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_UP, keyCode, 0)) } private inner class KeyConnection : BaseInputConnection(this, false) { + // A press keeps the route chosen on its first down across repeats and the matching up. + private val controlRoutes = HashMap() + + private var composingText = "" + private var composingCursor = 0 + override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean { + composingText = "" + composingCursor = 0 type(text) return true } - override fun setComposingText(text: CharSequence?, newCursorPosition: Int): Boolean = true - override fun finishComposingText(): Boolean = true - - override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean { - repeat(beforeLength) { tap(KeyEvent.KEYCODE_DEL) } - repeat(afterLength) { tap(KeyEvent.KEYCODE_FORWARD_DEL) } + override fun setComposingText(text: CharSequence?, newCursorPosition: Int): Boolean { + composingText = text?.toString().orEmpty() + val rawCursor = if (newCursorPosition > 0) { + composingText.length.toLong() + newCursorPosition - 1L + } else { + newCursorPosition.toLong() + } + composingCursor = rawCursor.coerceIn(0L, composingText.length.toLong()).toInt() return true } - override fun sendKeyEvent(event: KeyEvent): Boolean = this@KeyboardHost.sendKeyEvent(event) + override fun finishComposingText(): Boolean { + val text = composingText + composingText = "" + composingCursor = 0 + type(text) + return true + } + + override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean { + val before = beforeLength.coerceAtLeast(0) + val after = afterLength.coerceAtLeast(0) + if (before == 0 && after == 0) return true + val consumedBefore = minOf(before, composingCursor) + val consumedAfter = minOf(after, composingText.length - composingCursor) + val guestBefore = before - consumedBefore + val guestAfter = after - consumedAfter + if (guestBefore > 1 || guestAfter > 1) return false + return applyDeletion( + composingCursor - consumedBefore, + composingCursor + consumedAfter, + guestBefore, + guestAfter, + ) + } + + override fun deleteSurroundingTextInCodePoints(beforeLength: Int, afterLength: Int): Boolean { + val before = beforeLength.coerceAtLeast(0) + val after = afterLength.coerceAtLeast(0) + if (before == 0 && after == 0) return true + if (splitsPair(composingCursor)) return false + val text = composingText + val beforePoints = Character.codePointCount(text, 0, composingCursor) + val afterPoints = Character.codePointCount(text, composingCursor, text.length) + val consumedBefore = minOf(before, beforePoints) + val consumedAfter = minOf(after, afterPoints) + val start = Character.offsetByCodePoints(text, composingCursor, -consumedBefore) + val end = Character.offsetByCodePoints(text, composingCursor, consumedAfter) + if (hasUnpairedSurrogate(text, start, end)) return false + return applyDeletion( + start, + end, + before - consumedBefore, + after - consumedAfter, + ) + } + + private fun applyDeletion(start: Int, end: Int, guestBefore: Int, guestAfter: Int): Boolean { + if (guestBefore > 64 || guestAfter > 64) return false + if (splitsPair(start) || splitsPair(end)) return false + if (start < end) { + composingText = composingText.removeRange(start, end) + composingCursor = start + } + val controls = StringBuilder() + repeat(guestBefore) { controls.append(BACKSPACE) } + repeat(guestAfter) { controls.append(FORWARD_DELETE) } + if (controls.isNotEmpty()) sendText(controls.toString()) + return true + } + + private fun splitsPair(index: Int): Boolean = + index > 0 && index < composingText.length && + composingText[index - 1].isHighSurrogate() && composingText[index].isLowSurrogate() + + private fun hasUnpairedSurrogate(text: CharSequence, start: Int, end: Int): Boolean { + var i = start + while (i < end) { + val c = text[i] + if (c.isHighSurrogate()) { + if (i + 1 >= end || !text[i + 1].isLowSurrogate()) return true + i += 2 + } else if (c.isLowSurrogate()) { + return true + } else { + i++ + } + } + return false + } + + override fun sendKeyEvent(event: KeyEvent): Boolean { + val control = softControl(event.keyCode) + if (control == null) return this@KeyboardHost.sendKeyEvent(event) + if (event.action == KeyEvent.ACTION_DOWN) { + val soft = if (event.repeatCount == 0) { + val route = !event.isModified() + controlRoutes[event.keyCode] = route + route + } else { + controlRoutes[event.keyCode] ?: !event.isModified() + } + if (!soft) return this@KeyboardHost.sendKeyEvent(event) + if (control == ENTER) finishComposingText() + sendText(control.toString()) + return true + } + if (event.action == KeyEvent.ACTION_UP) { + val soft = controlRoutes.remove(event.keyCode) ?: !event.isModified() + if (soft) return true + return this@KeyboardHost.sendKeyEvent(event) + } + return this@KeyboardHost.sendKeyEvent(event) + } override fun performEditorAction(actionCode: Int): Boolean { - tap(KeyEvent.KEYCODE_ENTER) + finishComposingText() + sendText(ENTER.toString()) return true } @@ -140,8 +248,22 @@ class KeyboardHost( override fun getSelectedText(flags: Int): CharSequence? = null } - private class CharKeyEvent(origin: KeyEvent, private val ch: Char) : KeyEvent(origin) { - override fun getUnicodeChar(): Int = ch.code - override fun getUnicodeChar(metaState: Int): Int = ch.code + private fun softControl(keyCode: Int): Char? = when (keyCode) { + KeyEvent.KEYCODE_DEL -> BACKSPACE + KeyEvent.KEYCODE_FORWARD_DEL -> FORWARD_DELETE + KeyEvent.KEYCODE_ENTER -> ENTER + KeyEvent.KEYCODE_TAB -> TAB + else -> null + } + + private fun KeyEvent.isModified(): Boolean = + isCtrlPressed || isShiftPressed || isAltPressed || isMetaPressed + + private companion object { + // Control characters represent editing keys on the guest text channel. + const val ENTER = '\r' + const val BACKSPACE = '\b' + const val FORWARD_DELETE = '\u007f' + const val TAB = '\t' } } diff --git a/app/src/main/java/com/droiddeck/launcher/input/OnScreenLayout.kt b/app/src/main/java/com/droiddeck/launcher/input/OnScreenLayout.kt index e8490f624f..88ecec5fc7 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/OnScreenLayout.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/OnScreenLayout.kt @@ -36,6 +36,13 @@ 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 { + 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 { if (saved == null) return emptyList() if (width <= 0 || height <= 0) return saved.elements val layout = oriented(saved, dock?.portrait ?: (height > width)) diff --git a/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java b/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java index 5c69e9065b..81a84fcdba 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java +++ b/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java @@ -59,7 +59,7 @@ public final class PadBridge { private final PadState[] playerStates = new PadState[SLOTS]; private final float[][] rawSticks = new float[SLOTS][4]; private final Map rightStickLayouts = new HashMap<>(); - private final boolean[][] keyTriggers = new boolean[SLOTS][2]; + private final TriggerKey[][] keyTriggers = TriggerKey.slots(SLOTS); private final int[] retainedSticks = new int[SLOTS]; private final PadState effectiveState = new PadState(); private final PadState homeGuideReport = new PadState(); @@ -484,7 +484,7 @@ public final class PadBridge { stateFor(slot).clear(); retainedSticks[slot] = 0; Arrays.fill(rawSticks[slot], 0f); - Arrays.fill(keyTriggers[slot], false); + for (TriggerKey key : keyTriggers[slot]) key.reset(); } private void mutateState(java.util.function.Consumer mutation) { @@ -530,7 +530,7 @@ public final class PadBridge { float lx = event.getAxisValue(MotionEvent.AXIS_X); float ly = event.getAxisValue(MotionEvent.AXIS_Y); boolean wired = wiredXboxLayout(device, event.getSource()); - boolean rxRyStick = rightStickUsesRxRy(event, device, rightStickLayouts); + boolean rxRyStick = Boolean.TRUE.equals(rightStickUsesRxRy(event, device, rightStickLayouts)); float rx = event.getAxisValue(rxRyStick ? MotionEvent.AXIS_RX : MotionEvent.AXIS_Z); float ry = event.getAxisValue(rxRyStick ? MotionEvent.AXIS_RY : MotionEvent.AXIS_RZ); retainStick(slot, JoyCon.LEFT, lx, ly); @@ -570,26 +570,76 @@ public final class PadBridge { return true; } - static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, boolean[] held, int side) { + static final class TriggerKey { + static final float RELEASE_FROM_PEAK = 0.05f; + boolean held; + boolean handoff; + boolean axisLive; + boolean axisMovedWhilePressed; + float peak; + float axis; + + static TriggerKey[][] slots(int count) { + TriggerKey[][] keys = new TriggerKey[count][2]; + for (TriggerKey[] pair : keys) { + pair[0] = new TriggerKey(); + pair[1] = new TriggerKey(); + } + return keys; + } + + void reset() { + held = false; + handoff = false; + axisLive = false; + axisMovedWhilePressed = false; + peak = 0f; + axis = 0f; + } + } + + static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, TriggerKey[] keys, int side) { + TriggerKey key = keys[side]; if (repeatCount > 0) return current; if (!analog) { - held[side] = pressed; + key.held = pressed; return pressed ? 1f : 0f; } if (pressed) { - if (current != 0f) return current; - held[side] = true; + key.axisMovedWhilePressed = false; + if (key.axisLive || current != 0f) return current; + key.held = true; return 1f; } - if (!held[side]) return current; - held[side] = false; + if (!key.axisMovedWhilePressed) key.axisLive = false; + if (key.handoff) { + key.handoff = false; + return key.axis; + } + if (!key.held) return current; + key.held = false; return 0f; } - static float axisTrigger(float value, boolean[] held, int side) { - if (!held[side]) return value; - if (value == 0f) return 1f; - held[side] = false; + static float axisTrigger(float value, TriggerKey[] keys, int side) { + TriggerKey key = keys[side]; + key.axis = value; + if (value != 0f) { + key.axisLive = true; + key.axisMovedWhilePressed = true; + } + if (key.held) { + if (value == 0f) return 1f; + key.held = false; + key.handoff = true; + key.peak = value; + return 1f; + } + if (key.handoff) { + key.peak = Math.max(key.peak, value); + if (value > key.peak - TriggerKey.RELEASE_FROM_PEAK) return 1f; + key.handoff = false; + } return value; } @@ -604,14 +654,14 @@ public final class PadBridge { return false; } - static boolean rightStickUsesRxRy(MotionEvent event, InputDevice device, Map layouts) { + public static Boolean rightStickUsesRxRy(MotionEvent event, InputDevice device, Map layouts) { int source = event.getSource(); if (wiredXboxLayout(device, source)) return true; boolean hasRxRy = hasAxis(device, source, MotionEvent.AXIS_RX) && hasAxis(device, source, MotionEvent.AXIS_RY); boolean hasZRz = hasAxis(device, source, MotionEvent.AXIS_Z) && hasAxis(device, source, MotionEvent.AXIS_RZ); - if (!hasRxRy) return false; + if (!hasRxRy) return hasZRz ? false : null; if (!hasZRz) return true; Boolean cached = layouts.get(event.getDeviceId()); if (cached != null) return cached; @@ -619,7 +669,7 @@ public final class PadBridge { && nearCentre(device, source, event, MotionEvent.AXIS_RX, MotionEvent.AXIS_RY); boolean zRzEvidence = atMinimum(device, source, event, MotionEvent.AXIS_RX, MotionEvent.AXIS_RY) && nearCentre(device, source, event, MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ); - if (rxRyEvidence == zRzEvidence) return false; + if (rxRyEvidence == zRzEvidence) return null; boolean useRxRy = rxRyEvidence; layouts.put(event.getDeviceId(), useRxRy); return useRxRy; diff --git a/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt b/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt index dccba8a1b6..8f21ad67de 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt @@ -90,7 +90,7 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S val sticks = physical.getOrPut(event.deviceId) { Sticks() } val device = event.device val wired = wiredLayout.getOrPut(event.deviceId) { PadBridge.wiredXboxLayout(device, event.source) } - val rxRyStick = PadBridge.rightStickUsesRxRy(event, device, rightStickLayouts) + val rxRyStick = PadBridge.rightStickUsesRxRy(event, device, rightStickLayouts) ?: false sticks.leftX = event.getAxisValue(MotionEvent.AXIS_X) sticks.leftY = event.getAxisValue(MotionEvent.AXIS_Y) sticks.rightX = scrollAxis(event, if (rxRyStick) MotionEvent.AXIS_RX else MotionEvent.AXIS_Z) diff --git a/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt b/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt new file mode 100644 index 0000000000..051e745945 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt @@ -0,0 +1,324 @@ +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 { + 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 > read(context: Context, key: String, default: E): E = + prefs(context).getString(key, null)?.let { name -> enumValues().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::class.java) + private val setups = EnumMap(AirTrigger::class.java) + private val held = EnumSet.noneOf(AirTrigger::class.java) + private val pressed = EnumSet.noneOf(AirTrigger::class.java) + private val heldOnScreen = EnumMap(AirTrigger::class.java) + private val timers = EnumMap(AirTrigger::class.java) + + fun configure(setups: Map) { + 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() + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/input/SessionTextInput.kt b/app/src/main/java/com/droiddeck/launcher/input/SessionTextInput.kt new file mode 100644 index 0000000000..387351def2 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/input/SessionTextInput.kt @@ -0,0 +1,327 @@ +package com.droiddeck.launcher.input + +import android.content.Context +import android.net.LocalSocket +import android.net.LocalSocketAddress +import android.os.Handler +import android.os.Looper +import android.util.Log +import com.droiddeck.launcher.runtime.LinuxRuntime +import com.droiddeck.launcher.wayland.WaylandCompositor +import java.io.File +import java.io.IOException +import java.util.concurrent.RejectedExecutionException +import java.util.concurrent.ScheduledThreadPoolExecutor +import java.util.concurrent.TimeUnit + +private enum class TextDelivery(val result: Int) { + NOT_DELIVERED(WaylandCompositor.TEXT_NOT_DELIVERED), + DELIVERED(WaylandCompositor.TEXT_DELIVERED), + UNRESOLVED(WaylandCompositor.TEXT_UNRESOLVED), +} + +class SessionTextInput(context: Context, private val hasFocus: () -> Boolean) { + private val delivery = deliveryFor(context) + private val owner = Any() + + fun start() = delivery.start(owner, hasFocus) + fun stop() = delivery.stop(owner) + + private companion object { + private var instance: SessionTextDelivery? = null + + @Synchronized private fun deliveryFor(context: Context): SessionTextDelivery = + instance ?: SessionTextDelivery(context.applicationContext).also { instance = it } + } +} + +private class SessionTextDelivery(private val appContext: Context) { + private val handler = Handler(Looper.getMainLooper()) + private val lock = Any() + private var generation = 0L + @Volatile private var active = false + private var owner: Any? = null + private var focusCheck: (() -> Boolean)? = null + private var executor: ScheduledThreadPoolExecutor? = null + private var socket: LocalSocket? = null + private var pendingToken = 0 + private var runningToken = 0 + private var failedToken = 0 + private val guestListener = object : WaylandCompositor.TextInputFallbackListener { + override fun onTextInputFallback(text: String, token: Int): Boolean { + synchronized(lock) { + if (!active || pendingToken != 0 || failedToken != 0 || token <= 0) return false + val received = generation + pendingToken = token + val posted = try { + handler.post { enqueue(text, received, token) } + } catch (e: RuntimeException) { + false + } + if (!posted) pendingToken = 0 + return posted + } + } + } + + fun start(nextOwner: Any, hasFocus: () -> Boolean) { + val previous = synchronized(lock) { + if (owner === nextOwner) return + owner + } + if (previous != null) stop(previous) + val queue = ScheduledThreadPoolExecutor(1) { runnable -> + Thread(runnable, "session-text-input").apply { isDaemon = true } + } + queue.executeExistingDelayedTasksAfterShutdownPolicy = false + synchronized(lock) { + this.owner = nextOwner + focusCheck = hasFocus + active = true + executor = queue + if (failedToken != 0) scheduleRetryLocked(failedToken, INITIAL_DELAY_MS) + } + WaylandCompositor.setTextInputFallbackListener(guestListener) + } + + fun stop(oldOwner: Any) { + val detached = synchronized(lock) { + if (owner !== oldOwner) return + owner = null + focusCheck = null + active = false + generation += 1 + val queue = executor + val open = socket + val token = if (runningToken == 0 && failedToken == 0) pendingToken else 0 + executor = null + socket = null + Triple(queue, open, token) + } + WaylandCompositor.clearTextInputFallbackListener(guestListener) + handler.removeCallbacksAndMessages(null) + detached.second?.let { requestCancel(it) } + detached.first?.shutdown() + if (detached.third != 0) complete(detached.third) + } + + private fun enqueue(text: String, received: Long, token: Int) { + val currentFocus = synchronized(lock) { if (active && generation == received) focusCheck else null } + if (currentFocus == null || !currentFocus() || !WaylandCompositor.isTextInputFallbackListener(guestListener)) { + Log.d(TAG, "guest text fallback skipped outside the active focused session") + complete(token) + return + } + val bytes = text.toByteArray(Charsets.UTF_8) + if (bytes.isEmpty() || bytes.size > MAX_BYTES) { + complete(token) + return + } + val queue = synchronized(lock) { + if (active && generation == received) executor else null + } + if (queue == null) { + complete(token) + return + } + try { + queue.execute { + try { + val delivery = send(bytes, received, token) + if (delivery == TextDelivery.UNRESOLVED) recover(token) + else complete(token, delivery) + } finally { + releaseRunning(token) + } + } + } catch (e: RejectedExecutionException) { + complete(token) + } + } + + private fun recover(token: Int) { + if (probe()) { + complete(token) + return + } + val marked = synchronized(lock) { + if (pendingToken == token && failedToken == 0) { + failedToken = token + WaylandCompositor.completeTextInputFallback(token, TextDelivery.UNRESOLVED.result) + scheduleRetryLocked(token, INITIAL_DELAY_MS) + true + } else { + false + } + } + if (marked) Log.w(TAG, "text injection could not be confirmed") + } + + private fun scheduleRetryLocked(token: Int, delayMs: Long) { + if (!active || failedToken != token || pendingToken != token) return + val queue = executor ?: return + val current = generation + try { + queue.schedule({ retryProbe(current, token, delayMs) }, delayMs, TimeUnit.MILLISECONDS) + } catch (e: RejectedExecutionException) { + } + } + + private fun retryProbe(received: Long, token: Int, delayMs: Long) { + val ready = synchronized(lock) { + active && generation == received && failedToken == token && pendingToken == token + } + if (!ready) return + val proven = probe() + val owned = synchronized(lock) { + if (proven) { + if (active && generation == received && failedToken == token && pendingToken == token) { + pendingToken = 0 + runningToken = 0 + failedToken = 0 + true + } else { + false + } + } else { + if (active && generation == received && failedToken == token && pendingToken == token) { + val next = (delayMs * 2).coerceAtMost(MAX_DELAY_MS) + scheduleRetryLocked(token, next) + } + false + } + } + if (owned) WaylandCompositor.completeTextInputFallback(token, TextDelivery.NOT_DELIVERED.result) + } + + private fun probe(): Boolean { + val live = LocalSocket() + return try { + live.connect(LocalSocketAddress(endpoint().path, LocalSocketAddress.Namespace.FILESYSTEM)) + live.soTimeout = TIMEOUT_MS + val out = live.outputStream + out.write(lengthPrefix(0)) + out.flush() + live.inputStream.read() == 0 + } catch (e: IOException) { + Log.w(TAG, "could not probe guest text input state", e) + false + } finally { + close(live) + } + } + + private fun complete(token: Int, delivery: TextDelivery = TextDelivery.NOT_DELIVERED) { + val owned = synchronized(lock) { + if (pendingToken == token) { + pendingToken = 0 + runningToken = 0 + failedToken = 0 + true + } else { + false + } + } + if (owned) WaylandCompositor.completeTextInputFallback(token, delivery.result) + } + + private fun releaseRunning(token: Int) { + synchronized(lock) { + if (runningToken == token) runningToken = 0 + } + } + + private fun send(bytes: ByteArray, received: Long, token: Int): TextDelivery { + val live = LocalSocket() + if (!claim(live, received, token)) { + close(live) + return TextDelivery.NOT_DELIVERED + } + var requested = false + try { + live.connect(LocalSocketAddress(endpoint().path, LocalSocketAddress.Namespace.FILESYSTEM)) + live.soTimeout = TIMEOUT_MS + if (!isCurrent(received)) return TextDelivery.NOT_DELIVERED + val out = live.outputStream + out.write(lengthPrefix(bytes.size)) + requested = true + out.write(bytes) + out.flush() + val input = live.inputStream + val ack = try { + input.read() + } catch (e: IOException) { + // Android may report a socket read timeout as a plain IOException. + requestCancel(live) + input.read() + } + if (ack == 0) Log.d(TAG, "guest did not complete text delivery") + if (ack != 0 && ack != 1 && isCurrent(received)) Log.w(TAG, "guest did not acknowledge text delivery") + return when (ack) { + 1 -> TextDelivery.DELIVERED + 0 -> TextDelivery.NOT_DELIVERED + else -> TextDelivery.UNRESOLVED + } + } catch (e: IOException) { + if (isCurrent(received)) Log.w(TAG, "could not hand text to the guest", e) + if (!requested) return TextDelivery.NOT_DELIVERED + return TextDelivery.UNRESOLVED + } finally { + release(live) + close(live) + } + } + + private fun requestCancel(live: LocalSocket) { + try { + live.shutdownOutput() + } catch (e: IOException) { + Log.w(TAG, "could not request guest text input cancellation", e) + } + } + + private fun isCurrent(received: Long) = synchronized(lock) { active && generation == received } + + private fun claim(live: LocalSocket, received: Long, token: Int) = synchronized(lock) { + if (!active || generation != received || pendingToken != token || runningToken != 0 || failedToken != 0) { + false + } else { + runningToken = token + socket = live + true + } + } + + private fun release(live: LocalSocket) { + synchronized(lock) { + if (socket === live) socket = null + } + } + + private fun endpoint(): File = File(LinuxRuntime.sessionRoot(appContext), "text-input.sock") + + private fun lengthPrefix(size: Int): ByteArray { + val flagged = if (size == 0) size else size or Int.MIN_VALUE + return byteArrayOf( + (flagged ushr 24).toByte(), + (flagged ushr 16).toByte(), + (flagged ushr 8).toByte(), + flagged.toByte(), + ) + } + + private fun close(sock: LocalSocket) { + try { + sock.close() + } catch (e: IOException) { + } + } + + private companion object { + const val TAG = "SessionTextInput" + const val MAX_BYTES = 65536 + const val TIMEOUT_MS = 3000 + const val INITIAL_DELAY_MS = 500L + const val MAX_DELAY_MS = 5000L + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt index 0e42e770e3..d72274443b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt @@ -288,12 +288,26 @@ object BwrapSpawner { } private fun preload(session: List, rootfs: String, env: MutableMap): List { - 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 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 binds = ArrayList() val paths = libs.map { lib -> "$PRELOAD_DIR/${lib.substringAfterLast('/')}".also { binds.add(Bind(rootfs + lib, it)) } } - env["LD_PRELOAD"] = (paths + listOfNotNull(env["LD_PRELOAD"]?.takeIf { it.isNotBlank() })).joinToString(":") + env["LD_PRELOAD"] = (paths + inherited).joinToString(":") + if (libs.any { it.endsWith("/liblse_emu.so") }) { + env.putIfAbsent("LSE_EMU", "1") + } 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)) @@ -563,12 +577,15 @@ object BwrapSpawner { private fun run(context: Context, plan: Plan, client: LocalSocket, out: DataOutputStream, id: Int) { val verbose = plan.env["DROIDDECK_PROOT_VERBOSE"]?.toIntOrNull() - val native = if (NativeGuest.forSession(context)) nativeLaunch(context, plan) else null + val nativeSession = NativeGuest.forSession(context) + val native = if (nativeSession) 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) } @@ -585,7 +602,6 @@ 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) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/ElfSeccompPatch.kt b/app/src/main/java/com/droiddeck/launcher/runtime/ElfSeccompPatch.kt index 817cbc9757..8ebf839fd7 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/ElfSeccompPatch.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/ElfSeccompPatch.kt @@ -38,6 +38,11 @@ object ElfSeccompPatch { val end = minOf(data.size, buffer.getLong(at + 8).toInt() + buffer.getLong(at + 32).toInt()) and 3.inv() var pos = start while (pos + 4 <= end) { + if (patchTermiosRequest(buffer, pos, end)) { + patched++ + pos += 4 + continue + } val replacement = when (buffer.getInt(pos)) { MOV_X8_SET_ROBUST_LIST -> NOP MOV_X8_CLONE3, MOV_X8_RSEQ -> MOV_X0_ENOSYS @@ -65,6 +70,40 @@ object ElfSeccompPatch { return patched } + /** + * glibc 2.42 and later read and set a terminal with TCGETS2 and TCSETS2/W2/F2, which Android's + * SELinux policy refuses on an app's pseudo-terminal slaves (EACCES): isatty() was false in every + * Konsole, ssh and tmux session, so bash had no prompt or job control and stdout was not line + * buffered. TCGETS and TCSETS* carry the same struct without its two speed fields, which glibc + * then takes from c_cflag. A site is `movz xN, #lo` then `movk xN, #hi, lsl #16`; the movz gets + * the old request and the movk becomes a no-op. + */ + private fun patchTermiosRequest(buffer: ByteBuffer, pos: Int, end: Int): Boolean { + val movz = buffer.getInt(pos) + if ((movz and 0x7fe00000) != 0x52800000) return false + val low = (movz ushr 5) and 0xffff + if (low !in 0x542a..0x542d) return false + val register = movz and 0x1f + var next = pos + 4 + while (next < minOf(end, pos + 4 + 4 * 4)) { + val movk = buffer.getInt(next) + if ((movk and 0x7fe00000) == 0x72a00000 && (movk and 0x1f) == register) { + val request = when ((movk ushr 5) and 0xffff) { + 0x802c -> if (low == 0x542a) 0x5401 else return false + 0x402c -> if (low != 0x542a) 0x5402 + (low - 0x542b) else return false + else -> return false + } + buffer.putInt(pos, (movz and 0x1f.inv() and (0xffff shl 5).inv()) or (request shl 5) or register) + buffer.putInt(next, NOP) + return true + } + // Anything between that might read or write the register would see the old low half + if (intArrayOf(0, 5, 10, 16).any { (movk ushr it) and 0x1f == register }) return false + next += 4 + } + return false + } + /** Patches the file behind [path] (symlinks followed) if it still has unpatched call sites. */ fun patchFile(path: File): Int { val target = path.canonicalFile diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/FrameAcquireWorkerProbe.kt b/app/src/main/java/com/droiddeck/launcher/runtime/FrameAcquireWorkerProbe.kt new file mode 100644 index 0000000000..403a8c59cc --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/runtime/FrameAcquireWorkerProbe.kt @@ -0,0 +1,271 @@ +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() + @Synchronized private fun breadcrumb(stage: Stage, reason: Reason) { + if (reported.add(stage)) Log.i("FrameAcquireWorkerProbe", "worker_admission=" + reason.name) + } + + internal fun validEnvironment(agentEnvironment: List, customEnvironment: List): 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, 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() + 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, 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 + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt index 2c5fbad51e..50a190c1ba 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt @@ -1,13 +1,11 @@ package com.droiddeck.launcher.runtime import android.content.Context -import android.os.Environment import com.droiddeck.launcher.core.DownloadSource 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 @@ -37,7 +35,7 @@ object GuestCommand { SessionFiles.stage(context, root) LinuxNetworkLinkComponent(context, root).publish() val runtimeDir = File(context.filesDir, ".flatpak-rt").apply { mkdirs() } - val binds = LinuxRuntime.binds(context, null, runtimeDir, Environment.getExternalStorageDirectory(), extraBinds) + val binds = LinuxRuntime.binds(context, null, runtimeDir, LinuxRuntime.sharedStorage(context), extraBinds) val native = NativeGuest.forSession(context) val fastPathKey = if (!native && fastPath && !fakeRoot && linkDir == null && ProotFastPath.enabled(context)) ProotFastPath.key(root, binds) else null val guest = mutableListOf( @@ -68,7 +66,6 @@ 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) } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt b/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt new file mode 100644 index 0000000000..e3f7d0ba01 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt @@ -0,0 +1,1008 @@ +package com.droiddeck.launcher.runtime + +import android.app.ActivityManager +import android.app.Service +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.ServiceConnection +import android.net.LocalServerSocket +import android.net.LocalSocket +import android.os.Binder +import android.os.Handler +import android.os.IBinder +import android.os.Looper +import android.os.Parcel +import android.os.ParcelFileDescriptor +import android.os.Process +import android.system.ErrnoException +import android.system.Os +import android.system.OsConstants +import android.system.StructPollfd +import android.util.Log +import org.json.JSONObject +import java.io.DataInputStream +import java.io.File +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +/** + * A guest program run as the main process of its own Android process. + * + * Android counts the processes in an app process's cgroup against its child-process limit, but not + * the app processes themselves. The worker execs the program in place; its binder fd stays open + * across the exec, so the system keeps the process as a live service process. The program's own + * children are still counted. See docs/phantom-processes.md. + */ +open class GuestWorker : Service() { + private val binder = object : Binder() { + override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean { + if (code != RUN) return super.onTransact(code, data, reply, flags) + val argv = data.createStringArray() ?: return false + val env = data.createStringArray() ?: return false + val fds = List(data.readInt()) { data.readFileDescriptor() } + val targets = data.createIntArray() ?: IntArray(fds.size) { it } + 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)) + } + 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 + // app gave up and starts the program another way) the program must not run here. + var why = "" + // poll() with a timeout counts as network I/O to StrictMode on the main thread + android.os.StrictMode.setThreadPolicy(android.os.StrictMode.ThreadPolicy.LAX) + val committed = runCatching { + fun byte(timeout: Int): Int { + val poll = StructPollfd().apply { fd = go.fileDescriptor; events = OsConstants.POLLIN.toShort() } + val ready = Os.poll(arrayOf(poll), timeout) + return (if (ready > 0) Os.read(go.fileDescriptor, ByteArray(1), 0, 1) else -1) + .also { why = "poll $ready revents ${poll.revents} read $it" } + } + // The commit, an answer, and the app's word that it has the answer: the app may + // have stopped waiting for it (and started the program another way) meanwhile. + // That last word comes, or the app closes its end (a byte or EOF): no timeout, + // which could drop a launch the app has already reported as started. + byte(GO_TIMEOUT_MS) == 1 && Os.write(go.fileDescriptor, byteArrayOf(1), 0, 1) == 1 && byte(-1) == 1 + }.getOrElse { why = it.toString(); false } + go.close() + if (committed) exec(argv, env, fds, targets, fillBinderFd, nice) + else { + Log.w(TAG, "launch not committed ($why): not running ${argv.firstOrNull()}") + Process.killProcess(Process.myPid()) + } + } + return true + } + } + + override fun onBind(intent: Intent): IBinder = binder + + private fun exec(argv: Array, env: Array, fds: List, targets: IntArray, fillBinderFd: Boolean, + nice: Int) { + try { + val top = targets.maxOrNull() ?: 2 + val (binderTop, binderFd) = keepBinderOpen(maxOf(BINDER_FDS, top + 1)) + // Out of the way first, so that placing one fd cannot overwrite another not yet placed. + val above = maxOf(MOVED_FDS, top + 1, binderTop + 1) + val moved = fds.map { pfd -> pfd?.let { Os.fcntlInt(it.fileDescriptor, OsConstants.F_DUPFD, above) } } + moved.forEachIndexed { i, fd -> + if (fd == null || i >= targets.size) return@forEachIndexed + val source = ParcelFileDescriptor.adoptFd(fd).also { kept.add(it) }.fileDescriptor + Os.dup2(source, targets[i]) + Os.fcntlInt(source, OsConstants.F_SETFD, OsConstants.FD_CLOEXEC) + } + // A session of its own: in zygote's process group, a program signalling its group + // (kill(0, sig)) would reach every process of the app. + runCatching { Os.setsid() } + // The native hook closes the binder fds in every other process (hook/handoff.c). Only an + // app launch asks for the number (a whole argument or variable value), never a guest's. + val fill = { arg: String -> + if (!fillBinderFd) arg + else if (arg == BINDER_FD_TOKEN) binderFd.toString() + else if (arg.endsWith("=$BINDER_FD_TOKEN")) arg.removeSuffix(BINDER_FD_TOKEN) + binderFd + else arg + } + // This thread blocks SIGQUIT, SIGUSR1 and SIGPIPE (Android's runtime), and an exec keeps + // that: the program's hook sets DDH_SIGMASK instead (none blocked, unless the request says). + val mask = if (env.any { it.startsWith("DDH_SIGMASK=") }) emptyList() else listOf("DDH_SIGMASK=0") + // Android raised this thread to THREAD_PRIORITY_TOP_APP_BOOST (a service the top app binds with + // BIND_IMPORTANT is scheduled as the top app); the program and its threads would keep it and + // run ahead of the game. They get the asker's priority instead, as a forked child would. + runCatching { Process.setThreadPriority(nice) } + Os.execve(argv[0], argv.map(fill).toTypedArray(), + env.filterNot { it.startsWith("DDH_WORKER_PID=") }.map(fill).toTypedArray() + mask + + "DDH_WORKER_PID=${Process.myPid()}") + } catch (e: ErrnoException) { + Log.e(TAG, "could not exec ${argv.firstOrNull()}", e) + } + Process.killProcess(Process.myPid()) + } + + /** + * Binder fds stay open across the exec, at [from] or above, where no fd of the program goes. + * Returns the highest fd used and the one on /dev/binder, whose closing Android takes for + * the death of this process. + */ + private fun keepBinderOpen(from: Int): Pair { + var highest = from - 1 + var binder = -1 + File("/proc/self/fd").listFiles()?.forEach { link -> + val target = runCatching { Os.readlink(link.path) }.getOrNull() ?: return@forEach + if (target !in BINDER_DEVICES && !target.startsWith("/dev/binderfs/")) return@forEach + // A copy, not adoptFd(): some of these fds are owned (fdsan) by a ParcelFileDescriptor. + val copy = runCatching { ParcelFileDescriptor.fromFd(link.name.toIntOrNull() ?: return@forEach) }.getOrNull() + ?: return@forEach + val kept = Os.fcntlInt(copy.fileDescriptor, OsConstants.F_DUPFD, from) + highest = maxOf(highest, kept) + if (target.substringAfterLast('/') == "binder") binder = kept + copy.close() + } + return highest to binder + } + + companion object { + const val RUN = IBinder.FIRST_CALL_TRANSACTION + /** An argument, or a variable's whole value, in an app launch: replaced by the number of its kept binder fd. */ + const val BINDER_FD_TOKEN = "@DDH_WORKER_BINDER_FD@" + // Longer than the app may wait for the hook's "go" (GuestWorkers.ACK_TIMEOUT_MS) before it commits + private const val GO_TIMEOUT_MS = 15000 + private val BINDER_DEVICES = setOf("/dev/binder", "/dev/hwbinder", "/dev/vndbinder") + private const val BINDER_FDS = 900 + private const val MOVED_FDS = 1200 + private const val TAG = "GuestWorker" + private val kept = ArrayList() + + fun isWorkerProcess(context: Context, process: String?): Boolean = + process != null && process.startsWith(context.packageName + ":g") && + process.substring(context.packageName.length + 2).all { it.isDigit() } + } +} + +class GuestWorker0 : GuestWorker() +class GuestWorker1 : GuestWorker() +class GuestWorker2 : GuestWorker() +class GuestWorker3 : GuestWorker() +class GuestWorker4 : GuestWorker() +class GuestWorker5 : GuestWorker() +class GuestWorker6 : GuestWorker() +class GuestWorker7 : GuestWorker() +class GuestWorker8 : GuestWorker() +class GuestWorker9 : GuestWorker() +class GuestWorker10 : GuestWorker() +class GuestWorker11 : GuestWorker() +class GuestWorker12 : GuestWorker() +class GuestWorker13 : GuestWorker() +class GuestWorker14 : GuestWorker() +class GuestWorker15 : GuestWorker() +class GuestWorker16 : GuestWorker() +class GuestWorker17 : GuestWorker() +class GuestWorker18 : GuestWorker() +class GuestWorker19 : GuestWorker() +class GuestWorker20 : GuestWorker() +class GuestWorker21 : GuestWorker() +class GuestWorker22 : GuestWorker() +class GuestWorker23 : GuestWorker() +class GuestWorker24 : GuestWorker() +class GuestWorker25 : GuestWorker() +class GuestWorker26 : GuestWorker() +class GuestWorker27 : GuestWorker() +class GuestWorker28 : GuestWorker() +class GuestWorker29 : GuestWorker() +class GuestWorker30 : GuestWorker() +class GuestWorker31 : GuestWorker() +class GuestWorker32 : GuestWorker() +class GuestWorker33 : GuestWorker() +class GuestWorker34 : GuestWorker() +class GuestWorker35 : GuestWorker() +class GuestWorker36 : GuestWorker() +class GuestWorker37 : GuestWorker() +class GuestWorker38 : GuestWorker() +class GuestWorker39 : GuestWorker() +class GuestWorker40 : GuestWorker() +class GuestWorker41 : GuestWorker() +class GuestWorker42 : GuestWorker() +class GuestWorker43 : GuestWorker() +class GuestWorker44 : GuestWorker() +class GuestWorker45 : GuestWorker() +class GuestWorker46 : GuestWorker() +class GuestWorker47 : GuestWorker() +class GuestWorker48 : GuestWorker() +class GuestWorker49 : GuestWorker() +class GuestWorker50 : GuestWorker() +class GuestWorker51 : GuestWorker() +class GuestWorker52 : GuestWorker() +class GuestWorker53 : GuestWorker() +class GuestWorker54 : GuestWorker() +class GuestWorker55 : GuestWorker() +class GuestWorker56 : GuestWorker() +class GuestWorker57 : GuestWorker() +class GuestWorker58 : GuestWorker() +class GuestWorker59 : GuestWorker() +class GuestWorker60 : GuestWorker() +class GuestWorker61 : GuestWorker() +class GuestWorker62 : GuestWorker() +class GuestWorker63 : GuestWorker() +class GuestWorker64 : GuestWorker() +class GuestWorker65 : GuestWorker() +class GuestWorker66 : GuestWorker() +class GuestWorker67 : GuestWorker() +class GuestWorker68 : GuestWorker() +class GuestWorker69 : GuestWorker() +class GuestWorker70 : GuestWorker() +class GuestWorker71 : GuestWorker() +class GuestWorker72 : GuestWorker() +class GuestWorker73 : GuestWorker() +class GuestWorker74 : GuestWorker() +class GuestWorker75 : GuestWorker() +class GuestWorker76 : GuestWorker() +class GuestWorker77 : GuestWorker() +class GuestWorker78 : GuestWorker() +class GuestWorker79 : GuestWorker() +class GuestWorker80 : GuestWorker() +class GuestWorker81 : GuestWorker() +class GuestWorker82 : GuestWorker() +class GuestWorker83 : GuestWorker() +class GuestWorker84 : GuestWorker() +class GuestWorker85 : GuestWorker() +class GuestWorker86 : GuestWorker() +class GuestWorker87 : GuestWorker() +class GuestWorker88 : GuestWorker() +class GuestWorker89 : GuestWorker() +class GuestWorker90 : GuestWorker() +class GuestWorker91 : GuestWorker() +class GuestWorker92 : GuestWorker() +class GuestWorker93 : GuestWorker() +class GuestWorker94 : GuestWorker() +class GuestWorker95 : GuestWorker() +class GuestWorker96 : GuestWorker() +class GuestWorker97 : GuestWorker() +class GuestWorker98 : GuestWorker() +class GuestWorker99 : GuestWorker() +class GuestWorker100 : GuestWorker() +class GuestWorker101 : GuestWorker() +class GuestWorker102 : GuestWorker() +class GuestWorker103 : GuestWorker() +class GuestWorker104 : GuestWorker() +class GuestWorker105 : GuestWorker() +class GuestWorker106 : GuestWorker() +class GuestWorker107 : GuestWorker() +class GuestWorker108 : GuestWorker() +class GuestWorker109 : GuestWorker() +class GuestWorker110 : GuestWorker() +class GuestWorker111 : GuestWorker() +class GuestWorker112 : GuestWorker() +class GuestWorker113 : GuestWorker() +class GuestWorker114 : GuestWorker() +class GuestWorker115 : GuestWorker() +class GuestWorker116 : GuestWorker() +class GuestWorker117 : GuestWorker() +class GuestWorker118 : GuestWorker() +class GuestWorker119 : GuestWorker() +class GuestWorker120 : GuestWorker() +class GuestWorker121 : GuestWorker() +class GuestWorker122 : GuestWorker() +class GuestWorker123 : GuestWorker() +class GuestWorker124 : GuestWorker() +class GuestWorker125 : GuestWorker() +class GuestWorker126 : GuestWorker() +class GuestWorker127 : GuestWorker() + +/** The pool of [GuestWorker] processes, and the socket guests ask it through (`droiddeck-spawn`). */ +object GuestWorkers { + private const val TAG = "GuestWorkers" + private val classes: List> = listOf( + GuestWorker0::class.java, GuestWorker1::class.java, GuestWorker2::class.java, + GuestWorker3::class.java, GuestWorker4::class.java, GuestWorker5::class.java, + GuestWorker6::class.java, GuestWorker7::class.java, GuestWorker8::class.java, + GuestWorker9::class.java, GuestWorker10::class.java, GuestWorker11::class.java, + GuestWorker12::class.java, GuestWorker13::class.java, GuestWorker14::class.java, + GuestWorker15::class.java, GuestWorker16::class.java, GuestWorker17::class.java, + GuestWorker18::class.java, GuestWorker19::class.java, GuestWorker20::class.java, + GuestWorker21::class.java, GuestWorker22::class.java, GuestWorker23::class.java, + GuestWorker24::class.java, GuestWorker25::class.java, GuestWorker26::class.java, + GuestWorker27::class.java, GuestWorker28::class.java, GuestWorker29::class.java, + GuestWorker30::class.java, GuestWorker31::class.java, GuestWorker32::class.java, + GuestWorker33::class.java, GuestWorker34::class.java, GuestWorker35::class.java, + GuestWorker36::class.java, GuestWorker37::class.java, GuestWorker38::class.java, + GuestWorker39::class.java, GuestWorker40::class.java, GuestWorker41::class.java, + GuestWorker42::class.java, GuestWorker43::class.java, GuestWorker44::class.java, + GuestWorker45::class.java, GuestWorker46::class.java, GuestWorker47::class.java, + GuestWorker48::class.java, GuestWorker49::class.java, GuestWorker50::class.java, + GuestWorker51::class.java, GuestWorker52::class.java, GuestWorker53::class.java, + GuestWorker54::class.java, GuestWorker55::class.java, GuestWorker56::class.java, + GuestWorker57::class.java, GuestWorker58::class.java, GuestWorker59::class.java, + GuestWorker60::class.java, GuestWorker61::class.java, GuestWorker62::class.java, + GuestWorker63::class.java, GuestWorker64::class.java, GuestWorker65::class.java, + GuestWorker66::class.java, GuestWorker67::class.java, GuestWorker68::class.java, + GuestWorker69::class.java, GuestWorker70::class.java, GuestWorker71::class.java, + GuestWorker72::class.java, GuestWorker73::class.java, GuestWorker74::class.java, + GuestWorker75::class.java, GuestWorker76::class.java, GuestWorker77::class.java, + GuestWorker78::class.java, GuestWorker79::class.java, GuestWorker80::class.java, + GuestWorker81::class.java, GuestWorker82::class.java, GuestWorker83::class.java, + GuestWorker84::class.java, GuestWorker85::class.java, GuestWorker86::class.java, + GuestWorker87::class.java, GuestWorker88::class.java, GuestWorker89::class.java, + GuestWorker90::class.java, GuestWorker91::class.java, GuestWorker92::class.java, + GuestWorker93::class.java, GuestWorker94::class.java, GuestWorker95::class.java, + GuestWorker96::class.java, GuestWorker97::class.java, GuestWorker98::class.java, + GuestWorker99::class.java, GuestWorker100::class.java, GuestWorker101::class.java, + GuestWorker102::class.java, GuestWorker103::class.java, GuestWorker104::class.java, + GuestWorker105::class.java, GuestWorker106::class.java, GuestWorker107::class.java, + GuestWorker108::class.java, GuestWorker109::class.java, GuestWorker110::class.java, + GuestWorker111::class.java, GuestWorker112::class.java, GuestWorker113::class.java, + GuestWorker114::class.java, GuestWorker115::class.java, GuestWorker116::class.java, + GuestWorker117::class.java, GuestWorker118::class.java, GuestWorker119::class.java, + GuestWorker120::class.java, GuestWorker121::class.java, GuestWorker122::class.java, + GuestWorker123::class.java, GuestWorker124::class.java, GuestWorker125::class.java, + GuestWorker126::class.java, GuestWorker127::class.java, + ) + + private class Slot(val index: Int) { + lateinit var connection: ServiceConnection + val connected = CountDownLatch(1) + @Volatile var service: IBinder? = null + @Volatile var pid = -1 + @Volatile var guest = false + /** The session it runs a program for ([serve]'s number). */ + @Volatile var session = 0 + @Volatile var onExit: ((Int) -> Unit)? = null + /** The priority it runs its program at: the asker's (a guest, or the app thread that started it). */ + @Volatile var nice = 0 + /** Set once its program was handed over: only then does its end count as the program's. */ + @Volatile var started = false + /** Between the pid and the last word of a launch (under the slots lock): its end is held back. */ + var launching = false + /** It ended while launching: reported once the launch turns out to have run, never otherwise. */ + var endedLaunching = false + } + + private val slots = arrayOfNulls(classes.size) + // Workers bound ahead of need while a session runs: a zygote fork and the bind take about + // 60-100 ms, which every program the session starts would otherwise wait for. + private val warm = ArrayDeque() + @Volatile private var warmTarget = 0 + // Numbers the sessions: an old session's teardown can still be running when the next one starts. + @Volatile private var session = 0 + // The latest session whose teardown has begun + @Volatile private var stopped = 0 + // Held for a launch's last word and for marking a session stopped + private val authorizing = Any() + private val warming = java.util.concurrent.atomic.AtomicBoolean(false) + private const val WARM_WORKERS = 2 + // A game's start hands off a burst of programs (Wine's services, the agent's checks) within a few + // seconds: bound ahead while the client starts it, not forked while the game draws its first frames. + private const val LAUNCH_WORKERS = 16 + private const val LAUNCH_MS = 20_000L + @Volatile private var launchUntil = 0L + private val launches = java.util.concurrent.atomic.AtomicInteger() + private const val ACK_TIMEOUT_MS = 5000 + private const val ANSWER_TIMEOUT_MS = 5000 + private const val RECEIVE_TIMEOUT_MS = 10000 + // argv and the environment of one exec, with room: Linux caps them at a quarter of the stack + private const val MAX_REQUEST_BYTES = 8 shl 20 + private const val MAX_RECEIVING = 32 + private val receiving = java.util.concurrent.atomic.AtomicInteger() + private val connections = java.util.concurrent.Executors.newSingleThreadExecutor { Thread(it, "guest-worker-binder").apply { isDaemon = true } } + @Volatile private var server: Thread? = null + // Android sets a worker's main thread to THREAD_PRIORITY_TOP_APP_BOOST again each time the app returns to the top + private const val TOP_APP_BOOST = -10 + private const val PRIORITY_CHECK_MS = 2000L + @Volatile private var keeper: Thread? = null + + /** The app, once [attach] or [serve] ran in its main process; null before. */ + @Volatile var context: Context? = null + private set + + /** Whether the session runs its programs in workers: the native userland, and not turned off. */ + fun enabled(context: Context): Boolean = handoffAllowed(context) && NativeGuest.enabled(context) + + private fun handoffAllowed(context: Context): Boolean = + android.os.Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.session.SessionPrefs.childProcessHandoff(context) + + /** How the running session's root was started: in a worker (true) or counted (false); null with none running. */ + @Volatile var sessionRootUncounted: Boolean? = null + + /** + * Whether Android's child-process limit is out of the session's way: as the running session + * started (a proot session, or one whose root fell back to a counted start, is not), else as + * the next one would start. + */ + fun limitHandled(context: Context): Boolean = + sessionRootUncounted ?: (NativeGuest.sessionMode != false && handoffAllowed(context) && NativeGuest.nextSession(context)) + + /** Whether pid is a program running in one of the workers. */ + fun runsInWorker(pid: Int): Boolean = pid > 0 && synchronized(slots) { slots.any { it != null && it.started && it.pid == pid } } + + fun socketName(context: Context): String = "droiddeck-spawn." + context.packageName + "." + Process.myUid() + + /** + * Runs [argv] (a host command line) as the main process of a free worker with [env] and the + * fds in [stdio] as its 0, 1 and 2. Returns its pid, or -1. Blocks: not for the main thread. + * [onExit] runs once the process is gone. + */ + fun start(context: Context, argv: List, env: List, stdio: List, onExit: (Int) -> Unit): Int = + start(context, argv, env, stdio, IntArray(stdio.size) { it }, onExit) + + /** As [start], with the fds in [fds] placed at the numbers in [targets]. */ + fun start(context: Context, argv: List, env: List, fds: List, targets: IntArray, + onExit: (Int) -> Unit): Int = start(context, argv, env, fds, targets, false, onExit) + + /** + * [guest]: one of the session's guest programs, which [guestPids] lists and [stopGuests] ends. + * [commit] runs with the pid before the worker may run the program; false, and it does not. + * [confirmed] runs once the worker has taken it on, just before it is told to run it; false, and it does not. + * [owner]: the session asking (the one a guest's request names), else the latest. + */ + private fun start(context: Context, argv: List, env: List, fds: List, 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 { + val app = context.applicationContext + if (guest && owner <= stopped) { + Log.w(TAG, (if (owner == 0) "a request naming no session" else "session $owner is stopping") + + ": not starting ${argv.firstOrNull()}") + return -1 + } + val slot = takeWarm() ?: bind(app)?.takeIf { fresh -> + fresh.connected.await(10, TimeUnit.SECONDS).also { if (!it) release(app, fresh) } + } ?: run { + Log.w(TAG, "no worker started for ${argv.firstOrNull()}") + return -1 + } + slot.guest = guest + slot.session = owner + slot.onExit = onExit + slot.nice = nice + // during a game's start the pool drains instead: its refill would fork while the game starts + if (android.os.SystemClock.elapsedRealtime() >= launchUntil) refill(app) + // The worker execs once a byte comes through this socket: after the reply has reached us, so + // that its exec does not cut the reply off, and after the slot is marked started. Closed + // without one, the worker ends without running the program (the caller starts it another way). + // It answers with a byte of its own: without that it gave up waiting, and nothing runs. + var go: Array? = null + var data: Parcel? = Parcel.obtain() + val reply = Parcel.obtain() + try { + go = ParcelFileDescriptor.createSocketPair() + data!!.writeStringArray(argv.toTypedArray()) + data.writeStringArray(env.toTypedArray()) + data.writeInt(fds.size) + fds.forEach { data.writeFileDescriptor(it.fileDescriptor) } + data.writeIntArray(targets) + 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)) + // 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 } + if (stopping() || !commit(pid)) { + Log.w(TAG, "worker ${slot.index}: ${argv.firstOrNull()} was not taken on") + release(app, slot) + return -1 + } + // launching, not started yet: an end before the last word is reported only if the launch ran + val live = synchronized(slots) { + (slots[slot.index] === slot && !stopping()).also { if (it) { slot.pid = pid; slot.launching = true } } + } + if (!live) { + Log.w(TAG, "worker ${slot.index} ended, or its session is stopping, before running ${argv.firstOrNull()}") + release(app, slot) + return -1 + } + Os.write(go[1].fileDescriptor, byteArrayOf(1), 0, 1) + val answer = StructPollfd().apply { fd = go[1].fileDescriptor; events = OsConstants.POLLIN.toShort() } + // then the word to run it: given only here, once its answer is in, so that a worker whose + // answer came too late never runs a program this call reports as not started. [confirmed] + // goes first: a caller that hears nothing runs the program itself, so it must have heard + // before the worker may run it (an app dying in between loses the program, not doubles it). + // The word and a teardown's start exclude each other: a launch is authorized before stopGuests() + // marks the session stopped, and is then stopped with the pids it takes (guestPids lists a + // 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 + } + } + val endedRunning = synchronized(slots) { + slot.launching = false + if (accepted && !slot.endedLaunching) slot.started = true + accepted && slot.endedLaunching + } + if (!accepted) { + Log.w(TAG, "worker ${slot.index} did not take ${argv.firstOrNull()} on") + release(app, slot) + return -1 + } + // it ran and was already gone by now: its end, once + if (endedRunning) reportEnd(app, slot) + } catch (e: Exception) { + Log.w(TAG, "worker ${slot.index} refused ${argv.firstOrNull()}", e) + synchronized(slots) { slot.launching = false } + release(app, slot) + return -1 + } finally { + data?.recycle() + reply.recycle() + go?.forEach { runCatching { it.close() } } + } + Log.i(TAG, "worker ${slot.index} (pid ${slot.pid}) runs ${argv.lastOrNull { !it.startsWith("-") }}") + return slot.pid + } + + /** Binds a free worker; its [Slot.connected] opens once it is up. Null when all are in use. */ + private fun bind(app: Context): Slot? { + val slot = synchronized(slots) { + val index = slots.indexOfFirst { it == null } + if (index < 0) { + Log.w(TAG, "all ${slots.size} workers are busy") + return null + } + Slot(index).also { slots[index] = it } + } + slot.connection = object : ServiceConnection { + override fun onServiceConnected(name: ComponentName, binder: IBinder) { + slot.service = binder + slot.connected.countDown() + } + + override fun onServiceDisconnected(name: ComponentName) = release(app, slot) + + override fun onBindingDied(name: ComponentName) = release(app, slot) + } + // Callbacks off the main thread: start() waits for onServiceConnected, and a caller holding a + // lock the main thread is waiting for (PulseAudio's launch) would otherwise wait out the timeout. + val bound = runCatching { + app.bindService(Intent(app, classes[slot.index]), Context.BIND_AUTO_CREATE or Context.BIND_IMPORTANT, + connections, slot.connection) + }.onFailure { Log.w(TAG, "worker ${slot.index} could not be bound", it) }.getOrDefault(false) + if (!bound) { + release(app, slot) + return null + } + return slot + } + + private fun takeWarm(): Slot? = synchronized(slots) { + while (warm.isNotEmpty()) { + val slot = warm.removeFirst() + if (slots[slot.index] === slot && slot.service?.isBinderAlive == true) return slot + } + null + } + + /** Brings the warm workers back up to [warmTarget], one at a time, off the caller's thread. */ + private fun refill(app: Context) { + if (warmTarget == 0 || !warming.compareAndSet(false, true)) return + Thread({ + try { + while (true) { + val missing = warmTarget - synchronized(slots) { warm.size } + if (missing <= 0) break + // all at once: the zygote forks them in parallel + val fresh = (1..missing).mapNotNull { bind(app) } + if (fresh.isEmpty()) break + for (slot in fresh) { + if (!slot.connected.await(10, TimeUnit.SECONDS)) { + release(app, slot) + continue + } + // decided once, under the lock: kept warm, or released + val kept = synchronized(slots) { + (slots[slot.index] === slot && warmTarget > 0).also { if (it) warm.addLast(slot) } + } + if (!kept) release(app, slot) + } + } + } finally { + warming.set(false) + } + }, "guest-worker-warm").apply { isDaemon = true; start() } + } + + /** A game is about to start: [LAUNCH_WORKERS] bound ahead, back to [WARM_WORKERS] once it is up. */ + fun expectLaunch(context: Context) { + val app = context.applicationContext + val raised = synchronized(slots) { (warmTarget > 0).also { if (it) warmTarget = LAUNCH_WORKERS } } + if (!raised) return + launchUntil = android.os.SystemClock.elapsedRealtime() + LAUNCH_MS + val launch = launches.incrementAndGet() + refill(app) + Thread({ + try { + Thread.sleep(LAUNCH_MS) + } catch (_: InterruptedException) { + return@Thread + } + if (launches.get() != launch) return@Thread + val extra = synchronized(slots) { + if (warmTarget != LAUNCH_WORKERS) emptyList() + else { + warmTarget = WARM_WORKERS + List((warm.size - WARM_WORKERS).coerceAtLeast(0)) { warm.removeLast() } + } + } + extra.forEach { release(app, it) } + refill(app) + }, "guest-worker-launch").apply { isDaemon = true; start() } + } + + private fun release(app: Context, slot: Slot) { + var report = false + val removed = synchronized(slots) { + warm.remove(slot) + if (slot.launching) slot.endedLaunching = true else report = slot.started + (slots[slot.index] === slot).also { if (it) slots[slot.index] = null } + } + if (!removed) return + runCatching { app.unbindService(slot.connection) } + if (report) reportEnd(app, slot) + } + + private fun reportEnd(app: Context, slot: Slot) { + val onExit = slot.onExit ?: return + Thread({ onExit(exitStatus(app, slot.pid)) }, "guest-worker-exit").start() + } + + /** The worker's exit as a wait status (exit code << 8, or the signal), -1 when unknown. */ + private fun exitStatus(app: Context, pid: Int): Int { + if (pid <= 0 || android.os.Build.VERSION.SDK_INT < 30) return -1 + val am = app.getSystemService(ActivityManager::class.java) + var recorded = false + repeat(20) { + am.getHistoricalProcessExitReasons(app.packageName, pid, 1).firstOrNull()?.let { + recorded = true + // an exit code only when the process exited itself; a signal number otherwise (a native crash) + if (it.reason == android.app.ApplicationExitInfo.REASON_EXIT_SELF) return (it.status and 0xff) shl 8 + if (it.status in 1..64) return it.status and 0x7f + // Android records the death first and the zygote's status later (as UNKNOWN, 0, then + // EXIT_SELF): a reason without a status may still be completed + if (it.reason != android.app.ApplicationExitInfo.REASON_UNKNOWN) return OsConstants.SIGKILL + } + Thread.sleep(50) + } + // killed by Android with no signal recorded, not a clean exit + return if (recorded) OsConstants.SIGKILL else -1 + } + + /** The pids of session [of]'s guest programs running in workers. */ + fun guestPids(of: Int = session): List = + synchronized(slots) { slots.mapNotNull { s -> s?.takeIf { it.guest && it.session == of }?.pid?.takeIf { it > 0 } } } + + /** Ends session [of]'s guest programs that are still running, and, for the latest session, the warm workers. */ + fun stopGuests(of: Int = session) { + // the check and the reset together: a new session's serve() may be under way + val drained = synchronized(authorizing) { + synchronized(slots) { + stopped = maxOf(stopped, of) + if (of != session) emptyList() else { warmTarget = 0; warm.toList().also { warm.clear() } } + } + } + 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) } + Thread.sleep(500) + pids.forEach { Process.killProcess(it) } + } + + /** Listens for `droiddeck-spawn` requests from the session's guests. */ + fun attach(context: Context) { + this.context = context.applicationContext + } + + /** Puts a running program's main thread back to its asker's priority after Android boosted it (once started, never stops). */ + private fun keepPriorities() { + synchronized(this) { + if (keeper != null) return + keeper = Thread({ + while (true) { + try { + Thread.sleep(PRIORITY_CHECK_MS) + } catch (_: InterruptedException) { + return@Thread + } + val running = synchronized(slots) { + slots.filterNotNull().filter { it.started && it.pid > 0 && it.nice != TOP_APP_BOOST } + } + for (s in running) runCatching { + if (Process.getThreadPriority(s.pid) == TOP_APP_BOOST) Process.setThreadPriority(s.pid, s.nice) + } + } + }, "guest-worker-priority").apply { isDaemon = true; start() } + } + } + + /** Starts a session's use of the workers (and the spawn socket, once); returns its number. */ + fun serve(context: Context): Int { + val app = context.applicationContext + this.context = app + val number = synchronized(slots) { warmTarget = WARM_WORKERS; ++session } + refill(app) + keepPriorities() + synchronized(this) { + if (server != null) return number + server = Thread({ + val socket = try { + LocalServerSocket(socketName(app)) + } catch (e: Exception) { + Log.e(TAG, "no spawn socket", e) + synchronized(this) { server = null } + return@Thread + } + while (true) { + val client = runCatching { socket.accept() }.getOrNull() + if (client == null) { + Thread.sleep(100) // out of fds, for one: do not spin + continue + } + // A bounded number of requests still coming in: a stalled sender holds a thread + if (receiving.incrementAndGet() > MAX_RECEIVING) { + receiving.decrementAndGet() + Log.w(TAG, "$MAX_RECEIVING spawn requests are still coming in: refusing another") + runCatching { client.close() } + continue + } + Thread({ + try { + handle(app, client) { receiving.decrementAndGet() } + } catch (e: Throwable) { + Log.w(TAG, "spawn request failed", e) + } + }, "guest-spawn").start() + } + }, "guest-spawn-server").apply { isDaemon = true; start() } + } + return number + } + + private fun handle(app: Context, client: LocalSocket, received: () -> Unit) { + var receiving = true + val done = { if (receiving) { receiving = false; received() } } + try { + handleRequest(app, client, done) + } finally { + done() + } + } + + private fun handleRequest(app: Context, client: LocalSocket, received: () -> Unit) { + client.use { + if (client.peerCredentials.uid != Process.myUid()) return + // The whole request and its fds within this, however slowly they come (the wait for a + // program's exit is not): each read gets what is left of it + val deadline = android.os.SystemClock.elapsedRealtime() + RECEIVE_TIMEOUT_MS + fun left() { + val ms = deadline - android.os.SystemClock.elapsedRealtime() + if (ms <= 0) throw java.net.SocketTimeoutException("spawn request not received in time") + client.soTimeout = ms.toInt() + } + val input = DataInputStream(client.inputStream) + val fds = ArrayList() + fun take() { + val received = client.ancillaryFileDescriptors.orEmpty() + try { + received.forEach { fds.add(ParcelFileDescriptor.dup(it)) } + } finally { + received.forEach { runCatching { Os.close(it) } } + } + } + // fds can come with any read, the request's own bytes too: each read's are taken at once + fun fill(bytes: ByteArray) { + var got = 0 + while (got < bytes.size) { + left() + val n = input.read(bytes, got, bytes.size - got) + take() + if (n < 0) throw java.io.EOFException("spawn request ended at $got of ${bytes.size} bytes") + got += n + } + } + // Until start() has them: closed on every way out before that, from the first byte on + var handedOver = false + try { + val length = ByteArray(4).also { fill(it) }.let { java.nio.ByteBuffer.wrap(it).int } + if (length !in 1..MAX_REQUEST_BYTES) { + Log.w(TAG, "spawn request of $length bytes refused") + return + } + val payload = ByteArray(length).also { fill(it) } + val request = JSONObject(String(payload)) + if (request.has("fdchunks")) { + // The hook sends its fds after the request, a chunk with each byte (hook/handoff.c) + val total = (request.optJSONArray("fds")?.length() ?: 0) + (if (request.has("table")) 1 else 0) + while (fds.size < total) { + left() + if (input.read() < 0) throw java.io.EOFException("fds ended at ${fds.size} of $total") + take() + } + } else { + take() + } + received() + val argv = request.getJSONArray("argv").let { a -> List(a.length()) { a.getString(it) } } + val env = LinkedHashMap() + request.optJSONObject("env")?.let { o -> o.keys().forEach { env[it] = o.getString(it) } } + request.optJSONArray("envlist")?.let { a -> + for (i in 0 until a.length()) a.getString(i).split('=', limit = 2).let { if (it.size == 2) env[it[0]] = it[1] } + } + // What the hook told the program that asked (it may run in a worker itself) is not this one's + env.keys.removeAll { it.startsWith("DDH_") } + val cwd = request.optString("cwd", "/") + val wait = request.optBoolean("wait", false) + // A path without a slash names a file in the cwd, as execve() takes it, not one on PATH + val file = request.optString("file", "").let { if (it.isNotEmpty() && '/' !in it) "./$it" else it } + // The handoff table (the hook's) comes last among the fds; the rest go to these numbers. + val tableIndex = request.optInt("table", -1) + val numbers = request.optJSONArray("fds")?.let { a -> IntArray(a.length()) { a.getInt(it) } } ?: IntArray(3) { it } + val table = fds.getOrNull(tableIndex)?.takeIf { pfd -> + runCatching { Os.readlink("/proc/self/fd/${pfd.fd}") }.getOrNull()?.contains("ddnatv-handoff") == true + } + val slot = request.optInt("slot", -1) + val parent = request.optInt("parent", -1) + var programFds = fds.filterIndexed { i, _ -> i != tableIndex } + var targets = numbers + if (table != null && slot >= 0) { + // The program reports its own exit status into the table (hook/handoff.c) + val tableFd = (numbers.maxOrNull() ?: 2) + 1 + programFds = programFds + table + targets = numbers + tableFd + env["DDH_TABLE"] = "$tableFd:$slot:$parent:${request.optInt("child", -1)}" + } + val root = env["DDNATV_ROOT"]?.let(::File) + val out = client.outputStream + if (root == null || argv.isEmpty()) { + out.write("error no guest root or program\n".toByteArray()) + return + } + val shell = listOf("/usr/bin/bash", "/bin/bash").first { File(root, it.removePrefix("/")).isFile } + val args = if (file.isNotEmpty()) { + listOf("-c", "unset DDH_WRAPPER; cd -- \"\$1\" 2>/dev/null; a=\$2; f=\$3; shift 3; exec -a \"\$a\" \"\$f\" \"\$@\"", + "droiddeck-spawn", cwd, argv[0], file) + argv.drop(1) + } else { + listOf("-c", "unset DDH_WRAPPER; cd -- \"\$1\" 2>/dev/null; shift; exec \"\$@\"", "droiddeck-spawn", cwd) + argv + } + val command = NativeGuest.command(root, shell, args) + env["DDNATV_REAL_EXE"] = File(root, shell.removePrefix("/")).path + // The hook restores these in the program (tools/nativeguest/hook/handoff.c). + if (request.has("sigign")) env["DDH_SIGIGN"] = request.getLong("sigign").toString() + if (request.has("nofile")) { + env["DDH_NOFILE"] = request.getLong("nofile").toString() + + (if (request.has("nofilemax")) ":" + request.getLong("nofilemax") else "") + } + if (request.has("umask")) env["DDH_UMASK"] = request.getLong("umask").toString() + if (request.has("pgid")) env["DDH_PGID"] = request.getLong("pgid").toString() + if (request.has("anchor")) env["DDH_ANCHOR"] = request.getLong("anchor").toString() + if (request.has("pstart")) env["DDH_PSTART"] = request.getLong("pstart").toString() + if (request.has("astart")) env["DDH_ASTART"] = request.getLong("astart").toString() + env["DDH_SIGMASK"] = request.optLong("sigmask", 0L).toString() + // The shell above: the hook restores nothing there (bash changes its own signal mask), + // only in the program it execs, which no longer has this. + env["DDH_WRAPPER"] = "1" + val child = request.optInt("child", -1) + val exited = CountDownLatch(1) + var status = -1 + var worker = -1 + // The hook answers the pid with "go" (ack): without it (it died, or gave up and runs the + // program itself) the worker must not run it too. + val ack = request.optBoolean("ack", false) + var answered = false + // the hook's last word, sent once the worker has taken the program on and before it runs it + var confirmedToHook = false + // The session whose guest asks, not the latest: a new session can start (serve()) while an + // older one's guests are still sending, and that older one's teardown must find its programs. + // A request that names none is refused (start() runs nothing for session 0): the hook and + // droiddeck-spawn always name it, and which session's it is cannot be told otherwise. + 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 { + out.write("ok\n".toByteArray()) + out.flush() + confirmedToHook = true + }.isSuccess + confirmed + }, commit = { started -> + worker = started + if (!ack) return@start true + runCatching { + out.write("pid $started\n".toByteArray()) + out.flush() + answered = true + client.soTimeout = ACK_TIMEOUT_MS + // the whole line: a hook whose write stopped short treats it as failed and runs the program itself + val line = StringBuilder() + var ended = false + while (!ended) { + val c = input.read() + if (c < 0) break + if (c == '\n'.code) ended = true else line.append(c.toChar()) + } + 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() } } + if (!answered) { + out.write(if (pid > 0) "pid $pid\n".toByteArray() else "error no worker\n".toByteArray()) + out.flush() + } else if (!confirmedToHook) { + // nothing runs it in a worker: the hook runs it itself + runCatching { out.write("error not started\n".toByteArray()); out.flush() } + } + if (pid > 0 && wait) { + exited.await() + // droiddeck-spawn exits with this: an exit code, or 128 plus the signal + val code = if (status < 0) 1 else if (status and 0x7f == 0) (status shr 8) and 0xff else 128 + (status and 0x7f) + out.write("exit $code\n".toByteArray()) + out.flush() + } + } finally { + if (!handedOver) fds.forEach { runCatching { it.close() } } + } + } + } + + // Layout of the hook's table (tools/nativeguest/hook/handoff.c): a 64-byte header, then 64-byte + // entries of int32 child, real, parent, state, ..., and at 32 the app's report: int32 status, child. + // The report is one 8-byte write tagged with the child it is for; only the hook changes an + // entry's state, so a report that lands after the entry went to another child is ignored there. + private fun reportExit(table: ParcelFileDescriptor, slot: Int, status: Int, parent: Int, child: Int, worker: Int) { + runCatching { + val entry = 64L + slot * 64L + val head = java.nio.ByteBuffer.allocate(16).order(java.nio.ByteOrder.nativeOrder()) + Os.pread(table.fileDescriptor, head, entry) + val real = head.getInt(4) + val state = head.getInt(12) + // Also while the hook holds the entry (TAKEN) or has already guessed its end (EXITED): + // the report is for this child only, and wins over the timeout's guess (ddh_status) + if (head.getInt(0) != child || head.getInt(8) != parent || (real != 0 && real != worker) || state !in 1..4) + return@runCatching + // An exit Android has no record of is reported as a failure, not as a signal. + val report = java.nio.ByteBuffer.allocate(8).order(java.nio.ByteOrder.nativeOrder()) + .putInt(0, if (status < 0) 1 shl 8 else status).putInt(4, child) + Os.pwrite(table.fileDescriptor, report, entry + 32) + if (parent > 0) Process.sendSignal(parent, OsConstants.SIGCHLD) + }.onFailure { Log.w(TAG, "could not report an exit to the guest's parent", it) } + runCatching { table.close() } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt b/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt index 3f4589ae13..8008cf82ed 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt @@ -35,9 +35,40 @@ object LegacyNames { @Synchronized fun migrateEtc(root: File) { for ((old, new) in LINKED_DIRS) moveAndLink(File(root, old), File(root, new)) - File(root, "etc/droiddeck/empty").mkdirs() + clearEmptyStandIn(root) + File(root, NO_THERMAL).mkdirs() } + /** + * It stands in for /sys/bus/pci/devices, and libpci exits the whole process on an entry it cannot + * parse; older builds let thermal bind mount points leak into it. The guest can write here, so a + * link is never followed: one in place of the folder is removed, and one above it stops the cleanup. + */ + private fun clearEmptyStandIn(root: File) { + val linkedAbove = listOf("etc", "etc/droiddeck").firstOrNull { Files.isSymbolicLink(File(root, it).toPath()) } + if (linkedAbove != null) { + Log.w(TAG, "not clearing the empty stand-in: $linkedAbove is a link") + return + } + val empty = File(root, "etc/droiddeck/empty") + if (Files.isSymbolicLink(empty.toPath())) runCatching { Files.delete(empty.toPath()) } + .onFailure { Log.w(TAG, "could not remove the link at $empty", it); return } + empty.mkdirs() + empty.listFiles()?.forEach { entry -> + runCatching { deleteWithoutFollowing(entry.toPath()) }.onFailure { Log.w(TAG, "could not clear $entry", it) } + } + } + + private fun deleteWithoutFollowing(path: java.nio.file.Path) { + if (Files.isDirectory(path, java.nio.file.LinkOption.NOFOLLOW_LINKS)) { + Files.newDirectoryStream(path).use { entries -> entries.forEach(::deleteWithoutFollowing) } + } + Files.deleteIfExists(path) + } + + /** Stands in for a /sys/class/thermal the kernel won't list; proot adds the bound zones' mount points to it. */ + const val NO_THERMAL = "etc/droiddeck/no-thermal" + @Synchronized fun migrateRootfs(root: File) { migrateEtc(root) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt index b76172edb1..1f5d1a4d56 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt @@ -302,9 +302,9 @@ class LinuxNetworkLinkComponent( val etc = File(rootDir, "etc") replace(File(etc, "resolv.conf"), text) val hosts = File(etc, "hosts") - if (!hosts.isFile || !hosts.readText().contains("localhost")) { - hosts.writeText("127.0.0.1 localhost\n::1 localhost\n") - } + val existing = if (hosts.isFile) hosts.readText() else null + val wanted = hostsText(existing) + if (wanted != existing) replace(hosts, wanted) Log.i(TAG, "resolver: " + servers.joinToString(" ")) } catch (e: IOException) { Log.w(TAG, "Could not write the resolver", e) @@ -338,6 +338,42 @@ class LinuxNetworkLinkComponent( companion object { private val WRITES = Any() + private const val HOSTS_BLOCK_START = "# DroidDeck: Unity telemetry is refused (start)" + private const val HOSTS_BLOCK_END = "# DroidDeck: Unity telemetry is refused (end)" + + // Unity 5's player seeds its bundled OpenSSL before its first HTTPS request, and that code jumps + // to a bad address under FEX (Windlands, 428370). Refusing these telemetry hosts makes the request + // fail before TLS starts; the games run without them. + internal val UNITY_TELEMETRY_HOSTS = listOf( + "config.uca.cloud.unity3d.com", "api.uca.cloud.unity3d.com", "cdp.cloud.unity3d.com", + "stats.unity3d.com", "perf-events.cloud.unity3d.com", + ) + + internal fun hostsText(existing: String?): String { + val kept = mutableListOf() + var block: MutableList? = null + for (line in existing.orEmpty().lines()) { + when { + line == HOSTS_BLOCK_START -> { + block?.let(kept::addAll) + block = mutableListOf() + } + line == HOSTS_BLOCK_END -> block = null + block != null -> block!!.add(line) + else -> kept.add(line) + } + } + block?.let(kept::addAll) + kept.removeAll { it.isBlank() } + return buildString { + if (kept.none { it.substringBefore('#').contains("localhost") }) append("127.0.0.1 localhost\n::1 localhost\n") + kept.forEach { append(it).append('\n') } + append(HOSTS_BLOCK_START).append('\n') + append("0.0.0.0 ").append(UNITY_TELEMETRY_HOSTS.joinToString(" ")).append('\n') + append(HOSTS_BLOCK_END).append('\n') + } + } + internal fun gateways(properties: LinkProperties?, capabilities: NetworkCapabilities?): List = listOf(Inet4Address::class.java, Inet6Address::class.java).mapNotNull { family -> properties?.routes.orEmpty() diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index fd59297b1f..327e7fc1ea 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -185,7 +185,12 @@ public final class LinuxRuntime { public static List lastBinds(Context context) { List binds = lastBinds; if (binds != null) return binds; - return binds(context, null, null, android.os.Environment.getExternalStorageDirectory(), null); + return binds(context, null, null, sharedStorage(context), null); + } + + /** The phone's shared storage, or null when it should stay out of the container. */ + public static File sharedStorage(Context context) { + return SessionPrefs.mountSharedStorage(context) ? android.os.Environment.getExternalStorageDirectory() : null; } public static List prootPrefix(Context context, File root, String cwd) { @@ -243,7 +248,7 @@ public final class LinuxRuntime { // A kernel that refuses to list /sys/class/thermal (Pixel 10, Android 17) made mangoapp abort // at start ("filesystem_error ... Permission denied: '/sys/class/thermal/'") until its // wrapper gave up: it lists the directory for CPU temperatures. Empty there instead. - if (new File("/sys/class/thermal").list() == null) bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/class/thermal"); + if (new File("/sys/class/thermal").list() == null) bind(cmd, new File(root, LegacyNames.NO_THERMAL).getPath() + ":/sys/class/thermal"); bind(cmd, context.getFilesDir().getPath()); bind(cmd, context.getCacheDir().getPath()); bind(cmd, liveDir(context).getPath()); diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt index 49541416eb..6e69ffe376 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt @@ -22,14 +22,24 @@ object NativeGuest { } fun enabled(context: Context): Boolean = - SessionPrefs.nativeUserland(context) && available(LinuxRuntime.rootDir(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 + * installed will have one. + */ + fun nextSession(context: Context): Boolean = + willRun(LinuxRuntime.rootDir(context), LinuxRuntime.isInstalled(context)) + + internal fun willRun(root: File, installed: Boolean): Boolean = !installed || loader(root) != null /** The mode the running session started in; null between sessions. */ @Volatile var sessionMode: Boolean? = null /** * Whether a session's helpers (root commands, Flatpak sandboxes, installers) run natively: the - * session's own mode while one runs, as the setting can change under it and the rootfs is only + * session's own mode while one runs, as the rootfs is only * prepared for native programs at a session's start. */ fun forSession(context: Context): Boolean = sessionMode ?: enabled(context) @@ -94,8 +104,11 @@ 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, program: String, hostname: String? = null): Map { - val preload = preloadList(root) + fun sessionEnvironment( + root: File, binds: List, program: String, hostname: String? = null, lseEmu: String? = null, + ): Map { + val preload = preloadList(root).filterNot { lseEmu == "0" && it.substringAfterLast('/') == "liblse_emu.so" } + val lse = lseEmu ?: "1".takeIf { preload.any { it.substringAfterLast('/') == "liblse_emu.so" } } return linkedMapOf( "DDNATV_ROOT" to root.path, "DDNATV_EXEC" to execLoader.orEmpty(), @@ -103,6 +116,7 @@ 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() } } @@ -112,8 +126,9 @@ object NativeGuest { File(BwrapSpawner.hostPath(binds.map { BwrapSpawner.Bind.parse(it) }, root.path, cwd)).takeIf { it.isDirectory } ?: root /** A process for [guest] (argv) started as proot would with [binds], in guest directory [cwd]. */ - fun processBuilder(context: Context, root: File, binds: List, guest: List, cwd: String = "/root"): ProcessBuilder = - ProcessBuilder(command(root, guest.first(), guest.drop(1))) + fun processBuilder(context: Context, root: File, binds: List, guest: List, cwd: String = "/root"): ProcessBuilder { + if (sessionMode == null) prepare(context, root) + return ProcessBuilder(command(root, guest.first(), guest.drop(1))) .directory(workingDirectory(root, binds, cwd)) .also { builder -> builder.environment().apply { @@ -121,6 +136,7 @@ object NativeGuest { putAll(sessionEnvironment(root, binds, guest.first(), SessionPrefs.guestHostname(context))) } } + } private const val RUNPATH_CONF = "etc/ld.so.conf.d/zz-droiddeck-native.conf" private val SCAN_DIRS = listOf("usr/lib", "usr/local/lib", "opt") @@ -149,6 +165,7 @@ object NativeGuest { } /** What a rootfs needs before anything runs in it natively; cheap once done. */ + @Synchronized fun prepare(context: Context, root: File) { val relinked = relinkAbsoluteSymlinks(context, root) if (relinked > 0) android.util.Log.i(TAG, "native userland: $relinked absolute symlinks made relative") diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt b/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt index 27ef86f086..33fa897237 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt @@ -3,7 +3,6 @@ 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 @@ -12,17 +11,14 @@ object ProotFastPath { const val LIBRARY = "/usr/local/lib/libddfastpath.so" const val MAX_BINDS = 256 - fun allows(preference: Boolean, noSeccomp: Boolean, source: String, nativeUserland: Boolean = false): Boolean = - preference && !noSeccomp && !nativeUserland && source == LinuxRuntime.PROOT_PACK + internal fun allows(source: String, native: Boolean): Boolean = + !native && source == LinuxRuntime.PROOT_PACK - fun enabled(context: Context): Boolean { - val preference = SessionPrefs.prootFastPath(context) - val noSeccomp = SessionPrefs.prootNoSeccomp(context) - val nativeUserland = SessionPrefs.nativeUserland(context) + fun enabled(context: Context, native: Boolean = NativeGuest.forSession(context)): Boolean { + if (native) return false val source = LinuxRuntime.prootSource(context) - 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") + val on = allows(source, native) + if (!on) Log.i(TAG, "proot: fast path off - binary is $source, not the patched proot") return on } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/RootSpawner.kt b/app/src/main/java/com/droiddeck/launcher/runtime/RootSpawner.kt index 16228be728..1791df54b0 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/RootSpawner.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/RootSpawner.kt @@ -8,7 +8,6 @@ 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 @@ -128,7 +127,6 @@ 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) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/UserApps.kt b/app/src/main/java/com/droiddeck/launcher/runtime/UserApps.kt index efc460ee04..ea9b0ba699 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/UserApps.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/UserApps.kt @@ -14,6 +14,7 @@ import com.droiddeck.launcher.R import com.droiddeck.launcher.core.Downloader import com.droiddeck.launcher.core.FileUtils import com.droiddeck.launcher.core.Hashes +import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.store.FlathubApi import org.json.JSONArray import org.json.JSONObject @@ -184,9 +185,10 @@ object UserApps { fun binds(context: Context): List { val internal = Environment.getExternalStorageDirectory().canonicalPath + val mounted = SessionPrefs.mountSharedStorage(context) return root(context).listFiles().orEmpty().mapNotNull { dir -> val target = runCatching { Os.readlink(File(dir, "files").path) }.getOrNull() ?: return@mapNotNull null - target.takeIf { !it.startsWith("$internal/") && File(it).isDirectory } + target.takeIf { !(mounted && it.startsWith("$internal/")) && File(it).isDirectory } }.distinct() } @@ -475,7 +477,8 @@ object UserApps { if (!file.isFile) return context.getString(R.string.user_apps_file_gone) if (!FlatpakManager.ready(context)) FlatpakManager.setup(context, onProgress)?.let { return it } val shared = Environment.getExternalStorageDirectory().canonicalPath - val copy = File(LinuxRuntime.rootDir(context), "tmp/droiddeck-bundle.flatpak").takeIf { !file.canonicalPath.startsWith("$shared/") } + val copy = File(LinuxRuntime.rootDir(context), "tmp/droiddeck-bundle.flatpak") + .takeIf { !SessionPrefs.mountSharedStorage(context) || !file.canonicalPath.startsWith("$shared/") } try { if (copy != null) { onProgress(context.getString(R.string.user_apps_copying, file.name), -1) diff --git a/app/src/main/java/com/droiddeck/launcher/session/BottomDesktop.kt b/app/src/main/java/com/droiddeck/launcher/session/BottomDesktop.kt index b25ed487a2..b815d29fdd 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/BottomDesktop.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/BottomDesktop.kt @@ -40,6 +40,7 @@ object BottomDesktop { val generation: Int, val installed: Boolean, val nativeUserland: Boolean, + val sharedStorage: File?, ) @Volatile private var launch: Launch? = null @@ -91,10 +92,11 @@ object BottomDesktop { sessionDir: File, generation: Int, nativeUserland: Boolean, + sharedStorage: File?, stillCurrent: () -> Boolean, ) { val prepared = Launch(ArrayList(guest), ArrayList(binds), sessionRoot, hostEnvironment.copyOf(), root, sessionDir, generation, - DesktopCatalog.desktopInstalled(root), nativeUserland) + DesktopCatalog.desktopInstalled(root), nativeUserland, sharedStorage) synchronized(launchLock) { if (stillCurrent()) launch = prepared } } @@ -217,6 +219,19 @@ object BottomDesktop { fun sendText(text: String) { val target = service ?: return + if (text.isNotEmpty() && text.all { it == '\r' || it == '\n' || it == '\b' || it == '\u007f' || it == '\t' }) { + for (c in text) { + val evdev = when (c) { + '\r', '\n' -> 28 + '\b' -> 14 + '\u007f' -> 111 + else -> 15 + } + sendKey(evdev, true) + sendKey(evdev, false) + } + return + } send(target, Message.obtain(null, Comp.MSG_TEXT).apply { data = Bundle().apply { putString(Comp.KEY_TEXT, text) } }) } @@ -313,7 +328,7 @@ object BottomDesktop { val runtime = runtimeDir(context).apply { mkdirs() } val imeDir = File(current.sessionRoot, "bottom-desktop-ime") main.post { if (generation == guestGeneration) watchIme(imeDir) } - val binds = LinuxRuntime.binds(context, current.sessionRoot, runtime, Environment.getExternalStorageDirectory(), current.binds) + val binds = LinuxRuntime.binds(context, current.sessionRoot, runtime, current.sharedStorage, current.binds) val guest = ArrayList(current.guest).apply { add("DD_WIDTH=$width") add("DD_HEIGHT=$height") @@ -328,7 +343,8 @@ object BottomDesktop { LinuxRuntime.commandWithBinds(context, current.root, binds, guest) } val environment = if (current.nativeUserland) { - com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(current.root, binds, guest.first(), SessionPrefs.guestHostname(context)) + 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) .map { (k, v) -> "$k=$v" }.toTypedArray() } else current.hostEnvironment val line = command.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") } diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt index 146509bba7..b9be461b01 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -30,6 +30,8 @@ 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", @@ -38,7 +40,8 @@ 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) + 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 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") @@ -253,6 +256,28 @@ 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) @@ -1124,7 +1149,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 -> "fex" + DD_BIONIC, DD_XBOX -> "fex" else -> null } diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index c9c55f9c27..9490279fa8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -5,6 +5,7 @@ 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 @@ -25,6 +26,7 @@ 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 @@ -221,7 +223,7 @@ internal object EnhancedSessionLogShare { Category.values().map { category -> val budget = budgets.getValue(category) val records = ArrayList() - val selected = candidates.filter { it.category == category } + val selected = candidates.filter { it.category == category }.sortedBy(::sharePriority) val zip = File(out, "DroidDeck-${folder.name}-${category.suffix}.zip") ZipOutputStream(zip.outputStream().buffered()).use { archive -> val names = HashSet() @@ -268,7 +270,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 } + val candidates = discovery.candidates.filter { it.linePrefix == null }.sortedBy(::sharePriority) if (candidates.isEmpty()) { out.deleteRecursively() return null @@ -616,7 +618,8 @@ internal object EnhancedSessionLogShare { redactionLearningComplete: Boolean, ) { val entries = JSONArray() - records.take(MAX_MANIFEST_RECORDS).forEach { record -> + val (discovery, rest) = records.partition { it.origin == "discovery" } + (discovery + rest).take(MAX_MANIFEST_RECORDS).forEach { record -> entries.put(JSONObject().apply { put("entry", record.entry) put("origin", record.origin) @@ -680,6 +683,15 @@ 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") } } @@ -697,15 +709,6 @@ 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) @@ -722,16 +725,7 @@ internal object EnhancedSessionLogShare { add(source.file, source.root, source.entry, "battlenet") } } else { - 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") - } - } + battleNetRoots(context).forEach { (prefix, root) -> addRecentLogs(root, "battlenet/$prefix", "battlenet") } } val sessionScan = walk(folder, remaining(maxFiles, out.size)) truncated = truncated || sessionScan.truncated @@ -742,9 +736,28 @@ 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 { @@ -816,6 +829,39 @@ internal object EnhancedSessionLogShare { return ScanResult(files, truncated, partial) } + private class AntiCheatRoots(val roots: List>, val partial: Boolean) + + private fun antiCheatRoots(context: Context): AntiCheatRoots { + var partial = false + val seen = HashSet() + 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> { val drive = File(BattleNet.prefix(context), "pfx/drive_c") val data = File(drive, "ProgramData/Battle.net") @@ -922,7 +968,9 @@ 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.joinToString("/") { safeComponent(it) } + return parts.mapIndexed { index, part -> + if (index == 1 && parts[0] == "anticheat" && APP_ID.matches(part)) part else safeComponent(part) + }.joinToString("/") } private fun safeComponent(value: String): String { @@ -935,7 +983,7 @@ internal object EnhancedSessionLogShare { private fun category(entry: String): Category { val value = entry.lowercase(Locale.US) - if (value.startsWith("battlenet/") || value.startsWith("stores/") || value.startsWith("tools/") || value.startsWith("rpcs3/") || + if (value.startsWith("battlenet/") || value.startsWith("anticheat/") || 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 @@ -944,7 +992,7 @@ internal object EnhancedSessionLogShare { private val GAME_LOG = Regex("steam-[0-9]+\\.(log|txt)") private val KNOWN_COMPONENTS = setOf( - "steam", "graphics", "games", "battlenet", "client", "agent", "setup", "stores", "tools", + "steam", "graphics", "games", "battlenet", "anticheat", "anticheatlauncher.log", "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", @@ -955,11 +1003,15 @@ 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", @@ -967,6 +1019,7 @@ 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 diff --git a/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt b/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt new file mode 100644 index 0000000000..9d3cdd2e21 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt @@ -0,0 +1,18 @@ +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 } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index 708c1bcada..099cf7f46d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -114,7 +114,7 @@ object GameEnvironmentStore { ) { publishGameCores(context) val stored = config ?: read(context) - val resolved = stored.copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + stored.shared) + val resolved = GameEnvironment.withKnownGames(stored).copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + stored.shared) val json = encode(resolved) val dxvk = TextureFiltering.dxvkOptions( SessionPrefs.textureAnisotropy(context), SessionPrefs.textureLodBias(context), diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt b/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt index 263860334c..3c2d722c06 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt @@ -59,13 +59,18 @@ object GameStorage { return when { pref == SessionPrefs.GAME_STORAGE_OFF -> null pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) } - else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) } + else -> reachable(pref).let { path -> Option(SessionPrefs.gameStorageLabel(context), path).takeIf { attached(File(path)) } } } } fun disconnected(context: Context): Boolean { val pref = SessionPrefs.gameStorage(context) - return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref)) + return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(reachable(pref))) + } + + internal fun reachable(path: String, usable: (File) -> Boolean = { it.isDirectory && it.canWrite() }): String { + val alias = UsbLink.storagePath(path) + return if (alias != path && !usable(File(path)) && usable(File(alias))) alias else path } internal fun attached( diff --git a/app/src/main/java/com/droiddeck/launcher/session/Onboarding.kt b/app/src/main/java/com/droiddeck/launcher/session/Onboarding.kt index 2d18a84a30..bbfa7bfc29 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/Onboarding.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/Onboarding.kt @@ -29,6 +29,10 @@ object Onboarding { /** The setup screens belong to the first run; later runtime, Proton and Steam client updates keep the usual Play button. */ val firstRun = MutableStateFlow(true) + /** Called once, when this process finishes the first-run downloads itself; not when everything was already in place. */ + @Volatile var onFirstRunReady: (() -> Unit)? = null + @Volatile private var worked = false + fun attach(context: Context) { appContext = context.applicationContext val prefs = context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE) @@ -52,8 +56,10 @@ object Onboarding { private fun markFirstRunDone() { val context = appContext ?: return + val live = firstRun.value && worked context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(KEY_FIRST_RUN_DONE, true).apply() firstRun.value = false + if (live) onFirstRunReady?.invoke() } /** Keeps the process in the foreground, with one notification, while a step downloads and the runtime installer is not already doing so. */ @@ -90,6 +96,7 @@ object Onboarding { } fun report(step: Step, label: String, percent: Int) { + worked = true failed.value = failed.value - step active.value = active.value + (step to Progress(label, percent)) keepAlive() diff --git a/app/src/main/java/com/droiddeck/launcher/session/PageCacheTrim.kt b/app/src/main/java/com/droiddeck/launcher/session/PageCacheTrim.kt new file mode 100644 index 0000000000..8dc2079e1c --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/PageCacheTrim.kt @@ -0,0 +1,70 @@ +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, alive: () -> Boolean) { + Thread({ + var baseline = 0L + var files = emptyList() + 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 +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt b/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt index 412fc79627..756a721a7a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt @@ -9,6 +9,8 @@ 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 @@ -34,7 +36,9 @@ 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 prereleases: Boolean = false, val x86_64: Boolean = false, val label: Int = 0) { + val arch: String get() = if (x86_64) "x86-64" else "ARM64" + } 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) @@ -42,11 +46,13 @@ 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), ) @@ -66,11 +72,14 @@ object ProtonExtras { internal fun installedIn(dir: File, tool: Tool): List = dir.listFiles() - ?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && usable(it) } + ?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && x86_64Build(it) == tool.x86_64 && 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 @@ -108,15 +117,31 @@ object ProtonExtras { fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool)) - fun missing(context: Context, tool: Tool): String? = - if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null + 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): 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) private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE) - fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false) + fun declined(context: Context, id: String = OWN): Boolean = choices(context).getBoolean("$id.declined", false) - fun setDeclined(context: Context, declined: Boolean) { - choices(context).edit().putBoolean("$OWN.declined", declined).apply() + fun setDeclined(context: Context, declined: Boolean, id: String = OWN) { + choices(context).edit().putBoolean("$id.declined", declined).apply() } fun cachedLatest(context: Context, tool: Tool): String? = @@ -220,8 +245,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 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 + // 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 if (deleteTool(context, old)) ComponentsManager.forgetProton(context, old) else Log.w(TAG, "could not remove $old") } @@ -288,7 +313,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) + val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch) 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() @@ -305,7 +330,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) + val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch) 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() @@ -374,7 +399,7 @@ object ProtonExtras { archive.delete() unqueue(context, tool) record(context, tool, placed, asset.tag) - if (tool.id == OWN || tool.id == BIONIC) replaceOlder(context, tool) + if (tool.id == OWN || tool.id == BIONIC || tool.id == ANTICHEAT) replaceOlder(context, tool) if (EsyncPacks.enabled(context)) { onProgress(context.getString(R.string.esync_fetching), -1) try { diff --git a/app/src/main/java/com/droiddeck/launcher/session/QuestSteamVrLaunch.kt b/app/src/main/java/com/droiddeck/launcher/session/QuestSteamVrLaunch.kt new file mode 100644 index 0000000000..8f619b86b3 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/QuestSteamVrLaunch.kt @@ -0,0 +1,35 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import java.io.File + +/** + * On a Quest, SteamVR has to run inside the immersive activity. A launch from Steam's library happens in the + * guest, so the guest's SteamVR helper leaves a request in the shared runtime directory for the session to act on. + */ +object QuestSteamVrLaunch { + private const val DIR = ".wayland-rt/droiddeck-steamvr" + private const val MARKER = "quest-immersive" + private const val REQUEST = "xr-request" + + fun publish(context: Context) { + val dir = File(context.filesDir, DIR) + val marker = File(dir, MARKER) + if (!QuestExperimental.isSupported()) { + marker.delete() + return + } + runCatching { + dir.mkdirs() + marker.writeText("") + } + } + + /** A request left by an earlier session must not open the immersive view in this one. */ + fun clearRequest(context: Context) { + File(context.filesDir, "$DIR/$REQUEST").delete() + } + + fun takeRequest(context: Context): Boolean = + QuestExperimental.isSupported() && File(context.filesDir, "$DIR/$REQUEST").delete() +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt b/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt index 53fc319c26..08fa86f608 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt @@ -46,7 +46,16 @@ object SecondaryLibrary { } fun privateRoot(files: File, library: File): File { - val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray()) + val own = privateDir(files, library.canonicalPath) + if (own.exists()) return own + val raw = UsbLink.rawPath(library.absolutePath) + val alias = if (raw != library.absolutePath) raw else UsbLink.storagePath(library.absolutePath) + if (alias == library.absolutePath) return own + return privateDir(files, runCatching { File(alias).canonicalPath }.getOrDefault(alias)).takeIf { it.exists() } ?: own + } + + private fun privateDir(files: File, path: String): File { + val digest = MessageDigest.getInstance("SHA-256").digest(path.toByteArray()) .joinToString("") { "%02x".format(it.toInt() and 255) } return File(files, "steam-libraries/$digest") } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt index 919891fa45..10a20f9fcc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt @@ -16,6 +16,7 @@ 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? = diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index aa240b6ed0..dc708cb51d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -5,12 +5,14 @@ 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 import com.droiddeck.launcher.runtime.LegacyNames import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.runtime.ProotFastPath +import org.json.JSONObject import java.io.File object SessionFiles { @@ -21,6 +23,12 @@ 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") internal val DESKTOP_FILES = arrayOf( @@ -35,6 +43,7 @@ object SessionFiles { "usr/local/bin/kwin_wayland_wrapper" to "usr/local/bin/kwin_wayland_wrapper", "usr/lib/firefox/defaults/pref/droiddeck.js" to "usr/lib/firefox/defaults/pref/droiddeck.js", "etc/xdg/autostart/droiddeck-clipboard.desktop" to "etc/xdg/autostart/droiddeck-clipboard.desktop", + "usr/share/applications/droiddeck-return-gaming.desktop" to "usr/share/applications/droiddeck-return-gaming.desktop", "etc/xdg/fastfetch/config.jsonc" to "etc/xdg/fastfetch/config.jsonc", ) @@ -98,10 +107,23 @@ object SessionFiles { } private val STAGE_LOCK = Any() + @Volatile private var activeSessionLseEmu: String? = 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 = false) = + stage(context, root, startsSession, lseEmu = null) - private fun stageNow(context: Context, root: File, startsSession: Boolean) { + 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?) { 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) @@ -129,7 +151,11 @@ object SessionFiles { "usr/local/bin/droiddeck-agent" to "usr/local/bin/droiddeck-agent", "usr/local/bin/steam-compatibility" to "usr/local/bin/steam-compatibility", "usr/local/bin/droiddeck-clipboard" to "usr/local/bin/droiddeck-clipboard", + "usr/local/bin/droiddeck-spawn" to "usr/local/bin/droiddeck-spawn", + "usr/local/bin/droiddeck-log-writer" to "usr/local/bin/droiddeck-log-writer", "usr/local/bin/droiddeck-desktop-clipboard" to "usr/local/bin/droiddeck-desktop-clipboard", + "usr/local/bin/droiddeck-text-input" to "usr/local/bin/droiddeck-text-input", + "usr/local/bin/droiddeck-steam-ime" to "usr/local/bin/droiddeck-steam-ime", "usr/local/bin/droiddeck-gpu-window" to "usr/local/bin/droiddeck-gpu-window", "usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install", "usr/local/bin/droiddeck-steam-preapply" to "usr/local/bin/droiddeck-steam-preapply", @@ -153,6 +179,7 @@ object SessionFiles { "usr/local/bin/droiddeck-desktop-bookmarks" to "usr/local/bin/droiddeck-desktop-bookmarks", "usr/local/bin/droiddeck-downloads" to "usr/local/bin/droiddeck-downloads", "usr/local/bin/droiddeck-root" to "usr/local/bin/droiddeck-root", + "usr/local/bin/droiddeck-user" to "usr/local/bin/droiddeck-user", "usr/local/bin/droiddeck-text" to "usr/local/bin/droiddeck-text", "usr/local/bin/droiddeck-snapd" to "usr/local/bin/droiddeck-snapd", "usr/local/bin/droiddeck-emulators" to "usr/local/bin/droiddeck-emulators", @@ -272,6 +299,7 @@ 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) @@ -331,22 +359,25 @@ object SessionFiles { if (installed) ledger.staged(key, target) else Log.e(TAG, "DirectAudio $set/$relative NOT staged") } for (pack in SERVICE_PACKS.keys) stageStoreService(context, root, pack, ledger) + 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("/usr/local/lib/libddsession.so\n") + val preload = StringBuilder(lsePreload(CpuFeatures.lacksAtomics, File(root, LSE_EMU).isFile, lseEmu)) + preload.append("/usr/local/lib/libddsession.so\n") if (!File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()) { preload.append("/usr/local/lib/libfakeinput.so\n") } - val nativeUserland = SessionPrefs.nativeUserland(context) - if (nativeUserland) com.droiddeck.launcher.runtime.NativeGuest.prepare(context, root) - if (ProotFastPath.enabled(context)) { + 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 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"), preload.toString()) + FileUtils.writeString(File(etc, "droiddeck/native-preload"), nativePreload) val staged = File(etc, "ld.so.preload.staged") if (!FileUtils.writeString(staged, preload.toString()) || !staged.renameTo(File(etc, "ld.so.preload"))) { @@ -357,6 +388,7 @@ object SessionFiles { Log.e(TAG, "could not write steam-compatibility-label") } writeCjkFontConfig(root, etc) + writeSessionBusPolicy(etc) writeDesktopStrings(context, File(etc, "droiddeck").apply { mkdirs() }) val droiddeckEtc = File(etc, "droiddeck").apply { mkdirs() } val stagedSocket = File(droiddeckEtc, "bwrap-socket.staged") @@ -416,6 +448,42 @@ object SessionFiles { seen?.let { SessionPrefs.setBootMovieSteamSeen(context, it) } } + private fun stageImeFiles(context: Context, root: File, ledger: StageLedger) { + val entries = LinkedHashMap() + try { + val text = context.assets.open("linuxfs/$IME_MANIFEST").bufferedReader().use { it.readText() } + val files = JSONObject(text).getJSONObject("files") + for (name in files.keys()) { + entries[name] = files.optJSONObject(name)?.optString("mode").orEmpty().toIntOrNull(8) ?: IME_DEFAULT_MODE + } + entries[IME_MANIFEST] = IME_DEFAULT_MODE + } catch (e: Exception) { + Log.w(TAG, "the Chinese input payload is not bundled; Steam sessions start without it", e) + return + } + for ((relative, mode) in entries) { + val target = File(root, relative) + if (ledger.current(relative, target)) continue + val staged = File(target.parentFile, target.name + ".staged") + var installed = false + try { + target.parentFile?.mkdirs() + context.assets.open("linuxfs/$relative").use { input -> + staged.outputStream().use { output -> FileUtils.copy(input, output) } + } + installed = staged.setReadable(true, false) && + staged.setWritable((mode and 0x80) != 0, true) && + staged.setExecutable((mode and 0x49) != 0, false) && + staged.renameTo(target) + } catch (e: Exception) { + Log.w(TAG, "could not stage $relative", e) + } finally { + if (!installed) staged.delete() + } + if (installed) ledger.staged(relative, target) else Log.e(TAG, "$relative NOT staged") + } + } + internal fun resetMissingStartupMovie(config: File, force: Boolean): Boolean { synchronized(STEAM_CONFIG) { if (!config.isFile) return true @@ -879,6 +947,24 @@ object SessionFiles { } } + /** + * A session bus admits only its owner, and with droiddeck-user (the native hook's ordinary + * user) a root process and a user's share the bus while the kernel sees one Android uid. + */ + private fun writeSessionBusPolicy(etc: File) { + val xml = """ + + + + + +""" + val conf = File(etc, "dbus-1/session.d/droiddeck-users.conf") + conf.parentFile?.mkdirs() + if (!FileUtils.writeString(conf, xml)) Log.e(TAG, "could not write the session bus policy") + } + private fun writeCjkFontConfig(root: File, etc: File) { try { val confDir = File(etc, "fonts/conf.d").apply { mkdirs() } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index a7dffb7e20..523857654a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -63,6 +63,24 @@ object SessionPrefs { .takeIf { value -> orientationOptions.any { it.first == value } } ?: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + fun orientation(context: Context, mode: String?): Int { + val key = when (mode) { + "steam", SessionService.MODE_STEAM, SessionService.MODE_RUN -> "orientation.steam" + "desktop", SessionService.MODE_DESKTOP -> "orientation.desktop" + else -> null + } ?: return orientation(context) + val stored = prefs(context).getInt(key, Int.MIN_VALUE) + return if (stored == Int.MIN_VALUE) orientation(context) + else stored.takeIf { value -> orientationOptions.any { it.first == value } } ?: orientation(context) + } + + fun setOrientation(context: Context, mode: String, orientation: Int) { + require(mode == "steam" || mode == "desktop") + require(orientationOptions.any { it.first == orientation }) + val key = if (mode == "steam") "orientation.steam" else "orientation.desktop" + prefs(context).edit().putInt(key, orientation).apply() + } + /** The session menu's width in dp the user dragged it to; null keeps the default. */ fun drawerWidthDp(context: Context): Int? = prefs(context).getInt("drawerWidthDp", 0).takeIf { it > 0 } @@ -75,21 +93,73 @@ object SessionPrefs { prefs(context).edit().putInt("orientation", orientation).apply() } - fun windowOrientation(context: Context, followScreen: Boolean, smallestWidthDp: Int): Int = - if (followScreen && smallestWidthDp >= SessionDisplay.UNFOLDED_MIN_DP && !prefs(context).contains("orientation")) + fun windowOrientation(context: Context, followScreen: Boolean, smallestWidthDp: Int, mode: String? = null): Int { + val modeKey = when (mode) { + "steam", SessionService.MODE_STEAM, SessionService.MODE_RUN -> "orientation.steam" + "desktop", SessionService.MODE_DESKTOP -> "orientation.desktop" + else -> null + } + val preferences = prefs(context) + if (modeKey != null && preferences.contains(modeKey)) return orientation(context, mode) + return if (followScreen && smallestWidthDp >= SessionDisplay.UNFOLDED_MIN_DP && !preferences.contains("orientation")) ActivityInfo.SCREEN_ORIENTATION_USER else orientation(context) + } - fun portrait(context: Context): Boolean = when (orientation(context)) { + fun portrait(context: Context, mode: String? = null): Boolean = when (orientation(context, mode)) { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> true ActivityInfo.SCREEN_ORIENTATION_USER -> context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT else -> false } - fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true) + 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 setLauncherFullscreen(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("launcherFullscreen", on).apply() + 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 launcherFrost(context: Context): Boolean = prefs(context).getBoolean("launcherFrost", false) + + fun setLauncherFrost(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("launcherFrost", on).apply() + } + + fun frostWallpaper(context: Context): Boolean = prefs(context).getBoolean("frostWallpaper", true) + + fun setFrostWallpaper(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("frostWallpaper", on).apply() + } + + fun frostCards(context: Context): Boolean = prefs(context).getBoolean("frostCards", true) + + fun setFrostCards(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("frostCards", on).apply() + } + + fun frostTransparency(context: Context): Int = frostPercent(context, "frostTransparency", com.droiddeck.launcher.ui.FROST_WALLPAPER_DEFAULT) + + fun setFrostTransparency(context: Context, percent: Int) = setFrostPercent(context, "frostTransparency", percent) + + fun frostCardTransparency(context: Context): Int = frostPercent(context, "frostCardTransparency", com.droiddeck.launcher.ui.FROST_DEFAULT) + + fun setFrostCardTransparency(context: Context, percent: Int) = setFrostPercent(context, "frostCardTransparency", percent) + + private fun frostPercent(context: Context, key: String, default: Int): Int = + prefs(context).getInt(key, default).coerceIn(0, com.droiddeck.launcher.ui.FROST_MAX) + + private fun setFrostPercent(context: Context, key: String, percent: Int) { + prefs(context).edit().putInt(key, percent.coerceIn(0, com.droiddeck.launcher.ui.FROST_MAX)).apply() } fun controllerHaptics(context: Context): Boolean = prefs(context).getBoolean("controllerHaptics", true) @@ -305,13 +375,13 @@ object SessionPrefs { prefs(context).edit().putInt("libraryCardLevel", level).apply() } - fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", true) + fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", false) fun setLibraryShowTitle(context: Context, show: Boolean) { prefs(context).edit().putBoolean("libraryShowTitle", show).apply() } - fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", true) + fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", false) fun setLibraryShowSize(context: Context, show: Boolean) { prefs(context).edit().putBoolean("libraryShowSize", show).apply() @@ -493,6 +563,17 @@ object SessionPrefs { prefs(context).edit().putString("drawerPageHidden", keys.joinToString(",")).apply() } + fun drawerSections(context: Context): Map = + idList(prefs(context).getString("drawerSections", null)).mapNotNull { entry -> + val at = entry.lastIndexOf('=').takeIf { it > 0 } ?: return@mapNotNull null + entry.substring(0, at) to (entry.substring(at + 1) == "1") + }.toMap() + + fun setDrawerSections(context: Context, sections: Map) { + prefs(context).edit().putString("drawerSections", sections.entries.filter { ',' !in it.key } + .joinToString(",") { "${it.key}=${if (it.value) 1 else 0}" }).apply() + } + fun setNavTabHidden(context: Context, keys: Set) { prefs(context).edit().putString("navTabHidden", keys.joinToString(",")).apply() } @@ -876,13 +957,21 @@ object SessionPrefs { } - fun picturePosition(context: Context): String = - prefs(context).getString("picturePosition", "center") - ?.takeIf { it in listOf("top", "bottom", "left", "right", "center") } ?: "center" + private val picturePositions = setOf("center", "top", "bottom", "left", "right") - fun setPicturePosition(context: Context, position: String) { - prefs(context).edit().putString("picturePosition", - position.takeIf { it in listOf("top", "bottom", "left", "right", "center") } ?: "center").apply() + 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 integerScaling(context: Context): Boolean = @@ -960,12 +1049,6 @@ object SessionPrefs { fun micAsked(context: Context): Boolean = prefs(context).getBoolean("micAsked", false) - fun allFilesAsked(context: Context): Boolean = prefs(context).getBoolean("allFilesAsked", false) - - fun setAllFilesAsked(context: Context) { - prefs(context).edit().putBoolean("allFilesAsked", true).apply() - } - fun bluetoothAsked(context: Context): Boolean = prefs(context).getBoolean("bluetoothAsked", false) fun setBluetoothAsked(context: Context) { @@ -1090,22 +1173,22 @@ object SessionPrefs { fun gameThreadHints(context: Context): Boolean = prefs(context).getBoolean("gameThreadHints", true) - fun prootNoSeccomp(context: Context): Boolean = prefs(context).getBoolean("prootNoSeccomp", false) + /** Whether the phone's shared storage (/sdcard) is mounted into the Linux container. */ + @JvmStatic + fun mountSharedStorage(context: Context): Boolean = prefs(context).getBoolean("mountSharedStorage", true) - fun setProotNoSeccomp(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("prootNoSeccomp", on).apply() + fun setMountSharedStorage(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("mountSharedStorage", 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) - fun prootFastPath(context: Context): Boolean = prefs(context).getBoolean("prootFastPath", true) - - fun setProotFastPath(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("prootFastPath", on).apply() + fun setDesktopAsUser(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("desktopAsUser", on).apply() } fun cursorComposite(context: Context): Boolean = prefs(context).getBoolean("cursorComposite", true) @@ -1227,6 +1310,11 @@ object SessionPrefs { prefs(context).edit().putBoolean("venus", on).apply() } + /** Venus off with no choice stored, so that Auto turning it off does not read as the user's own choice. */ + fun clearVenus(context: Context) { + prefs(context).edit().remove("venus").apply() + } + fun setVkBridge(context: Context, on: Boolean) { prefs(context).edit().putBoolean("vkBridge", on).putBoolean("bridgeFellBack", false).apply() } @@ -1426,10 +1514,12 @@ object SessionPrefs { fun resolutionStored(context: Context, mode: String, panel: Pair, portrait: Boolean): String { if (!portrait) return landscapeResolutionStored(context, mode, panel) - val value = prefs(context).getString("displayResolution.portrait.$mode", null) ?: return SessionDisplay.LINK_LANDSCAPE + 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 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}" } ?: SessionDisplay.LINK_LANDSCAPE + return parseOrientedResolution(value)?.let { "${it.first}x${it.second}" } ?: fallback } fun parseOrientedResolution(text: String): Pair? = @@ -1691,6 +1781,9 @@ 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 } @@ -1787,10 +1880,17 @@ object SessionPrefs { prefs(context).edit().putBoolean(hdrKey(mode), on).apply() } - fun zeroCopy(context: Context, mode: String): Boolean = prefs(context).getBoolean("zeroCopy.$mode", true) + /** 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) { - prefs(context).edit().putBoolean("zeroCopy.$mode", on).apply() + prefs(context).edit().putBoolean("zeroCopy.${prefMode(mode)}", on).apply() } const val FPS_UNPACED = -1 @@ -1800,16 +1900,18 @@ object SessionPrefs { const val PIP_FPS = 30 - fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false): Int { - val limit = when { - mirrorRefreshLimit <= 0 && sessionLimit <= 0 -> FPS_UNPACED - mirrorRefreshLimit <= 0 -> sessionLimit - sessionLimit <= 0 -> mirrorRefreshLimit - else -> minOf(mirrorRefreshLimit, sessionLimit) - } + fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false, hostCap: Int = 0): Int { + val limit = listOf(mirrorRefreshLimit, sessionLimit, hostCap).filter { it > 0 }.minOrNull() ?: FPS_UNPACED 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 + val upscalerChoices = listOf( 2 to "Nearest", 0 to "Linear", 4 to "AMD FSR 1", 3 to "Snapdragon GSR", 8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only", @@ -1905,24 +2007,84 @@ 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 - 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) + if (profileId.startsWith("game:")) { + return hasGameUpscalerOverride(context, profileId.removePrefix("game:")) + } + return legacyScreenEffectsUpscaler(context, profileId) != null } fun screenEffectsUpscaler(context: Context, profileId: String?): Int { if (profileId.isNullOrBlank()) return 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) + 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) } fun setScreenEffectsUpscaler(context: Context, profileId: String?, mode: Int) { @@ -1930,6 +2092,10 @@ 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) ?: "{}") @@ -1966,6 +2132,7 @@ 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 { @@ -2110,6 +2277,12 @@ object SessionPrefs { (resolutionChosen(context, SessionService.MODE_DESKTOP) || resolutionChosen(context, SessionService.MODE_DESKTOP, true))) SessionService.MODE_DESKTOP else prefMode(mode) + fun showGlassesShortcut(context: Context): Boolean = prefs(context).getBoolean("showGlassesShortcut", true) + + fun setShowGlassesShortcut(context: Context, show: Boolean) { + prefs(context).edit().putBoolean("showGlassesShortcut", show).apply() + } + fun pipAutoEnter(context: Context): Boolean = prefs(context).getBoolean("pipAutoEnter", true) fun setPipAutoEnter(context: Context, enabled: Boolean) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 18b3d5b4e8..fb6d3503f8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -47,6 +47,7 @@ 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 @@ -394,8 +395,10 @@ 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) - SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL) - val steamUrlGameId = SessionState.steamUrl + val launchSteamUrl = intent?.getStringExtra(EXTRA_STEAM_URL) + val frontendSteamGame = intent?.getBooleanExtra(EXTRA_FRONTEND_STEAM_GAME, false) == true + SessionState.steamUrl = launchSteamUrl + val steamUrlGameId = launchSteamUrl ?.let { url -> when { url.startsWith(GAME_URL_PREFIX) -> @@ -417,6 +420,7 @@ class SessionService : Service() { SessionPrefs.screenEffectsProfileId(SessionState.mode, resolvedGameId, SessionState.program), ) com.droiddeck.launcher.stores.battlenet.BattleNetClient.clearRequests(LinuxRuntime.sessionRoot(this)) + QuestSteamVrLaunch.clearRequest(this) val gen = synchronized(SessionState.startLock) { synchronized(stopLock) { SessionState.steamClientArch = null @@ -425,6 +429,11 @@ 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 @@ -446,7 +455,7 @@ class SessionService : Service() { Thread({ OrphanReaper.reap("session starting") ProtonExtras.awaitReplacement(120_000) - runSession(gen) + runSession(gen, launchSteamUrl, frontendSteamGame) }, "session-start").start() return START_NOT_STICKY } @@ -499,7 +508,7 @@ class SessionService : Service() { } - private fun runSession(gen: Int) { + private fun runSession(gen: Int, launchSteamUrl: String?, frontendSteamGame: Boolean) { SessionPrefs.ensurePowerVrAutoDriversAfterGpuQuery(this) if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) { com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) } @@ -554,9 +563,11 @@ class SessionService : Service() { return } } - val agentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) } + val nextAgentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) } .onFailure { Log.w(TAG, "agent environment skipped", it) } - .getOrDefault(emptyList()) + val agentEnvironment = nextAgentEnvironment.getOrDefault(emptyList()) + val customEnvironment = extraEnv() + val lseEmu = (customEnvironment + agentEnvironment).lastOrNull { it.startsWith("LSE_EMU=") }?.substringAfter('=') try { if (systemVulkan) { SystemVulkanDriver.prepare(this) @@ -566,7 +577,7 @@ class SessionService : Service() { } pruneSystemVulkanRuntime() } - SessionFiles.stage(this, root, startsSession = true) + SessionFiles.stage(this, root, startsSession = true, lseEmu = lseEmu) } 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) @@ -613,6 +624,9 @@ class SessionService : Service() { val size = SessionState.outputSize val guest = ArrayList() 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) } @@ -622,7 +636,7 @@ class SessionService : Service() { .onFailure { Log.w(TAG, "forced components", it) } } try { - SessionEvents.step("client-environment") { addClientEnvironment(guest, steamHere, agentEnvironment) } + SessionEvents.step("client-environment") { addClientEnvironment(guest, steamHere, agentEnvironment, customEnvironment) } } 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) @@ -660,7 +674,7 @@ class SessionService : Service() { Log.i(TAG, "game resolution: ${w}x$h on a ${size.first}x${size.second} output") } if (SessionState.followScreen || size.first < size.second || - SessionPrefs.orientation(this) == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) + SessionPrefs.orientation(this, SessionState.mode) == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) guest.add("DD_FOLLOW_OUTPUT=1") if (SessionState.hdr) { guest.add("DD_HDR=1") @@ -704,10 +718,38 @@ class SessionService : Service() { if (com.droiddeck.launcher.gpu.Lossless.owned(this)) guest.add("DD_LOSSLESS_OWNED=1") } guest.add("DD_LAUNCH_DIR=" + sessionRoot.path) + // 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) + } + } + 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. guest.add("BL_LAUNCH_DIR=" + sessionRoot.path) GameStorage.effective(this)?.let { guest.add("DD_LIBRARY_LABEL=" + it.label.replace('"', ' ')) } if (SessionState.mode == MODE_STEAM && SessionState.steamUi == "desktop") guest.add("DD_STEAM_UI=desktop") + if (SessionPrefs.desktopAsUser(this)) guest.add("DD_DESKTOP_USER=1") // Detailed graphics logs: per-game logs and the guest's Vulkan summary (a GPU that is not // an Adreno, or Setup's switch), and graphics-report.txt for every session. if (GraphicsReport.detailed(this)) guest.add("DD_GAME_LOGS=1") @@ -722,7 +764,7 @@ class SessionService : Service() { val desktopGuest = ArrayList(guest) guest.add(LinuxRuntime.SESSION_SCRIPT) guest.add(SessionState.mode) - if (SessionState.mode == MODE_STEAM) SessionState.steamUrl?.takeIf { it.startsWith("steam://") }?.let { + if (SessionState.mode == MODE_STEAM) launchSteamUrl?.takeIf { it.startsWith("steam://") }?.let { guest.add(it) Log.i(TAG, "steam: handing the client $it") } @@ -742,14 +784,16 @@ class SessionService : Service() { SessionEvents.step("shm-clear") { FileUtils.clear(File(LinuxRuntime.liveDir(this), "shm")) } - val binds = sessionBinds(controllersOn, fakeInputDir, sessionDir, guest, sessionRoot, runtimeDir) - val nativeUserland = com.droiddeck.launcher.runtime.NativeGuest.enabled(this) + 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) synchronized(stopLock) { if (gen == sessionGen && SessionState.running) com.droiddeck.launcher.runtime.NativeGuest.sessionMode = nativeUserland } - val fastPathKey = if (ProotFastPath.enabled(this)) { + val fastPathKey = if (fastPath) { val prootBinds = LinuxRuntime.binds( - this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds, + this, sessionRoot, runtimeDir, sharedStorage, binds, ) val root = LinuxRuntime.rootDir(this) ProotFastPath.key(root, prootBinds)?.also { key -> @@ -763,21 +807,19 @@ class SessionService : Service() { } } else null - val sessionBindSpecs = LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds) + val sessionBindSpecs = LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds) val command = if (nativeUserland) { LinuxRuntime.rememberSessionBinds(sessionBindSpecs) com.droiddeck.launcher.runtime.NativeGuest.command(root, guest.first(), guest.drop(1)) } else { - LinuxRuntime.command(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds, guest) + 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 } @@ -789,7 +831,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)) + com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(root, sessionBindSpecs, guest.first(), SessionPrefs.guestHostname(this), lseEmu) .forEach { (k, v) -> env[k] = v } } else prootEnv @@ -797,7 +839,7 @@ class SessionService : Service() { val terminalCommand = if (nativeUserland) { com.droiddeck.launcher.runtime.NativeGuest.command(root, shellGuest.first(), shellGuest.drop(1)) } else { - LinuxRuntime.command(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds, shellGuest) + LinuxRuntime.command(this, sessionRoot, runtimeDir, sharedStorage, binds, shellGuest) } val terminalHostEnvironment = LinkedHashMap(System.getenv()) hostEnv.asArray().forEach { entry -> @@ -808,7 +850,7 @@ class SessionService : Service() { SessionTerminal.prepare(terminalCommand, terminalHostEnvironment.map { (key, value) -> "$key=$value" }.toTypedArray(), root, gen) val (fastPathName, _) = ProotFastPath.hostEnv("") BottomDesktop.prepare(desktopGuest, binds, sessionRoot, - prootEnv.asArray().filterNot { it.startsWith("$fastPathName=") }.toTypedArray(), root, sessionDir, gen, nativeUserland, + prootEnv.asArray().filterNot { it.startsWith("$fastPathName=") }.toTypedArray(), root, sessionDir, gen, nativeUserland, sharedStorage, ) { gen == sessionGen && SessionState.running } } @@ -861,10 +903,10 @@ class SessionService : Service() { watchLaunchRequests(sessionRoot) watchSyncWanted(root) EsyncPacks.fetchInBackground(this, root) - val pid = SessionEvents.step("guest-launch") { HostProcess.start(line, hostEnv.asArray(), root, { status -> + val pid = SessionEvents.step("guest-launch") { HostProcess.startUncounted(line, hostEnv.asArray(), root, { status -> if (gen != sessionGen) { Log.i(TAG, "an earlier session's process ended ($status); the current one carries on") - return@start + return@startUncounted } val program = programStatus(sessionRoot) Log.i(TAG, "session ended: $status" + if (program != null) " (program $program)" else "") @@ -880,10 +922,19 @@ class SessionService : Service() { syncWatcher = null } abandonStart(gen, sessionDir, started) - if (pid > 1) Thread({ teardown(pid) }, "session-teardown").start() + val workers = ownWorkers + if (pid > 1) Thread({ teardown(pid, workerSession = workers) }, "session-teardown").start() + else com.droiddeck.launcher.runtime.GuestWorkers.stopGuests(workers) return } sessionPid = pid + // Under the lock Stop clears it with, and only while this session still runs: a Stop since the + // check above has cleared it already, and this would set it again for no running session. + val uncounted = com.droiddeck.launcher.runtime.GuestWorkers.runsInWorker(pid) + synchronized(stopLock) { + if (gen == sessionGen && SessionState.running) + com.droiddeck.launcher.runtime.GuestWorkers.sessionRootUncounted = uncounted + } if (pid > 1) { raiseTracer(pid, gen) SessionEvents.guestStarted(pid) @@ -895,11 +946,15 @@ 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 }) + listOfNotNull(BottomDesktop.suspendPid.takeIf { it > 1 }) + + (if (workers > 0) com.droiddeck.launcher.runtime.GuestWorkers.guestPids(workers) else emptyList()) }, suspendAudio = { if (!pulse.setSinkSuspended(true)) Log.w(TAG, "could not suspend audio sink") @@ -991,7 +1046,8 @@ class SessionService : Service() { return com.droiddeck.launcher.input.GesturePrefs.read(this, game).relativeMouseMode } - private fun addClientEnvironment(guest: MutableList, steamHere: Boolean, agentEnvironment: List) { + private fun addClientEnvironment(guest: MutableList, steamHere: Boolean, + agentEnvironment: List, customEnvironment: List) { guest.add("/usr/bin/env") guest.add("-i") guest.add("DROIDDECK_BWRAP_SOCKET=" + com.droiddeck.launcher.runtime.BwrapSpawner.socket(this)) @@ -1109,7 +1165,7 @@ class SessionService : Service() { guest.add("DD_ZRAM=1") } guest.add("AUDIO_DIRECT_DECAY=0") - val extra = extraEnv() + agentEnvironment + val extra = customEnvironment + 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) } @@ -1256,6 +1312,8 @@ class SessionService : Service() { guest: MutableList, sessionRoot: File, runtimeDir: File, + sharedStorage: File?, + fastPath: Boolean, ): ArrayList { val binds = ArrayList() if (controllersOn) binds.add(fakeInputDir.path + ":/dev/input") @@ -1299,7 +1357,24 @@ class SessionService : Service() { if (controllersOn) components.add(RumbleComponent().also { it.attach(this) }) val home = File(LinuxRuntime.rootDir(this), "root") File(home, "Storage").mkdirs() - binds.add(Environment.getExternalStorageDirectory().path + ":/root/Storage") + 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) { + 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() + binds.add(folder.path + ":" + guest) + Log.i(TAG, "added game: $folder -> $guest (shared storage not mounted)") + } + } val library = GameStorage.effective(this) steamLibraryMounts = emptyMap() var storageDiagnosticLibrary: File? = null @@ -1343,7 +1418,7 @@ class SessionService : Service() { Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only") } } - for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) { + for (root in addedGameRoots) { if (root.host.isDirectory && root.host.canRead()) { File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs() binds.add(root.host.path + ":" + root.guest) @@ -1372,8 +1447,8 @@ 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 (ProotFastPath.enabled(this)) { - ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds).size + var room = if (fastPath) { + ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size } else Int.MAX_VALUE for (games in gamesLibraries) { if (games.host.path + ":" + games.guest !in binds) continue @@ -1414,8 +1489,8 @@ class SessionService : Service() { continue } try { - val room = if (ProotFastPath.enabled(this)) { - ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds).size + val room = if (fastPath) { + ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, sharedStorage, binds).size } else Int.MAX_VALUE val content = SecondaryLibrary.contentPath(entry.host) val extra = SecondaryLibrary.binds(filesDir, entry.host, listOf(entry.guest), content = content) @@ -1443,8 +1518,8 @@ class SessionService : Service() { if (problem != null) { Log.w(TAG, "x86-64 steam library: $problem") } else try { - val room = if (ProotFastPath.enabled(this)) { - ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds).size + val room = if (fastPath) { + 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) if (extra.size > room) { @@ -1465,8 +1540,8 @@ class SessionService : Service() { continue } try { - val room = if (ProotFastPath.enabled(this)) { - ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds).size + val room = if (fastPath) { + 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) if (extra.size > room) { @@ -1501,8 +1576,8 @@ class SessionService : Service() { try { val listing = File(filesDir, "session/desktop-volumes.json").apply { parentFile?.mkdirs() } val volumes = org.json.JSONArray() - var room = if (ProotFastPath.enabled(this)) { - ProotFastPath.MAX_BINDS - LinuxRuntime.binds(this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds).size + var room = if (fastPath) { + 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)) { if (!root.removable || !root.readable) continue @@ -1522,10 +1597,15 @@ class SessionService : Service() { return binds } - private fun teardown(prootPid: Int, expectedStartTime: Long? = null) { + // The workers' session number of the session running now (GuestWorkers.serve) + @Volatile private var guestWorkerSession = 0 + + private fun teardown(prootPid: Int, expectedStartTime: Long? = null, workerSession: Int = guestWorkerSession) { fun stillSameProcess(): Boolean = expectedStartTime == null || readStat(prootPid)?.second == expectedStartTime if (!stillSameProcess()) return - val tree = descendants(prootPid) + // The session's programs that run in worker processes are not descendants of its root. + val workers = if (expectedStartTime == null) com.droiddeck.launcher.runtime.GuestWorkers.guestPids(workerSession) else emptyList() + val tree = descendants(prootPid) + workers.flatMap { pid -> listOfNotNull(readStat(pid)?.let { Pair(pid, it.second) }) + descendants(pid) } if (!stillSameProcess()) return saveWineRegistries(tree) android.os.Process.sendSignal(prootPid, 15) @@ -1542,6 +1622,7 @@ class SessionService : Service() { killed++ } if (killed > 0) Log.i(TAG, "swept $killed process(es) proot left behind") + if (expectedStartTime == null) com.droiddeck.launcher.runtime.GuestWorkers.stopGuests(workerSession) } private fun clearCachedApps() { @@ -1716,6 +1797,7 @@ class SessionService : Service() { SessionEvents.record("steam.game_launch_requested", mapOf("gameId" to gameId, "generation" to gen)) watchGameExit(gameId, gen, exitWatchToken, pendingSteamPreviousGameId) Log.i(TAG, "queued Steam game $gameId for the running client") + com.droiddeck.launcher.runtime.GuestWorkers.expectLaunch(this) } private fun watchGameExit( @@ -2312,12 +2394,16 @@ class SessionService : Service() { return } completeNativeSleep() + var workers = 0 val (ended, endedArch) = synchronized(stopLock) { if (gen != null && gen != sessionGen) return + // as it is when running is cleared: startup registers its workers under this lock too + workers = guestWorkerSession cancelQueuedSteamGame() gameExitWatchToken++ // also when startup stopped before the guest ran com.droiddeck.launcher.runtime.NativeGuest.sessionMode = null + com.droiddeck.launcher.runtime.GuestWorkers.sessionRootUncounted = null if (!SessionState.running) return if (relaunch) SessionState.confirmRelaunchStop() SessionEvents.record("guest.exited", mapOf("status" to status)) @@ -2378,7 +2464,8 @@ class SessionService : Service() { if (prootPid > 1 && steamClientMayRun) askSteamToExit(prootPid) com.droiddeck.launcher.stores.gog.GogComet.end(stoppedSession) auxiliary.forEach { (pid, started) -> teardown(pid, started) } - if (prootPid > 1) teardown(prootPid) + if (prootPid > 1) teardown(prootPid, workerSession = workers) + else com.droiddeck.launcher.runtime.GuestWorkers.stopGuests(workers) killGuestLeftovers(ended) pruneSystemVulkanRuntime() finishSessionStop(status, stoppedGen, collectEnded) @@ -2387,6 +2474,7 @@ class SessionService : Service() { } else { Thread({ pruneSystemVulkanRuntime() }, "system-vulkan-prune").start() Thread({ + com.droiddeck.launcher.runtime.GuestWorkers.stopGuests(workers) com.droiddeck.launcher.stores.gog.GogComet.end(stoppedSession) finishSessionStop(status, stoppedGen, collectEnded) if (launcherEnded) importLauncherGames() @@ -2705,6 +2793,9 @@ 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( @@ -2712,6 +2803,7 @@ class SessionService : Service() { steamUi: String? = null, steamUrl: String? = null, programArgs: Array? = null, gameId: String? = null, displayId: Int = Display.DEFAULT_DISPLAY, + frontendSteamGame: Boolean = false, ) { SteamClientPrefetch.cancel() SessionState.activityDisplayId = displayId @@ -2722,6 +2814,7 @@ 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) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionVisibilityPolicy.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionVisibilityPolicy.kt index 90630ebbcd..79cc595af9 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionVisibilityPolicy.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionVisibilityPolicy.kt @@ -1,6 +1,12 @@ 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, diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index 0c1d8ddb1b..c9852d4b8b 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -12,17 +12,17 @@ object SettingsReset { private const val TAG = "SettingsReset" internal val SESSION_KEYS = setOf( - "orientation", "launcherFullscreen", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt", + "orientation", "launcherFullscreen", "launcherFullscreenMode", "sessionFullscreenMode", "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", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "drawerPageOrder", "drawerPageHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys", + "stretch16x9", "avoidNotch", "picturePosition", "picturePosition.portrait", "picturePosition.landscape", "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", "paceCores", + "tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "producerAcquireFences", "paceCores", "directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus", - "noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "nativeUserland", "cursorComposite", + "noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "nativeUserland", "cursorComposite", "mountSharedStorage", "guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics", "buildWatermark", "upscaler", "upscaleSharpness", "screenEffects", "blackFrameInsertion", "textureAnisotropy", "textureLodBias", "steamDownloadsInBackground", "steam_offline", "steam_offline_auto", "steam_offline_by_network", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds", "skipBootMovie", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt index 578f1c5cb4..4b08d0a3da 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt @@ -10,9 +10,23 @@ import java.io.File // browser view placed outside the Big Picture window, composition capped at "notification" so gamescope keeps the game // focused, and gamepad focus on the main UI. The hold is a lease the app renews, so Steam recovers if the app goes away. object SteamQam { - data class Target(val port: Int, val path: String) + /** [mainPath] is Steam's main menu page, shown beside the quick access menu in the split layout. */ + data class Target(val port: Int, val path: String, val mainPath: String? = null) + const val MAIN_MENU = 1 const val QUICK_ACCESS = 2 + + /** Height in CSS pixels both menus are laid out at in the split layout, so they show at one scale. */ + const val SPLIT_CSS_HEIGHT = 480 + + /** Steam's own width for the main menu; quick access takes the rest of the panel. */ + const val MAIN_CSS_WIDTH = 240 + + /** Holds the parked main menu in place and spreads its item rows (not dividers) over the full height, at most 80 px each. */ + private const val MAIN_PARKED_CSS = + ".BasicUI > .Panel { transform: none !important; width: 100% !important; height: 100% !important; margin: 0 !important; } " + + ".BasicUI > .Panel > :has(> .Focusable) { flex: 1 1 0 !important; height: auto !important; max-height: 80px; } " + + ".BasicUI > .Panel > :has(> .Focusable) > .Panel { height: 100% !important; }" const val LEASE_MS = 5_000 private const val TAG = "SteamQam" private const val EVAL_MS = 6_000L @@ -26,21 +40,54 @@ object SteamQam { * Takes or renews the lease for [owner], or releases it. A live lease held by a newer panel is never taken back by an * older one, so a late request from a panel being torn down cannot end its replacement's lease or change its layout. */ - internal fun leaseScript(on: Boolean, owner: Long, aspect: Float = 0f): String = + internal fun leaseScript(on: Boolean, owner: Long, aspect: Float = 0f, split: Boolean = false): String = if (on) "if (!(g.__ddQamUntil > Date.now()) || !(g.__ddQamOwner > $owner)) { g.__ddQamOwner = $owner; g.__ddQamUntil = Date.now() + $LEASE_MS;" + - (if (aspect > 0f) " g.__ddQamAspect = $aspect;" else "") + " }" + (if (aspect > 0f) " g.__ddQamAspect = $aspect;" else "") + " g.__ddQamSplit = $split; }" else "if (g.__ddQamOwner === $owner) g.__ddQamUntil = 0;" - /** [aspect] is the panel's width over height: the menu is laid out at that shape so every tab shows at one scale. */ - internal fun script(on: Boolean, aspect: Float = 0f, owner: Long = 0): String = """(() => { - const g = globalThis, QAM = 2; + /** + * [aspect] is the panel's width over height: the menu is laid out at that shape so every tab shows at one scale. With + * [split], Steam's main menu is kept rendered at its own width beside the quick access menu, which gets the rest. + */ + internal fun script(on: Boolean, aspect: Float = 0f, owner: Long = 0, split: Boolean = false): String = """(() => { + const g = globalThis, QAM = 2, MAIN = 1; const W = SteamUIStore.WindowStore.SteamUIWindows[0]; const m = W.MenuStore, c = W.m_CompositionStateStore; const nav = W.m_FocusNavContext; const popup = g_PopupManager.GetExistingPopup("SP BPM_uid0"); const held = () => g.__ddQamUntil > Date.now(); - const ours = () => held() && m.m_eOpenSideMenu === QAM && !g.__ddQamTop; + const split = () => held() && g.__ddQamSplit === true; + // Steam's views carry no names: the main menu's is the one Steam focuses while the main menu is open. Until Steam + // has shown it, the main menu is opened once with its view parked like the quick access menu's. + const probing = () => g.__ddMainProbe > Date.now(); + const ours = () => held() && !g.__ddQamTop && (m.m_eOpenSideMenu === QAM || (probing() && m.m_eOpenSideMenu === MAIN)); const width = (h) => g.__ddQamAspect > 0 ? Math.round(h * g.__ddQamAspect) : 0; + const parkX = () => popup.m_popup.innerWidth + 64; + const mainSize = () => [$MAIN_CSS_WIDTH, $SPLIT_CSS_HEIGHT]; + const qamSplitSize = () => [Math.max(Math.round($SPLIT_CSS_HEIGHT * (g.__ddQamAspect > 0 ? g.__ddQamAspect : 1)) - $MAIN_CSS_WIDTH, 320), $SPLIT_CSS_HEIGHT]; + const size = (w, h) => split() ? qamSplitSize() : [width(h) || w, h]; + const mainView = () => views().find(v => v.__ddMain); + // Only the quick access view is parked: the one Steam focuses while quick access is open. Before Steam has + // focused it, any view but the main menu's and the header's web page (Store and other pages) may be it. + const headerView = () => W.m_HeaderStore?.m_currentBrowserAndBackstack?.m_browserView; + const isQam = (v) => !v.__ddMain && v !== headerView() && + (!!v.__ddQamView || !views().some(o => o.__ddQamView) || (probing() && m.m_eOpenSideMenu === MAIN)); + const mainParked = () => split() && (m.m_eOpenSideMenu !== MAIN || probing()); + const mainDoc = () => { + for (const s of SteamUIStore.m_GamepadNavigationManager?.m_rgGamepadInputSources || []) { + try { const d = s.m_targetWindow?.document; if (d?.title?.startsWith("MainMenu")) return d; } catch (e) {} + } + return null; + }; + // Steam slides the main menu out whenever it is not the open side menu; parked, it stays in place and fills its view. + const mainStyle = (on) => { + const d = mainDoc(); + let s = d?.getElementById("dd-main-split"); + if (!on) { s?.remove(); return; } + if (!d?.head) return; + if (!s) { s = d.createElement("style"); s.id = "dd-main-split"; d.head.appendChild(s); } + if (s.textContent !== "$MAIN_PARKED_CSS") s.textContent = "$MAIN_PARKED_CSS"; + }; if (!c.__ddQam) { c.__ddQam = c.ComputeOverallMinimumRequestedComposition; m.__ddQam = m.OnMenuDeactivated; @@ -59,6 +106,18 @@ object SteamQam { return without >= 2 ? v : 1; }; } + // Steam frosts its Store page while a side menu is open; a parked menu is not over it. + const inst = m.m_Instance; + if (inst?.SetStoreBrowserGlass && !inst.__ddQamGlass) { + inst.__ddQamGlass = inst.SetStoreBrowserGlass; + inst.SetStoreBrowserGlass = function (e) { return inst.__ddQamGlass.call(this, ours() ? 0 : e); }; + } + const glass = () => { + const on = !ours() && m.m_eOpenSideMenu !== 0; + if (g.__ddQamGlassOn === on) return; + g.__ddQamGlassOn = on; + inst?.SetStoreBrowserGlass?.(m.m_eOpenSideMenu); + }; const views = () => popup?.m_rgChildBrowserViews || []; const backdrop = (hide) => { const doc = popup?.m_popup?.document; @@ -75,16 +134,61 @@ object SteamQam { }; const keep = () => { for (const v of views()) { - if (v.__ddQam) continue; - v.__ddQam = v.SetBounds; + if (!v.__ddQam) v.__ddQam = v.SetBounds; + if (v.__ddQamW === 4) continue; + v.__ddQamW = 4; + v.__ddQamVis = v.__ddQamVis || v.SetVisible; + v.__ddQamFocus = v.__ddQamFocus || v.SetFocus; v.SetBounds = function (x, y, w, h, ...r) { + if (v.__ddMain && mainParked()) { + if (w > 0) v.__ddMainAsked = [x, y, w, h]; + [w, h] = mainSize(); + v.__ddMainOn = true; v.__ddMainW = w; v.__ddMainH = h; + return v.__ddQam.call(this, parkX(), 0, w, h, ...r); + } + if (v.__ddMain && w > 0) mainStyle(false); v.__ddAsked = [x, y, w, h]; - if (w > 0 && ours()) { x = popup.m_popup.innerWidth + 64; w = width(h) || w; } + if (w > 0 && ours() && isQam(v)) { x = parkX(); [w, h] = size(w, h); } v.__ddAt = x; v.__ddW = w; + v.__ddH = h; return v.__ddQam.call(this, x, y, w, h, ...r); }; + v.SetVisible = function (on, ...r) { + return v.__ddQamVis.call(this, on || (!!v.__ddMain && mainParked()), ...r); + }; + v.SetFocus = function (on, ...r) { + if (on && m.m_eOpenSideMenu === MAIN && v !== headerView()) { + for (const o of views()) if (o !== v) delete o.__ddMain; + v.__ddMain = true; + delete v.__ddQamView; + } + if (on && m.m_eOpenSideMenu === QAM && !v.__ddMain && v !== headerView()) { + for (const o of views()) if (o !== v) delete o.__ddQamView; + v.__ddQamView = true; + } + return v.__ddQamFocus.call(this, on, ...r); + }; } + if (g.__ddMainProbe && !probing()) { g.__ddMainProbe = 0; g.__ddMainProbed = true; } + if (probing() && mainView()) { g.__ddMainProbe = 0; g.__ddMainProbed = true; } + const mv = mainView(); + if (mv && !probing()) { + if (mainParked()) { + const [w, h] = mainSize(); + if (!mv.__ddMainOn || mv.__ddMainW !== w || mv.__ddMainH !== h) { + mv.__ddQam.call(mv, parkX(), 0, w, h); + mv.__ddQamVis.call(mv, true); + mv.__ddMainOn = true; mv.__ddMainW = w; mv.__ddMainH = h; + } + } else if (mv.__ddMainOn) { + mv.__ddMainOn = false; + if (m.m_eOpenSideMenu !== MAIN) { mv.__ddQamVis.call(mv, false); mv.__ddQam.call(mv, 0, 0, 0, 0); } + else if (mv.__ddMainAsked) mv.__ddQam.call(mv, ...mv.__ddMainAsked); + } + } + mainStyle(!!mv && mainParked() && !probing()); + glass(); if (!held()) { const parked = !g.__ddQamTop; g.__ddQamTop = false; @@ -124,6 +228,25 @@ object SteamQam { } g.__ddQamTop = false; } + // Each Split activation gets a fresh probe budget, and a spent one refills after a backoff, so a Steam that was + // still loading does not leave the main menu undiscovered for good. + if (split() !== !!g.__ddQamSplitOn) { g.__ddQamSplitOn = split(); if (split()) g.__ddMainProbes = 0; } + if (split() && !mv) { + if (probing()) return; + if ((g.__ddMainProbes || 0) >= 3 && Date.now() - (g.__ddMainProbeLast || 0) > 30000) g.__ddMainProbes = 0; + if ((g.__ddMainProbes || 0) < 3 && m.m_eOpenSideMenu !== MAIN) { + g.__ddMainProbes = (g.__ddMainProbes || 0) + 1; + g.__ddMainProbeLast = Date.now(); + g.__ddMainProbe = Date.now() + 1500; + m.OpenMainMenu(); + c.EnsureCorrectComposition?.(); + return; + } + } + if (g.__ddMainProbed) { + g.__ddMainProbed = false; + if (m.m_eOpenSideMenu === MAIN) m.OpenQuickAccessMenu(g.__ddQamTab ?? undefined); + } const decky = !!g.DeckyPluginLoader?.tabsHook?.qamBrowserViewPatch; // Decky hooks the menu after Steam starts; the menu has to unmount for its tab to appear, so reopen on the next tick. if (m.m_eOpenSideMenu === QAM && decky && !g.__ddQamDecky) { g.__ddQamDecky = true; m.CloseSideMenus(); return; } @@ -136,18 +259,26 @@ object SteamQam { if (m.m_eQuickAccessTab != null) g.__ddQamTab = m.m_eQuickAccessTab; if (!g.__ddQamOn) { g.__ddQamOn = true; c.EnsureCorrectComposition?.(); } for (const v of views()) { + if (v.__ddMain) continue; + if (!isQam(v)) { + // A view parked before the quick access view was known goes back where Steam asked for it. + const a = v.__ddAsked; + if (a?.[2] > 0 && v.__ddAt >= popup.m_popup.innerWidth) { v.__ddQam.call(v, ...a); v.__ddAt = a[0]; v.__ddW = a[2]; v.__ddH = a[3]; } + continue; + } if (!v.__ddAsked) { const b = v.GetBounds?.(); - if (b && b.width > 0) { v.__ddAsked = [b.x, b.y, b.width, b.height]; v.__ddAt = b.x; v.__ddW = b.width; } + if (b && b.width > 0) { v.__ddAsked = [b.x, b.y, b.width, b.height]; v.__ddAt = b.x; v.__ddW = b.width; v.__ddH = b.height; } } const a = v.__ddAsked; - if (a?.[2] > 0 && (v.__ddAt < popup.m_popup.innerWidth || (width(a[3]) && v.__ddW !== width(a[3])))) v.SetBounds(...a); + const [w, h] = a?.[2] > 0 ? size(a[2], a[3]) : [0, 0]; + if (a?.[2] > 0 && (v.__ddAt < popup.m_popup.innerWidth || v.__ddW !== w || v.__ddH !== h)) v.SetBounds(...a); } const main = nav?.m_rgGamepadNavigationTrees?.find(t => t.m_ID === "GamepadUI_Full_Root"); - if (main && nav.m_LastActiveNavTree?.m_ID?.startsWith("QuickAccess")) nav.SetActiveNavTree(main); + if (main && /^(QuickAccess|MainMenu)/.test(nav.m_LastActiveNavTree?.m_ID ?? "")) nav.SetActiveNavTree(main); backdrop(true); }; - ${leaseScript(on, owner, aspect)} + ${leaseScript(on, owner, aspect, split)} keep(); if (held() && !g.__ddQamTimer) { g.__ddQamTimer = setInterval(() => { @@ -161,7 +292,8 @@ object SteamQam { /** [open] is Steam's open side menu; [top] is true while the menu is shown on the top screen. */ data class Hold(val open: Int, val top: Boolean) - fun hold(context: Context, aspect: Float, owner: Long): Hold? = eval(context, script(true, aspect, owner))?.let(::parseHold) + fun hold(context: Context, aspect: Float, owner: Long, split: Boolean = false): Hold? = + eval(context, script(true, aspect, owner, split))?.let(::parseHold) internal fun parseHold(text: String): Hold? = runCatching { val a = JSONArray(text) @@ -181,7 +313,9 @@ object SteamQam { fun target(context: Context): Target? = runCatching { val devtools = File(AgentGuest.dir(context), "cdp-port").readText().trim().toInt() val (relay, secret) = parseRelay(helper(context, "start", devtools.toString())) ?: return null - val found = runCatching { parseTarget(relay, get(relay, "/$secret/json"))?.let { it.copy(path = "/$secret${it.path}") } } + val found = runCatching { + parseTarget(relay, get(relay, "/$secret/json"))?.let { t -> t.copy(path = "/$secret${t.path}", mainPath = t.mainPath?.let { "/$secret$it" }) } + } if (found.getOrNull() == null) helper(context, "stop", relay.toString()) found.getOrThrow() }.onFailure { android.util.Log.e(TAG, "no quick access target: $it") }.getOrNull() @@ -232,14 +366,16 @@ object SteamQam { internal fun parseTarget(port: Int, json: String): Target? { val list = JSONArray(json) - for (i in 0 until list.length()) { - val t = list.optJSONObject(i) ?: continue - if (!t.optString("title").startsWith("QuickAccess")) continue - val ws = t.optString("webSocketDebuggerUrl") - val path = Regex("^ws://[^/]+(/devtools/page/[A-Za-z0-9-]+)$").find(ws)?.groupValues?.get(1) ?: continue - return Target(port, path) + fun page(prefix: String): String? { + for (i in 0 until list.length()) { + val t = list.optJSONObject(i) ?: continue + if (!t.optString("title").startsWith(prefix)) continue + val ws = t.optString("webSocketDebuggerUrl") + Regex("^ws://[^/]+(/devtools/page/[A-Za-z0-9-]+)$").find(ws)?.groupValues?.get(1)?.let { return it } + } + return null } - return null + return page("QuickAccess")?.let { Target(port, it, page("MainMenu")) } } private fun eval(context: Context, expression: String): String? = runCatching { diff --git a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt index b309bca43b..207a9921e6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt @@ -105,14 +105,9 @@ object WinComponents { const val VCREDIST_ARM64 = "vcredist2022_arm64" internal fun builtInArm64Runtime(): Component { - fun value(view: String, name: String, type: String, data: String) = Step("set_register_key", JSONObject() - .put("action", "set_register_key").put("key", "HKLM\\Software\\${view}Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64") - .put("value", name).put("type", type).put("data", data)) - val steps = listOf("", "Wow6432Node\\").flatMap { view -> - listOf(value(view, "Installed", "REG_DWORD", "1"), value(view, "Major", "REG_DWORD", "14"), value(view, "Minor", "REG_DWORD", "44"), - value(view, "Bld", "REG_DWORD", "35211"), value(view, "Rbld", "REG_DWORD", "0"), value(view, "Version", "REG_SZ", "v14.44.35211.00")) - } - return Component(VCREDIST_ARM64, "Microsoft Visual C++ 2015-2022 ARM64 runtime 14.44.35211 (registry entries only)", "Microsoft", "ready", emptyList(), steps) + val install = Step("install_exe", JSONObject().put("action", "install_exe").put("file_name", "VC_redist.arm64.exe") + .put("url", "https://aka.ms/vs/17/release/vc_redist.arm64.exe")) + return Component(VCREDIST_ARM64, "Microsoft Visual C++ 2015-2022 Redistributable (arm64)", "Microsoft", "ready", emptyList(), listOf(install), revision = 2) } private fun parse(body: String): List? { diff --git a/app/src/main/java/com/droiddeck/launcher/session/XboxBackCompatComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/XboxBackCompatComponents.kt new file mode 100644 index 0000000000..e547cd8963 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/XboxBackCompatComponents.kt @@ -0,0 +1,78 @@ +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 = 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 = 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() + 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 } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrGesture.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrGesture.kt new file mode 100644 index 0000000000..cbd66f1964 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrGesture.kt @@ -0,0 +1,68 @@ +package com.droiddeck.launcher.session.xr + +/** + * The menu gesture: both controllers held together. It arms when the two aim points come within + * [ARM_METRES], cancels once they part beyond [CANCEL_METRES], and fires after [HOLD_MS] held. + * It needs both controllers apart again before it can arm a second time. + */ +internal class XrGesture { + enum class Phase { IDLE, ARMING, FIRED } + + var phase = Phase.IDLE + private set + var progress = 0f + private set + var midpoint = Vec3.ZERO + private set + private var startedMs = 0L + private var needsRelease = false + + /** Returns true on the frame the gesture completes. */ + fun update(left: XrHand, right: XrHand, nowMs: Long): Boolean { + if (!left.active || !right.active) { + reset(release = false) + return false + } + val a = left.aim.position + val b = right.aim.position + val distance = (a - b).length + midpoint = Vec3.lerp(a, b, 0.5f) + if (needsRelease) { + if (distance > CANCEL_METRES) needsRelease = false + phase = Phase.IDLE + progress = 0f + return false + } + when (phase) { + Phase.IDLE, Phase.FIRED -> if (distance < ARM_METRES) { + phase = Phase.ARMING + startedMs = nowMs + progress = 0f + } + Phase.ARMING -> if (distance > CANCEL_METRES) { + phase = Phase.IDLE + progress = 0f + } else { + progress = ((nowMs - startedMs).toFloat() / HOLD_MS).coerceIn(0f, 1f) + if (progress >= 1f) { + phase = Phase.FIRED + needsRelease = true + return true + } + } + } + return false + } + + fun reset(release: Boolean) { + phase = Phase.IDLE + progress = 0f + if (release) needsRelease = true + } + + companion object { + const val ARM_METRES = 0.09f + const val CANCEL_METRES = 0.14f + const val HOLD_MS = 1500L + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrHost.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrHost.kt new file mode 100644 index 0000000000..48424cccbf --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrHost.kt @@ -0,0 +1,160 @@ +package com.droiddeck.launcher.session.xr + +import java.nio.ByteBuffer +import java.nio.ByteOrder + +/** + * Typed access to the two buffers quest_xr.cpp shares each frame (app/src/main/cpp/questxr/xr_host.h). + * The offsets here must match that header. + */ +internal object XrHostLayout { + const val VERSION = 1 + const val LAYERS = 6 + const val STATE_SIZE = 288 + const val CONTROL_SIZE = 552 + const val POSE_SIZE = 32 + const val HAND_SIZE = 96 + const val STATE_HEAD = 32 + const val STATE_HANDS = 64 + const val HAND_GRIP = 0 + const val HAND_AIM = 32 + const val HAND_TRIGGER = 64 + const val HAND_SQUEEZE = 68 + const val HAND_STICK = 72 + const val HAND_BUTTONS = 80 + const val HAND_ACTIVE = 84 + const val CONTROL_HANDS = 8 + const val HAND_CONTROL_SIZE = 40 + const val HAND_CONTROL_MASK = 0 + const val HAND_CONTROL_LASER = 4 + const val HAND_CONTROL_HAPTIC = 8 + const val CONTROL_ORB = 88 + const val CONTROL_LAYERS = 136 + const val LAYER_SIZE = 64 + + const val FLAG_SURFACE_SWAPCHAIN = 1 + const val FLAG_FOCUSED = 2 + const val MASK_INPUT = 1 + const val LAYER_ALPHA = 1 + const val LAYER_HEAD_LOCKED = 2 + + const val SECONDARY_CLICK = 1 shl 2 +} + +internal class XrHand( + val grip: Pose, + val aim: Pose, + val trigger: Float, + val squeeze: Float, + val stickX: Float, + val stickY: Float, + val buttons: Int, + val active: Boolean, +) { + val secondary: Boolean get() = buttons and XrHostLayout.SECONDARY_CLICK != 0 + + companion object { + val IDLE = XrHand(Pose(), Pose(), 0f, 0f, 0f, 0f, 0, false) + } +} + +internal class XrFrame(val flags: Int, val frame: Long, val displayTimeNs: Long, val head: Pose, val hands: List) { + val focused: Boolean get() = flags and XrHostLayout.FLAG_FOCUSED != 0 + val surfaces: Boolean get() = flags and XrHostLayout.FLAG_SURFACE_SWAPCHAIN != 0 +} + +internal class XrHaptic(val durationMs: Int, val amplitude: Float, val frequency: Float = 0f) + +internal class XrLayerOut( + val id: Int, + val pose: Pose, + val width: Float, + val height: Float, + val order: Int, + val alpha: Boolean = true, +) + +internal class XrControlOut { + val masks = BooleanArray(2) + val lasers = FloatArray(2) + val haptics = arrayOfNulls(2) + var orb: Orb? = null + val layers = mutableListOf() + + class Orb(val position: Vec3, val radius: Float, val progress: Float, val burst: Float) +} + +internal class XrHost(state: ByteBuffer, control: ByteBuffer) { + private val state = state.order(ByteOrder.nativeOrder()) + private val control = control.order(ByteOrder.nativeOrder()) + private val hapticIds = LongArray(2) + + init { + require(state.capacity() >= XrHostLayout.STATE_SIZE && control.capacity() >= XrHostLayout.CONTROL_SIZE) { "XR host buffers too small" } + } + + fun read(): XrFrame = readFrame(state) + + fun write(out: XrControlOut) = writeControl(control, out, hapticIds) + + companion object { + fun readPose(b: ByteBuffer, at: Int) = Pose( + Quat(b.getFloat(at), b.getFloat(at + 4), b.getFloat(at + 8), b.getFloat(at + 12)), + Vec3(b.getFloat(at + 16), b.getFloat(at + 20), b.getFloat(at + 24)), + ) + + fun writePose(b: ByteBuffer, at: Int, pose: Pose) { + b.putFloat(at, pose.orientation.x); b.putFloat(at + 4, pose.orientation.y) + b.putFloat(at + 8, pose.orientation.z); b.putFloat(at + 12, pose.orientation.w) + b.putFloat(at + 16, pose.position.x); b.putFloat(at + 20, pose.position.y); b.putFloat(at + 24, pose.position.z) + b.putInt(at + 28, 0) + } + + fun readFrame(b: ByteBuffer): XrFrame { + val hands = (0 until 2).map { hand -> + val at = XrHostLayout.STATE_HANDS + hand * XrHostLayout.HAND_SIZE + XrHand( + readPose(b, at + XrHostLayout.HAND_GRIP), readPose(b, at + XrHostLayout.HAND_AIM), + b.getFloat(at + XrHostLayout.HAND_TRIGGER), b.getFloat(at + XrHostLayout.HAND_SQUEEZE), + b.getFloat(at + XrHostLayout.HAND_STICK), b.getFloat(at + XrHostLayout.HAND_STICK + 4), + b.getInt(at + XrHostLayout.HAND_BUTTONS), b.getInt(at + XrHostLayout.HAND_ACTIVE) != 0, + ) + } + return XrFrame(b.getInt(8), b.getLong(16), b.getLong(24), readPose(b, XrHostLayout.STATE_HEAD), hands) + } + + fun writeControl(b: ByteBuffer, out: XrControlOut, hapticIds: LongArray) { + for (i in 0 until XrHostLayout.CONTROL_SIZE step 4) b.putInt(i, 0) + b.putInt(0, XrHostLayout.VERSION) + for (hand in 0 until 2) { + val at = XrHostLayout.CONTROL_HANDS + hand * XrHostLayout.HAND_CONTROL_SIZE + b.putInt(at + XrHostLayout.HAND_CONTROL_MASK, if (out.masks[hand]) XrHostLayout.MASK_INPUT else 0) + b.putFloat(at + XrHostLayout.HAND_CONTROL_LASER, out.lasers[hand]) + out.haptics[hand]?.let { hapticIds[hand]++ } + val haptic = at + XrHostLayout.HAND_CONTROL_HAPTIC + b.putLong(haptic, hapticIds[hand]) + out.haptics[hand]?.let { + b.putLong(haptic + 8, it.durationMs * 1_000_000L) + b.putFloat(haptic + 16, it.amplitude) + b.putFloat(haptic + 20, it.frequency) + } + } + out.orb?.let { orb -> + val at = XrHostLayout.CONTROL_ORB + b.putInt(at, 1) + b.putFloat(at + 4, orb.progress); b.putFloat(at + 8, orb.burst); b.putFloat(at + 12, orb.radius) + writePose(b, at + 16, Pose(position = orb.position)) + } + out.layers.take(XrHostLayout.LAYERS).forEachIndexed { index, layer -> + val at = XrHostLayout.CONTROL_LAYERS + index * XrHostLayout.LAYER_SIZE + b.putInt(at, layer.id) + b.putInt(at + 4, 1) + b.putInt(at + 8, if (layer.alpha) XrHostLayout.LAYER_ALPHA else 0) + b.putInt(at + 12, layer.order) + writePose(b, at + 16, layer.pose) + b.putFloat(at + 48, layer.width); b.putFloat(at + 52, layer.height) + } + for (index in out.layers.size until XrHostLayout.LAYERS) b.putInt(XrHostLayout.CONTROL_LAYERS + index * XrHostLayout.LAYER_SIZE, -1) + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrInteraction.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrInteraction.kt new file mode 100644 index 0000000000..d045a87663 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrInteraction.kt @@ -0,0 +1,303 @@ +package com.droiddeck.launcher.session.xr + +import kotlin.math.PI +import kotlin.math.abs + +/** + * [barButton]: the grab bar has a button at its left end; the menu has its own close button instead. + * [tilt]: how far the panel leans back from upright, in radians, as a keyboard lies on a desk. + */ +internal enum class XrPanelKind( + val key: String, val resizable: Boolean, val chrome: Boolean, val barButton: Boolean = false, val tilt: Float = 0f, +) { + MENU("menu", resizable = true, chrome = true), + PET_HEAD("pet_head", resizable = false, chrome = false), + PET_CHAT("pet_chat", resizable = true, chrome = true, barButton = true), + KEYBOARD("keyboard_desk", resizable = true, chrome = true, barButton = true, tilt = (PI / 4).toFloat()); + + /** Turned towards [head] about the vertical axis, then leant back by [tilt]. */ + fun orient(position: Vec3, head: Vec3): Quat = facing(position, head) * Quat.pitch(-tilt) +} + +/** Where a panel is and how big, in metres; [pixelWidth] and [pixelHeight] are its surface's size. */ +internal class XrPanelState(val kind: XrPanelKind, var pose: Pose, var width: Float, var height: Float) { + var pixelWidth = XrUnits.pixels(width) + var pixelHeight = XrUnits.pixels(height) + /** 0 while it opens or closes from [animationFrom], 1 when it is in place and takes input. */ + var scale = 1f + var animationFrom: Vec3? = null + + val shownPose: Pose get() = animationFrom?.let { Pose(pose.orientation, Vec3.lerp(it, pose.position, scale)) } ?: pose + val interactive: Boolean get() = scale >= 1f + + fun hit(ray: Pose): XrHit? = hitPlane(ray, bounded = true) + + /** Where [ray] meets this panel's plane; [bounded] limits it to the panel itself. */ + fun hitPlane(ray: Pose, bounded: Boolean, plane: Pose = pose, w: Float = width, h: Float = height): XrHit? { + val normal = plane.orientation.rotate(Vec3(0f, 0f, 1f)) + val direction = ray.forward + val denominator = direction dot normal + if (denominator > -1e-4f) return null + val distance = ((plane.position - ray.position) dot normal) / denominator + if (distance <= 0f) return null + val local = plane.toLocal(ray.position + direction * distance) + if (bounded && (abs(local.x) > w / 2f || abs(local.y) > h / 2f)) return null + return XrHit(this, local.x, local.y, distance) + } + + fun u(localX: Float) = (localX / width + 0.5f).coerceIn(0f, 1f) + fun v(localY: Float) = (0.5f - localY / height).coerceIn(0f, 1f) + fun pixelX(localX: Float) = u(localX) * pixelWidth + fun pixelY(localY: Float) = v(localY) * pixelHeight + + /** The grab bar runs along the bottom, as under Quest's own windows, with its button at the left end. */ + fun inBar(hit: XrHit) = kind.chrome && hit.y + 0.5f * height <= XrUnits.BAR_METRES + fun inBarButtons(hit: XrHit) = kind.barButton && inBar(hit) && hit.x + 0.5f * width <= XrUnits.BAR_BUTTONS_METRES + fun inResizeGrip(hit: XrHit) = kind.resizable && + 0.5f * width - hit.x <= XrUnits.GRIP_METRES && hit.y + 0.5f * height <= XrUnits.GRIP_METRES +} + +internal class XrHit(val panel: XrPanelState, val x: Float, val y: Float, val distance: Float) + +internal object XrUnits { + const val DP_PER_METRE = 900f + const val DENSITY = 2f + const val DPI = 320 + const val BAR_METRES = 52f / DP_PER_METRE + const val BAR_BUTTONS_DP = 150f + const val BAR_BUTTONS_METRES = BAR_BUTTONS_DP / DP_PER_METRE + const val GRIP_METRES = 0.05f + const val MIN_METRES = 0.3f + const val MAX_METRES = 1.6f + const val MIN_DISTANCE = 0.4f + const val MAX_DISTANCE = 3f + fun pixels(metres: Float) = (metres * DP_PER_METRE * DENSITY).toInt().coerceAtLeast(16) +} + +internal sealed class XrPointerEvent(val panel: XrPanelState) { + class Down(panel: XrPanelState, val x: Float, val y: Float, val hand: Int = 0) : XrPointerEvent(panel) + class Move(panel: XrPanelState, val x: Float, val y: Float, val hand: Int = 0) : XrPointerEvent(panel) + class Up(panel: XrPanelState, val x: Float, val y: Float, val hand: Int = 0) : XrPointerEvent(panel) + class Cancel(panel: XrPanelState, val hand: Int = 0) : XrPointerEvent(panel) + class Scroll(panel: XrPanelState, val x: Float, val y: Float, val amount: Float) : XrPointerEvent(panel) + class Back(panel: XrPanelState) : XrPointerEvent(panel) + class Click(panel: XrPanelState) : XrPointerEvent(panel) + class Resized(panel: XrPanelState) : XrPointerEvent(panel) + class Moved(panel: XrPanelState) : XrPointerEvent(panel) +} + +internal class XrInteractionOut { + val events = mutableListOf() + val masks = BooleanArray(2) + val lasers = FloatArray(2) + val ticks = BooleanArray(2) + /** Where each controller points on each panel, in its pixels, left hand first; panels with no entry show none. */ + val cursors = mutableMapOf>>() + + fun point(panel: XrPanelState, x: Float, y: Float) { + cursors.getOrPut(panel) { mutableListOf() } += x to y + } +} + +/** + * What the two controllers do to the panels each frame. A controller acts on a panel only while it + * points at one, or while it holds one it picked up, pressed or is resizing; only then is its input + * taken from the game. + */ +internal class XrInteraction { + private sealed class Hold { + object None : Hold() + class Press(val panel: XrPanelState, var x: Float, var y: Float) : Hold() + class Move(val panel: XrPanelState, var offset: Vec3, val byGrip: Boolean) : Hold() + class Resize(val panel: XrPanelState, val plane: Pose, val width: Float, val height: Float, val startX: Float, val startY: Float) : Hold() + class HeadPress(val panel: XrPanelState, val startX: Float, val startY: Float, val offset: Vec3) : Hold() + } + + private val holds = arrayOf(Hold.None, Hold.None) + private val trigger = BooleanArray(2) + private val grip = BooleanArray(2) + private val secondary = BooleanArray(2) + + fun holding(panel: XrPanelState) = holds.any { held(it) === panel } + + private fun held(hold: Hold): XrPanelState? = when (hold) { + is Hold.Press -> hold.panel + is Hold.Move -> hold.panel + is Hold.Resize -> hold.panel + is Hold.HeadPress -> hold.panel + Hold.None -> null + } + + /** Lets go of everything, as when the immersive view goes. A button still held counts only once let go and pressed again. */ + fun reset() { + holds.fill(Hold.None) + trigger.fill(true) + grip.fill(true) + secondary.fill(true) + } + + /** Cancels a press and ends a move or resize where it is, as when the headset loses focus; then [reset]. */ + fun cancel(out: XrInteractionOut) { + for ((hand, hold) in holds.withIndex()) when (hold) { + is Hold.Press -> out.events += XrPointerEvent.Cancel(hold.panel, hand) + is Hold.Move -> out.events += XrPointerEvent.Moved(hold.panel) + is Hold.Resize -> out.events += XrPointerEvent.Resized(hold.panel) + else -> Unit + } + reset() + } + + /** Lets go of [panel], as when it closes. */ + fun release(panel: XrPanelState, out: XrInteractionOut) { + for (hand in 0..1) if (held(holds[hand]) === panel) { + if (holds[hand] is Hold.Press) out.events += XrPointerEvent.Cancel(panel, hand) + holds[hand] = Hold.None + } + } + + fun update(head: Pose, hands: List, panels: List, dtSeconds: Float): XrInteractionOut { + val out = XrInteractionOut() + for (hand in 0..1) handFrame(hand, head, hands[hand], panels.filter { it.interactive }, dtSeconds, out) + return out + } + + private fun handFrame(index: Int, head: Pose, hand: XrHand, panels: List, dt: Float, out: XrInteractionOut) { + val wasTrigger = trigger[index] + val wasGrip = grip[index] + val wasSecondary = secondary[index] + trigger[index] = if (wasTrigger) hand.trigger > 0.4f else hand.trigger > 0.6f + grip[index] = if (wasGrip) hand.squeeze > 0.5f else hand.squeeze > 0.7f + secondary[index] = hand.secondary + val triggerDown = trigger[index] && !wasTrigger + val triggerUp = !trigger[index] && wasTrigger + val gripDown = grip[index] && !wasGrip + val secondaryDown = secondary[index] && !wasSecondary + val hold = holds[index] + if (!hand.active) { + if (hold is Hold.Press) out.events += XrPointerEvent.Cancel(hold.panel, index) + if (hold is Hold.Move) out.events += XrPointerEvent.Moved(hold.panel) + if (hold is Hold.Resize) out.events += XrPointerEvent.Resized(hold.panel) + holds[index] = Hold.None + return + } + val ray = hand.aim + when (hold) { + is Hold.Move -> { + val panel = hold.panel + if (abs(hand.stickY) > 0.2f) { + val length = hold.offset.length + val wanted = (length * (1f + hand.stickY * 1.2f * dt)).coerceIn(XrUnits.MIN_DISTANCE, XrUnits.MAX_DISTANCE) + hold.offset = hold.offset.normalized() * wanted + } + val position = ray.toWorld(hold.offset) + panel.pose = Pose(panel.kind.orient(position, head.position), position) + out.masks[index] = true + out.lasers[index] = hold.offset.length + val released = if (hold.byGrip) !grip[index] else !trigger[index] + if (released) { + holds[index] = Hold.None + out.events += XrPointerEvent.Moved(panel) + } + return + } + is Hold.Resize -> { + val panel = hold.panel + out.masks[index] = true + hold.panel.hitPlane(ray, bounded = false, plane = hold.plane, w = hold.width, h = hold.height)?.let { hit -> + val left = -hold.width / 2f + val top = hold.height / 2f + val width = (hold.width + hit.x - hold.startX).coerceIn(XrUnits.MIN_METRES, XrUnits.MAX_METRES) + val height = (hold.height + hold.startY - hit.y).coerceIn(XrUnits.MIN_METRES, XrUnits.MAX_METRES) + panel.width = width + panel.height = height + panel.pose = Pose(hold.plane.orientation, hold.plane.toWorld(Vec3(left + width / 2f, top - height / 2f, 0f))) + out.lasers[index] = hit.distance + } + if (!trigger[index]) { + holds[index] = Hold.None + out.events += XrPointerEvent.Resized(panel) + } + return + } + is Hold.Press -> { + val panel = hold.panel + out.masks[index] = true + val hit = panel.hitPlane(ray, bounded = false) + if (hit != null) { + val x = panel.pixelX(hit.x) + val y = panel.pixelY(hit.y) + if (x != hold.x || y != hold.y) out.events += XrPointerEvent.Move(panel, x, y, index) + hold.x = x; hold.y = y + out.lasers[index] = hit.distance + out.point(panel, x, y) + } + if (secondaryDown) out.events += XrPointerEvent.Back(panel) + if (triggerUp || !trigger[index]) { + out.events += if (hit != null) XrPointerEvent.Up(panel, hold.x, hold.y, index) else XrPointerEvent.Cancel(panel, index) + holds[index] = Hold.None + } + return + } + is Hold.HeadPress -> { + val panel = hold.panel + out.masks[index] = true + val hit = panel.hitPlane(ray, bounded = false) + if (hit != null) { + out.lasers[index] = hit.distance + val moved = Vec3(hit.x - hold.startX, hit.y - hold.startY, 0f).length + if (moved > HEAD_DRAG_METRES) { + holds[index] = Hold.Move(panel, hold.offset, byGrip = false) + val position = ray.toWorld(hold.offset) + panel.pose = Pose(panel.kind.orient(position, head.position), position) + return + } + } + if (!trigger[index]) { + holds[index] = Hold.None + if (panel.hit(ray) != null) out.events += XrPointerEvent.Click(panel) + } + return + } + Hold.None -> Unit + } + val hit = panels.mapNotNull { it.hit(ray) }.minByOrNull { it.distance } ?: return + val panel = hit.panel + out.masks[index] = true + out.lasers[index] = hit.distance + val x = panel.pixelX(hit.x) + val y = panel.pixelY(hit.y) + out.point(panel, x, y) + val other = holds[1 - index] + val heldByOther = held(other) === panel && other !is Hold.Press + when { + heldByOther -> Unit + gripDown -> { + holds[index] = Hold.Move(panel, ray.toLocal(panel.pose.position), byGrip = true) + out.ticks[index] = true + } + triggerDown && panel.kind == XrPanelKind.PET_HEAD -> + holds[index] = Hold.HeadPress(panel, hit.x, hit.y, ray.toLocal(panel.pose.position)) + triggerDown && panel.inResizeGrip(hit) -> { + holds[index] = Hold.Resize(panel, panel.pose, panel.width, panel.height, hit.x, hit.y) + out.ticks[index] = true + } + triggerDown && panel.inBar(hit) && !panel.inBarButtons(hit) -> { + holds[index] = Hold.Move(panel, ray.toLocal(panel.pose.position), byGrip = false) + out.ticks[index] = true + } + triggerDown -> { + holds[index] = Hold.Press(panel, x, y) + out.events += XrPointerEvent.Down(panel, x, y, index) + } + } + if (holds[index] === Hold.None) { + if (abs(hand.stickY) > 0.25f) out.events += XrPointerEvent.Scroll(panel, x, y, hand.stickY * SCROLL_PER_SECOND * dt) + if (secondaryDown) out.events += XrPointerEvent.Back(panel) + } + } + + companion object { + const val HEAD_DRAG_METRES = 0.02f + const val SCROLL_PER_SECOND = 12f + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrKeyboard.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrKeyboard.kt new file mode 100644 index 0000000000..275322d745 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrKeyboard.kt @@ -0,0 +1,283 @@ +package com.droiddeck.launcher.session.xr + +import android.view.KeyEvent +import androidx.compose.ui.res.stringResource +import com.droiddeck.launcher.R +import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.Backspace +import androidx.compose.material.icons.automirrored.outlined.KeyboardReturn +import androidx.compose.material.icons.outlined.KeyboardArrowUp +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.text.TextRange +import androidx.compose.ui.text.input.EditCommand +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.ImeOptions +import androidx.compose.ui.text.input.PlatformTextInputService +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.droiddeck.launcher.input.PC_KEY_ROWS +import kotlinx.coroutines.delay +import com.droiddeck.launcher.ui.TypingRequest + +/** Sends text fields in the floating panels to [XrKeyboard], since the system keyboard cannot show in the immersive view. */ +internal class XrTextInput : PlatformTextInputService { + private var request: TypingRequest? = null + + override fun startInput( + value: TextFieldValue, imeOptions: ImeOptions, + onEditCommand: (List) -> Unit, onImeActionPerformed: (ImeAction) -> Unit, + ) { + val next = TypingRequest(value, imeOptions, { onEditCommand(TypingRequest.editsFor(it)) }, onImeActionPerformed) + request = next + XrPanels.startTyping(next) + } + + override fun stopInput() { + request?.let { XrPanels.stopTyping(it) } + request = null + } + + override fun showSoftwareKeyboard() { + request?.let { XrPanels.startTyping(it) } + } + + override fun hideSoftwareKeyboard() { + request?.let { XrPanels.stopTyping(it) } + } + + override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) { + request?.value = newValue + } +} + +internal object XrKeys { + private val letters = listOf("qwertyuiop", "asdfghjkl", "zxcvbnm") + private val symbols = listOf("1234567890", "@#&*-+=()", "!?:;'\"/,") + + fun rows(numbers: Boolean, shift: Boolean): List = + (if (numbers) symbols else letters).map { if (shift && !numbers) it.uppercase() else it } + + fun insert(value: TextFieldValue, text: String): TextFieldValue { + val start = minOf(value.selection.start, value.selection.end) + val end = maxOf(value.selection.start, value.selection.end) + val next = value.text.substring(0, start) + text + value.text.substring(end) + return TextFieldValue(next, TextRange(start + text.length)) + } + + fun backspace(value: TextFieldValue): TextFieldValue { + val start = minOf(value.selection.start, value.selection.end) + val end = maxOf(value.selection.start, value.selection.end) + if (start != end) return TextFieldValue(value.text.substring(0, start) + value.text.substring(end), TextRange(start)) + if (start == 0) return value + val cut = value.text.offsetByCodePoints(start, -1) + return TextFieldValue(value.text.substring(0, cut) + value.text.substring(start), TextRange(cut)) + } + + const val REPEAT_DELAY_MS = 450L + const val REPEAT_MS = 50L + + /** Return sends when the field asks for an action, and starts a new line otherwise. */ + fun returnSends(options: ImeOptions) = options.imeAction != ImeAction.Default && options.imeAction != ImeAction.None && + options.singleLine +} + +/** Where the laser keyboard's keys go: a text field in a panel, or the game. */ +internal interface XrKeyTarget { + fun type(text: String) + fun backspace() + fun enter() +} + +internal class XrFieldTarget(private val request: TypingRequest) : XrKeyTarget { + override fun type(text: String) = request.send(XrKeys.insert(request.value, text)) + override fun backspace() = request.send(XrKeys.backspace(request.value)) + override fun enter() = if (XrKeys.returnSends(request.imeOptions)) request.action() else type("\n") +} + +internal class XrGameTarget(private val host: XrMenuHost) : XrKeyTarget { + override fun type(text: String) = host.xrTypeText(text) + override fun backspace() = host.xrTapKey(KeyEvent.KEYCODE_DEL) + override fun enter() = host.xrTapKey(KeyEvent.KEYCODE_ENTER) +} + +/** + * DroidDeck's PC keyboard typing into a panel's text field: the keys that make a character type it, + * Backspace, Enter and Space edit, and Shift and Caps Lock pick the case. The rest have nothing to do there. + */ +internal class XrPcText(private val target: XrKeyTarget, private val timer: XrTimer = XrTimer.Main) { + private val keys = PC_KEY_ROWS.flatten() + .filter { it.labelRes == 0 && it.label.length == 1 && it.code !in ARROWS } + .associateBy { it.code } + private val shifts = mutableSetOf() + private var caps = false + private var stopRepeat: (() -> Unit)? = null + + fun key(code: Int, down: Boolean) { + if (code == LEFT_SHIFT || code == RIGHT_SHIFT) { + if (down) shifts += code else shifts -= code + return + } + if (!down && code != BACKSPACE) return + stopRepeat?.invoke() + stopRepeat = null + if (!down) return + val shifted = shifts.isNotEmpty() + when (code) { + BACKSPACE -> { + target.backspace() + stopRepeat = timer.after(XrKeys.REPEAT_DELAY_MS, ::repeatBackspace) + } + ENTER -> target.enter() + SPACE -> target.type(" ") + CAPS -> caps = !caps + else -> keys[code]?.let { key -> + target.type(when { + shifted && key.shifted != null -> key.shifted + key.label[0].isLetter() && (shifted xor caps) -> key.label.uppercase() + else -> key.label + }) + } + } + } + + private fun repeatBackspace() { + target.backspace() + stopRepeat = timer.after(XrKeys.REPEAT_MS, ::repeatBackspace) + } + + private companion object { + const val LEFT_SHIFT = 42 + const val RIGHT_SHIFT = 54 + const val BACKSPACE = 14 + const val ENTER = 28 + const val SPACE = 57 + const val CAPS = 58 + val ARROWS = setOf(103, 105, 106, 108) + } +} + +/** Runs an action later on the main thread; the function it returns cancels it. */ +internal fun interface XrTimer { + fun after(ms: Long, action: () -> Unit): () -> Unit + + companion object { + private val handler by lazy { android.os.Handler(android.os.Looper.getMainLooper()) } + val Main = XrTimer { ms, action -> + val runnable = Runnable(action) + handler.postDelayed(runnable, ms) + ({ handler.removeCallbacks(runnable) }) + } + } +} + +/** The Android-style text keyboard. */ +@Composable +internal fun XrKeyboard(target: XrKeyTarget) { + var shift by remember { mutableStateOf(false) } + var numbers by remember { mutableStateOf(false) } + fun type(text: String) { + target.type(text) + if (shift) shift = false + } + Column(Modifier.fillMaxSize().padding(8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { + XrKeys.rows(numbers, shift).forEachIndexed { index, row -> + Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(6.dp)) { + if (index == 2) KeyIcon(Icons.Outlined.KeyboardArrowUp, stringResource(R.string.pckb_key_shift), active = shift, weight = 1.5f) { shift = !shift } + row.forEach { key -> Key(key.toString()) { type(key.toString()) } } + if (index == 2) KeyIcon(Icons.AutoMirrored.Outlined.Backspace, stringResource(R.string.pckb_key_backspace), weight = 1.5f, repeats = true) { target.backspace() } + } + } + Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(6.dp)) { + Key(if (numbers) "abc" else "?123", weight = 1.5f) { numbers = !numbers } + Key(",") { type(",") } + Key(" ", weight = 5f) { type(" ") } + Key(".") { type(".") } + KeyIcon(Icons.AutoMirrored.Outlined.KeyboardReturn, stringResource(R.string.pckb_key_enter), weight = 1.5f) { target.enter() } + } + } +} + +/** A key that lights while the laser is over it and dips while it is pressed; [repeats] keeps acting while held. */ +@Composable +private fun RowScope.KeyBox( + weight: Float, active: Boolean, onClick: () -> Unit, repeats: Boolean = false, content: @Composable (Color) -> Unit, +) { + val colors = MaterialTheme.colorScheme + val source = remember { MutableInteractionSource() } + val (pointedAt, pointed) = rememberXrPointed() + val hovered = pointed.value + val pressed by source.collectIsPressedAsState() + val action by rememberUpdatedState(onClick) + var repeated by remember { mutableStateOf(false) } + if (repeats) LaunchedEffect(pressed) { + if (!pressed) return@LaunchedEffect + repeated = false + delay(XrKeys.REPEAT_DELAY_MS) + repeated = true + while (true) { + action() + delay(XrKeys.REPEAT_MS) + } + } + val fill by animateColorAsState( + when { + pressed -> colors.primary + active -> colors.primary.copy(alpha = 0.8f) + hovered -> colors.onSurface.copy(alpha = 0.22f).compositeOver(colors.surfaceVariant) + else -> colors.surfaceVariant + }, tween(if (pressed) 40 else 140), label = "keyFill", + ) + val scale by animateFloatAsState(if (pressed) 0.9f else if (hovered) 1.05f else 1f, tween(if (pressed) 40 else 140), label = "keyScale") + Box( + Modifier.weight(weight).fillMaxHeight() + .then(pointedAt) + .graphicsLayer { scaleX = 1f + (scale - 1f) * size.height / size.width; scaleY = scale } + .clip(RoundedCornerShape(8.dp)).background(fill) + .border(if (hovered) 2.dp else 0.dp, if (hovered) colors.primary else Color.Transparent, RoundedCornerShape(8.dp)) + .clickable(interactionSource = source, indication = null) { if (repeated) repeated = false else onClick() }, + contentAlignment = Alignment.Center, + ) { content(if (pressed || active) colors.onPrimary else colors.onSurface) } +} + +@Composable +private fun RowScope.Key(label: String, weight: Float = 1f, onClick: () -> Unit) = + KeyBox(weight, active = false, onClick) { tint -> Text(label, color = tint, fontSize = 22.sp, maxLines = 1) } + +@Composable +private fun RowScope.KeyIcon(icon: ImageVector, label: String, active: Boolean = false, weight: Float = 1f, repeats: Boolean = false, onClick: () -> Unit) = + KeyBox(weight, active, onClick, repeats) { tint -> Icon(icon, label, tint = tint) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrMath.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrMath.kt new file mode 100644 index 0000000000..4f5072f142 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrMath.kt @@ -0,0 +1,61 @@ +package com.droiddeck.launcher.session.xr + +import kotlin.math.atan2 +import kotlin.math.cos +import kotlin.math.sin +import kotlin.math.sqrt + +internal data class Vec3(val x: Float, val y: Float, val z: Float) { + operator fun plus(o: Vec3) = Vec3(x + o.x, y + o.y, z + o.z) + operator fun minus(o: Vec3) = Vec3(x - o.x, y - o.y, z - o.z) + operator fun times(s: Float) = Vec3(x * s, y * s, z * s) + infix fun dot(o: Vec3) = x * o.x + y * o.y + z * o.z + infix fun cross(o: Vec3) = Vec3(y * o.z - z * o.y, z * o.x - x * o.z, x * o.y - y * o.x) + val length: Float get() = sqrt(this dot this) + fun normalized(): Vec3 = length.let { if (it > 1e-6f) this * (1f / it) else ZERO } + + companion object { + val ZERO = Vec3(0f, 0f, 0f) + val FORWARD = Vec3(0f, 0f, -1f) + val UP = Vec3(0f, 1f, 0f) + fun lerp(a: Vec3, b: Vec3, t: Float) = a + (b - a) * t + } +} + +internal data class Quat(val x: Float, val y: Float, val z: Float, val w: Float) { + fun rotate(v: Vec3): Vec3 { + val u = Vec3(x, y, z) + return u * (2f * (u dot v)) + v * (w * w - (u dot u)) + (u cross v) * (2f * w) + } + + fun conjugate() = Quat(-x, -y, -z, w) + + operator fun times(o: Quat) = Quat( + w * o.x + x * o.w + y * o.z - z * o.y, + w * o.y - x * o.z + y * o.w + z * o.x, + w * o.z + x * o.y - y * o.x + z * o.w, + w * o.w - x * o.x - y * o.y - z * o.z, + ) + + companion object { + val IDENTITY = Quat(0f, 0f, 0f, 1f) + fun yaw(radians: Float) = Quat(0f, sin(radians / 2f), 0f, cos(radians / 2f)) + fun pitch(radians: Float) = Quat(sin(radians / 2f), 0f, 0f, cos(radians / 2f)) + } +} + +internal data class Pose(val orientation: Quat = Quat.IDENTITY, val position: Vec3 = Vec3.ZERO) { + val forward: Vec3 get() = orientation.rotate(Vec3.FORWARD) + fun toLocal(world: Vec3): Vec3 = orientation.conjugate().rotate(world - position) + fun toWorld(local: Vec3): Vec3 = position + orientation.rotate(local) +} + +/** Yaw of a direction in the horizontal plane, 0 along -Z, matching [Quat.yaw] applied to -Z. */ +internal fun yawOf(direction: Vec3): Float = atan2(-direction.x, -direction.z) + +/** An orientation that turns +Z, the side of a quad that shows, from [position] towards [target] about the vertical axis only. */ +internal fun facing(position: Vec3, target: Vec3): Quat { + val d = target - position + if (d.x * d.x + d.z * d.z < 1e-8f) return Quat.IDENTITY + return Quat.yaw(atan2(d.x, d.z)) +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelChrome.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelChrome.kt new file mode 100644 index 0000000000..00540563a1 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelChrome.kt @@ -0,0 +1,126 @@ +package com.droiddeck.launcher.session.xr + +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Remove +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.State +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.layout.boundsInWindow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +/** + * The frame of a floating panel: the content, a bar under it to grab it by with up to two buttons at + * its left end, a corner grip to resize it, and the dot where a controller points. Its sizes match [XrUnits]. + */ +@Composable +internal fun XrPanelChrome( + cursor: State>>, + buttons: List, + resizable: Boolean, + content: @Composable () -> Unit, +) { + val colors = MaterialTheme.colorScheme + val shape = RoundedCornerShape(18.dp) + Box(Modifier.fillMaxSize().clip(shape).background(colors.background).border(1.dp, Color(0x33FFFFFF), shape)) { + Column(Modifier.fillMaxSize()) { + Box(Modifier.weight(1f).fillMaxWidth().padding(start = 10.dp, top = 10.dp, end = 10.dp)) { + CompositionLocalProvider(LocalXrPointers provides cursor) { content() } + } + Box( + Modifier.fillMaxWidth().height(52.dp).background(colors.surfaceVariant.copy(alpha = 0.6f)), + contentAlignment = Alignment.Center, + ) { + Box(Modifier.width(72.dp).height(6.dp).clip(CircleShape).background(colors.onSurface.copy(alpha = 0.35f))) + if (buttons.isNotEmpty()) Row( + Modifier.align(Alignment.CenterStart).width(XrUnits.BAR_BUTTONS_DP.dp).padding(start = 8.dp), + horizontalArrangement = Arrangement.spacedBy(4.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + buttons.take(2).forEach { button -> + if (button.icon != null) IconButton(onClick = button.onClick, modifier = Modifier.size(44.dp)) { + Icon(button.icon, button.label, tint = colors.onSurface) + } else TextButton(onClick = button.onClick, modifier = Modifier.height(40.dp), contentPadding = PaddingValues(horizontal = 10.dp)) { + Text(button.label, color = colors.onSurface, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, maxLines = 1) + } + } + } + } + } + if (resizable) Canvas(Modifier.align(Alignment.BottomEnd).padding(6.dp).size(28.dp)) { + val stroke = Stroke(width = 3.dp.toPx()) + for (step in 1..3) { + val inset = size.width * step / 4f + drawLine(Color(0x99FFFFFF), Offset(size.width, inset), Offset(inset, size.height), stroke.width) + } + } + val density = LocalDensity.current + Canvas(Modifier.fillMaxSize()) { + val radius = with(density) { 7.dp.toPx() } + for ((x, y) in cursor.value) { + drawCircle(Color(0xCC1E9EFF), radius, Offset(x, y)) + drawCircle(Color.White, radius, Offset(x, y), style = Stroke(with(density) { 2.dp.toPx() })) + } + } + } +} + +/** Where each laser meets the panel, in the panel's pixels; null off a floating panel. */ +internal val LocalXrPointers = staticCompositionLocalOf>>?> { null } + +/** + * Whether a laser rests on the element the returned [Modifier] is put on, for both controllers at + * once, where a mouse hover has room for one. False off a floating panel. + */ +@Composable +internal fun rememberXrPointed(): Pair> { + val pointers = LocalXrPointers.current + var bounds by remember { mutableStateOf(Rect.Zero) } + val pointed = remember(pointers) { + derivedStateOf { pointers != null && pointers.value.any { (x, y) -> bounds.contains(Offset(x, y)) } } + } + return Modifier.onGloballyPositioned { bounds = it.boundsInWindow() } to pointed +} + +/** With no [icon] the button shows [label] itself, for a short word such as a keyboard mode. */ +internal class XrPanelButton(val icon: ImageVector?, val label: String, val onClick: () -> Unit) + +internal val XrCollapseIcon get() = Icons.Outlined.Remove diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelWindow.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelWindow.kt new file mode 100644 index 0000000000..0d54d8cafe --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanelWindow.kt @@ -0,0 +1,271 @@ +package com.droiddeck.launcher.session.xr + +import android.app.Presentation +import android.content.Context +import android.hardware.display.DisplayManager +import android.hardware.display.VirtualDisplay +import android.os.Bundle +import android.os.SystemClock +import android.view.InputDevice +import android.view.MotionEvent +import android.view.Surface +import android.view.View +import android.view.ViewGroup +import android.view.WindowManager +import android.view.inspector.WindowInspector +import android.widget.FrameLayout +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.LocalTextInputService +import androidx.compose.ui.text.input.TextInputService +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LifecycleRegistry +import androidx.activity.OnBackPressedDispatcher +import androidx.activity.OnBackPressedDispatcherOwner +import androidx.activity.setViewTreeOnBackPressedDispatcherOwner +import androidx.lifecycle.ViewModelStore +import androidx.lifecycle.ViewModelStoreOwner +import androidx.lifecycle.setViewTreeLifecycleOwner +import androidx.lifecycle.setViewTreeViewModelStoreOwner +import androidx.savedstate.SavedStateRegistry +import androidx.savedstate.SavedStateRegistryController +import androidx.savedstate.SavedStateRegistryOwner +import androidx.savedstate.setViewTreeSavedStateRegistryOwner +import com.droiddeck.launcher.ui.LocalPresentationWindow + +/** Keeps a panel's Compose content running while the activity that made it is stopped behind the XR view. */ +private class PanelOwner : LifecycleOwner, SavedStateRegistryOwner, ViewModelStoreOwner, OnBackPressedDispatcherOwner { + private val registry = LifecycleRegistry(this) + private val saved = SavedStateRegistryController.create(this) + override val lifecycle: Lifecycle get() = registry + override val savedStateRegistry: SavedStateRegistry get() = saved.savedStateRegistry + override val viewModelStore = ViewModelStore() + override val onBackPressedDispatcher = OnBackPressedDispatcher() + + fun own(view: View) { + view.setViewTreeLifecycleOwner(this) + view.setViewTreeSavedStateRegistryOwner(this) + view.setViewTreeViewModelStoreOwner(this) + view.setViewTreeOnBackPressedDispatcherOwner(this) + } + + init { + saved.performRestore(null) + registry.currentState = Lifecycle.State.RESUMED + } + + fun destroy() { + registry.currentState = Lifecycle.State.DESTROYED + viewModelStore.clear() + } +} + +/** + * One floating panel's Android side: a private virtual display drawing into the panel's OpenXR + * surface, and a presentation on it holding the Compose content. Main thread only. + */ +internal class XrPanelWindow( + private val context: Context, + private var surface: Surface, + width: Int, + height: Int, + startPaused: Boolean, + private val content: @Composable () -> Unit, +) { + private var paused = startPaused + private val owner = PanelOwner() + private val textInput = TextInputService(XrTextInput()) + private val display: VirtualDisplay = context.getSystemService(DisplayManager::class.java).createVirtualDisplay( + "DroidDeck XR panel", width, height, XrUnits.DPI, surface.takeUnless { paused }, DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY, + ) + private val presentation = PanelPresentation(context, display.display) + private var downTime = 0L + private var target: View? = null + /** The controllers pressing the panel, by hand, as fingers of one touch. */ + private val touches = linkedMapOf>() + private var hovering: View? = null + private var hoverAt = 0f to 0f + private var cursor: Pair? = null + + init { + try { + presentation.show() + } catch (failure: RuntimeException) { + release() + throw failure + } + } + + val displayId: Int get() = display.display.displayId + + fun resize(surface: Surface, width: Int, height: Int) { + this.surface = surface + if (!paused) display.surface = surface + display.resize(width, height, XrUnits.DPI) + } + + /** Stops drawing into the panel's layer, or starts again. */ + fun pause(pause: Boolean) { + if (pause == paused) return + paused = pause + display.surface = if (pause) null else surface + } + + fun release() { + runCatching { presentation.dismiss() } + owner.destroy() + display.release() + } + + private inner class PanelPresentation(outer: Context, display: android.view.Display) : Presentation(outer, display) { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + window?.setBackgroundDrawableResource(android.R.color.transparent) + window?.addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) + val compose = ComposeView(context).apply { + owner.own(this) + setContent { + CompositionLocalProvider( + LocalPresentationWindow provides true, + LocalTextInputService provides textInput, + ) { content() } + } + } + val frame = FrameLayout(context).apply { + addView(compose, FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) + } + setContentView(frame) + window?.decorView?.let(owner::own) + } + } + + /** + * The topmost window on this panel's display under the point, so popups and dialogs get the input. + * A focusable popup or dialog on top takes a press outside it too, as on a touchscreen, where it + * dismisses itself rather than letting the press act on what is behind it. + */ + private fun rootAt(x: Float, y: Float): View? { + val roots = WindowInspector.getGlobalWindowViews().filter { it.isAttachedToWindow && it.display?.displayId == displayId && it.isShown } + val location = IntArray(2) + fun contains(root: View): Boolean { + root.getLocationOnScreen(location) + return x >= location[0] && y >= location[1] && x < location[0] + root.width && y < location[1] + root.height + } + val top = roots.lastOrNull() ?: return null + val focusable = (top.layoutParams as? WindowManager.LayoutParams) + ?.let { it.flags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE == 0 } ?: false + if (roots.size > 1 && focusable && !contains(top)) return top + return roots.lastOrNull(::contains) ?: top + } + + /** Sends every finger in [touches] to [target]; [action] is already shifted by its pointer index where it needs one. */ + private fun sendTouches(action: Int, time: Long) { + val view = target ?: return + val location = IntArray(2) + view.getLocationOnScreen(location) + val properties = touches.keys.map { hand -> + MotionEvent.PointerProperties().apply { id = hand; toolType = MotionEvent.TOOL_TYPE_FINGER } + }.toTypedArray() + val coords = touches.values.map { (x, y) -> + MotionEvent.PointerCoords().apply { this.x = x - location[0]; this.y = y - location[1]; pressure = 1f; size = 1f } + }.toTypedArray() + val event = MotionEvent.obtain(downTime, time, action, touches.size, properties, coords, 0, 0, 1f, 1f, 0, 0, + InputDevice.SOURCE_TOUCHSCREEN, 0) + try { + view.dispatchTouchEvent(event) + } finally { + event.recycle() + } + } + + private fun indexed(action: Int, hand: Int) = + action or (touches.keys.indexOf(hand) shl MotionEvent.ACTION_POINTER_INDEX_SHIFT) + + private fun send(view: View, action: Int, x: Float, y: Float, time: Long, generic: Boolean, scroll: Float = 0f): Boolean { + val location = IntArray(2) + view.getLocationOnScreen(location) + val properties = arrayOf(MotionEvent.PointerProperties().apply { + id = 0 + toolType = if (generic) MotionEvent.TOOL_TYPE_MOUSE else MotionEvent.TOOL_TYPE_FINGER + }) + val coords = arrayOf(MotionEvent.PointerCoords().apply { + this.x = x - location[0] + this.y = y - location[1] + pressure = 1f + size = 1f + if (scroll != 0f) setAxisValue(MotionEvent.AXIS_VSCROLL, scroll) + }) + val source = if (generic) InputDevice.SOURCE_MOUSE else InputDevice.SOURCE_TOUCHSCREEN + val event = MotionEvent.obtain(if (generic) time else downTime, time, action, 1, properties, coords, 0, 0, 1f, 1f, 0, 0, source, 0) + return try { + if (generic) view.dispatchGenericMotionEvent(event) else view.dispatchTouchEvent(event) + } finally { + event.recycle() + } + } + + /** The laser resting on the panel, as a mouse hovering, so keys and buttons light under it. Null: it left. */ + fun hover(at: Pair?) { + cursor = at + if (target != null) return + val now = SystemClock.uptimeMillis() + val root = at?.let { (x, y) -> rootAt(x, y) } + if (root !== hovering) endHover(now) + if (root == null || at == null) return + if (hovering == null) send(root, MotionEvent.ACTION_HOVER_ENTER, at.first, at.second, now, generic = true) + send(root, MotionEvent.ACTION_HOVER_MOVE, at.first, at.second, now, generic = true) + hovering = root + hoverAt = at + } + + private fun endHover(now: Long) { + hovering?.let { send(it, MotionEvent.ACTION_HOVER_EXIT, hoverAt.first, hoverAt.second, now, generic = true) } + hovering = null + } + + fun pointer(event: XrPointerEvent) { + val now = SystemClock.uptimeMillis() + when (event) { + is XrPointerEvent.Down -> { + if (event.hand in touches) return + touches[event.hand] = event.x to event.y + if (touches.size == 1) { + endHover(now) + downTime = now + target = rootAt(event.x, event.y) + sendTouches(MotionEvent.ACTION_DOWN, now) + } else sendTouches(indexed(MotionEvent.ACTION_POINTER_DOWN, event.hand), now) + } + is XrPointerEvent.Move -> { + if (event.hand !in touches) return + touches[event.hand] = event.x to event.y + sendTouches(MotionEvent.ACTION_MOVE, now) + } + is XrPointerEvent.Up -> { + if (event.hand !in touches) return + touches[event.hand] = event.x to event.y + if (touches.size > 1) { + sendTouches(indexed(MotionEvent.ACTION_POINTER_UP, event.hand), now) + touches -= event.hand + } else { + sendTouches(MotionEvent.ACTION_UP, now) + touches.clear() + target = null + hover(cursor) + } + } + is XrPointerEvent.Cancel -> { + if (event.hand !in touches) return + sendTouches(MotionEvent.ACTION_CANCEL, now) + touches.clear() + target = null + } + is XrPointerEvent.Scroll -> rootAt(event.x, event.y)?.let { + send(it, MotionEvent.ACTION_SCROLL, event.x, event.y, now, generic = true, scroll = event.amount) + } + else -> Unit + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanels.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanels.kt new file mode 100644 index 0000000000..17431f1458 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrPanels.kt @@ -0,0 +1,611 @@ +package com.droiddeck.launcher.session.xr + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log +import android.view.Surface +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.KeyboardHide +import androidx.compose.runtime.Composable +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.R +import com.droiddeck.launcher.agent.AgentHost +import com.droiddeck.launcher.session.QuestExperimental +import com.droiddeck.launcher.ui.AgentPage +import com.droiddeck.launcher.ui.AgentPet +import com.droiddeck.launcher.ui.DroidDeckTheme +import com.droiddeck.launcher.ui.PcKeyboard +import com.droiddeck.launcher.ui.PetFigure +import com.droiddeck.launcher.ui.TypingRequest +import com.droiddeck.launcher.ui.petStateNow +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.cancel +import kotlinx.coroutines.launch +import java.lang.ref.WeakReference +import java.nio.ByteBuffer +import java.util.concurrent.ConcurrentLinkedQueue +import kotlin.math.PI + +/** The 2D session window, which hands its menu to the immersive view while that is open. */ +internal interface XrMenuHost { + @Composable + fun XrMenuContent() + fun xrSetMenuOpen(open: Boolean) + fun xrMenuBack() + /** A key of DroidDeck's PC keyboard, by Linux key code, to the game. */ + fun xrSendKey(code: Int, down: Boolean) + /** Text from the laser keyboard to the game, as the Android keyboard sends it. */ + fun xrTypeText(text: String) + fun xrTapKey(keyCode: Int) + /** The immersive view opened or closed; Steam's screen, which SteamVR mirrors as its Steam window, sizes for it. */ + fun xrImmersiveChanged(active: Boolean) +} + +/** What the immersive view's native loop offers: surface-backed layers it composites in front of the game. */ +internal interface XrLayerSource { + val context: Context + fun createLayer(width: Int, height: Int): Int + fun layerSurface(id: Int): Surface? + fun destroyLayer(id: Int) + fun setOrbImage(image: android.graphics.Bitmap) + fun leave() +} + +/** + * DroidDeck's own windows inside the immersive Quest view: the session menu, opened by holding the + * controllers together, and the agent pet with its chat. Quest only. [frame] runs on the XR thread + * each frame; the rest runs on the main thread. + */ +internal object XrPanels { + private const val TAG = "XrPanels" + private const val OPEN_MS = 350f + private const val CLOSE_MS = 250f + private const val BURST_MS = 400f + + /** The immersive view is up, so the menu and pet belong in it. Always false off Quest. */ + @Volatile + var immersiveActive = false + + /** Counts attachments, so work posted from one immersive view is dropped once a later one, or none, is up. */ + @Volatile + private var attachment = 0 + private set + + private val main = Handler(Looper.getMainLooper()) + + /** Whether the headset shows the session; panels draw into their layers only then. */ + @Volatile + private var drawing = false + private val lock = Any() + private val ops = ConcurrentLinkedQueue<() -> Unit>() + private var source: XrLayerSource? = null + private var host: XrHost? = null + private var menuHost: WeakReference? = null + private var scope: CoroutineScope? = null + + private class Panel(val state: XrPanelState, val content: @Composable (State>>) -> Unit) { + val cursorState = mutableStateOf>>(emptyList()) + var layerId = -1 + var window: XrPanelWindow? = null + var openedMs = 0L + var closingMs = 0L + var resizing = false + var cursor: List> = emptyList() + } + + private val panels = mutableListOf() + private val gesture = XrGesture() + private val interaction = XrInteraction() + private var lastFrameMs = 0L + private var orbImageSent = false + private var lastHead = Pose() + private var burstMs = 0L + private var burstAt = Vec3.ZERO + private var lastTick = 0 + private var menuFrom: Vec3? = null + private val typing = mutableStateOf(null) + /** The keyboard was opened for the game, from the session menu; a panel's text field takes it over while it types. */ + private val gameKeyboard = mutableStateOf(false) + private val pcKeyboard = mutableStateOf(false) + + fun gateOpen(model: String, device: String, manufacturer: String, immersive: Boolean) = + immersive && QuestExperimental.supported(model, device, manufacturer) + + fun setMenuHost(menu: XrMenuHost?) { + menuHost = menu?.let { WeakReference(it) } + if (immersiveActive) menu?.xrImmersiveChanged(true) + } + + fun clearMenuHost(menu: XrMenuHost) { + if (menuHost?.get() === menu) menuHost = null + } + + /** Main thread: the immersive view handed over its buffers. */ + fun attach(layers: XrLayerSource, state: ByteBuffer, control: ByteBuffer) { + if (!QuestExperimental.isSupported()) return + synchronized(lock) { + source = layers + host = XrHost(state, control) + orbImageSent = false + } + attachment++ + immersiveActive = true + menuHost?.get()?.xrImmersiveChanged(true) + scope?.cancel() + scope = MainScope().also { scope -> + scope.launch { + snapshotFlow { com.droiddeck.launcher.agent.AgentGuest.focusRevision }.collect { + menuHost?.get()?.xrImmersiveChanged(true) + } + } + scope.launch { + snapshotFlow { AgentPet.enabled && AgentHost.installed }.collect { on -> + if (on) { if (!shown(XrPanelKind.PET_CHAT)) open(XrPanelKind.PET_HEAD) } + else { close(XrPanelKind.PET_HEAD); close(XrPanelKind.PET_CHAT) } + } + } + } + } + + /** + * XR thread, as the session becomes visible or stops being so. OpenXR allows writing into a surface + * swapchain only while the session is visible or focused, and requires the writes to have stopped + * before xrEndSession, so this returns once the panels have stopped or started drawing. + */ + fun setDrawing(visible: Boolean) { + val done = java.util.concurrent.CountDownLatch(1) + val apply = Runnable { + try { + drawing = visible + synchronized(lock) { panels.mapNotNull { it.window } }.forEach { it.pause(!visible) } + } finally { + done.countDown() + } + } + if (Looper.myLooper() == Looper.getMainLooper()) apply.run() + else if (main.post(apply) && !done.await(1, java.util.concurrent.TimeUnit.SECONDS)) + Log.w(TAG, "panels did not ${if (visible) "start" else "stop"} drawing within a second") + } + + /** Main thread: the immersive view is going; every panel goes with it. */ + fun detach() { + if (!immersiveActive) return + immersiveActive = false + scope?.cancel() + scope = null + val windows = synchronized(lock) { + source = null + host = null + ops.clear() + interaction.reset() + panels.mapNotNull { it.window }.also { panels.clear() } + } + windows.forEach { it.release() } + typing.value = null + gameKeyboard.value = false + gesture.reset(release = false) + menuHost?.get()?.xrSetMenuOpen(false) + menuHost?.get()?.xrImmersiveChanged(false) + } + + /** Main thread, from the session window's menu state. */ + fun showMenu(): Boolean { + if (!immersiveActive) return false + open(XrPanelKind.MENU, menuFrom) + menuFrom = null + return true + } + + fun hideMenu() = close(XrPanelKind.MENU) + + /** Main thread: closes the immersive view, as a stop chosen in its menu asks. */ + fun leaveImmersive() { + synchronized(lock) { source }?.leave() + } + + /** Main thread: a text field in a panel wants typing, so the laser keyboard opens. */ + fun startTyping(request: TypingRequest) { + if (!immersiveActive) return + typing.value = request + open(XrPanelKind.KEYBOARD) + } + + fun stopTyping(request: TypingRequest) { + if (typing.value !== request) return + typing.value = null + if (!gameKeyboard.value) close(XrPanelKind.KEYBOARD) + } + + /** + * Main thread: the session menu's keyboards. [pc] picks DroidDeck's PC keyboard over the Android-style one; + * asking again for the one already open closes it. False off the immersive view, where the 2D keyboards stay. + */ + fun toggleGameKeyboard(pc: Boolean): Boolean { + if (!immersiveActive) return false + if (gameKeyboard.value && pcKeyboard.value == pc && shown(XrPanelKind.KEYBOARD)) hideKeyboard() + else showGameKeyboard(pc) + return true + } + + fun showGameKeyboard(pc: Boolean): Boolean { + if (!immersiveActive) return false + gameKeyboard.value = true + pcKeyboard.value = pc + open(XrPanelKind.KEYBOARD) + return true + } + + private fun hideKeyboard() { + typing.value = null + gameKeyboard.value = false + close(XrPanelKind.KEYBOARD) + } + + private fun shown(kind: XrPanelKind) = synchronized(lock) { panels.any { it.state.kind == kind && it.closingMs == 0L } } + + private fun open(kind: XrPanelKind, from: Vec3? = null) { + ops += { create(kind, from) } + } + + private fun close(kind: XrPanelKind) { + ops += { + panels.filter { it.state.kind == kind && it.closingMs == 0L }.forEach { panel -> + panel.closingMs = SystemClock.uptimeMillis() + val out = XrInteractionOut() + interaction.release(panel.state, out) + dispatch(out) + } + } + } + + /** XR thread. */ + private fun create(kind: XrPanelKind, from: Vec3?) { + val layers = source ?: return + panels.firstOrNull { it.state.kind == kind }?.let { existing -> + if (existing.closingMs != 0L) { + existing.closingMs = 0L + val elapsed = 1f - Math.cbrt((1.0 - existing.state.scale).coerceIn(0.0, 1.0)).toFloat() + existing.openedMs = SystemClock.uptimeMillis() - (elapsed * OPEN_MS).toLong() + } + return + } + val placed = XrPlacement.load(layers.context, kind, lastHead) + val state = XrPanelState(kind, placed.pose, placed.width, placed.height) + state.scale = 0f + state.animationFrom = from ?: placed.pose.position + val id = layers.createLayer(state.pixelWidth, state.pixelHeight) + val surface = if (id >= 0) layers.layerSurface(id) else null + if (surface == null) { + Log.w(TAG, "no layer for the ${kind.key} panel") + if (id >= 0) layers.destroyLayer(id) + if (kind == XrPanelKind.MENU) main.post { menuHost?.get()?.xrSetMenuOpen(false) } + return + } + val panel = Panel(state, contentFor(kind)) + panel.layerId = id + panel.openedMs = SystemClock.uptimeMillis() + panels += panel + val context = layers.context + main.post { + synchronized(lock) { + if (panel !in panels) return@post + panel.window = runCatching { + XrPanelWindow(context, surface, state.pixelWidth, state.pixelHeight, startPaused = !drawing) { + panel.content(panel.cursorState) + } + }.onFailure { + Log.w(TAG, "could not show the ${kind.key} panel", it) + panels -= panel + ops += { if (source === layers) layers.destroyLayer(id) } + if (kind == XrPanelKind.MENU) menuHost?.get()?.xrSetMenuOpen(false) + }.getOrNull() + } + } + } + + private fun contentFor(kind: XrPanelKind): @Composable (State>>) -> Unit = when (kind) { + XrPanelKind.MENU -> { cursor -> + DroidDeckTheme { + XrPanelChrome(cursor, buttons = emptyList(), resizable = true) { + menuHost?.get()?.XrMenuContent() + } + } + } + XrPanelKind.PET_HEAD -> { _ -> + DroidDeckTheme { Box(Modifier.fillMaxSize()) { PetFigure(petStateNow(), Modifier.fillMaxSize()) } } + } + XrPanelKind.KEYBOARD -> { cursor -> + DroidDeckTheme { + val buttons = listOf( + XrPanelButton(Icons.Outlined.KeyboardHide, stringResource(R.string.pckb_hide), ::hideKeyboard), + XrPanelButton(null, if (pcKeyboard.value) "Android" else "PC") { pcKeyboard.value = !pcKeyboard.value }, + ) + XrPanelChrome(cursor, buttons, resizable = true) { KeyboardContent() } + } + } + XrPanelKind.PET_CHAT -> { cursor -> + DroidDeckTheme { + XrPanelChrome(cursor, listOf(XrPanelButton(XrCollapseIcon, stringResource(R.string.bottom_chat_close), ::collapseChat)), resizable = true) { + AgentPage(Modifier.fillMaxSize().padding(horizontal = 12.dp), visible = true, startTyping = false, hidesPet = false) + } + } + } + } + + /** A panel's text field takes the keyboard while it types; otherwise its keys go to the game. */ + @Composable + private fun KeyboardContent() { + val request = typing.value + val host = menuHost?.get()?.takeIf { gameKeyboard.value } + val target = request?.let(::XrFieldTarget) ?: host?.let(::XrGameTarget) ?: return + if (pcKeyboard.value) { + val pcText = remember(request) { request?.let { XrPcText(XrFieldTarget(it)) } } + PcKeyboard( + sendKey = { code, down -> pcText?.key(code, down) ?: host?.xrSendKey(code, down) }, + onAndroidKeyboard = { pcKeyboard.value = false }, + onClose = ::hideKeyboard, + heightFraction = 1f, + showButtons = false, + hoverFeedback = true, + ) + } else XrKeyboard(target) + } + + private fun collapseChat() { + close(XrPanelKind.PET_CHAT) + open(XrPanelKind.PET_HEAD) + } + + private fun expandChat(from: Vec3) { + close(XrPanelKind.PET_HEAD) + open(XrPanelKind.PET_CHAT, from) + } + + /** XR thread, once per frame, from QuestXrActivity.onXrHostFrame. */ + fun frame() = synchronized(lock) { + val host = host ?: return + val layers = source ?: return + val frame = host.read() + lastHead = frame.head + while (true) (ops.poll() ?: break).invoke() + if (!orbImageSent) { + orbImageSent = true + runCatching { + android.graphics.BitmapFactory.decodeResource(layers.context.resources, R.drawable.logo) + }.getOrNull()?.let { layers.setOrbImage(it); it.recycle() } + } + val now = SystemClock.uptimeMillis() + val dt = if (lastFrameMs == 0L) 0f else ((now - lastFrameMs) / 1000f).coerceIn(0f, 0.1f) + lastFrameMs = now + val control = XrControlOut() + animate(now, layers) + val active = panels.filter { it.closingMs == 0L && it.window != null } + if (frame.focused) { + if (gesture.update(frame.hands[0], frame.hands[1], now)) { + burstMs = now + burstAt = gesture.midpoint + lastTick = 0 + for (hand in 0..1) control.haptics[hand] = XrHaptic(60, 0.9f) + val from = gesture.midpoint + val posted = attachment + main.post { if (immersiveActive && posted == attachment) toggleMenu(from) } + } else if (gesture.phase == XrGesture.Phase.ARMING) { + val step = (gesture.progress * 4).toInt() + if (step > lastTick) for (hand in 0..1) control.haptics[hand] = XrHaptic(18, 0.2f + 0.15f * step) + lastTick = step + } else lastTick = 0 + val out = interaction.update(frame.head, frame.hands, active.map { it.state }, dt) + for (hand in 0..1) { + control.masks[hand] = out.masks[hand] + control.lasers[hand] = out.lasers[hand] + if (out.ticks[hand] && control.haptics[hand] == null) control.haptics[hand] = XrHaptic(12, 0.35f) + } + dispatch(out) + } else { + gesture.reset(release = false) + val out = XrInteractionOut() + interaction.cancel(out) + dispatch(out) + } + control.orb = orb(now) + panels.forEachIndexed { index, panel -> + if (panel.layerId < 0 || panel.window == null) return@forEachIndexed + val state = panel.state + control.layers += XrLayerOut(panel.layerId, state.shownPose, state.width * state.scale, state.height * state.scale, + order = if (state.kind == XrPanelKind.PET_HEAD) 100 else index) + } + host.write(control) + } + + private fun orb(now: Long): XrControlOut.Orb? { + if (gesture.phase == XrGesture.Phase.ARMING) + return XrControlOut.Orb(gesture.midpoint, 0.02f + 0.01f * gesture.progress, gesture.progress, 0f) + val burst = (now - burstMs) / BURST_MS + if (burstMs != 0L && burst < 1f) return XrControlOut.Orb(burstAt, 0.03f, 1f, burst.coerceAtLeast(0.01f)) + return null + } + + private fun animate(now: Long, layers: XrLayerSource) { + val gone = mutableListOf() + for (panel in panels) { + val state = panel.state + if (panel.closingMs != 0L) { + val t = ((now - panel.closingMs) / CLOSE_MS).coerceIn(0f, 1f) + state.scale = minOf(state.scale, 1f - easeOut(t)) + if (state.animationFrom == null) state.animationFrom = state.pose.position + if (t >= 1f) gone += panel + } else if (state.scale < 1f) { + state.scale = easeOut(((now - panel.openedMs) / OPEN_MS).coerceIn(0f, 1f)) + if (state.scale >= 1f) state.animationFrom = null + } + } + for (panel in gone) { + panels -= panel + if (panel.layerId >= 0) layers.destroyLayer(panel.layerId) + val window = panel.window + val context = layers.context + val state = panel.state + val head = lastHead + main.post { + window?.release() + XrPlacement.save(context, state.kind, head, state.pose, state.width, state.height) + } + } + } + + private fun easeOut(t: Float) = 1f - (1f - t) * (1f - t) * (1f - t) + + /** XR thread: hands each panel its input on the main thread and follows up on moves and resizes. */ + private fun dispatch(out: XrInteractionOut) { + val layers = source ?: return + for (panel in panels) { + val cursor = out.cursors[panel.state]?.toList().orEmpty() + if (cursor != panel.cursor) { + panel.cursor = cursor + val target = panel.cursorState + val window = panel.window + main.post { + target.value = cursor + window?.hover(cursor.firstOrNull()) + } + } + } + for (event in out.events) { + val panel = panels.firstOrNull { it.state === event.panel } ?: continue + when (event) { + is XrPointerEvent.Back -> main.post { back(panel.state.kind) } + is XrPointerEvent.Click -> { + val from = panel.state.pose.position + main.post { expandChat(from) } + } + is XrPointerEvent.Resized -> { + savePlacement(panel, layers) + resize(panel, layers) + } + is XrPointerEvent.Moved -> savePlacement(panel, layers) + else -> { + val window = panel.window + main.post { window?.pointer(event) } + } + } + } + } + + /** XR thread: the place a move or resize ended at, read together now and saved on the main thread. */ + private fun savePlacement(panel: Panel, layers: XrLayerSource) { + val state = panel.state + val kind = state.kind + val head = lastHead + val pose = state.pose + val width = state.width + val height = state.height + val context = layers.context + main.post { XrPlacement.save(context, kind, head, pose, width, height) } + } + + /** XR thread: gives a resized panel a surface of its new size once its content has moved over to it. */ + private fun resize(panel: Panel, layers: XrLayerSource) { + val state = panel.state + val width = XrUnits.pixels(state.width) + val height = XrUnits.pixels(state.height) + if (width == state.pixelWidth && height == state.pixelHeight) return + val id = layers.createLayer(width, height) + val surface = if (id >= 0) layers.layerSurface(id) else null + if (surface == null) { + if (id >= 0) layers.destroyLayer(id) + return + } + val window = panel.window + main.post { + window?.resize(surface, width, height) + ops += { + if (panel in panels) { + val old = panel.layerId + panel.layerId = id + state.pixelWidth = width + state.pixelHeight = height + if (old >= 0) layers.destroyLayer(old) + } else if (source === layers) layers.destroyLayer(id) + } + } + } + + /** Main thread. */ + private fun toggleMenu(from: Vec3) { + val menu = menuHost?.get() ?: return + if (shown(XrPanelKind.MENU)) menu.xrSetMenuOpen(false) + else { + menuFrom = from + menu.xrSetMenuOpen(true) + } + } + + /** Main thread: B on a panel goes back a step, as Back does in the 2D window. */ + private fun back(kind: XrPanelKind) { + when (kind) { + XrPanelKind.MENU -> menuHost?.get()?.xrMenuBack() + XrPanelKind.PET_CHAT -> collapseChat() + XrPanelKind.PET_HEAD -> Unit + XrPanelKind.KEYBOARD -> hideKeyboard() + } + } +} + +/** Where each panel kind was left, relative to where the user faced, so it comes back there. */ +internal object XrPlacement { + class Placed(val pose: Pose, val width: Float, val height: Float) + + private class Default(val yaw: Float, val distance: Float, val dy: Float, val width: Float, val height: Float) + + private val defaults = mapOf( + XrPanelKind.MENU to Default(0f, 0.95f, -0.12f, 0.9f, 0.6f), + XrPanelKind.PET_CHAT to Default(0.6f, 0.95f, -0.12f, 0.6f, 0.7f), + XrPanelKind.PET_HEAD to Default(0.7f, 0.75f, -0.45f, 0.12f, 0.12f), + XrPanelKind.KEYBOARD to Default(0f, 0.5f, -0.5f, 0.8f, 0.36f), + ) + + private fun prefs(context: Context) = context.getSharedPreferences("quest_xr_panels", Context.MODE_PRIVATE) + + fun place(kind: XrPanelKind, head: Pose, yaw: Float, distance: Float, dy: Float): Pose { + val angle = yawOf(head.forward) + yaw + val direction = Quat.yaw(angle).rotate(Vec3.FORWARD) + val position = head.position + direction * distance + Vec3(0f, dy, 0f) + return Pose(kind.orient(position, head.position), position) + } + + fun relative(head: Pose, position: Vec3): Triple { + val offset = position - head.position + val distance = Vec3(offset.x, 0f, offset.z).length + var yaw = yawOf(offset) - yawOf(head.forward) + while (yaw > PI) yaw -= (2 * PI).toFloat() + while (yaw < -PI) yaw += (2 * PI).toFloat() + return Triple(yaw, distance, offset.y) + } + + fun load(context: Context, kind: XrPanelKind, head: Pose): Placed { + val fallback = defaults.getValue(kind) + val saved = prefs(context).getString(kind.key, null)?.split(',')?.mapNotNull { it.toFloatOrNull() } + val values = saved?.takeIf { it.size == 5 } ?: listOf(fallback.yaw, fallback.distance, fallback.dy, fallback.width, fallback.height) + val distance = values[1].coerceIn(XrUnits.MIN_DISTANCE, XrUnits.MAX_DISTANCE) + val width = if (kind.resizable) values[3].coerceIn(XrUnits.MIN_METRES, XrUnits.MAX_METRES) else fallback.width + val height = if (kind.resizable) values[4].coerceIn(XrUnits.MIN_METRES, XrUnits.MAX_METRES) else fallback.height + return Placed(place(kind, head, values[0], distance, values[2].coerceIn(-1.5f, 1.5f)), width, height) + } + + fun save(context: Context, kind: XrPanelKind, head: Pose, pose: Pose, width: Float, height: Float) { + val (yaw, distance, dy) = relative(head, pose.position) + prefs(context).edit().putString(kind.key, listOf(yaw, distance, dy, width, height).joinToString(",")).apply() + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/xr/XrSteamScreen.kt b/app/src/main/java/com/droiddeck/launcher/session/xr/XrSteamScreen.kt new file mode 100644 index 0000000000..d797f5be9b --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/xr/XrSteamScreen.kt @@ -0,0 +1,16 @@ +package com.droiddeck.launcher.session.xr + +/** Whether the guest's focus report shows Steam's own screen, with no game holding a window. */ +internal object XrSteamScreen { + /** Steam's own UI and SteamVR, which have windows of their own but are not games. */ + private val STEAM_APPS = setOf(769L, 250820L) + + /** + * Gamescope lists Steam itself while its screen is up, so a report naming no app at all, as the guest + * writes when it could not collect focus or gamescope has not published it, says nothing. + */ + fun shown(focusedApp: Long?, focusableApps: List?): Boolean { + val apps = (listOfNotNull(focusedApp) + focusableApps.orEmpty()).filter { it > 0 } + return apps.isNotEmpty() && apps.all { it in STEAM_APPS } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunch.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunch.kt index 8dfa21a725..e76e5279e1 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunch.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunch.kt @@ -97,7 +97,7 @@ object StoreLaunch { lines += "del \"%~dp0$EA_ENV\"" lines += ":run" lines += "if exist \"$EA_ORIGIN\" start \"\" \"$EA_ORIGIN\"" - lines += run + lines += "$run %*" lines += "taskkill /f /im Origin.exe >nul 2>&1" } else { lines += run diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index 52a44f34cc..8c0d4198f1 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -121,6 +121,8 @@ object StoresState { var unfinished by mutableStateOf>(emptyList()) internal set + var steamPicking by mutableStateOf(null) + fun isUnfinished(item: CatalogItem): Boolean = unfinished.any { it.store == item.store && (it.id == item.id || (it.id == null && it.folder.name == StoreInstallRoot.folderName(item.title, item.id))) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/WebCookies.kt b/app/src/main/java/com/droiddeck/launcher/stores/WebCookies.kt index b44a274c50..6077ebe327 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/WebCookies.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/WebCookies.kt @@ -14,9 +14,14 @@ internal object WebCookies { } } + fun scopes(url: String, paths: List): List { + 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, domain: String, paths: List, done: (Int) -> Unit) { val cookies = CookieManager.getInstance() - val lines = urls.flatMap { url -> expired(cookies.getCookie(url), domain, paths, Uri.parse(url).host).map { url to it } } + val lines = urls.flatMap { url -> expired(cookies.getCookie(url), domain, scopes(url, paths), Uri.parse(url).host).map { url to it } } if (lines.isEmpty()) { done(0) return diff --git a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetStore.kt b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetStore.kt index 426d3616a9..6ee2f1b16d 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetStore.kt @@ -7,6 +7,7 @@ import com.droiddeck.launcher.R import com.droiddeck.launcher.frontend.AddedGames import com.droiddeck.launcher.runtime.BattleNet import com.droiddeck.launcher.runtime.LinuxRuntime +import com.droiddeck.launcher.session.GameStorage import com.droiddeck.launcher.stores.CatalogItem import com.droiddeck.launcher.stores.InstalledStoreGame import com.droiddeck.launcher.stores.Store @@ -130,13 +131,13 @@ object BattleNetClient { StoresState.post { opener?.invoke(args) } } - fun library(context: Context, root: File = preferred(context)): List = - AddedGames.guestPath(context, StoreInstallRoot.storeDir(root, Store.BATTLENET))?.let { listOf("--library", it) }.orEmpty() + fun library(context: Context, root: File? = preferred(context)): List = + root?.let { AddedGames.guestPath(context, StoreInstallRoot.storeDir(it, Store.BATTLENET)) }?.let { listOf("--library", it) }.orEmpty() - internal fun preferred(context: Context): File { + internal fun preferred(context: Context): File? { val second = StoreInstallRoot.libraryRoot(context)?.absolutePath return StoreInstallRoot.targets(context).firstOrNull { it.root.absolutePath == second && (it.root.isDirectory || it.root.mkdirs()) }?.root - ?: StoreInstallRoot.internalRoot(context) + ?: StoreInstallRoot.internalRoot(context).takeIf { second == null && !GameStorage.disconnected(context) } } fun installGame(context: Context, uid: String, root: File) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaBackend.kt index bd8d5c1212..3da83576bb 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaBackend.kt @@ -44,7 +44,7 @@ object EaBackend : StoreBackend { signOuts.incrementAndGet() StoresState.post { StoresState.shelves.remove(store) } EaUpdates.available.clear() - runCatching { WebCookies.expire(EaLogin.SIGN_IN_URLS, ".ea.com", listOf("/")) {} } + EaLogin.forget {} } override fun syncLibrary(context: Context, force: Boolean) { @@ -100,9 +100,7 @@ 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) { - runCatching { WebCookies.expire(SIGN_IN_URLS, ".ea.com", listOf("/")) { done() } }.onFailure { done() } - } + override fun forgetSignIn(done: () -> Unit) = forget(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) @@ -116,7 +114,11 @@ internal class EaLogin(private val pending: EaAuth.Pending, override val userAge } companion object { - val SIGN_IN_URLS = listOf("https://accounts.ea.com", "https://signin.ea.com", "https://www.ea.com") + 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() } + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLsx.kt b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLsx.kt index f9e6b286a0..35e9bdb343 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLsx.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLsx.kt @@ -67,7 +67,7 @@ object EaLsx { } @Volatile var game: Game? = null - @Volatile private var account: Account? = null + @Volatile internal var account: Account? = null /** The one session of the current launch that may act for the account. */ /** Bumped whenever the launch changes; a connection accepted under an older one is not admitted. */ @Volatile internal var generation = 0 @@ -333,10 +333,11 @@ object EaLsx { private fun now() = LocalDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")) - private fun answer(session: Session, m: Message): String? { + internal fun answer(session: Session, m: Message): String? { val g = game val who = account val person = who?.takeIf { session.trusted } + val profile = who?.takeIf { session.trusted || session.claimed } val locale = g?.locale ?: "en_US" return when (m.name) { "ChallengeResponse" -> { @@ -355,15 +356,16 @@ object EaLsx { "GetConfig" -> tag("GetConfigResponse", body = SERVICES.joinToString("") { tag("Service", "Name" to it.first, "Facility" to it.second) }) "GetProfile" -> tag( "GetProfileResponse", - "Persona" to person?.persona.orEmpty(), "SubscriberLevel" to 0, "CommerceCurrency" to "USD", "IsTrialSubscriber" to false, - "Country" to "US", "UserId" to person?.userId.orEmpty(), "GeoCountry" to "US", "AvatarId" to "", "IsSubscriber" to false, - "IsSteamSubscriber" to false, "PersonaId" to person?.personaId.orEmpty(), "IsUnderAge" to false, "UserIndex" to 0, + "Persona" to profile?.persona.orEmpty(), "SubscriberLevel" to 0, "CommerceCurrency" to "USD", "IsTrialSubscriber" to false, + "Country" to "US", "UserId" to profile?.userId.orEmpty(), "GeoCountry" to "US", "AvatarId" to "", "IsSubscriber" to false, + "IsSteamSubscriber" to false, "PersonaId" to profile?.personaId.orEmpty(), "IsUnderAge" to false, "UserIndex" to 0, ) "GetSetting" -> tag("GetSettingResponse", "Setting" to when (m.attrs["SettingId"]) { "ENVIRONMENT" -> "production" "LANGUAGE" -> locale else -> "false" }) + "GetSettings" -> tag("GetSettingsResponse", "IsIGOAvailable" to false, "IsIGOEnabled" to false, "IsTelemetryEnabled" to false, "IsManualOffline" to false) "GetGameInfo" -> tag("GetGameInfoResponse", "GameInfo" to when (m.attrs["GameInfoId"]) { "FREETRIAL" -> "false" "LANGUAGES" -> LANGUAGES @@ -403,7 +405,7 @@ object EaLsx { ) }) } - "GetPresence" -> tag("GetPresenceResponse", "UserId" to person?.userId.orEmpty(), "Presence" to "INGAME") + "GetPresence" -> tag("GetPresenceResponse", "UserId" to profile?.userId.orEmpty(), "Presence" to "INGAME") "QueryPresence" -> tag("QueryPresenceResponse", body = "") "QueryFriends" -> tag("QueryFriendsResponse", body = "") "GetBlockList" -> tag("GetBlockListResponse", "Return" to "Success", body = "") diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogComet.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogComet.kt index 8ad240e651..56e8d6e128 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogComet.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogComet.kt @@ -1,7 +1,6 @@ package com.droiddeck.launcher.stores.gog import android.content.Context -import android.os.Environment import android.util.Log import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -9,7 +8,6 @@ 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 @@ -143,14 +141,13 @@ object GogComet { val pb = if (com.droiddeck.launcher.runtime.NativeGuest.forSession(context)) { val root = LinuxRuntime.rootDir(context) com.droiddeck.launcher.runtime.NativeGuest.processBuilder(context, root, - LinuxRuntime.binds(context, null, null, Environment.getExternalStorageDirectory(), null), guest).redirectErrorStream(true) + LinuxRuntime.binds(context, null, null, LinuxRuntime.sharedStorage(context), null), guest).redirectErrorStream(true) } else { - ProcessBuilder(LinuxRuntime.command(context, null, null, Environment.getExternalStorageDirectory(), guest)).redirectErrorStream(true).also { + ProcessBuilder(LinuxRuntime.command(context, null, null, LinuxRuntime.sharedStorage(context), guest)).redirectErrorStream(true).also { it.environment().apply { 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) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/steam/SteamStore.kt b/app/src/main/java/com/droiddeck/launcher/stores/steam/SteamStore.kt index f0ececd00a..bbcd1f425d 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/steam/SteamStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/steam/SteamStore.kt @@ -6,9 +6,6 @@ import android.net.Uri import android.util.Log import android.widget.Toast import androidx.annotation.StringRes -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue import com.droiddeck.launcher.R import com.droiddeck.launcher.frontend.Library import com.droiddeck.launcher.session.SessionService @@ -46,8 +43,6 @@ internal object SteamStore { /** InvalidPassword, AccessDenied, AccountNotFound, Revoked, Expired, AccountLogonDenied. */ private val REFUSALS = setOf(5, 15, 18, 26, 27, 63) - var picking by mutableStateOf(null) - class Plan(val installDir: String, val downloadBytes: Long, val installBytes: Long, val buildId: String, val linuxBuild: Boolean) { companion object { fun of(json: JSONObject): Plan? { @@ -222,7 +217,7 @@ internal object SteamStore { toast(context, R.string.steam_store_close_steam) return } - picking = item + StoresState.steamPicking = item } fun install(context: Context, item: CatalogItem, target: SteamClient.Target) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCatalog.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCatalog.kt index 7afcaeb321..405b0b955d 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCatalog.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCatalog.kt @@ -8,6 +8,9 @@ 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( @@ -148,6 +151,13 @@ 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() @@ -172,7 +182,8 @@ 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) pc.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } ?: 0L else 0L, + sizeBytes = if (!installable) 0L else (if (backCompat) console.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } else null) + ?.takeIf { it > 0 } ?: pc.maxOfOrNull { it.optLong("MaxDownloadSizeInBytes") } ?: 0L, extra = mapOf("market" to Xodus.market(), "access" to kind.orEmpty(), "pc" to flag(installable), "cloud" to flag(streams), "format" to format), ) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCloudSettingsPanel.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCloudSettingsPanel.kt index b4f9ab9cb3..c1ddd7d704 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCloudSettingsPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCloudSettingsPanel.kt @@ -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 uses the Lossless.dll DroidDeck already uses for games. Screen effects " + + "(DDFG) or LSFG can add frames. LSFG requires Lossless Scaling installed through Steam. Screen effects " + "apply to the web engine.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 8.dp, bottom = 6.dp)) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt index b33d1d0d77..1c88e48655 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxManifest.kt @@ -80,6 +80,10 @@ 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 @@ -94,17 +98,16 @@ internal object XboxManifest { } fun executable(folder: File): String { - for (path in read(folder).executables) { + val listed = read(folder).executables + for (path in listed) { require(!path.startsWith('/') && !path.contains(':') && path.split('/').none { it == ".." || it.isEmpty() }) - var file = folder - for (part in path.split('/')) { - val matches = file.listFiles().orEmpty().filter { it.name.equals(part, true) } - require(matches.size == 1) { "Missing or ambiguous Xbox launch path." } - file = matches.single() - } + val file = path.split('/').fold(folder) { dir, part -> + dir?.listFiles().orEmpty().filter { it.name.equals(part, true) }.singleOrNull() + } ?: continue require(file.canonicalPath.startsWith(folder.canonicalPath + File.separator)) if (file.isFile) return forwarded(folder, file) ?: file.relativeTo(folder).invariantSeparatorsPath } + require(listed.isEmpty()) { "Missing or ambiguous Xbox launch path." } error("The Xbox package has no supported PC launch executable.") } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxNativePlayerActivity.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxNativePlayerActivity.kt index b4d12ba922..346a65d9b4 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxNativePlayerActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxNativePlayerActivity.kt @@ -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 (the Lossless.dll DroidDeck uses for games); the frame-rate target caps the output" + "Lossless Scaling frame generation from the Steam installation; 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 DroidDeck has the Lossless.dll (frame generation settings).", + if (!lsfg) androidx.compose.material3.Text("LSFG appears here once Lossless Scaling is installed through Steam.", 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( diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt index 39866fceea..6be4ddb14e 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt @@ -1,12 +1,10 @@ package com.droiddeck.launcher.stores.xbox import android.content.Context -import android.os.Environment 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 @@ -82,7 +80,7 @@ internal object Xodus { networkLink.start() val runtime = (runtimeDirectory ?: File(app.filesDir, "xbox-runtime")).apply { mkdirs() } val root = LinuxRuntime.rootDir(app) - val external = Environment.getExternalStorageDirectory() + val external = LinuxRuntime.sharedStorage(app) val extraBinds = StoreInstallRoot.externalBindSpecsForXodus(app) val binds = LinuxRuntime.binds(app, null, null, external, extraBinds) val fastPathPreloaded = runCatching { @@ -108,7 +106,6 @@ 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) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentEntries.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentEntries.kt index ff282615f5..1df2b17315 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentEntries.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentEntries.kt @@ -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 { AgentMarkdown(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) } + if (reply.text.isNotBlank()) SelectionContainer { AgentReply(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) } if (reply.options.isNotEmpty()) AgentChoices(reply.options, answerable, onSent) } } @@ -377,10 +377,11 @@ 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), + modifier = Modifier.size(72.dp).clip(Shape12).background(pal.surfaceVariant).clickable { viewing = true }, ) else Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.heightIn(min = 40.dp).clip(Shape12).background(pal.surfaceVariant).padding(horizontal = 10.dp, vertical = 8.dp), @@ -396,4 +397,5 @@ 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 } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentMarkdown.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentMarkdown.kt index 0d85087f85..49f351a175 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentMarkdown.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentMarkdown.kt @@ -37,6 +37,106 @@ 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 { + val parts = mutableListOf() + 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) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt index 429db30258..b2793e5ba1 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt @@ -5,7 +5,9 @@ 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 @@ -50,12 +52,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 @@ -79,6 +81,7 @@ 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 @@ -108,6 +111,7 @@ 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 @@ -301,7 +305,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.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() && + val hidden = !composer.focused && !composer.tray && !composer.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() && AgentHost.approvals.isEmpty() var listHeight by remember { mutableIntStateOf(0) } Box( @@ -319,6 +323,7 @@ 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) } @@ -344,6 +349,12 @@ 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() + val photosCopying = mutableStateMapOf() var focusRequests by mutableIntStateOf(0) private set private var consumedFocusRequests by mutableIntStateOf(0) @@ -390,7 +401,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) listOfNotNull(mode ?: model) + val parts = if (compact) listOf(model) else listOfNotNull( AgentHost.harness.name, model, AgentHost.effort, mode, stringResource(R.string.agent_plan_short).takeIf { AgentHost.plan && AgentHost.harness.plans }, @@ -532,7 +543,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()) AgentMarkdown(AgentHost.live, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) + if (AgentHost.live.isNotBlank()) AgentReply(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) @@ -748,6 +759,8 @@ 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() } } @@ -813,7 +826,34 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState 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 + } + } 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), @@ -841,6 +881,7 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState 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("*/*")) } } }) + } } /** @@ -974,51 +1018,15 @@ private fun VoiceButton(voice: AgentVoice, onStart: () -> Unit, onSend: () -> Un } } -/** Attaches what the running game shows, taken from its own surface so nothing drawn over it is in the picture. */ +/** Opens the photo tray in place of the keyboard; while it is open, brings the keyboard back. */ @Composable -private fun GameFrameButton() { - val context = LocalContext.current +private fun AttachButton(trayOpen: Boolean, onClick: () -> Unit) { val pal = LocalPalette.current - 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("*/*")) } - } + 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, + ) } @Composable diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt index a462fca130..db538977f5 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt @@ -67,13 +67,18 @@ 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(Modifier.fillMaxWidth().padding(bottom = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { + Column(agentPanelFrame(), 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) { @@ -269,12 +274,8 @@ internal fun AgentProcessList(modifier: Modifier) { @Composable internal fun AgentUsage() { val context = LocalContext.current - val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - 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), - ) { + Column(agentPanelFrame(), 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)), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPet.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPet.kt index 8adadcab9c..2ded416719 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPet.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPet.kt @@ -88,7 +88,14 @@ internal object AgentPet { private set /** The floating windows could not be made, so the pet stays in DroidDeck's own windows instead. */ private var floatFailed by mutableStateOf(false) - val floating get() = enabled && allowed && !floatFailed + val floating get() = enabled && allowed && !floatFailed && usesOverlayWindows(onQuest) + /** Quest's shell turns overlay windows into system panels that take input from the VR view. */ + private val onQuest = com.droiddeck.launcher.session.QuestExperimental.isSupported() + + internal fun usesOverlayWindows(quest: Boolean) = !quest + + /** On Quest the chat opens as its own panel window, which Horizon moves, resizes and closes. */ + internal fun chatInOwnWindow(quest: Boolean = onQuest) = quest /** How to close the chat open inside each DroidDeck window that has one. */ private val closeInWindow = java.util.WeakHashMap Unit>() @@ -118,7 +125,7 @@ internal object AgentPet { AgentHost.prefs(context).edit().putBoolean(KEY, on).apply() if (on) { allowed = PetWindows.allowed(context) - if (!allowed) requestFloating(context) + if (!allowed && usesOverlayWindows(onQuest)) requestFloating(context) } } @@ -251,9 +258,12 @@ private fun PetLayer(host: AgentPetHost) { val density = LocalDensity.current val openLabel = androidx.compose.ui.res.stringResource(com.droiddeck.launcher.R.string.agent_pet_open) val openChat = { - motion.dock() - chatShown = true - chatOpen = true + if (AgentPet.chatInOwnWindow()) com.droiddeck.launcher.agent.AgentChatActivity.open(context) + else { + motion.dock() + chatShown = true + chatOpen = true + } } val closeChat = { chatOpen = false diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPetWindows.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPetWindows.kt index 72e5d0b635..e2381ca2a4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPetWindows.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPetWindows.kt @@ -21,6 +21,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -495,7 +496,13 @@ internal class PetWindows(private val context: Context) { * under it. Its contents are built while it is closed, so opening only animates. */ @Composable -internal fun PetChat(open: Boolean, motion: PetMotion, onClose: () -> Unit, onClosed: () -> Unit) { +internal fun PetChat( + open: Boolean, motion: PetMotion, onClose: () -> Unit, + page: @Composable ColumnScope.(AgentMenuSlot) -> Unit = { slot -> + AgentPage(Modifier.weight(1f).fillMaxWidth(), visible = open, startTyping = AgentHost.entries.isEmpty(), hidesPet = false, menuSlot = slot) + }, + onClosed: () -> Unit, +) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val density = androidx.compose.ui.platform.LocalDensity.current @@ -552,14 +559,16 @@ internal fun PetChat(open: Boolean, motion: PetMotion, onClose: () -> Unit, onCl alpha = fade.value } .clip(Shape16).background(colors.background).border(1.dp, pal.line, Shape16) - .clickable(remember { MutableInteractionSource() }, null, enabled = open) {} + // Never disabled: a disabled clickable leaves the focus tree, and the one it puts back on reopening + // sits unfocused above the still-focused editor, where key events then find no focus target. + .clickable(remember { MutableInteractionSource() }, null) {} .padding(start = 12.dp, end = 12.dp, top = 6.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)) { Box(Modifier.weight(1f)) { menuSlot.content?.invoke() } HeaderAction(Icons.Outlined.Close, stringResource(R.string.agent_close), size = 34.dp, tag = "agent-pet-close", onClick = onClose) } - AgentPage(Modifier.weight(1f).fillMaxWidth(), visible = open, startTyping = AgentHost.entries.isEmpty(), hidesPet = false, menuSlot = menuSlot) + page(menuSlot) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt new file mode 100644 index 0000000000..d6c5dabe68 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt @@ -0,0 +1,280 @@ +package com.droiddeck.launcher.ui + +import android.Manifest +import android.content.ContentUris +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.os.Build +import android.os.Environment +import android.provider.MediaStore +import android.provider.Settings +import android.widget.Toast +import androidx.activity.compose.LocalActivityResultRegistryOwner +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.GridItemSpan +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Check +import androidx.compose.material.icons.outlined.FolderOpen +import androidx.compose.material.icons.outlined.PhotoCamera +import androidx.compose.material.icons.outlined.PhotoLibrary +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.SnapshotStateMap +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.selected +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import coil.compose.AsyncImage +import coil.request.ImageRequest +import com.droiddeck.launcher.R +import com.droiddeck.launcher.agent.AgentAttachments +import com.droiddeck.launcher.agent.AgentHost +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +/** The device's photos, newest first, as MediaStore lets the app see them. */ +internal object AgentPhotos { + enum class Access { NONE, SELECTED, ALL } + + /** Android stops showing the request after repeated denials and answers it at once, so a denied request sends later ones to Settings. */ + var refused = false + + fun permissions(sdk: Int = Build.VERSION.SDK_INT): Array = when { + sdk >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> arrayOf(Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) + sdk >= Build.VERSION_CODES.TIRAMISU -> arrayOf(Manifest.permission.READ_MEDIA_IMAGES) + else -> arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) + } + + fun access(context: Context): Access { + fun granted(permission: String) = context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED + val all = permissions().first() + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager() -> Access.ALL + granted(all) -> Access.ALL + Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && granted(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) -> Access.SELECTED + else -> Access.NONE + } + } + + class Photo(val uri: Uri, val name: String) + + fun recent(context: Context, limit: Int = 300): List = runCatching { + val images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI + context.contentResolver.query( + images, arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME), null, null, "${MediaStore.Images.Media.DATE_ADDED} DESC", + )?.use { c -> + buildList { + while (size < limit && c.moveToNext()) add(Photo(ContentUris.withAppendedId(images, c.getLong(0)), c.getString(1).orEmpty())) + } + }.orEmpty() + }.getOrDefault(emptyList()) +} + +/** + * Copies [uris] into the conversation's attachments off the main thread, then hands [onCopied] what was attached: nothing if the + * conversation changed meanwhile or [current] says the copy was superseded. + */ +internal fun attachUris(context: Context, uris: List, current: () -> Boolean = { true }, onCopied: (List>) -> Unit = {}) { + if (uris.isEmpty()) return + val chat = AgentHost.chat + Thread({ + val copied = uris.mapNotNull { uri -> AgentAttachments.copy(context, chat, listOf(uri)).firstOrNull()?.let { uri to it } } + android.os.Handler(android.os.Looper.getMainLooper()).post { + val paths = copied.map { it.second } + if (AgentHost.chat == chat && current()) { + AgentAttachments.pending.addAll(paths) + onCopied(copied) + } else { + AgentAttachments.discard(context, paths) + onCopied(emptyList()) + } + } + }, "agent-attach").start() +} + +/** Attaches what the running game shows, taken from its own surface so nothing drawn over it is in the picture. */ +private fun attachGameFrame(context: Context) { + val grab = AgentAttachments.gameFrame ?: return + val chat = AgentHost.chat + grab frame@{ frame -> + if (frame == null) { + Toast.makeText(context, R.string.agent_attach_game_failed, 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 -> Toast.makeText(context, R.string.agent_attach_game_failed, Toast.LENGTH_SHORT).show() + AgentHost.chat == chat -> AgentAttachments.pending.add(path) + else -> AgentAttachments.discard(context, listOf(path)) + } + } + }, "agent-game-frame").start() + } +} + +/** Shown in place of the keyboard: recent photos to tap onto the message, and the system picker for anything else. */ +@Composable +internal fun AgentPhotoTray(height: Dp, copies: SnapshotStateMap, copying: SnapshotStateMap, onFiles: (() -> Unit)?) { + val context = LocalContext.current + val pal = LocalPalette.current + var access by remember { mutableStateOf(AgentPhotos.access(context)) } + var photos by remember { mutableStateOf?>(null) } + var reloads by remember { mutableStateOf(0) } + // A window no activity owns (the floating pet's chat) cannot ask for a permission, so it sends the user to the app's settings. + val launcher = if (LocalActivityResultRegistryOwner.current != null) { + rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { + AgentAttachments.picking = false + access = AgentPhotos.access(context) + if (access == AgentPhotos.Access.NONE) AgentPhotos.refused = true + reloads++ + } + } else null + val request = { + if (launcher != null && !AgentPhotos.refused) { + AgentAttachments.pick { launcher.launch(AgentPhotos.permissions()) } + } else { + val details = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + context.packageName)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + runCatching { context.startActivity(details) } + } + Unit + } + // Access can change in Settings, and new pictures arrive, while the app is in the background. + val lifecycle = LocalLifecycleOwner.current.lifecycle + DisposableEffect(lifecycle) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) { + access = AgentPhotos.access(context) + reloads++ + } + } + lifecycle.addObserver(observer) + onDispose { lifecycle.removeObserver(observer) } + } + LaunchedEffect(access, reloads) { + photos = if (access == AgentPhotos.Access.NONE) emptyList() else withContext(Dispatchers.IO) { AgentPhotos.recent(context) } + } + LazyVerticalGrid( + GridCells.Adaptive(96.dp), + Modifier.fillMaxWidth().height(height).padding(top = 8.dp).testTag("agent-photo-tray"), + horizontalArrangement = Arrangement.spacedBy(4.dp), + verticalArrangement = Arrangement.spacedBy(4.dp), + ) { + if (AgentAttachments.gameFrame != null) item { + TrayTile(Icons.Outlined.PhotoCamera, stringResource(R.string.agent_attach_game), "agent-game-frame") { attachGameFrame(context) } + } + if (onFiles != null) item { TrayTile(Icons.Outlined.FolderOpen, stringResource(R.string.agent_attach_files), "agent-attach-files", onFiles) } + if (access != AgentPhotos.Access.ALL) item { + TrayTile( + Icons.Outlined.PhotoLibrary, + stringResource(if (access == AgentPhotos.Access.NONE) R.string.agent_photos_allow else R.string.agent_photos_more), + "agent-photos-allow", + onClick = request, + ) + } + val list = photos + if (list != null && list.isEmpty() && access != AgentPhotos.Access.NONE) item(span = { GridItemSpan(maxLineSpan) }) { + Text( + stringResource(R.string.agent_photos_empty), fontSize = 13.sp, color = pal.onSurfaceVariant, textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth().padding(16.dp), + ) + } + items(list.orEmpty(), key = { it.uri.toString() }) { photo -> + val uri = photo.uri + val path = copies[uri] + val selected = path != null && path in AgentAttachments.pending + Box( + Modifier.aspectRatio(1f).clip(Shape12).background(pal.surfaceVariant) + .then(if (selected) Modifier.border(3.dp, pal.primary, Shape12) else Modifier) + .clickable { + when { + selected -> AgentAttachments.pending.remove(path) + path != null && AgentAttachments.host(context, path).exists() -> AgentAttachments.pending.add(path) + uri in copying -> Unit + else -> { + // Leaving the conversation clears the markers, so a copy started before that is no longer current even back in it. + val copy = Any() + copying[uri] = copy + attachUris(context, listOf(uri), current = { copying[uri] === copy }) { copied -> + copied.forEach { (u, p) -> copies[u] = p } + if (copying[uri] === copy) copying.remove(uri) + } + } + } + }.semantics { + contentDescription = photo.name + this.selected = selected + }.testTag("agent-photo"), + ) { + AsyncImage( + model = ImageRequest.Builder(context).data(uri).size(320).build(), contentDescription = null, + contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize(), + ) + if (selected) Box( + contentAlignment = Alignment.Center, + modifier = Modifier.align(Alignment.TopEnd).padding(6.dp).size(22.dp).clip(CircleShape).background(pal.primary), + ) { + Icon(Icons.Outlined.Check, null, tint = pal.onPrimary, modifier = Modifier.size(16.dp)) + } + } + } + } +} + +@Composable +private fun TrayTile(icon: ImageVector, label: String, tag: String, onClick: () -> Unit) { + val pal = LocalPalette.current + Column( + horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, + modifier = Modifier.aspectRatio(1f).clip(Shape12).background(pal.surfaceVariant).clickable(onClick = onClick).padding(8.dp).testTag(tag), + ) { + Icon(icon, null, tint = pal.onBackground, modifier = Modifier.size(26.dp)) + Text( + label, fontSize = 12.sp, color = pal.onBackground, textAlign = TextAlign.Center, maxLines = 3, overflow = TextOverflow.Ellipsis, + modifier = Modifier.padding(top = 6.dp), + ) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPictureViewer.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPictureViewer.kt new file mode 100644 index 0000000000..3dea67d609 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPictureViewer.kt @@ -0,0 +1,113 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.gestures.awaitEachGesture +import androidx.compose.foundation.gestures.awaitFirstDown +import androidx.compose.foundation.gestures.calculatePan +import androidx.compose.foundation.gestures.calculateZoom +import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Close +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.input.pointer.positionChanged +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Popup +import androidx.compose.ui.window.PopupProperties +import coil.compose.AsyncImage +import com.droiddeck.launcher.R +import kotlin.math.abs + +private const val MAX_ZOOM = 5f +private const val TAP_ZOOM = 2.5f + +/** + * A picture over the whole window: pinch or double-tap to zoom, drag to pan. A tap, a swipe down, + * Back or B close it. It is a popup, not a dialog, because the pet's chat lives in an overlay window, + * which has no activity token to show a dialog with. + */ +@Composable +internal fun PictureViewer(model: Any, description: String?, onDismiss: () -> Unit) { + Popup( + alignment = Alignment.Center, onDismissRequest = onDismiss, + properties = PopupProperties(focusable = true, dismissOnBackPress = true, dismissOnClickOutside = false), + ) { + var size by remember { mutableStateOf(IntSize.Zero) } + var scale by remember { mutableFloatStateOf(1f) } + var offset by remember { mutableStateOf(Offset.Zero) } + fun clamp(o: Offset, s: Float): Offset { + val x = size.width * (s - 1f) / 2f + val y = size.height * (s - 1f) / 2f + return Offset(o.x.coerceIn(-x, x), o.y.coerceIn(-y, y)) + } + val fade = if (scale == 1f && size.height > 0) (1f - abs(offset.y) / size.height * 2f).coerceIn(0.3f, 1f) else 1f + Box( + Modifier.fillMaxSize().onSizeChanged { size = it }.background(Color.Black.copy(alpha = 0.94f * fade)) + .pointerInput(Unit) { + detectTapGestures( + onDoubleTap = { at -> + if (scale > 1f) { scale = 1f; offset = Offset.Zero } else { + scale = TAP_ZOOM + offset = clamp((Offset(size.width / 2f, size.height / 2f) - at) * (TAP_ZOOM - 1f), TAP_ZOOM) + } + }, + onTap = { if (scale == 1f) onDismiss() }, + ) + } + .pointerInput(Unit) { + awaitEachGesture { + awaitFirstDown(requireUnconsumed = false) + do { + val event = awaitPointerEvent() + val zoom = event.calculateZoom() + val pan = event.calculatePan() + if (zoom != 1f || pan != Offset.Zero) { + val next = (scale * zoom).coerceIn(1f, MAX_ZOOM) + offset = if (next > 1f) clamp(offset * (next / scale) + pan, next) else Offset(0f, offset.y + pan.y) + scale = next + event.changes.forEach { if (it.positionChanged()) it.consume() } + } + } while (event.changes.any { it.pressed }) + if (scale == 1f) { + if (abs(offset.y) > size.height / 6f) onDismiss() else offset = Offset.Zero + } + } + }, + ) { + AsyncImage( + model = model, contentDescription = description, contentScale = ContentScale.Fit, + modifier = Modifier.fillMaxSize().graphicsLayer { + scaleX = scale; scaleY = scale; translationX = offset.x; translationY = offset.y + }, + ) + IconButton( + onClick = onDismiss, + modifier = Modifier.align(Alignment.TopEnd).padding(12.dp).size(44.dp).clip(CircleShape).background(Color.Black.copy(alpha = 0.5f)), + ) { + Icon(Icons.Outlined.Close, stringResource(R.string.common_close), tint = Color.White) + } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentSetupView.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentSetupView.kt index 25b01904d8..615d59cb61 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentSetupView.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentSetupView.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.platform.testTag import com.droiddeck.launcher.agent.AgentSetup.Status import com.droiddeck.launcher.agent.AgentSetup.Step import com.droiddeck.launcher.core.WirelessAdbPairingService +import com.droiddeck.launcher.session.QuestExperimental @Composable internal fun AgentSetupView(modifier: Modifier, firstControl: Modifier = Modifier, onDone: () -> Unit = {}) { @@ -104,11 +105,16 @@ internal fun AgentSetupView(modifier: Modifier, firstControl: Modifier = Modifie var keyOpen by rememberSaveable(harness.id) { mutableStateOf(false) } val (title, hint) = labels(step, harness.name, keyed) val lab = AgentHost.lab?.takeIf { it.prepare && it.running } + val questConnection = step == Step.CONNECTION && status != Status.DONE && QuestExperimental.isSupported() val detail = when { step == Step.PREPARE && lab != null -> stringResource(R.string.agent_prepare_progress, lab.permille / 10, clock(lab.etaSeconds.toLong().coerceAtLeast(0))) keyed && status == Status.DONE && AgentSetup.detail[step] == null -> harness.providers.filter { it.id in AgentSetup.keys }.joinToString(" · ") { it.name }.ifEmpty { stringResource(R.string.agent_step_free_models) } + // The Quest hint holds the one-time commands, so it stays under the status until the step passes. + questConnection -> AgentSetup.detail[step]?.let { "$it\n$hint" } ?: hint + // The Quest hint is setup instructions; once connected, the row says what it is for. + step == Step.CONNECTION && QuestExperimental.isSupported() -> AgentSetup.detail[step] ?: stringResource(R.string.agent_step_connection_hint) else -> AgentSetup.detail[step] ?: hint } // Shown while the sign-in is pending, so it is still there after a trip to the browser for the key. @@ -121,6 +127,7 @@ internal fun AgentSetupView(modifier: Modifier, firstControl: Modifier = Modifie Status.TODO, Status.FAILED -> CheckState.WARN }, title, detail, divider = index < steps.lastIndex && !showKey, + detailLines = if (questConnection) Int.MAX_VALUE else 2, ) { val blocked = (step in setOf(Step.SIGN_IN, Step.GITHUB, Step.BUILD_TOOLS) && AgentSetup.status[Step.INSTALL] != Status.DONE) || (step == Step.PREPARE && AgentSetup.status[Step.BUILD_TOOLS] != Status.DONE) @@ -258,7 +265,9 @@ internal fun agentStorageWarning(item: AgentStorage.Item) = when (item) { @Composable private fun labels(step: Step, harness: String, keyed: Boolean = false): Pair = when (step) { - Step.CONNECTION -> stringResource(R.string.agent_step_connection) to stringResource(R.string.agent_step_connection_hint) + Step.CONNECTION -> stringResource(R.string.agent_step_connection) to + if (QuestExperimental.isSupported()) stringResource(R.string.agent_step_connection_quest_hint, LocalContext.current.packageName) + else stringResource(R.string.agent_step_connection_hint) Step.INSTALL -> stringResource(R.string.agent_step_install, harness) to stringResource(R.string.agent_step_install_hint) Step.SIGN_IN -> stringResource(R.string.agent_step_sign_in, harness) to stringResource(if (keyed) R.string.agent_step_sign_in_key_hint else R.string.agent_step_sign_in_hint) Step.GITHUB -> stringResource(R.string.agent_step_github) to stringResource(R.string.agent_step_github_hint) @@ -267,7 +276,7 @@ private fun labels(step: Step, harness: String, keyed: Boolean = false): Pair R.string.agent_action_pair + Step.CONNECTION -> if (QuestExperimental.isSupported()) R.string.agent_action_allow else R.string.agent_action_pair Step.INSTALL -> R.string.agent_action_install Step.SIGN_IN, Step.GITHUB -> R.string.agent_action_sign_in Step.BUILD_TOOLS -> R.string.agent_action_install @@ -276,6 +285,7 @@ private fun action(step: Step): Int = when (step) { /** The pairing DroidDeck already uses for the phantom process fix; the agent reuses its key. */ private fun pair(context: android.content.Context) { + if (QuestExperimental.isSupported()) return AgentSetup.trustOnDevice(context) if (!WirelessAdbPairingService.notificationsEnabled(context)) { context.startActivity(android.content.Intent(android.provider.Settings.ACTION_APP_NOTIFICATION_SETTINGS) .putExtra(android.provider.Settings.EXTRA_APP_PACKAGE, context.packageName) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt b/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt new file mode 100644 index 0000000000..d4d734fa02 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt @@ -0,0 +1,62 @@ +package com.droiddeck.launcher.ui + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.LinearGradient +import android.graphics.Paint +import android.graphics.Shader +import android.view.View +import android.widget.FrameLayout +import com.droiddeck.launcher.input.AirTrigger +import java.util.EnumMap +import java.util.EnumSet + +@SuppressLint("ViewConstructor") +class AirTriggerGlow(context: Context) : View(context) { + private val lit = EnumSet.noneOf(AirTrigger::class.java) + private val density = resources.displayMetrics.density + private val paints = EnumMap(AirTrigger::class.java) + + init { + isClickable = false + isFocusable = false + importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO + layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) + val top = TOP_DP * density + for ((trigger, look) in mapOf(AirTrigger.LEFT to LEFT, AirTrigger.RIGHT to RIGHT)) { + val (color, fade) = look + paints[trigger] = Paint().apply { + shader = LinearGradient(0f, top, 0f, top + HEIGHT_DP * density, + fade.map { Color.argb(it, Color.red(color), Color.green(color), Color.blue(color)) }.toIntArray(), + STOPS, Shader.TileMode.CLAMP) + } + } + } + + fun show(trigger: AirTrigger, on: Boolean) { + if (if (on) lit.add(trigger) else lit.remove(trigger)) invalidate() + } + + override fun onDraw(canvas: Canvas) { + val width = WIDTH_DP * density + val margin = SIDE_DP * density + val top = TOP_DP * density + for (trigger in lit) { + val left = if (trigger == AirTrigger.LEFT) margin else this.width - margin - width + canvas.drawRect(left, top, left + width, top + HEIGHT_DP * density, paints.getValue(trigger)) + } + } + + private companion object { + // Game Space's tgk_*_top_pressed images and their landscape placement on a 2688 x 1216 RedMagic screen. + const val WIDTH_DP = 78f + const val HEIGHT_DP = 33f + const val SIDE_DP = 37f + const val TOP_DP = 2f + val STOPS = floatArrayOf(0f, 0.04f, 0.05f, 0.2f, 0.4f, 0.6f, 0.8f, 1f) + val LEFT = Color.rgb(230, 23, 57) to listOf(255, 255, 150, 102, 55, 36, 18, 0) + val RIGHT = Color.rgb(23, 91, 230) to listOf(255, 255, 151, 94, 41, 27, 14, 0) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomDesktopPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomDesktopPanel.kt index c9e8362c4d..38359530db 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomDesktopPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomDesktopPanel.kt @@ -46,7 +46,11 @@ class BottomDesktopPanel( private val status = ComposeView(context).apply { setContent { DroidDeckTheme { BottomDesktopStatus(state.value, ::startAgain) } } } - private val keyboardHost = KeyboardHost(context) { event -> sendKey(event) } + private val keyboardHost = KeyboardHost( + context, + sendKeyEvent = { event -> sendKey(event) }, + sendText = BottomDesktop::sendText, + ) private var directTouch = SessionPrefs.bottomDesktopDirectTouch(context) private val touchMode = mutableStateOf(directTouch) private val trackpad = TouchpadGestures(ViewConfiguration.get(context).scaledTouchSlop.toFloat(), TrackpadInput()).apply { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt index fe66a06396..1524da8b92 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt @@ -338,6 +338,24 @@ internal fun sessionBarModel( internal fun deckPanelTabs(context: Context, selected: DeckPanel, onSelect: (DeckPanel) -> Unit) = BarTabs(DeckPanel.entries.map { context.getString(it.label) }, selected.ordinal) { onSelect(DeckPanel.entries[it]) } +internal fun padKeysView( + context: Context, steam: Boolean, onMenu: () -> Unit, onSteam: () -> Unit, onQam: () -> Unit, +): ComposeView = ComposeView(context).apply { + setContent { DroidDeckTheme { PadKeys(steam, onMenu, onSteam, onQam) } } +} + +@Composable +internal fun PadKeys(steam: Boolean, onMenu: () -> Unit, onSteam: () -> Unit, onQam: () -> Unit) { + Row( + Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), + horizontalArrangement = if (steam) Arrangement.SpaceBetween else Arrangement.Center, + ) { + if (steam) BarActions(null, false, onSteam, null) + BarActions(onMenu, false, null, null) + if (steam) BarActions(null, false, null, onQam) + } +} + internal fun bottomScreenBarView(context: Context, model: () -> BottomBarModel): ComposeView = ComposeView(context).apply { setContent { DroidDeckTheme { BottomScreenBar(model()) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt index d2630fa7b7..76a3c40636 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt @@ -8,11 +8,14 @@ import androidx.compose.foundation.Canvas import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.AlignHorizontalCenter import androidx.compose.material.icons.outlined.AlignHorizontalLeft import androidx.compose.material.icons.outlined.AlignHorizontalRight +import androidx.compose.material.icons.outlined.VerticalSplit import androidx.compose.material.icons.outlined.WidthFull import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -72,7 +75,8 @@ internal enum class QamFit(val id: String, @StringRes val label: Int, val icon: FULL("full", R.string.bottom_qam_layout_full, Icons.Outlined.WidthFull, 0), LEFT("left", R.string.bottom_qam_layout_left, Icons.Outlined.AlignHorizontalLeft, -1), CENTER("center", R.string.bottom_qam_layout_center, Icons.Outlined.AlignHorizontalCenter, 0), - RIGHT("right", R.string.bottom_qam_layout_right, Icons.Outlined.AlignHorizontalRight, 1); + RIGHT("right", R.string.bottom_qam_layout_right, Icons.Outlined.AlignHorizontalRight, 1), + SPLIT("split", R.string.bottom_qam_layout_split, Icons.Outlined.VerticalSplit, 0); val next: QamFit get() = entries[(ordinal + 1) % entries.size] @@ -92,6 +96,7 @@ internal enum class QamFit(val id: String, @StringRes val label: Int, val icon: internal object QamLayout { private const val WIDE_CSS = "div.BasicUI { width: 100% !important; } div[class*=\\\"tab_\\\"] { max-width: none !important; }" + private const val PARKED_CSS = " #Footer { display: none !important; }" /** Scale and left edge of the menu in a box; [align] -1, 0 or 1 places a narrower menu left, centred or right. */ fun fit(boxWidth: Float, boxHeight: Float, contentRight: Float, cssHeight: Float, align: Int = 0): Pair { @@ -102,10 +107,13 @@ internal object QamLayout { fun toCss(x: Float, y: Float, scale: Float, left: Float): Pair = (x - left) / scale to y / scale /** Makes the menu follow the panel-shaped view (Steam sizes it once, on open) and lifts each tab's 300 px cap, then measures where the content ends. */ - /** [wide] is false while the menu is shown on the top screen, where it keeps Steam's own layout. */ - fun contentScript(wide: Boolean): String = "(() => { let s = document.getElementById('dd-qam-wide'); " + + /** + * [wide] is false while the menu is shown on the top screen, where it keeps Steam's own layout. [parked] hides the + * button-hint footer Steam draws in a game, which stays an empty black strip while the controller is not on the menu. + */ + fun contentScript(wide: Boolean, parked: Boolean = wide): String = "(() => { let s = document.getElementById('dd-qam-wide'); " + "if (!s) { s = document.createElement('style'); s.id = 'dd-qam-wide'; document.head.appendChild(s); } " + - "const css = '${if (wide) WIDE_CSS else ""}'; " + + "const css = '${(if (wide) WIDE_CSS else "") + (if (parked) PARKED_CSS else "")}'; " + "if (s.textContent !== css) s.textContent = css; if (document.scrollingElement.scrollLeft) document.scrollingElement.scrollLeft = 0; " + "const w = innerWidth; let right = 0; for (const e of document.body.querySelectorAll('*')) { " + "const r = e.getBoundingClientRect(); const tab = /(^| )tab_/.test(String(e.className)); " + @@ -117,17 +125,90 @@ private const val TICK_MS = 1_000L private const val FAST_TICK_MS = 150L private const val MAX_RETRY_MS = 4_000L -/** The last frame shown, so returning to the panel shows the menu at once while the live stream reconnects. */ +/** One of Steam's menu pages streamed to the panel; the last frame is kept so returning to the panel shows it at once. */ +internal class MenuStream { + @Volatile var page: CdpPage? = null + val live = java.util.concurrent.atomic.AtomicBoolean(false) + val image = mutableStateOf(null) + val shape = mutableStateOf(null) + + fun show(frame: ImageBitmap) { + image.value = frame + live.set(true) + } + + /** Connects to [path] and starts its screencast; false when the page cannot be reached. */ + fun connect(port: Int, path: String): Boolean { + page?.close() + page = null + live.set(false) + val p = runCatching { + CdpPage(port, path) { method, params -> + if (method == "Page.screencastFrame") { + page?.send("Page.screencastFrameAck", JSONObject().put("sessionId", params.optInt("sessionId"))) + decodeFrame(params.optString("data"))?.let(::show) + } + } + }.onFailure { android.util.Log.w("SteamQam", "devtools connect: $it") }.getOrNull() ?: return false + page = p + p.send("Page.enable") + val started = p.call("Page.startScreencast", JSONObject().put("format", "jpeg").put("quality", 85) + .put("maxWidth", 1920).put("maxHeight", 1440)) + if (started == null || started.has("error") || !started.has("result")) { + p.close() + page = null + return false + } + return true + } + + /** Runs [script], which returns the page's [width, height, pixel ratio, content right], and refreshes a still page. */ + fun refresh(script: String) { + val p = page ?: return + // The screencast sends frames only when the menu repaints, so a still menu needs one screenshot. + if (!live.get()) { + p.call("Page.captureScreenshot", JSONObject().put("format", "jpeg").put("quality", 85)) + ?.optJSONObject("result")?.optString("data")?.let(::decodeFrame)?.let(::show) + } + (p.evaluate(script) as? String)?.let { text -> + runCatching { + val a = JSONArray(text) + val layout = FloatArray(4) { a.getDouble(it).toFloat() } + if (!layout.contentEquals(shape.value)) shape.value = layout + } + } + } + + /** Stops the stream and runs [restore] on the page, which outlives this connection. */ + fun stop(restore: String) { + val p = page ?: return + page = null + runCatching { p.send("Page.stopScreencast") } + runCatching { p.evaluate(restore) } + p.close() + } + + fun frame(): QamFrame? { + val img = image.value + val l = shape.value + return if (img != null && l != null && l[0] > 0f) QamFrame(img, l[0], l[1], l[3].coerceIn(l[0] * 0.25f, l[0])) else null + } +} + +/** Steam's main menu beside the quick access menu; Steam's side of the hold keeps it in place and filling its view. */ +internal object MainMenuLayout { + const val CONTENT_SCRIPT = "JSON.stringify([innerWidth, innerHeight, devicePixelRatio, innerWidth])" +} + +/** Panel streams kept across visits to the panel. */ private object QamCache { - @Volatile var image: ImageBitmap? = null - @Volatile var shape: FloatArray? = null + val qam = MenuStream() + val main = MenuStream() } @Composable internal fun SteamQamPanel() { val context = LocalContext.current.applicationContext - var image by remember { mutableStateOf(QamCache.image) } - var shape by remember { mutableStateOf(QamCache.shape) } var failed by remember { mutableStateOf(false) } var slow by remember { mutableStateOf(false) } LaunchedEffect(Unit) { @@ -135,78 +216,67 @@ internal fun SteamQamPanel() { slow = true } val fit = QamFit.current(context) - val holder = remember { arrayOfNulls(1) } + val qam = QamCache.qam + val mainMenu = QamCache.main val owner = remember { SteamQam.newOwner() } val relay = remember { intArrayOf(0) } - val live = remember { java.util.concurrent.atomic.AtomicBoolean(false) } + val mainPath = remember { arrayOfNulls(1) } val aspect = remember { floatArrayOf(0f) } val measure = Modifier.fillMaxSize().onSizeChanged { if (it.height > 0) aspect[0] = it.width.toFloat() / it.height } - val show = { frame: ImageBitmap -> image = frame; QamCache.image = frame; live.set(true) } LaunchedEffect(Unit) { withContext(Dispatchers.IO) { var misses = 0 + // The main menu page backs off on its own, so Quick Access stays available while its neighbour cannot connect. + var mainMisses = 0 + var mainRetryAt = 0L + fun split() = QamFit.current(context) == QamFit.SPLIT // The lease is renewed on its own, so slow discovery or a retry backoff never lets the held menu lapse. val renew = launch { while (isActive) { - if (SessionState.phase == SessionPhase.READY && aspect[0] > 0f) SteamQam.hold(context, aspect[0], owner) + if (SessionState.phase == SessionPhase.READY && aspect[0] > 0f) SteamQam.hold(context, aspect[0], owner, split()) delay(TICK_MS) } } try { while (isActive) { // Holding the menu before Steam's first frame keeps gamescope from presenting it. - if (SessionState.phase != SessionPhase.READY) { + if (SessionState.phase != SessionPhase.READY || aspect[0] == 0f) { delay(FAST_TICK_MS) continue } - if (aspect[0] == 0f) { - delay(FAST_TICK_MS) - continue - } - val held = SteamQam.hold(context, aspect[0], owner) + val split = split() + val held = SteamQam.hold(context, aspect[0], owner, split) ensureActive() var reached = held != null if (held?.open == SteamQam.QUICK_ACCESS) { - var page = holder[0] - if (page == null || page.closed) { - page?.close() - live.set(false) - page = SteamQam.target(context)?.let { t -> + if (qam.page?.closed != false) { + val t = SteamQam.target(context) + if (t != null) { if (relay[0] != 0 && relay[0] != t.port) SteamQam.stopRelay(context, relay[0]) relay[0] = t.port - runCatching { - CdpPage(t.port, t.path) { method, params -> - if (method == "Page.screencastFrame") { - holder[0]?.send("Page.screencastFrameAck", JSONObject().put("sessionId", params.optInt("sessionId"))) - decodeFrame(params.optString("data"))?.let(show) - } - } - }.onFailure { android.util.Log.w("SteamQam", "devtools connect: $it") }.getOrNull() + mainPath[0] = t.mainPath + qam.connect(t.port, t.path) + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) } - holder[0] = page ensureActive() - page?.send("Page.enable") - val started = page?.call("Page.startScreencast", JSONObject().put("format", "jpeg").put("quality", 85) - .put("maxWidth", 1920).put("maxHeight", 1440)) - if (page != null && (started == null || started.has("error") || !started.has("result"))) { - page.close() - page = null - holder[0] = null - } } - // The screencast sends frames only when the menu repaints, so a still menu needs one screenshot. - if (!live.get()) { - page?.call("Page.captureScreenshot", JSONObject().put("format", "jpeg").put("quality", 85)) - ?.optJSONObject("result")?.optString("data")?.let(::decodeFrame)?.let(show) - } - reached = page != null - val wide = !held.top && QamFit.current(context) == QamFit.FULL - (page?.evaluate(QamLayout.contentScript(wide)) as? String)?.let { text -> - runCatching { - val a = JSONArray(text) - val layout = floatArrayOf(a.getDouble(0).toFloat(), a.getDouble(1).toFloat(), a.getDouble(2).toFloat(), a.getDouble(3).toFloat()) - if (!layout.contentEquals(shape)) { shape = layout; QamCache.shape = layout } + reached = qam.page?.closed == false + val wide = !held.top && (QamFit.current(context) == QamFit.FULL || split) + qam.refresh(QamLayout.contentScript(wide, parked = !held.top)) + val path = mainPath[0] + if (split && path != null) { + val now = android.os.SystemClock.elapsedRealtime() + if (mainMenu.page?.closed != false && now >= mainRetryAt) { + if (mainMenu.connect(relay[0], path)) { + mainMisses = 0 + } else { + mainMisses++ + mainRetryAt = now + minOf(TICK_MS shl minOf(mainMisses - 1, 2), MAX_RETRY_MS) + } } + mainMenu.refresh(MainMenuLayout.CONTENT_SCRIPT) + } else if (!split) { + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) } } failed = !reached @@ -214,7 +284,7 @@ internal fun SteamQamPanel() { misses = if (reached) 0 else misses + 1 val wait = when { !reached -> minOf(TICK_MS shl minOf(misses - 1, 2), MAX_RETRY_MS) - live.get() -> TICK_MS + qam.live.get() && (!split || mainMenu.live.get() || mainMenu.page?.closed != false) -> TICK_MS else -> FAST_TICK_MS } val used = QamFit.current(context) @@ -225,35 +295,46 @@ internal fun SteamQamPanel() { } finally { withContext(NonCancellable) { renew.cancelAndJoin() - val page = holder[0] - holder[0] = null - runCatching { page?.send("Page.stopScreencast") } - // The page outlives this connection, so the widened layout would otherwise stay on the top screen. - runCatching { page?.evaluate(QamLayout.contentScript(wide = false)) } - page?.close() + // The pages outlive these connections, so the widened layouts would otherwise stay on the top screen. + qam.stop(QamLayout.contentScript(wide = false)) + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) SteamQam.release(context, relay[0], owner) } } } } - val img = image - val l = shape - val f = remember(img, l) { - if (img != null && l != null && l[0] > 0f) QamFrame(img, l[0], l[1], l[3].coerceIn(l[0] * 0.25f, l[0])) else null - } - if (f == null) { + val qamFrame = qam.frame() + if (qamFrame == null) { Box(measure) { if (slow) PanelNote(stringResource(if (failed) R.string.bottom_qam_unavailable else R.string.achievements_reading)) } return } - BoxWithConstraints(measure.background(f.fill)) { + if (fit != QamFit.SPLIT) { + MenuCanvas(qamFrame, fit.align, measure) { qam.page } + return + } + // Each side is as wide as its menu at the shared scale, so neither is shrunk nor padded with empty space. + val mainFrame = mainMenu.frame() + val mainWidth = mainFrame?.cssWidth ?: SteamQam.MAIN_CSS_WIDTH.toFloat() + Row(measure) { + val left = Modifier.weight(mainWidth).fillMaxHeight() + if (mainFrame != null) MenuCanvas(mainFrame, -1, left) { mainMenu.page } + else Box(left.background(qamFrame.fill)) + MenuCanvas(qamFrame, -1, Modifier.weight(qamFrame.cssWidth).fillMaxHeight()) { qam.page } + } +} + +/** Draws [f] scaled into the box, placed by [align], and forwards touches on it to [page]. */ +@Composable +private fun MenuCanvas(f: QamFrame, align: Int, modifier: Modifier, page: () -> CdpPage?) { + BoxWithConstraints(modifier.background(f.fill)) { val density = LocalDensity.current val boxW = with(density) { maxWidth.toPx() } val boxH = with(density) { maxHeight.toPx() } - val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight, fit.align) + val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight, align) Canvas( - Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH, fit) { + Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH, align) { var touching = false var target: CdpPage? = null try { @@ -268,7 +349,7 @@ internal fun SteamQamPanel() { PointerEventType.Release -> "touchEnd" else -> null }?.takeIf { it == "touchStart" || touching } ?: continue - if (type == "touchStart") target = holder[0] + if (type == "touchStart") target = page() touching = type != "touchEnd" val points = if (type == "touchEnd") JSONArray() else JSONArray().put(JSONObject().put("x", x.toDouble()).put("y", y.toDouble())) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt b/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt index da1d8d4bb4..b954512fff 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt @@ -24,7 +24,11 @@ object ControllerHaptics { tick(context) } - fun tick(context: Context) { + fun tick(context: Context) = vibrate(context, VibrationEffect.EFFECT_TICK, 10) + + fun click(context: Context) = vibrate(context, VibrationEffect.EFFECT_CLICK, 20) + + private fun vibrate(context: Context, predefined: Int, fallbackMs: Long) { val vibrator = if (Build.VERSION.SDK_INT >= 31) { context.getSystemService(VibratorManager::class.java)?.defaultVibrator } else { @@ -32,11 +36,11 @@ object ControllerHaptics { } ?: return if (!vibrator.hasVibrator()) return if (Build.VERSION.SDK_INT >= 29) { - vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK)) + vibrator.vibrate(VibrationEffect.createPredefined(predefined)) } else if (Build.VERSION.SDK_INT >= 26) { - vibrator.vibrate(VibrationEffect.createOneShot(10, VibrationEffect.DEFAULT_AMPLITUDE)) + vibrator.vibrate(VibrationEffect.createOneShot(fallbackMs, VibrationEffect.DEFAULT_AMPLITUDE)) } else { - @Suppress("DEPRECATION") vibrator.vibrate(10) + @Suppress("DEPRECATION") vibrator.vibrate(fallbackMs) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DevPreview.kt b/app/src/main/java/com/droiddeck/launcher/ui/DevPreview.kt index 46ea147324..3e8b6b1d1e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DevPreview.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DevPreview.kt @@ -57,12 +57,17 @@ import com.droiddeck.launcher.stores.StoresState /** What the Library pretends while a developer previews it. Nothing here is saved: a restart always comes back to [OFF]. */ internal enum class LibraryPreview { OFF, NOTHING_INSTALLED, SIGNED_OUT, SAMPLE } +/** How many games the Steam home pretends are installed. Nothing here is saved. */ +internal enum class SteamHomePreview(val games: Int) { OFF(-1), NONE(0), FEW(3), MANY(12) } + internal enum class DrawerPreview { STEAM, DESKTOP, GAME } /** Developer tools' preview states: screens that are otherwise hard to reach, shown without changing anything real. */ internal object DevPreview { var library by mutableStateOf(LibraryPreview.OFF) var drawer by mutableStateOf(null) + var steamHome by mutableStateOf(SteamHomePreview.OFF) + var openSteam by mutableStateOf(false) /** The UI zoo sheet: where previews are picked, one at a time, only when asked for. */ var zoo by mutableStateOf(false) /** Opt-in: a preview button where its state lives (the Library's toolbar), for switching states without the zoo. */ @@ -87,6 +92,41 @@ internal fun sampleOwned(store: Store): List = internal fun sampleInstalled(owned: Map>): Set = owned.values.flatMap { items -> items.take(SAMPLE_INSTALLED).map { it.key } }.toSet() +/** The Steam home's games while a developer previews it: this many invented titles, no art, nothing installed. */ +internal fun sampleSteamHomeGames(count: Int): List = listOf( + "Portal 2", "Hades", "Celeste", "Stardew Valley", "Hollow Knight", "Balatro", + "Dead Cells", "Terraria", "Vampire Survivors", "Slay the Spire", "Cuphead", "Inscryption", +).take(count).mapIndexed { i, name -> + com.droiddeck.launcher.frontend.Library.SteamGame(1000 + i, name, art = null, library = "steam", lastPlayed = 1_700_000_000_000L - i * 86_400_000L) +} + +/** The pill a previewed Steam home shows, so the fake state is never mistaken for the real one. */ +@Composable +internal fun SteamHomePreviewPill(modifier: Modifier = Modifier) { + val preview = DevPreview.steamHome + if (preview == SteamHomePreview.OFF) return + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val label = stringResource( + when (preview) { + SteamHomePreview.NONE -> R.string.dev_preview_steam_none + SteamHomePreview.FEW -> R.string.dev_preview_steam_few + else -> R.string.dev_preview_steam_many + }, + ) + val end = stringResource(R.string.dev_preview_end) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), + modifier = modifier.background(colors.surface, CircleShape).border(1.dp, pal.signal, CircleShape) + .clickable(role = Role.Button, onClickLabel = end) { DevPreview.steamHome = SteamHomePreview.OFF } + .padding(start = 14.dp, end = 10.dp, top = 8.dp, bottom = 8.dp).testTag("dev-preview-steam-end"), + ) { + Icon(Icons.Outlined.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp)) + Text(stringResource(R.string.dev_preview_banner, label), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) + Icon(Icons.Filled.Close, end, tint = colors.onSurfaceVariant, modifier = Modifier.size(18.dp)) + } +} + /** The pill a previewed Library shows, so the fake state is never mistaken for the real one. */ @Composable internal fun LibraryPreviewPill(modifier: Modifier = Modifier) { @@ -159,7 +199,6 @@ internal fun SessionDrawerPreview(secondScreens: List) { secondScreenDisplays = secondScreens, selectedSecondScreenDisplay = secondScreens.firstOrNull()?.id ?: -1, onSecondScreenDisplay = {}, - onImportLossless = {}, onKeyboard = {}, onHardwareKeyboard = {}, onSteamMenu = if (steam) ({}) else null, onQam = if (steam) ({}) else null, @@ -215,6 +254,17 @@ internal fun UiZooSheet() { DrawerPreview.GAME to R.string.session_title_game, )) ActionRow(stringResource(label), null, show, onClick = { close(); DevPreview.drawer = mode }, modifier = Modifier.testTag("zoo-drawer-${mode.name.lowercase()}")) } + SettingsGroup(stringResource(R.string.dev_preview_steam_home)) { + for ((mode, label) in listOf( + SteamHomePreview.NONE to R.string.dev_preview_steam_none, + SteamHomePreview.FEW to R.string.dev_preview_steam_few, + SteamHomePreview.MANY to R.string.dev_preview_steam_many, + )) ActionRow( + stringResource(label), null, show, + onClick = { close(); DevPreview.steamHome = mode; DevPreview.openSteam = true }, + modifier = Modifier.testTag("zoo-steam-${mode.name.lowercase()}"), + ) + } SettingsGroup(stringResource(R.string.dev_preview_library)) { for ((mode, label) in listOf( LibraryPreview.NOTHING_INSTALLED to R.string.dev_preview_library_nothing_installed, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DrawerEntryHint.kt b/app/src/main/java/com/droiddeck/launcher/ui/DrawerEntryHint.kt index 59c87675e9..3810161619 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DrawerEntryHint.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DrawerEntryHint.kt @@ -7,13 +7,16 @@ import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideOutHorizontally import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.displayCutout +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.widthIn @@ -35,6 +38,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role @@ -90,6 +94,29 @@ internal fun DrawerEntryHint(steam: Boolean, inverted: Boolean, onOpen: () -> Un } } +/** A Quest has no system Back gesture, so a laser drag in from the right edge stands in for it. */ +@Composable +internal fun DrawerEdgeSwipe(onBack: () -> Unit) { + val density = LocalDensity.current + val threshold = with(density) { 48.dp.toPx() } + val strip = with(density) { 12.toDp() } + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.CenterEnd) { + Box( + Modifier.fillMaxHeight().width(strip).testTag("drawer-edge") + .pointerInput(Unit) { + var travelled = 0f + detectHorizontalDragGestures( + onDragStart = { travelled = 0f }, + onDragEnd = { if (travelled <= -threshold) onBack() }, + ) { change, amount -> + change.consume() + travelled += amount + } + }, + ) + } +} + @Composable internal fun DrawerCornerTap(onOpen: () -> Unit) { Box(Modifier.fillMaxSize().windowInsetsPadding(WindowInsets.displayCutout), contentAlignment = Alignment.TopEnd) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DrawerSections.kt b/app/src/main/java/com/droiddeck/launcher/ui/DrawerSections.kt new file mode 100644 index 0000000000..fd6839d134 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/DrawerSections.kt @@ -0,0 +1,142 @@ +package com.droiddeck.launcher.ui + +import android.content.Context +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically +import androidx.compose.foundation.LocalIndication +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState +import androidx.compose.foundation.interaction.collectIsHoveredAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.ExpandMore +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.compositionLocalOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateMapOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.stateDescription +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.droiddeck.launcher.R +import com.droiddeck.launcher.session.SessionPrefs + +/** + * Inside the session menu every top-level settings group folds to its header and a summary of its values. + * Groups start folded; a group the player opens or folds stays that way across sessions. + */ +internal object DrawerSectionState { + private val chosen = mutableStateMapOf() + + fun load(context: Context) { + if (DevPreview.drawer != null) return + chosen.clear() + chosen.putAll(SessionPrefs.drawerSections(context)) + } + + fun isOpen(key: String) = chosen[key] ?: false + + fun toggle(context: Context, key: String) { + chosen[key] = !isOpen(key) + if (DevPreview.drawer == null) SessionPrefs.setDrawerSections(context, chosen.toMap()) + } +} + +internal class DrawerSections(val context: Context, val track: (String) -> Modifier) + +internal val LocalDrawerSections = compositionLocalOf { null } + +@Composable +internal fun DrawerSection( + sections: DrawerSections, key: String, title: String, summary: String?, tag: String?, + content: @Composable ColumnScope.() -> Unit, +) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val open = DrawerSectionState.isOpen(key) + val source = remember { MutableInteractionSource() } + val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value + val rotation by animateFloatAsState(if (open) 180f else 0f, Motion.tw(180), label = "sectionArrow") + val state = stringResource(if (open) R.string.widgets_expanded else R.string.widgets_collapsed) + val toggle = { DrawerSectionState.toggle(sections.context, key) } + val shape = RoundedCornerShape(14.dp) + Column( + Modifier.fillMaxWidth().padding(top = 6.dp).clip(shape) + .background(colors.surface).border(1.dp, if (open) pal.line2 else pal.line, shape), + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = Modifier.fillMaxWidth().heightIn(min = 48.dp) + .then(sections.track("section-$key")) + .testTag("drawer-section-$key") + .background(if (hot) pal.signal.copy(alpha = 0.12f) else androidx.compose.ui.graphics.Color.Transparent) + .glideBorder(hot, shape, pal.signal) + .hoverable(source) + .clickable(interactionSource = source, indication = LocalIndication.current, role = Role.Button, onClick = toggle) + .controllerConfirm(onClick = toggle) + .semantics { contentDescription = title; stateDescription = state } + .padding(start = 12.dp, end = 8.dp, top = 6.dp, bottom = 6.dp), + ) { + Column(Modifier.weight(1f)) { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) { + Text(title.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, + color = if (open) colors.onBackground else colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f, fill = false)) + if (tag != null) Text( + tag, fontSize = 10.sp, fontWeight = FontWeight.SemiBold, color = pal.signal, maxLines = 1, + modifier = Modifier.clip(RoundedCornerShape(6.dp)).background(pal.signal.copy(alpha = 0.14f)) + .padding(horizontal = 6.dp, vertical = 2.dp), + ) + } + if (!open && !summary.isNullOrEmpty()) Text( + summary, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, + modifier = Modifier.padding(top = 2.dp), + ) + } + Icon(Icons.Outlined.ExpandMore, contentDescription = null, tint = colors.onSurfaceVariant, + modifier = Modifier.size(22.dp).rotate(rotation)) + } + AnimatedVisibility(open, enter = expandVertically(Motion.tw(200)) + fadeIn(Motion.tw(160)), + exit = shrinkVertically(Motion.tw(160)) + fadeOut(Motion.tw(120))) { + Column(Modifier.fillMaxWidth()) { + Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line)) + // Only top-level groups fold; groups and dialogs opened from inside one draw normally. + CompositionLocalProvider(LocalDrawerSections provides null) { content() } + } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt b/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt index d14086ffc5..c2225dd513 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt @@ -26,7 +26,8 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri fun on(key: String) = cfg[key] == "1" fun int(key: String, fallback: Int) = cfg[key]?.toIntOrNull() ?: fallback - SettingsGroup(stringResource(R.string.drawer_hud)) { + SettingsGroup(stringResource(R.string.drawer_hud), key = "performance-hud", + detail = stringResource(if (a.hudOn) R.string.widgets_on else R.string.widgets_off)) { ToggleRow(host, "hud", stringResource(R.string.drawer_hud), null, a.hudOn, chipModifier = track("hud"), onChange = a.onHud) if (a.hudOn) ToggleRow( host, "hud-only-during-game", stringResource(R.string.hud_only_during_game), @@ -38,7 +39,8 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri } if (!a.hudOn) return@SettingsGroup val size = DroidDeckHudSize.from(cfg["hudSize"]) - ChoiceRow(host, "hud-size", stringResource(R.string.hud_size), stringResource(R.string.hud_size_hint), + ChoiceRow(host, "hud-size", stringResource(R.string.hud_size), + stringResource(if (size == DroidDeckHudSize.SIDE_STRIP) R.string.hud_size_side_strip_hint else R.string.hud_size_hint), listOf( DroidDeckHudSize.FULL to stringResource(R.string.hud_size_full), DroidDeckHudSize.TILES to stringResource(R.string.hud_size_tiles), @@ -46,6 +48,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri DroidDeckHudSize.MINIMAL to stringResource(R.string.hud_size_minimal), DroidDeckHudSize.MEGA to stringResource(R.string.hud_size_mega), DroidDeckHudSize.STRIP to stringResource(R.string.hud_size_strip), + DroidDeckHudSize.SIDE_STRIP to stringResource(R.string.hud_size_side_strip), ), size, chipModifier = track("hud-size")) { a.onHudSetting("hudSize", it.token) } ChoiceRow(host, "hud-hold", stringResource(R.string.hud_hold), null, @@ -62,7 +65,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri if (a.dashboardAvailable && a.secondScreenDisplays.isNotEmpty()) BottomStripSettings(host, track) if (!a.hudOn) return - SettingsGroup(stringResource(R.string.hud_group_look)) { + SettingsGroup(stringResource(R.string.hud_group_look), key = "performance-hud-look") { SliderRow(stringResource(R.string.hud_scale), null, int("hudScale", 100), 50..150, step = 5, format = { "$it%" }, modifier = track("hud-scale")) { a.onHudSetting("hudScale", it.toString()) } SliderRow(stringResource(R.string.drawer_hud_opacity), null, int("hudOpacity", 80), 0..100, step = 5, format = { "$it%" }, @@ -85,7 +88,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri } var editing by remember { mutableStateOf(false) } - SettingsGroup(stringResource(R.string.hud_group_metrics)) { + SettingsGroup(stringResource(R.string.hud_group_metrics), key = "performance-hud-metrics") { ActionRow(stringResource(R.string.hud_group_metrics), null, stringResource(R.string.common_edit), onClick = { editing = true }, modifier = track("hud-readings")) val rows = DroidDeckHudSize.rowsFor(DroidDeckHudSize.from(cfg["hudSize"]), cfg) @@ -103,7 +106,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri ) } - if (on("showTemp") || on("showGpuTemp") || on("showBatteryTemp")) SettingsGroup(stringResource(R.string.hud_group_temps)) { + if (on("showTemp") || on("showGpuTemp") || on("showBatteryTemp")) SettingsGroup(stringResource(R.string.hud_group_temps), key = "performance-hud-temps") { ChoiceRow(host, "hud-temp-unit", stringResource(R.string.hud_temp_unit), null, listOf("c" to "°C", "f" to "°F"), if (cfg["tempUnit"].equals("f", true)) "f" else "c", chipModifier = track("hud-temp-unit")) { a.onHudSetting("tempUnit", it) } @@ -129,7 +132,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri } } - SettingsGroup(stringResource(R.string.hud_group_more)) { + SettingsGroup(stringResource(R.string.hud_group_more), key = "performance-hud-more") { ActionRow(stringResource(R.string.hud_export), stringResource(R.string.hud_export_hint), stringResource(R.string.hud_export_button), onClick = a.onHudExport, modifier = track("hud-export")) ActionRow(stringResource(R.string.hud_reset), null, stringResource(R.string.hud_reset_button), @@ -145,7 +148,7 @@ private fun BottomStripSettings(host: MenuHost, track: (String) -> Modifier) { var hudOn by remember { mutableStateOf(SessionPrefs.bottomHud(context)) } var onTabs by remember { mutableStateOf(SessionPrefs.bottomStripOnTabs(context)) } var shown by remember { mutableStateOf(SessionPrefs.bottomStripMetrics(context)) } - SettingsGroup(stringResource(R.string.bottom_hud_group)) { + SettingsGroup(stringResource(R.string.bottom_hud_group), key = "performance-bottom-hud") { ToggleRow(host, "bottom-hud", stringResource(R.string.bottom_hud_group), null, hudOn, chipModifier = track("bottom-hud")) { on -> hudOn = on diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt index 83f2e05436..bc8576b287 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrameGenMenu.kt @@ -1,52 +1,371 @@ package com.droiddeck.launcher.ui +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.withFrameNanos +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.input.InputMode +import androidx.compose.ui.platform.LocalInputModeManager +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import com.droiddeck.launcher.R import com.droiddeck.launcher.gpu.FrameGen import com.droiddeck.launcher.gpu.Lossless @Composable internal fun FrameGenMenu( - host: MenuHost, mode: FrameGen.Mode, lossless: Lossless.State, + mode: FrameGen.Mode, + lossless: Lossless.State, onPick: (FrameGen.Mode) -> Unit, - onImportLossless: () -> Unit, gameProfileId: String? = null, hasGameOverride: Boolean = false, onResetGame: () -> Unit = {}, + focusModifier: Modifier = Modifier, + legacyButtons: Boolean = false, + listLayout: Boolean = false, + sessionHost: MenuHost? = null, ) { + val sessionEngineAnchor = remember { FocusRequester() } + val need = stringResource(R.string.lsfg_needs_steam) + val selectedEngine = mode.engine.takeIf { it != FrameGen.ENGINE_OFF } + val offLabel = FrameGen.label(LocalContext.current, FrameGen.Mode.OFF) + val colors = MaterialTheme.colorScheme val context = LocalContext.current - AnchoredMenu(host.open == "fg", onDismiss = { if (host.open == "fg") host.open = null }, title = stringResource(R.string.frame_gen_title)) { firstItemFocus -> - val need = when { - lossless.ready -> null - lossless.owned -> stringResource(R.string.lsfg_needs_install) - else -> stringResource(R.string.lsfg_needs_steam) + var pacerEnabled by remember { mutableStateOf(FrameGen.pacerEnabled(context)) } + val engines = listOf(FrameGen.ENGINE_LSFG to "LSFG", FrameGen.ENGINE_DDFG to "DDFG", FrameGen.ENGINE_ZEROFG to "ZeroFG") + + if (legacyButtons) { + val context = LocalContext.current + val options = buildList { + add(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) + (2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_DDFG, it)) } + (2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_ZEROFG, it)) } + (2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_LSFG, it)) } + FrameGen.ADAPTIVE_TARGETS.forEach { add(FrameGen.Mode(FrameGen.ENGINE_LSFG, target = it)) } } - @Composable - fun item(m: FrameGen.Mode, enabled: Boolean = true, detail: String? = null, focus: FocusRequester? = null) = - MenuItem(FrameGen.label(context, m), checked = mode == m, enabled = enabled, detail = detail, focusRequester = focus) { - onPick(m); host.open = null + Column(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, bottom = 8.dp)) { + options.forEachIndexed { index, option -> + val selected = mode == option || + (option.engine == FrameGen.ENGINE_OFF && selectedEngine == null) + val enabled = option.engine != FrameGen.ENGINE_LSFG || lossless.ready || selected + val pick = { onPick(option) } + OutlinedButton( + onClick = pick, + enabled = enabled, + modifier = (if (index == 0) focusModifier else Modifier).fillMaxWidth() + .padding(top = if (index == 0) 0.dp else 6.dp) + .controllerConfirm(enabled = enabled, onClick = pick), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selected) colors.primary else colors.onSurface, + ), + ) { Text(FrameGen.label(context, option)) } } - item(FrameGen.Mode.OFF, focus = firstItemFocus) - if (gameProfileId != null) { - MenuItem(stringResource(R.string.comp_game_use_general), checked = !hasGameOverride) { + if (selectedEngine == FrameGen.ENGINE_LSFG && !lossless.ready) { + Text( + need, + color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(top = 6.dp), + ) + } + if (gameProfileId != null) { + val resetGame = onResetGame + OutlinedButton( + onClick = resetGame, + modifier = Modifier.fillMaxWidth().padding(top = 6.dp) + .controllerConfirm(onClick = resetGame), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + ) { + Text(stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓") + } + } + } + return + } + + Column(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, top = 0.dp, bottom = 8.dp)) { + if (sessionHost != null) { + SessionFrameGenEngine( + sessionHost, mode, listOf(FrameGen.ENGINE_OFF to offLabel) + engines, + lossless.ready, need, focusModifier, sessionEngineAnchor, onPick, + ) + } else { + OutlinedButton( + onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) }, + modifier = Modifier.fillMaxWidth().controllerConfirm( + onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) }, + ), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selectedEngine == null) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selectedEngine == null) colors.primary else colors.onSurface, + ), + ) { Text(offLabel) } + + if (listLayout) { + Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { + engines.forEach { (engine, label) -> + val selected = selectedEngine == engine + val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready + val pick = { + onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4))) + } + OutlinedButton( + onClick = pick, + enabled = enabled, + modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = enabled, onClick = pick), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selected) colors.primary else colors.onSurface, + ), + ) { Text(label) } + } + } + } else { + Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { + val focusIndex = engines.indexOfFirst { (engine, _) -> + selectedEngine == engine || engine != FrameGen.ENGINE_LSFG || lossless.ready + } + engines.forEachIndexed { index, (engine, label) -> + val selected = selectedEngine == engine + val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready + val pick = { + onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4))) + } + OutlinedButton( + onClick = pick, + enabled = enabled, + modifier = (if (index == focusIndex) focusModifier else Modifier) + .weight(1f).controllerConfirm(enabled = enabled, onClick = pick), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selected) colors.primary else colors.onSurface, + ), + ) { Text(label) } + } + } + } + } + + val multiplierEnabled = mode.engine != FrameGen.ENGINE_LSFG || lossless.ready + if (listLayout) { + Column( + Modifier.fillMaxWidth().padding(top = 8.dp), + verticalArrangement = Arrangement.spacedBy(6.dp), + ) { + (2..4).forEach { multiplier -> + val selected = mode.multiplier == multiplier && mode.target == 0 + val pickMultiplier = { onPick(mode.copy(multiplier = multiplier, target = 0)) } + OutlinedButton( + onClick = pickMultiplier, + enabled = multiplierEnabled, + modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier) + .frameGenFocus(sessionHost), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface, + contentColor = if (selected) colors.secondary else colors.onSurface, + ), + ) { Text("${multiplier}×") } + } + } + } else { + Row( + Modifier.fillMaxWidth().padding(top = 8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + (2..4).forEach { multiplier -> + val selected = mode.multiplier == multiplier && mode.target == 0 + val pickMultiplier = { onPick(mode.copy(multiplier = multiplier, target = 0)) } + OutlinedButton( + onClick = pickMultiplier, + enabled = multiplierEnabled, + modifier = Modifier.weight(1f).controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier) + .frameGenFocus(sessionHost), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface, + contentColor = if (selected) colors.secondary else colors.onSurface, + ), + ) { Text("${multiplier}×") } + } + } + } + + val togglePacer = { + val enabled = !pacerEnabled + FrameGen.setPacer(context, enabled) + pacerEnabled = enabled + } + OutlinedButton( + onClick = togglePacer, + modifier = Modifier.fillMaxWidth().padding(top = 8.dp) + .controllerConfirm(onClick = togglePacer).frameGenFocus(sessionHost), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (pacerEnabled) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (pacerEnabled) colors.primary else colors.onSurface, + ), + ) { + Text("ZeroPacer" + if (pacerEnabled) " ✓" else "") + } + + + if (selectedEngine == FrameGen.ENGINE_LSFG) { + Row( + Modifier.fillMaxWidth().padding(top = 8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + FrameGen.ADAPTIVE_TARGETS.forEach { target -> + val adaptiveMode = FrameGen.Mode(FrameGen.ENGINE_LSFG, target = target) + val selected = mode.target == target + val pickTarget = { onPick(adaptiveMode) } + OutlinedButton( + onClick = pickTarget, + enabled = lossless.ready, + modifier = Modifier.weight(1f).controllerConfirm( + enabled = lossless.ready, + onClick = pickTarget, + ).frameGenFocus(sessionHost), + contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface, + contentColor = if (selected) colors.secondary else colors.onSurface, + ), + ) { + Text(FrameGen.label(LocalContext.current, adaptiveMode)) + } + } + } + } + + if (sessionHost == null && selectedEngine == FrameGen.ENGINE_LSFG && !lossless.ready) { + Text(need, color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(top = 6.dp)) + } + + if (gameProfileId != null && (sessionHost == null || hasGameOverride)) { + val input = LocalInputModeManager.current + val resetGame = { + if (sessionHost != null && input.inputMode == InputMode.Keyboard) { + sessionEngineAnchor.requestFocus() + } onResetGame() - host.open = null } + OutlinedButton( + onClick = resetGame, + modifier = Modifier.fillMaxWidth().padding(top = 8.dp) + .testTag("framegen-use-global").controllerConfirm(onClick = resetGame) + .frameGenFocus(sessionHost), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + ) { + Text(if (sessionHost != null) stringResource(R.string.frame_gen_use_global) + else stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓") + } } - for (m in 2..4) item(FrameGen.Mode(FrameGen.ENGINE_DDFG, m)) - val lsfg = (2..4).map { FrameGen.Mode(FrameGen.ENGINE_LSFG, it) } + - FrameGen.ADAPTIVE_TARGETS.map { FrameGen.Mode(FrameGen.ENGINE_LSFG, target = it) } - lsfg.forEachIndexed { i, m -> item(m, enabled = lossless.ready, detail = need.takeIf { i == 0 }) } - if (lossless.owned) { - val using = when (lossless.source) { - Lossless.Source.STEAM -> stringResource(R.string.lsfg_using_steam) - Lossless.Source.IMPORT -> stringResource(R.string.lsfg_using_import) - Lossless.Source.NONE -> null + } +} + +@Composable +private fun Modifier.frameGenFocus(sessionHost: MenuHost?): Modifier = + if (sessionHost != null) focusGlide(RoundedCornerShape(percent = 50)) else this + +@Composable +private fun SessionFrameGenEngine( + host: MenuHost, + mode: FrameGen.Mode, + options: List>, + losslessReady: Boolean, + losslessNote: String, + focusModifier: Modifier, + anchor: FocusRequester, + onPick: (FrameGen.Mode) -> Unit, +) { + val label = stringResource(R.string.frame_gen_engine) + val selectedLabel = options.firstOrNull { (engine, _) -> engine == mode.engine }?.second + ?: options.first().second + val key = "frame-generation-engine" + val open = host.open == key + val input = LocalInputModeManager.current + var anchorFocused by remember { mutableStateOf(false) } + val selectedOption = remember { FocusRequester() } + var keyboardOpened by remember { mutableStateOf(false) } + val initial = options.firstOrNull { (engine, _) -> engine == mode.engine }?.first + ?: FrameGen.ENGINE_OFF + val close = { if (host.open == key) host.open = null } + + // Keep the options in the drawer's focus tree. A separate popup window can + // steal focus from the controller before Compose can focus the selected row. + LaunchedEffect(open) { + if (!keyboardOpened || (!open && host.open != null)) return@LaunchedEffect + val target = if (open) selectedOption else anchor + withFrameNanos { } + target.requestFocus() + if (!open) keyboardOpened = false + } + + val blockedSelection = !losslessReady && mode.engine == FrameGen.ENGINE_LSFG + SettingsRow(label, losslessNote.takeIf { blockedSelection && !open }, highlighted = open) { + ValueChip( + selectedLabel, open, + modifier = focusModifier.focusRequester(anchor).onFocusChanged { anchorFocused = it.isFocused } + .heightIn(min = 48.dp).testTag("setting-$key") + .semantics { contentDescription = label; stateDescription = selectedLabel }, + ) { + if (open) close() + else { + keyboardOpened = anchorFocused || input.inputMode == InputMode.Keyboard + host.open = key + } + } + } + if (open) { + Column(Modifier.fillMaxWidth().padding(horizontal = 8.dp).controllerBack(close)) { + options.forEach { (engine, text) -> + val selected = engine == mode.engine + val enabled = selected || engine != FrameGen.ENGINE_LSFG || losslessReady + MenuItem( + label = text, checked = selected, enabled = enabled, + detail = losslessNote.takeIf { engine == FrameGen.ENGINE_LSFG && !losslessReady }, + focusRequester = selectedOption.takeIf { engine == initial }, + modifier = Modifier.heightIn(min = 48.dp).testTag("framegen-engine:$engine"), + ) { + close() + if (!selected) { + onPick(if (engine == FrameGen.ENGINE_OFF) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) + else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4))) + } + } } - MenuItem(stringResource(R.string.lsfg_import), checked = false, detail = using) { host.open = null; onImportLossless() } } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt index bc55af594e..574ad4c56c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt @@ -272,7 +272,10 @@ private fun Content( return } if (selected == "steam") { - SteamHome(s, a, modifier) + Box(modifier) { + SteamHome(s, a, Modifier.fillMaxSize()) + SteamHomePreviewPill(Modifier.align(androidx.compose.ui.Alignment.BottomCenter).padding(bottom = 20.dp)) + } return } if (selected == "store") { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 4fea952f34..b7bf1caaa0 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -88,6 +88,7 @@ import com.droiddeck.launcher.input.SecondScreenDisplay import com.droiddeck.launcher.core.DownloadSource import com.droiddeck.launcher.core.PhantomProcessLimit import com.droiddeck.launcher.core.PhantomProcessStatus +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import kotlin.math.roundToInt import kotlinx.coroutines.withTimeoutOrNull @@ -176,7 +177,14 @@ class FrontEndState( val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, val launcherOrientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER, val homePage: String = com.droiddeck.launcher.core.AppUiPrefs.HOME_PAGE_STEAM, - val launcherFullscreen: Boolean = true, + val launcherFullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, + val sessionFullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, + val launcherFrost: Boolean = false, + val frostWallpaper: Boolean = true, + val frostCards: Boolean = true, + val frostTransparency: Int = FROST_WALLPAPER_DEFAULT, + val frostCardTransparency: Int = FROST_DEFAULT, + val frostSupported: Boolean = false, val controllerHaptics: Boolean = true, val downloadSource: String = DownloadSource.MODE_AUTO, val downloadMirror: String = "", @@ -240,7 +248,6 @@ class FrontEndActions( val onVkBridgeSafe: (Boolean) -> Unit = {}, val onBridgeProtonDxvk: (Boolean) -> Unit = {}, val onFrameGenPick: (FrameGen.Mode) -> Unit, - val onImportLossless: () -> Unit, val onProtons: () -> Unit, val onComponents: (focusContent: Boolean) -> Unit, val onGameComponents: (Library.SteamGame) -> Unit = { onComponents(true) }, @@ -271,7 +278,7 @@ class FrontEndActions( val onShareSessionLog: (File) -> Unit = {}, val onSaveSessionLog: (File) -> Unit = {}, val onDeleteSessionLog: (File, () -> Unit) -> Unit = { _, done -> done() }, - val onClearLogs: () -> Unit = {}, + val onClearLogs: (() -> Unit) -> Unit = {}, val onResetSettings: () -> Unit = {}, val onOffline: () -> Unit, val onOfflineAuto: () -> Unit = {}, @@ -283,7 +290,13 @@ class FrontEndActions( val onOrientation: (Int) -> Unit = {}, val onLauncherOrientation: (Int) -> Unit = {}, val onHomePage: (String) -> Unit = {}, - val onLauncherFullscreen: (Boolean) -> Unit = {}, + val onLauncherFullscreenMode: (FullscreenMode) -> Unit = {}, + val onSessionFullscreenMode: (FullscreenMode) -> Unit = {}, + val onLauncherFrost: (Boolean) -> Unit = {}, + val onFrostWallpaper: (Boolean) -> Unit = {}, + val onFrostCards: (Boolean) -> Unit = {}, + val onFrostTransparency: (Int) -> Unit = {}, + val onFrostCardTransparency: (Int) -> Unit = {}, val onControllerHaptics: (Boolean) -> Unit = {}, val onAnimationsEnabled: (Boolean) -> Unit = {}, val onLowStorageWarning: (Boolean) -> Unit = {}, @@ -446,6 +459,15 @@ internal suspend fun focusWithinFrames(done: () -> Boolean, target: () -> FocusR } } +internal suspend fun holdFocus(held: () -> Boolean, target: () -> FocusRequester?) { + val since = MainTabSteps.otherKeys + repeat(RAIL_HOLD_FRAMES) { frame -> + androidx.compose.runtime.withFrameNanos { } + if (MainTabSteps.otherKeys != since) return + if (frame == 0 || !held()) runCatching { target()?.requestFocus() } + } +} + internal suspend fun focusSoon(target: () -> FocusRequester) { repeat(30) { androidx.compose.runtime.withFrameNanos { } @@ -658,6 +680,11 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com LaunchedEffect(SetupTabs.openSection) { if (SetupTabs.openSection != null && (railSelection != "setup" || s.pageKey != null)) showRailPage("setup", true) } + LaunchedEffect(DevPreview.openSteam) { + if (!DevPreview.openSteam) return@LaunchedEffect + DevPreview.openSteam = false + showRailPage("steam", true) + } LaunchedEffect(DevPreview.openLibrary) { if (!DevPreview.openLibrary) return@LaunchedEffect DevPreview.openLibrary = false @@ -687,9 +714,12 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com if (anyFocused) return } } + val launcherFullscreen = s.launcherFullscreenMode.hidesSystemBars( + androidx.compose.ui.platform.LocalConfiguration.current.orientation, + ) androidx.compose.foundation.layout.BoxWithConstraints( - modifier = Modifier.fillMaxSize().background(colors.background) - .windowInsetsPadding(if (s.launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars) + modifier = Modifier.fillMaxSize().background(if (LocalFrost.current != null) Color.Transparent else colors.background) + .windowInsetsPadding(if (launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars) .onFocusChanged { anyFocused = it.hasFocus }, ) { val bottomNavigation = maxHeight > maxWidth @@ -770,10 +800,13 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com val stepScope = androidx.compose.runtime.rememberCoroutineScope() val pageKeyNow = androidx.compose.runtime.rememberUpdatedState(s.pageKey) var railHold by remember { mutableStateOf(null) } + val stepView = androidx.compose.ui.platform.LocalView.current val tabStep = androidx.compose.runtime.rememberUpdatedState { step: Int -> if (!processSettingsPageVisible) { val keys = navigationKeys(s) keys.getOrNull(keys.indexOf(railSelectionNow.value) + step)?.let { key -> + releaseFocusedTextField(stepView) + OpenMenus.leaveAll(withPage = true) PageSwipe.direction = step if (s.dualScreen) { onRailSelect(key); return@let } showRailPage(key, false) @@ -842,7 +875,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com com.droiddeck.launcher.stores.StoresState.pendingInstall?.let { item -> StoreTheme(item.store) { InstallWhere(item) } } com.droiddeck.launcher.stores.StoresState.itchPicking?.let { item -> StoreTheme(item.store) { ItchBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.itchPicking = null } } } com.droiddeck.launcher.stores.StoresState.gameJoltPicking?.let { item -> StoreTheme(item.store) { GameJoltBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.gameJoltPicking = null } } } - com.droiddeck.launcher.stores.steam.SteamStore.picking?.let { item -> StoreTheme(item.store) { SteamInstallWhereDialog(item) { com.droiddeck.launcher.stores.steam.SteamStore.picking = null } } } + com.droiddeck.launcher.stores.StoresState.steamPicking?.let { item -> StoreTheme(item.store) { SteamInstallWhereDialog(item) { com.droiddeck.launcher.stores.StoresState.steamPicking = null } } } StepsLayer(screenAt) UiZooSheet() SessionDrawerPreview(s.secondScreenDisplays) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index d804a4fa56..b2e989f568 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -1,6 +1,9 @@ package com.droiddeck.launcher.ui import androidx.compose.ui.platform.LocalContext +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.FocusRequester import android.os.Build @@ -50,6 +53,7 @@ import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -81,6 +85,7 @@ import com.droiddeck.launcher.core.DeviceSupport import com.droiddeck.launcher.core.DownloadSource import com.droiddeck.launcher.core.PhantomProcessLimit import com.droiddeck.launcher.core.PhantomProcessStatus +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.stores.download.StoreDownloadTier import com.droiddeck.launcher.R @@ -103,7 +108,7 @@ internal object SetupTabs { } @Composable -internal fun CheckRow(state: CheckState, title: String, detail: String?, divider: Boolean = true, action: (@Composable () -> Unit)? = null) { +internal fun CheckRow(state: CheckState, title: String, detail: String?, divider: Boolean = true, detailLines: Int = 2, action: (@Composable () -> Unit)? = null) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val tint = when (state) { @@ -135,7 +140,7 @@ internal fun CheckRow(state: CheckState, title: String, detail: String?, divider } Column(modifier = Modifier.weight(1f)) { Text(title, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - if (detail != null) Text(detail, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis) + if (detail != null) Text(detail, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = detailLines, overflow = TextOverflow.Ellipsis) } if (action != null) action() } @@ -152,6 +157,20 @@ internal fun SetupPanel( ) { val host = rememberMenuHost() val ctx = LocalContext.current + val frostRow = s.frostSupported && s.theme != Themes.TRUE_BLACK + var steamOrientation by remember { mutableStateOf(SessionPrefs.orientation(ctx, "steam")) } + var desktopOrientation by remember { mutableStateOf(SessionPrefs.orientation(ctx, "desktop")) } + val lifecycleOwner = LocalLifecycleOwner.current + DisposableEffect(lifecycleOwner, ctx) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) { + steamOrientation = SessionPrefs.orientation(ctx, "steam") + desktopOrientation = SessionPrefs.orientation(ctx, "desktop") + } + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { lifecycleOwner.lifecycle.removeObserver(observer) } + } var hideHomeFromRecents by remember { mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.hideHomeFromRecents(ctx)) } var processLimitBusy by remember { mutableStateOf(false) } var processLimitMessage by remember { mutableStateOf(null) } @@ -251,7 +270,7 @@ internal fun SetupPanel( val listing = searching && query.isNotBlank() val fixed = tab == CONTROLLER_TAB && !listing Column(modifier = Modifier.weight(1f).fillMaxWidth().then(if (fixed) Modifier else Modifier.verticalScroll(rememberScrollState())).padding(bottom = if (fixed) 0.dp else 24.dp)) { - if (listing) SettingsSearchResults(query) { section -> pick(section.ordinal) } + if (listing) SettingsSearchResults(query, frostRow) { section -> pick(section.ordinal) } else when (tab) { OVERVIEW_TAB -> { OnboardingCard(limitBlocks, a.onShowPhantomGate) @@ -398,7 +417,8 @@ internal fun SetupPanel( listOfNotNull( gpu.displayName(ctx), s.installed?.let { stringResource(R.string.setup_ready_runtime, it) }, - stringResource(R.string.setup_ready_limit_off).takeIf { !limitBlocks }, + stringResource(R.string.setup_ready_limit_off) + .takeIf { !limitBlocks && s.phantomProcessStatus != PhantomProcessStatus.UNCOUNTED }, s.offlineAccount?.takeIf { it.isNotEmpty() }?.let { stringResource(R.string.setup_ready_signed_in, it) }, ).joinToString(" · "), open = showChecks, onDetails = { showChecks = !showChecks }, @@ -447,6 +467,35 @@ internal fun SetupPanel( if (s.theme == Themes.GRADIENT) GradientColorRows() if (s.theme == Themes.CUSTOM) CustomColorRows() if (s.theme == Themes.TRUE_BLACK) HighlightColorRow() + if (frostRow) { + ToggleRow( + host, "launcher-frost", stringResource(R.string.setup_frosted_background), + stringResource(R.string.setup_frosted_background_hint), s.launcherFrost, onChange = a.onLauncherFrost, + ) + if (s.launcherFrost) { + val ctx = androidx.compose.ui.platform.LocalContext.current + val percent: (Int) -> String = { ctx.getString(R.string.ctrl_percent, it) } + ToggleRow( + host, "launcher-frost-wallpaper", stringResource(R.string.setup_frosted_wallpaper), null, + s.frostWallpaper, onChange = a.onFrostWallpaper, + ) + SliderRow( + stringResource(R.string.setup_frost_transparency), stringResource(R.string.setup_frost_transparency_hint), + s.frostTransparency, 0..FROST_MAX, step = FROST_STEP, enabled = s.frostWallpaper, format = percent, + onChange = a.onFrostTransparency, + ) + ToggleRow( + host, "launcher-frost-cards", stringResource(R.string.setup_frosted_cards), + stringResource(if (s.frostWallpaper) R.string.setup_frosted_cards_hint else R.string.setup_frosted_cards_needs_wallpaper), + s.frostCards, enabled = s.frostWallpaper, onChange = a.onFrostCards, + ) + SliderRow( + stringResource(R.string.setup_frost_card_transparency), stringResource(R.string.setup_frost_card_transparency_hint), + s.frostCardTransparency, 0..FROST_MAX, step = FROST_STEP, enabled = s.frostWallpaper && s.frostCards, format = percent, + onChange = a.onFrostCardTransparency, + ) + } + } ChoiceRow( host, "app-scale", stringResource(R.string.setup_app_scale), stringResource(R.string.setup_app_scale_hint), com.droiddeck.launcher.core.AppUiPrefs.scales.map { percent -> @@ -516,13 +565,39 @@ internal fun SetupPanel( ChoiceRow( host, "orientation", stringResource(R.string.setup_session_orientation), stringResource(R.string.setup_session_orientation_hint), SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) }, - s.orientation, onPick = a.onOrientation, + s.orientation, onPick = { value -> + a.onOrientation(value) + steamOrientation = SessionPrefs.orientation(ctx, "steam") + desktopOrientation = SessionPrefs.orientation(ctx, "desktop") + }, + ) + ChoiceRow( + host, "orientation-steam", stringResource(R.string.setup_session_orientation) + " (Steam)", stringResource(R.string.setup_session_orientation_hint), + SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) }, + steamOrientation, onPick = { value -> + steamOrientation = value + SessionPrefs.setOrientation(ctx, "steam", value) + }, + ) + ChoiceRow( + host, "orientation-desktop", stringResource(R.string.setup_session_orientation) + " (Desktop)", stringResource(R.string.setup_session_orientation_hint), + SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) }, + desktopOrientation, onPick = { value -> + desktopOrientation = value + SessionPrefs.setOrientation(ctx, "desktop", value) + }, + ) + val fullscreenModes = FullscreenMode.entries.map { it to stringResource(it.label) } + ChoiceRow( + host, "launcher-fullscreen", stringResource(R.string.setup_launcher_fullscreen), + stringResource(R.string.setup_fullscreen_on), + fullscreenModes, s.launcherFullscreenMode, onPick = a.onLauncherFullscreenMode, + ) + ChoiceRow( + host, "session-fullscreen", stringResource(R.string.setup_session_fullscreen), + stringResource(R.string.setup_fullscreen_on), + fullscreenModes, s.sessionFullscreenMode, onPick = a.onSessionFullscreenMode, ) - ToggleRow( - host, "launcher-fullscreen", stringResource(R.string.setup_fullscreen), - if (s.launcherFullscreen) stringResource(R.string.setup_fullscreen_on) else stringResource(R.string.setup_fullscreen_off), - s.launcherFullscreen, - ) { a.onLauncherFullscreen(it) } ToggleRow( host, "page-swipe", stringResource(R.string.setup_page_swipe), stringResource(R.string.setup_page_swipe_hint), PageSwipe.on, @@ -610,89 +685,102 @@ internal fun SetupPanel( } } DEVELOPER_TAB -> { - val devContext = LocalContext.current + var manageLogs by rememberSaveable { mutableStateOf(false) } SettingsGroup(stringResource(R.string.dev_tools_title)) { - ToggleRow(host, "developer-tools", stringResource(R.string.dev_tools_title), stringResource(R.string.dev_tools_hint), DeveloperTools.on) { - DeveloperTools.set(devContext, it) + ToggleRow(host, "developer-tools", stringResource(R.string.dev_tools_show), stringResource(R.string.dev_tools_hint), DeveloperTools.on, sideBySide = true) { + DeveloperTools.set(ctx, it) + } + if (DeveloperTools.on) ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), stringResource(R.string.setup_agent_commands_hint), s.agentCommands, sideBySide = true) { a.onAgentCommands() } + if (DeveloperTools.on && com.droiddeck.launcher.agent.AgentHost.available) { + ToggleRow(host, "agent-pet", stringResource(R.string.rail_agent), stringResource(R.string.dev_harness_overlay_hint), AgentPet.enabled, sideBySide = true) { + AgentPet.set(ctx, it) + } + if (AgentPet.enabled && !AgentPet.allowed && AgentPet.usesOverlayWindows(com.droiddeck.launcher.session.QuestExperimental.isSupported())) ActionRow( + stringResource(R.string.setup_agent_pet_float), stringResource(R.string.setup_agent_pet_float_hint), + stringResource(R.string.setup_agent_pet_allow), onClick = { AgentPet.requestFloating(ctx) }, sideBySide = true, + ) } - if (DeveloperTools.on) ActionRow( - stringResource(R.string.dev_ui_zoo), stringResource(R.string.dev_ui_zoo_hint), stringResource(R.string.dev_ui_zoo_open), - onClick = { DevPreview.zoo = true }, modifier = Modifier.testTag("dev-ui-zoo"), - ) - if (DeveloperTools.on) ToggleRow( - host, "preview-shortcuts", stringResource(R.string.dev_preview_shortcuts), stringResource(R.string.dev_preview_shortcuts_hint), - DevPreview.shortcuts, - ) { DevPreview.setShortcuts(devContext, it) } } - SettingsGroup(stringResource(R.string.dev_group_logs)) { - ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled) { a.onLogs() } + if (DeveloperTools.on) SettingsGroup(stringResource(R.string.dev_group_previews)) { + ActionRow( + stringResource(R.string.dev_ui_zoo), stringResource(R.string.dev_ui_zoo_hint), stringResource(R.string.dev_ui_zoo_open), + onClick = { DevPreview.zoo = true }, modifier = Modifier.testTag("dev-ui-zoo"), sideBySide = true, + ) + ToggleRow( + host, "preview-shortcuts", stringResource(R.string.dev_preview_shortcuts), stringResource(R.string.dev_preview_shortcuts_hint), + DevPreview.shortcuts, sideBySide = true, + ) { DevPreview.setShortcuts(ctx, it) } + } + SettingsGroup(stringResource(R.string.dev_group_diagnostics)) { + ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled, sideBySide = true) { a.onLogs() } if (DeveloperTools.on) ToggleRow( host, "enhanced-diagnostics", stringResource(R.string.setup_enhanced_diagnostics), - stringResource(R.string.setup_enhanced_diagnostics_hint), s.enhancedDiagnosticsArmed, + stringResource(R.string.setup_enhanced_diagnostics_hint), s.enhancedDiagnosticsArmed, sideBySide = true, ) { a.onEnhancedDiagnostics() } ToggleRow( host, "game-debug-logs", stringResource(R.string.setup_game_debug_logs), stringResource(if (s.gameDebugLogsNeedsRestart) R.string.setup_game_debug_logs_restart else R.string.setup_game_debug_logs_hint), s.gameDebugLogsEnabled, - enabled = s.logsEnabled, + enabled = s.logsEnabled, sideBySide = true, ) { a.onGameDebugLogs() } - if (DeveloperTools.on) ToggleRow(host, "vacdiag", stringResource(R.string.setup_vac_diag), stringResource(R.string.setup_vac_diag_hint), s.vacDiagnostics) { a.onVacDiagnostics() } - if (DeveloperTools.on) ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), null, s.agentCommands) { a.onAgentCommands() } - if (DeveloperTools.on && com.droiddeck.launcher.agent.AgentHost.available) { - val agentContext = androidx.compose.ui.platform.LocalContext.current - ToggleRow(host, "agent-pet", stringResource(R.string.setup_agent_pet), stringResource(R.string.setup_agent_pet_hint), AgentPet.enabled) { - AgentPet.set(agentContext, it) - } - if (AgentPet.enabled && !AgentPet.allowed) ActionRow( - stringResource(R.string.setup_agent_pet_float), stringResource(R.string.setup_agent_pet_float_hint), - stringResource(R.string.setup_agent_pet_allow), onClick = { AgentPet.requestFloating(agentContext) }, - ) - } - if (DeveloperTools.on) ToggleRow(host, "graphics-logs", stringResource(R.string.setup_graphics_logs), stringResource(R.string.setup_graphics_logs_hint), s.graphicsLogs) { a.onGraphicsLogs() } - if (DeveloperTools.on && !s.adreno && com.droiddeck.launcher.session.SessionPrefs.steamGpuCompositingAllowed()) ToggleRow(host, "steam-gpu-drawing", stringResource(R.string.setup_steam_gpu_drawing), stringResource(R.string.setup_steam_gpu_drawing_hint), s.steamGpuDrawing) { a.onSteamGpuDrawing() } + if (DeveloperTools.on) ToggleRow(host, "vacdiag", stringResource(R.string.setup_vac_diag), stringResource(R.string.setup_vac_diag_hint), s.vacDiagnostics, sideBySide = true) { a.onVacDiagnostics() } + if (DeveloperTools.on) ToggleRow(host, "graphics-logs", stringResource(R.string.setup_graphics_logs), stringResource(R.string.setup_graphics_logs_hint), s.graphicsLogs, sideBySide = true) { a.onGraphicsLogs() } + if (DeveloperTools.on && !s.adreno && com.droiddeck.launcher.session.SessionPrefs.steamGpuCompositingAllowed()) ToggleRow(host, "steam-gpu-drawing", stringResource(R.string.setup_steam_gpu_drawing), stringResource(R.string.setup_steam_gpu_drawing_hint), s.steamGpuDrawing, sideBySide = true) { a.onSteamGpuDrawing() } + } + SettingsGroup(stringResource(R.string.dev_group_log_files)) { ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs, - progress = com.droiddeck.launcher.session.SessionLogShare.progress) - androidx.compose.material3.HorizontalDivider() - Text(stringResource(R.string.setup_log_sessions), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, - color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) - Text(stringResource(R.string.setup_log_export_hint), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.padding(start = 14.dp, end = 14.dp, bottom = 8.dp)) - val sessionLogs = remember(ctx, logsRefresh) { com.droiddeck.launcher.session.SessionLogShare.sessions(ctx).asReversed() } - if (sessionLogs.isEmpty()) { - Text(stringResource(R.string.setup_log_empty), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) - } - sessionLogs.forEach { folder -> - val active = folder == com.droiddeck.launcher.session.SessionPaths.current() - var details by remember(folder) { mutableStateOf(null) } - LaunchedEffect(folder, logsRefresh) { - details = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { - com.droiddeck.launcher.session.SessionLogShare.details(folder) - } + progress = com.droiddeck.launcher.session.SessionLogShare.progress, sideBySide = true) + ActionRow( + stringResource(R.string.setup_saved_logs), stringResource(R.string.dev_log_manage_hint), + stringResource(if (manageLogs) R.string.common_close else R.string.setup_manage), + onClick = { manageLogs = !manageLogs }, sideBySide = true, + ) + if (manageLogs) { + Text(stringResource(R.string.setup_log_sessions), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) + Text(stringResource(R.string.setup_log_export_hint), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(start = 14.dp, end = 14.dp, bottom = 8.dp)) + val sessionLogs = remember(ctx, logsRefresh) { com.droiddeck.launcher.session.SessionLogShare.sessions(ctx).asReversed() } + if (sessionLogs.isEmpty()) { + Text(stringResource(R.string.setup_log_empty), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) } - Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp)) { - Text(folder.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, - maxLines = 1, overflow = TextOverflow.Ellipsis) - details?.let { detail -> - Text( - stringResource(R.string.setup_log_size_date, - android.text.format.Formatter.formatShortFileSize(ctx, detail.sizeBytes), - "${android.text.format.DateFormat.getDateFormat(ctx).format(java.util.Date(detail.modifiedAt))} ${android.text.format.DateFormat.getTimeFormat(ctx).format(java.util.Date(detail.modifiedAt))}"), - fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + sessionLogs.forEach { folder -> + val active = folder == com.droiddeck.launcher.session.SessionPaths.current() + var details by remember(folder) { mutableStateOf(null) } + LaunchedEffect(folder, logsRefresh) { + details = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { + com.droiddeck.launcher.session.SessionLogShare.details(folder) + } } - if (active) Text(stringResource(R.string.setup_log_current), fontSize = 12.sp, color = MaterialTheme.colorScheme.primary) - Row(Modifier.fillMaxWidth().padding(top = 6.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { - SecondaryButton(stringResource(R.string.setup_log_share), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onShareSessionLog(folder) } - SecondaryButton(stringResource(R.string.setup_log_save), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onSaveSessionLog(folder) } - SecondaryButton(stringResource(R.string.setup_log_delete), compact = true, enabled = !active, modifier = Modifier.weight(1f)) { deleteSessionLogs = folder } + Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp)) { + Text(folder.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, + maxLines = 1, overflow = TextOverflow.Ellipsis) + details?.let { detail -> + Text( + stringResource(R.string.setup_log_size_date, + android.text.format.Formatter.formatShortFileSize(ctx, detail.sizeBytes), + "${android.text.format.DateFormat.getDateFormat(ctx).format(java.util.Date(detail.modifiedAt))} ${android.text.format.DateFormat.getTimeFormat(ctx).format(java.util.Date(detail.modifiedAt))}"), + fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + if (active) Text(stringResource(R.string.setup_log_current), fontSize = 12.sp, color = MaterialTheme.colorScheme.primary) + Row(Modifier.fillMaxWidth().padding(top = 6.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { + SecondaryButton(stringResource(R.string.setup_log_share), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onShareSessionLog(folder) } + SecondaryButton(stringResource(R.string.setup_log_save), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onSaveSessionLog(folder) } + SecondaryButton(stringResource(R.string.setup_log_delete), compact = true, enabled = !active, modifier = Modifier.weight(1f)) { deleteSessionLogs = folder } + } } + androidx.compose.material3.HorizontalDivider() } - androidx.compose.material3.HorizontalDivider() + ActionRow(stringResource(R.string.setup_saved_logs_hint, com.droiddeck.launcher.session.SessionPaths.KEEP_SESSIONS), + null, stringResource(R.string.setup_clear_logs), + onClick = { a.onClearLogs { logsRefresh++ } }, sideBySide = true) } - ActionRow(stringResource(R.string.setup_saved_logs), stringResource(R.string.setup_saved_logs_hint, com.droiddeck.launcher.session.SessionPaths.KEEP_SESSIONS), stringResource(R.string.setup_clear_logs), a.onClearLogs) + } + SettingsGroup(stringResource(R.string.dev_group_reset)) { ActionRow(stringResource(R.string.setup_reset_settings), stringResource(R.string.setup_reset_settings_hint), - stringResource(R.string.setup_reset_settings_button), a.onResetSettings) + stringResource(R.string.setup_reset_settings_button), a.onResetSettings, sideBySide = true) } } GLASSES_TAB -> GlassesSetupPanel() @@ -792,7 +880,7 @@ internal fun ReadinessCard( @Composable private fun FrameGenMenu(s: FrontEndState, a: FrontEndActions, host: MenuHost) { - FrameGenMenu(host, s.frameGen, s.lossless, a.onFrameGenPick, a.onImportLossless) + FrameGenMenu(s.frameGen, s.lossless, a.onFrameGenPick, legacyButtons = true) } @Composable @@ -813,12 +901,80 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost com.droiddeck.launcher.gpu.FrameGen.hasGameOverride(context, it) } ?: false) } + val scalingFilterChoices = SessionPrefs.upscalerChoices(context) + var gameUpscaler by remember(frameGenProfileKey) { + mutableStateOf(frameGenProfileKey?.let { + SessionPrefs.screenEffectsUpscaler(context, "game:$it") + } ?: SessionPrefs.upscaler(context)) + } + var gameUpscalerOverride by remember(frameGenProfileKey) { + mutableStateOf(frameGenProfileKey?.let { SessionPrefs.hasGameUpscalerOverride(context, it) } ?: false) + } + val lifecycleOwner = LocalLifecycleOwner.current + DisposableEffect(lifecycleOwner, frameGenProfileKey) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) { + frameGenProfileKey?.let { key -> + gameUpscaler = SessionPrefs.screenEffectsUpscaler(context, "game:$key") + gameUpscalerOverride = SessionPrefs.hasGameUpscalerOverride(context, key) + } + } + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { lifecycleOwner.lifecycle.removeObserver(observer) } + } var wincompOpen by remember(wincompKey) { mutableStateOf(null) } val wincompPicks = remember(wincompKey, wincompOpen) { wincompKey?.let { com.droiddeck.launcher.session.WinComponents.picks(context, it) }.orEmpty() } val steamScope = game?.let { com.droiddeck.launcher.session.NoSteamLaunch.scope(it) } val steamCard: (@Composable (Modifier) -> Unit)? = if (game != null && steamScope != null) { m -> Box(m) { GameSettingsCard(host, game, steamScope) } } else null + val frameGenMenuContent: @Composable () -> Unit = { + FrameGenMenu( + mode = if (frameGenProfileKey != null) gameFrameGenMode else s.frameGen, + lossless = s.lossless, + onPick = { mode -> + val key = frameGenProfileKey + if (key == null) { + a.onFrameGenPick(mode) + } else { + com.droiddeck.launcher.gpu.FrameGen.setForGame(context, key, mode) + gameFrameGenMode = mode + gameFrameGenOverride = true + } + }, + legacyButtons = true, + gameProfileId = frameGenProfileKey, + hasGameOverride = gameFrameGenOverride, + onResetGame = { + val key = frameGenProfileKey + if (key != null) { + com.droiddeck.launcher.gpu.FrameGen.clearGame(context, key) + gameFrameGenMode = com.droiddeck.launcher.gpu.FrameGen.mode(context) + gameFrameGenOverride = false + } + }, + ) + } + val scalingFilterMenuContent: @Composable () -> Unit = { + val key = frameGenProfileKey + if (key != null) ScalingFilterMenu( + mode = gameUpscaler, + options = scalingFilterChoices, + hasGameOverride = gameUpscalerOverride, + onPick = { mode -> + SessionPrefs.setGameUpscaler(context, key, mode) + gameUpscaler = SessionPrefs.screenEffectsUpscaler(context, "game:$key") + gameUpscalerOverride = SessionPrefs.hasGameUpscalerOverride(context, key) + }, + onResetGame = { + SessionPrefs.clearGameUpscaler(context, key) + gameUpscaler = SessionPrefs.upscaler(context) + gameUpscalerOverride = false + }, + gameName = game?.name, + ) + } val cards = if (game?.library == com.droiddeck.launcher.frontend.Library.EPIC_LAUNCHER) listOfNotNull(steamCard) else buildList<@Composable (Modifier) -> Unit> { add { m -> val back = stringResource(R.string.hop_from_games) @@ -840,33 +996,18 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost ) { host.open = if (host.open == "fg") null else "fg" } - FrameGenMenu( - host = host, - mode = if (frameGenProfileKey != null) gameFrameGenMode else s.frameGen, - lossless = s.lossless, - onPick = { mode -> - val key = frameGenProfileKey - if (key == null) { - a.onFrameGenPick(mode) - } else { - com.droiddeck.launcher.gpu.FrameGen.setForGame(context, key, mode) - gameFrameGenMode = mode - gameFrameGenOverride = true - } - }, - onImportLossless = a.onImportLossless, - gameProfileId = frameGenProfileKey, - hasGameOverride = gameFrameGenOverride, - onResetGame = { - val key = frameGenProfileKey - if (key != null) { - com.droiddeck.launcher.gpu.FrameGen.clearGame(context, key) - gameFrameGenMode = - com.droiddeck.launcher.gpu.FrameGen.mode(context) - gameFrameGenOverride = false - } - } - ) + + } + } + if (frameGenProfileKey != null) add { m -> + Box(m) { + SettingCard( + stringResource(R.string.display_filter), + scalingFilterChoices.firstOrNull { it.first == gameUpscaler }?.second ?: scalingFilterChoices.first().second, + "card:scaling-filter", Modifier.fillMaxSize(), + ) { + host.open = if (host.open == "scaling-filter") null else "scaling-filter" + } } } if (controller != null) add { m -> SettingCard(stringResource(R.string.setup_card_controls), stringResource(R.string.setup_card_controls_hint), "card:controls", m, controller.onMapping) } @@ -898,6 +1039,16 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost repeat(columns - row.size) { Spacer(Modifier.weight(1f)) } } } + if (host.open == "fg") { + Box(Modifier.fillMaxWidth().padding(top = 4.dp)) { + frameGenMenuContent() + } + } + if (host.open == "scaling-filter") { + Box(Modifier.fillMaxWidth().padding(top = 4.dp)) { + scalingFilterMenuContent() + } + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt index 4245236747..adfa9eebcd 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt @@ -308,7 +308,8 @@ internal fun SecondaryButton(text: String, enabled: Boolean = true, compact: Boo Box( contentAlignment = Alignment.Center, modifier = modifier.paneItem("btn:$text").downToFirstTile().heightIn(min = if (pill) 40.dp else if (compact) 44.dp else 48.dp).graphicsLayer { scaleX = scale; scaleY = scale }.clip(shape).background(fill).glideBorder(hot, shape, pal.signal, if (pill) Color.White.copy(alpha = 0.14f) else pal.line2) - .alpha(if (enabled) 1f else 0.5f) + // The label always gets a layer of its own: sharing one with the fill and outline, they did not draw under the agent's latest reply. + .graphicsLayer { alpha = if (enabled) 1f else 0.5f } .hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) .controllerConfirm(enabled = enabled, onClick = onClick) .padding(horizontal = if (pill) 16.dp else if (compact) 10.dp else 16.dp, vertical = if (pill) 8.dp else if (compact) 7.dp else 11.dp), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index 5e47621be9..5415293cfb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -96,6 +96,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.AsyncImage import com.droiddeck.launcher.R +import com.droiddeck.launcher.frontend.AddedGameEdits import com.droiddeck.launcher.frontend.GameRemoval import com.droiddeck.launcher.frontend.Library import com.droiddeck.launcher.runtime.CurseForgeApp @@ -104,6 +105,7 @@ import com.droiddeck.launcher.runtime.WowAddonCatalog import com.droiddeck.launcher.runtime.WowAddons import com.droiddeck.launcher.store.UserAppsState import com.droiddeck.launcher.session.GameSaves +import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.SessionState import com.droiddeck.launcher.stores.CatalogItem import com.droiddeck.launcher.stores.CloudSaves @@ -233,7 +235,7 @@ internal fun GameDetail( steppedTo = null return@LaunchedEffect } - focusSoon { tabFocus.getValue(t) } + holdFocus({ onStrip }) { tabFocus.getValue(t) } steppedTo = null } fun cycle(step: Int) { @@ -241,7 +243,7 @@ internal fun GameDetail( val at = tabs.indexOf(tab).coerceAtLeast(0) val next = tabs[(at + step + tabs.size) % tabs.size] picked = next - if (inPage) steppedTo = next + steppedTo = next } val art: Any? = game?.hero ?: item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover val artModel: Any? = if (art is String) cardArtRequest(art, item?.tallImageUrl) else art @@ -394,7 +396,7 @@ private fun GameCapsule(scores: GameScores?, actions: @Composable () -> Unit) { } @Composable -private fun GameTabBar( +internal fun GameTabBar( tabs: List, selected: Int, onSelect: (Int) -> Unit, modifier: Modifier = Modifier, focusRequesters: List? = null, bumpers: Boolean = true, compact: Boolean = false, @@ -1001,6 +1003,25 @@ private fun LaunchTab(game: Library.SteamGame, s: FrontEndState, a: FrontEndActi } val folder = game.gameFiles if (game.library == Library.ADDED && game.source == Library.ADDED && !s.shortcutPicker && folder != null) ShortcutFields(game, folder) + if (game.library == Library.ADDED && Store.byId(game.source) == Store.EA && folder != null) StoreLaunchOptions(folder, a) + } +} + +@Composable +private fun StoreLaunchOptions(folder: File, a: FrontEndActions) { + val app = LocalContext.current.applicationContext + val scope = rememberCoroutineScope() + var saved by remember(folder.path) { mutableStateOf(SessionPrefs.addedGameLaunch(app, folder.path)) } + var editing by remember(folder.path) { mutableStateOf(false) } + Column(Modifier.fillMaxWidth().tabPanel()) { + MenuItem(stringResource(R.string.edit_launch_options), checked = false, detail = saved.ifEmpty { "—" }) { editing = true } + } + if (editing) TextEntryDialog(stringResource(R.string.edit_launch_options), saved, onDismiss = { editing = false }) { value -> + scope.launch { + withContext(Dispatchers.IO) { AddedGameEdits.setLaunchOptions(app, folder.path, value) } + saved = value + a.onAddedGamesChanged(listOf(folder.path)) + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GlassesPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/GlassesPanel.kt index 877cad9240..ba44249ca9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GlassesPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GlassesPanel.kt @@ -23,6 +23,9 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.draw.clip @@ -31,6 +34,7 @@ import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.sp import androidx.compose.runtime.getValue +import com.droiddeck.launcher.session.SessionPrefs import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor @@ -67,6 +71,21 @@ internal val GlassesIcon: ImageVector by lazy { }.build() } +@Composable +internal fun rememberShowGlassesShortcut(): Boolean { + val context = LocalContext.current + var show by remember(context) { mutableStateOf(SessionPrefs.showGlassesShortcut(context)) } + DisposableEffect(context) { + val preferences = context.getSharedPreferences("session", android.content.Context.MODE_PRIVATE) + val listener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key -> + if (key == "showGlassesShortcut") show = SessionPrefs.showGlassesShortcut(context) + } + preferences.registerOnSharedPreferenceChangeListener(listener) + onDispose { preferences.unregisterOnSharedPreferenceChangeListener(listener) } + } + return show +} + @Composable internal fun rememberGlasses(): Pair { val g by Glasses.state.collectAsState() @@ -88,7 +107,7 @@ internal fun VrControllerGroups(host: MenuHost, track: (String) -> Modifier = { androidx.compose.runtime.LaunchedEffect(Unit) { com.droiddeck.launcher.input.VrControllers.load(context) } val c by com.droiddeck.launcher.input.VrControllers.settings.collectAsState() val emulate = com.droiddeck.launcher.input.VrControllers.Emulate.entries - SettingsGroup(stringResource(R.string.vr_controllers_group)) { + SettingsGroup(stringResource(R.string.vr_controllers_group), key = "vr-controllers") { ChoiceRow(host, "vr-emulate", stringResource(R.string.vr_controllers_emulate), stringResource(R.string.vr_controllers_emulate_hint), emulate.map { it to stringResource(when (it) { com.droiddeck.launcher.input.VrControllers.Emulate.OFF -> R.string.vr_controllers_off @@ -133,6 +152,7 @@ internal fun GlassesGroups( ) { val display = tab == null || tab == GlassesTab.DISPLAY val vr = tab == null || tab == GlassesTab.VR + val showShortcut = rememberShowGlassesShortcut() val picture = GlassesRendering.picture(s, g.sbs, steamVrRunning) val usesGlasses = GlassesRendering.usesGlasses(g, outputActive, steamVrRunning) val spatialTracking = g.spatialConnected && s.positionalTracking @@ -142,13 +162,13 @@ internal fun GlassesGroups( val directView = usesGlasses && picture == GlassesRendering.Picture.STEREO val menuScreen = !inSession && g.usable && s.gameOnGlasses && s.screen3dof if (g.canControl && onRecenter != null && s.headTracking && (virtualScreen || menuScreen || (directView && steamVrRunning))) { - SettingsGroup(stringResource(R.string.glasses_quick_actions), compact = true) { + SettingsGroup(stringResource(R.string.glasses_quick_actions), compact = true, key = "vr-glasses-quick") { ActionRow(stringResource(R.string.glasses_recenter), if (virtualScreen || menuScreen) stringResource(R.string.glasses_recenter_screen_hint) else null, stringResource(R.string.cardboard_recenter_button), onRecenter) } } - if (display) SettingsGroup(g.model) { + if (display) SettingsGroup(g.model, key = "vr-glasses") { if (g.experimental) SettingsRow(stringResource(R.string.glasses_control), stringResource( if (g.supportsDisplayModeControl) R.string.glasses_xreal_experimental else R.string.glasses_pro2_experimental)) {} val status = if (g.hasDisplay) stringResource(R.string.glasses_status, g.width, g.height, kotlin.math.round(g.hz).toInt(), @@ -168,9 +188,15 @@ internal fun GlassesGroups( } ToggleRow(host, "glasses-game", stringResource(R.string.glasses_game_on), stringResource(R.string.glasses_game_on_hint), s.gameOnGlasses, chipModifier = track("glasses-game")) { Glasses.setGameOnGlasses(it) } + if (inSession) { + val context = androidx.compose.ui.platform.LocalContext.current + ToggleRow(host, "glasses-shortcut", stringResource(R.string.glasses_show_shortcut), + stringResource(R.string.glasses_show_shortcut_hint), showShortcut, + chipModifier = track("glasses-shortcut")) { SessionPrefs.setShowGlassesShortcut(context, it) } + } } if (display && g.canControl && g.supportsDisplayModeControl && (inSession || g.sbs || g.sbsSupport == GlassesState.SBS_FAILS)) { - SettingsGroup(stringResource(R.string.glasses_display_mode)) { + SettingsGroup(stringResource(R.string.glasses_display_mode), key = "vr-glasses-mode") { if (g.sbsSupport == GlassesState.SBS_FAILS && !g.sbs) { ActionRow(stringResource(R.string.glasses_3d), stringResource(R.string.glasses_3d_failed), stringResource(R.string.stores_dl_retry), { Glasses.set3d(true) }) @@ -182,12 +208,12 @@ internal fun GlassesGroups( val profiles = if (inSession) listOf(GlassesDisplayModes.profile(g.sbs, false)) else listOf(GlassesDisplayProfile.TWO_D, GlassesDisplayProfile.THREE_D) for (profile in profiles) SettingsGroup(stringResource(if (profile == GlassesDisplayProfile.TWO_D) - R.string.glasses_output_2d else R.string.glasses_output_3d)) { + R.string.glasses_output_2d else R.string.glasses_output_3d), key = "vr-glasses-output-${profile.name.lowercase()}") { GlassesResolutionRow(host, g, s, profile, track) if ((profile == GlassesDisplayProfile.THREE_D) == g.sbs) GlassesRefreshRow(host, g, s, track) } } - if (display && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.glasses_picture_group)) { + if (display && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.glasses_picture_group), key = "vr-glasses-picture") { ChoiceRow(host, "glasses-picture", stringResource(R.string.glasses_picture), stringResource(R.string.glasses_picture_hint), listOf( GlassesSettings.PICTURE_AUTO to stringResource(R.string.glasses_picture_auto), @@ -213,7 +239,7 @@ internal fun GlassesGroups( format = { SpatialMeasurements.distance(it / 10f) }, modifier = track("glasses-distance")) { Glasses.setScreenDistanceDm(it) } } } - if (vr && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.cardboard_steamvr)) { + if (vr && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.cardboard_steamvr), key = "vr-glasses-steamvr") { steamVr() if (g.supportsDisplayModeControl) ToggleRow(host, "glasses-auto3d", stringResource(R.string.glasses_auto3d), stringResource(R.string.glasses_auto3d_hint), s.auto3d, chipModifier = track("glasses-auto3d")) { Glasses.setAuto3d(it) } @@ -226,7 +252,7 @@ internal fun GlassesGroups( format = { "$it°" }, modifier = track("glasses-vr-fov")) { Glasses.setVrFovDeg(it) } } if ((tab == null || tab == GlassesTab.TRACKING) && g.canControl) { - SettingsGroup(stringResource(R.string.glasses_head_tracking)) { + SettingsGroup(stringResource(R.string.glasses_head_tracking), key = "vr-glasses-tracking") { val trackingHint = when { inSession && !usesGlasses -> R.string.glasses_screen_no_output spatialVr -> R.string.glasses_head_tracking_spatial_vr_hint @@ -240,13 +266,13 @@ internal fun GlassesGroups( chipModifier = track("glasses-tracking")) { Glasses.setHeadTracking(it) } } val calibration by Glasses.calibration.collectAsState() - if (calibration.supported) SettingsGroup(stringResource(R.string.glasses_calibration)) { + if (calibration.supported) SettingsGroup(stringResource(R.string.glasses_calibration), key = "vr-glasses-calibration") { GlassesCalibrationControls(calibration, onStart = Glasses::startCalibration, onCancel = Glasses::cancelCalibration, onReset = Glasses::resetCalibration, onDone = { onRecenter?.invoke() }) } } - if ((tab == null || tab == GlassesTab.HARDWARE) && g.canControl && g.hardwareControls) SettingsGroup(stringResource(R.string.glasses_hardware)) { + if ((tab == null || tab == GlassesTab.HARDWARE) && g.canControl && g.hardwareControls) SettingsGroup(stringResource(R.string.glasses_hardware), key = "vr-glasses-hardware") { if (g.brightnessMax > 0) SliderRow(stringResource(R.string.glasses_brightness), null, g.brightness.coerceAtLeast(0), 0..g.brightnessMax, step = 1, modifier = track("glasses-brightness")) { Glasses.setBrightness(it) } if (g.volumeMax > 0) SliderRow(stringResource(R.string.glasses_volume), null, g.volume.coerceAtLeast(0), 0..g.volumeMax, step = 1, @@ -259,7 +285,7 @@ internal fun GlassesGroups( androidx.compose.runtime.LaunchedEffect(Unit) { HandTracking.load(context) } if ((tab == null || tab == GlassesTab.TRACKING) && g.canControl) { if (g.spatialConnected) { - SettingsGroup(stringResource(R.string.glasses_experimental)) { + SettingsGroup(stringResource(R.string.glasses_experimental), key = "vr-glasses-experimental") { val spatial by SpatialTracking.status.collectAsState() ToggleRow(host, "glasses-position", stringResource(R.string.glasses_position), stringResource(R.string.glasses_position_hint), s.positionalTracking, chipModifier = track("glasses-position")) { Glasses.setPositionalTracking(it) } @@ -282,7 +308,7 @@ internal fun GlassesGroups( s.joyConTracking, enabled = s.positionalTracking, chipModifier = track("glasses-joycons")) { Glasses.setJoyConTracking(it) } } } - if (hands.usable) SettingsGroup(stringResource(R.string.phone_camera_tracking_group)) { + if (hands.usable) SettingsGroup(stringResource(R.string.phone_camera_tracking_group), key = "vr-hand-camera") { HandCameraRows(host, track, inSession) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GlassesSetupPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/GlassesSetupPanel.kt index 8b2378ae4d..ced0d6b579 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GlassesSetupPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GlassesSetupPanel.kt @@ -21,12 +21,20 @@ internal fun GlassesSetupPanel() { val (glasses, settings) = rememberGlasses() val host = rememberMenuHost() val tabs = glassesTabs(glasses) + val context = androidx.compose.ui.platform.LocalContext.current + val showShortcut = rememberShowGlassesShortcut() var selectedTab by rememberSaveable { mutableStateOf(GlassesTab.DISPLAY) } val tab = selectedTab.takeIf { selected -> tabs.any { it.first == selected } } ?: GlassesTab.DISPLAY LaunchedEffect(tab, glasses.present, glasses.canControl, glasses.model) { host.open = null } Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) { Note(stringResource(R.string.setup_glasses_scope)) + SettingsGroup(stringResource(R.string.glasses_shortcut_group), key = "glasses-shortcut") { + ToggleRow(host, "glasses-shortcut", stringResource(R.string.glasses_show_shortcut), + stringResource(R.string.glasses_show_shortcut_hint), showShortcut) { + com.droiddeck.launcher.session.SessionPrefs.setShowGlassesShortcut(context, it) + } + } if (!glasses.present && !glasses.hasDisplay && !glasses.canControl) { Note(stringResource(R.string.setup_glasses_connect)) } else { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GlideWindows.kt b/app/src/main/java/com/droiddeck/launcher/ui/GlideWindows.kt index c13bebef13..7000bb936f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GlideWindows.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GlideWindows.kt @@ -76,7 +76,7 @@ internal fun WindowDialog( content: @Composable () -> Unit, ) { if (!LocalPresentationWindow.current) { - Dialog(onDismissRequest, properties, content) + Dialog(onDismissRequest, properties) { SolidSurfaces(content) } return } Popup( @@ -87,7 +87,7 @@ internal fun WindowDialog( Modifier.fillMaxSize().background(androidx.compose.ui.graphics.Color.Black.copy(alpha = 0.6f)) .tapOutside { if (properties.dismissOnClickOutside) onDismissRequest() }, contentAlignment = Alignment.Center, - ) { content() } + ) { SolidSurfaces(content) } } } @@ -150,7 +150,7 @@ internal fun GlidePopup( ) { Popup(popupPositionProvider, onDismissRequest, properties) { if (properties.focusable) TrackKeyWindow() - FocusGlideHost(content = content) + SolidSurfaces { FocusGlideHost(content = content) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/InputSettingsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/InputSettingsPage.kt index 2fe1346034..1274945a3b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/InputSettingsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/InputSettingsPage.kt @@ -174,14 +174,15 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe detail = if (library.usersOfBindings(b.id).size > 1) stringResource(R.string.input_shared_detail, b.name, library.usersOfBindings(b.id).size) else "${profile.name} · ${roleLabel(role)}", onSave = { action -> if (update { l -> + val currentPreset = l.preset(editing.preset) val geometry = if (!editing.click && elementProperties != null && layout != null) l.withLayout(layout.copy(elements = layout.elements.map { if (it.id == elementProperties!!.id) elementProperties!!.copy(name = elementProperties!!.name.trim().ifBlank { it.name }) else it })) else l geometry.withPreset(when { - editing.element != null && editing.click -> b.copy(clicks = b.clicks + (editing.element.id to action)) - editing.element != null -> b.copy(elements = b.elements + (editing.element.id to action)) - editing.key != null -> b.copy(keys = b.keys.filterNot { it.key == editing.key } + PhysicalInputBinding(editing.key, action)) - else -> b.copy(controls = b.controls + (editing.control to action)) + editing.element != null && editing.click -> currentPreset.copy(clicks = currentPreset.clicks + (editing.element.id to action)) + editing.element != null -> currentPreset.copy(elements = currentPreset.elements + (editing.element.id to action)) + editing.key != null -> currentPreset.copy(keys = currentPreset.keys.filterNot { it.key == editing.key } + PhysicalInputBinding(editing.key, action)) + else -> currentPreset.copy(controls = currentPreset.controls + (editing.control to action)) }) }) edit = null }) } else if (!surface) key(page, profileId, role) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt index f06c43851c..b57dddc10d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt @@ -44,6 +44,7 @@ import com.droiddeck.launcher.session.SessionPrefs import kotlin.math.abs import kotlin.math.atan2 import kotlin.math.hypot +import kotlin.math.max import kotlin.math.min @SuppressLint("ViewConstructor") @@ -63,6 +64,7 @@ class InputSurfaceView( private val art by lazy(LazyThreadSafetyMode.NONE) { PadArt(context) } private var artworkDpad = emptyList() private val artworkDpadBounds = RectF() + private var crossDpads = emptyList, RectF>>() private var requestedLayout = customLayout init { customLayout = surfaceStyle.shown(customLayout); addView(content, LayoutParams(-1, -1)); renderCustom(pad) } @@ -135,7 +137,7 @@ class InputSurfaceView( val views = owners.values.distinct() owners.clear() for (view in views) { - if (view is HoldButton) { view.cancel(); continue } + if (view is HoldButton) { view.cancelTouches(); continue } val cancel = MotionEvent.obtain(event.downTime, event.eventTime, MotionEvent.ACTION_CANCEL, 0f, 0f, 0) try { view.dispatchTouchEvent(cancel) } finally { cancel.recycle() } } @@ -174,10 +176,23 @@ class InputSurfaceView( val now = android.os.SystemClock.uptimeMillis() val cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0) try { cancelOwners(cancel) } finally { cancel.recycle() } + customCanvas?.let { canvas -> for (i in 0 until canvas.childCount) (canvas.getChildAt(i) as? HoldButton)?.cancel() } forwardedPointers = 0 elementSources.forEach { it.release() } } + /** Presses a button as a finger would, for input from outside the screen; [holder] tells holds apart. */ + fun hold(elementId: String, holder: Int, held: Boolean, cancelled: Boolean = false): Boolean { + val canvas = customCanvas ?: return false + for (i in 0 until canvas.childCount) { + val button = canvas.getChildAt(i) as? HoldButton ?: continue + if ((button.tag as? InputSurfaceElement)?.id != elementId) continue + button.press(-1 - holder, held, cancelled) + return true + } + return false + } + override fun onVisibilityChanged(changedView: View, visibility: Int) { super.onVisibilityChanged(changedView, visibility) if (visibility != VISIBLE) releaseInputs() @@ -185,6 +200,7 @@ class InputSurfaceView( private fun renderCustom(pad: PadBridge?) { artworkDpad = emptyList() + crossDpads = emptyList() val canvas = object : ViewGroup(context) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val layout = customLayout @@ -203,6 +219,7 @@ class InputSurfaceView( child.layout(x, y, x + child.measuredWidth, y + child.measuredHeight) } updateArtworkDpad(this) + updateCrossDpad(this) } override fun dispatchDraw(canvas: Canvas) { @@ -244,11 +261,39 @@ class InputSurfaceView( canvas.getChildAt(index) as? HoldButton } val previous = artworkDpad - artworkDpad = if (crossed(buttons)) buttons else emptyList() + artworkDpad = if (crossed(buttons, artworkDpadBounds)) buttons else emptyList() if (artworkDpad != previous) (previous + artworkDpad).forEach { it.invalidate() } } - private fun crossed(buttons: List): Boolean { + private fun updateCrossDpad(canvas: ViewGroup) { + val buttons = (0 until canvas.childCount).map(canvas::getChildAt).filterIsInstance() + val (ups, rights, downs, lefts) = DIRECTIONS.map { direction -> buttons.filter { (it.tag as? InputSurfaceElement)?.control == direction } } + crossDpads = ups.flatMap { up -> rights.flatMap { right -> downs.flatMap { down -> + lefts.mapNotNull { left -> listOf(up, right, down, left).let { arms -> hole(arms)?.let { arms to it } } } } } } + } + + private fun hole(buttons: List): RectF? { + val (up, right, down, left) = buttons + val hole = RectF(left.right.toFloat(), up.bottom.toFloat(), right.left.toFloat(), down.top.toFloat()) + val across = max(up.left, down.left) to min(up.right, down.right) + val along = max(left.top, right.top) to min(left.bottom, right.bottom) + return hole.takeIf { + !it.isEmpty && across.first < across.second && along.first < along.second && + across.first < it.right && across.second > it.left && along.first < it.bottom && along.second > it.top + } + } + + private fun crossTarget(x: Float, y: Float): HoldButton? { + val first = crossDpads.firstOrNull()?.first?.first() ?: return null + val hx = x - (originX(first) - first.left) + val hy = y - (originY(first) - first.top) + return crossDpads.filter { (arms, hole) -> arms.all { it.visibility == VISIBLE } && hole.contains(hx, hy) } + .flatMap { it.first }.distinct().minByOrNull { arm -> + hypot(max(max(arm.left - hx, hx - arm.right), 0f), max(max(arm.top - hy, hy - arm.bottom), 0f)) + } + } + + private fun crossed(buttons: List, bounds: RectF): Boolean { if (buttons.size != DIRECTIONS.size) return false val (up, right, down, left) = buttons val centerX = (left.left + right.right) / 2f @@ -258,7 +303,7 @@ class InputSurfaceView( kotlin.math.abs((left.top + left.bottom) / 2f - centerY) > 2f || kotlin.math.abs((right.top + right.bottom) / 2f - centerY) > 2f || up.bottom >= down.top || left.right >= right.left) return false - artworkDpadBounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat()) + bounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat()) return true } @@ -284,6 +329,7 @@ class InputSurfaceView( val views = (canvas.childCount - 1 downTo 0).map(canvas::getChildAt).filter { it.visibility == VISIBLE } views.firstOrNull { !(it is StickView && it.adaptive) && hits(it, x, y, 0f) }?.let { return it } views.filter { it is HoldButton && hits(it, x, y, slack(it)) }.minByOrNull { distance(it, x, y) }?.let { return it } + crossTarget(x, y)?.let { return it } if (views.any { it is HoldButton && hits(it, x, y, slack(it) + ADAPTIVE_CLEARANCE_PX) }) return null return views.filter { it is StickView && it.adaptive && it !in owners.values && (hits(it, x, y, 0f) || it.captures(x - originX(it), y - originY(it))) } .minByOrNull { distance(it, x, y) } @@ -449,17 +495,22 @@ class InputSurfaceView( fun press(pointer: Int, pressed: Boolean, cancelled: Boolean = false) { if (pressed) pointers.add(pointer) else pointers.remove(pointer) - set(pointers.isNotEmpty(), cancelled) + set(pointers.isNotEmpty(), cancelled, touch = pointer >= 0) } fun cancel() { pointers.clear(); set(false, cancelled = true); source?.release() } + fun cancelTouches() { + pointers.removeAll { it >= 0 } + if (pointers.isEmpty()) cancel() + } + override fun onDetachedFromWindow() { cancel(); super.onDetachedFromWindow() } - private fun set(pressed: Boolean, cancelled: Boolean = false) { + private fun set(pressed: Boolean, cancelled: Boolean = false, touch: Boolean = true) { if (down == pressed) return down = pressed - if (pressed) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY) + if (pressed && touch) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY) if (!pressed && cancelled) source?.cancel() else source?.update(if (pressed) 1f else 0f) invalidate() if (artwork != null && this in artworkDpad) customCanvas?.invalidate() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LabBuilds.kt b/app/src/main/java/com/droiddeck/launcher/ui/LabBuilds.kt index 8bfc59306b..c813b4fa1c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LabBuilds.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LabBuilds.kt @@ -3,6 +3,9 @@ package com.droiddeck.launcher.ui import android.text.format.DateUtils import androidx.compose.foundation.background import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -26,8 +29,11 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -41,7 +47,7 @@ import com.droiddeck.launcher.lab.LabOverlay * [onRebuild] offers to build a kept one again for this install, when something can. */ @Composable -internal fun LabBuilds(sessionRunning: Boolean = false, onRebuild: ((LabOverlay.Info) -> Unit)? = null) { +internal fun LabBuilds(sessionRunning: Boolean = false, header: (@Composable () -> Unit)? = null, onRebuild: ((LabOverlay.Info) -> Unit)? = null) { val context = LocalContext.current var version by remember { mutableIntStateOf(0) } var busy by remember { mutableStateOf(false) } @@ -54,6 +60,7 @@ internal fun LabBuilds(sessionRunning: Boolean = false, onRebuild: ((LabOverlay. val paused = active == null && current != null && LabOverlay.skipped == LabOverlay.SKIPPED_APP_IMAGE val restartFailed = stringResource(R.string.lab_restart_failed) val canRestart = !busy && !sessionRunning + var showKept by androidx.compose.runtime.saveable.rememberSaveable { mutableStateOf(false) } /** Android may have given the APK an app image again, which a Lab build cannot load over. */ fun restart() { @@ -73,8 +80,8 @@ internal fun LabBuilds(sessionRunning: Boolean = false, onRebuild: ((LabOverlay. val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - Column(Modifier.fillMaxWidth().padding(top = 18.dp)) { - Text( + Column(Modifier.fillMaxWidth().padding(top = if (header == null) 18.dp else 0.dp)) { + if (header != null) header() else Text( stringResource(R.string.lab_builds).uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 10.dp), ) @@ -99,7 +106,29 @@ internal fun LabBuilds(sessionRunning: Boolean = false, onRebuild: ((LabOverlay. PrimaryButton(stringResource(R.string.lab_restart), compact = true, enabled = canRestart) { restart() } } } - for (build in saved) rows += { + val foldKept = (current != null || pending != null) && saved.isNotEmpty() + if (foldKept) rows += { + val src = remember { MutableInteractionSource() } + val toggle = { showKept = !showKept } + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth().paneItem("lab:kept") + .background(if (rememberHot(src)) pal.signal.copy(alpha = 0.14f) else Color.Transparent) + .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.Button, onClick = toggle) + .controllerConfirm(onClick = toggle) + .padding(horizontal = 14.dp, vertical = 12.dp), + ) { + Text( + pluralStringResource(R.plurals.lab_kept_count, saved.size, saved.size), fontSize = 14.sp, + color = colors.onSurfaceVariant, modifier = Modifier.weight(1f), + ) + Text( + stringResource(if (showKept) R.string.common_hide else R.string.common_show), fontSize = 13.5.sp, + fontWeight = FontWeight.SemiBold, color = pal.signal, + ) + } + } + if (!foldKept || showKept) for (build in saved) rows += { var armed by remember(build.dir) { mutableStateOf(false) } val info = build.info BuildRow( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LauncherFrost.kt b/app/src/main/java/com/droiddeck/launcher/ui/LauncherFrost.kt new file mode 100644 index 0000000000..91f2cdf402 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/LauncherFrost.kt @@ -0,0 +1,130 @@ +package com.droiddeck.launcher.ui + +import android.app.Activity +import android.graphics.drawable.ColorDrawable +import android.os.Build +import android.os.PowerManager +import android.view.WindowManager +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.graphics.lerp +import androidx.compose.ui.graphics.luminance +import java.util.function.Consumer + +internal val LocalFrost = staticCompositionLocalOf { null } + +internal const val FROST_MAX = 100 +internal const val FROST_STEP = 10 +internal const val FROST_DEFAULT = 50 +internal const val FROST_WALLPAPER_DEFAULT = 80 +private const val FROST_TEXT_LIFT = 0.5f +private const val FROST_LIFT_STEPS = 5 +private const val FROST_TINT_MAX = 0.9f +private const val FROST_SEARCH_STEPS = 12 +private const val FROST_BLUR_DP = 28 + +private class FrostScale(val solid: Float, val default: Float, val clear: Float) { + fun at(percent: Int): Float { + val t = percent.coerceIn(0, FROST_MAX) / FROST_DEFAULT.toFloat() + return if (t <= 1f) solid + (default - solid) * t else default + (clear - default) * (t - 1f) + } +} + +private val TINT_DARK = FrostScale(0.9f, 0.58f, 0.32f) +private val TINT_LIGHT = FrostScale(0.94f, 0.7f, 0.48f) +private val CARD_DARK = FrostScale(1f, 0.6f, 0.3f) +private val CARD_LIGHT = FrostScale(1f, 0.74f, 0.45f) +private val TEXT_LIFT_MAX = FrostScale(FROST_TEXT_LIFT, FROST_TEXT_LIFT, 1f) + +class FrostChoice( + val transparency: Int = FROST_WALLPAPER_DEFAULT, + val cards: Boolean = false, + val cardTransparency: Int = FROST_DEFAULT, +) + +internal class FrostLook(val veil: Color, val lift: Float, val cardAlpha: Float) + +internal fun frostLook(palette: Palette, choice: FrostChoice): FrostLook { + val light = palette.background.luminance() > 0.5f + val cardAlpha = if (!choice.cards) 1f else (if (light) CARD_LIGHT else CARD_DARK).at(choice.cardTransparency) + val maxLift = maxOf(TEXT_LIFT_MAX.at(choice.transparency), if (choice.cards) TEXT_LIFT_MAX.at(choice.cardTransparency) else 0f) + // Android reports only the wallpaper's main colours, and any part of it can sit behind text. + fun readable(alpha: Float, lift: Float): Boolean = listOf(Color.Black, Color.White).all { behind -> + val page = palette.background.copy(alpha = alpha).compositeOver(behind) + val card = palette.surface.copy(alpha = cardAlpha).compositeOver(page) + val hint = lerp(palette.onSurfaceVariant, palette.onBackground, lift) + minOf(ThemeColors.contrast(hint, page), ThemeColors.contrast(hint, card)) >= ThemeColors.MIN_CONTRAST + } + var low = 0f + var high = FROST_TINT_MAX + if (readable(low, maxLift)) high = low + else if (!readable(high, maxLift)) high = 1f + else repeat(FROST_SEARCH_STEPS) { + val mid = (low + high) / 2 + if (readable(mid, maxLift)) high = mid else low = mid + } + val lifts = (0..FROST_LIFT_STEPS).map { FROST_TEXT_LIFT + (maxLift - FROST_TEXT_LIFT) * it / FROST_LIFT_STEPS } + val tint = maxOf((if (light) TINT_LIGHT else TINT_DARK).at(choice.transparency), kotlin.math.ceil(high * 255f) / 255f) + val alpha = if (lifts.any { readable(tint, it) }) tint else 1f + val lift = lifts.firstOrNull { readable(alpha, it) } ?: maxLift + return FrostLook(palette.background.copy(alpha = alpha), lift, cardAlpha) +} + +internal fun Palette.frosted(look: FrostLook): Palette = Palette( + id, label, detail, + background = background, + surface = if (look.cardAlpha < 1f) surface.copy(alpha = look.cardAlpha) else surface, + surfaceVariant = if (look.cardAlpha < 1f) surfaceVariant.copy(alpha = look.cardAlpha) else surfaceVariant, + line = line, line2 = line2, + onBackground = onBackground, onSurfaceVariant = lerp(onSurfaceVariant, onBackground, look.lift), + primary = primary, primary2 = primary2, onPrimary = onPrimary, signal = signal, + good = good, error = error, warning = warning, +) + + +internal class LauncherFrost(private val activity: Activity) { + var available by mutableStateOf(false) + private set + var prepared = false + private set + + private var stopListening: (() -> Unit)? = null + + val supported: Boolean + get() = Build.VERSION.SDK_INT >= 31 && + (available || activity.getSystemService(PowerManager::class.java)?.isPowerSaveMode == true) + + fun start() { + if (Build.VERSION.SDK_INT < 31 || stopListening != null) return + val windows = activity.windowManager + val blur = Consumer { available = it } + available = windows.isCrossWindowBlurEnabled + windows.addCrossWindowBlurEnabledListener(blur) + stopListening = { windows.removeCrossWindowBlurEnabledListener(blur) } + } + + fun stop() { + stopListening?.invoke() + stopListening = null + } + + // A window made see-through after its first frame keeps drawing over its old frames, so this runs before setContent. + fun prepare(on: Boolean) { + prepared = on && Build.VERSION.SDK_INT >= 31 + if (prepared) activity.window.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT)) + } + + fun show(on: Boolean) { + if (!prepared || Build.VERSION.SDK_INT < 31) return + val window = activity.window + val flags = WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER or WindowManager.LayoutParams.FLAG_BLUR_BEHIND + if (on) window.addFlags(flags) else window.clearFlags(flags) + window.attributes = window.attributes.apply { + blurBehindRadius = if (on) (FROST_BLUR_DP * activity.resources.displayMetrics.density).toInt() else 0 + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index f7bd8e9f20..20e61f1d1f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -17,6 +17,7 @@ import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope +import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -195,14 +196,18 @@ internal fun librarySources( } } +internal fun alwaysLibraryTabs(signedIn: Collection, stores: Boolean, soundMode: Boolean): Set = + (if (soundMode) emptyList() else signedIn.map { it.librarySource }).toSet() + + listOfNotNull(Library.ADDED.takeIf { stores }, Store.BATTLENET.id.takeIf { stores }) + internal object LibraryDisplay { const val DEFAULT_LEVEL = 2 val scales = listOf(0.75f, 0.875f, 1f, 1.2f, 1.45f) var level by mutableIntStateOf(DEFAULT_LEVEL) private set - var title by mutableStateOf(true) + var title by mutableStateOf(false) private set - var size by mutableStateOf(true) + var size by mutableStateOf(false) private set fun load(context: android.content.Context) { @@ -374,7 +379,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, .map { it.store.id }.toSet() val sources = librarySources( all, storeTabs.map { it.store.id }, - listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.ADDED.takeIf { stores }, Store.BATTLENET.id.takeIf { stores }).toSet() + signInChips, + alwaysLibraryTabs(owned.keys, stores, soundMode) + signInChips, favorites, concealed, offStores = if (soundMode) emptySet() else storeTabs.filterNot { it.shown }.map { it.store.id }.toSet(), places = if (soundMode) DEFAULT_LIBRARY_PLACES else StoreTabsState.libraryPlaces, @@ -527,13 +532,11 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, val grid = remember { LazyGridState() } val detailScroll = rememberScrollState() var cycled by remember { mutableIntStateOf(0) } - var gridFocused by remember { mutableStateOf(false) } LaunchedEffect(source, sort) { grid.scrollToItem(0) } LaunchedEffect(cycled) { if (cycled == 0 || ff == null || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect - focusWithinFrames({ gridFocused }) { - if (ff.firstTileAttached > 0) ff.firstTile else ff.items["libchip:$source"] ?: FocusRequester.Default - } + val chip = "libchip:$source" + holdFocus({ ff.last == chip }) { ff.items[chip] } } CardDetailHost( open, detailScroll, @@ -559,7 +562,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, else { focusManager.clearFocus(force = true); onSelect(it) } }, searchCleared = open != null, - onFocus = { gridFocused = it }, + onFocus = {}, soundMode = soundMode, wallArt = { wallTiles(all.filterNot(concealed).mapNotNull { entryArt(it, tall = true) }) }, emptyText = when { @@ -749,20 +752,23 @@ private fun LibraryGrid( } } } + val manage = !soundMode && !s.shortcutPicker LazyVerticalGrid( columns = if (listMode) GridCells.Fixed(1) else remember(baseWidth, level) { LevelCells(baseWidth, level) }, state = grid, - modifier = Modifier.fillMaxSize().onFocusChanged { onFocus(it.hasFocus) }.focusGroup().bumpers(onPrevious = { onCycle(-1) }, onNext = { onCycle(1) }).onSizeChanged { - val gap = with(density) { 10.dp.roundToPx() } - columns = if (listMode) 1 else libraryColumns(it.width, with(density) { baseWidth.roundToPx() }, gap, level) - gridH = it.height - }, + modifier = Modifier.fillMaxSize().onFocusChanged { onFocus(it.hasFocus) }.focusGroup() + .then(if (sourceChipsShown(sources, manage)) Modifier.bumpers(onPrevious = { onCycle(-1) }, onNext = { onCycle(1) }) else Modifier) + .onSizeChanged { + val gap = with(density) { 10.dp.roundToPx() } + columns = if (listMode) 1 else libraryColumns(it.width, with(density) { baseWidth.roundToPx() }, gap, level) + gridH = it.height + }, horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(top = 4.dp, bottom = 16.dp), ) { val header: @Composable () -> Unit = { LibraryHeader(s, a, if (soundMode) total else visible.size + hiddenUninstalled, searchCleared, source == Store.XBOX.id, showUninstalled, onShowUninstalled, collections = Store.byId(source)?.takeIf { it == Store.ITCH || it == Store.GAMEJOLT }, soundMode = soundMode, onAddSoundtrack = onAddSoundtrack, onCollections = onCollections, source = source) } - val filters: @Composable () -> Unit = { LibraryFilters(sources, source, onSource, manage = !soundMode && !s.shortcutPicker) } + val filters: @Composable () -> Unit = { LibraryFilters(sources, source, onSource, manage) } item(key = if (soundMode) "header" else "filters", span = { GridItemSpan(maxLineSpan) }) { Box(Modifier.onSizeChanged { chipsH = it.height }) { Rise(0) { if (soundMode) header() else filters() } } } @@ -904,10 +910,13 @@ private fun LibraryHeader( if (s.steamGamesX64 && narrow) Box(Modifier.padding(top = 4.dp)) { ClientTag() } } +private fun sourceChipsShown(sources: List, manage: Boolean): Boolean = + (manage && sources.isNotEmpty()) || sources.size >= 2 || sources.singleOrNull() == LIBRARY_HIDDEN + @OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class) @Composable -private fun LibraryFilters(sources: List, source: String, onSource: (String) -> Unit, manage: Boolean) { - val chips = (manage && sources.isNotEmpty()) || sources.size >= 2 || sources.singleOrNull() == LIBRARY_HIDDEN +internal fun LibraryFilters(sources: List, source: String, onSource: (String) -> Unit, manage: Boolean) { + val chips = sourceChipsShown(sources, manage) if (!chips && !manage) return val pal = LocalPalette.current val keys = if (chips) listOf(LIBRARY_ALL) + sources else emptyList() @@ -923,42 +932,54 @@ private fun LibraryFilters(sources: List, source: String, onSource: (Str horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(top = 4.dp, bottom = 2.dp), ) { - Box(Modifier.weight(1f).edgeFade(scroll).horizontalScroll(scroll)) { - Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) { - for (id in keys) { - val store = Store.byId(id) - val dot = sourceDot(id) - val label = when (id) { - LIBRARY_ALL -> stringResource(R.string.stores_tab_all) - Library.ADDED -> stringResource(R.string.library_custom_games) - LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites) - LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden) - else -> store?.shortLabel ?: sourceLabel(id) - } - androidx.compose.runtime.key(id) { - val reveal = remember { BringIntoViewRequester() } - LaunchedEffect(source) { if (source == id) reveal.bringIntoView() } - StoreChip( - label = label, on = source == id, under = fillShown && highlighted == id, key = id, mark = dot ?: pal.signal, - modifier = Modifier.bringIntoViewRequester(reveal).testTag("library-source-$id") - .onGloballyPositioned { bounds[id] = it.boundsInParent() }, - lead = { - if (dot != null) Box(Modifier.size(9.dp).background(dot, CircleShape)) - else Icon(Icons.Filled.GridView, null, modifier = Modifier.size(14.dp)) - }, - onFocused = { focused = it }, - paneKey = "libchip:$id", - ) { onSource(id) } + BoxWithConstraints(Modifier.weight(1f)) { + if (sourceTabsAsMenu(maxWidth, keys.size)) { + TabMenu( + keys.map { librarySourceChipLabel(it) }, keys.indexOf(source), { onSource(keys[it]) }, + chipModifier = Modifier.paneItem("libchip:$source"), + leading = { i, _ -> LibrarySourceMark(sourceDot(keys[i])) }, + ) + } else Box(Modifier.edgeFade(scroll).horizontalScroll(scroll)) { + Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) { + for (id in keys) { + val dot = sourceDot(id) + androidx.compose.runtime.key(id) { + val reveal = remember { BringIntoViewRequester() } + LaunchedEffect(source) { if (source == id) reveal.bringIntoView() } + StoreChip( + label = librarySourceChipLabel(id), on = source == id, under = fillShown && highlighted == id, key = id, mark = dot ?: pal.signal, + modifier = Modifier.bringIntoViewRequester(reveal).testTag("library-source-$id") + .onGloballyPositioned { bounds[id] = it.boundsInParent() }, + lead = { LibrarySourceMark(dot) }, + onFocused = { focused = it }, + paneKey = "libchip:$id", + ) { onSource(id) } + } } } + if (highlighted in keys) ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown) } - if (highlighted in keys) ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown) } if (manage) ManageStoresChip() } } } +@Composable +private fun librarySourceChipLabel(id: String): String = when (id) { + LIBRARY_ALL -> stringResource(R.string.stores_tab_all) + Library.ADDED -> stringResource(R.string.library_custom_games) + LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites) + LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden) + else -> Store.byId(id)?.shortLabel ?: sourceLabel(id) +} + +@Composable +private fun LibrarySourceMark(dot: Color?) { + if (dot != null) Box(Modifier.size(9.dp).background(dot, CircleShape)) + else Icon(Icons.Filled.GridView, null, modifier = Modifier.size(14.dp)) +} + @Composable private fun sourceTitle(src: String): String = when (src) { LIBRARY_ALL -> stringResource(R.string.library_all_games) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LiftSheet.kt b/app/src/main/java/com/droiddeck/launcher/ui/LiftSheet.kt index 66f6ea110a..6769798ad9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LiftSheet.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LiftSheet.kt @@ -711,6 +711,10 @@ internal fun SheetChips( Modifier.fillMaxWidth().onFocusChanged { within = it.hasFocus }, contentAlignment = Alignment.CenterStart, ) { + if (tabsAsMenu(maxWidth, labels.size)) { + TabMenu(labels, selected, onPick, focus = chips) + return@BoxWithConstraints + } val equal = !width.isSpecified && maxWidth / labels.size.coerceAtLeast(1) >= 96.dp val least = if (width.isSpecified) maxOf(width, 64.dp) else 64.dp val scroll = rememberScrollState() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 3509d0a83d..2f0cc48a1f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -62,6 +62,7 @@ class ModeSettings( val hdrReason: String?, val hdrDisplay: Boolean = true, val zeroCopy: Boolean = true, + val producerAcquireFences: Boolean? = null, val gpuDrivers: String? = null, val upscaler: Int = 0, val upscaleSharpness: Int = 75, @@ -86,7 +87,8 @@ class ModeSettings( val fexPreset: String? = null, val forceSsbs: Boolean = false, val syncBackend: String? = null, - val picturePosition: String? = null, + val picturePositionLandscape: String? = null, + val picturePositionPortrait: String? = null, val integerScaling: Boolean? = null, val stretch16x9: Boolean? = null, val avoidNotch: Boolean? = null, @@ -125,6 +127,7 @@ class ModeSettingsActions( val onResolutionPortrait: (String) -> Unit = {}, val onHdr: (Boolean) -> Unit, val onZeroCopy: (Boolean) -> Unit = {}, + val onProducerAcquireFences: (Boolean) -> Unit = {}, val onGpuDrivers: () -> Unit = {}, val onUpscaler: (Int) -> Unit = {}, val onUpscaleSharpness: (Int) -> Unit = {}, @@ -150,7 +153,7 @@ class ModeSettingsActions( val onFexPreset: (String) -> Unit = {}, val onForceSsbs: (Boolean) -> Unit = {}, val onSyncBackend: (String) -> Unit = {}, - val onPicturePosition: (String) -> Unit = {}, + val onPicturePosition: (Boolean, String) -> Unit = { _, _ -> }, val onIntegerScaling: (Boolean) -> Unit = {}, val onStretch16x9: (Boolean) -> Unit = {}, val onAvoidNotch: (Boolean) -> Unit = {}, @@ -260,15 +263,16 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: ResolutionRow(host, "resolution-portrait", stringResource(R.string.display_resolution_portrait), s.resolutionPortrait, portraitChoice, com.droiddeck.launcher.session.SessionDisplay.LINK_LANDSCAPE, if (sessionDisplay.isLink(s.resolution)) portraitChoice else sessionDisplay.orientCustom(s.resolution, true), - s.panelSize, a.onResolutionPortrait, portrait = true) - s.picturePosition?.let { position -> - ChoiceRow(host, "picture-position", stringResource(R.string.display_picture_position), null, - listOf("top" to stringResource(R.string.display_position_top), - "bottom" to stringResource(R.string.display_position_bottom), - "left" to stringResource(R.string.display_position_left), - "right" to stringResource(R.string.display_position_right), - "center" to stringResource(R.string.display_position_center)), - position, onPick = a.onPicturePosition) + s.panelSize, a.onResolutionPortrait, portrait = true, + defaultChoice = if (s.mode == SessionService.MODE_STEAM) sessionDisplay.DEFAULT_STEAM_PORTRAIT_RESOLUTION + else sessionDisplay.DEFAULT_RESOLUTION) + s.picturePositionLandscape?.let { position -> + PicturePositionRow(host, position, key = "picture-position-landscape", + labelRes = R.string.display_picture_position_landscape) { a.onPicturePosition(false, it) } + } + s.picturePositionPortrait?.let { position -> + PicturePositionRow(host, position, key = "picture-position-portrait", + labelRes = R.string.display_picture_position_portrait) { a.onPicturePosition(true, it) } } if (s.stretch16x9 != null && (com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(s.panelSize) || com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize))) { @@ -284,6 +288,11 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: stringResource(R.string.display_avoid_notch_hint), checked = enabled, onChange = a.onAvoidNotch) } ToggleRow(host, "zero-copy", stringResource(R.string.display_zero_copy), null, checked = s.zeroCopy, onChange = a.onZeroCopy) + s.producerAcquireFences?.let { enabled -> + ToggleRow(host, "producer-acquire-fences", stringResource(R.string.producer_acquire_fences), + stringResource(R.string.producer_acquire_fences_summary), checked = enabled, + onChange = a.onProducerAcquireFences) + } } SettingsGroup(stringResource(R.string.display_image_scaling)) { s.integerScaling?.let { enabled -> @@ -735,3 +744,22 @@ internal fun CustomFollowScaleDialog(initial: Float?, onSave: (Float) -> Unit, o dismissButton = { androidx.compose.material3.TextButton(onClick = onDismiss, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } }, ) } + +@Composable +internal fun PicturePositionRow( + host: MenuHost, position: String, + chipModifier: Modifier = Modifier, + key: String = "picture-position", + @androidx.annotation.StringRes labelRes: Int = R.string.display_picture_position, + onPick: (String) -> Unit, +) { + ChoiceRow(host, key, stringResource(labelRes), null, + listOf( + "center" to stringResource(R.string.display_position_center), + "top" to stringResource(R.string.display_position_top), + "bottom" to stringResource(R.string.display_position_bottom), + "left" to stringResource(R.string.display_position_left), + "right" to stringResource(R.string.display_position_right), + ), + position, chipModifier = chipModifier, onPick = onPick) +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt b/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt index 2fa5d01cbd..dcf1050ee7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt @@ -116,10 +116,7 @@ internal object NavTabs { fun more(s: FrontEndState) = listed(s).filter { place(s, it) == TabPlace.MORE } - fun bar(s: FrontEndState): List { - val shown = listed(s).filter { place(s, it) == TabPlace.BAR } - return if (more(s).isEmpty()) shown else shown + MORE - } + fun bar(s: FrontEndState): List = listed(s).filter { place(s, it) == TabPlace.BAR } + MORE fun setHidden(context: Context, key: String, hide: Boolean) { hidden = if (hide && hideable(key)) hidden + key else hidden - key diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt b/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt index 5c40727031..bd63dce034 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt @@ -8,6 +8,9 @@ import com.droiddeck.launcher.input.PcKey import androidx.compose.ui.res.stringResource import android.view.KeyEvent import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable @@ -69,6 +72,9 @@ fun PcKeyboard( sendKey: (Int, Boolean) -> Unit, onAndroidKeyboard: () -> Unit, onClose: () -> Unit, + heightFraction: Float? = null, + showButtons: Boolean = true, + hoverFeedback: Boolean = false, ) { val pal = LocalPalette.current val colors = MaterialTheme.colorScheme @@ -76,31 +82,40 @@ fun PcKeyboard( var capsOn by remember { mutableStateOf(false) } val firstKey = remember { FocusRequester() } val shifted = (mods[42] ?: MOD_OFF) != MOD_OFF || (mods[54] ?: MOD_OFF) != MOD_OFF + // Keys go to wherever sendKey points now, but a held key is let go where it went down. + val currentSend by androidx.compose.runtime.rememberUpdatedState(sendKey) + val heldAt = remember { mutableMapOf Unit>() } + fun down(code: Int) { + val send = currentSend + heldAt[code] = send + send(code, true) + } + fun up(code: Int) = (heldAt.remove(code) ?: currentSend)(code, false) fun releaseOnceModifiers() { - for ((code, state) in mods.toMap()) if (state == MOD_ONCE) { sendKey(code, false); mods[code] = MOD_OFF } + for ((code, state) in mods.toMap()) if (state == MOD_ONCE) { up(code); mods[code] = MOD_OFF } } fun press(key: PcKey) { if (key.code in PC_MODIFIERS) { when (mods[key.code] ?: MOD_OFF) { - MOD_OFF -> { sendKey(key.code, true); mods[key.code] = MOD_ONCE } + MOD_OFF -> { down(key.code); mods[key.code] = MOD_ONCE } MOD_ONCE -> mods[key.code] = MOD_LOCKED - else -> { sendKey(key.code, false); mods[key.code] = MOD_OFF } + else -> { up(key.code); mods[key.code] = MOD_OFF } } return } - sendKey(key.code, true) + down(key.code) } fun release(key: PcKey) { if (key.code in PC_MODIFIERS) return - sendKey(key.code, false) + up(key.code) if (key.code == 58) capsOn = !capsOn releaseOnceModifiers() } androidx.compose.runtime.DisposableEffect(Unit) { - onDispose { for ((code, state) in mods.toMap()) if (state != MOD_OFF) sendKey(code, false) } + onDispose { for (code in heldAt.keys.toList()) up(code) } } - LaunchedEffect(Unit) { runCatching { firstKey.requestFocus() } } + LaunchedEffect(Unit) { if (!hoverFeedback) runCatching { firstKey.requestFocus() } } val prefsContext = LocalContext.current remember { PcKeyboardPrefs.load(prefsContext) } @@ -108,7 +123,7 @@ fun PcKeyboard( val rows = PC_KEY_ROWS.map { row -> row.filter { it.code !in hiddenCodes } }.filter { it.isNotEmpty() } BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) { - val rowHeight = ((maxHeight * (PcKeyboardPrefs.size / 100f) - 24.dp - 3.dp * rows.size - 10.dp) / rows.size) + val rowHeight = ((maxHeight * (heightFraction ?: (PcKeyboardPrefs.size / 100f)) - 24.dp - 3.dp * rows.size - 10.dp) / rows.size) .coerceIn(20.dp, 56.dp) Box( Modifier.fillMaxWidth() @@ -122,9 +137,11 @@ fun PcKeyboard( Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().height(24.dp)) { Text(stringResource(R.string.drawer_pc_keyboard), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant) Spacer(Modifier.weight(1f)) - HeaderButton(stringResource(R.string.pckb_android), onAndroidKeyboard) - Spacer(Modifier.width(8.dp)) - HeaderButton(stringResource(R.string.pckb_hide), onClose) + if (showButtons) { + HeaderButton(stringResource(R.string.pckb_android), onAndroidKeyboard) + Spacer(Modifier.width(8.dp)) + HeaderButton(stringResource(R.string.pckb_hide), onClose) + } } rows.forEachIndexed { r, row -> Row(horizontalArrangement = Arrangement.spacedBy(3.dp), modifier = Modifier.fillMaxWidth().height(rowHeight)) { @@ -139,7 +156,7 @@ fun PcKeyboard( } key(key.code) { KeyCap( - label, key.weight, lit, locked = state == MOD_LOCKED, + label, key.weight, lit, locked = state == MOD_LOCKED, hoverFeedback = hoverFeedback, modifier = if (r == 0 && i == 0) Modifier.focusRequester(firstKey) else Modifier, onDown = { press(key) }, onUp = { release(key) }, ) @@ -154,25 +171,35 @@ fun PcKeyboard( @Composable private fun RowScope.KeyCap( - label: String, weight: Float, lit: Boolean, locked: Boolean, + label: String, weight: Float, lit: Boolean, locked: Boolean, hoverFeedback: Boolean, modifier: Modifier, onDown: () -> Unit, onUp: () -> Unit, ) { val pal = LocalPalette.current val src = remember { MutableInteractionSource() } val focused by src.collectIsFocusedAsState() + val hovered by src.collectIsHoveredAsState() + val (pointedAt, laser) = com.droiddeck.launcher.session.xr.rememberXrPointed() + val pointed = hoverFeedback && (hovered || laser.value) var down by remember { mutableStateOf(false) } val fill by animateColorAsState( when { down -> pal.signal.copy(alpha = 0.55f) lit -> pal.signal.copy(alpha = if (locked) 0.45f else 0.28f) + pointed -> Color.White.copy(alpha = 0.2f) else -> Color.White.copy(alpha = 0.07f) - }, Motion.tw(160), label = "keyFill", + }, Motion.tw(if (down) 40 else 160), label = "keyFill", + ) + val scale by animateFloatAsState( + if (!hoverFeedback) 1f else if (down) 0.9f else if (pointed) 1.06f else 1f, Motion.tw(if (down) 40 else 140), label = "keyScale", ) Box( contentAlignment = Alignment.Center, modifier = modifier.weight(weight).fillMaxHeight() + .then(pointedAt) + .graphicsLayer { scaleX = 1f + (scale - 1f) * size.height / size.width; scaleY = scale } .background(fill, RoundedCornerShape(7.dp)) - .glideBorder(focused, RoundedCornerShape(7.dp), pal.signal, if (lit) pal.signal.copy(alpha = 0.7f) else Color.White.copy(alpha = 0.12f)) + .glideBorder(if (hoverFeedback) pointed || down else focused, RoundedCornerShape(7.dp), pal.signal, if (lit) pal.signal.copy(alpha = 0.7f) else Color.White.copy(alpha = 0.12f)) + .then(if (hoverFeedback) Modifier.hoverable(src) else Modifier) .pointerInput(Unit) { awaitEachGesture { awaitFirstDown().consume() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PenSettingsGroup.kt b/app/src/main/java/com/droiddeck/launcher/ui/PenSettingsGroup.kt index 646c8cfcc6..772c6cc27c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/PenSettingsGroup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/PenSettingsGroup.kt @@ -11,7 +11,7 @@ internal fun PenSettingsGroup( host: MenuHost, pen: SessionPrefs.Pen, track: (String) -> Modifier = { Modifier }, onPick: (key: String, value: String) -> Unit, ) { - SettingsGroup(stringResource(R.string.mode_pen)) { + SettingsGroup(stringResource(R.string.mode_pen), key = "controller-pen") { ChoiceRow(host, "pen", stringResource(R.string.mode_pen), null, listOf(SessionPrefs.PEN_MOUSE to stringResource(R.string.mode_pen_mouse), SessionPrefs.PEN_TOUCH to stringResource(R.string.mode_pen_touch)), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PerformanceDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/PerformanceDialog.kt index 0c3947f986..45edd262af 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/PerformanceDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/PerformanceDialog.kt @@ -46,9 +46,8 @@ fun PerformancePage( fsyncFirst: Boolean, gamescopeRealtime: Boolean, gpuClockPin: Boolean, - prootNoSeccomp: Boolean, - prootFastPath: Boolean, - nativeUserland: Boolean, + nativeDesktopAvailable: Boolean, + desktopAsUser: Boolean, cursorComposite: Boolean, guestHostname: String, phantomWarning: String?, @@ -64,9 +63,7 @@ fun PerformancePage( onFsyncFirst: (Boolean) -> Unit, onGamescopeRealtime: (Boolean) -> Unit, onGpuClockPin: (Boolean) -> Unit, - onProotNoSeccomp: (Boolean) -> Unit, - onProotFastPath: (Boolean) -> Unit, - onNativeUserland: (Boolean) -> Unit, + onDesktopAsUser: (Boolean) -> Unit, onCursorComposite: (Boolean) -> Unit, onGuestHostname: (String) -> Unit, onClientCore: (Int, Boolean) -> Unit, @@ -150,26 +147,6 @@ fun PerformancePage( stringResource(R.string.perf_fastsync_hint), fastSync, onChange = onFastSync, ) - ToggleRow( - host, "seccomp", stringResource(R.string.perf_seccomp), - stringResource(R.string.perf_seccomp_hint), - prootNoSeccomp, onChange = onProotNoSeccomp, - ) - ToggleRow( - host, "fastpath", stringResource(R.string.perf_fastpath), - when { - nativeUserland -> stringResource(R.string.perf_fastpath_needs_proot) - prootNoSeccomp -> stringResource(R.string.perf_fastpath_needs_seccomp) - else -> stringResource(R.string.perf_fastpath_hint) - }, - prootFastPath && !prootNoSeccomp && !nativeUserland, enabled = !prootNoSeccomp && !nativeUserland, - onChange = onProotFastPath, - ) - ToggleRow( - host, "nativeuserland", stringResource(R.string.perf_native_userland), - stringResource(R.string.perf_native_userland_hint), - nativeUserland, onChange = onNativeUserland, - ) ToggleRow( host, "cursorcomposite", stringResource(R.string.perf_cursor_composite), stringResource(R.string.perf_cursor_composite_hint), @@ -194,6 +171,12 @@ fun PerformancePage( modifier = Modifier.width(220.dp).focusGlide(), ) } + ToggleRow( + host, "desktopasuser", stringResource(R.string.perf_desktop_as_user), + stringResource(R.string.perf_desktop_as_user_hint), + desktopAsUser && nativeDesktopAvailable, enabled = nativeDesktopAvailable, + onChange = onDesktopAsUser, + ) } if (phantomWarning != null) { Spacer(Modifier.height(16.dp)) @@ -218,7 +201,7 @@ fun PerformancePage( @Composable internal fun GpuClockGroup(host: MenuHost, on: Boolean, chipModifier: Modifier = Modifier, onChange: (Boolean) -> Unit) { - SettingsGroup(stringResource(R.string.perf_gpu)) { + SettingsGroup(stringResource(R.string.perf_gpu), key = "performance-gpu") { ToggleRow( host, "gpuclock", stringResource(R.string.perf_gpuclock), null, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt b/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt index ca9ca5976c..34121eb342 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt @@ -16,12 +16,14 @@ fun ResolutionRow( panel: Pair, onPick: (String) -> Unit, chipModifier: Modifier = Modifier, portrait: Boolean = false, + defaultChoice: String = SessionDisplay.DEFAULT_RESOLUTION, ) { val custom = "custom" val linked = stored == link val size = SessionDisplay.resolveChoice(panel, choice, portrait) val screen = SessionDisplay.resolveChoice(panel, SessionDisplay.MATCH_SCREEN, portrait) - val choices = SessionDisplay.resolutionOptions(panel) + val presets = SessionDisplay.resolutionOptions(panel) + val choices = if (defaultChoice == SessionDisplay.DEFAULT_RESOLUTION) presets else listOf(defaultChoice) + presets val customFollow = !linked && SessionDisplay.isFollow(choice) && choice !in choices val selected = if (linked) link else if (SessionDisplay.isFollow(choice)) choice else if (size == screen) SessionDisplay.MATCH_SCREEN else choice @@ -36,7 +38,7 @@ fun ResolutionRow( else if (value == SessionDisplay.FOLLOW_SCREEN) stringResource(R.string.display_follow_screen) else if (SessionDisplay.isFollow(value)) stringResource(R.string.display_follow_screen_scaled, SessionDisplay.formatScale(SessionDisplay.followScale(value) ?: 1f)) + " (${dimensions.first}×${dimensions.second})" - else if (value == SessionDisplay.DEFAULT_RESOLUTION) stringResource(R.string.mode_res_default, "${dimensions.first}×${dimensions.second}") + else if (value == defaultChoice) stringResource(R.string.mode_res_default, "${dimensions.first}×${dimensions.second}") else "${dimensions.first}×${dimensions.second}" } + listOf(SessionDisplay.FOLLOW_CUSTOM to stringResource(R.string.display_follow_screen_scaled, if (customFollow) SessionDisplay.formatScale(SessionDisplay.followScale(choice) ?: 1f) else "…" diff --git a/app/src/main/java/com/droiddeck/launcher/ui/RomsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/RomsDialog.kt index 2504a2eee3..e9e09f7e45 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/RomsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/RomsDialog.kt @@ -3,6 +3,8 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.shape.CircleShape import com.droiddeck.launcher.R import androidx.compose.ui.res.stringResource +import androidx.compose.ui.platform.LocalContext +import com.droiddeck.launcher.session.SessionPrefs import androidx.compose.foundation.layout.Column import androidx.compose.ui.Modifier import androidx.compose.foundation.layout.Spacer @@ -22,7 +24,7 @@ fun RomsDialog(path: String?, onChoose: () -> Unit, onClear: () -> Unit, onDismi text = { Column { Text( - stringResource(R.string.roms_text), + stringResource(if (SessionPrefs.mountSharedStorage(LocalContext.current)) R.string.roms_text else R.string.roms_text_unmounted), style = MaterialTheme.typography.bodyMedium, ) Spacer(Modifier.height(10.dp)) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt new file mode 100644 index 0000000000..b012bb1292 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt @@ -0,0 +1,69 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.R + +@Composable +internal fun ScalingFilterMenu( + mode: Int, + options: List>, + hasGameOverride: Boolean, + onPick: (Int) -> Unit, + onResetGame: () -> Unit, + gameName: String? = null, +) { + val colors = MaterialTheme.colorScheme + Column(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, bottom = 8.dp)) { + val selectedLabel = options.firstOrNull { it.first == mode }?.second ?: mode.toString() + Text( + stringResource( + if (hasGameOverride) R.string.display_filter_game_profile else R.string.display_filter_default_profile, + if (hasGameOverride) gameName.orEmpty() else selectedLabel, + selectedLabel, + ), + color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 6.dp), + ) + options.forEachIndexed { index, (option, label) -> + val selected = mode == option + val pick = { onPick(option) } + OutlinedButton( + onClick = pick, + modifier = Modifier.fillMaxWidth() + .padding(top = if (index == 0) 0.dp else 6.dp) + .controllerConfirm(onClick = pick), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selected) colors.primary else colors.onSurface, + ), + ) { Text(label) } + } + Text( + stringResource(R.string.display_filter_note), + color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(top = 6.dp), + ) + OutlinedButton( + onClick = onResetGame, + modifier = Modifier.fillMaxWidth().padding(top = 6.dp) + .controllerConfirm(onClick = onResetGame), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + ) { + Text(stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓") + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ScreenTaps.kt b/app/src/main/java/com/droiddeck/launcher/ui/ScreenTaps.kt index 20c942dea6..d61e51bdd7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ScreenTaps.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ScreenTaps.kt @@ -1,6 +1,7 @@ package com.droiddeck.launcher.ui import android.content.Context +import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText import androidx.compose.foundation.gestures.awaitEachGesture @@ -48,10 +49,18 @@ internal fun releaseTextField(field: EditText, origin: IntArray, x: Float, y: Fl val insideX = x >= origin[0] - margin && x <= origin[0] + field.width + margin val insideY = y >= origin[1] - margin && y <= origin[1] + field.height + margin if (insideX && insideY) return + releaseTextField(field) +} + +internal fun releaseTextField(field: EditText) { field.clearFocus() (field.context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)?.hideSoftInputFromWindow(field.windowToken, 0) } +internal fun releaseFocusedTextField(view: View) { + (view.rootView.findFocus() as? EditText)?.let(::releaseTextField) +} + /** A dialog's touches never reach the activity, so a dialog holding a search field counts its taps and releases the field itself. */ internal fun Modifier.releaseTextFieldOnTap(): Modifier = composed { val view = LocalView.current diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt b/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt index 73df657efe..508c0f4ea9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt @@ -22,9 +22,11 @@ import androidx.compose.material.icons.outlined.Tune import androidx.lifecycle.setViewTreeLifecycleOwner import androidx.lifecycle.setViewTreeViewModelStoreOwner import androidx.savedstate.setViewTreeSavedStateRegistryOwner +import com.droiddeck.launcher.input.ControllerPrefs import com.droiddeck.launcher.input.DeckPanel import com.droiddeck.launcher.input.KeyboardHost import com.droiddeck.launcher.input.PadBridge +import com.droiddeck.launcher.wayland.WaylandCompositor import com.droiddeck.launcher.input.SecondScreenMode import com.droiddeck.launcher.SessionActivity import com.droiddeck.launcher.session.BottomDesktop @@ -396,6 +398,7 @@ class SecondScreenPresentation( val layout = panelLayout(mode) val controls = InputSurfaceView(context, pad, layout?.elements.orEmpty(), surfaceStyle = layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()) + controls.alpha = ControllerPrefs.onScreenOpacity(context) / 100f controlsView = controls root.addView(controls, weightParams()) attachKeyboard() @@ -490,12 +493,19 @@ class SecondScreenPresentation( } private fun attachKeyboard() { - val host = KeyboardHost(context) { event -> - val handled = sessionActivity.dispatchKeyEvent(event) - if (fieldKeyboard && event.action == KeyEvent.ACTION_UP && - (event.keyCode == KeyEvent.KEYCODE_ENTER || event.keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER)) root.post { closeFieldKeyboard() } - handled - } + val host = KeyboardHost( + context, + sendKeyEvent = { event -> + val handled = sessionActivity.dispatchImeKeyEvent(event) + if (fieldKeyboard && event.action == KeyEvent.ACTION_UP && + (event.keyCode == KeyEvent.KEYCODE_ENTER || event.keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER)) root.post { closeFieldKeyboard() } + handled + }, + sendText = { text -> + WaylandCompositor.textInputCommit(text) + if (fieldKeyboard && text == "\r") root.post { closeFieldKeyboard() } + }, + ) host.onImeChanged = { visible -> if (!visible && keyboardShown.value) keyboardClosed() } keyboardHost = host root.addView(host, ViewGroup.LayoutParams(1, 1)) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionDrawerPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionDrawerPage.kt index b2bc10c8a4..f9e8924c8f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionDrawerPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionDrawerPage.kt @@ -6,21 +6,28 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.droiddeck.launcher.session.SessionPrefs +/** HUD holds the Performance page and GAMES the Game page; the names stay because saved page orders use them. */ internal enum class SessionDrawerPage(val firstControl: String) { - CONTROLLER("input-profile"), - GLASSES("glasses-game"), - DISPLAY("fg"), - HUD("hud"), - EFFECTS("look"), - GAMES("anisotropy"), - AGENT("agent-input"), - SESSION("suspend"), + CONTROLLER("section-controller-input"), + HUD("section-performance-pacing"), + FRAMEGEN("fg"), + DISPLAY("section-display"), + EFFECTS("section-effects-look"), + GAMES("section-game-profile"), + VR("section-vr-steamvr"), + SESSION("pause"), MORE("more-edit"), - VR("steamvr"), + ACHIEVEMENTS("achievements"), + AGENT("agent-input"), } internal object DrawerPages { - var order by mutableStateOf(SessionDrawerPage.entries.toList()) + private val defaultOrder = SessionDrawerPage.entries.toMutableList().apply { + remove(SessionDrawerPage.VR) + add(indexOf(SessionDrawerPage.MORE) + 1, SessionDrawerPage.VR) + }.toList() + + var order by mutableStateOf(defaultOrder) private set var hidden by mutableStateOf(emptySet()) private set @@ -37,6 +44,7 @@ internal object DrawerPages { } fun arrange(saved: List): List { + if (saved.isEmpty()) return defaultOrder val all = SessionDrawerPage.entries val out = saved.mapNotNull { name -> all.firstOrNull { it.name == name } }.distinct().toMutableList() for (page in all.filterNot { it in out }) { @@ -60,27 +68,27 @@ internal object DrawerPages { } fun reset(context: Context) { - order = SessionDrawerPage.entries.toList() + order = defaultOrder hidden = emptySet() if (DevPreview.drawer != null) return SessionPrefs.setDrawerPageOrder(context, order.map { it.name }) SessionPrefs.setDrawerPageHidden(context, emptySet()) } - fun isDefault() = order == SessionDrawerPage.entries.toList() && hidden.isEmpty() + fun isDefault() = order == defaultOrder && hidden.isEmpty() } internal fun offeredDrawerPages( - hasGlasses: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown, + hasAchievements: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown, ): List = DrawerPages.order.filter { - (hasGlasses || it != SessionDrawerPage.GLASSES) && + (hasAchievements || it != SessionDrawerPage.ACHIEVEMENTS) && (hasAgent || it != SessionDrawerPage.AGENT) } internal fun sessionDrawerPages( - hasGlasses: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown, -): List = offeredDrawerPages(hasGlasses, hasAgent).filter { it !in DrawerPages.hidden } + hasAchievements: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown, +): List = offeredDrawerPages(hasAchievements, hasAgent).filter { it !in DrawerPages.hidden } /** The pages shown as tabs: everything up to and including the More tab. */ internal fun List.strip(): List { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index ae00595556..6e843c212d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -16,11 +16,15 @@ import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.input.key.type import androidx.compose.ui.layout.LayoutCoordinates +import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.layout.Layout import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.LayoutDirection import kotlin.math.roundToInt import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay @@ -37,6 +41,7 @@ import androidx.compose.material.icons.outlined.DesktopWindows import androidx.compose.material.icons.outlined.Keyboard import androidx.compose.material.icons.outlined.AutoFixHigh import androidx.compose.material.icons.outlined.ExpandMore +import androidx.compose.material.icons.outlined.EmojiEvents import androidx.compose.material.icons.outlined.Home import androidx.compose.material.icons.outlined.MoreHoriz import androidx.compose.material.icons.automirrored.outlined.ArrowBack @@ -72,6 +77,7 @@ import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight @@ -81,6 +87,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.systemGestureExclusion import androidx.compose.foundation.ScrollState import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.rememberScrollState @@ -88,6 +95,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Slider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -95,6 +103,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.unit.Dp import androidx.compose.runtime.rememberUpdatedState @@ -107,6 +116,11 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.droiddeck.launcher.HomeApp +import com.droiddeck.launcher.input.AirTrigger +import com.droiddeck.launcher.input.AirTriggerAction +import com.droiddeck.launcher.input.AirTriggerLed +import com.droiddeck.launcher.input.RapidFireRate +import com.droiddeck.launcher.input.ControllerPrefs import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.animateColorAsState import androidx.compose.animation.core.Spring @@ -152,6 +166,7 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.res.stringResource +import androidx.compose.ui.res.vectorResource import androidx.compose.ui.platform.LocalContext import com.droiddeck.launcher.R import com.droiddeck.launcher.core.FexPreset @@ -162,6 +177,7 @@ import com.droiddeck.launcher.gpu.ScreenEffectLooks import com.droiddeck.launcher.gpu.Cardboard import com.droiddeck.launcher.gpu.SteamVr import com.droiddeck.launcher.gpu.ScreenEffects +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.ComponentsManager import com.droiddeck.launcher.input.PC_KEY_GROUP_IDS @@ -175,12 +191,13 @@ import java.util.Locale internal val SessionDrawerPage.title: Int get() = when (this) { SessionDrawerPage.CONTROLLER -> R.string.drawer_page_controller - SessionDrawerPage.GLASSES -> R.string.drawer_page_glasses SessionDrawerPage.DISPLAY -> R.string.drawer_page_display - SessionDrawerPage.HUD -> R.string.drawer_hud - SessionDrawerPage.VR -> R.string.vr_title + SessionDrawerPage.HUD -> R.string.drawer_page_performance + SessionDrawerPage.FRAMEGEN -> R.string.frame_gen_title + SessionDrawerPage.VR -> R.string.drawer_page_vr SessionDrawerPage.EFFECTS -> R.string.drawer_page_effects - SessionDrawerPage.GAMES -> R.string.game_settings_title + SessionDrawerPage.GAMES -> R.string.drawer_page_game + SessionDrawerPage.ACHIEVEMENTS -> R.string.achievements_title SessionDrawerPage.AGENT -> R.string.rail_agent SessionDrawerPage.SESSION -> R.string.mode_session SessionDrawerPage.MORE -> R.string.drawer_page_more @@ -188,12 +205,13 @@ internal val SessionDrawerPage.title: Int get() = when (this) { internal val SessionDrawerPage.icon get() = when (this) { SessionDrawerPage.CONTROLLER -> Icons.Outlined.SportsEsports - SessionDrawerPage.GLASSES -> GlassesIcon SessionDrawerPage.DISPLAY -> Icons.Outlined.DesktopWindows SessionDrawerPage.HUD -> Icons.Outlined.Speed + SessionDrawerPage.FRAMEGEN -> Icons.Outlined.Layers SessionDrawerPage.VR -> VrHeadsetIcon SessionDrawerPage.EFFECTS -> Icons.Outlined.AutoFixHigh SessionDrawerPage.GAMES -> Icons.Outlined.Layers + SessionDrawerPage.ACHIEVEMENTS -> Icons.Outlined.EmojiEvents SessionDrawerPage.AGENT -> Icons.Outlined.Terminal SessionDrawerPage.SESSION -> Icons.Outlined.Settings SessionDrawerPage.MORE -> Icons.Outlined.MoreHoriz @@ -205,9 +223,15 @@ private class DrawerFocus { var focused by mutableStateOf(null) private set + private val sectionOrder = mutableMapOf>() + private fun requester(key: String) = requesters.getOrPut(key) { FocusRequester() } - fun track(page: SessionDrawerPage, key: String): Modifier = Modifier.focusRequester(requester(key)).onFocusChanged { + fun sections(page: SessionDrawerPage): List = sectionOrder[page]?.toList().orEmpty() + + fun track(page: SessionDrawerPage, key: String): Modifier = Modifier.focusRequester(requester(key)).also { + if (key.startsWith("section-")) sectionOrder.getOrPut(page) { LinkedHashSet() }.add(key) + }.onFocusChanged { if (it.isFocused) { last[page] = key focused = key @@ -219,6 +243,12 @@ private class DrawerFocus { fun forget(page: SessionDrawerPage) { last.remove(page) } } +data class AirTriggerMenu( + val enabled: Boolean, val selected: Map, val buttons: List>, + val vibration: Boolean = false, val screenLight: Boolean = false, val led: AirTriggerLed = AirTriggerLed.STEADY, + val actions: Map = emptyMap(), val rates: Map = emptyMap(), +) + class DrawerActions( val steam: Boolean, val desktop: Boolean, @@ -258,6 +288,8 @@ class DrawerActions( val upscaleSharpness: Int = 75, val integerScaling: Boolean = false, val onIntegerScaling: (Boolean) -> Unit = {}, + val picturePosition: String = "center", + val onPicturePosition: (String) -> Unit = {}, val gameZoomAvailable: Boolean = false, val gameZoom: Float = 1.0f, val onGameZoom: (Float) -> Unit = {}, @@ -305,7 +337,6 @@ class DrawerActions( val hdr: Boolean = false, val hdrAvailable: Boolean = false, val onHdr: (Boolean) -> Unit = {}, - val onImportLossless: () -> Unit, val onKeyboard: () -> Unit, val onHardwareKeyboard: () -> Unit, val wowChatShown: Boolean = false, @@ -313,13 +344,24 @@ class DrawerActions( val onWowChat: (String?) -> Unit = {}, val onSteamMenu: (() -> Unit)?, val onQam: (() -> Unit)?, - val onAchievements: (() -> Unit)? = null, + val controllerConnected: Boolean = false, + val achievementsGame: com.droiddeck.launcher.stores.StoreAchievements.Game? = null, + val achievementsTitle: String? = null, val achievementsProgress: Pair? = null, val onOsc: (String) -> Unit, val onEditSteamTouch: (() -> Unit)? = null, val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null, val onControllerSize: (Int) -> Unit = {}, + val onControllerOpacity: (Int) -> Unit = {}, val onRumble: (Boolean) -> Unit = {}, + val airTriggers: AirTriggerMenu? = null, + val onAirTriggers: (Boolean) -> Unit = {}, + val onAirTriggerButton: (AirTrigger, String) -> Unit = { _, _ -> }, + val onAirTriggerAction: (AirTrigger, AirTriggerAction) -> Unit = { _, _ -> }, + val onAirTriggerRate: (AirTrigger, RapidFireRate) -> Unit = { _, _ -> }, + val onAirTriggerVibration: (Boolean) -> Unit = {}, + val onAirTriggerScreenLight: (Boolean) -> Unit = {}, + val onAirTriggerLed: (AirTriggerLed) -> Unit = {}, val onSuspendPolicy: (String) -> Unit, val onSteamDownloadsInBackground: (Boolean) -> Unit = {}, val onBackActionsInverted: (Boolean) -> Unit, @@ -365,6 +407,8 @@ class DrawerActions( val paused: Boolean = false, val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, val onOrientation: (Int) -> Unit = {}, + val fullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, + val onFullscreenMode: (FullscreenMode) -> Unit = {}, val onResume: () -> Unit = {}, val onPipAutoEnter: (Boolean) -> Unit = {}, val unfoldedControls: Boolean? = null, @@ -378,6 +422,8 @@ class DrawerActions( val quickButtons: Map = emptyMap(), val onQuickButton: (com.droiddeck.launcher.input.InputCommand, Boolean) -> Unit = { _, _ -> }, val onUnfoldedControls: (Boolean) -> Unit = {}, + val deckPanel: com.droiddeck.launcher.input.DeckPanel? = null, + val onDeckPanel: (com.droiddeck.launcher.input.DeckPanel) -> Unit = {}, val unfoldedControlsWithController: Boolean = false, val onUnfoldedControlsWithController: (Boolean) -> Unit = {}, val onShareLogs: () -> Unit, @@ -418,7 +464,7 @@ class DrawerActions( @Composable internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, controllerActive: Boolean, onPageChange: (SessionDrawerPage) -> Unit, a: DrawerActions, docked: Boolean = false, backRequest: Int = 0, onLayerChange: (Boolean) -> Unit = {}) { - val pages = sessionDrawerPages(a.glassesPresent) + val pages = sessionDrawerPages(a.achievementsGame != null) val page = requestedPage.takeIf { it in pages } ?: pages.first() var managing by rememberSaveable { mutableStateOf(false) } var releaseSignal by remember { mutableStateOf(0) } @@ -428,37 +474,32 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont val pal = LocalPalette.current val host = rememberMenuHost() val (glasses, glassesSettings) = rememberGlasses() - val glassesPages = glassesTabs(glasses) + (GlassesTab.CONTROLLERS to stringResource(R.string.vr_controllers_tab)) - var selectedGlassesTab by rememberSaveable { mutableStateOf(GlassesTab.DISPLAY) } - val glassesTab = selectedGlassesTab.takeIf { key -> glassesPages.any { it.first == key } } ?: GlassesTab.DISPLAY - var androidAppsExpanded by rememberSaveable { mutableStateOf(false) } - var advancedEffectsExpanded by rememberSaveable { mutableStateOf(false) } + remember { DrawerSectionState.load(drawerContext) } var appToChooseDisplay by remember { mutableStateOf(null) } var confirmStop by remember { mutableStateOf(false) } + var airTriggersShown by remember { mutableStateOf(false) } var sheetCoords by remember { mutableStateOf(null) } val widthContext = LocalContext.current var savedWidth by remember { mutableStateOf(SessionPrefs.drawerWidthDp(widthContext)) } var stopCoords by remember { mutableStateOf(null) } val pageScroll = remember { SessionDrawerPage.entries.associateWith { ScrollState(0) } } - LaunchedEffect(glassesTab) { - if (page == SessionDrawerPage.GLASSES) host.open = null - pageScroll.getValue(SessionDrawerPage.GLASSES).scrollTo(0) - } val veil by animateFloatAsState(if (open) 1f else 0f, Motion.tw(260), label = "veil") val focus = remember { DrawerFocus() } val inputModeManager = LocalInputModeManager.current val focusManager = LocalFocusManager.current // A page kept inside More is one step deeper than the strip: back returns to More before it closes the menu. val insideMore = page in pages.inMore() + val airPanel = airTriggersShown && page == SessionDrawerPage.CONTROLLER && a.airTriggers != null BackHandler(enabled = open) { when { host.open != null -> host.open = null + airPanel -> airTriggersShown = false insideMore -> onPageChange(SessionDrawerPage.MORE) else -> a.onClose() } } BackHandler(enabled = open && confirmStop) { confirmStop = false } - val layerOpen = open && (host.open != null || appToChooseDisplay != null || confirmStop || insideMore) + val layerOpen = open && (host.open != null || appToChooseDisplay != null || confirmStop || insideMore || airPanel) LaunchedEffect(layerOpen) { onLayerChange(layerOpen) } var seenBackRequest by remember { mutableStateOf(backRequest) } LaunchedEffect(backRequest) { @@ -468,10 +509,30 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont confirmStop -> confirmStop = false appToChooseDisplay != null -> appToChooseDisplay = null host.open != null -> host.open = null + airPanel -> airTriggersShown = false insideMore -> onPageChange(SessionDrawerPage.MORE) } } - LaunchedEffect(page) { host.open = null; appToChooseDisplay = null; managing = false } + LaunchedEffect(page) { host.open = null; appToChooseDisplay = null; managing = false; airTriggersShown = false } + var airPanelFocused by remember { mutableStateOf(airPanel) } + LaunchedEffect(airPanel) { + val moved = airPanel != airPanelFocused + airPanelFocused = airPanel + if (!moved || !open || !controllerActive) return@LaunchedEffect + val target = if (airPanel) "air-triggers-toggle" else "air-triggers" + repeat(24) { + androidx.compose.runtime.withFrameNanos { } + focus.request(target) + if (focus.focused == target) return@LaunchedEffect + } + } + LaunchedEffect(host.open) { + if (host.open == "frame-generation") repeat(24) { + androidx.compose.runtime.withFrameNanos { } + focus.request("frame-generation") + if (focus.focused == "frame-generation") return@LaunchedEffect + } + } LaunchedEffect(a.selectedGameProfileId) { if (host.open == "fex") host.open = null } @@ -492,7 +553,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont if (open && !controllerActive) focusManager.clearFocus(force = true) } var focusedPage by remember { mutableStateOf(page) } - LaunchedEffect(open, page, glassesTab, controllerActive, host.open, appToChooseDisplay, confirmStop) { + LaunchedEffect(open, page, controllerActive, host.open, appToChooseDisplay, confirmStop) { if (!open) { host.open = null confirmStop = false @@ -501,24 +562,19 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont if (host.open != null || appToChooseDisplay != null || confirmStop) return@LaunchedEffect val turned = page != focusedPage focusedPage = page - val first = when { - page == SessionDrawerPage.GLASSES -> "glasses-tab-$glassesTab" - page == SessionDrawerPage.SESSION && a.isHomeApp -> "apps" - else -> page.firstControl - } if (turned) focus.forget(page) - val target = focus.target(page) ?: first + val target = focus.target(page) ?: page.firstControl repeat(24) { androidx.compose.runtime.withFrameNanos { } focus.request(target) if (focus.focused == target) return@LaunchedEffect } focus.forget(page) - focus.request(first) - if (first != page.firstControl) repeat(4) { + // Which sections a page shows depends on the session, so the first one shown takes focus. + for (key in listOf(page.firstControl) + focus.sections(page)) repeat(2) { androidx.compose.runtime.withFrameNanos { } - if (focus.focused == first) return@LaunchedEffect - focus.request(page.firstControl) + focus.request(key) + if (focus.focused == key) return@LaunchedEffect } } } @@ -533,8 +589,8 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } androidx.compose.foundation.layout.BoxWithConstraints(modifier = Modifier.fillMaxSize().exposeTestTags(), contentAlignment = Alignment.CenterEnd) { val short = maxHeight < 440.dp - // The handle keeps a strip on the left free, so a sheet dragged wide can always be dragged back. - val maxSheet = (maxWidth - DRAWER_EDGE_GAP).coerceAtLeast(0.dp) + // At full width the handle's strip sits on the screen's left edge, so the sheet can still be dragged back. + val maxSheet = (maxWidth - DRAWER_HANDLE_STRIP).coerceAtLeast(0.dp) val minSheet = minOf(DRAWER_MIN_WIDTH, maxSheet) val defaultSheet = minOf(420.dp, maxWidth * 0.92f) val sheetWidth = if (docked) maxWidth else (savedWidth?.dp ?: defaultSheet).coerceIn(minSheet, maxSheet) @@ -555,6 +611,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont .controllerBack { when { host.open != null -> host.open = null + airPanel -> airTriggersShown = false managing -> DrawerPages.heldFrom?.let { held -> DrawerPages.rearrange(drawerContext, held) releaseSignal++ @@ -587,13 +644,6 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont focus.track(page, "screen").testTag("drawer-screen-picker"), ) } else if (roomyHeader) Spacer(Modifier.weight(1f)) - SteamActionPill( - stringResource(if (a.paused) R.string.resume_session else R.string.stores_dl_pause), - if (a.paused) Icons.Outlined.PlayArrow else Icons.Outlined.Pause, focus.track(page, "pause"), - ) { host.open = null; if (a.paused) a.onResume() else a.onPause() } - if (a.pipSupported) SteamActionPill( - stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"), - ) { host.open = null; a.onPip() } val steamActions = a.steam && a.onSteamMenu != null && a.onQam != null val qamInteraction = remember { MutableInteractionSource() } var qamStartedOnPress by remember { mutableStateOf(false) } @@ -626,12 +676,6 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true } } - a.onAchievements?.let { show -> - DrawerAchievementsRow(a.achievementsProgress, Modifier.padding(top = if (short) 6.dp else 10.dp).then(focus.track(page, "achievements"))) { - host.open = null; show() - } - } - Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(top = 6.dp), @@ -644,16 +688,14 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont host.open = null; onPageChange(pages.strip().step(pages.tabFor(page), 1)) } } - if (insideMore && !managing) DrawerMoreBack(stringResource(page.title), focus.track(page, "more-back")) { host.open = null; onPageChange(SessionDrawerPage.MORE) } + if (insideMore && !managing && !airPanel) DrawerMoreBack(stringResource(page.title), focus.track(page, "more-back")) { host.open = null; onPageChange(SessionDrawerPage.MORE) } + if (airPanel && !managing) DrawerMoreBack(stringResource(R.string.air_triggers_title), focus.track(page, "air-triggers-back"), + parent = stringResource(page.title)) { host.open = null; airTriggersShown = false } if (managing) ManageDrawerPages( - offeredDrawerPages(a.glassesPresent), + offeredDrawerPages(a.achievementsGame != null), Modifier.weight(1f).fillMaxWidth().padding(top = 8.dp, start = 14.dp, end = 14.dp), releaseSignal, ) { managing = false } else { - if (page == SessionDrawerPage.GLASSES) SegmentedTabs( - glassesPages, glassesTab, modifier = Modifier.fillMaxWidth().padding(top = 8.dp), - tabModifier = { key -> focus.track(page, "glasses-tab-$key").testTag("glasses-tab-$key") }, - ) { selectedGlassesTab = it } // The agent's chat scrolls itself and keeps its composer at the bottom, so it takes the height left. if (page == SessionDrawerPage.AGENT) AgentPageWithControls( Modifier.weight(1f).fillMaxWidth().padding(top = 8.dp, start = 14.dp, end = 14.dp), @@ -663,377 +705,31 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont showControlsWithoutKeyboard = true, ) else Column( modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(pageScroll.getValue(page)), - ) { CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true) { + ) { + val track: (String) -> Modifier = { key -> focus.track(page, key) } + val sections = remember(page) { DrawerSections(drawerContext, track) } + CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true, LocalDrawerSections provides sections) { + DrawerColumns(two = sheetWidth >= DRAWER_TWO_COLUMN_WIDTH && page.inColumns) { when (page) { - SessionDrawerPage.HUD -> DroidDeckHudSettings(host, a) { key -> focus.track(page, key) } - SessionDrawerPage.DISPLAY -> { - SettingsGroup(stringResource(R.string.drawer_page_display)) { - if (a.gameZoomAvailable) SettingsRow( - stringResource(R.string.game_zoom_title), - stringResource(R.string.game_zoom_hint), - ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - val zoomOutEnabled = a.gameZoom > 1.0f - val zoomInEnabled = a.gameZoom < 3.0f - val zoomResetEnabled = a.gameZoom > 1.0f - val zoomOut = { a.onGameZoom((a.gameZoom - 0.25f).coerceAtLeast(1.0f)) } - val zoomIn = { a.onGameZoom((a.gameZoom + 0.25f).coerceAtMost(3.0f)) } - val zoomReset = { a.onGameZoom(1.0f) } - - OutlinedButton( - onClick = zoomOut, - enabled = zoomOutEnabled, - modifier = focus.track(page, "game-zoom-out").width(42.dp) - .controllerConfirm(enabled = zoomOutEnabled, onClick = zoomOut), - contentPadding = PaddingValues(horizontal = 4.dp, vertical = 0.dp), - ) { Text("−") } - Text("${(a.gameZoom * 100.0f).toInt()}%", fontSize = 12.sp) - OutlinedButton( - onClick = zoomIn, - enabled = zoomInEnabled, - modifier = focus.track(page, "game-zoom-in").width(42.dp) - .controllerConfirm(enabled = zoomInEnabled, onClick = zoomIn), - contentPadding = PaddingValues(horizontal = 4.dp, vertical = 0.dp), - ) { Text("+") } - OutlinedButton( - onClick = zoomReset, - enabled = zoomResetEnabled, - modifier = focus.track(page, "game-zoom-reset").width(48.dp) - .controllerConfirm(enabled = zoomResetEnabled, onClick = zoomReset), - contentPadding = PaddingValues(horizontal = 2.dp, vertical = 0.dp), - ) { Text("1×") } - } - } - val fgOpen = host.open == "fg" - val offLabel = stringResource(R.string.frame_gen_off) - val fgLabel = FrameGen.label(LocalContext.current, a.frameGen) - SettingsRow( - stringResource(R.string.frame_gen_title), - if (a.frameGenTargetGameId != null) - "${stringResource(R.string.frame_gen_scope_game)} · ${a.frameGenTargetGameName ?: "ID ${a.frameGenTargetGameId}"}" - else stringResource(R.string.frame_gen_scope_global), - highlighted = fgOpen - ) { - Box { - ValueChip(fgLabel, fgOpen, modifier = focus.track(page, "fg")) { host.open = if (fgOpen) null else "fg" } - FrameGenMenu( - host, a.frameGen, a.lossless, a.onFrameGenPick, a.onImportLossless, - gameProfileId = a.frameGenTargetGameId, - hasGameOverride = a.hasGameOverride, - onResetGame = a.onFrameGenReset, - ) - } - } - if (a.direct) SliderRow( - stringResource(R.string.drawer_frame_limit), stringResource(R.string.drawer_frame_limit_note), - a.fpsLimit.takeIf { it > 0 } ?: SessionPrefs.FPS_LIMIT_OFF, - SessionPrefs.FPS_LIMIT_OFF..SessionPrefs.FPS_LIMIT_MAX, step = 5, - format = { if (it <= SessionPrefs.FPS_LIMIT_OFF) offLabel else it.toString() }, - modifier = focus.track(page, "fps-limit"), - onChange = { a.onFpsLimit(if (it <= SessionPrefs.FPS_LIMIT_OFF) 0 else it) }) - if (a.steam && !a.direct && a.onQam != null) SettingsRow( - stringResource(R.string.drawer_frame_limit), stringResource(R.string.drawer_frame_limit_steam_hint), - ) { - DrawerOutlineButton(stringResource(R.string.drawer_open_steam_qam), modifier = focus.track(page, "fps-limit-steam")) { - host.open = null - a.onQam?.invoke() - } - } - } - SettingsGroup(stringResource(R.string.setup_orientation)) { - ChoiceRow(host, "orientation", stringResource(R.string.setup_session_orientation), null, - SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) }, - a.orientation, chipModifier = focus.track(page, "orientation"), onPick = a.onOrientation) - } - SettingsGroup(stringResource(R.string.display_image_scaling)) { - if (a.steam) SettingsRow(stringResource(R.string.display_integer_scaling), null) { - PadTextButton( - onClick = { a.onIntegerScaling(!a.integerScaling) } - ) { - Text(stringResource( - if (a.integerScaling) R.string.display_scaling_integer - else R.string.display_scaling_fit - )) - } - } - ChoiceRow(host, "upscaler", stringResource(R.string.display_filter), null, - SessionPrefs.upscalerChoices(LocalContext.current), a.upscaler, - note = stringResource(R.string.display_filter_note), - chipModifier = focus.track(page, "upscaler"), onPick = a.onUpscaler) - if (SessionPrefs.upscalerHasSharpness(a.upscaler)) SliderRow( - stringResource(R.string.display_sharpness), null, a.upscaleSharpness, 0..100, step = 5, - format = { "$it%" }, modifier = focus.track(page, "upscale-sharpness"), onChange = a.onUpscaleSharpness) - } - SecondScreenGroup(host, a) { key -> focus.track(page, key) } - } - SessionDrawerPage.EFFECTS -> { - ScreenEffectsGroup(host, a, advancedEffectsExpanded, - onAdvancedToggle = { advancedEffectsExpanded = !advancedEffectsExpanded }) { key -> focus.track(page, key) } - } - SessionDrawerPage.VR -> { - SteamVrGroup(a) { key -> focus.track(page, key) } - if (!a.glassesOutput) CardboardGroup(host, a) { key -> focus.track(page, key) } - } SessionDrawerPage.CONTROLLER -> { - SettingsGroup(stringResource(R.string.drawer_page_controller)) { - InputQuickSettings(host, desktop = a.desktop, onChanged = a.onInputSelection, onEdit = a.onInputSettings) { key -> focus.track(page, key) } - } - SettingsGroup(stringResource(R.string.input_device_settings)) { - a.padType?.let { type -> - ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint), - listOf(SessionPrefs.CONTROLLER_DECK to stringResource(R.string.mode_controller_deck), - SessionPrefs.CONTROLLER_STEAM to stringResource(R.string.mode_controller_steam), - SessionPrefs.CONTROLLER_DS4 to stringResource(R.string.mode_controller_ds4), - SessionPrefs.CONTROLLER_DUALSENSE to stringResource(R.string.mode_controller_dualsense), - SessionPrefs.CONTROLLER_XBOX360 to stringResource(R.string.mode_controller_x360)), - type, chipModifier = focus.track(page, "pad-type"), onPick = a.onPadType) - } - a.controller?.let { c -> - SliderRow(stringResource(R.string.ctrl_size), null, c.size, 80..125, step = 5, - format = { "$it%" }, modifier = focus.track(page, "controller-size"), - onChange = a.onControllerSize) - ToggleRow(host, "rumble", stringResource(R.string.ctrl_rumble), null, c.rumble, - chipModifier = focus.track(page, "rumble"), onChange = a.onRumble) - } - } - SettingsGroup(stringResource(R.string.input_touchscreen)) { - ChoiceRow(host, "touch", stringResource(R.string.input_touchscreen), stringResource(R.string.input_touchscreen_hint), - listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.drawer_touch_auto, a.touchAuto), SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_direct), SessionPrefs.TOUCH_GESTURES to stringResource(R.string.mode_touch_gestures), SessionPrefs.TOUCH_OFF to stringResource(R.string.widgets_off)), - a.touchMode, chipModifier = focus.track(page, "touch"), onPick = a.onTouch) - if (a.touchActive == SessionPrefs.TOUCH_PAD) - RelativeMouseRow(host, a, focus.track(page, "relative-mouse")) - if (a.touchActive == SessionPrefs.TOUCH_DIRECT) - ToggleRow(host, "direct-cursor", stringResource(R.string.input_touch_cursor), - stringResource(R.string.input_touch_cursor_hint), a.directCursor, - chipModifier = focus.track(page, "direct-cursor"), onChange = a.onDirectCursor) - when (a.touchActive) { - SessionPrefs.TOUCH_GESTURES -> ActionRow(stringResource(R.string.gesture_settings), null, - stringResource(R.string.ctrl_edit), a.onGestureSettings, - modifier = focus.track(page, "gesture-settings")) - SessionPrefs.TOUCH_DIRECT -> ChoiceRow(host, "long-press", stringResource(R.string.input_touch_hold), stringResource(R.string.input_touch_hold_hint), - listOf(MOUSE_BEHAVIOR_NONE to stringResource(R.string.gesture_hold_left), - MOUSE_BEHAVIOR_CLICK to stringResource(R.string.gesture_right_click), - MOUSE_BEHAVIOR_HOLD to stringResource(R.string.gesture_hold_right)), - a.directHoldBehavior, chipModifier = focus.track(page, "long-press"), - onPick = a.onDirectHoldBehavior) - } - } - a.pen?.let { PenSettingsGroup(host, it, track = { key -> focus.track(page, key) }, onPick = a.onPen) } - SettingsGroup(stringResource(R.string.input_screen_visibility)) { - ChoiceRow(host, "osc", stringResource(R.string.mode_osc), null, - if (a.steam) listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_STEAM_TOUCH to stringResource(R.string.osc_steam_touch), SessionPrefs.OSC_STEAM_QAM to stringResource(R.string.mode_osc_qam), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)) - else listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)), - if (!a.steam && a.oscMode == SessionPrefs.OSC_STEAM_TOUCH) SessionPrefs.OSC_AUTO else a.oscMode, - chipModifier = focus.track(page, "osc"), onPick = a.onOsc) - a.adaptiveSticks?.let { on -> - ToggleRow(host, "adaptive-sticks", stringResource(R.string.ctrl_adaptive), null, on, - chipModifier = focus.track(page, "adaptive-sticks"), onChange = a.onAdaptiveSticks) - } - if (a.showFloatingSteamControls) { - ToggleRow(host, "rear-buttons", stringResource(R.string.osc_rear_buttons), null, a.oscRearButtons, - chipModifier = focus.track(page, "rear-buttons"), onChange = a.onOscRearButtons) - ToggleRow(host, "trackpads", stringResource(R.string.osc_trackpads), null, a.oscTrackpads, - chipModifier = focus.track(page, "trackpads"), onChange = a.onOscTrackpads) - } - for ((button, shown) in a.quickButtons) { - val key = "quick-${button.name.lowercase()}" - ToggleRow(host, key, stringResource(quickButtonLabel(button)), null, shown, - chipModifier = focus.track(page, key)) { a.onQuickButton(button, it) } - } - a.onEditSteamTouch?.let { edit -> - ActionRow(stringResource(R.string.osc_steam_layout), stringResource(R.string.osc_steam_layout_hint), stringResource(R.string.ctrl_edit), edit) - } - if (a.steam && a.unfoldedControls != null) ToggleRow(host, "unfolded-controls", stringResource(R.string.unfolded_controls), - stringResource(R.string.unfolded_controls_hint), a.unfoldedControls, - chipModifier = focus.track(page, "unfolded-controls"), onChange = a.onUnfoldedControls) - if (a.steam && a.unfoldedControls == true) ToggleRow(host, "unfolded-controls-with-controller", - stringResource(R.string.unfolded_controls_with_controller), - stringResource(R.string.unfolded_controls_with_controller_hint), a.unfoldedControlsWithController, - chipModifier = focus.track(page, "unfolded-controls-with-controller"), - onChange = a.onUnfoldedControlsWithController) - } - SettingsGroup(stringResource(R.string.shortcuts_title)) { - if (a.steam) ToggleRow(host, "back-hold", stringResource(R.string.back_hold), - stringResource(R.string.back_hold_hint), a.backHold, - chipModifier = focus.track(page, "back-hold"), onChange = a.onBackHold) - if (a.steam) ChoiceRow(host, "back-actions", stringResource(R.string.input_back_taps), stringResource(R.string.input_back_taps_hint), - listOf(false to stringResource(SessionPrefs.BACK_MENU_THEN_QAM), true to stringResource(SessionPrefs.BACK_QAM_THEN_MENU)), - a.backActionsInverted, chipModifier = focus.track(page, "back-actions"), onPick = a.onBackActionsInverted) - if (a.steam) ChoiceRow(host, "back-double-tap", stringResource(R.string.back_double_tap_window), null, - SessionPrefs.BACK_DOUBLE_TAP_MS_OPTIONS.map { it to stringResource(R.string.back_tap_ms, it) }, - a.backDoubleTapMs, chipModifier = focus.track(page, "back-double-tap"), onPick = a.onBackDoubleTapMs) - PhysicalShortcutRows(modifierFor = { focus.track(page, "physical-shortcut-${it.name}") }) - if (a.secondScreenDisplays.isNotEmpty()) ToggleRow(host, "docked-menu-controller", stringResource(R.string.drawer_docked_menu_controller), - null, a.dockedMenuController, - chipModifier = focus.track(page, "docked-menu-controller"), onChange = a.onDockedMenuController) - ToggleRow(host, "corner-tap", stringResource(R.string.drawer_corner_tap), - stringResource(R.string.drawer_corner_tap_hint), a.cornerTap, - chipModifier = focus.track(page, "corner-tap"), onChange = a.onCornerTap) - } - SettingsGroup(stringResource(R.string.drawer_latency)) { - ToggleRow(host, "low-latency", stringResource(R.string.drawer_low_latency), - stringResource(R.string.drawer_low_latency_hint), a.lowLatency, - chipModifier = focus.track(page, "low-latency"), onChange = a.onLowLatency) - ToggleRow(host, "evdev-mouse", stringResource(R.string.drawer_evdev_mouse), - null, a.evdevMouse, - chipModifier = focus.track(page, "evdev-mouse"), onChange = a.onEvdevMouse) - if (a.touchActive != SessionPrefs.TOUCH_PAD) - RelativeMouseRow(host, a, focus.track(page, "relative-mouse")) - } - SettingsGroup(stringResource(R.string.drawer_keyboard)) { - Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(8.dp)) { - DrawerOutlineButton(stringResource(R.string.drawer_pc_keyboard), modifier = Modifier.weight(1f).height(48.dp).then(focus.track(page, "hardware"))) { - host.open = null; a.onHardwareKeyboard() - } - DrawerOutlineButton(stringResource(R.string.drawer_android_keyboard), modifier = Modifier.weight(1f).height(48.dp).then(focus.track(page, "android"))) { - host.open = null; a.onKeyboard() - } - } - if (a.wowChatShown) ChoiceRow( - host, "wow-chat", stringResource(R.string.wow_chat_title), null, - listOf( - null to stringResource(R.string.wow_chat_ask), - SessionPrefs.WOW_CHAT_VOICE to stringResource(R.string.wow_chat_voice), - SessionPrefs.WOW_CHAT_KEYBOARD to stringResource(R.string.pckb_android), - ), - a.wowChat, chipModifier = focus.track(page, "wow-chat"), onPick = a.onWowChat, - ) - val keyboardContext = LocalContext.current - remember { PcKeyboardPrefs.load(keyboardContext) } - SliderRow( - stringResource(R.string.pckb_size), stringResource(R.string.pckb_size_hint), - PcKeyboardPrefs.size, SessionPrefs.PC_KEYBOARD_SIZE_RANGE, step = 1, - format = { "$it%" }, modifier = focus.track(page, "pckb-size"), - onChange = { PcKeyboardPrefs.setSize(keyboardContext, it) }) - SliderRow( - stringResource(R.string.pckb_opacity), stringResource(R.string.pckb_opacity_hint), - PcKeyboardPrefs.opacity, SessionPrefs.PC_KEYBOARD_OPACITY_RANGE, step = 5, - format = { "$it%" }, modifier = focus.track(page, "pckb-opacity"), - onChange = { PcKeyboardPrefs.setOpacity(keyboardContext, it) }) - MultiRow( - host, "pckb-hidden", stringResource(R.string.pckb_hidden_keys), - stringResource(R.string.pckb_hidden_keys_hint), - listOf( - 0 to stringResource(R.string.pckb_group_function), - 1 to stringResource(R.string.pckb_group_nav), - 2 to stringResource(R.string.pckb_group_arrows), - ), - PC_KEY_GROUP_IDS.filterValues { it in PcKeyboardPrefs.hiddenKeys }.keys, - onToggle = { id, on -> PcKeyboardPrefs.toggleHiddenKey(keyboardContext, PC_KEY_GROUP_IDS.getValue(id), on) }) - } + val airTriggers = a.airTriggers + if (airPanel && airTriggers != null) AirTriggersPanel(host, airTriggers, a, track) + else DrawerControllerPage(host, a, a.controllerConnected || controllerActive, track) { host.open = null; airTriggersShown = true } } - SessionDrawerPage.GLASSES -> if (glassesTab == GlassesTab.CONTROLLERS) { - VrControllerGroups(host) { key -> focus.track(page, key) } - } else { - GlassesGroups(host, glasses, glassesSettings, { key -> focus.track(page, key) }, onRecenter = a.onGlassesRecenter, - tab = glassesTab, outputActive = a.glassesOutput, steamVrRunning = a.steamVr == SteamVr.Status.RUNNING, - steamVr = { SteamVrRow(a) }) - } - SessionDrawerPage.GAMES -> { - if (a.steam || a.direct) SelectedGameProfileGroup(host, a) { key -> focus.track(page, key) } - Text(stringResource(R.string.fex_next_launch), fontSize = 12.sp, - color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) - TextureFilteringGroup(host, a) { key -> focus.track(page, key) } - if (a.steam || a.direct) SettingsGroup(stringResource(R.string.game_settings_title)) { - DrawerFexPresetRow(host, a, focus.track(page, "fex")) - DrawerNoSteamRow(host, a, focus.track(page, "no-steam")) - GameEnvironmentRow( - modifier = focus.track(page, "game-env"), - showHint = false, - initialScope = a.selectedGameProfileId?.toString().orEmpty(), - ) - } - ComponentsDrawerPage(host, a) { key -> focus.track(page, key) } - ComponentDownloadsDrawerGroup( - host = host, - catalog = a.componentCatalog, - catalogAt = a.componentCatalogAt, - checking = a.componentCatalogChecking, - packages = a.components?.packages.orEmpty(), - downloads = a.componentDownloads, - onRefresh = a.onComponentCatalogRefresh, - onDownload = a.onComponentDownload, - track = { key -> focus.track(page, key) }, - ) + SessionDrawerPage.HUD -> DrawerPerformancePage(host, a, track) + SessionDrawerPage.FRAMEGEN -> DrawerFrameGenPage(host, a, track) + SessionDrawerPage.DISPLAY -> DrawerDisplayPage(host, a, track) + SessionDrawerPage.EFFECTS -> ScreenEffectsGroup(host, a, track) + SessionDrawerPage.GAMES -> DrawerGamePage(host, a, track) + SessionDrawerPage.VR -> DrawerVrPage(host, a, glasses, glassesSettings, track) + SessionDrawerPage.SESSION -> DrawerSessionPage(host, a, track) { app -> + host.open = null + if (a.secondScreenDisplays.isEmpty()) a.onLaunchAndroidApp(app, null) else appToChooseDisplay = app } + SessionDrawerPage.MORE -> DrawerMorePage(host, pages.inMore(), a, { host.open = null; onPageChange(it) }, { host.open = null; managing = true }, track) + SessionDrawerPage.ACHIEVEMENTS -> a.achievementsGame?.let { DrawerAchievementsPage(it, a.achievementsTitle, track) } SessionDrawerPage.AGENT -> Unit - SessionDrawerPage.MORE -> DrawerMorePage(host, pages.inMore(), { host.open = null; onPageChange(it) }, { host.open = null; managing = true }) { key -> focus.track(page, key) } - SessionDrawerPage.SESSION -> { - SettingsGroup(stringResource(R.string.drawer_support)) { - SettingsRow(stringResource(R.string.report_problem), stringResource(R.string.report_problem_hint)) { - DrawerOutlineButton(stringResource(R.string.drawer_share_logs), modifier = focus.track(page, "share-logs"), - progress = com.droiddeck.launcher.session.SessionLogShare.progress) { - host.open = null - a.onShareLogs() - } - } - } - if (a.isHomeApp) SettingsGroup(stringResource(R.string.drawer_android_apps)) { - SettingsRow(stringResource(R.string.drawer_launch_app), null) { - DrawerOutlineButton(if (androidAppsExpanded) stringResource(R.string.common_hide) else stringResource(R.string.common_show), modifier = focus.track(page, "apps")) { - androidAppsExpanded = !androidAppsExpanded - } - } - if (androidAppsExpanded) { - if (a.androidApps.isEmpty()) { - Text(stringResource(R.string.drawer_no_apps), fontSize = 12.sp, color = colors.onSurfaceVariant, - modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) - } else for (app in a.androidApps) { - MenuItem( - app.label, checked = false, - modifier = focus.track(page, "app:${app.packageName}/${app.className}"), - leading = { - app.icon?.let { icon -> - Image(bitmap = icon.asImageBitmap(), contentDescription = null, - modifier = Modifier.size(26.dp).clip(RoundedCornerShape(6.dp))) - } - }, - ) { - host.open = null - if (a.secondScreenDisplays.isEmpty()) a.onLaunchAndroidApp(app, null) - else appToChooseDisplay = app - } - } - } - } - SettingsGroup(stringResource(R.string.drawer_session_behavior)) { - if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic), - stringResource(R.string.drawer_mic_hint), a.micEnabled, - chipModifier = focus.track(page, "microphone"), onChange = a.onMicEnabled) - ChoiceRow( - host, "suspend", stringResource(R.string.mode_suspend), - null, - listOf( - SessionPrefs.SUSPEND_AUTO to stringResource(R.string.common_auto), - SessionPrefs.SUSPEND_MANUAL to stringResource(R.string.mode_suspend_manual), - SessionPrefs.SUSPEND_NEVER to stringResource(R.string.common_never), - ) + if (a.steam) listOf( - SessionPrefs.SUSPEND_NATIVE to stringResource(R.string.mode_suspend_native), - ) else emptyList(), - a.suspendPolicy, - note = stringResource(if (a.steam) R.string.mode_suspend_steam_note else R.string.mode_suspend_note), - chipModifier = focus.track(page, "suspend"), - onPick = a.onSuspendPolicy, - ) - if (a.steam && a.suspendPolicy != SessionPrefs.SUSPEND_NEVER) ToggleRow( - host, "background-downloads", stringResource(R.string.mode_background_downloads), - stringResource(R.string.mode_background_downloads_hint), - a.steamDownloadsInBackground, - onChange = a.onSteamDownloadsInBackground, - ) - } - if (a.pipSupported) SettingsGroup(stringResource(R.string.pip_title)) { - ToggleRow(host, "pip-auto", stringResource(R.string.pip_auto), null, - a.pipAutoEnter, onChange = a.onPipAutoEnter) - } - Column(Modifier.fillMaxWidth().padding(top = 12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { - if (!a.isHomeApp) DrawerActionButton(stringResource(R.string.drawer_background), Icons.AutoMirrored.Outlined.ExitToApp, - modifier = focus.track(page, "background")) { host.open = null; a.onBackground() } - } - } + } } } } } @@ -1078,6 +774,447 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } } +@Composable +private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected: Boolean, track: (String) -> Modifier, onAirTriggers: () -> Unit) { + val on = stringResource(R.string.widgets_on) + val off = stringResource(R.string.widgets_off) + val padTag = if (padConnected) stringResource(R.string.drawer_tag_controller) else null + val noPadTag = if (padConnected) null else stringResource(R.string.drawer_tag_no_controller) + SettingsGroup(stringResource(R.string.drawer_section_input), key = "controller-input") { + InputQuickSettings(host, desktop = a.desktop, onChanged = a.onInputSelection, onEdit = a.onInputSettings, track = track) + } + val c = a.controller + val padTypes = listOf(SessionPrefs.CONTROLLER_DECK to stringResource(R.string.mode_controller_deck), + SessionPrefs.CONTROLLER_STEAM to stringResource(R.string.mode_controller_steam), + SessionPrefs.CONTROLLER_DS4 to stringResource(R.string.mode_controller_ds4), + SessionPrefs.CONTROLLER_DUALSENSE to stringResource(R.string.mode_controller_dualsense), + SessionPrefs.CONTROLLER_XBOX360 to stringResource(R.string.mode_controller_x360)) + val rumbleLabel = stringResource(R.string.ctrl_rumble) + val airTriggers = a.airTriggers + val airTriggersLabel = stringResource(R.string.air_triggers_title) + if (a.padType != null || c != null || airTriggers != null) SettingsGroup( + stringResource(R.string.input_device_settings), key = "controller-pad", tag = padTag, + detail = summary(a.padType?.let { padTypes.labelOf(it) }, c?.let { "$rumbleLabel ${if (it.rumble) on else off}" }, + airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" }), + ) { + a.padType?.let { type -> + ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint), + padTypes, type, chipModifier = track("pad-type"), onPick = a.onPadType) + } + c?.let { + ToggleRow(host, "rumble", rumbleLabel, null, it.rumble, chipModifier = track("rumble"), onChange = a.onRumble) + } + airTriggers?.let { + ActionRow(airTriggersLabel, if (it.enabled) on else off, stringResource(R.string.air_triggers_open), onAirTriggers, + modifier = track("air-triggers")) + } + } + val oscChoices = if (a.steam) listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_STEAM_TOUCH to stringResource(R.string.osc_steam_touch), SessionPrefs.OSC_STEAM_QAM to stringResource(R.string.mode_osc_qam), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)) + else listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)) + val oscValue = if (!a.steam && a.oscMode == SessionPrefs.OSC_STEAM_TOUCH) SessionPrefs.OSC_AUTO else a.oscMode + SettingsGroup(stringResource(R.string.input_screen_visibility), key = "controller-osc", tag = noPadTag, + detail = summary(oscChoices.labelOf(oscValue), c?.let { "${it.size}%" })) { + ChoiceRow(host, "osc", stringResource(R.string.mode_osc), null, oscChoices, oscValue, chipModifier = track("osc"), onPick = a.onOsc) + c?.let { + SliderRow(stringResource(R.string.ctrl_size), null, it.size, 80..125, step = 5, + format = { v -> "$v%" }, modifier = track("controller-size"), onChange = a.onControllerSize) + SliderRow(stringResource(R.string.ctrl_opacity), null, it.onScreenOpacity, ControllerPrefs.onScreenOpacityRange, step = 5, + format = { v -> "$v%" }, modifier = track("controller-opacity").testTag("controller-opacity"), + onChange = a.onControllerOpacity) + } + a.adaptiveSticks?.let { adaptive -> + ToggleRow(host, "adaptive-sticks", stringResource(R.string.ctrl_adaptive), null, adaptive, + chipModifier = track("adaptive-sticks"), onChange = a.onAdaptiveSticks) + } + if (a.showFloatingSteamControls) { + ToggleRow(host, "rear-buttons", stringResource(R.string.osc_rear_buttons), null, a.oscRearButtons, + chipModifier = track("rear-buttons"), onChange = a.onOscRearButtons) + ToggleRow(host, "trackpads", stringResource(R.string.osc_trackpads), null, a.oscTrackpads, + chipModifier = track("trackpads"), onChange = a.onOscTrackpads) + } + for ((button, shown) in a.quickButtons) { + val key = "quick-${button.name.lowercase()}" + ToggleRow(host, key, stringResource(quickButtonLabel(button)), null, shown, + chipModifier = track(key)) { a.onQuickButton(button, it) } + } + a.onEditSteamTouch?.let { edit -> + ActionRow(stringResource(R.string.osc_steam_layout), stringResource(R.string.osc_steam_layout_hint), stringResource(R.string.ctrl_edit), edit, + modifier = track("steam-touch-layout")) + } + if (a.steam && a.unfoldedControls != null) ToggleRow(host, "unfolded-controls", stringResource(R.string.unfolded_controls), + stringResource(R.string.unfolded_controls_hint), a.unfoldedControls, + chipModifier = track("unfolded-controls"), onChange = a.onUnfoldedControls) + a.deckPanel?.let { panel -> + ChoiceRow(host, "deck-panel", stringResource(R.string.ctrl_layout), null, + com.droiddeck.launcher.input.DeckPanel.entries.map { it to stringResource(it.label) }, panel, + chipModifier = track("deck-panel"), onPick = a.onDeckPanel) + } + if (a.steam && a.unfoldedControls == true) ToggleRow(host, "unfolded-controls-with-controller", + stringResource(R.string.unfolded_controls_with_controller), + stringResource(R.string.unfolded_controls_with_controller_hint), a.unfoldedControlsWithController, + chipModifier = track("unfolded-controls-with-controller"), + onChange = a.onUnfoldedControlsWithController) + } + val touchChoices = listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.drawer_touch_auto, a.touchAuto), SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_direct), SessionPrefs.TOUCH_GESTURES to stringResource(R.string.mode_touch_gestures), SessionPrefs.TOUCH_OFF to stringResource(R.string.widgets_off)) + SettingsGroup(stringResource(R.string.input_touchscreen), key = "controller-touch", tag = noPadTag, detail = touchChoices.labelOf(a.touchMode)) { + ChoiceRow(host, "touch", stringResource(R.string.input_touchscreen), stringResource(R.string.input_touchscreen_hint), + touchChoices, a.touchMode, chipModifier = track("touch"), onPick = a.onTouch) + if (a.touchActive == SessionPrefs.TOUCH_PAD) RelativeMouseRow(host, a, track("relative-mouse")) + if (a.touchActive == SessionPrefs.TOUCH_DIRECT) + ToggleRow(host, "direct-cursor", stringResource(R.string.input_touch_cursor), + stringResource(R.string.input_touch_cursor_hint), a.directCursor, + chipModifier = track("direct-cursor"), onChange = a.onDirectCursor) + when (a.touchActive) { + SessionPrefs.TOUCH_GESTURES -> ActionRow(stringResource(R.string.gesture_settings), null, + stringResource(R.string.ctrl_edit), a.onGestureSettings, modifier = track("gesture-settings")) + SessionPrefs.TOUCH_DIRECT -> ChoiceRow(host, "long-press", stringResource(R.string.input_touch_hold), stringResource(R.string.input_touch_hold_hint), + listOf(MOUSE_BEHAVIOR_NONE to stringResource(R.string.gesture_hold_left), + MOUSE_BEHAVIOR_CLICK to stringResource(R.string.gesture_right_click), + MOUSE_BEHAVIOR_HOLD to stringResource(R.string.gesture_hold_right)), + a.directHoldBehavior, chipModifier = track("long-press"), onPick = a.onDirectHoldBehavior) + } + } + a.pen?.let { PenSettingsGroup(host, it, track = track, onPick = a.onPen) } + SettingsGroup(stringResource(R.string.drawer_section_mouse), key = "controller-mouse", + detail = "${stringResource(R.string.drawer_evdev_mouse)} ${if (a.evdevMouse) on else off}") { + ToggleRow(host, "evdev-mouse", stringResource(R.string.drawer_evdev_mouse), null, a.evdevMouse, + chipModifier = track("evdev-mouse"), onChange = a.onEvdevMouse) + if (a.touchActive != SessionPrefs.TOUCH_PAD) RelativeMouseRow(host, a, track("relative-mouse")) + } + val backOrders = listOf(false to stringResource(SessionPrefs.BACK_MENU_THEN_QAM), true to stringResource(SessionPrefs.BACK_QAM_THEN_MENU)) + SettingsGroup(stringResource(R.string.shortcuts_title), key = "controller-shortcuts", + detail = if (a.steam) summary(backOrders.labelOf(a.backActionsInverted), stringResource(R.string.back_tap_ms, a.backDoubleTapMs)) else null) { + if (a.steam) ToggleRow(host, "back-hold", stringResource(R.string.back_hold), + stringResource(R.string.back_hold_hint), a.backHold, + chipModifier = track("back-hold"), onChange = a.onBackHold) + if (a.steam) ChoiceRow(host, "back-actions", stringResource(R.string.input_back_taps), stringResource(R.string.input_back_taps_hint), + backOrders, a.backActionsInverted, chipModifier = track("back-actions"), onPick = a.onBackActionsInverted) + if (a.steam) ChoiceRow(host, "back-double-tap", stringResource(R.string.back_double_tap_window), null, + SessionPrefs.BACK_DOUBLE_TAP_MS_OPTIONS.map { it to stringResource(R.string.back_tap_ms, it) }, + a.backDoubleTapMs, chipModifier = track("back-double-tap"), onPick = a.onBackDoubleTapMs) + PhysicalShortcutRows(modifierFor = { track("physical-shortcut-${it.name}") }) + if (a.secondScreenDisplays.isNotEmpty()) ToggleRow(host, "docked-menu-controller", stringResource(R.string.drawer_docked_menu_controller), + null, a.dockedMenuController, + chipModifier = track("docked-menu-controller"), onChange = a.onDockedMenuController) + ToggleRow(host, "corner-tap", stringResource(R.string.drawer_corner_tap), + stringResource(R.string.drawer_corner_tap_hint), a.cornerTap, + chipModifier = track("corner-tap"), onChange = a.onCornerTap) + } + val keyboardContext = LocalContext.current + remember { PcKeyboardPrefs.load(keyboardContext) } + SettingsGroup(stringResource(R.string.drawer_section_keyboard_layout), key = "controller-keyboard", + detail = summary("${PcKeyboardPrefs.size}%", "${PcKeyboardPrefs.opacity}%")) { + if (a.wowChatShown) ChoiceRow( + host, "wow-chat", stringResource(R.string.wow_chat_title), null, + listOf( + null to stringResource(R.string.wow_chat_ask), + SessionPrefs.WOW_CHAT_VOICE to stringResource(R.string.wow_chat_voice), + SessionPrefs.WOW_CHAT_KEYBOARD to stringResource(R.string.pckb_android), + ), + a.wowChat, chipModifier = track("wow-chat"), onPick = a.onWowChat, + ) + SliderRow( + stringResource(R.string.pckb_size), stringResource(R.string.pckb_size_hint), + PcKeyboardPrefs.size, SessionPrefs.PC_KEYBOARD_SIZE_RANGE, step = 1, + format = { "$it%" }, modifier = track("pckb-size"), + onChange = { PcKeyboardPrefs.setSize(keyboardContext, it) }) + SliderRow( + stringResource(R.string.pckb_opacity), stringResource(R.string.pckb_opacity_hint), + PcKeyboardPrefs.opacity, SessionPrefs.PC_KEYBOARD_OPACITY_RANGE, step = 5, + format = { "$it%" }, modifier = track("pckb-opacity"), + onChange = { PcKeyboardPrefs.setOpacity(keyboardContext, it) }) + MultiRow( + host, "pckb-hidden", stringResource(R.string.pckb_hidden_keys), + stringResource(R.string.pckb_hidden_keys_hint), + listOf( + 0 to stringResource(R.string.pckb_group_function), + 1 to stringResource(R.string.pckb_group_nav), + 2 to stringResource(R.string.pckb_group_arrows), + ), + PC_KEY_GROUP_IDS.filterValues { it in PcKeyboardPrefs.hiddenKeys }.keys, + onToggle = { id, shown -> PcKeyboardPrefs.toggleHiddenKey(keyboardContext, PC_KEY_GROUP_IDS.getValue(id), shown) }) + } + Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(top = 12.dp)) { + DrawerOutlineButton(stringResource(R.string.drawer_pc_keyboard), modifier = Modifier.weight(1f).height(48.dp).then(track("hardware"))) { + host.open = null; a.onHardwareKeyboard() + } + DrawerOutlineButton(stringResource(R.string.drawer_android_keyboard), modifier = Modifier.weight(1f).height(48.dp).then(track("android"))) { + host.open = null; a.onKeyboard() + } + } +} + +@Composable +private fun DrawerPerformancePage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { + val offLabel = stringResource(R.string.frame_gen_off) + val limit = if (a.direct && a.fpsLimit > 0) "${stringResource(R.string.drawer_frame_limit)} ${a.fpsLimit}" else null + SettingsGroup(stringResource(R.string.drawer_section_pacing), key = "performance-pacing", detail = summary(limit)) { + if (a.direct) SliderRow( + stringResource(R.string.drawer_frame_limit), stringResource(R.string.drawer_frame_limit_note), + a.fpsLimit.takeIf { it > 0 } ?: SessionPrefs.FPS_LIMIT_OFF, + SessionPrefs.FPS_LIMIT_OFF..SessionPrefs.FPS_LIMIT_MAX, step = 5, + format = { if (it <= SessionPrefs.FPS_LIMIT_OFF) offLabel else it.toString() }, + modifier = track("fps-limit"), + onChange = { a.onFpsLimit(if (it <= SessionPrefs.FPS_LIMIT_OFF) 0 else it) }) + if (a.steam && !a.direct && a.onQam != null) SettingsRow( + stringResource(R.string.drawer_frame_limit), stringResource(R.string.drawer_frame_limit_steam_hint), + ) { + DrawerOutlineButton(stringResource(R.string.drawer_open_steam_qam), modifier = track("fps-limit-steam")) { + host.open = null + a.onQam?.invoke() + } + } + if (a.blackFrameInsertionAvailable) ToggleRow(host, "bfi", stringResource(R.string.drawer_bfi), + stringResource(R.string.drawer_bfi_note), a.blackFrameInsertion, + chipModifier = track("bfi"), onChange = a.onBlackFrameInsertion) + ToggleRow(host, "low-latency", stringResource(R.string.drawer_low_latency), + stringResource(R.string.drawer_low_latency_hint), a.lowLatency, + chipModifier = track("low-latency"), onChange = a.onLowLatency) + } + DroidDeckHudSettings(host, a, track) +} + + + +@Composable +private fun DrawerFrameGenSettings(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { + val fgLabel = FrameGen.label(LocalContext.current, a.frameGen) + val scope = if (a.frameGenTargetGameId != null) + "${stringResource(R.string.frame_gen_scope_game)} · ${a.frameGenTargetGameName ?: "ID ${a.frameGenTargetGameId}"}" + else stringResource(R.string.frame_gen_scope_global) + + SettingsGroup(stringResource(R.string.frame_gen_title), compact = true, key = "frame-generation", detail = summary(fgLabel, scope)) { + FrameGenMenu( + mode = a.frameGen, + lossless = a.lossless, + onPick = a.onFrameGenPick, + + gameProfileId = a.frameGenTargetGameId, + hasGameOverride = a.hasGameOverride, + onResetGame = a.onFrameGenReset, + focusModifier = track("frame-generation"), + sessionHost = host, + ) + } +} + +@Composable +private fun DrawerFrameGenPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { + DrawerFrameGenSettings(host, a, track) +} + + +@Composable +private fun DrawerDisplayPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { + val orientations = SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) } + SettingsGroup(stringResource(R.string.drawer_page_display), key = "display", + detail = summary(if (a.gameZoomAvailable) "${(a.gameZoom * 100.0f).toInt()}%" else null, orientations.labelOf(a.orientation))) { + if (a.gameZoomAvailable) GameZoomRow(a.gameZoom, track, a.onGameZoom) + ChoiceRow(host, "orientation", stringResource(R.string.setup_session_orientation), null, + orientations, a.orientation, chipModifier = track("orientation"), onPick = a.onOrientation) + ChoiceRow(host, "session-fullscreen", stringResource(R.string.setup_session_fullscreen), + stringResource(R.string.setup_fullscreen_on), + FullscreenMode.entries.map { it to stringResource(it.label) }, a.fullscreenMode, + chipModifier = track("session-fullscreen"), onPick = a.onFullscreenMode) + if (a.steam) PicturePositionRow(host, a.picturePosition, track("picture-position"), onPick = a.onPicturePosition) + } + val filters = SessionPrefs.upscalerChoices(LocalContext.current) + val integer = stringResource(if (a.integerScaling) R.string.display_scaling_integer else R.string.display_scaling_fit) + SettingsGroup(stringResource(R.string.display_image_scaling), key = "display-scaling", + detail = summary(filters.labelOf(a.upscaler), integer.takeIf { a.steam })) { + if (a.steam) SettingsRow(stringResource(R.string.display_integer_scaling), null) { + PadTextButton(onClick = { a.onIntegerScaling(!a.integerScaling) }, modifier = track("integer-scaling")) { Text(integer) } + } + ChoiceRow(host, "upscaler", stringResource(R.string.display_filter), null, filters, a.upscaler, + note = stringResource(R.string.display_filter_note), + chipModifier = track("upscaler"), onPick = a.onUpscaler) + if (SessionPrefs.upscalerHasSharpness(a.upscaler)) SliderRow( + stringResource(R.string.display_sharpness), null, a.upscaleSharpness, 0..100, step = 5, + format = { "$it%" }, modifier = track("upscale-sharpness"), onChange = a.onUpscaleSharpness) + } + SecondScreenGroup(host, a, track) +} + +private const val GAME_ZOOM_MIN = 100 +private const val GAME_ZOOM_MAX = 300 +private const val GAME_ZOOM_STEP = 25 +private const val GAME_ZOOM_INTERVALS = (GAME_ZOOM_MAX - GAME_ZOOM_MIN) / GAME_ZOOM_STEP + +@Composable +internal fun GameZoomRow( + zoom: Float, + track: (String) -> Modifier, + onZoom: (Float) -> Unit, +) { + val source = remember { MutableInteractionSource() } + val focused by source.collectIsFocusedAsState() + val label = stringResource(R.string.game_zoom_title) + val percent = (zoom * 100f).roundToInt().coerceIn(GAME_ZOOM_MIN, GAME_ZOOM_MAX) + val value = stringResource(R.string.game_zoom_value, percent) + fun detent(value: Float): Int = ((value - GAME_ZOOM_MIN) / GAME_ZOOM_STEP).roundToInt() + val selectedDetent = detent(percent.toFloat()) + val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl + val pal = LocalPalette.current + val colors = MaterialTheme.colorScheme + + fun chooseDetent(index: Int) { + val next = GAME_ZOOM_MIN + index.coerceIn(0, GAME_ZOOM_INTERVALS) * GAME_ZOOM_STEP + if (next != percent) onZoom(next / 100f) + } + Column(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 6.dp)) { + Row( + Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text(label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) + Text(value, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold, + color = colors.onSurface, modifier = Modifier.testTag("game-zoom-value")) + } + Slider( + value = (GAME_ZOOM_MIN + selectedDetent * GAME_ZOOM_STEP).toFloat(), + onValueChange = { chooseDetent(detent(it)) }, + valueRange = GAME_ZOOM_MIN.toFloat()..GAME_ZOOM_MAX.toFloat(), + steps = GAME_ZOOM_INTERVALS - 1, + interactionSource = source, + modifier = track("game-zoom-slider").fillMaxWidth().heightIn(min = 48.dp) + .glideBorder(focused, RoundedCornerShape(10.dp), pal.signal) + .testTag("game-zoom-slider") + .semantics { contentDescription = label; stateDescription = value } + .onPreviewKeyEvent { event -> + val delta = when (event.key) { + Key.DirectionLeft -> if (rtl) 1 else -1 + Key.DirectionRight -> if (rtl) -1 else 1 + else -> return@onPreviewKeyEvent false + } + if (event.type == KeyEventType.KeyDown && event.nativeKeyEvent.repeatCount == 0) { + chooseDetent(selectedDetent + delta) + } + true + }, + ) + } + Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line)) +} + +@Composable +private fun DrawerGamePage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { + val colors = MaterialTheme.colorScheme + if (a.steam || a.direct) SelectedGameProfileGroup(host, a, track) + if (a.steam || a.direct) SettingsGroup(stringResource(R.string.drawer_section_compat), key = "game-compat") { + DrawerFexPresetRow(host, a, track("fex")) + DrawerNoSteamRow(host, a, track("no-steam")) + GameEnvironmentRow( + modifier = track("game-env"), + showHint = false, + initialScope = a.selectedGameProfileId?.toString().orEmpty(), + ) + Text(stringResource(R.string.fex_next_launch), fontSize = 12.sp, + color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 10.dp, vertical = 8.dp)) + } + TextureFilteringGroup(host, a, track) + ComponentsDrawerPage(host, a, track) + ComponentDownloadsDrawerGroup( + host = host, + catalog = a.componentCatalog, + catalogAt = a.componentCatalogAt, + checking = a.componentCatalogChecking, + packages = a.components?.packages.orEmpty(), + downloads = a.componentDownloads, + onRefresh = a.onComponentCatalogRefresh, + onDownload = a.onComponentDownload, + track = track, + ) +} + +@Composable +private fun DrawerVrPage(host: MenuHost, a: DrawerActions, glasses: com.droiddeck.launcher.glasses.GlassesState, + glassesSettings: com.droiddeck.launcher.glasses.GlassesSettings, track: (String) -> Modifier) { + val running = a.steamVr == SteamVr.Status.RUNNING + if (a.glassesPresent) { + GlassesGroups(host, glasses, glassesSettings, track, onRecenter = a.onGlassesRecenter, + outputActive = a.glassesOutput, steamVrRunning = running) + VrControllerGroups(host, track) + } + SteamVrGroup(a, track) + if (!a.glassesOutput) CardboardGroup(host, a, track) +} + +@Composable +private fun DrawerSessionPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier, onLaunch: (HomeApp.LaunchableApp) -> Unit) { + val colors = MaterialTheme.colorScheme + Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + DrawerActionButton(stringResource(if (a.paused) R.string.resume_session else R.string.drawer_pause_game), + if (a.paused) Icons.Outlined.PlayArrow else Icons.Outlined.Pause, modifier = track("pause")) { + host.open = null + if (a.paused) a.onResume() else a.onPause() + } + if (a.pipSupported) DrawerActionButton(stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, modifier = track("pip")) { + host.open = null + a.onPip() + } + } + val suspendChoices = listOf( + SessionPrefs.SUSPEND_AUTO to stringResource(R.string.common_auto), + SessionPrefs.SUSPEND_MANUAL to stringResource(R.string.mode_suspend_manual), + SessionPrefs.SUSPEND_NEVER to stringResource(R.string.common_never), + ) + if (a.steam) listOf(SessionPrefs.SUSPEND_NATIVE to stringResource(R.string.mode_suspend_native)) else emptyList() + SettingsGroup(stringResource(R.string.drawer_session_behavior), key = "session-behavior", + detail = summary(stringResource(R.string.mode_suspend) + " " + suspendChoices.labelOf(a.suspendPolicy).orEmpty())) { + if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic), + stringResource(R.string.drawer_mic_hint), a.micEnabled, + chipModifier = track("microphone"), onChange = a.onMicEnabled) + ChoiceRow( + host, "suspend", stringResource(R.string.mode_suspend), null, suspendChoices, a.suspendPolicy, + note = stringResource(if (a.steam) R.string.mode_suspend_steam_note else R.string.mode_suspend_note), + chipModifier = track("suspend"), onPick = a.onSuspendPolicy, + ) + if (a.steam && a.suspendPolicy != SessionPrefs.SUSPEND_NEVER) ToggleRow( + host, "background-downloads", stringResource(R.string.mode_background_downloads), + stringResource(R.string.mode_background_downloads_hint), a.steamDownloadsInBackground, + chipModifier = track("background-downloads"), onChange = a.onSteamDownloadsInBackground, + ) + if (a.pipSupported) ToggleRow(host, "pip-auto", stringResource(R.string.pip_auto), null, + a.pipAutoEnter, chipModifier = track("pip-auto"), onChange = a.onPipAutoEnter) + } + if (a.isHomeApp) SettingsGroup(stringResource(R.string.drawer_android_apps), key = "session-apps", + detail = a.androidApps.take(3).joinToString(", ") { it.label }) { + if (a.androidApps.isEmpty()) { + Text(stringResource(R.string.drawer_no_apps), fontSize = 12.sp, color = colors.onSurfaceVariant, + modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) + } else for (app in a.androidApps) { + MenuItem( + app.label, checked = false, + modifier = track("app:${app.packageName}/${app.className}"), + leading = { + app.icon?.let { icon -> + Image(bitmap = icon.asImageBitmap(), contentDescription = null, + modifier = Modifier.size(26.dp).clip(RoundedCornerShape(6.dp))) + } + }, + ) { onLaunch(app) } + } + } + // Players reach for Share logs while something is going wrong, so Support never folds. + CompositionLocalProvider(LocalDrawerSections provides null) { SettingsGroup(stringResource(R.string.drawer_support)) { + SettingsRow(stringResource(R.string.report_problem), stringResource(R.string.report_problem_hint)) { + DrawerOutlineButton(stringResource(R.string.drawer_share_logs), modifier = track("share-logs"), + progress = com.droiddeck.launcher.session.SessionLogShare.progress) { + host.open = null + a.onShareLogs() + } + } + } } + if (!a.isHomeApp) Column(Modifier.fillMaxWidth().padding(top = 12.dp)) { + DrawerActionButton(stringResource(R.string.drawer_background), Icons.AutoMirrored.Outlined.ExitToApp, + modifier = track("background")) { host.open = null; a.onBackground() } + } +} + +private fun List>.labelOf(value: T): String? = firstOrNull { it.first == value }?.second + +private fun summary(vararg parts: String?): String = parts.filterNot { it.isNullOrEmpty() }.joinToString(" · ") + @Composable private fun DrawerActionButton(text: String, icon: androidx.compose.ui.graphics.vector.ImageVector, modifier: Modifier = Modifier, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme @@ -1219,7 +1356,16 @@ private fun DrawerPageTabs(page: SessionDrawerPage, pages: List Unit) { +private fun DrawerMoreBack(title: String, modifier: Modifier, parent: String = stringResource(R.string.drawer_page_more), onBack: () -> Unit) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val source = remember { MutableInteractionSource() } val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value val shape = RoundedCornerShape(12.dp) - val label = stringResource(R.string.drawer_more_back, stringResource(R.string.drawer_page_more)) + val label = stringResource(R.string.drawer_more_back, parent) Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier.padding(top = 8.dp, start = 14.dp, end = 14.dp).fillMaxWidth().heightIn(min = 44.dp).clip(shape) @@ -1253,18 +1399,112 @@ private fun DrawerMoreBack(title: String, modifier: Modifier, onBack: () -> Unit .padding(horizontal = 8.dp), ) { Icon(Icons.AutoMirrored.Outlined.ArrowBack, null, tint = colors.onSurfaceVariant, modifier = Modifier.size(22.dp)) - Text(stringResource(R.string.drawer_page_more), fontSize = 13.sp, color = colors.onSurfaceVariant) + Text(parent, fontSize = 13.sp, color = colors.onSurfaceVariant) Text("·", fontSize = 13.sp, color = colors.onSurfaceVariant) Text(title, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) } } +@Composable +private fun AirTriggersPanel(host: MenuHost, t: AirTriggerMenu, a: DrawerActions, track: (String) -> Modifier) { + CompositionLocalProvider(LocalDrawerSections provides null) { SettingsGroup(stringResource(R.string.air_triggers_title)) { + ToggleRow(host, "air-triggers-toggle", stringResource(R.string.air_triggers_use), stringResource(R.string.air_triggers_use_hint), t.enabled, + chipModifier = track("air-triggers-toggle"), onChange = a.onAirTriggers) + ToggleRow(host, "air-triggers-vibration", stringResource(R.string.air_triggers_vibration), stringResource(R.string.air_triggers_vibration_hint), + t.vibration, enabled = t.enabled, chipModifier = track("air-triggers-vibration"), onChange = a.onAirTriggerVibration) + ToggleRow(host, "air-triggers-screen-light", stringResource(R.string.air_triggers_screen_light), stringResource(R.string.air_triggers_screen_light_hint), + t.screenLight, enabled = t.enabled, chipModifier = track("air-triggers-screen-light"), onChange = a.onAirTriggerScreenLight) + val leds = listOf(AirTriggerLed.OFF to R.string.air_triggers_led_off, AirTriggerLed.STEADY to R.string.air_triggers_led_steady, + AirTriggerLed.PULSE to R.string.air_triggers_led_pulse).map { (led, text) -> led to stringResource(text) } + ChoiceRow(host, "air-triggers-led", stringResource(R.string.air_triggers_led), null, leds, t.led, + enabled = t.enabled, chipModifier = track("air-triggers-led"), onPick = a.onAirTriggerLed) + for (trigger in AirTrigger.entries) { + val key = "air-trigger-${trigger.name.lowercase()}" + val left = trigger == AirTrigger.LEFT + val label = stringResource(if (left) R.string.air_trigger_left else R.string.air_trigger_right) + ChoiceRow(host, key, label, stringResource(R.string.air_trigger_button_hint), t.buttons, t.selected.getValue(trigger), + enabled = t.enabled, chipModifier = track(key)) { a.onAirTriggerButton(trigger, it) } + AirTriggerActionRow(host, "$key-action", stringResource(if (left) R.string.air_trigger_left_action else R.string.air_trigger_right_action), + t.actions[trigger] ?: AirTriggerAction.TAP, t.rates[trigger] ?: RapidFireRate.NORMAL, t.enabled, track("$key-action"), + onAction = { a.onAirTriggerAction(trigger, it) }, onRate = { a.onAirTriggerRate(trigger, it) }) + } + } } +} + +@Composable +private fun AirTriggerActionRow( + host: MenuHost, key: String, label: String, action: AirTriggerAction, rate: RapidFireRate, enabled: Boolean, chipModifier: Modifier, + onAction: (AirTriggerAction) -> Unit, onRate: (RapidFireRate) -> Unit, +) { + val open = host.open == key + var rateOpen by remember { mutableStateOf(false) } + LaunchedEffect(open) { if (!open) rateOpen = false } + val actions = listOf(AirTriggerAction.TAP to R.string.air_trigger_action_tap, AirTriggerAction.LATCH to R.string.air_trigger_action_hold, + AirTriggerAction.RAPID to R.string.air_trigger_action_rapid).map { (value, text) -> value to stringResource(text) } + val rates = listOf(R.string.air_trigger_rate_low, R.string.air_trigger_rate_normal, R.string.air_trigger_rate_high).map { stringResource(it) } + val rapidLabel = actions.last().second + val frequency = stringResource(R.string.air_trigger_rapid_frequency) + SettingsRow(label, null, highlighted = open) { Box { + ValueChip(actions.first { it.first == action }.second, open, enabled, modifier = chipModifier.testTag("setting-$key")) { + host.open = if (open) null else key + } + AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = if (rateOpen) null else label) { first -> + val arrowFocus = remember { FocusRequester() } + val keyboard = LocalInputModeManager.current.inputMode == InputMode.Keyboard + var shown by remember { mutableStateOf(rateOpen) } + LaunchedEffect(rateOpen) { + if (shown == rateOpen) return@LaunchedEffect + shown = rateOpen + withFrameNanos { } + if (keyboard) runCatching { (if (rateOpen) first else arrowFocus).requestFocus() } + } + if (rateOpen) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(start = 10.dp)) { + Text(rapidLabel.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f)) + MenuGlyphButton("✕", stringResource(R.string.common_close), Modifier.testTag("$key-rate-close")) { rateOpen = false } + } + ValueSlider(rate.ordinal, 0..RapidFireRate.entries.lastIndex, 1, true, frequency, { rates[it] }, + modifier = Modifier.focusRequester(first).testTag("$key-rate")) { if (it != rate.ordinal) onRate(RapidFireRate.entries[it]) } + } else actions.forEachIndexed { index, (value, text) -> + val pick = { onAction(value); host.open = null } + if (value != AirTriggerAction.RAPID) MenuItem(text, checked = value == action, focusRequester = if (index == 0) first else null, onClick = pick) + else Row(verticalAlignment = Alignment.CenterVertically) { + MenuItem(text, checked = value == action, modifier = Modifier.weight(1f), onClick = pick) + MenuGlyphButton("›", stringResource(R.string.air_trigger_rapid_settings), + Modifier.focusRequester(arrowFocus).testTag("$key-rate-open")) { rateOpen = true } + } + } + } + } } +} + +@Composable +private fun MenuGlyphButton(glyph: String, description: String, modifier: Modifier = Modifier, onClick: () -> Unit) { + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value + val shape = RoundedCornerShape(8.dp) + Box( + contentAlignment = Alignment.Center, + modifier = modifier.size(40.dp).clip(shape) + .background(if (hot) Color.White.copy(alpha = 0.07f) else Color.Transparent) + .glideBorder(hot, shape, pal.signal) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick) + .controllerConfirm(onClick = onClick) + .semantics { contentDescription = description }, + ) { + Text(glyph, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground) + } +} + /** The pages kept inside More, and the way into arranging which pages sit on the strip and which here. */ @Composable -private fun DrawerMorePage(host: MenuHost, pages: List, onOpen: (SessionDrawerPage) -> Unit, onEdit: () -> Unit, track: (String) -> Modifier) { +private fun DrawerMorePage(host: MenuHost, pages: List, a: DrawerActions, onOpen: (SessionDrawerPage) -> Unit, onEdit: () -> Unit, track: (String) -> Modifier) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - SettingsGroup(stringResource(R.string.drawer_page_more)) { + // The list of pages is the page itself, so it never folds. + CompositionLocalProvider(LocalDrawerSections provides null) { SettingsGroup(stringResource(R.string.drawer_page_more)) { if (pages.isEmpty()) Text( stringResource(R.string.drawer_more_empty), fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp), @@ -1288,23 +1528,23 @@ private fun DrawerMorePage(host: MenuHost, pages: List, onOpe ) { Icon(item.icon, null, tint = colors.onSurfaceVariant, modifier = Modifier.size(22.dp)) Text(stringResource(item.title), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, modifier = Modifier.weight(1f)) + if (item == SessionDrawerPage.ACHIEVEMENTS) a.achievementsProgress?.takeIf { it.second > 0 }?.let { (done, total) -> + Text(stringResource(R.string.achievements_count_short, done, total), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = pal.signal) + } } } - } + } } Spacer(Modifier.height(10.dp)) DrawerOutlineButton(stringResource(R.string.drawer_manage_pages), modifier = track("more-edit").testTag("drawer-more-edit"), onClick = onEdit) } @Composable -private fun ScreenEffectsGroup( - host: MenuHost, a: DrawerActions, advancedExpanded: Boolean, onAdvancedToggle: () -> Unit, - track: (String) -> Modifier, -) { +private fun ScreenEffectsGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { val e = a.effects val preset = ScreenEffectLooks.match(e, a.upscaler) - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - SettingsGroup(stringResource(R.string.drawer_effects)) { + val lookLabel = preset?.let { stringResource(it.label) } ?: stringResource(R.string.drawer_look_custom) + SettingsGroup(stringResource(R.string.drawer_effects), key = "effects-look", + detail = summary(lookLabel, a.screenEffectsTargets.labelOf(a.screenEffectsTarget))) { ChoiceRow( host, "effects-profile", stringResource(R.string.screen_effects_target), stringResource(R.string.screen_effects_target_hint), a.screenEffectsTargets, @@ -1358,31 +1598,13 @@ private fun ScreenEffectsGroup( if (a.hdrAvailable) ToggleRow(host, "hdr", stringResource(R.string.mode_hdr), null, a.hdr, chipModifier = track("hdr"), onChange = a.onHdr) else ToggleRow(host, "fake-hdr", stringResource(R.string.drawer_fake_hdr), null, e.hdr, chipModifier = track("fake-hdr")) { a.onEffects(e.copy(hdr = it)) } - if (a.blackFrameInsertionAvailable) ToggleRow(host, "bfi", stringResource(R.string.drawer_bfi), - stringResource(R.string.drawer_bfi_note), a.blackFrameInsertion, - chipModifier = track("bfi"), onChange = a.onBlackFrameInsertion) } - val source = remember { MutableInteractionSource() } - val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value - val rotation by animateFloatAsState(if (advancedExpanded) 180f else 0f, Motion.tw(180), label = "advancedArrow") - val description = stringResource(if (advancedExpanded) R.string.widgets_expanded else R.string.widgets_collapsed) - val toggle = { host.open = null; onAdvancedToggle() } - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(10.dp), - modifier = track("effects-advanced").fillMaxWidth().padding(top = 12.dp).heightIn(min = 48.dp) - .glideBorder(hot, RoundedCornerShape(8.dp), pal.signal) - .hoverable(source).clickable(interactionSource = source, indication = LocalIndication.current, role = Role.Button, onClick = toggle) - .controllerConfirm(onClick = toggle).semantics { stateDescription = description }.padding(horizontal = 4.dp), - ) { - Text(stringResource(R.string.drawer_effects_advanced).uppercase(), fontSize = 12.sp, - fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = colors.onSurfaceVariant) - Box(Modifier.weight(1f).height(1.dp).background(pal.line)) - Icon(Icons.Outlined.ExpandMore, contentDescription = null, tint = colors.onSurfaceVariant, - modifier = Modifier.size(22.dp).rotate(rotation)) - } - AnimatedVisibility(advancedExpanded) { - Column(Modifier.fillMaxWidth().clip(RoundedCornerShape(14.dp)).background(colors.surface).border(1.dp, pal.line, RoundedCornerShape(14.dp))) { + val tuned = listOfNotNull( + stringResource(R.string.drawer_cas).takeIf { e.cas }, stringResource(R.string.drawer_deband).takeIf { e.deband }, + ) + SettingsGroup(stringResource(R.string.drawer_section_tuning), key = "effects-tune", + tag = if (preset == null) stringResource(R.string.drawer_tag_custom) else null, detail = summary(*tuned.toTypedArray())) { + run { ToggleRow(host, "cas", stringResource(R.string.drawer_cas), null, e.cas, chipModifier = track("cas")) { a.onEffects(e.copy(cas = it)) } if (e.cas) SliderRow(stringResource(R.string.drawer_cas_level), null, e.casLevel, 0..100, step = 5, format = { "$it%" }, modifier = track("cas-level")) { a.onEffects(e.copy(casLevel = it)) } @@ -1404,7 +1626,8 @@ private fun ScreenEffectsGroup( @Composable private fun CardboardGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { val c = a.cardboard - SettingsGroup(stringResource(R.string.cardboard_title)) { + SettingsGroup(stringResource(R.string.cardboard_title), key = "vr-cardboard", + detail = stringResource(if (c.enabled) R.string.widgets_on else R.string.widgets_off)) { ToggleRow(host, "cardboard", stringResource(R.string.cardboard_mode), stringResource(R.string.cardboard_mode_hint), c.enabled, chipModifier = track("cardboard")) { a.onCardboard(c.copy(enabled = it)) } if (!c.enabled) return@SettingsGroup @@ -1437,7 +1660,8 @@ private fun CardboardGroup(host: MenuHost, a: DrawerActions, track: (String) -> @Composable private fun SteamVrGroup(a: DrawerActions, track: (String) -> Modifier) { - SettingsGroup(stringResource(R.string.steamvr_title)) { + SettingsGroup(stringResource(R.string.steamvr_title), key = "vr-steamvr", + tag = if (a.steamVr == SteamVr.Status.RUNNING) stringResource(R.string.drawer_tag_running) else null) { val vrLabel = stringResource(R.string.cardboard_steamvr) val enterLabel = stringResource(if (a.immersiveSteamVr) R.string.steamvr_enter else R.string.cardboard_steamvr_start) @Composable fun button(label: String, text: String, action: String) { @@ -1486,7 +1710,44 @@ internal fun secondScreenModes(none: Boolean, deckPad: Boolean, dashboard: Boole private val DRAWER_MIN_WIDTH = 300.dp private val DRAWER_HANDLE_STRIP = 24.dp -private val DRAWER_EDGE_GAP = 80.dp +private val DRAWER_COLUMN_GAP = 10.dp +// Two columns once each would be as wide as the narrowest single-column sheet. +private val DRAWER_TWO_COLUMN_WIDTH = DRAWER_MIN_WIDTH * 2 + DRAWER_COLUMN_GAP + +private val SessionDrawerPage.inColumns: Boolean + get() = this != SessionDrawerPage.MORE && this != SessionDrawerPage.ACHIEVEMENTS + +/** + * On a wide sheet, lays a page's groups out in two columns, the first half on the left. The split is by count, not + * height, so a group keeps its column while others fold and unfold. + */ +@Composable +internal fun DrawerColumns(two: Boolean, content: @Composable () -> Unit) { + // Keep a single composition so resizing only remeasures existing children. + Layout(content, Modifier.fillMaxWidth()) { measurables, constraints -> + val width = constraints.maxWidth + if (!two || measurables.size < 2) { + val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) } + return@Layout layout(width, placeables.sumOf { it.height }) { + var y = 0 + placeables.forEach { it.placeRelative(0, y); y += it.height } + } + } + val gap = DRAWER_COLUMN_GAP.roundToPx() + val column = ((width - gap) / 2).coerceAtLeast(0) + val child = Constraints(maxWidth = column) + val placeables = measurables.map { it.measure(child) } + val half = (placeables.size + 1) / 2 + val left = placeables.take(half) + val right = placeables.drop(half) + layout(width, maxOf(left.sumOf { it.height }, right.sumOf { it.height })) { + var y = 0 + left.forEach { it.placeRelative(0, y); y += it.height } + y = 0 + right.forEach { it.placeRelative(column + gap, y); y += it.height } + } + } +} /** A grip on the sheet's left edge: dragging it, or pressing left and right on a controller, resizes the sheet. */ @Composable @@ -1508,6 +1769,8 @@ private fun DrawerResizeHandle(width: Dp, min: Dp, max: Dp, onWidth: (Dp) -> Uni contentAlignment = Alignment.Center, modifier = modifier.width(24.dp).height(96.dp) .onGloballyPositioned { coords = it } + // On the screen's edge, Android's back swipe would take the drag. + .systemGestureExclusion() .focusable(true, source) .onPreviewKeyEvent { event -> val key = event.nativeKeyEvent @@ -1563,7 +1826,8 @@ private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String) val swapsGame = a.gameSwapAvailable || a.gameOnBottom val hasSecondScreen = a.secondScreenDisplays.isNotEmpty() if (!hasSecondScreen && !choosesDisplay && !swapsGame) return - SettingsGroup(stringResource(R.string.drawer_second_screen)) { + SettingsGroup(stringResource(R.string.drawer_second_screen), key = "display-second", + tag = if (hasSecondScreen) stringResource(R.string.drawer_tag_attached) else null) { if (hasSecondScreen) ChoiceRow(host, "dual-screen-mode", stringResource(R.string.setup_dual_screen_sessions), null, listOf( com.droiddeck.launcher.input.DualScreen.MODE_AUTO to stringResource(R.string.setup_dual_screen_auto), @@ -1643,7 +1907,8 @@ private fun TextureFilteringGroup(host: MenuHost, a: DrawerActions, track: (Stri val lodBiasChoices: List> = (if (inherited) listOf(null to stringResource(R.string.comp_game_use_general)) else emptyList()) + SessionPrefs.textureLodBiasChoices(LocalContext.current).map { (value, label) -> value as String? to label } - SettingsGroup(stringResource(R.string.drawer_texture)) { + SettingsGroup(stringResource(R.string.drawer_texture), key = "game-textures", + detail = summary(anisotropyChoices.labelOf(a.textureAnisotropy), lodBiasChoices.labelOf(a.textureLodBias))) { ChoiceRow(host, "anisotropy", stringResource(R.string.drawer_anisotropy), null, anisotropyChoices, a.textureAnisotropy, chipModifier = track("anisotropy"), onPick = a.onTextureAnisotropy) ChoiceRow(host, "texture-sharpness", stringResource(R.string.drawer_texture_sharpness), null, @@ -1660,7 +1925,7 @@ private fun SelectedGameProfileGroup(host: MenuHost, a: DrawerActions, track: (S val options: List> = listOf(null to stringResource(R.string.comp_scope_general)) + a.gameProfiles.map { (id, name) -> Pair(id, name) } val profile = a.selectedGameProfile - SettingsGroup(stringResource(R.string.drawer_selected_profile)) { + SettingsGroup(stringResource(R.string.drawer_selected_profile), key = "game-profile", detail = options.labelOf(a.selectedGameProfileId)) { DrawerStackedChoice( host = host, key = "game-profile", @@ -1799,7 +2064,7 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin val colors = MaterialTheme.colorScheme val snap = a.components if (snap == null) { - SettingsGroup(stringResource(R.string.drawer_page_components)) { + SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components") { Text(stringResource(R.string.comp_reading), fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(14.dp)) } return @@ -1809,7 +2074,7 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin } if (a.selectedGameProfileId != null) { if (gameProfile == null) { - SettingsGroup(stringResource(R.string.drawer_page_components)) { + SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components") { Text( stringResource(R.string.comp_reading), fontSize = 13.sp, @@ -1819,7 +2084,7 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin } return } - SettingsGroup(stringResource(R.string.drawer_page_components)) { + DrawerComponentSettingsGroup(stringResource(R.string.drawer_game_components_note, gameProfile.name)) { DrawerStackedChoice( host = host, key = "game-cmp-proton", @@ -1862,17 +2127,11 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin ) } } - Text( - stringResource(R.string.drawer_game_components_note, gameProfile.name), - fontSize = 12.sp, - color = colors.onSurfaceVariant, - modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp), - ) return } val running = snap.protons.filter { it.inUseByGame } val view = snap.protons.firstOrNull { it.proton.id == a.defaultProtonId } ?: running.firstOrNull() ?: snap.protons.firstOrNull() - SettingsGroup(stringResource(R.string.drawer_running_now)) { + SettingsGroup(stringResource(R.string.drawer_running_now), key = "game-running-now") { val src = remember { MutableInteractionSource() } val hot = src.collectIsFocusedAsState().value val pal = LocalPalette.current @@ -1902,13 +2161,13 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin } } if (view == null) { - SettingsGroup(stringResource(R.string.drawer_page_components)) { + SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components") { Text(stringResource(R.string.drawer_no_proton), fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(14.dp)) } return } val p = view.proton - SettingsGroup(stringResource(R.string.drawer_page_components)) { + DrawerComponentSettingsGroup(stringResource(R.string.drawer_components_note)) { DrawerStackedChoice( host, "cmp-proton", stringResource(R.string.comp_proton), listOfNotNull( @@ -1944,10 +2203,16 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin ) } } - Text( - stringResource(R.string.drawer_components_note), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp), - ) +} + +@Composable +internal fun DrawerComponentSettingsGroup(note: String, content: @Composable ColumnScope.() -> Unit) { + // The note stays visible when collapsed, but both belong to one drawer column item. + Column(Modifier.fillMaxWidth()) { + SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components", content = content) + Text(note, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp)) + } } @Composable @@ -1965,7 +2230,8 @@ internal fun ComponentDownloadsDrawerGroup( val colors = MaterialTheme.colorScheme val installed = packages.map { it.file }.toSet() val nightlyPicked = remember { mutableStateMapOf() } - SettingsGroup(stringResource(R.string.drawer_component_downloads)) { + SettingsGroup(stringResource(R.string.drawer_component_downloads), key = "game-downloads", + tag = if (downloads.isNotEmpty()) stringResource(R.string.drawer_tag_downloading) else null) { Text(stringResource(R.string.drawer_component_downloads_hint), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) SettingsRow(stringResource(R.string.comp_nightlies_checked, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt index b95dd6ae1b..4359813c07 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt @@ -39,6 +39,7 @@ internal class SettingsEntry( val words: List = emptyList(), val developer: Boolean = false, val tab: String? = null, + val frost: Boolean = false, ) { val within: Int? get() = section?.title ?: tab?.let { railLabelIcon(it).first } ?: group @@ -84,20 +85,23 @@ internal object SettingsIndex { s(SettingsSection.PERFORMANCE, R.string.perf_esync, "esync", "sync", "wine"), s(SettingsSection.PERFORMANCE, R.string.perf_fsync, "fsync", "sync", "wine"), s(SettingsSection.PERFORMANCE, R.string.perf_fastsync, "ntsync", "sync", "wine"), - s(SettingsSection.PERFORMANCE, R.string.perf_seccomp, "proot"), - s(SettingsSection.PERFORMANCE, R.string.perf_fastpath, "proot"), - s(SettingsSection.PERFORMANCE, R.string.perf_native_userland, "proot"), s(SettingsSection.PERFORMANCE, R.string.perf_cursor_composite, "mouse", "cursor"), s(SettingsSection.PERFORMANCE, R.string.perf_hostname, "name"), + s(SettingsSection.PERFORMANCE, R.string.perf_desktop_as_user, "root", "user", "sudo", "fakeroot"), s(SettingsSection.CONTROLLER, R.string.setup_tab_controller, "gamepad", "buttons", "mapping", "profile", "remap"), SettingsEntry(SettingsPlace.TAB, R.string.rail_storage, tab = "storage", words = listOf("sd card", "space", "uninstall", "disk")), + SettingsEntry(SettingsPlace.TAB, R.string.storage_shared_mount, tab = "storage", words = listOf("sdcard", "mount", "privacy", "files")), SettingsEntry(SettingsPlace.TAB, R.string.rail_sync, tab = "sync", words = listOf("syncthing", "saves")), SettingsEntry(SettingsPlace.TAB, R.string.rail_decky, tab = "decky", words = listOf("plugins", "plugin store", "homebrew", "loader")), SettingsEntry(SettingsPlace.TAB, R.string.rail_boot_movies, tab = "boot-movies", words = listOf("startup movie", "boot video", "animation", "steamdeckrepo")), s(SettingsSection.GLASSES, R.string.setup_tab_glasses, "xreal", "viture", "vr", "ar"), s(SettingsSection.LAUNCHER, R.string.setup_theme, "color", "dark"), + SettingsEntry( + SettingsPlace.SETTINGS, R.string.setup_frosted_background, section = SettingsSection.LAUNCHER, frost = true, + words = listOf("blur", "wallpaper", "background", "cards", "transparent", "transparency", "opacity", "glass"), + ), s(SettingsSection.LAUNCHER, R.string.setup_app_scale, "size", "zoom"), s(SettingsSection.LAUNCHER, R.string.setup_launcher_icon), s(SettingsSection.LAUNCHER, R.string.setup_animations), @@ -109,7 +113,8 @@ internal object SettingsIndex { s(SettingsSection.LAUNCHER, R.string.setup_home, "home screen", "launcher"), s(SettingsSection.LAUNCHER, R.string.setup_launcher_orientation, "rotate", "portrait"), s(SettingsSection.LAUNCHER, R.string.setup_session_orientation, "rotate", "portrait"), - s(SettingsSection.LAUNCHER, R.string.setup_fullscreen), + s(SettingsSection.LAUNCHER, R.string.setup_launcher_fullscreen, "status bar", "navigation bar", "portrait"), + s(SettingsSection.LAUNCHER, R.string.setup_session_fullscreen, "status bar", "navigation bar", "portrait"), s(SettingsSection.LAUNCHER, R.string.setup_page_swipe, "gesture"), s(SettingsSection.LAUNCHER, R.string.setup_controller_haptics, "vibration", "rumble"), s(SettingsSection.LAUNCHER, R.string.setup_dual_screen_launcher, "thor", "second screen", "bottom screen"), @@ -123,7 +128,8 @@ internal object SettingsIndex { s(SettingsSection.DEVELOPER, R.string.setup_game_debug_logs, "logs", "wine", "proton"), SettingsEntry(SettingsPlace.SETTINGS, R.string.setup_enhanced_diagnostics, section = SettingsSection.DEVELOPER, words = listOf("logs"), developer = true), s(SettingsSection.DEVELOPER, R.string.setup_reset_settings, "default"), - s(SettingsSection.DEVELOPER, R.string.dev_tools_title, "agent", "ai", "claude", "codex"), + s(SettingsSection.DEVELOPER, R.string.dev_tools_show, "agent", "ai", "claude", "codex"), + SettingsEntry(SettingsPlace.SETTINGS, R.string.setup_agent_commands, section = SettingsSection.DEVELOPER, words = listOf("debugging tools", "cli"), developer = true), SettingsEntry(SettingsPlace.SETTINGS, R.string.setup_graphics_logs, section = SettingsSection.DEVELOPER, words = listOf("logs", "gpu"), developer = true), d(R.string.drawer_page_display, R.string.drawer_frame_limit, "fps", "cap", "limit", "non-steam", "desktop"), @@ -149,6 +155,6 @@ internal object SettingsIndex { sh(R.string.stores_tab_library, R.string.stores_tab_library, "second library", "sd card", "steam library"), ) - fun search(context: Context, query: String): List = - entries.filter { (!it.developer || DeveloperTools.on) && it.matches(context, query) } + fun search(context: Context, query: String, frost: Boolean = false): List = + entries.filter { (!it.developer || DeveloperTools.on) && (!it.frost || frost) && it.matches(context, query) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt new file mode 100644 index 0000000000..cf50f10701 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsJump.kt @@ -0,0 +1,62 @@ +package com.droiddeck.launcher.ui + +import android.os.SystemClock +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.tween +import androidx.compose.foundation.relocation.BringIntoViewRequester +import androidx.compose.foundation.relocation.bringIntoViewRequester +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.withFrameNanos +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind + +/** The row a settings search result opens, so the page it lands on can scroll to it and flash it. */ +internal object SettingsJump { + class Target(val label: String, val at: Long = SystemClock.uptimeMillis()) + + var target: Target? by mutableStateOf(null) + + fun to(label: String) { target = Target(label) } +} + +private const val JUMP_WINDOW_MS = 5_000L + +/** False in the search results, whose rows carry the same labels as the rows they open. */ +internal val LocalSearchTargets = staticCompositionLocalOf { true } + +@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class) +@Composable +internal fun Modifier.searchTarget(label: String): Modifier { + val pal = LocalPalette.current + val flash = remember { Animatable(0f) } + val reveal = remember { BringIntoViewRequester() } + var claimed by remember { mutableStateOf(null) } + val target = SettingsJump.target.takeIf { LocalSearchTargets.current } + if (target != null && target.label == label) SideEffect { + if (SettingsJump.target === target) { + SettingsJump.target = null + if (SystemClock.uptimeMillis() - target.at <= JUMP_WINDOW_MS) claimed = target + } + } + claimed?.let { mine -> + LaunchedEffect(mine) { + withFrameNanos { } + reveal.bringIntoView() + repeat(2) { + flash.animateTo(1f, tween(220)) + flash.animateTo(0f, tween(420)) + } + claimed = null + } + } + return bringIntoViewRequester(reveal).drawBehind { + if (flash.value > 0f) drawRect(pal.signal.copy(alpha = 0.28f * flash.value)) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt index 0a4ab5590c..b76a5157f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsSearch.kt @@ -96,14 +96,14 @@ internal fun SettingsPillSearch( } @Composable -internal fun SettingsSearchResults(query: String, onOpen: (SettingsSection) -> Unit) { +internal fun SettingsSearchResults(query: String, frost: Boolean, onOpen: (SettingsSection) -> Unit) { val ctx = LocalContext.current - val found = remember(query) { SettingsIndex.search(ctx, query) } + val found = remember(query, frost) { SettingsIndex.search(ctx, query, frost) } if (found.isEmpty()) { Note(stringResource(R.string.settings_search_none, query.trim())) return } - Column { + androidx.compose.runtime.CompositionLocalProvider(LocalSearchTargets provides false) { Column { found.groupBy { it.place }.forEach { (place, entries) -> SettingsGroup(stringResource(place.title)) { entries.forEach { entry -> @@ -112,9 +112,10 @@ internal fun SettingsSearchResults(query: String, onOpen: (SettingsSection) -> U val section = entry.section val tab = entry.tab if (section != null) { - ActionRow(title, within, stringResource(R.string.store_open), onClick = { onOpen(section) }) + ActionRow(title, within, stringResource(R.string.store_open), onClick = { SettingsJump.to(title); onOpen(section) }) } else if (tab != null) { ActionRow(title, within, stringResource(R.string.store_open), onClick = { + SettingsJump.to(title) if (tab == NavTabs.MORE) MoreTabs.editing = true if (tab == "downloads") DownloadsNav.showSettings = true RailRequest.key = tab @@ -125,5 +126,5 @@ internal fun SettingsSearchResults(query: String, onOpen: (SettingsSection) -> U } } } - } + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt index e6bda83fa5..b9ddae4311 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt @@ -87,6 +87,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.TransformOrigin import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.key.onPreviewKeyEvent +import androidx.compose.ui.node.currentValueOf import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.detectTapGestures @@ -152,14 +153,43 @@ internal fun Modifier.blockTouches(): Modifier = pointerInput(Unit) { detectTapG internal fun Modifier.tapOutside(onTap: () -> Unit): Modifier = pointerInput(onTap) { detectTapGestures(onTap = { onTap() }) } -internal fun Modifier.bumpers(onPrevious: () -> Unit, onNext: () -> Unit): Modifier = onPreviewKeyEvent { event -> - val keyEvent = event.nativeKeyEvent - val previous = keyEvent.keyCode == KeyEvent.KEYCODE_BUTTON_L1 - if (!previous && keyEvent.keyCode != KeyEvent.KEYCODE_BUTTON_R1) { - false - } else { - if (keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) { if (previous) onPrevious() else onNext() } - true +internal fun Modifier.bumpers(onPrevious: () -> Unit, onNext: () -> Unit): Modifier = this then BumpersElement(onPrevious, onNext) + +private data class BumpersElement(val onPrevious: () -> Unit, val onNext: () -> Unit) : + androidx.compose.ui.node.ModifierNodeElement() { + override fun create() = BumpersNode(onPrevious, onNext) + override fun update(node: BumpersNode) { + node.onPrevious = onPrevious + node.onNext = onNext + } +} + +internal class BumpersNode(var onPrevious: () -> Unit, var onNext: () -> Unit) : + Modifier.Node(), androidx.compose.ui.input.key.KeyInputModifierNode, androidx.compose.ui.node.CompositionLocalConsumerModifierNode { + override fun onAttach() { PageBumpers.attached += this } + override fun onDetach() { PageBumpers.attached -= this } + override fun onPreKeyEvent(event: androidx.compose.ui.input.key.KeyEvent): Boolean = PageBumpers.handle(event.nativeKeyEvent, this) + override fun onKeyEvent(event: androidx.compose.ui.input.key.KeyEvent): Boolean = false + + @OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class) + fun step(previous: Boolean) { + releaseFocusedTextField(currentValueOf(androidx.compose.ui.platform.LocalView)) + OpenMenus.leaveAll(withPage = false) + if (previous) onPrevious() else onNext() + // Android keeps touch mode through gamepad buttons, and the pages move the focus only outside it. + val input = currentValueOf(LocalInputModeManager) + if (input.inputMode != InputMode.Keyboard) input.requestInputMode(InputMode.Keyboard) + } +} + +internal object PageBumpers { + val attached = ArrayList() + + fun handle(event: KeyEvent, node: BumpersNode? = attached.lastOrNull()): Boolean { + val previous = event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 + if (node == null || (!previous && event.keyCode != KeyEvent.KEYCODE_BUTTON_R1)) return false + if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) node.step(previous) + return true } } @@ -182,7 +212,8 @@ internal fun TabStrip( Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = modifier) { if (bumpers) BumperKey("LB", stringResource(R.string.widgets_prev_tab)) { onSelect((selected + tabs.size - 1) % tabs.size) } // Centred, the bumpers sit at the edges and the tabs in the middle, as in the bottom bar. - Box(if (centered) Modifier.weight(1f) else Modifier.weight(1f, fill = false), contentAlignment = Alignment.Center) { Row( + Box(if (centered) Modifier.weight(1f) else Modifier.weight(1f, fill = false), contentAlignment = Alignment.Center) { androidx.compose.foundation.layout.BoxWithConstraints { + if (tabsAsMenu(maxWidth, tabs.size)) TabMenu(tabs, selected, onSelect, focus = focusRequesters) else Row( modifier = Modifier.clip(shape).background(colors.surfaceVariant).border(1.dp, pal.line2, shape) .horizontalScroll(scroll).selectableGroup().padding(3.dp), ) { @@ -209,7 +240,7 @@ internal fun TabStrip( .padding(horizontal = tabPadding, vertical = if (compact) 6.dp else 12.dp), ) } - } } + } } } if (bumpers) BumperKey("RB", stringResource(R.string.widgets_next_tab)) { onSelect((selected + 1) % tabs.size) } } } @@ -267,6 +298,25 @@ private class BelowEndProvider(private val gap: Int) : PopupPositionProvider { } } +private val StepKeys = setOf(KeyEvent.KEYCODE_BUTTON_L1, KeyEvent.KEYCODE_BUTTON_R1, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.KEYCODE_BUTTON_R2) + +private fun launcherOf(view: android.view.View) = view.context.findActivity() as? com.droiddeck.launcher.FrontEndActivity + +// A popup is a window of its own, so controller input sent to it never reaches the launcher's. +private fun Modifier.passSteps(host: android.view.View): Modifier = onPreviewKeyEvent { event -> + event.nativeKeyEvent.keyCode in StepKeys && launcherOf(host) != null && host.rootView.dispatchKeyEvent(event.nativeKeyEvent) +} + +@Composable +private fun PassTriggerMotion(host: android.view.View) { + val popup = androidx.compose.ui.platform.LocalView.current + androidx.compose.runtime.DisposableEffect(popup, host) { + val launcher = launcherOf(host)?.takeIf { it.window.decorView === host.rootView } + if (launcher != null) popup.setOnGenericMotionListener { _, event -> launcher.onMenuMotion(event); false } + onDispose { popup.setOnGenericMotionListener(null) } + } +} + @OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class) @Composable fun AnchoredMenu( @@ -277,6 +327,13 @@ fun AnchoredMenu( val state = remember { MutableTransitionState(false) } state.targetState = open if (!state.currentState && !state.targetState && state.isIdle) return + val dismissNow = rememberUpdatedState(onDismiss) + if (open) androidx.compose.runtime.DisposableEffect(Unit) { + val leave = { _: Boolean -> dismissNow.value() } + OpenMenus.leave += leave + onDispose { OpenMenus.leave -= leave } + } + val hostView = androidx.compose.ui.platform.LocalView.current val firstItemFocus = remember { FocusRequester() } val inputMode = LocalInputModeManager.current.inputMode LaunchedEffect(open, inputMode) { @@ -294,6 +351,7 @@ fun AnchoredMenu( val pal = LocalPalette.current Popup(popupPositionProvider = provider, onDismissRequest = onDismiss, properties = PopupProperties(focusable = true)) { TrackKeyWindow() + PassTriggerMotion(hostView) val popupInput = LocalInputModeManager.current LaunchedEffect(open, inputMode) { if (!open || inputMode != InputMode.Keyboard) return@LaunchedEffect @@ -307,7 +365,7 @@ fun AnchoredMenu( runCatching { firstItemFocus.requestFocus() } } } - CompositionLocalProvider(LocalDensity provides density, LocalConfiguration provides configuration) { + SolidSurfaces { CompositionLocalProvider(LocalDensity provides density, LocalConfiguration provides configuration) { AnimatedVisibility( visibleState = state, enter = fadeIn(Motion.tw(180)) + scaleIn(Motion.sp(0.7f), initialScale = 0.94f, transformOrigin = TransformOrigin(if (compact) 0f else 1f, 0f)), @@ -323,6 +381,7 @@ fun AnchoredMenu( .clip(RowShape) .background(pal.surfaceVariant.copy(alpha = 0.95f)) .border(1.dp, pal.signal.copy(alpha = 0.22f), RowShape) + .passSteps(hostView) .controllerBack(onDismiss) .padding(6.dp), ) { @@ -363,7 +422,7 @@ fun AnchoredMenu( } } } - } + } } } } @@ -397,12 +456,13 @@ fun MenuItem( .padding(horizontal = 10.dp, vertical = 9.dp), ) { Text("✓", fontSize = 12.sp, color = pal.signal, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f).clearAndSetSemantics {}) + val ink = if (checked) pal.signal else colors.onBackground if (leading != null) { - leading() + androidx.compose.runtime.CompositionLocalProvider(androidx.compose.material3.LocalContentColor provides ink) { leading() } Spacer(Modifier.width(8.dp)) } Column(modifier = Modifier.weight(1f)) { - Text(label, fontSize = 13.5.sp, color = if (checked) pal.signal else colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis) + Text(label, fontSize = 13.5.sp, color = ink, maxLines = 2, overflow = TextOverflow.Ellipsis) if (detail != null) Text(detail, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis) } if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() } @@ -443,7 +503,11 @@ fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Mo } @Composable -fun SettingsGroup(title: String, compact: Boolean = false, detail: String? = null, content: @Composable ColumnScope.() -> Unit) { +fun SettingsGroup(title: String, compact: Boolean = false, detail: String? = null, key: String? = null, tag: String? = null, content: @Composable ColumnScope.() -> Unit) { + LocalDrawerSections.current?.let { sections -> + DrawerSection(sections, key ?: title, title, detail, tag, content) + return + } val tight = compact || LocalCompactSettings.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current @@ -462,7 +526,7 @@ fun SettingsGroup(title: String, compact: Boolean = false, detail: String? = nul } @Composable -fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hintLines: Int? = null, stacked: Boolean = false, control: @Composable () -> Unit) { +fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hintLines: Int? = null, stacked: Boolean = false, tightControlSpacing: Boolean = false, sideBySide: Boolean = false, control: @Composable () -> Unit) { val compact = LocalCompactSettings.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current @@ -472,8 +536,8 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint lineHeight = if (compact) 14.sp else androidx.compose.ui.unit.TextUnit.Unspecified, minLines = hintLines ?: 1, maxLines = hintLines ?: Int.MAX_VALUE, overflow = TextOverflow.Ellipsis) } - if (compact && !stacked) Column( - modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 10.dp, vertical = 6.dp), + if (compact && !stacked && !sideBySide) Column( + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding(horizontal = 10.dp, vertical = 6.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { Text(label, fontSize = 13.sp, lineHeight = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, @@ -481,19 +545,19 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hint control() } if (hint != null || hintLines != null) hintText(11.sp) - } else if (stacked || LocalNarrowPane.current) Column( - modifier = Modifier.fillMaxWidth().background(bg).padding( + } else if (stacked || (LocalNarrowPane.current && !sideBySide)) Column( + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding( horizontal = if (compact) 10.dp else 14.dp, - vertical = if (compact) 6.dp else 12.dp), + vertical = if (tightControlSpacing) 2.dp else if (compact) 6.dp else 12.dp), ) { Text(label, fontSize = if (compact) 13.sp else 15.sp, lineHeight = if (compact) 16.sp else androidx.compose.ui.unit.TextUnit.Unspecified, fontWeight = FontWeight.SemiBold, color = colors.onBackground) if (hint != null || hintLines != null) hintText(if (compact) 11.sp else 13.sp) - Box(Modifier.padding(top = if (compact) 6.dp else 8.dp)) { control() } + Box(Modifier.padding(top = if (tightControlSpacing) 2.dp else if (compact) 6.dp else 8.dp)) { control() } } else Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp), + modifier = Modifier.searchTarget(label).fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp), ) { Column(modifier = Modifier.weight(1f).padding(end = 12.dp)) { Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) @@ -549,8 +613,8 @@ fun UncertainMark(description: String) { } @Composable -fun ToggleRow(host: MenuHost, key: String, label: String, hint: String?, checked: Boolean, enabled: Boolean = true, chipModifier: Modifier = Modifier, onChange: (Boolean) -> Unit) = - SettingsRow(label, hint) { +fun ToggleRow(host: MenuHost, key: String, label: String, hint: String?, checked: Boolean, enabled: Boolean = true, chipModifier: Modifier = Modifier, sideBySide: Boolean = false, onChange: (Boolean) -> Unit) = + SettingsRow(label, hint, sideBySide = sideBySide) { ToggleSwitch(checked, enabled, label, chipModifier.testTag("setting-$key")) { host.open = null; onChange(it) } } @@ -597,7 +661,7 @@ fun SliderRow( ) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - Column(Modifier.fillMaxWidth()) { + Column(Modifier.searchTarget(label).fillMaxWidth()) { ValueSlider(value, range, step, enabled, label, format, modifier = modifier.padding(horizontal = 6.dp, vertical = 3.dp), onChange = onChange) if (hint != null) Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, @@ -710,8 +774,10 @@ fun MultiRow( } @Composable -fun ActionRow(label: String, hint: String?, button: String, onClick: () -> Unit, progress: Float? = null, modifier: Modifier = Modifier) { - SettingsRow(label, hint) { SecondaryButton(button, modifier = modifier, progress = progress, onClick = onClick) } +fun ActionRow(label: String, hint: String?, button: String, onClick: () -> Unit, progress: Float? = null, modifier: Modifier = Modifier, sideBySide: Boolean = false) { + SettingsRow(label, hint, sideBySide = sideBySide) { + SecondaryButton(button, compact = sideBySide, modifier = modifier, progress = progress, onClick = onClick) + } } @Composable diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SheetRows.kt b/app/src/main/java/com/droiddeck/launcher/ui/SheetRows.kt index 181a837065..af9136fba4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SheetRows.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SheetRows.kt @@ -2,7 +2,10 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.layout.Box import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import com.droiddeck.launcher.R @@ -12,8 +15,26 @@ internal fun FrameGenGroup(s: FrontEndState, a: FrontEndActions) { SettingsGroup(stringResource(R.string.frame_gen_title)) { SettingsRow(stringResource(R.string.frame_gen_title), stringResource(R.string.frame_gen_hint), highlighted = host.open == "fg") { Box { - ValueChip(s.frameGenLabel, host.open == "fg") { host.open = if (host.open == "fg") null else "fg" } - FrameGenMenu(host, s.frameGen, s.lossless, a.onFrameGenPick, a.onImportLossless) + val open = host.open == "fg" + ValueChip(s.frameGenLabel, open) { host.open = if (open) null else "fg" } + AnchoredMenu( + open = open, + onDismiss = { if (host.open == "fg") host.open = null }, + title = stringResource(R.string.frame_gen_title), + compact = true, + minWidth = 220.dp, + ) { firstItemFocus -> + FrameGenMenu( + mode = s.frameGen, + lossless = s.lossless, + onPick = { mode -> + a.onFrameGenPick(mode) + host.open = null + }, + focusModifier = Modifier.focusRequester(firstItemFocus), + legacyButtons = true, + ) + } } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt index b70345bb2b..95a4ece552 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt @@ -82,17 +82,25 @@ import kotlinx.coroutines.withContext private const val WALL_MIN_GAMES = 4 private const val WALL_DISTINCT = 40 -private const val IDLE_FRAME_NS = 30_000_000L +internal val IdleFrames = IdleFrameGate() -internal object IdleFrames { - private var shown = 0L +internal class IdleFrameGate { + private var next = Long.MIN_VALUE + private var shown = Long.MIN_VALUE fun due(nanos: Long): Boolean { if (nanos == shown) return true - if (nanos - shown < IDLE_FRAME_NS) return false + // Allow sub-ms vsync jitter; carry the phase on panels whose refresh isn't a multiple of 60. + if (nanos + VSYNC_TOLERANCE_NS < next) return false + next = if (next == Long.MIN_VALUE || nanos - next >= FRAME_NS) nanos + FRAME_NS else next + FRAME_NS shown = nanos return true } + + private companion object { + const val FRAME_NS = 1_000_000_000L / 60 + const val VSYNC_TOLERANCE_NS = 500_000L + } } @Composable @@ -113,7 +121,8 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) } val owned = remember(ownedAll, concealed) { ownedAll.filter { it.first.toLong() !in concealed } } val featured = remember(featuredAll, concealed) { featuredAll.filter { it.appId.toLong() !in concealed } } - val games = remember(s.steamGames, LibraryHidden.keys, LibraryHidden.steam) { s.steamGames.filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending { it.lastPlayed }.thenBy { it.gameId }) } + val previewing = DevPreview.steamHome + val games = remember(s.steamGames, previewing, LibraryHidden.keys, LibraryHidden.steam) { (if (previewing == SteamHomePreview.OFF) s.steamGames else sampleSteamHomeGames(previewing.games)).filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending { it.lastPlayed }.thenBy { it.gameId }) } val narrow = LocalNarrowPane.current var words by remember { mutableStateOf(null) } val mode = com.droiddeck.launcher.session.SessionService.MODE_STEAM @@ -163,12 +172,12 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) games.isEmpty() -> EmptyLibrary( avoid = words, wall = if (owned.isEmpty() && featured.isEmpty()) null else { { CapsuleWall(emptyList(), owned = owned, featured = featured) } }, - ) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade() } } + ) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade(bottomWhenTall = true) } } games.size < WALL_MIN_GAMES -> CapsuleFan(games) else -> CapsuleWall(games, owned = owned, featured = featured) } }, - scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() }, + scrim = { if (games.size >= WALL_MIN_GAMES) WallFade(bottomWhenTall = true) }, words = { val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState() val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState() @@ -232,19 +241,35 @@ internal fun Modifier.overhang(by: androidx.compose.ui.unit.Dp = 4.dp): Modifier } @Composable -internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang()) { +internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang(), bottomWhenTall: Boolean = false) { val colors = MaterialTheme.colorScheme - Box( - modifier.background( - Brush.horizontalGradient( - 0f to colors.background.copy(alpha = 0.86f), - 0.34f to colors.background.copy(alpha = 0.6f), - 0.68f to colors.background.copy(alpha = 0.14f), - 1f to colors.background.copy(alpha = 0.04f), - ), - ), - ) - Box(modifier.background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f)))) + BoxWithConstraints(modifier) { + if (bottomWhenTall && maxHeight > maxWidth) { + // The words sit at the bottom of a tall page, so the art stays clear above them and darkens only behind them. + Box( + Modifier.fillMaxSize().background( + Brush.verticalGradient( + 0f to colors.background.copy(alpha = 0.12f), + 0.5f to colors.background.copy(alpha = 0.18f), + 0.72f to colors.background.copy(alpha = 0.72f), + 1f to colors.background.copy(alpha = 0.94f), + ), + ), + ) + } else { + Box( + Modifier.fillMaxSize().background( + Brush.horizontalGradient( + 0f to colors.background.copy(alpha = 0.86f), + 0.34f to colors.background.copy(alpha = 0.6f), + 0.68f to colors.background.copy(alpha = 0.14f), + 1f to colors.background.copy(alpha = 0.04f), + ), + ), + ) + Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f)))) + } + } } @Composable @@ -387,31 +412,45 @@ private fun CapsuleFan(games: List) { transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float") } val still = Motion.scale == 0f - val slots = listOf( + val landscape = listOf( FanSlot(0.54f, 0.14f, 0.62f, -9f), FanSlot(0.70f, 0.24f, 0.56f, 5f), FanSlot(0.40f, 0.30f, 0.50f, -17f), ) + // A tall page sizes the cards from its width, so they fit any aspect; heights are fractions of the width. + val portrait = listOf( + FanSlot(0.27f, 0.11f, 0.70f, -9f), + FanSlot(0.55f, 0.19f, 0.64f, 5f), + FanSlot(0.04f, 0.26f, 0.56f, -17f), + ) BoxWithConstraints( Modifier.fillMaxSize().drawBehind { drawRect( Brush.radialGradient( listOf(pal.signal.copy(alpha = 0.14f), Color.Transparent), - center = Offset(size.width * 0.68f, size.height * 0.45f), radius = size.height * 0.6f, + center = if (size.height > size.width) Offset(size.width * 0.55f, size.height * 0.28f) else Offset(size.width * 0.68f, size.height * 0.45f), + radius = if (size.height > size.width) size.width * 0.9f else size.height * 0.6f, ), ) }, ) { val radius = with(density) { 14.dp.toPx() } + val tall = maxHeight > maxWidth + val slots = if (tall) portrait else landscape for (i in games.indices.reversed()) { val slot = slots[i] - val h = maxHeight * slot.height + val h = if (tall) maxWidth * slot.height else maxHeight * slot.height + val x = if (tall) { + // The lean and the float swing the corners out by about h/2 * sin(angle). + val swing = h * kotlin.math.sin(Math.toRadians(kotlin.math.abs(slot.lean) + 2.0)).toFloat() / 2f + (maxWidth * slot.x).coerceIn(swing, (maxWidth - h * 2f / 3f - swing).coerceAtLeast(swing)) + } else maxWidth * slot.x val v: State = floats[i] val look = WallCapsule(artBrush(hueOf(games[i].name)), games[i].art) val art = look.art?.let { rememberCapsuleArt(it, with(density) { Size((h * 2f / 3f).toPx(), h.toPx()) }, radius) } Spacer( Modifier - .offset(x = maxWidth * slot.x, y = maxHeight * slot.y) + .offset(x = x, y = maxHeight * slot.y) .size(h * 2f / 3f, h) .graphicsLayer { val t = if (still) 0f else v.value diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt b/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt index b888f08065..20a18aa845 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt @@ -145,11 +145,16 @@ internal class StepOutScope(private val items: List Unit>() + + fun leaveAll(withPage: Boolean) = leave.toList().forEach { it(withPage) } +} + private val OutPull = 6.dp private val OutBoxCorner = 16.dp private val OutFillet = 10.dp -@OptIn(ExperimentalComposeUiApi::class) @Composable internal fun StepOut( open: Boolean, @@ -163,6 +168,22 @@ internal fun StepOut( items: Int = 4, handle: @Composable () -> Unit, content: @Composable StepOutScope.() -> Unit, +) = SolidSurfaces { StepOutPanel(open, pill, preferredSide, accent, onDismiss, onClosed, pillCorner, maxWidth, items, handle, content) } + +@OptIn(ExperimentalComposeUiApi::class) +@Composable +private fun StepOutPanel( + open: Boolean, + pill: Rect, + preferredSide: StepSide, + accent: Color, + onDismiss: () -> Unit, + onClosed: () -> Unit, + pillCorner: Dp?, + maxWidth: Dp, + items: Int, + handle: @Composable () -> Unit, + content: @Composable StepOutScope.() -> Unit, ) { val colors = MaterialTheme.colorScheme val density = LocalDensity.current @@ -179,13 +200,25 @@ internal fun StepOut( val glide = LocalFocusGlide.current val opener = remember { arrayOfNulls(1) } val openNow = androidx.compose.runtime.rememberUpdatedState(open) + val dismissNow = androidx.compose.runtime.rememberUpdatedState(onDismiss) + val leavesWithPage = remember { booleanArrayOf(false) } + val presence = remember { Animatable(1f) } + if (open) androidx.compose.runtime.DisposableEffect(Unit) { + val leave = { withPage: Boolean -> + opener[0] = null + leavesWithPage[0] = withPage + dismissNow.value() + } + OpenMenus.leave += leave + onDispose { OpenMenus.leave -= leave } + } var moving by remember { mutableStateOf(false) } val placed = remember { arrayOfNulls(3) } if (moving) VeilRing() val pull = with(density) { OutPull.toPx() } val corner = pillCorner?.let { with(density) { it.toPx() } } ?: minOf(pill.height, pill.width) / 2f - BoxWithConstraints(Modifier.fillMaxSize()) { + BoxWithConstraints(Modifier.fillMaxSize().graphicsLayer { alpha = presence.value }) { val hostWidth = constraints.maxWidth.toFloat() val hostHeight = constraints.maxHeight.toFloat() val availableHeight = with(density) { @@ -206,9 +239,11 @@ internal fun StepOut( if (grown && flipped) edge.snapTo(if (open) out else rest) val boxBottom = pill.bottom + pull + c.height if (open) { + leavesWithPage[0] = false + presence.snapTo(1f) if (!grown) { opener[0] = glide?.current - edge.snapTo(rest); bottom.snapTo(pill.bottom); tint.snapTo(0f) + edge.snapTo(rest); bottom.snapTo(pill.bottom); tint.snapTo(0f); dim.snapTo(0f) pieces.forEach { it.snapTo(0f) } grown = true } @@ -226,7 +261,10 @@ internal fun StepOut( } else { opener[0]?.let { o -> if (inputMode.inputMode == InputMode.Keyboard) runCatching { o.requester.requestFocus() } } opener[0] = null - coroutineScope { + if (leavesWithPage[0]) { + moving = true + presence.animateTo(0f, Motion.tw(160)) + } else coroutineScope { pieces.forEach { launch { it.animateTo(0f, Motion.tw(90)) } } launch { delay(Motion.ms(60).toLong()); dim.animateTo(0f, Motion.tw(300)) } moving = true diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoragePage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoragePage.kt index 00b09f2145..caa629aa55 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoragePage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoragePage.kt @@ -168,6 +168,20 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) { } } +@Composable +private fun SharedStorageGroup() { + val ctx = LocalContext.current + var on by remember { mutableStateOf(SessionPrefs.mountSharedStorage(ctx)) } + SettingsGroup(stringResource(R.string.setup_runtime)) { + SettingsRow(stringResource(R.string.storage_shared_mount), stringResource(R.string.storage_shared_mount_hint)) { + ToggleSwitch(on, label = stringResource(R.string.storage_shared_mount), modifier = Modifier.testTag("setting-shared-storage")) { + SessionPrefs.setMountSharedStorage(ctx, it) + on = it + } + } + } +} + @Composable private fun DefaultStorageGroup() { val ctx = LocalContext.current @@ -347,6 +361,7 @@ private fun OverviewContent(report: StorageSummary, sessionRunning: Boolean, wid Note(stringResource(R.string.storage_session_running)) } DefaultStorageGroup() + SharedStorageGroup() SectionTitle(stringResource(R.string.storage_where), null) val unused = report.unusedTools val tiles = listOf<@Composable (Modifier) -> Unit>( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoreAchievementsUi.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoreAchievementsUi.kt index 2d6e37753c..2f7c962934 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoreAchievementsUi.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoreAchievementsUi.kt @@ -56,6 +56,7 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext @@ -358,6 +359,67 @@ internal fun SessionAchievementsPanel(label: String, state: AchievementsState, t } } +/** The Achievements page of the session menu: the same list as the full panel, inside the menu's own scroll. */ +@Composable +internal fun DrawerAchievementsPage(game: StoreAchievements.Game, title: String?, track: (String) -> Modifier) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val label = StoreAchievements.forSource(game.source)?.label.orEmpty() + val state = rememberAchievements(game) ?: AchievementsState.READING + val kinds = remember(state.list) { + val list = state.list.orEmpty() + val split = groups(list) + if (split.size < 2) emptyList() else listOf(R.string.stores_tab_all to list) + split + } + var pick by remember { mutableIntStateOf(0) } + if (pick >= kinds.size) pick = 0 + var noteHadFocus by remember { mutableStateOf(false) } + val firstRow = remember { FocusRequester() } + val loaded = !state.list.isNullOrEmpty() + LaunchedEffect(loaded) { + if (loaded && noteHadFocus) { + noteHadFocus = false + withFrameNanos { } + runCatching { firstRow.requestFocus() } + } + } + Column(Modifier.fillMaxWidth().padding(top = 8.dp, start = 4.dp, end = 4.dp)) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + Text(title.orEmpty(), fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + state.list?.takeIf { it.isNotEmpty() }?.let { list -> + if (state.all) Trophy(18.dp, Modifier.padding(end = 6.dp)) + Text(stringResource(R.string.achievements_count_short, state.done, list.size), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = pal.signal) + } + } + val list = state.list + if (list.isNullOrEmpty()) { + Text(achievementsNote(state, label).orEmpty(), fontSize = 13.sp, color = colors.onSurfaceVariant, + modifier = Modifier.padding(top = 12.dp).then(track("achievements")) + .onFocusChanged { if (it.isFocused) noteHadFocus = true }.focusable()) + return@Column + } + LinearProgressIndicator( + progress = { state.done / list.size.toFloat() }, color = pal.signal, trackColor = pal.line, + modifier = Modifier.padding(top = 8.dp).fillMaxWidth().height(4.dp).clip(RoundedCornerShape(2.dp)), + ) + if (kinds.isNotEmpty()) TabStrip( + kinds.map { (name, group) -> if (name == R.string.stores_tab_all) stringResource(name) + " · " + group.size else stringResource(name, group.size) }, + pick, { pick = it }, Modifier.padding(top = 10.dp), bumpers = false, compact = true, + ) + val shown = kinds.getOrNull(pick)?.second ?: list + val sections = if (pick == 0) groups(shown).filter { it.second.isNotEmpty() } else listOf(null to shown) + val first = sections.firstOrNull()?.second?.firstOrNull()?.id + Column(Modifier.padding(top = 6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { + for ((group, items) in sections) { + if (group != null) AchievementGroupLabel(stringResource(group, items.size)) + for (a in items) androidx.compose.runtime.key(a.id) { + AchievementRow(a, compact = true, if (a.id == first) track("achievements").focusRequester(firstRow) else Modifier) + } + } + } + } +} + @Composable internal fun DrawerAchievementsRow(progress: Pair?, modifier: Modifier = Modifier, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt index 963c2f9c99..33963e2d34 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt @@ -453,7 +453,7 @@ private fun StoreDot(store: Store, signedIn: Boolean) { @OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class) @Composable -private fun StoreChips( +internal fun StoreChips( selected: String, focused: String?, tabs: List, onStore: (Store) -> Unit, onSettings: (Rect?) -> Unit, onFocusChip: (String?) -> Unit, ) { @@ -470,27 +470,42 @@ private fun StoreChips( val tabScroll = rememberScrollState() Box(Modifier.fillMaxWidth()) { Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { - Box(Modifier.weight(1f).edgeFade(tabScroll).horizontalScroll(tabScroll)) { - Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) { - for (tab in tabs) { - val store = tab.store - if (tab.shown) { - val signedIn = StoresState.isSignedIn(store) && StoresState.expired[store] != true - key(store) { - val reveal = remember { BringIntoViewRequester() } - LaunchedEffect(selected) { if (selected == store.id) reveal.bringIntoView() } - StoreChip( - label = store.shortLabel, on = selected == store.id, under = fillShown && highlighted == store.id, key = store.id, mark = sourceColours(store.id).dot, - modifier = Modifier.bringIntoViewRequester(reveal).onGloballyPositioned { bounds[store.id] = it.boundsInParent() }, - lead = { StoreDot(store, signedIn) }, - description = store.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out), - onFocused = onFocusChip, - ) { onStore(store) } + val shown = tabs.filter { it.shown }.map { it.store } + BoxWithConstraints(Modifier.weight(1f)) { + if (sourceTabsAsMenu(maxWidth, shown.size)) TabMenu( + shown.map { it.shortLabel }, shown.indexOfFirst { it.id == selected }, { onStore(shown[it]) }, + chipModifier = shown.fold(Modifier as Modifier) { m, st -> key(st) { m.paneItem("storechip:${st.id}") } }, + descriptions = shown.map { st -> + val signedIn = StoresState.isSignedIn(st) && StoresState.expired[st] != true + st.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out) + }, + leading = { i, inList -> + val signedIn = StoresState.isSignedIn(shown[i]) && StoresState.expired[shown[i]] != true + if (inList) Box(Modifier.size(12.dp).background(sourceColours(shown[i].id).dot.copy(alpha = if (signedIn) 1f else 0.35f), CircleShape)) + else StoreDot(shown[i], signedIn) + }, + ) else Box(Modifier.edgeFade(tabScroll).horizontalScroll(tabScroll)) { + Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) { + for (tab in tabs) { + val store = tab.store + if (tab.shown) { + val signedIn = StoresState.isSignedIn(store) && StoresState.expired[store] != true + key(store) { + val reveal = remember { BringIntoViewRequester() } + LaunchedEffect(selected) { if (selected == store.id) reveal.bringIntoView() } + StoreChip( + label = store.shortLabel, on = selected == store.id, under = fillShown && highlighted == store.id, key = store.id, mark = sourceColours(store.id).dot, + modifier = Modifier.bringIntoViewRequester(reveal).onGloballyPositioned { bounds[store.id] = it.boundsInParent() }, + lead = { StoreDot(store, signedIn) }, + description = store.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out), + onFocused = onFocusChip, + ) { onStore(store) } + } } } } + ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown) } - ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown) } var cogAt by remember { mutableStateOf(null) } Box(Modifier.onGloballyPositioned { cogAt = it.boundsInRoot() }) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt new file mode 100644 index 0000000000..1a05328069 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt @@ -0,0 +1,111 @@ +package com.droiddeck.launcher.ui + +import android.content.res.Configuration +import androidx.compose.foundation.LocalIndication +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState +import androidx.compose.foundation.interaction.collectIsHoveredAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.ExpandLess +import androidx.compose.material.icons.outlined.ExpandMore +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +private val TAB_MENU_BELOW = 600.dp +private val TAB_MIN_WIDTH = 96.dp + +/** Whether [count] tabs in [width] become a [TabMenu]: on a narrow page, when they would not fit side by side. */ +internal fun tabsAsMenu(width: Dp, count: Int): Boolean = + count > 2 && width < TAB_MENU_BELOW && width / count < TAB_MIN_WIDTH + +@Composable +internal fun sourceTabsAsMenu(width: Dp, count: Int): Boolean = + count > 1 && (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT || + (width < TAB_MENU_BELOW && width / count < TAB_MIN_WIDTH)) + +/** + * Tabs as one chip naming the shown tab, which opens the list of them, as the second screen's + * picker does. Each of [focus] lands on the chip, so callers that focus a tab still reach it. + */ +@Composable +internal fun TabMenu( + labels: List, selected: Int, onPick: (Int) -> Unit, + modifier: Modifier = Modifier, focus: List? = null, + chipModifier: Modifier = Modifier, descriptions: List? = null, + leading: (@Composable (index: Int, inList: Boolean) -> Unit)? = null, +) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + var open by remember { mutableStateOf(false) } + val source = remember { MutableInteractionSource() } + val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value + val shape = RoundedCornerShape(22.dp) + val label = labels.getOrNull(selected).orEmpty() + val description = descriptions?.getOrNull(selected) ?: label + val toggle = { open = !open } + Box(modifier) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = focus.orEmpty().fold(chipModifier.height(44.dp)) { m, r -> m.focusRequester(r) } + .testTag("tab-menu") + .semantics { contentDescription = description } + .clip(shape).background(if (hot || open) pal.signal.copy(alpha = 0.14f) else colors.surfaceVariant) + .glideBorder(hot || open, shape, pal.signal, pal.line2) + .hoverable(source) + .clickable(role = Role.Button, interactionSource = source, indication = LocalIndication.current, onClick = toggle) + .controllerConfirm(onClick = toggle) + .padding(start = 14.dp, end = 10.dp), + ) { + if (selected in labels.indices) androidx.compose.runtime.CompositionLocalProvider(androidx.compose.material3.LocalContentColor provides colors.onBackground) { + leading?.invoke(selected, false) + } + Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, + overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false)) + Icon(if (open) Icons.Outlined.ExpandLess else Icons.Outlined.ExpandMore, contentDescription = null, + tint = colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) + } + AnchoredMenu(open, { open = false }, compact = true, minWidth = 200.dp) { first -> + labels.forEachIndexed { i, item -> + MenuItem( + item, checked = i == selected, + leading = leading?.let { { it(i, true) } }, + focusRequester = first.takeIf { i == selected || (i == 0 && selected !in labels.indices) }, + modifier = Modifier.testTag("tab-menu:$i") + .then(descriptions?.getOrNull(i)?.let { d -> Modifier.semantics { contentDescription = d } } ?: Modifier), + ) { open = false; onPick(i) } + } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/Theme.kt b/app/src/main/java/com/droiddeck/launcher/ui/Theme.kt index a639615129..17151e1782 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/Theme.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/Theme.kt @@ -230,35 +230,51 @@ val LocalPalette = staticCompositionLocalOf { Themes.byId(Themes.GRAPHITE) } val Palette.onSignal: Color get() = if (signal.luminance() > 0.18f) Color(0xFF03111F) else Color.White +internal val LocalSolidPalette = staticCompositionLocalOf { null } + @Composable -fun DroidDeckTheme(theme: String? = null, appScale: Int = AppUiPrefs.DEFAULT_SCALE, content: @Composable () -> Unit) { +fun DroidDeckTheme(theme: String? = null, appScale: Int = AppUiPrefs.DEFAULT_SCALE, frost: FrostChoice? = null, content: @Composable () -> Unit) { val context = LocalContext.current remember(context) { Themes.loadGradient(context) } val id = theme ?: SessionPrefs.theme(context) if (id == Themes.INNER_GAMER) InnerGamerHue(Themes.rgbSpeed) - val p = Themes.byId(id) - val scheme = darkColorScheme( - primary = p.primary, onPrimary = p.onPrimary, secondary = p.onSurfaceVariant, - background = p.background, onBackground = p.onBackground, - surface = p.surface, onSurface = p.onBackground, - surfaceVariant = p.surfaceVariant, onSurfaceVariant = p.onSurfaceVariant, - error = p.error, - ) + val solid = Themes.byId(id) + val look = frost?.let { frostLook(solid, it) } + val p = if (look == null) solid else solid.frosted(look) val baseDensity = LocalDensity.current val baseConfiguration = LocalConfiguration.current val density = remember(baseDensity, appScale) { scaledAppDensity(baseDensity, appScale) } val configuration = remember(baseConfiguration, appScale) { scaledAppConfiguration(baseConfiguration, appScale) } CompositionLocalProvider( LocalPalette provides p, + LocalSolidPalette provides solid.takeIf { look != null }, + LocalFrost provides look?.veil, LocalDensity provides density, LocalConfiguration provides configuration, ) { - MaterialTheme(colorScheme = scheme, typography = ContentDirected) { + MaterialTheme(colorScheme = p.scheme(), typography = ContentDirected) { FocusGlideHost { ProvideTextStyle(TextStyle(textDirection = TextDirection.Content), content) } } } } +private fun Palette.scheme() = darkColorScheme( + primary = primary, onPrimary = onPrimary, secondary = onSurfaceVariant, + background = background, onBackground = onBackground, + surface = surface, onSurface = onBackground, + surfaceVariant = surfaceVariant, onSurfaceVariant = onSurfaceVariant, + error = error, +) + +@Composable +internal fun SolidSurfaces(content: @Composable () -> Unit) { + val solid = LocalSolidPalette.current + if (solid == null) content() + else CompositionLocalProvider(LocalPalette provides solid, LocalSolidPalette provides null, LocalFrost provides null) { + MaterialTheme(colorScheme = solid.scheme(), typography = MaterialTheme.typography, content = content) + } +} + private val ContentDirected = Typography().run { fun TextStyle.byContent() = copy(textDirection = TextDirection.Content) Typography( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ThemeColors.kt b/app/src/main/java/com/droiddeck/launcher/ui/ThemeColors.kt index 279941154f..88cd13355a 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ThemeColors.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ThemeColors.kt @@ -69,7 +69,7 @@ internal object ThemeColors { private val DARK_INK = Color(0xFF03111F) - private fun contrast(a: Color, b: Color): Float { + internal fun contrast(a: Color, b: Color): Float { val x = a.luminance() val y = b.luminance() return (max(x, y) + 0.05f) / (min(x, y) + 0.05f) @@ -80,7 +80,7 @@ internal object ThemeColors { return if (worst(DARK_INK) >= worst(Color.White)) DARK_INK else Color.White } - private const val MIN_CONTRAST = 4.5f + internal const val MIN_CONTRAST = 4.5f private fun fitTo(ink: Color, argb: Int): Int { fun short(color: Int) = contrast(ink, Color(color)) < MIN_CONTRAST diff --git a/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt index 92478a6cd2..f15b69287b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt @@ -9,7 +9,6 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.background -import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.hoverable @@ -21,10 +20,14 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.selection.selectable +import androidx.compose.foundation.selection.selectableGroup import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size @@ -44,6 +47,7 @@ import androidx.compose.material.icons.outlined.Science import androidx.compose.material.icons.outlined.SwapHoriz import androidx.compose.material.icons.outlined.Sync import androidx.compose.material.icons.outlined.Verified +import androidx.compose.material.icons.outlined.WarningAmber import androidx.compose.material3.Icon import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.vector.ImageVector @@ -109,49 +113,49 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie val me = remember { AppUpdates.installed() } val colors = MaterialTheme.colorScheme Column(modifier = modifier) { - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), - modifier = Modifier.fillMaxWidth().padding(bottom = 10.dp), - ) { - Text( - stringResource(R.string.upd_build, me.version, s.buildLabel), fontSize = 12.5.sp, color = colors.onSurfaceVariant, - maxLines = 1, modifier = Modifier.weight(1f) - .basicMarquee(iterations = Int.MAX_VALUE, initialDelayMillis = 700, velocity = 40.dp), - ) - val checked = u.catalog?.checkedAt?.takeIf { it > 0 } - if (!LocalNarrowPane.current) Text( - if (u.checking) stringResource(R.string.common_checking) else if (checked != null) stringResource(R.string.upd_checked, ago(checked).replaceFirstChar { it.lowercase() }) else stringResource(R.string.upd_not_checked), - fontSize = 13.sp, color = colors.onSurfaceVariant, - ) - val clipboard = LocalClipboardManager.current - val context = LocalContext.current - val details = buildDetails(me, s.buildLabel) - ToolIcon(Icons.Outlined.ContentCopy, stringResource(R.string.upd_copy_build)) { - clipboard.setText(AnnotatedString(details)) - android.widget.Toast.makeText(context, context.getString(R.string.upd_copied), android.widget.Toast.LENGTH_SHORT).show() - } - ToolIcon(Icons.Outlined.Refresh, stringResource(R.string.store_check_updates), busy = u.checking, enabled = !u.checking && u.stage == null, onClick = ua.onCheck) - } BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) { val stacked = LocalNarrowPane.current || maxWidth < 600.dp - Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { - if (stacked) { - StatusPanel(s, u, ua, me) + val context = LocalContext.current + val agentReady = com.droiddeck.launcher.agent.AgentHost.installed && + (com.droiddeck.launcher.agent.AgentSetup.ready || com.droiddeck.launcher.agent.AgentSetup.completed(context)) + val installed: @Composable () -> Unit = { + SectionLabel(stringResource(R.string.upd_installed_label)) + InstalledCard(s, u, me) + CheckRow(u, ua) + LabBuilds(s.sessionRunning, header = { SectionLabel(stringResource(R.string.lab_builds)) }, onRebuild = if (agentReady) { info -> + com.droiddeck.launcher.agent.AgentHost.send(context, context.getString(R.string.agent_rebuild_lab, info.label)) + context.startActivity(android.content.Intent(context, com.droiddeck.launcher.FrontEndActivity::class.java) + .putExtra(com.droiddeck.launcher.stores.download.StoreDownloadService.EXTRA_NAV, "agent") + .addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP or android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) + } else null) + } + val channel: @Composable () -> Unit = { + SectionLabel(stringResource(R.string.upd_channel)) + ChannelPicker(u, ua) { StatusPanel(s, u, ua, me, embedded = it) } + } + val testers: @Composable () -> Unit = { + SectionLabel(stringResource(R.string.upd_testers), top = 22.dp) + ToggleRow( + host, "build-watermark", stringResource(R.string.setup_build_watermark), + stringResource(R.string.setup_build_watermark_hint), s.buildWatermark, + ) { a.onBuildWatermark() } + } + if (stacked) { + Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { + installed() Box(Modifier.height(18.dp)) - ChannelLabel() - ChannelPicker(u, ua, s.sessionRunning) - } else { - ChannelLabel() - Row(horizontalArrangement = Arrangement.spacedBy(18.dp)) { - Box(Modifier.weight(1f)) { ChannelPicker(u, ua, s.sessionRunning) } - Box(Modifier.weight(1.15f)) { StatusPanel(s, u, ua, me) } - } + channel() + testers() } - Box(Modifier.padding(top = 18.dp)) { - ToggleRow( - host, "build-watermark", stringResource(R.string.setup_build_watermark), - stringResource(R.string.setup_build_watermark_hint), s.buildWatermark, - ) { a.onBuildWatermark() } + } else { + Row(Modifier.fillMaxSize(), horizontalArrangement = Arrangement.spacedBy(24.dp)) { + Column(Modifier.weight(1f).fillMaxHeight().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { + installed() + testers() + } + Column(Modifier.weight(1.15f).fillMaxHeight().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { + channel() + } } } } @@ -169,8 +173,114 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie ) } +private val TEST_TINT = Color(0xFF9B6CFF) + @Composable -private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, me: AppUpdates.Installed) { +private fun SectionLabel(text: String, top: androidx.compose.ui.unit.Dp = 4.dp) { + Text( + text, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = top, bottom = 10.dp), + ) +} + +/** What is installed: which kind of build, its version and versionCode, and its commit, as the first thing on the page. */ +@Composable +private fun InstalledCard(s: FrontEndState, u: UpdatesState, me: AppUpdates.Installed) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val catalog = u.catalog + val lab = com.droiddeck.launcher.lab.LabOverlay.active + val basePr = if (me.pr > 0) me.pr else Regex("""\bpr(\d+)\b""").find(s.buildLabel)?.groupValues?.get(1)?.toIntOrNull() ?: 0 + val kind = when { + lab != null -> stringResource(R.string.upd_kind_lab) + me.pr > 0 -> stringResource(R.string.upd_kind_test) + catalog?.stable?.let { AppUpdates.isRunning(it, me) } == true -> stringResource(R.string.upd_stable) + catalog?.preview?.let { AppUpdates.isRunning(it, me) } == true -> stringResource(R.string.upd_preview) + else -> null + } + val tint = if (lab != null || me.pr > 0) TEST_TINT else pal.signal + val title = when { + lab != null -> lab.label + me.pr > 0 -> stringResource(R.string.upd_pr, me.pr) + else -> stringResource(R.string.upd_droiddeck_version, me.version) + } + val subtitle = when { + lab != null && basePr > 0 -> stringResource(R.string.upd_lab_on_pr, basePr) + lab != null -> stringResource(R.string.upd_lab_on_version, me.version) + me.pr > 0 -> catalog?.tests?.firstOrNull { it.pr == me.pr }?.title?.takeIf { it.isNotBlank() }?.let(::changeTitle) + else -> null + } + val built = lab?.built?.takeIf { it > 0 } ?: me.committedAt + val meta = listOfNotNull( + me.version.takeIf { lab != null || me.pr > 0 }, + stringResource(R.string.upd_version_code, me.versionCode), + me.commit.take(7).takeIf { it.length == 7 }, + built.takeIf { it > 0 }?.let { stringResource(R.string.upd_built_ago, ago(it).replaceFirstChar { c -> c.lowercase() }) }, + ).joinToString(" · ") + val clipboard = LocalClipboardManager.current + val context = LocalContext.current + val details = buildDetails(me, s.buildLabel) + Row( + verticalAlignment = Alignment.Top, horizontalArrangement = Arrangement.spacedBy(12.dp), + modifier = Modifier.fillMaxWidth().clip(Shape16).background(colors.surface).border(1.dp, pal.line, Shape16).padding(start = 18.dp, end = 12.dp, top = 14.dp, bottom = 16.dp), + ) { + Column(Modifier.weight(1f).padding(top = 2.dp)) { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { + if (kind != null) Text( + kind.uppercase(), fontSize = 10.5.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.6.sp, color = tint, maxLines = 1, + modifier = Modifier.clip(CircleShape).background(tint.copy(alpha = 0.16f)).padding(horizontal = 8.dp, vertical = 3.dp), + ) + Text(title, fontSize = 20.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + if (subtitle != null) Text(subtitle, fontSize = 14.sp, fontWeight = FontWeight.Medium, color = colors.onBackground, maxLines = 2, + overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 6.dp)) + Text(meta, fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 4.dp)) + } + ToolIcon(Icons.Outlined.ContentCopy, stringResource(R.string.upd_copy_build)) { + clipboard.setText(AnnotatedString(details)) + android.widget.Toast.makeText(context, context.getString(R.string.upd_copied), android.widget.Toast.LENGTH_SHORT).show() + } + } +} + +@Composable +private fun CheckRow(u: UpdatesState, ua: UpdatesActions) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + val enabled = !u.checking && u.stage == null + val checked = u.catalog?.checkedAt?.takeIf { it > 0 } + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 14.dp), + ) { + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), + modifier = Modifier.offset(x = (-6).dp).paneItem("updates:check").heightIn(min = 40.dp).clip(Shape12) + .background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent) + .glideBorder(hot, Shape12, pal.signal) + .hoverable(src).clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.Button, onClick = ua.onCheck) + .controllerConfirm(enabled = enabled, onClick = ua.onCheck) + .padding(horizontal = 6.dp), + ) { + if (u.checking) androidx.compose.material3.CircularProgressIndicator(Modifier.size(16.dp), color = pal.signal, strokeWidth = 2.dp) + else Icon(Icons.Outlined.Refresh, contentDescription = null, tint = pal.signal.copy(alpha = if (enabled) 1f else 0.5f), modifier = Modifier.size(18.dp)) + Text( + if (u.checking) stringResource(R.string.common_checking) else stringResource(R.string.upd_check_now), + fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = pal.signal.copy(alpha = if (enabled || u.checking) 1f else 0.5f), + ) + } + Box(Modifier.weight(1f)) + Text( + if (checked != null) stringResource(R.string.upd_checked, ago(checked).replaceFirstChar { it.lowercase() }) else stringResource(R.string.upd_not_checked), + fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, + ) + } +} + +@Composable +private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, me: AppUpdates.Installed, embedded: Boolean = false) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val catalog = u.catalog @@ -196,17 +306,24 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m else -> Look(pal.good, stringResource(R.string.upd_current_status), stringResource(R.string.upd_current_headline, name), null) } Column( - modifier = Modifier.fillMaxWidth().clip(Shape16).background(colors.surface).border(1.dp, pal.line, Shape16).padding(18.dp), + modifier = if (embedded) Modifier.fillMaxWidth().padding(start = 12.dp, end = 12.dp, bottom = 14.dp) + else Modifier.fillMaxWidth().clip(Shape16).background(colors.surface).border(1.dp, pal.line, Shape16).padding(18.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp)) { Box(Modifier.size(7.dp).clip(CircleShape).background(look.tint)) Text(look.status, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = look.tint) - if (offered) Text(stringResource(R.string.upd_dot_ago, ago(release!!.publishedAt)), fontSize = 13.sp, color = colors.onSurfaceVariant) } - Text(look.headline, fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, modifier = Modifier.padding(top = 4.dp)) + if (!embedded) Text(look.headline, fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, modifier = Modifier.padding(top = 4.dp)) if (offered) { - ReleaseNotes(changeTitle(release!!.title.ifBlank { release.tag }), release.summary, release.tag) - ReleaseFacts(release) + val size = release!!.apk?.size?.takeIf { it > 0 }?.let { megabytes(it) } + Text( + listOfNotNull(stringResource(R.string.upd_released_ago, ago(release.publishedAt)), size).joinToString(" · "), + fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 2.dp), + ) + val older = (release.committedAt.takeIf { it > 0 } ?: release.publishedAt).let { it > 0 && me.committedAt > 0 && it < me.committedAt } + if (offer == Offer.SWITCH && older) OlderNote(me.committedAt) + val title = changeTitle(release.title.ifBlank { release.tag }) + ReleaseNotes(title.takeUnless { it == look.headline || (release.version != null && it.endsWith(release.version)) }, release.summary, release.tag) } if (release != null && u.follow.channel == Channel.TEST && catalog != null) { androidx.compose.runtime.LaunchedEffect(release.tag, release.commit, release.apk?.sha256) { ua.onSeen(release) } @@ -228,8 +345,10 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m else LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(6.dp).clip(CircleShape)) } offered && installBlock != null -> Unit - offer == Offer.UPDATE -> PrimaryButton(stringResource(R.string.upd_update_button, button), enabled = installable, main = true) { ua.onInstall(release!!) } - offer == Offer.SWITCH -> PrimaryButton(stringResource(R.string.upd_install_button, button), enabled = installable, main = true) { ua.onInstall(release!!) } + offer == Offer.UPDATE -> PrimaryButton(stringResource(R.string.upd_update_button, button), enabled = installable, main = true, fill = true, + modifier = Modifier.fillMaxWidth()) { ua.onInstall(release!!) } + offer == Offer.SWITCH -> PrimaryButton(stringResource(R.string.upd_switch_to_button, channelTitle(u.follow), button), enabled = installable, main = true, + fill = true, modifier = Modifier.fillMaxWidth()) { ua.onInstall(release!!) } offer == Offer.AHEAD && u.follow.channel == Channel.STABLE && installBlock == null -> SecondaryButton(stringResource(R.string.upd_install_anyway, release?.version.orEmpty()), enabled = installable) { ua.onInstall(release!!) } offer == Offer.GONE -> PrimaryButton(stringResource(R.string.upd_follow_preview), main = true) { ua.onFollow(Follow(Channel.NIGHTLY)) } @@ -238,25 +357,53 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m if (s.sessionRunning && (offered || offer == Offer.AHEAD)) { Text(stringResource(R.string.upd_stop_session), fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp)) } + if (offered) ReleaseFacts(release!!) if (u.follow.channel == Channel.NIGHTLY) { PreviewHistory(catalog, me, s, u, ua) } } } +/** A switch that installs a build made before the installed one; Android keeps the app's data across it. */ @Composable -private fun ReleaseNotes(title: String, notes: String, key: String) { +private fun OlderNote(installedAt: Long) { + val context = LocalContext.current + val date = android.text.format.DateUtils.formatDateTime(context, installedAt, + android.text.format.DateUtils.FORMAT_SHOW_DATE or android.text.format.DateUtils.FORMAT_ABBREV_MONTH) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), + modifier = Modifier.padding(top = 12.dp).fillMaxWidth().clip(Shape12).background(AttentionAmber.copy(alpha = 0.12f)) + .padding(horizontal = 12.dp, vertical = 10.dp), + ) { + Icon(Icons.Outlined.WarningAmber, contentDescription = null, tint = AttentionAmber, modifier = Modifier.size(20.dp)) + Column { + Text(stringResource(R.string.upd_older_than_installed, date), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = AttentionAmber) + Text(stringResource(R.string.upd_data_stays), fontSize = 12.5.sp, color = MaterialTheme.colorScheme.onSurfaceVariant) + } + } +} + +@Composable +private fun channelTitle(f: Follow) = when (f.channel) { + Channel.STABLE -> stringResource(R.string.upd_stable) + Channel.NIGHTLY -> stringResource(R.string.upd_preview) + Channel.TEST -> stringResource(R.string.upd_pr, f.pr) +} + +@Composable +private fun ReleaseNotes(title: String?, notes: String, key: String) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current var open by rememberSaveable(key) { mutableStateOf(false) } var cut by remember(key) { mutableStateOf(false) } - Text( + if (title != null) Text( title, fontSize = 15.sp, color = colors.onBackground, maxLines = if (open) Int.MAX_VALUE else 2, overflow = TextOverflow.Ellipsis, onTextLayout = { if (it.hasVisualOverflow) cut = true }, modifier = Modifier.padding(top = 10.dp), ) if (notes.isNotBlank()) Text( - notes, fontSize = 13.5.sp, color = colors.onSurfaceVariant, maxLines = if (open) Int.MAX_VALUE else 1, overflow = TextOverflow.Ellipsis, - onTextLayout = { if (it.hasVisualOverflow) cut = true }, modifier = Modifier.padding(top = 4.dp), + notes, fontSize = 13.5.sp, color = colors.onSurfaceVariant, maxLines = if (open) Int.MAX_VALUE else if (title == null) 3 else 1, + overflow = TextOverflow.Ellipsis, onTextLayout = { if (it.hasVisualOverflow) cut = true }, + modifier = Modifier.padding(top = if (title == null) 10.dp else 4.dp), ) if (cut || open) { val src = remember { MutableInteractionSource() } @@ -287,47 +434,77 @@ private fun changeTitle(t: String): String = private fun megabytes(bytes: Long) = stringResource(R.string.upd_mb, ((bytes + 524_288) / 1_048_576).toInt()) @Composable -private fun ChannelLabel() { - Text( - stringResource(R.string.upd_channel), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, - color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 10.dp), - ) -} - -@Composable -private fun ChannelPicker(u: UpdatesState, ua: UpdatesActions, sessionRunning: Boolean) { +private fun ChannelPicker(u: UpdatesState, ua: UpdatesActions, status: @Composable (embedded: Boolean) -> Unit) { val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current val catalog = u.catalog val tests = catalog?.tests.orEmpty() val me = remember { AppUpdates.installed() } val ready = tests.count { AppUpdates.installable(it, me) } var showTests by rememberSaveable { mutableStateOf(false) } + val listing = (showTests || u.follow.channel == Channel.TEST) && tests.isNotEmpty() + val shown = if (listing || showTests) Channel.TEST else u.follow.channel Column(verticalArrangement = Arrangement.spacedBy(10.dp)) { - ChannelCard( - Icons.Outlined.Verified, stringResource(R.string.upd_stable), stringResource(R.string.upd_stable_hint), - catalog?.stable?.let { stringResource(R.string.upd_version_ago, it.version ?: it.tag, ago(it.publishedAt)) }, u.follow.channel == Channel.STABLE, - ) { ua.onFollow(Follow(Channel.STABLE)) } - ChannelCard( - Icons.Outlined.Bolt, stringResource(R.string.upd_preview), stringResource(R.string.upd_preview_hint), - catalog?.preview?.let { ago(it.publishedAt) }, u.follow.channel == Channel.NIGHTLY, - ) { ua.onFollow(Follow(Channel.NIGHTLY)) } - ChannelCard( - Icons.Outlined.Science, stringResource(R.string.upd_tests), stringResource(R.string.upd_tests_hint), - if (tests.isEmpty()) stringResource(R.string.upd_tests_none) else pluralStringResource(R.plurals.upd_tests_count, ready, ready), - u.follow.channel == Channel.TEST, enabled = tests.isNotEmpty() || u.follow.channel == Channel.TEST, - ) { showTests = !showTests } - AnimatedVisibility((showTests || u.follow.channel == Channel.TEST) && tests.isNotEmpty(), enter = expandVertically(Motion.sp(1f)) + fadeIn(Motion.sp(1f)), exit = shrinkVertically(Motion.sp(1f)) + fadeOut(Motion.sp(1f))) { - TestList(tests, me, u, ua) + Row( + horizontalArrangement = Arrangement.spacedBy(4.dp), + modifier = Modifier.fillMaxWidth().clip(CircleShape).background(colors.surface).border(1.dp, pal.line, CircleShape) + .padding(4.dp).selectableGroup(), + ) { + ChannelSegment(Icons.Outlined.Verified, stringResource(R.string.upd_stable), null, shown == Channel.STABLE) { + showTests = false; ua.onFollow(Follow(Channel.STABLE)) + } + ChannelSegment(Icons.Outlined.Bolt, stringResource(R.string.upd_preview), null, shown == Channel.NIGHTLY) { + showTests = false; ua.onFollow(Follow(Channel.NIGHTLY)) + } + ChannelSegment( + Icons.Outlined.Science, stringResource(R.string.upd_tests_short), ready.takeIf { it > 0 }?.toString(), + shown == Channel.TEST, enabled = tests.isNotEmpty() || u.follow.channel == Channel.TEST, + ) { showTests = !showTests } } - val context = androidx.compose.ui.platform.LocalContext.current - val agentReady = com.droiddeck.launcher.agent.AgentHost.installed && - (com.droiddeck.launcher.agent.AgentSetup.ready || com.droiddeck.launcher.agent.AgentSetup.completed(context)) - LabBuilds(sessionRunning, onRebuild = if (agentReady) { info -> - com.droiddeck.launcher.agent.AgentHost.send(context, context.getString(R.string.agent_rebuild_lab, info.label)) - context.startActivity(android.content.Intent(context, com.droiddeck.launcher.FrontEndActivity::class.java) - .putExtra(com.droiddeck.launcher.stores.download.StoreDownloadService.EXTRA_NAV, "agent") - .addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP or android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) - } else null) + val hint = when { + listing || u.follow.channel == Channel.TEST -> stringResource(R.string.upd_tests_hint) + u.follow.channel == Channel.NIGHTLY -> stringResource(R.string.upd_preview_hint) + + (catalog?.preview?.let { " · " + stringResource(R.string.upd_latest_ago, ago(it.publishedAt)) } ?: "") + else -> stringResource(R.string.upd_stable_hint) + + (catalog?.stable?.let { " · " + stringResource(R.string.upd_version_ago, it.version ?: it.tag, ago(it.publishedAt)) } ?: "") + } + Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp)) + if (tests.isEmpty() && catalog != null && showTests) Text(stringResource(R.string.upd_tests_none), fontSize = 12.5.sp, color = colors.onSurfaceVariant) + if (!listing) status(false) + AnimatedVisibility(listing, enter = expandVertically(Motion.sp(1f)) + fadeIn(Motion.sp(1f)), exit = shrinkVertically(Motion.sp(1f)) + fadeOut(Motion.sp(1f))) { + TestList(tests, me, u, ua, status) + } + } +} + +@Composable +private fun RowScope.ChannelSegment( + icon: ImageVector, title: String, badge: String?, selected: Boolean, + enabled: Boolean = true, onClick: () -> Unit, +) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.CenterHorizontally), + modifier = Modifier.weight(1f).heightIn(min = 44.dp).paneItem("channel:$title") + .clip(CircleShape) + .background(if (selected) pal.signal.copy(alpha = 0.16f) else if (hot) pal.signal.copy(alpha = 0.10f) else Color.Transparent) + .glideBorder(hot, CircleShape, pal.signal, if (selected) pal.signal else Color.Transparent) + .alpha(if (enabled) 1f else 0.5f) + .hoverable(src) + .selectable(selected = selected, interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onClick) + .controllerConfirm(enabled = enabled, onClick = onClick) + .padding(horizontal = 6.dp), + ) { + Icon(icon, contentDescription = null, tint = if (selected) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(18.dp)) + Text(title, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = if (selected) colors.onBackground else colors.onSurfaceVariant, + maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false)) + if (badge != null) Text( + badge, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = colors.onSurfaceVariant, + modifier = Modifier.clip(CircleShape).background(colors.surfaceVariant).padding(horizontal = 6.dp, vertical = 1.dp), + ) } } @@ -514,7 +691,7 @@ private fun LinkPill(label: String, url: String) { } @Composable -private fun TestList(tests: List, me: AppUpdates.Installed, u: UpdatesState, ua: UpdatesActions) { +private fun TestList(tests: List, me: AppUpdates.Installed, u: UpdatesState, ua: UpdatesActions, status: @Composable (embedded: Boolean) -> Unit) { val colors = MaterialTheme.colorScheme var query by rememberSaveable { mutableStateOf("") } val needle = query.trim().removePrefix("#").removePrefix("@") @@ -525,58 +702,30 @@ private fun TestList(tests: List, me: AppUpdates.Installed, u: UpdatesS val (ready, old) = matches.partition { it.versionCode >= me.versionCode } val followedOld = u.follow.channel == Channel.TEST && old.any { it.pr == u.follow.pr } var showOld by rememberSaveable { mutableStateOf(false) } - Column(Modifier.padding(start = 18.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { - if (tests.size > 5 || query.isNotEmpty()) AdbTextField( - value = query, onValueChange = { query = it }, label = stringResource(R.string.upd_tests_find), - keyboardType = KeyboardType.Text, imeAction = ImeAction.Search, compact = true, showLabel = false, - placeholder = stringResource(R.string.upd_tests_find), modifier = Modifier.fillMaxWidth(), - ) - if (matches.isEmpty()) Text(stringResource(R.string.upd_tests_no_match), fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(4.dp)) - ready.forEach { t -> TestRow(t, u.follow.pr == t.pr && u.follow.channel == Channel.TEST) { ua.onFollow(Follow(Channel.TEST, t.pr)) } } - if (old.isNotEmpty()) { - MoreLink(stringResource(R.string.upd_tests_old, old.size, me.versionCode), "tests:old") { showOld = !showOld } - if (showOld || followedOld || needle.isNotEmpty()) old.forEach { t -> - TestRow(t, u.follow.pr == t.pr && u.follow.channel == Channel.TEST, tooOld = true) { ua.onFollow(Follow(Channel.TEST, t.pr)) } + val oldShown = showOld || followedOld || needle.isNotEmpty() + val followed = u.follow.pr.takeIf { u.follow.channel == Channel.TEST } + val rowShown = followed != null && (ready.any { it.pr == followed } || (oldShown && old.any { it.pr == followed })) + Column(verticalArrangement = Arrangement.spacedBy(10.dp)) { + // A followed test's row carries the status; browsing Tests while following Stable or Preview shows it only for an install running or failed. + if (if (followed != null) !rowShown else u.stage != null || u.error != null) status(false) + Column(Modifier.padding(start = 18.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { + if (tests.size > 5 || query.isNotEmpty()) AdbTextField( + value = query, onValueChange = { query = it }, label = stringResource(R.string.upd_tests_find), + keyboardType = KeyboardType.Text, imeAction = ImeAction.Search, compact = true, showLabel = false, + placeholder = stringResource(R.string.upd_tests_find), modifier = Modifier.fillMaxWidth(), + ) + if (matches.isEmpty()) Text(stringResource(R.string.upd_tests_no_match), fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(4.dp)) + ready.forEach { t -> TestRow(t, followed == t.pr, status = status) { ua.onFollow(Follow(Channel.TEST, t.pr)) } } + if (old.isNotEmpty()) { + MoreLink(stringResource(R.string.upd_tests_old, old.size, me.versionCode), "tests:old") { showOld = !showOld } + if (oldShown) old.forEach { t -> + TestRow(t, followed == t.pr, tooOld = true, status = status) { ua.onFollow(Follow(Channel.TEST, t.pr)) } + } } } } } -@Composable -private fun ChannelCard( - icon: ImageVector, title: String, hint: String, latest: String?, selected: Boolean, - enabled: Boolean = true, onClick: () -> Unit, -) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(14.dp), - modifier = Modifier.fillMaxWidth().paneItem("channel:$title") - .clip(Shape14).background(colors.surface).background(fill).glideBorder(hot, Shape14, pal.signal, pal.line) - .alpha(if (enabled) 1f else 0.55f) - .hoverable(src) - .clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onClick) - .controllerConfirm(enabled = enabled, onClick = onClick) - .padding(horizontal = 14.dp, vertical = 10.dp), - ) { - Box(contentAlignment = Alignment.Center, modifier = Modifier.size(38.dp).clip(Shape12).background(if (selected) pal.signal.copy(alpha = 0.18f) else colors.surfaceVariant)) { - Icon(icon, contentDescription = null, tint = if (selected) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(22.dp)) - } - Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) { - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Text(title, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - if (latest != null) Text(latest, fontSize = 12.sp, fontWeight = FontWeight.Medium, color = if (selected) pal.signal else colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - RadioDot(selected) - } -} - @Composable private fun RadioDot(selected: Boolean, size: androidx.compose.ui.unit.Dp = 22.dp) { val pal = LocalPalette.current @@ -586,40 +735,46 @@ private fun RadioDot(selected: Boolean, size: androidx.compose.ui.unit.Dp = 22.d } @Composable -private fun TestRow(t: Release, selected: Boolean, tooOld: Boolean = false, onClick: () -> Unit) { +private fun TestRow(t: Release, selected: Boolean, tooOld: Boolean = false, status: @Composable (embedded: Boolean) -> Unit, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(12.dp), - modifier = Modifier.fillMaxWidth().paneItem("test:${t.pr}") - .heightIn(min = 52.dp) - .clip(Shape12) - .background(colors.surface).background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent) - .glideBorder(hot, Shape12, pal.signal, pal.line) - .alpha(if (tooOld && !selected) 0.6f else 1f) - .hoverable(src) - .clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onClick) - .controllerConfirm(onClick = onClick) - .padding(horizontal = 12.dp, vertical = 8.dp), + Column( + Modifier.fillMaxWidth().clip(Shape12).background(colors.surface) + .glideBorder(hot, Shape12, pal.signal, if (selected) pal.signal.copy(alpha = 0.5f) else pal.line), ) { - Text("#${t.pr}", fontSize = 13.sp, fontWeight = FontWeight.Bold, color = if (selected) pal.signal else colors.onSurfaceVariant) - Column(Modifier.weight(1f)) { - Text(changeTitle(t.title.ifBlank { stringResource(R.string.upd_pr, t.pr) }), fontSize = 13.5.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - val detail = when { - t.apk == null -> stringResource(R.string.upd_not_built) - tooOld -> stringResource(R.string.upd_tests_old_row, t.versionCode) - else -> stringResource(R.string.upd_updated, ago(t.builtAt.takeIf { it > 0 } ?: t.publishedAt)) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(12.dp), + modifier = Modifier.fillMaxWidth().paneItem("test:${t.pr}") + .heightIn(min = 52.dp) + .background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent) + .alpha(if (tooOld && !selected) 0.6f else 1f) + .hoverable(src) + .clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onClick) + .controllerConfirm(onClick = onClick) + .padding(horizontal = 12.dp, vertical = 8.dp), + ) { + Text("#${t.pr}", fontSize = 13.sp, fontWeight = FontWeight.Bold, color = if (selected) pal.signal else colors.onSurfaceVariant) + Column(Modifier.weight(1f)) { + Text(changeTitle(t.title.ifBlank { stringResource(R.string.upd_pr, t.pr) }), fontSize = 13.5.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + val detail = when { + t.apk == null -> stringResource(R.string.upd_not_built) + tooOld -> stringResource(R.string.upd_tests_old_row, t.versionCode) + else -> stringResource(R.string.upd_updated, ago(t.builtAt.takeIf { it > 0 } ?: t.publishedAt)) + } + Text( + listOfNotNull(detail, t.author.takeIf { it.isNotEmpty() }?.let { "@$it" }, t.shortCommit).joinToString(" · "), + fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, + ) + if (t.newerCommitPushed) Text(stringResource(R.string.upd_newer_commit_short), fontSize = 12.sp, color = AttentionAmber, maxLines = 1, overflow = TextOverflow.Ellipsis) } - Text( - listOfNotNull(detail, t.author.takeIf { it.isNotEmpty() }?.let { "@$it" }, t.shortCommit).joinToString(" · "), - fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, - ) - if (t.newerCommitPushed) Text(stringResource(R.string.upd_newer_commit_short), fontSize = 12.sp, color = AttentionAmber, maxLines = 1, overflow = TextOverflow.Ellipsis) + RadioDot(selected, 20.dp) + } + AnimatedVisibility(selected, enter = expandVertically(Motion.sp(1f)) + fadeIn(Motion.sp(1f)), exit = shrinkVertically(Motion.sp(1f)) + fadeOut(Motion.sp(1f))) { + status(true) } - RadioDot(selected, 20.dp) } } diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/BottomDesktopCompositorService.kt b/app/src/main/java/com/droiddeck/launcher/wayland/BottomDesktopCompositorService.kt index d1c64b4b39..4b9d25957a 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/BottomDesktopCompositorService.kt +++ b/app/src/main/java/com/droiddeck/launcher/wayland/BottomDesktopCompositorService.kt @@ -31,7 +31,7 @@ class BottomDesktopCompositorService : Service() { MSG_RESIZE -> resize(msg.arg1, msg.arg2) MSG_TOUCH -> WaylandCompositor.nativeSendTouch(msg.arg1 and 0xff, msg.arg1 shr 8, msg.arg2 ushr 16, msg.arg2 and 0xffff) - MSG_KEY -> WaylandCompositor.nativeSendKey(msg.arg1, msg.arg2) + MSG_KEY -> WaylandCompositor.nativeSendKeyOrdered(msg.arg1, msg.arg2) MSG_POINTER -> WaylandCompositor.nativeSendPointer(1, msg.arg1, msg.arg2) MSG_SCENE -> WaylandCompositor.nativeSendSceneInput(msg.arg1, msg.arg2, msg.peekData()?.getInt(KEY_B) ?: 0) MSG_CURSOR -> if (CompositorHost.isStarted) WaylandCompositor.nativeSetCursorComposite(msg.arg1 != 0) diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt index d9d2eb111f..d193c2b025 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt @@ -67,13 +67,14 @@ object CompositorHost { outputHeight: Int, refreshHz: Float, fpsLimit: Int, + layerFpsLimit: Int = fpsLimit, ): Boolean { WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path) ownVsyncThread = SessionPrefs.vsyncThread(context) WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context)) blackFrameInsertion = SessionPrefs.blackFrameInsertion(context) WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion) - pace(refreshHz, fpsLimit) + pace(refreshHz, fpsLimit, layerFpsLimit) if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight) if (started) { attached = surface @@ -95,23 +96,23 @@ object CompositorHost { private var blackFrameInsertion = false private var pictureHolds = 0 - private fun pace(refreshHz: Float, fpsLimit: Int) { + private fun pace(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int) { WaylandCompositor.nativeSetFpsLimit(fpsLimit) - WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz) + WaylandCompositor.nativeSetLayerFrameRate(SessionPrefs.layerFrameRate(layerFpsLimit, refreshHz, blackFrameInsertion)) WaylandCompositor.nativeSetOutputRefreshRate(refreshHz) SessionState.refreshHz = refreshHz } @Synchronized - fun updatePacing(refreshHz: Float, fpsLimit: Int) { - if (started) pace(refreshHz, fpsLimit) + fun updatePacing(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) { + if (started) pace(refreshHz, fpsLimit, layerFpsLimit) } @Synchronized - fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int) { + fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) { blackFrameInsertion = on WaylandCompositor.nativeSetBlackFrameInsertion(on) - if (started) pace(refreshHz, fpsLimit) + if (started) pace(refreshHz, fpsLimit, layerFpsLimit) } /** Presents only pictures until the matching release; false when nothing is strobing. */ diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java index afe0df226f..a2676304d9 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java +++ b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java @@ -9,6 +9,10 @@ public final class WaylandCompositor { private WaylandCompositor() {} + public static native boolean frameWorkerProbeEnabled(); + public static native boolean frameWorkerProbeGrant(int owner, int pid, long expires, String path, long dev, long ino, long startTicks); + public static native void frameWorkerProbeRevoke(int owner, int pid); + private static volatile Runnable firstFrameListener; public static void setFirstFrameListener(Runnable r) { firstFrameListener = r; } @@ -202,6 +206,27 @@ public final class WaylandCompositor { if (l != null) l.onTextInput(enabled, program, x, y, w, h); } + public interface TextInputFallbackListener { + boolean onTextInputFallback(String text, int token); + } + + private static volatile TextInputFallbackListener textInputFallbackListener; + + public static void setTextInputFallbackListener(TextInputFallbackListener l) { textInputFallbackListener = l; } + + public static boolean isTextInputFallbackListener(TextInputFallbackListener l) { return textInputFallbackListener == l; } + + public static void clearTextInputFallbackListener(TextInputFallbackListener l) { + if (textInputFallbackListener == l) textInputFallbackListener = null; + } + + @SuppressWarnings("unused") + static boolean onTextInputFallback(byte[] utf8, int token) { + TextInputFallbackListener l = textInputFallbackListener; + if (l == null || utf8 == null) return false; + return l.onTextInputFallback(new String(utf8, java.nio.charset.StandardCharsets.UTF_8), token); + } + private static byte[] utf8(String s) { return s == null ? new byte[0] : s.getBytes(java.nio.charset.StandardCharsets.UTF_8); } @@ -210,14 +235,28 @@ public final class WaylandCompositor { public static void textInputCommit(String text) { if (text != null && !text.isEmpty()) nativeTextInputCommit(utf8(text)); } + public static void textInputCommitAndSubmit(String text) { + if (text != null && !text.isEmpty()) nativeTextInputCommitAndSubmit(utf8(text)); + } + public static void textInputPreedit(String text, int cursor) { nativeTextInputPreedit(utf8(text), cursor, cursor); } public static void textInputDelete(int before, int after) { nativeTextInputDelete(before, after); } + public static final int TEXT_NOT_DELIVERED = 0; + public static final int TEXT_DELIVERED = 1; + public static final int TEXT_UNRESOLVED = 2; + + public static void completeTextInputFallback(int token, int result) { + nativeCompleteTextInputFallback(token, result); + } + private static native void nativeSetClipboardText(byte[] utf8); private static native void nativeTextInputCommit(byte[] utf8); + private static native void nativeTextInputCommitAndSubmit(byte[] utf8); private static native void nativeTextInputPreedit(byte[] utf8, int cursorBegin, int cursorEnd); private static native void nativeTextInputDelete(int before, int after); + private static native void nativeCompleteTextInputFallback(int token, int result); public static native void nativeStart(String xdgRuntimeDir); @@ -248,6 +287,10 @@ public final class WaylandCompositor { public static native void nativeSendKey(int evdev, int state); + // Ordered delivery: key events share the host queue with text commits so keys cannot overtake pending text. + public static native void nativeSendKeyOrdered(int evdev, int state); + public static native void nativeSelectGameField(boolean copy); + public static native boolean nativeFocusTakesTouch(); public static native boolean nativeCursorInputPos(int[] out); @@ -290,6 +333,8 @@ public final class WaylandCompositor { public static native void nativeSetZeroCopy(boolean on); + public static native void nativeSetMirrorCapture(boolean on); + public static native void nativeSetDisplayBufferDriver(boolean on); public static native int nativeZeroCopyFrames(); @@ -417,12 +462,14 @@ public final class WaylandCompositor { public static final int SCENE_BUTTON = 3, SCENE_WHEEL = 4, SCENE_POINTER_DELTA = 6, SCENE_AXIS = 11, SCENE_AXIS_FINGER = 12; public static final int WHEEL_STEP_UNITS = 120, POINTER_DELTA_SCALE = 256; - public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_DDFG = 1; + public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_DDFG = 1, FG_ENGINE_ZEROFG = 2; public static native void nativeSetFrameGenEngine(int kind); public static native void nativeSetFrameGenArmed(boolean armed, int multiplier, int targetFps); + public static native void nativeSetFrameGenPacer(boolean on); + public static native void nativeSetLsfgCachePath(String path); public static native void nativeSetFrameGenTuning(float flowScale, float refreshHz); diff --git a/app/src/main/res/color/wireless_pairing_key_text.xml b/app/src/main/res/color/wireless_pairing_key_text.xml new file mode 100644 index 0000000000..62b63fbefb --- /dev/null +++ b/app/src/main/res/color/wireless_pairing_key_text.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_frame_generation.xml b/app/src/main/res/drawable/ic_frame_generation.xml new file mode 100644 index 0000000000..bf643a0c8d --- /dev/null +++ b/app/src/main/res/drawable/ic_frame_generation.xml @@ -0,0 +1,14 @@ + + + + diff --git a/app/src/main/res/drawable/wireless_pairing_key.xml b/app/src/main/res/drawable/wireless_pairing_key.xml new file mode 100644 index 0000000000..51bffe4ff2 --- /dev/null +++ b/app/src/main/res/drawable/wireless_pairing_key.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/wireless_pairing_panel.xml b/app/src/main/res/drawable/wireless_pairing_panel.xml new file mode 100644 index 0000000000..4e88b9b826 --- /dev/null +++ b/app/src/main/res/drawable/wireless_pairing_panel.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/wireless_pairing_keypad.xml b/app/src/main/res/layout/wireless_pairing_keypad.xml new file mode 100644 index 0000000000..159a4e75fd --- /dev/null +++ b/app/src/main/res/layout/wireless_pairing_keypad.xml @@ -0,0 +1,38 @@ + + + + +