diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-21 19:29:28 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-21 19:29:28 +0100 |
commit | c06048a7af347bf843bf25bd305cbbf4d6cec266 (patch) | |
tree | 15b3ae75465198d1ec2bdd21d6879305c74680ca /video | |
parent | ff38e35d832b7c7a3e189bee4a80271fd3a3c978 (diff) |
do less global memory fences in atomics
Diffstat (limited to 'video')
-rw-r--r-- | video/video-widget.cpp | 20 |
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*) |