فهرست منبع

UI: Greatly improve main window repaint performance

The VolumeMeter widgets were apparently being drawn as transparent
widgets, which meant that it was necessary to redraw everything under
the widgets in order to properly draw the widgets, so the entire mixer
section of the window was being redrawn every time the meters updated.
This caused a significant perf hit when the only thing wanted/desired
was just to update the meters. This was more noticeable after changing
the audio meter update rate to 60hz from 30hz.

The fix is to simply mark them as opaque widgets, and paint the
background ourselves rather than rely on what's under the window. CPU
perf for painting the main window has been vastly improved because of
this; CPU usage of Qt in the main window is now reduced by at least half
of what it was, if not more.
jp9000 5 سال پیش
والد
کامیت
f4f2d383b1
1فایلهای تغییر یافته به همراه7 افزوده شده و 0 حذف شده
  1. 7 0
      UI/volume-control.cpp

+ 7 - 0
UI/volume-control.cpp

@@ -531,6 +531,8 @@ VolumeMeter::VolumeMeter(QWidget *parent, obs_volmeter_t *obs_volmeter,
 			 bool vertical)
 			 bool vertical)
 	: QWidget(parent), obs_volmeter(obs_volmeter), vertical(vertical)
 	: QWidget(parent), obs_volmeter(obs_volmeter), vertical(vertical)
 {
 {
+	setAttribute(Qt::WA_OpaquePaintEvent, true);
+
 	// Use a font that can be rendered small.
 	// Use a font that can be rendered small.
 	tickFont = QFont("Arial");
 	tickFont = QFont("Arial");
 	tickFont.setPixelSize(7);
 	tickFont.setPixelSize(7);
@@ -1041,6 +1043,11 @@ void VolumeMeter::paintEvent(QPaintEvent *event)
 
 
 	// Actual painting of the widget starts here.
 	// Actual painting of the widget starts here.
 	QPainter painter(this);
 	QPainter painter(this);
+
+	// Paint window background color (as widget is opaque)
+	QColor background = palette().color(QPalette::ColorRole::Window);
+	painter.fillRect(rect, background);
+
 	if (vertical) {
 	if (vertical) {
 		// Invert the Y axis to ease the math
 		// Invert the Y axis to ease the math
 		painter.translate(0, height);
 		painter.translate(0, height);