[Screen Ruler] Remove latch sync, since we don't capture the overlay window anymore (#20218)

This commit is contained in:
Andrey Nekrasov
2022-09-01 16:56:27 +03:00
committed by GitHub
parent c8b7995d8c
commit 006165574e
5 changed files with 0 additions and 92 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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)

View File

@@ -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" />

View File

@@ -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