From 03508faabfc2f5b76039cfd13d02a341baa848a4 Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Tue, 17 Jul 2018 19:16:26 +0100 Subject: WIP. --- gui/fpgaviewwidget.h | 62 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 25 deletions(-) (limited to 'gui/fpgaviewwidget.h') diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 33eb2800..19440054 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -21,12 +21,15 @@ #define MAPGLWIDGET_H #include +#include #include #include #include #include #include #include +#include +#include #include "nextpnr.h" @@ -209,14 +212,6 @@ class LineShader class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT - Q_PROPERTY(QColor backgroundColor MEMBER backgroundColor_ DESIGNABLE true) - Q_PROPERTY(QColor gridColor MEMBER gridColor_ DESIGNABLE true) - Q_PROPERTY(QColor gFrameColor MEMBER gFrameColor_ DESIGNABLE true) - Q_PROPERTY(QColor gHiddenColor MEMBER gHiddenColor_ DESIGNABLE true) - Q_PROPERTY(QColor gInactiveColor MEMBER gInactiveColor_ DESIGNABLE true) - Q_PROPERTY(QColor gActiveColor MEMBER gActiveColor_ DESIGNABLE true) - Q_PROPERTY(QColor gSelectedColor MEMBER gSelectedColor_ DESIGNABLE true) - Q_PROPERTY(QColor frameColor MEMBER frameColor_ DESIGNABLE true) public: FPGAViewWidget(QWidget *parent = 0); @@ -246,8 +241,12 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions void newContext(Context *ctx); void onSelectedArchItem(std::vector decals); void onHighlightGroupChanged(std::vector decals, int group); + void pokeRenderer(void); private: + void renderLines(void); + void renderLinesWorker(void); + QPoint lastPos_; LineShader lineShader_; QMatrix4x4 viewMove_; @@ -263,23 +262,36 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions Context *ctx_; - QColor backgroundColor_; - QColor gridColor_; - QColor gFrameColor_; - QColor gHiddenColor_; - QColor gInactiveColor_; - QColor gActiveColor_; - QColor gSelectedColor_; - QColor frameColor_; - - LineShaderData selectedShader_; - std::vector selectedItems_; - bool selectedItemsChanged_; - - LineShaderData highlightShader_[8]; - std::vector highlightItems_[8]; - bool highlightItemsChanged_[8]; - QColor highlightColors[8]; + QWaitCondition render_; + std::unique_ptr renderThread_; + + struct { + QColor background; + QColor grid; + QColor frame; + QColor hidden; + QColor inactive; + QColor active; + QColor selected; + QColor highlight[8]; + } colors_; + + struct RendererData { + LineShaderData decals[4]; + LineShaderData selected; + LineShaderData highlighted[8]; + }; + + struct RendererArgs { + std::vector selectedItems; + std::vector highlightedItems[8]; + bool highlightedOrSelectedChanged; + }; + + std::unique_ptr rendererData_; + QMutex rendererDataLock_; + std::unique_ptr rendererArgs_; + QMutex rendererArgsLock_; }; NEXTPNR_NAMESPACE_END -- cgit v1.2.3 From 0385ad1b1cc3dcd4673b3c674bc28ca12a7c7450 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Fri, 20 Jul 2018 10:58:30 +0100 Subject: Refactor renderer thread --- gui/fpgaviewwidget.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'gui/fpgaviewwidget.h') diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 19440054..f846abca 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -209,6 +210,60 @@ class LineShader void draw(const LineShaderData &data, const QColor &color, float thickness, const QMatrix4x4 &projection); }; +class PeriodicRunner : public QThread +{ + Q_OBJECT +private: + QMutex mutex_; + QWaitCondition condition_; + bool abort_; + std::function target_; + QTimer timer_; +public: + explicit PeriodicRunner(QObject *parent, std::function target) : + QThread(parent), abort_(false), target_(target), timer_(this) + { + connect(&timer_, &QTimer::timeout, this, &PeriodicRunner::poke); + } + + void run(void) override + { + for (;;) { + mutex_.lock(); + condition_.wait(&mutex_); + + if (abort_) { + mutex_.unlock(); + return; + } + + target_(); + + mutex_.unlock(); + } + } + + void startTimer(std::chrono::milliseconds value) + { + timer_.start(value); + } + + ~PeriodicRunner() + { + mutex_.lock(); + abort_ = true; + condition_.wakeOne(); + mutex_.unlock(); + + wait(); + } + + void poke(void) + { + condition_.wakeOne(); + } +}; + class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT @@ -245,7 +300,6 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions private: void renderLines(void); - void renderLinesWorker(void); QPoint lastPos_; LineShader lineShader_; @@ -261,9 +315,9 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions const float zoomLvl2_ = 50.0f; Context *ctx_; + QTimer paintTimer_; - QWaitCondition render_; - std::unique_ptr renderThread_; + std::unique_ptr renderRunner_; struct { QColor background; -- cgit v1.2.3 From 19f4b68f07edcbcb24282f5d3941d5d4a97afa03 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Fri, 20 Jul 2018 13:19:45 +0100 Subject: clang-format and uncomment debug --- gui/fpgaviewwidget.h | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'gui/fpgaviewwidget.h') diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index f846abca..0d0ef89c 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -28,8 +28,8 @@ #include #include #include -#include #include +#include #include #include "nextpnr.h" @@ -213,15 +213,16 @@ class LineShader class PeriodicRunner : public QThread { Q_OBJECT -private: + private: QMutex mutex_; QWaitCondition condition_; bool abort_; std::function target_; QTimer timer_; -public: - explicit PeriodicRunner(QObject *parent, std::function target) : - QThread(parent), abort_(false), target_(target), timer_(this) + + public: + explicit PeriodicRunner(QObject *parent, std::function target) + : QThread(parent), abort_(false), target_(target), timer_(this) { connect(&timer_, &QTimer::timeout, this, &PeriodicRunner::poke); } @@ -243,10 +244,7 @@ public: } } - void startTimer(std::chrono::milliseconds value) - { - timer_.start(value); - } + void startTimer(std::chrono::milliseconds value) { timer_.start(value); } ~PeriodicRunner() { @@ -258,10 +256,7 @@ public: wait(); } - void poke(void) - { - condition_.wakeOne(); - } + void poke(void) { condition_.wakeOne(); } }; class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions @@ -319,7 +314,8 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions std::unique_ptr renderRunner_; - struct { + struct + { QColor background; QColor grid; QColor frame; @@ -330,13 +326,15 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions QColor highlight[8]; } colors_; - struct RendererData { + struct RendererData + { LineShaderData decals[4]; LineShaderData selected; LineShaderData highlighted[8]; }; - - struct RendererArgs { + + struct RendererArgs + { std::vector selectedItems; std::vector highlightedItems[8]; bool highlightedOrSelectedChanged; -- cgit v1.2.3