mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11193646b2 | ||
|
|
422b339af8 |
No files matched your search
@@ -133,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 (!ab->display && dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
close(fd);
|
||||
} else {
|
||||
if (!ab->display && !g_import_failed_logged) {
|
||||
if (!g_import_failed_logged) {
|
||||
g_import_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_IMPORT_SYNC_FILE failed (%s): releases wait for the display's fence here instead",
|
||||
strerror(errno));
|
||||
|
||||
@@ -3888,8 +3888,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
else -> return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
if ((event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD)) && !drawerOpen) {
|
||||
if (com.droiddeck.launcher.input.PointerCapture.isMouse(event) && !drawerOpen) {
|
||||
if (appUiOwnsPointer()) {
|
||||
if (super.dispatchGenericMotionEvent(event)) return true
|
||||
if (touchEditorOpen) return false
|
||||
@@ -5401,8 +5400,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun handleTouch(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
val penRouted = if (pen >= 0) routePen(event, pen).takeIf { it != PenRouter.Route.TOUCH } else null
|
||||
if (penRouted == null && (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD))) return onMouse(event)
|
||||
if (penRouted == null && com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return onMouse(event)
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sessionTouchDown = true
|
||||
@@ -6834,7 +6832,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun onBottomGameHover(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
if (pipUi || pen < 0) return false
|
||||
if (pipUi) return false
|
||||
if (pen < 0) return onBottomGameMouse(event)
|
||||
return when (routePen(event, pen)) {
|
||||
PenRouter.Route.TOUCH -> false
|
||||
PenRouter.Route.PEN -> {
|
||||
@@ -6846,8 +6845,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun onBottomGameMouse(event: MotionEvent): Boolean {
|
||||
if (PenStream.penIndex(event) >= 0 || !com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return false
|
||||
notePress(event)
|
||||
onMouse(event)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun onBottomGameTouch(event: MotionEvent): Boolean {
|
||||
if (pipUi) return true
|
||||
if (onBottomGameMouse(event)) return true
|
||||
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) && PenStream.penIndex(event) < 0) return false
|
||||
notePress(event)
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
|
||||
@@ -10,6 +10,9 @@ object PointerCapture {
|
||||
|
||||
fun isTouchpad(event: MotionEvent): Boolean = event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun isMouse(event: MotionEvent): Boolean =
|
||||
event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun delta(event: MotionEvent): FloatArray {
|
||||
var dx = event.x
|
||||
var dy = event.y
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Bundle
|
||||
import android.view.Display
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.PointerIcon
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.View
|
||||
@@ -44,6 +45,7 @@ class BottomGameScreen(
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
surfaceView.pointerIcon = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_NULL)
|
||||
surfaceView.setOnTouchListener { _, event -> onTouch(event) }
|
||||
surfaceView.holder.addCallback(callback)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,37 @@ class PointerCaptureTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aHoveringMouseOrTouchpadDrivesThePointer() {
|
||||
listOf(
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_BUTTON_PRESS, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_SCROLL, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_TOUCHPAD, x = 640f, y = 360f),
|
||||
).forEach { event ->
|
||||
try {
|
||||
assertTrue(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchesPensControllersAndCapturedMiceAreNotAHoveringMouse() {
|
||||
listOf(
|
||||
InputDevice.SOURCE_TOUCHSCREEN,
|
||||
InputDevice.SOURCE_STYLUS,
|
||||
InputDevice.SOURCE_JOYSTICK,
|
||||
InputDevice.SOURCE_MOUSE_RELATIVE,
|
||||
).forEach { source ->
|
||||
val event = event(MotionEvent.ACTION_MOVE, source, x = 640f, y = 360f)
|
||||
try {
|
||||
assertFalse(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchpadTravelMatchesTheSameDistanceOnScreen() {
|
||||
assertEquals(0.5f, PointerCapture.touchpadScale(unitsPerMm = 20f, padWidth = 2000f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
|
||||
}
|
||||
|
||||
@@ -157,10 +157,42 @@ class SessionPenRoutingTest {
|
||||
SessionPrefs.setPenSetting(activity, "pen", SessionPrefs.PEN_TOUCH)
|
||||
invoke("readPrefs")
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP, 0), CompositorShadow.pens.map { it.flags })
|
||||
}
|
||||
|
||||
@Test fun aMouseOnTheOtherScreensGameMovesTheSessionPointer() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
fun touch(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameTouch",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
val mouse = MotionEvent.TOOL_TYPE_MOUSE
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 10, mouse to 250f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_BUTTON_PRESS, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_DOWN, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_MOVE, 30, mouse to 750f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_UP, 40, mouse to 750f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 50, finger to 600f, source = InputDevice.SOURCE_TOUCHPAD)))
|
||||
assertEquals(
|
||||
listOf(InputSpace.x(250f, 1000), InputSpace.x(250f, 1000), InputSpace.x(750f, 1000), InputSpace.x(600f, 1000)),
|
||||
CompositorShadow.pointers.map { it.second },
|
||||
)
|
||||
assertTrue(CompositorShadow.pointers.all { it.first == 1 && it.third == InputSpace.y(300f, 600) })
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
assertTrue(CompositorShadow.touches.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aControllerOnTheOtherScreensGameIsNotTakenAsAMouse() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_MOVE, 10, finger to 500f, source = InputDevice.SOURCE_JOYSTICK)))
|
||||
assertTrue(CompositorShadow.pointers.isEmpty())
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun glassesAProgramPointerLockAndAppUiDropPenHover() {
|
||||
state<Boolean>("glassesOutputActive").value = true
|
||||
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))
|
||||
|
||||
@@ -474,3 +474,13 @@ Short strokes never released it, and taps kept landing at the relative pointer i
|
||||
counts its touch-down warps, and a frame that contains one is left out of the hold decision. Touch drags, mouse motion
|
||||
and mouse warps still count, so a drag on a game that follows the pointer releases the hold and a recentring game is
|
||||
still held. `tools/tests/test_gamescope_pointer_hold_touch_down.py` compiles the rule with the 0133 rule.
|
||||
|
||||
## 0146 rendervulkan: composite only into output images the display has finished scanning out
|
||||
|
||||
The host compositor now releases a zero-copy display buffer as soon as the display latches the next one, and attaches
|
||||
the display's release fence to the buffer's dma-buf instead of waiting for it on the CPU. That wait had held every
|
||||
release back by about one refresh, so a chain of three buffers ran at two thirds of the refresh rate. KGSL Turnip does
|
||||
not wait on fences attached to a dma-buf, so the composite now checks each output image's dma-buf with `poll(POLLOUT)`.
|
||||
It picks the next image that is neither held by the host nor still being scanned out. Only when every free image is
|
||||
still on the display does it wait for one, up to 100 ms. On kernels that cannot attach the fence, the host keeps
|
||||
waiting itself and nothing changes. `tools/gamescope/tests/nested-swapchain.cpp` covers the choice and the busy check.
|
||||
@@ -0,0 +1,106 @@
|
||||
diff --git a/src/output_image_pick.hpp b/src/output_image_pick.hpp
|
||||
new file mode 100644
|
||||
index 0000000..193d9de
|
||||
--- /dev/null
|
||||
+++ b/src/output_image_pick.hpp
|
||||
@@ -0,0 +1,50 @@
|
||||
+#pragma once
|
||||
+#include <cstdint>
|
||||
+#include <poll.h>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+struct OutputImagePick
|
||||
+{
|
||||
+ uint32_t image;
|
||||
+ bool scanoutPending;
|
||||
+};
|
||||
+
|
||||
+template <typename Held, typename Busy>
|
||||
+inline OutputImagePick PickOutputImage( uint32_t count, uint32_t first, uint32_t last, uint32_t deferred,
|
||||
+ Held &&held, Busy &&busy )
|
||||
+{
|
||||
+ for ( int pass = 0; pass < 2; pass++ )
|
||||
+ {
|
||||
+ for ( uint32_t i = 0; i < count; i++ )
|
||||
+ {
|
||||
+ const uint32_t image = ( first + i ) % count;
|
||||
+ if ( count > 3 && ( image == last || image == deferred ) )
|
||||
+ continue;
|
||||
+ if ( held( image ) )
|
||||
+ continue;
|
||||
+ const bool pending = busy( image );
|
||||
+ if ( pass == 0 && pending )
|
||||
+ continue;
|
||||
+ return { image, pending };
|
||||
+ }
|
||||
+ }
|
||||
+ return { first, busy( first ) };
|
||||
+}
|
||||
+
|
||||
+inline bool DmabufScanoutPending( int fd )
|
||||
+{
|
||||
+ if ( fd < 0 )
|
||||
+ return false;
|
||||
+ pollfd p = { .fd = fd, .events = POLLOUT, .revents = 0 };
|
||||
+ return poll( &p, 1, 0 ) == 0;
|
||||
+}
|
||||
+
|
||||
+inline void WaitDmabufScanout( int fd, int timeoutMs )
|
||||
+{
|
||||
+ if ( fd < 0 )
|
||||
+ return;
|
||||
+ pollfd p = { .fd = fd, .events = POLLOUT, .revents = 0 };
|
||||
+ poll( &p, 1, timeoutMs );
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index 1d3a80c..3668a10 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "steamcompmgr.hpp"
|
||||
#include "log.hpp"
|
||||
#include "Utils/Process.h"
|
||||
+#include "output_image_pick.hpp"
|
||||
|
||||
#include "cs_composite_blit.h"
|
||||
#include "cs_composite_blur.h"
|
||||
@@ -4297,18 +4298,29 @@ static bool vulkan_output_image_held( uint32_t nImage )
|
||||
return false;
|
||||
}
|
||||
|
||||
+static bool vulkan_output_image_scanout_pending( uint32_t nImage )
|
||||
+{
|
||||
+ for ( const auto &pImage : { g_output.outputImages[ nImage ], g_output.outputImagesPartialOverlay[ nImage ] } )
|
||||
+ {
|
||||
+ if ( pImage != nullptr && pImage->GetBackendFb() != nullptr && gamescope::DmabufScanoutPending( pImage->dmabuf().fd[0] ) )
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
static uint32_t vulkan_free_output_image( uint32_t nFirst )
|
||||
{
|
||||
- const uint32_t uCount = g_output.outputImages.size();
|
||||
- for ( uint32_t i = 0; i < uCount; i++ )
|
||||
+ const gamescope::OutputImagePick pick = gamescope::PickOutputImage( g_output.outputImages.size(), nFirst,
|
||||
+ g_output.nLastOutImage, g_output.nDeferredOutImage, vulkan_output_image_held, vulkan_output_image_scanout_pending );
|
||||
+ if ( pick.scanoutPending )
|
||||
{
|
||||
- const uint32_t nImage = ( nFirst + i ) % uCount;
|
||||
- if ( uCount > 3 && ( nImage == g_output.nLastOutImage || nImage == g_output.nDeferredOutImage ) )
|
||||
- continue;
|
||||
- if ( !vulkan_output_image_held( nImage ) )
|
||||
- return nImage;
|
||||
+ for ( const auto &pImage : { g_output.outputImages[ pick.image ], g_output.outputImagesPartialOverlay[ pick.image ] } )
|
||||
+ {
|
||||
+ if ( pImage != nullptr && pImage->GetBackendFb() != nullptr )
|
||||
+ gamescope::WaitDmabufScanout( pImage->dmabuf().fd[0], 100 );
|
||||
+ }
|
||||
}
|
||||
- return nFirst;
|
||||
+ return pick.image;
|
||||
}
|
||||
|
||||
std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamescope::Rc<CVulkanTexture> pPipewireTexture, bool partial, gamescope::Rc<CVulkanTexture> pOutputOverride, bool increment, std::unique_ptr<CVulkanCmdBuffer> pInCommandBuffer )
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-1a29c65d
|
||||
GAMESCOPE_SHA256=18620dfedb65860da00003e965cc09784a650ef6ecc9a17056405fe0a1392a02
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-f3a45b31
|
||||
GAMESCOPE_SHA256=3908af87b2ee8a328e9780fc805c6a7bddd11d7405b9992d717b94e16c019313
|
||||
@@ -2,6 +2,9 @@
|
||||
#include "nested_surface_format.hpp"
|
||||
#include "dmabuf_import.hpp"
|
||||
#include "sdl_refresh.hpp"
|
||||
#include "output_image_pick.hpp"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
@@ -152,5 +155,43 @@ int main()
|
||||
assert(DmabufMemoryType(memory, 7, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX);
|
||||
assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == UINT32_MAX);
|
||||
|
||||
using gamescope::PickOutputImage;
|
||||
auto none = [](uint32_t) { return false; };
|
||||
auto pick = PickOutputImage(5, 2, 1, 0, none, none);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
auto heldTwo = [](uint32_t i) { return i == 2; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldTwo, none);
|
||||
assert(pick.image == 3 && !pick.scanoutPending);
|
||||
auto scanningTwo = [](uint32_t i) { return i == 2; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, none, scanningTwo);
|
||||
assert(pick.image == 3 && !pick.scanoutPending);
|
||||
auto scanningAll = [](uint32_t) { return true; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldTwo, scanningAll);
|
||||
assert(pick.image == 3 && pick.scanoutPending);
|
||||
auto heldAll = [](uint32_t) { return true; };
|
||||
auto scanningOne = [](uint32_t i) { return i == 1; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldAll, none);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
pick = PickOutputImage(5, 1, 0, 1, heldAll, scanningOne);
|
||||
assert(pick.image == 1 && pick.scanoutPending);
|
||||
pick = PickOutputImage(3, 1, 0, 2, none, none);
|
||||
assert(pick.image == 1 && !pick.scanoutPending);
|
||||
pick = PickOutputImage(3, 1, 0, 2, none, scanningOne);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
|
||||
int fds[2];
|
||||
assert(pipe(fds) == 0);
|
||||
assert(!gamescope::DmabufScanoutPending(fds[1]));
|
||||
assert(!gamescope::DmabufScanoutPending(-1));
|
||||
fcntl(fds[1], F_SETFL, O_NONBLOCK);
|
||||
char block[4096] = {};
|
||||
while (write(fds[1], block, sizeof(block)) > 0) {}
|
||||
assert(gamescope::DmabufScanoutPending(fds[1]));
|
||||
gamescope::WaitDmabufScanout(fds[1], 1);
|
||||
while (read(fds[0], block, sizeof(block)) == sizeof(block) && gamescope::DmabufScanoutPending(fds[1])) {}
|
||||
assert(!gamescope::DmabufScanoutPending(fds[1]));
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
std::puts("Gamescope presentation and DMA-BUF import tests passed");
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_vk_pending_completion import function
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SRC = ROOT / 'app/src/main/cpp/waylandcomp/src'
|
||||
|
||||
HARNESS = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-util.h>
|
||||
struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); };
|
||||
struct wl_event_source { int unused; };
|
||||
struct wl_event_loop;
|
||||
enum { WL_EVENT_READABLE = 1 };
|
||||
struct wl_client;
|
||||
struct wl_resource { int unused; };
|
||||
struct surface;
|
||||
struct dmabuf_buffer { int fd; };
|
||||
typedef struct AHardwareBuffer { int unused; } AHardwareBuffer;
|
||||
DEFINES
|
||||
STRUCT
|
||||
static struct wl_list g_bufs;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static int g_import_failed_logged;
|
||||
static int import_ok, imports, imported_flags, deferred_releases, frees, sources;
|
||||
static struct wl_event_source g_source;
|
||||
void wl_list_init(struct wl_list *l) { l->prev = l; l->next = l; }
|
||||
void wl_list_insert(struct wl_list *l, struct wl_list *e) {
|
||||
e->next = l->next; e->prev = l; l->next->prev = e; l->next = e;
|
||||
}
|
||||
static int fake_ioctl(int fd, unsigned long req, void *arg) {
|
||||
struct droiddeck_dma_buf_sync_file *f = arg;
|
||||
(void)fd;
|
||||
assert(req == DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE);
|
||||
++imports; imported_flags = (int)f->flags;
|
||||
if (import_ok) return 0;
|
||||
errno = ENOTTY; return -1;
|
||||
}
|
||||
#define ioctl fake_ioctl
|
||||
static int droiddeck_dmabuf_fd(struct dmabuf_buffer *b) { return b->fd; }
|
||||
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; }
|
||||
static struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *l, int fd, uint32_t m,
|
||||
int (*cb)(int, uint32_t, void *), void *d) {
|
||||
(void)l; (void)fd; (void)m; (void)cb; (void)d; ++sources; return &g_source;
|
||||
}
|
||||
static int on_fence_readable(int fd, uint32_t mask, void *data) { (void)fd; (void)mask; (void)data; return 0; }
|
||||
static void send_deferred_release(struct ahb_buf *ab) { ++deferred_releases; ab->release_pending = 0; }
|
||||
static void maybe_free(struct ahb_buf *ab) { (void)ab; ++frees; }
|
||||
FUNCTIONS
|
||||
static void reset(void) { import_ok = imports = imported_flags = deferred_releases = frees = sources = 0; }
|
||||
static void run(int display, int can_import, int fence_signalled) {
|
||||
reset();
|
||||
wl_list_init(&g_bufs);
|
||||
struct dmabuf_buffer b = {.fd = 7};
|
||||
struct ahb_buf ab;
|
||||
memset(&ab, 0, sizeof(ab));
|
||||
ab.id = 42; ab.b = &b; ab.display = display; ab.on_layer = 1; ab.release_pending = 1; ab.fence_fd = -1;
|
||||
wl_list_insert(&g_bufs, &ab.link);
|
||||
int fds[2]; assert(pipe(fds) == 0);
|
||||
if (fence_signalled) assert(write(fds[1], "x", 1) == 1);
|
||||
import_ok = can_import;
|
||||
handle_released(42, fds[0]);
|
||||
assert(!ab.on_layer && imports == 1 && imported_flags == DROIDDECK_DMA_BUF_SYNC_READ);
|
||||
if (can_import || fence_signalled) {
|
||||
assert(deferred_releases == 1 && frees == 1 && !ab.fence_src && ab.fence_fd == -1);
|
||||
errno = 0; assert(fcntl(fds[0], F_GETFD) == -1 && errno == EBADF);
|
||||
} else {
|
||||
assert(deferred_releases == 0 && sources == 1 && ab.fence_src == &g_source && ab.fence_fd == fds[0]);
|
||||
close(fds[0]);
|
||||
}
|
||||
close(fds[1]);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 4);
|
||||
run(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ZeroCopyReleaseAtLatchTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not cc:
|
||||
raise AssertionError('C compiler required')
|
||||
source_dir = Path(os.environ.get('DROIDDECK_DMABUF_TEST_SOURCE', SRC))
|
||||
ahb = (source_dir / 'ahb_swapchain.c').read_text()
|
||||
defines = '\n'.join(re.findall(r'^(?:struct droiddeck_dma_buf_sync_file \{.*?\};|#define DROIDDECK_DMA_BUF_\w+ .*)$',
|
||||
ahb, re.M))
|
||||
struct = re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group()
|
||||
functions = '\n'.join(function(ahb, n) for n in ('find_buf', 'handle_released'))
|
||||
source = HARNESS.replace('DEFINES', '#include <fcntl.h>\n#include <sys/ioctl.h>\n' + defines)
|
||||
source = source.replace('STRUCT', struct).replace('FUNCTIONS', functions)
|
||||
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-release-latch-')
|
||||
cls.addClassCleanup(cls.tmp.cleanup)
|
||||
probe = Path(cls.tmp.name) / 'probe.c'
|
||||
probe.write_text(source)
|
||||
cls.binary = probe.with_suffix('')
|
||||
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror', '-Wno-unused-function', '-UNDEBUG',
|
||||
'-I', str(SRC.parent / 'prebuilt/include'), str(probe), '-o', str(cls.binary)],
|
||||
capture_output=True, text=True)
|
||||
if built.returncode:
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
|
||||
def scenario(self, display, can_import, fence_signalled):
|
||||
result = subprocess.run([str(self.binary), str(display), str(can_import), str(fence_signalled)],
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_display_buffer_released_at_latch_when_fence_attaches(self):
|
||||
self.scenario(1, 1, 0)
|
||||
|
||||
def test_swapchain_buffer_released_at_latch_when_fence_attaches(self):
|
||||
self.scenario(0, 1, 0)
|
||||
|
||||
def test_display_buffer_waits_for_fence_when_kernel_cannot_attach(self):
|
||||
self.scenario(1, 0, 0)
|
||||
|
||||
def test_swapchain_buffer_waits_for_fence_when_kernel_cannot_attach(self):
|
||||
self.scenario(0, 0, 0)
|
||||
|
||||
def test_signalled_fence_releases_without_waiting(self):
|
||||
self.scenario(1, 0, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"repository": "domsvoboda/nexus-runtime",
|
||||
"tag": "runtime-11.0-experimental-g86b2e622",
|
||||
"archive": "nexus-runtime-11.0-experimental-g86b2e622-x86_64.tar.xz",
|
||||
"sha512": "a93d566b68f56e6689d644cc3006bd91515e0ef849898cc9b0603ebceda01be5d5e8c5b21718d0ff073f5f1d6fbc31727f4a92450754465c6b8ef32a14c7e5fd",
|
||||
"tag": "runtime-11.0-20261102-g76c6dd13",
|
||||
"archive": "nexus-runtime-11.0-experimental-g76c6dd13-x86_64.tar.xz",
|
||||
"sha512": "ed6bf55af56128d831ec78ce223770978250d8a4692ea1f24f26258e9d5460c8106e9e6000f554665c91cfcf2abdd235e018d845d8f0cbbed0daaa3d50e61b62",
|
||||
"source": {
|
||||
"name": "nexus-runtime-11.0-experimental-g86b2e622-source.tar.xz",
|
||||
"sha256": "ec8c3d0c8b2a9fe37a53bcaec15a43c3ed9c0c001a4531578c73adc23505f050"
|
||||
"name": "nexus-runtime-11.0-experimental-g76c6dd13-source.tar.xz",
|
||||
"sha256": "9fd3ce24d0c9032fc2237df828c69f07e3de67f6c7008c89881ae7b805f953f5"
|
||||
},
|
||||
"xgameruntime": "b25c05f3d74c4574df93b6fa6c33f06847202ee3",
|
||||
"xgameruntime": "455b1ba9c59984f9478af062fa1aec496bc58ccc",
|
||||
"dlls": {
|
||||
"twinapi.appcore.dll": "aacc1e720dac6cf4192fc6e0f2064499dcda0b339c40601112ab7ceeeb0bdc9e",
|
||||
"windows.web.dll": "e5ae3dc522c5b2502a9d672641f8ffd6c29b93df397b44333c16949d699869de",
|
||||
"libnghttp2.dll": "1001dbbff8b9cb1efa558825b95cbe8efdf5570ad30f5177bdce61b2d102026e",
|
||||
"xgameruntime.dll": "0736131f2c2aeb33866f3f6d1193fc33acd30dd6b3d544dea9830e00e282b3c9",
|
||||
"winhttp.dll": "84c17a9757494af066dd3aea9ce52ed718bcfd3d58739ba6284f83e8eefce8ae",
|
||||
"wintypes.dll": "9542f783f066749ac5e1a5e6e90026eeba575f708e1f4d313caadcfbe51e181d"
|
||||
"twinapi.appcore.dll": "a9e640dee244a900a2d629ea62f2794e8ff973f916871b32b8f3b0f385e70006",
|
||||
"windows.web.dll": "c0b3c78c0d61f0df5387f8bbf6b6b1090d27db07ebdf6f941dce51b02dd28faa",
|
||||
"libnghttp2.dll": "a9c265b965d9af735886eb51e01afde905bc7ea53ed3dcc9ae18e2aebd45d8d0",
|
||||
"xgameruntime.dll": "90b4fd26bd52924a38b720840a3ad1cd9281a9aa64a91c0b52b650d096f1a883",
|
||||
"winhttp.dll": "e8e4e8a91834b481e305a0b6ae83894378ed6a1e83d5a1200605ca7526a46d45",
|
||||
"wintypes.dll": "0583b241fcbf2817a5088373875212f8f2c06bc84d854bc7fc4eb3b5cf75e126"
|
||||
},
|
||||
"compat": {
|
||||
"files/share/xodus-nexus/compat/PlayFabGameSave.dll": [
|
||||
"compat/PlayFabGameSave.dll",
|
||||
"d73ce4802ed5995375a1ce2b85b7c9b30105442a654679f14b99abea2906c69f"
|
||||
"83b4e9985244558b8449a92aafad64681182073d92d60e7bf3536bbac74d7e03"
|
||||
],
|
||||
"files/share/doc/nexus-runtime/runtime-compat-LICENSE": [
|
||||
"LICENSE.runtime-compat",
|
||||
|
||||
Reference in new issue
Block a user