ui: combine OnroadHud into NvgWindow (#24369)

* ui: combine OnroadHUD and NVGWindow

* draw hud first

* cleanup

* removed commented line

* fix text rendering

* increase cpu usage
pull/24366/head
Willem Melching 3 years ago committed by GitHub
parent 1810909195
commit a3cfa444d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selfdrive/test/test_onroad.py
  2. 40
      selfdrive/ui/qt/onroad.cc
  3. 64
      selfdrive/ui/qt/onroad.h
  4. 1
      selfdrive/ui/qt/widgets/cameraview.cc

@ -26,7 +26,7 @@ PROCS = {
"./camerad": 26.0,
"./locationd": 9.1,
"selfdrive.controls.plannerd": 11.7,
"./_ui": 18.4,
"./_ui": 21.0,
"selfdrive.locationd.paramsd": 9.0,
"./_sensord": 6.17,
"selfdrive.controls.radard": 4.5,

@ -18,18 +18,13 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
stacked_layout->setStackingMode(QStackedLayout::StackAll);
main_layout->addLayout(stacked_layout);
QStackedLayout *road_view_layout = new QStackedLayout;
road_view_layout->setStackingMode(QStackedLayout::StackAll);
nvg = new NvgWindow(VISION_STREAM_ROAD, this);
road_view_layout->addWidget(nvg);
hud = new OnroadHud(this);
road_view_layout->addWidget(hud);
QWidget * split_wrapper = new QWidget;
split = new QHBoxLayout(split_wrapper);
split->setContentsMargins(0, 0, 0, 0);
split->setSpacing(0);
split->addLayout(road_view_layout);
split->addWidget(nvg);
stacked_layout->addWidget(split_wrapper);
@ -57,7 +52,7 @@ void OnroadWindow::updateState(const UIState &s) {
alerts->updateAlert(alert, bgColor);
}
hud->updateState(s);
nvg->updateState(s);
if (bg != bgColor) {
// repaint border
@ -167,15 +162,14 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) {
}
}
// OnroadHud
OnroadHud::OnroadHud(QWidget *parent) : QWidget(parent) {
// NvgWindow
NvgWindow::NvgWindow(VisionStreamType type, QWidget* parent) : fps_filter(UI_FREQ, 3, 1. / UI_FREQ), CameraViewWidget("camerad", type, true, parent) {
engage_img = loadPixmap("../assets/img_chffr_wheel.png", {img_size, img_size});
dm_img = loadPixmap("../assets/img_driver_face.png", {img_size, img_size});
connect(this, &OnroadHud::valueChanged, [=] { update(); });
}
void OnroadHud::updateState(const UIState &s) {
void NvgWindow::updateState(const UIState &s) {
const int SET_SPEED_NA = 255;
const SubMaster &sm = *(s.sm);
const auto cs = sm["controlsState"].getControlsState();
@ -202,9 +196,8 @@ void OnroadHud::updateState(const UIState &s) {
}
}
void OnroadHud::paintEvent(QPaintEvent *event) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
void NvgWindow::drawHud(QPainter &p) {
p.save();
// Header gradient
QLinearGradient bg(0, header_h - (header_h / 2.5), 0, header_h);
@ -246,9 +239,10 @@ void OnroadHud::paintEvent(QPaintEvent *event) {
drawIcon(p, radius / 2 + (bdr_s * 2), rect().bottom() - footer_h / 2,
dm_img, QColor(0, 0, 0, 70), dmActive ? 1.0 : 0.2);
}
p.restore();
}
void OnroadHud::drawText(QPainter &p, int x, int y, const QString &text, int alpha) {
void NvgWindow::drawText(QPainter &p, int x, int y, const QString &text, int alpha) {
QFontMetrics fm(p.font());
QRect init_rect = fm.boundingRect(text);
QRect real_rect = fm.boundingRect(init_rect, 0, text);
@ -258,7 +252,7 @@ void OnroadHud::drawText(QPainter &p, int x, int y, const QString &text, int alp
p.drawText(real_rect.x(), real_rect.bottom(), text);
}
void OnroadHud::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
void NvgWindow::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
p.setPen(Qt::NoPen);
p.setBrush(bg);
p.drawEllipse(x - radius / 2, y - radius / 2, radius, radius);
@ -266,11 +260,6 @@ void OnroadHud::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, flo
p.drawPixmap(x - img_size / 2, y - img_size / 2, img);
}
// NvgWindow
NvgWindow::NvgWindow(VisionStreamType type, QWidget* parent) : fps_filter(UI_FREQ, 3, 1. / UI_FREQ), CameraViewWidget("camerad", type, true, parent) {
}
void NvgWindow::initializeGL() {
CameraViewWidget::initializeGL();
@ -377,12 +366,15 @@ void NvgWindow::drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV
void NvgWindow::paintGL() {
CameraViewWidget::paintGL();
UIState *s = uiState();
if (s->worldObjectsVisible()) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
drawHud(painter);
UIState *s = uiState();
if (s->worldObjectsVisible()) {
drawLaneLines(painter, s);
if (s->scene.longitudinal_control) {

@ -9,26 +9,40 @@
// ***** onroad widgets *****
class OnroadAlerts : public QWidget {
Q_OBJECT
public:
OnroadAlerts(QWidget *parent = 0) : QWidget(parent) {};
void updateAlert(const Alert &a, const QColor &color);
class OnroadHud : public QWidget {
protected:
void paintEvent(QPaintEvent*) override;
private:
QColor bg;
Alert alert = {};
};
// container window for the NVG UI
class NvgWindow : public CameraViewWidget {
Q_OBJECT
Q_PROPERTY(QString speed MEMBER speed NOTIFY valueChanged);
Q_PROPERTY(QString speedUnit MEMBER speedUnit NOTIFY valueChanged);
Q_PROPERTY(QString maxSpeed MEMBER maxSpeed NOTIFY valueChanged);
Q_PROPERTY(bool is_cruise_set MEMBER is_cruise_set NOTIFY valueChanged);
Q_PROPERTY(bool engageable MEMBER engageable NOTIFY valueChanged);
Q_PROPERTY(bool dmActive MEMBER dmActive NOTIFY valueChanged);
Q_PROPERTY(bool hideDM MEMBER hideDM NOTIFY valueChanged);
Q_PROPERTY(int status MEMBER status NOTIFY valueChanged);
Q_PROPERTY(QString speed MEMBER speed);
Q_PROPERTY(QString speedUnit MEMBER speedUnit);
Q_PROPERTY(QString maxSpeed MEMBER maxSpeed);
Q_PROPERTY(bool is_cruise_set MEMBER is_cruise_set);
Q_PROPERTY(bool engageable MEMBER engageable);
Q_PROPERTY(bool dmActive MEMBER dmActive);
Q_PROPERTY(bool hideDM MEMBER hideDM);
Q_PROPERTY(int status MEMBER status);
public:
explicit OnroadHud(QWidget *parent);
explicit NvgWindow(VisionStreamType type, QWidget* parent = 0);
void updateState(const UIState &s);
private:
void drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity);
void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255);
void paintEvent(QPaintEvent *event) override;
QPixmap engage_img;
QPixmap dm_img;
@ -43,32 +57,6 @@ private:
bool hideDM = false;
int status = STATUS_DISENGAGED;
signals:
void valueChanged();
};
class OnroadAlerts : public QWidget {
Q_OBJECT
public:
OnroadAlerts(QWidget *parent = 0) : QWidget(parent) {};
void updateAlert(const Alert &a, const QColor &color);
protected:
void paintEvent(QPaintEvent*) override;
private:
QColor bg;
Alert alert = {};
};
// container window for the NVG UI
class NvgWindow : public CameraViewWidget {
Q_OBJECT
public:
explicit NvgWindow(VisionStreamType type, QWidget* parent = 0);
protected:
void paintGL() override;
void initializeGL() override;
@ -76,6 +64,7 @@ protected:
void updateFrameMat(int w, int h) override;
void drawLaneLines(QPainter &painter, const UIState *s);
void drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV3::Reader &lead_data, const QPointF &vd);
void drawHud(QPainter &p);
inline QColor redColor(int alpha = 255) { return QColor(201, 34, 49, alpha); }
inline QColor whiteColor(int alpha = 255) { return QColor(255, 255, 255, alpha); }
@ -94,7 +83,6 @@ public:
private:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent* e) override;
OnroadHud *hud;
OnroadAlerts *alerts;
NvgWindow *nvg;
QColor bg = bg_colors[STATUS_DISENGAGED];

@ -253,7 +253,6 @@ void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
stream_width = vipc_client->buffers[0].width;
stream_height = vipc_client->buffers[0].height;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
for (int i = 0; i < 3; ++i) {
glBindTexture(GL_TEXTURE_2D, textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

Loading…
Cancel
Save