UI: refactor GLWindow (#20764)
parent
0d10f9c4ad
commit
140e6248e2
15 changed files with 358 additions and 310 deletions
@ -0,0 +1,57 @@ |
|||||||
|
#include <iostream> |
||||||
|
|
||||||
|
#include "common/timing.h" |
||||||
|
#include "common/swaglog.h" |
||||||
|
|
||||||
|
#include "onroad.hpp" |
||||||
|
#include "paint.hpp" |
||||||
|
|
||||||
|
OnroadWindow::~OnroadWindow() { |
||||||
|
makeCurrent(); |
||||||
|
doneCurrent(); |
||||||
|
} |
||||||
|
|
||||||
|
void OnroadWindow::initializeGL() { |
||||||
|
initializeOpenGLFunctions(); |
||||||
|
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; |
||||||
|
std::cout << "OpenGL vendor: " << glGetString(GL_VENDOR) << std::endl; |
||||||
|
std::cout << "OpenGL renderer: " << glGetString(GL_RENDERER) << std::endl; |
||||||
|
std::cout << "OpenGL language version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; |
||||||
|
|
||||||
|
enabled = true; |
||||||
|
ui_nvg_init(&QUIState::ui_state); |
||||||
|
prev_draw_t = millis_since_boot(); |
||||||
|
} |
||||||
|
|
||||||
|
void OnroadWindow::setEnabled(bool on) { |
||||||
|
enabled = on; |
||||||
|
} |
||||||
|
|
||||||
|
void OnroadWindow::update(const UIState &s) { |
||||||
|
// Connecting to visionIPC requires opengl to be current
|
||||||
|
if (s.vipc_client->connected){ |
||||||
|
makeCurrent(); |
||||||
|
} |
||||||
|
|
||||||
|
// TODO: will hide do this?
|
||||||
|
if(enabled) { |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OnroadWindow::resizeGL(int w, int h) { |
||||||
|
std::cout << "resize " << w << "x" << h << std::endl; |
||||||
|
} |
||||||
|
|
||||||
|
void OnroadWindow::paintGL() { |
||||||
|
ui_draw(&QUIState::ui_state); |
||||||
|
|
||||||
|
double cur_draw_t = millis_since_boot(); |
||||||
|
double dt = cur_draw_t - prev_draw_t; |
||||||
|
// TODO: check if onroad
|
||||||
|
if (dt > 66 && QUIState::ui_state.scene.started && !QUIState::ui_state.scene.driver_view) { |
||||||
|
// warn on sub 15fps
|
||||||
|
LOGW("slow frame time: %.2f", dt); |
||||||
|
} |
||||||
|
prev_draw_t = cur_draw_t; |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <QOpenGLFunctions> |
||||||
|
#include <QOpenGLWidget> |
||||||
|
#include <QTimer> |
||||||
|
|
||||||
|
#include "ui/ui.hpp" |
||||||
|
|
||||||
|
// container window for the NVG UI
|
||||||
|
class OnroadWindow : public QOpenGLWidget, protected QOpenGLFunctions { |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
using QOpenGLWidget::QOpenGLWidget; |
||||||
|
explicit OnroadWindow(QWidget* parent = 0) : QOpenGLWidget(parent) {}; |
||||||
|
~OnroadWindow(); |
||||||
|
|
||||||
|
protected: |
||||||
|
void paintGL() override; |
||||||
|
void initializeGL() override; |
||||||
|
void resizeGL(int w, int h) override; |
||||||
|
|
||||||
|
private: |
||||||
|
bool enabled; |
||||||
|
double prev_draw_t = 0; |
||||||
|
|
||||||
|
public slots: |
||||||
|
void setEnabled(bool on); |
||||||
|
void update(const UIState &s); |
||||||
|
}; |
@ -1,12 +1,13 @@ |
|||||||
#include "request_repeater.hpp" |
#include "request_repeater.hpp" |
||||||
|
|
||||||
RequestRepeater::RequestRepeater(QObject *parent, QString requestURL, const QString &cache_key, int period_seconds, bool disableWithScreen) : |
RequestRepeater::RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey, |
||||||
HttpRequest(parent, requestURL, cache_key), disableWithScreen(disableWithScreen) { |
int period) : HttpRequest(parent, requestURL, cacheKey) { |
||||||
QTimer* timer = new QTimer(this); |
timer = new QTimer(this); |
||||||
|
timer->setTimerType(Qt::VeryCoarseTimer); |
||||||
QObject::connect(timer, &QTimer::timeout, [=](){ |
QObject::connect(timer, &QTimer::timeout, [=](){ |
||||||
if (!GLWindow::ui_state.scene.started && reply == NULL && (GLWindow::ui_state.awake || !disableWithScreen)) { |
if (!QUIState::ui_state.scene.started && QUIState::ui_state.awake && reply == NULL) { |
||||||
sendRequest(requestURL); |
sendRequest(requestURL); |
||||||
} |
} |
||||||
}); |
}); |
||||||
timer->start(period_seconds * 1000); |
timer->start(period * 1000); |
||||||
} |
} |
||||||
|
@ -1,9 +1,10 @@ |
|||||||
#include "api.hpp" |
#include "api.hpp" |
||||||
#include "home.hpp" |
#include "ui.hpp" |
||||||
|
|
||||||
class RequestRepeater : public HttpRequest { |
class RequestRepeater : public HttpRequest { |
||||||
|
|
||||||
public: |
public: |
||||||
RequestRepeater(QObject *parent, QString requestURL, const QString &cache_key = "", int period_seconds = 0, bool disableWithScreen = true); |
RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey = "", int period = 0); |
||||||
bool disableWithScreen; |
|
||||||
|
private: |
||||||
|
QTimer *timer; |
||||||
}; |
}; |
||||||
|
Loading…
Reference in new issue