6. Platform
The MicroEJ platform for i.MX RT595 EVK Rev. C1 has been built against the MicroEJ Architecture for Cortex M33 (version 7.14.0) and the UI extension pack (version 13.0.3). This extension pack provides the library MicroUI-3.0 and this library has been designed:
- to replace a set of basic shapes renderings using a GPU instead of using software algorithms;
- to be extended by third-party UI libraries.
The MicroEJ platform for i.MX RT595 EVK Rev. C1 provides some additional extended UI libraries to target the GCNanoLiteV GPU:
- VGLite : This library exposes the VGLite APIs to draw Vector Graphics. It allows to draw paths with either plain color (opaque and transparent) or gradient. It also allows to dynamically apply matrix transformations to the rendered paths (translation, scale, rotation, perspective).
- VectorFont: This library allows to draw strings using TTF fonts. The rendered text can filled with plain color or gradient. The text baseline can follow a line or a curve.
![digraph structs {
rankdir=LR
node [shape=record];
struct3 [label="Application |{ {Widget|MWT|MicroUI}|{VGLite Util|VGLite} | VectorFont}| Platform | {Software Algorithms|Hardware (GPU)}"];
}](../_images/graphviz-e3aba361a900e7198ae162151661ee943c87bca7.png)
6.1. MicroUI Drawings
MicroUI provides several basic shapes rendering (pixel oriented). MicroEJ platform for i.MX RT595 EVK Rev. C1 overrides weak implementation (which performs the drawing in software) to use the GPU. The drawings are using the vg_lite APIs (i.e. vg_lite_blit
, vg_lite_draw
, …). The following functions are hardware accelerated (under circonstances):
Shapes
- UI_DRAWING_fillRectangle
- UI_DRAWING_fillRoundRectangle
- UI_DRAWING_fillCircle
- UI_DRAWING_fillEllipse
- UI_DRAWING_fillCircleArc
- UI_DRAWING_fillEllipseArc
- DW_DRAWING_drawThickFadedPoint (fade == 1)
- DW_DRAWING_drawThickFadedLine (fade == 1)
- DW_DRAWING_drawThickFadedCircle (fade == 1)
- DW_DRAWING_drawThickFadedCircleArc (fade == 1)
- DW_DRAWING_drawThickFadedEllipse (fade == 1)
- DW_DRAWING_drawThickLine
- DW_DRAWING_drawThickCircle
- DW_DRAWING_drawThickEllipse
- DW_DRAWING_drawThickCircleArc
Images
- UI_DRAWING_drawImage (image not transparent)
- DW_DRAWING_drawFlippedImage (full image and not transparent)
- DW_DRAWING_drawRotatedImageNearestNeighbor (image not transparent)
- DW_DRAWING_drawRotatedImageBilinear (image not transparent)
- DW_DRAWING_drawScaledImageNearestNeighbor (image not transparent)
- DW_DRAWING_drawScaledImageBilinear (image not transparent)
MicroUI manages several RAW formats. A subset of these RAW formats is supported by the VG Lite blit
feature:
MicroUI RAW format | Bits per pixel | blit compatible format |
---|---|---|
ARGB8888 | 32 | VG_LITE_RGBA8888 |
RGB888 | 24 | |
RGB565 | 16 | VG_LITE_RGB565 |
ARGB1555 | 16 | VG_LITE_RGBA5551 |
ARGB4444 | 16 | VG_LITE_RGBA4444 |
A1 | 1 | |
A2 | 2 | |
A4 | 4 | VG_LITE_A4 |
A8 | 8 | VG_LITE_A8 |
C1 | 1 | |
C2 | 2 | |
C4 | 4 | |
AC11 | 2 | |
AC22 | 4 | |
AC44 | 8 | |
LARGB8888 | 8 | |
LRGB888 | 8 |
6.2. VG Lite Library
The i.MX RT595 EVK Rev. C1 provides a native and a simulator implementation of the VGLite foundation library.
Both of these implementation support:
- The Vector Graphics APIs:
vg_lite_draw
vg_lite_draw_grad
- All matrix transformations.
For more detail about the VG Lite foundation library see: VG Lite Library.
Note
Clipping is managed using the MicroUI GraphicsContext setClip API.
6.2.1. Native Implementation
The VGLite foundation library is implemented over the vg_lite native library which uses the GCNanoLiteV GPU of the i.MX RT595 EVK Rev. C1.
Note
When a clip is applied to a MicroUI GraphicsContext, it will be internally managed using vg_lite scissor APIs.
6.2.2. Simulator Implementation
The MIMXRT595-VEE-IAR83 Virtual Device uses the Desktop rendering vector capabilities to render the MicroUI API for SVG, OpenVG, TrueType.
Note
The virtual device runs over Java2D which support vector graphics via Path2D. The default Java2D rendering quality is used and the following information are ignored:
- VGLite path bounding box,
- VGLite drawing quality.
Warning
The following blending algorithms are not supported.
- VG_LITE_BLEND_SCREEN,
- VG_LITE_BLEND_MULTIPLY,
- VG_LITE_BLEND_ADDITIVE.
6.3. VectorFont Library
The VectorFont add-on library contains seven native methods which are implemented on board and simulator:
VectorFont.init()
: initializes the FreeType library which is used.VectorFont.loadTrueTypeFont(...)
: loads the font data from the file.VectorFontPainter.drawStringNative(...)
: draws a string.VectorFontPainter.drawStringArcNative(...)
: draws a curved string.VectorFont.stringWidthNative(...)
: computes the width (in pixels) of the string boundig box.VectorFontPainter.drawCharNative(...)
: draws a character.VectorFont.charWidthNative(...)
: computes the width (in pixels) of the character boundig box.LinearGradient.initNative(...)
: allocates a new gradient in memory.LinearGradient.closeNative(...)
: closes the gradient resource.
6.3.1. Native Implementation
The VectorFont native methods have been implemented in the low-level LLVECTOR_FONT
library. It is in
charge of the drawing algorithms: for each character of the string to draw, the corresponding glyph is
extracted using the FreeType library. A transformation matrix is computed
for each glyph to determine the character size and position on the screen based on the glyph metrics. A
renderer module for FreeType engine, called ftvglite
, has been developped to render glyphs with the
VG Lite library. The transformation matrix and color information (alpha, gradient) to apply are set to
the renderer.
![digraph {
node [shape = box];
LL [label="LLVECTOR_FONT"];
FT [label="FreeType"];
VG [label="ftvglite"]
LL -> FT [label="character", fontsize=8];
LL -> VG [label="transformations,\ncolors", fontsize=8];
FT -> LL [label="metrics", fontsize=8];
FT -> VG [label="render", fontsize=8];
}](../_images/graphviz-1df24b59f8c5fd11045f3165d6beeee4115670b4.png)
Note
The ftvglite
renderer is based on
Smooth rasterer from the FreeType
project. It has been modified to use VG Lite to render glyphs with the GPU.
Here is a brief summary of the LLVECTOR_FONT
natives:
VectorFont.init()
- is called at application startup. It initializes the FreeType library and sets the VG Lite renderer as font renderer.
VectorFont.loadTrueTypeFont(...)
- loads a font file from the given path and returns a handle of the allocated object. The font is loaded by the FreeType engine. A loaded font cannot be deallocated.
VectorFontPainter.drawStringNative(...)
- draws a string loading each glyph character by character by FreeType library and rendering its outline with the VG Lite engine. Kerning information is used if available to compute character advance. VG Lite matrix implementation is used to compute transformations applied to each characters (translation, rotation, scaling).
VectorFontPainter.drawStringArcNative(...)
:- draws a string around a circle arc. It uses almost the same techniques as
drawStringNative(...)
except that the transformations applied to each character are different. VectorFont.stringWidthNative(...)
- computes the string with the same algorithm as
drawStringNative(...)
but without rendering. VectorFontPainter.drawCharNative(...)
- draws a character loading its glyph with FreeType library and rendering its outline with the VG Lite engine. VG Lite matrix implementation is used to compute transformations applied to the character (translation, rotation, scaling).
VectorFont.charWidthNative(...)
- computes the character with the same algorithm as
drawCharNative(...)
but without rendering. LinearGradient.initNative(...)
:- allocates a new VG Lite gradient in memory.
LinearGradient.closeNative(...)
:- closes the gradient resource.
Note
FreeType is a free font engine written in C which supports many vector font formats. At the moment the VectorFont library only supports TrueType fonts (TTF).
6.3.2. Simulator
The implementation in the simulator relies on Java2D API which natively support TrueType fonts and gradient colors.
The drawString
methods (and the equivalent drawChars
) directly uses Graphics2D.drawChars
from Java 2D API to
render text. The curved text implementation follows the same algorithm as the C native implementation and uses the
VG Lite Library implementation in the simulator to manage transformations.
Antialiasing is enabled on text rendering for drawString
and on global rendering for drawStringArc
.
VectorFont.init()
- does nothing on simulator.
VectorFont.loadTrueTypeFont(...)
- loads a font file from the given path and returns a handle of the allocated object. It creates a new
java.awt.Font
with the given size which is stored in a map to be retrieved by its handle. VectorFontPainter.drawStringNative(...)
- draws a string loading each glyph character by character directly using Graphics2D.drawChars from Java 2D API.
Text antialiasing is set with
RenderingHints.VALUE_TEXT_ANTIALIAS_ON
. VectorFontPainter.drawStringArcNative(...)
:- draws a string around a circle arc. It uses almost the same techniques as
drawStringNative(...)
except that for each character it extracts its shape and applies transformations with the transformation matrix from VG Lite Java API. The shape is then drawn withGraphics2D.fill
. Antialiasing is applied on shapes (RenderingHints.VALUE_ANTIALIAS_ON
). VectorFont.stringWidthNative(...)
- computes the string width as the sum of all its characters width.
VectorFontPainter.drawCharNative(...)
- draws a character by extracting its shape and applying the given transformation matrix. The shape is then drawn with
Graphics2D.fill
. Antialiasing is applied on the shape (RenderingHints.VALUE_ANTIALIAS_ON
). VectorFont.charWidthNative(...)
- returns the character bounding box width.
LinearGradient.initNative(...)
:- allocates a new instance of
java.awt.LinearGradientPaint
. LinearGradient.closeNative(...)
:- releases the gradient reference.