Browse Source

Windows: Use timer to update VBlank registration for embedded HWNDComponentPeer

v7.0.9
attila 2 years ago
parent
commit
a93d0a7ed0
1 changed files with 42 additions and 9 deletions
  1. +42
    -9
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp

+ 42
- 9
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -1641,6 +1641,31 @@ private:
JUCE_IMPLEMENT_SINGLETON (VBlankDispatcher)
//==============================================================================
class SimpleTimer : private Timer
{
public:
SimpleTimer (int intervalMs, std::function<void()> callbackIn)
: callback (std::move (callbackIn))
{
jassert (callback);
startTimer (intervalMs);
}
~SimpleTimer() override
{
stopTimer();
}
private:
void timerCallback() override
{
callback();
}
std::function<void()> callback;
};
//==============================================================================
class HWNDComponentPeer : public ComponentPeer,
private VBlankListener,
@@ -1682,8 +1707,10 @@ public:
return ModifierKeys::currentModifiers;
};
if (updateCurrentMonitor())
VBlankDispatcher::getInstance()->updateDisplay (*this, currentMonitor);
updateCurrentMonitorAndRefreshVBlankDispatcher();
if (parentToAddTo != nullptr)
monitorUpdateTimer.emplace (1000, [this] { updateCurrentMonitorAndRefreshVBlankDispatcher(); });
suspendResumeRegistration = ScopedSuspendResumeNotificationRegistration { hwnd };
}
@@ -3675,10 +3702,18 @@ private:
return 0;
}
bool updateCurrentMonitor()
enum class ForceRefreshDispatcher
{
no,
yes
};
void updateCurrentMonitorAndRefreshVBlankDispatcher (ForceRefreshDispatcher force = ForceRefreshDispatcher::no)
{
auto monitor = MonitorFromWindow (hwnd, MONITOR_DEFAULTTONULL);
return std::exchange (currentMonitor, monitor) != monitor;
if (std::exchange (currentMonitor, monitor) != monitor || force == ForceRefreshDispatcher::yes)
VBlankDispatcher::getInstance()->updateDisplay (*this, currentMonitor);
}
bool handlePositionChanged()
@@ -3697,9 +3732,7 @@ private:
}
handleMovedOrResized();
if (updateCurrentMonitor())
VBlankDispatcher::getInstance()->updateDisplay (*this, currentMonitor);
updateCurrentMonitorAndRefreshVBlankDispatcher();
return ! dontRepaint; // to allow non-accelerated openGL windows to draw themselves correctly.
}
@@ -3857,8 +3890,7 @@ private:
auto* dispatcher = VBlankDispatcher::getInstance();
dispatcher->reconfigureDisplays();
updateCurrentMonitor();
dispatcher->updateDisplay (*this, currentMonitor);
updateCurrentMonitorAndRefreshVBlankDispatcher (ForceRefreshDispatcher::yes);
}
//==============================================================================
@@ -4625,6 +4657,7 @@ private:
RectangleList<int> deferredRepaints;
ScopedSuspendResumeNotificationRegistration suspendResumeRegistration;
std::optional<SimpleTimer> monitorUpdateTimer;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HWNDComponentPeer)


Loading…
Cancel
Save