From f0488bb2e192d5cfc3acc5d04f6120c2105b70bc Mon Sep 17 00:00:00 2001 From: Max <112043822+Maxaubert@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:50:01 +0100 Subject: [PATCH 1/2] feat(transform): capture blink for Glint, one unzoomed frame for screen capture (#565) While the transform is applied every capture API returns the zoomed picture, so a snipping tool froze the magnified view. Wind.CaptureBlink.v1 writes identity and pauses writes until the tool ends the blink (or 400 ms), then restores the last transform. glint.exe joins kOverlayExes. Version 0.30.0. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kg7JN7LbXNRgNRb4hZBEt6 --- docs/architecture/03-engines.md | 2 +- docs/architecture/05-transform-engine.md | 20 ++++++++++++++ src/core/main.cpp | 35 ++++++++++++++++++++++-- src/transform/transform_model.cpp | 8 ++++++ src/transform/transform_model.h | 5 ++++ src/version.h | 6 ++-- 6 files changed, 70 insertions(+), 6 deletions(-) diff --git a/docs/architecture/03-engines.md b/docs/architecture/03-engines.md index 8f1a5717..d0454d9f 100644 --- a/docs/architecture/03-engines.md +++ b/docs/architecture/03-engines.md @@ -121,7 +121,7 @@ a game at 8x swaps engines with level and lens kept. Three dampers: and `borderless` stay per tick. - **350 ms settle** (`t.wantModel`/`t.wantSinceMs`): the candidate must hold for 350 ms. Each flip rebuilds DWM's magnification context, a visible stall. -- **Overlay freeze** (`IsOverlayFg`): while Snipping Tool, ScreenSketch or TextInputHost +- **Overlay freeze** (`IsOverlayFg`): while Snipping Tool, ScreenSketch, TextInputHost, Glint (`kOverlayExes`) or the game-inspect focus stealer holds foreground, the pick is skipped, so handing foreground back is not a second handover. Inspect sessions are never switched. diff --git a/docs/architecture/05-transform-engine.md b/docs/architecture/05-transform-engine.md index 4964e87b..d235796b 100644 --- a/docs/architecture/05-transform-engine.md +++ b/docs/architecture/05-transform-engine.md @@ -343,6 +343,26 @@ layered, click-through, tool, non-activating or no-redirection-bitmap windows. W Snipping Tool overlay froze the view for 1.5 s on every snip. `WS_EX_TOPMOST` is not in the veto set, because games set it. `launchQuiesce=0` disables the hold; it is a test knob only. +## Capture blink + +While the transform is applied, every screen-capture API returns the magnified picture (GDI +`BitBlt` and DXGI Desktop Duplication, measured 2026-11-12 with Glint's `zoomprobe`). A snipping +tool that freezes the screen therefore froze the zoomed view, and zooming out inside its overlay +showed nothing more (issue #565). + +Glint asks for a blink with the registered message `Wind.CaptureBlink.v1`, sent to the +`WindMagnifierWnd` window (allowed through UIPI with `ChangeWindowMessageFilterEx`): + +| wParam | Wind does | Reply | +|---|---|---| +| 1 | `TransformModel::captureBlink(true)` writes identity on the session's channel, two `DwmFlush` calls wait until that frame is composited, and `captureBlinkUntilMs` pauses the tick's writes (`PresentExtras::pauseWrites`) | 1 when the desktop is now unzoomed, 0 when the transform engine is not zoomed | +| 0 | `captureBlink(false)` writes the last applied transform back and clears the pause | 1 | + +The restore is an explicit write because an unpaused tick only writes on change. If the tool never +sends wParam 0, the tick restores the view after 400 ms. Only the transform engine needs this: the +render overlay is capture-excluded. `glint.exe` is also in `kOverlayExes`, so its overlay freezes +the engine pick like the Snipping Tool's ([03](03-engines.md)). + ## Hook writes (removed) A removed experiment moved runtime ownership to the mouse-hook thread and diff --git a/src/core/main.cpp b/src/core/main.cpp index 3ebd4a19..71bfc6e6 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -378,6 +378,7 @@ struct TickState { DWORD quiescedPid = 0; // fires at most once per process instance HWND lastCoverFg = nullptr; // edge-detect cover-takeover foregrounds unsigned long long lastCoverProbeMs = 0; // throttles the idle-tick cover watch to ~4Hz + unsigned long long captureBlinkUntilMs = 0; // capture blink (#565) in progress: writes paused until then IMagnifierModel* wantModel = nullptr; // hybrid stickiness: candidate engine and how long it unsigned long long wantSinceMs = 0; // has been the candidate (debounces foreground reads) unsigned long long kbHookDivergentSinceMs = 0; // LL keyboard-hook watchdog dwell (issue #156) @@ -523,7 +524,7 @@ static bool IsTransformExcluded(HWND fg, const Config& cfg) { // user can sensibly pick out of a file browser, and a second user-managed list is not worth the // settings surface. Only consulted for windows that already failed the free style test below. static const char* kOverlayExes = - "SnippingTool.exe,ScreenSketch.exe,ScreenClippingHost.exe,TextInputHost.exe"; + "SnippingTool.exe,ScreenSketch.exe,ScreenClippingHost.exe,TextInputHost.exe,glint.exe"; // Is the foreground an overlay rather than a real app? While one is up the Auto engine choice is // FROZEN: such a tool holds foreground for a couple of seconds and hands it straight back, so @@ -2502,7 +2503,13 @@ static PresentExtras BuildPresentExtras(TickState& t, double lvl, double dt, boo // Deadline-based, so a short press can never strand leftover hold into the next session // (the old tick countdown only decremented while zoomed, which did exactly that). const bool quiesceHold = QuiesceHoldActive(t); - ex.pauseWrites = t.clickPauseTicks > 0 || quiesceHold; + // Capture blink (#565): a tool that never sends the end message must not strand the view at 1x. + if (t.captureBlinkUntilMs && GetTickCount64() >= t.captureBlinkUntilMs) { + t.captureBlinkUntilMs = 0; + if (auto* tm = dynamic_cast(t.model)) tm->captureBlink(false); + wind::Log(wind::LogLevel::Info, "blink", "capture blink timed out; transform restored"); + } + ex.pauseWrites = t.clickPauseTicks > 0 || quiesceHold || t.captureBlinkUntilMs != 0; { auto& zs = g_input.state(); ex.zoomDriven = zs.inHeld.load() || zs.outHeld.load() || g_input.anyBoundKeyPressed() || @@ -3096,6 +3103,28 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { if (g_tick) g_tick->cursorHidden = !g_tick->cursorHidden; return 0; } + // Capture blink (#565). Glint (snipping tool) sends wParam 1 before it copies the screen and + // wParam 0 after. Every capture API sees the zoomed picture while the transform is applied, so + // start writes identity, waits until that frame is composited and pauses the tick's writes; end + // puts the last transform back. Reply 1 = the desktop is unzoomed now. Runs on the tick thread + // (this window's thread), as the thread-affine Magnification API requires. + static const UINT kCaptureBlinkMsg = RegisterWindowMessageW(L"Wind.CaptureBlink.v1"); + if (kCaptureBlinkMsg && msg == kCaptureBlinkMsg) { + auto* tm = g_tick ? dynamic_cast(g_tick->model) : nullptr; + if (!tm) return 0; + if (wp == 1) { + if (!tm->captureBlink(true)) return 0; + g_tick->captureBlinkUntilMs = GetTickCount64() + 400; + DwmFlush(); // the identity write lands on the next composition; two flushes make + DwmFlush(); // sure that frame is on screen before the tool copies it + return 1; + } + if (g_tick->captureBlinkUntilMs) { + g_tick->captureBlinkUntilMs = 0; + tm->captureBlink(false); + } + return 1; + } if (msg == WM_HOTKEY && wp == kQuickZoomHotkeyId) { if (g_tick) g_tick->quickZoomHotkey.store(true); // RunTick consumes it (rising-edge via MOD_NOREPEAT) return 0; @@ -3394,6 +3423,8 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, PWSTR, int) { HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"Wind", WS_OVERLAPPED, 0, 0, 0, 0, nullptr, nullptr, hInst, nullptr); if (!hwnd) return 1; + // Glint's capture blink (#565) comes from an ordinary process; let it through UIPI. + ChangeWindowMessageFilterEx(hwnd, RegisterWindowMessageW(L"Wind.CaptureBlink.v1"), MSGFLT_ALLOW, nullptr); // Mouse AND keyboard (issue #167). The keyboard registration exists for exactly one reason: an // LL hook can be silently evicted mid-hold, and the key UP then reaches nobody, stranding a diff --git a/src/transform/transform_model.cpp b/src/transform/transform_model.cpp index 94931efe..c4810a5f 100644 --- a/src/transform/transform_model.cpp +++ b/src/transform/transform_model.cpp @@ -262,6 +262,14 @@ void TransformModel::noteWrite(double ms, bool ok) { // 0.02ms avg / 0.5ms max, so it never stalls the tick. The hitch is DWM's ASYNCHRONOUS // re-scale work, addressed by txMaxStepPct. Writes stay on the tick thread; only the timing // instrumentation remains. +bool TransformModel::captureBlink(bool on) { + if (!active_ || lastLevel_ <= 1.0) return false; + // Same channel as the session's own writes, so the restore lands exactly where the view was. + if (on) writeTransform(1.0f, 0, 0, 0, 0, fastPan_); + else writeTransform((float)lastLevel_, lastOffX_, lastOffY_, lastTxX_, lastTxY_, fastPan_); + return true; +} + void TransformModel::writeTransform(float lvl, int offX, int offY, int tx, int ty, bool fast) { LARGE_INTEGER fr, a, b; QueryPerformanceFrequency(&fr); QueryPerformanceCounter(&a); diff --git a/src/transform/transform_model.h b/src/transform/transform_model.h index c05f207f..3066f580 100644 --- a/src/transform/transform_model.h +++ b/src/transform/transform_model.h @@ -27,6 +27,11 @@ class TransformModel : public IMagnifierModel { // This session draws DWM's pointer (false: the legacy sprite session). Before the session's // setActive(true) it answers for the session about to start. bool nativeSession() const { return active_ ? nativeSession_ : nativePref_; } + // Capture blink (issue #565): a screen-capture tool (Glint) needs one unmagnified desktop + // frame, because every capture API returns the zoomed picture while the transform is applied. + // on=true writes identity (only while zoomed; returns false otherwise), on=false writes the + // last applied transform back. The caller pauses the tick's own writes in between. + bool captureBlink(bool on); bool initialize(const MonitorTarget& monitor) override; // MONITOR GEOMETRY CAN CHANGE UNDER A LIVE SESSION (issue #230). mon_ feeds the clamp bounds in // ComputeMagTransform, the crosshair's placement offsets and the MagSetInputTransform rects, and diff --git a/src/version.h b/src/version.h index 42c78eda..1b961ab0 100644 --- a/src/version.h +++ b/src/version.h @@ -5,9 +5,9 @@ #pragma once #define WIND_VER_MAJOR 0 -#define WIND_VER_MINOR 29 -#define WIND_VER_PATCH 4 +#define WIND_VER_MINOR 30 +#define WIND_VER_PATCH 0 // String form for logs/snapshot/UI. Keep in sync with the numeric parts above (tests/test_version.cpp // fails when it is not). A literal, not stringized: wind.rc and wind_tray.rc consume it as one string. -#define WIND_VERSION_STR "0.29.4" +#define WIND_VERSION_STR "0.30.0" From bf297887e0d7146f166b6400f83c7849e622365d Mon Sep 17 00:00:00 2001 From: Max <112043822+Maxaubert@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:19:18 +0100 Subject: [PATCH 2/2] feat(transform): capture blink grabs the frame itself, blink is about one frame (#565) Wind now prepares a warm Desktop Duplication device, writes 1x, flushes one composition, grabs that frame and writes the zoom straight back, then copies the pixels into the section Glint created. Replaces the start/end protocol that held 1x for Glint's ~60 ms GDI capture. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kg7JN7LbXNRgNRb4hZBEt6 --- docs/architecture/05-transform-engine.md | 32 +++--- src/core/main.cpp | 46 ++++----- src/transform/blink_capture.cpp | 118 +++++++++++++++++++++++ src/transform/blink_capture.h | 47 +++++++++ src/transform/transform_model.h | 5 +- 5 files changed, 208 insertions(+), 40 deletions(-) create mode 100644 src/transform/blink_capture.cpp create mode 100644 src/transform/blink_capture.h diff --git a/docs/architecture/05-transform-engine.md b/docs/architecture/05-transform-engine.md index d235796b..ef7939a6 100644 --- a/docs/architecture/05-transform-engine.md +++ b/docs/architecture/05-transform-engine.md @@ -350,18 +350,26 @@ While the transform is applied, every screen-capture API returns the magnified p tool that freezes the screen therefore froze the zoomed view, and zooming out inside its overlay showed nothing more (issue #565). -Glint asks for a blink with the registered message `Wind.CaptureBlink.v1`, sent to the -`WindMagnifierWnd` window (allowed through UIPI with `ChangeWindowMessageFilterEx`): - -| wParam | Wind does | Reply | -|---|---|---| -| 1 | `TransformModel::captureBlink(true)` writes identity on the session's channel, two `DwmFlush` calls wait until that frame is composited, and `captureBlinkUntilMs` pauses the tick's writes (`PresentExtras::pauseWrites`) | 1 when the desktop is now unzoomed, 0 when the transform engine is not zoomed | -| 0 | `captureBlink(false)` writes the last applied transform back and clears the pause | 1 | - -The restore is an explicit write because an unpaused tick only writes on change. If the tool never -sends wParam 0, the tick restores the view after 400 ms. Only the transform engine needs this: the -render overlay is capture-excluded. `glint.exe` is also in `kOverlayExes`, so its overlay freezes -the engine pick like the Snipping Tool's ([03](03-engines.md)). +Glint creates a section `Local\Glint.CaptureFrame.` and sends the registered message +`Wind.CaptureBlink.v1` (wParam 2, lParam = its pid) to the `WindMagnifierWnd` window, which +`ChangeWindowMessageFilterEx` lets through UIPI. On the tick thread, WndProc: + +1. `BlinkCapture::prepare` (`src/transform/blink_capture.*`): a D3D11 device on the target + monitor's output, created on first use (~150 ms) and kept warm. Done before the blink, so it never + lengthens it. +2. `TransformModel::captureBlink(true)` writes identity on the session's channel; one `DwmFlush`. +3. `grab`: a fresh `DuplicateOutput1` (FP16 first), whose first frame is the 1x desktop, and a GPU + copy into a staging texture. +4. `captureBlink(false)` writes the last applied transform back. The visible blink is steps 2 to 4, + about one frame (an earlier version kept 1x while Glint copied the screen with GDI, ~60 ms, which + the owner found too visible). +5. `publish` maps the copy and writes a 32-byte `BlinkFrameHeader` (magic `GLBF`, version 1, size, + stride, format 1 = BGRA8 or 2 = RGBA16F scRGB, monitor origin) plus the rows into the section. + +Reply 1 means the frame is in the section; 0 means not zoomed or a step failed, and Glint captures +as usual. The restore is an explicit write because an unpaused tick only writes on change. Only the +transform engine needs this: the render overlay is capture-excluded. `glint.exe` is also in +`kOverlayExes`, so its overlay freezes the engine pick like the Snipping Tool's ([03](03-engines.md)). ## Hook writes (removed) diff --git a/src/core/main.cpp b/src/core/main.cpp index 71bfc6e6..c8dd5282 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -2,6 +2,7 @@ // Proprietary source-available software; see LICENSE. SPDX-License-Identifier: LicenseRef-Wind-Proprietary #include #include +#include "blink_capture.h" // Glint capture blink (#565) #include #include #include @@ -378,7 +379,6 @@ struct TickState { DWORD quiescedPid = 0; // fires at most once per process instance HWND lastCoverFg = nullptr; // edge-detect cover-takeover foregrounds unsigned long long lastCoverProbeMs = 0; // throttles the idle-tick cover watch to ~4Hz - unsigned long long captureBlinkUntilMs = 0; // capture blink (#565) in progress: writes paused until then IMagnifierModel* wantModel = nullptr; // hybrid stickiness: candidate engine and how long it unsigned long long wantSinceMs = 0; // has been the candidate (debounces foreground reads) unsigned long long kbHookDivergentSinceMs = 0; // LL keyboard-hook watchdog dwell (issue #156) @@ -2503,13 +2503,7 @@ static PresentExtras BuildPresentExtras(TickState& t, double lvl, double dt, boo // Deadline-based, so a short press can never strand leftover hold into the next session // (the old tick countdown only decremented while zoomed, which did exactly that). const bool quiesceHold = QuiesceHoldActive(t); - // Capture blink (#565): a tool that never sends the end message must not strand the view at 1x. - if (t.captureBlinkUntilMs && GetTickCount64() >= t.captureBlinkUntilMs) { - t.captureBlinkUntilMs = 0; - if (auto* tm = dynamic_cast(t.model)) tm->captureBlink(false); - wind::Log(wind::LogLevel::Info, "blink", "capture blink timed out; transform restored"); - } - ex.pauseWrites = t.clickPauseTicks > 0 || quiesceHold || t.captureBlinkUntilMs != 0; + ex.pauseWrites = t.clickPauseTicks > 0 || quiesceHold; { auto& zs = g_input.state(); ex.zoomDriven = zs.inHeld.load() || zs.outHeld.load() || g_input.anyBoundKeyPressed() || @@ -3103,27 +3097,27 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { if (g_tick) g_tick->cursorHidden = !g_tick->cursorHidden; return 0; } - // Capture blink (#565). Glint (snipping tool) sends wParam 1 before it copies the screen and - // wParam 0 after. Every capture API sees the zoomed picture while the transform is applied, so - // start writes identity, waits until that frame is composited and pauses the tick's writes; end - // puts the last transform back. Reply 1 = the desktop is unzoomed now. Runs on the tick thread - // (this window's thread), as the thread-affine Magnification API requires. + // Capture blink (#565). Every capture API sees the zoomed picture while the transform is + // applied, so Glint (snipping tool) asks Wind for the real desktop: wParam 2, lParam = Glint's + // pid, which names the section it created. Wind prepares the duplication first (slow once, then + // warm), writes identity, flushes one composition, grabs that frame, writes the zoom straight + // back (the visible blink is about one frame) and copies the pixels into the section. + // Reply 1 = the frame is in the section; 0 = not zoomed or it failed (Glint captures as usual). + // Runs on the tick thread (this window's thread), as the thread-affine Magnification API needs. static const UINT kCaptureBlinkMsg = RegisterWindowMessageW(L"Wind.CaptureBlink.v1"); if (kCaptureBlinkMsg && msg == kCaptureBlinkMsg) { + static wind::BlinkCapture s_blink; auto* tm = g_tick ? dynamic_cast(g_tick->model) : nullptr; - if (!tm) return 0; - if (wp == 1) { - if (!tm->captureBlink(true)) return 0; - g_tick->captureBlinkUntilMs = GetTickCount64() + 400; - DwmFlush(); // the identity write lands on the next composition; two flushes make - DwmFlush(); // sure that frame is on screen before the tool copies it - return 1; - } - if (g_tick->captureBlinkUntilMs) { - g_tick->captureBlinkUntilMs = 0; - tm->captureBlink(false); - } - return 1; + if (wp != 2 || !tm || !tm->blinkable()) return 0; + if (!s_blink.prepare(g_tick->mon)) return 0; + tm->captureBlink(true); + DwmFlush(); // the identity frame is composited and on screen + const bool grabbed = s_blink.grab(); + tm->captureBlink(false); // zoom back before the slow part (reading the copy) + const bool ok = grabbed && s_blink.publish(g_tick->mon, static_cast(lp)); + wind::Log(wind::LogLevel::Info, "blink", "capture blink for pid %lu: %s", + static_cast(lp), ok ? "ok" : "failed"); + return ok ? 1 : 0; } if (msg == WM_HOTKEY && wp == kQuickZoomHotkeyId) { if (g_tick) g_tick->quickZoomHotkey.store(true); // RunTick consumes it (rising-edge via MOD_NOREPEAT) diff --git a/src/transform/blink_capture.cpp b/src/transform/blink_capture.cpp new file mode 100644 index 00000000..7c19d31d --- /dev/null +++ b/src/transform/blink_capture.cpp @@ -0,0 +1,118 @@ +// Copyright (c) 2026 Max Aubert. All rights reserved. +// Proprietary source-available software; see LICENSE. SPDX-License-Identifier: LicenseRef-Wind-Proprietary +#include "blink_capture.h" +#include "logging.h" +#include +#include + +using Microsoft::WRL::ComPtr; + +namespace wind { + +bool BlinkCapture::prepare(const MonitorTarget& mon) { + if (device_ && output_ && wcscmp(device_name_, mon.device) == 0) return true; + device_.Reset(); ctx_.Reset(); output_.Reset(); staging_.Reset(); + ComPtr factory; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return false; + ComPtr adapter; + for (UINT ai = 0; factory->EnumAdapters1(ai, &adapter) != DXGI_ERROR_NOT_FOUND; ++ai) { + ComPtr out; + for (UINT oi = 0; adapter->EnumOutputs(oi, &out) != DXGI_ERROR_NOT_FOUND; ++oi) { + DXGI_OUTPUT_DESC d{}; + if (SUCCEEDED(out->GetDesc(&d)) && wcscmp(d.DeviceName, mon.device) == 0) { + ComPtr o5; + if (FAILED(out.As(&o5))) return false; + D3D_FEATURE_LEVEL want[] = { D3D_FEATURE_LEVEL_11_0 }; + D3D_FEATURE_LEVEL got{}; + HRESULT hr = D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, want, 1, D3D11_SDK_VERSION, + device_.ReleaseAndGetAddressOf(), &got, ctx_.ReleaseAndGetAddressOf()); + if (FAILED(hr)) { + Log(LogLevel::Warn, "blink", "D3D11CreateDevice failed hr=0x%08lX", (unsigned long)hr); + return false; + } + output_ = o5; + wcsncpy_s(device_name_, mon.device, _TRUNCATE); + return true; + } + out.Reset(); + } + adapter.Reset(); + } + Log(LogLevel::Warn, "blink", "no DXGI output for the target monitor"); + return false; +} + +bool BlinkCapture::grab() { + if (!output_) return false; + // A fresh duplication's first frame is the desktop as it is now: the 1x frame, since the caller + // flushed DWM after the identity write. FP16 first, so an HDR desktop keeps its range. + const DXGI_FORMAT fmts[] = { DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_B8G8R8A8_UNORM }; + ComPtr dupl; + HRESULT hr = output_->DuplicateOutput1(device_.Get(), 0, 2, fmts, &dupl); + if (FAILED(hr)) { + Log(LogLevel::Warn, "blink", "DuplicateOutput1 failed hr=0x%08lX", (unsigned long)hr); + return false; + } + DXGI_OUTDUPL_FRAME_INFO fi{}; + ComPtr res; + hr = dupl->AcquireNextFrame(100, &fi, &res); + if (FAILED(hr)) { + Log(LogLevel::Warn, "blink", "AcquireNextFrame failed hr=0x%08lX", (unsigned long)hr); + return false; + } + ComPtr tex; + bool ok = SUCCEEDED(res.As(&tex)); + if (ok) { + D3D11_TEXTURE2D_DESC d{}; + tex->GetDesc(&d); + if (!staging_ || d.Width != stagingDesc_.Width || d.Height != stagingDesc_.Height || + d.Format != stagingDesc_.Format) { + D3D11_TEXTURE2D_DESC s = d; + s.Usage = D3D11_USAGE_STAGING; + s.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + s.BindFlags = 0; + s.MiscFlags = 0; + s.MipLevels = 1; + s.ArraySize = 1; + ok = SUCCEEDED(device_->CreateTexture2D(&s, nullptr, staging_.ReleaseAndGetAddressOf())); + stagingDesc_ = s; + } + if (ok) ctx_->CopyResource(staging_.Get(), tex.Get()); + } + dupl->ReleaseFrame(); + return ok; +} + +bool BlinkCapture::publish(const MonitorTarget& mon, DWORD toolPid) { + if (!staging_) return false; + wchar_t name[64]; + swprintf_s(name, L"Local\\Glint.CaptureFrame.%lu", (unsigned long)toolPid); + HANDLE section = OpenFileMappingW(FILE_MAP_WRITE, FALSE, name); + if (!section) return false; + const bool fp16 = stagingDesc_.Format == DXGI_FORMAT_R16G16B16A16_FLOAT; + const unsigned bpp = fp16 ? 8u : 4u; + const unsigned w = stagingDesc_.Width, h = stagingDesc_.Height, row = w * bpp; + const size_t need = sizeof(BlinkFrameHeader) + size_t(row) * h; + bool ok = false; + if (void* view = MapViewOfFile(section, FILE_MAP_WRITE, 0, 0, 0)) { + MEMORY_BASIC_INFORMATION mbi{}; + VirtualQuery(view, &mbi, sizeof(mbi)); + D3D11_MAPPED_SUBRESOURCE m{}; + if (mbi.RegionSize >= need && SUCCEEDED(ctx_->Map(staging_.Get(), 0, D3D11_MAP_READ, 0, &m))) { + BlinkFrameHeader hdr{ 0x46424C47u, 1u, w, h, row, fp16 ? 2u : 1u, mon.x, mon.y }; + auto* dst = static_cast(view); + std::memcpy(dst, &hdr, sizeof(hdr)); + dst += sizeof(hdr); + const auto* src = static_cast(m.pData); + for (unsigned y = 0; y < h; ++y) std::memcpy(dst + size_t(y) * row, src + size_t(y) * m.RowPitch, row); + ctx_->Unmap(staging_.Get(), 0); + ok = true; + } + UnmapViewOfFile(view); + } + CloseHandle(section); + return ok; +} + +} // namespace wind diff --git a/src/transform/blink_capture.h b/src/transform/blink_capture.h new file mode 100644 index 00000000..e497a547 --- /dev/null +++ b/src/transform/blink_capture.h @@ -0,0 +1,47 @@ +// Copyright (c) 2026 Max Aubert. All rights reserved. +// Proprietary source-available software; see LICENSE. SPDX-License-Identifier: LicenseRef-Wind-Proprietary +#pragma once +#include +#include +#include +#include +#include "render_engine.h" // MonitorTarget + +namespace wind { + +// Capture blink for Glint (issue #565). While the transform zooms, every capture API returns the +// magnified picture, so a snipping tool cannot see the real desktop. Wind writes 1x for one +// composition, grabs that frame with Desktop Duplication, writes the zoom straight back and hands +// the pixels to the tool through a section the tool created. The visible blink is about one +// frame. Protocol and layout: docs/architecture/05-transform-engine.md, "Capture blink". +class BlinkCapture { +public: + // Device and output for the monitor. Slow the first time (~150 ms), then kept warm. Call it + // BEFORE the 1x write, so the device setup never lengthens the blink. + bool prepare(const MonitorTarget& mon); + // After the 1x write and a DwmFlush: duplicate, take the frame and queue a GPU copy. Fast. + bool grab(); + // After the zoom is back: read the copy and write it into the tool's section + // `Local\Glint.CaptureFrame.`. Returns false if the section is missing or too small. + bool publish(const MonitorTarget& mon, DWORD toolPid); + +private: + Microsoft::WRL::ComPtr device_; + Microsoft::WRL::ComPtr ctx_; + Microsoft::WRL::ComPtr output_; + Microsoft::WRL::ComPtr staging_; + D3D11_TEXTURE2D_DESC stagingDesc_{}; + wchar_t device_name_[32] = {}; +}; + +// Section header the tool reads (little-endian, 32 bytes, pixels follow). +struct BlinkFrameHeader { + unsigned magic; // 'GLBF' = 0x46424C47 + unsigned version; // 1 + unsigned width, height; + unsigned stride; // bytes per row in the section + unsigned format; // 1 = BGRA8, 2 = RGBA16F (scRGB, HDR desktop) + int x, y; // monitor origin, virtual-desktop pixels +}; + +} // namespace wind diff --git a/src/transform/transform_model.h b/src/transform/transform_model.h index 3066f580..f28fd65e 100644 --- a/src/transform/transform_model.h +++ b/src/transform/transform_model.h @@ -29,8 +29,9 @@ class TransformModel : public IMagnifierModel { bool nativeSession() const { return active_ ? nativeSession_ : nativePref_; } // Capture blink (issue #565): a screen-capture tool (Glint) needs one unmagnified desktop // frame, because every capture API returns the zoomed picture while the transform is applied. - // on=true writes identity (only while zoomed; returns false otherwise), on=false writes the - // last applied transform back. The caller pauses the tick's own writes in between. + // on=true writes identity, on=false writes the last applied transform back. blinkable() says + // whether there is a zoom to blink out of. + bool blinkable() const { return active_ && lastLevel_ > 1.0; } bool captureBlink(bool on); bool initialize(const MonitorTarget& monitor) override; // MONITOR GEOMETRY CAN CHANGE UNDER A LIVE SESSION (issue #230). mon_ feeds the clamp bounds in