LINUX.ORG.RU

Qt5 + FrameBuffer

 , ,


0

2

Пытаюсь заставить заработать Qt5 на FrameBuffer.

Для начала попробовал исполнить C-шную программу вида:

#include <linux/fb.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h> // For close
#include <sys/mman.h> // For mmap
#include <string.h> // For memset
 
#define FBDEV "/dev/fb0"
 
int main() {
  int fbfd= open(FBDEV, O_RDWR);
  if (fbfd < 0) {
    printf("Error in opening FrameBuffer: %d\n", fbfd);
    exit(fbfd);
  }
 
  struct fb_var_screeninfo vinfo;
 
  ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo);
 
  int fb_width= vinfo.xres;
  int fb_height= vinfo.yres;
  int fb_bpp= vinfo.bits_per_pixel;
  int fb_bytes= fb_bpp / 8;
 
  int fb_data_size= fb_width * fb_height * fb_bytes;
  char *fbdata= mmap(0, fb_data_size,
             PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, (off_t)0);
  memset(fbdata, 0, fb_data_size);
 
  for (int offset=0; offset < fb_data_size; offset= offset + 4) {
    fbdata[offset + 0]= 125;
    fbdata[offset + 1]= 125;
    fbdata[offset + 2]= 0;
    fbdata[offset + 3]= 0;
  }
 
  munmap(fbdata, fb_data_size);
  close(fbfd);
 
  printf("Width: %d\n", fb_width);
  printf("Height: %d\n", fb_height);
  printf("BPP: %d\n", fb_bpp);
  printf("Bytes: %d\n", fb_bytes);
}

Чисто посмотреть будет ли закрашивать экран. Да, закрашивает.

Далее скомпилировал и установил qt5-everywhere с таким настройками:

Build type: linux-g++ (arm64, CPU features: neon)
Compiler: gcc 7.5.0
Configuration: compile_examples enable_new_dtags largefile neon precompile_header shared shared rpath release c++11 c++14 c++17 c++1z concurrent dbus reduce_exports stl
Build options:
  Mode ................................... release
  Optimize release build for size ........ no
  Building shared libraries .............. yes
  Using C standard ....................... C11
  Using C++ standard ..................... C++17
  Using ccache ........................... no
  Using new DTAGS ........................ yes
  Relocatable ............................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. yes
  Build parts ............................ libs examples tools
Qt modules and options:
  Qt Concurrent .......................... yes
  Qt D-Bus ............................... yes
  Qt D-Bus directly linked to libdbus .... no
  Qt Gui ................................. yes
  Qt Network ............................. yes
  Qt Sql ................................. yes
  Qt Testlib ............................. yes
  Qt Widgets ............................. yes
  Qt Xml ................................. yes
Support enabled for:
  Using pkg-config ....................... yes
  udev ................................... no
  Using system zlib ...................... yes
  Zstandard support ...................... no
Qt Core:
  DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
  GLib ................................... yes
  iconv .................................. yes
  ICU .................................... no
  Built-in copy of the MIME database ..... yes
  Tracing backend ........................ <none>
  Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
  PCRE2 .................................. yes
    Using system PCRE2 ................... no
Qt Network:
  getifaddrs() ........................... yes
  IPv6 ifname ............................ yes
  libproxy ............................... no
  Linux AF_NETLINK ....................... yes
  OpenSSL ................................ no
    Qt directly linked to OpenSSL ........ no
  OpenSSL 1.1 ............................ no
  DTLS ................................... no
  OCSP-stapling .......................... no
  SCTP ................................... no
  Use system proxies ..................... yes
  GSSAPI ................................. no
Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ no
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ no
  Fontconfig ............................. no
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... no
    PNG .................................. yes
      Using system libpng ................ no
  Text formats:
    HtmlParser ........................... yes
    CssParser ............................ yes
    OdfWriter ............................ yes
    MarkdownReader ....................... yes
      Using system libmd4c ............... no
    MarkdownWriter ....................... yes
  EGL .................................... yes
  OpenVG ................................. no
  OpenGL:
    Desktop OpenGL ....................... yes
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
    OpenGL ES 3.2 ........................ no
  Vulkan ................................. no
  Session Management ..................... yes
Features used by QPA backends:
  evdev .................................. yes
  libinput ............................... no
  INTEGRITY HID .......................... no
  mtdev .................................. no
  tslib .................................. no
  xkbcommon .............................. no
  X11 specific:
    XLib ................................. yes
    XCB Xlib ............................. yes
    EGL on X11 ........................... yes
    xkbcommon-x11 ........................ no
QPA backends:
  DirectFB ............................... no
  EGLFS .................................. yes
  EGLFS details:
    EGLFS OpenWFD ........................ no
    EGLFS i.Mx6 .......................... no
    EGLFS i.Mx6 Wayland .................. no
    EGLFS RCAR ........................... no
    EGLFS EGLDevice ...................... yes
    EGLFS GBM ............................ no
    EGLFS VSP2 ........................... no
    EGLFS Mali ........................... no
    EGLFS Raspberry Pi ................... no
    EGLFS X11 ............................ yes
  LinuxFB ................................ yes
  VNC .................................... yes
Qt Sql:
  SQL item models ........................ yes
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows
Qt PrintSupport:
  CUPS ................................... no
Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no
Qt Testlib:
  Tester for item models ................. yes
Serial Port:
  ntddmodm ............................... no
Qt SerialBus:
  Socket CAN ............................. yes
  Socket CAN FD .......................... yes
  SerialPort Support ..................... yes
Further Image Formats:
  JasPer ................................. no
  MNG .................................... no
  TIFF ................................... yes
    Using system libtiff ................. no
  WEBP ................................... yes
    Using system libwebp ................. no
Qt QML:
  QML network support .................... yes
  QML debugging and profiling support .... yes
  QML just-in-time compiler .............. yes
  QML sequence object .................... yes
  QML XML http request ................... yes
  QML Locale ............................. yes
Qt QML Models:
  QML list model ......................... yes
  QML delegate model ..................... yes
Qt Quick:
  Direct3D 12 ............................ no
  AnimatedImage item ..................... yes
  Canvas item ............................ yes
  Support for Qt Quick Designer .......... yes
  Flipable item .......................... yes
  GridView item .......................... yes
  ListView item .......................... yes
  TableView item ......................... yes
  Path support ........................... yes
  PathView item .......................... yes
  Positioner items ....................... yes
  Repeater item .......................... yes
  ShaderEffect item ...................... yes
  Sprite item ............................ yes
QtQuick3D:
  Assimp ................................. yes
  System Assimp .......................... no
Qt Scxml:
  ECMAScript data model for QtScxml ...... yes
Qt Gamepad:
  SDL2 ................................... no
Qt 3D:
  Assimp ................................. yes
  System Assimp .......................... no
  Output Qt3D GL traces .................. no
  Use SSE2 instructions .................. no
  Use AVX2 instructions .................. no
  Aspects:
    Render aspect ........................ yes
    Input aspect ......................... yes
    Logic aspect ......................... yes
    Animation aspect ..................... yes
    Extras aspect ........................ yes
Qt 3D Renderers:
  OpenGL Renderer ........................ yes
  RHI Renderer ........................... no
Qt 3D GeometryLoaders:
  Autodesk FBX ........................... no
Qt Wayland Drivers:
  EGL .................................... yes
  Raspberry Pi ........................... no
  XComposite EGL ......................... no
  XComposite GLX ......................... no
  DRM EGL ................................ yes
  libhybris EGL .......................... no
  Linux dma-buf server buffer integration . yes
  Vulkan-based server buffer integration . no
  Shm emulation server buffer integration . yes
Qt Wayland Client Shell Integrations:
  xdg-shell .............................. yes
  xdg-shell unstable v5 (deprecated) ..... yes
  xdg-shell unstable v6 .................. yes
  ivi-shell .............................. yes
  wl-shell (deprecated) .................. yes
Qt Wayland Client ........................ yes
Qt Wayland Compositor .................... yes
Qt Wayland Compositor Layer Plugins:
  VSP2 hardware layer integration ........ no
Qt Bluetooth:
  BlueZ .................................. no
  BlueZ Low Energy ....................... no
  Linux Crypto API ....................... no
  Native Win32 Bluetooth ................. no
  WinRT Bluetooth API (desktop & UWP) .... no
  WinRT advanced bluetooth low energy API (desktop & UWP) . no
Qt Sensors:
  sensorfw ............................... no
Qt Quick Controls 2:
  Styles ................................. Default Fusion Imagine Material Universal
Qt Quick Templates 2:
  Hover support .......................... yes
  Multi-touch support .................... yes
Qt Positioning:
  Gypsy GPS Daemon ....................... no
  WinRT Geolocation API .................. no
Qt Location:
  Qt.labs.location experimental QML plugin . yes
  Geoservice plugins:
    OpenStreetMap ........................ yes
    HERE ................................. yes
    Esri ................................. yes
    Mapbox ............................... yes
    MapboxGL ............................. yes
    Itemsoverlay ......................... yes
QtXmlPatterns:
  XML schema support ..................... yes
Qt Multimedia:
  ALSA ................................... no
  GStreamer 1.0 .......................... yes
  GStreamer 0.10 ......................... no
  Video for Linux ........................ yes
  OpenAL ................................. no
  PulseAudio ............................. no
  Resource Policy (libresourceqt5) ....... no
  Windows Audio Services ................. no
  DirectShow ............................. no
  Windows Media Foundation ............... no
Qt TextToSpeech:
  Flite .................................. no
  Flite with ALSA ........................ no
  Speech Dispatcher ...................... no
Qt Tools:
  Qt Assistant ........................... yes
  Qt Designer ............................ yes
  Qt Distance Field Generator ............ yes
  kmap2qmap .............................. yes
  Qt Linguist ............................ yes
  Mac Deployment Tool .................... no
  makeqpf ................................ yes
  pixeltool .............................. yes
  qdbus .................................. yes
  qev .................................... yes
  Qt Attributions Scanner ................ yes
  qtdiag ................................. yes
  qtpaths ................................ yes
  qtplugininfo ........................... yes
  Windows deployment tool ................ no
  WinRT Runner Tool ...................... no
Qt Tools:
  QDoc ................................... no

Набросал тестовую программу:

pod@rover:~/Projects/QFB$ cat main.cpp
#include <QApplication>
#include <QLabel>
#include <QPixmap>

int main(int argc, char *argv[]) {
  QApplication app(argc, argv);

  QLabel label("Hello, World!");
  label.show();

  label.showMaximized();
  return app.exec();
}

Попробовал запустить:

pod@rover:~/Projects/QFB$ sudo ./QFB -platform linuxfb:fb="/dev/fb0"
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active

На экране ничего. Подскажите, пожалуйста, куда можно дальше копать.

Да, делается это всё на Jetson Nano.


sudo ./QFB -platform linuxfb:fb="/dev/fb0"

Указание fb=... лишнее.

Используй для старта переменные окружения. А не параметры. Например указать QT_QPA_GENERIC_PLUGINS какие плагины для ввода будут использоваться. и т.д. и т.п. из https://doc.qt.io/qt-5/embedded-linux.html

В добавок у тебя есть EGLFS. С ним как обстоят дела? Пробовал ли DRM/KMS задействовать.

Добавь в сборку Qt примеры. А то меня смущает отсутствие полноценного класса окна. Хотя, вроде, и так должно работать. Но есть всякие приколы с одним окном на экран.

Не очень понятно зачем тебе x11, wayland в опциях сборки.

Поиграй с QT_QPA_EGLFS_DEBUG, QT_LOGGING_RULES и т.п.

З.Ы.: gcc 7.5.0, qt5 - что всё так грустно?

AlexVR ★★★★★
()
Ответ на: комментарий от AlexVR

Пробовал ли DRM/KMS задействовать.

Что-то вроде такого:

The KMS/DRM backend also supports custom configurations via a JSON file. To enable this, set the QT_QPA_EGLFS_KMS_CONFIG environment variable to the name of the file. You can also embed this file into the application via the Qt resource system.

?

czan
() автор топика
Ответ на: комментарий от AlexVR

Добавь в сборку Qt примеры. А то меня смущает отсутствие полноценного класса окна. Хотя, вроде, и так должно работать. Но есть всякие приколы с одним окном на экран.

Нет. Всё то же самое.

Что удалось нарыть: в Qt за определение фреймбуфера отвечает функция determineFormat из файла qlinuxfbscreen.cpp. Там есть такой участок:

case 32: {
	const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
					 {0, 8, 0}, {24, 8, 0}};
	const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
					 {16, 8, 0}, {24, 8, 0}};
	if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_ARGB32;
	} else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_RGB32;
	} else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_RGB32;
	    // pixeltype = BGRPixel;
	}
	break;
    }

Происходит несовпадение по argb8888 и abgr8888.

Выяснил, что в случае с Jetson Nano, данные по фреймбуферу следующие:

rgba[ 0 ].offset =  16 
rgba[ 0 ].length =  8 
rgba[ 0 ].msb_right =  4189647520 

rgba[ 1 ].offset =  8 
rgba[ 1 ].length =  8 
rgba[ 1 ].msb_right =  4294967232 

rgba[ 2 ].offset =  0 
rgba[ 2 ].length =  8 
rgba[ 2 ].msb_right =  140730144 

rgba[ 3 ].offset =  24 
rgba[ 3 ].length =  8 
rgba[ 3 ].msb_right =  4294967232

Очень похоже на argb8888, но не точно. Что это может быть?

Я переписал участок кода и просто в тупую сделал так:

case 32: {
	const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
					 {0, 8, 0}, {24, 8, 0}};
	const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
					 {16, 8, 0}, {24, 8, 0}};
	if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_ARGB32;
	} else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_RGB32;
	} else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) {
	    format = QImage::Format_RGB32;
	    // pixeltype = BGRPixel;
	} else {format = QImage::Format_ARGB32;}
	break;
    }

Пересобрал Qt и появилась картинка на фреймбуфере!

czan
() автор топика