Graph drawing method, apparatus, terminal device, and storage medium
Patent Information
- Application Number
- CN202611164577.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-10-20
AI Technical Summary
然而,此类手动优化方式粒度较粗,难以覆盖绘制指令序列中细粒度的单个绘制操作,且对于已发布或无法修改源代码的应用,无法在系统层面实现无效绘制的自动识别和处理
[0011]本申请实施例中,在真实绘制之前,采用检测型画布遍历当前帧的绘制指令序列,获取绘制指令序列中多个绘制操作的元数据,该检测型画布用于接收绘制调用但不执行真实绘制,从而能够在不产生任何实际像素绘制的条件下提前获得各绘制操作的绘制信息,为后续无效绘制的识别提供数据基础且不影响正常的渲染流程;然后,根据多个绘制操作的绘制顺序,对多个绘制操作的元数据进行逆序可见性分析,确定被后续不透明绘制操作完全遮挡的目标绘制操作,能够按照从后向前的绘制顺序逐层累积覆盖区域,精确识别出对最终画面无贡献的绘制操作,若目标绘制操作满足预设安全跳过条件,则为目标绘制操作设置跳过标记,能够在几何覆盖分析的基础上进一步结合绘制属性信息进行安全性校验,仅当跳过该绘制操作不会改变最终显示结果时才允许其被标记,从而在保证显示正确性的前提下实现无效绘制的识别,最后,在执行绘制指令序列时,跳过具有跳过标记的目标绘制操作,使得真实绘制阶段无需执行对最终画面无贡献的绘制操作,减少绘制指令的执行数量,降低渲染过程中的计算开销和资源消耗。本申请方案通过检测遍历、逆序覆盖分析、安全条件判定和标记跳过的相互配合,在不依赖人工优化且不修改应用代码的前提下自动识别和跳过绘制指令序列中的无效绘制操作,同时保障最终显示画面的正确性,有效降低图形渲染过程中因无效绘制导致的资源消耗。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This application relates to the field of smart terminal technology, and in particular to a graphics drawing method, apparatus, terminal device, and storage medium. Background Technology
[0002] During the rendering process of a graphical user interface, the displayed content is organized into a series of drawing operations, which are executed sequentially during rendering to generate the final image. In scenarios involving complex interfaces, page transitions, or pop-up overlays, some of the earlier drawing operations, although submitted and executed, may not contribute to the final image, resulting in invalid drawing during the rendering process. The presence of invalid drawing increases the number of rendering instructions executed, leading to additional computational overhead and bandwidth pressure, and may potentially cause a decrease in frame rate and an increase in power consumption.
[0003] Currently, dealing with such invalid drawing operations typically relies on developers manually optimizing the view hierarchy during the application development phase, such as reducing layout nesting and merging background drawings. However, this manual optimization method is coarse-grained and cannot cover the fine-grained individual drawing operations in the drawing instruction sequence. Furthermore, for applications that have already been released or whose source code cannot be modified, it is impossible to achieve automatic identification and handling of invalid drawing at the system level.
[0004] Therefore, how to automatically identify and handle invalid rendering, and reduce resource consumption caused by invalid rendering during graphics rendering, is a problem that needs to be addressed. Summary of the Invention
[0005] This application provides a graphics drawing method, apparatus, terminal device, and storage medium that can automatically identify and process invalid drawings, reducing resource consumption caused by invalid drawings during graphics rendering.
[0006] In a first aspect, embodiments of this application provide a graphic drawing method, including: A detection-type canvas is used to traverse the drawing instruction sequence of the current frame to obtain metadata of multiple drawing operations in the drawing instruction sequence. The detection-type canvas is used to receive drawing calls but does not perform actual drawing. Based on the drawing order of the multiple drawing operations, reverse visibility analysis is performed on the metadata of the multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations. If the target drawing operation meets the preset safe skip condition, then a skip flag is set for the target drawing operation; When executing the drawing instruction sequence, target drawing operations with the skip flag are skipped.
[0007] Secondly, embodiments of this application provide a graphics drawing apparatus, comprising: The metadata acquisition unit is used to traverse the drawing instruction sequence of the current frame using a detection canvas to acquire metadata of multiple drawing operations in the drawing instruction sequence. The detection canvas is used to receive drawing calls but does not perform actual drawing. The target determination unit is used to perform reverse visibility analysis on the metadata of the multiple drawing operations according to the drawing order of the multiple drawing operations, and determine the target drawing operation that is completely occluded by the subsequent opaque drawing operation. A marker setting unit is used to set a skip marker for the target drawing operation if the target drawing operation meets a preset safe skip condition; A drawing processing unit is configured to skip target drawing operations with the skip flag when executing the drawing instruction sequence.
[0008] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the graphics drawing method as described in the first aspect above.
[0009] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the graphics drawing method described in the first aspect above.
[0010] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the graphics drawing method described in the first aspect above.
[0011] In this embodiment, before actual drawing, a detection canvas is used to traverse the drawing instruction sequence of the current frame to obtain metadata of multiple drawing operations in the drawing instruction sequence. This detection canvas is used to receive drawing calls but does not execute actual drawing, thereby obtaining the drawing information of each drawing operation in advance without generating any actual pixel drawing, providing a data basis for the identification of subsequent invalid drawing without affecting the normal rendering process. Then, according to the drawing order of multiple drawing operations, reverse visibility analysis is performed on the metadata of multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations, and the coverage area can be accumulated layer by layer according to the drawing order from back to front. This approach accurately identifies drawing operations that do not contribute to the final display. If a target drawing operation meets preset safety skipping conditions, a skip flag is set for it. Based on geometric coverage analysis, this approach further combines drawing attribute information for safety verification. A drawing operation is only allowed to be marked if skipping it will not change the final display result. This ensures display correctness while identifying invalid drawing. Finally, when executing the drawing instruction sequence, target drawing operations with skip flags are skipped, eliminating the need to execute drawing operations that do not contribute to the final display during the actual drawing stage. This reduces the number of drawing instructions executed and lowers computational overhead and resource consumption during rendering. This application's solution, through the coordinated use of detection traversal, reverse coverage analysis, safety condition judgment, and skipping flags, automatically identifies and skips invalid drawing operations in the drawing instruction sequence without relying on manual optimization or modifying application code. Simultaneously, it ensures the correctness of the final display and effectively reduces resource consumption caused by invalid drawing during graphics rendering. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a flowchart illustrating the implementation of the graphics drawing method provided in this application embodiment; Figure 2 This is a flowchart illustrating a specific implementation of step S101 in the graphic drawing method provided in this application embodiment; Figure 3 This is a flowchart illustrating a specific implementation of step S102 in the graphic drawing method provided in this application embodiment; Figure 4 This is a flowchart illustrating a specific implementation of step S104 in the graphics drawing method provided in this application embodiment; Figure 5This is a flowchart illustrating a specific implementation of consistency verification in the graphics drawing method provided in this application embodiment; Figure 6 This is a flowchart illustrating a specific implementation of the detection strategy reuse evaluation in the graphics drawing method provided in this application embodiment; Figure 7 This is a structural block diagram of the graphics drawing device provided in the embodiments of this application; Figure 8 This is a schematic diagram of the terminal device provided in the embodiments of this application. Detailed Implementation
[0014] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0015] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0016] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0017] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0018] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0019] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0020] By way of example and not limitation, the graphics drawing method provided in this application is applicable to various types of terminal devices that need to perform graphics drawing. Specific terminal devices may include mobile phones, tablets, wearable devices, laptops, ultra-mobile personal computers (UMPCs), desktop computers, interactive large screens, and servers, etc. This application does not impose any restrictions on the specific type of terminal device.
[0021] Figure 1 The implementation flow of the graphics drawing method provided in this application embodiment is illustrated. The method flow includes steps S101 to S104. The specific implementation principle of each step is as follows: Step S101: Use a detection canvas to traverse the drawing instruction sequence of the current frame and obtain the metadata of multiple drawing operations in the drawing instruction sequence. The detection canvas is used to receive drawing calls but does not perform actual drawing.
[0022] A drawing instruction sequence refers to a set of drawing instructions recorded by the view layer or rendering node. It contains multiple drawing operations arranged in drawing order, with each drawing operation corresponding to a specific drawing instruction, such as drawing a rectangle, drawing a path, drawing a bitmap, or drawing text. During the rendering process of the current frame, the drawing instruction sequence records all drawing operations that potentially contribute to the current frame's display.
[0023] In a conventional rendering process, the drawing function corresponding to each drawing operation is called when traversing the drawing instruction sequence, and pixel data is submitted to the rendering target to generate the final image. In this embodiment, a detection canvas is introduced as a traversal tool before actual drawing. The detection canvas is used to traverse the drawing instruction sequence of the current frame and obtain metadata of multiple drawing operations in the drawing instruction sequence. The detection canvas is a special canvas object used to receive drawing calls but not to perform actual rasterization. The detection canvas can receive drawing calls from the drawing instruction sequence traversal process, but after receiving a drawing call, the detection canvas does not submit pixel data to the rendering target, nor does it trigger the graphics processor's drawing execution; that is, it does not perform actual drawing. The detection canvas is only used to collect relevant information about each drawing operation.
[0024] In one possible implementation, the rendering context parameters of the current frame are obtained, and a detection canvas is constructed based on the rendering context parameters. The matrix state and clipping region state of the detection canvas are consistent with the real canvas.
[0025] Rendering context parameters refer to the set of parameters related to the canvas state during the rendering process of the current frame. This set of parameters can include information such as the transformation matrix, clipping region, render target size, transparency flag, and color space flag for the current frame. The transformation matrix describes the mapping relationship between the drawing operation and the device coordinate system. The clipping region limits the effective drawing area of the drawing operation; the drawing portion exceeding the clipping region will be clipped and will not generate pixels.
[0026] The real canvas refers to the canvas object used to perform actual drawing. This canvas object is bound to a rendering target (such as a framebuffer or surface). When drawing operations are performed on the real canvas, actual pixel data is generated and written to the rendering target. The state of the real canvas includes the current transformation matrix and clipping region, which determine the final position and effective range of subsequent drawing operations.
[0027] When constructing the detection canvas, its matrix state and clipping region state are set according to the rendering context parameters of the current frame. This ensures that the matrix state and clipping region state of the detection canvas are consistent with those of the real canvas. Consistent matrix states mean that the detection canvas and the real canvas have the same current transformation matrix, enabling drawing operations to be transformed from local coordinates to the same device coordinate space. Consistent clipping region states mean that the detection canvas and the real canvas have the same current clipping region, allowing the same clipping constraints to be applied to drawing operations. Furthermore, the detection canvas's save / restore stack state and drawing attributes are synchronized with the real canvas. After construction, the detection canvas presents a drawing interface consistent with a regular (real) canvas and can be used to receive drawing calls. However, since the detection canvas is not bound to any rendering target, it does not generate any pixel data or submit drawing results to any buffer when receiving drawing calls.
[0028] For example, at the frame rendering entry point, the transformation matrix and clipping region of the current frame are first obtained. A detection canvas is constructed based on this transformation matrix and clipping region, and the matrix of the detection canvas is set to this transformation matrix, and the clipping region of the detection canvas is set to this clipping region. This detection canvas has the same matrix state and clipping region state as the real canvas used in subsequent actual rendering. In this way, when the drawing instruction sequence is traversed using the detection canvas, the coordinate transformation and clipping processing of each drawing operation are completely consistent with the actual drawing stage, thereby ensuring that the valid drawing area in the obtained metadata corresponds to the actual drawing area in the actual drawing stage.
[0029] In one possible implementation, the detection canvas can be any of the following: a canvas subclass, a proxy canvas, a non-real drawing canvas, or a drawing instruction sequence accessor.
[0030] One possible implementation of the detection canvas includes inheriting a base canvas class that does not perform drawing, or intercepting drawing calls through a proxy canvas, and only recording relevant information about the drawing calls without submitting rasterization instructions to the rendering backend.
[0031] As one possible implementation of this application Figure 2 A specific implementation flow of step S101 in the graphics drawing method provided in this application embodiment is shown below: A1: Intercept the drawing calls during the traversal of the drawing instruction sequence.
[0032] During the process of traversing the drawing instruction sequence of the current frame using a detection-type canvas, each drawing operation in the drawing instruction sequence triggers its corresponding drawing call in sequence according to its drawing order. A drawing call is an interface instruction issued by the canvas object to request the execution of a specific drawing action, such as requesting to draw a rectangle, requesting to draw a bitmap, or requesting to draw text.
[0033] The detection canvas intercepts drawing calls during the traversal process. Intercepting drawing calls means that each drawing call issued in the sequence of drawing instructions is received by the detection canvas, not the actual canvas. The detection canvas receives and responds to these drawing calls, but does not perform the corresponding rasterization operations. That is, it does not submit pixel data to the rendering backend according to the normal drawing process. Instead, it extracts the drawing operation information carried in the drawing calls, such as drawing type, drawing area coordinates, transformation matrix parameters, and drawing attribute parameters, for use in the subsequent generation of metadata.
[0034] For example, when the drawing instruction sequence traverses to a drawing rectangle operation, the drawing rectangle function corresponding to the drawing rectangle operation is called. The detection canvas, as the current canvas object, receives the call to the drawing rectangle function, extracts the rectangle boundary coordinates and drawing attributes contained in the drawing rectangle operation, but does not actually fill or stroke the rectangle.
[0035] A2: Generate corresponding metadata for each drawing operation, wherein the metadata is used to characterize the drawing attribute information of the drawing operation.
[0036] Metadata refers to descriptive data records associated with a drawing operation, used to characterize the drawing attributes of that operation. For each intercepted drawing call, the detection canvas generates corresponding metadata based on the drawing information contained in the drawing call. Metadata may include drawing operation type, local boundary information, effective drawing area information, drawing parameter information, layer status information, and drawing order information, etc.
[0037] In one possible implementation, the drawing operation type indicates the type of drawing performed by the drawing operation, including at least one of the following: rectangle drawing, rounded rectangle drawing, path drawing, bitmap drawing, text drawing, region drawing, drawing element drawing, or rendering node drawing. Local boundary information indicates the boundary range of the drawing operation in the local coordinate system. Effective drawing area information indicates the effective drawing area after the drawing operation undergoes matrix transformation and intersects with the clipping region; this effective drawing area represents the range of screen pixels that the drawing operation may actually affect in device coordinate space. Drawing parameter information may include transparency values, blending modes, shader effect parameters, image filtering parameters, masking filtering parameters, and color filtering parameters. Layer status information indicates whether the drawing operation is located within a layer composition operation, including the drawing instruction sequence hierarchy path where the drawing operation is located, and the relevant attributes of the layer. The hierarchy path indicates the recursive path of the drawing operation in the view hierarchy or nested drawing element structure, and can uniquely identify the hierarchy position of a drawing operation. Drawing order information indicates the position of the drawing operation in the drawing instruction sequence, including the drawing sequence number of the drawing operation in the drawing instruction sequence.
[0038] In this embodiment, by intercepting drawing calls, the detection canvas can collect complete information about each drawing operation without the participation of the real canvas. This ensures that the detection traversal phase and the actual drawing phase maintain a consistent traversal order at the drawing call level, while avoiding any pixel writing to the actual rendering target. The detection canvas organizes the scattered drawing information intercepted during the traversal process into structured metadata according to a preset data structure, and associates this metadata with the corresponding drawing operation. Without affecting the normal rendering process, it obtains complete drawing information for each drawing operation in the drawing instruction sequence in advance, providing a data foundation for subsequent identification of completely occluded invalid drawing operations.
[0039] Step S102: Based on the drawing order of the multiple drawing operations, perform reverse visibility analysis on the metadata of the multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations.
[0040] The drawing order refers to the sequence of drawing operations within the drawing instruction sequence. When drawing operations are executed in this order, later drawing operations overlap earlier ones, so subsequent drawing operations appear visually in front of earlier ones. When a subsequent drawing operation is completely opaque and its drawing area completely covers the drawing area of a previous drawing operation, the drawing result of the previous operation is completely occluded and contributes nothing to the final image. The target drawing operation is the drawing operation in the drawing instruction sequence that is determined to be completely occluded by a subsequent opaque drawing operation.
[0041] Reverse visibility analysis refers to analyzing the occlusion relationships between drawing operations in reverse order of execution, starting with the last drawn operation and proceeding backward. Specifically, it first analyzes the last drawn operation in the order, then the second-to-last, and so on, until the first drawn operation is analyzed. This reverse analysis method corresponds to the actual process of image compositing. The purpose of reverse visibility analysis is to use the metadata of drawn operations to track and accumulate opaque coverage areas in reverse order, accurately identifying those drawn operations that, although located within the clipping area, are completely occluded by subsequent opaque drawn operations and thus contribute nothing to the final image.
[0042] As one possible implementation of this application Figure 3 A specific implementation flow of step S102 in the graphics drawing method provided in this application embodiment is shown below: B1: Following the reverse order of the drawing operations, traverse each drawing operation backward from the last drawn operation.
[0043] During the reverse traversal, the starting point of the traversal is the drawing operation that is drawn last in the drawing instruction sequence, that is, the last drawing operation drawn and the drawing operation located at the top layer in the picture; then, it proceeds forward in turn, processing the drawing operations that are drawn earlier in the drawing order, until the drawing operation that is drawn first in the drawing instruction sequence has been processed.
[0044] By traversing in reverse order, it can be ensured that when analyzing each drawing operation, all drawing operations drawn after it have been analyzed and their coverage area information has been recorded. This reverse traversal method allows coverage area information to be accumulated and passed down layer by layer from the top, providing the correct data flow for the accurate calculation of subsequent remaining visible areas.
[0045] For example, suppose the drawing instruction sequence of the current frame contains four drawing operations, numbered sequentially from front to back as Operation 1, Operation 2, Operation 3, and Operation 4. Operation 1 is drawn first and located at the bottom layer of the screen; Operation 4 is drawn last and located at the top layer of the screen. When traversing in reverse order, start with Operation 4, then traverse Operation 3, Operation 2, and finally Operation 1. By using this reverse traversal order, the coverage of each operation can be analyzed layer by layer from the top layer down.
[0046] B2: Based on the effective drawing area and the set of opaque covered areas of the currently traversed drawing operation, determine the remaining visible area of the currently traversed drawing operation. The set of opaque covered areas is used to record the pixel area covered by the traversed drawing operation from the current traversal position to the top layer.
[0047] The effective drawing area is the region in device coordinate space that the currently traversed drawing operation, after transformation by the transformation matrix and intersection with the clipping region, may actually affect screen pixels. The clipping region limits the effective drawing range of the drawing operation on the screen; any portion exceeding the clipping region will be clipped and will not generate pixels. The effective drawing area is equal to the intersection of the area covered by the drawing operation in device coordinate space and the clipping region. The effective drawing area can be obtained from the metadata corresponding to the drawing operation.
[0048] In one possible implementation, the opaque overlay region set is a dynamically maintained set of region data during the reverse traversal. During the reverse traversal, after each drawing operation is processed, if the drawing operation meets a preset overlay condition, the opaque pixel region actually covered by that drawing operation is added to the opaque overlay region set. As the traversal progresses from the topmost drawing operation, the opaque overlay region set continuously accumulates and expands, representing the pixel region commonly covered by all subsequent drawing operations that have been confirmed to be safely opaque, moving from the current traversal position towards the top of the screen. When processing any given drawing operation, the opaque overlay region set records all pixel regions covered by all subsequent drawing operations located above that drawing operation, which have been traversed and confirmed to be safely opaque.
[0049] The remaining visible area is the pixel region within the effective drawing area of the currently traversed drawing operation that is not covered by the set of opaque overlay regions. The remaining visible area is determined by subtracting the area covered by the set of opaque overlay regions from the effective drawing area; the remaining area is the remaining visible area. When the remaining visible area is empty, it means that the effective drawing area is completely contained within the set of opaque overlay regions, meaning that the entire drawing area of this drawing operation has been completely obscured by the upper-level opaque drawing operation. When the remaining visible area is not empty, it means that some areas within the effective drawing area are still not covered by the upper-level opaque drawing operation, and this drawing operation still contributes to the final image.
[0050] The remaining visible area is determined by comparing the effective drawing area with the set of opaque covered areas. The cumulative coverage of subsequent opaque drawing operations is accurately compared with the drawing range of the current drawing operation, which can provide a quantitative basis for judging whether the current drawing operation is completely occluded.
[0051] For example, suppose that when reversing to operation two, operations three and four have already been traversed and confirmed as opaque drawing operations, and the set of opaque overlay regions has recorded the pixel areas jointly covered by operations three and four. The effective drawing area of operation two is a rectangular area in the center of the screen. The effective drawing area of operation two is compared with the set of opaque overlay regions to calculate the remaining visible area. If the effective drawing area of operation two falls entirely within the set of opaque overlay regions, the remaining visible area is empty; if a portion of the effective drawing area of operation two is not covered by the set of opaque overlay regions, that portion is the remaining visible area.
[0052] In one possible implementation, after determining the remaining visible area, if the currently traversed drawing operation satisfies the opaque coverage condition, for example, the transparency value of the drawing operation is completely opaque and the blending mode is a mode that does not produce a blending effect with the lower layer, then the drawing operation has the ability to cover earlier drawn operations. The effective drawing area of the drawing operation is added to the set of opaque coverage areas for the visibility analysis of subsequent earlier drawn operations.
[0053] B3: If the remaining visible area is empty, then the drawing operation currently being traversed is determined to be the target drawing operation.
[0054] An empty residual visible area means that the difference between the effective drawing area of the currently traversed drawing operation and the set of opaque covered areas is empty. In other words, all effective drawing areas of this drawing operation are covered by subsequent opaque drawing operations. When the residual visible area is empty, no pixels are visible in the final image after this drawing operation, and its execution process does not contribute to the final display. In this case, the drawing operation is determined as the target drawing operation.
[0055] In one possible implementation, if the remaining visible area is not empty, the drawing operation has a portion that contributes to the final image and cannot be identified as a target drawing operation that is completely occluded; it still needs to be executed during the actual drawing stage. Simultaneously, when the drawing attribute of the drawing operation indicates that it is opaque and meets preset coverage conditions, the opaque area of the drawing operation is added to the set of opaque coverage areas for use during subsequent forward traversal.
[0056] In this embodiment, the opaque coverage area is gradually accumulated from the top layer of the screen in reverse order. When each drawing operation is traversed, the existing coverage area is used to determine whether the remaining visible area is empty, thereby accurately identifying the target drawing operation that is completely occluded, providing a basis for skipping invalid drawing operations while ensuring display correctness.
[0057] Step S103: If the target drawing operation meets the preset safe skip condition, then set a skip flag for the target drawing operation.
[0058] Preset safe skip conditions are a set of conditions used to determine whether a target drawing operation is allowed to be skipped. Their purpose is to ensure that skipping an operation does not change the correctness of the final displayed image. Even if a drawing operation is geometrically completely covered by a subsequent opaque drawing operation, if the drawing operation has certain visual characteristics, skipping the drawing operation may still have a perceptible impact on the final image. Preset safe skip conditions are used to exclude such cases, allowing skipping only when the skipping operation does not affect the final display result.
[0059] The skip flag is used to indicate that a specific drawing operation should be skipped in the subsequent actual drawing phase.
[0060] In one possible implementation, the skip flag can be stored in the visibility field of the structure corresponding to the target drawing operation in the drawing instruction sequence, or it can be stored in a mapping table between the drawing operation index and the visibility result.
[0061] In one possible implementation, the preset safety skip conditions may include: the drawing attributes of the target drawing operation indicate that it does not have a transparency effect, that is, the transparency value indicates that it is completely opaque; the drawing attributes of the target drawing operation indicate that it is in source overlay mode or source mode, does not use a special blending mode, and will not produce a blending effect with the underlying pixels; the drawing attributes of the target drawing operation indicate that it does not contain visual effect processing operations, such as shader processing operations, image filtering processing operations, mask filtering processing operations, or color filtering processing operations; the drawing attributes of the target drawing operation indicate that it does not contain layer compositing operations, does not involve off-screen compositing layers with visual side effects, such as not containing operations that combine layers after rendering them off-screen; and the target drawing operation is not a text drawing operation.
[0062] When the drawing attributes of a target drawing operation simultaneously meet the aforementioned preset safe skip conditions, it indicates that the drawing operation does not possess characteristics that produce visual side effects, and skipping the drawing operation will not change the final display result. In this case, a skip flag is set for the target drawing operation. Conversely, if the target drawing operation does not meet any of the aforementioned preset safe skip conditions, a skip flag is not set for the target drawing operation, and even if it is geometrically completely occluded, it remains visible and is executed normally during the actual drawing phase to ensure display correctness.
[0063] For example, suppose the aforementioned background rectangle has been identified as the target drawing operation, but its transparency value in its drawing properties is less than the opaque value, meaning the background rectangle is drawn semi-transparently. Skipping this semi-transparent background rectangle would cause the underlying pixels to not be blended correctly, changing the final display effect. In this case, the target drawing operation does not meet the preset safe skip condition, so no skip flag is set for it, and it still needs to be executed normally in the actual drawing stage.
[0064] In one possible implementation, setting a skip flag for the target drawing operation includes: storing the skip flag in the drawing operation structure of the drawing instruction sequence; or, storing the skip flag in a separate visibility mapping table based on the mapping information of the target drawing operation, wherein the visibility mapping table is used to establish the correspondence between drawing operations and skip flags.
[0065] In this embodiment of the application, by setting a skip flag, a security check is performed by combining the attribute information of the drawing operation with the geometric analysis. The flag is only allowed when skipping will not affect the final display result, thereby identifying invalid drawing operations that can be safely skipped while ensuring the correctness of the display.
[0066] Step S104: When executing the drawing instruction sequence, skip the target drawing operation with the skip mark.
[0067] Executing the drawing instruction sequence refers to entering the actual drawing stage, where each drawing operation in the drawing instruction sequence is submitted to the rendering backend to generate the final pixel image. During the execution of the drawing instruction sequence, each drawing operation is traversed sequentially from beginning to end according to its original drawing order, processing each operation one by one while maintaining the original drawing order to ensure consistency between the occlusion relationships and the image hierarchy.
[0068] As one possible implementation of this application Figure 4 A specific implementation flow of step S104 in the graphics drawing method provided in this application embodiment is shown below: C1: Traverse the drawing instruction sequence using the actual canvas.
[0069] In this embodiment, after completing the detection traversal, reverse visibility analysis, and skip flag setting, the actual drawing stage begins. During the execution of the drawing instruction sequence for actual drawing, a real canvas is used to traverse the drawing instruction sequence and execute each drawing operation. The detection-type canvas receives drawing calls but does not perform actual drawing during the detection traversal stage, while the real canvas receives drawing calls and submits pixel data to the rendering backend, such as to the graphics processor for rasterization processing, to generate the final display image.
[0070] During the actual rendering phase, a real canvas bound to the rendering target is acquired, and this real canvas is used to traverse the rendering instruction sequence of the current frame. During this traversal, each rendering function call in the rendering instruction sequence is received by the real canvas, which performs the corresponding rasterization operation and generates pixel data which is then written to the rendering target. The order in which the rendering instruction sequence is traversed using the real canvas is consistent with the order in which the rendering instruction sequence is traversed using the detection canvas, ensuring that the execution order of each rendering operation in the actual rendering phase is consistent with that in the detection phase.
[0071] C2: When the current drawing operation being iterated over has the skip flag, skip the execution of the current drawing operation and continue to traverse the next drawing operation.
[0072] For each drawing operation encountered during iteration, determine whether it has a skip flag. If it does, skip the drawing operation directly, do not call the corresponding drawing function, do not submit it to the rendering backend for drawing, and continue to the next drawing operation; if it does not have a skip flag, execute the drawing operation normally, and submit the pixel data to the rendering backend for drawing.
[0073] For example, when the real canvas is traversed to operation two, if it is found that operation two has a skip flag, then the drawing of operation two is not executed, and operation two is skipped directly, continuing to traverse operation three. If operation three does not have a skip flag, then the drawing call of operation three is executed normally, and the pixel data of operation three is submitted to the rendering backend. The final image only contains the drawing results of operation one, operation three, and operation four. The drawing result of operation two is not presented, and the final image is visually consistent with the image when operation two is not skipped, because operation two has been analyzed and confirmed to be completely occluded by subsequent opaque drawing operations during the detection and traversal phase.
[0074] In this embodiment of the application, during the actual drawing stage, the drawing operations to be executed in the actual drawing stage are selected according to the skip flag. This ensures that drawing operations that are determined to be completely obscured by subsequent opaque drawing operations and meet safety conditions are excluded from the execution scope of the actual drawing stage. This eliminates the need to execute drawing operations that do not contribute to the final image during the actual drawing stage, effectively reducing the number of drawing instructions executed, thereby reducing the computational overhead and resource consumption during the rendering process.
[0075] As one possible implementation of this application, after using the detection-type canvas traversal drawing instruction sequence and completing the visibility analysis, and before executing the drawing instruction sequence in the actual drawing phase, it is necessary to verify the consistency between the detection traversal phase and the actual drawing phase to ensure that there is a correct correspondence between the drawing operation corresponding to the skipped flag and the drawing operation to be executed in the actual drawing phase.
[0076] Figure 5This paper illustrates a specific implementation flow of consistency verification in the graphics drawing method provided in an embodiment of this application, which is described in detail below: D1: Obtain the current mapping information of the current drawing operation to be drawn. The current mapping information is used to establish the correspondence between the metadata recorded in the detection traversal stage and the drawing operation in the actual drawing stage.
[0077] The current mapping information includes the current drawing instruction sequence version number, the current drawing operation sequence number, the drawing operation type, and the hierarchical path.
[0078] Mapping information is identifying data used to establish the correspondence between drawing operations between the detection traversal phase and the actual drawing phase. During the detection traversal phase, when traversing the drawing instruction sequence using a detection-based canvas, corresponding metadata is generated for each drawing operation, and corresponding mapping information is also generated and recorded. Before executing the drawing instruction sequence in the actual drawing phase, the current mapping information for the current drawing operation to be drawn is obtained.
[0079] The current mapping information is used to establish the correspondence between the metadata recorded in the detection traversal phase and the drawing operations in the actual drawing phase. Through the mapping information, the skip flags obtained from the analysis of a certain drawing operation in the detection traversal phase can be accurately mapped to the same drawing operation in the actual drawing phase, avoiding incorrect application of skip flags due to changes in the drawing instruction sequence between the detection traversal phase and the actual drawing phase.
[0080] In one possible implementation, during the detection traversal phase, mapping information is generated for each drawing operation in the drawing instruction sequence. This mapping information is determined based on the hierarchical path to which the drawing operation belongs, the version number of the drawing instruction sequence, the sequential position of the drawing operation in the drawing instruction sequence, and the drawing operation type of the drawing operation.
[0081] When there are nested drawing instruction sequences or child rendering nodes in the interface, drawing operations in the same order may exist in different levels of drawing instruction sequences.
[0082] Hierarchical paths distinguish between drawing operations that are in the same position but are actually different at different levels by recording the complete path from the root drawing instruction sequence to the drawing instruction sequence containing the current drawing operation. For example, a hierarchical path can be represented as the third drawing operation in a sub-drawing instruction sequence under the root drawing instruction sequence.
[0083] The version number of a drawing instruction sequence is an identifier used to identify the version of the content of the drawing instruction sequence. When drawing operations in the drawing instruction sequence are added, deleted, rearranged, or their attributes are changed, the version number of the drawing instruction sequence is updated accordingly. The version number can be used to determine whether the drawing instruction sequence has changed between the detection traversal phase and the actual drawing phase.
[0084] The sequential position of a drawing operation within a drawing instruction sequence refers to its order number within the sequence, i.e., the drawing sequence number. This sequential position uniquely identifies a drawing operation within the same drawing instruction sequence.
[0085] The drawing operation type is used to help verify the correspondence of drawing operations and avoid incorrect correspondence between operations with the same order but different types.
[0086] This mapping information allows for the accurate association of skip markers generated during the detection traversal phase with the corresponding drawing operations in the actual drawing phase. The consistency of the drawing operations can be verified by comparing the mapping information between the two phases.
[0087] D2: Perform a consistency check between the current mapping information and the mapping information recorded during the detection canvas traversal phase.
[0088] Consistency verification refers to comparing the current mapping information obtained in the actual drawing phase with the mapping information recorded and stored in the detection traversal phase item by item to determine whether the two are consistent.
[0089] During the detection traversal phase, when using the detection-based canvas traversal to draw the instruction sequence, mapping information is generated and recorded for each drawing operation. This recorded mapping information is associated with the corresponding metadata and visibility analysis results. The current mapping information is then compared with the mapping information recorded during the detection traversal phase.
[0090] Specifically, the comparison involves checking whether the version numbers of the drawing instruction sequence are consistent. Consistent version numbers indicate that the drawing instruction sequence has not undergone any content changes between the detection traversal phase and the actual drawing phase. The comparison also involves checking whether the sequence numbers of the drawing operations are consistent. Consistent sequence numbers indicate that the position of the drawing operation in the drawing instruction sequence has not changed. The comparison further involves checking whether the types of the drawing operations are consistent. Consistent types indicate that the type of drawing operation at that position has not changed. Finally, the comparison involves checking whether the hierarchical paths are consistent. Consistent hierarchical paths indicate that the position of the drawing operation in the nested hierarchical structure has not changed.
[0091] By performing a consistency check, we verify that the analysis basis of the detection traversal phase is still valid before applying the skip flag, thus preventing skip errors caused by changes in the drawing instruction sequence after detection.
[0092] D3: When the consistency check passes, execute the step of skipping the target drawing operation with the skip mark.
[0093] When all the above comparison results are consistent, the consistency check passes, indicating that the drawing instruction sequence and the drawing operations within it targeted by the detection traversal stage and the actual drawing stage are the same. The skip flag generated in the detection traversal stage can be safely applied to the actual drawing stage. At this time, when executing the drawing instruction sequence, target drawing operations with skip flags are skipped, while drawing operations without skip flags are drawn normally.
[0094] D4: If the consistency check fails, cancel all skip operations in this frame and execute all drawing operations.
[0095] If any of the above comparison results are inconsistent—for example, if the version number, sequence number, drawing operation type, hierarchical path, total number of drawing operations, or save / restore state stack—the consistency check fails. A failed consistency check indicates a difference between the detection traversal phase and the actual drawing phase. The drawing instruction sequence may have been modified after the detection traversal phase, and the analysis results of the detection traversal phase may no longer be applicable to the current drawing instruction sequence. Skip markers may not accurately correspond to drawing operations in the actual drawing phase, and continuing to use the original skip markers may lead to incorrect skipping behavior, affecting the correctness of the final displayed image. In this case, all skip operations based on skip markers in the current frame are canceled, i.e., all skip markers generated during the detection traversal phase are ignored. All drawing operations in the drawing instruction sequence are executed normally in their drawing order, and each drawing operation is submitted to the rendering backend for drawing to ensure the correctness of the final displayed image.
[0096] In this embodiment, before executing the drawing instruction sequence, the analysis results of the detection traversal stage and the drawing operations of the actual drawing stage are checked for consistency. When the consistency check passes, the skip flag is applied normally to reduce rendering resource consumption. When the detection results do not match the actual situation and the consistency check fails, the original drawing path is rolled back to ensure display correctness. This improves rendering efficiency while ensuring the reliability of the final screen output.
[0097] As one possible implementation of this application, in a scenario with multi-frame continuous rendering, the drawing instruction sequence of adjacent frames may have content continuity, and the drawing instruction sequence does not change in every frame. To improve detection efficiency and reduce the overhead of the detection traversal stage, Figure 6 A specific implementation flow of the detection strategy reuse evaluation in the graphics drawing method provided in this application embodiment is shown below: E1: Obtain the status information of the drawing instruction sequence, the status information being used to indicate whether the drawing instruction sequence has changed.
[0098] The state information of a drawing instruction sequence is descriptive information used to characterize whether the drawing instruction sequence has changed in the current frame relative to the previous frame. The drawing instruction sequence may remain unchanged between frames, or it may be modified due to interface content updates, animation playback, user interaction, or window size changes. The state information is used to record state changes related to the drawing results of the drawing instruction sequence, in order to determine whether the visibility analysis results of the previous frame are still valid in the current frame.
[0099] In one possible implementation, the status information may include one or more of the following: content version number of the drawing instruction sequence, transformation matrix version number, clipping region version number, and visibility analysis version number.
[0100] The content version number identifies the version of each drawing operation and its order within the drawing instruction sequence, indicating whether the content of the drawing operations in the sequence has changed, such as whether any drawing operations have been added, deleted, or modified. The content version number is updated when drawing operations in the drawing instruction sequence are added, deleted, rearranged, or their drawing attributes are changed. A change in the content version number indicates that the content of the drawing instruction sequence has been modified, and the visibility analysis results of the previous frame are no longer applicable.
[0101] The transformation matrix version number identifies the version of the transformation matrix associated with a drawing operation in a drawing instruction sequence, indicating whether the transformation matrix corresponding to the drawing operation has changed. Changes to the transformation matrix affect the effective drawing area of the drawing operation in device coordinate space. When the transformation version number changes, even if the content of the drawing instruction sequence remains the same, the effective drawing area of each drawing operation may change, leading to alterations in occlusion relationships.
[0102] The clipping region version number identifies the version of the clipping region associated with a drawing operation in the drawing instruction sequence, indicating whether the clipping region corresponding to the drawing operation has changed. Changes in the clipping region affect the effective drawing area range of the drawing operation. When the clipping version number changes, the effective drawing area of each drawing operation may differ from the previous frame.
[0103] The visibility analysis version number identifies the version of the visibility analysis result itself, indicating whether the previous visibility analysis result is still valid. When any of the above version numbers changes, the visibility analysis version number is updated accordingly, indicating that the visibility analysis result of the previous frame has become invalid.
[0104] By obtaining the state information of the drawing instruction sequence, it is possible to determine whether the drawing instruction sequence has changed and the specific type of change, thereby providing a basis for judging whether the detection traversal needs to be re-executed.
[0105] In one possible implementation, the state information of the drawing instruction sequence can be obtained based on the rendering context parameters at the frame rendering entry point. For example, the state information can be determined based on the comparison result of the rendering context parameters of the current frame and the previous frame.
[0106] E2: If the status information indicates that the drawing instruction sequence has not changed, reuse the visibility analysis results of the previous frame.
[0107] When the status information indicates that the drawing instruction sequence has not changed, it means that the content, position, and drawing attributes of each drawing operation in the current frame's drawing instruction sequence are exactly the same as those in the previous frame, and the clipping region of the current frame is also the same as that of the previous frame. Therefore, the visibility analysis results of the previous frame still hold true in the current frame. In this case, there is no need to re-execute the detection-type canvas traversal and reverse visibility analysis. The visibility analysis results of the previous frame can be directly reused, including the target drawing operations and corresponding skip flags determined in the previous frame, and applied to the actual drawing stage of the current frame.
[0108] By reusing the visibility analysis results of the previous frame, the repeated execution of detection traversal and visibility analysis can be avoided, reducing the processing overhead of the detection stage during each frame rendering process, and further reducing resource consumption during the rendering process.
[0109] E3: If the status information indicates that the drawing instruction sequence has changed, re-execute the step of using a detection-type canvas to traverse the current frame of the drawing instruction sequence and obtain the metadata of multiple drawing operations in the drawing instruction sequence.
[0110] When the status information indicates a change in the drawing instruction sequence—for example, a change in the content version number indicating the addition, deletion, or modification of drawing operations; a change in the transformation matrix version number indicating a change in the position or size of the drawing operation; or a change in the clipping region version number indicating a change in the effective drawing range—the visibility analysis results of the previous frame may no longer be applicable to the current frame. In this case, the detection-type canvas traversal of the current frame's drawing instruction sequence is re-executed to obtain metadata for multiple drawing operations. Based on the newly obtained metadata, a reverse visibility analysis and skip flag setting are performed again to ensure that the visibility analysis results of the current frame accurately reflect the actual coverage relationship of each drawing operation in the current frame.
[0111] Specifically, the re-execution process includes: traversing the drawing instruction sequence of the current frame using a detection-type canvas to obtain the metadata of each drawing operation in the current frame's drawing instruction sequence; performing reverse visibility analysis on the metadata according to the drawing order to determine the target drawing operations that are completely occluded by subsequent opaque drawing operations; and setting skip flags for target drawing operations that meet preset safe skip conditions. The regenerated metadata and skip flags will replace the corresponding data from the previous frame and be applied to the actual drawing stage of the current frame.
[0112] In this embodiment, during the rendering of multiple consecutive frames, the state information is used to determine whether the drawing instruction sequence has changed. If the drawing instruction sequence has not changed, the visibility analysis result of the previous frame is directly reused to reduce detection overhead. If the drawing instruction sequence has changed, the detection traversal is re-executed to ensure the accuracy of the visibility analysis result. This achieves dynamic optimization of the detection strategy, reduces the overhead of the detection stage while ensuring the accuracy of visibility analysis, and balances detection efficiency and skip accuracy in dynamic rendering scenarios.
[0113] In one possible implementation, if the currently traversed drawing operation is a drawing element type or a nested node type, the system enters the sub-drawing instruction sequence. It then recursively traverses each sub-drawing operation in the sub-drawing instruction sequence according to the original drawing order, recording the parent-child hierarchical path information in the metadata. The drawing element type refers to the current drawing operation being a drawable type, which can contain sub-drawing operations. The nested node type refers to the current drawing operation being a render node type, which also contains sub-drawing instruction sequences.
[0114] When the detection canvas encounters a drawing operation of a drawing element type or a nested node type, this drawing operation itself is not a single graphics drawing instruction, but rather a container containing one or more sub-drawing operations. In this case, the detection canvas enters the sub-drawing instruction sequence corresponding to this drawing operation and recursively traverses each sub-drawing operation according to the original drawing order recorded in the sub-drawing instruction sequence. Specifically, for each sub-drawing operation in the sub-drawing instruction sequence, if the sub-drawing operation itself is still a drawing element type or a nested node type, it continues to traverse the next level of sub-drawing instruction sequence contained in the sub-drawing operation, and so on, until the lowest level single graphics drawing operation is reached. During the traversal, the detection canvas records parent-child hierarchical path information in the metadata. This parent-child hierarchical path information is used to indicate the hierarchical relationship of each drawing operation in the nested structure, so that subsequent visibility analysis can accurately correspond to the drawing operations at each level.
[0115] In one possible implementation, when the execution of the drawing instruction sequence traverses to a nested node containing a skip flag, the sub-drawing operations with skip flags in the sub-drawing instruction sequence corresponding to the nested node are skipped.
[0116] During the actual drawing phase, the drawing instruction sequence is traversed using the actual canvas. When a nested node is encountered, it is first checked whether the nested node contains a skip flag. If the nested node has a skip flag, the drawing execution of each sub-drawing operation with the skip flag is skipped when traversing the sub-drawing instruction sequence corresponding to the nested node. For sub-drawing operations without a skip flag, their drawing function calls are executed normally to complete pixel drawing. In this way, invalid sub-drawing operations within nested nodes can also be skipped during the actual drawing phase, and the skipping granularity reaches the sub-drawing operation level, rather than the entire nested node level. For nested nodes without a skip flag, their internal sub-drawing operations are executed normally according to the original drawing order.
[0117] The aforementioned nested processing method extends the scope of invalid drawing skipping from a single-level drawing instruction sequence to drawing elements and rendering node structures containing multiple levels of nesting. This allows invalid sub-drawing operations at each level to be skipped during the actual drawing stage for complex interfaces with hierarchical nesting relationships. It enables cross-level invalid drawing identification and skipping, further expanding the applicability of the method and reducing the number of drawing operations that need to be performed during the actual drawing stage.
[0118] As can be seen from the above, in this embodiment, before actual drawing, a detection canvas is used to traverse the drawing instruction sequence of the current frame to obtain metadata of multiple drawing operations in the drawing instruction sequence. This detection canvas is used to receive drawing calls but does not execute actual drawing, thereby enabling the drawing information of each drawing operation to be obtained in advance without generating any actual pixel drawing, providing a data basis for the identification of subsequent invalid drawing without affecting the normal rendering process. Then, according to the drawing order of multiple drawing operations, reverse visibility analysis is performed on the metadata of multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations, which can be accumulated layer by layer according to the drawing order from back to front. The system accurately identifies drawing operations that do not contribute to the final display. If a target drawing operation meets preset safety skipping conditions, a skip flag is set for it. Based on geometric coverage analysis, this system further combines drawing attribute information for safety verification. A drawing operation is only allowed to be marked if skipping it will not change the final display result. This ensures display correctness while identifying invalid drawing. Finally, when executing the drawing instruction sequence, target drawing operations with skip flags are skipped, eliminating the need to execute drawing operations that do not contribute to the final display during the actual drawing stage. This reduces the number of drawing instructions executed and lowers computational overhead and resource consumption during rendering. This application's solution, through the combined use of detection traversal, reverse coverage analysis, safety condition judgment, and skipping flags, automatically identifies and skips invalid drawing operations in the drawing instruction sequence without relying on manual optimization or modifying application code. This ensures the correctness of the final display and effectively reduces resource consumption caused by invalid drawing during graphics rendering.
[0119] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0120] Corresponding to the graphic drawing method described in the above embodiments, Figure 7 A structural block diagram of the graphics drawing apparatus provided in the embodiments of this application is shown. For ease of explanation, only the parts related to the embodiments of this application are shown.
[0121] Reference Figure 7 The graphics drawing device includes: a metadata acquisition unit 71, a target determination unit 72, a marker setting unit 73, and a drawing processing unit 74, wherein: Metadata acquisition unit 71 is used to traverse the drawing instruction sequence of the current frame using a detection canvas to acquire metadata of multiple drawing operations in the drawing instruction sequence. The detection canvas is used to receive drawing calls but does not perform actual drawing. The target determination unit 72 is used to perform reverse visibility analysis on the metadata of the multiple drawing operations according to the drawing order of the multiple drawing operations, and determine the target drawing operation that is completely occluded by the subsequent opaque drawing operation. The marker setting unit 73 is used to set a skip marker for the target drawing operation if the target drawing operation meets the preset safe skip conditions; The drawing processing unit 74 is configured to skip the target drawing operation with the skip mark when executing the drawing instruction sequence.
[0122] As one possible implementation of this application, the metadata acquisition unit 71 is specifically used for: Intercept the drawing calls during the traversal of the drawing instruction sequence; Generate corresponding metadata for each drawing operation, the metadata being used to characterize the drawing attribute information of the drawing operation.
[0123] As one possible implementation of this application, the target determination unit 72 is specifically used for: Following the reverse order of the drawing operations, traverse each drawing operation backward from the last drawing operation. Based on the effective drawing area and the set of opaque covered areas of the currently traversed drawing operation, the remaining visible area of the currently traversed drawing operation is determined. The set of opaque covered areas is used to record the pixel area covered by the drawing operation from the current traversal position to the top layer. If the remaining visible area is empty, then the drawing operation currently being traversed is determined to be the target drawing operation.
[0124] As one possible implementation of this application, the drawing processing unit 74 is specifically used for: The drawing instruction sequence is traversed using a real canvas. When the current drawing operation encountered during traversal has the skip flag, the execution of the current drawing operation is skipped, and the traversal continues to the next drawing operation.
[0125] As one possible implementation of this application, the graphics drawing device further includes: The mapping information acquisition unit is used to acquire the current mapping information of the current drawing operation to be drawn. The current mapping information is used to establish the correspondence between the metadata recorded in the detection traversal stage and the drawing operation in the actual drawing stage. A consistency verification unit is used to perform a consistency verification between the current mapping information and the mapping information recorded in the detection canvas traversal stage; when the consistency verification passes, the step of skipping the target drawing operation with the skip mark is executed; when the consistency verification fails, all skip operations in the current frame are canceled and all drawing operations are executed.
[0126] As one possible implementation of this application, the graphics drawing device further includes: A status acquisition unit is used to acquire status information of the drawing instruction sequence, the status information being used to indicate whether the drawing instruction sequence has changed; An information reuse processing unit is configured to reuse the visibility analysis results of the previous frame when the status information indicates that the drawing instruction sequence has not changed; and to re-execute the step of using a detection-type canvas to traverse the drawing instruction sequence of the current frame and obtain the metadata of multiple drawing operations in the drawing instruction sequence when the status information indicates that the drawing instruction sequence has changed.
[0127] As one possible implementation of this application, the graphics drawing apparatus further includes: a canvas construction detection unit, configured to: Get the rendering context parameters for the current frame; Based on the rendering context parameters, a detection canvas is constructed, and the matrix state and clipping region state of the detection canvas are consistent with the real canvas.
[0128] As can be seen from the above, in this embodiment, before actual drawing, a detection canvas is used to traverse the drawing instruction sequence of the current frame to obtain metadata of multiple drawing operations in the drawing instruction sequence. This detection canvas is used to receive drawing calls but does not execute actual drawing, thereby enabling the drawing information of each drawing operation to be obtained in advance without generating any actual pixel drawing, providing a data basis for the identification of subsequent invalid drawing without affecting the normal rendering process. Then, according to the drawing order of multiple drawing operations, reverse visibility analysis is performed on the metadata of multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations, which can be accumulated layer by layer according to the drawing order from back to front. The system accurately identifies drawing operations that do not contribute to the final display. If a target drawing operation meets preset safety skipping conditions, a skip flag is set for it. Based on geometric coverage analysis, this system further combines drawing attribute information for safety verification. A drawing operation is only allowed to be marked if skipping it will not change the final display result. This ensures display correctness while identifying invalid drawing. Finally, when executing the drawing instruction sequence, target drawing operations with skip flags are skipped, eliminating the need to execute drawing operations that do not contribute to the final display during the actual drawing stage. This reduces the number of drawing instructions executed and lowers computational overhead and resource consumption during rendering. This application's solution, through the combined use of detection traversal, reverse coverage analysis, safety condition judgment, and skipping flags, automatically identifies and skips invalid drawing operations in the drawing instruction sequence without relying on manual optimization or modifying application code. This ensures the correctness of the final display and effectively reduces resource consumption caused by invalid drawing during graphics rendering.
[0129] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0130] This application embodiment also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements... Figures 1 to 6 The steps of any graphic drawing method are represented.
[0131] This application embodiment also provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements... Figures 1 to 6 The steps of any graphic drawing method are represented.
[0132] This application also provides a computer program product that, when run on a terminal device, causes the terminal device to execute the implementation of... Figures 1 to 6 The steps of any graphic drawing method are represented.
[0133] Figure 8 This is a schematic diagram of a terminal device provided in an embodiment of this application. For example... Figure 8 As shown, the terminal device 8 in this embodiment includes: a processor 80, a memory 81, and a computer program 82 stored in the memory 81 and executable on the processor 80. When the processor 80 executes the computer program 82, it implements the steps in the various graphics drawing method embodiments described above, for example... Figure 1 Steps S101 to S104 are shown. Alternatively, when the processor 80 executes the computer program 82, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 7 The functions of units 71 to 74 are shown.
[0134] For example, the computer program 82 may be divided into one or more modules / units, which are stored in the memory 81 and executed by the processor 80 to complete this application. The one or more modules / units may be a series of computer-readable instruction segments capable of performing a specific function, which describe the execution process of the computer program 82 in the terminal device 8.
[0135] The terminal device 8 may include, but is not limited to, a processor 80 and a memory 81. Those skilled in the art will understand that... Figure 8 This is merely an example of terminal device 8 and does not constitute a limitation on terminal device 8. It may include more or fewer components than shown, or combine certain components, or different components. For example, terminal device 8 may also include input / output devices, network access devices, buses, etc.
[0136] The processor 80 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0137] The memory 81 can be an internal storage unit of the terminal device 8, such as a hard disk or memory of the terminal device 8. The memory 81 can also be an external storage device of the terminal device 8, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the terminal device 8. Furthermore, the memory 81 can include both internal and external storage units of the terminal device 8. The memory 81 is used to store the computer program and other programs and data required by the terminal device. The memory 81 can also be used to temporarily store data that has been output or will be output.
[0138] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0139] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0140] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a device / terminal equipment, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0141] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0142] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for drawing graphics, characterized in that, include: A detection-type canvas is used to traverse the drawing instruction sequence of the current frame to obtain metadata of multiple drawing operations in the drawing instruction sequence. The detection-type canvas is used to receive drawing calls but does not perform actual drawing. Based on the drawing order of the multiple drawing operations, reverse visibility analysis is performed on the metadata of the multiple drawing operations to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations. If the target drawing operation meets the preset safe skip condition, then a skip flag is set for the target drawing operation; When executing the drawing instruction sequence, target drawing operations with the skip flag are skipped.
2. The method according to claim 1, characterized in that, The method of using a detection-type canvas to traverse the current frame's drawing instruction sequence and obtaining metadata for multiple drawing operations in the drawing instruction sequence includes: Intercept the drawing calls during the traversal of the drawing instruction sequence; Generate corresponding metadata for each drawing operation, the metadata being used to characterize the drawing attribute information of the drawing operation.
3. The method according to claim 1, characterized in that, The step of performing reverse visibility analysis on the metadata of the multiple drawing operations according to their drawing order to determine the target drawing operation that is completely occluded by subsequent opaque drawing operations includes: Following the reverse order of the drawing operations, traverse each drawing operation backward from the last drawing operation. Based on the effective drawing area and the set of opaque covered areas of the currently traversed drawing operation, the remaining visible area of the currently traversed drawing operation is determined. The set of opaque covered areas is used to record the pixel area covered by the drawing operation from the current traversal position to the top layer. If the remaining visible area is empty, then the drawing operation currently being traversed is determined to be the target drawing operation.
4. The method according to claim 1, characterized in that, Skipping the target drawing operation with the skip marker when executing the drawing instruction sequence includes: The drawing instruction sequence is traversed using a real canvas. When the current drawing operation encountered during traversal has the skip flag, the execution of the current drawing operation is skipped, and the traversal continues to the next drawing operation.
5. The method according to claim 1, characterized in that, Before executing the drawing instruction sequence, the method further includes: Obtain the current mapping information of the current drawing operation to be drawn. The current mapping information is used to establish the correspondence between the metadata recorded in the detection traversal phase and the drawing operation in the actual drawing phase. Perform a consistency check between the current mapping information and the mapping information recorded during the detection canvas traversal phase; When the consistency check passes, the step of skipping the target drawing operation with the skip mark is executed; If the consistency check fails, cancel all skip operations in this frame and execute all drawing operations.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Obtain the status information of the drawing instruction sequence, the status information being used to indicate whether the drawing instruction sequence has changed; If the status information indicates that the drawing instruction sequence has not changed, the visibility analysis results of the previous frame are reused; If the status information indicates that the drawing instruction sequence has changed, the step of re-executing the drawing instruction sequence of the current frame using a detection-type canvas to obtain the metadata of multiple drawing operations in the drawing instruction sequence is performed.
7. The method according to any one of claims 1 to 5, characterized in that, Before the drawing instruction sequence that uses a detection-type canvas to traverse the current frame, the following is also included: Get the rendering context parameters for the current frame; Based on the rendering context parameters, a detection canvas is constructed, and the matrix state and clipping region state of the detection canvas are consistent with the real canvas.
8. A graphic drawing device, characterized in that, include: The metadata acquisition unit is used to traverse the drawing instruction sequence of the current frame using a detection canvas to acquire metadata of multiple drawing operations in the drawing instruction sequence. The detection canvas is used to receive drawing calls but does not perform actual drawing. The target determination unit is used to perform reverse visibility analysis on the metadata of the multiple drawing operations according to the drawing order of the multiple drawing operations, and determine the target drawing operation that is completely occluded by the subsequent opaque drawing operation. A marker setting unit is used to set a skip marker for the target drawing operation if the target drawing operation meets a preset safe skip condition; A drawing processing unit is configured to skip target drawing operations with the skip flag when executing the drawing instruction sequence.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the graphics drawing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the graphics drawing method as described in any one of claims 1 to 7.