forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mixxxdj#1809 from rryan/qt5-knob-sluggishness
Render WKnob, WKnobComposed and WSliderComposed using the GuiTick timer. Bug #1793015
- Loading branch information
Showing
15 changed files
with
164 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "util/widgetrendertimer.h" | ||
|
||
#include "util/time.h" | ||
|
||
WidgetRenderTimer::WidgetRenderTimer(mixxx::Duration renderFrequency, | ||
mixxx::Duration inactivityTimeout) | ||
: m_renderFrequency(renderFrequency), | ||
m_inactivityTimeout(inactivityTimeout), | ||
m_guiTickTimer(this) { | ||
connect(&m_guiTickTimer, SIGNAL(timeout()), | ||
this, SLOT(guiTick())); | ||
} | ||
|
||
void WidgetRenderTimer::guiTick() { | ||
mixxx::Duration now = mixxx::Time::elapsed(); | ||
if (now - m_lastActivity > m_inactivityTimeout) { | ||
m_guiTickTimer.stop(); | ||
} | ||
if (m_lastActivity > m_lastRender) { | ||
m_lastRender = m_lastActivity; | ||
emit(update()); | ||
} | ||
} | ||
|
||
void WidgetRenderTimer::activity() { | ||
m_lastActivity = mixxx::Time::elapsed(); | ||
if (!m_guiTickTimer.isActive()) { | ||
m_guiTickTimer.start(m_renderFrequency); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
|
||
#include "util/duration.h" | ||
#include "util/timer.h" | ||
|
||
// A helper class for rendering widgets on a timer when they need updating. | ||
// Prevents calling QWidget::update too quickly. Controlled by two parameters: | ||
// - renderFrequency: The frequency to render the widget at in response | ||
// to updates. | ||
// - inactivityTimeout: The timeout after which the widget's render timer is | ||
// deactivated. | ||
// | ||
// This class was created in response to Launchpad Bug #1793015. With Qt 4, we | ||
// would simply call QWidget::update in response to input events that required | ||
// re-rendering widgets, relying on Qt to batch them together and deliver them | ||
// at a reasonable frequency. On macOS, the behavior of QWidget::update in Qt 5 | ||
// seems to have changed such that render events happen much more frequently | ||
// than they used to. To address this, we instead use a downsampling timer | ||
// attached to the VSyncThread's render ticks for the waveform renderers. The | ||
// timer invokes guiTick(), which is responsible for actually calling | ||
// QWidget::update(). When input arrives, we call inputActivity to attach the | ||
// timer. After 1 second of inactivity, we disconnect the timer. | ||
class WidgetRenderTimer : public QObject { | ||
Q_OBJECT | ||
public: | ||
WidgetRenderTimer(mixxx::Duration renderFrequency, | ||
mixxx::Duration inactivityTimeout); | ||
|
||
// Call this method whenever the widget's state has changed such that a | ||
// re-render is necessary. | ||
void activity(); | ||
|
||
signals: | ||
// Emitted when the widget should actually render. Connect this signal to | ||
// QWidget::update or QWidget::repaint. | ||
void update(); | ||
|
||
private slots: | ||
// Called when the internal GuiTickTimer's timeout is elapsed. Decides | ||
// whether the widget should render in response to this timer tick. | ||
void guiTick(); | ||
|
||
private: | ||
const mixxx::Duration m_renderFrequency; | ||
const mixxx::Duration m_inactivityTimeout; | ||
GuiTickTimer m_guiTickTimer; | ||
mixxx::Duration m_lastActivity; | ||
mixxx::Duration m_lastRender; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.