As a rendering component, XComponent can be used to meet your requirements for advanced custom rendering, such as displaying camera preview streams and rendering game images. Problems such as black screen and frame freezing may occur during XComponent-based rendering. This document provides troubleshooting guidance from three aspects: XComponent Rendering Principles, Positioning Tool Chain for Image Rendering, and Typical Case Analysis.
XComponent is responsible for creating the surface and notifying the app of surface-related information through callbacks. Apps can set the properties of the surface through dedicated APIs. It should be noted that the component itself has no awareness of the actual drawn content and does not provide direct rendering APIs. The following figure shows the architecture of XComponent rendering.

XComponent holds a surface. You can call the APIs of the NativeWindow module to apply for and submit a buffer to the image queue, thereby transferring the custom drawing content to the surface. The following figure shows the main process.

The following figure shows the data flow.

After the preceding process is complete, the self-rendered content of the app can be displayed in the surface held by XComponent. XComponent integrates the surface into the UI, and the displayed content is the self-drawn content you sent. The default position and size of the surface are the same as those of XComponent. You can use the setXComponentSurfaceRect() API to customize the position and size of the surface.
Search for XComponent in the log to obtain the component ID, triggering information of onSurfaceCreated() and onLoad(), and surface ID obtained through getXComponentSurfaceId(), as shown in the following figure.

Search for C01401 or Bufferqueue in the log to obtain the image rendering exception information and the corresponding error code. For details about the error codes, see OHNativeErrorCode. The following figure shows the exception information.

Obtain the component tree information by referring to Obtaining an Application Component Tree. Then, search for XComponent to obtain the XComponent information, as shown in the following figure.

Obtain the Render Service information by referring to Obtaining System Service Details, as shown in the following figure.

You can run the hdc shell "hidumper -s RenderService -a allInfo" command to obtain information about the surface and RS tree at the same time.
1. Obtain the RS tree information.
The RS tree indicates the rendering tree information converted by Render Service based on the UI component tree. Run the hdc shell "hidumper -s RenderService -a RSTree" > RSTree.dump command to obtain the RS tree information, and then search for SURFACE_NODE to obtain the node information corresponding to XComponent, as shown in the following figure.

2. Obtain the surface information.
Run the hdc shell "hidumper -s RenderService -a surface" > surface.dump command to obtain the surface information, and then search for XComponent id and Surface id of XComponent to obtain surface and image queue information corresponding to XComponent, as shown in the following figure.

For details, see Checking Frame Data Statistics of All Processes.
For details, see Analyzing Frame Data.
Symptom
After NativeWindow is obtained from XComponent through the OnSurfaceCreated() API of OH_NativeXComponent, NativeWindow is passed to the rendering child thread for use. When the page exits and XComponent is destroyed, a crash occurs.
Possible causes
Solution
Symptom
The background of the content drawn using XComponent is transparent, but only the content drawn at the first layer can be seen in the cascading layout.
Possible causes
If your custom drawn content includes transparent elements, they will blend with the content below the surface. If the transmitted content is completely transparent and the background color of XComponent is set to black, a black area will be displayed, and the content below the cascading layout will be invisible.
Solution
Set backgroundColor of XComponent to transparent.
Symptom
When XComponent is used for rendering, a black screen is displayed.
Possible causes
Solution
Symptom
During page switching, the image rendered by XComponent flickers.
Possible causes
XComponent is destroyed and recreated, or the attributes of XComponent change.
Solution
Check whether the information about the XComponent node in the UI tree and RS tree changes, for example, the ID, width, height, background color, and transparency attributes. For details, see Image Rendering Information Query Using Hidumper.
Symptom
The buffer is obtained from the NativeWindow corresponding to XComponent and is drawn. After the buffer is displayed, the screen is blurred or screen tearing occurs.
Possible causes
When OH_NativeWindow_NativeWindowRequestBuffer() is used to obtain the buffer, a fence file descriptor (fenceFd) is returned. fenceFd is a file descriptor created by the consumer process and indicates whether the consumer has finished consuming the buffer. The producer can start filling the buffer only after the consumer has finished consuming the buffer. Otherwise, problems such as screen blur and screen tearing may occur.
Solution
After calling OH_NativeWindow_NativeWindowRequestBuffer(), wait until the value of fenceFd is -1 (indicating that the consumer has finished consuming the buffer) and then write the produced content to the buffer. For details, see NativeWindow Development (C/C++).
Symptom
The buffer is obtained from the NativeWindow corresponding to XComponent and then drawn. Frame freezing occurs during continuous rendering.
Possible causes
Solution
Symptom
When OH_NativeImage_AcquireNativeWindowBuffer() is used to obtain a buffer and OH_NativeImage_ReleaseNativeWindowBuffer() is used to return the buffer after consumption, memory leakage still occurs.
Possible causes
Solution