Basic steps of SCREEN programming
Here we take the ssplash application in the Qualcomm 8155 software baseline as an example for analysis.
Basic process:
Introducing these steps, we will introduce two problems in screen application programming from the two dimensions of why and how : why do you want to do this? How to do?
1. Wait for the /dev/screen node
why : The screen application depends on the screen service, so it must wait for the screen service to be ready.
how : You can use the waitfor or waitfor_attach interface to wait for the screen directory node to be generated (the generation of the screen directory node means that the screen service is ready), for example, the waitfor_attach interface used below waits for the screen service to be ready, and the timeout period is 5000ms.
/*Wait till "/dev/screen" shows up */
waitfor_attach ( "/dev/screen", 5000 );
2. Create screen context
Why: All screen API interfaces (except screen events) need to interact with the screen server through the context, so the first step in screen programming is to create a screen context to establish a connection between the application and the screen.
how: Please refer to the code below. There are various types of parameter flags required by the interface. For ordinary screen applications, select SCREEN_APPLICATION_CONTEXT. If you need power on display, you also need to set SCREEN_POWER_MANAGER_CONTEXT. The meaning of these two flags is: this is an application-level screen program with power on display permissions. For other flag information, please refer to Screen con in the developer manual. text types section .
screen_context_t screen_ctx;
/*Create a screen context*/
if ( EOK != ( rc = screen_create_context(&screen_ctx,
SCREEN_APPLICATION_CONTEXT |
SCREEN_POWER_MANAGER_CONTEXT )))
{
ERROR("screen_create_context(0x%x) failed, err=%d",
SCREEN_APPLICATION_CONTEXT|SCREEN_POWER_MANAGER_CONTEXT,
errno);
goto exit1;
}
3. Create a render target
why : It can be understood as the target you want to render through the screen. If the target needs to be displayed on the screen, it is usually a window window. If it does not need to be displayed on the screen, it can be a stream/pixmap.
how : Refer to the following example to create a windows instance.
/*Create a window on which we will show the splash*/
if ( EOK != ( rc = screen_create_window(&screen_win, screen_ctx))) {
ERROR("create win failed, err=%d", errno ) ;
goto exit3;
}
4. Set the target attribute
Why: Similar to framebuffer programming, you need to configure parameters for the target you want to display, such as display position, size, alpha, etc.
how: Refer to the example below.
if ( EOK != ( rc = screen_get_window_property_iv(screen_win,
SCREEN_PROPERTY_BUFFER_SIZE, rect+2)))
{
ERROR("GET SCREEN_PROPERTY_SIZE failed, err=%d", errno);
goto exit4;
}
position[0] = dims[0]/2 - rect[2]/2;
position[1] = dims[1]/2 - rect[3]/2;
if ( EOK != ( rc = screen_set_window_property_iv(screen_win,
SCREEN_PROPERTY_POSITION , position )))
{
ERROR("SET SCREEN_PROPERTY_POSITION failed, err=%d", errno);
goto exit4;
}
if ( EOK != ( rc = screen_set_window_property_iv(screen_win,
SCREEN_PROPERTY_STATIC , &static_content)))
{
ERROR("SET SCREEN_PROPERTY_STATIC failed, err=%d", errno);
goto exit4;
}
5. Create a render buffer
why : used to store the image data content to be displayed
how : Refer to the code below
/*Create one buffer*/
if (EOK != (rc = screen_create_window_buffers(screen_win, 1))){
ERROR("screen_create_window_buffers(1) failed, err=%d", errno);
goto error;
}
6,render target
why : render may be the most complicated part of the screen. There are many ways to implement render here, and there are also various operations, such as re-sizing the screen, using GPU to render and modify the content data of the screen, etc.
how : Refer to Chapter 3 Rendering in the developer manual
7. Push the rendered data
why : Push the rendered data to the screen
how : refer to the following code
/*Final call to post the window*/
if (EOK != ( rc = screen_post_window(screen_win,
screen_buf, 1, rect, 0)))
{
ERROR("screen_post_window failed, err=%d",errno);
goto exit4;
}
8. Handle input events (if necessary)
reference
https://blog.csdn.net/suixing_yuan/category_10911939.html
QNX 7.0 SCREEN Developer Manual_norlan_jame's Blog-CSDN Blog