From f1e674f30ca234023ce45ddb2e41f410adc09f1b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 20 Apr 2023 04:06:54 +1000 Subject: [PATCH] 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 old-commit-hash: fbcd0821c92af58137e5b34f0cfe37ffd1c08642 --- selfdrive/ui/qt/widgets/cameraview.cc | 14 ++++++++++++-- selfdrive/ui/qt/widgets/cameraview.h | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/widgets/cameraview.cc b/selfdrive/ui/qt/widgets/cameraview.cc index de3b64cffd..016129c348 100644 --- a/selfdrive/ui/qt/widgets/cameraview.cc +++ b/selfdrive/ui/qt/widgets/cameraview.cc @@ -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 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); diff --git a/selfdrive/ui/qt/widgets/cameraview.h b/selfdrive/ui/qt/widgets/cameraview.h index 9135620d35..8a140e5290 100644 --- a/selfdrive/ui/qt/widgets/cameraview.h +++ b/selfdrive/ui/qt/widgets/cameraview.h @@ -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];