summaryrefslogtreecommitdiffhomepage
path: root/video
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-02-21 19:29:28 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-02-21 19:29:28 +0100
commitc06048a7af347bf843bf25bd305cbbf4d6cec266 (patch)
tree15b3ae75465198d1ec2bdd21d6879305c74680ca /video
parentff38e35d832b7c7a3e189bee4a80271fd3a3c978 (diff)
do less global memory fences in atomics
Diffstat (limited to 'video')
-rw-r--r--video/video-widget.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/video/video-widget.cpp b/video/video-widget.cpp
index e73d34db..fb380fc4 100644
--- a/video/video-widget.cpp
+++ b/video/video-widget.cpp
@@ -25,11 +25,10 @@ video_widget::video_widget(QWidget* parent) : QWidget(parent)
void video_widget::update_image(const QImage& img)
{
- QMutexLocker l(&mtx);
-
- if (freshp)
+ if (freshp.load(std::memory_order_relaxed))
return;
- freshp = true;
+
+ QMutexLocker l(&mtx);
unsigned nbytes = (unsigned)(img.bytesPerLine() * img.height());
vec.resize(nbytes); vec.shrink_to_fit();
@@ -37,6 +36,8 @@ void video_widget::update_image(const QImage& img)
texture = QImage((const unsigned char*) vec.data(), img.width(), img.height(), img.bytesPerLine(), img.format());
texture.setDevicePixelRatio(devicePixelRatioF());
+
+ freshp.store(true, std::memory_order_relaxed);
}
void video_widget::paintEvent(QPaintEvent*)
@@ -49,16 +50,15 @@ void video_widget::paintEvent(QPaintEvent*)
void video_widget::update_and_repaint()
{
+ if (!freshp.load(std::memory_order_relaxed))
+ return;
+
if (!check_is_visible())
return;
QMutexLocker l(&mtx);
-
- if (freshp)
- {
- freshp = false;
- repaint();
- }
+ repaint();
+ freshp.store(false, std::memory_order_relaxed);
}
void video_widget::resizeEvent(QResizeEvent*)