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..ef7939a6 100644 --- a/docs/architecture/05-transform-engine.md +++ b/docs/architecture/05-transform-engine.md @@ -343,6 +343,34 @@ 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 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) 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..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 @@ -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 @@ -3096,6 +3097,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). 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 (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) return 0; @@ -3394,6 +3417,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/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.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..f28fd65e 100644 --- a/src/transform/transform_model.h +++ b/src/transform/transform_model.h @@ -27,6 +27,12 @@ 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, 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 // 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"