mirror of
https://dev.lirent.ru/Vatrog/vm-vgpu-streamer.git
synced 2026-07-09 21:36:37 +03:00
feat: add graphics-context sensors to producer contract
Append three host-readable sensor groups to the producer block, ABI
frozen by offset asserts (producer still fits page 0):
- cursor Tier-1 (hotspot, glyph dims, shape identity), published under
the existing cursor_seq gate
- content_change_ns: monotonic stamp of the last scene-content change
- display geometry on its own cache line under a geom_seq seqlock:
virtual-desktop bbox, captured-output origin, DPI, refresh
Source the cursor from each backend's existing grab metadata instead of
polling GetCursorInfo in the present pump: DDA from the duplication frame
info pointer position (no extra calls), NvFBC visibility from the grab
info plus one GetCursorInfo per frame for position, GDI from
GetCursorInfo. Position sampling now rides the frame rate, not the pump
tick.
Sample display geometry once at startup and re-sample only on backend
session recreate or a captured-mode change. Drop per-tick cursor
sampling (cursor_sample_pos) from the present loop.
Add src/stream/win32/geometry.{c,h}.
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#include "capture_dda.h"
|
||||
#include "capture-win32.h" /* capture_thread_arg (win32-private) */
|
||||
#include "present.h"
|
||||
#include "cursor.h" /* cursor_resolve_id + ctx->cursor compose state */
|
||||
#include "geometry.h" /* reactive geometry resample on recreate */
|
||||
#include "stream.h" /* vgpu_publish_cursor / vgpu_publish_cursor_shape */
|
||||
|
||||
typedef struct {
|
||||
ID3D11Device* dev;
|
||||
@@ -17,8 +20,61 @@ typedef struct {
|
||||
IDXGIOutputDuplication* dup;
|
||||
ID3D11Texture2D* staging;
|
||||
UINT W, H;
|
||||
int32_t cap_x, cap_y; /* captured output origin (virt coords) */
|
||||
UINT64 last_mouse_update; /* shape-gate by fi.LastMouseUpdateTime */
|
||||
int seeded; /* cold-start position seed done */
|
||||
} dda_state;
|
||||
|
||||
/* Source the cursor from the already-fetched frame info (0 syscalls for position) and publish
|
||||
* it under the cursor_seq gate. Position/visibility come from fi.PointerPosition; the shape is
|
||||
* re-extracted only when fi.LastMouseUpdateTime changed (shape-gate). Cold start: fi is invalid
|
||||
* until the mouse first moves (LastMouseUpdateTime==0) — seed the position once via one
|
||||
* GetCursorInfo, then rely on fi. ctx->cursor compose fields are written under ctx->lock; the
|
||||
* producer-block publish uses release/seq, no lock. */
|
||||
static void dda_source_cursor(vgpu_ctx* ctx, dda_state* st,
|
||||
const DXGI_OUTDUPL_FRAME_INFO* fi) {
|
||||
int vis = fi->PointerPosition.Visible ? 1 : 0;
|
||||
int x, y;
|
||||
UINT64 upd = (UINT64)fi->LastMouseUpdateTime.QuadPart;
|
||||
|
||||
if (!st->seeded && upd == 0) {
|
||||
CURSORINFO ci; ci.cbSize = sizeof ci;
|
||||
if (GetCursorInfo(&ci)) {
|
||||
vis = (ci.flags & CURSOR_SHOWING) != 0;
|
||||
x = ci.ptScreenPos.x; y = ci.ptScreenPos.y;
|
||||
} else {
|
||||
x = ctx->cursor.x; y = ctx->cursor.y;
|
||||
}
|
||||
st->seeded = 1;
|
||||
} else {
|
||||
x = fi->PointerPosition.Position.x;
|
||||
y = fi->PointerPosition.Position.y;
|
||||
if (upd != 0) st->seeded = 1;
|
||||
}
|
||||
|
||||
/* shape-gate: re-extract only when the mouse-update stamp advanced */
|
||||
if (upd != 0 && upd != st->last_mouse_update) {
|
||||
CURSORINFO ci; ci.cbSize = sizeof ci;
|
||||
if (GetCursorInfo(&ci) && ci.hCursor && ci.hCursor != ctx->cursor.handle) {
|
||||
EnterCriticalSection(&ctx->lock);
|
||||
cursor_apply_shape(ctx, ci.hCursor);
|
||||
LeaveCriticalSection(&ctx->lock);
|
||||
}
|
||||
st->last_mouse_update = upd;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&ctx->lock);
|
||||
ctx->cursor.visible = vis;
|
||||
ctx->cursor.x = x; ctx->cursor.y = y;
|
||||
uint32_t hx = (uint32_t)ctx->cursor.hot_x, hy = (uint32_t)ctx->cursor.hot_y;
|
||||
uint32_t gw = (uint32_t)ctx->cursor.gw, gh = (uint32_t)ctx->cursor.gh;
|
||||
uint32_t cid = (uint32_t)ctx->cursor.cursor_id;
|
||||
LeaveCriticalSection(&ctx->lock);
|
||||
|
||||
vgpu_publish_cursor_shape(&ctx->view, hx, hy, gw, gh, cid);
|
||||
vgpu_publish_cursor(&ctx->view, (int32_t)x, (int32_t)y, (uint32_t)vis);
|
||||
}
|
||||
|
||||
static DWORD WINAPI dda_thread(LPVOID param) {
|
||||
capture_thread_arg* arg = (capture_thread_arg*)param;
|
||||
vgpu_ctx* ctx = arg->ctx;
|
||||
@@ -33,12 +89,18 @@ static DWORD WINAPI dda_thread(LPVOID param) {
|
||||
if (hr == DXGI_ERROR_ACCESS_LOST) {
|
||||
if (st->dup) { st->dup->lpVtbl->Release(st->dup); st->dup = NULL; }
|
||||
if (FAILED(st->out1->lpVtbl->DuplicateOutput(st->out1,
|
||||
(IUnknown*)st->dev, &st->dup)))
|
||||
(IUnknown*)st->dev, &st->dup))) {
|
||||
Sleep(200);
|
||||
} else {
|
||||
/* display config may have changed across the access loss → resample geometry */
|
||||
geometry_sample_and_publish(ctx, st->cap_x, st->cap_y);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (FAILED(hr)) { Sleep(50); continue; }
|
||||
|
||||
dda_source_cursor(ctx, st, &fi);
|
||||
|
||||
ID3D11Texture2D* tex = NULL;
|
||||
res->lpVtbl->QueryInterface(res, &IID_ID3D11Texture2D, (void**)&tex);
|
||||
if (tex) {
|
||||
@@ -76,7 +138,14 @@ int dda_start(vgpu_ctx* ctx, int fps) {
|
||||
st->dev->lpVtbl->QueryInterface(st->dev, &IID_IDXGIDevice, (void**)&dxgiDev);
|
||||
if (dxgiDev) dxgiDev->lpVtbl->GetAdapter(dxgiDev, &adapter);
|
||||
if (adapter) adapter->lpVtbl->EnumOutputs(adapter, 0, &output);
|
||||
if (output) output->lpVtbl->QueryInterface(output, &IID_IDXGIOutput1, (void**)&st->out1);
|
||||
if (output) {
|
||||
DXGI_OUTPUT_DESC od;
|
||||
if (SUCCEEDED(output->lpVtbl->GetDesc(output, &od))) {
|
||||
st->cap_x = (int32_t)od.DesktopCoordinates.left;
|
||||
st->cap_y = (int32_t)od.DesktopCoordinates.top;
|
||||
}
|
||||
output->lpVtbl->QueryInterface(output, &IID_IDXGIOutput1, (void**)&st->out1);
|
||||
}
|
||||
|
||||
if (output) output->lpVtbl->Release(output);
|
||||
if (adapter) adapter->lpVtbl->Release(adapter);
|
||||
|
||||
Reference in New Issue
Block a user