mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-26 00:12:05 +08:00
cabana/cameraview: Scale the glViewPort by devicePixelRatio() (#27941)
* cameraview: Scale the glViewPort by devicePixelRatio() This fixes an issue seen in Cabana on a "hidpi" system with Wayland where devicePixelRatio() != 1 and the video doesn't take up the full widget area. On the recommended Ubuntu 20.04 install I wasn't able to reproduce, because devicePixelRatio() was always equal to 1 even with scaling to 200% or 300%. It might be different if "Fractional Scaling" is enabled in GNOME (I couldn't make that option work in mv WM.) Was going to enable just for Linux, but it appears to also be recommended for Retina MacOS: https://doc.qt.io/qt-5/scalability.html#high-dpi-scaling-on-macos-and-ios ... so have worked from the assumption that glViewport() always takes dimensions in device pixels, never the "device independent pixels" of Qt. * Update selfdrive/ui/qt/widgets/cameraview.cc * Update selfdrive/ui/qt/widgets/cameraview.cc --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
@@ -114,6 +114,16 @@ CameraWidget::~CameraWidget() {
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
// Qt uses device-independent pixels, depending on platform this may be
|
||||
// different to what OpenGL uses
|
||||
int CameraWidget::glWidth() {
|
||||
return width() * devicePixelRatio();
|
||||
}
|
||||
|
||||
int CameraWidget::glHeight() {
|
||||
return height() * devicePixelRatio();
|
||||
}
|
||||
|
||||
void CameraWidget::initializeGL() {
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
@@ -188,7 +198,7 @@ void CameraWidget::availableStreamsUpdated(std::set<VisionStreamType> streams) {
|
||||
}
|
||||
|
||||
void CameraWidget::updateFrameMat() {
|
||||
int w = width(), h = height();
|
||||
int w = glWidth(), h = glHeight();
|
||||
|
||||
if (zoomed_view) {
|
||||
if (active_stream_type == VISION_STREAM_DRIVER) {
|
||||
@@ -266,7 +276,7 @@ void CameraWidget::paintGL() {
|
||||
|
||||
updateFrameMat();
|
||||
|
||||
glViewport(0, 0, width(), height());
|
||||
glViewport(0, 0, glWidth(), glHeight());
|
||||
glBindVertexArray(frame_vao);
|
||||
glUseProgram(program->programId());
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
@@ -54,6 +54,9 @@ protected:
|
||||
void vipcThread();
|
||||
void clearFrames();
|
||||
|
||||
int glWidth();
|
||||
int glHeight();
|
||||
|
||||
bool zoomed_view;
|
||||
GLuint frame_vao, frame_vbo, frame_ibo;
|
||||
GLuint textures[2];
|
||||
|
||||
Reference in New Issue
Block a user