mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[Screen Ruler] Remove latch sync, since we don't capture the overlay window anymore (#20218)
This commit is contained in:
@@ -178,7 +178,6 @@ template<typename ToolT, typename TickFuncT>
|
||||
inline std::unique_ptr<OverlayUIState> OverlayUIState::CreateInternal(ToolT& toolState,
|
||||
TickFuncT tickFunc,
|
||||
CommonState& commonState,
|
||||
Latch& creationLatch,
|
||||
const wchar_t* toolWindowClassName,
|
||||
void* windowParam,
|
||||
const MonitorInfo& monitor,
|
||||
@@ -196,9 +195,6 @@ inline std::unique_ptr<OverlayUIState> OverlayUIState::CreateInternal(ToolT& too
|
||||
auto* state = uiState.get();
|
||||
uiCreatedEvent.SetEvent();
|
||||
|
||||
// Wait until all OverlayUI threads created their corresponding d2d devices
|
||||
creationLatch.arrive_and_wait();
|
||||
|
||||
state->RunUILoop();
|
||||
|
||||
commonState.closeOnOtherMonitors = true;
|
||||
@@ -211,14 +207,12 @@ inline std::unique_ptr<OverlayUIState> OverlayUIState::CreateInternal(ToolT& too
|
||||
}
|
||||
|
||||
std::unique_ptr<OverlayUIState> OverlayUIState::Create(Serialized<MeasureToolState>& toolState,
|
||||
Latch& creationLatch,
|
||||
CommonState& commonState,
|
||||
const MonitorInfo& monitor)
|
||||
{
|
||||
return OverlayUIState::CreateInternal(toolState,
|
||||
DrawMeasureToolTick,
|
||||
commonState,
|
||||
creationLatch,
|
||||
NonLocalizable::MeasureToolOverlayWindowName,
|
||||
&toolState,
|
||||
monitor,
|
||||
@@ -226,14 +220,12 @@ std::unique_ptr<OverlayUIState> OverlayUIState::Create(Serialized<MeasureToolSta
|
||||
}
|
||||
|
||||
std::unique_ptr<OverlayUIState> OverlayUIState::Create(BoundsToolState& toolState,
|
||||
Latch& creationLatch,
|
||||
CommonState& commonState,
|
||||
const MonitorInfo& monitor)
|
||||
{
|
||||
return OverlayUIState::CreateInternal(toolState,
|
||||
DrawBoundsToolTick,
|
||||
commonState,
|
||||
creationLatch,
|
||||
NonLocalizable::BoundsToolOverlayWindowName,
|
||||
&toolState,
|
||||
monitor,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "D2DState.h"
|
||||
#include "latch.h"
|
||||
#include "ToolState.h"
|
||||
|
||||
#include <common/display/monitors.h>
|
||||
@@ -28,7 +27,6 @@ class OverlayUIState final
|
||||
static std::unique_ptr<OverlayUIState> CreateInternal(ToolT& toolState,
|
||||
TickFuncT tickFunc,
|
||||
CommonState& commonState,
|
||||
Latch& creationLatch,
|
||||
const wchar_t* toolWindowClassName,
|
||||
void* windowParam,
|
||||
const MonitorInfo& monitor,
|
||||
@@ -39,11 +37,9 @@ public:
|
||||
~OverlayUIState();
|
||||
|
||||
static std::unique_ptr<OverlayUIState> Create(BoundsToolState& toolState,
|
||||
Latch& creationLatch,
|
||||
CommonState& commonState,
|
||||
const MonitorInfo& monitor);
|
||||
static std::unique_ptr<OverlayUIState> Create(Serialized<MeasureToolState>& toolState,
|
||||
Latch& creationLatch,
|
||||
CommonState& commonState,
|
||||
const MonitorInfo& monitor);
|
||||
inline HWND overlayWindowHandle() const
|
||||
|
||||
@@ -79,15 +79,12 @@ namespace winrt::PowerToys::MeasureToolCore::implementation
|
||||
|
||||
#if defined(DEBUG_PRIMARY_MONITOR_ONLY)
|
||||
const auto& monitorInfo = MonitorInfo::GetPrimaryMonitor();
|
||||
Latch createOverlayUILatch{ 1 };
|
||||
#else
|
||||
const auto monitors = MonitorInfo::GetMonitors(true);
|
||||
Latch createOverlayUILatch{ static_cast<ptrdiff_t>(monitors.size()) };
|
||||
for (const auto& monitorInfo : monitors)
|
||||
#endif
|
||||
{
|
||||
auto overlayUI = OverlayUIState::Create(_boundsToolState,
|
||||
createOverlayUILatch,
|
||||
_commonState,
|
||||
monitorInfo);
|
||||
#if !defined(DEBUG_PRIMARY_MONITOR_ONLY)
|
||||
@@ -118,15 +115,12 @@ namespace winrt::PowerToys::MeasureToolCore::implementation
|
||||
#if defined(DEBUG_PRIMARY_MONITOR_ONLY)
|
||||
std::vector<MonitorInfo> monitors = { MonitorInfo::GetPrimaryMonitor() };
|
||||
const auto& monitorInfo = monitors[0];
|
||||
Latch createOverlayUILatch{ 1 };
|
||||
#else
|
||||
const auto monitors = MonitorInfo::GetMonitors(true);
|
||||
Latch createOverlayUILatch{ static_cast<ptrdiff_t>(monitors.size()) };
|
||||
for (const auto& monitorInfo : monitors)
|
||||
#endif
|
||||
{
|
||||
auto overlayUI = OverlayUIState::Create(_measureToolState,
|
||||
createOverlayUILatch,
|
||||
_commonState,
|
||||
monitorInfo);
|
||||
#if !defined(DEBUG_PRIMARY_MONITOR_ONLY)
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
<ClInclude Include="BGRATextureView.h" />
|
||||
<ClInclude Include="EdgeDetection.h" />
|
||||
<ClInclude Include="ToolState.h" />
|
||||
<ClInclude Include="latch.h" />
|
||||
<ClInclude Include="OverlayUI.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="ScreenCapturing.h" />
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<latch>)
|
||||
#include <latch>
|
||||
using Latch = std::latch;
|
||||
#else
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <limits.h>
|
||||
|
||||
class Latch
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] static constexpr ptrdiff_t(max)() noexcept
|
||||
{
|
||||
return (1ULL << (sizeof(ptrdiff_t) * CHAR_BIT - 1)) - 1;
|
||||
}
|
||||
|
||||
constexpr explicit Latch(const std::ptrdiff_t _Expected) noexcept :
|
||||
_Counter{ _Expected }
|
||||
{
|
||||
}
|
||||
|
||||
Latch(const Latch&) = delete;
|
||||
Latch& operator=(const Latch&) = delete;
|
||||
|
||||
void count_down(const ptrdiff_t _Update = 1) noexcept
|
||||
{
|
||||
const ptrdiff_t _Current = _Counter.fetch_sub(_Update) - _Update;
|
||||
if (_Current == 0)
|
||||
{
|
||||
_Counter.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool try_wait() const noexcept
|
||||
{
|
||||
return _Counter.load() == 0;
|
||||
}
|
||||
|
||||
void wait() const noexcept
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
const ptrdiff_t _Current = _Counter.load();
|
||||
if (_Current == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
_Counter.wait(_Current, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
void arrive_and_wait(const ptrdiff_t _Update = 1) noexcept
|
||||
{
|
||||
const ptrdiff_t _Current = _Counter.fetch_sub(_Update) - _Update;
|
||||
if (_Current == 0)
|
||||
{
|
||||
_Counter.notify_all();
|
||||
}
|
||||
else
|
||||
{
|
||||
_Counter.wait(_Current, std::memory_order_relaxed);
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<std::ptrdiff_t> _Counter;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user