Files
minigui-docs/programming-guide/MiniGUIProgGuidePart3Chapter05.md
2019-12-25 15:17:27 +08:00

8.7 KiB
Raw Blame History

Integrating with GPU

Introduction

The graphics stack on Linux has had a long evolution.

Initially, graphics applications on Linux mainly used the old SVGALib; the Linux kernel did not provide any driver for graphics or GPU. In 2000s, the Linux kernel introduced the frame buffer driver to support the various graphics devices. However, the frame buffer driver did not provide a good implementation to support modern GPUs. If a software want to use the powerful GPU functions to render 3D objects, it has to write a lot of code for a specific GPU in application space. For desktop systems, it is not a problem, because the XFree86 project provided a complete graphics stack for 2D/3D rendering. But it is a nightmare for embedded systems.

Around 2010, the Free Destkop project introduced a new graphics stack for Linux system called DRI (Direct Rendering Infrastructure). As the name suggests, DRI provides applications with the ability to directly access the GPU for 2D/3D rendering. With or without X Window, applications can get the direct GPU rendering capabilities through DRI. This greatly improves the performance and user experience of Linux desktop systems.

After more than ten years of development, DRI technology has matured. Now, Linux-based desktop systems have switched from the traditional frame buffer driver to DRI. And the Linux-based embedded systems are switching from frame buffer to DRI.

Therefore, we introduced the support DRI in MiniGUI version 4.0.4, and developed the EGL implementation for MiniGUI based on Mesa, also the MiniGUI backend for Cairo.

Now, it is very easy to integrate MiniGUI with your GPU. Your MiniGUI app can exploit the GPU accelerated functions to render 2D/3D objects.

Architecture and Infrastructure

In practice, MiniGUI and the software which are used to integrated with GPU constitute the graphics stack of HybridOS.

HybridOS is a totally new open source operating system designed for smart IoT devices and cloud computing environment. FMSoft Technologies, the developer of MiniGUI, initiated HybridOS project in 2018.

HybridOS uses MiniGUI as the underlying windowing system, and the members of HybridOS project are now maintaining the whole graphics stack.

The following chart shows the graphics stack of HybridOS:

  -----------------------------------------------
 |           MiniGUI/HybridOS Apps               |
 |-----------------------------------------------|
 |           |         (Graphics Stack)          |
 |           |              ---------------------|
 |           |              | hiMesa             |
 |           | hiCairo      |  ------------------|
 |           | MiniGUI      |  | EGL for MiniGUI |
 | C++ libs  | hiDRMDrivers |  | GL, GLES, VG    |
 | C libs    | hiDRM        |  | GPU drivers     |
 |-----------------------------------------------|
 |  Linux Kernel                                 |
 |            -----------------------------------|
 |           |        DRI and DRI Drivers        |
  -----------------------------------------------

As shown in the chart above, the HybridOS graphics stack consists of the following software:

  • hiDRM is the LibDRM derivative for HybridOS.
  • hiDRMDrivers contains the drivers for MiniGUI DRM engine. The drivers implement the basic hardware acclerated graphics operations of various GPUs for MiniGUI.
  • hiMesa is the Mesa derivative for HybridOS, while Mesa is the open source implementation of OpenGL and other graphics APIs, including OpenGL ES (versions 1, 2, 3), OpenCL, OpenMAX, and Vulkan. It contains the following components:
    1. The implementatin of OpenGL, OpenGL ES (v1, 2, 3), and other graphics APIs.
    2. The EGL implementation for MiniGUI platform.
    3. The graphics drivers for various GPUs and a software driver called swrast.
  • hiCairo is the Cairo derivative for HybridOS. Cairo is a 2D vector graphics library for Gtk. We provide support for MiniGUI backend in hiCairo.

You can use the following script to fetch the source code of above software:

#!/bin/bash

# Use this if you want to visit GitHub via HTTPS
REPO_URL=https://github.com/FMSoftCN

# Use this one if you can visit GitHub via SSH
#REPO_URL=git@github.com:FMSoftCN

# Use this one if you are a developer of MiniGUI/HybridOS
#REPO_URL=git4os@gitlab.fmsoft.cn:hybridos

git clone $REPO_URL/hidrm -b hybridos
git clone $REPO_URL/hidrmdrivers
git clone $REPO_URL/himesa -b minigui-backend
git clone $REPO_URL/hicairo -b minigui-backend

NOTE The above fetching script may changed in the future.

The software all ship with the GNU autotools building scripts or the meson building scripts. You can refer to the README file for the instructions to build and install the software to your system.

Please note that the installation order of the software:

  1. hiDRM.
  2. MiniGUI with DRM engine enabled.
  3. hiDRMDrivers.
  4. hiMesa with support for MiniGUI platform enabled.
  5. hiCairo with MiniGUI backend enabled.

The EGL Implementation for MiniGUI

The following words give the official definition for EGL:

EGL™ is an interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system. It handles graphics context management, surface/buffer binding, and rendering synchronization and enables high-performance, accelerated, mixed-mode 2D and 3D rendering using other Khronos APIs. EGL also provides interop capability between Khronos to enable efficient transfer of data between APIs for example between a video subsystem running OpenMAX AL and a GPU running OpenGL ES.

Obviously, to integrate OpenGL and other graphics APIs with MiniGUI, we must implement EGL for MiniGUI.

As mentioned before, Mesa uses DRI to drive various GPUs and implement the graphics APIs. Basically, the EGL implementation for MiniGUI depends on the DRM engine of MiniGUI.

The EGL implementation for MiniGUI in Mesa is a sub driver of egl_dri2, which supports many platforms including x11, wayland, drm, and surfaceless.

On the other hand, if one MiniGUI instance was not using DRM engine, the EGL implementation for MiniGUI can still use the software driver in Mesa to render the graphics objects.

For more information about EGL, please refer to:

New APIs for GPU integration

3D Rendering on MiniGUI

Cairo and MiniGUI


<< Using mGPlus for Vector Graphics | Table of Contents | Using mGEff for Visual Effects and Animations >>