Преглед изворни кода

Docked windows keep their size in pixels while they move (issue #178)

At an interface size like 150 % the native child window's width came from its rounded edges, so it changed by a
pixel with the position and every step of a drag resized the window. Windows then showed the new, undrawn Direct2D
buffers for a moment: the rapid flicker (white here, other programs' old pictures on the reporter's GPU) of the
Playlist, the Channel rack and docked plugin windows. Position and size are now rounded each on its own, as JUCE does
for its own windows (dockstack::physicalPlace, used by every placement and check of a docked window).

Drag capture on Windows at 150 %: 14 blank frames in a 6 s drag of the Channel rack before, 0 after (two runs, and
0 for a docked channel window).
Ka1-S пре 2 недеља
родитељ
комит
6d0563ac0c
4 измењених фајлова са 48 додато и 3 уклоњено
  1. 15 0
      src/core/DockStack.h
  2. 8 3
      src/ui/NativeChild.cpp
  3. 24 0
      tests/U190hxTests.inc
  4. 1 0
      tests/tests.cpp

+ 15 - 0
src/core/DockStack.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include <cmath>
 #include <cstddef>
 #include <vector>
 
@@ -76,4 +77,18 @@ constexpr bool panelFades (bool animationsOn, bool panelIsChildWindow, bool wind
 {
     return animationsOn && ! (panelIsChildWindow && windowsAlphaFlashes);
 }
+// Issue #178 (round 190hx): a docked window's place in its parent's physical pixels. The position and the size are
+// rounded each on its own (as JUCE does for its own windows), so a window that only moves keeps its size in pixels at
+// any scale. Rounding the edges instead gave a size that depends on the position at 125 % / 150 % (a 101-unit-wide
+// window was 152 px at x = 0, 151 px at x = 1): every step of a drag resized the native window, and Windows showed the
+// new, still undrawn Direct2D buffers for a moment (a rapid flicker of other programs' old pictures).
+struct PhysicalRect
+{
+    int x = 0, y = 0, w = 0, h = 0;
+};
+inline PhysicalRect physicalPlace (int x, int y, int w, int h, double scale) noexcept
+{
+    const auto r = [] (double v) { return (int) std::lround (v); };
+    return { r (x * scale), r (y * scale), r (w * scale), r (h * scale) };
+}
 } // namespace lynx::dockstack

+ 8 - 3
src/ui/NativeChild.cpp

@@ -49,13 +49,18 @@ struct PeerScaleListeners : juce::ComponentPeer
 };
 
 // `bounds` (the component's bounds: in the main window's client area, LYNX's zoomed units) in the parent's physical
-// pixels (times the UI zoom = the peer's logical pixels, times the display's scale = physical)
+// pixels (times the UI zoom = the peer's logical pixels, times the display's scale = physical).
+// Issue #178 (round 190hx): the position and the size are rounded each on its own, as JUCE does for its own windows
+// (Rectangle::toNearestInt). Rounding the right and bottom EDGES made the size depend on the position at a scale that is
+// not a whole number (150 %: a 101-unit-wide window was 152 pixels at x = 0 and 151 at x = 1), so every step of a drag
+// also resized the native window: Windows then showed its Direct2D swap chain's new, undrawn buffers (other programs'
+// old pictures, white stripes) until the next frame, a rapid flicker while a panel or a docked window moved.
 #if JUCE_WINDOWS
 RECT physicalRect (const juce::Component& c, const juce::ComponentPeer& peer, juce::Rectangle<int> bounds)
 {
     const auto scale = peer.getPlatformScaleFactor() * (double) c.getDesktopScaleFactor();
-    const auto b = bounds.toDouble() * scale;
-    return { juce::roundToInt (b.getX()), juce::roundToInt (b.getY()), juce::roundToInt (b.getRight()), juce::roundToInt (b.getBottom()) };
+    const auto r = dockstack::physicalPlace (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), scale);
+    return { r.x, r.y, r.x + r.w, r.y + r.h };
 }
 
 // LYNX's own exact placement is under way (placePhysically): the window procedure leaves its position alone

+ 24 - 0
tests/U190hxTests.inc

@@ -0,0 +1,24 @@
+// Round 190hx (issue #178, "LYNX's own windows flicker while dragged"): a docked window keeps its size in pixels while it
+// moves, at every interface size (core/DockStack.h physicalPlace).
+#include "core/DockStack.h"
+
+TEST (u190hx_a_docked_window_that_only_moves_keeps_its_size_in_pixels)
+{
+    using lynx::dockstack::physicalPlace;
+    for (const auto scale : { 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 0.8, 0.9, 1.875 }) // (LYNX's sizes x display scales)
+        for (const auto width : { 97, 100, 101, 333, 640 })
+        {
+            const auto first = physicalPlace (0, 0, width, 211, scale);
+            for (int x = -40; x <= 400; ++x)
+            {
+                const auto r = physicalPlace (x, x / 3, width, 211, scale);
+                CHECK (r.w == first.w && r.h == first.h);
+                CHECK (std::abs (r.x - x * scale) <= 0.5 + 1e-9 && std::abs (r.y - (x / 3) * scale) <= 0.5 + 1e-9);
+            }
+        }
+    // the reporter's case: 150 % interface, a 101-unit window at x = 0 and x = 1 (edge rounding gave 152 then 151 px)
+    CHECK (physicalPlace (0, 0, 101, 50, 1.5).w == physicalPlace (1, 0, 101, 50, 1.5).w);
+    // at 100 % nothing changes: the exact pixels
+    const auto exact = physicalPlace (13, 27, 400, 300, 1.0);
+    CHECK (exact.x == 13 && exact.y == 27 && exact.w == 400 && exact.h == 300);
+}

+ 1 - 0
tests/tests.cpp

@@ -17769,6 +17769,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Iss152Tests.inc"
 #include "Win190evTests.inc"
 #include "U190heTests.inc"
+#include "U190hxTests.inc"
 #include "Mod190doTests.inc"
 #include "Parity190fyTests.inc"
 #include "Sampler190dhTests.inc"