3.8. sample_vot Usage Instructions

Function Description: The sample_vot example program, based on the DRM framework, implements the following functions:

  1. sample_vot: Read an image or create a frame buffer, fill it with color, and output to HDMI for display

  2. sample_rotation_square: Demonstrates rotation of a square (currently does not support 90-degree or 270-degree rotation of rectangles)

  3. sample_blend: Demonstrates blending of 3 layers

  4. sample_vot_drm_hotplug: Read an image or create a frame buffer, fill it with color, and output to HDMI for display. Supports HDMI hot-plug detection and asynchronous display based on Page Flip

For instructions on connecting HDMI to the development board, refer to the HDMI Interface section.

Note: HDMI driver must be manually loaded first: ./insmode_driver.sh

3.8.1. sample_vot

3.8.1.1. Function Overview

Function Description: sample_vot demonstrates the following functions by accepting different input parameters:

  1. List the resolutions supported by the HDMI display

  2. Read an image and display it via HDMI

  3. Create a frame buffer, fill it with color, and display it via HDMI

Software Architecture Description

display_sample_framework

Code Location and Directory Structure

  • Code location: app/samples/platform_samples/sample_vot

  • Directory structure

sample_vot/
├── Makefile
├── sample_vot
├── sample_vot.c
└── sample_vot.o

API Flow Description

Depending on the input parameters, the processing flow is divided into two cases:

Case Description Characteristics Differences (Function background color in diagram)
Directly display data in memory Allocate memory from the DRM framework Yellow
Read file and display Allocate memory externally and pass to DRM framework Green
sample

sample_vot_data_flow

Functions with background colors in the diagram are wrappers for DRM interfaces. Below is a detailed explanation of each function’s functionality and flow:

  1. __create_and_mmap_drm_frame_buffer (yellow background): Call DRM interface to allocate memory from the DRM framework

  2. __wraper_dma_buffer_to_drm_frame_buffer (green background): Allocate memory externally and pass it to the DRM framework

  3. display_setup: Call DRM interface to obtain an appropriate connector, and set corresponding crtc and connector as needed

  4. __add_property: Call DRM interface to set properties and complete layer display

Below are flowcharts for the four functions mentioned above:

__create_and_mmap_drm_frame_buffer

sample_display_create_buffer

__wraper_dma_buffer_to_drm_frame_buffer

sample_display_wraper_buffer

display_setup

sample_vot_display_setup

__add_property

sample_vot_add_property

3.8.1.2. Compilation and Deployment

Compilation

  • Enter the sample_vot directory and run make to compile

  • The output binary is sample_vot located in the source directory

  • For detailed compilation methods, refer to the Compilation Methods section

Program Deployment

  1. Upload the sample_vot and resource directories to the /userdata directory on the development board

  2. Enter the sample_vot directory and run chmod +x sample_vot to grant execution permission

3.8.1.3. Execution

Execution Method

Run the program: ./sample_vot

Program Parameter Options

  • ./sample_vot -l List the resolutions supported by the connected HDMI display

  • ./sample_vot -f Read ../resource/nv12_1920x1080.yuv and display it on the screen

  • ./sample_vot Create a frame buffer, fill it with RGB data, and display it on the screen

Execution Results

List Resolutions Supported by Display

Command:

./sample_vot -l

Log Output:

Print param Config:
        Function : print connector support resolution.
Print [hdmi] connector support resolution:
  [0] 1920x1080 60.00fps
  [1] 1920x1080 59.94fps
  [2] 1920x1080i 60.00fps
  [3] 1920x1080i 59.94fps
  [4] 1920x1080 50.00fps
  [5] 1920x1080i 50.00fps
  [6] 1920x1080 24.00fps
  [7] 1920x1080 23.98fps
Display Cyclic RGB Background

Command:

./sample_vot

Runtime Log:

Print param Config:
        Function : display.
        Input    : default data (R, G, B).
        Output   :
                 Resolution: select connector's first config from EDID
                 Connector: hdmi
display select resolution :1920*1080 .

Effect Description: The display will cycle through red, green, and blue colors every 2 seconds.

Display Image from File

Command:

./sample_vot -f

Runtime Log:

Print param Config:
        Function : display.
        Input    : file(../resource/nv12_1920x1080.yuv).
        Output   :
                 Resolution: 1920*1080
                 Connector: hdmi
display select resolution :1920*1080 .

Effect Description: The image ../resource/nv12_1920x1080.yuv will be displayed on the screen.

3.8.2. sample_rotation_square

3.8.2.1. Function Overview

Function Description: sample_rotation_square displays a square that rotates cyclically every 2 seconds at 0°, 90°, 180°, and 270°.

Software Architecture Description

sample_rotation_framework

Code Location and Directory Structure

  • Code location: app/samples/platform_samples/sample_rotation_square

  • Directory structure

sample_rotation_square/
├── Makefile
├── sample_rotation_square
├── sample_rotation_square.c
└── sample_rotation_square.o

API Flow Description

sample

sample_rototaion_data_flow

Functions with background colors in the diagram are wrappers for DRM interfaces. Below is a detailed explanation of each function’s functionality and flow:

  1. display_setup (red background): Call DRM interface to obtain an appropriate connector, and set corresponding crtc and connector as needed

  2. find_overlay_plane_id (red background): Traverse all planes to find the one that supports rotation

  3. __create_and_mmap_drm_frame_buffer (yellow background): Call DRM interface to allocate memory from the DRM framework

  4. __destroy_and_unmmap_drm_frame_buffer (yellow background): Call DRM interface to release memory allocated from the DRM framework

  5. __add_property (red background): Call DRM interface to set properties, completing layer rotation and display

display_setup

sample_vot_display_setup

find_overlay_plane_id

sample_display_flow_find_ovrlay_plane_id

__add_property

sample_vot_add_property

__create_and_mmap_drm_frame_buffer

sample_display_create_buffer

__destroy_and_unmmap_drm_frame_buffer

sample_display_destroy_and_unmmap

3.8.2.2. Compilation and Deployment

Compilation

  • Enter the sample_rotation_square directory and run make to compile

  • The output binary is sample_rotation_square located in the source directory

  • For detailed compilation methods, refer to the Compilation Methods section

Program Deployment

  1. Upload the sample_rotation_square and resource directories to the /userdata directory on the development board

  2. Enter the sample_rotation_square directory and run chmod +x sample_rotation_square to grant execution permission

3.8.2.3. Execution

Execution Method

Run the program: ./sample_rotation_square

Program Parameter Options

None

Execution Results

Command:

./sample_rotation_square

Log Output:

Print param Config:
        Output   :
                 Resolution: select connector's first config from EDID
                 Connector: hdmi

display select resolution :1920*1080 .

Effect Description:

  1. The display shows a white square with corners colored red, green, blue, and yellow respectively

  2. The square rotates every 2 seconds in the following sequence: 0°, 90°, 180°, 270°

3.8.3. sample_blend

3.8.3.1. Function Overview

Function Description: sample_blend demonstrates alpha blending of 3 layers before display.

Software Architecture Description

sample_rotation_framework

Code Location and Directory Structure

  • Code location: app/samples/platform_samples/sample_blend

  • Directory structure

sample_blend/
├── Makefile
├── sample_blend
├── sample_blend.c
└── sample_blend.o

API Flow Description

sample

sample_blend_data_flow

Functions with background colors in the diagram are wrappers for DRM interfaces. Below is a detailed explanation of each function’s functionality and flow:

  1. display_setup (red background): Call DRM interface to obtain an appropriate connector, and set corresponding crtc and connector as needed

  2. find_plane_ids (red background): Traverse all planes to find those that support blending

  3. __create_and_mmap_drm_frame_buffer (yellow background): Call DRM interface to allocate memory from the DRM framework

  4. __destroy_and_unmmap_drm_frame_buffer (yellow background): Call DRM interface to release memory allocated from the DRM framework

  5. __add_property (red background): Call DRM interface to set properties, completing multi-layer blending and display

display_setup

sample_vot_display_setup

find_plane_ids

sample_display_find_plane_ids

__add_property

sample_vot_add_property

__create_and_mmap_drm_frame_buffer

sample_display_create_buffer

3.8.3.2. Compilation and Deployment

Compilation

  • Enter the sample_blend directory and run make to compile

  • The output binary is sample_blend located in the source directory

  • For detailed compilation methods, refer to the Compilation Methods section

Program Deployment

  1. Upload the sample_blend directory to the /userdata directory on the development board

  2. Enter the sample_blend directory and run chmod +x sample_blend to grant execution permission

3.8.3.3. Execution

Execution Method

Run the program: ./sample_blend

Program Parameter Options

  • ./sample_blend -m 0 -v 30000 m specifies the blending mode, v specifies the blending value. Detailed parameter descriptions:

  1. Blending value: valid range is 0 - 65535, default is 32767

  2. Blending mode: 0: Pre-multiplied, 1: Coverage, 2: None, default is None

    Pre-multiplied mode: out.rgb = plane_alpha * fg.rgb + (1 - (plane_alpha * fg.alpha)) * bg.rgb

    Coverage mode: out.rgb = plane_alpha * fg.alpha * fg.rgb + (1 - (plane_alpha * fg.alpha)) * bg.rgb

    None mode: out.rgb = plane_alpha * fg.rgb + (1 - plane_alpha) * bg.rgb

Parameter explanations in formulas:

  1. plane_alpha: Blending value (-v specified value / 65535)

  2. fg.alpha: Foreground image alpha value

  3. fg.rgb: Current pixel color value

  4. bg.rgb: Background image color value

Execution Results

Command:

./sample_blend -m 0 -v 30000

Log Output:

Print param Config:
        AplhaBlend Param   :
                Mode    : Coverage
                Formula : out.rgb = plane_alpha * fg.alpha * fg.rgb + (1 - (plane_alpha * fg.alpha)) * bg.rgb
                Value   : 32767
display select resolution :1920*1080 .

Effect Description:

  1. The display shows a white background with three overlapping rectangles in red, green, and blue

  2. Non-overlapping areas blend with the background

  3. Overlapping areas: first blended with the background, then the colors of the two rectangles are blended together

3.8.3.4. Common Issues

  1. Issue 1:

    • Description: When the Linux DRM driver changes, layer IDs may change

    • Solution: Avoid hardcoding layer IDs in programs; instead, match by plane name (e.g., function find_plane_ids)

  2. Issue 2:

  3. Issue 3:

    • Description: After running a demo program, no effect is observed. Need to quickly determine if it’s a hardware issue

    • Solution: Use the command modetest -M vs-drm -a -s 75@31:1920x1080 -P 33@31:1920x1080@NV12. See: DRM Quick Experience

3.8.4. sample_vot_drm_hotplug

3.8.4.1. Function Overview

Function Description: based on sample_vot, sample_vot_drm_hotplug adds HDMI hot-plug detection, a select event loop, and Page Flip-based asynchronous display. It supports automatic reconnection and display resumption after “starting the program first and then plugging in the HDMI cable” or “unplugging and replugging the HDMI cable”. demonstrates the following functions by accepting different input parameters:

  1. List the resolutions supported by the HDMI display

  2. Read an image and display it via HDMI

  3. Create a frame buffer, fill it with color, and display it via HDMI

Software Architecture Description

display_sample_framework

Code Location and Directory Structure

  • Code location: app/samples/platform_samples/sample_vot_drm_hotplug

  • Directory structure

sample_vot_drm_hotplug/
├── sample_vot_drm_hotplug
├── sample_vot_async.c
├── Makefile
├── drm_hotplug.h
└── drm_hotplug.c

API Flow Description

Scenario Background color of text in the figure
HDMI display hot-plug Yellow
DRM Page Flip event Green
sample

sample_vot_drm_hotplug_data_flow

Function descriptions and flow in the figure with colored backgrounds:

  1. setup_udev_drm_monitor (yellow background): Create and initialize a udev listener that only receives device events from the DRM subsystem (such as HDMI hot-plug events).

  2. handle_udev_drm_hotplug (yellow background): Handle a single DRM hot-plug event read from the udev monitor, and determine whether it is an “insert” or “remove” based on the current connector status.

  3. setup_drm_event_context (green background): Initialize the DRM event context drmEventContext, which is used to receive and handle the Page Flip completion events reported by the DRM kernel.

Below are flowcharts for the three functions mentioned above:

setup_udev_drm_monitor

sample_vot_drm_hotplug_udev_setup

handle_udev_drm_hotplug

sample_vot_drm_hotplug_udev_handle

setup_drm_event_context

sample_vot_drm_hotplug_flip

3.8.4.2. Compilation and Deployment

Compilation

  • Enter the sample_vot_drm_hotplug directory and run make to compile

  • The output binary is sample_vot_drm_hotplug located in the source directory

  • For detailed compilation methods, refer to the Compilation Methods section

Program Deployment

  1. Upload the sample_vot_drm_hotplug and resource directories to the /userdata directory on the development board

  2. Enter the sample_vot_drm_hotplug directory and run chmod +x sample_vot_drm_hotplug to grant execution permission

3.8.4.3. Execution

Execution Method

Run the program: ./sample_vot_drm_hotplug

Program Parameter Options

  • ./sample_vot_drm_hotplug -l List the resolutions supported by the connected HDMI display

  • ./sample_vot_drm_hotplug -f Read ../resource/nv12_1920x1080.yuv and display it on the screen

  • ./sample_vot_drm_hotplug Create a frame buffer, fill it with RGB data, and display it on the screen

Execution Results

List Resolutions Supported by Display

Command:

./sample_vot_drm_hotplug -l

Log output:


Print param Config:
        Function : print connector support resolution.
Print [hdmi] connector support resolution:
  [0] 1920x1080 60.00fps
  [1] 1920x1080 59.94fps
  [2] 1920x1080i 60.00fps
  [3] 1920x1080i 59.94fps
  [4] 1920x1080 50.00fps
  [5] 1920x1080i 50.00fps
  [6] 1920x1080 24.00fps
  [7] 1920x1080 23.98fps
Display Cyclic RGB Background and HDMI hot-plug behavior on the monitor

Command:

./sample_vot_drm_hotplug

With HDMI not connected to the board, start the program, then plug in HDMI and unplug it again. Log output:


Print param Config:
        Function : display.
        Input    : default data (R, G, B).
        Output   :
                 Resolution: select connector's first config from EDID
                 Connector: hdmi
search hdmi connector: connector id is 75
display connector type 11 is not connected.
display_setup: no valid mode for connector type 11 (output=hdmi)
display_setup not ready, will wait for connector hotplug in main loop.
DRM hotplug event detected on /dev/dri/card0 (connector_type=11)
DRM connector is now CONNECTED (id=75)
hdmi index: 00 ch:3840 cv:2160 vrefresh:60
hdmi index: 01 ch:3840 cv:2160 vrefresh:60
hdmi index: 02 ch:3840 cv:2160 vrefresh:30
hdmi index: 03 ch:3840 cv:2160 vrefresh:30
hdmi index: 04 ch:3840 cv:2160 vrefresh:25
hdmi index: 05 ch:3840 cv:2160 vrefresh:24
hdmi index: 06 ch:3840 cv:2160 vrefresh:24
hdmi index: 07 ch:2560 cv:1440 vrefresh:60
hdmi index: 08 ch:1920 cv:1080 vrefresh:60
display connector connector found mode info.
display select resolution :1920*1080 .
Connector is now connected, start display.
page flip event: frame=2104 time=8937.489720
page flip event: frame=2225 time=8939.506395
page flip event: frame=2346 time=8941.523063
page flip event: frame=2467 time=8943.539721
page flip event: frame=2588 time=8945.556395
DRM hotplug event detected on /dev/dri/card0 (connector_type=11)
DRM connector is now DISCONNECTED (id=75)

Effect Description:

  • After the program starts, it reports that no HDMI connection is found. After the HDMI cable is plugged in, the program starts displaying frames.

  • During display, Page Flip events are triggered and print log messages.

  • The display will cycle through red, green, and blue colors every 2 seconds.

  • After HDMI is unplugged, the display is disconnected and frame display stops.

Display Image from File and HDMI hot-plug behavior on the monitor

Command:

./sample_vot_drm_hotplug -f

With HDMI connected to the board, start the program, then unplug HDMI and plug it back in. Log output:


Print param Config:
        Function : display.
        Input    : file(../resource/nv12_1920x1080.yuv).
        Output   :
                 Resolution: 1920*1080
                 Connector: hdmi
search hdmi connector: connector id is 75
hdmi index: 00 ch:3840 cv:2160 vrefresh:60
hdmi index: 01 ch:3840 cv:2160 vrefresh:60
hdmi index: 02 ch:3840 cv:2160 vrefresh:30
hdmi index: 03 ch:3840 cv:2160 vrefresh:30
hdmi index: 04 ch:3840 cv:2160 vrefresh:25
hdmi index: 05 ch:3840 cv:2160 vrefresh:24
hdmi index: 06 ch:3840 cv:2160 vrefresh:24
hdmi index: 07 ch:2560 cv:1440 vrefresh:60
hdmi index: 08 ch:1920 cv:1080 vrefresh:60
display connector connector found mode info.
display select resolution :1920*1080 .
page flip event: frame=4379 time=9518.206396
DRM hotplug event detected on /dev/dri/card0 (connector_type=11)
DRM connector is now DISCONNECTED (id=75)
DRM hotplug event detected on /dev/dri/card0 (connector_type=11)
DRM connector is now CONNECTED (id=75)
hdmi index: 00 ch:3840 cv:2160 vrefresh:60
hdmi index: 01 ch:3840 cv:2160 vrefresh:60
hdmi index: 02 ch:3840 cv:2160 vrefresh:60
hdmi index: 03 ch:3840 cv:2160 vrefresh:30
hdmi index: 04 ch:3840 cv:2160 vrefresh:30
hdmi index: 05 ch:3840 cv:2160 vrefresh:25
hdmi index: 06 ch:3840 cv:2160 vrefresh:24
hdmi index: 07 ch:3840 cv:2160 vrefresh:24
hdmi index: 08 ch:2560 cv:1440 vrefresh:60
hdmi index: 09 ch:1920 cv:1080 vrefresh:60
display connector connector found mode info.
display select resolution :1920*1080 .
Connector is now connected, start display.
page flip event: frame=4985 time=9533.806383

Effect Description:

  • After the program starts, it reports that a display connection is found and begins displaying frames. The monitor shows the image ../resource/nv12_1920x1080.yuv on the screen.

  • After HDMI is unplugged, the display is disconnected and frame display stops.

  • After HDMI is plugged in again, it reports that a display connection is found and resumes displaying the image.