diff options
-rw-r--r-- | common/nextpnr.h | 11 | ||||
-rw-r--r-- | gui/application.cc | 20 | ||||
-rw-r--r-- | gui/fpgaviewwidget.cc | 21 | ||||
-rw-r--r-- | gui/fpgaviewwidget.h | 32 |
4 files changed, 39 insertions, 45 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index e9cda565..09174320 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -250,10 +250,11 @@ struct CellInfo : ArchCellInfo class IdStringDB { friend class IdString; + private: mutable std::unordered_map<std::string, int> *idstring_str_to_idx; mutable std::vector<const std::string *> *idstring_idx_to_str; - + public: IdString id(const std::string &s) const { return IdString(this, s); } IdString id(const char *s) const { return IdString(this, s); } @@ -279,9 +280,7 @@ class DeterministicRNG uint64_t rngstate; public: - DeterministicRNG() : rngstate(0x3141592653589793) - { - } + DeterministicRNG() : rngstate(0x3141592653589793) {} uint64_t rng64() { @@ -340,7 +339,6 @@ class DeterministicRNG std::sort(a.begin(), a.end()); shuffle(a); } - }; class BaseCtx : public IdStringDB @@ -348,7 +346,7 @@ class BaseCtx : public IdStringDB private: std::mutex mutex; pthread_t mutex_owner; - + std::mutex generation_mutex; public: @@ -362,7 +360,6 @@ class BaseCtx : public IdStringDB { mutex.lock(); mutex_owner = pthread_self(); - } void unlock(void) diff --git a/gui/application.cc b/gui/application.cc index 12453b57..58dc23eb 100644 --- a/gui/application.cc +++ b/gui/application.cc @@ -37,17 +37,17 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) bool Application::notify(QObject *receiver, QEvent *event) { bool retVal = true; - //try { + try { retVal = QApplication::notify(receiver, event); - //} catch (assertion_failure ex) { - // QString msg; - // QTextStream out(&msg); - // out << ex.filename.c_str() << " at " << ex.line << "\n"; - // out << ex.msg.c_str(); - // QMessageBox::critical(0, "Error", msg); - //} catch (...) { - // QMessageBox::critical(0, "Error", "Fatal error !!!"); - //} + } catch (assertion_failure ex) { + QString msg; + QTextStream out(&msg); + out << ex.filename.c_str() << " at " << ex.line << "\n"; + out << ex.msg.c_str(); + QMessageBox::critical(0, "Error", msg); + } catch (...) { + QMessageBox::critical(0, "Error", "Fatal error !!!"); + } return retVal; } diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 9a03b2a5..b990baca 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -241,9 +241,10 @@ void LineShader::draw(const LineShaderData &line, const QColor &color, float thi } FPGAViewWidget::FPGAViewWidget(QWidget *parent) - : QOpenGLWidget(parent), lineShader_(this), zoom_(500.f), ctx_(nullptr), paintTimer_(this), rendererData_(new FPGAViewWidget::RendererData), rendererArgs_(new FPGAViewWidget::RendererArgs) + : QOpenGLWidget(parent), lineShader_(this), zoom_(500.f), ctx_(nullptr), paintTimer_(this), + rendererData_(new FPGAViewWidget::RendererData), rendererArgs_(new FPGAViewWidget::RendererArgs) { - colors_.background = QColor("#000000"); + colors_.background = QColor("#000000"); colors_.grid = QColor("#333"); colors_.frame = QColor("#d0d0d0"); colors_.hidden = QColor("#606060"); @@ -275,12 +276,12 @@ FPGAViewWidget::FPGAViewWidget(QWidget *parent) printf("Could not get OpenGL 3.1 context - trying anyway...\n "); } - connect(&paintTimer_, SIGNAL(timeout()), this, SLOT(update())); - paintTimer_.start(std::chrono::duration<int, std::milli>(1000/20)); // paint GL 20 times per second + connect(&paintTimer_, SIGNAL(timeout()), this, SLOT(update())); + paintTimer_.start(std::chrono::duration<int, std::milli>(1000 / 20)); // paint GL 20 times per second renderRunner_ = std::unique_ptr<PeriodicRunner>(new PeriodicRunner(this, [this] { renderLines(); })); renderRunner_->start(); - renderRunner_->startTimer(std::chrono::duration<int, std::milli>(1000/2)); // render line 2 times per second + renderRunner_->startTimer(std::chrono::duration<int, std::milli>(1000 / 2)); // render line 2 times per second } FPGAViewWidget::~FPGAViewWidget() {} @@ -301,7 +302,8 @@ void FPGAViewWidget::initializeGL() log_error("Could not compile shader.\n"); } initializeOpenGLFunctions(); - glClearColor(colors_.background.red() / 255, colors_.background.green() / 255, colors_.background.blue() / 255, 0.0); + glClearColor(colors_.background.red() / 255, colors_.background.green() / 255, colors_.background.blue() / 255, + 0.0); } void FPGAViewWidget::drawDecal(LineShaderData &out, const DecalXY &decal) @@ -417,9 +419,7 @@ void FPGAViewWidget::paintGL() rendererDataLock_.unlock(); } -void FPGAViewWidget::pokeRenderer(void) { - renderRunner_->poke(); -} +void FPGAViewWidget::pokeRenderer(void) { renderRunner_->poke(); } void FPGAViewWidget::renderLines(void) { @@ -439,7 +439,7 @@ void FPGAViewWidget::renderLines(void) ctx_->frameUiReload = false; decalsChanged = true; } - if (ctx_->belUiReload.size() > 0){ + if (ctx_->belUiReload.size() > 0) { ctx_->belUiReload.clear(); decalsChanged = true; } @@ -525,7 +525,6 @@ void FPGAViewWidget::renderLines(void) rendererDataLock_.unlock(); } - void FPGAViewWidget::onSelectedArchItem(std::vector<DecalXY> decals) { rendererArgsLock_.lock(); 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 <QOpenGLVertexArrayObject> #include <QOpenGLWidget> #include <QPainter> -#include <QTimer> #include <QThread> +#include <QTimer> #include <QWaitCondition> #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<void()> target_; QTimer timer_; -public: - explicit PeriodicRunner(QObject *parent, std::function<void()> target) : - QThread(parent), abort_(false), target_(target), timer_(this) + + public: + explicit PeriodicRunner(QObject *parent, std::function<void()> 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<PeriodicRunner> 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<DecalXY> selectedItems; std::vector<DecalXY> highlightedItems[8]; bool highlightedOrSelectedChanged; |