mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 08:16:02 +00:00
Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f3b885ee0 | ||
|
|
97e84184ed | ||
|
|
66a4d28044 | ||
|
|
e06ca23f66 | ||
|
|
e57bc43f6a | ||
|
|
3962b3e27f | ||
|
|
dc6b7f29cf | ||
|
|
ca29850d04 | ||
|
|
c0cc3b46a0 | ||
|
|
64b7339da9 | ||
|
|
4349563fd1 | ||
|
|
f29f72d5d9 | ||
|
|
367151be2c | ||
|
|
9925873764 | ||
|
|
33761c30ab | ||
|
|
089c18b49d | ||
|
|
cb8e70b940 | ||
|
|
3c0d25d83b | ||
|
|
6f45b5347d | ||
|
|
a3e8b44145 | ||
|
|
0f37154933 | ||
|
|
42133bec0b | ||
|
|
d7f43c26cd | ||
|
|
d5c83eae15 | ||
|
|
83dc5f37e9 | ||
|
|
d0022a35f9 | ||
|
|
acb2cba970 | ||
|
|
e58b463f54 |
No files matched your search
@@ -577,6 +577,12 @@ jobs:
|
||||
command -v i686-w64-mingw32-gcc >/dev/null || { sudo apt-get update -qq && sudo apt-get install -y -qq gcc-mingw-w64-i686; }
|
||||
bash tools/rockstar-launcher/build.sh
|
||||
|
||||
- name: Epic Games Launcher parent stand-in (x86_64-pc-windows-gnu)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
command -v x86_64-w64-mingw32-gcc >/dev/null || { sudo apt-get update -qq && sudo apt-get install -y -qq gcc-mingw-w64-x86-64; }
|
||||
bash tools/epic-launcher/build.sh
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: xbox-arm64
|
||||
@@ -588,7 +594,7 @@ jobs:
|
||||
path: |
|
||||
~/.cache/droiddeck-pack-inputs
|
||||
~/.cache/droiddeck-build
|
||||
key: pack-inputs-v2-${{ hashFiles('tools/packs/build.sh', 'tools/packs/fetch-verified.sh', 'tools/packs/tracking/release.env', 'tools/powervr/release.json') }}
|
||||
key: pack-inputs-v2-${{ hashFiles('tools/packs/build.sh', 'tools/packs/fetch-verified.sh', 'tools/packs/tracking/release.env', 'tools/packs/zstd/release.env', 'tools/powervr/release.json') }}
|
||||
restore-keys: pack-inputs-v2-
|
||||
- name: Build the add-on packs
|
||||
run: |
|
||||
@@ -823,6 +829,7 @@ jobs:
|
||||
run: |
|
||||
cargo test --locked --manifest-path tools/ubisoft-launcher/Cargo.toml
|
||||
cargo test --locked --manifest-path tools/rockstar-launcher/Cargo.toml
|
||||
cargo test --locked --manifest-path tools/epic-launcher/Cargo.toml
|
||||
|
||||
python-tests:
|
||||
name: Python and native regression tests
|
||||
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
jq -r --arg n "$2" '.assets // [] | .[] | select(.name == $n) | .digest // empty'
|
||||
}
|
||||
commit=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$BUILD_RUN" --jq .head_sha 2>/dev/null || echo "$GITHUB_SHA")
|
||||
for name in proot directaudio tracking xbox comet butler powervr ubisoft rockstar dirt; do
|
||||
for name in proot directaudio tracking xbox comet butler powervr ubisoft rockstar dirt epic; do
|
||||
file="packs/$name.tar.zst"
|
||||
[ -f "$file" ] || { echo "::error::$name.tar.zst is missing from Build APK run $BUILD_RUN"; exit 1; }
|
||||
sha=$(sha256sum "$file" | cut -d' ' -f1)
|
||||
|
||||
@@ -37,3 +37,4 @@ app/src/main/assets/directaudio/
|
||||
app/src/main/assets/hybris/
|
||||
/tools/vr/out/
|
||||
app/src/main/assets/linuxfs/usr/local/lib/droiddeck-rockstar/
|
||||
app/src/main/assets/linuxfs/usr/local/lib/droiddeck-epic/
|
||||
+2
-2
@@ -93,7 +93,7 @@ def trackingPack = rootProject.file('tools/packs/tracking/release.env').readLine
|
||||
def prootPackPin = rootProject.file('tools/packs/proot/release.env').readLines()
|
||||
.findAll { it.contains('=') && !it.startsWith('#') }
|
||||
.collectEntries { def kv = it.split('=', 2); [(kv[0].trim()): kv[1].trim()] }
|
||||
def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr', 'ubisoft', 'rockstar', 'dirt'].collectEntries { name ->
|
||||
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")
|
||||
@@ -202,7 +202,7 @@ android {
|
||||
}
|
||||
|
||||
androidResources {
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>droiddeck-ubisoft:<dir>droiddeck-rockstar:<dir>droiddeck-dirt:<dir>directaudio:<dir>hybris'
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>droiddeck-ubisoft:<dir>droiddeck-rockstar:<dir>droiddeck-dirt:<dir>droiddeck-epic:<dir>directaudio:<dir>hybris'
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
|
||||
@@ -302,15 +302,6 @@
|
||||
android:resizeableActivity="true"
|
||||
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboard|keyboardHidden|navigation|uiMode|density" />
|
||||
|
||||
<activity
|
||||
android:name=".session.KeepTopActivity"
|
||||
android:exported="false"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:taskAffinity="${applicationId}.keeptop"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
|
||||
android:resizeableActivity="true"
|
||||
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboard|keyboardHidden|navigation|uiMode|density" />
|
||||
<activity
|
||||
android:name=".ui.SessionTypingActivity"
|
||||
android:exported="false"
|
||||
|
||||
@@ -8,6 +8,7 @@ add_library(droiddeckwayland SHARED
|
||||
src/vk_loader.c
|
||||
src/sc_layer.c
|
||||
src/ahb_swapchain.c
|
||||
src/display_buffers.c
|
||||
src/waylandcomp_jni.c
|
||||
src/gpu_clock_pin.c
|
||||
src/droiddeck_ext.c
|
||||
@@ -34,7 +35,8 @@ add_library(droiddeckwayland SHARED
|
||||
generated/text-input-unstable-v3-protocol.c
|
||||
generated/xdg-toplevel-icon-v1-protocol.c
|
||||
generated/single-pixel-buffer-v1-protocol.c
|
||||
generated/banner-ahb-v1-protocol.c
|
||||
generated/droiddeck-ahb-v1-protocol.c
|
||||
generated/droiddeck-refresh-v1-protocol.c
|
||||
src/framegen_bridge.c
|
||||
src/framegen_jni.c
|
||||
src/hudframes.c
|
||||
|
||||
@@ -19,8 +19,8 @@ exactly how Turnip already imports every gralloc buffer on Android (`vk_android.
|
||||
in play already have every extension needed; nothing is missing in the drivers. What is missing is
|
||||
a **WSI hook**: Mesa's Wayland WSI always allocates its own dma-bufs and has no way to receive or
|
||||
allocate compositor-visible buffers, so **option (a) or (c) each need a ~300-line patch to
|
||||
`wsi_common_wayland.c` in our own Wayland Turnip build** (banners-turnip-wayland
|
||||
`build_turnip_wayland_wsi.sh`, Mesa `7cda7850`) plus a small private Wayland protocol. Nothing in
|
||||
`wsi_common_wayland.c` in our own Wayland Turnip build**
|
||||
(`build_turnip_wayland_wsi.sh`, Mesa `7cda7850`) plus a small private Wayland protocol. Nothing in
|
||||
the app can remove the copy on its own. Recommended: **option (a′) - the game's WSI allocates its
|
||||
swapchain images as `AHardwareBuffer`s (gralloc-native, UBWC), imports them through the AHB path
|
||||
Turnip already has, and hands the compositor the AHB over a Unix socket (`AHardwareBuffer_send/
|
||||
@@ -77,7 +77,7 @@ Mesa's Wayland WSI creates every native swapchain image with `wsi_create_native_
|
||||
(the Android-WSI import path, `tu_image.cc:880-925`) is only reachable from the Android swapchain.
|
||||
|
||||
The patch (in our Wayland Turnip build): a new `create_mem` for the Wayland chain, selected when the
|
||||
compositor advertises a private global `banner_layer_buffer_v1`:
|
||||
compositor advertises a private global `droiddeck_layer_buffer_v1`:
|
||||
1. `AHardwareBuffer_allocate(w, h, R8G8B8A8, GPU_COLOR_OUTPUT | GPU_SAMPLED_IMAGE)`;
|
||||
`vkGetAndroidHardwareBufferPropertiesANDROID` → `vkAllocateMemory` with
|
||||
`VkImportAndroidHardwareBufferInfoANDROID` (Turnip: `tu_device.cc:3828`), bind - the image was
|
||||
@@ -85,7 +85,7 @@ compositor advertises a private global `banner_layer_buffer_v1`:
|
||||
2. `wsi_image.dma_buf_fd = dup(native_handle->data[0])`, `drm_modifier` / `row_pitches[0]` from
|
||||
the same layout → the existing `zwp_linux_dmabuf_v1` path stays untouched: the compositor keeps
|
||||
importing a dma-buf and can keep the blit path as the fallback.
|
||||
3. `banner_layer_buffer_v1.attach(wl_buffer, socket_fd)`: the WSI creates a `socketpair`, sends one
|
||||
3. `droiddeck_layer_buffer_v1.attach(wl_buffer, socket_fd)`: the WSI creates a `socketpair`, sends one
|
||||
end in the request, and calls `AHardwareBuffer_sendHandleToUnixSocket(ahb, other_end)`; the
|
||||
compositor's request handler does `AHardwareBuffer_recvHandleFromUnixSocket` and stores the AHB
|
||||
on `struct dmabuf_buffer`. Per swapchain image, once - not per frame.
|
||||
@@ -262,7 +262,7 @@ D3D12 tabs) as the workload, session log in `Download/Wayland-logs/`.
|
||||
since the blit only changed its destination) and `dumpsys gfxinfo`/battery for 5 min each. This
|
||||
is the baseline the WSI patch is measured against.
|
||||
4. **Fence probe outcome → choose the acquire-fence design** (§3) before starting the WSI patch.
|
||||
5. **WSI patch (option a) in banners-turnip-wayland**, wcp rebuild, then the same steps 1–3 with
|
||||
5. **WSI patch (option a) in the Wayland Turnip build**, wcp rebuild, then the same steps 1–3 with
|
||||
the AHB arriving from the guest: log line to add on the compositor side `layer: buffer N of
|
||||
"<window>" received from the game (AHardwareBuffer WxH, UBWC)` and the fps delta vs X11.
|
||||
|
||||
@@ -296,7 +296,7 @@ unchanged. Off by default: with the variable unset no new code runs.
|
||||
Not zero-copy yet - it is the receive side. The copy disappears when step 5 lands and
|
||||
`sc_layer_present` is handed the game's own `AHardwareBuffer` instead of a pool slot.
|
||||
|
||||
## 7. Step 5 implemented (feat/wayland-zero-copy-wsi + banners-turnip-wayland `banner_ahb_wsi.py`)
|
||||
## 7. Step 5 implemented (feat/wayland-zero-copy-wsi + the Wayland Turnip build `droiddeck_ahb_wsi.py`)
|
||||
|
||||
Option (a′) as recommended, with one deviation forced by the build: the Wayland Turnip is a
|
||||
`platforms=wayland` build with Android detection off, so `VK_ANDROID_external_memory_android_hardware_buffer`
|
||||
|
||||
+10
-10
@@ -38,7 +38,7 @@
|
||||
|
||||
extern const struct wl_interface wl_buffer_interface;
|
||||
|
||||
static const struct wl_interface *banner_ahb_v1_types[] = {
|
||||
static const struct wl_interface *droiddeck_ahb_v1_types[] = {
|
||||
NULL,
|
||||
&wl_buffer_interface,
|
||||
NULL,
|
||||
@@ -50,18 +50,18 @@ static const struct wl_interface *banner_ahb_v1_types[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct wl_message banner_ahb_v1_requests[] = {
|
||||
{ "destroy", "", banner_ahb_v1_types + 0 },
|
||||
{ "attach", "ohuuuuuu", banner_ahb_v1_types + 1 },
|
||||
static const struct wl_message droiddeck_ahb_v1_requests[] = {
|
||||
{ "destroy", "", droiddeck_ahb_v1_types + 0 },
|
||||
{ "attach", "ohuuuuuu", droiddeck_ahb_v1_types + 1 },
|
||||
};
|
||||
|
||||
static const struct wl_message banner_ahb_v1_events[] = {
|
||||
{ "mode", "2u", banner_ahb_v1_types + 0 },
|
||||
static const struct wl_message droiddeck_ahb_v1_events[] = {
|
||||
{ "mode", "2u", droiddeck_ahb_v1_types + 0 },
|
||||
};
|
||||
|
||||
WL_PRIVATE const struct wl_interface banner_ahb_v1_interface = {
|
||||
"banner_ahb_v1", 2,
|
||||
2, banner_ahb_v1_requests,
|
||||
1, banner_ahb_v1_events,
|
||||
WL_PRIVATE const struct wl_interface droiddeck_ahb_v1_interface = {
|
||||
"droiddeck_ahb_v1", 2,
|
||||
2, droiddeck_ahb_v1_requests,
|
||||
1, droiddeck_ahb_v1_events,
|
||||
};
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef BANNER_AHB_V1_SERVER_PROTOCOL_H
|
||||
#define BANNER_AHB_V1_SERVER_PROTOCOL_H
|
||||
#ifndef DROIDDECK_AHB_V1_SERVER_PROTOCOL_H
|
||||
#define DROIDDECK_AHB_V1_SERVER_PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -14,7 +14,7 @@ struct wl_client;
|
||||
struct wl_resource;
|
||||
|
||||
/*
|
||||
* @section page_copyright_banner_ahb_v1 Copyright
|
||||
* @section page_copyright_droiddeck_ahb_v1 Copyright
|
||||
*
|
||||
* Copyright 2026 The412Banner
|
||||
*
|
||||
@@ -42,15 +42,15 @@ struct wl_resource;
|
||||
|
||||
|
||||
|
||||
struct banner_ahb_v1;
|
||||
struct droiddeck_ahb_v1;
|
||||
struct wl_buffer;
|
||||
|
||||
#ifndef BANNER_AHB_V1_INTERFACE
|
||||
#define BANNER_AHB_V1_INTERFACE
|
||||
extern const struct wl_interface banner_ahb_v1_interface;
|
||||
#ifndef DROIDDECK_AHB_V1_INTERFACE
|
||||
#define DROIDDECK_AHB_V1_INTERFACE
|
||||
extern const struct wl_interface droiddeck_ahb_v1_interface;
|
||||
#endif
|
||||
|
||||
struct banner_ahb_v1_interface {
|
||||
struct droiddeck_ahb_v1_interface {
|
||||
void (*destroy)(struct wl_client *client,
|
||||
struct wl_resource *resource);
|
||||
void (*attach)(struct wl_client *client,
|
||||
@@ -65,17 +65,17 @@ struct banner_ahb_v1_interface {
|
||||
uint32_t image_count);
|
||||
};
|
||||
|
||||
#define BANNER_AHB_V1_MODE 0
|
||||
#define DROIDDECK_AHB_V1_MODE 0
|
||||
|
||||
#define BANNER_AHB_V1_MODE_SINCE_VERSION 2
|
||||
#define DROIDDECK_AHB_V1_MODE_SINCE_VERSION 2
|
||||
|
||||
#define BANNER_AHB_V1_DESTROY_SINCE_VERSION 1
|
||||
#define BANNER_AHB_V1_ATTACH_SINCE_VERSION 1
|
||||
#define DROIDDECK_AHB_V1_DESTROY_SINCE_VERSION 1
|
||||
#define DROIDDECK_AHB_V1_ATTACH_SINCE_VERSION 1
|
||||
|
||||
static inline void
|
||||
banner_ahb_v1_send_mode(struct wl_resource *resource_, uint32_t enabled)
|
||||
droiddeck_ahb_v1_send_mode(struct wl_resource *resource_, uint32_t enabled)
|
||||
{
|
||||
wl_resource_post_event(resource_, BANNER_AHB_V1_MODE, enabled);
|
||||
wl_resource_post_event(resource_, DROIDDECK_AHB_V1_MODE, enabled);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2026 DroidDeck contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of 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 (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "wayland-util.h"
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
|
||||
#endif
|
||||
|
||||
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
|
||||
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
|
||||
#else
|
||||
#define WL_PRIVATE
|
||||
#endif
|
||||
|
||||
|
||||
static const struct wl_interface *droiddeck_refresh_v1_types[] = {
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct wl_message droiddeck_refresh_v1_requests[] = {
|
||||
{ "destroy", "", droiddeck_refresh_v1_types + 0 },
|
||||
{ "set_target", "uu", droiddeck_refresh_v1_types + 0 },
|
||||
};
|
||||
|
||||
static const struct wl_message droiddeck_refresh_v1_events[] = {
|
||||
{ "rate", "u", droiddeck_refresh_v1_types + 0 },
|
||||
{ "done", "", droiddeck_refresh_v1_types + 0 },
|
||||
};
|
||||
|
||||
WL_PRIVATE const struct wl_interface droiddeck_refresh_v1_interface = {
|
||||
"droiddeck_refresh_v1", 1,
|
||||
2, droiddeck_refresh_v1_requests,
|
||||
2, droiddeck_refresh_v1_events,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
|
||||
#ifndef DROIDDECK_REFRESH_V1_SERVER_PROTOCOL_H
|
||||
#define DROIDDECK_REFRESH_V1_SERVER_PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "wayland-server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wl_client;
|
||||
struct wl_resource;
|
||||
|
||||
/**
|
||||
* @page page_droiddeck_refresh_v1 The droiddeck_refresh_v1 protocol
|
||||
* @section page_ifaces_droiddeck_refresh_v1 Interfaces
|
||||
* - @subpage page_iface_droiddeck_refresh_v1 - panel refresh rates a nested compositor may ask for
|
||||
* @section page_copyright_droiddeck_refresh_v1 Copyright
|
||||
* <pre>
|
||||
*
|
||||
* Copyright 2026 DroidDeck contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of 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 (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions 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.
|
||||
* </pre>
|
||||
*/
|
||||
struct droiddeck_refresh_v1;
|
||||
|
||||
#ifndef DROIDDECK_REFRESH_V1_INTERFACE
|
||||
#define DROIDDECK_REFRESH_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_droiddeck_refresh_v1 droiddeck_refresh_v1
|
||||
* @section page_iface_droiddeck_refresh_v1_desc Description
|
||||
*
|
||||
* A nested compositor paces its clients against the refresh rate of the
|
||||
* panel it is shown on. When its clients are held to a frame rate the
|
||||
* panel's current rate does not divide evenly, frames are shown for an
|
||||
* uneven number of refreshes. This interface lets the nested compositor
|
||||
* see every refresh rate the panel can run at its current size and ask
|
||||
* for the one that suits the frame rate it is pacing to.
|
||||
*
|
||||
* On bind the compositor sends one rate event per refresh rate, lowest
|
||||
* first, followed by done. The list is sent again, in full, whenever it
|
||||
* changes (a different panel, or a limit the user placed on the panel's
|
||||
* rate). The rate the panel is running at is still reported the standard
|
||||
* way, through wl_output.mode.
|
||||
*
|
||||
* A request is a preference, not a guarantee: the user, the platform or
|
||||
* another output mirroring the panel may hold the panel at another rate.
|
||||
* The client reads the result from wl_output.mode.
|
||||
* @section page_iface_droiddeck_refresh_v1_api API
|
||||
* See @ref iface_droiddeck_refresh_v1.
|
||||
*/
|
||||
/**
|
||||
* @defgroup iface_droiddeck_refresh_v1 The droiddeck_refresh_v1 interface
|
||||
*
|
||||
* A nested compositor paces its clients against the refresh rate of the
|
||||
* panel it is shown on. When its clients are held to a frame rate the
|
||||
* panel's current rate does not divide evenly, frames are shown for an
|
||||
* uneven number of refreshes. This interface lets the nested compositor
|
||||
* see every refresh rate the panel can run at its current size and ask
|
||||
* for the one that suits the frame rate it is pacing to.
|
||||
*
|
||||
* On bind the compositor sends one rate event per refresh rate, lowest
|
||||
* first, followed by done. The list is sent again, in full, whenever it
|
||||
* changes (a different panel, or a limit the user placed on the panel's
|
||||
* rate). The rate the panel is running at is still reported the standard
|
||||
* way, through wl_output.mode.
|
||||
*
|
||||
* A request is a preference, not a guarantee: the user, the platform or
|
||||
* another output mirroring the panel may hold the panel at another rate.
|
||||
* The client reads the result from wl_output.mode.
|
||||
*/
|
||||
extern const struct wl_interface droiddeck_refresh_v1_interface;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
* @struct droiddeck_refresh_v1_interface
|
||||
*/
|
||||
struct droiddeck_refresh_v1_interface {
|
||||
/**
|
||||
* destroy the object
|
||||
*
|
||||
* The preference set through this object is dropped.
|
||||
*/
|
||||
void (*destroy)(struct wl_client *client,
|
||||
struct wl_resource *resource);
|
||||
/**
|
||||
* ask for a refresh rate
|
||||
*
|
||||
* refresh is the panel rate the client would like, in Hz, taken
|
||||
* from the advertised list; 0 withdraws the preference. frame_rate
|
||||
* is the frame rate the client holds its content to, in frames per
|
||||
* second, or 0 when the content is not held to a rate. The
|
||||
* compositor may multiply the content's frame rate itself
|
||||
* (generated frames); when it does, it picks the advertised rate
|
||||
* that the multiplied frame rate divides evenly instead of the
|
||||
* requested one.
|
||||
* @param refresh wanted panel refresh rate in Hz, 0 for none
|
||||
* @param frame_rate content frame rate in frames per second, 0 for unpaced
|
||||
*/
|
||||
void (*set_target)(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
uint32_t refresh,
|
||||
uint32_t frame_rate);
|
||||
};
|
||||
|
||||
#define DROIDDECK_REFRESH_V1_RATE 0
|
||||
#define DROIDDECK_REFRESH_V1_DONE 1
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
*/
|
||||
#define DROIDDECK_REFRESH_V1_RATE_SINCE_VERSION 1
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
*/
|
||||
#define DROIDDECK_REFRESH_V1_DONE_SINCE_VERSION 1
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
*/
|
||||
#define DROIDDECK_REFRESH_V1_DESTROY_SINCE_VERSION 1
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
*/
|
||||
#define DROIDDECK_REFRESH_V1_SET_TARGET_SINCE_VERSION 1
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
* Sends an rate event to the client owning the resource.
|
||||
* @param resource_ The client's resource
|
||||
* @param refresh panel refresh rate in Hz
|
||||
*/
|
||||
static inline void
|
||||
droiddeck_refresh_v1_send_rate(struct wl_resource *resource_, uint32_t refresh)
|
||||
{
|
||||
wl_resource_post_event(resource_, DROIDDECK_REFRESH_V1_RATE, refresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_refresh_v1
|
||||
* Sends an done event to the client owning the resource.
|
||||
* @param resource_ The client's resource
|
||||
*/
|
||||
static inline void
|
||||
droiddeck_refresh_v1_send_done(struct wl_resource *resource_)
|
||||
{
|
||||
wl_resource_post_event(resource_, DROIDDECK_REFRESH_V1_DONE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="banner_ahb_v1">
|
||||
<protocol name="droiddeck_ahb_v1">
|
||||
<copyright>
|
||||
Copyright 2026 The412Banner
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<interface name="banner_ahb_v1" version="2">
|
||||
<interface name="droiddeck_ahb_v1" version="2">
|
||||
<description summary="Android gralloc buffers behind dma-buf wl_buffers">
|
||||
Zero-copy window layers on Android. A Vulkan swapchain image that the
|
||||
client allocated as an Android AHardwareBuffer (gralloc) is still shared
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="droiddeck_refresh_v1">
|
||||
<copyright>
|
||||
Copyright 2026 DroidDeck contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of 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 (including the next
|
||||
paragraph) shall be included in all copies or substantial portions 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.
|
||||
</copyright>
|
||||
|
||||
<interface name="droiddeck_refresh_v1" version="1">
|
||||
<description summary="panel refresh rates a nested compositor may ask for">
|
||||
A nested compositor paces its clients against the refresh rate of the
|
||||
panel it is shown on. When its clients are held to a frame rate the
|
||||
panel's current rate does not divide evenly, frames are shown for an
|
||||
uneven number of refreshes. This interface lets the nested compositor
|
||||
see every refresh rate the panel can run at its current size and ask
|
||||
for the one that suits the frame rate it is pacing to.
|
||||
|
||||
On bind the compositor sends one rate event per refresh rate, lowest
|
||||
first, followed by done. The list is sent again, in full, whenever it
|
||||
changes (a different panel, or a limit the user placed on the panel's
|
||||
rate). The rate the panel is running at is still reported the standard
|
||||
way, through wl_output.mode.
|
||||
|
||||
A request is a preference, not a guarantee: the user, the platform or
|
||||
another output mirroring the panel may hold the panel at another rate.
|
||||
The client reads the result from wl_output.mode.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the object">
|
||||
The preference set through this object is dropped.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="set_target">
|
||||
<description summary="ask for a refresh rate">
|
||||
refresh is the panel rate the client would like, in Hz, taken from
|
||||
the advertised list; 0 withdraws the preference. frame_rate is the
|
||||
frame rate the client holds its content to, in frames per second, or
|
||||
0 when the content is not held to a rate. The compositor may multiply
|
||||
the content's frame rate itself (generated frames); when it does, it
|
||||
picks the advertised rate that the multiplied frame rate divides
|
||||
evenly instead of the requested one.
|
||||
</description>
|
||||
<arg name="refresh" type="uint" summary="wanted panel refresh rate in Hz, 0 for none"/>
|
||||
<arg name="frame_rate" type="uint" summary="content frame rate in frames per second, 0 for unpaced"/>
|
||||
</request>
|
||||
|
||||
<event name="rate">
|
||||
<description summary="a refresh rate the panel can run">
|
||||
Sent once per rate, lowest first, in Hz rounded to the nearest whole
|
||||
number.
|
||||
</description>
|
||||
<arg name="refresh" type="uint" summary="panel refresh rate in Hz"/>
|
||||
</event>
|
||||
|
||||
<event name="done">
|
||||
<description summary="the list of rates is complete">
|
||||
Ends a list of rate events. The rates received since the previous
|
||||
done replace the earlier list.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "droiddeck_ext.h"
|
||||
#include "sc_layer.h"
|
||||
#include "vk_present.h"
|
||||
#include "banner-ahb-v1-server-protocol.h"
|
||||
#include "droiddeck-ahb-v1-server-protocol.h"
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@@ -25,6 +25,7 @@ struct droiddeck_dma_buf_sync_file { uint32_t flags; int32_t fd; };
|
||||
#define DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW('b', 3, struct droiddeck_dma_buf_sync_file)
|
||||
|
||||
extern volatile int g_zero_copy;
|
||||
void droiddeck_dmabuf_formats_stale(void);
|
||||
|
||||
struct ahb_buf {
|
||||
uint64_t id;
|
||||
@@ -37,6 +38,7 @@ struct ahb_buf {
|
||||
struct wl_client *client;
|
||||
struct wl_resource *resource;
|
||||
struct wl_listener resource_destroy;
|
||||
int display;
|
||||
int on_layer;
|
||||
int release_pending;
|
||||
int64_t deferred_ns;
|
||||
@@ -131,10 +133,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 (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
if (!ab->display && dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
close(fd);
|
||||
} else {
|
||||
if (!g_import_failed_logged) {
|
||||
if (!ab->display && !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));
|
||||
@@ -187,7 +189,7 @@ int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b) {
|
||||
return b && *droiddeck_dmabuf_ahb_slot((struct dmabuf_buffer *)b) != NULL;
|
||||
}
|
||||
|
||||
int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h) {
|
||||
int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h, const struct vkp_draw *draw) {
|
||||
struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot(b) : NULL;
|
||||
if (!ab) return -1;
|
||||
int dmabuf_fd = droiddeck_dmabuf_fd(b);
|
||||
@@ -205,7 +207,7 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
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,
|
||||
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;
|
||||
@@ -259,6 +261,58 @@ uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b) {
|
||||
}
|
||||
|
||||
|
||||
static int adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb,
|
||||
uint32_t stride, uint32_t image_count, uint64_t modifier) {
|
||||
AHardwareBuffer_Desc d;
|
||||
AHardwareBuffer_describe(ahb, &d);
|
||||
int bw, bh;
|
||||
droiddeck_dmabuf_size(b, &bw, &bh);
|
||||
struct ahb_buf *ab = calloc(1, sizeof(*ab));
|
||||
if (!ab) return -1;
|
||||
ab->id = g_next_id++;
|
||||
ab->b = b;
|
||||
droiddeck_dmabuf_ref(b);
|
||||
ab->ahb = ahb;
|
||||
ab->w = bw; ab->h = bh;
|
||||
ab->stride = d.stride ? d.stride : stride;
|
||||
ab->image_count = image_count;
|
||||
ab->format = d.format;
|
||||
ab->modifier = modifier;
|
||||
ab->client = c;
|
||||
ab->resource = buffer;
|
||||
ab->resource_destroy.notify = on_buffer_resource_destroyed;
|
||||
wl_resource_add_destroy_listener(buffer, &ab->resource_destroy);
|
||||
ab->fence_fd = -1;
|
||||
wl_list_insert(g_bufs.prev, &ab->link);
|
||||
*droiddeck_dmabuf_ahb_slot(b) = ab;
|
||||
|
||||
if (g_last_chain.client != c || g_last_chain.w != bw || g_last_chain.h != bh ||
|
||||
g_last_chain.image_count != image_count || g_last_chain.modifier != modifier || g_last_chain.format != d.format) {
|
||||
char count[32] = "";
|
||||
if (image_count) snprintf(count, sizeof(count), "%u images, ", image_count);
|
||||
g_last_chain = (struct chain_seen){c, bw, bh, image_count, modifier, d.format};
|
||||
droiddeck_log("layer", "zero-copy: %s from %s (%s%dx%d, %s, %s, stride %u px)",
|
||||
image_count ? "AHB swapchain" : "display buffers", droiddeck_client_name(c), count, bw, bh,
|
||||
droiddeck_ahb_format_name(d.format), modifier == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)"
|
||||
: modifier == 0 ? "linear" : "unknown modifier", ab->stride);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ahb_swapchain_adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb,
|
||||
uint64_t modifier) {
|
||||
if (!g_advertised || *droiddeck_dmabuf_ahb_slot(b)) return -1;
|
||||
AHardwareBuffer_acquire(ahb);
|
||||
if (adopt(c, buffer, b, ahb, 0, 0, modifier) != 0) { AHardwareBuffer_release(ahb); return -1; }
|
||||
((struct ahb_buf *)*droiddeck_dmabuf_ahb_slot(b))->display = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
AHardwareBuffer *ahb_swapchain_display_buffer(const struct dmabuf_buffer *b) {
|
||||
struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot((struct dmabuf_buffer *)b) : NULL;
|
||||
return ab && ab->display ? ab->ahb : NULL;
|
||||
}
|
||||
|
||||
static void ahb_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); }
|
||||
|
||||
static void ahb_attach(struct wl_client *c, struct wl_resource *r, struct wl_resource *buffer, int32_t sock,
|
||||
@@ -295,36 +349,13 @@ static void ahb_attach(struct wl_client *c, struct wl_resource *r, struct wl_res
|
||||
AHardwareBuffer_release(ahb);
|
||||
return;
|
||||
}
|
||||
|
||||
struct ahb_buf *ab = calloc(1, sizeof(*ab));
|
||||
if (!ab) { AHardwareBuffer_release(ahb); wl_client_post_no_memory(c); return; }
|
||||
ab->id = g_next_id++;
|
||||
ab->b = b;
|
||||
droiddeck_dmabuf_ref(b);
|
||||
ab->ahb = ahb;
|
||||
ab->w = bw; ab->h = bh;
|
||||
ab->stride = d.stride ? d.stride : stride;
|
||||
ab->image_count = image_count;
|
||||
ab->format = d.format;
|
||||
ab->modifier = modifier;
|
||||
ab->client = c;
|
||||
ab->resource = buffer;
|
||||
ab->resource_destroy.notify = on_buffer_resource_destroyed;
|
||||
wl_resource_add_destroy_listener(buffer, &ab->resource_destroy);
|
||||
ab->fence_fd = -1;
|
||||
wl_list_insert(g_bufs.prev, &ab->link);
|
||||
*slot = ab;
|
||||
|
||||
if (g_last_chain.client != c || g_last_chain.w != bw || g_last_chain.h != bh ||
|
||||
g_last_chain.image_count != image_count || g_last_chain.modifier != modifier || g_last_chain.format != d.format) {
|
||||
g_last_chain = (struct chain_seen){c, bw, bh, image_count, modifier, d.format};
|
||||
droiddeck_log("layer", "zero-copy: AHB swapchain from %s (%u images, %dx%d, %s, %s, stride %u px)", droiddeck_client_name(c),
|
||||
image_count, bw, bh, droiddeck_ahb_format_name(d.format), modifier == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)"
|
||||
: modifier == 0 ? "linear" : "unknown modifier", ab->stride);
|
||||
if (adopt(c, buffer, b, ahb, stride, image_count, modifier) != 0) {
|
||||
AHardwareBuffer_release(ahb);
|
||||
wl_client_post_no_memory(c);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct banner_ahb_v1_interface ahb_impl = {
|
||||
static const struct droiddeck_ahb_v1_interface ahb_impl = {
|
||||
.destroy = ahb_destroy,
|
||||
.attach = ahb_attach,
|
||||
};
|
||||
@@ -336,20 +367,21 @@ static void on_client_resource_destroyed(struct wl_resource *r) {
|
||||
static void bind_ahb(struct wl_client *c, void *data, uint32_t ver, uint32_t id) {
|
||||
static struct wl_client *last_named;
|
||||
if (ver > 2) ver = 2;
|
||||
struct wl_resource *r = wl_resource_create(c, &banner_ahb_v1_interface, (int)ver, id);
|
||||
struct wl_resource *r = wl_resource_create(c, &droiddeck_ahb_v1_interface, (int)ver, id);
|
||||
if (!r) { wl_client_post_no_memory(c); return; }
|
||||
wl_resource_set_implementation(r, &ahb_impl, NULL, on_client_resource_destroyed);
|
||||
wl_list_insert(&g_clients, wl_resource_get_link(r));
|
||||
if (ver >= BANNER_AHB_V1_MODE_SINCE_VERSION) banner_ahb_v1_send_mode(r, g_zero_copy ? 1u : 0u);
|
||||
if (ver >= DROIDDECK_AHB_V1_MODE_SINCE_VERSION) droiddeck_ahb_v1_send_mode(r, g_zero_copy ? 1u : 0u);
|
||||
if (last_named != c) {
|
||||
last_named = c;
|
||||
droiddeck_log("layer", "zero-copy: %s bound banner_ahb_v1 version %u (%s)", droiddeck_client_name(c), ver,
|
||||
droiddeck_log("layer", "zero-copy: %s bound droiddeck_ahb_v1 version %u (%s)", droiddeck_client_name(c), ver,
|
||||
ver >= 2 ? "follows the live switch" : "version 1: decides from its launch environment only");
|
||||
}
|
||||
}
|
||||
|
||||
void ahb_swapchain_set_mode(int on, int live) {
|
||||
on = on ? 1 : 0;
|
||||
if (g_zero_copy != on) droiddeck_dmabuf_formats_stale();
|
||||
g_zero_copy = on;
|
||||
if (!g_advertised) {
|
||||
if (live) droiddeck_log("layer", "zero-copy switched %s from the drawer, but no display layer is available on this device: no change",
|
||||
@@ -361,8 +393,8 @@ void ahb_swapchain_set_mode(int on, int live) {
|
||||
int told = 0;
|
||||
struct wl_resource *r;
|
||||
wl_resource_for_each(r, &g_clients) {
|
||||
if (wl_resource_get_version(r) >= BANNER_AHB_V1_MODE_SINCE_VERSION) {
|
||||
banner_ahb_v1_send_mode(r, (uint32_t)on);
|
||||
if (wl_resource_get_version(r) >= DROIDDECK_AHB_V1_MODE_SINCE_VERSION) {
|
||||
droiddeck_ahb_v1_send_mode(r, (uint32_t)on);
|
||||
told++;
|
||||
}
|
||||
}
|
||||
@@ -385,7 +417,7 @@ void ahb_swapchain_init(struct wl_display *display) {
|
||||
wl_list_init(&g_bufs);
|
||||
wl_list_init(&g_clients);
|
||||
if (!sc_layer_available()) {
|
||||
droiddeck_log("layer", "zero-copy: no display layer on this device (see the line above): banner_ahb_v1 not advertised");
|
||||
droiddeck_log("layer", "zero-copy: no display layer on this device (see the line above): droiddeck_ahb_v1 not advertised");
|
||||
return;
|
||||
}
|
||||
g_loop = wl_display_get_event_loop(display);
|
||||
@@ -395,11 +427,11 @@ void ahb_swapchain_init(struct wl_display *display) {
|
||||
return;
|
||||
}
|
||||
wl_event_loop_add_fd(g_loop, g_rel_pipe[0], WL_EVENT_READABLE, on_release_pipe, NULL);
|
||||
if (!wl_global_create(display, &banner_ahb_v1_interface, 2, NULL, bind_ahb)) {
|
||||
droiddeck_log("error", "zero-copy: banner_ahb_v1 global creation failed");
|
||||
if (!wl_global_create(display, &droiddeck_ahb_v1_interface, 2, NULL, bind_ahb)) {
|
||||
droiddeck_log("error", "zero-copy: droiddeck_ahb_v1 global creation failed");
|
||||
return;
|
||||
}
|
||||
g_advertised = 1;
|
||||
droiddeck_log("layer", "zero-copy: banner_ahb_v1 version 2 advertised (games built for it present their own gralloc buffers while the switch is on)");
|
||||
droiddeck_log("layer", "zero-copy: droiddeck_ahb_v1 version 2 advertised (games built for it present their own gralloc buffers while the switch is on)");
|
||||
ahb_swapchain_set_mode(g_zero_copy, 0);
|
||||
}
|
||||
@@ -2,16 +2,21 @@
|
||||
#define AHB_SWAPCHAIN_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct dmabuf_buffer;
|
||||
struct surface;
|
||||
struct vkp_draw;
|
||||
|
||||
void ahb_swapchain_init(struct wl_display *display);
|
||||
void ahb_swapchain_set_mode(int on, int live);
|
||||
int ahb_swapchain_last_frame_age_ms(void);
|
||||
int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b);
|
||||
int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h);
|
||||
int ahb_swapchain_adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb,
|
||||
uint64_t modifier);
|
||||
AHardwareBuffer *ahb_swapchain_display_buffer(const struct dmabuf_buffer *b);
|
||||
int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h, const struct vkp_draw *draw);
|
||||
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);
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
#include "linux-dmabuf-v1-server-protocol.h"
|
||||
#include "sc_layer.h"
|
||||
#include "ahb_swapchain.h"
|
||||
#include "display_buffers.h"
|
||||
#include "viewporter-server-protocol.h"
|
||||
#include "droiddeck-desktop-v1-server-protocol.h"
|
||||
#include "droiddeck-refresh-v1-server-protocol.h"
|
||||
#include "presentation-time-server-protocol.h"
|
||||
#include "pointer-constraints-unstable-v1-server-protocol.h"
|
||||
#include "relative-pointer-unstable-v1-server-protocol.h"
|
||||
@@ -218,6 +220,7 @@ struct surface {
|
||||
|
||||
|
||||
struct vkp_image *shm_img;
|
||||
int black_fill;
|
||||
struct wl_resource *dmabuf;
|
||||
struct dmabuf_buffer *dmabuf_buf;
|
||||
struct wl_listener dmabuf_destroy;
|
||||
@@ -280,6 +283,8 @@ static int g_dirty;
|
||||
static int64_t g_dirty_since_ns;
|
||||
volatile int g_render_on_commit = 1;
|
||||
static int64_t g_rendered_tick_ns;
|
||||
static int g_tick_spare;
|
||||
static int g_scene_queues;
|
||||
static int g_tick_held;
|
||||
static int64_t g_hold_missed_ns;
|
||||
#define HOLD_RETRY_NS 1000000000LL
|
||||
@@ -289,7 +294,11 @@ static struct {
|
||||
int64_t tick_late_ns, tick_late_max_ns, wait_ns, wait_max_ns;
|
||||
const void *buffers[PACE_BUFFERS];
|
||||
uint64_t game_frames_seen;
|
||||
unsigned gaps[4];
|
||||
} g_pace;
|
||||
static int64_t g_game_frame_ns;
|
||||
|
||||
static void note_game_frame_gap(void);
|
||||
|
||||
static void pace_note_buffer(const void *buffer) {
|
||||
for (unsigned i = 0; i < g_pace.distinct && i < PACE_BUFFERS; i++)
|
||||
@@ -318,6 +327,16 @@ volatile int g_hide_shell;
|
||||
|
||||
volatile int g_zero_copy;
|
||||
static int g_zero_copy_paused;
|
||||
extern volatile int g_display_buffer_driver;
|
||||
extern void droiddeck_on_overlay_planes(int planes);
|
||||
static int g_overlay_planes_told = -1;
|
||||
|
||||
static void tell_overlay_planes(void) {
|
||||
const int planes = (g_zero_copy && g_display_buffer_driver) ? (sc_layer_overlay_affordable() ? 1 : 0) : -1;
|
||||
if (planes == g_overlay_planes_told) return;
|
||||
g_overlay_planes_told = planes;
|
||||
droiddeck_on_overlay_planes(planes);
|
||||
}
|
||||
static int g_zero_copy_fx_skip_said;
|
||||
|
||||
volatile int g_ubwc = 1;
|
||||
@@ -689,6 +708,13 @@ const struct wl_buffer_interface dbuf_buffer_impl = {
|
||||
.destroy = dbuf_buffer_destroy_req,
|
||||
};
|
||||
|
||||
static struct vkp_image *import_dmabuf(struct dmabuf_buffer *b) {
|
||||
AHardwareBuffer *ahb = ahb_swapchain_display_buffer(b);
|
||||
struct vkp_image *img = ahb ? vkp_image_from_ahb(ahb) : NULL;
|
||||
return img ? img : vkp_image_from_dmabuf(b->fd[0], b->format, b->modifier, b->width, b->height, b->stride[0],
|
||||
b->offset[0]);
|
||||
}
|
||||
|
||||
static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer) {
|
||||
if (buffer && wl_resource_instance_of(buffer, &wl_buffer_interface, &dbuf_buffer_impl))
|
||||
return wl_resource_get_user_data(buffer);
|
||||
@@ -868,6 +894,12 @@ int droiddeck_hud_frame_times(float *out, int len, int64_t *total) {
|
||||
static uint64_t g_game_frames;
|
||||
extern void droiddeck_on_game_surface(const char *window, const char *gpu);
|
||||
extern void droiddeck_on_game_frame(void);
|
||||
extern void droiddeck_on_content_rate(int fps);
|
||||
static int64_t g_cadence_ns;
|
||||
static int64_t g_cadence_frames;
|
||||
static int g_content_fps;
|
||||
static int g_framegen_layer_said;
|
||||
static int g_framegen_layer;
|
||||
extern void droiddeck_on_game_program(int pid, const char *program);
|
||||
|
||||
static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_resource *buffer) {
|
||||
@@ -888,6 +920,7 @@ static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_res
|
||||
s->buf_w = w;
|
||||
s->buf_h = h;
|
||||
s->buf_alpha = wl_shm_buffer_get_format(shm) == WL_SHM_FORMAT_ARGB8888;
|
||||
s->black_fill = 0;
|
||||
s->has_content = s->shm_img != NULL;
|
||||
g_stat_shm++;
|
||||
struct client_info *ci = client_info_of(wl_resource_get_client(s->resource));
|
||||
@@ -932,6 +965,7 @@ static void take_pixel(struct surface *s, const uint8_t bgra[4], struct wl_resou
|
||||
s->buf_w = 1;
|
||||
s->buf_h = 1;
|
||||
s->buf_alpha = bgra[3] != 0xff;
|
||||
s->black_fill = !bgra[0] && !bgra[1] && !bgra[2] && bgra[3] == 0xff;
|
||||
s->has_content = s->shm_img != NULL;
|
||||
}
|
||||
|
||||
@@ -950,8 +984,7 @@ static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_re
|
||||
wl_resource_add_destroy_listener(buffer, &s->dmabuf_destroy);
|
||||
}
|
||||
if (!b->img && !b->import_failed && b->n_planes >= 1) {
|
||||
b->img = vkp_image_from_dmabuf(b->fd[0], b->format, b->modifier, b->width, b->height,
|
||||
b->stride[0], b->offset[0]);
|
||||
b->img = import_dmabuf(b);
|
||||
if (b->img && g_zero_copy) sc_layer_probe_dmabuf_fd(b->fd[0]);
|
||||
if (!b->img) {
|
||||
b->import_failed = 1;
|
||||
@@ -1019,7 +1052,25 @@ static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_re
|
||||
}
|
||||
if (s == g_hud_surface) {
|
||||
g_hud_alive_ns = now_ns();
|
||||
if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; g_hud_new = 1; g_game_frames++; droiddeck_on_game_frame(); }
|
||||
if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; g_hud_new = 1; g_game_frames++; note_game_frame_gap(); droiddeck_on_game_frame(); }
|
||||
}
|
||||
}
|
||||
|
||||
static void note_game_frame_gap(void) {
|
||||
const int64_t now = now_ns();
|
||||
if (g_game_frame_ns && g_refresh_ns > 0) {
|
||||
const int64_t gap = (now - g_game_frame_ns + g_refresh_ns / 2) / g_refresh_ns;
|
||||
g_pace.gaps[gap < 1 ? 0 : gap > 4 ? 3 : gap - 1]++;
|
||||
}
|
||||
if (g_game_frame_ns && now - g_game_frame_ns >= 1000000000LL) { g_cadence_ns = 0; g_cadence_frames = 0; }
|
||||
g_game_frame_ns = now;
|
||||
if (!g_cadence_ns) g_cadence_ns = now;
|
||||
g_cadence_frames++;
|
||||
if (now - g_cadence_ns >= 1000000000LL) {
|
||||
g_content_fps = (int)((g_cadence_frames * 1000000000LL + (now - g_cadence_ns) / 2) / (now - g_cadence_ns));
|
||||
droiddeck_on_content_rate(g_content_fps);
|
||||
g_cadence_ns = now;
|
||||
g_cadence_frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1204,8 +1255,7 @@ static void cursor_publish_buffer(struct surface *s, struct wl_resource *buffer)
|
||||
} else if (db && db->n_planes >= 1 && db->width > 0 && db->height > 0 &&
|
||||
(int64_t)db->width * db->height <= CURSOR_MAX_PX) {
|
||||
if (!db->img && !db->import_failed) {
|
||||
db->img = vkp_image_from_dmabuf(db->fd[0], db->format, db->modifier, db->width, db->height,
|
||||
db->stride[0], db->offset[0]);
|
||||
db->img = import_dmabuf(db);
|
||||
if (!db->img) db->import_failed = 1;
|
||||
}
|
||||
if (!db->img) return;
|
||||
@@ -1213,8 +1263,9 @@ static void cursor_publish_buffer(struct surface *s, struct wl_resource *buffer)
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
if (vkp_image_readback(db->img, g_cursor_rb, CURSOR_MAX_PX) != 0) return;
|
||||
const int row = vkp_image_width(db->img);
|
||||
cursor_publish_pixels((const uint8_t *)g_cursor_rb, db->width, db->height,
|
||||
(size_t)db->width * 4, g_cursor_hx, g_cursor_hy);
|
||||
(size_t)(row > db->width ? row : db->width) * 4, g_cursor_hx, g_cursor_hy);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -1884,6 +1935,57 @@ static void output_send_mode(struct wl_resource *r, int mhz) {
|
||||
mhz);
|
||||
}
|
||||
|
||||
#define PANEL_RATES_MAX 16
|
||||
extern void droiddeck_on_refresh_target(int refresh, int frame_rate);
|
||||
static pthread_mutex_t g_panel_rates_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_panel_rates[PANEL_RATES_MAX], g_panel_rate_count;
|
||||
static atomic_int g_panel_rates_pending;
|
||||
static struct wl_list g_refresh_clients;
|
||||
static struct wl_resource *g_refresh_target_owner;
|
||||
|
||||
static void refresh_send_rates(struct wl_resource *r) {
|
||||
int rates[PANEL_RATES_MAX];
|
||||
pthread_mutex_lock(&g_panel_rates_lock);
|
||||
const int count = g_panel_rate_count;
|
||||
memcpy(rates, g_panel_rates, sizeof(rates));
|
||||
pthread_mutex_unlock(&g_panel_rates_lock);
|
||||
for (int i = 0; i < count; i++) droiddeck_refresh_v1_send_rate(r, (uint32_t)rates[i]);
|
||||
droiddeck_refresh_v1_send_done(r);
|
||||
}
|
||||
|
||||
static void refresh_notify_rates(void) {
|
||||
struct wl_resource *r;
|
||||
wl_resource_for_each(r, &g_refresh_clients) refresh_send_rates(r);
|
||||
}
|
||||
|
||||
static void refresh_resource_destroy(struct wl_resource *r) {
|
||||
wl_list_remove(wl_resource_get_link(r));
|
||||
if (g_refresh_target_owner != r) return;
|
||||
g_refresh_target_owner = NULL;
|
||||
droiddeck_on_refresh_target(0, 0);
|
||||
}
|
||||
|
||||
static void refresh_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); }
|
||||
|
||||
static void refresh_set_target(struct wl_client *c, struct wl_resource *r, uint32_t refresh, uint32_t frame_rate) {
|
||||
if (!refresh && !frame_rate && g_refresh_target_owner && g_refresh_target_owner != r) return;
|
||||
g_refresh_target_owner = refresh || frame_rate ? r : NULL;
|
||||
droiddeck_on_refresh_target((int)refresh, (int)frame_rate);
|
||||
}
|
||||
|
||||
static const struct droiddeck_refresh_v1_interface refresh_impl = {
|
||||
.destroy = refresh_destroy_req,
|
||||
.set_target = refresh_set_target,
|
||||
};
|
||||
|
||||
static void bind_refresh(struct wl_client *c, void *data, uint32_t ver, uint32_t id) {
|
||||
struct wl_resource *r = wl_resource_create(c, &droiddeck_refresh_v1_interface, ver, id);
|
||||
if (!r) { wl_client_post_no_memory(c); return; }
|
||||
wl_resource_set_implementation(r, &refresh_impl, NULL, refresh_resource_destroy);
|
||||
wl_list_insert(&g_refresh_clients, wl_resource_get_link(r));
|
||||
refresh_send_rates(r);
|
||||
}
|
||||
|
||||
static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t id) {
|
||||
struct wl_resource *r = wl_resource_create(c, &wl_output_interface, ver, id);
|
||||
if (!r) { wl_client_post_no_memory(c); return; }
|
||||
@@ -2014,19 +2116,47 @@ static int on_frame_timer(void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int black_fill_below(const struct draw_list *dl, int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct surface *s, *found = NULL;
|
||||
wl_list_for_each(s, &g_surfaces, link)
|
||||
if (s->shm_img == dl->d[i].img) { found = s; break; }
|
||||
if (!found || !found->black_fill || dl->d[i].blend) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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->dx != 0 || d->dy != 0 || d->dw != scene_w || d->dh != scene_h) continue;
|
||||
if (d->sx != 0 || d->sy != 0 || (int)d->sw != vkp_image_width(d->img) ||
|
||||
(int)d->sh != vkp_image_height(d->img)) 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;
|
||||
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;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void note_copy_scene(const struct draw_list *dl, int scene_w, int scene_h, int pointer) {
|
||||
static int said[6];
|
||||
const struct vkp_draw *t = dl->n > 0 ? &dl->d[dl->n - 1] : NULL;
|
||||
const int now[6] = {dl->n, pointer, t ? t->dw : 0, t ? t->dh : 0, scene_w, scene_h};
|
||||
if (!memcmp(now, said, sizeof(said))) return;
|
||||
memcpy(said, now, sizeof(said));
|
||||
if (pointer)
|
||||
droiddeck_log("layer", "zero-copy: copy path while the pointer is drawn into the scene");
|
||||
else if (t)
|
||||
droiddeck_log("layer", "zero-copy: copy path: no window fills the %dx%d scene on its own (%d surfaces, top one "
|
||||
"%dx%d at %d,%d from %.2f,%.2f %.2fx%.2f of a %dx%d %s buffer%s)", scene_w, scene_h, dl->n, t->dw, t->dh,
|
||||
t->dx, t->dy, t->sx, t->sy, t->sw, t->sh, vkp_image_width(t->img), vkp_image_height(t->img),
|
||||
vkp_image_is_dmabuf(t->img) ? "GPU" : "memory", t->blend ? ", translucent" : "");
|
||||
}
|
||||
|
||||
static struct surface *surface_for_image(const struct vkp_image *img) {
|
||||
struct surface *s;
|
||||
wl_list_for_each(s, &g_surfaces, link)
|
||||
@@ -2066,17 +2196,28 @@ static struct surface *hdr_unimported_fullscreen(const struct draw_list *dl, int
|
||||
}
|
||||
|
||||
static int is_hdr_surface(struct surface *s) {
|
||||
const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL;
|
||||
return c && (c->dataspace || c->convert);
|
||||
}
|
||||
|
||||
static int is_raw_hdr_surface(struct surface *s) {
|
||||
const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL;
|
||||
return c && c->dataspace;
|
||||
}
|
||||
|
||||
static int framegen_fits_layer(void) {
|
||||
const int64_t rate = (int64_t)g_content_fps * (1 + vkp_framegen_extra_images()) * 1000;
|
||||
return g_content_fps > 0 &&
|
||||
rate * 100 <= (int64_t)atomic_load(&g_output_refresh_mhz) * (g_framegen_layer ? 108 : 104);
|
||||
}
|
||||
|
||||
static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int framegen, struct hdr_scene *hs) {
|
||||
memset(hs, 0, sizeof(*hs));
|
||||
if (!droiddeck_color_hdr_open()) return 0;
|
||||
struct surface *un = hdr_unimported_fullscreen(dl, w, h);
|
||||
if (!un) {
|
||||
struct surface *lo = ahb_layer_only_candidate(w, h);
|
||||
if (lo && is_hdr_surface(lo)) un = lo;
|
||||
if (lo && is_raw_hdr_surface(lo)) un = lo;
|
||||
}
|
||||
if (un && g_zero_copy) { hs->color = droiddeck_color_of(un->resource); hs->who = un; return 3; }
|
||||
hs->hf.tonemap = !droiddeck_color_output();
|
||||
@@ -2084,24 +2225,48 @@ static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int fra
|
||||
for (int i = 0; i < dl->n; i++) {
|
||||
struct surface *s = surface_for_image(dl->d[i].img);
|
||||
if (!is_hdr_surface(s)) continue;
|
||||
hs->is_hdr[i] = 1;
|
||||
const struct droiddeck_color *c = droiddeck_color_of(s->resource);
|
||||
if (c->convert && hs->hf.convert && (hs->hf.convert->gain != c->gain ||
|
||||
memcmp(hs->hf.convert->to2020, c->to2020, sizeof(c->to2020)) != 0)) {
|
||||
static int said;
|
||||
if (!said) {
|
||||
said = 1;
|
||||
droiddeck_log("color", "two windows need different colour conversions in one frame: the upper one is "
|
||||
"shown as SDR");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
hs->is_hdr[i] = c->convert ? 2 : 1;
|
||||
if (c->convert) hs->hf.convert = c;
|
||||
hs->n_hdr++;
|
||||
hs->color = droiddeck_color_of(s->resource);
|
||||
hs->color = c;
|
||||
hs->who = s;
|
||||
}
|
||||
if (!hs->n_hdr) { free(hs->is_hdr); hs->is_hdr = NULL; return 0; }
|
||||
if (hs->color->convert) {
|
||||
static struct droiddeck_color composed;
|
||||
composed = *hs->color;
|
||||
composed.dataspace = DROIDDECK_ADATASPACE_BT2020_PQ;
|
||||
composed.convert = 0;
|
||||
hs->color = &composed;
|
||||
}
|
||||
hs->hf.is_hdr = hs->is_hdr;
|
||||
hs->hf.color = hs->color;
|
||||
hs->hf.peak_nits = hs->color->max_cll > 0.0f ? hs->color->max_cll
|
||||
: hs->color->has_st2086 ? hs->color->max_lum : 1000.0f;
|
||||
if (framegen) return 2;
|
||||
if (framegen) {
|
||||
if (!g_zero_copy || !framegen_fits_layer()) return 2;
|
||||
hs->why = "frame generation is on";
|
||||
return 1;
|
||||
}
|
||||
int li = g_zero_copy ? layer_candidate(dl, w, h) : -1;
|
||||
int over = li >= 0 ? dl->n - 1 - li : 0;
|
||||
if (!hs->hf.tonemap && !fx_on && li >= 0 && hs->is_hdr[li] &&
|
||||
if (!hs->hf.tonemap && !hs->hf.convert && !fx_on && li >= 0 && hs->is_hdr[li] &&
|
||||
(over == 0 || (over == 1 && sc_layer_overlay_affordable())))
|
||||
return 0;
|
||||
hs->why = hs->hf.tonemap ? "HDR output is switched off in the drawer"
|
||||
: fx_on ? "screen effects are on"
|
||||
: hs->hf.convert ? "its colours are converted to BT.2020 PQ"
|
||||
: !g_zero_copy ? "zero-copy presentation is off"
|
||||
: (li >= 0 && hs->is_hdr[li]) ? "a window is above the game and this display cannot compose a second layer"
|
||||
: "the HDR game is not one fullscreen window";
|
||||
@@ -2174,8 +2339,7 @@ static void hdr_note_precedence(struct surface *hs, int fx_on, int framegen) {
|
||||
static void hdr_count_copied(const struct draw_list *dl, const char *reason) {
|
||||
for (int i = 0; i < dl->n; i++) {
|
||||
struct surface *s = surface_for_image(dl->d[i].img);
|
||||
const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL;
|
||||
if (!c || !c->dataspace) continue;
|
||||
if (!is_hdr_surface(s)) continue;
|
||||
char name[160];
|
||||
describe(s, name, sizeof(name));
|
||||
droiddeck_color_frame_copied(name, reason);
|
||||
@@ -2317,6 +2481,8 @@ static void render_scene(void) {
|
||||
g_dirty_since_ns = 0;
|
||||
}
|
||||
g_dirty = 0;
|
||||
if (g_rendered_tick_ns == g_tick_vsync_ns) g_tick_spare = 0;
|
||||
g_scene_queues = 0;
|
||||
g_rendered_tick_ns = g_tick_vsync_ns;
|
||||
g_tick_held = 0;
|
||||
g_hud_fresh = 0;
|
||||
@@ -2378,7 +2544,13 @@ static void render_scene(void) {
|
||||
static int fell_back;
|
||||
vkp_apply_window_request();
|
||||
sc_layer_hide_overlay();
|
||||
if (sc_layer_present_hdr_scene(dl.d, dl.n, &hs.hf, w, h, hs.color) == 0) {
|
||||
const int generated = framegen ? sc_layer_present_generated(dl.d, dl.n, &hs.hf, w, h, 1, hs.color) : 0;
|
||||
if (framegen) g_framegen_layer = generated >= 0;
|
||||
if (generated > 0 && g_framegen_layer_said != 3) {
|
||||
g_framegen_layer_said = 3;
|
||||
droiddeck_log("framegen", "generated frames and the composed HDR picture go on the game's display layer");
|
||||
}
|
||||
if (framegen ? generated >= 0 : sc_layer_present_hdr_scene(dl.d, dl.n, &hs.hf, w, h, hs.color) == 0) {
|
||||
rendered = vkp_base_black(w, h) == 0;
|
||||
if (fell_back) { fell_back = 0; droiddeck_log("color", "the composed picture is on the game's display layer again"); }
|
||||
} else {
|
||||
@@ -2404,13 +2576,16 @@ static void render_scene(void) {
|
||||
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;
|
||||
int li = (g_zero_copy && !framegen && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1;
|
||||
tell_overlay_planes();
|
||||
const int fg_layer = framegen && 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 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; }
|
||||
const int ov_blocks = (li >= 0 && over > 0 && !fx_blocks && !sc_layer_overlay_affordable());
|
||||
if (ov_blocks) { li = -1; over = 0; }
|
||||
const int blocked = framegen ? 1 : bfi ? 4 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0));
|
||||
const int blocked = (framegen && !fg_layer) ? 1 : bfi ? 4 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0));
|
||||
if (g_zero_copy && !cursor_on && blocked != g_zero_copy_paused) {
|
||||
g_zero_copy_paused = blocked;
|
||||
if (blocked == 1)
|
||||
@@ -2419,14 +2594,21 @@ static void render_scene(void) {
|
||||
droiddeck_log("effects", "zero-copy paused: a window above the game needs the compositor pass for the whole scene");
|
||||
else if (blocked == 4)
|
||||
droiddeck_log("bfi", "zero-copy paused: black frame insertion needs the compositor pass");
|
||||
else if (blocked == 3)
|
||||
droiddeck_log("layer", "zero-copy paused: a window above the game would need a second display layer, "
|
||||
"which this display cannot compose in hardware - whole scene on the copy path");
|
||||
else if (blocked == 3) {
|
||||
const struct vkp_draw *top = &dl.d[dl.n - 1];
|
||||
struct surface *ts = surface_for_image(top->img);
|
||||
droiddeck_log("layer", "zero-copy paused: a window above the game (%dx%d at %d,%d%s, %s) would need a second "
|
||||
"display layer, which this display cannot compose in hardware - whole scene on the copy path",
|
||||
top->dw, top->dh, top->dx, top->dy, top->blend ? ", translucent" : "",
|
||||
ts ? client_name(wl_resource_get_client(ts->resource)) : "no client surface");
|
||||
}
|
||||
else
|
||||
droiddeck_log("effects", "zero-copy resumed: the game is back on its own display layer");
|
||||
}
|
||||
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 (cardboard) ls = NULL;
|
||||
if (cursor_on) ls = NULL;
|
||||
if (bfi) ls = NULL;
|
||||
@@ -2439,11 +2621,23 @@ static void render_scene(void) {
|
||||
if (li >= 0 || ls) {
|
||||
vkp_apply_window_request();
|
||||
int r = -1;
|
||||
if (!(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);
|
||||
if (r != 0 && li >= 0)
|
||||
const int fg_pass = framegen && fx_on && li >= 0;
|
||||
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;
|
||||
if (generated > 0 && g_framegen_layer_said != 1 + fg_pass) {
|
||||
g_framegen_layer_said = 1 + fg_pass;
|
||||
droiddeck_log("framegen", fg_pass
|
||||
? "generated frames and the game's frames go on the game's display layer straight from the screen effects pass"
|
||||
: "generated frames go on the game's display layer between the game's own frames");
|
||||
}
|
||||
if (fg_pass)
|
||||
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, ls ? droiddeck_surface_color(ls) : NULL);
|
||||
: sc_layer_present(dl.d[li].img, w, h, ld, ls ? droiddeck_surface_color(ls) : NULL);
|
||||
if (r == 0) {
|
||||
if (ls) ls->drawn = 1;
|
||||
int go[8], ov = 0;
|
||||
@@ -2457,8 +2651,10 @@ static void render_scene(void) {
|
||||
hdr_copy = "the overlay layer refused the window above it";
|
||||
} else {
|
||||
rendered = vkp_base_black(w, h) == 0;
|
||||
g_scene_queues = sc_layer_queues();
|
||||
}
|
||||
} else {
|
||||
sc_layer_hide();
|
||||
rendered = vkp_render(w, h, dl.d, dl.n) == 0;
|
||||
copy = 1;
|
||||
hdr_copy = "its display layer was unavailable this frame";
|
||||
@@ -2518,8 +2714,12 @@ static int commit_renders_on(void) {
|
||||
!g_bfi_running;
|
||||
}
|
||||
|
||||
static int tick_takes_scene(void) {
|
||||
return g_rendered_tick_ns != g_tick_vsync_ns || (g_tick_spare && g_scene_queues);
|
||||
}
|
||||
|
||||
static int render_on_commit(void) {
|
||||
return commit_renders_on() && !g_render_idle && g_rendered_tick_ns != g_tick_vsync_ns;
|
||||
return commit_renders_on() && !g_render_idle && tick_takes_scene();
|
||||
}
|
||||
|
||||
static void schedule_render(void) {
|
||||
@@ -2546,7 +2746,7 @@ static int scene_waits_for_game(int64_t now) {
|
||||
|
||||
static void on_commit_idle(void *data) {
|
||||
g_render_idle = NULL;
|
||||
if (!g_dirty || !commit_renders_on() || g_rendered_tick_ns == g_tick_vsync_ns || scene_waits_for_game(now_ns())) return;
|
||||
if (!g_dirty || !commit_renders_on() || !tick_takes_scene() || scene_waits_for_game(now_ns())) return;
|
||||
g_pace.commit_renders++;
|
||||
render_scene();
|
||||
}
|
||||
@@ -2621,6 +2821,7 @@ static void on_vsync(int64_t frame_time_ns) {
|
||||
if (d > 3000000LL && d < 40000000LL) g_refresh_ns = (g_refresh_ns * 7 + d) / 8;
|
||||
}
|
||||
g_last_vsync_ns = now;
|
||||
g_tick_spare = g_rendered_tick_ns != g_tick_vsync_ns;
|
||||
g_tick_vsync_ns = frame_time_ns;
|
||||
int tick_change = 0;
|
||||
if (vkp_apply_window_request()) tick_change = 1;
|
||||
@@ -3843,6 +4044,10 @@ static int on_input_readable(int fd, uint32_t mask, void *data) {
|
||||
output_notify_mode();
|
||||
wl_display_flush_clients(g_display);
|
||||
}
|
||||
if (atomic_exchange(&g_panel_rates_pending, 0)) {
|
||||
refresh_notify_rates();
|
||||
wl_display_flush_clients(g_display);
|
||||
}
|
||||
if (vsync) on_vsync(vsync_ns);
|
||||
return 0;
|
||||
}
|
||||
@@ -3892,6 +4097,23 @@ void droiddeck_wayland_output_resized(void) {
|
||||
(void)n;
|
||||
}
|
||||
|
||||
void droiddeck_wayland_set_panel_rates(const int *rates, int count) {
|
||||
if (count > PANEL_RATES_MAX) count = PANEL_RATES_MAX;
|
||||
pthread_mutex_lock(&g_panel_rates_lock);
|
||||
const int same = count == g_panel_rate_count && !memcmp(rates, g_panel_rates, (size_t)count * sizeof(int));
|
||||
if (!same) {
|
||||
memcpy(g_panel_rates, rates, (size_t)count * sizeof(int));
|
||||
g_panel_rate_count = count;
|
||||
}
|
||||
pthread_mutex_unlock(&g_panel_rates_lock);
|
||||
if (same || g_input_pipe[1] < 0) return;
|
||||
atomic_store(&g_panel_rates_pending, 1);
|
||||
struct input_msg m = { 10, 0, 0, 0, 0 };
|
||||
ssize_t n;
|
||||
do { n = write(g_input_pipe[1], &m, sizeof(m)); } while (n < 0 && errno == EINTR);
|
||||
(void)n;
|
||||
}
|
||||
|
||||
void droiddeck_wayland_set_output_refresh_rate(int mhz) {
|
||||
if (mhz <= 0) mhz = 60000;
|
||||
if (atomic_exchange(&g_output_refresh_mhz, mhz) == mhz || g_input_pipe[1] < 0) return;
|
||||
@@ -3974,12 +4196,15 @@ static int on_stats_timer(void *data) {
|
||||
struct vkp_perf vp;
|
||||
vkp_perf_take(&vp);
|
||||
const unsigned drops = sc_layer_drops_take();
|
||||
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)
|
||||
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",
|
||||
"release %.2f/%.2f ms (%u, %u held) | %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,
|
||||
vp.base_kept, vp.base_presents,
|
||||
@@ -3987,7 +4212,7 @@ 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);
|
||||
g_perf.releases, g_perf.releases_held, drops, aimed_next, aimed_later, aimed_even);
|
||||
#undef PERF_MS
|
||||
memset(&g_perf, 0, sizeof(g_perf));
|
||||
}
|
||||
@@ -3997,12 +4222,12 @@ static int on_stats_timer(void *data) {
|
||||
droiddeck_log("pacing", "last 10 s: tick reaches compositor %.2f/%.2f ms late (%u ticks, %u over 2 ms) | "
|
||||
"new frame waits %.2f/%.2f ms to be drawn (%u scenes, %u on arrival) | %llu game frames, %u re-attached after an "
|
||||
"empty attach, %u empty attaches, %u distinct buffers | feedback %u shown, %u replaced before drawing, "
|
||||
"%u not drawn",
|
||||
"%u not drawn | game frames arrived 1/2/3/4+ refreshes apart %u/%u/%u/%u",
|
||||
g_pace.ticks ? (double)g_pace.tick_late_ns / 1e6 / g_pace.ticks : 0.0, (double)g_pace.tick_late_max_ns / 1e6,
|
||||
g_pace.ticks, g_pace.ticks_late_2ms,
|
||||
g_pace.renders ? (double)g_pace.wait_ns / 1e6 / g_pace.renders : 0.0, (double)g_pace.wait_max_ns / 1e6,
|
||||
g_pace.renders, g_pace.commit_renders, (unsigned long long)game, g_pace.reattaches, g_pace.null_attaches, g_pace.distinct,
|
||||
g_pace.presented, g_pace.replaced, g_pace.undrawn);
|
||||
g_pace.presented, g_pace.replaced, g_pace.undrawn, g_pace.gaps[0], g_pace.gaps[1], g_pace.gaps[2], g_pace.gaps[3]);
|
||||
}
|
||||
if (g_bfi_stats.lit || g_bfi_stats.dark || g_bfi_stats.failed) {
|
||||
droiddeck_log("bfi", "last 10 s: %u pictures, %u black refreshes, %u black refreshes not presented",
|
||||
@@ -4028,6 +4253,12 @@ static int on_stats_timer(void *data) {
|
||||
"draw - expect a black picture (main device %u:%u)", ci->name,
|
||||
(unsigned)major(g_main_device), (unsigned)minor(g_main_device));
|
||||
}
|
||||
if (g_content_fps > 0 && now_ns() - g_game_frame_ns >= 2000000000LL) {
|
||||
g_content_fps = 0;
|
||||
g_cadence_ns = 0;
|
||||
g_cadence_frames = 0;
|
||||
droiddeck_on_content_rate(0);
|
||||
}
|
||||
wl_event_source_timer_update(g_stats_timer, 10000);
|
||||
return 0;
|
||||
}
|
||||
@@ -4106,6 +4337,7 @@ int droiddeck_wayland_run(void) {
|
||||
wl_list_init(&g_surfaces);
|
||||
wl_list_init(&g_toplevels);
|
||||
wl_list_init(&g_outputs);
|
||||
wl_list_init(&g_refresh_clients);
|
||||
wl_list_init(&g_constraints);
|
||||
wl_list_init(&g_relative_pointers);
|
||||
open_session_log();
|
||||
@@ -4143,6 +4375,7 @@ int droiddeck_wayland_run(void) {
|
||||
wl_display_init_shm(display);
|
||||
|
||||
wl_global_create(display, &wl_output_interface, 4, NULL, bind_output);
|
||||
wl_global_create(display, &droiddeck_refresh_v1_interface, 1, NULL, bind_refresh);
|
||||
wl_global_create(display, &xdg_wm_base_interface, 1, NULL, bind_xdg_wm_base);
|
||||
wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf);
|
||||
droiddeck_android_wlegl_init(display);
|
||||
@@ -4153,6 +4386,7 @@ 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);
|
||||
display_buffers_init(display);
|
||||
|
||||
|
||||
droiddeck_color_init(display);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define DRM_XBGR8888 FOURCC('X', 'B', '2', '4')
|
||||
#define MOD_LINEAR VKP_MOD_LINEAR
|
||||
#define MOD_INVALID VKP_MOD_INVALID
|
||||
#define MOD_QCOM_COMPRESSED VKP_MOD_QCOM_COMPRESSED
|
||||
#define MAX_PLANES 4
|
||||
|
||||
struct dmabuf_params {
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
#define _GNU_SOURCE
|
||||
#include "display_buffers.h"
|
||||
#include "ahb_swapchain.h"
|
||||
#include "compositor_internal.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "droiddeck_ext.h"
|
||||
#include "sc_layer.h"
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DISPLAY_BUFFERS_SOCKET "droiddeck-display-buffers"
|
||||
#define DISPLAY_BUFFERS_MAGIC 0x42444444u
|
||||
#define DISPLAY_BUFFERS_VERSION 1u
|
||||
#define DISPLAY_BUFFERS_ALLOC 1u
|
||||
#define DISPLAY_BUFFERS_FREE 2u
|
||||
#define DISPLAY_BUFFERS_MAX_SIDE 16384u
|
||||
#define DISPLAY_BUFFERS_MAX_PER_CLIENT 256
|
||||
#define DISPLAY_BUFFERS_PROBE_W 1280u
|
||||
#define DISPLAY_BUFFERS_PROBE_H 720u
|
||||
#define ALIGN_UP(v, a) (((v) + (a) - 1) / (a) * (a))
|
||||
|
||||
extern volatile int g_zero_copy;
|
||||
volatile int g_display_buffer_driver;
|
||||
|
||||
struct display_buffers_request {
|
||||
uint32_t magic, version, op, width, height, format, stride, offset;
|
||||
uint64_t size, id, modifier;
|
||||
};
|
||||
|
||||
struct display_buffers_reply {
|
||||
uint32_t magic, status;
|
||||
uint64_t id, size;
|
||||
};
|
||||
|
||||
struct peer {
|
||||
int fd;
|
||||
pid_t pid;
|
||||
int count;
|
||||
int logged_w, logged_h;
|
||||
uint32_t logged_format;
|
||||
struct wl_event_source *src;
|
||||
};
|
||||
|
||||
struct entry {
|
||||
uint64_t id;
|
||||
dev_t dev;
|
||||
ino_t ino;
|
||||
AHardwareBuffer *ahb;
|
||||
uint32_t format, stride, width, height;
|
||||
uint64_t modifier;
|
||||
struct peer *peer;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
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;
|
||||
static int g_ubwc_probed[2];
|
||||
|
||||
static uint32_t ahb_format_of(uint32_t drm, uint64_t modifier) {
|
||||
switch (drm) {
|
||||
case DRM_ABGR8888: case DRM_XBGR8888: return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
||||
case DRM_ARGB8888: case DRM_XRGB8888: return modifier == MOD_QCOM_COMPRESSED ? AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM : 0;
|
||||
case FOURCC('A', 'B', '3', '0'): case FOURCC('X', 'B', '3', '0'): return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t ubwc_meta_size(uint32_t w, uint32_t h) {
|
||||
return ALIGN_UP((uint64_t)ALIGN_UP((w + 15) / 16, 64) * ALIGN_UP((h + 3) / 4, 16), 4096);
|
||||
}
|
||||
|
||||
static uint64_t ubwc_size(uint32_t w, uint32_t h, uint32_t stride) {
|
||||
return ubwc_meta_size(w, h) + ALIGN_UP((uint64_t)stride * ALIGN_UP(h, 16), 4096);
|
||||
}
|
||||
|
||||
static void entry_free(struct entry *e) {
|
||||
wl_list_remove(&e->link);
|
||||
e->peer->count--;
|
||||
AHardwareBuffer_release(e->ahb);
|
||||
free(e);
|
||||
}
|
||||
|
||||
static AHardwareBuffer *allocate_ubwc(uint32_t w, uint32_t h, uint32_t format, uint32_t stride, int *fd, uint64_t *size) {
|
||||
const uint64_t tiers[2] = {SC_LAYER_AHB_USAGE_VENDOR_UBWC, 0};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
AHardwareBuffer_Desc d = {
|
||||
.width = w, .height = h, .layers = 1, .format = format,
|
||||
.usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
|
||||
AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | tiers[i]};
|
||||
AHardwareBuffer *ahb = NULL;
|
||||
if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) continue;
|
||||
AHardwareBuffer_Desc got;
|
||||
AHardwareBuffer_describe(ahb, &got);
|
||||
const uint64_t need = ubwc_size(w, h, got.stride * 4);
|
||||
*fd = !stride || (uint64_t)got.stride * 4 == stride ? sc_layer_ahb_fd(ahb, need) : -1;
|
||||
if (*fd >= 0 && (uint64_t)lseek(*fd, 0, SEEK_END) == need) { *size = need; return ahb; }
|
||||
*fd = -1;
|
||||
AHardwareBuffer_release(ahb);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint64_t gralloc_bytes(uint32_t format, uint64_t usage, uint32_t *stride) {
|
||||
AHardwareBuffer_Desc d = {
|
||||
.width = DISPLAY_BUFFERS_PROBE_W, .height = DISPLAY_BUFFERS_PROBE_H, .layers = 1, .format = format,
|
||||
.usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
|
||||
AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | usage};
|
||||
AHardwareBuffer *ahb = NULL;
|
||||
if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) return 0;
|
||||
AHardwareBuffer_describe(ahb, &d);
|
||||
const int fd = sc_layer_ahb_fd(ahb, 1);
|
||||
const off_t bytes = fd >= 0 ? lseek(fd, 0, SEEK_END) : 0;
|
||||
if (fd >= 0) lseek(fd, 0, SEEK_SET);
|
||||
AHardwareBuffer_release(ahb);
|
||||
*stride = d.stride;
|
||||
return bytes > 0 ? (uint64_t)bytes : 0;
|
||||
}
|
||||
|
||||
static int ubwc_probe(uint32_t format) {
|
||||
int *state = &g_ubwc_probed[format == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM ? 0 : 1];
|
||||
if (*state) return *state > 0;
|
||||
uint32_t stride = 0, linear_stride = 0;
|
||||
const uint64_t flagged = gralloc_bytes(format, SC_LAYER_AHB_USAGE_VENDOR_UBWC, &stride);
|
||||
const uint64_t plain = gralloc_bytes(format, 0, &stride);
|
||||
const uint64_t linear = gralloc_bytes(format, AHARDWAREBUFFER_USAGE_CPU_READ_RARELY, &linear_stride);
|
||||
const uint64_t need = ubwc_size(DISPLAY_BUFFERS_PROBE_W, DISPLAY_BUFFERS_PROBE_H, stride * 4);
|
||||
*state = stride && linear != need && (flagged == need || plain == need) ? 1 : -1;
|
||||
droiddeck_log("layer", "display buffers: gralloc %s buffers %s (%ux%u: the layout takes %llu bytes; gralloc gives %llu "
|
||||
"asked for UBWC, %llu unasked, %llu linear)", droiddeck_ahb_format_name(format),
|
||||
*state > 0 ? "use the UBWC layout the drivers render to: compressed frames can go on the display layer"
|
||||
: "do not match the UBWC layout the drivers render to: compressed frames are not offered",
|
||||
DISPLAY_BUFFERS_PROBE_W, DISPLAY_BUFFERS_PROBE_H, (unsigned long long)need, (unsigned long long)flagged,
|
||||
(unsigned long long)plain, (unsigned long long)linear);
|
||||
return *state > 0;
|
||||
}
|
||||
|
||||
int display_buffers_offer_ubwc(uint32_t drm) {
|
||||
const uint32_t format = ahb_format_of(drm, MOD_QCOM_COMPRESSED);
|
||||
if (!g_loop || !g_zero_copy || !g_ubwc || !g_display_buffer_driver || !format || !ubwc_probe(format)) return 0;
|
||||
g_ubwc_promised = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void display_buffers_withdraw_ubwc(void) { g_ubwc_promised = 0; }
|
||||
|
||||
static AHardwareBuffer *allocate(const struct display_buffers_request *q, uint32_t format, int *fd) {
|
||||
const uint32_t rows = (uint32_t)((q->size + q->stride - 1) / q->stride);
|
||||
const uint32_t dims[2][2] = {{q->width, q->height}, {q->stride / 4, rows}};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
AHardwareBuffer_Desc d = {
|
||||
.width = dims[i][0], .height = dims[i][1], .layers = 1, .format = format,
|
||||
.usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
|
||||
AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | AHARDWAREBUFFER_USAGE_CPU_READ_RARELY};
|
||||
AHardwareBuffer *ahb = NULL;
|
||||
if (i && dims[1][0] == dims[0][0] && dims[1][1] == dims[0][1]) break;
|
||||
if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) continue;
|
||||
AHardwareBuffer_Desc got;
|
||||
AHardwareBuffer_describe(ahb, &got);
|
||||
*fd = (uint64_t)got.stride * 4 == q->stride ? sc_layer_ahb_fd(ahb, q->size) : -1;
|
||||
if (*fd >= 0) return ahb;
|
||||
AHardwareBuffer_release(ahb);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int reply(struct peer *p, const struct display_buffers_reply *r, int fd) {
|
||||
char control[CMSG_SPACE(sizeof(int))] = {0};
|
||||
struct iovec iov = {.iov_base = (void *)r, .iov_len = sizeof(*r)};
|
||||
struct msghdr msg = {.msg_iov = &iov, .msg_iovlen = 1};
|
||||
if (fd >= 0) {
|
||||
msg.msg_control = control;
|
||||
msg.msg_controllen = sizeof(control);
|
||||
struct cmsghdr *c = CMSG_FIRSTHDR(&msg);
|
||||
c->cmsg_level = SOL_SOCKET;
|
||||
c->cmsg_type = SCM_RIGHTS;
|
||||
c->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
memcpy(CMSG_DATA(c), &fd, sizeof(int));
|
||||
}
|
||||
ssize_t n;
|
||||
do { n = sendmsg(p->fd, &msg, MSG_NOSIGNAL); } while (n < 0 && errno == EINTR);
|
||||
return n == (ssize_t)sizeof(*r) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void handle_alloc(struct peer *p, const struct display_buffers_request *q) {
|
||||
struct display_buffers_reply r = {.magic = DISPLAY_BUFFERS_MAGIC, .status = 1};
|
||||
const int compressed = q->modifier == MOD_QCOM_COMPRESSED;
|
||||
const uint32_t format = compressed || q->modifier == MOD_LINEAR ? ahb_format_of(q->format, q->modifier) : 0;
|
||||
struct entry *e = NULL;
|
||||
AHardwareBuffer *ahb = NULL;
|
||||
struct stat st;
|
||||
uint64_t need = 0;
|
||||
int fd = -1;
|
||||
const int sized = format && q->width && q->height && q->width <= DISPLAY_BUFFERS_MAX_SIDE &&
|
||||
q->height <= DISPLAY_BUFFERS_MAX_SIDE && q->stride % 4 == 0 && q->stride / 4 >= q->width &&
|
||||
q->stride / 4 <= DISPLAY_BUFFERS_MAX_SIDE;
|
||||
const int sane = !sized ? 0
|
||||
: compressed ? q->offset == ubwc_meta_size(q->width, q->height) &&
|
||||
q->size == ubwc_size(q->width, q->height, q->stride)
|
||||
: q->offset == 0 && q->size >= (uint64_t)q->stride * q->height &&
|
||||
q->size <= (uint64_t)q->stride * DISPLAY_BUFFERS_MAX_SIDE;
|
||||
const int wanted = compressed ? g_ubwc_promised : g_zero_copy;
|
||||
if (sane && wanted && ahb_swapchain_advertised() && p->count < DISPLAY_BUFFERS_MAX_PER_CLIENT)
|
||||
ahb = compressed ? allocate_ubwc(q->width, q->height, format, q->stride, &fd, &need) : allocate(q, format, &fd);
|
||||
if (ahb && fstat(fd, &st) == 0) e = calloc(1, sizeof(*e));
|
||||
if (e) {
|
||||
e->id = r.id = g_next_id++;
|
||||
e->dev = st.st_dev; e->ino = st.st_ino;
|
||||
e->ahb = ahb;
|
||||
e->format = format; e->stride = q->stride;
|
||||
e->width = q->width; e->height = q->height;
|
||||
e->modifier = q->modifier;
|
||||
e->peer = p;
|
||||
p->count++;
|
||||
wl_list_insert(&g_entries, &e->link);
|
||||
r.status = 0;
|
||||
r.size = (uint64_t)lseek(fd, 0, SEEK_END);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
if (p->logged_w != (int)q->width || p->logged_h != (int)q->height || p->logged_format != q->format) {
|
||||
AHardwareBuffer_Desc got;
|
||||
AHardwareBuffer_describe(ahb, &got);
|
||||
p->logged_w = (int)q->width; p->logged_h = (int)q->height; p->logged_format = q->format;
|
||||
droiddeck_log("layer", "display buffers: pid %d renders %ux%u %c%c%c%c %s straight into gralloc buffers "
|
||||
"(%s %ux%u, stride %u px, %llu bytes for the %llu it asked for)", (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", droiddeck_ahb_format_name(format), got.width, got.height,
|
||||
got.stride, (unsigned long long)r.size, (unsigned long long)q->size);
|
||||
}
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
if (reply(p, &r, fd) != 0 && e) entry_free(e);
|
||||
}
|
||||
|
||||
static void peer_gone(struct peer *p) {
|
||||
struct entry *e, *tmp;
|
||||
wl_list_for_each_safe(e, tmp, &g_entries, link)
|
||||
if (e->peer == p) entry_free(e);
|
||||
wl_event_source_remove(p->src);
|
||||
close(p->fd);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static int on_peer(int fd, uint32_t mask, void *data) {
|
||||
struct peer *p = data;
|
||||
for (;;) {
|
||||
struct display_buffers_request q;
|
||||
ssize_t n = recv(fd, &q, sizeof(q), MSG_DONTWAIT);
|
||||
if (n < 0 && errno == EINTR) continue;
|
||||
if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return 0;
|
||||
if (n != (ssize_t)sizeof(q) || q.magic != DISPLAY_BUFFERS_MAGIC || q.version != DISPLAY_BUFFERS_VERSION) break;
|
||||
if (q.op == DISPLAY_BUFFERS_ALLOC) {
|
||||
handle_alloc(p, &q);
|
||||
} else if (q.op == DISPLAY_BUFFERS_FREE) {
|
||||
struct entry *e, *tmp;
|
||||
wl_list_for_each_safe(e, tmp, &g_entries, link)
|
||||
if (e->peer == p && e->id == q.id) entry_free(e);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
peer_gone(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_listen(int fd, uint32_t mask, void *data) {
|
||||
int c = accept4(fd, NULL, NULL, SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||
if (c < 0) return 0;
|
||||
struct peer *p = calloc(1, sizeof(*p));
|
||||
if (!p) { close(c); return 0; }
|
||||
struct ucred cred = {0};
|
||||
socklen_t len = sizeof(cred);
|
||||
if (getsockopt(c, SOL_SOCKET, SO_PEERCRED, &cred, &len) == 0) p->pid = cred.pid;
|
||||
p->fd = c;
|
||||
p->src = wl_event_loop_add_fd(g_loop, c, WL_EVENT_READABLE, on_peer, p);
|
||||
if (!p->src) { close(c); free(p); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b) {
|
||||
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;
|
||||
wl_list_for_each(e, &g_entries, link) {
|
||||
if (e->dev != st.st_dev || e->ino != st.st_ino) continue;
|
||||
AHardwareBuffer_Desc d;
|
||||
AHardwareBuffer_describe(e->ahb, &d);
|
||||
const int compressed = e->modifier == MOD_QCOM_COMPRESSED;
|
||||
const int laid_out = compressed ? b->modifier == MOD_QCOM_COMPRESSED && (uint32_t)b->width == e->width &&
|
||||
(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)
|
||||
ahb_swapchain_adopt(c, buffer, b, e->ahb, e->modifier);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void display_buffers_init(struct wl_display *display) {
|
||||
wl_list_init(&g_entries);
|
||||
const char *dir = getenv("XDG_RUNTIME_DIR");
|
||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||
if (!ahb_swapchain_advertised() || !dir) return;
|
||||
if (snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/" DISPLAY_BUFFERS_SOCKET, dir) >= (int)sizeof(addr.sun_path)) {
|
||||
droiddeck_log("layer", "display buffers: %s is too long for a socket path, not offered", dir);
|
||||
return;
|
||||
}
|
||||
int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
|
||||
if (fd < 0) return;
|
||||
unlink(addr.sun_path);
|
||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0 || listen(fd, 16) != 0 ||
|
||||
!wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, on_listen, NULL)) {
|
||||
droiddeck_log("layer", "display buffers: socket %s failed (%s), not offered", addr.sun_path, strerror(errno));
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
g_loop = loop;
|
||||
droiddeck_log("layer", "display buffers: offered on %s (programs whose driver asks render into gralloc buffers while "
|
||||
"zero-copy is on)", addr.sun_path);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef DISPLAY_BUFFERS_H
|
||||
#define DISPLAY_BUFFERS_H
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct dmabuf_buffer;
|
||||
|
||||
void display_buffers_init(struct wl_display *display);
|
||||
int display_buffers_offer_ubwc(uint32_t drm);
|
||||
void display_buffers_withdraw_ubwc(void);
|
||||
void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b);
|
||||
|
||||
#endif
|
||||
@@ -16,6 +16,9 @@ struct droiddeck_color {
|
||||
float max_lum, min_lum;
|
||||
int has_cta861;
|
||||
float max_cll, max_fall;
|
||||
int convert;
|
||||
float to2020[9];
|
||||
float gain;
|
||||
char text[256];
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#define MIXED_FORMAT VK_FORMAT_A2B10G10R10_UNORM_PACK32
|
||||
|
||||
struct pc_encode { float ndc[4]; float params[4]; float rects[HDRC_MAX_RECTS][4]; };
|
||||
struct pc_encode { float ndc[4]; float params[4]; uint32_t rects[HDRC_MAX_RECTS][2]; float conv[3][4]; };
|
||||
|
||||
static VkDevice g_dev;
|
||||
static int g_ready;
|
||||
@@ -266,7 +266,16 @@ int hdrc_encode(VkCommandBuffer cmd, VkImage mixed, VkImage out, VkFormat out_fm
|
||||
pc.params[1] = p->peak_nits > 0.0f ? p->peak_nits : 1000.0f;
|
||||
pc.params[2] = p->mode == HDRC_OUT_SDR ? 1.0f : 0.0f;
|
||||
pc.params[3] = (float)count + 16.0f * (float)mask;
|
||||
for (int i = 0; i < count; i++) memcpy(pc.rects[i], p->rects[i], sizeof(pc.rects[i]));
|
||||
for (int i = 0; i < count; i++) {
|
||||
uint32_t v[4];
|
||||
for (int k = 0; k < 4; k++) v[k] = p->rects[i][k] <= 0.0f ? 0u : p->rects[i][k] >= 65535.0f ? 65535u : (uint32_t)p->rects[i][k];
|
||||
pc.rects[i][0] = v[0] | v[1] << 16;
|
||||
pc.rects[i][1] = v[2] | v[3] << 16;
|
||||
}
|
||||
for (int k = 0; k < 3; k++) memcpy(pc.conv[k], &p->conv[3 * k], 3 * sizeof(float));
|
||||
pc.conv[0][3] = (float)(p->conv_mask & mask);
|
||||
pc.conv[1][3] = p->conv_linear ? 1.0f : 0.0f;
|
||||
pc.conv[2][3] = p->conv_gain;
|
||||
|
||||
VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_out[slot].rp,
|
||||
.framebuffer = fb, .renderArea = {{0, 0}, {(uint32_t)w, (uint32_t)h}}};
|
||||
|
||||
@@ -14,6 +14,10 @@ struct hdrc_params {
|
||||
int count;
|
||||
unsigned hdr_mask;
|
||||
float rects[HDRC_MAX_RECTS][4];
|
||||
unsigned conv_mask;
|
||||
int conv_linear;
|
||||
float conv_gain;
|
||||
float conv[9];
|
||||
};
|
||||
|
||||
void hdrc_bind_device(VkDevice dev, const VkPhysicalDeviceMemoryProperties *memprops);
|
||||
|
||||
@@ -6,7 +6,8 @@ layout(binding = 0) uniform sampler2D Mixed;
|
||||
layout(push_constant) uniform PC {
|
||||
vec4 ndc;
|
||||
vec4 params;
|
||||
vec4 rects[6];
|
||||
uvec2 rects[6];
|
||||
vec4 conv[3];
|
||||
} pc;
|
||||
|
||||
layout(location = 0) in vec2 fragTexCoord;
|
||||
@@ -55,28 +56,38 @@ float toneCurve(float x, float peak) {
|
||||
return knee + (1.0 - knee) * (1.0 - exp(-(x - knee) / rate));
|
||||
}
|
||||
|
||||
bool isHdrPixel(vec2 p) {
|
||||
float packed = pc.params.w;
|
||||
float count = mod(packed, 16.0);
|
||||
float mask = floor(packed / 16.0);
|
||||
int rectAt(vec2 p) {
|
||||
float count = mod(pc.params.w, 16.0);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (float(i) >= count - 0.5) break;
|
||||
vec4 r = pc.rects[i];
|
||||
if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) {
|
||||
float bit = mod(floor(mask / exp2(float(i))), 2.0);
|
||||
return bit > 0.5;
|
||||
}
|
||||
uvec2 r = pc.rects[i];
|
||||
vec2 lo = vec2(float(r.x & 0xFFFFu), float(r.x >> 16));
|
||||
vec2 hi = vec2(float(r.y & 0xFFFFu), float(r.y >> 16));
|
||||
if (p.x >= lo.x && p.y >= lo.y && p.x < hi.x && p.y < hi.y) return i;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool bitOf(float mask, int i) {
|
||||
return i >= 0 && mod(floor(mask / exp2(float(i))), 2.0) > 0.5;
|
||||
}
|
||||
|
||||
vec3 convertedNits(vec3 c) {
|
||||
vec3 lin = pc.conv[1].w > 0.5 ? c : pqToLinear(c);
|
||||
return vec3(dot(pc.conv[0].xyz, lin), dot(pc.conv[1].xyz, lin), dot(pc.conv[2].xyz, lin)) * pc.conv[2].w;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 c = texelFetch(Mixed, ivec2(gl_FragCoord.xy), 0).rgb;
|
||||
bool hdr = isHdrPixel(gl_FragCoord.xy);
|
||||
int at = rectAt(gl_FragCoord.xy);
|
||||
bool hdr = bitOf(floor(pc.params.w / 16.0), at);
|
||||
bool conv = hdr && bitOf(pc.conv[0].w, at);
|
||||
float sdrWhite = max(pc.params.x, 1.0);
|
||||
vec3 outc;
|
||||
if (pc.params.z < 0.5) {
|
||||
if (hdr) {
|
||||
if (conv) {
|
||||
outc = linearToPq(max(convertedNits(c), 0.0) / 10000.0);
|
||||
} else if (hdr) {
|
||||
outc = c;
|
||||
} else {
|
||||
vec3 nits = (BT709_TO_BT2020 * srgbToLinear(c)) * sdrWhite;
|
||||
@@ -86,7 +97,8 @@ void main() {
|
||||
if (!hdr) {
|
||||
outc = c;
|
||||
} else {
|
||||
vec3 rel = max(BT2020_TO_BT709 * (pqToLinear(c) * 10000.0), 0.0) / sdrWhite;
|
||||
vec3 nits = conv ? convertedNits(c) : pqToLinear(c) * 10000.0;
|
||||
vec3 rel = max(BT2020_TO_BT709 * nits, 0.0) / sdrWhite;
|
||||
float m = max(max(rel.r, rel.g), rel.b);
|
||||
if (m > 1e-6) rel *= toneCurve(m, max(pc.params.y, sdrWhite) / sdrWhite) / m;
|
||||
outc = linearToSrgb(clamp(rel, 0.0, 1.0));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
const uint32_t hdr_encode_code[] = {
|
||||
0x07230203,0x00010000,0x0008000b,0x0000018e,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x07230203,0x00010000,0x0008000b,0x000001ff,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x0008000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000010d,0x00000186,0x0000018d,
|
||||
0x0008000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000151,0x000001f7,0x000001fe,
|
||||
0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,
|
||||
0x6e69616d,0x00000000,0x00070005,0x0000000b,0x62677273,0x694c6f54,0x7261656e,0x33667628,
|
||||
0x0000003b,0x00030005,0x0000000a,0x00000063,0x00070005,0x0000000e,0x656e696c,0x6f547261,
|
||||
@@ -10,272 +10,354 @@ const uint32_t hdr_encode_code[] = {
|
||||
0x6f547170,0x656e694c,0x76287261,0x003b3366,0x00030005,0x00000010,0x00000065,0x00060005,
|
||||
0x00000014,0x656e696c,0x6f547261,0x76287150,0x003b3366,0x00030005,0x00000013,0x00000079,
|
||||
0x00070005,0x0000001a,0x656e6f74,0x76727543,0x31662865,0x3b31663b,0x00000000,0x00030005,
|
||||
0x00000018,0x00000078,0x00040005,0x00000019,0x6b616570,0x00000000,0x00060005,0x00000021,
|
||||
0x64487369,0x78695072,0x76286c65,0x003b3266,0x00030005,0x00000020,0x00000070,0x00030005,
|
||||
0x00000023,0x00006f6c,0x00030005,0x00000028,0x00006968,0x00030005,0x0000003c,0x00006f6c,
|
||||
0x00030005,0x0000003f,0x00006968,0x00030005,0x00000050,0x00000070,0x00030005,0x0000006f,
|
||||
0x00000070,0x00040005,0x0000008c,0x6e617073,0x00000000,0x00040005,0x00000091,0x65746172,
|
||||
0x00000000,0x00040005,0x000000a2,0x6b636170,0x00006465,0x00030005,0x000000a7,0x00004350,
|
||||
0x00040006,0x000000a7,0x00000000,0x0063646e,0x00050006,0x000000a7,0x00000001,0x61726170,
|
||||
0x0000736d,0x00050006,0x000000a7,0x00000002,0x74636572,0x00000073,0x00030005,0x000000a9,
|
||||
0x00006370,0x00040005,0x000000b0,0x6e756f63,0x00000074,0x00040005,0x000000b4,0x6b73616d,
|
||||
0x00000000,0x00030005,0x000000b9,0x00000069,0x00030005,0x000000cd,0x00000072,0x00030005,
|
||||
0x000000f5,0x00746962,0x00030005,0x00000106,0x00000063,0x00040005,0x0000010a,0x6578694d,
|
||||
0x00000064,0x00060005,0x0000010d,0x465f6c67,0x43676172,0x64726f6f,0x00000000,0x00030005,
|
||||
0x00000116,0x00726468,0x00040005,0x00000117,0x61726170,0x0000006d,0x00050005,0x0000011b,
|
||||
0x57726473,0x65746968,0x00000000,0x00040005,0x00000127,0x6374756f,0x00000000,0x00040005,
|
||||
0x0000012a,0x7374696e,0x00000000,0x00040005,0x00000139,0x61726170,0x0000006d,0x00040005,
|
||||
0x00000143,0x61726170,0x0000006d,0x00030005,0x0000014c,0x006c6572,0x00040005,0x0000015a,
|
||||
0x61726170,0x0000006d,0x00030005,0x00000164,0x0000006d,0x00040005,0x00000177,0x61726170,
|
||||
0x0000006d,0x00040005,0x00000179,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170,
|
||||
0x0000006d,0x00050005,0x00000186,0x4374756f,0x726f6c6f,0x00000000,0x00060005,0x0000018d,
|
||||
0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040047,0x000000a6,0x00000006,0x00000010,
|
||||
0x00030047,0x000000a7,0x00000002,0x00050048,0x000000a7,0x00000000,0x00000023,0x00000000,
|
||||
0x00050048,0x000000a7,0x00000001,0x00000023,0x00000010,0x00050048,0x000000a7,0x00000002,
|
||||
0x00000023,0x00000020,0x00040047,0x0000010a,0x00000021,0x00000000,0x00040047,0x0000010a,
|
||||
0x00000022,0x00000000,0x00040047,0x0000010d,0x0000000b,0x0000000f,0x00040047,0x00000186,
|
||||
0x0000001e,0x00000000,0x00040047,0x0000018d,0x0000001e,0x00000000,0x00020013,0x00000002,
|
||||
0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,
|
||||
0x00000006,0x00000003,0x00040020,0x00000008,0x00000007,0x00000007,0x00040021,0x00000009,
|
||||
0x00000007,0x00000008,0x00040020,0x00000016,0x00000007,0x00000006,0x00050021,0x00000017,
|
||||
0x00000006,0x00000016,0x00000016,0x00040017,0x0000001c,0x00000006,0x00000002,0x00040020,
|
||||
0x0000001d,0x00000007,0x0000001c,0x00020014,0x0000001e,0x00040021,0x0000001f,0x0000001e,
|
||||
0x0000001d,0x0004002b,0x00000006,0x00000025,0x414eb852,0x0004002b,0x00000006,0x0000002a,
|
||||
0x3d6147ae,0x0004002b,0x00000006,0x0000002d,0x3f870a3d,0x0004002b,0x00000006,0x00000030,
|
||||
0x4019999a,0x0006002c,0x00000007,0x00000031,0x00000030,0x00000030,0x00000030,0x0004002b,
|
||||
0x00000006,0x00000035,0x3d25aee6,0x0006002c,0x00000007,0x00000036,0x00000035,0x00000035,
|
||||
0x00000035,0x0004002b,0x00000006,0x00000041,0x3ed55555,0x0006002c,0x00000007,0x00000042,
|
||||
0x00000041,0x00000041,0x00000041,0x0004002b,0x00000006,0x00000049,0x3b4d2e1c,0x0006002c,
|
||||
0x00000007,0x0000004a,0x00000049,0x00000049,0x00000049,0x0004002b,0x00000006,0x00000052,
|
||||
0x00000000,0x0004002b,0x00000006,0x00000053,0x3f800000,0x0004002b,0x00000006,0x00000057,
|
||||
0x3c4fcdac,0x0006002c,0x00000007,0x00000058,0x00000057,0x00000057,0x00000057,0x0004002b,
|
||||
0x00000006,0x0000005b,0x3f560000,0x0004002b,0x00000006,0x00000060,0x4196d000,0x0004002b,
|
||||
0x00000006,0x00000061,0x41958000,0x0004002b,0x00000006,0x00000066,0x358637bd,0x0004002b,
|
||||
0x00000006,0x0000006a,0x40c8e06b,0x0006002c,0x00000007,0x0000006b,0x0000006a,0x0000006a,
|
||||
0x0000006a,0x0004002b,0x00000006,0x00000074,0x3e232000,0x0006002c,0x00000007,0x00000075,
|
||||
0x00000074,0x00000074,0x00000074,0x0004002b,0x00000006,0x00000080,0x429db000,0x0006002c,
|
||||
0x00000007,0x00000081,0x00000080,0x00000080,0x00000080,0x0004002b,0x00000006,0x00000086,
|
||||
0x3f4ccccd,0x0004002b,0x00000006,0x0000008f,0x3d4ccccd,0x0004002b,0x00000006,0x00000093,
|
||||
0x407a5e35,0x0004002b,0x00000006,0x00000095,0x3e4ccccd,0x00040017,0x000000a3,0x00000006,
|
||||
0x00000004,0x00040015,0x000000a4,0x00000020,0x00000000,0x0004002b,0x000000a4,0x000000a5,
|
||||
0x00000006,0x0004001c,0x000000a6,0x000000a3,0x000000a5,0x0005001e,0x000000a7,0x000000a3,
|
||||
0x000000a3,0x000000a6,0x00040020,0x000000a8,0x00000009,0x000000a7,0x0004003b,0x000000a8,
|
||||
0x000000a9,0x00000009,0x00040015,0x000000aa,0x00000020,0x00000001,0x0004002b,0x000000aa,
|
||||
0x000000ab,0x00000001,0x0004002b,0x000000a4,0x000000ac,0x00000003,0x00040020,0x000000ad,
|
||||
0x00000009,0x00000006,0x0004002b,0x00000006,0x000000b2,0x41800000,0x00040020,0x000000b8,
|
||||
0x00000007,0x000000aa,0x0004002b,0x000000aa,0x000000ba,0x00000000,0x0004002b,0x000000aa,
|
||||
0x000000c1,0x00000006,0x0004002b,0x00000006,0x000000c6,0x3f000000,0x00040020,0x000000cc,
|
||||
0x00000007,0x000000a3,0x0004002b,0x000000aa,0x000000ce,0x00000002,0x00040020,0x000000d0,
|
||||
0x00000009,0x000000a3,0x0004002b,0x000000a4,0x000000d3,0x00000000,0x0004002b,0x000000a4,
|
||||
0x000000db,0x00000001,0x0004002b,0x000000a4,0x000000e6,0x00000002,0x0004002b,0x00000006,
|
||||
0x000000fc,0x40000000,0x0003002a,0x0000001e,0x00000103,0x00090019,0x00000107,0x00000006,
|
||||
0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000108,
|
||||
0x00000107,0x00040020,0x00000109,0x00000000,0x00000108,0x0004003b,0x00000109,0x0000010a,
|
||||
0x00000000,0x00040020,0x0000010c,0x00000001,0x000000a3,0x0004003b,0x0000010c,0x0000010d,
|
||||
0x00000001,0x00040017,0x00000110,0x000000aa,0x00000002,0x00040020,0x00000115,0x00000007,
|
||||
0x0000001e,0x00040018,0x0000012b,0x00000007,0x00000003,0x0004002b,0x00000006,0x0000012c,
|
||||
0x3f209d49,0x0004002b,0x00000006,0x0000012d,0x3d8d844d,0x0004002b,0x00000006,0x0000012e,
|
||||
0x3c86594b,0x0006002c,0x00000007,0x0000012f,0x0000012c,0x0000012d,0x0000012e,0x0004002b,
|
||||
0x00000006,0x00000130,0x3ea89a02,0x0004002b,0x00000006,0x00000131,0x3f6b645a,0x0004002b,
|
||||
0x00000006,0x00000132,0x3db43958,0x0006002c,0x00000007,0x00000133,0x00000130,0x00000131,
|
||||
0x00000132,0x0004002b,0x00000006,0x00000134,0x3d315b57,0x0004002b,0x00000006,0x00000135,
|
||||
0x3c3ac711,0x0004002b,0x00000006,0x00000136,0x3f65460b,0x0006002c,0x00000007,0x00000137,
|
||||
0x00000134,0x00000135,0x00000136,0x0006002c,0x0000012b,0x00000138,0x0000012f,0x00000133,
|
||||
0x00000137,0x0004002b,0x00000006,0x00000140,0x461c4000,0x0004002b,0x00000006,0x0000014d,
|
||||
0x3fd48b44,0x0004002b,0x00000006,0x0000014e,0xbdff2e49,0x0004002b,0x00000006,0x0000014f,
|
||||
0xbc95182b,0x0006002c,0x00000007,0x00000150,0x0000014d,0x0000014e,0x0000014f,0x0004002b,
|
||||
0x00000006,0x00000151,0xbf166cf4,0x0004002b,0x00000006,0x00000152,0x3f9102de,0x0004002b,
|
||||
0x00000006,0x00000153,0xbdce075f,0x0006002c,0x00000007,0x00000154,0x00000151,0x00000152,
|
||||
0x00000153,0x0004002b,0x00000006,0x00000155,0xbd95182b,0x0004002b,0x00000006,0x00000156,
|
||||
0xbc07fcb9,0x0004002b,0x00000006,0x00000157,0x3f8f3190,0x0006002c,0x00000007,0x00000158,
|
||||
0x00000155,0x00000156,0x00000157,0x0006002c,0x0000012b,0x00000159,0x00000150,0x00000154,
|
||||
0x00000158,0x00040020,0x00000185,0x00000003,0x000000a3,0x0004003b,0x00000185,0x00000186,
|
||||
0x00000003,0x00040020,0x0000018c,0x00000001,0x0000001c,0x0004003b,0x0000018c,0x0000018d,
|
||||
0x00000018,0x00000078,0x00040005,0x00000019,0x6b616570,0x00000000,0x00050005,0x00000021,
|
||||
0x74636572,0x76287441,0x003b3266,0x00030005,0x00000020,0x00000070,0x00060005,0x00000028,
|
||||
0x4f746962,0x31662866,0x3b31693b,0x00000000,0x00040005,0x00000026,0x6b73616d,0x00000000,
|
||||
0x00030005,0x00000027,0x00000069,0x00070005,0x0000002b,0x766e6f63,0x65747265,0x74694e64,
|
||||
0x66762873,0x00003b33,0x00030005,0x0000002a,0x00000063,0x00030005,0x0000002d,0x00006f6c,
|
||||
0x00030005,0x00000032,0x00006968,0x00030005,0x00000046,0x00006f6c,0x00030005,0x00000049,
|
||||
0x00006968,0x00030005,0x0000005a,0x00000070,0x00030005,0x00000079,0x00000070,0x00040005,
|
||||
0x00000096,0x6e617073,0x00000000,0x00040005,0x0000009b,0x65746172,0x00000000,0x00040005,
|
||||
0x000000ac,0x6e756f63,0x00000074,0x00030005,0x000000b4,0x00004350,0x00040006,0x000000b4,
|
||||
0x00000000,0x0063646e,0x00050006,0x000000b4,0x00000001,0x61726170,0x0000736d,0x00050006,
|
||||
0x000000b4,0x00000002,0x74636572,0x00000073,0x00050006,0x000000b4,0x00000003,0x766e6f63,
|
||||
0x00000000,0x00030005,0x000000b6,0x00006370,0x00030005,0x000000bd,0x00000069,0x00030005,
|
||||
0x000000d1,0x00000072,0x00030005,0x000000d7,0x00006f6c,0x00030005,0x000000e5,0x00006968,
|
||||
0x00030005,0x00000126,0x006e696c,0x00040005,0x00000130,0x61726170,0x0000006d,0x00030005,
|
||||
0x0000014a,0x00000063,0x00040005,0x0000014e,0x6578694d,0x00000064,0x00060005,0x00000151,
|
||||
0x465f6c67,0x43676172,0x64726f6f,0x00000000,0x00030005,0x00000159,0x00007461,0x00040005,
|
||||
0x0000015a,0x61726170,0x0000006d,0x00030005,0x0000015f,0x00726468,0x00040005,0x00000164,
|
||||
0x61726170,0x0000006d,0x00040005,0x00000165,0x61726170,0x0000006d,0x00040005,0x00000168,
|
||||
0x766e6f63,0x00000000,0x00040005,0x0000016c,0x61726170,0x0000006d,0x00040005,0x0000016f,
|
||||
0x61726170,0x0000006d,0x00050005,0x00000173,0x57726473,0x65746968,0x00000000,0x00040005,
|
||||
0x00000180,0x6374756f,0x00000000,0x00040005,0x00000181,0x61726170,0x0000006d,0x00040005,
|
||||
0x00000189,0x61726170,0x0000006d,0x00040005,0x00000191,0x7374696e,0x00000000,0x00040005,
|
||||
0x000001a0,0x61726170,0x0000006d,0x00040005,0x000001a9,0x61726170,0x0000006d,0x00040005,
|
||||
0x000001b2,0x7374696e,0x00000000,0x00040005,0x000001b7,0x61726170,0x0000006d,0x00040005,
|
||||
0x000001bb,0x61726170,0x0000006d,0x00030005,0x000001c0,0x006c6572,0x00030005,0x000001d5,
|
||||
0x0000006d,0x00040005,0x000001e8,0x61726170,0x0000006d,0x00040005,0x000001ea,0x61726170,
|
||||
0x0000006d,0x00040005,0x000001f4,0x61726170,0x0000006d,0x00050005,0x000001f7,0x4374756f,
|
||||
0x726f6c6f,0x00000000,0x00060005,0x000001fe,0x67617266,0x43786554,0x64726f6f,0x00000000,
|
||||
0x00040047,0x000000b1,0x00000006,0x00000008,0x00040047,0x000000b3,0x00000006,0x00000010,
|
||||
0x00030047,0x000000b4,0x00000002,0x00050048,0x000000b4,0x00000000,0x00000023,0x00000000,
|
||||
0x00050048,0x000000b4,0x00000001,0x00000023,0x00000010,0x00050048,0x000000b4,0x00000002,
|
||||
0x00000023,0x00000020,0x00050048,0x000000b4,0x00000003,0x00000023,0x00000050,0x00040047,
|
||||
0x0000014e,0x00000021,0x00000000,0x00040047,0x0000014e,0x00000022,0x00000000,0x00040047,
|
||||
0x00000151,0x0000000b,0x0000000f,0x00040047,0x000001f7,0x0000001e,0x00000000,0x00040047,
|
||||
0x000001fe,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
|
||||
0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000003,0x00040020,
|
||||
0x00000008,0x00000007,0x00000007,0x00040021,0x00000009,0x00000007,0x00000008,0x00040020,
|
||||
0x00000016,0x00000007,0x00000006,0x00050021,0x00000017,0x00000006,0x00000016,0x00000016,
|
||||
0x00040017,0x0000001c,0x00000006,0x00000002,0x00040020,0x0000001d,0x00000007,0x0000001c,
|
||||
0x00040015,0x0000001e,0x00000020,0x00000001,0x00040021,0x0000001f,0x0000001e,0x0000001d,
|
||||
0x00040020,0x00000023,0x00000007,0x0000001e,0x00020014,0x00000024,0x00050021,0x00000025,
|
||||
0x00000024,0x00000016,0x00000023,0x0004002b,0x00000006,0x0000002f,0x414eb852,0x0004002b,
|
||||
0x00000006,0x00000034,0x3d6147ae,0x0004002b,0x00000006,0x00000037,0x3f870a3d,0x0004002b,
|
||||
0x00000006,0x0000003a,0x4019999a,0x0006002c,0x00000007,0x0000003b,0x0000003a,0x0000003a,
|
||||
0x0000003a,0x0004002b,0x00000006,0x0000003f,0x3d25aee6,0x0006002c,0x00000007,0x00000040,
|
||||
0x0000003f,0x0000003f,0x0000003f,0x0004002b,0x00000006,0x0000004b,0x3ed55555,0x0006002c,
|
||||
0x00000007,0x0000004c,0x0000004b,0x0000004b,0x0000004b,0x0004002b,0x00000006,0x00000053,
|
||||
0x3b4d2e1c,0x0006002c,0x00000007,0x00000054,0x00000053,0x00000053,0x00000053,0x0004002b,
|
||||
0x00000006,0x0000005c,0x00000000,0x0004002b,0x00000006,0x0000005d,0x3f800000,0x0004002b,
|
||||
0x00000006,0x00000061,0x3c4fcdac,0x0006002c,0x00000007,0x00000062,0x00000061,0x00000061,
|
||||
0x00000061,0x0004002b,0x00000006,0x00000065,0x3f560000,0x0004002b,0x00000006,0x0000006a,
|
||||
0x4196d000,0x0004002b,0x00000006,0x0000006b,0x41958000,0x0004002b,0x00000006,0x00000070,
|
||||
0x358637bd,0x0004002b,0x00000006,0x00000074,0x40c8e06b,0x0006002c,0x00000007,0x00000075,
|
||||
0x00000074,0x00000074,0x00000074,0x0004002b,0x00000006,0x0000007e,0x3e232000,0x0006002c,
|
||||
0x00000007,0x0000007f,0x0000007e,0x0000007e,0x0000007e,0x0004002b,0x00000006,0x0000008a,
|
||||
0x429db000,0x0006002c,0x00000007,0x0000008b,0x0000008a,0x0000008a,0x0000008a,0x0004002b,
|
||||
0x00000006,0x00000090,0x3f4ccccd,0x0004002b,0x00000006,0x00000099,0x3d4ccccd,0x0004002b,
|
||||
0x00000006,0x0000009d,0x407a5e35,0x0004002b,0x00000006,0x0000009f,0x3e4ccccd,0x00040017,
|
||||
0x000000ad,0x00000006,0x00000004,0x00040015,0x000000ae,0x00000020,0x00000000,0x00040017,
|
||||
0x000000af,0x000000ae,0x00000002,0x0004002b,0x000000ae,0x000000b0,0x00000006,0x0004001c,
|
||||
0x000000b1,0x000000af,0x000000b0,0x0004002b,0x000000ae,0x000000b2,0x00000003,0x0004001c,
|
||||
0x000000b3,0x000000ad,0x000000b2,0x0006001e,0x000000b4,0x000000ad,0x000000ad,0x000000b1,
|
||||
0x000000b3,0x00040020,0x000000b5,0x00000009,0x000000b4,0x0004003b,0x000000b5,0x000000b6,
|
||||
0x00000009,0x0004002b,0x0000001e,0x000000b7,0x00000001,0x00040020,0x000000b8,0x00000009,
|
||||
0x00000006,0x0004002b,0x00000006,0x000000bb,0x41800000,0x0004002b,0x0000001e,0x000000be,
|
||||
0x00000000,0x0004002b,0x0000001e,0x000000c5,0x00000006,0x0004002b,0x00000006,0x000000ca,
|
||||
0x3f000000,0x00040020,0x000000d0,0x00000007,0x000000af,0x0004002b,0x0000001e,0x000000d2,
|
||||
0x00000002,0x00040020,0x000000d4,0x00000009,0x000000af,0x0004002b,0x000000ae,0x000000d8,
|
||||
0x00000000,0x00040020,0x000000d9,0x00000007,0x000000ae,0x0004002b,0x000000ae,0x000000dc,
|
||||
0x0000ffff,0x0004002b,0x0000001e,0x000000e1,0x00000010,0x0004002b,0x000000ae,0x000000e6,
|
||||
0x00000001,0x0004002b,0x0000001e,0x00000113,0xffffffff,0x0004002b,0x00000006,0x00000120,
|
||||
0x40000000,0x0004002b,0x0000001e,0x00000127,0x00000003,0x00040020,0x00000134,0x00000009,
|
||||
0x000000ad,0x00090019,0x0000014b,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
|
||||
0x00000001,0x00000000,0x0003001b,0x0000014c,0x0000014b,0x00040020,0x0000014d,0x00000000,
|
||||
0x0000014c,0x0004003b,0x0000014d,0x0000014e,0x00000000,0x00040020,0x00000150,0x00000001,
|
||||
0x000000ad,0x0004003b,0x00000150,0x00000151,0x00000001,0x00040017,0x00000154,0x0000001e,
|
||||
0x00000002,0x00040020,0x0000015e,0x00000007,0x00000024,0x0004002b,0x000000ae,0x00000177,
|
||||
0x00000002,0x0004002b,0x00000006,0x00000186,0x461c4000,0x00040018,0x00000192,0x00000007,
|
||||
0x00000003,0x0004002b,0x00000006,0x00000193,0x3f209d49,0x0004002b,0x00000006,0x00000194,
|
||||
0x3d8d844d,0x0004002b,0x00000006,0x00000195,0x3c86594b,0x0006002c,0x00000007,0x00000196,
|
||||
0x00000193,0x00000194,0x00000195,0x0004002b,0x00000006,0x00000197,0x3ea89a02,0x0004002b,
|
||||
0x00000006,0x00000198,0x3f6b645a,0x0004002b,0x00000006,0x00000199,0x3db43958,0x0006002c,
|
||||
0x00000007,0x0000019a,0x00000197,0x00000198,0x00000199,0x0004002b,0x00000006,0x0000019b,
|
||||
0x3d315b57,0x0004002b,0x00000006,0x0000019c,0x3c3ac711,0x0004002b,0x00000006,0x0000019d,
|
||||
0x3f65460b,0x0006002c,0x00000007,0x0000019e,0x0000019b,0x0000019c,0x0000019d,0x0006002c,
|
||||
0x00000192,0x0000019f,0x00000196,0x0000019a,0x0000019e,0x0004002b,0x00000006,0x000001c1,
|
||||
0x3fd48b44,0x0004002b,0x00000006,0x000001c2,0xbdff2e49,0x0004002b,0x00000006,0x000001c3,
|
||||
0xbc95182b,0x0006002c,0x00000007,0x000001c4,0x000001c1,0x000001c2,0x000001c3,0x0004002b,
|
||||
0x00000006,0x000001c5,0xbf166cf4,0x0004002b,0x00000006,0x000001c6,0x3f9102de,0x0004002b,
|
||||
0x00000006,0x000001c7,0xbdce075f,0x0006002c,0x00000007,0x000001c8,0x000001c5,0x000001c6,
|
||||
0x000001c7,0x0004002b,0x00000006,0x000001c9,0xbd95182b,0x0004002b,0x00000006,0x000001ca,
|
||||
0xbc07fcb9,0x0004002b,0x00000006,0x000001cb,0x3f8f3190,0x0006002c,0x00000007,0x000001cc,
|
||||
0x000001c9,0x000001ca,0x000001cb,0x0006002c,0x00000192,0x000001cd,0x000001c4,0x000001c8,
|
||||
0x000001cc,0x00040020,0x000001f6,0x00000003,0x000000ad,0x0004003b,0x000001f6,0x000001f7,
|
||||
0x00000003,0x00040020,0x000001fd,0x00000001,0x0000001c,0x0004003b,0x000001fd,0x000001fe,
|
||||
0x00000001,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,
|
||||
0x0004003b,0x00000008,0x00000106,0x00000007,0x0004003b,0x00000115,0x00000116,0x00000007,
|
||||
0x0004003b,0x0000001d,0x00000117,0x00000007,0x0004003b,0x00000016,0x0000011b,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000127,0x00000007,0x0004003b,0x00000008,0x0000012a,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000139,0x00000007,0x0004003b,0x00000008,0x00000143,0x00000007,
|
||||
0x0004003b,0x00000008,0x0000014c,0x00000007,0x0004003b,0x00000008,0x0000015a,0x00000007,
|
||||
0x0004003b,0x00000016,0x00000164,0x00000007,0x0004003b,0x00000016,0x00000177,0x00000007,
|
||||
0x0004003b,0x00000016,0x00000179,0x00000007,0x0004003b,0x00000008,0x00000183,0x00000007,
|
||||
0x0004003d,0x00000108,0x0000010b,0x0000010a,0x0004003d,0x000000a3,0x0000010e,0x0000010d,
|
||||
0x0007004f,0x0000001c,0x0000010f,0x0000010e,0x0000010e,0x00000000,0x00000001,0x0004006e,
|
||||
0x00000110,0x00000111,0x0000010f,0x00040064,0x00000107,0x00000112,0x0000010b,0x0007005f,
|
||||
0x000000a3,0x00000113,0x00000112,0x00000111,0x00000002,0x000000ba,0x0008004f,0x00000007,
|
||||
0x00000114,0x00000113,0x00000113,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000106,
|
||||
0x00000114,0x0004003d,0x000000a3,0x00000118,0x0000010d,0x0007004f,0x0000001c,0x00000119,
|
||||
0x00000118,0x00000118,0x00000000,0x00000001,0x0003003e,0x00000117,0x00000119,0x00050039,
|
||||
0x0000001e,0x0000011a,0x00000021,0x00000117,0x0003003e,0x00000116,0x0000011a,0x00060041,
|
||||
0x000000ad,0x0000011c,0x000000a9,0x000000ab,0x000000d3,0x0004003d,0x00000006,0x0000011d,
|
||||
0x0000011c,0x0007000c,0x00000006,0x0000011e,0x00000001,0x00000028,0x0000011d,0x00000053,
|
||||
0x0003003e,0x0000011b,0x0000011e,0x00060041,0x000000ad,0x0000011f,0x000000a9,0x000000ab,
|
||||
0x000000e6,0x0004003d,0x00000006,0x00000120,0x0000011f,0x000500b8,0x0000001e,0x00000121,
|
||||
0x00000120,0x000000c6,0x000300f7,0x00000123,0x00000000,0x000400fa,0x00000121,0x00000122,
|
||||
0x00000145,0x000200f8,0x00000122,0x0004003d,0x0000001e,0x00000124,0x00000116,0x000300f7,
|
||||
0x00000126,0x00000000,0x000400fa,0x00000124,0x00000125,0x00000129,0x000200f8,0x00000125,
|
||||
0x0004003d,0x00000007,0x00000128,0x00000106,0x0003003e,0x00000127,0x00000128,0x000200f9,
|
||||
0x00000126,0x000200f8,0x00000129,0x0004003d,0x00000007,0x0000013a,0x00000106,0x0003003e,
|
||||
0x00000139,0x0000013a,0x00050039,0x00000007,0x0000013b,0x0000000b,0x00000139,0x00050091,
|
||||
0x00000007,0x0000013c,0x00000138,0x0000013b,0x0004003d,0x00000006,0x0000013d,0x0000011b,
|
||||
0x0005008e,0x00000007,0x0000013e,0x0000013c,0x0000013d,0x0003003e,0x0000012a,0x0000013e,
|
||||
0x0004003d,0x00000007,0x0000013f,0x0000012a,0x00060050,0x00000007,0x00000141,0x00000140,
|
||||
0x00000140,0x00000140,0x00050088,0x00000007,0x00000142,0x0000013f,0x00000141,0x0003003e,
|
||||
0x00000143,0x00000142,0x00050039,0x00000007,0x00000144,0x00000014,0x00000143,0x0003003e,
|
||||
0x00000127,0x00000144,0x000200f9,0x00000126,0x000200f8,0x00000126,0x000200f9,0x00000123,
|
||||
0x000200f8,0x00000145,0x0004003d,0x0000001e,0x00000146,0x00000116,0x000400a8,0x0000001e,
|
||||
0x00000147,0x00000146,0x000300f7,0x00000149,0x00000000,0x000400fa,0x00000147,0x00000148,
|
||||
0x0000014b,0x000200f8,0x00000148,0x0004003d,0x00000007,0x0000014a,0x00000106,0x0003003e,
|
||||
0x00000127,0x0000014a,0x000200f9,0x00000149,0x000200f8,0x0000014b,0x0004003d,0x00000007,
|
||||
0x0000015b,0x00000106,0x0003003e,0x0000015a,0x0000015b,0x00050039,0x00000007,0x0000015c,
|
||||
0x00000011,0x0000015a,0x0005008e,0x00000007,0x0000015d,0x0000015c,0x00000140,0x00050091,
|
||||
0x00000007,0x0000015e,0x00000159,0x0000015d,0x00060050,0x00000007,0x0000015f,0x00000052,
|
||||
0x00000052,0x00000052,0x0007000c,0x00000007,0x00000160,0x00000001,0x00000028,0x0000015e,
|
||||
0x0000015f,0x0004003d,0x00000006,0x00000161,0x0000011b,0x00060050,0x00000007,0x00000162,
|
||||
0x00000161,0x00000161,0x00000161,0x00050088,0x00000007,0x00000163,0x00000160,0x00000162,
|
||||
0x0003003e,0x0000014c,0x00000163,0x00050041,0x00000016,0x00000165,0x0000014c,0x000000d3,
|
||||
0x0004003d,0x00000006,0x00000166,0x00000165,0x00050041,0x00000016,0x00000167,0x0000014c,
|
||||
0x000000db,0x0004003d,0x00000006,0x00000168,0x00000167,0x0007000c,0x00000006,0x00000169,
|
||||
0x00000001,0x00000028,0x00000166,0x00000168,0x00050041,0x00000016,0x0000016a,0x0000014c,
|
||||
0x000000e6,0x0004003d,0x00000006,0x0000016b,0x0000016a,0x0007000c,0x00000006,0x0000016c,
|
||||
0x00000001,0x00000028,0x00000169,0x0000016b,0x0003003e,0x00000164,0x0000016c,0x0004003d,
|
||||
0x00000006,0x0000016d,0x00000164,0x000500ba,0x0000001e,0x0000016e,0x0000016d,0x00000066,
|
||||
0x000300f7,0x00000170,0x00000000,0x000400fa,0x0000016e,0x0000016f,0x00000170,0x000200f8,
|
||||
0x0000016f,0x00060041,0x000000ad,0x00000171,0x000000a9,0x000000ab,0x000000db,0x0004003d,
|
||||
0x00000006,0x00000172,0x00000171,0x0004003d,0x00000006,0x00000173,0x0000011b,0x0007000c,
|
||||
0x00000006,0x00000174,0x00000001,0x00000028,0x00000172,0x00000173,0x0004003d,0x00000006,
|
||||
0x00000175,0x0000011b,0x00050088,0x00000006,0x00000176,0x00000174,0x00000175,0x0004003d,
|
||||
0x00000006,0x00000178,0x00000164,0x0003003e,0x00000177,0x00000178,0x0003003e,0x00000179,
|
||||
0x00000176,0x00060039,0x00000006,0x0000017a,0x0000001a,0x00000177,0x00000179,0x0004003d,
|
||||
0x00000006,0x0000017b,0x00000164,0x00050088,0x00000006,0x0000017c,0x0000017a,0x0000017b,
|
||||
0x0004003d,0x00000007,0x0000017d,0x0000014c,0x0005008e,0x00000007,0x0000017e,0x0000017d,
|
||||
0x0000017c,0x0003003e,0x0000014c,0x0000017e,0x000200f9,0x00000170,0x000200f8,0x00000170,
|
||||
0x0004003d,0x00000007,0x0000017f,0x0000014c,0x00060050,0x00000007,0x00000180,0x00000052,
|
||||
0x00000052,0x00000052,0x00060050,0x00000007,0x00000181,0x00000053,0x00000053,0x00000053,
|
||||
0x0008000c,0x00000007,0x00000182,0x00000001,0x0000002b,0x0000017f,0x00000180,0x00000181,
|
||||
0x0003003e,0x00000183,0x00000182,0x00050039,0x00000007,0x00000184,0x0000000e,0x00000183,
|
||||
0x0003003e,0x00000127,0x00000184,0x000200f9,0x00000149,0x000200f8,0x00000149,0x000200f9,
|
||||
0x00000123,0x000200f8,0x00000123,0x0004003d,0x00000007,0x00000187,0x00000127,0x00050051,
|
||||
0x00000006,0x00000188,0x00000187,0x00000000,0x00050051,0x00000006,0x00000189,0x00000187,
|
||||
0x00000001,0x00050051,0x00000006,0x0000018a,0x00000187,0x00000002,0x00070050,0x000000a3,
|
||||
0x0000018b,0x00000188,0x00000189,0x0000018a,0x00000053,0x0003003e,0x00000186,0x0000018b,
|
||||
0x0004003b,0x00000008,0x0000014a,0x00000007,0x0004003b,0x00000023,0x00000159,0x00000007,
|
||||
0x0004003b,0x0000001d,0x0000015a,0x00000007,0x0004003b,0x0000015e,0x0000015f,0x00000007,
|
||||
0x0004003b,0x00000016,0x00000164,0x00000007,0x0004003b,0x00000023,0x00000165,0x00000007,
|
||||
0x0004003b,0x0000015e,0x00000168,0x00000007,0x0004003b,0x00000016,0x0000016c,0x00000007,
|
||||
0x0004003b,0x00000023,0x0000016f,0x00000007,0x0004003b,0x00000016,0x00000173,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000180,0x00000007,0x0004003b,0x00000008,0x00000181,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000189,0x00000007,0x0004003b,0x00000008,0x00000191,0x00000007,
|
||||
0x0004003b,0x00000008,0x000001a0,0x00000007,0x0004003b,0x00000008,0x000001a9,0x00000007,
|
||||
0x0004003b,0x00000008,0x000001b2,0x00000007,0x0004003b,0x00000008,0x000001b4,0x00000007,
|
||||
0x0004003b,0x00000008,0x000001b7,0x00000007,0x0004003b,0x00000008,0x000001bb,0x00000007,
|
||||
0x0004003b,0x00000008,0x000001c0,0x00000007,0x0004003b,0x00000016,0x000001d5,0x00000007,
|
||||
0x0004003b,0x00000016,0x000001e8,0x00000007,0x0004003b,0x00000016,0x000001ea,0x00000007,
|
||||
0x0004003b,0x00000008,0x000001f4,0x00000007,0x0004003d,0x0000014c,0x0000014f,0x0000014e,
|
||||
0x0004003d,0x000000ad,0x00000152,0x00000151,0x0007004f,0x0000001c,0x00000153,0x00000152,
|
||||
0x00000152,0x00000000,0x00000001,0x0004006e,0x00000154,0x00000155,0x00000153,0x00040064,
|
||||
0x0000014b,0x00000156,0x0000014f,0x0007005f,0x000000ad,0x00000157,0x00000156,0x00000155,
|
||||
0x00000002,0x000000be,0x0008004f,0x00000007,0x00000158,0x00000157,0x00000157,0x00000000,
|
||||
0x00000001,0x00000002,0x0003003e,0x0000014a,0x00000158,0x0004003d,0x000000ad,0x0000015b,
|
||||
0x00000151,0x0007004f,0x0000001c,0x0000015c,0x0000015b,0x0000015b,0x00000000,0x00000001,
|
||||
0x0003003e,0x0000015a,0x0000015c,0x00050039,0x0000001e,0x0000015d,0x00000021,0x0000015a,
|
||||
0x0003003e,0x00000159,0x0000015d,0x00060041,0x000000b8,0x00000160,0x000000b6,0x000000b7,
|
||||
0x000000b2,0x0004003d,0x00000006,0x00000161,0x00000160,0x00050088,0x00000006,0x00000162,
|
||||
0x00000161,0x000000bb,0x0006000c,0x00000006,0x00000163,0x00000001,0x00000008,0x00000162,
|
||||
0x0003003e,0x00000164,0x00000163,0x0004003d,0x0000001e,0x00000166,0x00000159,0x0003003e,
|
||||
0x00000165,0x00000166,0x00060039,0x00000024,0x00000167,0x00000028,0x00000164,0x00000165,
|
||||
0x0003003e,0x0000015f,0x00000167,0x0004003d,0x00000024,0x00000169,0x0000015f,0x000300f7,
|
||||
0x0000016b,0x00000000,0x000400fa,0x00000169,0x0000016a,0x0000016b,0x000200f8,0x0000016a,
|
||||
0x00070041,0x000000b8,0x0000016d,0x000000b6,0x00000127,0x000000be,0x000000b2,0x0004003d,
|
||||
0x00000006,0x0000016e,0x0000016d,0x0003003e,0x0000016c,0x0000016e,0x0004003d,0x0000001e,
|
||||
0x00000170,0x00000159,0x0003003e,0x0000016f,0x00000170,0x00060039,0x00000024,0x00000171,
|
||||
0x00000028,0x0000016c,0x0000016f,0x000200f9,0x0000016b,0x000200f8,0x0000016b,0x000700f5,
|
||||
0x00000024,0x00000172,0x00000169,0x00000005,0x00000171,0x0000016a,0x0003003e,0x00000168,
|
||||
0x00000172,0x00060041,0x000000b8,0x00000174,0x000000b6,0x000000b7,0x000000d8,0x0004003d,
|
||||
0x00000006,0x00000175,0x00000174,0x0007000c,0x00000006,0x00000176,0x00000001,0x00000028,
|
||||
0x00000175,0x0000005d,0x0003003e,0x00000173,0x00000176,0x00060041,0x000000b8,0x00000178,
|
||||
0x000000b6,0x000000b7,0x00000177,0x0004003d,0x00000006,0x00000179,0x00000178,0x000500b8,
|
||||
0x00000024,0x0000017a,0x00000179,0x000000ca,0x000300f7,0x0000017c,0x00000000,0x000400fa,
|
||||
0x0000017a,0x0000017b,0x000001ab,0x000200f8,0x0000017b,0x0004003d,0x00000024,0x0000017d,
|
||||
0x00000168,0x000300f7,0x0000017f,0x00000000,0x000400fa,0x0000017d,0x0000017e,0x0000018b,
|
||||
0x000200f8,0x0000017e,0x0004003d,0x00000007,0x00000182,0x0000014a,0x0003003e,0x00000181,
|
||||
0x00000182,0x00050039,0x00000007,0x00000183,0x0000002b,0x00000181,0x00060050,0x00000007,
|
||||
0x00000184,0x0000005c,0x0000005c,0x0000005c,0x0007000c,0x00000007,0x00000185,0x00000001,
|
||||
0x00000028,0x00000183,0x00000184,0x00060050,0x00000007,0x00000187,0x00000186,0x00000186,
|
||||
0x00000186,0x00050088,0x00000007,0x00000188,0x00000185,0x00000187,0x0003003e,0x00000189,
|
||||
0x00000188,0x00050039,0x00000007,0x0000018a,0x00000014,0x00000189,0x0003003e,0x00000180,
|
||||
0x0000018a,0x000200f9,0x0000017f,0x000200f8,0x0000018b,0x0004003d,0x00000024,0x0000018c,
|
||||
0x0000015f,0x000300f7,0x0000018e,0x00000000,0x000400fa,0x0000018c,0x0000018d,0x00000190,
|
||||
0x000200f8,0x0000018d,0x0004003d,0x00000007,0x0000018f,0x0000014a,0x0003003e,0x00000180,
|
||||
0x0000018f,0x000200f9,0x0000018e,0x000200f8,0x00000190,0x0004003d,0x00000007,0x000001a1,
|
||||
0x0000014a,0x0003003e,0x000001a0,0x000001a1,0x00050039,0x00000007,0x000001a2,0x0000000b,
|
||||
0x000001a0,0x00050091,0x00000007,0x000001a3,0x0000019f,0x000001a2,0x0004003d,0x00000006,
|
||||
0x000001a4,0x00000173,0x0005008e,0x00000007,0x000001a5,0x000001a3,0x000001a4,0x0003003e,
|
||||
0x00000191,0x000001a5,0x0004003d,0x00000007,0x000001a6,0x00000191,0x00060050,0x00000007,
|
||||
0x000001a7,0x00000186,0x00000186,0x00000186,0x00050088,0x00000007,0x000001a8,0x000001a6,
|
||||
0x000001a7,0x0003003e,0x000001a9,0x000001a8,0x00050039,0x00000007,0x000001aa,0x00000014,
|
||||
0x000001a9,0x0003003e,0x00000180,0x000001aa,0x000200f9,0x0000018e,0x000200f8,0x0000018e,
|
||||
0x000200f9,0x0000017f,0x000200f8,0x0000017f,0x000200f9,0x0000017c,0x000200f8,0x000001ab,
|
||||
0x0004003d,0x00000024,0x000001ac,0x0000015f,0x000400a8,0x00000024,0x000001ad,0x000001ac,
|
||||
0x000300f7,0x000001af,0x00000000,0x000400fa,0x000001ad,0x000001ae,0x000001b1,0x000200f8,
|
||||
0x000001ae,0x0004003d,0x00000007,0x000001b0,0x0000014a,0x0003003e,0x00000180,0x000001b0,
|
||||
0x000200f9,0x000001af,0x000200f8,0x000001b1,0x0004003d,0x00000024,0x000001b3,0x00000168,
|
||||
0x000300f7,0x000001b6,0x00000000,0x000400fa,0x000001b3,0x000001b5,0x000001ba,0x000200f8,
|
||||
0x000001b5,0x0004003d,0x00000007,0x000001b8,0x0000014a,0x0003003e,0x000001b7,0x000001b8,
|
||||
0x00050039,0x00000007,0x000001b9,0x0000002b,0x000001b7,0x0003003e,0x000001b4,0x000001b9,
|
||||
0x000200f9,0x000001b6,0x000200f8,0x000001ba,0x0004003d,0x00000007,0x000001bc,0x0000014a,
|
||||
0x0003003e,0x000001bb,0x000001bc,0x00050039,0x00000007,0x000001bd,0x00000011,0x000001bb,
|
||||
0x0005008e,0x00000007,0x000001be,0x000001bd,0x00000186,0x0003003e,0x000001b4,0x000001be,
|
||||
0x000200f9,0x000001b6,0x000200f8,0x000001b6,0x0004003d,0x00000007,0x000001bf,0x000001b4,
|
||||
0x0003003e,0x000001b2,0x000001bf,0x0004003d,0x00000007,0x000001ce,0x000001b2,0x00050091,
|
||||
0x00000007,0x000001cf,0x000001cd,0x000001ce,0x00060050,0x00000007,0x000001d0,0x0000005c,
|
||||
0x0000005c,0x0000005c,0x0007000c,0x00000007,0x000001d1,0x00000001,0x00000028,0x000001cf,
|
||||
0x000001d0,0x0004003d,0x00000006,0x000001d2,0x00000173,0x00060050,0x00000007,0x000001d3,
|
||||
0x000001d2,0x000001d2,0x000001d2,0x00050088,0x00000007,0x000001d4,0x000001d1,0x000001d3,
|
||||
0x0003003e,0x000001c0,0x000001d4,0x00050041,0x00000016,0x000001d6,0x000001c0,0x000000d8,
|
||||
0x0004003d,0x00000006,0x000001d7,0x000001d6,0x00050041,0x00000016,0x000001d8,0x000001c0,
|
||||
0x000000e6,0x0004003d,0x00000006,0x000001d9,0x000001d8,0x0007000c,0x00000006,0x000001da,
|
||||
0x00000001,0x00000028,0x000001d7,0x000001d9,0x00050041,0x00000016,0x000001db,0x000001c0,
|
||||
0x00000177,0x0004003d,0x00000006,0x000001dc,0x000001db,0x0007000c,0x00000006,0x000001dd,
|
||||
0x00000001,0x00000028,0x000001da,0x000001dc,0x0003003e,0x000001d5,0x000001dd,0x0004003d,
|
||||
0x00000006,0x000001de,0x000001d5,0x000500ba,0x00000024,0x000001df,0x000001de,0x00000070,
|
||||
0x000300f7,0x000001e1,0x00000000,0x000400fa,0x000001df,0x000001e0,0x000001e1,0x000200f8,
|
||||
0x000001e0,0x00060041,0x000000b8,0x000001e2,0x000000b6,0x000000b7,0x000000e6,0x0004003d,
|
||||
0x00000006,0x000001e3,0x000001e2,0x0004003d,0x00000006,0x000001e4,0x00000173,0x0007000c,
|
||||
0x00000006,0x000001e5,0x00000001,0x00000028,0x000001e3,0x000001e4,0x0004003d,0x00000006,
|
||||
0x000001e6,0x00000173,0x00050088,0x00000006,0x000001e7,0x000001e5,0x000001e6,0x0004003d,
|
||||
0x00000006,0x000001e9,0x000001d5,0x0003003e,0x000001e8,0x000001e9,0x0003003e,0x000001ea,
|
||||
0x000001e7,0x00060039,0x00000006,0x000001eb,0x0000001a,0x000001e8,0x000001ea,0x0004003d,
|
||||
0x00000006,0x000001ec,0x000001d5,0x00050088,0x00000006,0x000001ed,0x000001eb,0x000001ec,
|
||||
0x0004003d,0x00000007,0x000001ee,0x000001c0,0x0005008e,0x00000007,0x000001ef,0x000001ee,
|
||||
0x000001ed,0x0003003e,0x000001c0,0x000001ef,0x000200f9,0x000001e1,0x000200f8,0x000001e1,
|
||||
0x0004003d,0x00000007,0x000001f0,0x000001c0,0x00060050,0x00000007,0x000001f1,0x0000005c,
|
||||
0x0000005c,0x0000005c,0x00060050,0x00000007,0x000001f2,0x0000005d,0x0000005d,0x0000005d,
|
||||
0x0008000c,0x00000007,0x000001f3,0x00000001,0x0000002b,0x000001f0,0x000001f1,0x000001f2,
|
||||
0x0003003e,0x000001f4,0x000001f3,0x00050039,0x00000007,0x000001f5,0x0000000e,0x000001f4,
|
||||
0x0003003e,0x00000180,0x000001f5,0x000200f9,0x000001af,0x000200f8,0x000001af,0x000200f9,
|
||||
0x0000017c,0x000200f8,0x0000017c,0x0004003d,0x00000007,0x000001f8,0x00000180,0x00050051,
|
||||
0x00000006,0x000001f9,0x000001f8,0x00000000,0x00050051,0x00000006,0x000001fa,0x000001f8,
|
||||
0x00000001,0x00050051,0x00000006,0x000001fb,0x000001f8,0x00000002,0x00070050,0x000000ad,
|
||||
0x000001fc,0x000001f9,0x000001fa,0x000001fb,0x0000005d,0x0003003e,0x000001f7,0x000001fc,
|
||||
0x000100fd,0x00010038,0x00050036,0x00000007,0x0000000b,0x00000000,0x00000009,0x00030037,
|
||||
0x00000008,0x0000000a,0x000200f8,0x0000000c,0x0004003b,0x00000008,0x00000023,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000028,0x00000007,0x0004003d,0x00000007,0x00000024,0x0000000a,
|
||||
0x00060050,0x00000007,0x00000026,0x00000025,0x00000025,0x00000025,0x00050088,0x00000007,
|
||||
0x00000027,0x00000024,0x00000026,0x0003003e,0x00000023,0x00000027,0x0004003d,0x00000007,
|
||||
0x00000029,0x0000000a,0x00060050,0x00000007,0x0000002b,0x0000002a,0x0000002a,0x0000002a,
|
||||
0x00050081,0x00000007,0x0000002c,0x00000029,0x0000002b,0x00060050,0x00000007,0x0000002e,
|
||||
0x0000002d,0x0000002d,0x0000002d,0x00050088,0x00000007,0x0000002f,0x0000002c,0x0000002e,
|
||||
0x0007000c,0x00000007,0x00000032,0x00000001,0x0000001a,0x0000002f,0x00000031,0x0003003e,
|
||||
0x00000028,0x00000032,0x0004003d,0x00000007,0x00000033,0x00000023,0x0004003d,0x00000007,
|
||||
0x00000034,0x00000028,0x0004003d,0x00000007,0x00000037,0x0000000a,0x0007000c,0x00000007,
|
||||
0x00000038,0x00000001,0x00000030,0x00000036,0x00000037,0x0008000c,0x00000007,0x00000039,
|
||||
0x00000001,0x0000002e,0x00000033,0x00000034,0x00000038,0x000200fe,0x00000039,0x00010038,
|
||||
0x00000008,0x0000000a,0x000200f8,0x0000000c,0x0004003b,0x00000008,0x0000002d,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000032,0x00000007,0x0004003d,0x00000007,0x0000002e,0x0000000a,
|
||||
0x00060050,0x00000007,0x00000030,0x0000002f,0x0000002f,0x0000002f,0x00050088,0x00000007,
|
||||
0x00000031,0x0000002e,0x00000030,0x0003003e,0x0000002d,0x00000031,0x0004003d,0x00000007,
|
||||
0x00000033,0x0000000a,0x00060050,0x00000007,0x00000035,0x00000034,0x00000034,0x00000034,
|
||||
0x00050081,0x00000007,0x00000036,0x00000033,0x00000035,0x00060050,0x00000007,0x00000038,
|
||||
0x00000037,0x00000037,0x00000037,0x00050088,0x00000007,0x00000039,0x00000036,0x00000038,
|
||||
0x0007000c,0x00000007,0x0000003c,0x00000001,0x0000001a,0x00000039,0x0000003b,0x0003003e,
|
||||
0x00000032,0x0000003c,0x0004003d,0x00000007,0x0000003d,0x0000002d,0x0004003d,0x00000007,
|
||||
0x0000003e,0x00000032,0x0004003d,0x00000007,0x00000041,0x0000000a,0x0007000c,0x00000007,
|
||||
0x00000042,0x00000001,0x00000030,0x00000040,0x00000041,0x0008000c,0x00000007,0x00000043,
|
||||
0x00000001,0x0000002e,0x0000003d,0x0000003e,0x00000042,0x000200fe,0x00000043,0x00010038,
|
||||
0x00050036,0x00000007,0x0000000e,0x00000000,0x00000009,0x00030037,0x00000008,0x0000000d,
|
||||
0x000200f8,0x0000000f,0x0004003b,0x00000008,0x0000003c,0x00000007,0x0004003b,0x00000008,
|
||||
0x0000003f,0x00000007,0x0004003d,0x00000007,0x0000003d,0x0000000d,0x0005008e,0x00000007,
|
||||
0x0000003e,0x0000003d,0x00000025,0x0003003e,0x0000003c,0x0000003e,0x0004003d,0x00000007,
|
||||
0x00000040,0x0000000d,0x0007000c,0x00000007,0x00000043,0x00000001,0x0000001a,0x00000040,
|
||||
0x00000042,0x0005008e,0x00000007,0x00000044,0x00000043,0x0000002d,0x00060050,0x00000007,
|
||||
0x00000045,0x0000002a,0x0000002a,0x0000002a,0x00050083,0x00000007,0x00000046,0x00000044,
|
||||
0x00000045,0x0003003e,0x0000003f,0x00000046,0x0004003d,0x00000007,0x00000047,0x0000003c,
|
||||
0x0004003d,0x00000007,0x00000048,0x0000003f,0x0004003d,0x00000007,0x0000004b,0x0000000d,
|
||||
0x0007000c,0x00000007,0x0000004c,0x00000001,0x00000030,0x0000004a,0x0000004b,0x0008000c,
|
||||
0x00000007,0x0000004d,0x00000001,0x0000002e,0x00000047,0x00000048,0x0000004c,0x000200fe,
|
||||
0x0000004d,0x00010038,0x00050036,0x00000007,0x00000011,0x00000000,0x00000009,0x00030037,
|
||||
0x00000008,0x00000010,0x000200f8,0x00000012,0x0004003b,0x00000008,0x00000050,0x00000007,
|
||||
0x0004003d,0x00000007,0x00000051,0x00000010,0x00060050,0x00000007,0x00000054,0x00000052,
|
||||
0x00000052,0x00000052,0x00060050,0x00000007,0x00000055,0x00000053,0x00000053,0x00000053,
|
||||
0x0008000c,0x00000007,0x00000056,0x00000001,0x0000002b,0x00000051,0x00000054,0x00000055,
|
||||
0x0007000c,0x00000007,0x00000059,0x00000001,0x0000001a,0x00000056,0x00000058,0x0003003e,
|
||||
0x00000050,0x00000059,0x0004003d,0x00000007,0x0000005a,0x00000050,0x00060050,0x00000007,
|
||||
0x0000005c,0x0000005b,0x0000005b,0x0000005b,0x00050083,0x00000007,0x0000005d,0x0000005a,
|
||||
0x0000005c,0x00060050,0x00000007,0x0000005e,0x00000052,0x00000052,0x00000052,0x0007000c,
|
||||
0x00000007,0x0000005f,0x00000001,0x00000028,0x0000005d,0x0000005e,0x0004003d,0x00000007,
|
||||
0x00000062,0x00000050,0x0005008e,0x00000007,0x00000063,0x00000062,0x00000061,0x00060050,
|
||||
0x00000007,0x00000064,0x00000060,0x00000060,0x00000060,0x00050083,0x00000007,0x00000065,
|
||||
0x00000064,0x00000063,0x00060050,0x00000007,0x00000067,0x00000066,0x00000066,0x00000066,
|
||||
0x0007000c,0x00000007,0x00000068,0x00000001,0x00000028,0x00000065,0x00000067,0x00050088,
|
||||
0x00000007,0x00000069,0x0000005f,0x00000068,0x0007000c,0x00000007,0x0000006c,0x00000001,
|
||||
0x0000001a,0x00000069,0x0000006b,0x000200fe,0x0000006c,0x00010038,0x00050036,0x00000007,
|
||||
0x000200f8,0x0000000f,0x0004003b,0x00000008,0x00000046,0x00000007,0x0004003b,0x00000008,
|
||||
0x00000049,0x00000007,0x0004003d,0x00000007,0x00000047,0x0000000d,0x0005008e,0x00000007,
|
||||
0x00000048,0x00000047,0x0000002f,0x0003003e,0x00000046,0x00000048,0x0004003d,0x00000007,
|
||||
0x0000004a,0x0000000d,0x0007000c,0x00000007,0x0000004d,0x00000001,0x0000001a,0x0000004a,
|
||||
0x0000004c,0x0005008e,0x00000007,0x0000004e,0x0000004d,0x00000037,0x00060050,0x00000007,
|
||||
0x0000004f,0x00000034,0x00000034,0x00000034,0x00050083,0x00000007,0x00000050,0x0000004e,
|
||||
0x0000004f,0x0003003e,0x00000049,0x00000050,0x0004003d,0x00000007,0x00000051,0x00000046,
|
||||
0x0004003d,0x00000007,0x00000052,0x00000049,0x0004003d,0x00000007,0x00000055,0x0000000d,
|
||||
0x0007000c,0x00000007,0x00000056,0x00000001,0x00000030,0x00000054,0x00000055,0x0008000c,
|
||||
0x00000007,0x00000057,0x00000001,0x0000002e,0x00000051,0x00000052,0x00000056,0x000200fe,
|
||||
0x00000057,0x00010038,0x00050036,0x00000007,0x00000011,0x00000000,0x00000009,0x00030037,
|
||||
0x00000008,0x00000010,0x000200f8,0x00000012,0x0004003b,0x00000008,0x0000005a,0x00000007,
|
||||
0x0004003d,0x00000007,0x0000005b,0x00000010,0x00060050,0x00000007,0x0000005e,0x0000005c,
|
||||
0x0000005c,0x0000005c,0x00060050,0x00000007,0x0000005f,0x0000005d,0x0000005d,0x0000005d,
|
||||
0x0008000c,0x00000007,0x00000060,0x00000001,0x0000002b,0x0000005b,0x0000005e,0x0000005f,
|
||||
0x0007000c,0x00000007,0x00000063,0x00000001,0x0000001a,0x00000060,0x00000062,0x0003003e,
|
||||
0x0000005a,0x00000063,0x0004003d,0x00000007,0x00000064,0x0000005a,0x00060050,0x00000007,
|
||||
0x00000066,0x00000065,0x00000065,0x00000065,0x00050083,0x00000007,0x00000067,0x00000064,
|
||||
0x00000066,0x00060050,0x00000007,0x00000068,0x0000005c,0x0000005c,0x0000005c,0x0007000c,
|
||||
0x00000007,0x00000069,0x00000001,0x00000028,0x00000067,0x00000068,0x0004003d,0x00000007,
|
||||
0x0000006c,0x0000005a,0x0005008e,0x00000007,0x0000006d,0x0000006c,0x0000006b,0x00060050,
|
||||
0x00000007,0x0000006e,0x0000006a,0x0000006a,0x0000006a,0x00050083,0x00000007,0x0000006f,
|
||||
0x0000006e,0x0000006d,0x00060050,0x00000007,0x00000071,0x00000070,0x00000070,0x00000070,
|
||||
0x0007000c,0x00000007,0x00000072,0x00000001,0x00000028,0x0000006f,0x00000071,0x00050088,
|
||||
0x00000007,0x00000073,0x00000069,0x00000072,0x0007000c,0x00000007,0x00000076,0x00000001,
|
||||
0x0000001a,0x00000073,0x00000075,0x000200fe,0x00000076,0x00010038,0x00050036,0x00000007,
|
||||
0x00000014,0x00000000,0x00000009,0x00030037,0x00000008,0x00000013,0x000200f8,0x00000015,
|
||||
0x0004003b,0x00000008,0x0000006f,0x00000007,0x0004003d,0x00000007,0x00000070,0x00000013,
|
||||
0x00060050,0x00000007,0x00000071,0x00000052,0x00000052,0x00000052,0x00060050,0x00000007,
|
||||
0x00000072,0x00000053,0x00000053,0x00000053,0x0008000c,0x00000007,0x00000073,0x00000001,
|
||||
0x0000002b,0x00000070,0x00000071,0x00000072,0x0007000c,0x00000007,0x00000076,0x00000001,
|
||||
0x0000001a,0x00000073,0x00000075,0x0003003e,0x0000006f,0x00000076,0x0004003d,0x00000007,
|
||||
0x00000077,0x0000006f,0x0005008e,0x00000007,0x00000078,0x00000077,0x00000060,0x00060050,
|
||||
0x00000007,0x00000079,0x0000005b,0x0000005b,0x0000005b,0x00050081,0x00000007,0x0000007a,
|
||||
0x00000079,0x00000078,0x0004003d,0x00000007,0x0000007b,0x0000006f,0x0005008e,0x00000007,
|
||||
0x0000007c,0x0000007b,0x00000061,0x00060050,0x00000007,0x0000007d,0x00000053,0x00000053,
|
||||
0x00000053,0x00050081,0x00000007,0x0000007e,0x0000007d,0x0000007c,0x00050088,0x00000007,
|
||||
0x0000007f,0x0000007a,0x0000007e,0x0007000c,0x00000007,0x00000082,0x00000001,0x0000001a,
|
||||
0x0000007f,0x00000081,0x000200fe,0x00000082,0x00010038,0x00050036,0x00000006,0x0000001a,
|
||||
0x0004003b,0x00000008,0x00000079,0x00000007,0x0004003d,0x00000007,0x0000007a,0x00000013,
|
||||
0x00060050,0x00000007,0x0000007b,0x0000005c,0x0000005c,0x0000005c,0x00060050,0x00000007,
|
||||
0x0000007c,0x0000005d,0x0000005d,0x0000005d,0x0008000c,0x00000007,0x0000007d,0x00000001,
|
||||
0x0000002b,0x0000007a,0x0000007b,0x0000007c,0x0007000c,0x00000007,0x00000080,0x00000001,
|
||||
0x0000001a,0x0000007d,0x0000007f,0x0003003e,0x00000079,0x00000080,0x0004003d,0x00000007,
|
||||
0x00000081,0x00000079,0x0005008e,0x00000007,0x00000082,0x00000081,0x0000006a,0x00060050,
|
||||
0x00000007,0x00000083,0x00000065,0x00000065,0x00000065,0x00050081,0x00000007,0x00000084,
|
||||
0x00000083,0x00000082,0x0004003d,0x00000007,0x00000085,0x00000079,0x0005008e,0x00000007,
|
||||
0x00000086,0x00000085,0x0000006b,0x00060050,0x00000007,0x00000087,0x0000005d,0x0000005d,
|
||||
0x0000005d,0x00050081,0x00000007,0x00000088,0x00000087,0x00000086,0x00050088,0x00000007,
|
||||
0x00000089,0x00000084,0x00000088,0x0007000c,0x00000007,0x0000008c,0x00000001,0x0000001a,
|
||||
0x00000089,0x0000008b,0x000200fe,0x0000008c,0x00010038,0x00050036,0x00000006,0x0000001a,
|
||||
0x00000000,0x00000017,0x00030037,0x00000016,0x00000018,0x00030037,0x00000016,0x00000019,
|
||||
0x000200f8,0x0000001b,0x0004003b,0x00000016,0x0000008c,0x00000007,0x0004003b,0x00000016,
|
||||
0x00000091,0x00000007,0x0004003d,0x00000006,0x00000085,0x00000018,0x000500bc,0x0000001e,
|
||||
0x00000087,0x00000085,0x00000086,0x000300f7,0x00000089,0x00000000,0x000400fa,0x00000087,
|
||||
0x00000088,0x00000089,0x000200f8,0x00000088,0x0004003d,0x00000006,0x0000008a,0x00000018,
|
||||
0x000200fe,0x0000008a,0x000200f8,0x00000089,0x0004003d,0x00000006,0x0000008d,0x00000019,
|
||||
0x00050083,0x00000006,0x0000008e,0x0000008d,0x00000086,0x0007000c,0x00000006,0x00000090,
|
||||
0x00000001,0x00000028,0x0000008e,0x0000008f,0x0003003e,0x0000008c,0x00000090,0x0004003d,
|
||||
0x00000006,0x00000092,0x0000008c,0x00050088,0x00000006,0x00000094,0x00000092,0x00000093,
|
||||
0x0007000c,0x00000006,0x00000096,0x00000001,0x00000028,0x00000094,0x00000095,0x0003003e,
|
||||
0x00000091,0x00000096,0x0004003d,0x00000006,0x00000097,0x00000018,0x00050083,0x00000006,
|
||||
0x00000098,0x00000097,0x00000086,0x0004007f,0x00000006,0x00000099,0x00000098,0x0004003d,
|
||||
0x00000006,0x0000009a,0x00000091,0x00050088,0x00000006,0x0000009b,0x00000099,0x0000009a,
|
||||
0x0006000c,0x00000006,0x0000009c,0x00000001,0x0000001b,0x0000009b,0x00050083,0x00000006,
|
||||
0x0000009d,0x00000053,0x0000009c,0x00050085,0x00000006,0x0000009e,0x00000095,0x0000009d,
|
||||
0x00050081,0x00000006,0x0000009f,0x00000086,0x0000009e,0x000200fe,0x0000009f,0x00010038,
|
||||
0x000200f8,0x0000001b,0x0004003b,0x00000016,0x00000096,0x00000007,0x0004003b,0x00000016,
|
||||
0x0000009b,0x00000007,0x0004003d,0x00000006,0x0000008f,0x00000018,0x000500bc,0x00000024,
|
||||
0x00000091,0x0000008f,0x00000090,0x000300f7,0x00000093,0x00000000,0x000400fa,0x00000091,
|
||||
0x00000092,0x00000093,0x000200f8,0x00000092,0x0004003d,0x00000006,0x00000094,0x00000018,
|
||||
0x000200fe,0x00000094,0x000200f8,0x00000093,0x0004003d,0x00000006,0x00000097,0x00000019,
|
||||
0x00050083,0x00000006,0x00000098,0x00000097,0x00000090,0x0007000c,0x00000006,0x0000009a,
|
||||
0x00000001,0x00000028,0x00000098,0x00000099,0x0003003e,0x00000096,0x0000009a,0x0004003d,
|
||||
0x00000006,0x0000009c,0x00000096,0x00050088,0x00000006,0x0000009e,0x0000009c,0x0000009d,
|
||||
0x0007000c,0x00000006,0x000000a0,0x00000001,0x00000028,0x0000009e,0x0000009f,0x0003003e,
|
||||
0x0000009b,0x000000a0,0x0004003d,0x00000006,0x000000a1,0x00000018,0x00050083,0x00000006,
|
||||
0x000000a2,0x000000a1,0x00000090,0x0004007f,0x00000006,0x000000a3,0x000000a2,0x0004003d,
|
||||
0x00000006,0x000000a4,0x0000009b,0x00050088,0x00000006,0x000000a5,0x000000a3,0x000000a4,
|
||||
0x0006000c,0x00000006,0x000000a6,0x00000001,0x0000001b,0x000000a5,0x00050083,0x00000006,
|
||||
0x000000a7,0x0000005d,0x000000a6,0x00050085,0x00000006,0x000000a8,0x0000009f,0x000000a7,
|
||||
0x00050081,0x00000006,0x000000a9,0x00000090,0x000000a8,0x000200fe,0x000000a9,0x00010038,
|
||||
0x00050036,0x0000001e,0x00000021,0x00000000,0x0000001f,0x00030037,0x0000001d,0x00000020,
|
||||
0x000200f8,0x00000022,0x0004003b,0x00000016,0x000000a2,0x00000007,0x0004003b,0x00000016,
|
||||
0x000000b0,0x00000007,0x0004003b,0x00000016,0x000000b4,0x00000007,0x0004003b,0x000000b8,
|
||||
0x000000b9,0x00000007,0x0004003b,0x000000cc,0x000000cd,0x00000007,0x0004003b,0x00000016,
|
||||
0x000000f5,0x00000007,0x00060041,0x000000ad,0x000000ae,0x000000a9,0x000000ab,0x000000ac,
|
||||
0x0004003d,0x00000006,0x000000af,0x000000ae,0x0003003e,0x000000a2,0x000000af,0x0004003d,
|
||||
0x00000006,0x000000b1,0x000000a2,0x0005008d,0x00000006,0x000000b3,0x000000b1,0x000000b2,
|
||||
0x0003003e,0x000000b0,0x000000b3,0x0004003d,0x00000006,0x000000b5,0x000000a2,0x00050088,
|
||||
0x00000006,0x000000b6,0x000000b5,0x000000b2,0x0006000c,0x00000006,0x000000b7,0x00000001,
|
||||
0x00000008,0x000000b6,0x0003003e,0x000000b4,0x000000b7,0x0003003e,0x000000b9,0x000000ba,
|
||||
0x000200f9,0x000000bb,0x000200f8,0x000000bb,0x000400f6,0x000000bd,0x000000be,0x00000000,
|
||||
0x000200f9,0x000000bf,0x000200f8,0x000000bf,0x0004003d,0x000000aa,0x000000c0,0x000000b9,
|
||||
0x000500b1,0x0000001e,0x000000c2,0x000000c0,0x000000c1,0x000400fa,0x000000c2,0x000000bc,
|
||||
0x000000bd,0x000200f8,0x000000bc,0x0004003d,0x000000aa,0x000000c3,0x000000b9,0x0004006f,
|
||||
0x00000006,0x000000c4,0x000000c3,0x0004003d,0x00000006,0x000000c5,0x000000b0,0x00050083,
|
||||
0x00000006,0x000000c7,0x000000c5,0x000000c6,0x000500be,0x0000001e,0x000000c8,0x000000c4,
|
||||
0x000000c7,0x000300f7,0x000000ca,0x00000000,0x000400fa,0x000000c8,0x000000c9,0x000000ca,
|
||||
0x000200f8,0x000000c9,0x000200f9,0x000000bd,0x000200f8,0x000000ca,0x0004003d,0x000000aa,
|
||||
0x000000cf,0x000000b9,0x00060041,0x000000d0,0x000000d1,0x000000a9,0x000000ce,0x000000cf,
|
||||
0x0004003d,0x000000a3,0x000000d2,0x000000d1,0x0003003e,0x000000cd,0x000000d2,0x00050041,
|
||||
0x00000016,0x000000d4,0x00000020,0x000000d3,0x0004003d,0x00000006,0x000000d5,0x000000d4,
|
||||
0x00050041,0x00000016,0x000000d6,0x000000cd,0x000000d3,0x0004003d,0x00000006,0x000000d7,
|
||||
0x000000d6,0x000500be,0x0000001e,0x000000d8,0x000000d5,0x000000d7,0x000300f7,0x000000da,
|
||||
0x00000000,0x000400fa,0x000000d8,0x000000d9,0x000000da,0x000200f8,0x000000d9,0x00050041,
|
||||
0x00000016,0x000000dc,0x00000020,0x000000db,0x0004003d,0x00000006,0x000000dd,0x000000dc,
|
||||
0x00050041,0x00000016,0x000000de,0x000000cd,0x000000db,0x0004003d,0x00000006,0x000000df,
|
||||
0x000000de,0x000500be,0x0000001e,0x000000e0,0x000000dd,0x000000df,0x000200f9,0x000000da,
|
||||
0x000200f8,0x000000da,0x000700f5,0x0000001e,0x000000e1,0x000000d8,0x000000ca,0x000000e0,
|
||||
0x000000d9,0x000300f7,0x000000e3,0x00000000,0x000400fa,0x000000e1,0x000000e2,0x000000e3,
|
||||
0x000200f8,0x000000e2,0x00050041,0x00000016,0x000000e4,0x00000020,0x000000d3,0x0004003d,
|
||||
0x00000006,0x000000e5,0x000000e4,0x00050041,0x00000016,0x000000e7,0x000000cd,0x000000e6,
|
||||
0x0004003d,0x00000006,0x000000e8,0x000000e7,0x000500b8,0x0000001e,0x000000e9,0x000000e5,
|
||||
0x000000e8,0x000200f9,0x000000e3,0x000200f8,0x000000e3,0x000700f5,0x0000001e,0x000000ea,
|
||||
0x000000e1,0x000000da,0x000000e9,0x000000e2,0x000300f7,0x000000ec,0x00000000,0x000400fa,
|
||||
0x000000ea,0x000000eb,0x000000ec,0x000200f8,0x000000eb,0x00050041,0x00000016,0x000000ed,
|
||||
0x00000020,0x000000db,0x0004003d,0x00000006,0x000000ee,0x000000ed,0x00050041,0x00000016,
|
||||
0x000000ef,0x000000cd,0x000000ac,0x0004003d,0x00000006,0x000000f0,0x000000ef,0x000500b8,
|
||||
0x0000001e,0x000000f1,0x000000ee,0x000000f0,0x000200f9,0x000000ec,0x000200f8,0x000000ec,
|
||||
0x000700f5,0x0000001e,0x000000f2,0x000000ea,0x000000e3,0x000000f1,0x000000eb,0x000300f7,
|
||||
0x000000f4,0x00000000,0x000400fa,0x000000f2,0x000000f3,0x000000f4,0x000200f8,0x000000f3,
|
||||
0x0004003d,0x00000006,0x000000f6,0x000000b4,0x0004003d,0x000000aa,0x000000f7,0x000000b9,
|
||||
0x0004006f,0x00000006,0x000000f8,0x000000f7,0x0006000c,0x00000006,0x000000f9,0x00000001,
|
||||
0x0000001d,0x000000f8,0x00050088,0x00000006,0x000000fa,0x000000f6,0x000000f9,0x0006000c,
|
||||
0x00000006,0x000000fb,0x00000001,0x00000008,0x000000fa,0x0005008d,0x00000006,0x000000fd,
|
||||
0x000000fb,0x000000fc,0x0003003e,0x000000f5,0x000000fd,0x0004003d,0x00000006,0x000000fe,
|
||||
0x000000f5,0x000500ba,0x0000001e,0x000000ff,0x000000fe,0x000000c6,0x000200fe,0x000000ff,
|
||||
0x000200f8,0x000000f4,0x000200f9,0x000000be,0x000200f8,0x000000be,0x0004003d,0x000000aa,
|
||||
0x00000101,0x000000b9,0x00050080,0x000000aa,0x00000102,0x00000101,0x000000ab,0x0003003e,
|
||||
0x000000b9,0x00000102,0x000200f9,0x000000bb,0x000200f8,0x000000bd,0x000200fe,0x00000103,
|
||||
0x00010038
|
||||
0x000200f8,0x00000022,0x0004003b,0x00000016,0x000000ac,0x00000007,0x0004003b,0x00000023,
|
||||
0x000000bd,0x00000007,0x0004003b,0x000000d0,0x000000d1,0x00000007,0x0004003b,0x0000001d,
|
||||
0x000000d7,0x00000007,0x0004003b,0x0000001d,0x000000e5,0x00000007,0x00060041,0x000000b8,
|
||||
0x000000b9,0x000000b6,0x000000b7,0x000000b2,0x0004003d,0x00000006,0x000000ba,0x000000b9,
|
||||
0x0005008d,0x00000006,0x000000bc,0x000000ba,0x000000bb,0x0003003e,0x000000ac,0x000000bc,
|
||||
0x0003003e,0x000000bd,0x000000be,0x000200f9,0x000000bf,0x000200f8,0x000000bf,0x000400f6,
|
||||
0x000000c1,0x000000c2,0x00000000,0x000200f9,0x000000c3,0x000200f8,0x000000c3,0x0004003d,
|
||||
0x0000001e,0x000000c4,0x000000bd,0x000500b1,0x00000024,0x000000c6,0x000000c4,0x000000c5,
|
||||
0x000400fa,0x000000c6,0x000000c0,0x000000c1,0x000200f8,0x000000c0,0x0004003d,0x0000001e,
|
||||
0x000000c7,0x000000bd,0x0004006f,0x00000006,0x000000c8,0x000000c7,0x0004003d,0x00000006,
|
||||
0x000000c9,0x000000ac,0x00050083,0x00000006,0x000000cb,0x000000c9,0x000000ca,0x000500be,
|
||||
0x00000024,0x000000cc,0x000000c8,0x000000cb,0x000300f7,0x000000ce,0x00000000,0x000400fa,
|
||||
0x000000cc,0x000000cd,0x000000ce,0x000200f8,0x000000cd,0x000200f9,0x000000c1,0x000200f8,
|
||||
0x000000ce,0x0004003d,0x0000001e,0x000000d3,0x000000bd,0x00060041,0x000000d4,0x000000d5,
|
||||
0x000000b6,0x000000d2,0x000000d3,0x0004003d,0x000000af,0x000000d6,0x000000d5,0x0003003e,
|
||||
0x000000d1,0x000000d6,0x00050041,0x000000d9,0x000000da,0x000000d1,0x000000d8,0x0004003d,
|
||||
0x000000ae,0x000000db,0x000000da,0x000500c7,0x000000ae,0x000000dd,0x000000db,0x000000dc,
|
||||
0x00040070,0x00000006,0x000000de,0x000000dd,0x00050041,0x000000d9,0x000000df,0x000000d1,
|
||||
0x000000d8,0x0004003d,0x000000ae,0x000000e0,0x000000df,0x000500c2,0x000000ae,0x000000e2,
|
||||
0x000000e0,0x000000e1,0x00040070,0x00000006,0x000000e3,0x000000e2,0x00050050,0x0000001c,
|
||||
0x000000e4,0x000000de,0x000000e3,0x0003003e,0x000000d7,0x000000e4,0x00050041,0x000000d9,
|
||||
0x000000e7,0x000000d1,0x000000e6,0x0004003d,0x000000ae,0x000000e8,0x000000e7,0x000500c7,
|
||||
0x000000ae,0x000000e9,0x000000e8,0x000000dc,0x00040070,0x00000006,0x000000ea,0x000000e9,
|
||||
0x00050041,0x000000d9,0x000000eb,0x000000d1,0x000000e6,0x0004003d,0x000000ae,0x000000ec,
|
||||
0x000000eb,0x000500c2,0x000000ae,0x000000ed,0x000000ec,0x000000e1,0x00040070,0x00000006,
|
||||
0x000000ee,0x000000ed,0x00050050,0x0000001c,0x000000ef,0x000000ea,0x000000ee,0x0003003e,
|
||||
0x000000e5,0x000000ef,0x00050041,0x00000016,0x000000f0,0x00000020,0x000000d8,0x0004003d,
|
||||
0x00000006,0x000000f1,0x000000f0,0x00050041,0x00000016,0x000000f2,0x000000d7,0x000000d8,
|
||||
0x0004003d,0x00000006,0x000000f3,0x000000f2,0x000500be,0x00000024,0x000000f4,0x000000f1,
|
||||
0x000000f3,0x000300f7,0x000000f6,0x00000000,0x000400fa,0x000000f4,0x000000f5,0x000000f6,
|
||||
0x000200f8,0x000000f5,0x00050041,0x00000016,0x000000f7,0x00000020,0x000000e6,0x0004003d,
|
||||
0x00000006,0x000000f8,0x000000f7,0x00050041,0x00000016,0x000000f9,0x000000d7,0x000000e6,
|
||||
0x0004003d,0x00000006,0x000000fa,0x000000f9,0x000500be,0x00000024,0x000000fb,0x000000f8,
|
||||
0x000000fa,0x000200f9,0x000000f6,0x000200f8,0x000000f6,0x000700f5,0x00000024,0x000000fc,
|
||||
0x000000f4,0x000000ce,0x000000fb,0x000000f5,0x000300f7,0x000000fe,0x00000000,0x000400fa,
|
||||
0x000000fc,0x000000fd,0x000000fe,0x000200f8,0x000000fd,0x00050041,0x00000016,0x000000ff,
|
||||
0x00000020,0x000000d8,0x0004003d,0x00000006,0x00000100,0x000000ff,0x00050041,0x00000016,
|
||||
0x00000101,0x000000e5,0x000000d8,0x0004003d,0x00000006,0x00000102,0x00000101,0x000500b8,
|
||||
0x00000024,0x00000103,0x00000100,0x00000102,0x000200f9,0x000000fe,0x000200f8,0x000000fe,
|
||||
0x000700f5,0x00000024,0x00000104,0x000000fc,0x000000f6,0x00000103,0x000000fd,0x000300f7,
|
||||
0x00000106,0x00000000,0x000400fa,0x00000104,0x00000105,0x00000106,0x000200f8,0x00000105,
|
||||
0x00050041,0x00000016,0x00000107,0x00000020,0x000000e6,0x0004003d,0x00000006,0x00000108,
|
||||
0x00000107,0x00050041,0x00000016,0x00000109,0x000000e5,0x000000e6,0x0004003d,0x00000006,
|
||||
0x0000010a,0x00000109,0x000500b8,0x00000024,0x0000010b,0x00000108,0x0000010a,0x000200f9,
|
||||
0x00000106,0x000200f8,0x00000106,0x000700f5,0x00000024,0x0000010c,0x00000104,0x000000fe,
|
||||
0x0000010b,0x00000105,0x000300f7,0x0000010e,0x00000000,0x000400fa,0x0000010c,0x0000010d,
|
||||
0x0000010e,0x000200f8,0x0000010d,0x0004003d,0x0000001e,0x0000010f,0x000000bd,0x000200fe,
|
||||
0x0000010f,0x000200f8,0x0000010e,0x000200f9,0x000000c2,0x000200f8,0x000000c2,0x0004003d,
|
||||
0x0000001e,0x00000111,0x000000bd,0x00050080,0x0000001e,0x00000112,0x00000111,0x000000b7,
|
||||
0x0003003e,0x000000bd,0x00000112,0x000200f9,0x000000bf,0x000200f8,0x000000c1,0x000200fe,
|
||||
0x00000113,0x00010038,0x00050036,0x00000024,0x00000028,0x00000000,0x00000025,0x00030037,
|
||||
0x00000016,0x00000026,0x00030037,0x00000023,0x00000027,0x000200f8,0x00000029,0x0004003d,
|
||||
0x0000001e,0x00000116,0x00000027,0x000500af,0x00000024,0x00000117,0x00000116,0x000000be,
|
||||
0x000300f7,0x00000119,0x00000000,0x000400fa,0x00000117,0x00000118,0x00000119,0x000200f8,
|
||||
0x00000118,0x0004003d,0x00000006,0x0000011a,0x00000026,0x0004003d,0x0000001e,0x0000011b,
|
||||
0x00000027,0x0004006f,0x00000006,0x0000011c,0x0000011b,0x0006000c,0x00000006,0x0000011d,
|
||||
0x00000001,0x0000001d,0x0000011c,0x00050088,0x00000006,0x0000011e,0x0000011a,0x0000011d,
|
||||
0x0006000c,0x00000006,0x0000011f,0x00000001,0x00000008,0x0000011e,0x0005008d,0x00000006,
|
||||
0x00000121,0x0000011f,0x00000120,0x000500ba,0x00000024,0x00000122,0x00000121,0x000000ca,
|
||||
0x000200f9,0x00000119,0x000200f8,0x00000119,0x000700f5,0x00000024,0x00000123,0x00000117,
|
||||
0x00000029,0x00000122,0x00000118,0x000200fe,0x00000123,0x00010038,0x00050036,0x00000007,
|
||||
0x0000002b,0x00000000,0x00000009,0x00030037,0x00000008,0x0000002a,0x000200f8,0x0000002c,
|
||||
0x0004003b,0x00000008,0x00000126,0x00000007,0x0004003b,0x00000008,0x0000012b,0x00000007,
|
||||
0x0004003b,0x00000008,0x00000130,0x00000007,0x00070041,0x000000b8,0x00000128,0x000000b6,
|
||||
0x00000127,0x000000b7,0x000000b2,0x0004003d,0x00000006,0x00000129,0x00000128,0x000500ba,
|
||||
0x00000024,0x0000012a,0x00000129,0x000000ca,0x000300f7,0x0000012d,0x00000000,0x000400fa,
|
||||
0x0000012a,0x0000012c,0x0000012f,0x000200f8,0x0000012c,0x0004003d,0x00000007,0x0000012e,
|
||||
0x0000002a,0x0003003e,0x0000012b,0x0000012e,0x000200f9,0x0000012d,0x000200f8,0x0000012f,
|
||||
0x0004003d,0x00000007,0x00000131,0x0000002a,0x0003003e,0x00000130,0x00000131,0x00050039,
|
||||
0x00000007,0x00000132,0x00000011,0x00000130,0x0003003e,0x0000012b,0x00000132,0x000200f9,
|
||||
0x0000012d,0x000200f8,0x0000012d,0x0004003d,0x00000007,0x00000133,0x0000012b,0x0003003e,
|
||||
0x00000126,0x00000133,0x00060041,0x00000134,0x00000135,0x000000b6,0x00000127,0x000000be,
|
||||
0x0004003d,0x000000ad,0x00000136,0x00000135,0x0008004f,0x00000007,0x00000137,0x00000136,
|
||||
0x00000136,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000007,0x00000138,0x00000126,
|
||||
0x00050094,0x00000006,0x00000139,0x00000137,0x00000138,0x00060041,0x00000134,0x0000013a,
|
||||
0x000000b6,0x00000127,0x000000b7,0x0004003d,0x000000ad,0x0000013b,0x0000013a,0x0008004f,
|
||||
0x00000007,0x0000013c,0x0000013b,0x0000013b,0x00000000,0x00000001,0x00000002,0x0004003d,
|
||||
0x00000007,0x0000013d,0x00000126,0x00050094,0x00000006,0x0000013e,0x0000013c,0x0000013d,
|
||||
0x00060041,0x00000134,0x0000013f,0x000000b6,0x00000127,0x000000d2,0x0004003d,0x000000ad,
|
||||
0x00000140,0x0000013f,0x0008004f,0x00000007,0x00000141,0x00000140,0x00000140,0x00000000,
|
||||
0x00000001,0x00000002,0x0004003d,0x00000007,0x00000142,0x00000126,0x00050094,0x00000006,
|
||||
0x00000143,0x00000141,0x00000142,0x00060050,0x00000007,0x00000144,0x00000139,0x0000013e,
|
||||
0x00000143,0x00070041,0x000000b8,0x00000145,0x000000b6,0x00000127,0x000000d2,0x000000b2,
|
||||
0x0004003d,0x00000006,0x00000146,0x00000145,0x0005008e,0x00000007,0x00000147,0x00000144,
|
||||
0x00000146,0x000200fe,0x00000147,0x00010038
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "ahb_swapchain.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "vk_present.h"
|
||||
#include "framegen_bridge.h"
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <android/native_window.h>
|
||||
#include <android/rect.h>
|
||||
@@ -64,6 +65,8 @@ static struct {
|
||||
void (*setHdrMetadata_cta861_3)(ASurfaceTransaction *, ASurfaceControl *, const struct droiddeck_hdr_cta861_3 *);
|
||||
const void *(*getNativeHandle)(const AHardwareBuffer *);
|
||||
void (*setDesiredHdrHeadroom)(ASurfaceTransaction *, ASurfaceControl *, float);
|
||||
void (*setEnableBackPressure)(ASurfaceTransaction *, ASurfaceControl *, bool);
|
||||
void (*setDesiredPresentTime)(ASurfaceTransaction *, int64_t);
|
||||
int state;
|
||||
} api;
|
||||
|
||||
@@ -105,6 +108,8 @@ static int load_api(void) {
|
||||
SYM(setHdrMetadata_smpte2086, "ASurfaceTransaction_setHdrMetadata_smpte2086");
|
||||
SYM(setHdrMetadata_cta861_3, "ASurfaceTransaction_setHdrMetadata_cta861_3");
|
||||
SYM(setDesiredHdrHeadroom, "ASurfaceTransaction_setDesiredHdrHeadroom");
|
||||
SYM(setEnableBackPressure, "ASurfaceTransaction_setEnableBackPressure");
|
||||
SYM(setDesiredPresentTime, "ASurfaceTransaction_setDesiredPresentTime");
|
||||
#undef SYM
|
||||
if (!api.createFromWindow || !api.release || !api.txCreate || !api.txDelete || !api.txApply ||
|
||||
!api.setBuffer || !api.setZOrder || !api.setVisibility || !api.setGeometry ||
|
||||
@@ -134,7 +139,7 @@ void sc_layer_set_frame_rate(float fps) {
|
||||
}
|
||||
|
||||
|
||||
#define POOL_MAX 5
|
||||
#define POOL_MAX 8
|
||||
|
||||
struct slot {
|
||||
AHardwareBuffer *ahb;
|
||||
@@ -183,6 +188,12 @@ static int g_layers_ready;
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_pending_cb;
|
||||
static unsigned g_stat_layer_frames;
|
||||
static pthread_mutex_t g_timeline_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int64_t g_timeline_present_ns, g_timeline_deadline_ns, g_timeline_period_ns;
|
||||
static int g_timeline_late;
|
||||
static int64_t g_cadence_seen_ns, g_cadence_gap_ns, g_cadence_target_ns;
|
||||
static int g_group_frames = 1, g_group_index;
|
||||
static unsigned g_stat_aimed_next, g_stat_aimed_later, g_stat_aimed_even;
|
||||
static int g_two_logged;
|
||||
static AHardwareBuffer *g_blank;
|
||||
static ASurfaceControl *g_base_sc;
|
||||
@@ -219,6 +230,58 @@ static int64_t now_ns(void) {
|
||||
return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
}
|
||||
|
||||
void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns) {
|
||||
pthread_mutex_lock(&g_timeline_lock);
|
||||
g_timeline_present_ns = present_ns;
|
||||
g_timeline_deadline_ns = deadline_ns;
|
||||
g_timeline_period_ns = period_ns;
|
||||
pthread_mutex_unlock(&g_timeline_lock);
|
||||
}
|
||||
|
||||
static int64_t cadence_target(int64_t now, int64_t earliest, int64_t period) {
|
||||
const int64_t gap = now - g_cadence_seen_ns;
|
||||
g_cadence_seen_ns = now;
|
||||
if (gap <= 0 || gap > 8 * period) {
|
||||
g_cadence_gap_ns = 0;
|
||||
g_cadence_target_ns = earliest;
|
||||
return earliest;
|
||||
}
|
||||
g_cadence_gap_ns = g_cadence_gap_ns ? (g_cadence_gap_ns * 15 + gap) / 16 : gap;
|
||||
const int64_t steps = (g_cadence_gap_ns + period / 2) / period;
|
||||
const int64_t even = g_cadence_target_ns + steps * period;
|
||||
int64_t target = earliest;
|
||||
if (steps >= 1 && llabs(g_cadence_gap_ns - steps * period) < period / 8 &&
|
||||
even > earliest + period / 2 && even < earliest + steps * period + period / 2) {
|
||||
target = even;
|
||||
g_stat_aimed_even++;
|
||||
}
|
||||
g_cadence_target_ns = target;
|
||||
return target;
|
||||
}
|
||||
|
||||
static void apply_present_time(ASurfaceTransaction *tx, int game) {
|
||||
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;
|
||||
pthread_mutex_unlock(&g_timeline_lock);
|
||||
const int64_t now = now_ns();
|
||||
if (period <= 0 || now - deadline > 4 * period) return;
|
||||
int64_t ahead = now > deadline ? (now - deadline + period - 1) / period : -((deadline - now) / period);
|
||||
const int64_t slack = deadline + ahead * period - now;
|
||||
g_timeline_late = slack < (g_timeline_late ? period * 5 / 8 : period / 8);
|
||||
if (g_timeline_late) { ahead++; g_stat_aimed_later++; } else g_stat_aimed_next++;
|
||||
int64_t target = present + ahead * period;
|
||||
if (game && g_group_index > 0) {
|
||||
int64_t steps = (g_group_index * g_cadence_gap_ns / g_group_frames + period / 2) / period;
|
||||
if (steps < g_group_index) steps = g_group_index;
|
||||
if (target < g_cadence_target_ns + steps * period) target = g_cadence_target_ns + steps * period;
|
||||
} else if (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; }
|
||||
api.setDesiredPresentTime(tx, target - period / 2);
|
||||
}
|
||||
|
||||
static void on_complete(void *context, ASurfaceTransactionStats *stats) {
|
||||
struct complete_ctx *ctx = context;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
@@ -401,10 +464,22 @@ static void describe_handle(const struct droiddeck_native_handle *h, char *out,
|
||||
o += (size_t)snprintf(out + o, n - o, " %#x", (unsigned)h->data[h->numFds + i]);
|
||||
}
|
||||
|
||||
static int handle_fd(const struct droiddeck_native_handle *h, off_t need, int *which) {
|
||||
for (int i = 0; h && i < h->numFds; i++) {
|
||||
off_t sz = lseek(h->data[i], 0, SEEK_END);
|
||||
if (sz >= 0) lseek(h->data[i], 0, SEEK_SET);
|
||||
if (sz >= need) { if (which) *which = i; return h->data[i]; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sc_layer_ahb_fd(AHardwareBuffer *ahb, uint64_t need) {
|
||||
return load_api() == 0 ? handle_fd(api.getNativeHandle(ahb), (off_t)need, NULL) : -1;
|
||||
}
|
||||
|
||||
static int g_alloc_failed;
|
||||
|
||||
enum { TIER_UBWC, TIER_PLAIN, TIER_LINEAR };
|
||||
#define DROIDDECK_AHB_USAGE_VENDOR_UBWC (1ULL << 28)
|
||||
|
||||
static const char *tier_name(int tier) {
|
||||
return tier == TIER_UBWC ? "asked for UBWC" : tier == TIER_PLAIN ? "no UBWC request" : "linear by request (CPU bit)";
|
||||
@@ -419,7 +494,7 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm
|
||||
.format = fmt,
|
||||
.usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
|
||||
AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY |
|
||||
(tier == TIER_UBWC ? DROIDDECK_AHB_USAGE_VENDOR_UBWC : 0) |
|
||||
(tier == TIER_UBWC ? SC_LAYER_AHB_USAGE_VENDOR_UBWC : 0) |
|
||||
(tier == TIER_LINEAR ? AHARDWAREBUFFER_USAGE_CPU_READ_RARELY : 0)};
|
||||
AHardwareBuffer *ahb = NULL;
|
||||
if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) {
|
||||
@@ -459,13 +534,8 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm
|
||||
path = "AHardwareBuffer";
|
||||
img = vkp_image_import_ahb(ahb, info, sizeof(info));
|
||||
if (!img && tier == TIER_LINEAR) {
|
||||
const off_t need = (off_t)got.stride * 4 * h;
|
||||
int fd = -1, which = -1;
|
||||
for (int i = 0; nh && i < nh->numFds; i++) {
|
||||
off_t sz = lseek(nh->data[i], 0, SEEK_END);
|
||||
if (sz >= 0) lseek(nh->data[i], 0, SEEK_SET);
|
||||
if (sz >= need) { fd = nh->data[i]; which = i; break; }
|
||||
}
|
||||
int which = -1;
|
||||
int fd = handle_fd(nh, (off_t)got.stride * 4 * h, &which);
|
||||
if (fd < 0 && nh && nh->numFds > 0) { fd = nh->data[0]; which = 0; }
|
||||
mod = MOD_LINEAR;
|
||||
path = "linear dma-buf";
|
||||
@@ -506,16 +576,27 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int fence_signalled(int fd) {
|
||||
static int fence_wait(int fd, int timeout_ms) {
|
||||
struct pollfd p = {.fd = fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 0); } while (r < 0 && errno == EINTR);
|
||||
return r > 0;
|
||||
do { r = poll(&p, 1, timeout_ms); } while (r < 0 && errno == EINTR);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int fence_signalled(int fd) {
|
||||
return fence_wait(fd, 0) > 0;
|
||||
}
|
||||
|
||||
static void slot_keep_fence(struct slot *s, int fd) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
if (s->release_fd < 0) s->release_fd = fd; else close(fd);
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait_fd) {
|
||||
int idx = -1, pending = -1, fd = -1;
|
||||
*wait_fd = -1;
|
||||
g_alloc_failed = 0;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (int i = 0; i < l->pool_n; i++) {
|
||||
if (i == l->cur_slot || l->slots[i].busy) continue;
|
||||
@@ -535,15 +616,7 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait
|
||||
memset(s, 0, sizeof(*s)); s->release_fd = -1;
|
||||
}
|
||||
if (fd >= 0 && !vkp_can_wait_sync_fd()) {
|
||||
struct pollfd p = {.fd = fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
if (r == 0) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
if (s->release_fd < 0) s->release_fd = fd; else close(fd);
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return -1;
|
||||
}
|
||||
if (fence_wait(fd, 100) == 0) { slot_keep_fence(s, fd); return -1; }
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
@@ -558,6 +631,8 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait
|
||||
|
||||
int sc_layer_available(void) { return load_api() == 0; }
|
||||
|
||||
int sc_layer_queues(void) { return load_api() == 0 && api.setEnableBackPressure != NULL; }
|
||||
|
||||
void sc_layer_probe_dmabuf_fd(int fd) {
|
||||
static int done;
|
||||
if (done || fd < 0) return;
|
||||
@@ -595,9 +670,10 @@ static int ensure_sc(struct layer *l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int layer_geometry(int w, int h, int scene_w, int scene_h, int r[8]) {
|
||||
static int layer_geometry(int w, int h, int scene_w, int scene_h, const struct vkp_draw *draw, int r[8]) {
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
return vkp_map_rect(w, h, scene_w, scene_h, r) ? 1 : 0;
|
||||
if (draw) return vkp_map_draw(draw, r) ? 1 : 0;
|
||||
return vkp_map_rect(w, h, (const int[4]){0, 0, scene_w, scene_h}, r) ? 1 : 0;
|
||||
}
|
||||
|
||||
static ARect g_game_src, g_game_dst;
|
||||
@@ -757,6 +833,7 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d
|
||||
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);
|
||||
apply_geometry(tx, l, r);
|
||||
@@ -769,6 +846,7 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d
|
||||
pthread_mutex_lock(&g_lock);
|
||||
s->busy = 1;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
apply_present_time(tx, l == &g_layers[SC_LAYER_GAME]);
|
||||
api.txApply(tx);
|
||||
api.txDelete(tx);
|
||||
l->cur_slot = idx;
|
||||
@@ -799,11 +877,12 @@ unsigned sc_layer_drops_take(void) {
|
||||
}
|
||||
|
||||
int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token, int scene_w, int scene_h,
|
||||
const struct vkp_draw *draw,
|
||||
const struct droiddeck_color *color, uint32_t ahb_format) {
|
||||
struct layer *l = layer_of(SC_LAYER_GAME);
|
||||
int r[8];
|
||||
if (!ahb || !token || ensure_sc(l) != 0) goto unavailable;
|
||||
int g = layer_geometry(w, h, scene_w, scene_h, r);
|
||||
int g = layer_geometry(w, h, scene_w, scene_h, draw, r);
|
||||
if (g < 0) goto unavailable;
|
||||
if (g == 0) { if (acquire_fd >= 0) close(acquire_fd); sc_layer_hide(); return 1; }
|
||||
if (token == l->cur_token && l->shown && !l->recreate_pending) {
|
||||
@@ -821,6 +900,7 @@ int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, voi
|
||||
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);
|
||||
@@ -834,6 +914,7 @@ int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, voi
|
||||
l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f;
|
||||
return -1;
|
||||
}
|
||||
apply_present_time(tx, 1);
|
||||
api.txApply(tx);
|
||||
api.txDelete(tx);
|
||||
l->cur_slot = -1;
|
||||
@@ -848,12 +929,13 @@ unavailable:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct droiddeck_color *color) {
|
||||
int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw,
|
||||
const struct droiddeck_color *color) {
|
||||
struct layer *l = layer_of(SC_LAYER_GAME);
|
||||
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, r);
|
||||
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; }
|
||||
|
||||
@@ -879,10 +961,10 @@ int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int
|
||||
if (!draws || n <= 0 || ensure_sc(l) != 0) return -1;
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
if (vkp_pass_begin(scene_w, scene_h, draws, n, &rw, &rh) != 0) return -1;
|
||||
if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
if (!vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
int wait_fd;
|
||||
int idx = take_free_slot(l, rw, rh, AHB_RGBA8, &wait_fd);
|
||||
if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; }
|
||||
if (idx < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1;
|
||||
if (present_slot(l, idx, r, NULL, 0) != 0) return -1;
|
||||
if (!l->first_logged) {
|
||||
@@ -895,8 +977,97 @@ int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void slots_idle(struct layer *l, const int *idx, int from, int to) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (int i = from; i < to; i++) l->slots[idx[i]].busy = 0;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
static uint32_t g_hdr_pool_fmt = AHB_RGB10A2;
|
||||
|
||||
static int take_hdr_slot(struct layer *l, int w, int h, int *wait_fd) {
|
||||
int idx = take_free_slot(l, w, h, g_hdr_pool_fmt, wait_fd);
|
||||
if (idx < 0 && g_alloc_failed && g_hdr_pool_fmt == AHB_RGB10A2) {
|
||||
g_hdr_pool_fmt = AHB_RGBA8;
|
||||
droiddeck_log("color", "%s: this device will not make a 10-bit layer buffer (RGBA1010102): the HDR picture goes "
|
||||
"on 8-bit buffers instead (still tagged BT2020_PQ; less precision)", l->name);
|
||||
idx = take_free_slot(l, w, h, g_hdr_pool_fmt, wait_fd);
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const struct vkp_hdr_frame *hf,
|
||||
int scene_w, int scene_h, int composed, const struct droiddeck_color *color) {
|
||||
struct layer *l = layer_of(SC_LAYER_GAME);
|
||||
int rw = 0, rh = 0, r[8], idx[VKP_FG_MAX_GENERATIONS + 1], m = 0, first_fd = -1, have_fd = 0;
|
||||
struct vkp_image *dst[VKP_FG_MAX_GENERATIONS], *real = NULL;
|
||||
g_group_index = 0;
|
||||
g_group_frames = 1;
|
||||
if (!draws || n_draws <= 0 || ensure_sc(l) != 0) return -1;
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
const int deep = hf && !hf->tonemap;
|
||||
if (hf) composed = 1;
|
||||
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;
|
||||
const int mapped = vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r);
|
||||
if (!mapped) n = 0;
|
||||
if (composed) {
|
||||
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; }
|
||||
pthread_mutex_lock(&g_lock);
|
||||
l->slots[idx[VKP_FG_MAX_GENERATIONS]].busy = 1;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
real = l->slots[idx[VKP_FG_MAX_GENERATIONS]].img;
|
||||
have_fd = 1;
|
||||
}
|
||||
for (; m < n; m++) {
|
||||
int fd;
|
||||
idx[m] = take_free_slot(l, rw, rh, deep ? g_hdr_pool_fmt : AHB_RGBA8, &fd);
|
||||
if (idx[m] < 0) { log_drop(l); break; }
|
||||
if (have_fd && fd >= 0) {
|
||||
if (fence_wait(fd, 100) == 0) { slot_keep_fence(&l->slots[idx[m]], fd); log_drop(l); break; }
|
||||
close(fd);
|
||||
}
|
||||
pthread_mutex_lock(&g_lock);
|
||||
l->slots[idx[m]].busy = 1;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
dst[m] = l->slots[idx[m]].img;
|
||||
if (!have_fd) { first_fd = fd; have_fd = 1; }
|
||||
}
|
||||
if (vkp_pass_copy_generated(dst, m, real, first_fd) != 0) {
|
||||
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++) {
|
||||
if (present_slot(l, idx[k], r, color, 0) == 0) continue;
|
||||
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;
|
||||
g_group_frames = 1;
|
||||
return -1;
|
||||
}
|
||||
vkp_framegen_presented(m);
|
||||
if (real) {
|
||||
if (present_slot(l, idx[VKP_FG_MAX_GENERATIONS], r, color, 0) != 0) {
|
||||
slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
g_group_index = 0;
|
||||
g_group_frames = 1;
|
||||
return -1;
|
||||
}
|
||||
l->first_logged = 1;
|
||||
vkp_signal_first_frame();
|
||||
}
|
||||
if (hf && hf->color && hf->color->dataspace)
|
||||
droiddeck_color_frame_shown(hf->color, deep ? DROIDDECK_HDR_COMPOSED : DROIDDECK_HDR_TONEMAPPED,
|
||||
deep ? g_hdr_pool_fmt : AHB_RGBA8);
|
||||
return m;
|
||||
}
|
||||
|
||||
int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf,
|
||||
int scene_w, int scene_h, const struct droiddeck_color *color) {
|
||||
struct layer *l = layer_of(SC_LAYER_GAME);
|
||||
@@ -904,19 +1075,11 @@ int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct
|
||||
if (!draws || n <= 0 || !hf || ensure_sc(l) != 0) return -1;
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
if (vkp_pass_begin_hdr(scene_w, scene_h, draws, n, hf, &rw, &rh) != 0) return -1;
|
||||
if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
if (!vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
const int tm = hf->tonemap;
|
||||
const uint32_t fmt = tm ? AHB_RGBA8 : g_hdr_pool_fmt;
|
||||
g_alloc_failed = 0;
|
||||
int wait_fd;
|
||||
int idx = take_free_slot(l, rw, rh, fmt, &wait_fd);
|
||||
if (idx < 0 && g_alloc_failed && fmt == AHB_RGB10A2) {
|
||||
g_hdr_pool_fmt = AHB_RGBA8;
|
||||
droiddeck_log("color", "%s: this device will not make a 10-bit layer buffer (RGBA1010102): the HDR picture goes "
|
||||
"on 8-bit buffers instead (still tagged BT2020_PQ; less precision)", l->name);
|
||||
idx = take_free_slot(l, rw, rh, g_hdr_pool_fmt, &wait_fd);
|
||||
}
|
||||
if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; }
|
||||
int idx = tm ? take_free_slot(l, rw, rh, AHB_RGBA8, &wait_fd) : take_hdr_slot(l, rw, rh, &wait_fd);
|
||||
if (idx < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1;
|
||||
if (present_slot(l, idx, r, tm ? NULL : color, 0) != 0) return -1;
|
||||
if (color && color->dataspace)
|
||||
@@ -967,8 +1130,9 @@ int sc_layer_overlay_affordable(void) {
|
||||
if (want)
|
||||
droiddeck_log("layer", "overlay layer declined: this display rotates every layer %d° and the game "
|
||||
"layer is scaled %dx%d -> %dx%d, and on that combination a second layer drops the "
|
||||
"whole frame to GPU composition for the rest of the session (measured). The window "
|
||||
"above the game goes on the copy path instead - same picture, one blit.",
|
||||
"whole frame to GPU composition for the rest of the session (measured). A nested "
|
||||
"compositor is asked to compose its own overlays into the game picture; any other "
|
||||
"window above the game goes on the copy path instead.",
|
||||
deg, sr[0], sr[1], ds[0], ds[1]);
|
||||
else if (!first)
|
||||
droiddeck_log("layer", "overlay layer allowed again: the game layer is no longer both rotated and "
|
||||
@@ -1033,6 +1197,13 @@ void sc_layer_window_gone(void) {
|
||||
drain_and_free_pools();
|
||||
}
|
||||
|
||||
void sc_layer_aim_take(unsigned *next, unsigned *later, unsigned *even) {
|
||||
*next = g_stat_aimed_next;
|
||||
*later = g_stat_aimed_later;
|
||||
*even = g_stat_aimed_even;
|
||||
g_stat_aimed_next = g_stat_aimed_later = g_stat_aimed_even = 0;
|
||||
}
|
||||
|
||||
unsigned sc_layer_frames_take(void) {
|
||||
unsigned n = g_stat_layer_frames;
|
||||
g_stat_layer_frames = 0;
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
struct vkp_image;
|
||||
struct vkp_draw;
|
||||
struct droiddeck_color;
|
||||
struct vkp_hdr_frame;
|
||||
|
||||
enum sc_layer_id { SC_LAYER_GAME = 0, SC_LAYER_OVERLAY = 1, SC_LAYER_COUNT = 2 };
|
||||
|
||||
int sc_layer_available(void);
|
||||
#define SC_LAYER_AHB_USAGE_VENDOR_UBWC (1ULL << 28)
|
||||
int sc_layer_ahb_fd(AHardwareBuffer *ahb, uint64_t need);
|
||||
|
||||
void sc_layer_probe_dmabuf_fd(int fd);
|
||||
|
||||
@@ -18,21 +21,25 @@ int sc_layer_can_tag_hdr(void);
|
||||
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 droiddeck_color *color);
|
||||
int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw,
|
||||
const struct droiddeck_color *color);
|
||||
|
||||
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,
|
||||
int scene_w, int scene_h, int composed, const struct droiddeck_color *color);
|
||||
|
||||
struct vkp_hdr_frame;
|
||||
int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf,
|
||||
int scene_w, int scene_h, const struct droiddeck_color *color);
|
||||
|
||||
int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token,
|
||||
int scene_w, int scene_h, const struct droiddeck_color *color, uint32_t ahb_format);
|
||||
int scene_w, int scene_h, const struct vkp_draw *draw, const struct droiddeck_color *color, uint32_t ahb_format);
|
||||
|
||||
void sc_layer_set_frame_rate(float fps);
|
||||
|
||||
int sc_layer_overlay_affordable(void);
|
||||
|
||||
int sc_layer_queues(void);
|
||||
|
||||
int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent);
|
||||
|
||||
void sc_layer_hide(void);
|
||||
@@ -42,6 +49,8 @@ void sc_layer_hide_overlay(void);
|
||||
|
||||
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);
|
||||
unsigned sc_layer_frames_take(void);
|
||||
unsigned sc_layer_drops_take(void);
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef VK_LINEAR_DMABUF_H
|
||||
#define VK_LINEAR_DMABUF_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static inline int vkp_linear_dmabuf_through_buffer(int drm_modifiers, uint64_t modifier, int blit_dst) {
|
||||
return !drm_modifiers && modifier == 0 && !blit_dst;
|
||||
}
|
||||
|
||||
static inline int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) {
|
||||
return dmabuf && !staged;
|
||||
}
|
||||
|
||||
static inline VkPipelineStageFlags vkp_linear_dmabuf_readback_stage(int in_general) {
|
||||
return in_general ? VK_PIPELINE_STAGE_TRANSFER_BIT : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
}
|
||||
|
||||
static inline VkAccessFlags vkp_linear_dmabuf_readback_access(int in_general) {
|
||||
return in_general ? VK_ACCESS_TRANSFER_WRITE_BIT : 0;
|
||||
}
|
||||
|
||||
static inline uint32_t vkp_linear_dmabuf_texel_bytes(VkFormat fmt) {
|
||||
return fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? 8u : 4u;
|
||||
}
|
||||
|
||||
static inline VkDeviceSize vkp_linear_dmabuf_copy(VkFormat fmt, int w, int h, uint32_t stride, uint32_t offset,
|
||||
VkBufferImageCopy *copy) {
|
||||
const uint32_t texel = vkp_linear_dmabuf_texel_bytes(fmt);
|
||||
if (!copy || w <= 0 || h <= 0 || stride % texel || offset % texel || stride / texel < (uint32_t)w) return 0;
|
||||
*copy = (VkBufferImageCopy){
|
||||
.bufferOffset = offset,
|
||||
.bufferRowLength = stride / texel,
|
||||
.bufferImageHeight = (uint32_t)h,
|
||||
.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageExtent = {(uint32_t)w, (uint32_t)h, 1},
|
||||
};
|
||||
return (VkDeviceSize)offset + (VkDeviceSize)stride * (VkDeviceSize)(h - 1) + (VkDeviceSize)w * texel;
|
||||
}
|
||||
|
||||
static inline VkBufferMemoryBarrier vkp_linear_dmabuf_ownership(VkBuffer buffer, uint32_t queue_family,
|
||||
int acquire) {
|
||||
return (VkBufferMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.srcAccessMask = acquire ? 0 : VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.dstAccessMask = acquire ? VK_ACCESS_TRANSFER_READ_BIT : 0,
|
||||
.srcQueueFamilyIndex = acquire ? VK_QUEUE_FAMILY_FOREIGN_EXT : queue_family,
|
||||
.dstQueueFamilyIndex = acquire ? queue_family : VK_QUEUE_FAMILY_FOREIGN_EXT,
|
||||
.buffer = buffer,
|
||||
.offset = 0,
|
||||
.size = VK_WHOLE_SIZE,
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,8 @@
|
||||
X(EndCommandBuffer) X(ResetFences) X(QueueSubmit) X(QueuePresentKHR) X(WaitForFences) \
|
||||
X(QueueWaitIdle) X(GetMemoryFdPropertiesKHR) X(GetAndroidHardwareBufferPropertiesANDROID) \
|
||||
X(GetImageSubresourceLayout) X(MapMemory) X(UnmapMemory) X(CmdClearColorImage) \
|
||||
X(CreateBuffer) X(DestroyBuffer) X(GetBufferMemoryRequirements) X(BindBufferMemory) \
|
||||
X(CmdCopyBufferToImage) \
|
||||
\
|
||||
X(CreateShaderModule) X(DestroyShaderModule) X(CreatePipelineLayout) X(DestroyPipelineLayout) \
|
||||
X(CreateGraphicsPipelines) X(DestroyPipeline) X(CreateRenderPass) X(DestroyRenderPass) \
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "vk_present.h"
|
||||
#include "vk_loader.h"
|
||||
#include "vk_external_image_sync.h"
|
||||
#include "vk_linear_dmabuf.h"
|
||||
#include "sc_layer.h"
|
||||
#include "effects_chain.h"
|
||||
#include "cardboard.h"
|
||||
@@ -42,10 +43,15 @@ struct vkp_image {
|
||||
VkFormat fmt;
|
||||
int sampled;
|
||||
AHardwareBuffer *android_buffer;
|
||||
int staged;
|
||||
VkBuffer linear_buf;
|
||||
VkDeviceMemory linear_mem;
|
||||
VkBufferImageCopy linear_copy;
|
||||
};
|
||||
|
||||
static ANativeWindow *g_window;
|
||||
static int g_ahb_import;
|
||||
static int g_drm_modifiers;
|
||||
static char *g_driver_path, *g_library_name, *g_native_lib_dir;
|
||||
static int g_allow_driver_fallback;
|
||||
static int g_dev_state;
|
||||
@@ -628,6 +634,7 @@ static int dev_init(void) {
|
||||
if (has_ext(exts, ne, import_exts[i])) dev_exts[n_dev_exts++] = import_exts[i];
|
||||
else LOGE("present: driver MISSING %s (dmabuf import will fail)", import_exts[i]);
|
||||
}
|
||||
g_drm_modifiers = has_ext(exts, ne, "VK_EXT_image_drm_format_modifier");
|
||||
int want_hdr_md = 0;
|
||||
if (droiddeck_color_requested()) {
|
||||
want_hdr_md = has_ext(exts, ne, VK_EXT_HDR_METADATA_EXTENSION_NAME);
|
||||
@@ -1088,6 +1095,10 @@ struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t mo
|
||||
return vkp_image_import_dmabuf(fd, drm_format, modifier, w, h, stride, offset, 0);
|
||||
}
|
||||
|
||||
static int foreign_image(const struct vkp_image *img) {
|
||||
return vkp_linear_dmabuf_foreign_image(img->dmabuf, img->staged);
|
||||
}
|
||||
|
||||
/* Return client sources to FOREIGN after their final read. The consuming paths
|
||||
* wait for our fence before Wayland can release an ordinary dma-buf or an
|
||||
* android_wlegl AHardwareBuffer. Producer-fence synchronization is separate from
|
||||
@@ -1095,7 +1106,7 @@ struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t mo
|
||||
static void release_external_client_image(VkCommandBuffer cmd, struct vkp_image *img) {
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (!img || !vkp_external_client_barrier_pair(
|
||||
img->image, g_qfam, img->dmabuf, img->blit_dst, &pair))
|
||||
img->image, g_qfam, foreign_image(img), img->blit_dst, &pair))
|
||||
return;
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, NULL, 0, NULL, 1, &pair.release);
|
||||
@@ -1109,6 +1120,37 @@ static void release_external_client_draws(VkCommandBuffer cmd, const struct vkp_
|
||||
}
|
||||
}
|
||||
|
||||
static void stage_linear_dmabuf(VkCommandBuffer cmd, const struct vkp_image *img) {
|
||||
if (!img || !img->linear_buf) return;
|
||||
const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
VkBufferMemoryBarrier acquire = vkp_linear_dmabuf_ownership(img->linear_buf, g_qfam, 1);
|
||||
VkImageMemoryBarrier write = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = img->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
|
||||
0, NULL, 1, &acquire, 1, &write);
|
||||
g_vk.CmdCopyBufferToImage(cmd, img->linear_buf, img->image, VK_IMAGE_LAYOUT_GENERAL, 1, &img->linear_copy);
|
||||
VkBufferMemoryBarrier release = vkp_linear_dmabuf_ownership(img->linear_buf, g_qfam, 0);
|
||||
VkImageMemoryBarrier read = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = img->image, .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
|
||||
0, NULL, 1, &release, 1, &read);
|
||||
}
|
||||
|
||||
static void stage_linear_dmabufs(VkCommandBuffer cmd, const struct vkp_draw *draws, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
int seen = 0;
|
||||
for (int j = 0; j < i; j++) if (draws[j].img == draws[i].img) { seen = 1; break; }
|
||||
if (!seen) stage_linear_dmabuf(cmd, draws[i].img);
|
||||
}
|
||||
}
|
||||
|
||||
int vkp_image_is_dmabuf(const struct vkp_image *img) {
|
||||
return img && vkp_is_external_client_image(img->dmabuf, img->blit_dst);
|
||||
}
|
||||
@@ -1181,6 +1223,102 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int optimal_sampled(VkFormat fmt) {
|
||||
if (!g_vk.GetPhysicalDeviceFormatProperties2) return 0;
|
||||
VkFormatProperties2 fp = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
|
||||
g_vk.GetPhysicalDeviceFormatProperties2(g_pd, fmt, &fp);
|
||||
const VkFormatFeatureFlags need = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
return (fp.formatProperties.optimalTilingFeatures & need) == need;
|
||||
}
|
||||
|
||||
static void destroy_image_objects(struct vkp_image *img) {
|
||||
if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL);
|
||||
if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL);
|
||||
if (img->linear_buf) g_vk.DestroyBuffer(g_dev, img->linear_buf, NULL);
|
||||
if (img->linear_mem) g_vk.FreeMemory(g_dev, img->linear_mem, NULL);
|
||||
img->image = VK_NULL_HANDLE; img->mem = VK_NULL_HANDLE;
|
||||
img->linear_buf = VK_NULL_HANDLE; img->linear_mem = VK_NULL_HANDLE;
|
||||
img->staged = 0; img->in_general = 0;
|
||||
}
|
||||
|
||||
static int import_linear_dmabuf(struct vkp_image *img, int fd, const VkBufferImageCopy *copy, VkDeviceSize need) {
|
||||
int dupfd = dup(fd);
|
||||
if (dupfd < 0) return -1;
|
||||
VkDeviceSize size = need;
|
||||
off_t end = lseek(dupfd, 0, SEEK_END);
|
||||
if (end > 0 && (VkDeviceSize)end >= need) size = (VkDeviceSize)end;
|
||||
lseek(dupfd, 0, SEEK_SET);
|
||||
if (end > 0 && (VkDeviceSize)end < need) {
|
||||
LOGE("dmabuf: the linear %dx%d buffer holds %lld bytes, its row pitch needs %llu", img->w, img->h,
|
||||
(long long)end, (unsigned long long)need);
|
||||
close(dupfd);
|
||||
return -1;
|
||||
}
|
||||
VkExternalMemoryBufferCreateInfo ext = {
|
||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
|
||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT};
|
||||
VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .pNext = &ext, .size = size,
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
||||
VkResult r = g_vk.CreateBuffer(g_dev, &bci, NULL, &img->linear_buf);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
uint32_t allowed = 0xffffffff;
|
||||
if (g_vk.GetMemoryFdPropertiesKHR) {
|
||||
VkMemoryFdPropertiesKHR fp = {.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR};
|
||||
if (g_vk.GetMemoryFdPropertiesKHR(g_dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
|
||||
dupfd, &fp) == VK_SUCCESS)
|
||||
allowed = fp.memoryTypeBits;
|
||||
}
|
||||
VkMemoryRequirements breq;
|
||||
g_vk.GetBufferMemoryRequirements(g_dev, img->linear_buf, &breq);
|
||||
int bidx = memory_type(breq.memoryTypeBits & allowed, 0);
|
||||
r = VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
if (bidx < 0) goto fail;
|
||||
VkImportMemoryFdInfoKHR imp = {.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
|
||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, .fd = dupfd};
|
||||
VkMemoryDedicatedAllocateInfo ded = {.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
|
||||
.pNext = &imp, .buffer = img->linear_buf};
|
||||
VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &ded,
|
||||
.allocationSize = breq.size, .memoryTypeIndex = (uint32_t)bidx};
|
||||
r = g_vk.AllocateMemory(g_dev, &mai, NULL, &img->linear_mem);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
dupfd = -1;
|
||||
r = g_vk.BindBufferMemory(g_dev, img->linear_buf, img->linear_mem, 0);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
|
||||
VkImageCreateInfo ici = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, .format = img->fmt,
|
||||
.extent = {(uint32_t)img->w, (uint32_t)img->h, 1}, .mipLevels = 1, .arrayLayers = 1,
|
||||
.samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
|
||||
(img->sampled ? VK_IMAGE_USAGE_SAMPLED_BIT : 0),
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
|
||||
r = g_vk.CreateImage(g_dev, &ici, NULL, &img->image);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
VkMemoryRequirements ireq;
|
||||
g_vk.GetImageMemoryRequirements(g_dev, img->image, &ireq);
|
||||
int iidx = memory_type(ireq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||
if (iidx < 0) iidx = memory_type(ireq.memoryTypeBits, 0);
|
||||
r = VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
if (iidx < 0) goto fail;
|
||||
VkMemoryAllocateInfo iai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = ireq.size, .memoryTypeIndex = (uint32_t)iidx};
|
||||
r = g_vk.AllocateMemory(g_dev, &iai, NULL, &img->mem);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
r = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
img->linear_copy = *copy;
|
||||
img->staged = 1;
|
||||
img->in_general = 1;
|
||||
return 0;
|
||||
fail:
|
||||
LOGE("dmabuf: reading the linear %dx%d buffer at its row pitch failed (%s); importing it as an image",
|
||||
img->w, img->h, vk_result_name(r));
|
||||
if (dupfd >= 0) close(dupfd);
|
||||
destroy_image_objects(img);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h,
|
||||
uint32_t stride, uint32_t offset, int as_blit_dst) {
|
||||
if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL;
|
||||
@@ -1190,9 +1328,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
if (!img) return NULL;
|
||||
img->w = w; img->h = h; img->dmabuf = 1; img->blit_dst = as_blit_dst ? 1 : 0;
|
||||
img->fmt = drm_to_vk(drm_format);
|
||||
const int through_buffer = vkp_linear_dmabuf_through_buffer(g_drm_modifiers, modifier, as_blit_dst);
|
||||
const VkImageUsageFlags sampled_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
img->sampled = !as_blit_dst && g_vk.GetPhysicalDeviceImageFormatProperties2 &&
|
||||
modifier_importable(img->fmt, modifier, sampled_usage);
|
||||
const int modifier_sampled = !as_blit_dst && g_drm_modifiers && g_vk.GetPhysicalDeviceImageFormatProperties2 &&
|
||||
modifier_importable(img->fmt, modifier, sampled_usage);
|
||||
img->sampled = through_buffer ? optimal_sampled(img->fmt) : modifier_sampled;
|
||||
/* Each new format/modifier/size a client hands over, once, for the graphics report: a colour
|
||||
* or swizzle mismatch on a non-Adreno driver shows up as the pair it arrived as. */
|
||||
{
|
||||
@@ -1203,10 +1343,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
if (seen[i].fmt == drm_format && seen[i].mod == modifier && seen[i].w == w && seen[i].h == h) known = 1;
|
||||
if (!known && nseen < 32) {
|
||||
seen[nseen].fmt = drm_format; seen[nseen].mod = modifier; seen[nseen].w = w; seen[nseen].h = h; nseen++;
|
||||
droiddeck_log("gpu", "dmabuf import: %c%c%c%c %s %dx%d stride %u offset %u -> vk format %d, %s%s",
|
||||
droiddeck_log("gpu", "dmabuf import: %c%c%c%c %s %dx%d stride %u offset %u -> vk format %d, %s%s%s",
|
||||
drm_format & 0xff, (drm_format >> 8) & 0xff, (drm_format >> 16) & 0xff, (drm_format >> 24) & 0xff,
|
||||
vkp_modifier_name(modifier), w, h, stride, offset, (int)img->fmt,
|
||||
img->sampled ? "sampled" : "copied", as_blit_dst ? ", blit target" : "");
|
||||
img->sampled ? "sampled" : "copied", as_blit_dst ? ", blit target" : "",
|
||||
through_buffer ? ", trying a copy at its row pitch (no VK_EXT_image_drm_format_modifier)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,6 +1355,12 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
* vkCreateImage, which left the whole window unshown (David Cimo). One packed, 64-byte aligned
|
||||
* row is what a linear buffer that small holds. */
|
||||
if (stride == 0 && modifier == 0) stride = ((uint32_t)w * 4 + 63) & ~63u;
|
||||
if (through_buffer) {
|
||||
VkBufferImageCopy linear_copy;
|
||||
const VkDeviceSize linear_size = vkp_linear_dmabuf_copy(img->fmt, w, h, stride, offset, &linear_copy);
|
||||
if (linear_size && import_linear_dmabuf(img, fd, &linear_copy, linear_size) == 0) return img;
|
||||
img->sampled = modifier_sampled;
|
||||
}
|
||||
VkSubresourceLayout plane = {.offset = offset, .rowPitch = stride};
|
||||
VkImageDrmFormatModifierExplicitCreateInfoEXT modInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
|
||||
@@ -1501,8 +1648,7 @@ void vkp_image_destroy(struct vkp_image *img) {
|
||||
if (g_dev) {
|
||||
blendp_forget_image(img->image);
|
||||
if (img->map) g_vk.UnmapMemory(g_dev, img->mem);
|
||||
if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL);
|
||||
if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL);
|
||||
destroy_image_objects(img);
|
||||
}
|
||||
if (img->android_buffer) AHardwareBuffer_release(img->android_buffer);
|
||||
free(img);
|
||||
@@ -1600,7 +1746,7 @@ static void effects_source_note(int scene_w, int scene_h, const struct vkp_draw
|
||||
static void record_draw(VkCommandBuffer cmd, const struct vkp_draw *d, const VkImageBlit *blit, VkImage target,
|
||||
VkFormat target_fmt, int target_w, int target_h, VkFilter filter) {
|
||||
const struct vkp_image *im = d->img;
|
||||
const int external_client = vkp_image_is_dmabuf(im);
|
||||
const int external_client = vkp_is_external_client_image(foreign_image(im), im->blit_dst);
|
||||
if (d->blend && im->sampled &&
|
||||
blendp_draw(cmd, im->image, im->fmt, im->w, im->h, !external_client,
|
||||
target, target_fmt, target_w, target_h,
|
||||
@@ -1734,6 +1880,11 @@ static int compose_hdr(VkCommandBuffer cmd, const struct vkp_draw *draws, int n,
|
||||
|
||||
struct hdrc_params p = {.mode = mode, .sdr_white_nits = droiddeck_color_sdr_white(),
|
||||
.peak_nits = hf->peak_nits > 0.0f ? hf->peak_nits : 1000.0f};
|
||||
if (hf->convert) {
|
||||
p.conv_linear = hf->convert->convert == 2;
|
||||
p.conv_gain = hf->convert->gain;
|
||||
memcpy(p.conv, hf->convert->to2020, sizeof(p.conv));
|
||||
}
|
||||
int lowest_hdr = -1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
VkImageBlit blit;
|
||||
@@ -1750,6 +1901,7 @@ static int compose_hdr(VkCommandBuffer cmd, const struct vkp_draw *draws, int n,
|
||||
p.rects[p.count][0] = (float)blit.dstOffsets[0].x; p.rects[p.count][1] = (float)blit.dstOffsets[0].y;
|
||||
p.rects[p.count][2] = (float)blit.dstOffsets[1].x; p.rects[p.count][3] = (float)blit.dstOffsets[1].y;
|
||||
if (hf->is_hdr[i]) p.hdr_mask |= 1u << p.count;
|
||||
if (hf->is_hdr[i] == 2 && hf->convert) p.conv_mask |= 1u << p.count;
|
||||
p.count++;
|
||||
}
|
||||
if (i >= lowest_hdr && !truncated_said) {
|
||||
@@ -2084,6 +2236,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
blendp_begin_frame();
|
||||
stage_linear_dmabufs(cmd, draws, n);
|
||||
VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
|
||||
VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars));
|
||||
@@ -2101,7 +2254,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
if (seen || !im) continue;
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (vkp_external_client_barrier_pair(
|
||||
im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) {
|
||||
im->image, g_qfam, foreign_image(im), im->blit_dst, &pair)) {
|
||||
bars[nb++] = pair.acquire;
|
||||
} else if (!im->blit_dst && !im->in_general) {
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
@@ -2353,9 +2506,9 @@ int vkp_update_map(int scene_w, int scene_h) {
|
||||
return g_map.valid ? 0 : -1;
|
||||
}
|
||||
|
||||
int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]) {
|
||||
int vkp_map_rect(int img_w, int img_h, const int dst[4], int out[8]) {
|
||||
struct vkp_image tmp = {.w = img_w, .h = img_h};
|
||||
struct vkp_draw d = {&tmp, 0, 0, (float)img_w, (float)img_h, 0, 0, scene_w, scene_h};
|
||||
struct vkp_draw d = {&tmp, 0, 0, (float)img_w, (float)img_h, dst[0], dst[1], dst[2], dst[3]};
|
||||
return vkp_map_draw(&d, out);
|
||||
}
|
||||
|
||||
@@ -2383,9 +2536,10 @@ 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, src->dmabuf, src->blit_dst, &src_pair);
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq[2] = {
|
||||
src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
@@ -2489,22 +2643,26 @@ int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px) {
|
||||
VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
stage_linear_dmabuf(cmd, src);
|
||||
struct vkp_external_client_barrier_pair src_pair;
|
||||
const int src_external = vkp_external_client_barrier_pair(
|
||||
src->image, g_qfam, src->dmabuf, src->blit_dst, &src_pair);
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq[2] = {
|
||||
src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : 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},
|
||||
.image = src->image, .subresourceRange = range,
|
||||
.srcAccessMask = vkp_linear_dmabuf_readback_access(src->in_general),
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT},
|
||||
{.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_rb->image, .subresourceRange = range,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, 2, acq);
|
||||
g_vk.CmdPipelineBarrier(cmd, vkp_linear_dmabuf_readback_stage(src->in_general),
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 2, acq);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {src->w, src->h, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
@@ -2551,24 +2709,33 @@ static struct {
|
||||
int active;
|
||||
VkImage result;
|
||||
int rw, rh;
|
||||
int ngen;
|
||||
VkImage gens[VKP_FG_MAX_GENERATIONS];
|
||||
} g_pass;
|
||||
|
||||
static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *rw, int *rh);
|
||||
const struct vkp_hdr_frame *hf, int generate, int *rw, int *rh);
|
||||
|
||||
int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh) {
|
||||
return pass_begin_impl(scene_w, scene_h, draws, n, NULL, rw, rh);
|
||||
return pass_begin_impl(scene_w, scene_h, draws, n, NULL, 0, rw, rh);
|
||||
}
|
||||
|
||||
int vkp_pass_begin_generate(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *rw, int *rh) {
|
||||
if (pass_begin_impl(scene_w, scene_h, draws, n, hf, 1, rw, rh) != 0) return -1;
|
||||
return g_pass.ngen;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (!hf) return -1;
|
||||
return pass_begin_impl(scene_w, scene_h, draws, n, hf, rw, rh);
|
||||
return pass_begin_impl(scene_w, scene_h, draws, n, hf, 0, rw, rh);
|
||||
}
|
||||
|
||||
static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *rw, int *rh) {
|
||||
const struct vkp_hdr_frame *hf, int generate, int *rw, int *rh) {
|
||||
if (g_pass.active) vkp_pass_abort();
|
||||
g_pass.ngen = 0;
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
int input_w = scene_w, input_h = scene_h;
|
||||
int pass_n = n, overlay_start = n;
|
||||
@@ -2588,13 +2755,31 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
effects_source_note(scene_w, scene_h, draws, n, input_w, input_h,
|
||||
(int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f));
|
||||
}
|
||||
if (hf) {
|
||||
const int deep = hf && generate && !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 |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||
"HDR frame generation (scene)") == 0;
|
||||
const int narrow = hf && generate && !deep;
|
||||
if (hf && !deep && !narrow) {
|
||||
if (ensure_img(&g_hdrscene, scene_w, scene_h, HDR_FMT,
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||
"HDR composition (picture)") != 0)
|
||||
return -1;
|
||||
} else if (ensure_scene_image(input_w, input_h) != 0) return -1;
|
||||
} else if (!deep && ensure_scene_image(input_w, input_h) != 0) return -1;
|
||||
const VkFormat scene_fmt = deep ? FG_HDR_FMT : narrow || !hf ? SCENE_FMT : HDR_FMT;
|
||||
if (hf && generate) {
|
||||
static int said = -1;
|
||||
if (said != deep + 2 * hf->tonemap) {
|
||||
said = deep + 2 * hf->tonemap;
|
||||
droiddeck_log("color", hf->tonemap
|
||||
? "frame generation runs on the tone-mapped picture in 8 bits, onto the game's display layer"
|
||||
: deep ? "frame generation runs on the HDR picture in FP16 (RGBA16F), onto the game's display layer"
|
||||
: "frame generation runs on the HDR picture in 8 bits (the engine cannot take FP16 here), onto "
|
||||
"the game's display layer: banding possible in smooth gradients");
|
||||
}
|
||||
}
|
||||
|
||||
VkCommandBuffer cmd = g_cmds[0];
|
||||
g_vk.ResetCommandBuffer(cmd, 0);
|
||||
@@ -2602,12 +2787,13 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
blendp_begin_frame();
|
||||
stage_linear_dmabufs(cmd, draws, n);
|
||||
VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
|
||||
VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars));
|
||||
if (!bars) { g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
int nb = 0;
|
||||
VkImage scene_img = hf ? g_hdrscene.img : g_scene.img;
|
||||
VkImage scene_img = deep ? g_fgscene.img : narrow || !hf ? g_scene.img : g_hdrscene.img;
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
@@ -2620,7 +2806,7 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
if (seen || !im) continue;
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (vkp_external_client_barrier_pair(
|
||||
im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) {
|
||||
im->image, g_qfam, foreign_image(im), im->blit_dst, &pair)) {
|
||||
bars[nb++] = pair.acquire;
|
||||
} else if (!im->blit_dst && !im->in_general) {
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
@@ -2638,12 +2824,12 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
free(bars);
|
||||
|
||||
if (hf) {
|
||||
if (compose_hdr(cmd, draws, n, hf, scene_w, scene_h, g_hdrscene.img, HDR_FMT,
|
||||
if (compose_hdr(cmd, draws, n, hf, scene_w, scene_h, scene_img, scene_fmt,
|
||||
hf->tonemap ? HDRC_OUT_SDR : HDRC_OUT_PQ) != 0) {
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
return -1;
|
||||
}
|
||||
if (vkp_effects_active()) vkp_effects_set_formats(HDR_FMT, HDR_FMT);
|
||||
if (vkp_effects_active()) vkp_effects_set_formats(scene_fmt, scene_fmt);
|
||||
} else {
|
||||
VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}};
|
||||
g_vk.CmdClearColorImage(cmd, g_scene.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range);
|
||||
@@ -2662,24 +2848,42 @@ 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);
|
||||
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);
|
||||
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);
|
||||
if (generate) {
|
||||
VkImageMemoryBarrier b = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = g_pass.result, .subresourceRange = range,
|
||||
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT};
|
||||
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);
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) {
|
||||
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; }
|
||||
g_pass.active = 0;
|
||||
if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
VkCommandBuffer cmd = g_cmds[0];
|
||||
if (!dst || !dst->blit_dst) {
|
||||
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);
|
||||
return -1;
|
||||
@@ -2688,27 +2892,30 @@ int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) {
|
||||
if (gpu_wait < 0) { g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
|
||||
VkImageMemoryBarrier acq = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT,
|
||||
.dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &acq);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}};
|
||||
g_vk.CmdBlitImage(cmd, g_pass.result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst->image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit,
|
||||
(g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
VkImageMemoryBarrier rel = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &rel);
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct vkp_image *dst = dsts[i];
|
||||
VkImageMemoryBarrier acq = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT,
|
||||
.dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &acq);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}};
|
||||
g_vk.CmdBlitImage(cmd, srcs[i], src_layout, dst->image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit,
|
||||
(g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
VkImageMemoryBarrier rel = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &rel);
|
||||
}
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
|
||||
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
@@ -2728,6 +2935,19 @@ int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) {
|
||||
return pass_finish(&g_pass.result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, &dst, 1, wait_fd);
|
||||
}
|
||||
|
||||
int vkp_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_image *real, int wait_fd) {
|
||||
VkImage srcs[VKP_FG_MAX_GENERATIONS + 1];
|
||||
struct vkp_image *all[VKP_FG_MAX_GENERATIONS + 1];
|
||||
if (n > g_pass.ngen) n = g_pass.ngen;
|
||||
for (int i = 0; i < n; i++) { srcs[i] = g_pass.gens[i]; all[i] = dsts[i]; }
|
||||
if (real) { srcs[n] = g_pass.result; all[n] = real; }
|
||||
return pass_finish(srcs, VK_IMAGE_LAYOUT_GENERAL, all, n + (real ? 1 : 0), wait_fd);
|
||||
}
|
||||
|
||||
void vkp_pass_abort(void) {
|
||||
if (!g_pass.active) return;
|
||||
g_pass.active = 0;
|
||||
|
||||
@@ -96,6 +96,7 @@ struct vkp_hdr_frame {
|
||||
float peak_nits;
|
||||
int tonemap;
|
||||
const struct droiddeck_color *color;
|
||||
const struct droiddeck_color *convert;
|
||||
};
|
||||
int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *how);
|
||||
@@ -106,7 +107,7 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd);
|
||||
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]);
|
||||
int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]);
|
||||
int vkp_map_rect(int img_w, int img_h, const int dst[4], int out[8]);
|
||||
int vkp_surface_rotation_degrees(void);
|
||||
|
||||
ANativeWindow *vkp_window(void);
|
||||
@@ -114,6 +115,9 @@ void vkp_signal_first_frame(void);
|
||||
|
||||
int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh);
|
||||
int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd);
|
||||
int vkp_pass_begin_generate(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_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_image *real, int wait_fd);
|
||||
void vkp_pass_abort(void);
|
||||
|
||||
void droiddeck_log(const char *tag, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
@@ -34,11 +34,13 @@ extern int droiddeck_cursor_input_pos(int *x, int *y);
|
||||
extern void droiddeck_wayland_send_scene_input(int type, int a, int b);
|
||||
extern void droiddeck_wayland_set_cursor_composite(int on);
|
||||
extern void droiddeck_wayland_vsync(int64_t frame_time_ns);
|
||||
extern void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns);
|
||||
extern void droiddeck_stream_set(int on);
|
||||
extern void droiddeck_stream_frame(AHardwareBuffer *ahb);
|
||||
extern unsigned droiddeck_stream_frames(void);
|
||||
extern void droiddeck_wayland_output_resized(void);
|
||||
extern void droiddeck_wayland_set_output_refresh_rate(int mhz);
|
||||
extern void droiddeck_wayland_set_panel_rates(const int *rates, int count);
|
||||
extern volatile int g_fps_limit;
|
||||
extern volatile int g_release_unpaced;
|
||||
extern volatile int g_render_on_commit;
|
||||
@@ -48,6 +50,8 @@ extern volatile int g_hide_shell;
|
||||
extern volatile int g_zero_copy;
|
||||
extern volatile unsigned g_zero_copy_last;
|
||||
extern volatile int g_ubwc;
|
||||
extern volatile int g_display_buffer_driver;
|
||||
void droiddeck_dmabuf_formats_stale(void);
|
||||
extern volatile int g_no_render_node;
|
||||
extern volatile int g_output_w, g_output_h;
|
||||
|
||||
@@ -63,6 +67,9 @@ static jmethodID g_on_game_program;
|
||||
static jmethodID g_on_pointer_lock;
|
||||
static jmethodID g_on_clipboard;
|
||||
static jmethodID g_on_text_input;
|
||||
static jmethodID g_on_overlay_planes;
|
||||
static jmethodID g_on_refresh_target;
|
||||
static jmethodID g_on_content_rate;
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
(void)reserved;
|
||||
@@ -84,6 +91,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
g_on_clipboard = (*env)->GetStaticMethodID(env, g_compositor_cls, "onClipboardText", "([B)V");
|
||||
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");
|
||||
g_on_refresh_target = (*env)->GetStaticMethodID(env, g_compositor_cls, "onRefreshTarget", "(II)V");
|
||||
g_on_content_rate = (*env)->GetStaticMethodID(env, g_compositor_cls, "onContentRate", "(I)V");
|
||||
}
|
||||
}
|
||||
return JNI_VERSION_1_6;
|
||||
@@ -144,6 +154,27 @@ void droiddeck_on_game_frame(void) {
|
||||
if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
void droiddeck_on_refresh_target(int refresh, int frame_rate) {
|
||||
JNIEnv *env;
|
||||
if (!g_compositor_cls || !g_on_refresh_target || !(env = thread_env())) return;
|
||||
(*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_refresh_target, (jint)refresh, (jint)frame_rate);
|
||||
if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
void droiddeck_on_content_rate(int fps) {
|
||||
JNIEnv *env;
|
||||
if (!g_compositor_cls || !g_on_content_rate || !(env = thread_env())) return;
|
||||
(*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_content_rate, (jint)fps);
|
||||
if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
void droiddeck_on_overlay_planes(int planes) {
|
||||
JNIEnv *env;
|
||||
if (!g_compositor_cls || !g_on_overlay_planes || !(env = thread_env())) return;
|
||||
(*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_overlay_planes, (jint)planes);
|
||||
if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
void droiddeck_on_pointer_lock(int locked, int x, int y) {
|
||||
JNIEnv *env;
|
||||
if (!g_compositor_cls || !g_on_pointer_lock || !(env = thread_env())) return;
|
||||
@@ -365,6 +396,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeVsync(JNIEnv *env, j
|
||||
droiddeck_wayland_vsync((int64_t)frameTimeNanos);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeFrameTimeline(JNIEnv *env, jclass clazz, jlong presentNanos,
|
||||
jlong deadlineNanos, jlong periodNanos) {
|
||||
sc_layer_frame_timeline((int64_t)presentNanos, (int64_t)deadlineNanos, (int64_t)periodNanos);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetClockControl(JNIEnv *env, jclass clazz, jstring path) {
|
||||
const char *value = path ? (*env)->GetStringUTFChars(env, path, NULL) : NULL;
|
||||
@@ -380,11 +417,18 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetHideShell(JNIEnv
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetZeroCopy(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
int live = droiddeck_get_display() != NULL;
|
||||
if (!live) g_zero_copy = on ? 1 : 0;
|
||||
if (!live) { g_zero_copy = on ? 1 : 0; droiddeck_dmabuf_formats_stale(); }
|
||||
droiddeck_host_zero_copy(on ? 1 : 0, live);
|
||||
__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_nativeSetDisplayBufferDriver(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
g_display_buffer_driver = on ? 1 : 0;
|
||||
droiddeck_dmabuf_formats_stale();
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "session driver %s for display buffers", on ? "asks" : "does not ask");
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeZeroCopyLastFrameAgeMs(JNIEnv *env, jclass clazz) {
|
||||
return (jint)ahb_swapchain_last_frame_age_ms();
|
||||
@@ -418,6 +462,16 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetOutputRefreshRate
|
||||
droiddeck_wayland_set_output_refresh_rate(hz > 1.0f ? (int)(hz * 1000.0f + 0.5f) : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetPanelRates(JNIEnv *env, jclass clazz, jintArray rates) {
|
||||
(void)clazz;
|
||||
jint values[16];
|
||||
jsize count = rates ? (*env)->GetArrayLength(env, rates) : 0;
|
||||
if (count > 16) count = 16;
|
||||
if (count > 0) (*env)->GetIntArrayRegion(env, rates, 0, count, values);
|
||||
droiddeck_wayland_set_panel_rates((const int *)values, (int)count);
|
||||
}
|
||||
|
||||
extern void vkp_reset_first_frame(void);
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeResetFirstFrame(JNIEnv *env, jclass clazz) {
|
||||
|
||||
@@ -84,15 +84,18 @@ static struct {
|
||||
static _Atomic int g_gate = -1;
|
||||
static char g_gate_why[320];
|
||||
static _Atomic int g_output_on = 1;
|
||||
static _Atomic int g_output_wanted = 1;
|
||||
static pthread_mutex_t g_output_mu = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void droiddeck_color_set_request(int mode, const char *source, int dxvk_hdr, int zero_copy_forced) {
|
||||
pthread_mutex_lock(&g_mu);
|
||||
g_req.mode = mode < 0 ? 0 : mode > 2 ? 2 : mode;
|
||||
g_req.mode = mode < 0 ? 0 : mode > 3 ? 3 : mode;
|
||||
snprintf(g_req.source, sizeof(g_req.source), "%s", source ? source : "environment");
|
||||
g_req.dxvk_hdr = dxvk_hdr ? 1 : 0;
|
||||
g_req.zero_copy_forced = zero_copy_forced ? 1 : 0;
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
atomic_store(&g_output_on, 1);
|
||||
atomic_store(&g_output_wanted, 1);
|
||||
}
|
||||
|
||||
void droiddeck_color_set_display(int id, const char *name, const char *formats, int hdr10, float max_lum,
|
||||
@@ -610,11 +613,23 @@ int droiddeck_color_tonemapped_on_screen(void) {
|
||||
|
||||
void droiddeck_color_set_output(int on) {
|
||||
on = on ? 1 : 0;
|
||||
if (atomic_load(&g_gate) != 1) {
|
||||
droiddeck_log(TAG, "HDR output switch (%s) ignored: HDR is not open in this session", on ? "on" : "off");
|
||||
pthread_mutex_lock(&g_mu);
|
||||
const int tonemap_only = g_req.mode == 3;
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
pthread_mutex_lock(&g_output_mu);
|
||||
atomic_store(&g_output_wanted, on);
|
||||
const int gate = atomic_load(&g_gate);
|
||||
const int changed = gate == 1 && !(on && tonemap_only) && atomic_exchange(&g_output_on, on) != on;
|
||||
pthread_mutex_unlock(&g_output_mu);
|
||||
if (gate != 1) {
|
||||
if (gate == 0) droiddeck_log(TAG, "HDR output switch (%s) ignored: HDR is not open in this session", on ? "on" : "off");
|
||||
return;
|
||||
}
|
||||
if (atomic_exchange(&g_output_on, on) == on) return;
|
||||
if (on && tonemap_only) {
|
||||
droiddeck_log(TAG, "HDR output switch (on) ignored: this display cannot show HDR10, HDR frames stay tone-mapped");
|
||||
return;
|
||||
}
|
||||
if (!changed) return;
|
||||
char who[160];
|
||||
int age = droiddeck_color_last_frame_age_ms(), tm = droiddeck_color_tonemapped_on_screen();
|
||||
pthread_mutex_lock(&g_mu);
|
||||
@@ -658,6 +673,8 @@ static void desc_unref(struct cm_desc *d) { if (d && --d->refs <= 0) free(d); }
|
||||
|
||||
struct cm_params {
|
||||
uint32_t tf, primaries;
|
||||
int has_prim; int32_t prim[8];
|
||||
int has_lum; uint32_t lum_ref;
|
||||
int has_mprim; int32_t mprim[8];
|
||||
int has_mlum; uint32_t mlum_min, mlum_max;
|
||||
int has_cll; uint32_t cll;
|
||||
@@ -730,9 +747,83 @@ static void make_output_description(struct wl_client *c, struct wl_resource *par
|
||||
droiddeck_client_name(c), what, col->text);
|
||||
}
|
||||
|
||||
static const float BT709_XY[8] = {0.64f, 0.33f, 0.30f, 0.60f, 0.15f, 0.06f, 0.3127f, 0.3290f};
|
||||
static const float BT2020_XY[8] = {0.708f, 0.292f, 0.170f, 0.797f, 0.131f, 0.046f, 0.3127f, 0.3290f};
|
||||
|
||||
static void mat_mul(const double a[9], const double b[9], double out[9]) {
|
||||
double m[9];
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
m[3 * i + j] = a[3 * i] * b[j] + a[3 * i + 1] * b[3 + j] + a[3 * i + 2] * b[6 + j];
|
||||
memcpy(out, m, sizeof(m));
|
||||
}
|
||||
|
||||
static int mat_invert(const double m[9], double out[9]) {
|
||||
const double det = m[0] * (m[4] * m[8] - m[5] * m[7]) - m[1] * (m[3] * m[8] - m[5] * m[6]) +
|
||||
m[2] * (m[3] * m[7] - m[4] * m[6]);
|
||||
if (det > -1e-12 && det < 1e-12) return -1;
|
||||
const double k = 1.0 / det;
|
||||
double r[9] = {(m[4] * m[8] - m[5] * m[7]) * k, (m[2] * m[7] - m[1] * m[8]) * k, (m[1] * m[5] - m[2] * m[4]) * k,
|
||||
(m[5] * m[6] - m[3] * m[8]) * k, (m[0] * m[8] - m[2] * m[6]) * k, (m[2] * m[3] - m[0] * m[5]) * k,
|
||||
(m[3] * m[7] - m[4] * m[6]) * k, (m[1] * m[6] - m[0] * m[7]) * k, (m[0] * m[4] - m[1] * m[3]) * k};
|
||||
memcpy(out, r, sizeof(r));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rgb_to_xyz(const float xy[8], double out[9], double white[3]) {
|
||||
for (int i = 0; i < 4; i++)
|
||||
if (xy[2 * i + 1] < 1e-4f) return -1;
|
||||
double p[9], inv[9];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const double x = xy[2 * i], y = xy[2 * i + 1];
|
||||
p[i] = x / y; p[3 + i] = 1.0; p[6 + i] = (1.0 - x - y) / y;
|
||||
}
|
||||
white[0] = xy[6] / xy[7]; white[1] = 1.0; white[2] = (1.0 - xy[6] - xy[7]) / xy[7];
|
||||
if (mat_invert(p, inv) != 0) return -1;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const double scale = inv[3 * i] * white[0] + inv[3 * i + 1] * white[1] + inv[3 * i + 2] * white[2];
|
||||
out[i] = p[i] * scale; out[3 + i] = p[3 + i] * scale; out[6 + i] = p[6 + i] * scale;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int matrix_to_bt2020(const float xy[8], float out[9]) {
|
||||
static const double bradford[9] = {0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296};
|
||||
double src[9], dst[9], dst_inv[9], sw[3], dw[3], cone_inv[9], adapt[9], m[9];
|
||||
if (rgb_to_xyz(xy, src, sw) != 0 || rgb_to_xyz(BT2020_XY, dst, dw) != 0) return -1;
|
||||
if (mat_invert(dst, dst_inv) != 0 || mat_invert(bradford, cone_inv) != 0) return -1;
|
||||
double scale[9] = {0};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const double from = bradford[3 * i] * sw[0] + bradford[3 * i + 1] * sw[1] + bradford[3 * i + 2] * sw[2];
|
||||
const double to = bradford[3 * i] * dw[0] + bradford[3 * i + 1] * dw[1] + bradford[3 * i + 2] * dw[2];
|
||||
if (from > -1e-9 && from < 1e-9) return -1;
|
||||
scale[4 * i] = to / from;
|
||||
}
|
||||
mat_mul(scale, bradford, adapt);
|
||||
mat_mul(cone_inv, adapt, adapt);
|
||||
mat_mul(adapt, src, m);
|
||||
mat_mul(dst_inv, m, m);
|
||||
for (int i = 0; i < 9; i++) out[i] = (float)m[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct wl_resource *publish_description(struct wl_client *client, struct wl_resource *parent, uint32_t id,
|
||||
struct cm_desc *d) {
|
||||
struct wl_resource *out = wl_resource_create(client, &wp_image_description_v1_interface,
|
||||
wl_resource_get_version(parent), id);
|
||||
if (!out) { free(d); wl_client_post_no_memory(client); return NULL; }
|
||||
d->refs = 1;
|
||||
wl_resource_set_implementation(out, &image_description_impl, d, image_description_resource_destroy);
|
||||
wp_image_description_v1_send_ready(out, d->c.identity);
|
||||
pthread_mutex_lock(&g_mu);
|
||||
g_hdr.descs++;
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void params_create(struct wl_client *client, struct wl_resource *r, uint32_t id) {
|
||||
struct cm_params *p = wl_resource_get_user_data(r);
|
||||
if (!p->tf || !p->primaries) {
|
||||
if (!p->tf || (!p->primaries && !p->has_prim)) {
|
||||
wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET,
|
||||
"transfer function and primaries must both be set");
|
||||
return;
|
||||
@@ -744,10 +835,29 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3
|
||||
if (!g_next_identity) g_next_identity = 1;
|
||||
c->primaries = p->primaries;
|
||||
c->tf = p->tf;
|
||||
if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ)
|
||||
const float ref = p->has_lum ? (float)p->lum_ref : 203.0f;
|
||||
float xy[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
xy[i] = p->has_prim ? p->prim[i] / 1e6f
|
||||
: p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_SRGB ? BT709_XY[i] : BT2020_XY[i];
|
||||
if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && ref == 203.0f) {
|
||||
c->dataspace = DROIDDECK_ADATASPACE_BT2020_PQ;
|
||||
else if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG)
|
||||
c->dataspace = DROIDDECK_ADATASPACE_BT2020_HLG;
|
||||
} else if (matrix_to_bt2020(xy, c->to2020) == 0) {
|
||||
c->convert = 1;
|
||||
c->gain = 10000.0f * 203.0f / ref;
|
||||
} else {
|
||||
struct wl_resource *bad = wl_resource_create(client, &wp_image_description_v1_interface,
|
||||
wl_resource_get_version(r), id);
|
||||
free(d);
|
||||
if (!bad) { wl_client_post_no_memory(client); return; }
|
||||
wl_resource_set_implementation(bad, &image_description_impl, NULL, NULL);
|
||||
wp_image_description_v1_send_failed(bad, WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED,
|
||||
"the primaries do not form a colour space");
|
||||
droiddeck_log(TAG, "image description from %s refused: its primaries do not form a colour space",
|
||||
droiddeck_client_name(client));
|
||||
wl_resource_destroy(r);
|
||||
return;
|
||||
}
|
||||
|
||||
char dropped[160] = "";
|
||||
float mlum_min = 0.005f, mlum_max = 10000.0f;
|
||||
@@ -781,7 +891,12 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3
|
||||
}
|
||||
if (cll > 0.0f || fall > 0.0f) { c->has_cta861 = 1; c->max_cll = cll; c->max_fall = fall; }
|
||||
|
||||
int n = snprintf(c->text, sizeof(c->text), "%s, %s", primaries_name(c->primaries), tf_name(c->tf));
|
||||
int n = snprintf(c->text, sizeof(c->text), "%s, %s", p->has_prim ? "custom primaries" : primaries_name(c->primaries),
|
||||
tf_name(c->tf));
|
||||
if (c->convert && n < (int)sizeof(c->text))
|
||||
n += snprintf(c->text + n, sizeof(c->text) - (size_t)n,
|
||||
"; R %.4f,%.4f G %.4f,%.4f B %.4f,%.4f W %.4f,%.4f, reference white %.0f nits",
|
||||
xy[0], xy[1], xy[2], xy[3], xy[4], xy[5], xy[6], xy[7], ref);
|
||||
if (c->has_st2086 && n < (int)sizeof(c->text))
|
||||
n += snprintf(c->text + n, sizeof(c->text) - (size_t)n,
|
||||
"; mastering R %.4f,%.4f G %.4f,%.4f B %.4f,%.4f W %.4f,%.4f, %.4f-%.0f nits%s",
|
||||
@@ -793,19 +908,13 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3
|
||||
if (!c->has_st2086 && !c->has_cta861 && n < (int)sizeof(c->text))
|
||||
snprintf(c->text + n, sizeof(c->text) - (size_t)n, " (no HDR metadata: the game has not called vkSetHdrMetadataEXT)");
|
||||
|
||||
struct wl_resource *out = wl_resource_create(client, &wp_image_description_v1_interface,
|
||||
wl_resource_get_version(r), id);
|
||||
if (!out) { free(d); wl_client_post_no_memory(client); return; }
|
||||
d->refs = 1;
|
||||
wl_resource_set_implementation(out, &image_description_impl, d, image_description_resource_destroy);
|
||||
wp_image_description_v1_send_ready(out, c->identity);
|
||||
if (c->dataspace) {
|
||||
pthread_mutex_lock(&g_mu);
|
||||
g_hdr.descs++;
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
}
|
||||
droiddeck_log(TAG, "image description #%u from %s: %s -> ready (on a display layer: dataspace %s)", c->identity,
|
||||
droiddeck_client_name(client), c->text, dataspace_name(c->dataspace));
|
||||
if (!publish_description(client, r, id, d)) return;
|
||||
if (c->convert)
|
||||
droiddeck_log(TAG, "image description #%u from %s: %s -> ready (converted to BT.2020 PQ when the scene is "
|
||||
"composed)", c->identity, droiddeck_client_name(client), c->text);
|
||||
else
|
||||
droiddeck_log(TAG, "image description #%u from %s: %s -> ready (on a display layer: dataspace %s)", c->identity,
|
||||
droiddeck_client_name(client), c->text, dataspace_name(c->dataspace));
|
||||
if (dropped[0]) {
|
||||
size_t l = strlen(dropped);
|
||||
if (l && dropped[l - 1] == ',') dropped[l - 1] = 0;
|
||||
@@ -840,8 +949,8 @@ static void params_set_tf_power(struct wl_client *c, struct wl_resource *r, uint
|
||||
}
|
||||
static void params_set_primaries_named(struct wl_client *c, struct wl_resource *r, uint32_t primaries) {
|
||||
struct cm_params *p = wl_resource_get_user_data(r);
|
||||
PARAMS_ONCE(p->primaries, "primaries");
|
||||
if (primaries != WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) {
|
||||
PARAMS_ONCE(p->primaries || p->has_prim, "primaries");
|
||||
if (primaries != WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && primaries != WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) {
|
||||
wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED,
|
||||
"primaries %u were not advertised", primaries);
|
||||
return;
|
||||
@@ -850,12 +959,21 @@ static void params_set_primaries_named(struct wl_client *c, struct wl_resource *
|
||||
}
|
||||
static void params_set_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry, int32_t gx,
|
||||
int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) {
|
||||
wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE,
|
||||
"set_primaries is not supported");
|
||||
struct cm_params *p = wl_resource_get_user_data(r);
|
||||
PARAMS_ONCE(p->primaries || p->has_prim, "primaries");
|
||||
p->has_prim = 1;
|
||||
p->prim[0] = rx; p->prim[1] = ry; p->prim[2] = gx; p->prim[3] = gy;
|
||||
p->prim[4] = bx; p->prim[5] = by; p->prim[6] = wx; p->prim[7] = wy;
|
||||
}
|
||||
static void params_set_luminances(struct wl_client *c, struct wl_resource *r, uint32_t mn, uint32_t mx, uint32_t ref) {
|
||||
wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE,
|
||||
"set_luminances is not supported");
|
||||
struct cm_params *p = wl_resource_get_user_data(r);
|
||||
PARAMS_ONCE(p->has_lum, "luminances");
|
||||
if ((uint64_t)mx * 10000u <= mn || (uint64_t)ref * 10000u <= mn) {
|
||||
wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE,
|
||||
"maximum and reference luminance must be above the minimum");
|
||||
return;
|
||||
}
|
||||
p->has_lum = 1; p->lum_ref = ref;
|
||||
}
|
||||
static void params_set_mastering_display_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry,
|
||||
int32_t gx, int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) {
|
||||
@@ -1083,7 +1201,20 @@ static void cm_create_parametric_creator(struct wl_client *c, struct wl_resource
|
||||
}
|
||||
|
||||
static void cm_create_windows_scrgb(struct wl_client *c, struct wl_resource *r, uint32_t id) {
|
||||
wl_resource_post_error(r, WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "windows_scrgb is not supported");
|
||||
struct cm_desc *d = calloc(1, sizeof(*d));
|
||||
if (!d) { wl_client_post_no_memory(c); return; }
|
||||
struct droiddeck_color *col = &d->c;
|
||||
col->identity = g_next_identity++;
|
||||
if (!g_next_identity) g_next_identity = 1;
|
||||
col->primaries = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB;
|
||||
col->tf = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR;
|
||||
col->convert = 2;
|
||||
col->gain = 80.0f;
|
||||
matrix_to_bt2020(BT709_XY, col->to2020);
|
||||
snprintf(col->text, sizeof(col->text), "%s, %s (1.0 = 80 nits)", primaries_name(col->primaries), tf_name(col->tf));
|
||||
if (!publish_description(c, r, id, d)) return;
|
||||
droiddeck_log(TAG, "image description #%u from %s: %s -> ready (converted to BT.2020 PQ when the scene is composed)",
|
||||
col->identity, droiddeck_client_name(c), col->text);
|
||||
}
|
||||
|
||||
static const struct wp_color_manager_v1_interface cm_impl = {
|
||||
@@ -1103,14 +1234,20 @@ static void bind_cm(struct wl_client *c, void *data, uint32_t ver, uint32_t id)
|
||||
wl_resource_set_implementation(r, &cm_impl, NULL, NULL);
|
||||
wp_color_manager_v1_send_supported_intent(r, WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME);
|
||||
wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_WINDOWS_SCRGB);
|
||||
wp_color_manager_v1_send_supported_primaries_named(r, WP_COLOR_MANAGER_V1_PRIMARIES_SRGB);
|
||||
wp_color_manager_v1_send_supported_primaries_named(r, WP_COLOR_MANAGER_V1_PRIMARIES_BT2020);
|
||||
wp_color_manager_v1_send_supported_tf_named(r, WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ);
|
||||
wp_color_manager_v1_send_done(r);
|
||||
if (last_named != c) {
|
||||
last_named = c;
|
||||
droiddeck_log(TAG, "%s bound wp_color_manager_v1 version %u (offered: perceptual intent; parametric descriptions "
|
||||
"with mastering metadata; BT.2020 primaries; ST 2084 PQ) - its Vulkan driver can now list "
|
||||
"with custom primaries, luminances and mastering metadata; Windows scRGB; sRGB and BT.2020 primaries; "
|
||||
"ST 2084 PQ) - its Vulkan driver can now list "
|
||||
"VK_COLOR_SPACE_HDR10_ST2084_EXT", droiddeck_client_name(c), ver > 1 ? 1u : ver);
|
||||
}
|
||||
}
|
||||
@@ -1150,6 +1287,7 @@ void droiddeck_color_init(struct wl_display *display) {
|
||||
|
||||
char asked[128];
|
||||
if (mode == 2) snprintf(asked, sizeof(asked), "DROIDDECK_WAYLAND_HDR=force (%s)", source);
|
||||
else if (mode == 3) snprintf(asked, sizeof(asked), "HDR is on, tone-mapped for this display (%s)", source);
|
||||
else if (strstr(source, "env")) snprintf(asked, sizeof(asked), "DROIDDECK_WAYLAND_HDR=1 (%s)", source);
|
||||
else snprintf(asked, sizeof(asked), "HDR output is on (%s)", source);
|
||||
|
||||
@@ -1168,7 +1306,7 @@ void droiddeck_color_init(struct wl_display *display) {
|
||||
snprintf(why, sizeof(why), "this Android has no display layers with dataspace control "
|
||||
"(ASurfaceControl + ASurfaceTransaction_setBufferDataSpace, Android 10+)");
|
||||
else if (!ahb_ok)
|
||||
snprintf(why, sizeof(why), "zero-copy presentation is unavailable here (banner_ahb_v1 not advertised), and an "
|
||||
snprintf(why, sizeof(why), "zero-copy presentation is unavailable here (droiddeck_ahb_v1 not advertised), and an "
|
||||
"HDR frame is only honest on the game's own display layer");
|
||||
|
||||
if (why[0]) {
|
||||
@@ -1198,13 +1336,20 @@ void droiddeck_color_init(struct wl_display *display) {
|
||||
log_verdict(1);
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&g_output_mu);
|
||||
atomic_store(&g_gate, 1);
|
||||
if (mode == 3 || !atomic_load(&g_output_wanted)) atomic_store(&g_output_on, 0);
|
||||
pthread_mutex_unlock(&g_output_mu);
|
||||
char syms[160];
|
||||
sc_layer_hdr_symbols(syms, sizeof(syms));
|
||||
droiddeck_log(TAG, "HDR gate %s: %s and %s. Offering games HDR10: wp_color_manager_v1 version 1 (BT.2020 primaries "
|
||||
"+ ST 2084 PQ, parametric descriptions with mastering metadata) and 10-bit AB30/XB30 dma-buf formats; HDR "
|
||||
"frames go on the game's own display layer as BT2020_PQ (%s)",
|
||||
mode == 2 ? "FORCED OPEN (testing)" : "OPEN", asked, disp, syms);
|
||||
if (mode == 3) {
|
||||
droiddeck_log(TAG, "this display cannot show HDR10: games still render HDR and every HDR frame is tone-mapped to "
|
||||
"SDR on the game's display layer");
|
||||
}
|
||||
if (mode == 2 && !hdr10)
|
||||
droiddeck_log(TAG, "DROIDDECK_WAYLAND_HDR=force on a display without HDR10 - testing only: SurfaceFlinger will tone-map "
|
||||
"the game layer for this panel (expect GPU/CLIENT composition for it), nothing looks HDR");
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "droiddeck_ext.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "compositor_internal.h"
|
||||
#include "display_buffers.h"
|
||||
|
||||
|
||||
static void dbuf_buffer_resource_destroy(struct wl_resource *r) {
|
||||
@@ -58,6 +59,7 @@ static struct wl_resource *params_do_create(struct wl_client *c, struct wl_resou
|
||||
wl_resource_set_implementation(buf, &dbuf_buffer_impl, b, dbuf_buffer_resource_destroy);
|
||||
struct client_info *ci = client_info_of(c);
|
||||
if (ci) ci->dmabuf_buffers++;
|
||||
display_buffers_match(c, buf, b);
|
||||
return buf;
|
||||
}
|
||||
static void params_create(struct wl_client *c, struct wl_resource *r, int32_t w, int32_t h,
|
||||
@@ -111,13 +113,16 @@ static const struct zwp_linux_dmabuf_v1_interface dmabuf_impl = {
|
||||
static struct { uint32_t fmt; uint64_t mods[DMABUF_NMOD]; int n; } g_dmabuf_fmts[DMABUF_NFMT_MAX] = {
|
||||
{DRM_ARGB8888}, {DRM_XRGB8888}, {DRM_ABGR8888}, {DRM_XBGR8888}, {DRM_ABGR2101010}, {DRM_XBGR2101010}};
|
||||
static int g_dmabuf_nfmt = DMABUF_NFMT_SDR;
|
||||
static int g_dmabuf_fmts_ready;
|
||||
static volatile int g_dmabuf_fmts_ready;
|
||||
static void dmabuf_build_feedback(void);
|
||||
|
||||
void droiddeck_dmabuf_formats_stale(void) { g_dmabuf_fmts_ready = 0; }
|
||||
|
||||
static void dmabuf_build_formats(void) {
|
||||
char line[320];
|
||||
int pos = 0, compressed = 0;
|
||||
int pos = 0, compressed = 0, backed = 0;
|
||||
g_dmabuf_fmts_ready = 1;
|
||||
display_buffers_withdraw_ubwc();
|
||||
g_dmabuf_nfmt = droiddeck_color_hdr_open() ? DMABUF_NFMT_MAX : DMABUF_NFMT_SDR;
|
||||
for (int f = 0; f < g_dmabuf_nfmt; f++) {
|
||||
uint64_t got[DMABUF_NMOD];
|
||||
@@ -129,6 +134,12 @@ static void dmabuf_build_formats(void) {
|
||||
g_dmabuf_fmts[f].mods[k++] = got[i];
|
||||
if (got[i] == VKP_MOD_QCOM_COMPRESSED) compressed++;
|
||||
}
|
||||
int listed = 0;
|
||||
for (int i = 0; i < k; i++) if (g_dmabuf_fmts[f].mods[i] == VKP_MOD_QCOM_COMPRESSED) listed = 1;
|
||||
if (display_buffers_offer_ubwc(g_dmabuf_fmts[f].fmt) && !listed) {
|
||||
g_dmabuf_fmts[f].mods[k++] = VKP_MOD_QCOM_COMPRESSED;
|
||||
backed++;
|
||||
}
|
||||
g_dmabuf_fmts[f].mods[k++] = MOD_INVALID;
|
||||
g_dmabuf_fmts[f].n = k;
|
||||
uint32_t fmt = g_dmabuf_fmts[f].fmt;
|
||||
@@ -141,7 +152,10 @@ static void dmabuf_build_formats(void) {
|
||||
}
|
||||
droiddeck_log("dmabuf", "formats: %s%s", line,
|
||||
!g_ubwc ? " (DROIDDECK_WAYLAND_UBWC=0: qcom_compressed not advertised)" : "");
|
||||
if (g_ubwc && !compressed)
|
||||
if (backed)
|
||||
droiddeck_log("dmabuf", "qcom_compressed is advertised for %d formats the compositor's driver (%s) does not "
|
||||
"import as dma-bufs: this session's driver renders them into gralloc buffers", backed, vkp_gpu_name());
|
||||
else if (g_ubwc && !compressed)
|
||||
droiddeck_log("dmabuf", "the compositor's driver (%s) reports no importable qcom_compressed layout: "
|
||||
"game swapchains stay linear", vkp_gpu_name());
|
||||
if (g_dmabuf_nfmt > DMABUF_NFMT_SDR) {
|
||||
@@ -212,6 +226,7 @@ static void dmabuf_build_feedback(void) {
|
||||
return;
|
||||
}
|
||||
fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
|
||||
if (g_fmt_table_fd >= 0) close(g_fmt_table_fd);
|
||||
g_fmt_table_fd = fd;
|
||||
g_fmt_table_size = size;
|
||||
g_fmt_table_n = (uint16_t)n;
|
||||
|
||||
@@ -96,6 +96,8 @@ class App : Application() {
|
||||
com.droiddeck.launcher.session.SessionFiles.ensureUbisoftService(app)
|
||||
if (com.droiddeck.launcher.stores.StoreAccounts.signedInAs(app, com.droiddeck.launcher.stores.Store.ROCKSTAR) != null)
|
||||
com.droiddeck.launcher.session.SessionFiles.ensureRockstarService(app)
|
||||
if (com.droiddeck.launcher.stores.StoreAccounts.signedInAs(app, com.droiddeck.launcher.stores.Store.EPIC) != null)
|
||||
com.droiddeck.launcher.session.SessionFiles.ensureEpicParent(app)
|
||||
com.droiddeck.launcher.handtracking.HandTracking.load(app)
|
||||
}.onFailure { android.util.Log.w("App", "add-on pack prefetch failed", it) }
|
||||
}, "addon-packs").start()
|
||||
|
||||
@@ -194,6 +194,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var picturePosition by mutableStateOf("center")
|
||||
private var integerScaling by mutableStateOf(false)
|
||||
private var stretch16x9 by mutableStateOf(false)
|
||||
private var avoidNotch by mutableStateOf(false)
|
||||
private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
||||
private var launcherOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER)
|
||||
private var homePage by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.HOME_PAGE_STEAM)
|
||||
@@ -596,9 +597,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var theme by mutableStateOf("graphite")
|
||||
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 upscaler by mutableStateOf(0)
|
||||
private var upscaleSharpness by mutableStateOf(75)
|
||||
private var hdrReason by mutableStateOf<String?>(null)
|
||||
private var hdrDisplay by mutableStateOf(true)
|
||||
private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO)
|
||||
private var pen by mutableStateOf<SessionPrefs.Pen?>(null)
|
||||
private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL)
|
||||
@@ -2079,6 +2082,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
refreshHomeAppState()
|
||||
}
|
||||
if (settingsMode == SessionService.MODE_STEAM) refreshFoundSteamLibraries()
|
||||
settingsMode?.let { hdrOn = SessionPrefs.hdr(this, it) }
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false)
|
||||
@@ -2586,7 +2590,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
ModeSettings(
|
||||
mode = mode, resolution = resolution,
|
||||
panelSize = com.droiddeck.launcher.session.SessionDisplay.panelSize(this),
|
||||
hdr = hdrOn, hdrReason = hdrReason,
|
||||
hdr = hdrOn, hdrReason = hdrReason, hdrDisplay = hdrDisplay, zeroCopy = zeroCopyOn,
|
||||
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
|
||||
gpuDrivers = drivers.summary(),
|
||||
touchMode = touchMode,
|
||||
@@ -2604,6 +2608,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
picturePosition = if (mode == SessionService.MODE_STEAM) picturePosition else null,
|
||||
integerScaling = if (mode == SessionService.MODE_STEAM) integerScaling else null,
|
||||
stretch16x9 = if (mode == SessionService.MODE_STEAM) stretch16x9 else null,
|
||||
avoidNotch = if (mode == SessionService.MODE_STEAM) avoidNotch else null,
|
||||
mic = if (mode == SessionService.MODE_STEAM) mic else null,
|
||||
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
|
||||
storageOptions = storageOptions,
|
||||
@@ -2639,7 +2644,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
onIntegrationAppInfo = ::openAppInfo,
|
||||
onIntegrationLocation = ::openWifiDiscoverySettings,
|
||||
onResolution = { value -> SessionPrefs.setResolutionChoice(this, mode, value); resolution = value },
|
||||
onHdr = { on -> SessionPrefs.setHdr(this, mode, on); hdrOn = on },
|
||||
onHdr = { on -> com.droiddeck.launcher.session.SessionHdr.set(this, mode, on); hdrOn = on },
|
||||
onZeroCopy = { on ->
|
||||
SessionPrefs.setZeroCopy(this, mode, on); zeroCopyOn = on
|
||||
if (com.droiddeck.launcher.wayland.CompositorHost.isStarted && !SessionState.hdr &&
|
||||
SessionPrefs.prefMode(SessionState.mode) == SessionPrefs.prefMode(mode))
|
||||
com.droiddeck.launcher.wayland.WaylandCompositor.nativeSetZeroCopy(on)
|
||||
},
|
||||
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 },
|
||||
@@ -2666,6 +2677,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
onPicturePosition = { value -> SessionPrefs.setPicturePosition(this, value); picturePosition = value },
|
||||
onIntegerScaling = { on -> SessionPrefs.setIntegerScaling(this, on); integerScaling = on },
|
||||
onStretch16x9 = { on -> SessionPrefs.setStretch16x9(this, on); stretch16x9 = on },
|
||||
onAvoidNotch = { on -> SessionPrefs.setAvoidNotch(this, on); avoidNotch = on },
|
||||
onMic = { on ->
|
||||
SessionPrefs.setMicEnabled(this, on)
|
||||
mic = on
|
||||
@@ -2983,9 +2995,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
startupSession = SessionPrefs.startupSession(this)
|
||||
loadBootMovie()
|
||||
hdrOn = SessionPrefs.hdr(this, mode)
|
||||
zeroCopyOn = SessionPrefs.zeroCopy(this, mode)
|
||||
upscaler = SessionPrefs.upscaler(this)
|
||||
upscaleSharpness = SessionPrefs.upscaleSharpness(this)
|
||||
hdrReason = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason
|
||||
hdrReason = com.droiddeck.launcher.wayland.HdrSupport.blocked(this)
|
||||
hdrDisplay = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason == null
|
||||
touchMode = SessionPrefs.touchMode(this)
|
||||
if (!SessionPrefs.penSeen(this) && com.droiddeck.launcher.input.PenStream.penConnected()) SessionPrefs.setPenSeen(this)
|
||||
pen = SessionPrefs.pen(this).takeIf { SessionPrefs.penSeen(this) }
|
||||
@@ -2998,6 +3012,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
picturePosition = SessionPrefs.picturePosition(this)
|
||||
integerScaling = SessionPrefs.integerScaling(this)
|
||||
stretch16x9 = SessionPrefs.stretch16x9(this)
|
||||
avoidNotch = SessionPrefs.avoidNotch(this)
|
||||
mic = SessionPrefs.micEnabled(this)
|
||||
refreshWifiDiscovery()
|
||||
gameStorage = SessionPrefs.gameStorage(this)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -230,6 +230,20 @@ object AgentGuest {
|
||||
call(context, JSONObject().put("kind", "cdp").put("expression", expression).put("timeout", timeoutMs / 1000.0),
|
||||
timeoutMs + 2_000, trusted = true)
|
||||
|
||||
fun setGamescopeConvar(context: Context, name: String, value: Int): Boolean {
|
||||
val request = JSONObject()
|
||||
.put("kind", "exec")
|
||||
.put("argv", org.json.JSONArray(listOf("gamescopectl", name, value.toString())))
|
||||
.put("timeout", 5.0)
|
||||
val result = runCatching { call(context, request, 8_000, trusted = true) }
|
||||
val answer = result.getOrNull()
|
||||
val applied = answer?.optBoolean("ok") == true
|
||||
&& answer.optInt("exitCode", -1) == 0
|
||||
&& !answer.optBoolean("timedOut")
|
||||
if (!applied) Log.w(TAG, "gamescope did not take $name $value: ${result.exceptionOrNull() ?: answer}")
|
||||
return applied
|
||||
}
|
||||
|
||||
fun call(context: Context, request: JSONObject, timeoutMs: Long, trusted: Boolean = false): JSONObject {
|
||||
if (!trusted && request.optString("kind") in setOf("exec", "cdp")) AgentAccess.requireCommands(context)
|
||||
if (!SessionState.running) throw AgentException("NO_ACTIVE_SESSION", "There is no running session")
|
||||
|
||||
@@ -175,5 +175,6 @@ internal class AddonPack(
|
||||
val ROCKSTAR = AddonPack("rockstar", BuildConfig.PACK_ROCKSTAR_SHA256, BuildConfig.PACK_ROCKSTAR_SIZE,
|
||||
listOf("Launcher32.exe", "Launcher64.exe"))
|
||||
val DIRT = AddonPack("dirt", BuildConfig.PACK_DIRT_SHA256, BuildConfig.PACK_DIRT_SIZE, listOf("ws2_32.dll"))
|
||||
val EPIC = AddonPack("epic", BuildConfig.PACK_EPIC_SHA256, BuildConfig.PACK_EPIC_SIZE, listOf("EpicGamesLauncher.exe"))
|
||||
}
|
||||
}
|
||||
@@ -289,6 +289,7 @@ object DeviceReport {
|
||||
k("Guest host name", SessionPrefs.guestHostname(context))
|
||||
k("DirectAudio for games", SessionPrefs.directAudio(context))
|
||||
k("Stretch 16:9 to panel", SessionPrefs.stretch16x9(context))
|
||||
k("Avoid notch", SessionPrefs.avoidNotch(context))
|
||||
k("Return to launcher after a game", SessionPrefs.returnAfterGame(context))
|
||||
k("Microphone", SessionPrefs.micEnabled(context))
|
||||
k("On-screen controls", SessionPrefs.oscMode(context))
|
||||
|
||||
@@ -21,6 +21,8 @@ object FrameGen {
|
||||
private const val PREFS = "frame_gen"
|
||||
|
||||
data class Mode(val engine: String, val multiplier: Int = 2, val target: Int = 0) {
|
||||
val outputFactor: Int get() = if (engine == ENGINE_OFF) 1 else multiplier
|
||||
|
||||
companion object {
|
||||
val OFF = Mode(ENGINE_OFF)
|
||||
}
|
||||
|
||||
@@ -89,6 +89,11 @@ public class LinuxVulkanDriverManager {
|
||||
return m != null ? m.optString("minGlibc", "") : "";
|
||||
}
|
||||
|
||||
public boolean rendersToDisplayBuffers(String id) {
|
||||
JSONObject m = id == null || id.isEmpty() ? null : readMeta(id);
|
||||
return m != null && m.optBoolean("displayBuffers", false);
|
||||
}
|
||||
|
||||
public void removeDriver(String id) {
|
||||
if (id == null || id.isEmpty() || id.contains("/") || id.contains("..")) return;
|
||||
Log.d(TAG, "removing imported Linux Vulkan driver " + id);
|
||||
@@ -182,6 +187,7 @@ public class LinuxVulkanDriverManager {
|
||||
meta.put("driverVersion", version);
|
||||
meta.put("libc", "glibc");
|
||||
meta.put("minGlibc", minGlibc);
|
||||
meta.put("displayBuffers", zipMeta != null && zipMeta.optBoolean("displayBuffers", false));
|
||||
meta.put("sourceLibraryName", soName);
|
||||
meta.put("libraryName", stored);
|
||||
meta.put("importedAt", System.currentTimeMillis());
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.gpu
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
import org.json.JSONObject
|
||||
import kotlin.math.abs
|
||||
@@ -30,7 +31,7 @@ data class ScreenEffects(
|
||||
|
||||
fun push(upscaler: Int) {
|
||||
WaylandCompositor.nativeSetCas(cas, casLevel)
|
||||
WaylandCompositor.nativeSetHdr(hdr)
|
||||
WaylandCompositor.nativeSetHdr(hdr && !SessionState.hdrDisplay)
|
||||
WaylandCompositor.nativeSetDeband(deband, debandStrength)
|
||||
WaylandCompositor.nativeSetScreenEffects(brightness.toFloat(), contrast.toFloat(), gamma, saturation.toFloat(), aaMode, toon, crt, ntsc)
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(this, upscaler)?.name)
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.util.DisplayMetrics
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
internal class ControllerOverlayGeometry(
|
||||
width: Int, height: Int, private val safe: Rect, metrics: DisplayMetrics, scale: Float,
|
||||
) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
private val density = metrics.density
|
||||
private val dpi = metrics.ydpi.takeIf { it in metrics.densityDpi * .6f..metrics.densityDpi * 1.6f }
|
||||
?: metrics.densityDpi.toFloat()
|
||||
private val unit = minOf(
|
||||
min(w / 1600f, h / 900f) * min(1f, 80f / max(h / dpi * 25.4f, 1f)) * scale,
|
||||
(w - safe.left - safe.right).coerceAtLeast(1f) / 1200f,
|
||||
(h - safe.top - safe.bottom).coerceAtLeast(1f) / 900f,
|
||||
)
|
||||
|
||||
private fun anchor(value: Float, reference: Float, extent: Float, start: Int, end: Int): Float {
|
||||
val low = start + value * unit
|
||||
val high = extent - end - (reference - value) * unit
|
||||
return when {
|
||||
value < reference / 3f -> low
|
||||
value > reference * 2f / 3f -> high
|
||||
else -> (extent / 2f + (value - reference / 2f) * unit).coerceIn(low, max(low, high))
|
||||
}
|
||||
}
|
||||
|
||||
private fun x(ref: Float) = anchor(ref, 1600f, w, safe.left, safe.right)
|
||||
|
||||
private fun y(ref: Float) = anchor(ref, 900f, h, safe.top, safe.bottom)
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, kit: PadKit, rearButtons: Boolean, trackpads: Boolean): List<InputSurfaceElement> {
|
||||
if (!kit.steam) return placeStandardPad(elements, kit)
|
||||
val leftEdge = safe.left + 52f * density
|
||||
val middle = (w + safe.left - safe.right) / 2f
|
||||
val keyboard = Box(max(x(136f), leftEdge + 46f * unit), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
|
||||
val row = fitRow(listOfNotNull(keyboard,
|
||||
Box(max(x(370f), leftEdge + 66f * unit), y(852f), 66f, 30f),
|
||||
Box(middle - 140f * unit, y(850f), 46f, 26f),
|
||||
Box(middle + 140f * unit, y(850f), 46f, 26f),
|
||||
Box(x(1230f), y(852f), 66f, 30f)), leftEdge)
|
||||
val (guide, select, start, qam) = row.takeLast(4)
|
||||
val positions = shoulders() + face(1375f, 345f, 96f) + mapOf(
|
||||
InputControl.UP to Box(x(220f), y(345f) - 102.5f * unit, 55.5f, 47.5f),
|
||||
InputControl.RIGHT to Box(x(220f) + 102.5f * unit, y(345f), 47.5f, 55.5f),
|
||||
InputControl.DOWN to Box(x(220f), y(345f) + 102.5f * unit, 55.5f, 47.5f),
|
||||
InputControl.LEFT to Box(x(220f) - 102.5f * unit, y(345f), 47.5f, 55.5f),
|
||||
InputControl.LS to Box(x(290f), y(640f), 96f),
|
||||
InputControl.RS to Box(x(1310f), y(640f), 96f),
|
||||
InputControl.SELECT to select,
|
||||
InputControl.START to start,
|
||||
InputControl.GUIDE to guide,
|
||||
InputControl.QAM to qam,
|
||||
)
|
||||
val rear = mapOf(
|
||||
InputControl.L4 to Box(x(30f), y(470f), 30f, 58f),
|
||||
InputControl.L5 to Box(x(30f), y(590f), 30f, 58f),
|
||||
InputControl.R4 to Box(x(1570f), y(470f), 30f, 58f),
|
||||
InputControl.R5 to Box(x(1570f), y(590f), 30f, 58f),
|
||||
)
|
||||
val pads = mapOf(
|
||||
InputControl.LEFT_PAD to Box(x(470f), y(360f), 88f),
|
||||
InputControl.RIGHT_PAD to Box(x(1130f), y(360f), 88f),
|
||||
)
|
||||
val optional = rear.filterKeys { rearButtons } + pads.filterKeys { trackpads }
|
||||
val placed = elements.mapNotNull { element ->
|
||||
when {
|
||||
element.id == KEYBOARD -> row.first().place(element)
|
||||
element.id != "legacy:${element.control.id}" -> element
|
||||
element.control in rear || element.control in pads -> optional[element.control]?.place(element)
|
||||
else -> positions[element.control]?.place(element) ?: element
|
||||
}
|
||||
}
|
||||
return placed + optional.mapNotNull { (control, box) ->
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) null else box.place(InputSurfaceElement(control,
|
||||
0f, 0f, 0f, 0f, floating = false, buttonShape = InputButtonShape.PILL, showLabel = !control.isTrackpad))
|
||||
}
|
||||
}
|
||||
|
||||
private fun placeStandardPad(elements: List<InputSurfaceElement>, kit: PadKit): List<InputSurfaceElement> {
|
||||
val leftEdge = safe.left + 52f * density
|
||||
val middle = (w + safe.left - safe.right) / 2f
|
||||
val keyboard = Box(max(x(136f), leftEdge + 46f * unit), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
|
||||
val controls = if (kit.playStation) listOf(
|
||||
InputControl.QAM to Box(x(220f), y(848f), 46f),
|
||||
InputControl.SELECT to Box(middle - 160f * unit, y(850f), 50f, 30f),
|
||||
InputControl.GUIDE to Box(middle, y(850f), 46f),
|
||||
InputControl.START to Box(middle + 160f * unit, y(850f), 50f, 30f),
|
||||
) else listOf(
|
||||
InputControl.QAM to Box(x(220f), y(848f), 46f),
|
||||
InputControl.SELECT to Box(middle - 110f * unit, y(850f), 38f),
|
||||
InputControl.GUIDE to Box(middle, y(850f), 46f),
|
||||
InputControl.START to Box(middle + 110f * unit, y(850f), 38f),
|
||||
)
|
||||
val row = fitRow(listOfNotNull(keyboard) + controls.map { it.second }, leftEdge)
|
||||
val positions = controls.map { it.first }.zip(row.takeLast(controls.size)).toMap() + shoulders() +
|
||||
if (kit.playStation) {
|
||||
face(1350f, 395f, 96f) + dpad(250f, 395f, 125f, kit.dpad) + mapOf(
|
||||
InputControl.LS to Box(x(565f), y(690f), 100f),
|
||||
InputControl.RS to Box(x(1035f), y(690f), 100f),
|
||||
InputControl.L3 to Box(x(565f) - 135f * unit, y(690f) - 100f * unit, 42f),
|
||||
InputControl.R3 to Box(x(1035f) + 135f * unit, y(690f) - 100f * unit, 42f),
|
||||
)
|
||||
} else {
|
||||
face(1375f, 400f, 94f) + dpad(470f, 675f, 118f, kit.dpad) + mapOf(
|
||||
InputControl.LS to Box(x(235f), y(400f), 104f),
|
||||
InputControl.RS to Box(x(1130f), y(690f), 104f),
|
||||
InputControl.L3 to Box(x(235f) + 150f * unit, y(400f) - 110f * unit, 42f),
|
||||
InputControl.R3 to Box(x(1130f) + 160f * unit, y(690f) + 100f * unit, 42f),
|
||||
)
|
||||
}
|
||||
return elements.map { element ->
|
||||
when (element.id) {
|
||||
KEYBOARD -> row.first().place(element)
|
||||
"legacy:${element.control.id}" -> positions[element.control]?.place(element) ?: element
|
||||
else -> element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shoulders() = mapOf(
|
||||
InputControl.LT to Box(x(140f), y(66f), 88f, 34f),
|
||||
InputControl.LB to Box(x(140f), y(148f), 88f, 30f),
|
||||
InputControl.RT to Box(x(1460f), y(66f), 88f, 34f),
|
||||
InputControl.RB to Box(x(1460f), y(148f), 88f, 30f),
|
||||
)
|
||||
|
||||
private fun face(cx: Float, cy: Float, offset: Float) = mapOf(
|
||||
InputControl.Y to Box(x(cx), y(cy) - offset * unit, 58f),
|
||||
InputControl.X to Box(x(cx) - offset * unit, y(cy), 58f),
|
||||
InputControl.B to Box(x(cx) + offset * unit, y(cy), 58f),
|
||||
InputControl.A to Box(x(cx), y(cy) + offset * unit, 58f),
|
||||
)
|
||||
|
||||
private fun dpad(cx: Float, cy: Float, radius: Float, style: DpadStyle): Map<InputControl, Box> {
|
||||
val inner = radius * if (style == DpadStyle.DISC) .25f else .14f
|
||||
val depth = (radius - inner) / 2f
|
||||
val offset = (radius - depth) * unit
|
||||
val side = radius * .25f
|
||||
return mapOf(
|
||||
InputControl.UP to Box(x(cx), y(cy) - offset, side, depth),
|
||||
InputControl.RIGHT to Box(x(cx) + offset, y(cy), depth, side),
|
||||
InputControl.DOWN to Box(x(cx), y(cy) + offset, side, depth),
|
||||
InputControl.LEFT to Box(x(cx) - offset, y(cy), depth, side),
|
||||
)
|
||||
}
|
||||
|
||||
private fun fitRow(row: List<Box>, start: Float): List<Box> {
|
||||
val end = w - safe.right
|
||||
val gap = ((end - start - row.fold(0f) { sum, box -> sum + box.width }) / (row.size - 1)).coerceIn(0f, 8f * density)
|
||||
var edge = start - gap
|
||||
val pushed = row.map { box -> box.at(max(box.cx, edge + gap + box.width / 2f)).also { edge = it.cx + it.width / 2f } }
|
||||
edge = end + gap
|
||||
return pushed.asReversed().map { box -> box.at(min(box.cx, edge - gap - box.width / 2f)).also { edge = it.cx - it.width / 2f } }.asReversed()
|
||||
}
|
||||
|
||||
private inner class Box(val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw) {
|
||||
val width get() = max(hw * 2f * unit, w * .03f)
|
||||
|
||||
fun at(cx: Float) = Box(cx, cy, hw, hh)
|
||||
|
||||
fun place(element: InputSurfaceElement): InputSurfaceElement {
|
||||
val height = max(hh * 2f * unit, h * .03f)
|
||||
return element.copy(
|
||||
x = (cx - width / 2f).coerceIn(safe.left.toFloat(), max(safe.left.toFloat(), w - safe.right - width)) / w,
|
||||
y = (cy - height / 2f).coerceIn(safe.top.toFloat(), max(safe.top.toFloat(), h - safe.bottom - height)) / h,
|
||||
width = width / w, height = height / h,
|
||||
).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEYBOARD = "builtin:keyboard"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.input.GamepadGeometry.Box
|
||||
import kotlin.math.min
|
||||
|
||||
internal class ControllerPortraitGeometry(
|
||||
private val width: Float,
|
||||
private val height: Float,
|
||||
private val safe: Rect,
|
||||
private val density: Float,
|
||||
) {
|
||||
fun place(
|
||||
elements: List<InputSurfaceElement>, kit: PadKit, docked: Boolean, scale: Float,
|
||||
rearButtons: Boolean, trackpads: Boolean,
|
||||
): List<InputSurfaceElement> {
|
||||
val w = width - safe.left - safe.right
|
||||
val h = height - safe.top - safe.bottom
|
||||
if (w <= 0 || h <= 0) return elements
|
||||
val presented = elements.toMutableList()
|
||||
val buttons = mutableMapOf<String, Box>()
|
||||
val rear = presented.filter { it.control in REAR && isStock(it) }
|
||||
val pads = presented.filter { it.control.isTrackpad && isStock(it) }
|
||||
if (!docked && kit.steam) {
|
||||
if (rearButtons) REAR.forEach { addOptional(presented, it) } else presented.removeAll(rear)
|
||||
if (trackpads) {
|
||||
addOptional(presented, InputControl.LEFT_PAD)
|
||||
addOptional(presented, InputControl.RIGHT_PAD)
|
||||
} else presented.removeAll(pads)
|
||||
}
|
||||
fun put(control: InputControl, box: Box) { buttons["legacy:${control.id}"] = box }
|
||||
val reserve = if (docked) 0f else min(60f * density, h * .15f)
|
||||
val panel = if (docked) h else min(min(h * .60f, w * 1.15f) * scale, h - reserve)
|
||||
val top = height - safe.bottom - reserve - panel
|
||||
val unit = min(density, min(w / 275f, panel / 300f))
|
||||
val pad = 8f * unit
|
||||
val gap = 8f * unit
|
||||
val buttonHeight = 44f * unit
|
||||
val shoulders = if (docked) listOf(InputControl.LT, InputControl.LB, InputControl.SELECT, InputControl.START, InputControl.RB, InputControl.RT)
|
||||
else listOf(InputControl.LT, InputControl.LB, InputControl.RB, InputControl.RT)
|
||||
fun row(controls: List<InputControl>, y: Float, rowHeight: Float, spacing: Float) {
|
||||
val cell = (w - 2f * pad - (controls.size - 1) * spacing) / controls.size
|
||||
controls.forEachIndexed { index, control ->
|
||||
put(control, Box(safe.left + pad + cell / 2f + index * (cell + spacing), y, cell, rowHeight))
|
||||
}
|
||||
}
|
||||
row(shoulders, top + pad + buttonHeight / 2f, buttonHeight, 4f * unit)
|
||||
var bodyTop = top + pad + buttonHeight + gap
|
||||
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
|
||||
}
|
||||
val floor = height - safe.bottom - reserve - pad
|
||||
val bodyHeight = floor - bodyTop - gap
|
||||
if (bodyHeight <= 0f) return elements
|
||||
val hasLeftPad = presented.any { it.control == InputControl.LEFT_PAD && isStock(it) }
|
||||
val hasRightPad = presented.any { it.control == InputControl.RIGHT_PAD && isStock(it) }
|
||||
val hasLeftStick = presented.any { it.control == InputControl.LS && isStock(it) }
|
||||
val hasRightStick = presented.any { it.control == InputControl.RS && isStock(it) }
|
||||
val four = hasLeftPad && hasLeftStick || hasRightPad && hasRightStick
|
||||
val main = min(w * .46f, bodyHeight * .53f)
|
||||
val second = min(w * .42f, bodyHeight - main)
|
||||
val mainY = floor - main / 2f
|
||||
val secondY = bodyTop + second / 2f
|
||||
val left = safe.left + w * .25f
|
||||
val right = safe.left + w * .75f
|
||||
if (four) {
|
||||
val col = (w - 2f * pad - 3f * gap) / 4f
|
||||
val stick = min(col, main)
|
||||
put(InputControl.LEFT_PAD, Box(safe.left + pad + col * .5f, mainY, col, main))
|
||||
put(InputControl.LS, Box(safe.left + pad + col * 1.5f + gap, mainY, stick, stick))
|
||||
put(InputControl.RS, Box(safe.left + w - pad - col * 1.5f - gap, mainY, stick, stick))
|
||||
put(InputControl.RIGHT_PAD, Box(safe.left + w - pad - col * .5f, mainY, col, main))
|
||||
} else {
|
||||
put(if (hasLeftPad) InputControl.LEFT_PAD else InputControl.LS, Box(left, mainY, main, main))
|
||||
put(if (hasRightPad) InputControl.RIGHT_PAD else InputControl.RS, Box(right, mainY, main, main))
|
||||
}
|
||||
val radius = second / 2f
|
||||
val armWidth = radius * if (kit.dpad == DpadStyle.CROSS) .37f else .25f
|
||||
val inner = if (kit.dpad == DpadStyle.ARROWS) radius * .14f else armWidth
|
||||
val depth = radius - inner
|
||||
val distance = (radius + inner) / 2f
|
||||
put(InputControl.UP, Box(left, secondY - distance, armWidth * 2f, depth))
|
||||
put(InputControl.RIGHT, Box(left + distance, secondY, depth, armWidth * 2f))
|
||||
put(InputControl.DOWN, Box(left, secondY + distance, armWidth * 2f, depth))
|
||||
put(InputControl.LEFT, Box(left - distance, secondY, depth, armWidth * 2f))
|
||||
val face = second * .34f
|
||||
val spread = second * .30f
|
||||
put(InputControl.Y, Box(right, secondY - spread, face, face))
|
||||
put(InputControl.X, Box(right - spread, secondY, face, face))
|
||||
put(InputControl.B, Box(right + spread, secondY, face, face))
|
||||
put(InputControl.A, Box(right, secondY + spread, face, face))
|
||||
if (!docked) {
|
||||
val ids = listOf(KEYBOARD, "legacy:guide", "legacy:select", "legacy:start", "legacy:qam")
|
||||
.filter { id -> presented.any { it.id == id } }
|
||||
val inset = min(52f * density, w * .17f)
|
||||
val rowWidth = (w - inset - pad - gap * (ids.size - 1)) / ids.size.coerceAtLeast(1)
|
||||
val rowHeight = min(reserve * .8f, 44f * unit)
|
||||
ids.forEachIndexed { i, id ->
|
||||
val center = safe.left + inset + rowWidth / 2f + i * (rowWidth + gap)
|
||||
buttons[id] = Box(center, height - safe.bottom - reserve / 2f, rowWidth, rowHeight)
|
||||
}
|
||||
}
|
||||
return presented.map { element ->
|
||||
val box = buttons[element.id]
|
||||
if (box == null) element else element.copy(
|
||||
x = box.left / width, y = box.top / height, width = box.width / width, height = box.height / height,
|
||||
).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isStock(element: InputSurfaceElement) = element.id == "legacy:${element.control.id}"
|
||||
|
||||
private fun addOptional(elements: MutableList<InputSurfaceElement>, control: InputControl) {
|
||||
if (elements.none { it.control == control && isStock(it) }) {
|
||||
elements += InputSurfaceElement(control, 0f, 0f, 0f, 0f, floating = false,
|
||||
buttonShape = InputButtonShape.PILL, showLabel = !control.isTrackpad)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEYBOARD = "builtin:keyboard"
|
||||
val REAR = listOf(InputControl.L4, InputControl.L5, InputControl.R5, InputControl.R4)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,21 @@ object ControllerPrefs {
|
||||
const val STEAM_BLUE = 0xFF1A9FFF.toInt()
|
||||
const val OFF = "off"
|
||||
|
||||
val tints = listOf(
|
||||
STEAM_BLUE to R.string.ctrl_tint_steam_blue,
|
||||
0xFF66C0F4.toInt() to R.string.ctrl_tint_sky,
|
||||
0xFFE8EEF4.toInt() to R.string.ctrl_tint_white,
|
||||
0xFFC77DFF.toInt() to R.string.ctrl_tint_violet,
|
||||
0xFF3DDC84.toInt() to R.string.ctrl_tint_green,
|
||||
0xFFFFA726.toInt() to R.string.ctrl_tint_amber,
|
||||
0xFFFF5252.toInt() to R.string.ctrl_tint_red,
|
||||
0xFFFF6FB5.toInt() to R.string.ctrl_tint_pink,
|
||||
)
|
||||
|
||||
val opacities = listOf(40, 60, 80, 100)
|
||||
|
||||
val sizes = listOf(80, 90, 100, 110, 125)
|
||||
|
||||
val deadZones = listOf(0, 5, 8, 12, 15, 20, 25)
|
||||
const val DEFAULT_DEAD_ZONE_PERCENT = 12
|
||||
|
||||
@@ -24,15 +39,20 @@ object ControllerPrefs {
|
||||
OFF to R.string.ctrl_target_hidden,
|
||||
)
|
||||
|
||||
/** Settings still read: the rest only seed the one-time library and layout migrations. */
|
||||
class Settings(
|
||||
val tint: Int,
|
||||
val opacity: Int,
|
||||
val size: Int,
|
||||
val stickClick: Boolean,
|
||||
val adaptiveSticks: Boolean,
|
||||
val rumble: Boolean,
|
||||
val steamButton: Boolean,
|
||||
val qamButton: Boolean,
|
||||
val keyboardButton: Boolean,
|
||||
val selectSteam: Boolean,
|
||||
val joyConVr: Boolean,
|
||||
val snap: Boolean,
|
||||
val customLayout: Boolean,
|
||||
val mapping: Map<String, String>,
|
||||
val deadZone: Int,
|
||||
)
|
||||
@@ -43,17 +63,50 @@ object ControllerPrefs {
|
||||
val p = prefs(context)
|
||||
return Settings(
|
||||
tint = p.getInt("tint", STEAM_BLUE),
|
||||
opacity = p.getInt("opacity", 100).coerceIn(1, 100),
|
||||
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),
|
||||
rumble = rumbleEnabled(context),
|
||||
steamButton = p.getBoolean("steamButton", true),
|
||||
qamButton = p.getBoolean("qamButton", true),
|
||||
keyboardButton = p.getBoolean("keyboardButton", true),
|
||||
selectSteam = p.getBoolean("selectSteam", false),
|
||||
joyConVr = joyConVr(context),
|
||||
snap = snap(context),
|
||||
mapping = mappable.associate { (id, _) -> id to (p.getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id) },
|
||||
customLayout = p.all.keys.any { it.startsWith("layout.") },
|
||||
mapping = mappable.associate { (id, _) -> id to target(context, id) },
|
||||
deadZone = deadZone(context),
|
||||
)
|
||||
}
|
||||
|
||||
fun target(context: Context, id: String): String =
|
||||
prefs(context).getString("map.$id", id)?.takeIf { t -> targets.any { it.first == t } } ?: id
|
||||
|
||||
fun setTarget(context: Context, id: String, target: String) {
|
||||
prefs(context).edit().putString("map.$id", target).apply()
|
||||
}
|
||||
|
||||
fun setTint(context: Context, tint: Int) {
|
||||
prefs(context).edit().putInt("tint", tint).apply()
|
||||
}
|
||||
|
||||
fun setOpacity(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("opacity", percent).apply()
|
||||
}
|
||||
|
||||
fun setSize(context: Context, percent: Int) {
|
||||
prefs(context).edit().putInt("size", percent).apply()
|
||||
}
|
||||
|
||||
fun setStickClick(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("stickClick", on).apply()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("adaptiveSticks", on).apply()
|
||||
}
|
||||
|
||||
fun rumbleEnabled(context: Context): Boolean = prefs(context).getBoolean("rumble", true)
|
||||
|
||||
fun deadZone(context: Context): Int =
|
||||
@@ -67,6 +120,18 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("rumble", on).apply()
|
||||
}
|
||||
|
||||
fun setSteamButton(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("steamButton", on).apply()
|
||||
}
|
||||
|
||||
fun setKeyboardButton(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("keyboardButton", on).apply()
|
||||
}
|
||||
|
||||
fun setSelectSteam(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("selectSteam", on).apply()
|
||||
}
|
||||
|
||||
fun joyConVr(context: Context): Boolean = prefs(context).getBoolean("joyConVr", true)
|
||||
|
||||
fun setJoyConVr(context: Context, on: Boolean) {
|
||||
@@ -79,6 +144,24 @@ object ControllerPrefs {
|
||||
prefs(context).edit().putBoolean("snap", on).apply()
|
||||
}
|
||||
|
||||
fun layout(context: Context, width: Int, height: Int): Map<String, Pair<Float, Float>> {
|
||||
val raw = prefs(context).getString("layout.${width}x$height", null) ?: return emptyMap()
|
||||
return raw.split(';').mapNotNull { entry ->
|
||||
val (group, pos) = entry.split(':').takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||
val (x, y) = pos.split(',').mapNotNull { it.toFloatOrNull() }.takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||
group to (x to y)
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
fun setLayout(context: Context, width: Int, height: Int, positions: Map<String, Pair<Float, Float>>) {
|
||||
val raw = positions.entries.joinToString(";") { (group, pos) -> "$group:${pos.first},${pos.second}" }
|
||||
prefs(context).edit().putString("layout.${width}x$height", raw).apply()
|
||||
}
|
||||
|
||||
fun resetLayout(context: Context, width: Int, height: Int) {
|
||||
prefs(context).edit().remove("layout.${width}x$height").apply()
|
||||
}
|
||||
|
||||
fun resetAll(context: Context) {
|
||||
prefs(context).edit().clear().putBoolean("rumble", true).apply()
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
/** The on-screen layout each game draws, shared by the in-game Controller page and Settings › Controller. A null game is the default. */
|
||||
object ControlsChoice {
|
||||
const val NEW = "new"
|
||||
const val DEFAULT = "default"
|
||||
|
||||
data class Game(val id: Long, val name: String, val layout: String)
|
||||
|
||||
private fun own(library: InputLibrary, id: String?): String? = id?.takeIf { bindings ->
|
||||
library.bindings.any { it.id == bindings && !it.physical && it.layoutId?.let { l -> library.layouts.any { x -> x.id == l && x.supports(InputRole.PRIMARY) } } == true }
|
||||
}
|
||||
|
||||
private fun own(context: Context, library: InputLibrary, game: Long?) = own(library, GameControls.bindings(context, game))
|
||||
|
||||
/** The input library with [game]'s main-screen layout selected, without saving it. */
|
||||
fun library(context: Context, game: Long?, desktop: Boolean): InputLibrary {
|
||||
val library = InputLibraries.read(context)
|
||||
val chosen = own(context, library, game)
|
||||
return if (chosen == null) library else library.selectPart(desktop, InputRole.PRIMARY, chosen)
|
||||
}
|
||||
|
||||
fun options(context: Context, game: Long?, steamMode: Boolean, gameName: String? = null): List<Pair<String, String>> {
|
||||
val library = InputLibraries.read(context)
|
||||
val own = game != null && game in GameControls.games(context)
|
||||
return (if (own) listOf(DEFAULT to context.getString(R.string.osc_default)) else emptyList()) +
|
||||
listOf(InputLibraries.OVERLAY to context.getString(R.string.osc_layout_gamepad)) +
|
||||
(if (steamMode) listOf(GameControls.STEAM to context.getString(R.string.osc_layout_steam)) else emptyList()) +
|
||||
library.layouts.filter { it.editable && it.supports(InputRole.PRIMARY) && it.id != InputLibraries.OVERLAY }.map { it.id to it.name } +
|
||||
(if (game != null && !gameName.isNullOrBlank()) listOf(NEW to context.getString(R.string.osc_layout_new_for, gameName)) else emptyList())
|
||||
}
|
||||
|
||||
fun current(context: Context, game: Long?, steamMode: Boolean, desktop: Boolean = false): String =
|
||||
if (steamMode && GameControls.steamLayout(context, game)) GameControls.STEAM
|
||||
else library(context, game, desktop).activeLayout(desktop, InputRole.PRIMARY)?.id ?: InputLibraries.OVERLAY
|
||||
|
||||
fun choose(context: Context, game: Long?, id: String, desktop: Boolean, gameName: String? = null) {
|
||||
require(id != NEW)
|
||||
if (id == DEFAULT) { if (game != null) useDefault(context, game); return }
|
||||
val steam = id == GameControls.STEAM
|
||||
val bindings = if (steam) null else {
|
||||
val library = InputLibraries.read(context)
|
||||
val layout = library.layouts.first { it.id == id }
|
||||
library.bindings.firstOrNull { !it.physical && it.layoutId == layout.id && it.compatible(layout) }?.id ?: newInputId().also { newId ->
|
||||
InputLibraries.update(context) { it.withPreset(SavedInputBindings(newId, layout.name, false, layout.id)) }
|
||||
}
|
||||
}
|
||||
if (game != null) GameControls.choose(context, game, bindings, steam, gameName)
|
||||
else {
|
||||
if (bindings != null) InputLibraries.update(context) { it.selectPart(desktop, InputRole.PRIMARY, bindings) }
|
||||
SessionPrefs.setSteamTouchLayout(context, steam)
|
||||
}
|
||||
}
|
||||
|
||||
/** Copies the layout [game] draws now, actions included, into a layout of its own and chooses it for that game only. */
|
||||
fun newForGame(context: Context, game: Long, name: String, desktop: Boolean): Pair<String, String> {
|
||||
val layoutId = newInputId()
|
||||
val bindingsId = newInputId()
|
||||
InputLibraries.update(context) { latest -> copyForGame(context, latest, game, name, desktop, layoutId, bindingsId) }
|
||||
GameControls.choose(context, game, bindingsId, steam = false, name = name)
|
||||
return layoutId to bindingsId
|
||||
}
|
||||
|
||||
/** [latest] with a copy of the layout [game] draws now, actions included, under the given ids. Nothing is chosen for the game. */
|
||||
fun copyForGame(context: Context, latest: InputLibrary, game: Long, name: String, desktop: Boolean, layoutId: String, bindingsId: String): InputLibrary {
|
||||
run {
|
||||
val chosen = own(context, latest, game)
|
||||
val part = (if (chosen == null) latest else latest.selectPart(desktop, InputRole.PRIMARY, chosen)).activePart(desktop, InputRole.PRIMARY)
|
||||
val source = latest.layouts.firstOrNull { it.id == part.layout && it.editable } ?: latest.layouts.first { it.id == InputLibraries.OVERLAY }
|
||||
val actions = latest.bindings.firstOrNull { it.id == part.bindings && it.compatible(source) }
|
||||
?: latest.bindings.firstOrNull { !it.physical && it.compatible(source) }
|
||||
?: SavedInputBindings(bindingsId, source.name, false, source.id)
|
||||
val title = name.trim().take(80).ifEmpty { source.name }
|
||||
return latest.withLayout(source.derived(layoutId, title)).withPreset(actions.copy(id = bindingsId, name = title, layoutId = layoutId))
|
||||
}
|
||||
}
|
||||
|
||||
/** Uses [bindingsId], made by [copyForGame], for [game] only. */
|
||||
fun useForGame(context: Context, game: Long, name: String, bindingsId: String) = GameControls.choose(context, game, bindingsId, steam = false, name = name)
|
||||
|
||||
/** The profile, layout and actions the editor opens for [game], or null when its layout can't be edited here. */
|
||||
fun editTarget(context: Context, game: Long?, desktop: Boolean): Triple<String, String, String>? {
|
||||
val library = library(context, game, desktop)
|
||||
val layout = library.activeLayout(desktop, InputRole.PRIMARY)?.takeIf { it.editable } ?: return null
|
||||
return Triple(library.activeId(desktop), layout.id, library.activePart(desktop, InputRole.PRIMARY).bindings)
|
||||
}
|
||||
|
||||
/** Whether [game] has a layout of its own, rather than the default. */
|
||||
fun hasOwn(context: Context, game: Long?): Boolean = own(context, InputLibraries.read(context), game) != null
|
||||
|
||||
/** Whether saving an edit of [game]'s layout would also change the default or another game. */
|
||||
fun shared(context: Context, game: Long?): Boolean {
|
||||
game ?: return false
|
||||
val library = InputLibraries.read(context)
|
||||
val bindings = own(context, library, game) ?: return true
|
||||
val layout = library.preset(bindings).layoutId
|
||||
fun drawsLayout(id: String) = library.bindings.firstOrNull { it.id == id }?.layoutId == layout
|
||||
return library.usersOfLayout(layout ?: return true).isNotEmpty() ||
|
||||
library.selections.values.any { s -> s.parts[InputRole.PRIMARY]?.let(::drawsLayout) == true } ||
|
||||
GameControls.games(context).any { it != game && own(context, library, it)?.let(::drawsLayout) == true }
|
||||
}
|
||||
|
||||
fun useDefault(context: Context, game: Long) = GameControls.clear(context, game)
|
||||
|
||||
/** Games with a layout of their own, by name. */
|
||||
fun games(context: Context): List<Game> {
|
||||
val library = InputLibraries.read(context)
|
||||
return GameControls.games(context).mapNotNull { id ->
|
||||
val layout = when {
|
||||
GameControls.steamLayout(context, id) -> context.getString(R.string.osc_layout_steam)
|
||||
else -> own(context, library, id)?.let { b -> library.layouts.firstOrNull { it.id == library.preset(b).layoutId }?.name } ?: return@mapNotNull null
|
||||
}
|
||||
val name = GameControls.name(context, id)
|
||||
?: id.takeIf { it in Int.MIN_VALUE..Int.MAX_VALUE }?.let { runCatching { SteamTouchConfig.gameName(context, it.toInt()) }.getOrNull() }
|
||||
?: id.toString()
|
||||
Game(id, name, layout)
|
||||
}.sortedBy { it.name.lowercase() }
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
/** Decides where the on-screen controls go and why they're hidden, from the session's state alone. */
|
||||
object ControlsPresenter {
|
||||
enum class Place { NONE, MAIN, BOTTOM, STEAM }
|
||||
|
||||
data class State(
|
||||
val mode: String,
|
||||
val desktop: Boolean,
|
||||
val virtualPad: Boolean,
|
||||
val covered: Boolean,
|
||||
val controllerInUse: Boolean,
|
||||
val hiddenByTap: Boolean,
|
||||
val steamLayout: Boolean,
|
||||
val bottomScreen: Boolean,
|
||||
)
|
||||
|
||||
data class Plan(val place: Place, val hidden: OnScreenControls.Hidden? = null) {
|
||||
val shown get() = place != Place.NONE && hidden == null
|
||||
}
|
||||
|
||||
fun plan(state: State): Plan = when {
|
||||
state.covered || !state.virtualPad || state.mode == SessionPrefs.OSC_NEVER -> Plan(Place.NONE)
|
||||
state.mode == SessionPrefs.OSC_AUTO && state.desktop -> Plan(Place.NONE)
|
||||
else -> Plan(
|
||||
when {
|
||||
state.bottomScreen -> Place.BOTTOM
|
||||
state.steamLayout -> Place.STEAM
|
||||
else -> Place.MAIN
|
||||
},
|
||||
when {
|
||||
state.hiddenByTap -> OnScreenControls.Hidden.BY_TAP
|
||||
state.mode == SessionPrefs.OSC_AUTO && state.controllerInUse -> OnScreenControls.Hidden.BY_CONTROLLER
|
||||
else -> null
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import kotlin.math.min
|
||||
|
||||
internal class FloatingSteamOverlay(width: Int, height: Int, safe: Rect, density: Float) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
private val left = safe.left / w
|
||||
private val top = safe.top / h
|
||||
private val right = 1f - safe.right / w
|
||||
private val bottom = 1f - safe.bottom / h
|
||||
private val gap = 3f * density
|
||||
private val bottomPadding = 14f * density
|
||||
private val dp = min(density, min(width, height) / 250f)
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, lowerShortcuts: Boolean,
|
||||
rearButtons: Boolean?, trackpads: Boolean?): List<InputSurfaceElement> {
|
||||
val visible = elements.filter { element ->
|
||||
when {
|
||||
!isStock(element) -> true
|
||||
element.control in rear -> rearButtons != false
|
||||
element.control.isTrackpad -> trackpads != false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
val lowered = if (lowerShortcuts) lower(visible) else visible
|
||||
if (rearButtons != true && trackpads != true) return lowered
|
||||
val placed = lowered.toMutableList()
|
||||
fun add(control: InputControl, x: Float, y: List<Float>, widthDp: Int, heightDp: Int, shape: InputButtonShape) {
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) return
|
||||
val element = InputSurfaceElement(control, 0f, 0f, (widthDp * dp / w).coerceAtLeast(.03f),
|
||||
(heightDp * dp / h).coerceAtLeast(.03f), floating = false, buttonShape = shape, showLabel = !control.isTrackpad)
|
||||
findSpace(element, x, y, placed)?.let(placed::add)
|
||||
}
|
||||
if (rearButtons == true) {
|
||||
add(InputControl.L4, .045f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.L5, .045f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R4, .955f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R5, .955f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
}
|
||||
if (trackpads == true) {
|
||||
val rows = listOf(.45f, .36f, .54f, .27f, .63f)
|
||||
add(InputControl.LEFT_PAD, .34f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
add(InputControl.RIGHT_PAD, .66f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
}
|
||||
return placed
|
||||
}
|
||||
|
||||
private fun lower(elements: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val row = elements.filter { isStock(it) && it.control in shortcuts }
|
||||
val occupied = (elements - row.toSet()).toMutableList()
|
||||
val moved = mutableMapOf<String, InputSurfaceElement>()
|
||||
for (element in row.sortedBy { shortcuts.getValue(it.control) }) {
|
||||
val y = bottom - bottomPadding / h - element.height / 2f
|
||||
val position = findSpace(element, shortcuts.getValue(element.control), listOf(y, y - .07f), occupied)
|
||||
?: return elements
|
||||
occupied += position
|
||||
moved[element.id] = position
|
||||
}
|
||||
return elements.map { moved[it.id] ?: it }
|
||||
}
|
||||
|
||||
private fun findSpace(element: InputSurfaceElement, x: Float, rows: List<Float>,
|
||||
occupied: List<InputSurfaceElement>): InputSurfaceElement? {
|
||||
val maxX = right - element.width
|
||||
val maxY = bottom - element.height
|
||||
if (maxX < left || maxY < top) return null
|
||||
for (y in rows) {
|
||||
for (dx in horizontalOffsets) {
|
||||
val candidate = element.copy(
|
||||
x = (x + dx - element.width / 2f).coerceIn(left, maxX),
|
||||
y = (y - element.height / 2f).coerceIn(top, maxY),
|
||||
)
|
||||
if (occupied.none { overlaps(candidate, it) }) return candidate
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun overlaps(a: InputSurfaceElement, b: InputSurfaceElement): Boolean =
|
||||
a.x < b.x + b.width + gap / w && b.x < a.x + a.width + gap / w &&
|
||||
a.y < b.y + b.height + gap / h && b.y < a.y + a.height + gap / h
|
||||
|
||||
private fun isStock(element: InputSurfaceElement) = element.id == "legacy:${element.control.id}"
|
||||
|
||||
private companion object {
|
||||
val rear = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
val shortcuts = mapOf(InputControl.GUIDE to .23f, InputControl.SELECT to .41f, InputControl.START to .59f, InputControl.QAM to .77f)
|
||||
val horizontalOffsets = listOf(0f, -.035f, .035f, -.07f, .07f, -.105f, .105f)
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
/** Which on-screen layout each game uses. Games without a choice use the default profile's main-screen layout. */
|
||||
object GameControls {
|
||||
const val STEAM = "steam"
|
||||
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("game-controls", Context.MODE_PRIVATE)
|
||||
|
||||
/** The main-screen bindings preset saved for [game], whose layout is the one drawn. */
|
||||
fun bindings(context: Context, game: Long?): String? = game?.let { prefs(context).getString("$it.bindings", null) }
|
||||
|
||||
fun steamLayout(context: Context, game: Long?): Boolean {
|
||||
val p = prefs(context)
|
||||
return if (game != null && p.contains("$game.steam")) p.getBoolean("$game.steam", false) else SessionPrefs.steamTouchLayout(context)
|
||||
}
|
||||
|
||||
fun choose(context: Context, game: Long, bindings: String?, steam: Boolean, name: String? = null) {
|
||||
prefs(context).edit().apply { if (bindings == null) remove("$game.bindings") else putString("$game.bindings", bindings) }
|
||||
.apply { if (!name.isNullOrBlank()) putString("$game.name", name) }
|
||||
.putBoolean("$game.steam", steam).apply()
|
||||
}
|
||||
|
||||
/** Games with their own choice, in the order of their ids. */
|
||||
fun games(context: Context): List<Long> = prefs(context).all.keys
|
||||
.filter { it.endsWith(".steam") || it.endsWith(".bindings") }
|
||||
.mapNotNull { it.substringBeforeLast('.').toLongOrNull() }.distinct().sorted()
|
||||
|
||||
fun name(context: Context, game: Long): String? = prefs(context).getString("$game.name", null)
|
||||
|
||||
fun clear(context: Context, game: Long) {
|
||||
prefs(context).edit().remove("$game.bindings").remove("$game.steam").apply()
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ object GamepadGeometry {
|
||||
VIEW, STEAM, QAM, MENU,
|
||||
PANELS,
|
||||
L4, L5, R5, R4,
|
||||
LEFT_TOUCH, RIGHT_TOUCH,
|
||||
}
|
||||
|
||||
data class Box(val cx: Float, val cy: Float, val width: Float, val height: Float) {
|
||||
@@ -27,11 +26,10 @@ object GamepadGeometry {
|
||||
|
||||
fun tall(w: Float, h: Float): Boolean = h >= w * 0.45f
|
||||
|
||||
fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = false, upright: Boolean = false,
|
||||
trackpads: Boolean = false): Map<Slot, Box> {
|
||||
fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false): Map<Slot, Box> {
|
||||
if (w <= 0f || h <= 0f) return emptyMap()
|
||||
if (upright || portraitDock && h >= w * 0.6f && w >= 300 * density && h >= 300 * density) {
|
||||
return portraitLayout(w, h, density, grips, trackpads)
|
||||
if (portraitDock && h >= w * 0.9f && w >= 300 * density && h >= 360 * density) {
|
||||
return portraitLayout(w, h, density)
|
||||
}
|
||||
val pad = 8 * density
|
||||
val buttonH = 40 * density
|
||||
@@ -72,7 +70,6 @@ object GamepadGeometry {
|
||||
else -> 1
|
||||
}
|
||||
middleGrid(columns, gap - 2 * gutter, shoulderY - buttonH / 2f)
|
||||
if (grips) gripsBetween(boxes, w, gap - 2 * gutter, boxes.values.maxOf { if (it.cx in (w - gap) / 2f..(w + gap) / 2f) it.bottom else 0f } + gutter, h - pad, density)
|
||||
} else {
|
||||
val side = min(min(w * 0.5f, h * 0.70f), (w - 2 * gridButton - 2 * gutter) / 1.42f)
|
||||
val main = side * 0.62f
|
||||
@@ -88,75 +85,45 @@ object GamepadGeometry {
|
||||
val gap = w - 2 * (side * 0.40f + main / 2f)
|
||||
val columns = if (gap >= 2 * gridButton) 2 else 1
|
||||
val rows = (middle.size + columns - 1) / columns
|
||||
val gridTop = h - pad - rows * buttonH - (rows - 1) * 10 * density
|
||||
middleGrid(columns, gap - 2 * gutter, gridTop)
|
||||
if (grips) gripsBetween(boxes, w, w - 2 * (side * 0.74f + second / 2f) - 2 * gutter, shoulderY + buttonH / 2f + gutter, gridTop - gutter, density)
|
||||
middleGrid(columns, gap - 2 * gutter, h - pad - rows * buttonH - (rows - 1) * 10 * density)
|
||||
val panelsW = min(112 * density, w - 2 * (side * 0.57f + shoulderW / 2f) - 2 * gutter)
|
||||
if (panelsW >= buttonH) boxes[Slot.PANELS] = Box(w / 2f, shoulderY, panelsW, buttonH)
|
||||
}
|
||||
return boxes
|
||||
}
|
||||
|
||||
/** The back grips in the gap between a landscape panel's two clusters: one row of four, or two rows of two. */
|
||||
private fun gripsBetween(boxes: MutableMap<Slot, Box>, w: Float, span: Float, top: Float, bottom: Float, density: Float) {
|
||||
val gap = 8 * density
|
||||
val minimum = 44 * density
|
||||
val rows = if ((span - 3 * gap) / 4f >= minimum) 1 else if ((span - gap) / 2f >= minimum) 2 else return
|
||||
val perRow = 4 / rows
|
||||
val cellW = ((span - (perRow - 1) * gap) / perRow).coerceAtMost(96 * density)
|
||||
val cellH = ((bottom - top - (rows - 1) * gap) / rows).coerceAtMost(64 * density)
|
||||
if (cellH < minimum) return
|
||||
for ((i, slot) in listOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4).withIndex()) {
|
||||
val col = i % perRow; val row = i / perRow
|
||||
boxes[slot] = Box(w / 2f + (col - (perRow - 1) / 2f) * (cellW + gap), bottom - (rows - 1 - row) * (cellH + gap) - cellH / 2f, cellW, cellH)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The panel under a portrait game: shoulders with View and Menu across the top, the back grips under them when the kit has
|
||||
* them, then the d-pad and face buttons and, along the bottom edge, the sticks or trackpads, each as large as the panel allows.
|
||||
*/
|
||||
private fun portraitLayout(w: Float, h: Float, density: Float, grips: Boolean, trackpads: Boolean): Map<Slot, Box> {
|
||||
private fun portraitLayout(w: Float, h: Float, density: Float): Map<Slot, Box> {
|
||||
val pad = 8 * density
|
||||
val gap = 8 * density
|
||||
val buttonH = 44 * density
|
||||
val boxes = LinkedHashMap<Slot, Box>()
|
||||
val topGap = 4 * density
|
||||
val topW = (w - 2 * pad - 5 * topGap) / 6f
|
||||
val top = listOf(Slot.LEFT_OUTER_SHOULDER, Slot.LEFT_INNER_SHOULDER, Slot.VIEW, Slot.MENU, Slot.RIGHT_INNER_SHOULDER, Slot.RIGHT_OUTER_SHOULDER)
|
||||
for ((i, slot) in top.withIndex()) boxes[slot] = Box(pad + topW / 2f + i * (topW + topGap), pad + buttonH / 2f, topW, buttonH)
|
||||
var areaTop = pad + buttonH + gap
|
||||
if (grips) {
|
||||
val gripW = (w - 2 * pad - 3 * gap) / 4f
|
||||
val gripH = min(56 * density, (h - areaTop) * 0.12f).coerceAtLeast(buttonH)
|
||||
for ((i, slot) in listOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4).withIndex())
|
||||
boxes[slot] = Box(pad + gripW / 2f + i * (gripW + gap), areaTop + gripH / 2f, gripW, gripH)
|
||||
areaTop += gripH + gap
|
||||
}
|
||||
val area = h - pad - areaTop - gap
|
||||
if (trackpads) {
|
||||
val second = min(w * 0.42f, area * 0.5f)
|
||||
val rowH = area - second
|
||||
val col = (w - 2 * pad - 3 * gap) / 4f
|
||||
val stick = min(col, rowH)
|
||||
val rowY = h - pad - rowH / 2f
|
||||
val secondY = areaTop + second / 2f
|
||||
boxes[Slot.LEFT_SECOND] = Box(w * 0.25f, secondY, second, second)
|
||||
boxes[Slot.RIGHT_SECOND] = Box(w * 0.75f, secondY, second, second)
|
||||
boxes[Slot.LEFT_TOUCH] = Box(pad + col / 2f, rowY, col, rowH)
|
||||
boxes[Slot.LEFT_MAIN] = Box(pad + col * 1.5f + gap, rowY, stick, stick)
|
||||
boxes[Slot.RIGHT_MAIN] = Box(w - pad - col * 1.5f - gap, rowY, stick, stick)
|
||||
boxes[Slot.RIGHT_TOUCH] = Box(w - pad - col / 2f, rowY, col, rowH)
|
||||
return boxes
|
||||
}
|
||||
val main = min(w * 0.46f, area * 0.53f)
|
||||
val second = min(w * 0.42f, area - main)
|
||||
val secondY = areaTop + second / 2f
|
||||
val scale = min(1f, (h - 2 * pad - 4 * gap - 3 * buttonH) / (w * 0.7f))
|
||||
val main = w * 0.4f * scale
|
||||
val second = w * 0.3f * scale
|
||||
val mainY = h - pad - main / 2f
|
||||
boxes[Slot.LEFT_SECOND] = Box(w * 0.25f, secondY, second, second)
|
||||
boxes[Slot.RIGHT_SECOND] = Box(w * 0.75f, secondY, second, second)
|
||||
boxes[Slot.LEFT_MAIN] = Box(w * 0.25f, mainY, main, main)
|
||||
boxes[Slot.RIGHT_MAIN] = Box(w * 0.75f, mainY, main, main)
|
||||
val secondY = mainY - main / 2f - gap - second / 2f
|
||||
val shoulderY = secondY - second / 2f - gap - buttonH / 2f
|
||||
val boxes = linkedMapOf(
|
||||
Slot.LEFT_MAIN to Box(w * 0.25f, mainY, main, main),
|
||||
Slot.RIGHT_MAIN to Box(w * 0.75f, mainY, main, main),
|
||||
Slot.LEFT_SECOND to Box(w * 0.25f, secondY, second, second),
|
||||
Slot.RIGHT_SECOND to Box(w * 0.75f, secondY, second, second),
|
||||
)
|
||||
val utilityW = (w - 2 * pad - 3 * gap) / 4f
|
||||
for ((i, slot) in middle.withIndex()) {
|
||||
boxes[slot] = Box(pad + utilityW / 2f + i * (utilityW + gap), pad + buttonH / 2f, utilityW, buttonH)
|
||||
}
|
||||
val gripTop = pad + buttonH + gap
|
||||
val gripH = min(64 * density, shoulderY - buttonH / 2f - gap - gripTop)
|
||||
for ((i, slot) in listOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4).withIndex()) {
|
||||
boxes[slot] = Box(pad + utilityW / 2f + i * (utilityW + gap), gripTop + gripH / 2f, utilityW, gripH)
|
||||
}
|
||||
val panelsW = min(112 * density, w * 0.22f)
|
||||
val shoulderW = (w - 2 * pad - 4 * gap - panelsW) / 4f
|
||||
boxes[Slot.PANELS] = Box(w / 2f, shoulderY, panelsW, buttonH)
|
||||
boxes[Slot.LEFT_OUTER_SHOULDER] = Box(pad + shoulderW / 2f, shoulderY, shoulderW, buttonH)
|
||||
boxes[Slot.LEFT_INNER_SHOULDER] = Box(pad + shoulderW * 1.5f + gap, shoulderY, shoulderW, buttonH)
|
||||
boxes[Slot.RIGHT_INNER_SHOULDER] = Box(w - pad - shoulderW * 1.5f - gap, shoulderY, shoulderW, buttonH)
|
||||
boxes[Slot.RIGHT_OUTER_SHOULDER] = Box(w - pad - shoulderW / 2f, shoulderY, shoulderW, buttonH)
|
||||
return boxes
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,11 @@ import org.json.JSONObject
|
||||
import java.util.UUID
|
||||
|
||||
object InputLibraries {
|
||||
private const val VERSION = 15
|
||||
private const val VERSION = 14
|
||||
private val redesignVersions = 15..16
|
||||
private const val KIT_DPAD = "kit:dpad"
|
||||
private const val KEYBOARD = "builtin:keyboard"
|
||||
private const val REDESIGN_BACKUP = "library-before-controller-revert"
|
||||
private const val KEY = "library"
|
||||
private const val RECOVERY = "library-recovery."
|
||||
const val OVERLAY = "builtin.overlay"
|
||||
@@ -23,16 +27,24 @@ object InputLibraries {
|
||||
fun read(context: Context): InputLibrary {
|
||||
val p = prefs(context)
|
||||
val raw = p.getString(KEY, null)
|
||||
val decoded = raw?.let(::decode)
|
||||
val decoded = raw?.let { decode(it, context) }
|
||||
if (raw != null && decoded == null) return scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, migrate(context))))
|
||||
var library = decoded ?: scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, migrate(context))))
|
||||
val version = raw?.let { JSONObject(it).getInt("version") } ?: 0
|
||||
if (version in redesignVersions && raw != null) {
|
||||
val encoded = encode(library)
|
||||
if (encoded.length > 2_000_000) return library
|
||||
if (!commitWithBackup(p, raw, REDESIGN_BACKUP, encoded)) {
|
||||
android.util.Log.e("InputLibraries", "Could not save the restored input library")
|
||||
return library
|
||||
}
|
||||
}
|
||||
if (version < 5) library = scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, library)))
|
||||
if (version < 11) library = neutralStockLayouts(library)
|
||||
if (version < 10) library = restyleGamepads(context, library)
|
||||
if (version < 12) library = barStockLayouts(library)
|
||||
if (version < 13) library = LegacyScreenKeyMigration.pin(library)
|
||||
if (version < 14) library = deckGamepadSurfaces(context, library)
|
||||
if (version < 15) library = kitGamepads(library)
|
||||
if (version < 6 || !p.contains(LegacyScreenKeyMigration.BACKUP)) {
|
||||
val legacy = LegacyScreenKeyMigration.snapshot(context)
|
||||
if (legacy != null) {
|
||||
@@ -75,24 +87,35 @@ object InputLibraries {
|
||||
fun update(context: Context, change: (InputLibrary) -> InputLibrary): InputLibrary {
|
||||
val p = prefs(context)
|
||||
val stored = p.getString(KEY, null)
|
||||
val invalid = stored != null && decode(stored) == null
|
||||
val invalid = stored != null && decode(stored, context) == null
|
||||
require(!invalid || runCatching { JSONObject(stored!!).getInt("version") }.getOrNull()?.let { it <= VERSION } != false) {
|
||||
"The saved input library cannot be edited by this version."
|
||||
}
|
||||
val updated = change(read(context)).validate()
|
||||
if (invalid) {
|
||||
val backupKey = when {
|
||||
invalid -> RECOVERY + UUID.nameUUIDFromBytes(stored!!.toByteArray(Charsets.UTF_8))
|
||||
stored != null && p.getString(KEY, null) == stored &&
|
||||
JSONObject(stored).getInt("version") in redesignVersions -> REDESIGN_BACKUP
|
||||
else -> null
|
||||
}
|
||||
if (backupKey != null) {
|
||||
val encoded = encode(updated)
|
||||
require(encoded.length <= 2_000_000) { "The input library is too large to save." }
|
||||
val recovery = RECOVERY + UUID.nameUUIDFromBytes(stored!!.toByteArray(Charsets.UTF_8))
|
||||
if (!p.edit().putString(recovery, stored).putString(KEY, encoded).commit()) {
|
||||
// A failed commit has already changed the in-memory preferences; put the previous library back.
|
||||
p.edit().putString(KEY, stored).remove(recovery).apply()
|
||||
error("Could not save the input library and its recovery copy.")
|
||||
check(commitWithBackup(p, requireNotNull(stored), backupKey, encoded)) {
|
||||
"Could not save the input library and its recovery copy."
|
||||
}
|
||||
} else write(context, updated)
|
||||
return updated
|
||||
}
|
||||
|
||||
private fun commitWithBackup(prefs: android.content.SharedPreferences, raw: String, backupKey: String, encoded: String): Boolean {
|
||||
val previousBackup = prefs.getString(backupKey, null)
|
||||
if (prefs.edit().putString(backupKey, raw).putString(KEY, encoded).commit()) return true
|
||||
// SharedPreferences updates its in-memory values even when the disk write fails.
|
||||
prefs.edit().putString(KEY, raw).putString(backupKey, previousBackup).apply()
|
||||
return false
|
||||
}
|
||||
|
||||
private fun write(context: Context, library: InputLibrary) {
|
||||
val encoded = encode(library.validate())
|
||||
require(encoded.length <= 2_000_000) { "The input library is too large to save." }
|
||||
@@ -129,14 +152,27 @@ object InputLibraries {
|
||||
return InputLibrary(profiles, layouts, bindings, selected).validate()
|
||||
}
|
||||
|
||||
fun setAdaptiveSticks(context: Context, layoutId: String, on: Boolean): Boolean = runCatching {
|
||||
update(context) { library ->
|
||||
library.copy(layouts = library.layouts.map { layout ->
|
||||
if (layout.id != layoutId || !layout.editable) layout
|
||||
else layout.copy(elements = layout.elements.map { if (it.kind == InputElementKind.STICK) it.copy(floating = on, hideWhenIdle = on) else it })
|
||||
})
|
||||
}
|
||||
}.onSuccess { ControllerPrefs.setAdaptiveSticks(context, on) }.isSuccess
|
||||
|
||||
fun setQuickButton(context: Context, layoutId: String, button: InputCommand, shown: Boolean): Boolean = runCatching {
|
||||
update(context) { library -> library.layouts.firstOrNull { it.id == layoutId && it.editable }?.let { library.withLayout(it.withQuickButton(button, shown)) } ?: library }
|
||||
}.isSuccess
|
||||
|
||||
fun defaultPositions(context: Context, library: InputLibrary, layout: SavedInputLayout): Pair<List<InputSurfaceElement>, Float>? {
|
||||
val origin = layout.origin ?: layout.id
|
||||
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements to it.aspect }
|
||||
if (origin == OVERLAY) {
|
||||
if (origin == OVERLAY || origin.startsWith("migrated.layout.")) {
|
||||
val (surfaceContext, metrics) = primaryDisplay(context)
|
||||
val w = metrics.widthPixels.coerceAtLeast(1)
|
||||
val h = metrics.heightPixels.coerceAtLeast(1)
|
||||
return KitLayout.elements(surfaceContext, PadKit.current(context), w, h, scale = layout.scale) to w.toFloat() / h
|
||||
val size = if (origin == OVERLAY) listOf(metrics.widthPixels, metrics.heightPixels)
|
||||
else origin.removePrefix("migrated.layout.").split('x').mapNotNull { it.toIntOrNull() }
|
||||
return size.takeIf { it.size == 2 && it.all { side -> side > 0 } }?.let { LegacyGamepadLayout(surfaceContext, it[0], it[1]).elements() to it[0].toFloat() / it[1] }
|
||||
}
|
||||
return library.layouts.firstOrNull { it.id == origin && it.id != layout.id }?.let { it.elements to it.aspect }
|
||||
}
|
||||
@@ -148,12 +184,29 @@ object InputLibraries {
|
||||
return surfaceContext to DisplayMetrics().also { if (display != null) display.getRealMetrics(it) else it.setTo(context.resources.displayMetrics) }
|
||||
}
|
||||
|
||||
private fun restyleGamepads(context: Context, library: InputLibrary): InputLibrary {
|
||||
if (library.layouts.none { it.id == OVERLAY || it.id.startsWith("migrated.layout.") }) return library
|
||||
val (surfaceContext, metrics) = primaryDisplay(context)
|
||||
return library.copy(layouts = library.layouts.map { layout ->
|
||||
val size = when {
|
||||
layout.id == OVERLAY -> listOf(metrics.widthPixels, metrics.heightPixels)
|
||||
layout.id.startsWith("migrated.layout.") -> layout.id.removePrefix("migrated.layout.").split('x').mapNotNull { it.toIntOrNull() }
|
||||
else -> emptyList()
|
||||
}
|
||||
if (size.size != 2 || size.any { it <= 0 }) layout
|
||||
else layout.copy(elements = LegacyGamepadLayout(surfaceContext, size[0], size[1]).restyle(layout.elements))
|
||||
})
|
||||
}
|
||||
|
||||
private fun upgradeOverlay(context: Context, library: InputLibrary): InputLibrary {
|
||||
if (library.layouts.none { it.template == InputLayoutTemplate.OVERLAY }) return library
|
||||
val (surfaceContext, metrics) = primaryDisplay(context)
|
||||
val settings = ControllerPrefs.read(context)
|
||||
val style = InputSurfaceStyle(opacity = settings.opacity)
|
||||
val elements = LegacyGamepadLayout(surfaceContext, metrics.widthPixels.coerceAtLeast(1), metrics.heightPixels.coerceAtLeast(1)).elements()
|
||||
val style = InputSurfaceStyle(settings.tint, settings.opacity)
|
||||
val replacements = library.layouts.filter { it.template == InputLayoutTemplate.OVERLAY }.associate { old ->
|
||||
old.id to old.copy(name = "Gamepad", elements = emptyList(), template = InputLayoutTemplate.CUSTOM, style = style)
|
||||
old.id to old.copy(name = "Gamepad", elements = elements, template = InputLayoutTemplate.CUSTOM, style = style,
|
||||
aspect = (metrics.widthPixels.coerceAtLeast(1).toFloat() / metrics.heightPixels.coerceAtLeast(1)).coerceIn(.05f, 20f))
|
||||
}
|
||||
var result = library.copy(layouts = library.layouts.map { replacements[it.id] ?: it })
|
||||
val migrated = mutableMapOf<Pair<String, String>, String>()
|
||||
@@ -164,8 +217,9 @@ object InputLibraries {
|
||||
val id = migrated.getOrPut(key) {
|
||||
val old = library.preset(part.bindings)
|
||||
val newId = migrationBindingId(result, old.id, layout.id)
|
||||
val clicks = if (settings.stickClick) old.clicks else old.clicks + KitLayout.clickIds.associateWith { InputAction.Disabled }
|
||||
result = result.withPreset(old.copy(id = newId, layoutId = layout.id, clicks = clicks))
|
||||
val keyboard = elements.filter { it.id == "builtin:keyboard" }.associate { it.id to InputAction.Command(InputCommand.KEYBOARD) }
|
||||
val clicks = if (settings.stickClick) old.clicks else old.clicks + elements.filter { it.hasClick }.associate { it.id to InputAction.Disabled }
|
||||
result = result.withPreset(old.copy(id = newId, layoutId = layout.id, elements = old.elements + keyboard, clicks = clicks))
|
||||
newId
|
||||
}
|
||||
part.copy(bindings = id)
|
||||
@@ -174,6 +228,15 @@ object InputLibraries {
|
||||
}
|
||||
val oldBindings = migrated.keys.map { it.first }.toSet()
|
||||
result = result.copy(bindings = result.bindings.filter { it.id !in oldBindings || result.usersOfBindings(it.id).isNotEmpty() })
|
||||
// Older editor layouts were resolution-specific. Keep each as a selectable saved layout.
|
||||
for (key in ControllerPrefs.prefs(context).all.keys.filter { it.startsWith("layout.") }.sorted()) {
|
||||
val size = key.removePrefix("layout.").split('x').mapNotNull { it.toIntOrNull() }
|
||||
if (size.size != 2 || size.any { it <= 0 } || result.layouts.size >= 128) continue
|
||||
if (size[0] == metrics.widthPixels && size[1] == metrics.heightPixels) continue
|
||||
val id = "migrated.$key"
|
||||
if (result.layouts.none { it.id == id }) result = result.withLayout(SavedInputLayout(id, "Gamepad ${size[0]} × ${size[1]}",
|
||||
LegacyGamepadLayout(surfaceContext, size[0], size[1]).elements(), style = style, aspect = (size[0].toFloat() / size[1]).coerceIn(.05f, 20f)))
|
||||
}
|
||||
return result.validate()
|
||||
}
|
||||
|
||||
@@ -239,16 +302,6 @@ object InputLibraries {
|
||||
return library.withLayout(saved.copy(elements = InputStockLayouts.gamepad(leftPad, rightStick))).validate()
|
||||
}
|
||||
|
||||
/** Gamepads saved by the old editor follow the virtual controller's kit again; their positions don't map onto the new controls. */
|
||||
private fun kitGamepads(library: InputLibrary): InputLibrary {
|
||||
return library.copy(layouts = library.layouts.map { layout ->
|
||||
val origin = layout.origin ?: layout.id
|
||||
if (origin != OVERLAY && !origin.startsWith("migrated.layout.")) return@map layout
|
||||
val extras = layout.elements.filterNot { KitLayout.isKit(it.id) }
|
||||
layout.copy(elements = extras, origin = if (layout.id == OVERLAY) null else OVERLAY, aspect = if (extras.isEmpty()) 0f else layout.aspect, scale = 1f)
|
||||
}).validate()
|
||||
}
|
||||
|
||||
private fun migrationBindingId(library: InputLibrary, binding: String, layout: String): String {
|
||||
val seed = JSONArray(listOf(binding, layout)).toString().toByteArray(Charsets.UTF_8)
|
||||
val base = "migrated.bindings." + UUID.nameUUIDFromBytes(seed)
|
||||
@@ -281,7 +334,7 @@ object InputLibraries {
|
||||
.put("elementOpacity", e.opacity.toDouble()).put("buttonShape", e.buttonShape.name).put("showLabel", e.showLabel).put("alwaysShown", e.alwaysShown))
|
||||
layouts.put(JSONObject().put("id", layout.id).put("name", layout.name).put("template", layout.template.name).put("elements", elements)
|
||||
.put("tint", layout.style.tint ?: JSONObject.NULL).put("opacity", layout.style.opacity).put("screen", layout.screen.name).put("aspect", layout.aspect.toDouble()).put("scale", layout.scale.toDouble())
|
||||
.put("hidden", JSONArray(layout.style.hidden.map { it.name }.sorted())).put("origin", layout.origin ?: JSONObject.NULL).put("kitless", layout.kitless))
|
||||
.put("hidden", JSONArray(layout.style.hidden.map { it.name }.sorted())).put("origin", layout.origin ?: JSONObject.NULL))
|
||||
}
|
||||
val bindings = JSONArray()
|
||||
for (b in library.bindings) {
|
||||
@@ -310,22 +363,32 @@ object InputLibraries {
|
||||
.put("profiles", profiles).put("layouts", layouts).put("bindings", bindings).toString()
|
||||
}
|
||||
|
||||
internal fun decode(raw: String): InputLibrary? = runCatching {
|
||||
internal fun decode(raw: String, context: Context? = null): InputLibrary? = runCatching {
|
||||
require(raw.length <= 2_000_000)
|
||||
val doc = JSONObject(raw); require(doc.getInt("version") in 2..VERSION)
|
||||
val doc = JSONObject(raw)
|
||||
val version = doc.getInt("version")
|
||||
val restore = context != null && version in redesignVersions
|
||||
require(version in 2..VERSION || restore)
|
||||
val generated = mutableSetOf<String>()
|
||||
val layouts = doc.getJSONArray("layouts").objects(256).map { layout ->
|
||||
val elements = layout.getJSONArray("elements").objects(64).map { e ->
|
||||
val stored = layout.getJSONArray("elements").objects(64).map { e ->
|
||||
InputSurfaceElement(requireNotNull(InputControl.fromId(e.getString("control"))), e.getDouble("x").toFloat(),
|
||||
e.getDouble("y").toFloat(), e.getDouble("width").toFloat(), e.getDouble("height").toFloat(),
|
||||
e.getString("id"), InputElementKind.valueOf(e.getString("kind")), e.getString("name"),
|
||||
e.optBoolean("floating", true), e.optBoolean("hideWhenIdle", false), e.optBoolean("mouseGestures", false), e.optBoolean("toggle", false), e.optInt("icon", 0), e.optString("image", ""),
|
||||
e.optDouble("elementOpacity", 1.0).toFloat(), InputButtonShape.valueOf(e.optString("buttonShape", InputButtonShape.ROUNDED.name)), e.optBoolean("showLabel", true), e.optBoolean("alwaysShown", false))
|
||||
}
|
||||
SavedInputLayout(layout.getString("id"), layout.getString("name"), elements, InputLayoutTemplate.valueOf(layout.getString("template")),
|
||||
val id = layout.getString("id")
|
||||
val origin = layout.optionalString("origin")
|
||||
val followsGamepad = restore && !layout.optBoolean("kitless") &&
|
||||
(id == OVERLAY || origin == OVERLAY) &&
|
||||
stored.none { it.id.startsWith("legacy:") || it.id == KIT_DPAD || it.id == KEYBOARD }
|
||||
if (followsGamepad) generated += id
|
||||
SavedInputLayout(id, layout.getString("name"), if (restore) stored.map { it.bounded() } else stored, InputLayoutTemplate.valueOf(layout.getString("template")),
|
||||
InputSurfaceStyle(if (!layout.has("tint")) ControllerPrefs.STEAM_BLUE else if (layout.isNull("tint")) null else layout.getInt("tint"), layout.optInt("opacity", 100),
|
||||
layout.optJSONArray("hidden")?.let { hidden -> (0 until hidden.length()).map { InputCommand.valueOf(hidden.getString(it)) }.toSet() }.orEmpty()),
|
||||
InputLayoutScreen.valueOf(layout.optString("screen", InputLayoutScreen.BOTH.name)), layout.optDouble("aspect", 0.0).toFloat(), layout.optionalString("origin"),
|
||||
layout.optDouble("scale", 1.0).toFloat(), layout.optBoolean("kitless", false))
|
||||
InputLayoutScreen.valueOf(layout.optString("screen", InputLayoutScreen.BOTH.name)), layout.optDouble("aspect", 0.0).toFloat(), origin,
|
||||
layout.optDouble("scale", 1.0).toFloat())
|
||||
}
|
||||
val bindings = doc.getJSONArray("bindings").objects(512).map { b ->
|
||||
val controls = b.getJSONObject("controls").actions(28).mapKeys { requireNotNull(InputControl.fromId(it.key)) }
|
||||
@@ -352,9 +415,41 @@ object InputLibraries {
|
||||
value.optBoolean("profileSelected", profile != InputProfiles.AUTO || parts.length() == 0))
|
||||
}
|
||||
}.orEmpty()
|
||||
InputLibrary(profiles, layouts, bindings, doc.getString("selected"), doc.getString("steam"), doc.getString("desktop"), selections).validate()
|
||||
val library = InputLibrary(profiles, layouts, bindings, doc.getString("selected"), doc.getString("steam"), doc.getString("desktop"), selections)
|
||||
(if (restore) restoreGamepads(requireNotNull(context), library, generated) else library).validate()
|
||||
}.getOrNull()
|
||||
|
||||
private fun restoreGamepads(context: Context, library: InputLibrary, generated: Set<String>): InputLibrary {
|
||||
val (display, metrics) = primaryDisplay(context)
|
||||
val height = metrics.heightPixels.coerceAtLeast(1)
|
||||
val layouts = library.layouts.map { layout ->
|
||||
if (layout.id !in generated) return@map layout
|
||||
val width = if (layout.aspect > 0f) (layout.aspect * height).toInt().coerceAtLeast(1)
|
||||
else metrics.widthPixels.coerceAtLeast(1)
|
||||
val gamepad = LegacyGamepadLayout(display, width, height, scale = layout.scale).elements()
|
||||
layout.copy(elements = gamepad.take(64 - layout.elements.size) + layout.elements,
|
||||
aspect = (width.toFloat() / height).coerceIn(.05f, 20f))
|
||||
}
|
||||
val byId = layouts.associateBy { it.id }
|
||||
val bindings = library.bindings.map { preset ->
|
||||
val layout = byId[preset.layoutId] ?: return@map preset
|
||||
val elements = layout.elements.associateBy { it.id }
|
||||
val defaults = layout.elements.mapNotNull { element ->
|
||||
val action = when (element.id) {
|
||||
KEYBOARD -> InputAction.Command(InputCommand.KEYBOARD)
|
||||
KIT_DPAD -> InputAction.Native()
|
||||
else -> return@mapNotNull null
|
||||
}
|
||||
element.id to action
|
||||
}.toMap()
|
||||
preset.copy(
|
||||
elements = defaults + preset.elements.filter { (id, action) -> elements[id]?.let { action.validFor(it) } == true },
|
||||
clicks = preset.clicks.filter { (id, action) -> elements[id]?.hasClick == true && action.validForClick() },
|
||||
)
|
||||
}
|
||||
return library.copy(layouts = layouts, bindings = bindings)
|
||||
}
|
||||
|
||||
private fun JSONArray.objects(limit: Int): List<JSONObject> {
|
||||
require(length() <= limit)
|
||||
return (0 until length()).map { getJSONObject(it) }
|
||||
|
||||
@@ -22,8 +22,6 @@ data class SavedInputLayout(
|
||||
val aspect: Float = 0f,
|
||||
val origin: String? = null,
|
||||
val scale: Float = 1f,
|
||||
/** The player removed every kit control from this gamepad, so it must not follow the virtual controller again. */
|
||||
val kitless: Boolean = false,
|
||||
) {
|
||||
val editable get() = template == InputLayoutTemplate.CUSTOM
|
||||
val quickButtons get() = QUICK_BUTTONS.filter { button -> elements.any { it.quickButton == button } }
|
||||
@@ -51,7 +49,7 @@ data class SavedInputBindings(
|
||||
|
||||
fun action(element: InputSurfaceElement) = elements[element.id]
|
||||
?: if (element.id == "legacy:${element.control.id}") controls[element.control] ?: InputAction.Native()
|
||||
else defaultElementAction(element.id)
|
||||
else InputAction.Disabled
|
||||
|
||||
fun clickAction(element: InputSurfaceElement) = clicks[element.id]
|
||||
?: defaultElementClick(element, action(element)) { controls[it] ?: InputAction.Native() }
|
||||
@@ -138,8 +136,8 @@ data class InputLibrary(
|
||||
fun withPreset(value: SavedInputBindings) = copy(bindings = bindings.filterNot { it.id == value.id } + value)
|
||||
fun withLayout(value: SavedInputLayout) = copy(layouts = layouts.filterNot { it.id == value.id } + value,
|
||||
bindings = bindings.map { preset -> if (preset.layoutId != value.id) preset else preset.copy(
|
||||
elements = preset.elements.filter { (id, action) -> value.element(id)?.let { action.validFor(it) } == true },
|
||||
clicks = preset.clicks.filter { (id, action) -> value.element(id)?.hasClick == true && action.validForClick() }) })
|
||||
elements = preset.elements.filter { (id, action) -> value.elements.any { it.id == id && action.validFor(it) } },
|
||||
clicks = preset.clicks.filter { (id, action) -> value.elements.any { it.id == id && it.hasClick && action.validForClick() } }) })
|
||||
|
||||
fun duplicateProfile(id: String, name: String, newId: String = newInputId(), sharePhysical: Boolean = false): InputLibrary {
|
||||
require(profiles.size < 64)
|
||||
@@ -273,8 +271,8 @@ data class InputLibrary(
|
||||
require(preset.physical || preset.keys.isEmpty())
|
||||
val layout = preset.layoutId?.let { id -> layouts.first { it.id == id } }
|
||||
require(!preset.physical || layout == null && preset.elements.isEmpty() && preset.clicks.isEmpty())
|
||||
require(preset.elements.all { (id, action) -> layout?.element(id)?.let { action.validFor(it) } == true })
|
||||
require(preset.clicks.all { (id, action) -> layout?.element(id)?.hasClick == true && action.validForClick() })
|
||||
require(preset.elements.all { (id, action) -> layout?.elements?.firstOrNull { it.id == id }?.let { action.validFor(it) } == true })
|
||||
require(preset.clicks.all { (id, action) -> layout?.elements?.any { it.id == id && it.hasClick } == true && action.validForClick() })
|
||||
require(preset.keys.all { it.key.device.isNotBlank() && it.key.keyCode >= 0 && it.key.scanCode >= 0 &&
|
||||
it.action.validFor(InputControl.A) && (it.action !is InputAction.Native || it.action.target == null) })
|
||||
}
|
||||
@@ -314,12 +312,3 @@ internal fun InputAction.validFor(element: InputSurfaceElement): Boolean = when
|
||||
element.kind == InputElementKind.TRIGGER -> target == InputControl.LT || target == InputControl.RT
|
||||
else -> target.dimensions == 1 && target != InputControl.LT && target != InputControl.RT
|
||||
}
|
||||
|
||||
/**
|
||||
* A saved element, or the kit control that [id] names: in a layout made from the built-in gamepad every kit control keeps its
|
||||
* binding while it's removed, so Reset or Restore brings it back with its action.
|
||||
*/
|
||||
internal fun SavedInputLayout.element(id: String): InputSurfaceElement? =
|
||||
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf {
|
||||
this.id == InputLibraries.OVERLAY || origin == InputLibraries.OVERLAY || KitLayout.bindsTo(id, elements)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ data class InputProfile(
|
||||
copy(bindings = bindings + (role to (bindings[role].orEmpty() + (control to action))))
|
||||
|
||||
fun elementAction(role: InputRole, id: String, control: InputControl): InputAction =
|
||||
elements[role]?.get(id) ?: if (id == "legacy:${control.id}") action(role, control) else defaultElementAction(id)
|
||||
elements[role]?.get(id) ?: if (id == "legacy:${control.id}") action(role, control) else InputAction.Disabled
|
||||
|
||||
fun elementClickAction(role: InputRole, element: InputSurfaceElement): InputAction = clicks[role]?.get(element.id)
|
||||
?: defaultElementClick(element, elementAction(role, element.id, element.control)) { action(role, it) }
|
||||
@@ -115,10 +115,3 @@ internal fun InputAction.validFor(control: InputControl): Boolean = when (this)
|
||||
is InputAction.Scroll -> control.dimensions == 2 && speed.isFinite() && speed in 1f..60f
|
||||
else -> true
|
||||
}
|
||||
|
||||
/** What an on-screen element with no saved action does: kit controls press their own button, everything else is unassigned. */
|
||||
internal fun defaultElementAction(id: String): InputAction = when (id) {
|
||||
KitLayout.DPAD_ID -> InputAction.Native()
|
||||
KitLayout.KEYBOARD_ID -> InputAction.Command(InputCommand.KEYBOARD)
|
||||
else -> InputAction.Disabled
|
||||
}
|
||||
@@ -38,13 +38,8 @@ data class InputSurfaceElement(
|
||||
) {
|
||||
val hasClick get() = kind == InputElementKind.STICK || kind == InputElementKind.TRACKPAD
|
||||
|
||||
fun bounded() = copy(x = x.coerceIn(0f, 1f - MIN_SIZE), y = y.coerceIn(0f, 1f - MIN_SIZE),
|
||||
width = width.coerceIn(MIN_SIZE, (1f - x.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)),
|
||||
height = height.coerceIn(MIN_SIZE, (1f - y.coerceIn(0f, 1f - MIN_SIZE)).coerceAtLeast(MIN_SIZE)))
|
||||
|
||||
companion object {
|
||||
const val MIN_SIZE = .01f
|
||||
}
|
||||
fun bounded() = copy(x = x.coerceIn(0f, 0.97f), y = y.coerceIn(0f, 0.97f),
|
||||
width = width.coerceIn(0.03f, (1f - x.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)), height = height.coerceIn(0.03f, (1f - y.coerceIn(0f, 0.97f)).coerceAtLeast(0.03f)))
|
||||
}
|
||||
|
||||
internal val QUICK_BUTTONS = listOf(InputCommand.STEAM, InputCommand.QUICK_ACCESS, InputCommand.KEYBOARD)
|
||||
@@ -56,31 +51,15 @@ val InputSurfaceElement.quickButton: InputCommand? get() = when {
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** Controls whose boxes touch, grown by 15%, scale around one shared anchor so a cluster such as the face buttons keeps its shape. */
|
||||
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> {
|
||||
internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceElement> = map { e ->
|
||||
fun anchor(centre: Float) = when { centre < 1f / 3f -> 0f; centre > 2f / 3f -> 1f; else -> .5f }
|
||||
val group = IntArray(size) { it }
|
||||
fun root(i: Int): Int = if (group[i] == i) i else root(group[i]).also { group[i] = it }
|
||||
for (i in indices) for (j in i + 1 until size) {
|
||||
val a = this[i]; val b = this[j]
|
||||
val near = kotlin.math.abs(a.x + a.width / 2 - b.x - b.width / 2) < (a.width + b.width) / 2 * 1.15f &&
|
||||
kotlin.math.abs(a.y + a.height / 2 - b.y - b.height / 2) < (a.height + b.height) / 2 * 1.15f
|
||||
if (near) group[root(i)] = root(j)
|
||||
}
|
||||
val anchors = indices.groupBy(::root).mapValues { (_, members) ->
|
||||
anchor(members.map { this[it].x + this[it].width / 2 }.average().toFloat()) to anchor(members.map { this[it].y + this[it].height / 2 }.average().toFloat())
|
||||
}
|
||||
return mapIndexed { i, e -> e.scaledAround(factor, anchors.getValue(root(i))) }
|
||||
}
|
||||
|
||||
private fun InputSurfaceElement.scaledAround(factor: Float, anchor: Pair<Float, Float>): InputSurfaceElement {
|
||||
val e = this
|
||||
val w = (e.width * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
|
||||
val h = (e.height * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
|
||||
val w = (e.width * factor).coerceIn(.03f, 1f)
|
||||
val h = (e.height * factor).coerceIn(.03f, 1f)
|
||||
val cx = e.x + e.width / 2
|
||||
val cy = e.y + e.height / 2
|
||||
val (ax, ay) = anchor
|
||||
return e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
|
||||
val ax = anchor(cx)
|
||||
val ay = anchor(cy)
|
||||
e.copy(x = (ax + (cx - ax) * factor - w / 2).coerceIn(0f, 1f - w), y = (ay + (cy - ay) * factor - h / 2).coerceIn(0f, 1f - h),
|
||||
width = w, height = h).bounded()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@ package com.droiddeck.launcher.input
|
||||
class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole, val element: InputSurfaceElement) {
|
||||
private val router = pad.inputRouter
|
||||
private val route = router?.channel(role, element.control, element = element)
|
||||
/** The kit's D-pad keeps each direction's own binding, as the separate direction buttons it replaced did. */
|
||||
private val arms = if (element.id == KitLayout.DPAD_ID && router != null)
|
||||
listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { router.channel(role, it, element = KitLayout.element("legacy:${it.id}")) }
|
||||
else emptyList()
|
||||
private val deck = DeckControls.source(role, routed = true)
|
||||
private val clickDeck = DeckControls.source(role, routed = true)
|
||||
private val clickOwner = Any()
|
||||
@@ -59,15 +55,6 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
fingerDown = down
|
||||
if (latched) 1f else 0f
|
||||
} else value
|
||||
if (arms.isNotEmpty() && route?.action is InputAction.Native) {
|
||||
val ready = route.update(x, y, touching) != null
|
||||
val values = listOf(y < -.5f, x > .5f, y > .5f, x < -.5f).map { if (it && ready) 1f else 0f }
|
||||
val toPad = arms.mapIndexed { i, arm -> arm.update(values[i])?.takeIf { it.isPad }?.let { it to values[i] } }.filterNotNull()
|
||||
if (toPad.isNotEmpty() || nativePad) writePad(this, null) { state -> state.clear(); for ((t, v) in toPad) state.add(t, v) }
|
||||
nativePad = toPad.isNotEmpty()
|
||||
InputTiming.end(timing)
|
||||
return
|
||||
}
|
||||
val target = if (router == null) element.control else route?.update(x, y, touching)
|
||||
val toPad = target?.isPad == true
|
||||
val toDeck = target != null && !target.isPad
|
||||
@@ -88,7 +75,6 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
fun cancel() {
|
||||
if (closed) return
|
||||
route?.takeIf { it.action is InputAction.Command }?.release()
|
||||
arms.filter { it.action is InputAction.Command }.forEach { it.release() }
|
||||
update(0f)
|
||||
}
|
||||
|
||||
@@ -126,13 +112,13 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
|
||||
closed = true
|
||||
router?.removeSnapshot(snapshot)
|
||||
releaseNative(); resetLatch()
|
||||
route?.close(); arms.forEach { it.close() }; clickRoute?.close(); gestureWheel?.close(); gestureRight?.close(); gestureMiddle?.close(); deck.close(); clickDeck.close()
|
||||
route?.close(); clickRoute?.close(); gestureWheel?.close(); gestureRight?.close(); gestureMiddle?.close(); deck.close(); clickDeck.close()
|
||||
}
|
||||
|
||||
fun release() {
|
||||
if (closed) return
|
||||
releaseNative(); resetLatch()
|
||||
route?.release(); arms.forEach { it.release() }; clickRoute?.release(); gestureWheel?.release(); gestureRight?.release(); gestureMiddle?.release()
|
||||
route?.release(); clickRoute?.release(); gestureWheel?.release(); gestureRight?.release(); gestureMiddle?.release()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Places a virtual controller's default on-screen controls. Each kit is drawn on a 1600 × 900 reference screen; controls keep
|
||||
* their distance from the nearest edge, so wider screens spread them apart instead of stretching them. Clusters such as the face
|
||||
* buttons are placed by their centre so they move as one, and the row along the bottom-left edge always starts after DroidDeck's
|
||||
* corner button.
|
||||
*/
|
||||
object KitLayout {
|
||||
const val DPAD_ID = "kit:dpad"
|
||||
const val KEYBOARD_ID = "builtin:keyboard"
|
||||
|
||||
/** Whether [id] names one of a kit's own controls rather than a key or control the player added. */
|
||||
fun isKit(id: String) = id.startsWith("legacy:") || id == DPAD_ID || id == KEYBOARD_ID
|
||||
|
||||
/** The control a kit id stands for in a layout that keeps no kit positions, so bindings saved for it stay valid. */
|
||||
fun element(id: String): InputSurfaceElement? = when {
|
||||
id == DPAD_ID -> InputSurfaceElement(InputControl.LS, 0f, 0f, .1f, .1f, id, InputElementKind.DPAD)
|
||||
id == KEYBOARD_ID -> InputSurfaceElement(InputControl.A, 0f, 0f, .1f, .1f, id)
|
||||
id.startsWith("legacy:") -> InputControl.entries.firstOrNull { "legacy:${it.id}" == id }
|
||||
?.let { InputSurfaceElement(it, 0f, 0f, .1f, .1f, id, InputElementKind.from(it)) }
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** The direction buttons the kit's D-pad stands in for; their saved overrides stay with the D-pad. */
|
||||
val dpadDirectionIds = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { "legacy:${it.id}" }
|
||||
|
||||
/** Whether a binding for [id] belongs to a layout made of [elements]. */
|
||||
fun bindsTo(id: String, elements: List<InputSurfaceElement>) =
|
||||
elements.any { it.id == id } || id in dpadDirectionIds && elements.any { it.id == DPAD_ID }
|
||||
|
||||
/** Every kit control that has a click, across all virtual controllers. */
|
||||
val clickIds = listOf(InputControl.LS, InputControl.RS, InputControl.LEFT_PAD, InputControl.RIGHT_PAD).map { "legacy:${it.id}" }
|
||||
private const val REF_W = 1600f
|
||||
private const val REF_H = 900f
|
||||
/** The widest pair of side controls on any kit: a larger size never pushes the two halves, or the rows, into each other. */
|
||||
private const val MIN_SPAN = 1200f
|
||||
private const val MAX_HEIGHT_MM = 80f
|
||||
/** The smallest half-size of any kit control in reference units. */
|
||||
private const val SMALLEST_HALF = 26f
|
||||
private const val CORNER_DP = 52f
|
||||
private const val ROW_DP = 60f
|
||||
private const val BUTTON_DP = 44f
|
||||
private const val GAP_DP = 8f
|
||||
|
||||
private class Spec(val control: InputControl, val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw, val id: String = "legacy:${control.id}",
|
||||
val kind: InputElementKind = InputElementKind.from(control), val shape: InputButtonShape = InputButtonShape.CIRCLE, val icon: Int = 0, val name: String = control.label,
|
||||
val ax: Float = cx, val ay: Float = cy)
|
||||
|
||||
private fun shoulders() = listOf(
|
||||
Spec(InputControl.LT, 140f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.LB, 140f, 148f, 88f, 30f, shape = InputButtonShape.PILL),
|
||||
Spec(InputControl.RT, 1460f, 66f, 88f, 34f, shape = InputButtonShape.PILL), Spec(InputControl.RB, 1460f, 148f, 88f, 30f, shape = InputButtonShape.PILL))
|
||||
|
||||
private fun face(cx: Float, cy: Float, r: Float, off: Float) = listOf(
|
||||
Spec(InputControl.Y, cx, cy - off, r, ax = cx, ay = cy), Spec(InputControl.X, cx - off, cy, r, ax = cx, ay = cy),
|
||||
Spec(InputControl.B, cx + off, cy, r, ax = cx, ay = cy), Spec(InputControl.A, cx, cy + off, r, ax = cx, ay = cy))
|
||||
|
||||
private fun dpad(cx: Float, cy: Float, half: Float) =
|
||||
Spec(InputControl.LS, cx, cy, half, id = DPAD_ID, kind = InputElementKind.DPAD, shape = InputButtonShape.ROUNDED, name = "D-pad")
|
||||
|
||||
private fun keyboard(cx: Float) = Spec(InputControl.A, cx, 848f, 46f, id = KEYBOARD_ID, icon = InputButtonIcons.KEYBOARD, name = "Keyboard")
|
||||
|
||||
private fun specs(kit: PadKit): List<Spec> = when {
|
||||
kit.steam -> shoulders() + listOf(
|
||||
Spec(InputControl.L4, 30f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.L5, 30f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
|
||||
Spec(InputControl.R4, 1570f, 470f, 30f, 58f, shape = InputButtonShape.ROUNDED), Spec(InputControl.R5, 1570f, 590f, 30f, 58f, shape = InputButtonShape.ROUNDED),
|
||||
dpad(220f, 345f, 150f)) + face(1375f, 345f, 58f, 96f) + listOf(
|
||||
Spec(InputControl.LS, 290f, 640f, 96f), Spec(InputControl.RS, 1310f, 640f, 96f),
|
||||
Spec(InputControl.LEFT_PAD, 470f, 360f, 88f, shape = InputButtonShape.ROUNDED), Spec(InputControl.RIGHT_PAD, 1130f, 360f, 88f, shape = InputButtonShape.ROUNDED),
|
||||
Spec(InputControl.SELECT, 660f, 150f, 46f, 26f, shape = InputButtonShape.PILL), Spec(InputControl.START, 940f, 150f, 46f, 26f, shape = InputButtonShape.PILL),
|
||||
Spec(InputControl.GUIDE, 370f, 852f, 66f, 30f, shape = InputButtonShape.PILL), Spec(InputControl.QAM, 1230f, 852f, 66f, 30f, shape = InputButtonShape.PILL),
|
||||
keyboard(136f))
|
||||
kit.playStation -> shoulders() + listOf(dpad(250f, 395f, 125f)) + face(1350f, 395f, 58f, 96f) + listOf(
|
||||
Spec(InputControl.LS, 565f, 690f, 100f), Spec(InputControl.RS, 1035f, 690f, 100f),
|
||||
Spec(InputControl.L3, 430f, 590f, 42f, ax = 565f, ay = 690f), Spec(InputControl.R3, 1170f, 590f, 42f, ax = 1035f, ay = 690f),
|
||||
Spec(InputControl.SELECT, 640f, 150f, 50f, 30f, shape = InputButtonShape.PILL), Spec(InputControl.START, 960f, 150f, 50f, 30f, shape = InputButtonShape.PILL),
|
||||
Spec(InputControl.GUIDE, 800f, 250f, 46f), Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
|
||||
else -> shoulders() + listOf(Spec(InputControl.LS, 235f, 400f, 104f), dpad(470f, 675f, 118f)) + face(1375f, 400f, 58f, 94f) + listOf(
|
||||
Spec(InputControl.RS, 1130f, 690f, 104f), Spec(InputControl.L3, 385f, 290f, 42f, ax = 235f, ay = 400f), Spec(InputControl.R3, 1290f, 790f, 42f, ax = 1130f, ay = 690f),
|
||||
Spec(InputControl.SELECT, 690f, 162f, 38f), Spec(InputControl.GUIDE, 800f, 162f, 54f), Spec(InputControl.START, 910f, 162f, 38f),
|
||||
Spec(InputControl.QAM, 220f, 848f, 46f), keyboard(136f))
|
||||
}
|
||||
|
||||
/** The default controls for [kit] on a [width] × [height] screen. */
|
||||
fun elements(context: Context, kit: PadKit, width: Int, height: Int, inset: Rect = Rect(), scale: Float = 1f): List<InputSurfaceElement> {
|
||||
if (width <= 0 || height <= 0) return emptyList()
|
||||
// Insets stay as reported unless what's left is too small to keep every control above the minimum element size.
|
||||
val smallestUnit = InputSurfaceElement.MIN_SIZE * max(width, height) / (2 * SMALLEST_HALF)
|
||||
fun fit(a: Int, b: Int, side: Int, reference: Float): Pair<Int, Int> {
|
||||
val first = a.coerceAtLeast(0); val second = b.coerceAtLeast(0)
|
||||
val room = (side - (smallestUnit * reference).toInt() - 1).coerceAtLeast(0)
|
||||
return if (first + second <= room) first to second else (first.toLong() * room / (first + second)).toInt() to (second.toLong() * room / (first + second)).toInt()
|
||||
}
|
||||
val (left, right) = fit(inset.left, inset.right, width, MIN_SPAN)
|
||||
val (top, bottom) = fit(inset.top, inset.bottom, height, REF_H)
|
||||
val safe = Rect(left, top, right, bottom)
|
||||
if (height > width) return portrait(context, kit, width, height, safe, scale)
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val unit = (min(w / REF_W, h / REF_H) * cap(context, min(width, height)) * scale).coerceAtMost(min((w - safe.left - safe.right).coerceAtLeast(1f) / MIN_SPAN, (h - safe.top - safe.bottom).coerceAtLeast(1f) / REF_H))
|
||||
fun x(ref: Float) = when {
|
||||
ref < REF_W / 3f -> safe.left + ref * unit
|
||||
ref > REF_W * 2f / 3f -> w - safe.right - (REF_W - ref) * unit
|
||||
else -> (w / 2f + (ref - REF_W / 2f) * unit).between(safe.left + ref * unit, w - safe.right - (REF_W - ref) * unit)
|
||||
}
|
||||
fun y(ref: Float) = when {
|
||||
ref < REF_H / 3f -> safe.top + ref * unit
|
||||
ref > REF_H * 2f / 3f -> h - safe.bottom - (REF_H - ref) * unit
|
||||
else -> (h / 2f + (ref - REF_H / 2f) * unit).between(safe.top + ref * unit, h - safe.bottom - (REF_H - ref) * unit)
|
||||
}
|
||||
val density = context.resources.displayMetrics.density
|
||||
var edge = safe.left + CORNER_DP * density
|
||||
val specs = specs(kit)
|
||||
val row = specs.filter { it.cy > REF_H * .88f && it.cx < REF_W / 3f }.sortedBy { it.cx }.associateWith { s ->
|
||||
val hw = s.hw * unit
|
||||
max(x(s.cx), edge + hw).also { edge = it + hw + GAP_DP * density }
|
||||
}
|
||||
return specs.map { s ->
|
||||
val cx = row[s] ?: (x(s.ax) + (s.cx - s.ax) * unit); val cy = y(s.ay) + (s.cy - s.ay) * unit; val hw = s.hw * unit; val hh = s.hh * unit
|
||||
InputSurfaceElement(s.control, (cx - hw) / w, (cy - hh) / h, 2 * hw / w, 2 * hh / h, s.id, s.kind, if (s.name == s.control.label) kit.name(s.control) else s.name,
|
||||
floating = s.kind == InputElementKind.STICK, buttonShape = s.shape, icon = s.icon).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A portrait surface gets the same pad as the panel under the game, in the lower part of the screen, with the keyboard,
|
||||
* Steam, Quick Access and stick-click buttons in a row along the bottom edge that starts after DroidDeck's corner button.
|
||||
*/
|
||||
private fun portrait(context: Context, kit: PadKit, width: Int, height: Int, safe: Rect, scale: Float): List<InputSurfaceElement> {
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val density = context.resources.displayMetrics.density
|
||||
val row = ROW_DP * density
|
||||
val inner = (w - safe.left - safe.right).coerceAtLeast(1f)
|
||||
val area = (min(h * .6f, inner * 1.15f) * scale).coerceAtMost(h - safe.top - safe.bottom - row).coerceAtLeast(1f)
|
||||
val top = h - safe.bottom - row - area
|
||||
val pad = dock(context, kit, inner.toInt(), area.toInt(), true, InputControl.LS, InputControl.RS, upright = true).map { e ->
|
||||
e.copy(x = (safe.left + e.x * inner) / w, y = (top + e.y * area) / h, width = e.width * inner / w, height = e.height * area / h,
|
||||
floating = e.kind == InputElementKind.STICK)
|
||||
}
|
||||
val specs = specs(kit)
|
||||
fun spec(control: InputControl, id: String = "legacy:${control.id}") = specs.firstOrNull { it.control == control && it.id == id }
|
||||
val gap = GAP_DP * density
|
||||
val leftRow = listOfNotNull(spec(InputControl.A, KEYBOARD_ID), spec(InputControl.GUIDE).takeIf { kit.steam }, spec(InputControl.L3))
|
||||
val rightRow = listOfNotNull(spec(InputControl.QAM), spec(InputControl.GUIDE).takeIf { !kit.steam }, spec(InputControl.R3))
|
||||
val start = safe.left + CORNER_DP * density
|
||||
val span = (w - safe.right - gap - start - gap * (leftRow.size + rightRow.size - 1)).coerceAtLeast(1f)
|
||||
val size = min(BUTTON_DP * density, span / (leftRow + rightRow).sumOf { (it.hw / it.hh).toDouble() }.toFloat())
|
||||
val cy = h - safe.bottom - row / 2f
|
||||
val placed = mutableListOf<InputSurfaceElement>()
|
||||
fun put(s: Spec, cx: Float) {
|
||||
val bw = size * s.hw / s.hh
|
||||
placed += InputSurfaceElement(s.control, (cx - bw / 2) / w, (cy - size / 2) / h, bw / w, size / h, s.id, s.kind,
|
||||
if (s.name == s.control.label) kit.name(s.control) else s.name, buttonShape = s.shape, icon = s.icon)
|
||||
}
|
||||
var left = start
|
||||
for (s in leftRow) {
|
||||
val bw = size * s.hw / s.hh
|
||||
put(s, left + bw / 2); left += bw + gap
|
||||
}
|
||||
var right = w - safe.right - gap
|
||||
for (s in rightRow) {
|
||||
val bw = size * s.hw / s.hh
|
||||
put(s, right - bw / 2); right -= bw + gap
|
||||
}
|
||||
return pad + placed
|
||||
}
|
||||
|
||||
/** Controls for the panel below the game, in [GamepadGeometry]'s slots. */
|
||||
fun dock(context: Context, kit: PadKit, width: Int, height: Int, portrait: Boolean, left: InputControl, right: InputControl,
|
||||
upright: Boolean = false): List<InputSurfaceElement> {
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright,
|
||||
trackpads = kit.steam)
|
||||
val placed = mutableListOf<InputSurfaceElement>()
|
||||
fun put(control: InputControl, box: GamepadGeometry.Box?, shape: InputButtonShape, id: String = "legacy:${control.id}",
|
||||
kind: InputElementKind = InputElementKind.from(control), name: String = kit.name(control)) {
|
||||
val b = box ?: return
|
||||
placed += InputSurfaceElement(control, b.left / w, b.top / h, b.width / w, b.height / h, id, kind, name, floating = false, buttonShape = shape).bounded()
|
||||
}
|
||||
fun square(box: GamepadGeometry.Box?) = box?.let { val side = min(it.width, it.height); GamepadGeometry.Box(it.cx, it.cy, side, side) }
|
||||
val four = GamepadGeometry.Slot.LEFT_TOUCH in boxes
|
||||
val leftMain = if (four || !kit.steam && left == InputControl.LEFT_PAD) InputControl.LS else left
|
||||
val rightMain = if (four || !kit.steam && right == InputControl.RIGHT_PAD) InputControl.RS else right
|
||||
if (four) {
|
||||
put(InputControl.LEFT_PAD, boxes[GamepadGeometry.Slot.LEFT_TOUCH], InputButtonShape.ROUNDED)
|
||||
put(InputControl.RIGHT_PAD, boxes[GamepadGeometry.Slot.RIGHT_TOUCH], InputButtonShape.ROUNDED)
|
||||
}
|
||||
put(leftMain, square(boxes[GamepadGeometry.Slot.LEFT_MAIN]), InputButtonShape.CIRCLE)
|
||||
put(InputControl.LS, square(boxes[GamepadGeometry.Slot.LEFT_SECOND]), InputButtonShape.ROUNDED, DPAD_ID, InputElementKind.DPAD, "D-pad")
|
||||
put(rightMain, square(boxes[GamepadGeometry.Slot.RIGHT_MAIN]), InputButtonShape.CIRCLE)
|
||||
square(boxes[GamepadGeometry.Slot.RIGHT_SECOND])?.let { b ->
|
||||
val r = b.width * .17f; val off = b.width * .3f
|
||||
listOf(InputControl.Y to (0f to -1f), InputControl.B to (1f to 0f), InputControl.A to (0f to 1f), InputControl.X to (-1f to 0f)).forEach { (c, d) ->
|
||||
put(c, GamepadGeometry.Box(b.cx + d.first * off, b.cy + d.second * off, 2 * r, 2 * r), InputButtonShape.CIRCLE)
|
||||
}
|
||||
}
|
||||
put(InputControl.LT, boxes[GamepadGeometry.Slot.LEFT_OUTER_SHOULDER], InputButtonShape.PILL)
|
||||
put(InputControl.LB, boxes[GamepadGeometry.Slot.LEFT_INNER_SHOULDER], InputButtonShape.PILL)
|
||||
put(InputControl.RB, boxes[GamepadGeometry.Slot.RIGHT_INNER_SHOULDER], InputButtonShape.PILL)
|
||||
put(InputControl.RT, boxes[GamepadGeometry.Slot.RIGHT_OUTER_SHOULDER], InputButtonShape.PILL)
|
||||
put(InputControl.SELECT, boxes[GamepadGeometry.Slot.VIEW], InputButtonShape.PILL)
|
||||
put(InputControl.START, boxes[GamepadGeometry.Slot.MENU], InputButtonShape.PILL)
|
||||
if (kit.steam) listOf(InputControl.L4 to GamepadGeometry.Slot.L4, InputControl.L5 to GamepadGeometry.Slot.L5,
|
||||
InputControl.R5 to GamepadGeometry.Slot.R5, InputControl.R4 to GamepadGeometry.Slot.R4).forEach { (c, slot) -> put(c, boxes[slot], InputButtonShape.ROUNDED) }
|
||||
return placed
|
||||
}
|
||||
|
||||
private fun cap(context: Context, shortSide: Int): Float {
|
||||
val metrics = context.resources.displayMetrics
|
||||
val nominal = metrics.densityDpi.toFloat()
|
||||
val dpi = metrics.ydpi.takeIf { it > nominal * .6f && it < nominal * 1.6f } ?: nominal
|
||||
val mm = shortSide / dpi * 25.4f
|
||||
return min(1f, MAX_HEIGHT_MM / max(mm, 1f))
|
||||
}
|
||||
|
||||
/** The middle band never comes closer to an edge than the edge rows' own reference spacing allows. */
|
||||
private fun Float.between(low: Float, high: Float) = coerceIn(low, max(low, high))
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import kotlin.math.*
|
||||
|
||||
internal class LegacyGamepadLayout(private val context: Context, private val width: Int, private val height: Int, private val safe: Rect = Rect(),
|
||||
private val scale: Float = 1f) {
|
||||
private val resources get() = context.resources
|
||||
private val settings = ControllerPrefs.read(context)
|
||||
private var fit = 1f
|
||||
private class Control(val id: String, val group: String, val stick: Int, val radiusDp: Float, val offsetXDp: Float, val offsetYDp: Float) {
|
||||
var radius = 0f
|
||||
var cx = 0f
|
||||
var cy = 0f
|
||||
val halfW get() = if (id in shoulderIds) radius * SHOULDER_WIDTH else radius
|
||||
val halfH get() = if (id in shoulderIds) radius * SHOULDER_HEIGHT else radius
|
||||
}
|
||||
private val controls = listOf(
|
||||
Control("up", "dpad", -1, 30f, 0f, -50f),
|
||||
Control("right", "dpad", -1, 30f, 50f, 0f),
|
||||
Control("down", "dpad", -1, 30f, 0f, 50f),
|
||||
Control("left", "dpad", -1, 30f, -50f, 0f),
|
||||
Control("ls", "ls", 0, 48f, 0f, 0f),
|
||||
Control("rs", "rs", 1, 48f, 0f, 0f),
|
||||
Control("a", "face", -1, 30f, 0f, 50f),
|
||||
Control("b", "face", -1, 30f, 50f, 0f),
|
||||
Control("x", "face", -1, 30f, -50f, 0f),
|
||||
Control("y", "face", -1, 30f, 0f, -50f),
|
||||
Control("lb", "lb", -1, 24f, 0f, 0f),
|
||||
Control("rb", "rb", -1, 24f, 0f, 0f),
|
||||
Control("lt", "lt", -1, 24f, 0f, 0f),
|
||||
Control("rt", "rt", -1, 24f, 0f, 0f),
|
||||
Control("select", "select", -1, 20f, 0f, 0f),
|
||||
Control("start", "start", -1, 20f, 0f, 0f),
|
||||
Control("guide", "guide", -1, 22f, 0f, 0f),
|
||||
Control("qam", "qam", -1, 22f, 0f, 0f),
|
||||
)
|
||||
|
||||
private val groups = controls.map { it.group }.distinct()
|
||||
|
||||
private fun dp(value: Float) = value * resources.displayMetrics.density
|
||||
|
||||
private fun scaled(value: Float) = dp(value) * settings.size / 100f * scale * fit
|
||||
|
||||
private fun fitScale(): Float {
|
||||
val metrics = resources.displayMetrics
|
||||
val heightMm = (height - safe.top - safe.bottom) / pxPerMm(metrics.ydpi)
|
||||
val faceMm = dp(60f) / pxPerMm(metrics.xdpi)
|
||||
val floor = (MIN_FACE_MM / faceMm).coerceAtMost(1f)
|
||||
return (heightMm / FULL_SIZE_HEIGHT_MM).coerceIn(floor, 1f)
|
||||
}
|
||||
|
||||
private fun pxPerMm(dpi: Float): Float {
|
||||
val nominal = resources.displayMetrics.densityDpi.toFloat()
|
||||
return (if (dpi > nominal * 0.6f && dpi < nominal * 1.6f) dpi else nominal) / 25.4f
|
||||
}
|
||||
|
||||
private fun placeAuto(w: Float, h: Float) {
|
||||
val metrics = resources.displayMetrics
|
||||
val mmX = pxPerMm(metrics.xdpi)
|
||||
val mmY = pxPerMm(metrics.ydpi)
|
||||
val usableW = w - safe.left - safe.right
|
||||
val usableH = h - safe.top - safe.bottom
|
||||
val inboard = (0.17f * usableW / mmX).coerceIn(24f, 40f) * mmX
|
||||
val lift = (0.285f * usableH / mmY).coerceIn(22f, 45f) * mmY
|
||||
val gap = dp(12f)
|
||||
val floor = BOTTOM_MARGIN_MM * mmY
|
||||
val drop = max(drop("dpad", "ls", gap), drop("rs", "face", gap))
|
||||
val restY = min(h - safe.bottom - lift, h - safe.bottom - floor - drop)
|
||||
put("ls", safe.left + inboard, restY)
|
||||
put("face", w - safe.right - inboard, restY)
|
||||
besideBelow("dpad", "ls", 1f, gap, floor)
|
||||
besideBelow("rs", "face", -1f, gap, floor)
|
||||
val phone = usableH / mmY < PHONE_MAX_HEIGHT_MM
|
||||
val shoulderY = if (phone) safe.top + floor + halfH("lb")
|
||||
else min(centre("ls").second - extent("ls"), centre("face").second - extent("face")) - gap - halfH("lb")
|
||||
shoulders("ls", "lb", "lt", 1f, gap, shoulderY)
|
||||
shoulders("face", "rb", "rt", -1f, gap, shoulderY)
|
||||
val bottom = h - safe.bottom - floor - extent("guide")
|
||||
val spread = extent("guide") + gap / 2f
|
||||
put("guide", w / 2f - spread, bottom)
|
||||
put("qam", w / 2f + spread, bottom)
|
||||
val inner = max(centre("dpad").first + extent("dpad"), w - centre("rs").first + extent("rs")) + gap + extent("select")
|
||||
put("select", inner, restY)
|
||||
put("start", w - inner, restY)
|
||||
if (phone) {
|
||||
val top = max(centre("lb").first + extent("lb"), w - centre("rb").first + extent("rb")) + gap * 2.5f + extent("select")
|
||||
put("select", top, shoulderY)
|
||||
put("start", w - top, shoulderY)
|
||||
}
|
||||
if (crowded("select", gap) || crowded("start", gap)) {
|
||||
above("select", "dpad", gap)
|
||||
val (sx, sy) = centre("select")
|
||||
put("start", w - sx, sy)
|
||||
if (crowded("start", gap)) above("start", "rs", gap)
|
||||
}
|
||||
if (crowded("guide", gap, gap, "qam") || crowded("qam", gap, gap, "guide")) {
|
||||
val row = centre("select").second
|
||||
put("guide", w / 2f - spread, row)
|
||||
put("qam", w / 2f + spread, row)
|
||||
if (crowded("guide", gap, gap, "qam") || crowded("qam", gap, gap, "guide")) {
|
||||
val top = safe.top + dp(8f) + extent("guide")
|
||||
put("guide", w / 2f - spread, top)
|
||||
put("qam", w / 2f + spread, top)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun drop(group: String, anchor: String, gap: Float): Float =
|
||||
(extent(anchor) + extent(group) + gap) * sin(Math.toRadians(DROP_DEGREES)).toFloat() + extent(group)
|
||||
|
||||
private fun besideBelow(group: String, anchor: String, inward: Float, gap: Float, margin: Float) {
|
||||
val (ax, ay) = centre(anchor)
|
||||
val reach = extent(anchor) + extent(group) + gap
|
||||
val floor = height - safe.bottom - margin - extent(group)
|
||||
val dy = min(reach * sin(Math.toRadians(DROP_DEGREES)).toFloat(), floor - ay)
|
||||
val dx = sqrt(max(0f, reach * reach - dy * dy))
|
||||
put(group, ax + inward * dx, ay + dy)
|
||||
}
|
||||
|
||||
private fun shoulders(anchor: String, bumper: String, trigger: String, inward: Float, gap: Float, y: Float) {
|
||||
val (ax, _) = centre(anchor)
|
||||
val spread = extent(bumper) + gap / 2f
|
||||
put(bumper, ax + inward * spread, y)
|
||||
put(trigger, ax - inward * spread, y)
|
||||
}
|
||||
|
||||
private fun above(group: String, anchor: String, gap: Float) {
|
||||
val (ax, ay) = centre(anchor)
|
||||
put(group, ax, ay - extent(anchor) - gap - extent(group))
|
||||
}
|
||||
|
||||
private fun crowded(group: String, gap: Float, space: Float = gap / 2f, except: String? = null): Boolean {
|
||||
val (x, y) = centre(group)
|
||||
return groups.any { other ->
|
||||
if (other == group || other == except) return@any false
|
||||
val (ox, oy) = centre(other)
|
||||
val dx = x - ox
|
||||
val dy = y - oy
|
||||
sqrt(dx * dx + dy * dy) < extent(group) + extent(other) + space
|
||||
}
|
||||
}
|
||||
|
||||
private fun members(group: String) = controls.filter { it.group == group }
|
||||
|
||||
private fun centre(group: String): Pair<Float, Float> {
|
||||
val first = members(group).first()
|
||||
return (first.cx - scaled(first.offsetXDp)) to (first.cy - scaled(first.offsetYDp))
|
||||
}
|
||||
|
||||
private fun extent(group: String): Float = members(group).maxOf { control ->
|
||||
sqrt(scaled(control.offsetXDp).let { it * it } + scaled(control.offsetYDp).let { it * it }) + control.halfW
|
||||
}
|
||||
|
||||
private fun halfH(group: String): Float = members(group).maxOf { abs(scaled(it.offsetYDp)) + it.halfH }
|
||||
|
||||
private fun put(group: String, x: Float, y: Float) {
|
||||
for (control in members(group)) {
|
||||
control.cx = x + scaled(control.offsetXDp)
|
||||
control.cy = y + scaled(control.offsetYDp)
|
||||
}
|
||||
}
|
||||
|
||||
private fun clamp(group: String) {
|
||||
val list = members(group)
|
||||
val margin = dp(4f)
|
||||
val minX = list.minOf { it.cx - it.halfW } - safe.left - margin
|
||||
val maxX = list.maxOf { it.cx + it.halfW } - (width - safe.right - margin)
|
||||
val minY = list.minOf { it.cy - it.halfH } - safe.top - margin
|
||||
val maxY = list.maxOf { it.cy + it.halfH } - (height - safe.bottom - margin)
|
||||
val dx = if (minX < 0) -minX else if (maxX > 0) -maxX else 0f
|
||||
val dy = if (minY < 0) -minY else if (maxY > 0) -maxY else 0f
|
||||
if (dx == 0f && dy == 0f) return
|
||||
for (control in list) { control.cx += dx; control.cy += dy }
|
||||
}
|
||||
|
||||
|
||||
fun elements(previousStickGeometry: Boolean = false): List<InputSurfaceElement> {
|
||||
fit = fitScale()
|
||||
controls.forEach { it.radius = scaled(it.radiusDp) }
|
||||
placeAuto(width.toFloat(), height.toFloat())
|
||||
for ((group, position) in ControllerPrefs.layout(context, width, height)) {
|
||||
if (group in groups && position.first.isFinite() && position.second.isFinite()) put(group, position.first * width, position.second * height)
|
||||
}
|
||||
groups.forEach(::clamp)
|
||||
val result = controls.filter {
|
||||
settings.mapping[it.id] != ControllerPrefs.OFF && (it.id != "guide" || settings.steamButton) && (it.id != "qam" || settings.qamButton)
|
||||
}.map { c ->
|
||||
InputSurfaceElement(requireNotNull(InputControl.fromId(c.id)), (c.cx - c.halfW) / width, (c.cy - c.halfH) / height,
|
||||
2 * c.halfW / width, 2 * c.halfH / height, floating = settings.adaptiveSticks, hideWhenIdle = c.stick >= 0 && settings.adaptiveSticks,
|
||||
buttonShape = if (c.id in shoulderIds) InputButtonShape.PILL else InputButtonShape.CIRCLE).let { if (previousStickGeometry) widenStickPreviously(it) else widenStick(it) }.bounded()
|
||||
}.toMutableList()
|
||||
if (settings.keyboardButton) result += keyboard()
|
||||
return result
|
||||
}
|
||||
|
||||
fun regenerate(stored: List<InputSurfaceElement>): List<InputSurfaceElement> = withGeometry(stored, elements())
|
||||
|
||||
fun rescale(stored: List<InputSurfaceElement>, from: LegacyGamepadLayout): List<InputSurfaceElement> {
|
||||
val before = from.elements().associateBy { it.id }
|
||||
val after = elements().associateBy { it.id }
|
||||
return stored.map { e ->
|
||||
val b = before[e.id] ?: return@map e
|
||||
val a = after[e.id] ?: return@map e
|
||||
val w = (a.width * e.width / b.width).coerceIn(.03f, 1f)
|
||||
val h = (a.height * e.height / b.height).coerceIn(.03f, 1f)
|
||||
val cx = a.x + a.width / 2 + (e.x + e.width / 2 - b.x - b.width / 2)
|
||||
val cy = a.y + a.height / 2 + (e.y + e.height / 2 - b.y - b.height / 2)
|
||||
e.copy(x = (cx - w / 2).coerceIn(0f, 1f - w), y = (cy - h / 2).coerceIn(0f, 1f - h), width = w, height = h).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
fun buttonsOnly(stored: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val inset = dp(BUTTONS_ONLY_INSET_DP)
|
||||
val bottom = height - safe.bottom - inset
|
||||
val radius = dp(BUTTONS_ONLY_RADIUS_DP)
|
||||
fun pick(control: InputControl, shown: Boolean) = stored.firstOrNull { it.id == "legacy:${control.id}" }
|
||||
?: stored.firstOrNull { it.control == control && it.kind == InputElementKind.BUTTON }
|
||||
?: InputSurfaceElement(control, 0f, 0f, 0f, 0f, buttonShape = InputButtonShape.CIRCLE).takeIf { shown }
|
||||
return listOfNotNull(
|
||||
pick(InputControl.GUIDE, settings.steamButton)?.let { circle(it, safe.left + inset, bottom, radius) },
|
||||
pick(InputControl.QAM, settings.qamButton)?.let { circle(it, width - safe.right - inset, bottom, radius) },
|
||||
stored.firstOrNull { it.id == KEYBOARD_ID }?.let { circle(it, width / 2f, bottom, dp(KEYBOARD_RADIUS_DP)) },
|
||||
)
|
||||
}
|
||||
|
||||
fun dock(stored: List<InputSurfaceElement>, portrait: Boolean, grips: Boolean, left: InputControl = InputControl.LS,
|
||||
right: InputControl = InputControl.RS): List<InputSurfaceElement> {
|
||||
val boxes = GamepadGeometry.layout(width.toFloat(), height.toFloat(), resources.displayMetrics.density, portrait)
|
||||
val placed = mutableListOf<InputSurfaceElement>()
|
||||
fun box(control: InputControl, slot: GamepadGeometry.Slot, shape: InputButtonShape) {
|
||||
val b = boxes[slot] ?: return
|
||||
placed += InputSurfaceElement(control, b.left / width, b.top / height, b.width / width, b.height / height,
|
||||
floating = false, buttonShape = shape).bounded()
|
||||
}
|
||||
fun cross(controls: List<InputControl>, slot: GamepadGeometry.Slot) {
|
||||
val b = boxes[slot] ?: return
|
||||
val side = min(b.width, b.height)
|
||||
val spread = side * CROSS_SPREAD
|
||||
val radius = side * CROSS_RADIUS
|
||||
controls.zip(listOf(0f to -1f, 1f to 0f, 0f to 1f, -1f to 0f)).forEach { (control, direction) ->
|
||||
placed += circle(InputSurfaceElement(control, 0f, 0f, 0f, 0f, buttonShape = InputButtonShape.CIRCLE),
|
||||
b.cx + direction.first * spread, b.cy + direction.second * spread, radius)
|
||||
}
|
||||
}
|
||||
box(left, GamepadGeometry.Slot.LEFT_MAIN, InputButtonShape.CIRCLE)
|
||||
cross(DPAD_ORDER, GamepadGeometry.Slot.LEFT_SECOND)
|
||||
box(right, GamepadGeometry.Slot.RIGHT_MAIN, InputButtonShape.CIRCLE)
|
||||
cross(FACE_ORDER, GamepadGeometry.Slot.RIGHT_SECOND)
|
||||
box(InputControl.LT, GamepadGeometry.Slot.LEFT_OUTER_SHOULDER, InputButtonShape.PILL)
|
||||
box(InputControl.LB, GamepadGeometry.Slot.LEFT_INNER_SHOULDER, InputButtonShape.PILL)
|
||||
box(InputControl.RB, GamepadGeometry.Slot.RIGHT_INNER_SHOULDER, InputButtonShape.PILL)
|
||||
box(InputControl.RT, GamepadGeometry.Slot.RIGHT_OUTER_SHOULDER, InputButtonShape.PILL)
|
||||
box(InputControl.SELECT, GamepadGeometry.Slot.VIEW, InputButtonShape.PILL)
|
||||
box(InputControl.START, GamepadGeometry.Slot.MENU, InputButtonShape.PILL)
|
||||
if (grips) GRIPS.forEach { (control, slot) -> box(control, slot, InputButtonShape.ROUNDED) }
|
||||
val surfaces = listOf(left, right).filter { it.isTrackpad }
|
||||
return withGeometry(stored, placed) + placed.filter { p -> (GRIPS.any { it.first == p.control } || p.control in surfaces) && stored.none { it.id == p.id } }
|
||||
}
|
||||
|
||||
private fun circle(e: InputSurfaceElement, cx: Float, cy: Float, radius: Float) =
|
||||
e.copy(x = (cx - radius) / width, y = (cy - radius) / height, width = 2 * radius / width, height = 2 * radius / height).bounded()
|
||||
|
||||
private fun withGeometry(stored: List<InputSurfaceElement>, placed: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val byId = placed.associateBy { it.id }
|
||||
return stored.mapNotNull { e -> byId[e.id]?.let { e.copy(x = it.x, y = it.y, width = it.width, height = it.height) } }
|
||||
}
|
||||
|
||||
private fun keyboard(): InputSurfaceElement {
|
||||
val radius = dp(KEYBOARD_RADIUS_DP)
|
||||
val cx = safe.left + dp(KEYBOARD_X_DP)
|
||||
val cy = height - safe.bottom - dp(KEYBOARD_Y_DP)
|
||||
return InputSurfaceElement(InputControl.A, (cx - radius) / width, (cy - radius) / height, 2 * radius / width, 2 * radius / height,
|
||||
KEYBOARD_ID, name = "Keyboard", icon = InputButtonIcons.KEYBOARD, buttonShape = InputButtonShape.CIRCLE).bounded()
|
||||
}
|
||||
|
||||
fun restyle(elements: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val dpad = elements.filter { it.id == "legacy:${it.control.id}" && it.control in DPAD && it.buttonShape == InputButtonShape.ROUNDED }
|
||||
val centreX = dpad.map { (it.x + it.width / 2f) * width }.average().toFloat()
|
||||
val centreY = dpad.map { (it.y + it.height / 2f) * height }.average().toFloat()
|
||||
val resize = untouchedDpad(dpad, centreX, centreY)
|
||||
return elements.map { e ->
|
||||
when {
|
||||
e.id == KEYBOARD_ID && e.icon == 0 && e.name == "Keyboard" && e.buttonShape == InputButtonShape.ROUNDED &&
|
||||
e.x == .02f && e.y == .9f && e.width == .12f && e.height == .08f -> keyboard()
|
||||
e.id == "legacy:${e.control.id}" && e.buttonShape == InputButtonShape.ROUNDED -> {
|
||||
val round = e.copy(buttonShape = if (e.control.id in shoulderIds) InputButtonShape.PILL else InputButtonShape.CIRCLE)
|
||||
(if (resize && e.control in DPAD) resizeDpad(round, centreX, centreY) else widenStick(round)).bounded()
|
||||
}
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun untouchedDpad(dpad: List<InputSurfaceElement>, centreX: Float, centreY: Float): Boolean {
|
||||
if (dpad.size != DPAD.size) return false
|
||||
val radius = dpad[0].width * width / 2f
|
||||
val tolerance = 1.5f
|
||||
val offset = radius * LEGACY_DPAD_OFFSET_DP / LEGACY_DPAD_RADIUS_DP
|
||||
return dpad.all { e ->
|
||||
val old = controls.first { it.id == e.control.id }
|
||||
val dx = (e.x + e.width / 2f) * width - centreX
|
||||
val dy = (e.y + e.height / 2f) * height - centreY
|
||||
abs(e.width * width / 2f - radius) <= tolerance && abs(e.height * height / 2f - radius) <= tolerance &&
|
||||
abs(dx - offset * sign(old.offsetXDp)) <= tolerance && abs(dy - offset * sign(old.offsetYDp)) <= tolerance
|
||||
}
|
||||
}
|
||||
|
||||
private fun resizeDpad(e: InputSurfaceElement, centreX: Float, centreY: Float): InputSurfaceElement {
|
||||
val old = controls.first { it.id == e.control.id }
|
||||
val radius = e.width * width / 2f * old.radiusDp / LEGACY_DPAD_RADIUS_DP
|
||||
val cx = centreX + ((e.x + e.width / 2f) * width - centreX) * abs(old.offsetXDp + old.offsetYDp) / LEGACY_DPAD_OFFSET_DP
|
||||
val cy = centreY + ((e.y + e.height / 2f) * height - centreY) * abs(old.offsetXDp + old.offsetYDp) / LEGACY_DPAD_OFFSET_DP
|
||||
return e.copy(x = (cx - radius) / width, y = (cy - radius) / height, width = 2 * radius / width, height = 2 * radius / height)
|
||||
}
|
||||
|
||||
private fun widenStickPreviously(e: InputSurfaceElement): InputSurfaceElement {
|
||||
val extra = e.width * (STICK_REACH - 1f)
|
||||
return when (e.control) {
|
||||
InputControl.LS -> (e.x - extra).coerceAtLeast(0f).let { x -> e.copy(x = x, width = e.x + e.width - x) }
|
||||
InputControl.RS -> e.copy(width = (e.width + extra).coerceAtMost(1f - e.x))
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
|
||||
private fun widenStick(e: InputSurfaceElement): InputSurfaceElement {
|
||||
val extra = e.width * (STICK_REACH - 1f)
|
||||
val width = e.width + extra
|
||||
return when (e.control) {
|
||||
InputControl.LS -> e.copy(x = (e.x - extra).coerceIn(0f, (1f - width).coerceAtLeast(0f)), width = width)
|
||||
InputControl.RS -> e.copy(x = e.x.coerceIn(0f, (1f - width).coerceAtLeast(0f)), width = width)
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
private companion object {
|
||||
const val MIN_FACE_MM = 9.5f
|
||||
const val FULL_SIZE_HEIGHT_MM = 85f
|
||||
const val BOTTOM_MARGIN_MM = 5f
|
||||
const val DROP_DEGREES = 35.0
|
||||
const val PHONE_MAX_HEIGHT_MM = 90f
|
||||
const val SHOULDER_WIDTH = 1.45f
|
||||
const val SHOULDER_HEIGHT = 0.8f
|
||||
val shoulderIds = setOf("lb", "rb", "lt", "rt")
|
||||
const val STICK_REACH = 1.25f
|
||||
const val LEGACY_DPAD_RADIUS_DP = 26f
|
||||
const val LEGACY_DPAD_OFFSET_DP = 52f
|
||||
val DPAD = setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
|
||||
const val KEYBOARD_ID = "builtin:keyboard"
|
||||
const val KEYBOARD_RADIUS_DP = 18f
|
||||
const val KEYBOARD_X_DP = 90f
|
||||
const val KEYBOARD_Y_DP = 34f
|
||||
const val BUTTONS_ONLY_RADIUS_DP = 30f
|
||||
const val BUTTONS_ONLY_INSET_DP = 44f
|
||||
const val CROSS_SPREAD = .30f
|
||||
const val CROSS_RADIUS = .16f
|
||||
val DPAD_ORDER = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
|
||||
val FACE_ORDER = listOf(InputControl.Y, InputControl.B, InputControl.A, InputControl.X)
|
||||
val GRIPS = listOf(InputControl.L4 to GamepadGeometry.Slot.L4, InputControl.L5 to GamepadGeometry.Slot.L5,
|
||||
InputControl.R5 to GamepadGeometry.Slot.R5, InputControl.R4 to GamepadGeometry.Slot.R4)
|
||||
}
|
||||
}
|
||||
@@ -3,78 +3,114 @@ package com.droiddeck.launcher.input
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.view.Gravity
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.WindowInsets
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import com.droiddeck.launcher.ui.PadArt
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayout.Dock? = null) : FrameLayout(context) {
|
||||
/** Why the controls are hidden while the corner button stays. */
|
||||
enum class Hidden { BY_TAP, BY_CONTROLLER }
|
||||
|
||||
private val surface = InputSurfaceView(context, pad, inputRole = InputRole.PRIMARY, haptics = dock != null)
|
||||
private var layout: SavedInputLayout? = null
|
||||
private val safe = Rect()
|
||||
private var viewWidth = 0
|
||||
private var viewHeight = 0
|
||||
private val corner = CornerButton(context)
|
||||
var hidden: Hidden? = null
|
||||
private val placements = object : LinkedHashMap<Placement, List<InputSurfaceElement>>(4, .75f, true) {
|
||||
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<Placement, List<InputSurfaceElement>>) = size > PLACEMENT_CACHE
|
||||
}
|
||||
private val quickToggle = QuickToggle(context)
|
||||
var isButtonsOnly = false
|
||||
private set
|
||||
/** Holding the corner button opens DroidDeck's controller menu. */
|
||||
var onCornerHold: (() -> Unit)? = null
|
||||
/** The player tapped the corner button. */
|
||||
var onCornerTap: ((Hidden?) -> Unit)? = null
|
||||
val inputSurface: InputSurfaceView get() = surface
|
||||
var isQuickHidden = false
|
||||
private set
|
||||
var isPinnedOnly = false
|
||||
private set
|
||||
val hasPinned get() = layout?.elements?.any { it.alwaysShown } == true
|
||||
val inputSurface: com.droiddeck.launcher.ui.InputSurfaceView get() = surface
|
||||
var onTouchMiss: ((MotionEvent) -> Unit)?
|
||||
get() = surface.onTouchMiss
|
||||
set(value) { surface.onTouchMiss = value }
|
||||
|
||||
init {
|
||||
addView(surface, LayoutParams(-1, -1))
|
||||
val size = (CORNER_HIT_DP * resources.displayMetrics.density).toInt()
|
||||
addView(corner, LayoutParams(size, size, Gravity.START or Gravity.BOTTOM))
|
||||
val size = (QUICK_HIT_DP * 2 * resources.displayMetrics.density).toInt()
|
||||
addView(quickToggle, LayoutParams(size, size, Gravity.START or Gravity.BOTTOM))
|
||||
}
|
||||
|
||||
fun updateLayout(value: SavedInputLayout?) {
|
||||
val kit = PadKit.current(context)
|
||||
if (layout == value && surface.kit == kit) return
|
||||
if (layout == value) return
|
||||
releaseAll()
|
||||
layout = value
|
||||
surface.kit = kit
|
||||
render()
|
||||
}
|
||||
|
||||
fun setHidden(value: Hidden?) {
|
||||
if (hidden == value) return
|
||||
fun setButtonsOnly(enabled: Boolean) {
|
||||
if (isButtonsOnly == enabled) return
|
||||
releaseAll()
|
||||
hidden = value
|
||||
isButtonsOnly = enabled
|
||||
isQuickHidden = false
|
||||
render()
|
||||
}
|
||||
|
||||
fun setQuickHidden(hidden: Boolean) {
|
||||
if (isButtonsOnly || isQuickHidden == hidden) return
|
||||
releaseAll()
|
||||
isQuickHidden = hidden
|
||||
render()
|
||||
}
|
||||
|
||||
fun setPinnedOnly(enabled: Boolean) {
|
||||
if (isPinnedOnly == enabled) return
|
||||
releaseAll()
|
||||
isPinnedOnly = enabled
|
||||
render()
|
||||
}
|
||||
|
||||
private data class Placement(val layout: SavedInputLayout?, val width: Int, val height: Int, val safe: Rect, val buttonsOnly: Boolean)
|
||||
|
||||
private fun placed(): List<InputSurfaceElement> {
|
||||
val key = Placement(layout, viewWidth, viewHeight, Rect(safe), isButtonsOnly)
|
||||
return placements.getOrPut(key) {
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad
|
||||
OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, isButtonsOnly, dock,
|
||||
rearButtons = SessionPrefs.oscRearButtons(context).takeIf { steam },
|
||||
trackpads = SessionPrefs.oscTrackpads(context).takeIf { steam })
|
||||
}
|
||||
}
|
||||
|
||||
private fun render() {
|
||||
val placed = OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, dock)
|
||||
surface.updateCustomLayout(if (hidden != null) placed.filter { it.alwaysShown } else placed)
|
||||
surface.updateStyle(layout?.style ?: InputSurfaceStyle())
|
||||
corner.visibility = if (layout == null || dock != null) GONE else VISIBLE
|
||||
corner.alpha = (layout?.style?.opacity ?: 100) / 100f
|
||||
corner.invalidate()
|
||||
val elements = placed()
|
||||
surface.updateCustomLayout(when {
|
||||
isPinnedOnly -> elements.filter { it.alwaysShown }
|
||||
isQuickHidden -> elements.filter { it.id == "builtin:keyboard" || it.alwaysShown }
|
||||
else -> elements
|
||||
})
|
||||
quickToggle.visibility = if (isButtonsOnly || isPinnedOnly || layout == null || dock != null) GONE else VISIBLE
|
||||
refreshAppearance()
|
||||
}
|
||||
|
||||
private fun refreshAppearance() {
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
val artwork = PadKit.forOverlay(context, layout)
|
||||
surface.updateStyle(style, artwork)
|
||||
quickToggle.tint = style.tint.takeUnless { artwork != null }
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.invalidate()
|
||||
}
|
||||
|
||||
fun takesTouchAt(x: Float, y: Float) = surface.takesTouchAt(x, y) ||
|
||||
corner.visibility == VISIBLE && x >= corner.left && x < corner.right && y >= corner.top && y < corner.bottom
|
||||
fun cornerTakes(x: Float, y: Float) = corner.visibility == VISIBLE && x >= corner.left && x < corner.right && y >= corner.top && y < corner.bottom
|
||||
quickToggle.visibility == VISIBLE && x >= quickToggle.left && x < quickToggle.right && y >= quickToggle.top && y < quickToggle.bottom
|
||||
fun releaseAll() = surface.releaseInputs()
|
||||
fun reload() { releaseAll(); surface.kit = PadKit.current(context); render() }
|
||||
fun reload() { releaseAll(); placements.clear(); render() }
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val w = MeasureSpec.getSize(widthMeasureSpec)
|
||||
@@ -91,14 +127,14 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
val cutout = if (Build.VERSION.SDK_INT >= 28) insets.displayCutout else null
|
||||
val margin = (CORNER_MARGIN_DP * resources.displayMetrics.density).toInt()
|
||||
val params = corner.layoutParams as LayoutParams
|
||||
val left = (cutout?.safeInsetLeft ?: 0) + margin
|
||||
val bottom = (cutout?.safeInsetBottom ?: 0) + margin
|
||||
val offset = ((QUICK_CENTER_DP - QUICK_HIT_DP) * resources.displayMetrics.density).toInt()
|
||||
val params = quickToggle.layoutParams as LayoutParams
|
||||
val left = (cutout?.safeInsetLeft ?: 0) + offset
|
||||
val bottom = (cutout?.safeInsetBottom ?: 0) + offset
|
||||
if (params.leftMargin != left || params.bottomMargin != bottom) {
|
||||
params.leftMargin = left
|
||||
params.bottomMargin = bottom
|
||||
corner.layoutParams = params
|
||||
quickToggle.layoutParams = params
|
||||
}
|
||||
val fresh = Rect(cutout?.safeInsetLeft ?: 0, if (dock == null) cutout?.safeInsetTop ?: 0 else 0, cutout?.safeInsetRight ?: 0, cutout?.safeInsetBottom ?: 0)
|
||||
if (fresh != safe) {
|
||||
@@ -108,45 +144,42 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
return super.onApplyWindowInsets(insets)
|
||||
}
|
||||
|
||||
private inner class CornerButton(context: Context) : View(context) {
|
||||
private val art = PadArt(context)
|
||||
private val badge = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private inner class QuickToggle(context: Context) : View(context) {
|
||||
var tint: Int? = ControllerPrefs.STEAM_BLUE
|
||||
private val density = resources.displayMetrics.density
|
||||
private var armed = false
|
||||
private var held = false
|
||||
private val hold = Runnable { if (armed) { held = true; performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) } }
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val stroke = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE; strokeWidth = 1.5f * density }
|
||||
private val text = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
textAlign = Paint.Align.CENTER
|
||||
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
|
||||
textSize = 22 * density
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val dimmed = hidden != null && !armed
|
||||
if (dimmed) canvas.saveLayerAlpha(0f, 0f, w, h, 170)
|
||||
art.system(canvas, w, h, PadArt.Shape.ROUND, PadArt.Icon.MARK, armed)
|
||||
if (dimmed) canvas.restore()
|
||||
if (hidden == Hidden.BY_CONTROLLER) {
|
||||
val d = art.density
|
||||
val r = RectF(w - 15 * d, 3 * d, w - 2 * d, 12 * d)
|
||||
badge.style = Paint.Style.FILL; badge.color = Color.rgb(0x16, 0x19, 0x1E)
|
||||
canvas.drawRoundRect(r, 2.5f * d, 2.5f * d, badge)
|
||||
badge.style = Paint.Style.STROKE; badge.strokeWidth = 1.3f * d; badge.color = Color.rgb(0xFF, 0xB3, 0x47)
|
||||
canvas.drawRoundRect(r, 2.5f * d, 2.5f * d, badge)
|
||||
}
|
||||
val x = width / 2f
|
||||
val y = height / 2f
|
||||
val radius = QUICK_RADIUS_DP * density
|
||||
val color = tint
|
||||
fill.color = if (color != null) InputSurfaceView.shade(color, 190, 0.12f) else (InputSurfaceView.SURFACE and 0x00ffffff) or (190 shl 24)
|
||||
canvas.drawCircle(x, y, radius, fill)
|
||||
stroke.color = if (color != null) InputSurfaceView.light(color, 150, 0.25f) else InputSurfaceView.LINE
|
||||
canvas.drawCircle(x, y, radius, stroke)
|
||||
text.color = if (color != null) InputSurfaceView.light(color, 210, 0.75f) else InputSurfaceView.TEXT
|
||||
canvas.drawText(if (isQuickHidden) "+" else "−", x, y + text.textSize * 0.35f, text)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> { armed = true; held = false; postDelayed(hold, ViewConfiguration.getLongPressTimeout().toLong()); invalidate() }
|
||||
MotionEvent.ACTION_CANCEL -> { armed = false; removeCallbacks(hold); invalidate() }
|
||||
MotionEvent.ACTION_DOWN -> armed = true
|
||||
MotionEvent.ACTION_CANCEL -> armed = false
|
||||
MotionEvent.ACTION_UP -> {
|
||||
removeCallbacks(hold)
|
||||
if (armed && held) post { onCornerHold?.invoke() }
|
||||
else if (armed && event.x in 0f..width.toFloat() && event.y in 0f..height.toFloat()) {
|
||||
if (armed && event.x in 0f..width.toFloat() && event.y in 0f..height.toFloat()) {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
val next = if (hidden == null) Hidden.BY_TAP else null
|
||||
setHidden(next)
|
||||
onCornerTap?.invoke(next)
|
||||
setQuickHidden(!isQuickHidden)
|
||||
}
|
||||
armed = false
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
return true
|
||||
@@ -154,7 +187,9 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val CORNER_HIT_DP = 48f
|
||||
const val CORNER_MARGIN_DP = 4f
|
||||
const val QUICK_CENTER_DP = 34f
|
||||
const val QUICK_HIT_DP = 26f
|
||||
const val QUICK_RADIUS_DP = 18f
|
||||
const val PLACEMENT_CACHE = 4
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,17 @@ package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OnScreenLayout {
|
||||
internal fun supportsFloatingSteamControls(controller: String, layout: SavedInputLayout?) =
|
||||
layout?.id == InputLibraries.OVERLAY &&
|
||||
(controller == SessionPrefs.CONTROLLER_DECK || controller == SessionPrefs.CONTROLLER_STEAM)
|
||||
|
||||
data class Dock(val portrait: Boolean, val grips: Boolean, val left: InputControl = InputControl.LS, val right: InputControl = InputControl.RS) {
|
||||
companion object {
|
||||
fun deck(portrait: Boolean, gamepad: SavedInputLayout?): Dock {
|
||||
@@ -19,23 +26,40 @@ object OnScreenLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The built-in gamepad keeps no kit positions until its kit is edited; until then the kit follows the virtual controller and
|
||||
* the layout stores only the keys and controls the player added on top.
|
||||
*/
|
||||
fun generated(layout: SavedInputLayout) = (layout.id == InputLibraries.OVERLAY || layout.origin == InputLibraries.OVERLAY) &&
|
||||
!layout.kitless && layout.elements.none { KitLayout.isKit(it.id) }
|
||||
private const val TOLERANCE = .01f
|
||||
private const val KEYBOARD_ID = "builtin:keyboard"
|
||||
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect, dock: Dock? = null): List<InputSurfaceElement> {
|
||||
layout ?: return emptyList()
|
||||
if (width <= 0 || height <= 0) return layout.elements
|
||||
if (generated(layout)) {
|
||||
val kit = PadKit.current(context)
|
||||
val extras = if (layout.elements.isEmpty()) emptyList() else fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
|
||||
return (if (dock != null) KitLayout.dock(context, kit, width, height, dock.portrait, dock.left, dock.right)
|
||||
else KitLayout.elements(context, kit, width, height, safe, layout.scale)) + extras
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect,
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null, rearButtons: Boolean? = null,
|
||||
trackpads: Boolean? = null): List<InputSurfaceElement> {
|
||||
val stored = layout?.elements ?: return emptyList()
|
||||
if (width <= 0 || height <= 0) return stored
|
||||
val generator = LegacyGamepadLayout(context, width, height, safe, layout.scale)
|
||||
val (reference, generated) = reference(context, layout, width, height)
|
||||
if (buttonsOnly && dock == null) return generator.buttonsOnly(stored) + fit(stored.filter { it.alwaysShown }, reference.first, reference.second, width, height, safe)
|
||||
val gamepad = if (generated) stored.filter(::isGamepad) else emptyList()
|
||||
val others = fit(stored.filterNot { generated && isGamepad(it) || dock != null && it.alwaysShown }, reference.first, reference.second, width, height, safe)
|
||||
val placed = when {
|
||||
gamepad.isEmpty() -> emptyList()
|
||||
dock != null -> generator.dock(gamepad, dock.portrait, dock.grips, dock.left, dock.right)
|
||||
else -> generator.regenerate(gamepad)
|
||||
}
|
||||
return fit(layout.elements, aspect(context, layout), 1f, width, height, safe)
|
||||
val byId = (placed + others).associateBy { it.id }
|
||||
val ordered = stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
val kit = PadKit.forOverlay(context, layout) ?: return ordered
|
||||
if (generated &&
|
||||
ControllerPrefs.layout(context, reference.first.toInt(), reference.second.toInt()).isEmpty() &&
|
||||
ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
if (dock != null || height > width) {
|
||||
return ControllerPortraitGeometry(width.toFloat(), height.toFloat(), safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, kit, dock != null, layout.scale, rearButtons == true, trackpads == true)
|
||||
}
|
||||
return ControllerOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
.place(ordered, kit, rearButtons == true, trackpads == true)
|
||||
}
|
||||
if (dock != null || !kit.steam) return ordered
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
fun editorElements(context: Context, layout: SavedInputLayout, width: Int, height: Int, edited: Boolean = false): List<InputSurfaceElement> =
|
||||
@@ -69,8 +93,35 @@ object OnScreenLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private fun aspect(context: Context, layout: SavedInputLayout): Float = layout.aspect.takeIf { it > 0f } ?: run {
|
||||
val metrics = InputLibraries.primaryDisplay(context).second
|
||||
max(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1).toFloat() / min(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1)
|
||||
private fun isGamepad(e: InputSurfaceElement) = e.id.startsWith("legacy:") || e.id == KEYBOARD_ID
|
||||
|
||||
fun generatedSize(context: Context, layout: SavedInputLayout, width: Int, height: Int): Pair<Int, Int>? =
|
||||
reference(context, layout, width, height).takeIf { it.second }?.first?.let { it.first.toInt() to it.second.toInt() }
|
||||
|
||||
private fun reference(context: Context, layout: SavedInputLayout, width: Int, height: Int): Pair<Pair<Float, Float>, Boolean> {
|
||||
val (display, metrics) = InputLibraries.primaryDisplay(context)
|
||||
val long = max(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1)
|
||||
val short = min(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1)
|
||||
val gamepad = layout.elements.filter(::isGamepad)
|
||||
if (gamepad.any { it.id.startsWith("legacy:") }) {
|
||||
val named = layout.id.removePrefix("migrated.layout.").takeIf { it != layout.id }?.split('x')?.mapNotNull { it.toIntOrNull() }
|
||||
?.takeIf { it.size == 2 && it.all { size -> size > 0 } }?.let { it[0] to it[1] }
|
||||
val aspectSize = layout.aspect.takeIf { layout.id == InputLibraries.OVERLAY && it > 0f }
|
||||
?.let { (it * height).roundToInt().coerceAtLeast(1) to height }
|
||||
for ((w, h) in listOfNotNull(named, width to height, aspectSize, long to short, short to long).distinct()) {
|
||||
val generator = LegacyGamepadLayout(display, w, h, scale = layout.scale)
|
||||
if (matches(gamepad, generator.elements()) || matches(gamepad, generator.elements(previousStickGeometry = true))) return (w.toFloat() to h.toFloat()) to true
|
||||
}
|
||||
}
|
||||
val aspect = layout.aspect.takeIf { it > 0f } ?: (long.toFloat() / short)
|
||||
return (aspect to 1f) to false
|
||||
}
|
||||
|
||||
private fun matches(stored: List<InputSurfaceElement>, generated: List<InputSurfaceElement>): Boolean {
|
||||
val byId = generated.associateBy { it.id }
|
||||
return stored.all { e ->
|
||||
val g = byId[e.id] ?: return@all false
|
||||
abs(e.x - g.x) <= TOLERANCE && abs(e.y - g.y) <= TOLERANCE && abs(e.width - g.width) <= TOLERANCE && abs(e.height - g.height) <= TOLERANCE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,8 +107,6 @@ public final class PadBridge {
|
||||
private volatile Runnable onPlayerInput;
|
||||
private Runnable onChordInput;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean playerInputPosted = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
private volatile Runnable onPhysicalInput;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean physicalInputPosted = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
|
||||
private static final long STATS_WINDOW_MS = 10_000;
|
||||
private int statButtons, statAxes, statOnScreen, statDropped;
|
||||
@@ -370,20 +368,6 @@ public final class PadBridge {
|
||||
onPlayerInput = listener;
|
||||
}
|
||||
|
||||
/** Input from a controller the player holds, never from the on-screen controls. */
|
||||
public void setOnPhysicalInput(Runnable listener) {
|
||||
onPhysicalInput = listener;
|
||||
}
|
||||
|
||||
private void notePhysicalInput() {
|
||||
Runnable listener = onPhysicalInput;
|
||||
if (listener == null || !physicalInputPosted.compareAndSet(false, true)) return;
|
||||
mainHandler.post(() -> {
|
||||
physicalInputPosted.set(false);
|
||||
listener.run();
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void setOnChordInput(Runnable listener) {
|
||||
onChordInput = listener;
|
||||
}
|
||||
@@ -449,7 +433,7 @@ public final class PadBridge {
|
||||
}
|
||||
noteDevice(device, slot);
|
||||
if (pressed && event.getRepeatCount() == 0 && !event.isCanceled()) noteChordInput(slot);
|
||||
if (pressed) { notePlayerInput(); notePhysicalInput(); }
|
||||
if (pressed) notePlayerInput();
|
||||
statButtons++;
|
||||
scheduleStats();
|
||||
publish(slot);
|
||||
@@ -537,7 +521,7 @@ public final class PadBridge {
|
||||
retainStick(slot, side, x, y);
|
||||
projectSticks(slot);
|
||||
if (chordStickInput) noteChordInput(slot);
|
||||
if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) { notePlayerInput(); notePhysicalInput(); }
|
||||
if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) notePlayerInput();
|
||||
publish(slot);
|
||||
InputTiming.end(timing);
|
||||
return true;
|
||||
@@ -579,7 +563,6 @@ public final class PadBridge {
|
||||
if (Math.max(Math.max(Math.abs(pad.leftX), Math.abs(pad.leftY)), Math.max(Math.abs(pad.rightX), Math.abs(pad.rightY))) > 0.5f
|
||||
|| lt > 0.5f || rt > 0.5f || pad.up || pad.right || pad.down || pad.left) {
|
||||
notePlayerInput();
|
||||
notePhysicalInput();
|
||||
}
|
||||
publish(slot);
|
||||
InputTiming.end(timing);
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.droiddeck.launcher.input
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
enum class FaceGlyphs { MONO_LETTERS, COLOR_LETTERS, COLOR_SYMBOLS, MONO_SYMBOLS }
|
||||
enum class DpadStyle { CROSS, DISC, ARROWS }
|
||||
enum class StickCap { RINGED, DISHED, KNURLED }
|
||||
internal enum class FaceGlyphs { MONO_LETTERS, COLOR_LETTERS, COLOR_SYMBOLS, MONO_SYMBOLS }
|
||||
internal enum class DpadStyle { CROSS, DISC, ARROWS }
|
||||
internal enum class StickCap { RINGED, DISHED, KNURLED }
|
||||
|
||||
enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap, private val xbox: Boolean = false) {
|
||||
internal enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap, private val xbox: Boolean = false) {
|
||||
STEAM_DECK(FaceGlyphs.MONO_LETTERS, DpadStyle.CROSS, StickCap.RINGED),
|
||||
STEAM_CONTROLLER(FaceGlyphs.MONO_LETTERS, DpadStyle.CROSS, StickCap.RINGED),
|
||||
XBOX(FaceGlyphs.COLOR_LETTERS, DpadStyle.DISC, StickCap.DISHED, xbox = true),
|
||||
@@ -35,14 +35,14 @@ enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun of(type: String) = when (type) {
|
||||
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
|
||||
SessionPrefs.CONTROLLER_XBOX360 -> XBOX
|
||||
SessionPrefs.CONTROLLER_DS4 -> DUALSHOCK
|
||||
SessionPrefs.CONTROLLER_DUALSENSE -> DUALSENSE
|
||||
else -> STEAM_DECK
|
||||
}
|
||||
|
||||
fun current(context: Context) = of(SessionPrefs.steamController(context))
|
||||
fun forOverlay(context: Context, layout: SavedInputLayout?): PadKit? =
|
||||
if (layout?.id != InputLibraries.OVERLAY) null else when (SessionPrefs.steamController(context)) {
|
||||
SessionPrefs.CONTROLLER_DECK -> STEAM_DECK
|
||||
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
|
||||
SessionPrefs.CONTROLLER_XBOX360 -> XBOX
|
||||
SessionPrefs.CONTROLLER_DS4 -> DUALSHOCK
|
||||
SessionPrefs.CONTROLLER_DUALSENSE -> DUALSENSE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,7 @@ data class PhysicalInputKey(val device: String, val name: String, val keyCode: I
|
||||
|
||||
data class PhysicalInputBinding(val key: PhysicalInputKey, val action: InputAction)
|
||||
|
||||
class PhysicalInputBindings(
|
||||
private val router: InputRouter,
|
||||
private val onPress: (KeyEvent) -> Unit = {},
|
||||
) {
|
||||
class PhysicalInputBindings(private val router: InputRouter) {
|
||||
private class Entry(val binding: PhysicalInputBinding, val channel: InputRouter.Channel) {
|
||||
var heldDevice = -1
|
||||
var suppressed = false
|
||||
@@ -69,10 +66,7 @@ class PhysicalInputBindings(
|
||||
if (identity != key.device) continue
|
||||
entry.heldDevice = event.deviceId
|
||||
entry.suppressed = event.repeatCount != 0
|
||||
if (!entry.suppressed) {
|
||||
entry.channel.update(1f)
|
||||
onPress(event)
|
||||
}
|
||||
if (!entry.suppressed) entry.channel.update(1f)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -20,11 +20,7 @@ import java.util.ArrayDeque
|
||||
import java.util.UUID
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
class SteamControllerBle(
|
||||
private val context: Context,
|
||||
router: InputRouter? = null,
|
||||
private val onPhysicalInput: (() -> Unit)? = null,
|
||||
) {
|
||||
class SteamControllerBle(private val context: Context, router: InputRouter? = null) {
|
||||
private val inputLock = router ?: Any()
|
||||
private var routedInput = router?.let(::TritonInputRouter)
|
||||
@Volatile private var stopped = false
|
||||
@@ -43,7 +39,6 @@ class SteamControllerBle(
|
||||
private var outputSequence = 0L
|
||||
private var outputWritePending = false
|
||||
private var featureRead = 0L
|
||||
private var lastPressedControls = 0
|
||||
|
||||
fun start(): Unit = synchronized(inputLock) {
|
||||
if (stopped || started) return@synchronized
|
||||
@@ -271,18 +266,12 @@ class SteamControllerBle(
|
||||
val timing = InputTiming.begin()
|
||||
FakeInputWriter.writeTritonState(SLOT, reportId, routedInput?.route(data) ?: data)
|
||||
InputTiming.end(timing)
|
||||
if (connected && onPhysicalInput != null) {
|
||||
val pressed = TritonInputRouter.pressedControls(data)
|
||||
if (pressed and lastPressedControls.inv() != 0) onPhysicalInput()
|
||||
lastPressedControls = pressed
|
||||
}
|
||||
}
|
||||
|
||||
private fun release() = synchronized(inputLock) {
|
||||
if (stopped) return@synchronized
|
||||
routedInput?.release()
|
||||
withSlot {
|
||||
lastPressedControls = 0
|
||||
FakeInputWriter.writeTritonState(SLOT, if (reportId == 0x47) 0x47 else 0x45, ByteArray(STATE_BYTES))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,6 @@ class SteamTouchControls(
|
||||
private var selectedArm = 0
|
||||
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val art = com.droiddeck.launcher.ui.PadArt(context)
|
||||
private val stroke = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
|
||||
private val text = Paint(Paint.ANTI_ALIAS_FLAG).apply { textAlign = Paint.Align.CENTER; isFakeBoldText = true }
|
||||
|
||||
@@ -241,10 +240,7 @@ class SteamTouchControls(
|
||||
private fun cx(e: Element) = e.x * width
|
||||
private fun cy(e: Element) = e.y * height
|
||||
|
||||
private fun reach(e: Element, x: Float, y: Float): Float {
|
||||
val dx = (x - cx(e)) / radius(e); val dy = (y - cy(e)) / radiusY(e)
|
||||
return if (e.type in TRACKPADS) max(abs(dx), abs(dy)) else hypot(dx, dy)
|
||||
}
|
||||
private fun reach(e: Element, x: Float, y: Float) = hypot((x - cx(e)) / radius(e), (y - cy(e)) / radiusY(e))
|
||||
|
||||
private fun hit(list: List<Element>, x: Float, y: Float): Element? =
|
||||
list.filter { reach(it, x, y) <= 1.15f }.minByOrNull { reach(it, x, y) }
|
||||
@@ -285,61 +281,58 @@ class SteamTouchControls(
|
||||
val r = radius(e)
|
||||
val pressed = !editing && e.type in pressedTypes()
|
||||
val alpha = (255 * alphaScale * if (faded) FADED else 1f).toInt().coerceIn(30, 255)
|
||||
stroke.color = Color.rgb(Color.red(tint), Color.green(tint), Color.blue(tint)); stroke.strokeWidth = lineWidth()
|
||||
fill.color = Color.argb(217, 230, 233, 236)
|
||||
if (alpha < 255) canvas.saveLayerAlpha(x - r * 1.5f, y - r * 1.5f, x + r * 1.5f, y + r * 1.5f, alpha)
|
||||
val ink = Color.argb(alpha, Color.red(tint), Color.green(tint), Color.blue(tint))
|
||||
stroke.color = if (isSelected) Color.rgb(26, 159, 255) else ink
|
||||
stroke.strokeWidth = if (isSelected) lineWidth() * 2f else lineWidth()
|
||||
fill.color = Color.argb((alpha * 0.85f).toInt(), 230, 233, 236)
|
||||
text.color = ink
|
||||
text.typeface = android.graphics.Typeface.DEFAULT_BOLD
|
||||
when (e.type) {
|
||||
SteamTouchConfig.DPAD -> if (visuals[SteamTouchConfig.DPAD].orEmpty().any { it.binding?.hasIcon == true }) drawDpad(canvas, e, x, y, r) else {
|
||||
val bits = if (editing) 0L else dpadBits(e)
|
||||
val held = (if (bits and DPAD_UP != 0L) 1 else 0) or (if (bits and DPAD_RIGHT != 0L) 2 else 0) or
|
||||
(if (bits and DPAD_DOWN != 0L) 4 else 0) or (if (bits and DPAD_LEFT != 0L) 8 else 0)
|
||||
canvas.save(); canvas.translate(x - r, y - r)
|
||||
art.dpad(canvas, 2 * r, 2 * r, PadKit.STEAM_DECK, held, ink = glyphInk())
|
||||
canvas.restore()
|
||||
}
|
||||
SteamTouchConfig.DPAD -> drawDpad(canvas, e, x, y, r)
|
||||
SteamTouchConfig.JOYSTICK_LEFT, SteamTouchConfig.JOYSTICK_RIGHT -> {
|
||||
val f = fingers.values.firstOrNull { it.element?.type == e.type }.takeIf { !editing }
|
||||
var kx = 0f; var ky = 0f
|
||||
if (f != null) {
|
||||
canvas.drawCircle(x, y, r, stroke)
|
||||
val f = fingers.values.firstOrNull { it.element?.type == e.type }
|
||||
if (f != null && !editing) {
|
||||
val d = hypot(f.x - x, f.y - y)
|
||||
val k = if (d > r) r / d else 1f
|
||||
kx = (f.x - x) * k * .54f; ky = (f.y - y) * k * .54f
|
||||
val kx = x + (f.x - x) * k
|
||||
val ky = y + (f.y - y) * k
|
||||
canvas.drawCircle(kx, ky, r * 0.42f, fill)
|
||||
}
|
||||
art.stick(canvas, x, y, r, PadKit.STEAM_DECK, kx, ky, f != null)
|
||||
}
|
||||
SteamTouchConfig.TRACKPAD_LEFT, SteamTouchConfig.TRACKPAD_RIGHT, SteamTouchConfig.TRACKPAD_CENTER -> {
|
||||
val f = fingers.values.firstOrNull { it.element?.type == e.type }.takeIf { !editing }
|
||||
canvas.save(); canvas.translate(x - r, y - r)
|
||||
art.trackpad(canvas, r * 2f, r * 2f, f != null, (f?.x ?: x) - x + r, (f?.y ?: y) - y + r)
|
||||
canvas.restore()
|
||||
if (editing) art.text(canvas, context.getString(R.string.deck_surface_trackpad), x, y, r * .3f, Color.argb(128, 255, 255, 255))
|
||||
val rect = RectF(x - r * 1.3f, y - r * 0.85f, x + r * 1.3f, y + r * 0.85f)
|
||||
if (pressed) canvas.drawRoundRect(rect, r * 0.18f, r * 0.18f, fill)
|
||||
canvas.drawRoundRect(rect, r * 0.18f, r * 0.18f, stroke)
|
||||
if (editing) {
|
||||
text.textSize = r * 0.3f
|
||||
text.color = Color.argb(alpha / 2, 255, 255, 255)
|
||||
canvas.drawText(context.getString(R.string.deck_surface_trackpad), x, y - (text.descent() + text.ascent()) / 2, text)
|
||||
}
|
||||
}
|
||||
SteamTouchConfig.STEAM -> {
|
||||
if (isSelected) canvas.drawCircle(x, y, r, stroke)
|
||||
drawMark(canvas, x, y, r * 0.5f, if (pressed) accent else ink, alpha)
|
||||
}
|
||||
SteamTouchConfig.STEAM -> systemButton(canvas, x, y, r, com.droiddeck.launcher.ui.PadArt.Shape.PILL, com.droiddeck.launcher.ui.PadArt.Icon.STEAM, pressed)
|
||||
SteamTouchConfig.SELECT, SteamTouchConfig.START -> {
|
||||
val binding = visuals[e.type]?.firstOrNull()?.binding
|
||||
if (binding?.hasIcon == true) drawFace(canvas, e.type, binding, x, y, r, pressed)
|
||||
else systemButton(canvas, x, y, r, com.droiddeck.launcher.ui.PadArt.Shape.CHIP,
|
||||
if (e.type == SteamTouchConfig.START) com.droiddeck.launcher.ui.PadArt.Icon.MENU else com.droiddeck.launcher.ui.PadArt.Icon.VIEW, pressed)
|
||||
if (binding?.hasIcon == true) {
|
||||
drawFace(canvas, e.type, binding, x, y, r, alpha, pressed); return
|
||||
}
|
||||
val rect = RectF(x - r * 1.08f, y - r * 0.55f, x + r * 1.08f, y + r * 0.55f)
|
||||
if (pressed) canvas.drawRoundRect(rect, r * 0.5f, r * 0.5f, fill)
|
||||
canvas.drawRoundRect(rect, r * 0.5f, r * 0.5f, stroke)
|
||||
val t = r * 0.26f
|
||||
val dir = if (e.type == SteamTouchConfig.START) 1f else -1f
|
||||
val tri = Path().apply {
|
||||
moveTo(x + dir * t, y); lineTo(x - dir * t * 0.75f, y - t); lineTo(x - dir * t * 0.75f, y + t); close()
|
||||
}
|
||||
canvas.drawPath(tri, Paint(Paint.ANTI_ALIAS_FLAG).apply { color = if (pressed) Color.argb(alpha, 23, 26, 33) else ink })
|
||||
}
|
||||
else -> drawFace(canvas, e.type, visuals[e.type]?.firstOrNull()?.binding, x, y, r, pressed)
|
||||
}
|
||||
if (alpha < 255) canvas.restore()
|
||||
if (isSelected) {
|
||||
stroke.color = accent; stroke.strokeWidth = lineWidth() * 2f
|
||||
if (isSquare(e.type)) canvas.drawRoundRect(RectF(x - r, y - r, x + r, y + r), r * .3f, r * .3f, stroke) else canvas.drawCircle(x, y, r, stroke)
|
||||
else -> drawFace(canvas, e.type, visuals[e.type]?.firstOrNull()?.binding, x, y, r, alpha, pressed)
|
||||
}
|
||||
}
|
||||
|
||||
private fun systemButton(canvas: Canvas, x: Float, y: Float, r: Float, shape: com.droiddeck.launcher.ui.PadArt.Shape,
|
||||
icon: com.droiddeck.launcher.ui.PadArt.Icon, pressed: Boolean) {
|
||||
canvas.save(); canvas.translate(x - r * 1.4f, y - r * 1.4f)
|
||||
art.system(canvas, r * 2.8f, r * 2.8f, shape, icon, pressed, glyphInk())
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
/** Glyphs follow the colour picked for Steam touch controls; white keeps the shared artwork's own ink. */
|
||||
private fun glyphInk() = if (tint != Color.WHITE) tint else com.droiddeck.launcher.ui.PadArt.INK
|
||||
|
||||
private fun isSquare(type: Int) = type in setOf(SteamTouchConfig.BUMPER_LEFT, SteamTouchConfig.BUMPER_RIGHT,
|
||||
SteamTouchConfig.TRIGGER_LEFT, SteamTouchConfig.TRIGGER_RIGHT, SteamTouchConfig.THUMB, SteamTouchConfig.KEYBOARD,
|
||||
SteamTouchConfig.PASTE, SteamTouchConfig.MACRO_1_FINGER, SteamTouchConfig.MACRO_2_FINGER) ||
|
||||
@@ -357,29 +350,53 @@ class SteamTouchControls(
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
private fun drawFace(canvas: Canvas, type: Int, binding: SteamTouchBindings.Binding?, x: Float, y: Float, r: Float, pressed: Boolean) {
|
||||
val shape = if (isSquare(type)) art.roundRect(x - r, y - r, x + r, y + r, r * .3f) else art.circle(x, y, r)
|
||||
private fun drawFace(canvas: Canvas, type: Int, binding: SteamTouchBindings.Binding?, x: Float, y: Float, r: Float,
|
||||
alpha: Int, pressed: Boolean) {
|
||||
val square = isSquare(type)
|
||||
val rect = RectF(x - r, y - r, x + r, y + r)
|
||||
val corner = r * 0.3f
|
||||
fun shape(paint: Paint) = if (square) canvas.drawRoundRect(rect, corner, corner, paint) else canvas.drawCircle(x, y, r, paint)
|
||||
val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let(::iconOrLoad)
|
||||
val custom = binding != null && binding.background.isNotEmpty() && !binding.background.equals(SteamTouchBindings.DEFAULT_BACKGROUND, true)
|
||||
art.glass(canvas, shape, pressed && !custom, if (custom) parseColor(binding!!.background, SteamTouchBindings.DEFAULT_BACKGROUND) else 0x850E1014.toInt())
|
||||
val ink = if (pressed && !custom) com.droiddeck.launcher.ui.PadArt.ON_ACCENT else glyphInk()
|
||||
if (icon != null) {
|
||||
val s = r * 0.62f
|
||||
if (custom) canvas.drawBitmap(tinted(binding!!.icon, icon, binding.foreground), null, RectF(x - s, y - s, x + s, y + s), Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG))
|
||||
else canvas.drawBitmap(inked(binding!!.icon, icon), null, RectF(x - s, y - s, x + s, y + s),
|
||||
Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG).apply { colorFilter = android.graphics.PorterDuffColorFilter(ink, android.graphics.PorterDuff.Mode.SRC_IN) })
|
||||
val custom = binding.background.isNotEmpty() && !binding.background.equals(SteamTouchBindings.DEFAULT_BACKGROUND, true)
|
||||
if (custom) {
|
||||
shape(Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = parseColor(binding.background, SteamTouchBindings.DEFAULT_BACKGROUND)
|
||||
this.alpha = if (pressed) alpha else (alpha * 0.85f).toInt()
|
||||
})
|
||||
canvas.drawBitmap(tinted(binding.icon, icon, binding.foreground), null, RectF(x - s, y - s, x + s, y + s),
|
||||
Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG).apply { this.alpha = alpha })
|
||||
} else {
|
||||
if (pressed) shape(fill)
|
||||
val ink = if (pressed) Color.argb(alpha, 23, 26, 33) else stroke.color
|
||||
canvas.drawBitmap(inked(binding.icon, icon), null, RectF(x - s, y - s, x + s, y + s),
|
||||
Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG).apply {
|
||||
colorFilter = android.graphics.PorterDuffColorFilter(ink, android.graphics.PorterDuff.Mode.SRC_IN)
|
||||
})
|
||||
}
|
||||
shape(stroke)
|
||||
return
|
||||
}
|
||||
if (type == SteamTouchConfig.THUMB) { art.icon(canvas, x, y, r * 1.1f, com.droiddeck.launcher.ui.PadArt.Icon.QAM, ink); return }
|
||||
if (type == SteamTouchConfig.KEYBOARD) { art.icon(canvas, x, y, r * 1.1f, com.droiddeck.launcher.ui.PadArt.Icon.KEYBOARD, ink); return }
|
||||
val shown = label(type)
|
||||
val size = when {
|
||||
if (pressed) shape(fill)
|
||||
shape(stroke)
|
||||
if (type == SteamTouchConfig.THUMB) { drawDots(canvas, x, y, r, if (pressed) Color.argb(alpha, 23, 26, 33) else text.color); return }
|
||||
if (type == SteamTouchConfig.KEYBOARD) { drawKeyboardGlyph(canvas, x, y, r, if (pressed) Color.argb(alpha, 23, 26, 33) else text.color); return }
|
||||
val own = label(type)
|
||||
val shown = own
|
||||
text.textSize = when {
|
||||
shown.length <= 1 -> r * 0.9f
|
||||
shown.length <= 2 -> r * 0.66f
|
||||
shown.length <= 5 -> r * 0.4f
|
||||
else -> r * 0.3f
|
||||
}
|
||||
art.text(canvas, if (shown.length > 10) shown.take(9) + "…" else shown, x, y, size, ink, r * 1.8f)
|
||||
text.color = when {
|
||||
pressed -> Color.argb(alpha, 23, 26, 33)
|
||||
shown == own -> LABEL_COLORS[type]?.let { Color.argb(alpha, Color.red(it), Color.green(it), Color.blue(it)) } ?: text.color
|
||||
else -> text.color
|
||||
}
|
||||
val line = if (shown.length > 10) shown.take(9) + "…" else shown
|
||||
canvas.drawText(line, x, y - (text.descent() + text.ascent()) / 2, text)
|
||||
}
|
||||
|
||||
private fun drawDots(canvas: Canvas, x: Float, y: Float, r: Float, color: Int) {
|
||||
@@ -387,6 +404,15 @@ class SteamTouchControls(
|
||||
for (i in -1..1) canvas.drawCircle(x + i * r * 0.3f, y + r * 0.22f, r * 0.08f, p)
|
||||
}
|
||||
|
||||
private fun drawKeyboardGlyph(canvas: Canvas, x: Float, y: Float, r: Float, color: Int) {
|
||||
val p = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color; style = Paint.Style.STROKE; strokeWidth = lineWidth() * 0.8f }
|
||||
val body = RectF(x - r * 0.6f, y - r * 0.34f, x + r * 0.6f, y + r * 0.34f)
|
||||
canvas.drawRoundRect(body, r * 0.08f, r * 0.08f, p)
|
||||
val dot = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = color }
|
||||
for (row in 0..1) for (i in 0..5) canvas.drawCircle(body.left + r * 0.15f + i * r * 0.18f, body.top + r * 0.18f + row * r * 0.17f, r * 0.035f, dot)
|
||||
canvas.drawLine(x - r * 0.3f, body.bottom - r * 0.14f, x + r * 0.3f, body.bottom - r * 0.14f, p)
|
||||
}
|
||||
|
||||
private val iconsLoading = HashSet<String>()
|
||||
|
||||
private val inkedIcons = android.util.LruCache<String, android.graphics.Bitmap>(48)
|
||||
@@ -1452,7 +1478,6 @@ class SteamTouchControls(
|
||||
var onSaved: () -> Unit = {}
|
||||
|
||||
companion object {
|
||||
private val TRACKPADS = setOf(SteamTouchConfig.TRACKPAD_LEFT, SteamTouchConfig.TRACKPAD_RIGHT, SteamTouchConfig.TRACKPAD_CENTER)
|
||||
private const val TAG = "SteamTouch"
|
||||
private const val POLL_MS = 150L
|
||||
private const val MOVE_REDRAW_MS = 33L
|
||||
@@ -1494,5 +1519,11 @@ class SteamTouchControls(
|
||||
put(SteamTouchConfig.PASTE, 0L)
|
||||
}
|
||||
|
||||
private val LABEL_COLORS = mapOf(
|
||||
SteamTouchConfig.A to Color.rgb(72, 133, 48),
|
||||
SteamTouchConfig.B to Color.rgb(211, 68, 37),
|
||||
SteamTouchConfig.X to Color.rgb(23, 60, 184),
|
||||
SteamTouchConfig.Y to Color.rgb(235, 200, 70),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -63,25 +63,16 @@ class TritonInputRouter(private val router: InputRouter) {
|
||||
fun release() = synchronized(router) { channels.forEach { it.release() }; last = null }
|
||||
fun close() = synchronized(router) { release(); channels.forEach { it.close() }; router.removeSnapshot(snapshot) }
|
||||
|
||||
private fun bits(data: ByteArray): Int = (data[1].toInt() and 255) or ((data[2].toInt() and 255) shl 8) or
|
||||
((data[3].toInt() and 255) shl 16) or ((data[4].toInt() and 255) shl 24)
|
||||
private fun putBits(data: ByteArray, value: Int) { for (i in 0..3) data[i + 1] = (value ushr (i * 8)).toByte() }
|
||||
private fun short(data: ByteArray, offset: Int) = ((data[offset].toInt() and 255) or (data[offset + 1].toInt() shl 8)).toShort().toInt()
|
||||
private fun axis(data: ByteArray, offset: Int): Float = short(data, offset).let { it / if (it < 0) 32768f else 32767f }
|
||||
private fun shortValue(value: Float) = (value * if (value < 0f) 32768f else 32767f).roundToInt().coerceIn(-32768, 32767)
|
||||
private fun putShort(data: ByteArray, offset: Int, value: Int) { data[offset] = value.toByte(); data[offset + 1] = (value shr 8).toByte() }
|
||||
|
||||
companion object {
|
||||
private const val CONTROL_BITS = 0x0fffffff
|
||||
|
||||
internal fun pressedControls(data: ByteArray): Int {
|
||||
var active = bits(data) and CONTROL_BITS
|
||||
if ((5..15 step 2).any { kotlin.math.abs(short(data, it)) > 16384 }) active = active or (1 shl 28)
|
||||
return active
|
||||
}
|
||||
|
||||
private fun bits(data: ByteArray): Int = (data[1].toInt() and 255) or ((data[2].toInt() and 255) shl 8) or
|
||||
((data[3].toInt() and 255) shl 16) or ((data[4].toInt() and 255) shl 24)
|
||||
|
||||
private fun short(data: ByteArray, offset: Int) =
|
||||
((data[offset].toInt() and 255) or (data[offset + 1].toInt() shl 8)).toShort().toInt()
|
||||
private fun bit(c: InputControl): Int = when (c) {
|
||||
InputControl.A -> 0x1; InputControl.B -> 0x2; InputControl.X -> 0x4; InputControl.Y -> 0x8
|
||||
InputControl.QAM -> 0x10; InputControl.R3 -> 0x20; InputControl.START -> 0x40
|
||||
|
||||
@@ -17,6 +17,9 @@ import android.provider.Settings
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.core.SessionPart
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionHdr
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
@@ -74,8 +77,10 @@ class DeviceControlsComponent(context: Context, root: File, private val activity
|
||||
val value = Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, 128)
|
||||
write("backlight/droiddeck/brightness", "$value\n")
|
||||
write("backlight/droiddeck/actual_brightness", "$value\n")
|
||||
val state = JSONObject().put("brightness", (value.coerceIn(1, 255) - 1) / 254.0)
|
||||
.put("brightnessWritable", Settings.System.canWrite(context)).toString()
|
||||
val controls = JSONObject().put("brightness", (value.coerceIn(1, 255) - 1) / 254.0)
|
||||
.put("brightnessWritable", Settings.System.canWrite(context))
|
||||
if (SessionState.hdrCapable) controls.put("hdr", SessionState.hdr)
|
||||
val state = controls.toString()
|
||||
if (force || state != previous) {
|
||||
write("state.json", JSONObject(state).put("revision", ++revision).toString())
|
||||
previous = state
|
||||
@@ -132,6 +137,9 @@ class DeviceControlsComponent(context: Context, root: File, private val activity
|
||||
audio.setStreamVolume(AudioManager.STREAM_MUSIC,
|
||||
it.coerceIn(0, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)), 0)
|
||||
}
|
||||
"hdr.request" -> if (text == "0" || text == "1") {
|
||||
SessionHdr.set(context, SessionPrefs.prefMode(SessionState.mode), text == "1")
|
||||
}
|
||||
"mute.request" -> if (text == "0" || text == "1") {
|
||||
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
|
||||
if (text == "1") AudioManager.ADJUST_MUTE else AudioManager.ADJUST_UNMUTE, 0)
|
||||
@@ -196,7 +204,7 @@ class DeviceControlsComponent(context: Context, root: File, private val activity
|
||||
private const val STREAM_MUTE_CHANGED_ACTION = "android.media.STREAM_MUTE_CHANGED_ACTION"
|
||||
private const val PERMISSION_CHANNEL = "brightness_permission"
|
||||
private const val PERMISSION_NOTIFICATION = 0x4442
|
||||
private val REQUESTS = setOf("brightness.request", "volume.request", "mute.request")
|
||||
private val REQUESTS = setOf("brightness.request", "volume.request", "mute.request", "hdr.request")
|
||||
@JvmStatic fun directory(root: File) = File(root, "etc/droiddeck-device-controls")
|
||||
@JvmStatic fun prepareBacklight(context: Context, root: File): File {
|
||||
val base = File(directory(root), "backlight")
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
class ContentCadence {
|
||||
var rate = 0
|
||||
private set
|
||||
private var candidate = 0
|
||||
private var streak = 0
|
||||
private var misses = 0
|
||||
private val reengage = HashMap<Int, Int>()
|
||||
|
||||
fun note(fps: Int, panelRates: IntArray): Boolean {
|
||||
val snapped = snap(fps, panelRates)
|
||||
if (rate != 0) {
|
||||
if (snapped == rate) {
|
||||
misses = 0
|
||||
return false
|
||||
}
|
||||
if (++misses < RELEASE_SAMPLES) return false
|
||||
reengage[rate] = minOf((reengage[rate] ?: ENGAGE_SAMPLES) * 2, MAX_ENGAGE_SAMPLES)
|
||||
rate = 0
|
||||
misses = 0
|
||||
candidate = snapped
|
||||
streak = if (snapped > 0) 1 else 0
|
||||
return true
|
||||
}
|
||||
if (snapped == 0 || snapped != candidate) {
|
||||
candidate = snapped
|
||||
streak = if (snapped > 0) 1 else 0
|
||||
return false
|
||||
}
|
||||
if (++streak < (reengage[snapped] ?: ENGAGE_SAMPLES)) return false
|
||||
rate = snapped
|
||||
misses = 0
|
||||
return true
|
||||
}
|
||||
|
||||
fun reset(): Boolean {
|
||||
val engaged = rate != 0
|
||||
rate = 0
|
||||
candidate = 0
|
||||
streak = 0
|
||||
misses = 0
|
||||
return engaged
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ENGAGE_SAMPLES = 3
|
||||
const val RELEASE_SAMPLES = 3
|
||||
const val MAX_ENGAGE_SAMPLES = 30
|
||||
private const val MIN_FPS = 20
|
||||
private const val MAX_DIVISOR = 6
|
||||
|
||||
fun snap(fps: Int, panelRates: IntArray): Int {
|
||||
if (fps < MIN_FPS) return 0
|
||||
var best = 0
|
||||
for (hz in panelRates) for (divisor in 1..MAX_DIVISOR) {
|
||||
if (hz % divisor != 0) continue
|
||||
val step = hz / divisor
|
||||
val miss = Math.abs(step - fps)
|
||||
if (miss <= 1 && (best == 0 || miss < Math.abs(best - fps) || (miss == Math.abs(best - fps) && step > best))) best = step
|
||||
}
|
||||
return best
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
import android.view.MotionEvent
|
||||
import android.view.WindowManager
|
||||
|
||||
// While a session is on screen, sits invisibly on top of every other display, so that display's
|
||||
// home launcher is not its top activity. lmkd kills the launcher first; restarted as a top activity
|
||||
// it takes focus from the session, which then drops to adj 50 and is killed next.
|
||||
// Android gives a translucent activity alone in its task an input sink that eats every touch on the
|
||||
// display whatever its window flags say, so a touch makes the guard leave that display until the
|
||||
// session is back on top.
|
||||
class KeepTopActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@Suppress("DEPRECATION") overridePendingTransition(0, 0)
|
||||
if (intent.getBooleanExtra(EXTRA_BOUNCE, false)) {
|
||||
bounces++
|
||||
finish()
|
||||
return
|
||||
}
|
||||
if (intent.getIntExtra(EXTRA_GENERATION, -1) != generation) {
|
||||
finishAndRemoveTask()
|
||||
return
|
||||
}
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
|
||||
val id = display?.displayId ?: Display.INVALID_DISPLAY
|
||||
starting.remove(id)
|
||||
if (id in yielded) {
|
||||
finishAndRemoveTask()
|
||||
return
|
||||
}
|
||||
guards[id]?.takeIf { it !== this && !it.isFinishing }?.finishAndRemoveTask()
|
||||
guards[id] = this
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN && !isFinishing) {
|
||||
val id = display?.displayId ?: Display.INVALID_DISPLAY
|
||||
yielded.add(id)
|
||||
Log.i(TAG, "display $id touched, leaving it to the app below")
|
||||
finishAndRemoveTask()
|
||||
onYield?.invoke()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
guards.values.remove(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "KeepTop"
|
||||
private const val EXTRA_BOUNCE = "bounce"
|
||||
private const val EXTRA_GENERATION = "generation"
|
||||
private var generation = 0
|
||||
var bounces = 0
|
||||
private set
|
||||
private val guards = HashMap<Int, KeepTopActivity>()
|
||||
private const val START_TIMEOUT_MS = 2_000L
|
||||
private val starting = HashMap<Int, Long>()
|
||||
private val yielded = HashSet<Int>()
|
||||
const val YIELD_GRACE_MS = 5_000L
|
||||
var onYield: (() -> Unit)? = null
|
||||
|
||||
fun rearm() = yielded.clear()
|
||||
|
||||
fun guardOtherDisplays(context: Context, sessionDisplay: Int): Boolean {
|
||||
val displays = context.getSystemService(DisplayManager::class.java)?.displays ?: return false
|
||||
var started = false
|
||||
for (display in displays) {
|
||||
val id = display.displayId
|
||||
if (id == sessionDisplay || id in yielded || display.state != Display.STATE_ON || guards[id]?.isFinishing == false ||
|
||||
starting[id]?.let { SystemClock.elapsedRealtime() - it < START_TIMEOUT_MS } == true) continue
|
||||
runCatching {
|
||||
launch(context, id, bounce = false)
|
||||
starting[id] = SystemClock.elapsedRealtime()
|
||||
started = true
|
||||
Log.i(TAG, "guarding display $id from a home launcher restart")
|
||||
}.onFailure { Log.w(TAG, "could not guard display $id", it) }
|
||||
}
|
||||
if (!started) return false
|
||||
return runCatching { launch(context, sessionDisplay, bounce = true) }
|
||||
.onFailure { Log.w(TAG, "could not return focus to display $sessionDisplay", it) }.isSuccess
|
||||
}
|
||||
|
||||
fun hasPendingStarts() = starting.isNotEmpty()
|
||||
|
||||
const val RETRY_MS = START_TIMEOUT_MS + 250
|
||||
|
||||
fun stepAside() {
|
||||
generation++
|
||||
guards.values.toList().forEach { it.finishAndRemoveTask() }
|
||||
guards.clear()
|
||||
starting.clear()
|
||||
}
|
||||
|
||||
fun release() {
|
||||
stepAside()
|
||||
yielded.clear()
|
||||
}
|
||||
|
||||
private fun launch(context: Context, displayId: Int, bounce: Boolean) {
|
||||
val intent = Intent(context, KeepTopActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
.putExtra(EXTRA_BOUNCE, bounce)
|
||||
.putExtra(EXTRA_GENERATION, generation)
|
||||
context.startActivity(intent, ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
// Tracks a pause that skipped the session's departure cleanup for the keep-top focus bounce.
|
||||
internal class LightPause {
|
||||
private var pending = false
|
||||
private var bouncesAtPause = 0
|
||||
|
||||
fun paused(bounces: Int) {
|
||||
pending = true
|
||||
bouncesAtPause = bounces
|
||||
}
|
||||
|
||||
// The bounce resumes the session within tens of milliseconds; still paused at the timeout means
|
||||
// something else holds the pause.
|
||||
fun timedOut(): Boolean = take()
|
||||
|
||||
fun stopped(): Boolean = take()
|
||||
|
||||
fun resumed(bounces: Int): Resume {
|
||||
if (!pending) return Resume.NORMAL
|
||||
pending = false
|
||||
return if (bounces != bouncesAtPause) Resume.LIGHT else Resume.CLEANUP_FIRST
|
||||
}
|
||||
|
||||
private fun take(): Boolean {
|
||||
val was = pending
|
||||
pending = false
|
||||
return was
|
||||
}
|
||||
|
||||
enum class Resume { NORMAL, LIGHT, CLEANUP_FIRST }
|
||||
}
|
||||
@@ -13,15 +13,19 @@ object PerfMode {
|
||||
private const val TAG = "PerfMode"
|
||||
const val BFI_MIN_REFRESH_HZ = 100f
|
||||
|
||||
fun apply(a: Activity, fpsLimit: Int = 0, refreshLimit: Int = 0): String {
|
||||
fun apply(a: Activity, fpsLimit: Int = 0, refreshLimit: Int = 0, requestedRefresh: Int = 0, held: Boolean = false): String {
|
||||
val parts = ArrayList<String>(2)
|
||||
|
||||
parts += try {
|
||||
val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay
|
||||
if (display == null || Build.VERSION.SDK_INT < 23) "display mode unchanged" else {
|
||||
if (display == null || Build.VERSION.SDK_INT < 23) "display mode unchanged" else if (held) {
|
||||
if (a.window.attributes.preferredDisplayModeId != 0) {
|
||||
a.window.attributes = a.window.attributes.apply { preferredDisplayModeId = 0 }
|
||||
}
|
||||
"display ${display.mode.refreshRate.toInt()} Hz (set by the system)"
|
||||
} else {
|
||||
val cur = display.mode
|
||||
val cap = minOf(peakRefreshCap(a), refreshLimit.takeIf { it > 0 }?.toFloat() ?: Float.POSITIVE_INFINITY)
|
||||
val best = selectMode(display.supportedModes, cur, fpsLimit, cap)
|
||||
val best = selectMode(display.supportedModes, cur, fpsLimit, refreshCap(a, refreshLimit), requestedRefresh)
|
||||
if (best != null && needsChange(display.supportedModes, a.window.attributes.preferredDisplayModeId, best)) {
|
||||
a.window.attributes = a.window.attributes.apply { preferredDisplayModeId = best.modeId }
|
||||
"display ${cur.refreshRate.toInt()} → ${best.refreshRate.toInt()} Hz (mode ${best.modeId})"
|
||||
@@ -55,12 +59,64 @@ object PerfMode {
|
||||
return if (peak >= 1f) peak else Float.POSITIVE_INFINITY
|
||||
}
|
||||
|
||||
internal fun selectMode(modes: Array<Display.Mode>, current: Display.Mode, fpsLimit: Int, cap: Float): Display.Mode? {
|
||||
private fun refreshCap(context: Context, refreshLimit: Int): Float =
|
||||
minOf(peakRefreshCap(context), refreshLimit.takeIf { it > 0 }?.toFloat() ?: Float.POSITIVE_INFINITY)
|
||||
|
||||
fun panelRates(a: Activity, refreshLimit: Int = 0, held: Boolean = false): IntArray = try {
|
||||
val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay
|
||||
if (display == null || Build.VERSION.SDK_INT < 23) IntArray(0)
|
||||
else panelRates(display.supportedModes, display.mode, refreshCap(a, refreshLimit), held)
|
||||
} catch (t: Throwable) { Log.w(TAG, "panel rates", t); IntArray(0) }
|
||||
|
||||
internal fun panelRates(modes: Array<Display.Mode>, current: Display.Mode, cap: Float, held: Boolean = false): IntArray =
|
||||
if (held) intArrayOf(Math.round(current.refreshRate))
|
||||
else allowedModes(modes, current, cap).map { Math.round(it.refreshRate) }.distinct().sorted().toIntArray()
|
||||
|
||||
fun panelHeld(a: Activity): Boolean = try {
|
||||
val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay
|
||||
val wanted = a.window.attributes.preferredDisplayModeId
|
||||
val requested = display?.supportedModes?.firstOrNull { wanted != 0 && it.modeId == wanted }
|
||||
display != null && requested != null && panelHeld(requested.refreshRate, display.mode.refreshRate)
|
||||
} catch (t: Throwable) { Log.w(TAG, "panel held", t); false }
|
||||
|
||||
internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean =
|
||||
requestedHz > 1f && activeHz > 1f && Math.abs(requestedHz - activeHz) > 0.5f
|
||||
|
||||
fun pacedRate(ownLimit: Int, limiterRate: Int, limiterRefresh: Int, steadyRate: Int): Int = when {
|
||||
ownLimit > 0 -> ownLimit
|
||||
limiterRate <= 0 -> steadyRate
|
||||
steadyRate <= 0 || limiterRate < limiterRefresh || limiterRefresh <= 0 -> limiterRate
|
||||
cadenceFits(limiterRate.toFloat(), steadyRate) -> limiterRate
|
||||
else -> steadyRate
|
||||
}
|
||||
|
||||
fun contentRate(fps: Int, frameGenFactor: Int, frameGenTarget: Int): Int = when {
|
||||
frameGenFactor <= 1 -> fps
|
||||
frameGenTarget > 0 -> frameGenTarget
|
||||
else -> fps * frameGenFactor
|
||||
}
|
||||
|
||||
private fun allowedModes(modes: Array<Display.Mode>, current: Display.Mode, cap: Float): List<Display.Mode> =
|
||||
modes.filter {
|
||||
it.physicalWidth == current.physicalWidth && it.physicalHeight == current.physicalHeight &&
|
||||
it.refreshRate <= cap + 0.5f
|
||||
}
|
||||
|
||||
internal fun selectMode(
|
||||
modes: Array<Display.Mode>,
|
||||
current: Display.Mode,
|
||||
fpsLimit: Int,
|
||||
cap: Float,
|
||||
requestedRefresh: Int = 0,
|
||||
): Display.Mode? {
|
||||
val sameSize = modes.filter {
|
||||
it.physicalWidth == current.physicalWidth && it.physicalHeight == current.physicalHeight
|
||||
}
|
||||
val allowed = sameSize.filter { it.refreshRate <= cap + 0.5f }
|
||||
return allowed.filter { cadenceFits(it.refreshRate, fpsLimit) }.maxByOrNull { it.refreshRate }
|
||||
val allowed = allowedModes(modes, current, cap)
|
||||
val requested = if (fpsLimit > 0 || requestedRefresh <= 0) null else allowed
|
||||
.filter { it.refreshRate >= requestedRefresh - 0.5f }.minByOrNull { it.refreshRate }
|
||||
return requested
|
||||
?: allowed.filter { cadenceFits(it.refreshRate, fpsLimit) }.maxByOrNull { it.refreshRate }
|
||||
?: allowed.maxByOrNull { it.refreshRate }
|
||||
?: sameSize.minByOrNull { it.refreshRate }
|
||||
}
|
||||
|
||||
@@ -69,18 +69,8 @@ object SessionDisplay {
|
||||
|
||||
const val UNFOLDED_MIN_DP = 600
|
||||
|
||||
/**
|
||||
* The game's share of a screen with the controls below it, at the game's [aspect] across the full width. A tab row under the bar
|
||||
* comes out of the controls while they keep [UNFOLDED_MIN_CONTROLS_SHARE] of the screen, and out of the game otherwise.
|
||||
*/
|
||||
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0, aspect: Float = 16f / 9f): Int {
|
||||
val game = minOf((width / aspect.coerceAtLeast(.5f)).toInt(), (height * UNFOLDED_MAX_GAME_SHARE).toInt())
|
||||
val tabs = tabRow.coerceAtLeast(0)
|
||||
val roomy = height - game - tabs >= height * UNFOLDED_MIN_CONTROLS_SHARE
|
||||
return (if (roomy) game else game - tabs).coerceAtLeast(0) and 1.inv()
|
||||
}
|
||||
|
||||
const val UNFOLDED_MIN_CONTROLS_SHARE = .45f
|
||||
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0): Int =
|
||||
(minOf(width * 9 / 16, (height * UNFOLDED_MAX_GAME_SHARE).toInt()) - tabRow.coerceAtLeast(0)).coerceAtLeast(0) and 1.inv()
|
||||
|
||||
fun unfoldedControlsWanted(
|
||||
enabled: Boolean,
|
||||
|
||||
@@ -39,6 +39,7 @@ object SessionFiles {
|
||||
private val SERVICE_PACKS = mapOf(
|
||||
AddonPack.UBISOFT to "usr/local/lib/droiddeck-ubisoft",
|
||||
AddonPack.ROCKSTAR to "usr/local/lib/droiddeck-rockstar",
|
||||
AddonPack.EPIC to "usr/local/lib/droiddeck-epic",
|
||||
AddonPack.DIRT to "usr/local/lib/droiddeck-dirt",
|
||||
)
|
||||
|
||||
@@ -47,6 +48,8 @@ object SessionFiles {
|
||||
|
||||
fun ensureRockstarService(context: Context) = ensureStoreService(context, AddonPack.ROCKSTAR)
|
||||
|
||||
fun ensureEpicParent(context: Context) = ensureStoreService(context, AddonPack.EPIC)
|
||||
|
||||
/** The DiRT 3 / DiRT Showdown ws2_32 stand-in; droiddeck-game-env applies it only when it is staged. */
|
||||
fun ensureDirtStandIn(context: Context) = ensureStoreService(context, AddonPack.DIRT)
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.agent.AgentGuest
|
||||
import com.droiddeck.launcher.wayland.CompositorHost
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
object SessionHdr {
|
||||
private const val RETRIES = 5
|
||||
private const val RETRY_MS = 2_000L
|
||||
|
||||
private val requests = Executors.newSingleThreadExecutor { runnable ->
|
||||
Thread(runnable, "session-hdr").apply { isDaemon = true }
|
||||
}
|
||||
@Volatile private var wanted = false
|
||||
|
||||
fun set(context: Context, mode: String, on: Boolean) {
|
||||
SessionPrefs.setHdr(context, mode, on)
|
||||
if (!SessionState.running || !SessionState.hdrCapable || !CompositorHost.isStarted) return
|
||||
if (SessionPrefs.prefMode(SessionState.mode) != mode) return
|
||||
SessionState.hdr = on
|
||||
wanted = on
|
||||
WaylandCompositor.nativeSetHdrOutput(on)
|
||||
WaylandCompositor.nativeSetZeroCopy(on || SessionPrefs.zeroCopy(context, mode))
|
||||
val app = context.applicationContext
|
||||
val session = SessionState.sessionId
|
||||
requests.execute {
|
||||
var tries = 0
|
||||
while (wanted == on && SessionState.running && SessionState.sessionId == session &&
|
||||
!AgentGuest.setGamescopeConvar(app, "hdr_enabled", if (on) 1 else 0) && tries++ < RETRIES) {
|
||||
try { Thread.sleep(RETRY_MS) } catch (e: InterruptedException) { return@execute }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -664,27 +664,20 @@ object SessionPrefs {
|
||||
prefs(context).getString("shape", null)
|
||||
?: if (context.packageManager.hasSystemFeature("android.hardware.sensor.hinge_angle")) SHAPE_WIDE else SHAPE_AUTO
|
||||
|
||||
/** Auto, Always or Never. Older builds also stored the Steam layout and a buttons-only mode here. */
|
||||
fun oscMode(context: Context, steamSession: Boolean = false): String = when (val mode = prefs(context).getString("osc", OSC_AUTO)) {
|
||||
OSC_ALWAYS, OSC_NEVER -> mode
|
||||
OSC_STEAM_QAM -> OSC_ALWAYS
|
||||
OSC_STEAM_TOUCH -> if (steamSession) OSC_ALWAYS else OSC_AUTO
|
||||
else -> OSC_AUTO
|
||||
fun oscMode(context: Context, steamSession: Boolean = true): String {
|
||||
val saved = prefs(context).getString("osc", OSC_AUTO) ?: OSC_AUTO
|
||||
return if (!steamSession && saved == OSC_STEAM_QAM) OSC_AUTO else saved
|
||||
}
|
||||
|
||||
fun setOscMode(context: Context, mode: String) {
|
||||
val editor = prefs(context).edit()
|
||||
if (!prefs(context).contains("steamTouchLayout")) editor.putBoolean("steamTouchLayout", steamTouchLayout(context))
|
||||
editor.putString("osc", mode).apply()
|
||||
prefs(context).edit().putString("osc", mode).apply()
|
||||
}
|
||||
|
||||
/** Draw Steam's touch layout for the game instead of DroidDeck's own. */
|
||||
fun steamTouchLayout(context: Context): Boolean =
|
||||
prefs(context).getBoolean("steamTouchLayout", prefs(context).getString("osc", null) == OSC_STEAM_TOUCH)
|
||||
fun oscRearButtons(context: Context): Boolean = prefs(context).getBoolean("oscRearButtons", false)
|
||||
fun setOscRearButtons(context: Context, shown: Boolean) { prefs(context).edit().putBoolean("oscRearButtons", shown).apply() }
|
||||
|
||||
fun setSteamTouchLayout(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("steamTouchLayout", on).apply()
|
||||
}
|
||||
fun oscTrackpads(context: Context): Boolean = prefs(context).getBoolean("oscTrackpads", false)
|
||||
fun setOscTrackpads(context: Context, shown: Boolean) { prefs(context).edit().putBoolean("oscTrackpads", shown).apply() }
|
||||
|
||||
fun linuxDriver(context: Context): String =
|
||||
prefs(context).getString("linuxDriver", null)
|
||||
@@ -842,6 +835,12 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("stretch16x9", on).apply()
|
||||
}
|
||||
|
||||
fun avoidNotch(context: Context): Boolean = prefs(context).getBoolean("avoidNotch", false)
|
||||
|
||||
fun setAvoidNotch(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("avoidNotch", on).apply()
|
||||
}
|
||||
|
||||
|
||||
fun directAudio(context: Context): Boolean = prefs(context).getBoolean("directAudio", true)
|
||||
|
||||
@@ -1633,10 +1632,18 @@ object SessionPrefs {
|
||||
return Pair(w and 1.inv(), h and 1.inv())
|
||||
}
|
||||
|
||||
fun hdr(context: Context, mode: String): Boolean = prefs(context).getBoolean("hdr.$mode", false)
|
||||
fun hdrKey(mode: String): String = "hdr.$mode"
|
||||
|
||||
fun hdr(context: Context, mode: String): Boolean = prefs(context).getBoolean(hdrKey(mode), false)
|
||||
|
||||
fun setHdr(context: Context, mode: String, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("hdr.$mode", on).apply()
|
||||
prefs(context).edit().putBoolean(hdrKey(mode), on).apply()
|
||||
}
|
||||
|
||||
fun zeroCopy(context: Context, mode: String): Boolean = prefs(context).getBoolean("zeroCopy.$mode", true)
|
||||
|
||||
fun setZeroCopy(context: Context, mode: String, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("zeroCopy.$mode", on).apply()
|
||||
}
|
||||
|
||||
const val FPS_UNPACED = -1
|
||||
@@ -1962,7 +1969,7 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("pipAutoEnter", enabled).apply()
|
||||
}
|
||||
|
||||
fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", true)
|
||||
fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", false)
|
||||
|
||||
fun controlsBelowWanted(context: Context, mode: String, width: Int, height: Int, pip: Boolean = false): Boolean =
|
||||
SessionDisplay.unfoldedControlsWanted(
|
||||
|
||||
@@ -1025,6 +1025,9 @@ class SessionService : Service() {
|
||||
if (!bridge && !venus && SystemVulkanDriver.usesDefault(linuxDriverId)) {
|
||||
SystemVulkanDriver.addEnvironment(this, guest)
|
||||
}
|
||||
com.droiddeck.launcher.wayland.WaylandCompositor.nativeSetDisplayBufferDriver(
|
||||
!bridge && !venus && LinuxVulkanDriverManager(this).rendersToDisplayBuffers(linuxDriverId),
|
||||
)
|
||||
(if (bridge || venus) null else LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId))
|
||||
?.let { guest.add(LinuxVulkanDriver.ENV + "=" + it) }
|
||||
if (!com.droiddeck.launcher.core.DeviceSupport.adreno() && lastXwaylandCrashed()) {
|
||||
@@ -1613,6 +1616,11 @@ class SessionService : Service() {
|
||||
return
|
||||
}
|
||||
val accepted = gameId!!
|
||||
if (pendingSteamGameId == null && SteamGameProcess.alreadyRunning(accepted, SessionState.gameId)) {
|
||||
Log.i(TAG, "game $accepted is already running; resuming it instead of launching it again")
|
||||
if (SessionState.suspended || SessionState.suspending) resumeSession()
|
||||
return
|
||||
}
|
||||
if (!pendingSteamPreviousGamePending) {
|
||||
pendingSteamPreviousGameId = SessionState.gameId
|
||||
pendingSteamPreviousGamePending = true
|
||||
@@ -2394,8 +2402,7 @@ class SessionService : Service() {
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
if (rootIntent?.component?.className in setOf(
|
||||
com.droiddeck.launcher.ui.DualScreenActivity::class.java.name,
|
||||
com.droiddeck.launcher.ui.SessionTypingActivity::class.java.name,
|
||||
KeepTopActivity::class.java.name)) return
|
||||
com.droiddeck.launcher.ui.SessionTypingActivity::class.java.name)) return
|
||||
if (pipTask || xrActivityVisible) {
|
||||
Log.i(TAG, "panel task dismissed - retaining the session under its active surface policy")
|
||||
activityVisible = false
|
||||
|
||||
@@ -115,6 +115,10 @@ object SessionState {
|
||||
|
||||
@JvmStatic var hdr = false
|
||||
|
||||
@JvmStatic var hdrCapable = false
|
||||
|
||||
@JvmStatic var hdrDisplay = false
|
||||
|
||||
@Volatile private var deckPadValue = false
|
||||
@JvmStatic var deckPad: Boolean
|
||||
get() = deckPadValue
|
||||
|
||||
@@ -18,7 +18,7 @@ object SettingsReset {
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController",
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"stretch16x9", "avoidNotch", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
|
||||
@@ -61,4 +61,11 @@ object SteamGameProcess {
|
||||
runCatching { File(p, "cmdline").readBytes() }
|
||||
.getOrNull()?.let { matches(it, gameId) } == true
|
||||
} == true
|
||||
|
||||
// A front end that resumes a player by launching the same game again would otherwise have Steam
|
||||
// start it a second time, which Steam answers with "Game already running".
|
||||
fun alreadyRunning(requested: String, current: String?, proc: File = File("/proc")): Boolean {
|
||||
val appId = steamAppIdForGameId(requested) ?: return false
|
||||
return appId == steamAppIdForGameId(current.orEmpty()) && running(requested, proc)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.ComponentCallbacks2
|
||||
|
||||
internal object TopUnderPressure {
|
||||
const val WINDOW_MS = 5_000L
|
||||
|
||||
fun isPressure(level: Int) =
|
||||
level == ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL || level == ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW
|
||||
|
||||
fun shouldReclaim(nowMs: Long, pressureAtMs: Long, sessionRunning: Boolean, finishing: Boolean) =
|
||||
sessionRunning && !finishing && pressureAtMs > 0 && nowMs - pressureAtMs in 0..WINDOW_MS
|
||||
}
|
||||
@@ -13,6 +13,15 @@ object StoreLaunch {
|
||||
const val EPIC_ARGS = ".droiddeck-epic-args"
|
||||
const val UBISOFT_LAUNCH = ".droiddeck-ubisoft.json"
|
||||
private const val UBISOFT_SERVICE = "Z:\\usr\\local\\lib\\droiddeck-ubisoft\\droiddeck-upc.exe"
|
||||
const val EPIC_PARENT = "Z:\\usr\\local\\lib\\droiddeck-epic\\EpicGamesLauncher.exe"
|
||||
/** Per-game environment switch: 1 starts any Epic game under [EPIC_PARENT], 0 never does. */
|
||||
const val EPIC_PARENT_SWITCH = "DD_EPIC_PARENT"
|
||||
/** Epic app names whose launchers treat the game as unowned unless a process named EpicGamesLauncher.exe started it. */
|
||||
val EPIC_PARENT_TITLES = setOf(
|
||||
"9d2d0eb64d5c44529cece33fe2a46482", "8769e24080ea413b8ebca3f1b8c50951", "Heather",
|
||||
"c180bd9859624278aa20f1333918498a", "0828ecd4297c4f89bfcc45420e695b67",
|
||||
"e5f031908d2e460b8757387d1a136e48", "afd9f29c1af44610b9e0f9b69742e257",
|
||||
)
|
||||
const val EA_ENV = ".droiddeck-ea-env"
|
||||
/** A sleeping stand-in that the launch hook installs; older EA SDKs require a running Origin process. */
|
||||
const val EA_ORIGIN = "C:\\Program Files (x86)\\Origin\\Origin.exe"
|
||||
@@ -39,22 +48,29 @@ object StoreLaunch {
|
||||
val args = sidecar.args.joinToString(" ") { if (sidecar.store == Store.ROCKSTAR) batchArg(it) else quoteArg(it) }
|
||||
val run = "\"%~dp0$exe\"" + (if (args.isNotEmpty()) " $args" else "")
|
||||
if (sidecar.store == Store.EPIC) {
|
||||
lines += "set \"$PARENT_VAR=${if (sidecar.id in EPIC_PARENT_TITLES) "1" else ""}\""
|
||||
lines += "if \"%$EPIC_PARENT_SWITCH%\"==\"1\" set \"$PARENT_VAR=1\""
|
||||
lines += "if \"%$EPIC_PARENT_SWITCH%\"==\"0\" set \"$PARENT_VAR=\""
|
||||
lines += "if defined $PARENT_VAR set \"SteamAppId=\""
|
||||
lines += "if defined $PARENT_VAR if not exist \"$EPIC_PARENT\" set \"$PARENT_VAR=\""
|
||||
lines += "if defined $PARENT_VAR set $PARENT_VAR=\"$EPIC_PARENT\""
|
||||
val game = "%$PARENT_VAR% $run"
|
||||
lines += "if exist \"%~dp0$EPIC_ARGS\" goto client"
|
||||
lines += "set \"$CODE_VAR=\""
|
||||
lines += "if exist \"%~dp0$EPIC_CODE\" set /p $CODE_VAR=<\"%~dp0$EPIC_CODE\""
|
||||
lines += "if exist \"%~dp0$EPIC_CODE\" del \"%~dp0$EPIC_CODE\""
|
||||
lines += "if defined $CODE_VAR goto signed"
|
||||
lines += run
|
||||
lines += "$game %*"
|
||||
lines += "goto :eof"
|
||||
lines += ":signed"
|
||||
lines += "set \"$CODE_VAR=\" & $run -AUTH_LOGIN=unused -AUTH_PASSWORD=%$CODE_VAR% -AUTH_TYPE=exchangecode"
|
||||
lines += "set \"$CODE_VAR=\" & $game -AUTH_LOGIN=unused -AUTH_PASSWORD=%$CODE_VAR% -AUTH_TYPE=exchangecode %*"
|
||||
lines += "goto :eof"
|
||||
lines += ":client"
|
||||
lines += "set \"$CLIENT_VAR=\""
|
||||
lines += "set /p $CLIENT_VAR=<\"%~dp0$EPIC_ARGS\""
|
||||
lines += "del \"%~dp0$EPIC_ARGS\""
|
||||
lines += "if exist \"%~dp0$EPIC_CODE\" del \"%~dp0$EPIC_CODE\""
|
||||
lines += "set \"$CLIENT_VAR=\" & \"%~dp0$exe\" %$CLIENT_VAR%"
|
||||
lines += "set \"$CLIENT_VAR=\" & %$PARENT_VAR% \"%~dp0$exe\" %$CLIENT_VAR% %*"
|
||||
} else if (sidecar.store == Store.ROCKSTAR) {
|
||||
lines += "if not exist \"C:\\Program Files\\Rockstar Games\\Launcher\\launch.json\" goto direct"
|
||||
lines += "\"C:\\Program Files\\Rockstar Games\\Launcher\\Launcher.exe\""
|
||||
@@ -107,6 +123,7 @@ object StoreLaunch {
|
||||
|
||||
private const val CODE_VAR = "DD_X"
|
||||
private const val CLIENT_VAR = "DD_A"
|
||||
private const val PARENT_VAR = "DD_P"
|
||||
|
||||
fun installedGame(context: Context, store: Store, id: String): Library.SteamGame? {
|
||||
val folder = StoreInstallRoot.gameFolders(context).firstOrNull { folder ->
|
||||
|
||||
@@ -152,7 +152,7 @@ internal fun SessionDrawerPreview(secondScreens: List<SecondScreenDisplay>) {
|
||||
suspendPolicy = suspend, onSuspendPolicy = { suspend = it },
|
||||
backActionsInverted = inverted, onBackActionsInverted = { inverted = it },
|
||||
touchMode = touch, onTouch = { touch = it },
|
||||
touchAuto = stringResource(R.string.mode_touch_mouse),
|
||||
touchAuto = stringResource(R.string.session_touch_auto_direct),
|
||||
fexPreset = fex, onFexPreset = { fex = it },
|
||||
fpsLimit = fps, onFpsLimit = { fps = it },
|
||||
secondScreenMode = second, onSecondScreenMode = { second = it },
|
||||
|
||||
@@ -38,7 +38,7 @@ internal fun InputElementProperties(element: InputSurfaceElement, action: InputA
|
||||
withContext(Dispatchers.IO) { InputButtonImages.import(context.applicationContext, uri) }?.let { change(current.copy(icon = 0, image = it)) }
|
||||
}
|
||||
}
|
||||
ToggleRow(host, "element-toggle", stringResource(R.string.input_toggle_button), null, element.toggle) { onChange(element.copy(toggle = it)) }
|
||||
ToggleRow(host, "element-toggle", stringResource(R.string.input_toggle_button), stringResource(R.string.input_toggle_button_hint), element.toggle) { onChange(element.copy(toggle = it)) }
|
||||
ChoiceRow(host, "element-shape", stringResource(R.string.input_button_shape), null,
|
||||
InputButtonShape.entries.map { it to stringResource(when (it) { InputButtonShape.ROUNDED -> R.string.input_shape_rounded; InputButtonShape.PILL -> R.string.input_shape_pill; InputButtonShape.CIRCLE -> R.string.input_shape_circle; InputButtonShape.RECTANGLE -> R.string.input_shape_rectangle }) },
|
||||
element.buttonShape) { onChange(element.copy(buttonShape = it)) }
|
||||
@@ -63,7 +63,7 @@ internal fun InputElementProperties(element: InputSurfaceElement, action: InputA
|
||||
}
|
||||
}
|
||||
if (element.kind == InputElementKind.TRACKPAD) {
|
||||
ToggleRow(rememberMenuHost(), "element-mouse-gestures", stringResource(R.string.input_mouse_gestures), null, element.mouseGestures) { onChange(element.copy(mouseGestures = it)) }
|
||||
ToggleRow(rememberMenuHost(), "element-mouse-gestures", stringResource(R.string.input_mouse_gestures), stringResource(R.string.input_mouse_gestures_hint), element.mouseGestures) { onChange(element.copy(mouseGestures = it)) }
|
||||
}
|
||||
if (element.kind == InputElementKind.STICK) {
|
||||
val host = rememberMenuHost()
|
||||
|
||||
@@ -3,16 +3,54 @@ package com.droiddeck.launcher.ui
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.view.View
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.*
|
||||
|
||||
@Composable
|
||||
internal fun InputLayoutRow(layout: SavedInputLayout, role: InputRole, detail: String?, onManage: () -> Unit, onPick: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(Modifier.weight(1f).focusRow(onClick = onPick).padding(12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
InputLayoutThumbnail(layout, role)
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(layout.name, style = MaterialTheme.typography.titleMedium)
|
||||
Text(detail ?: stringResource(R.string.input_layout_count, layout.elements.size),
|
||||
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
PadTextButton(onClick = onManage, modifier = Modifier.testTag("layout-manage-${layout.id}")) { Text("⋮", style = MaterialTheme.typography.titleLarge) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun InputLayoutThumbnail(layout: SavedInputLayout, role: InputRole) {
|
||||
AndroidView(factory = { InputLayoutPreviewView(it) }, modifier = Modifier.width(112.dp).height(76.dp).testTag("layout-preview-${layout.id}"),
|
||||
update = { it.update(layout, role) })
|
||||
}
|
||||
|
||||
internal class InputLayoutPreviewView(context: Context) : View(context) {
|
||||
private val renderer = InputSurfaceView(context)
|
||||
private var sourceHeight = 563
|
||||
fun update(layout: SavedInputLayout, role: InputRole) {
|
||||
sourceHeight = if (role == InputRole.PRIMARY) 563 else 870
|
||||
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
|
||||
renderer.layout(0, 0, 1000, sourceHeight)
|
||||
renderer.showLayout(layout.copy(style = layout.style.copy(opacity = 100)))
|
||||
val primary = role == InputRole.PRIMARY
|
||||
val artwork = if (primary) PadKit.forOverlay(context, layout) else null
|
||||
val elements = if (artwork != null) OnScreenLayout.editorElements(context, layout, 1000, sourceHeight) else layout.elements
|
||||
renderer.updateCustomLayout(elements)
|
||||
renderer.updateStyle(layout.style.copy(opacity = 100), artwork)
|
||||
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
|
||||
renderer.layout(0, 0, 1000, sourceHeight)
|
||||
contentDescription = layout.name
|
||||
@@ -30,4 +68,28 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun InputColorRow(host: MenuHost, value: Int?, onPick: (Int?) -> Unit) {
|
||||
val open = host.open == "layout-color"
|
||||
val tints = listOf<Pair<Int?, Int>>(null to R.string.ctrl_tint_gray) + ControllerPrefs.tints
|
||||
SettingsRow(stringResource(R.string.ctrl_color), null, highlighted = open) {
|
||||
Box {
|
||||
ValueChip(tints.firstOrNull { it.first == value }?.second?.let { stringResource(it) }
|
||||
?: stringResource(R.string.ctrl_custom), open, modifier = Modifier.testTag("setting-layout-color")) {
|
||||
host.open = if (open) null else "layout-color"
|
||||
}
|
||||
AnchoredMenu(open, onDismiss = { if (host.open == "layout-color") host.open = null }, title = stringResource(R.string.ctrl_color)) { firstItemFocus ->
|
||||
tints.forEachIndexed { index, (color, name) ->
|
||||
MenuItem(stringResource(name), checked = value == color, leading = {
|
||||
Box(Modifier.size(14.dp).background(Color(color ?: GRAY_SWATCH), CircleShape).border(1.dp, Color.White.copy(alpha = .35f), CircleShape))
|
||||
}, focusRequester = if (index == 0) firstItemFocus else null) {
|
||||
onPick(color)
|
||||
host.open = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val GRAY_SWATCH = 0xFF26292E.toInt()
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.*
|
||||
|
||||
@Composable
|
||||
internal fun InputQuickSettings(host: MenuHost, desktop: Boolean, onChanged: (InputRole?) -> Unit = {}, onEdit: () -> Unit = {}, track: (String) -> Modifier = { Modifier }) {
|
||||
val context = LocalContext.current
|
||||
var library by remember { mutableStateOf(InputLibraries.read(context)) }
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var naming by remember { mutableStateOf(false) }
|
||||
var failure by remember { mutableStateOf<String?>(null) }
|
||||
DisposableEffect(context) {
|
||||
val preferences = context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
|
||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == "library") library = InputLibraries.read(context) }
|
||||
preferences.registerOnSharedPreferenceChangeListener(listener)
|
||||
onDispose { preferences.unregisterOnSharedPreferenceChangeListener(listener) }
|
||||
}
|
||||
fun update(role: InputRole?, change: (InputLibrary) -> InputLibrary) {
|
||||
runCatching { InputLibraries.update(context, change) }.onSuccess { library = it; onChanged(role) }
|
||||
.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
|
||||
}
|
||||
val selection = library.selection(desktop)
|
||||
val mixed = selection.parts.isNotEmpty()
|
||||
val active = library.profile(library.activeId(desktop))
|
||||
val profiles = listOf(InputProfiles.AUTO to stringResource(R.string.input_quick_auto, if (desktop) library.profile(library.desktop).name else library.profile(library.steam).name)) +
|
||||
library.profiles.map { it.id to it.name } + if (mixed) listOf("mixed" to stringResource(R.string.input_quick_mixed, active.name)) else emptyList()
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(Modifier.weight(1f).focusRow { expanded = !expanded }.padding(14.dp).testTag("input-profile-expand"),
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(if (expanded) "▾" else "▸", color = MaterialTheme.colorScheme.onSurface)
|
||||
Text(stringResource(R.string.input_profile), style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurface)
|
||||
}
|
||||
Box(Modifier.padding(end = 14.dp).widthIn(max = 280.dp)) {
|
||||
ChoiceChip(host, "input-profile", stringResource(R.string.input_profile), profiles, if (mixed) "mixed" else selection.profile,
|
||||
modifier = track("input-profile")) { id -> if (id != "mixed") update(null) { it.selectProfile(desktop, id) } }
|
||||
}
|
||||
}
|
||||
if (expanded) Surface(
|
||||
modifier = Modifier.fillMaxWidth().padding(start = 18.dp, end = 12.dp, bottom = 14.dp).testTag("input-profile-parts"),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
color = MaterialTheme.colorScheme.primary.copy(alpha = .08f),
|
||||
border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary.copy(alpha = .35f)),
|
||||
) {
|
||||
Column(Modifier.padding(vertical = 6.dp)) {
|
||||
for (role in InputRole.entries) {
|
||||
val options = library.bindings.filter { binding ->
|
||||
if (role == InputRole.PHYSICAL) binding.physical
|
||||
else !binding.physical && library.layouts.any { it.id == binding.layoutId && it.supports(role) }
|
||||
}.map { it.id to it.name }
|
||||
ChoiceRow(host, "input-part-${role.name}", roleLabel(role), null, options, library.activePart(desktop, role).bindings,
|
||||
chipModifier = track("input-part-${role.name}")) { id -> update(role) { it.selectPart(desktop, role, id) } }
|
||||
}
|
||||
if (mixed) SecondaryButton(stringResource(R.string.input_save_combination)) { naming = true }
|
||||
ActionRow(stringResource(R.string.input_settings), null, stringResource(R.string.ctrl_edit), onEdit,
|
||||
modifier = track("input-settings").testTag("input-profile-edit"))
|
||||
}
|
||||
}
|
||||
if (naming) {
|
||||
var name by remember { mutableStateOf("") }
|
||||
AlertDialog(onDismissRequest = { naming = false }, title = { Text(stringResource(R.string.input_save_combination)) },
|
||||
text = { OutlinedTextField(name, { name = it.take(80) }, singleLine = true, label = { Text(stringResource(R.string.input_name)) }) },
|
||||
confirmButton = { PadTextButton(enabled = name.isNotBlank(), onClick = { update(null) { it.saveSelection(desktop, name) }; naming = false }) { Text(stringResource(R.string.gesture_save_changes)) } },
|
||||
dismissButton = { PadTextButton(onClick = { naming = false }) { Text(stringResource(R.string.common_cancel)) } })
|
||||
}
|
||||
failure?.let { message -> AlertDialog(onDismissRequest = { failure = null }, title = { Text(stringResource(R.string.input_save_failed)) },
|
||||
text = { Text(message) }, confirmButton = { PadTextButton(onClick = { failure = null }) { Text(stringResource(R.string.common_ok)) } }) }
|
||||
}
|
||||
@@ -1,10 +1,18 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.OpenableColumns
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.focusGroup
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -12,85 +20,142 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.*
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/** The in-game Remap buttons page. */
|
||||
@Composable
|
||||
fun InputSettingsDialog(onBack: () -> Unit, onChanged: () -> Unit, desktop: Boolean = false) {
|
||||
fun InputSettingsDialog(onBack: () -> Unit, onChanged: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val activity = context.findActivity() as? com.droiddeck.launcher.SessionActivity
|
||||
val target = activity?.inputEditorDisplay(InputRole.SECONDARY)
|
||||
if (activity != null && target != null && target.displayId != activity.window.decorView.display?.displayId) {
|
||||
InputDisplayContent(activity, target, onBack) { InputSettingsPane(onBack, onChanged, desktop) }
|
||||
} else Dialog(onDismissRequest = onBack, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
InputSettingsPane(onBack, onChanged, desktop)
|
||||
InputDisplayContent(activity, target, onBack) { InputSettingsPane(onBack, onChanged) }
|
||||
} else InputSettingsWindow(onBack, onChanged)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InputSettingsWindow(onBack: () -> Unit, onChanged: () -> Unit) {
|
||||
Dialog(onDismissRequest = onBack, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
InputSettingsPane(onBack, onChanged)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InputSettingsPane(onBack: () -> Unit, onChanged: () -> Unit, desktop: Boolean) {
|
||||
private fun InputSettingsPane(onBack: () -> Unit, onChanged: () -> Unit) {
|
||||
var editingSurface by remember { mutableStateOf(false) }
|
||||
val window = (androidx.compose.ui.platform.LocalView.current.parent as? androidx.compose.ui.window.DialogWindowProvider)?.window
|
||||
DisposableEffect(window, editingSurface) {
|
||||
window?.setDimAmount(if (editingSurface) 0f else .32f)
|
||||
onDispose { }
|
||||
}
|
||||
BoxWithConstraints(Modifier.fillMaxSize().systemBarsPadding().padding(8.dp)) {
|
||||
CompositionLocalProvider(LocalNarrowPane provides (maxWidth < NarrowPaneWidth)) {
|
||||
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surface) {
|
||||
InputSettingsPage(onBack, onChanged, remapOnly = true, desktop = desktop)
|
||||
Surface(Modifier.fillMaxSize(), color = if (editingSurface) androidx.compose.ui.graphics.Color.Transparent else MaterialTheme.colorScheme.surface) {
|
||||
InputSettingsPage(onBack, onChanged, onSurfaceEditing = { editingSurface = it })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum class InputPage { HOME, REMAP }
|
||||
private data class InputBindingEdit(val preset: String, val control: InputControl, val key: PhysicalInputKey? = null)
|
||||
private enum class InputPage { HOME, PROFILE, SOURCE, LAYOUTS, REUSE }
|
||||
private data class InputBindingEdit(val preset: String, val control: InputControl, val element: InputSurfaceElement? = null, val key: PhysicalInputKey? = null, val click: Boolean = false)
|
||||
private data class InputNameRequest(val title: Int, val initial: String, val sources: List<Pair<String, String>> = emptyList(),
|
||||
val source: String = "", val offerSharing: Boolean = false, val save: (String, String, Boolean) -> Unit)
|
||||
private data class InputConfirmation(val title: String, val detail: String, val action: () -> Unit)
|
||||
private data class InputReuseRequest(val name: String, val layoutOnly: Boolean, val apply: (Boolean) -> Unit)
|
||||
|
||||
/** Settings › Controller: the in-game Controller page for the default, or with [remapOnly] just the physical controller's buttons. */
|
||||
@Composable
|
||||
fun InputSettingsPage(onBack: () -> Unit, onChanged: () -> Unit = {}, embedded: Boolean = false, onSurfaceEditing: (Boolean) -> Unit = {},
|
||||
remapOnly: Boolean = false, desktop: Boolean = false) {
|
||||
fun InputSettingsPage(onBack: () -> Unit, onChanged: () -> Unit = {}, embedded: Boolean = false, onSurfaceEditing: (Boolean) -> Unit = {}) {
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onBackground) {
|
||||
InputSettingsContent(onBack, onChanged, embedded, onSurfaceEditing, remapOnly, desktop)
|
||||
InputSettingsContent(onBack, onChanged, embedded, onSurfaceEditing)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embedded: Boolean, onSurfaceEditing: (Boolean) -> Unit,
|
||||
remapOnly: Boolean, desktop: Boolean) {
|
||||
private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embedded: Boolean, onSurfaceEditing: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val host = rememberMenuHost()
|
||||
var library by remember { mutableStateOf(InputLibraries.read(context)) }
|
||||
var page by remember { mutableStateOf(if (remapOnly) InputPage.REMAP else InputPage.HOME) }
|
||||
var page by remember { mutableStateOf(InputPage.HOME) }
|
||||
var bindingsTab by remember { mutableIntStateOf(0) }
|
||||
var profileId by remember { mutableStateOf(InputProfile.GAME) }
|
||||
var role by remember { mutableStateOf(InputRole.PHYSICAL) }
|
||||
var edit by remember { mutableStateOf<InputBindingEdit?>(null) }
|
||||
var naming by remember { mutableStateOf<InputNameRequest?>(null) }
|
||||
var confirmation by remember { mutableStateOf<InputConfirmation?>(null) }
|
||||
var reuse by remember { mutableStateOf<InputReuseRequest?>(null) }
|
||||
var capture by remember { mutableStateOf(false) }
|
||||
var surface by remember { mutableStateOf<Triple<String, String, String>?>(null) }
|
||||
var revision by remember { mutableIntStateOf(0) }
|
||||
LaunchedEffect(surface) { onSurfaceEditing(surface != null) }
|
||||
var surface by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(surface) { onSurfaceEditing(surface) }
|
||||
DisposableEffect(Unit) { onDispose { onSurfaceEditing(false) } }
|
||||
var managingLayout by remember { mutableStateOf<SavedInputLayout?>(null) }
|
||||
var exporting by remember { mutableStateOf<String?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val controller = rememberControllerSettings()
|
||||
fun changed() { library = InputLibraries.read(context); revision++; onChanged() }
|
||||
var oscMode by remember { mutableStateOf(SessionPrefs.oscMode(context)) }
|
||||
fun update(change: (InputLibrary) -> InputLibrary): Boolean = runCatching { InputLibraries.update(context, change) }
|
||||
.onSuccess { library = it; onChanged() }.onFailure { error = it.message ?: context.getString(R.string.input_save_failed) }.isSuccess
|
||||
fun go(next: InputPage) { page = next; host.open = null }
|
||||
fun back() {
|
||||
when {
|
||||
edit != null -> edit = null
|
||||
page == InputPage.REMAP && !remapOnly -> go(InputPage.HOME)
|
||||
else -> onBack()
|
||||
page == InputPage.HOME -> onBack()
|
||||
page == InputPage.PROFILE -> go(InputPage.HOME)
|
||||
page == InputPage.SOURCE -> go(InputPage.PROFILE)
|
||||
else -> go(InputPage.SOURCE)
|
||||
}
|
||||
}
|
||||
BackHandler(enabled = !embedded || page != InputPage.HOME || edit != null, onBack = ::back)
|
||||
val profile = library.profile(library.activeId(desktop))
|
||||
val preset = library.preset(library.activePart(desktop, InputRole.PHYSICAL).bindings)
|
||||
val profile = library.profile(profileId)
|
||||
val preset = library.preset(profile.binding(role))
|
||||
val layout = library.layout(profileId, role)
|
||||
val importer = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
val target = role
|
||||
scope.launch {
|
||||
val raw = withContext(Dispatchers.IO) { readLayoutFile(context, uri) }
|
||||
val metrics = inputDisplayMetrics(context, target)
|
||||
val imported = raw?.let { InputLayoutFile.import(context, it, layoutFileName(context, uri) ?: context.getString(R.string.ctrl_layout),
|
||||
if (target == InputRole.PRIMARY) InputLayoutScreen.MAIN else InputLayoutScreen.SECONDARY, layout?.style ?: InputSurfaceStyle(),
|
||||
metrics.widthPixels, metrics.heightPixels, metrics.density) }
|
||||
if (imported == null) error = context.getString(R.string.input_layout_import_failed)
|
||||
else if (update { it.withLayout(imported.first).withPreset(imported.second).chooseLayout(profileId, target, imported.first.id) }) go(InputPage.SOURCE)
|
||||
}
|
||||
}
|
||||
val exporter = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/json")) { uri ->
|
||||
val text = exporting
|
||||
exporting = null
|
||||
if (uri != null && text != null) scope.launch {
|
||||
val saved = withContext(Dispatchers.IO) { runCatching { context.contentResolver.openOutputStream(uri, "wt")?.use { it.write(text.toByteArray()) } != null }.getOrDefault(false) }
|
||||
if (!saved) error = context.getString(R.string.input_save_failed)
|
||||
}
|
||||
}
|
||||
fun rename(title: Int, name: String, save: (String) -> Unit) {
|
||||
naming = InputNameRequest(title, name) { value, _, _ -> save(value) }
|
||||
}
|
||||
fun newProfile(copy: Boolean) {
|
||||
naming = InputNameRequest(if (copy) R.string.input_copy_profile else R.string.input_new_profile,
|
||||
if (copy) profile.name else "", library.profiles.map { it.id to it.name }, profileId, offerSharing = true) { name, source, shared ->
|
||||
val id = newInputId()
|
||||
if (update { it.duplicateProfile(source, name, id, sharePhysical = shared) }) { profileId = id; go(InputPage.PROFILE) }
|
||||
}
|
||||
}
|
||||
fun editPart(nextRole: InputRole) { role = nextRole; bindingsTab = 0; go(InputPage.SOURCE) }
|
||||
val pageFocus = remember { androidx.compose.ui.focus.FocusRequester() }
|
||||
val inputMode = androidx.compose.ui.platform.LocalInputModeManager.current
|
||||
var settled by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(page, edit != null, surface) {
|
||||
LaunchedEffect(page, role, profileId, edit != null, surface) {
|
||||
if (!settled) { settled = true; return@LaunchedEffect }
|
||||
if (surface != null || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect
|
||||
if (surface || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect
|
||||
repeat(2) { withFrameNanos { } }
|
||||
runCatching { pageFocus.requestFocus() }
|
||||
}
|
||||
@@ -98,46 +163,70 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe
|
||||
Box(Modifier.focusRequester(pageFocus).focusGroup()) {
|
||||
if (editing != null) {
|
||||
val b = library.preset(editing.preset)
|
||||
val current = editing.key?.let { k -> b.keys.firstOrNull { it.key == k }?.action ?: InputAction.Disabled }
|
||||
var elementProperties by remember(editing) { mutableStateOf(editing.element) }
|
||||
val current = editing.element?.let { if (editing.click) b.clickAction(it) else b.action(it) }
|
||||
?: editing.key?.let { k -> b.keys.firstOrNull { it.key == k }?.action ?: InputAction.Disabled }
|
||||
?: b.controls[editing.control] ?: InputAction.Native()
|
||||
InputActionEditor(editing.control, current, editing.key?.label ?: editing.control.label,
|
||||
onBack = { edit = null }, nativeTargets = editing.key == null, detail = stringResource(R.string.input_remap_buttons), onSave = { action ->
|
||||
if (update { l -> l.withPreset(when {
|
||||
InputActionEditor(editing.control, current, if (editing.click) stringResource(R.string.input_click_name, editing.element!!.name)
|
||||
else editing.element?.name ?: editing.key?.label ?: editing.control.label,
|
||||
properties = { action -> if (!editing.click) elementProperties?.let { e -> InputElementProperties(e, action) { elementProperties = it } } },
|
||||
onBack = { edit = null }, element = editing.element, nativeTargets = editing.key == null, click = editing.click,
|
||||
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 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))
|
||||
}) }) edit = null
|
||||
})
|
||||
} else if (surface == null) key(page) {
|
||||
} else if (!surface) key(page, profileId, role) {
|
||||
SettingsPage(host, title = when (page) {
|
||||
InputPage.HOME -> if (embedded) null else stringResource(R.string.setup_controller)
|
||||
InputPage.REMAP -> stringResource(R.string.input_remap_buttons)
|
||||
}, onBack = ::back, showBack = !(embedded && page == InputPage.HOME), compactLayout = true) {
|
||||
InputPage.PROFILE -> profile.name
|
||||
InputPage.SOURCE -> roleLabel(role)
|
||||
InputPage.LAYOUTS -> stringResource(R.string.input_saved_layouts)
|
||||
InputPage.REUSE -> stringResource(R.string.input_use_settings_from)
|
||||
}, eyebrow = when (page) {
|
||||
InputPage.SOURCE -> profile.name
|
||||
InputPage.LAYOUTS, InputPage.REUSE -> "${profile.name} · ${roleLabel(role)}"
|
||||
else -> null
|
||||
},
|
||||
onBack = ::back, showBack = !(embedded && page == InputPage.HOME), compactLayout = true) {
|
||||
when (page) {
|
||||
InputPage.HOME -> {
|
||||
SettingsGroup(stringResource(R.string.input_default_profiles)) {
|
||||
ChoiceRow(host, "auto-desktop", stringResource(R.string.input_desktop_mode), null,
|
||||
library.profiles.map { it.id to it.name }, library.desktop) { id -> update { it.copy(desktop = id) } }
|
||||
ChoiceRow(host, "auto-game", stringResource(R.string.input_game_mode), null,
|
||||
library.profiles.map { it.id to it.name }, library.steam) { id -> update { it.copy(steam = id) } }
|
||||
for (desktop in listOf(true, false)) {
|
||||
val selection = library.selection(desktop)
|
||||
if (selection.profile != InputProfiles.AUTO || selection.parts.isNotEmpty()) InputHint(stringResource(R.string.input_quick_override_hint,
|
||||
stringResource(if (desktop) R.string.input_desktop_mode else R.string.input_game_mode)))
|
||||
}
|
||||
}
|
||||
if (InputLibraries.hasPendingScreenKeyMigration(context)) InputHint(stringResource(R.string.input_import_failed))
|
||||
if (InputLibraries.hasLibraryRecovery(context)) InputHint(stringResource(R.string.input_library_recovered))
|
||||
DefaultControlsGroup(host, revision, onEdit = { surface = it }, onChanged = ::changed,
|
||||
onFailure = { error = it.message ?: context.getString(R.string.input_save_failed) })
|
||||
SettingsGroup(stringResource(R.string.drawer_page_controller)) {
|
||||
var padType by remember { mutableStateOf(SessionPrefs.steamController(context)) }
|
||||
ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), null,
|
||||
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)),
|
||||
padType) { SessionPrefs.setSteamController(context, it); padType = it; onChanged() }
|
||||
if (library.profiles.any { it.id.startsWith("migrated.screenkeys.") }) Text(stringResource(R.string.input_imported_keys_hint),
|
||||
Modifier.padding(16.dp), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
SettingsGroup(stringResource(R.string.input_profiles)) {
|
||||
for (p in library.profiles) InputNavigationRow(p.name, when {
|
||||
p.id == library.steam && p.id == library.desktop -> stringResource(R.string.input_default_both)
|
||||
p.id == library.steam -> stringResource(R.string.input_default_game)
|
||||
p.id == library.desktop -> stringResource(R.string.input_default_desktop)
|
||||
else -> null
|
||||
}, Modifier.testTag("input-profile-${p.id}")) { profileId = p.id; go(InputPage.PROFILE) }
|
||||
PadTextButton(onClick = { newProfile(false) }, modifier = Modifier.padding(8.dp)) { Text(stringResource(R.string.input_new_profile)) }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.input_device_settings)) {
|
||||
ToggleRow(host, "controller-rumble", stringResource(R.string.ctrl_rumble), null, controller.rumble) { ControllerPrefs.setRumble(context, it); onChanged() }
|
||||
ChoiceRow(host, "controller-dead-zone", stringResource(R.string.ctrl_dead_zone), null, ControllerPrefs.deadZones.map { it to stringResource(R.string.ctrl_percent, it) }, controller.deadZone) { ControllerPrefs.setDeadZone(context, it); onChanged() }
|
||||
ToggleRow(host, "controller-joycon-vr", stringResource(R.string.ctrl_joycon_vr), null, controller.joyConVr) { ControllerPrefs.setJoyConVr(context, it); onChanged() }
|
||||
ActionRow(stringResource(R.string.input_remap_buttons), null, stringResource(R.string.ctrl_edit), { go(InputPage.REMAP) },
|
||||
modifier = Modifier.testTag("input-remap"))
|
||||
}
|
||||
val games = remember(revision) { ControlsChoice.games(context) }
|
||||
if (games.isNotEmpty()) SettingsGroup(stringResource(R.string.osc_games_own)) {
|
||||
for (game in games) ActionRow(game.name, game.layout, stringResource(R.string.osc_use_default), {
|
||||
ControlsChoice.useDefault(context, game.id); changed()
|
||||
}, modifier = Modifier.testTag("osc-use-default-${game.id}"))
|
||||
ToggleRow(host, "controller-joycon-vr", stringResource(R.string.ctrl_joycon_vr), stringResource(R.string.ctrl_joycon_vr_hint), controller.joyConVr) { ControllerPrefs.setJoyConVr(context, it); onChanged() }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.shortcuts_title)) { PhysicalShortcutRows() }
|
||||
SettingsGroup(stringResource(R.string.input_latency)) {
|
||||
@@ -155,70 +244,191 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe
|
||||
} }, confirmButton = { PadTextButton(onClick = { reading = false }) { Text(stringResource(R.string.common_close)) } })
|
||||
}
|
||||
}
|
||||
InputPage.REMAP -> {
|
||||
SettingsGroup(stringResource(R.string.input_physical)) {
|
||||
Box(Modifier.padding(horizontal = 12.dp, vertical = 12.dp)) {
|
||||
SheetChips(listOf(stringResource(R.string.input_buttons), stringResource(R.string.input_axes), stringResource(R.string.input_extra_keys)), bindingsTab) { bindingsTab = it }
|
||||
InputPage.PROFILE -> {
|
||||
SettingsGroup(stringResource(R.string.input_profile_controls)) {
|
||||
for (r in InputRole.entries) InputNavigationRow(roleLabel(r),
|
||||
if (r == InputRole.PHYSICAL) stringResource(R.string.input_physical_hint) else library.layout(profileId, r)?.name,
|
||||
Modifier.testTag("input-part-${r.name.lowercase()}"), leading = {
|
||||
library.layout(profileId, r)?.let { InputLayoutThumbnail(it, r) }
|
||||
}) { editPart(r) }
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Actions {
|
||||
SecondaryButton(stringResource(R.string.input_rename)) { rename(R.string.input_rename, profile.name) { name -> update { it.withProfile(profile.copy(name = name)) } } }
|
||||
SecondaryButton(stringResource(R.string.input_copy_profile)) { newProfile(true) }
|
||||
SecondaryButton(stringResource(R.string.input_reset_actions)) {
|
||||
confirmation = InputConfirmation(context.getString(R.string.input_reset_actions), context.getString(R.string.input_reset_profile_detail, profile.name)) { update { it.resetProfile(profileId) } }
|
||||
}
|
||||
if (bindingsTab != 2) InputControlGrid(preset, InputControl.padControls.asList(), bindingsTab == 1) { edit = InputBindingEdit(preset.id, it) }
|
||||
else {
|
||||
for (b in preset.keys) {
|
||||
InputNavigationRow(b.key.label, actionLabel(b.action)) { edit = InputBindingEdit(preset.id, InputControl.A, key = b.key) }
|
||||
PadTextButton(onClick = { update { it.withPreset(preset.copy(keys = preset.keys - b)) } }) { Text(stringResource(R.string.input_remove_binding)) }
|
||||
if (profileId !in listOf(InputProfile.GAME, InputProfile.DESKTOP)) SecondaryButton(stringResource(R.string.input_delete)) {
|
||||
confirmation = InputConfirmation(context.getString(R.string.input_delete), context.getString(R.string.input_delete_profile_detail, profile.name)) {
|
||||
if (update { it.removeProfile(profileId) }) { profileId = InputProfile.GAME; go(InputPage.HOME) }
|
||||
}
|
||||
InputNavigationRow(stringResource(R.string.input_capture), null) { capture = true }
|
||||
}
|
||||
val defaults = InputProfile.defaults(profile.base).bindings[InputRole.PHYSICAL].orEmpty()
|
||||
if (preset.controls != defaults || preset.keys.isNotEmpty()) ActionRow(stringResource(R.string.input_reset_actions), null,
|
||||
stringResource(R.string.hud_reset_button), { update { it.withPreset(preset.copy(controls = defaults, keys = emptyList())) } },
|
||||
modifier = Modifier.testTag("input-remap-reset"))
|
||||
}
|
||||
}
|
||||
InputPage.SOURCE -> {
|
||||
if (role == InputRole.PRIMARY) SettingsGroup(stringResource(R.string.input_screen_visibility)) {
|
||||
ChoiceRow(host, "controller-osc", stringResource(R.string.mode_osc), stringResource(R.string.input_visibility_shared),
|
||||
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)),
|
||||
oscMode) { SessionPrefs.setOscMode(context, it); oscMode = it; onChanged() }
|
||||
}
|
||||
if (layout != null) SettingsGroup(stringResource(R.string.ctrl_layout)) {
|
||||
if (layout.editable) InputNavigationRow(stringResource(R.string.input_edit_layout), layout.name, Modifier.testTag("input-surface-${role.name.lowercase()}")) { surface = true }
|
||||
else InputHint(layout.name)
|
||||
InputNavigationRow(stringResource(R.string.input_saved_layouts), stringResource(R.string.input_saved_layouts_hint)) { go(InputPage.LAYOUTS) }
|
||||
if (layout.editable) {
|
||||
if (role != InputRole.PRIMARY || PadKit.forOverlay(context, layout) == null) {
|
||||
InputColorRow(host, layout.style.tint) { color -> update { it.withLayout(layout.copy(style = layout.style.copy(tint = color))) } }
|
||||
}
|
||||
SliderRow(stringResource(R.string.ctrl_opacity), null, layout.style.opacity, 1..100, step = 1,
|
||||
format = { "$it%" }) { opacity -> update { it.withLayout(layout.copy(style = layout.style.copy(opacity = opacity))) } }
|
||||
for (button in layout.quickButtons) ToggleRow(host, "quick-${button.name.lowercase()}", stringResource(quickButtonLabel(button)), null,
|
||||
button !in layout.style.hidden) { on -> update { it.withLayout(layout.withQuickButton(button, on)) } }
|
||||
}
|
||||
if (role == InputRole.SECONDARY) InputHint(stringResource(R.string.input_second_screen_enable))
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.input_assign_actions)) {
|
||||
val users = library.usersOfBindings(preset.id)
|
||||
if (users.size > 1) InputHint(stringResource(R.string.input_shared_with, users.filterNot { it.id == profileId }.joinToString { it.name }))
|
||||
val elements = layout?.takeIf { it.editable }?.elements
|
||||
if (elements != null) {
|
||||
if (elements.isEmpty()) InputHint(stringResource(R.string.input_empty_elements))
|
||||
for (e in elements) {
|
||||
InputNavigationRow(e.name, actionLabel(preset.action(e)), Modifier.testTag("input-element-${e.id}")) { edit = InputBindingEdit(preset.id, e.control, e) }
|
||||
if (e.hasClick) InputNavigationRow(stringResource(R.string.input_click_name, e.name), actionLabel(preset.clickAction(e)), Modifier.testTag("input-click-${e.id}")) { edit = InputBindingEdit(preset.id, InputControl.A, e, click = true) }
|
||||
}
|
||||
} else {
|
||||
Box(Modifier.padding(horizontal = 12.dp, vertical = 12.dp)) {
|
||||
SheetChips(listOf(stringResource(R.string.input_buttons), stringResource(R.string.input_axes)) +
|
||||
if (preset.physical) listOf(stringResource(R.string.input_extra_keys)) else emptyList(), bindingsTab) { bindingsTab = it }
|
||||
}
|
||||
val controls = InputControl.padControls.asList()
|
||||
if (bindingsTab != 2) InputControlGrid(preset, controls, bindingsTab == 1) { edit = InputBindingEdit(preset.id, it) }
|
||||
else {
|
||||
for (b in preset.keys) {
|
||||
InputNavigationRow(b.key.label, actionLabel(b.action)) { edit = InputBindingEdit(preset.id, InputControl.A, key = b.key) }
|
||||
PadTextButton(onClick = { update { it.withPreset(preset.copy(keys = preset.keys - b)) } }) { Text(stringResource(R.string.input_remove_binding)) }
|
||||
}
|
||||
InputNavigationRow(stringResource(R.string.input_capture), stringResource(R.string.input_capture_hint)) { capture = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.input_reuse)) {
|
||||
InputNavigationRow(stringResource(R.string.input_use_settings_from), stringResource(R.string.input_reuse_hint)) { go(InputPage.REUSE) }
|
||||
if (library.usersOfBindings(preset.id).size > 1 || layout?.let { it.editable && library.usersOfLayout(it.id).size > 1 } == true)
|
||||
InputNavigationRow(stringResource(R.string.input_make_independent), stringResource(R.string.input_independent_hint), Modifier.testTag("input-make-independent")) {
|
||||
update { it.usePart(profileId, role, profileId, shared = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
InputPage.LAYOUTS -> {
|
||||
InputHint(stringResource(R.string.input_layout_geometry_hint))
|
||||
SettingsGroup(stringResource(R.string.input_saved_layouts)) {
|
||||
var showOther by remember { mutableStateOf(false) }
|
||||
val available = library.layouts.filter { it.supports(role) }
|
||||
val other = available.filter { saved -> !saved.id.startsWith("builtin.") && saved.id != layout?.id &&
|
||||
library.usersOfLayout(saved.id).isEmpty() && library.bindings.none { it.layoutId == saved.id && library.selectedBindings(it.id) } }
|
||||
for (saved in available.filter { showOther || it !in other }) {
|
||||
InputLayoutRow(saved, role, if (saved.id == layout?.id) stringResource(R.string.input_current_layout) else null,
|
||||
onManage = { managingLayout = saved }) {
|
||||
reuse = InputReuseRequest(saved.name, layoutOnly = true) { shared -> if (update { it.useLayout(profileId, role, saved.id, shared) }) go(InputPage.SOURCE) }
|
||||
}
|
||||
}
|
||||
if (other.isNotEmpty()) PadTextButton(onClick = { showOther = !showOther }, modifier = Modifier.padding(8.dp)) {
|
||||
Text(stringResource(if (showOther) R.string.input_hide_other_layouts else R.string.input_other_layouts, other.size))
|
||||
}
|
||||
Row {
|
||||
PadTextButton(onClick = { naming = InputNameRequest(R.string.input_new_layout, "") { name, _, _ ->
|
||||
val created = SavedInputLayout(newInputId(), name, screen = if (role == InputRole.PRIMARY) InputLayoutScreen.MAIN else InputLayoutScreen.SECONDARY)
|
||||
if (update { it.withLayout(created).useLayout(profileId, role, created.id, shared = true) }) { go(InputPage.SOURCE); surface = true }
|
||||
} }, modifier = Modifier.padding(8.dp)) { Text(stringResource(R.string.input_new_layout)) }
|
||||
PadTextButton(onClick = { importer.launch(arrayOf("application/json", "text/plain", "application/octet-stream", "*/*")) },
|
||||
modifier = Modifier.padding(8.dp).testTag("input-layout-import")) { Text(stringResource(R.string.boot_movie_import)) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
InputPage.REUSE -> {
|
||||
InputHint(stringResource(R.string.input_reuse_explanation, roleLabel(role)))
|
||||
SettingsGroup(stringResource(R.string.input_profiles)) {
|
||||
for (p in library.profiles.filterNot { it.id == profileId }) InputNavigationRow(p.name, library.layout(p.id, role)?.name) {
|
||||
reuse = InputReuseRequest(p.name, layoutOnly = false) { shared -> if (update { it.usePart(profileId, role, p.id, shared) }) go(InputPage.SOURCE) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
managingLayout?.let { saved -> AlertDialog(onDismissRequest = { managingLayout = null }, title = { Text(saved.name) },
|
||||
text = { Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text(stringResource(R.string.input_layout_count, saved.elements.size))
|
||||
SecondaryButton(stringResource(R.string.input_rename)) {
|
||||
managingLayout = null
|
||||
rename(R.string.input_rename_layout, saved.name) { name -> update { it.withLayout(saved.copy(name = name)) } }
|
||||
}
|
||||
val exported = remember(saved, library) {
|
||||
val metrics = inputDisplayMetrics(context, if (saved.screen == InputLayoutScreen.SECONDARY) InputRole.SECONDARY else InputRole.PRIMARY)
|
||||
InputLayoutFile.export(saved, library.bindings.firstOrNull { it.id == preset.id && it.layoutId == saved.id }
|
||||
?: library.bindings.firstOrNull { it.layoutId == saved.id }, metrics.widthPixels, metrics.heightPixels)
|
||||
}
|
||||
if (exported != null) SecondaryButton(stringResource(R.string.screen_key_layout_export)) {
|
||||
managingLayout = null
|
||||
exporting = exported
|
||||
exporter.launch(InputLayoutFile.fileName(saved))
|
||||
}
|
||||
val used = library.usersOfLayout(saved.id).isNotEmpty() || library.bindings.any { it.layoutId == saved.id && library.selectedBindings(it.id) }
|
||||
if (!used && saved.editable) SecondaryButton(stringResource(R.string.input_delete)) {
|
||||
managingLayout = null
|
||||
confirmation = InputConfirmation(context.getString(R.string.input_delete), context.getString(R.string.input_delete_layout_detail, saved.name)) { update { it.removeLayout(saved.id) } }
|
||||
}
|
||||
} }, confirmButton = { PadTextButton(onClick = { managingLayout = null }) { Text(stringResource(R.string.common_close)) } }) }
|
||||
if (capture) InputCaptureDialog(onDismiss = { capture = false }) { capture = false; edit = InputBindingEdit(preset.id, InputControl.A, key = it) }
|
||||
surface?.let { (profileId, layoutId, bindingsId) ->
|
||||
val name = library.layouts.firstOrNull { it.id == layoutId }?.name.orEmpty()
|
||||
InputSurfaceDialog(profileId, onDismiss = { surface = null; changed() }, onChanged = ::changed, role = InputRole.PRIMARY,
|
||||
layoutId = layoutId, bindingsId = bindingsId, scope = stringResource(R.string.osc_scope_default, name))
|
||||
}
|
||||
if (surface) InputSurfaceDialog(profileId, onDismiss = { surface = false; library = InputLibraries.read(context) }, onChanged = {
|
||||
library = InputLibraries.read(context); onChanged()
|
||||
}, role = role, layoutId = layout?.id, bindingsId = preset.id)
|
||||
naming?.let { request -> key(request) { InputNameDialog(request) { naming = null } } }
|
||||
reuse?.let { request -> key(request) { InputReuseDialog(request) { reuse = null } } }
|
||||
confirmation?.let { request -> AlertDialog(onDismissRequest = { confirmation = null }, title = { Text(request.title) },
|
||||
text = { Text(request.detail) }, confirmButton = { PadTextButton(onClick = { confirmation = null; request.action() }) { Text(stringResource(R.string.common_ok)) } },
|
||||
dismissButton = { PadTextButton(onClick = { confirmation = null }) { Text(stringResource(R.string.common_cancel)) } }) }
|
||||
error?.let { message -> AlertDialog(onDismissRequest = { error = null }, title = { Text(stringResource(R.string.input_save_failed)) },
|
||||
text = { Text(message) }, confirmButton = { PadTextButton(onClick = { error = null }) { Text(stringResource(R.string.common_ok)) } }) }
|
||||
}
|
||||
|
||||
/** The in-game "On-screen controls" group, for games without a layout of their own. */
|
||||
@Composable
|
||||
private fun DefaultControlsGroup(host: MenuHost, revision: Int, onEdit: (Triple<String, String, String>) -> Unit, onChanged: () -> Unit,
|
||||
onFailure: (Throwable) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val options = remember(revision) { ControlsChoice.options(context, null, steamMode = true) }
|
||||
val choice = remember(revision) { ControlsChoice.current(context, null, steamMode = true) }
|
||||
var oscMode by remember { mutableStateOf(SessionPrefs.oscMode(context)) }
|
||||
var touch by remember { mutableStateOf(SessionPrefs.touchMode(context)) }
|
||||
var below by remember { mutableStateOf(SessionPrefs.unfoldedControls(context)) }
|
||||
SettingsGroup(stringResource(R.string.osc_group_for, stringResource(R.string.osc_default))) {
|
||||
ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), null, options, choice) { id ->
|
||||
runCatching { ControlsChoice.choose(context, null, id, desktop = false) }.onSuccess { onChanged() }.onFailure(onFailure)
|
||||
private fun InputNameDialog(request: InputNameRequest, onDismiss: () -> Unit) {
|
||||
var name by remember { mutableStateOf(request.initial) }
|
||||
var source by remember { mutableStateOf(request.source) }
|
||||
var shared by remember { mutableStateOf(false) }
|
||||
val host = rememberMenuHost()
|
||||
AlertDialog(onDismissRequest = onDismiss, title = { Text(stringResource(request.title)) }, text = { Column(Modifier.verticalScroll(rememberScrollState())) {
|
||||
OutlinedTextField(name, { name = it.take(80) }, label = { Text(stringResource(R.string.input_name)) }, singleLine = true, modifier = Modifier.testTag("input-name"))
|
||||
if (request.sources.isNotEmpty()) ChoiceRow(host, "input-copy-source", stringResource(R.string.input_start_from), null, request.sources, source) { source = it }
|
||||
if (request.offerSharing) {
|
||||
Row(Modifier.fillMaxWidth().focusRow(role = Role.Checkbox, checked = shared) { shared = !shared }.testTag("input-share-physical"), verticalAlignment = Alignment.CenterVertically) {
|
||||
Checkbox(shared, null)
|
||||
Text(stringResource(R.string.input_share_physical))
|
||||
}
|
||||
Text(stringResource(R.string.input_new_independent_hint), style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
if (choice != GameControls.STEAM) ActionRow(stringResource(R.string.osc_edit_layout), null, stringResource(R.string.ctrl_edit), {
|
||||
host.open = null
|
||||
ControlsChoice.editTarget(context, null, desktop = false)?.let(onEdit)
|
||||
}, modifier = Modifier.testTag("osc-edit"))
|
||||
SettingsRow(stringResource(R.string.osc_show), null) {
|
||||
SegmentedTabs(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)), oscMode,
|
||||
tabModifier = { Modifier.testTag("osc-$it") }) { SessionPrefs.setOscMode(context, it); oscMode = it; onChanged() }
|
||||
} }, confirmButton = { PadTextButton(enabled = name.isNotBlank(), onClick = { request.save(name.trim(), source, shared); onDismiss() }) { Text(stringResource(R.string.gesture_save_changes)) } },
|
||||
dismissButton = { PadTextButton(onClick = onDismiss) { Text(stringResource(R.string.common_cancel)) } })
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InputReuseDialog(request: InputReuseRequest, onDismiss: () -> Unit) {
|
||||
var shared by remember { mutableStateOf(false) }
|
||||
AlertDialog(onDismissRequest = onDismiss, title = { Text(request.name) }, text = { Column(Modifier.verticalScroll(rememberScrollState())) {
|
||||
Text(stringResource(if (request.layoutOnly) R.string.input_reuse_layout_detail else R.string.input_reuse_part_detail))
|
||||
for (link in listOf(false, true)) Row(Modifier.fillMaxWidth().focusRow(role = Role.RadioButton, checked = shared == link) { shared = link }, verticalAlignment = Alignment.CenterVertically) {
|
||||
RadioButton(shared == link, null)
|
||||
Text(stringResource(if (link) R.string.input_keep_shared else R.string.input_independent_copy))
|
||||
}
|
||||
ChoiceRow(host, "touch", stringResource(R.string.input_touches), null,
|
||||
listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.common_auto), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_mouse),
|
||||
SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), SessionPrefs.TOUCH_GESTURES to stringResource(R.string.mode_touch_gestures),
|
||||
SessionPrefs.TOUCH_OFF to stringResource(R.string.widgets_off)), touch) { SessionPrefs.setTouchMode(context, it); touch = it; onChanged() }
|
||||
ToggleRow(host, "unfolded-controls", stringResource(R.string.unfolded_controls), null, below) {
|
||||
SessionPrefs.setUnfoldedControls(context, it); below = it; onChanged()
|
||||
}
|
||||
}
|
||||
} }, confirmButton = { PadTextButton(onClick = { request.apply(shared); onDismiss() }) { Text(stringResource(R.string.common_ok)) } },
|
||||
dismissButton = { PadTextButton(onClick = onDismiss) { Text(stringResource(R.string.common_cancel)) } })
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -241,9 +451,10 @@ private fun InputControlGrid(preset: SavedInputBindings, available: List<InputCo
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InputNavigationRow(title: String, detail: String?, modifier: Modifier = Modifier, onClick: () -> Unit) {
|
||||
private fun InputNavigationRow(title: String, detail: String?, modifier: Modifier = Modifier, leading: (@Composable () -> Unit)? = null, onClick: () -> Unit) {
|
||||
Row(modifier.fillMaxWidth().focusRow(RoundedCornerShape(0.dp), onClick = onClick).heightIn(min = 64.dp).padding(14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
leading?.invoke()
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||
if (detail != null) Text(detail, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
@@ -252,6 +463,43 @@ private fun InputNavigationRow(title: String, detail: String?, modifier: Modifie
|
||||
}
|
||||
}
|
||||
|
||||
internal fun quickButtonLabel(button: InputCommand) = when (button) {
|
||||
InputCommand.STEAM -> R.string.ctrl_steam_button
|
||||
InputCommand.QUICK_ACCESS -> R.string.ctrl_qam_button
|
||||
else -> R.string.ctrl_keyboard_button
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
internal fun inputDisplayMetrics(context: Context, role: InputRole): DisplayMetrics = DisplayMetrics().also { metrics ->
|
||||
(context.findActivity() as? com.droiddeck.launcher.SessionActivity)?.inputEditorDisplay(role)?.getRealMetrics(metrics)
|
||||
?: metrics.setTo(context.resources.displayMetrics)
|
||||
}
|
||||
|
||||
private fun readLayoutFile(context: Context, uri: Uri): String? = runCatching {
|
||||
context.contentResolver.openInputStream(uri)?.use { input ->
|
||||
val out = java.io.ByteArrayOutputStream()
|
||||
val buffer = ByteArray(8192)
|
||||
while (true) {
|
||||
val read = input.read(buffer)
|
||||
if (read < 0) break
|
||||
out.write(buffer, 0, read)
|
||||
if (out.size() > 1_000_000) return@use null
|
||||
}
|
||||
out.toString(Charsets.UTF_8.name())
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
private fun layoutFileName(context: Context, uri: Uri): String? = runCatching {
|
||||
context.contentResolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use { cursor ->
|
||||
if (cursor.moveToFirst()) cursor.getString(0)?.substringBeforeLast('.')?.trim()?.takeIf { it.isNotEmpty() } else null
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
@Composable
|
||||
internal fun roleLabel(role: InputRole) = stringResource(when (role) {
|
||||
InputRole.PHYSICAL -> R.string.input_physical; InputRole.PRIMARY -> R.string.input_primary; InputRole.SECONDARY -> R.string.input_secondary
|
||||
})
|
||||
|
||||
@Composable
|
||||
private fun InputHint(text: String) {
|
||||
Text(text, Modifier.padding(14.dp), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
|
||||
@@ -63,24 +63,40 @@ import com.droiddeck.launcher.session.SessionState
|
||||
private data class SurfaceSnapshot(val elements: List<InputSurfaceElement>, val actions: Map<String, InputAction>,
|
||||
val clicks: Map<String, InputAction>, val scale: Float, val aspect: Float)
|
||||
|
||||
private class GamepadScaler(private val context: android.content.Context, private val width: Int, private val height: Int) {
|
||||
private fun generator(scale: Float) = LegacyGamepadLayout(context, width, height, scale = scale)
|
||||
val ids = generator(1f).elements().map { it.id }.toSet()
|
||||
fun rescale(stored: List<InputSurfaceElement>, from: Float, to: Float) = generator(to).rescale(stored, generator(from))
|
||||
fun reset(stored: List<InputSurfaceElement>) = generator(1f).regenerate(stored).associateBy { it.id }.let { placed -> stored.map { placed[it.id] ?: it } }
|
||||
}
|
||||
|
||||
private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputBindings, val defaults: List<InputSurfaceElement>? = null,
|
||||
private val defaultsFrame: Float = 0f, snap: Boolean = true) {
|
||||
private val defaultsFrame: Float = 0f, private var gamepad: GamepadScaler? = null, snap: Boolean = true) {
|
||||
val hasGamepad get() = gamepad != null
|
||||
var elements by mutableStateOf(layout.elements)
|
||||
var actions by mutableStateOf(preset.elements)
|
||||
var clicks by mutableStateOf(preset.clicks)
|
||||
var selected by mutableStateOf<String?>(null)
|
||||
var toolsExpanded by mutableStateOf(false)
|
||||
var toolsX by mutableFloatStateOf(.02f)
|
||||
var toolsY by mutableFloatStateOf(.02f)
|
||||
var snap by mutableStateOf(snap)
|
||||
var popover by mutableStateOf<EditorPopover?>(null)
|
||||
var confirmDiscard by mutableStateOf(false)
|
||||
var adding by mutableStateOf(false)
|
||||
var properties by mutableStateOf(false)
|
||||
var clickProperties by mutableStateOf(false)
|
||||
var history by mutableStateOf<List<SurfaceSnapshot>>(emptyList())
|
||||
var layoutScale by mutableFloatStateOf(layout.scale)
|
||||
var aspect by mutableFloatStateOf(layout.aspect)
|
||||
private var scaleBase by mutableStateOf<Pair<List<InputSurfaceElement>, List<InputSurfaceElement>>?>(null)
|
||||
private var scaleBase by mutableStateOf<Triple<List<InputSurfaceElement>, List<InputSurfaceElement>, Float>?>(null)
|
||||
private var scaleValue by mutableIntStateOf(100)
|
||||
val scale get() = if (scaleBase?.second == elements) scaleValue else 100
|
||||
val positioned get() = defaults?.let { elements.withPositionsOf(refit(it, defaultsFrame)) }?.takeIf { it != elements }
|
||||
private val rescales get() = gamepad?.let { pad -> elements.any { it.id in pad.ids } } == true
|
||||
val scale get() = when {
|
||||
scaleBase?.second == elements -> scaleValue
|
||||
rescales -> (layoutScale * 100).roundToInt()
|
||||
else -> 100
|
||||
}
|
||||
val positioned get() = (if (rescales) gamepad!!.reset(elements) else defaults?.let { elements.withPositionsOf(refit(it, defaultsFrame)) })
|
||||
?.takeIf { it != elements || rescales && layoutScale != 1f }
|
||||
|
||||
private fun refit(placed: List<InputSurfaceElement>, from: Float): List<InputSurfaceElement> {
|
||||
if (from <= 0f || aspect <= 0f || abs(from / aspect - 1f) < .01f) return placed
|
||||
@@ -90,71 +106,50 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
|
||||
val dirty get() = elements != layout.elements || actions != preset.elements || clicks != preset.clicks || layoutScale != layout.scale || aspect != layout.aspect
|
||||
fun checkpoint() { history = (history + SurfaceSnapshot(elements, actions, clicks, layoutScale, aspect)).takeLast(40) }
|
||||
fun undo() { history.lastOrNull()?.let { elements = it.elements; actions = it.actions; clicks = it.clicks; layoutScale = it.scale; aspect = it.aspect; history = history.dropLast(1) } }
|
||||
fun beginEdit(displayed: List<InputSurfaceElement>, aspect: Float) {
|
||||
fun beginEdit(displayed: List<InputSurfaceElement>, aspect: Float, scaler: GamepadScaler? = gamepad) {
|
||||
checkpoint()
|
||||
elements = OnScreenLayout.editorFrame(layout.copy(elements = elements), displayed)
|
||||
this.aspect = aspect
|
||||
scaler?.let { gamepad = it }
|
||||
}
|
||||
fun scaleAll(percent: Int) {
|
||||
val base = scaleBase?.takeIf { it.second == elements } ?: (elements to elements).also { checkpoint() }
|
||||
elements = base.first.scaled(percent / 100f)
|
||||
scaleValue = percent; scaleBase = base.first to elements
|
||||
}
|
||||
fun resetPositions() { positioned?.let { checkpoint(); elements = it } }
|
||||
private val restored get() = defaults?.let { refit(it, defaultsFrame) }
|
||||
private fun matches(defaults: List<InputSurfaceElement>, placed: List<InputSurfaceElement>) = defaults.size == placed.size && defaults.all { a ->
|
||||
placed.any { e -> e.copy(x = a.x, y = a.y, width = a.width, height = a.height) == a &&
|
||||
abs(e.x - a.x) < .002f && abs(e.y - a.y) < .002f && abs(e.width - a.width) < .002f && abs(e.height - a.height) < .002f }
|
||||
}
|
||||
val atDefaults get() = restored?.let { matches(it, elements) } == true
|
||||
/** The kit's own controls are where the kit puts them, so only the added ones need saving. */
|
||||
val kitAtDefaults get() = restored?.let { matches(it, elements.filter { e -> KitLayout.isKit(e.id) }) } == true
|
||||
fun reset() {
|
||||
val d = restored?.takeIf { !atDefaults } ?: return
|
||||
checkpoint(); elements = d; selected = null
|
||||
actions = actions.filterKeys { id -> KitLayout.bindsTo(id, d) }; clicks = clicks.filterKeys { id -> d.any { it.id == id } }
|
||||
}
|
||||
fun hiddenDefaults(): List<InputSurfaceElement> = defaults?.let { refit(it, defaultsFrame) }?.filter { d -> elements.none { it.id == d.id } }.orEmpty()
|
||||
fun add(element: InputSurfaceElement) { checkpoint(); elements = elements + element; selected = element.id; popover = null }
|
||||
fun remove(id: String) {
|
||||
checkpoint(); elements = elements.filterNot { it.id == id }; selected = null
|
||||
if (!KitLayout.isKit(id)) { actions = actions - id; clicks = clicks - id }
|
||||
}
|
||||
fun resizeSelected(factor: Float) {
|
||||
val e = element ?: return
|
||||
checkpoint()
|
||||
val w = (e.width * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f); val h = (e.height * factor).coerceIn(InputSurfaceElement.MIN_SIZE, 1f)
|
||||
val cx = e.x + e.width / 2; val cy = e.y + e.height / 2
|
||||
elements = elements.map { if (it.id == e.id) e.copy(x = (cx - w / 2).coerceIn(0f, 1f - w), y = (cy - h / 2).coerceIn(0f, 1f - h), width = w, height = h).bounded() else it }
|
||||
val base = scaleBase?.takeIf { it.second == elements } ?: Triple(elements, elements, if (rescales) layoutScale else 0f).also { checkpoint() }
|
||||
val factor = percent / 100f
|
||||
val pad = gamepad
|
||||
elements = if (base.third > 0f && pad != null) {
|
||||
layoutScale = factor
|
||||
val others = base.first.filterNot { it.id in pad.ids }.scaled(factor / base.third).associateBy { it.id }
|
||||
pad.rescale(base.first, base.third, factor).map { others[it.id] ?: it }
|
||||
} else base.first.scaled(factor)
|
||||
scaleValue = percent; scaleBase = Triple(base.first, elements, base.third)
|
||||
}
|
||||
fun resetPositions() { positioned?.let { checkpoint(); elements = it; if (rescales) layoutScale = 1f } }
|
||||
fun action(e: InputSurfaceElement) = preset.copy(elements = actions).action(e)
|
||||
fun clickAction(e: InputSurfaceElement) = preset.copy(elements = actions, clicks = clicks).clickAction(e)
|
||||
}
|
||||
|
||||
/** Offered when the layout being edited is shared: [create] makes the copy that Done then saves into, and [scope] describes it. */
|
||||
/** Turns an edit of a shared layout into a copy for one game: [copy] adds it to the library being saved, [use] picks it once that save succeeded. */
|
||||
class InputEditorSplit(val label: String, val scope: String, val copy: (InputLibrary, String, String) -> InputLibrary, val use: (String) -> Unit)
|
||||
|
||||
@Composable
|
||||
fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () -> Unit,
|
||||
role: InputRole = InputRole.SECONDARY, layoutId: String? = null, bindingsId: String? = null, scope: String? = null,
|
||||
split: InputEditorSplit? = null) {
|
||||
role: InputRole = InputRole.SECONDARY, layoutId: String? = null, bindingsId: String? = null) {
|
||||
val context = LocalContext.current
|
||||
val host = LocalInputActivity.current ?: context.findActivity() as? ComponentActivity
|
||||
val library = remember { InputLibraries.read(context) }
|
||||
val savedLayout = remember { library.layouts.first { it.id == (layoutId ?: library.profile(profile).parts.getValue(role).layout) } }
|
||||
val savedBindings = remember { library.preset(bindingsId ?: library.profile(profile).binding(role)) }
|
||||
val layoutUsers = library.usersOfLayout(savedLayout.id).size
|
||||
var splitting by remember { mutableStateOf(false) }
|
||||
val bindingUsers = library.usersOfBindings(savedBindings.id).size
|
||||
val draft = remember {
|
||||
val (display, metrics) = InputLibraries.primaryDisplay(context)
|
||||
val gamepad = savedLayout.elements.takeIf { e -> e.any { it.id.startsWith("legacy:") } }?.let {
|
||||
val (w, h) = OnScreenLayout.generatedSize(context, savedLayout, metrics.widthPixels, metrics.heightPixels) ?: (metrics.widthPixels to metrics.heightPixels)
|
||||
GamepadScaler(display, w, h)
|
||||
}
|
||||
val defaults = InputLibraries.defaultPositions(context, library, savedLayout)
|
||||
val start = if (OnScreenLayout.generated(savedLayout) && defaults != null) savedLayout.copy(elements = defaults.first +
|
||||
OnScreenLayout.fit(savedLayout.elements, savedLayout.aspect.takeIf { it > 0f } ?: defaults.second, 1f, (defaults.second * 1000).roundToInt(), 1000, Rect()),
|
||||
aspect = defaults.second) else savedLayout
|
||||
SurfaceDraft(start, savedBindings, defaults?.first, defaults?.second ?: 0f, ControllerPrefs.snap(context))
|
||||
SurfaceDraft(savedLayout, savedBindings, defaults?.first, defaults?.second ?: 0f, gamepad, ControllerPrefs.snap(context))
|
||||
}
|
||||
val manager = remember { context.getSystemService(DisplayManager::class.java) }
|
||||
var revision by remember { mutableIntStateOf(0) }
|
||||
var discard by remember { mutableStateOf(false) }
|
||||
var failure by remember { mutableStateOf<String?>(null) }
|
||||
val target = remember(revision, role) {
|
||||
if (host is SessionActivity) host.inputEditorDisplay(role)
|
||||
@@ -165,23 +160,15 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
|
||||
}
|
||||
}
|
||||
val remote = target != null && target.displayId != host?.window?.decorView?.display?.displayId
|
||||
fun leave() { if (draft.dirty) draft.confirmDiscard = true else onDismiss() }
|
||||
fun leave() { if (draft.dirty) discard = true else onDismiss() }
|
||||
fun save() {
|
||||
runCatching {
|
||||
val copy = split?.takeIf { splitting }
|
||||
val (layoutTarget, bindingsTarget) = if (copy != null) newInputId() to newInputId() else savedLayout.id to savedBindings.id
|
||||
InputLibraries.update(context) { saved ->
|
||||
val latest = copy?.copy?.invoke(saved, layoutTarget, bindingsTarget) ?: saved
|
||||
val l = latest.layouts.first { it.id == layoutTarget }
|
||||
val p = latest.preset(bindingsTarget)
|
||||
val generated = draft.kitAtDefaults && OnScreenLayout.generated(l.copy(elements = emptyList(), kitless = false))
|
||||
val extras = draft.elements.filterNot { KitLayout.isKit(it.id) }
|
||||
val edited = if (generated) l.copy(elements = extras, aspect = if (extras.isEmpty()) 0f else draft.aspect, scale = draft.layoutScale, kitless = false)
|
||||
else l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale, kitless = draft.elements.none { KitLayout.isKit(it.id) })
|
||||
latest.withLayout(edited).withPreset(p.copy(elements = draft.actions.filterKeys { id -> edited.element(id) != null },
|
||||
clicks = draft.clicks.filterKeys { id -> edited.element(id)?.hasClick == true }))
|
||||
InputLibraries.update(context) { latest ->
|
||||
val l = latest.layouts.first { it.id == savedLayout.id }
|
||||
val p = latest.preset(savedBindings.id)
|
||||
latest.withLayout(l.copy(elements = draft.elements, aspect = draft.aspect, scale = draft.layoutScale)).withPreset(p.copy(elements = draft.actions.filterKeys { id -> draft.elements.any { it.id == id } },
|
||||
clicks = draft.clicks.filterKeys { id -> draft.elements.any { it.id == id && it.hasClick } }))
|
||||
}
|
||||
copy?.use?.invoke(bindingsTarget)
|
||||
}.onSuccess { onChanged(); onDismiss() }.onFailure { failure = it.message ?: context.getString(R.string.input_save_failed) }
|
||||
}
|
||||
DisposableEffect(manager) {
|
||||
@@ -222,53 +209,56 @@ fun InputSurfaceDialog(profile: String, onDismiss: () -> Unit, onChanged: () ->
|
||||
androidx.compose.ui.graphics.Color.Transparent else MaterialTheme.colorScheme.surface) {
|
||||
val element = draft.element
|
||||
BackHandler { if (draft.properties) draft.properties = false else leave() }
|
||||
val editorScope = split?.scope?.takeIf { splitting } ?: scope ?: if (layoutUsers > 1) stringResource(R.string.input_editor_shared, layoutUsers) else savedLayout.name
|
||||
val splitLabel = split?.label?.takeIf { !splitting }
|
||||
val propertiesEditor: @Composable (InputSurfaceElement) -> Unit = { element ->
|
||||
var properties by remember(element.id) { mutableStateOf(element) }
|
||||
InputActionEditor(if (draft.clickProperties) InputControl.A else element.control,
|
||||
if (draft.clickProperties) draft.clickAction(element) else draft.action(element),
|
||||
if (draft.clickProperties) stringResource(R.string.input_click_name, element.name) else element.name,
|
||||
onBack = { draft.properties = false }, element = element, click = draft.clickProperties,
|
||||
properties = { action ->
|
||||
if (!draft.clickProperties) InputElementProperties(properties, action) { properties = it }
|
||||
}, detail = editorScope, onSave = { action ->
|
||||
draft.checkpoint()
|
||||
if (draft.clickProperties) draft.clicks = draft.clicks + (element.id to action) else draft.actions = draft.actions + (element.id to action)
|
||||
draft.elements = draft.elements.map { if (it.id == element.id) properties.copy(name = properties.name.trim().ifBlank { element.name }) else it }
|
||||
draft.properties = false
|
||||
})
|
||||
}
|
||||
when {
|
||||
(remote || target == null) && draft.properties && element != null -> propertiesEditor(element)
|
||||
draft.properties && element != null -> {
|
||||
var properties by remember(element.id) { mutableStateOf(element) }
|
||||
InputActionEditor(if (draft.clickProperties) InputControl.A else element.control,
|
||||
if (draft.clickProperties) draft.clickAction(element) else draft.action(element),
|
||||
if (draft.clickProperties) stringResource(R.string.input_click_name, element.name) else element.name,
|
||||
onBack = { draft.properties = false }, element = element, click = draft.clickProperties,
|
||||
properties = { action ->
|
||||
if (!draft.clickProperties) InputElementProperties(properties, action) { properties = it }
|
||||
if (layoutUsers > 1) Text(stringResource(R.string.input_editor_shared, layoutUsers),
|
||||
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 12.dp))
|
||||
}, detail = if (bindingUsers > 1) stringResource(R.string.input_shared_detail, savedBindings.name, bindingUsers)
|
||||
else "${library.profile(profile).name} · ${roleLabel(role)}", onSave = { action ->
|
||||
draft.checkpoint()
|
||||
if (draft.clickProperties) draft.clicks = draft.clicks + (element.id to action) else draft.actions = draft.actions + (element.id to action)
|
||||
draft.elements = draft.elements.map { if (it.id == element.id) properties.copy(name = properties.name.trim().ifBlank { element.name }) else it }
|
||||
draft.properties = false
|
||||
})
|
||||
}
|
||||
target == null -> SettingsPage(rememberMenuHost(), savedLayout.name, ::leave) {
|
||||
Text(stringResource(R.string.input_display_unavailable))
|
||||
failure?.let { Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error) }
|
||||
if (draft.confirmDiscard) {
|
||||
Text(stringResource(R.string.input_editor_discard), style = MaterialTheme.typography.titleSmall)
|
||||
SecondaryButton(stringResource(R.string.input_keep_editing)) { draft.confirmDiscard = false }
|
||||
SecondaryButton(stringResource(R.string.input_discard), onClick = onDismiss)
|
||||
}
|
||||
PrimaryButton(stringResource(R.string.input_editor_done)) { save() }
|
||||
}
|
||||
remote -> SettingsPage(rememberMenuHost(), stringResource(R.string.input_editor_remote), ::leave, lede = editorScope) {
|
||||
splitLabel?.let { SecondaryButton(it, compact = true, modifier = Modifier.padding(horizontal = 8.dp).testTag("input-editor-split")) { splitting = true } }
|
||||
SurfaceToolbar(draft, ::save, ::leave, onDismiss)
|
||||
failure?.let { Text(it, Modifier.padding(horizontal = 8.dp), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error) }
|
||||
remote -> SettingsPage(rememberMenuHost(), stringResource(R.string.input_editor_remote), ::leave,
|
||||
lede = if (layoutUsers > 1) stringResource(R.string.input_editor_shared, layoutUsers) else savedLayout.name) {
|
||||
SurfaceToolbar(draft, ::save, ::leave)
|
||||
SurfaceSelection(draft)
|
||||
when (draft.popover) { EditorPopover.ADD -> AddRows(draft); EditorPopover.HIDDEN -> HiddenRows(draft); null -> Unit }
|
||||
}
|
||||
else -> Box(Modifier.fillMaxSize()) {
|
||||
SurfaceCanvas(draft, transparent = host is SessionActivity && role == InputRole.PRIMARY)
|
||||
EditorChrome(draft, editorScope, splitLabel, { splitting = true }, failure, ::save, ::leave, onDismiss)
|
||||
if (draft.properties && element != null) Surface(Modifier.align(Alignment.CenterEnd).fillMaxHeight().fillMaxWidth(.44f),
|
||||
color = MaterialTheme.colorScheme.surface, shadowElevation = 12.dp) {
|
||||
propertiesEditor(element)
|
||||
}
|
||||
FloatingSurfaceTools(draft, ::save, ::leave)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (draft.adding) AlertDialog(onDismissRequest = { draft.adding = false }, title = { Text(stringResource(R.string.input_add_element)) }, confirmButton = {}, text = { Column {
|
||||
for (kind in InputElementKind.entries) PadTextButton(onClick = { draft.checkpoint()
|
||||
val w = if (kind.control.dimensions == 2) .4f else .2f
|
||||
val h = .3f
|
||||
val name = context.getString(kind.label()) + " " + (draft.elements.count { it.kind == kind } + 1)
|
||||
val element = InputSurfaceElement(kind.control, (1f - w) / 2, (1f - h) / 2, w, h, newInputId(), kind, name)
|
||||
draft.elements = draft.elements + element; draft.selected = element.id
|
||||
draft.adding = false; draft.toolsExpanded = false }) { Text(stringResource(kind.label())) }
|
||||
} })
|
||||
if (discard) AlertDialog(onDismissRequest = { discard = false }, title = { Text(stringResource(R.string.input_editor_discard)) },
|
||||
confirmButton = { PadTextButton(onClick = onDismiss) { Text(stringResource(R.string.common_ok)) } },
|
||||
dismissButton = { PadTextButton(onClick = { discard = false }) { Text(stringResource(R.string.common_cancel)) } })
|
||||
failure?.let { AlertDialog(onDismissRequest = { failure = null }, title = { Text(stringResource(R.string.input_save_failed)) }, text = { Text(it) },
|
||||
confirmButton = { PadTextButton(onClick = { failure = null }) { Text(stringResource(R.string.common_ok)) } }) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -277,158 +267,70 @@ private fun SurfaceCanvas(draft: SurfaceDraft, transparent: Boolean = false) {
|
||||
update = { view ->
|
||||
view.setBackgroundColor(if (transparent) android.graphics.Color.TRANSPARENT else android.graphics.Color.rgb(10, 11, 13))
|
||||
view.style = draft.layout.style.copy(hidden = emptySet()); view.sourceLayout = draft.layout; view.aspect = draft.aspect; view.elements = draft.elements; view.selected = draft.selected; view.snap = draft.snap
|
||||
view.isEnabled = !draft.properties && draft.popover == null && !draft.confirmDiscard
|
||||
view.isEnabled = !draft.properties && !draft.adding
|
||||
view.onSelect = { if (!draft.properties) draft.selected = it }
|
||||
view.onBeginEdit = { e, w, h -> draft.beginEdit(e, w.toFloat() / h) }
|
||||
view.onBeginEdit = { e, w, h -> draft.beginEdit(e, w.toFloat() / h, if (draft.hasGamepad) GamepadScaler(view.context, w, h) else null) }
|
||||
view.onChange = { e -> if (!draft.properties) draft.elements = draft.elements.map { if (it.id == e.id) e else it } }
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private enum class EditorPopover { ADD, HIDDEN }
|
||||
|
||||
@Composable
|
||||
private fun EditorBar(modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit) {
|
||||
Surface(modifier, shape = RoundedCornerShape(16.dp), color = MaterialTheme.colorScheme.surface.copy(alpha = .96f),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface, shadowElevation = 8.dp) {
|
||||
Row(Modifier.horizontalScroll(rememberScrollState()).padding(6.dp), horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically, content = content)
|
||||
}
|
||||
}
|
||||
|
||||
/** The editor's tools over the canvas: one toolbar, a bar on the selected control, and the Add and Hidden lists. */
|
||||
@Composable
|
||||
private fun EditorChrome(draft: SurfaceDraft, scope: String, splitLabel: String?, onSplit: () -> Unit, failure: String?,
|
||||
onSave: () -> Unit, onLeave: () -> Unit, onDiscard: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
private fun FloatingSurfaceTools(draft: SurfaceDraft, onSave: () -> Unit, onLeave: () -> Unit) {
|
||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
Column(Modifier.align(Alignment.TopCenter).padding(top = 10.dp).widthIn(max = maxWidth - 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
EditorBar(Modifier.testTag("input-editor-tools")) {
|
||||
if (draft.confirmDiscard) {
|
||||
Text(stringResource(R.string.input_editor_discard), Modifier.padding(horizontal = 8.dp), style = MaterialTheme.typography.titleSmall)
|
||||
SecondaryButton(stringResource(R.string.input_keep_editing), compact = true) { draft.confirmDiscard = false }
|
||||
PrimaryButton(stringResource(R.string.input_discard), compact = true, onClick = onDiscard)
|
||||
} else {
|
||||
SecondaryButton(stringResource(R.string.common_cancel), compact = true, onClick = onLeave)
|
||||
SecondaryButton(stringResource(R.string.input_editor_undo), enabled = draft.history.isNotEmpty(), compact = true) { draft.undo() }
|
||||
SecondaryButton(stringResource(R.string.input_editor_add), enabled = draft.elements.size < 64, compact = true) {
|
||||
draft.popover = if (draft.popover == EditorPopover.ADD) null else EditorPopover.ADD
|
||||
val density = LocalDensity.current
|
||||
val screenWidth = with(density) { maxWidth.toPx() }
|
||||
val screenHeight = with(density) { maxHeight.toPx() }
|
||||
val margin = with(density) { 8.dp.toPx() }
|
||||
var panelSize by remember { mutableStateOf(IntSize.Zero) }
|
||||
val x = (draft.toolsX * screenWidth).coerceIn(margin, (screenWidth - panelSize.width - margin).coerceAtLeast(margin))
|
||||
val y = (draft.toolsY * screenHeight).coerceIn(margin, (screenHeight - panelSize.height - margin).coerceAtLeast(margin))
|
||||
val position by rememberUpdatedState(Offset(x, y))
|
||||
val expandedWidth = minOf(420.dp, maxWidth - 16.dp)
|
||||
val panelWidth by animateDpAsState(if (draft.toolsExpanded) expandedWidth else 152.dp, label = "input-tools-width")
|
||||
Surface(Modifier.offset { IntOffset(x.roundToInt(), y.roundToInt()) }
|
||||
.width(panelWidth).clipToBounds()
|
||||
.heightIn(max = maxHeight - 16.dp).onSizeChanged { panelSize = it },
|
||||
shape = RoundedCornerShape(18.dp), color = MaterialTheme.colorScheme.surface,
|
||||
tonalElevation = 6.dp, shadowElevation = 10.dp) {
|
||||
Column {
|
||||
Row(Modifier.fillMaxWidth().heightIn(min = 52.dp).testTag("input-editor-tools")
|
||||
.pointerInput(screenWidth, screenHeight, panelSize) {
|
||||
var dragPosition = Offset.Zero
|
||||
detectDragGestures(onDragStart = { dragPosition = position }) { change, delta ->
|
||||
change.consume()
|
||||
dragPosition = Offset((dragPosition.x + delta.x).coerceIn(margin, (screenWidth - panelSize.width - margin).coerceAtLeast(margin)),
|
||||
(dragPosition.y + delta.y).coerceIn(margin, (screenHeight - panelSize.height - margin).coerceAtLeast(margin)))
|
||||
draft.toolsX = dragPosition.x / screenWidth
|
||||
draft.toolsY = dragPosition.y / screenHeight
|
||||
}
|
||||
}
|
||||
if (draft.defaults != null) SecondaryButton(stringResource(R.string.input_hidden_count, draft.hiddenDefaults().size), compact = true) {
|
||||
draft.popover = if (draft.popover == EditorPopover.HIDDEN) null else EditorPopover.HIDDEN
|
||||
.clickable { draft.toolsExpanded = !draft.toolsExpanded }.padding(horizontal = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text("⠿", color = MaterialTheme.colorScheme.primary)
|
||||
Text(stringResource(if (draft.toolsExpanded) R.string.input_hide_tools else R.string.input_tools), style = MaterialTheme.typography.titleSmall, maxLines = 1)
|
||||
}
|
||||
AnimatedVisibility(draft.toolsExpanded, enter = expandVertically(expandFrom = Alignment.Top) + fadeIn(),
|
||||
exit = shrinkVertically(shrinkTowards = Alignment.Top) + fadeOut()) {
|
||||
Column(Modifier.requiredWidth(expandedWidth).verticalScroll(rememberScrollState())) {
|
||||
HorizontalDivider()
|
||||
SurfaceToolbar(draft, onSave, onLeave)
|
||||
HorizontalDivider()
|
||||
SurfaceSelection(draft)
|
||||
}
|
||||
if (draft.defaults != null) SecondaryButton(stringResource(R.string.hud_reset_button), enabled = !draft.atDefaults, compact = true) { draft.reset() }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Checkbox(draft.snap, { draft.snap = it; ControllerPrefs.setSnap(context, it) })
|
||||
Text(stringResource(R.string.ctrl_editor_snap))
|
||||
}
|
||||
if (draft.elements.isNotEmpty()) {
|
||||
SecondaryButton("−", enabled = draft.scale > 80, compact = true) { draft.scaleAll((draft.scale - 5).coerceAtLeast(80)) }
|
||||
Text("${draft.scale}%", Modifier.widthIn(min = 44.dp).testTag("input-editor-scale"), style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
SecondaryButton("+", enabled = draft.scale < 150, compact = true) { draft.scaleAll((draft.scale + 5).coerceAtMost(150)) }
|
||||
}
|
||||
PrimaryButton(stringResource(R.string.input_editor_done), compact = true, onClick = onSave)
|
||||
}
|
||||
}
|
||||
Row(Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = .7f), RoundedCornerShape(50)).padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(scope, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
splitLabel?.let { SecondaryButton(it, compact = true, modifier = Modifier.testTag("input-editor-split"), onClick = onSplit) }
|
||||
}
|
||||
failure?.let { Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error) }
|
||||
when (draft.popover) {
|
||||
EditorPopover.ADD -> EditorList { AddRows(draft) }
|
||||
EditorPopover.HIDDEN -> EditorList { HiddenRows(draft) }
|
||||
null -> Unit
|
||||
}
|
||||
}
|
||||
val e = draft.element
|
||||
if (e != null && !draft.properties && draft.popover == null && !draft.confirmDiscard) {
|
||||
val density = LocalDensity.current
|
||||
var size by remember { mutableStateOf(IntSize.Zero) }
|
||||
val w = with(density) { maxWidth.toPx() }
|
||||
val h = with(density) { maxHeight.toPx() }
|
||||
val gap = with(density) { 12.dp.toPx() }
|
||||
val margin = with(density) { 8.dp.toPx() }
|
||||
val top = h * e.y - gap - size.height
|
||||
val above = top > with(density) { 110.dp.toPx() }
|
||||
val x = (w * (e.x + e.width / 2) - size.width / 2).coerceIn(margin, (w - size.width - margin).coerceAtLeast(margin))
|
||||
val y = if (above) top else (h * (e.y + e.height) + gap).coerceAtMost(h - size.height - margin)
|
||||
EditorBar(Modifier.offset { IntOffset(x.roundToInt(), y.roundToInt()) }.onSizeChanged { size = it }.testTag("input-editor-selection")) {
|
||||
SecondaryButton("−", compact = true) { draft.resizeSelected(1f / 1.1f) }
|
||||
SecondaryButton("+", compact = true) { draft.resizeSelected(1.1f) }
|
||||
PrimaryButton(stringResource(R.string.input_options), compact = true) { draft.clickProperties = false; draft.properties = true }
|
||||
if (e.hasClick) SecondaryButton(stringResource(R.string.input_click_short), compact = true) { draft.clickProperties = true; draft.properties = true }
|
||||
SecondaryButton(stringResource(R.string.input_remove_element), compact = true) { draft.remove(e.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EditorList(content: @Composable ColumnScope.() -> Unit) {
|
||||
Surface(Modifier.widthIn(min = 260.dp, max = 360.dp), shape = RoundedCornerShape(16.dp), color = MaterialTheme.colorScheme.surface.copy(alpha = .97f),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface, shadowElevation = 8.dp) {
|
||||
Column(Modifier.padding(6.dp).heightIn(max = 320.dp).verticalScroll(rememberScrollState()), content = content)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EditorRow(title: String, action: String, onClick: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 10.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(title, Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium)
|
||||
SecondaryButton(action, compact = true, onClick = onClick)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CloseRow(draft: SurfaceDraft) {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 10.dp, vertical = 4.dp), horizontalArrangement = Arrangement.End) {
|
||||
SecondaryButton(stringResource(R.string.common_close), compact = true) { draft.popover = null }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AddRows(draft: SurfaceDraft) {
|
||||
val context = LocalContext.current
|
||||
CloseRow(draft)
|
||||
for (control in listOf(InputControl.L3, InputControl.R3).filter { c -> draft.elements.none { it.id == "legacy:${c.id}" } })
|
||||
EditorRow(control.label, stringResource(R.string.input_editor_add)) { draft.add(InputSurfaceElement(control, .47f, .45f, .06f, .1f, buttonShape = InputButtonShape.CIRCLE)) }
|
||||
for (kind in InputElementKind.entries) EditorRow(stringResource(kind.label()), stringResource(R.string.input_editor_add)) {
|
||||
val w = if (kind.control.dimensions == 2) .2f else .1f
|
||||
val h = if (kind.control.dimensions == 2) .35f else .16f
|
||||
val name = context.getString(kind.label()) + " " + (draft.elements.count { it.kind == kind } + 1)
|
||||
draft.add(InputSurfaceElement(kind.control, (1f - w) / 2, (1f - h) / 2, w, h, newInputId(), kind, name))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HiddenRows(draft: SurfaceDraft) {
|
||||
val hidden = draft.hiddenDefaults()
|
||||
CloseRow(draft)
|
||||
if (hidden.isEmpty()) Text(stringResource(R.string.input_nothing_hidden), Modifier.padding(12.dp), style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
for (e in hidden) EditorRow(e.name, stringResource(R.string.input_restore)) { draft.add(e) }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun SurfaceToolbar(draft: SurfaceDraft, onSave: () -> Unit, onLeave: () -> Unit, onDiscard: () -> Unit) {
|
||||
private fun SurfaceToolbar(draft: SurfaceDraft, onSave: () -> Unit, onLeave: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
if (draft.confirmDiscard) {
|
||||
FlowRow(Modifier.fillMaxWidth().padding(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(stringResource(R.string.input_editor_discard), style = MaterialTheme.typography.titleSmall)
|
||||
SecondaryButton(stringResource(R.string.input_keep_editing), compact = true) { draft.confirmDiscard = false }
|
||||
PrimaryButton(stringResource(R.string.input_discard), compact = true, onClick = onDiscard)
|
||||
}
|
||||
return
|
||||
}
|
||||
FlowRow(Modifier.fillMaxWidth().padding(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
SecondaryButton(stringResource(R.string.common_cancel), compact = true, onClick = onLeave)
|
||||
SecondaryButton(stringResource(R.string.input_editor_add), enabled = draft.elements.size < 64, compact = true) { draft.popover = EditorPopover.ADD }
|
||||
if (draft.defaults != null) SecondaryButton(stringResource(R.string.input_hidden_count, draft.hiddenDefaults().size), compact = true) { draft.popover = EditorPopover.HIDDEN }
|
||||
SecondaryButton(stringResource(R.string.input_editor_add), enabled = draft.elements.size < 64, compact = true) { draft.adding = true }
|
||||
SecondaryButton(stringResource(R.string.input_editor_undo), enabled = draft.history.isNotEmpty(), compact = true) { draft.undo() }
|
||||
if (draft.defaults != null) SecondaryButton(stringResource(R.string.input_reset_positions), enabled = draft.positioned != null, compact = true) { draft.resetPositions() }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
@@ -450,7 +352,9 @@ private fun SurfaceSelection(draft: SurfaceDraft) {
|
||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
PrimaryButton(stringResource(R.string.input_properties), compact = true) { draft.clickProperties = false; draft.properties = true }
|
||||
if (e.hasClick) SecondaryButton(stringResource(R.string.input_click_properties), compact = true) { draft.clickProperties = true; draft.properties = true }
|
||||
SecondaryButton(stringResource(R.string.input_remove_element), compact = true) { draft.remove(e.id) }
|
||||
SecondaryButton(stringResource(R.string.input_remove_element), compact = true) {
|
||||
draft.checkpoint(); draft.elements = draft.elements.filterNot { it.id == e.id }; draft.actions = draft.actions - e.id; draft.clicks = draft.clicks - e.id; draft.selected = null
|
||||
}
|
||||
}
|
||||
} ?: Text(stringResource(R.string.input_editor_hint))
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.input.OnScreenLayout
|
||||
import com.droiddeck.launcher.input.PadKit
|
||||
import com.droiddeck.launcher.input.SavedInputLayout
|
||||
import com.droiddeck.launcher.input.InputSurfaceElement
|
||||
import com.droiddeck.launcher.input.InputSurfaceStyle
|
||||
@@ -22,9 +23,14 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
|
||||
var aspect = 1f
|
||||
set(value) { field = value; refreshElements(); invalidate() }
|
||||
var sourceLayout: SavedInputLayout? = null
|
||||
set(value) { field = value; refreshElements(); invalidate() }
|
||||
set(value) {
|
||||
field = value
|
||||
updatePreviewStyle()
|
||||
refreshElements()
|
||||
invalidate()
|
||||
}
|
||||
var style = InputSurfaceStyle()
|
||||
set(value) { field = value; preview.updateStyle(value) }
|
||||
set(value) { field = value; updatePreviewStyle() }
|
||||
var snap = true
|
||||
set(value) { field = value; if (!value) clearGuides() }
|
||||
private var guideX: Float? = null
|
||||
@@ -50,6 +56,10 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
|
||||
addView(preview, LayoutParams(-1, -1))
|
||||
}
|
||||
|
||||
private fun updatePreviewStyle() {
|
||||
preview.updateStyle(style, PadKit.forOverlay(context, sourceLayout))
|
||||
}
|
||||
|
||||
private fun refreshElements() {
|
||||
visibleElements = sourceLayout?.let { layout ->
|
||||
OnScreenLayout.editorElements(context, layout.copy(elements = elements, aspect = aspect), width, height)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.graphics.RadialGradient
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Shader
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.view.Gravity
|
||||
@@ -31,9 +36,6 @@ import com.droiddeck.launcher.input.InputAction
|
||||
import com.droiddeck.launcher.input.InputButtonIcons
|
||||
import com.droiddeck.launcher.input.InputButtonShape
|
||||
import com.droiddeck.launcher.input.InputButtonImages
|
||||
import com.droiddeck.launcher.input.KitLayout
|
||||
import com.droiddeck.launcher.input.OnScreenLayout
|
||||
import com.droiddeck.launcher.input.SavedInputLayout
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.input.PadKit
|
||||
import com.droiddeck.launcher.input.pcKeyLabel
|
||||
@@ -50,15 +52,15 @@ class InputSurfaceView(
|
||||
val inputRole: InputRole = InputRole.SECONDARY,
|
||||
private var surfaceStyle: InputSurfaceStyle = InputSurfaceStyle(),
|
||||
private val haptics: Boolean = inputRole != InputRole.PRIMARY,
|
||||
kit: PadKit = PadKit.current(context),
|
||||
) : FrameLayout(context) {
|
||||
var kit: PadKit = kit
|
||||
set(value) { if (field != value) { field = value; customCanvas?.let { c -> for (i in 0 until c.childCount) c.getChildAt(i).invalidate() } } }
|
||||
private val art = PadArt(context)
|
||||
private val content = FrameLayout(context)
|
||||
private val elementSources = ArrayList<InputSurfaceSource>()
|
||||
private var customCanvas: ViewGroup? = null
|
||||
private val owners = HashMap<Int, View>()
|
||||
private var artwork: PadKit? = null
|
||||
private val art by lazy(LazyThreadSafetyMode.NONE) { PadArt(context) }
|
||||
private var artworkDpad = emptyList<HoldButton>()
|
||||
private val artworkDpadBounds = RectF()
|
||||
private var requestedLayout = customLayout
|
||||
init { customLayout = surfaceStyle.shown(customLayout); addView(content, LayoutParams(-1, -1)); renderCustom(pad) }
|
||||
|
||||
@@ -137,35 +139,24 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateStyle(style: InputSurfaceStyle) {
|
||||
if (surfaceStyle == style) return
|
||||
internal fun updateStyle(style: InputSurfaceStyle, artwork: PadKit? = null) {
|
||||
if (surfaceStyle == style && this.artwork == artwork) return
|
||||
val relayout = surfaceStyle.hidden != style.hidden
|
||||
surfaceStyle = style
|
||||
this.artwork = artwork
|
||||
if (relayout) updateCustomLayout(requestedLayout)
|
||||
customCanvas?.let { canvas -> for (i in 0 until canvas.childCount) styleElement(canvas.getChildAt(i)) }
|
||||
customCanvas?.let { canvas ->
|
||||
for (i in 0 until canvas.childCount) styleElement(canvas.getChildAt(i))
|
||||
canvas.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun styleElement(view: View) {
|
||||
view.alpha = surfaceStyle.opacity / 100f * ((view.tag as? InputSurfaceElement)?.opacity ?: 1f)
|
||||
(view as? Surface)?.tint = surfaceStyle.tint
|
||||
view.invalidate()
|
||||
}
|
||||
|
||||
private var generated: SavedInputLayout? = null
|
||||
|
||||
/** Shows [layout]; a layout that has no elements of its own gets the virtual controller's defaults at this view's size. */
|
||||
fun showLayout(layout: SavedInputLayout?) {
|
||||
generated = layout?.takeIf(OnScreenLayout::generated)
|
||||
kit = PadKit.current(context)
|
||||
updateStyle(layout?.style ?: InputSurfaceStyle())
|
||||
updateCustomLayout(generated?.let { OnScreenLayout.elements(context, it, width, height, android.graphics.Rect(), null) } ?: layout?.elements.orEmpty())
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
val layout = generated ?: return
|
||||
post { if (generated === layout) updateCustomLayout(OnScreenLayout.elements(context, layout, width, height, android.graphics.Rect(), null)) }
|
||||
}
|
||||
|
||||
fun updateCustomLayout(requested: List<InputSurfaceElement>) {
|
||||
requestedLayout = requested
|
||||
val layout = surfaceStyle.shown(requested)
|
||||
@@ -191,6 +182,7 @@ class InputSurfaceView(
|
||||
}
|
||||
|
||||
private fun renderCustom(pad: PadBridge?) {
|
||||
artworkDpad = emptyList()
|
||||
val canvas = object : ViewGroup(context) {
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val layout = customLayout
|
||||
@@ -208,14 +200,30 @@ class InputSurfaceView(
|
||||
val x = (width * e.x).toInt(); val y = (height * e.y).toInt()
|
||||
child.layout(x, y, x + child.measuredWidth, y + child.measuredHeight)
|
||||
}
|
||||
updateArtworkDpad(this)
|
||||
}
|
||||
|
||||
override fun dispatchDraw(canvas: Canvas) {
|
||||
val kit = artwork
|
||||
if (kit != null && artworkDpad.isNotEmpty()) {
|
||||
val alpha = (artworkDpad.first().alpha * 255f).toInt()
|
||||
val saved = if (alpha == 255) canvas.save()
|
||||
else canvas.saveLayerAlpha(artworkDpadBounds, alpha)
|
||||
canvas.translate(artworkDpadBounds.left, artworkDpadBounds.top)
|
||||
val held = artworkDpad.foldIndexed(0) { i, bits, button -> if (button.highlighted) bits or (1 shl i) else bits }
|
||||
art.dpad(canvas, artworkDpadBounds.width(), artworkDpadBounds.height(), kit, held)
|
||||
canvas.restoreToCount(saved)
|
||||
}
|
||||
super.dispatchDraw(canvas)
|
||||
}
|
||||
}
|
||||
canvas.clipChildren = customLayout.none(::adaptive)
|
||||
canvas.clipChildren = customLayout.none { it.kind == InputElementKind.STICK && (classic(it) || adaptive(it)) }
|
||||
for (element in customLayout) {
|
||||
val source = pad?.let { InputSurfaceSource(it, inputRole, element).also { s -> elementSources += s } }
|
||||
canvas.addView(when (element.kind) {
|
||||
InputElementKind.STICK -> StickView(context, element, source, element.floating, element.hideWhenIdle && pad != null)
|
||||
InputElementKind.TRACKPAD -> TrackpadView(context, source)
|
||||
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, captioned = element.showLabel,
|
||||
stock = element.id == "legacy:${element.control.id}" && element.name == element.control.label, source = source)
|
||||
InputElementKind.DPAD -> DirectionPad(context, element, source)
|
||||
else -> HoldButton(context, element, source)
|
||||
}.apply { tag = element; contentDescription = element.name; styleElement(this); source?.onStateChanged = { postInvalidate() } })
|
||||
@@ -224,6 +232,29 @@ class InputSurfaceView(
|
||||
customCanvas = canvas
|
||||
}
|
||||
|
||||
private fun updateArtworkDpad(canvas: ViewGroup) {
|
||||
val buttons = DIRECTIONS.mapNotNull { direction ->
|
||||
val index = customLayout.indexOfFirst { element ->
|
||||
element.control == direction && classic(element) && element.buttonShape == InputButtonShape.CIRCLE &&
|
||||
element.name == direction.label && element.icon == 0 && element.image.isEmpty() &&
|
||||
element.showLabel && !element.toggle && element.opacity == 1f
|
||||
}
|
||||
canvas.getChildAt(index) as? HoldButton
|
||||
}
|
||||
artworkDpad = emptyList()
|
||||
if (buttons.size != DIRECTIONS.size) return
|
||||
val (up, right, down, left) = buttons
|
||||
val centerX = (left.left + right.right) / 2f
|
||||
val centerY = (up.top + down.bottom) / 2f
|
||||
if (kotlin.math.abs((up.left + up.right) / 2f - centerX) > 2f ||
|
||||
kotlin.math.abs((down.left + down.right) / 2f - centerX) > 2f ||
|
||||
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
|
||||
artworkDpadBounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat())
|
||||
artworkDpad = buttons
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
if (pad != null && elementSources.isEmpty()) {
|
||||
@@ -285,12 +316,64 @@ class InputSurfaceView(
|
||||
private fun feedback(view: View, type: Int) { if (haptics) view.performHapticFeedback(type) }
|
||||
|
||||
private abstract class Surface(context: Context) : View(context) {
|
||||
var tint: Int? = null
|
||||
protected val density = resources.displayMetrics.density
|
||||
protected val rect = RectF()
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val stroke = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
|
||||
protected val labelPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
textAlign = Paint.Align.CENTER
|
||||
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
|
||||
color = TEXT
|
||||
}
|
||||
protected val captionPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
textAlign = Paint.Align.CENTER
|
||||
color = TEXT_DIM
|
||||
}
|
||||
|
||||
protected fun drawSurface(canvas: Canvas, lit: Boolean, shape: InputButtonShape = InputButtonShape.ROUNDED, classic: Boolean = false) {
|
||||
val inset = if (classic && tint != null) 0.75f * density else density
|
||||
rect.set(inset, inset, width - inset, height - inset)
|
||||
val radius = when (shape) { InputButtonShape.CIRCLE, InputButtonShape.PILL -> min(width, height) / 2f; InputButtonShape.RECTANGLE -> 2 * density; else -> CORNER * density }
|
||||
val color = tint
|
||||
if (classic && color != null) {
|
||||
val corner = if (shape == InputButtonShape.PILL) radius * 0.55f else radius
|
||||
fill.color = if (lit) shade(color, 160, 1f) else shade(color, 80, 0.12f)
|
||||
canvas.drawRoundRect(rect, corner, corner, fill)
|
||||
stroke.color = if (lit) light(color, 230, 0.7f) else light(color, 150, 0.25f)
|
||||
stroke.strokeWidth = 1.5f * density
|
||||
canvas.drawRoundRect(rect, corner, corner, stroke)
|
||||
return
|
||||
}
|
||||
fill.color = tint?.let { color -> (color and 0x00ffffff) or ((if (lit) 140 else 48) shl 24) } ?: if (lit) ACCENT_WASH else SURFACE
|
||||
canvas.drawRoundRect(rect, radius, radius, fill)
|
||||
stroke.color = tint?.let { color -> (color and 0x00ffffff) or ((if (lit) 255 else 160) shl 24) } ?: if (lit) ACCENT else LINE
|
||||
stroke.strokeWidth = (if (lit) 2f else 1f) * density
|
||||
canvas.drawRoundRect(rect, radius, radius, stroke)
|
||||
}
|
||||
|
||||
protected fun drawCircle(canvas: Canvas, x: Float, y: Float, radius: Float, fillColor: Int, strokeColor: Int) {
|
||||
fill.color = fillColor
|
||||
canvas.drawCircle(x, y, radius, fill)
|
||||
stroke.color = strokeColor
|
||||
stroke.strokeWidth = 1.5f * density
|
||||
canvas.drawCircle(x, y, radius, stroke)
|
||||
}
|
||||
|
||||
protected fun drawKeyboard(canvas: Canvas, x: Float, y: Float, lit: Boolean) {
|
||||
val color = tint ?: return
|
||||
stroke.color = if (lit) light(color, 230, 0.7f) else light(color, 150, 0.25f)
|
||||
stroke.strokeWidth = 1.5f * density
|
||||
rect.set(x - 10 * density, y - 7 * density, x + 10 * density, y + 7 * density)
|
||||
canvas.drawRoundRect(rect, 2 * density, 2 * density, stroke)
|
||||
for (row in 0..1) for (col in 0..2) {
|
||||
val kx = x + (-6f + col * 5f) * density
|
||||
val ky = y + (-3f + row * 4f) * density
|
||||
canvas.drawLine(kx, ky, kx + 2 * density, ky, stroke)
|
||||
}
|
||||
canvas.drawLine(x - 5 * density, y + 4 * density, x + 5 * density, y + 4 * density, stroke)
|
||||
}
|
||||
|
||||
protected fun textColor(lit: Boolean) = if (lit) Color.WHITE else tint?.let { light(it, 210, 0.75f) } ?: TEXT
|
||||
}
|
||||
|
||||
private inner class HoldButton(context: Context, private val element: InputSurfaceElement, private val source: InputSurfaceSource?) : Surface(context) {
|
||||
@@ -310,61 +393,55 @@ class InputSurfaceView(
|
||||
}
|
||||
private val imageRect = RectF()
|
||||
|
||||
val highlighted get() = if (element.toggle) source?.latched == true else down
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val lit = if (element.toggle) source?.latched == true else down
|
||||
val w = width.toFloat(); val h = height.toFloat()
|
||||
val c = element.control
|
||||
val native = element.id == "legacy:${c.id}" && element.showLabel && element.icon == 0 && bitmap == null &&
|
||||
(element.name == c.label || element.name == kit.name(c)) && (c !in FACE || element.buttonShape == InputButtonShape.CIRCLE)
|
||||
when {
|
||||
element.id == KitLayout.KEYBOARD_ID && element.icon == InputButtonIcons.KEYBOARD -> art.system(canvas, w, h, PadArt.Shape.ROUND, PadArt.Icon.KEYBOARD, lit)
|
||||
native && c in FACE -> art.face(canvas, w / 2f, h / 2f, min(w, h) / 2f - art.dp(2f), c, kit, lit)
|
||||
native && c in SHOULDERS -> art.shoulder(canvas, w, h, c, kit, lit)
|
||||
native && c in GRIPS -> art.grip(canvas, w, h, c.label, lit)
|
||||
native && (c == InputControl.L3 || c == InputControl.R3) -> art.small(canvas, w, h, c.label, lit)
|
||||
native && c in SYSTEM -> systemLook(c).let { (shape, icon) -> art.system(canvas, w, h, shape, icon, lit) }
|
||||
else -> custom(canvas, w, h, lit)
|
||||
val lit = highlighted
|
||||
val classic = classic(element)
|
||||
val kit = artwork
|
||||
if (kit != null && element.image.isEmpty() && element.showLabel) {
|
||||
if (this in artworkDpad) return
|
||||
if (element.id == "builtin:keyboard" && element.icon == InputButtonIcons.KEYBOARD) {
|
||||
art.system(canvas, width.toFloat(), height.toFloat(), PadArt.Shape.ROUND, PadArt.Icon.KEYBOARD, lit)
|
||||
return
|
||||
}
|
||||
val control = element.control
|
||||
val native = element.id == "legacy:${control.id}" && element.icon == 0 &&
|
||||
(element.name == control.label || element.name == kit.name(control)) &&
|
||||
usesStockShape(control, element.buttonShape)
|
||||
if (native && art.button(canvas, width, height, control, kit, lit)) return
|
||||
}
|
||||
}
|
||||
|
||||
private fun systemLook(c: InputControl): Pair<PadArt.Shape, PadArt.Icon> = when {
|
||||
kit.steam -> when (c) {
|
||||
InputControl.SELECT -> PadArt.Shape.CHIP to PadArt.Icon.VIEW
|
||||
InputControl.START -> PadArt.Shape.CHIP to PadArt.Icon.MENU
|
||||
InputControl.GUIDE -> PadArt.Shape.PILL to PadArt.Icon.STEAM
|
||||
else -> PadArt.Shape.PILL to PadArt.Icon.QAM
|
||||
}
|
||||
kit.playStation -> when (c) {
|
||||
InputControl.SELECT -> PadArt.Shape.PILL to if (kit == PadKit.DUALSHOCK) PadArt.Icon.SHARE else PadArt.Icon.CREATE
|
||||
InputControl.START -> PadArt.Shape.PILL to if (kit == PadKit.DUALSHOCK) PadArt.Icon.OPTIONS else PadArt.Icon.MENU
|
||||
InputControl.GUIDE -> PadArt.Shape.ROUND to PadArt.Icon.HOME
|
||||
else -> PadArt.Shape.ROUND to PadArt.Icon.QAM
|
||||
}
|
||||
else -> PadArt.Shape.ROUND to when (c) {
|
||||
InputControl.SELECT -> PadArt.Icon.BACK
|
||||
InputControl.START -> PadArt.Icon.START
|
||||
InputControl.GUIDE -> PadArt.Icon.HOME
|
||||
else -> PadArt.Icon.QAM
|
||||
}
|
||||
}
|
||||
|
||||
private fun custom(canvas: Canvas, w: Float, h: Float, lit: Boolean) {
|
||||
val inset = art.dp(2f)
|
||||
art.glass(canvas, when (element.buttonShape) {
|
||||
InputButtonShape.CIRCLE -> art.circle(w / 2f, h / 2f, min(w, h) / 2f - inset)
|
||||
InputButtonShape.PILL -> art.roundRect(inset, inset, w - inset, h - inset, min(w, h) / 2f)
|
||||
InputButtonShape.RECTANGLE -> art.roundRect(inset, inset, w - inset, h - inset, art.dp(4f))
|
||||
InputButtonShape.ROUNDED -> art.roundRect(inset, inset, w - inset, h - inset, min(w, h) * .22f)
|
||||
}, lit)
|
||||
labelPaint.color = if (lit) PadArt.ON_ACCENT else PadArt.INK
|
||||
drawSurface(canvas, lit, element.buttonShape, classic)
|
||||
val cx = width / 2f
|
||||
labelPaint.color = if (classic && tint != null) textColor(lit) else if (lit) ACCENT else TEXT
|
||||
bitmap?.let {
|
||||
val scale = min(w * .84f / it.width, h * .84f / it.height)
|
||||
imageRect.set(w / 2f - it.width * scale / 2, (h - it.height * scale) / 2, w / 2f + it.width * scale / 2, (h + it.height * scale) / 2)
|
||||
val scale = min(width * .84f / it.width, height * .84f / it.height)
|
||||
imageRect.set(cx - it.width * scale / 2, (height - it.height * scale) / 2,
|
||||
cx + it.width * scale / 2, (height + it.height * scale) / 2)
|
||||
canvas.drawBitmap(it, null, imageRect, labelPaint)
|
||||
return
|
||||
}
|
||||
if (element.icon != 0 && InputButtonIcons.draw(canvas, element.icon, w / 2f, h / 2f, min(w, h) * .6f, labelPaint, symbol)) return
|
||||
if (element.showLabel) art.text(canvas, element.name, w / 2f, h / 2f, min(h * .34f, 26 * density), labelPaint.color, w * .82f)
|
||||
if (classic && element.id == "builtin:keyboard" && element.icon == InputButtonIcons.KEYBOARD) { drawKeyboard(canvas, cx, height / 2f, lit); return }
|
||||
if (element.icon != 0 && InputButtonIcons.draw(canvas, element.icon, cx, height / 2f, min(width, height) * .68f, labelPaint, symbol)) return
|
||||
if (!element.showLabel) return
|
||||
labelPaint.style = Paint.Style.FILL
|
||||
if (classic && element.name == element.control.label) {
|
||||
val radius = min(width, height) / 2f
|
||||
val direction = DIRECTIONS.indexOf(element.control)
|
||||
if (direction >= 0) { drawArrow(canvas, cx, height / 2f, radius * .34f, direction, labelPaint); return }
|
||||
val glyph = glyph(element.control)
|
||||
labelPaint.textSize = when {
|
||||
element.buttonShape == InputButtonShape.PILL -> height / 2f * 0.8f
|
||||
glyph.length > 2 -> 11 * density
|
||||
else -> radius * if (glyph.length == 2) 0.62f else 0.85f
|
||||
}
|
||||
canvas.drawText(glyph, cx, height / 2f + labelPaint.textSize * .35f, labelPaint)
|
||||
return
|
||||
}
|
||||
labelPaint.textSize = min(height * .3f, 30 * density)
|
||||
val labelWidth = labelPaint.measureText(element.name)
|
||||
if (labelWidth > width * .84f) labelPaint.textSize *= width * .84f / labelWidth
|
||||
canvas.drawText(element.name, cx, height / 2f + labelPaint.textSize * .35f, labelPaint)
|
||||
}
|
||||
|
||||
fun press(pointer: Int, pressed: Boolean, cancelled: Boolean = false) {
|
||||
@@ -382,10 +459,13 @@ class InputSurfaceView(
|
||||
if (pressed) 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()
|
||||
}
|
||||
}
|
||||
|
||||
private inner class TrackpadView(context: Context, private val source: InputSurfaceSource? = null) : Surface(context) {
|
||||
private inner class TrackpadView(context: Context, private val right: Boolean, private val captioned: Boolean,
|
||||
private val stock: Boolean,
|
||||
private val source: InputSurfaceSource? = null) : Surface(context) {
|
||||
private var gestureX = 0f
|
||||
private var gestureY = 0f
|
||||
private val mouse = TouchpadGestures(ViewConfiguration.get(context).scaledTouchSlop.toFloat(), object : PointerGestures.Listener {
|
||||
@@ -402,9 +482,33 @@ class InputSurfaceView(
|
||||
private var clicked = false
|
||||
private var fingerX = 0f
|
||||
private var fingerY = 0f
|
||||
private val guide = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE; color = GUIDE }
|
||||
private val dot = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = ACCENT }
|
||||
private val glow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
art.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
if (!captioned || stock && artwork?.steam == true) {
|
||||
art.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
return
|
||||
}
|
||||
drawSurface(canvas, clicked)
|
||||
val cx = width / 2f
|
||||
val cy = height / 2f
|
||||
guide.strokeWidth = density
|
||||
val reach = (min(width, height) / 2f - 24 * density).coerceAtLeast(0f)
|
||||
canvas.drawCircle(cx, cy, reach, guide)
|
||||
canvas.drawCircle(cx, cy, reach / 2f, guide)
|
||||
canvas.drawLine(cx - reach, cy, cx + reach, cy, guide)
|
||||
canvas.drawLine(cx, cy - reach, cx, cy + reach, guide)
|
||||
captionPaint.textSize = 12 * density
|
||||
captionPaint.color = if (touching) ACCENT else TEXT_DIM
|
||||
canvas.drawText((contentDescription?.toString() ?: if (right) context.getString(R.string.deck_right_trackpad) else context.getString(R.string.deck_left_trackpad)).uppercase(), cx, 28 * density, captionPaint)
|
||||
if (touching) {
|
||||
val radius = 56 * density
|
||||
glow.shader = RadialGradient(fingerX, fingerY, radius, ACCENT_GLOW, Color.TRANSPARENT, Shader.TileMode.CLAMP)
|
||||
canvas.drawCircle(fingerX, fingerY, radius, glow)
|
||||
canvas.drawCircle(fingerX, fingerY, (if (clicked) 16 else 12) * density, dot)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@@ -476,31 +580,67 @@ class InputSurfaceView(
|
||||
private var originY = 0f
|
||||
private var knobX = 0f
|
||||
private var knobY = 0f
|
||||
private val ring = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
|
||||
private val knob = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
val adaptive get() = adaptive(element)
|
||||
|
||||
private fun radius() = (min(width, height) / 2f - 3 * density).coerceAtLeast(1f)
|
||||
|
||||
fun reach() = radius() * STICK_REACH
|
||||
fun reach() = min(width, height) * if (classic(element)) CLASSIC_REACH else PANEL_REACH
|
||||
|
||||
fun captures(x: Float, y: Float): Boolean {
|
||||
val cx = centreX()
|
||||
val dx = when (element.control) { InputControl.LS -> maxOf(0f, x - cx); InputControl.RS -> minOf(0f, x - cx); else -> x - cx }
|
||||
val limit = radius() * ADAPTIVE_REACH
|
||||
val dx = if (element.control == InputControl.LS) maxOf(0f, x - cx) else x - cx
|
||||
val limit = reach() * ADAPTIVE_REACH
|
||||
return dx * dx + (y - height / 2f) * (y - height / 2f) <= limit * limit
|
||||
}
|
||||
|
||||
fun centreX() = width / 2f
|
||||
fun centreX() = when {
|
||||
!classic(element) || width <= height -> width / 2f
|
||||
element.control == InputControl.LS -> width - height / 2f
|
||||
else -> height / 2f
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (hideWhenIdle && !touching) return
|
||||
val cx = if (touching) originX else centreX()
|
||||
val cy = if (touching) originY else height / 2f
|
||||
val r = radius()
|
||||
val travel = r * KNOB_TRAVEL / reach().coerceAtLeast(1f)
|
||||
art.stick(canvas, cx, cy, r, kit, knobX * travel, knobY * travel, touching || clicking)
|
||||
val kit = artwork
|
||||
if (kit != null && classic(element) && element.name == element.control.label) {
|
||||
val radius = min(width, height) / 2f - 2f * density
|
||||
if (radius > 0f) {
|
||||
art.stick(canvas, cx, cy, radius, kit, knobX, knobY, touching || clicking)
|
||||
if (element.showLabel) {
|
||||
labelPaint.color = TEXT
|
||||
drawDirectionLabels(canvas, source, false, cx, cy, radius * .66f, radius * .34f, labelPaint)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
val color = tint
|
||||
if (classic(element) && color != null) {
|
||||
val radius = min(width, height) / 2f - 0.75f * density
|
||||
drawCircle(canvas, cx, cy, radius,
|
||||
if (touching) shade(color, 160, 1f) else shade(color, 60, 0.12f), if (touching) light(color, 230, 0.7f) else light(color, 150, 0.25f))
|
||||
val knobRadius = radius * 0.46f
|
||||
drawCircle(canvas, cx + knobX, cy + knobY, knobRadius,
|
||||
if (touching || clicking) shade(color, 160, 1f) else shade(color, 120, 0.35f), if (touching) light(color, 230, 0.7f) else light(color, 150, 0.25f))
|
||||
if (!element.showLabel) return
|
||||
labelPaint.color = textColor(touching)
|
||||
if (drawDirectionLabels(canvas, source, false, cx, cy, radius * 0.66f, radius * 0.34f, labelPaint)) return
|
||||
labelPaint.textSize = knobRadius * 0.8f
|
||||
val label = if (element.name == element.control.label) glyph(element.control) else element.name
|
||||
canvas.drawText(label, cx + knobX, cy + knobY + labelPaint.textSize * 0.35f, labelPaint)
|
||||
return
|
||||
}
|
||||
drawSurface(canvas, clicking)
|
||||
ring.strokeWidth = 2 * density
|
||||
ring.color = if (touching) ACCENT else LINE
|
||||
canvas.drawCircle(cx, cy, reach(), ring)
|
||||
knob.color = if (touching) ACCENT else KNOB
|
||||
canvas.drawCircle(cx + knobX, cy + knobY, reach() * 0.45f, knob)
|
||||
if (!element.showLabel) return
|
||||
labelPaint.color = PadArt.INK
|
||||
drawDirectionLabels(canvas, source, false, cx, cy, r * .66f, r * .34f, labelPaint)
|
||||
labelPaint.color = if (touching) ACCENT else TEXT
|
||||
drawDirectionLabels(canvas, source, false, cx, cy, reach() * 1.32f, reach() * 0.68f, labelPaint)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@@ -563,20 +703,34 @@ class InputSurfaceView(
|
||||
}
|
||||
|
||||
private inner class DirectionPad(context: Context, private val element: InputSurfaceElement, private val source: InputSurfaceSource? = null) : View(context) {
|
||||
private val density = resources.displayMetrics.density
|
||||
private var held = 0
|
||||
private val arm = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val label = Paint(Paint.ANTI_ALIAS_FLAG).apply { textAlign = Paint.Align.CENTER; typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD); color = TEXT }
|
||||
private val rect = RectF()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val labels = element.showLabel && directionLabels(context, source?.directions, true).isNotEmpty()
|
||||
art.dpad(canvas, width.toFloat(), height.toFloat(), kit, held, chevrons = !labels)
|
||||
if (!labels) return
|
||||
val half = min(width, height) / 2f
|
||||
drawDirectionLabels(canvas, source, true, width / 2f, height / 2f, half * .68f, half * .32f, label)
|
||||
val size = min(width, height) * 0.86f
|
||||
val cx = width / 2f
|
||||
val cy = height / 2f
|
||||
val half = size / 2f
|
||||
val thick = size / 3f / 2f
|
||||
fun armRect(bit: Int, l: Float, t: Float, r: Float, b: Float) {
|
||||
arm.color = if (held and bit != 0) ACCENT else KNOB
|
||||
rect.set(l, t, r, b)
|
||||
canvas.drawRoundRect(rect, 8 * density, 8 * density, arm)
|
||||
}
|
||||
armRect(1, cx - thick, cy - half, cx + thick, cy - thick)
|
||||
armRect(4, cx - thick, cy + thick, cx + thick, cy + half)
|
||||
armRect(8, cx - half, cy - thick, cx - thick, cy + thick)
|
||||
armRect(2, cx + thick, cy - thick, cx + half, cy + thick)
|
||||
arm.color = KNOB
|
||||
canvas.drawRect(cx - thick, cy - thick, cx + thick, cy + thick, arm)
|
||||
if (element.showLabel) drawDirectionLabels(canvas, source, true, cx, cy, (half + thick) / 2f, thick * 1.7f, label)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_CANCEL) { source?.cancel(); held = 0; invalidate(); return true }
|
||||
val bits = when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
|
||||
val dx = event.getX(0) - width / 2f
|
||||
@@ -611,21 +765,54 @@ class InputSurfaceView(
|
||||
companion object {
|
||||
private const val CLICK_MS = 300L
|
||||
private const val STICK_TAP_MS = 200L
|
||||
private const val STICK_REACH = .62f
|
||||
private const val KNOB_TRAVEL = .54f
|
||||
private const val CLASSIC_REACH = 0.5f
|
||||
private const val PANEL_REACH = 0.30f
|
||||
private const val HIT_SLACK = 0.25f
|
||||
private const val ADAPTIVE_CLEARANCE_PX = 5f
|
||||
private const val ADAPTIVE_REACH = 1.71f
|
||||
private val ADAPTIVE_REACH = 1.4f * kotlin.math.sqrt(1.5f)
|
||||
|
||||
|
||||
private const val CORNER = 20f
|
||||
private const val CORNER_PILL = 22f
|
||||
private val ACCENT = Color.rgb(0x1A, 0x9F, 0xFF)
|
||||
private val ACCENT_WASH = Color.argb(0x2E, 0x1A, 0x9F, 0xFF)
|
||||
private val ACCENT_GLOW = Color.argb(0x66, 0x1A, 0x9F, 0xFF)
|
||||
private val ON_ACCENT = Color.rgb(0x03, 0x11, 0x1F)
|
||||
internal val SURFACE = Color.rgb(0x0A, 0x0B, 0x0D)
|
||||
internal val LINE = Color.rgb(0x26, 0x29, 0x2E)
|
||||
private val GUIDE = Color.rgb(0x16, 0x18, 0x1B)
|
||||
internal val TEXT = Color.rgb(0xF2, 0xF4, 0xF7)
|
||||
private val FACE = setOf(InputControl.A, InputControl.B, InputControl.X, InputControl.Y)
|
||||
private val SHOULDERS = setOf(InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT)
|
||||
private val GRIPS = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
private val SYSTEM = setOf(InputControl.SELECT, InputControl.START, InputControl.GUIDE, InputControl.QAM)
|
||||
private val TEXT_DIM = Color.rgb(0x7A, 0x80, 0x8A)
|
||||
private val KNOB = Color.rgb(0x2A, 0x2D, 0x33)
|
||||
|
||||
private fun adaptive(element: InputSurfaceElement) = element.kind == InputElementKind.STICK && element.floating
|
||||
private fun adaptive(element: InputSurfaceElement) = element.kind == InputElementKind.STICK && element.floating && element.hideWhenIdle
|
||||
|
||||
private fun classic(element: InputSurfaceElement) = (element.id == "legacy:${element.control.id}" || element.id == "builtin:keyboard") &&
|
||||
(element.buttonShape == InputButtonShape.CIRCLE || element.buttonShape == InputButtonShape.PILL)
|
||||
|
||||
private fun usesStockShape(control: InputControl, shape: InputButtonShape): Boolean = when (control) {
|
||||
InputControl.LT, InputControl.LB, InputControl.RB, InputControl.RT -> shape == InputButtonShape.PILL
|
||||
InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5 -> shape == InputButtonShape.PILL || shape == InputButtonShape.ROUNDED
|
||||
else -> shape == InputButtonShape.CIRCLE
|
||||
}
|
||||
|
||||
private val DIRECTIONS = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
|
||||
|
||||
internal fun shade(tint: Int, alpha: Int, f: Float) =
|
||||
Color.argb(alpha, (Color.red(tint) * f).toInt(), (Color.green(tint) * f).toInt(), (Color.blue(tint) * f).toInt())
|
||||
|
||||
internal fun light(tint: Int, alpha: Int, f: Float) = Color.argb(alpha, (Color.red(tint) + (255 - Color.red(tint)) * f).toInt(),
|
||||
(Color.green(tint) + (255 - Color.green(tint)) * f).toInt(), (Color.blue(tint) + (255 - Color.blue(tint)) * f).toInt())
|
||||
|
||||
private fun glyph(control: InputControl) = when (control) {
|
||||
InputControl.LS -> "L"
|
||||
InputControl.RS -> "R"
|
||||
InputControl.SELECT -> "⧉"
|
||||
InputControl.START -> "☰"
|
||||
InputControl.GUIDE -> "◉"
|
||||
InputControl.QAM -> "⋯"
|
||||
else -> control.id.uppercase()
|
||||
}
|
||||
|
||||
private val CARDINAL = listOf(0f to -1f, 1f to 0f, 0f to 1f, -1f to 0f)
|
||||
private val DIAGONAL = listOf(.7071f to -.7071f, .7071f to .7071f, -.7071f to .7071f, -.7071f to -.7071f)
|
||||
@@ -650,6 +837,16 @@ class InputSurfaceView(
|
||||
return labels.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun drawArrow(canvas: Canvas, x: Float, y: Float, size: Float, direction: Int, paint: Paint) {
|
||||
val (fx, fy) = when (direction) { 0 -> 0f to -1f; 1 -> 1f to 0f; 2 -> 0f to 1f; else -> -1f to 0f }
|
||||
val path = Path()
|
||||
path.moveTo(x + fx * size, y + fy * size)
|
||||
path.lineTo(x - fx * size * 0.7f - fy * size, y - fy * size * 0.7f + fx * size)
|
||||
path.lineTo(x - fx * size * 0.7f + fy * size, y - fy * size * 0.7f - fx * size)
|
||||
path.close()
|
||||
canvas.drawPath(path, paint)
|
||||
}
|
||||
|
||||
internal fun dp(context: Context, value: Int): Int = (value * context.resources.displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
internal fun outline(context: Context, radius: Float, fill: Int) = GradientDrawable().apply {
|
||||
|
||||
@@ -59,6 +59,8 @@ class ModeSettings(
|
||||
val panelSize: Pair<Int, Int> = 1280 to 720,
|
||||
val hdr: Boolean,
|
||||
val hdrReason: String?,
|
||||
val hdrDisplay: Boolean = true,
|
||||
val zeroCopy: Boolean = true,
|
||||
val gpuDrivers: String? = null,
|
||||
val upscaler: Int = 0,
|
||||
val upscaleSharpness: Int = 75,
|
||||
@@ -85,6 +87,7 @@ class ModeSettings(
|
||||
val picturePosition: String? = null,
|
||||
val integerScaling: Boolean? = null,
|
||||
val stretch16x9: Boolean? = null,
|
||||
val avoidNotch: Boolean? = null,
|
||||
val steamClientArch: String? = null,
|
||||
val returnAfterGame: Boolean? = null,
|
||||
val shaderPrecache: Boolean? = null,
|
||||
@@ -114,6 +117,7 @@ class ModeSettings(
|
||||
class ModeSettingsActions(
|
||||
val onResolution: (String) -> Unit,
|
||||
val onHdr: (Boolean) -> Unit,
|
||||
val onZeroCopy: (Boolean) -> Unit = {},
|
||||
val onGpuDrivers: () -> Unit = {},
|
||||
val onUpscaler: (Int) -> Unit = {},
|
||||
val onUpscaleSharpness: (Int) -> Unit = {},
|
||||
@@ -142,6 +146,7 @@ class ModeSettingsActions(
|
||||
val onPicturePosition: (String) -> Unit = {},
|
||||
val onIntegerScaling: (Boolean) -> Unit = {},
|
||||
val onStretch16x9: (Boolean) -> Unit = {},
|
||||
val onAvoidNotch: (Boolean) -> Unit = {},
|
||||
val onSteamRepair: () -> Unit = {},
|
||||
val onSteamClientArch: (String) -> Unit = {},
|
||||
val onMangoapp: (Boolean) -> Unit = {},
|
||||
@@ -250,6 +255,11 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
listOf(false to stringResource(R.string.display_preserve), true to stringResource(R.string.display_stretch)),
|
||||
s.stretch16x9 && canStretch, enabled = canStretch, onPick = a.onStretch16x9)
|
||||
}
|
||||
s.avoidNotch?.let { enabled ->
|
||||
ToggleRow(host, "avoid-notch", stringResource(R.string.display_avoid_notch),
|
||||
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)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.display_image_scaling)) {
|
||||
s.integerScaling?.let { enabled ->
|
||||
@@ -276,9 +286,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.mode_hdr)) {
|
||||
ToggleRow(
|
||||
host, "hdr", stringResource(R.string.mode_hdr10),
|
||||
s.hdrReason?.let { stringResource(R.string.mode_hdr_unavailable, it) }
|
||||
?: stringResource(R.string.mode_hdr_restart),
|
||||
host, "hdr", stringResource(if (s.hdrDisplay) R.string.mode_hdr10 else R.string.drawer_fake_hdr),
|
||||
s.hdrReason?.let { stringResource(R.string.mode_hdr_unavailable, it) },
|
||||
checked = s.hdr && s.hdrReason == null, enabled = s.hdrReason == null, onChange = a.onHdr,
|
||||
)
|
||||
}
|
||||
@@ -286,9 +295,7 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
extras.drivers(s.gpuDrivers)
|
||||
}
|
||||
if (tab == SheetTab.CONTROLS) {
|
||||
SettingsGroup(stringResource(R.string.drawer_page_controller)) {
|
||||
ActionRow(stringResource(R.string.input_remap_buttons), null, stringResource(R.string.ctrl_edit), a.onInputSettings)
|
||||
}
|
||||
InputQuickSettings(host, desktop = s.mode == SessionService.MODE_DESKTOP, onEdit = a.onInputSettings)
|
||||
SettingsGroup(if (steam) stringResource(R.string.mode_touch_controls) else stringResource(R.string.mode_touch)) {
|
||||
ChoiceRow(
|
||||
host, "touch", stringResource(R.string.mode_touch), null,
|
||||
@@ -301,6 +308,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
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),
|
||||
), s.oscMode,
|
||||
note = stringResource(R.string.mode_osc_note), onPick = a.onOsc,
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.graphics.RadialGradient
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Shader
|
||||
import android.graphics.Typeface
|
||||
import androidx.core.graphics.PathParser
|
||||
import com.droiddeck.launcher.input.DpadStyle
|
||||
import com.droiddeck.launcher.input.FaceGlyphs
|
||||
import com.droiddeck.launcher.input.InputControl
|
||||
@@ -25,7 +24,7 @@ import kotlin.math.sin
|
||||
|
||||
/** The on-screen controls' shared drawing: one glass material, shaped per virtual controller. */
|
||||
internal class PadArt(context: Context) {
|
||||
val density = context.resources.displayMetrics.density
|
||||
private val density = context.resources.displayMetrics.density
|
||||
private val body = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val shine = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val edge = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
|
||||
@@ -39,7 +38,47 @@ internal class PadArt(context: Context) {
|
||||
private var shineTop = Float.NaN
|
||||
private var shineHeight = Float.NaN
|
||||
|
||||
fun dp(value: Float) = value * density
|
||||
private fun dp(value: Float) = value * density
|
||||
|
||||
fun button(canvas: Canvas, width: Int, height: Int, control: InputControl, kit: PadKit, pressed: Boolean): Boolean {
|
||||
val w = width.toFloat()
|
||||
val h = height.toFloat()
|
||||
if (min(w, h) <= dp(4f)) return false
|
||||
when (control) {
|
||||
InputControl.A, InputControl.B, InputControl.X, InputControl.Y ->
|
||||
face(canvas, w / 2f, h / 2f, min(w, h) / 2f - dp(2f), control, kit, pressed)
|
||||
InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT -> shoulder(canvas, w, h, control, kit, pressed)
|
||||
InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5 -> grip(canvas, w, h, control.label, pressed)
|
||||
InputControl.L3, InputControl.R3 -> small(canvas, w, h, control.label, pressed)
|
||||
InputControl.SELECT, InputControl.START, InputControl.GUIDE, InputControl.QAM -> {
|
||||
val (shape, icon) = systemLook(kit, control)
|
||||
system(canvas, w, h, shape, icon, pressed)
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun systemLook(kit: PadKit, control: InputControl): Pair<Shape, Icon> = when {
|
||||
kit.steam -> when (control) {
|
||||
InputControl.SELECT -> Shape.CHIP to Icon.VIEW
|
||||
InputControl.START -> Shape.CHIP to Icon.MENU
|
||||
InputControl.GUIDE -> Shape.PILL to Icon.STEAM
|
||||
else -> Shape.PILL to Icon.QAM
|
||||
}
|
||||
kit.playStation -> when (control) {
|
||||
InputControl.SELECT -> Shape.PILL to if (kit == PadKit.DUALSHOCK) Icon.SHARE else Icon.CREATE
|
||||
InputControl.START -> Shape.PILL to if (kit == PadKit.DUALSHOCK) Icon.OPTIONS else Icon.MENU
|
||||
InputControl.GUIDE -> Shape.ROUND to Icon.HOME
|
||||
else -> Shape.ROUND to Icon.QAM
|
||||
}
|
||||
else -> Shape.ROUND to when (control) {
|
||||
InputControl.SELECT -> Icon.BACK
|
||||
InputControl.START -> Icon.START
|
||||
InputControl.GUIDE -> Icon.HOME
|
||||
else -> Icon.QAM
|
||||
}
|
||||
}
|
||||
|
||||
fun glass(canvas: Canvas, shape: Path, pressed: Boolean, tint: Int = BODY) {
|
||||
shape.computeBounds(rect, false)
|
||||
@@ -127,7 +166,7 @@ internal class PadArt(context: Context) {
|
||||
}
|
||||
|
||||
enum class Shape { ROUND, PILL, CHIP }
|
||||
enum class Icon { VIEW, MENU, QAM, KEYBOARD, BACK, START, CREATE, HOME, STEAM, SHARE, OPTIONS, MARK }
|
||||
enum class Icon { VIEW, MENU, QAM, KEYBOARD, BACK, START, CREATE, HOME, STEAM, SHARE, OPTIONS }
|
||||
|
||||
fun system(canvas: Canvas, w: Float, h: Float, shape: Shape, icon: Icon, pressed: Boolean, ink: Int = INK) {
|
||||
val cx = w / 2f; val cy = h / 2f
|
||||
@@ -179,22 +218,9 @@ internal class PadArt(context: Context) {
|
||||
text(canvas, when (icon) { Icon.STEAM -> "STEAM"; Icon.SHARE -> "SHARE"; else -> "OPTIONS" }, cx, cy, 14 * u, color, size * 1.9f)
|
||||
ink.letterSpacing = 0f
|
||||
}
|
||||
Icon.MARK -> mark(canvas, cx, cy, size * .5f, color, if (color == ON_ACCENT) ON_ACCENT else ACCENT)
|
||||
}
|
||||
}
|
||||
|
||||
fun mark(canvas: Canvas, cx: Float, cy: Float, radius: Float, ink: Int, orb: Int) {
|
||||
val k = radius / 111.86f
|
||||
canvas.save()
|
||||
canvas.translate(cx - 71.98f * k, cy - 111.86f * k)
|
||||
canvas.scale(k, k)
|
||||
fill.shader = null; fill.color = ink
|
||||
canvas.drawPath(MARK, fill)
|
||||
fill.color = orb
|
||||
canvas.drawCircle(63.98f, 111.86f, 55.98f, fill)
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
private fun chevron(canvas: Canvas, ax: Float, ay: Float, dx: Float, dy: Float, k: Float, color: Int, width: Float) {
|
||||
val px = -dy; val py = dx
|
||||
line.color = color; line.strokeWidth = width
|
||||
@@ -216,6 +242,7 @@ internal class PadArt(context: Context) {
|
||||
fun dpad(canvas: Canvas, w: Float, h: Float, kit: PadKit, held: Int, chevrons: Boolean = true, ink: Int = INK) {
|
||||
val cx = w / 2f; val cy = h / 2f
|
||||
val s = min(w, h) / 2f - dp(3f)
|
||||
if (s <= 0f) return
|
||||
val dirs = arrayOf(floatArrayOf(0f, -1f), floatArrayOf(1f, 0f), floatArrayOf(0f, 1f), floatArrayOf(-1f, 0f))
|
||||
when (kit.dpad) {
|
||||
DpadStyle.CROSS, DpadStyle.DISC -> {
|
||||
@@ -232,7 +259,7 @@ internal class PadArt(context: Context) {
|
||||
for (i in 0..3) {
|
||||
val dx = dirs[i][0]; val dy = dirs[i][1]
|
||||
val on = held and (1 shl i) != 0
|
||||
if (on) {
|
||||
if (on && half > dp(2f)) {
|
||||
fill.shader = null; fill.color = PRESSED
|
||||
val near = half + dp(1f); val far = arms - dp(2f); val side = half - dp(2f)
|
||||
rect.set(if (dx == 0f) cx - side else if (dx > 0) cx + near else cx - far, if (dy == 0f) cy - side else if (dy > 0) cy + near else cy - far,
|
||||
@@ -269,6 +296,7 @@ internal class PadArt(context: Context) {
|
||||
}
|
||||
|
||||
fun stick(canvas: Canvas, cx: Float, cy: Float, radius: Float, kit: PadKit, kx: Float, ky: Float, active: Boolean) {
|
||||
fill.alpha = 255
|
||||
fill.shader = RadialGradient(cx, cy, radius, WELL_IN, WELL_OUT, Shader.TileMode.CLAMP)
|
||||
fill.setShadowLayer(dp(2.5f), 0f, dp(1.5f), SHADOW)
|
||||
canvas.drawCircle(cx, cy, radius, fill)
|
||||
@@ -327,12 +355,6 @@ internal class PadArt(context: Context) {
|
||||
fill.color = ACCENT; canvas.drawCircle(fx, fy, dp(5f), fill)
|
||||
}
|
||||
|
||||
fun label(canvas: Canvas, w: Float, h: Float, round: Boolean, value: String, pressed: Boolean) {
|
||||
val inset = dp(2f)
|
||||
glass(canvas, if (round) circle(w / 2f, h / 2f, min(w, h) / 2f - inset) else roundRect(inset, inset, w - inset, h - inset, min(w, h) * .25f), pressed)
|
||||
text(canvas, value, w / 2f, h / 2f, min(h * .38f, dp(18f)), if (pressed) ON_ACCENT else INK, w * .82f)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VISUAL = .72f
|
||||
val ACCENT = Color.rgb(0x1A, 0x9F, 0xFF)
|
||||
@@ -352,8 +374,5 @@ internal class PadArt(context: Context) {
|
||||
InputControl.X to Color.rgb(0x4C, 0x9B, 0xF0), InputControl.Y to Color.rgb(0xF5, 0xC0, 0x2E))
|
||||
private val SYMBOL_COLORS = mapOf(InputControl.A to Color.rgb(0x8D, 0xB4, 0xF2), InputControl.B to Color.rgb(0xF2, 0x61, 0x6B),
|
||||
InputControl.X to Color.rgb(0xEE, 0x93, 0xD6), InputControl.Y to Color.rgb(0x45, 0xCB, 0xAA))
|
||||
private const val MARK_DATA = "M-31.98 0H56.055V40.489A71.81 71.81 0 0 0 56.055 183.231V223.72H-31.98Z" +
|
||||
"M71.885 0.28A111.86 111.86 0 0 1 71.885 223.44V183.234A71.81 71.81 0 0 0 71.885 40.486Z"
|
||||
val MARK: Path by lazy { PathParser.createPathFromPathData(MARK_DATA) }
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,8 @@ class SecondScreenPresentation(
|
||||
if (!created || !currentMode.controls) return
|
||||
val controls = controlsView ?: return
|
||||
val layout = panelLayout(currentMode)
|
||||
controls.showLayout(layout)
|
||||
controls.updateCustomLayout(layout?.elements.orEmpty())
|
||||
controls.updateStyle(layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle())
|
||||
}
|
||||
|
||||
fun showKeyboard(): Boolean {
|
||||
@@ -292,7 +293,8 @@ class SecondScreenPresentation(
|
||||
if (mode == SecondScreenMode.DECK_CONTROLS) deckPanel.value = SessionPrefs.deckPanel(context)
|
||||
bar(mode)
|
||||
val layout = panelLayout(mode)
|
||||
val controls = InputSurfaceView(context, pad).also { it.showLayout(layout) }
|
||||
val controls = InputSurfaceView(context, pad, layout?.elements.orEmpty(),
|
||||
surfaceStyle = layout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle())
|
||||
controlsView = controls
|
||||
root.addView(controls, weightParams())
|
||||
attachKeyboard()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
internal enum class SessionDrawerPage(val firstControl: String) {
|
||||
CONTROLLER("touch"),
|
||||
CONTROLLER("input-profile"),
|
||||
GLASSES("glasses-game"),
|
||||
DISPLAY("fg"),
|
||||
HUD("hud"),
|
||||
|
||||
@@ -50,6 +50,8 @@ import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.material.icons.outlined.Speed
|
||||
import androidx.compose.material.icons.outlined.SportsEsports
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.RadioButtonDefaults
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.ui.semantics.Role
|
||||
@@ -279,6 +281,9 @@ class DrawerActions(
|
||||
val blackFrameInsertion: Boolean = false,
|
||||
val blackFrameInsertionAvailable: Boolean = false,
|
||||
val onBlackFrameInsertion: (Boolean) -> Unit = {},
|
||||
val hdr: Boolean = false,
|
||||
val hdrAvailable: Boolean = false,
|
||||
val onHdr: (Boolean) -> Unit = {},
|
||||
val onImportLossless: () -> Unit,
|
||||
val onKeyboard: () -> Unit,
|
||||
val onHardwareKeyboard: () -> Unit,
|
||||
@@ -290,11 +295,7 @@ class DrawerActions(
|
||||
val onAchievements: (() -> Unit)? = null,
|
||||
val achievementsProgress: Pair<Int, Int>? = null,
|
||||
val onOsc: (String) -> Unit,
|
||||
val layoutGame: String? = null,
|
||||
val layoutOptions: List<Pair<String, String>> = emptyList(),
|
||||
val layoutChoice: String = "",
|
||||
val onLayout: (String) -> Unit = {},
|
||||
val onEditLayout: (() -> Unit)? = null,
|
||||
val onEditSteamTouch: (() -> Unit)? = null,
|
||||
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
|
||||
val onRumble: (Boolean) -> Unit = {},
|
||||
val onSuspendPolicy: (String) -> Unit,
|
||||
@@ -340,6 +341,15 @@ class DrawerActions(
|
||||
val onPause: () -> Unit = {},
|
||||
val onPipAutoEnter: (Boolean) -> Unit = {},
|
||||
val unfoldedControls: Boolean? = null,
|
||||
val adaptiveSticks: Boolean? = null,
|
||||
val onAdaptiveSticks: (Boolean) -> Unit = {},
|
||||
val showFloatingSteamControls: Boolean = false,
|
||||
val oscRearButtons: Boolean = false,
|
||||
val oscTrackpads: Boolean = false,
|
||||
val onOscRearButtons: (Boolean) -> Unit = {},
|
||||
val onOscTrackpads: (Boolean) -> Unit = {},
|
||||
val quickButtons: Map<com.droiddeck.launcher.input.InputCommand, Boolean> = emptyMap(),
|
||||
val onQuickButton: (com.droiddeck.launcher.input.InputCommand, Boolean) -> Unit = { _, _ -> },
|
||||
val onUnfoldedControls: (Boolean) -> Unit = {},
|
||||
val unfoldedControlsWithController: Boolean = false,
|
||||
val onUnfoldedControlsWithController: (Boolean) -> Unit = {},
|
||||
@@ -664,52 +674,12 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
if (!a.glassesOutput) CardboardGroup(host, a) { key -> focus.track(page, key) }
|
||||
}
|
||||
SessionDrawerPage.CONTROLLER -> {
|
||||
SettingsGroup(a.layoutGame?.let { stringResource(R.string.osc_group_for, it) } ?: stringResource(R.string.mode_osc)) {
|
||||
if (a.layoutOptions.isNotEmpty()) ChoiceRow(host, "osc-layout", stringResource(R.string.osc_layout), null,
|
||||
a.layoutOptions, a.layoutChoice, chipModifier = focus.track(page, "osc-layout"), onPick = a.onLayout)
|
||||
a.onEditLayout?.let { edit ->
|
||||
ActionRow(stringResource(R.string.osc_edit_layout), null, stringResource(R.string.ctrl_edit), { host.open = null; edit() },
|
||||
modifier = focus.track(page, "osc-edit"))
|
||||
}
|
||||
SettingsRow(stringResource(R.string.osc_show), null) {
|
||||
SegmentedTabs(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)), a.oscMode,
|
||||
tabModifier = { focus.track(page, "osc-$it") }, onPick = a.onOsc)
|
||||
}
|
||||
ChoiceRow(host, "touch", stringResource(R.string.input_touches), null,
|
||||
listOf(SessionPrefs.TOUCH_AUTO to stringResource(R.string.drawer_touch_auto, a.touchAuto), SessionPrefs.TOUCH_DIRECT to stringResource(R.string.mode_touch_mouse),
|
||||
SessionPrefs.TOUCH_PAD to stringResource(R.string.mode_touch_touchpad), 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),
|
||||
null, 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), null,
|
||||
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)
|
||||
}
|
||||
if (a.steam && a.unfoldedControls != null) ToggleRow(host, "unfolded-controls", stringResource(R.string.unfolded_controls),
|
||||
null, 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),
|
||||
null, a.unfoldedControlsWithController,
|
||||
chipModifier = focus.track(page, "unfolded-controls-with-controller"),
|
||||
onChange = a.onUnfoldedControlsWithController)
|
||||
}
|
||||
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), null,
|
||||
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),
|
||||
@@ -720,9 +690,89 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
a.controller?.let { c ->
|
||||
ToggleRow(host, "rumble", stringResource(R.string.ctrl_rumble), null, c.rumble,
|
||||
chipModifier = focus.track(page, "rumble"), onChange = a.onRumble)
|
||||
|
||||
}
|
||||
ActionRow(stringResource(R.string.input_remap_buttons), null, stringResource(R.string.ctrl_edit),
|
||||
a.onInputSettings, modifier = focus.track(page, "remap"))
|
||||
}
|
||||
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}") })
|
||||
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)) {
|
||||
@@ -742,57 +792,28 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
),
|
||||
a.wowChat, chipModifier = focus.track(page, "wow-chat"), onPick = a.onWowChat,
|
||||
)
|
||||
}
|
||||
a.pen?.let { PenSettingsGroup(host, it, track = { key -> focus.track(page, key) }, onPick = a.onPen) }
|
||||
var moreControls by rememberSaveable { mutableStateOf(false) }
|
||||
SettingsGroup(stringResource(R.string.osc_more)) {
|
||||
ActionRow(stringResource(R.string.osc_more_detail), null, stringResource(if (moreControls) R.string.common_hide else R.string.common_show),
|
||||
{ moreControls = !moreControls }, modifier = focus.track(page, "more-controls"))
|
||||
if (moreControls) {
|
||||
if (a.steam) ToggleRow(host, "back-hold", stringResource(R.string.back_hold),
|
||||
null, a.backHold,
|
||||
chipModifier = focus.track(page, "back-hold"), onChange = a.onBackHold)
|
||||
if (a.steam) ChoiceRow(host, "back-actions", stringResource(R.string.input_back_taps), null,
|
||||
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}") })
|
||||
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)
|
||||
ToggleRow(host, "low-latency", stringResource(R.string.drawer_low_latency),
|
||||
null, 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"))
|
||||
val keyboardContext = LocalContext.current
|
||||
remember { PcKeyboardPrefs.load(keyboardContext) }
|
||||
SliderRow(
|
||||
stringResource(R.string.pckb_size), null,
|
||||
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), null,
|
||||
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),
|
||||
null,
|
||||
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 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) })
|
||||
}
|
||||
}
|
||||
SessionDrawerPage.GLASSES -> if (glassesTab == GlassesTab.CONTROLLERS) {
|
||||
@@ -832,7 +853,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
SessionDrawerPage.AGENT -> Unit
|
||||
SessionDrawerPage.SESSION -> {
|
||||
SettingsGroup(stringResource(R.string.drawer_support)) {
|
||||
SettingsRow(stringResource(R.string.report_problem), null) {
|
||||
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
|
||||
@@ -870,7 +891,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.drawer_session_behavior)) {
|
||||
if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic),
|
||||
null, a.micEnabled,
|
||||
stringResource(R.string.drawer_mic_hint), a.micEnabled,
|
||||
chipModifier = focus.track(page, "microphone"), onChange = a.onMicEnabled)
|
||||
ChoiceRow(
|
||||
host, "suspend", stringResource(R.string.mode_suspend),
|
||||
@@ -889,7 +910,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
)
|
||||
if (a.steam && a.suspendPolicy != SessionPrefs.SUSPEND_NEVER) ToggleRow(
|
||||
host, "background-downloads", stringResource(R.string.mode_background_downloads),
|
||||
null,
|
||||
stringResource(R.string.mode_background_downloads_hint),
|
||||
a.steamDownloadsInBackground,
|
||||
onChange = a.onSteamDownloadsInBackground,
|
||||
)
|
||||
@@ -1106,20 +1127,20 @@ private fun ScreenEffectsGroup(
|
||||
SettingsGroup(stringResource(R.string.drawer_effects)) {
|
||||
ChoiceRow(
|
||||
host, "effects-profile", stringResource(R.string.screen_effects_target),
|
||||
null, a.screenEffectsTargets,
|
||||
stringResource(R.string.screen_effects_target_hint), a.screenEffectsTargets,
|
||||
a.screenEffectsTarget, chipModifier = track("effects-profile"),
|
||||
onPick = a.onScreenEffectsTarget,
|
||||
)
|
||||
ActionRow(
|
||||
stringResource(R.string.screen_effects_reset),
|
||||
null,
|
||||
stringResource(R.string.screen_effects_reset_hint),
|
||||
stringResource(R.string.hud_reset_button),
|
||||
a.onScreenEffectsReset,
|
||||
modifier = track("effects-reset"),
|
||||
)
|
||||
if (a.screenEffectsCanDelete) ActionRow(
|
||||
stringResource(R.string.screen_effects_delete),
|
||||
null,
|
||||
stringResource(R.string.screen_effects_delete_hint),
|
||||
stringResource(R.string.common_delete),
|
||||
a.onScreenEffectsDelete,
|
||||
modifier = track("effects-delete"),
|
||||
@@ -1154,7 +1175,9 @@ private fun ScreenEffectsGroup(
|
||||
ToggleRow(host, "toon", stringResource(R.string.drawer_toon), null, e.toon, chipModifier = track("toon")) { a.onEffects(e.copy(toon = it)) }
|
||||
ToggleRow(host, "crt", stringResource(R.string.drawer_crt), null, e.crt, chipModifier = track("crt")) { a.onEffects(e.copy(crt = it)) }
|
||||
ToggleRow(host, "ntsc", stringResource(R.string.drawer_ntsc), null, e.ntsc, chipModifier = track("ntsc")) { a.onEffects(e.copy(ntsc = it)) }
|
||||
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.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)
|
||||
@@ -1202,7 +1225,7 @@ private fun ScreenEffectsGroup(
|
||||
private fun CardboardGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
|
||||
val c = a.cardboard
|
||||
SettingsGroup(stringResource(R.string.cardboard_title)) {
|
||||
ToggleRow(host, "cardboard", stringResource(R.string.cardboard_mode), null,
|
||||
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
|
||||
ChoiceRow(host, "cardboard-source", stringResource(R.string.cardboard_source), null,
|
||||
@@ -1676,6 +1699,8 @@ internal fun ComponentDownloadsDrawerGroup(
|
||||
val installed = packages.map { it.file }.toSet()
|
||||
val nightlyPicked = remember { mutableStateMapOf<String, Boolean>() }
|
||||
SettingsGroup(stringResource(R.string.drawer_component_downloads)) {
|
||||
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,
|
||||
if (catalogAt > 0) java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT)
|
||||
.format(java.util.Date(catalogAt * 1000)) else stringResource(R.string.comp_never)), null, stacked = true) {
|
||||
|
||||
@@ -137,7 +137,7 @@ internal object SettingsIndex {
|
||||
SettingsEntry(SettingsPlace.STEAM_QAM, R.string.drawer_frame_limit, R.string.perf_title, words = listOf("fps", "cap", "limit", "steam games")),
|
||||
SettingsEntry(SettingsPlace.STEAM_QAM, R.string.perf_title, words = listOf("performance overlay", "fps", "counter", "tdp")),
|
||||
|
||||
sh(R.string.drawer_page_display, R.string.display_session, "resolution", "scaling", "hdr", "refresh"),
|
||||
sh(R.string.drawer_page_display, R.string.display_session, "resolution", "scaling", "hdr", "refresh", "zero-copy"),
|
||||
sh(R.string.drawer_page_display, R.string.sheet_graphics_drivers, "turnip", "driver", "gpu", "adreno", "mali"),
|
||||
sh(R.string.mode_tab_steam, R.string.setup_offline, "offline", "steam"),
|
||||
sh(R.string.mode_audio, R.string.mode_mic, "microphone", "voice"),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.wayland
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Process
|
||||
@@ -29,11 +30,28 @@ object CompositorHost {
|
||||
@Volatile
|
||||
private var vsyncGeneration = 0
|
||||
|
||||
private fun vsyncCallback(generation: Int) = object : Choreographer.FrameCallback {
|
||||
override fun doFrame(frameTimeNanos: Long) {
|
||||
if (generation != vsyncGeneration) return
|
||||
private fun postVsync(generation: Int) {
|
||||
val choreographer = Choreographer.getInstance()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
choreographer.postVsyncCallback { data ->
|
||||
if (generation != vsyncGeneration) return@postVsyncCallback
|
||||
val lines = data.frameTimelines
|
||||
val line = data.preferredFrameTimeline
|
||||
val period = if (lines.size > 1) {
|
||||
lines[1].expectedPresentationTimeNanos - lines[0].expectedPresentationTimeNanos
|
||||
} else {
|
||||
0L
|
||||
}
|
||||
WaylandCompositor.nativeFrameTimeline(line.expectedPresentationTimeNanos, line.deadlineNanos, period)
|
||||
WaylandCompositor.nativeVsync(data.frameTimeNanos)
|
||||
if (vsyncRunning) postVsync(generation)
|
||||
}
|
||||
return
|
||||
}
|
||||
choreographer.postFrameCallback { frameTimeNanos ->
|
||||
if (generation != vsyncGeneration) return@postFrameCallback
|
||||
WaylandCompositor.nativeVsync(frameTimeNanos)
|
||||
if (vsyncRunning) Choreographer.getInstance().postFrameCallback(this)
|
||||
if (vsyncRunning) postVsync(generation)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,14 +167,14 @@ object CompositorHost {
|
||||
|
||||
private fun resumeVsync() {
|
||||
if (vsyncRunning) return
|
||||
val callback = vsyncCallback(++vsyncGeneration)
|
||||
val generation = ++vsyncGeneration
|
||||
vsyncRunning = true
|
||||
WaylandCompositor.nativeLog("screen", if (ownVsyncThread) "screen tick runs on its own display-priority thread" else "screen tick runs on the main thread")
|
||||
if (!ownVsyncThread) {
|
||||
Choreographer.getInstance().postFrameCallback(callback)
|
||||
postVsync(generation)
|
||||
return
|
||||
}
|
||||
vsyncHandler.post { Choreographer.getInstance().postFrameCallback(callback) }
|
||||
vsyncHandler.post { postVsync(generation) }
|
||||
}
|
||||
|
||||
private fun pauseVsync() {
|
||||
|
||||
@@ -48,8 +48,11 @@ object HdrSupport {
|
||||
)
|
||||
}
|
||||
|
||||
fun blocked(context: Context): String? =
|
||||
if (Build.VERSION.SDK_INT < 29) context.getString(R.string.hdr_needs_android_10) else null
|
||||
|
||||
private fun reason(context: Context, hdr10: Boolean, formats: String): String? = when {
|
||||
Build.VERSION.SDK_INT < 29 -> context.getString(R.string.hdr_needs_android_10)
|
||||
Build.VERSION.SDK_INT < 29 -> blocked(context)
|
||||
!hdr10 -> if (formats.isEmpty()) context.getString(R.string.hdr_none) else context.getString(R.string.hdr_not_hdr10, formats)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -94,6 +94,73 @@ public final class WaylandCompositor {
|
||||
if (l != null) l.onPointerLock(locked, x, y);
|
||||
}
|
||||
|
||||
public interface OverlayPlanesListener {
|
||||
void onOverlayPlanes(int planes);
|
||||
}
|
||||
|
||||
private static volatile OverlayPlanesListener overlayPlanesListener;
|
||||
private static volatile int overlayPlanes = -1;
|
||||
|
||||
public static synchronized void setOverlayPlanesListener(OverlayPlanesListener l) {
|
||||
overlayPlanesListener = l;
|
||||
if (l != null) l.onOverlayPlanes(overlayPlanes);
|
||||
}
|
||||
|
||||
public static synchronized void clearOverlayPlanesListener(OverlayPlanesListener l) {
|
||||
if (overlayPlanesListener == l) overlayPlanesListener = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static synchronized void onOverlayPlanes(int planes) {
|
||||
overlayPlanes = planes;
|
||||
OverlayPlanesListener l = overlayPlanesListener;
|
||||
if (l != null) l.onOverlayPlanes(planes);
|
||||
}
|
||||
|
||||
public interface RefreshTargetListener {
|
||||
void onRefreshTarget(int refresh, int frameRate);
|
||||
}
|
||||
|
||||
private static volatile RefreshTargetListener refreshTargetListener;
|
||||
private static volatile long refreshTarget;
|
||||
|
||||
public static void setRefreshTargetListener(RefreshTargetListener l) {
|
||||
refreshTargetListener = l;
|
||||
long target = refreshTarget;
|
||||
if (l != null) l.onRefreshTarget((int) (target >> 32), (int) target);
|
||||
}
|
||||
|
||||
public static void clearRefreshTargetListener(RefreshTargetListener l) {
|
||||
if (refreshTargetListener == l) refreshTargetListener = null;
|
||||
}
|
||||
|
||||
public interface ContentRateListener {
|
||||
void onContentRate(int fps);
|
||||
}
|
||||
|
||||
private static volatile ContentRateListener contentRateListener;
|
||||
|
||||
public static void setContentRateListener(ContentRateListener l) {
|
||||
contentRateListener = l;
|
||||
}
|
||||
|
||||
public static void clearContentRateListener(ContentRateListener l) {
|
||||
if (contentRateListener == l) contentRateListener = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static void onContentRate(int fps) {
|
||||
ContentRateListener l = contentRateListener;
|
||||
if (l != null) l.onContentRate(fps);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static void onRefreshTarget(int refresh, int frameRate) {
|
||||
refreshTarget = ((long) refresh << 32) | (frameRate & 0xffffffffL);
|
||||
RefreshTargetListener l = refreshTargetListener;
|
||||
if (l != null) l.onRefreshTarget(refresh, frameRate);
|
||||
}
|
||||
|
||||
public interface ClipboardListener {
|
||||
void onGuestClipboardText(String text);
|
||||
}
|
||||
@@ -180,6 +247,8 @@ public final class WaylandCompositor {
|
||||
|
||||
public static native void nativeVsync(long frameTimeNanos);
|
||||
|
||||
public static native void nativeFrameTimeline(long presentNanos, long deadlineNanos, long periodNanos);
|
||||
|
||||
public static native void nativeSetClockControl(String path);
|
||||
|
||||
public static native int nativeCompositorTid();
|
||||
@@ -210,8 +279,12 @@ public final class WaylandCompositor {
|
||||
|
||||
public static native void nativeSetOutputRefreshRate(float hz);
|
||||
|
||||
public static native void nativeSetPanelRates(int[] rates);
|
||||
|
||||
public static native void nativeSetZeroCopy(boolean on);
|
||||
|
||||
public static native void nativeSetDisplayBufferDriver(boolean on);
|
||||
|
||||
public static native int nativeZeroCopyFrames();
|
||||
|
||||
public static native int nativeZeroCopyLastFrameAgeMs();
|
||||
@@ -247,7 +320,7 @@ public final class WaylandCompositor {
|
||||
public static native void nativeResetFirstFrame();
|
||||
|
||||
|
||||
public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2;
|
||||
public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2, HDR_MODE_TONEMAP = 3;
|
||||
|
||||
public static native void nativeSetHdrRequest(int mode, String source, boolean dxvkHdr, boolean zeroCopyForced);
|
||||
|
||||
|
||||
@@ -75,9 +75,14 @@
|
||||
<string name="input_independent_copy">نسخة مستقلة</string>
|
||||
<string name="input_floating_stick">بدء العصا عند موضع اللمس</string>
|
||||
<string name="input_hide_idle">إخفاء العصا عند عدم الاستخدام</string>
|
||||
<string name="input_tools">الأدوات</string>
|
||||
<string name="input_quick_auto">تلقائي (%1$s)</string>
|
||||
<string name="input_quick_mixed">مخصص (%1$s)</string>
|
||||
<string name="input_save_combination">حفظ كملف تعريف جديد</string>
|
||||
<string name="input_profile_controls_mode">عناصر تحكم ملف التعريف</string>
|
||||
<string name="input_profile">ملف التعريف</string>
|
||||
<string name="input_mouse_gestures">إيماءات لوحة لمس الفأرة</string>
|
||||
<string name="input_mouse_gestures_hint">عند تعيينها لمؤشر الفأرة: اضغط للنقر، واستمر للتمرير بالسحب، ومرّر بإصبعين.</string>
|
||||
<string name="input_quick_override_hint">لدى %1$s تجاوز للقائمة السريعة. اختر تلقائي هناك لاستخدام ملف التعريف الافتراضي والأجزاء الثلاثة المحفوظة.</string>
|
||||
<string name="input_route_local">إدخال DroidDeck</string>
|
||||
<string name="input_axis_action_hint" formatted="false">يُحتجز أثناء تحريك العصا في أي اتجاه: يُضغط فوق 55% ويُحرّر تحت 35%. استخدم مفاتيح الاتجاه لتعيين كل اتجاه على حدة. تُنفَّذ أوامر DroidDeck مرة واحدة لكل انحراف. يُضبط النقر على العصا على حدة.</string>
|
||||
@@ -99,11 +104,17 @@
|
||||
<string name="input_shortcut_hold_hint">في وضع Steam. الاستمرار بالضغط على رجوع يفتح الوصول السريع أيضًا.</string>
|
||||
<string name="input_restore_shortcut">الاستعادة إلى الافتراضي</string>
|
||||
<string name="input_virtual_controller">وحدة تحكم افتراضية</string>
|
||||
<string name="input_virtual_controller_hint">نوع وحدة التحكم التي يراها Steam أو اللعبة.</string>
|
||||
<string name="input_touchscreen">شاشة لمس</string>
|
||||
<string name="input_touchscreen_hint">كيفية التعامل مع اللمسات على شاشة اللعبة. تحتفظ أزرار ملف التعريف بإجراءاتها المعيّنة.</string>
|
||||
<string name="input_touch_cursor">مؤشر اللمس</string>
|
||||
<string name="input_touch_cursor_hint">إظهار مؤشر للمسات المباشرة على شاشة اللعبة.</string>
|
||||
<string name="input_touch_hold">اللمس والاستمرار</string>
|
||||
<string name="input_touch_hold_hint">إجراء الفأرة عند الاستمرار بإصبع على شاشة اللعبة.</string>
|
||||
<string name="input_back_taps">نقرات زر رجوع</string>
|
||||
<string name="input_back_taps_hint">الإجراء الأول: نقرة واحدة. الإجراء الثاني: نقرتان.</string>
|
||||
<string name="input_toggle_button">زر تبديل</string>
|
||||
<string name="input_toggle_button_hint">اضغط للاستمرار، واضغط مرة أخرى للتحرير. فتح قائمة أو تبديل ملف التعريف يحرّر الزر.</string>
|
||||
<string name="input_button_shape">الشكل</string>
|
||||
<string name="input_shape_rounded">مستدير</string>
|
||||
<string name="input_shape_pill">كبسولة</string>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="input_settings">ملفات تعريف الإدخال</string>
|
||||
<string name="input_profiles">ملفات التعريف</string>
|
||||
<string name="input_physical">وحدة تحكم فعلية</string>
|
||||
<string name="input_primary">الشاشة الرئيسية</string>
|
||||
@@ -22,6 +23,7 @@
|
||||
<string name="input_command_steam">فتح قائمة Steam</string>
|
||||
<string name="input_command_qam">فتح الوصول السريع في Steam</string>
|
||||
<string name="input_remove_element">إزالة عنصر التحكم</string>
|
||||
<string name="input_add_element">إضافة عنصر تحكم</string>
|
||||
<string name="input_extra_keys">أزرار خاصة بالجهاز</string>
|
||||
<string name="input_capture">تعيين زر فعلي</string>
|
||||
<string name="input_capture_confirm">حرّر الزر ثم اختر تحرير أو إعادة المحاولة أو إلغاء. يلغي B أو رجوع بعد التحرير.</string>
|
||||
|
||||
@@ -281,7 +281,6 @@
|
||||
<string name="mode_hdr">HDR</string>
|
||||
<string name="mode_hdr10">إخراج HDR10</string>
|
||||
<string name="mode_hdr_unavailable">غير متاح: %1$s.</string>
|
||||
<string name="mode_hdr_restart">أعد تشغيل التطبيق لتطبيق التغيير.</string>
|
||||
<string name="mode_drivers">برامج التشغيل</string>
|
||||
<string name="mode_gpu_drivers">برامج تشغيل GPU</string>
|
||||
<string name="mode_gpu_drivers_hint">مشتركة بين Steam وسطح المكتب. يتم ضبطها في صفحة «المكوّنات».</string>
|
||||
@@ -295,10 +294,14 @@
|
||||
<string name="mode_pen_touch">اللمس</string>
|
||||
<string name="mode_pen_button">الزر الجانبي</string>
|
||||
<string name="mode_osc">عناصر التحكم على الشاشة</string>
|
||||
<string name="mode_osc_qam">Steam + QAM</string>
|
||||
<string name="mode_osc_note">يعرض الخيار «تلقائي» عناصر التحكم عند عدم توصيل وحدة تحكم.</string>
|
||||
<string name="osc_steam_touch">لمس Steam (تجريبي)</string>
|
||||
<string name="osc_style_next_session">تبدأ عناصر التحكم باللمس من Steam مع جلسة Steam التالية</string>
|
||||
<string name="osc_steam_layout">تخطيط لمس Steam</string>
|
||||
<string name="screen_key_layout_export">تصدير</string>
|
||||
<string name="screen_key_image">صورة</string>
|
||||
<string name="osc_steam_layout_hint">انقل عناصر التحكم باللمس لهذه اللعبة أو غيّر حجمها أو أخفها؛ ويتم الحفظ في Steam</string>
|
||||
<string name="mode_controller">وحدة التحكم</string>
|
||||
<string name="mode_controller_hint">كيف يرى Steam وحدة التحكم لديك. يُطبَّق في الجلسة التالية.</string>
|
||||
<string name="mode_controller_deck">وحدة تحكم Steam Deck</string>
|
||||
@@ -429,6 +432,7 @@
|
||||
<string name="mode_directaudio_hint">يتجاوز PulseAudio لتقليل زمن الاستجابة.</string>
|
||||
<string name="mode_mic">الميكروفون</string>
|
||||
<string name="mode_mic_hint">للدردشة الصوتية.</string>
|
||||
<string name="drawer_mic_hint">شغّل التقاط الميكروفون أو أوقفه لهذه الجلسة.</string>
|
||||
<string name="drawer_mic_failed">تعذّر تغيير الميكروفون. يُرجى المحاولة مرة أخرى.</string>
|
||||
<string name="mode_network">الشبكة</string>
|
||||
<string name="mode_wifi_discovery">اكتشاف Wi-Fi</string>
|
||||
@@ -794,6 +798,7 @@
|
||||
<string name="drawer_keyboard">لوحة المفاتيح</string>
|
||||
<string name="drawer_latency">زمن الاستجابة</string>
|
||||
<string name="drawer_low_latency">وضع زمن الاستجابة المنخفض</string>
|
||||
<string name="drawer_low_latency_hint">يزيد استهلاك CPU والبطارية</string>
|
||||
<string name="drawer_low_latency_controller">وحدة تحكم بزمن استجابة منخفض</string>
|
||||
<string name="drawer_low_latency_controller_hint">تبلغ وحدة التحكم بمعدل 1000 هرتز بدلًا من 250 هرتز. استهلاك معالج أعلى قليلًا.</string>
|
||||
<string name="drawer_low_latency_touch">لمس بزمن استجابة منخفض</string>
|
||||
@@ -1367,8 +1372,12 @@
|
||||
<string name="ctrl_opacity">العتامة</string>
|
||||
<string name="ctrl_percent">%1$d%%</string>
|
||||
<string name="ctrl_size">حجم الأزرار</string>
|
||||
<string name="ctrl_adaptive">عصي تكيّفية</string>
|
||||
<string name="ctrl_rumble">اهتزاز اللعبة</string>
|
||||
<string name="ctrl_dead_zone">المنطقة الميتة لعصا التحكم</string>
|
||||
<string name="ctrl_steam_button">زر Steam</string>
|
||||
<string name="ctrl_qam_button">زر QAM</string>
|
||||
<string name="ctrl_keyboard_button">زر لوحة المفاتيح</string>
|
||||
<string name="ctrl_joycon_vr">أجهزة Joy-Con كوحدات تحكم VR</string>
|
||||
<string name="ctrl_joycon_vr_hint">أثناء تشغيل SteamVR، يصبح كل Joy-Con يدًا. وجّهه إلى الأمام واضغط مطولًا على Home أو Capture لإعادة توسيطه.</string>
|
||||
<string name="setup_animations">الرسوم المتحركة</string>
|
||||
@@ -1501,6 +1510,8 @@
|
||||
<string name="deck_surface_trackpad">لوحة اللمس</string>
|
||||
<string name="deck_close">إغلاق عناصر التحكّم على الشاشة الثانية</string>
|
||||
<string name="deck_open_steam_menu">فتح قائمة Steam</string>
|
||||
<string name="deck_right_trackpad">لوحة اللمس اليمنى</string>
|
||||
<string name="deck_left_trackpad">لوحة اللمس اليسرى</string>
|
||||
<string name="second_trackpad">لوحة اللمس</string>
|
||||
<string name="second_show_keyboard">إظهار لوحة المفاتيح</string>
|
||||
<string name="second_hide_keyboard">إخفاء لوحة المفاتيح</string>
|
||||
@@ -1539,8 +1550,11 @@
|
||||
<string name="pckb_android">لوحة مفاتيح Android</string>
|
||||
<string name="pckb_hide">إخفاء ✕</string>
|
||||
<string name="pckb_size">الحجم على الشاشة</string>
|
||||
<string name="pckb_size_hint">نسبة الشاشة التي تشغلها لوحة المفاتيح، بما في ذلك الشريط العلوي.</string>
|
||||
<string name="pckb_opacity">العتامة</string>
|
||||
<string name="pckb_opacity_hint">قلّلها لرؤية اللعبة خلف لوحة المفاتيح.</string>
|
||||
<string name="pckb_hidden_keys">المفاتيح المخفية</string>
|
||||
<string name="pckb_hidden_keys_hint">المفاتيح التي نادرًا ما تستخدمها لا تظهر على لوحة المفاتيح.</string>
|
||||
<string name="pckb_group_function">صف Esc ومفاتيح الوظائف</string>
|
||||
<string name="pckb_group_nav">Ins / Del / Home / End / PgUp / PgDn</string>
|
||||
<string name="pckb_group_arrows">مفاتيح الأسهم</string>
|
||||
@@ -1785,6 +1799,8 @@
|
||||
<string name="drivers_installed_pick">تم تثبيت %1$s - اختره من القائمة</string>
|
||||
<string name="session_wait_removal">انتظر حتى تنتهي إزالة بيئة التشغيل</string>
|
||||
<string name="session_title_game">لعبة</string>
|
||||
<string name="session_touch_auto_touchpad">لوحة اللمس</string>
|
||||
<string name="session_touch_auto_direct">مباشر</string>
|
||||
<string name="session_swap_failed">فشل التبديل: %1$s</string>
|
||||
<string name="session_profile_save_failed">فشل حفظ ملف التعريف: %1$s</string>
|
||||
<string name="session_desktop_paused">تم إيقاف سطح المكتب مؤقتًا</string>
|
||||
@@ -2076,6 +2092,15 @@
|
||||
<string name="fm_up_one_level">الانتقال لمستوى أعلى</string>
|
||||
<string name="fm_choose_folder">اختر مجلدًا</string>
|
||||
<string name="fm_choose_file">اختر ملفًا</string>
|
||||
<string name="ctrl_tint_steam_blue">أزرق Steam</string>
|
||||
<string name="ctrl_tint_sky">سماوي</string>
|
||||
<string name="ctrl_tint_white">أبيض</string>
|
||||
<string name="ctrl_tint_violet">بنفسجي</string>
|
||||
<string name="ctrl_tint_green">أخضر</string>
|
||||
<string name="ctrl_tint_amber">كهرماني</string>
|
||||
<string name="ctrl_tint_red">أحمر</string>
|
||||
<string name="ctrl_tint_pink">وردي</string>
|
||||
<string name="ctrl_tint_gray">رمادي</string>
|
||||
<string name="ctrl_button_a">الزر A</string>
|
||||
<string name="ctrl_button_b">الزر B</string>
|
||||
<string name="ctrl_button_x">الزر X</string>
|
||||
@@ -2539,10 +2564,13 @@
|
||||
<string name="driver_tag_bundle">Android + Linux</string>
|
||||
<string name="phantom_warning">%1$s. %2$s\n\n%3$s</string>
|
||||
<string name="display_session">شاشة الجلسة</string>
|
||||
<string name="display_zero_copy">العرض بدون نسخ</string>
|
||||
<string name="display_resolution">الدقة</string>
|
||||
<string name="display_game_fit">ملاءمة اللعبة لنسبة 16:9</string>
|
||||
<string name="display_game_fit_hint">كيفية ملاءمة ألعاب 16:9 لهذه الشاشة. يُطبَّق في الجلسة التالية.</string>
|
||||
<string name="display_game_fit_unavailable">اختر «مطابقة الشاشة» أو حجمًا مخصَّصًا أضيق من 16:9.</string>
|
||||
<string name="display_avoid_notch">تجنّب فتحة الكاميرا</string>
|
||||
<string name="display_avoid_notch_hint">يُبقي الصورة بعيدًا عن فتحة الكاميرا. يُطبَّق عند العودة إلى الجلسة.</string>
|
||||
<string name="display_preserve">الحفاظ على النسب</string>
|
||||
<string name="display_stretch">تمديد لملء الشاشة</string>
|
||||
<string name="display_image_scaling">تكبير الصورة</string>
|
||||
@@ -3233,6 +3261,7 @@
|
||||
<string name="glasses_pro2_experimental">تتبّع تجريبي لحركة الرأس لنظارة Pro 2. لا يُدعم بعد ضبط السطوع ومستوى الصوت أو تبديل وضع العرض.</string>
|
||||
<string name="cardboard_title">Cardboard VR</string>
|
||||
<string name="cardboard_mode">وضع Cardboard</string>
|
||||
<string name="cardboard_mode_hint">عرض للعين اليسرى وآخر لليمنى لنظارة واقع افتراضي للهاتف.</string>
|
||||
<string name="cardboard_source">الصورة</string>
|
||||
<string name="cardboard_source_screen">شاشة افتراضية</string>
|
||||
<string name="cardboard_source_sbs">ثلاثي الأبعاد جنبًا إلى جنب</string>
|
||||
@@ -3255,6 +3284,7 @@
|
||||
<string name="cardboard_steamvr_unavailable">غير متوفر في هذه الجلسة.</string>
|
||||
<string name="cardboard_steamvr_failed">لم يستجب SteamVR؛ تحقّق من سجل الجلسة.</string>
|
||||
<string name="drawer_component_downloads">تنزيل المكوّنات</string>
|
||||
<string name="drawer_component_downloads_hint">التنزيلات مشتركة مع صفحة «المكوّنات». اختر نسخة منزّلة أعلاه لاستخدامها عند التشغيل التالي للعبة.</string>
|
||||
<string name="drawer_component_choose_download">اختر نسخة لتنزيلها</string>
|
||||
<string name="stores_fact_developer">المطوّر</string>
|
||||
<string name="stores_fact_publisher">الناشر</string>
|
||||
|
||||
Loaded 100 of 275 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user