Background
In a terminal device, when a CPU (central Processing Unit), a GPU (Graphics Processing Unit), and a display perform User Interface (UI) rendering, they cooperate in the following manner: after the frame synchronization signal arrives, the application program is informed to conduct user interface rendering, a main thread of the application program starts to calculate display contents in a CPU, such as view creation, layout calculation, picture decoding, text drawing and the like, after the calculation is completed, the CPU submits the display contents to a GPU, the GPU conducts conversion, blending and rendering according to the display contents, after the rendering is completed, the GPU places rendering results into a frame buffer area, and after the next frame synchronization signal arrives, data in the frame buffer area are transmitted to a display to be displayed.
Taking the iOS system as an example, an application performs user interface rendering through frames such as UIKit and CoreAnimation provided by the system, but these frames all require operations on a main thread, and internal implementation is also performed on the CPU by the main thread, such as preparing a hierarchical relationship of views, setting layer attributes, drawing bitmaps, decoding pictures, and the like. When the view level of the user interface is complex, if the CPU or the GPU cannot complete the task within one rendering period, the content of the user interface cannot be updated on the screen in time, which may cause the user interface to be stuck.
Disclosure of Invention
The application provides a view level optimization method to solve the problems in the prior art. The application also relates to a device for view level optimization and an electronic device.
The application provides a view level optimization method, which comprises the following steps:
acquiring attributes of views contained in each level of a view hierarchy;
finding an associated view having a hierarchical association with the view in the view hierarchy;
and judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view.
Optionally, the view hierarchy includes: a view hierarchy tree;
the level association relation between the view and the associated view means that the associated view is an ancestor view of the view in the view level tree, and the associated view is at the level nearest to the level of the view.
Optionally, the attributes of the view include: a rasterized attribute and a non-rasterized attribute;
accordingly, the views in the view hierarchy tree include: a rasterized root view, a rasterized sub-view and a non-rasterized view;
wherein, the rasterization root view is provided with a state identifier, the state identifier includes: a first state identification that allows rasterization with the rasterized sub-view, and a second state identification that does not allow rasterization with the rasterized sub-view.
Optionally, the constraint condition for rasterizing the view and the associated view includes at least one of the following:
the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier.
Optionally, the finding of the associated view having a hierarchical association relationship with the view in the view hierarchical structure is implemented in the following manner:
looking up an ancestor view of the view in the view hierarchy tree;
judging whether the searched ancestor view has an associated view of the view, if so, executing the step of judging whether the view and the associated view meet the constraint condition for rasterization according to the associated view and the attributes of the view;
if not, judging whether the attribute of the view is a rasterization attribute, if so, taking the view as a rasterization root view, and setting the state identifier of the view as the first state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterized root view, and the attribute of the view is a rasterized attribute;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, if so, judging whether the associated view is a rasterization root view, and if so, executing the step of rasterizing the view and the associated view; if the view is not the rasterization root view, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, if so, judging whether the associated view is a rasterization root view, and if so, judging whether the state identifier of the associated view is a first state identifier; if the state identification is the first state identification, executing the step of rasterizing the view and the associated view; if the view is not the first state identifier, setting the associated view as a parent view of the view; if the view is not the rasterization root view, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterization root view, the attribute of the view is a rasterization attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, and if the attribute of the view is the rasterization attribute, judging whether the state identifier of the associated view is a first state identifier; if the state identification is the first state identification, executing the step of rasterizing the view and the associated view; if the view is not the first state identifier, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, the rasterizing of the view and the associated view is implemented by the following method:
hiding the view, and drawing the display characteristics of the view on the bitmap where the associated view is located; or combining the view and the associated view and drawing the combined result on a bitmap.
Optionally, for the views included in the view level tree, traversing the views included in the view level tree in a depth traversal manner from a root view in the view level tree;
and each time one view is traversed, the step of searching the view hierarchy for the associated view having the hierarchical association relation with the view is executed aiming at the traversed view, and the step of judging whether the view and the associated view meet the constraint condition for rasterization according to the associated view and the attribute of the view.
Optionally, the view level optimization method includes:
and judging whether the views contained in the view level tree are traversed or not, if not, traversing the views which are not traversed in the views contained in the view level tree.
The present application further provides a management device for view level optimization, including:
the view attribute acquiring unit is used for acquiring the attributes of the views contained in each level of the view hierarchy;
an associated view searching unit, configured to search, in the view hierarchy, an associated view having a hierarchical association relationship with the view;
the rasterization judging unit is used for judging whether the view and the associated view meet the constraint condition for rasterization according to the associated view and the attribute of the view, and if so, operating the rasterization unit;
the rasterizing unit is used for rasterizing the view and the associated view.
The present application further provides an electronic device, comprising:
a memory and a processor;
the memory is to store computer-executable instructions, and the processor is to execute the computer-executable instructions to:
acquiring attributes of views contained in each level of a view hierarchy;
finding an associated view having a hierarchical association with the view in the view hierarchy;
and judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view.
The view level optimization method provided by the application comprises the following steps: acquiring attributes of views contained in each level of a view hierarchy; finding an associated view having a hierarchical association with the view in the view hierarchy; and judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view.
The view hierarchy optimization method includes the steps of searching for an associated view having a hierarchy association relationship with a view in a view hierarchy, judging whether the view and the associated view meet a constraint condition for rasterization according to attributes of the view and the associated view acquired in advance, rasterizing the view onto the associated view if the view and the associated view meet the constraint condition for rasterization, and reducing views included in each hierarchy of the view hierarchy by performing rasterization on the view included in the view hierarchy, simplifying the hierarchy relationship of the view hierarchy, and reducing complexity of the view hierarchy.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. This application is capable of implementation in many different ways than those herein set forth and of similar import by those skilled in the art without departing from the spirit of this application and is therefore not limited to the specific implementations disclosed below.
The application provides a view level optimization method, a view level optimization device and electronic equipment. The following detailed description and the description of the steps of the method are individually made with reference to the drawings of the embodiments provided in the present application.
The embodiment of the method for optimizing the view level provided by the application is as follows:
referring to fig. 1, which shows a processing flow diagram of an embodiment of a method for view level optimization provided by the present application, referring to fig. 2, which shows a schematic diagram of an application interface provided by the present application, referring to fig. 3, which shows a schematic diagram of a view level tree provided by the present application, referring to fig. 4, which shows a schematic diagram of a rasterized view level tree provided by the present application.
Step S101, obtaining the attributes of the views contained in each level of the view hierarchy.
The views described in the embodiments of the present application refer to objects used for displaying elements such as images, texts, or videos, a common view is a rectangular view, the views can be used for processing manipulation behaviors such as mouse clicks or touch gestures of a user, and the views can be built in another view to form a hierarchical structure, i.e., a view hierarchy, where each view controls the position of its sub-view in the view hierarchy. According to the view hierarchy optimization method provided by the application, the view in the view hierarchy is subjected to rasterization processing to simplify the hierarchical relationship, and taking any two views as an example, the rasterization processing is performed on the two views, so that one view can be hidden, the display characteristic of the hidden view is drawn on the other view, or the two views are combined, and the combined result of the two views is drawn on a bitmap. Similarly, the rasterization processing is performed on three views or more, and similar to the rasterization processing described above on two views, the display characteristics of multiple views are displayed on the same bitmap, so as to simplify the hierarchical relationship in the view hierarchy and reduce the complexity of the view hierarchy.
For illustration, the embodiment uses a tree view hierarchy, such as the iOS application interface shown in fig. 2, which includes a root view (RootView) that includes three sub-views: view1, View3 and View6, wherein the sub-View 1 comprises a sub-View 2, the sub-View 3 comprises two sub-views View4 and View5, the sub-View 6 comprises a sub-View 7, and a Button exists in the sub-View 4. The View hierarchy tree corresponding to the application interface is shown in fig. 3, wherein "parent-child relationship" exists between adjacent views of the hierarchy, root View RootView is a parent View of child View1, child View3 and child View6, child View1 is a parent View of child View2, child View3 is a parent View of child View4 and child View5, child View6 is a parent View of child View7, and Button has "parent-child relationship" with child View 4.
In the view hierarchy tree, there is only one parent view per child view, but there may be only one child view per parent view or there may be multiple child views. And similarly, the parent view of the child view may also have a parent view, and so on, up to the root view in the view hierarchy tree. The parent view of the child view, the parent view of the child view, and the like, together form an ancestor view of the child view. As shown in FIG. 2, the ancestor View of child View View1 comprises root View rootView; the ancestor View of the child View View2 comprises a child View View1 and a root View rootView; the ancestor View of child View View3 comprises root View rootView; the ancestor View of the child View View4 comprises a child View View3 and a root View rootView; the ancestor View of the Button comprises a child View View4, a child View View3 and a root View rootView; the ancestor View of the child View View5 comprises a child View View3 and a root View rootView; the ancestor View of child View View6 comprises root View rootView; the ancestor View of the child View View7 includes the child View View6 and the root View rootView.
In practical applications, not all views need to support the rasterization process, and are merged with other views, and there may be some views that are not allowed to be rasterized with other views according to the characteristics of the views themselves. Setting corresponding attributes aiming at the view, wherein the attributes of the view comprise a rasterization attribute and a non-rasterization attribute, and if the current view allows rasterization processing with other views, the attribute of the current view is the rasterization attribute; on the contrary, if the current view does not allow rasterization processing with other views, the attribute of the current view is a non-rasterization attribute.
Based on this, the views in the view hierarchy tree can be divided into: a rasterized root view, a rasterized sub-view, and a non-rasterized view. Each rasterization root view in the view level tree has at least one sub-view, the rasterization root view is also provided with a state identifier, the state identifier specifically comprises a first state identifier and a second state identifier, and if the identifier of the rasterization root view is the first state identifier, the current rasterization root view is allowed to be rasterized with the sub-view (namely the rasterization sub-view) of the current rasterization root view; if the identification of the rasterized root view is the second state identification, it indicates that the current rasterized root view is not allowed to be rasterized with its child views (i.e., rasterized child views). In this embodiment, the state identifier of the rasterized root view is default to be the first state identifier.
This step obtains attributes of views included in the view hierarchical tree, for example, the attributes of the views are determined according to characteristic information of the views in the view hierarchical tree, that is, the attributes of the views are: determining whether an attribute of a view included in the view hierarchy tree is a rasterized attribute or a non-rasterized attribute. The View hierarchy tree shown in fig. 3, wherein the attributes of root View, child View1 through child View7 are rasterized attributes, and the attribute of Button is non-rasterized attribute. Correspondingly, the root View RootView, the sub-View 5 and the sub-View 6 are rasterized root views; the sub-View View1, sub-View View2, sub-View View3, sub-View View4, and sub-View View7 are rasterized sub-views; the Button is a non-rasterized view.
Step S102, finding the associated view having the hierarchical association relation with the view in the view hierarchical structure.
The level association relation between the view and the associated view means that the associated view is an ancestor view of the view in the view level tree, and the associated view is at the level nearest to the level of the view. The View level tree shown in FIG. 3, wherein the ancestor View of the child View View1 has only root View rootView, then the associated View of the child View View1 is root View rootView. The ancestor View of child View View2 includes: the child View1 and the root View RootView, but the child View1 is adjacent to the child View2 at a level significantly closer to the level of the child View1 relative to the root View RootView, and therefore, the child View1 is used as the associated View of the child View 2.
In this step, an associated view having a hierarchical association relationship with the view is searched in the view hierarchical structure, which is specifically implemented as follows:
1) looking up an ancestor view of the view in the view hierarchy tree;
specifically, when searching the ancestor view of the view in the view hierarchical tree, sequentially searching the parent view of the view, the parent view of the view and the root view in the view hierarchical tree from the parent view of the view upwards.
2) Judging whether the searched ancestor view has an associated view of the view, if so, executing the following step S103, and judging whether the view and the associated view meet the constraint condition for rasterization according to the associated view and the attributes of the view; if not, judging whether the attribute of the view is a rasterization attribute, if so, taking the view as a rasterization root view, and setting the state identifier of the view as the first state identifier; if the attribute is not the rasterization attribute, the processing is not required.
Step S103, judging whether the view and the associated view meet the constraint condition for rasterization according to the associated view and the attribute of the view.
The constraint condition for rasterizing the view and the associated view in the embodiment of the application includes: the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier. On this basis, the step determines whether the view and the associated view satisfy the constraint condition for rasterization according to the associated view and the attribute of the view, and is specifically implemented as follows:
a. judging whether the attribute of the view is a rasterization attribute, if so, executing the substep b; if not, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, if so, marking the state identifier of the associated view as the second state identifier.
b. Judging whether the associated view is a rasterization root view or not, and if so, executing a substep c; and if not, setting the associated view as the parent view of the view.
c. Judging whether the state identifier of the associated view is a first state identifier, if so, executing the following step S104, and rasterizing the view and the associated view; and if not, setting the associated view as the parent view of the view.
As shown in the View level tree of FIG. 3, when the sub-View View1 is processed, as described above, the attribute of the sub-View View1 is a rasterization attribute, and the attribute of the associated View (root View) of the sub-View View1 is also a rasterization attribute. Based on the above, whether the attribute of the child View1 is a rasterization attribute is judged, because the attribute of the child View1 is a rasterization attribute, whether the associated View (root View RootView) is a rasterization root View is further judged, because the associated View (root View RootView) is a rasterization root View, whether the state identifier of the associated View (root View RootView) is a first state identifier is further judged, and if the state identifier of the root View RootView is the first state identifier, rasterization is performed on the child View1 and the root View RootView, and the child View1 is merged onto the root View RootView.
In addition to the implementation manners provided above, the constraint condition may be any one or a combination of more than one of the associated view being a rasterized root view or a non-rasterized view, the attribute of the view being a rasterized attribute, and the state identifier of the associated view being a first state identifier. Constraints such as rasterization of the view and the associated view include: if the associated view is a rasterized root view and the attribute of the view is a rasterized attribute, determining whether the view and the associated view satisfy the constraint condition for rasterization according to the associated view and the attribute of the view, specifically implementing the following:
a. judging whether the attribute of the view is a rasterization attribute, if so, executing the substep b; if not, setting the associated view as a parent view of the view, judging whether the associated view is a rasterization root view, and if so, marking the state identifier of the associated view as the second state identifier.
b. Judging whether the associated view is a rasterization root view, if so, executing the following step S104 to rasterize the view and the associated view; and if not, setting the associated view as the parent view of the view.
For another example, the constraint condition for rasterizing the view and the associated view includes: if the associated view is a rasterized root view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier, then whether the view and the associated view meet the constraint condition for rasterization is determined according to the associated view and the attribute of the view, which is specifically implemented as follows:
a. judging whether the attribute of the view is a rasterization attribute, if so, executing the substep b; if not, setting the associated view as a parent view of the view, judging whether the associated view is a rasterization root view, and if so, marking the state identifier of the associated view as the second state identifier.
b. Judging whether the state identifier of the associated view is a first state identifier or not; if yes, executing the following step S104, and rasterizing the view and the associated view; and if not, setting the associated view as the parent view of the view.
And step S104, rasterizing the view and the associated view.
The precondition for this step to be implemented is that the determination result of step S103 determining whether the view and the associated view satisfy the constraint condition for rasterization is yes, and rasterizing the view and the associated view based on this, specifically, combining the view and the associated view, and drawing the combined result of the two on a bitmap; the view may also be hidden and the display characteristics of the view may be drawn on the bitmap where the associated view is located.
In a specific implementation, when the step S102 and the step S103 are executed, the views included in the view hierarchy tree may also be processed in a traversal manner, and the step S102 and the step S103 are executed on the basis of the traversal. Specifically, during traversal, the views included in the view hierarchy tree may be traversed in a depth traversal manner starting from a root view in the view hierarchy tree, and the operations in step S102 and step S103 are performed on the traversed views each time one view is traversed.
Based on this, in the traversal process, in order to ensure that all views in the view hierarchy tree are traversed, the following traversal detection operation may also be performed after each traversal completes one view: judging whether the views contained in the view level tree are completely traversed or not, if so, indicating that all the views in the view level tree are completely traversed, and ending the processing; if not, traversing the views which are not traversed in the views contained in the view hierarchy tree.
As shown in fig. 3, the view level tree is traversed by using a depth traversal manner starting from a root view in the view level tree, and the traversal order of the views in the view level tree is as follows: root View RootView- > child View1- > child View2- > child View3- > child View4- > Button- > child View5- > child View6- > child View 7.
According to the traversal sequence, when the root view RootView is traversed, no parent node exists in the root view RootView, and no processing is needed.
When traversing to the child View1, the associated View of the child View1 is a root View RootView, and according to the processing logic, since the attribute of the child View1 is a rasterization attribute, the associated View (root View RootView) is a rasterization root View, and the state identifier of the associated View (root View RootView) is a first state identifier, the rasterization result is to merge the child View1 into the root View RootView, as shown in the View hierarchy tree provided in fig. 4.
When traversing to sub-View View2, the ancestor View of sub-View View2 includes: the child View1 and the root View RootView, wherein the associated View satisfying the condition is the root View RootView, according to the processing logic, since the attribute of the child View2 is the rasterization attribute, the associated View (root View RootView) is the rasterization root View, and the state identifier of the associated View (root View RootView) is the first state identifier, the rasterization result is to merge the child View2 onto the root View RootView, as shown in the View hierarchy tree provided in fig. 4.
When traversing to the sub-View View3, the processing is similar to that of the sub-View View1, and the final sub-View View3 is merged onto the root View rootView.
When traversing to the sub-View View4, the processing is similar to that of the sub-View View2, and the final sub-View View4 is merged onto the root View rootView.
When traversing to the Button, the ancestor view of the Button includes: the View node comprises a child View4, a child View3 and a root View RootView, wherein the associated View meeting the condition is the root View RootView, the associated node of the Button is the root View RootView, and the root View RootView is set as a parent View of the Button because the attribute of the Button is a non-rasterization attribute, namely: changing the Button parent View from the previous child View View4 to the root View rootView; and since the root view RootView is a rasterized root view, the state identifier of the root view RootView is set to the second state identifier, that is: the state identification of the root view RootView is changed from the default first state identification to the second state identification. After that, the root View RootView is not allowed to be rasterized with other sub-views, and the sub-views View5, 6 and 7 are not allowed to be merged onto the root View RootView, as shown in the View level tree provided in fig. 4.
When traversing to the child View View5, the associated View is the root View RootView, but since the state of the root View RootView is set to the second state identification during the Button traversal process, although the child View View5 satisfies the remaining conditions of being rasterized onto the root View RootView, the child View View5 cannot be rasterized onto the root View RootView, as shown in the View level tree provided in FIG. 4.
Similarly, the sub-View View6 cannot be rasterized onto the root View rootView, but the sub-View View7 satisfies the condition of being rasterized onto the sub-View View6, and finally the sub-View View7 is rasterized onto the sub-View View6, the sub-views being as shown in the View level tree provided in FIG. 4.
In summary, the method for view hierarchy optimization searches an associated view having a hierarchy association relationship with a view in a view hierarchy, determines whether the view and the associated view satisfy a constraint condition for rasterization according to attributes of the view and the associated view acquired in advance, rasterizes the view onto the associated view if the view and the associated view satisfy the constraint condition for rasterization, and reduces views included in each hierarchy of the view hierarchy by performing the rasterization on the view included in the view hierarchy, simplifies the hierarchy relationship of the view hierarchy, and reduces complexity of the view hierarchy.
Another embodiment of a method for view level optimization provided by the present application is as follows:
in addition to the above-provided method embodiment of view level optimization, the present application also provides a method embodiment of view level optimization, similar to the above-provided method embodiment of view level optimization. Since this embodiment is similar to the method embodiment, it is relatively simple to describe, and the relevant portions should be referred to the corresponding description of the method embodiment provided above. The method embodiments described below are merely illustrative.
The view level optimization method comprises the following steps:
obtaining the attribute of a view contained in each level of a view hierarchical structure of an object to be rendered;
finding an associated view having a hierarchical association with the view in the view hierarchy;
judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view;
triggering user interface rendering for the object to be rendered based on a main thread;
switching from the main thread to a sub-thread, and drawing a bitmap corresponding to the object to be rendered on the sub-thread according to the view hierarchical structure obtained by rasterization;
calling back the main thread, and applying the drawn bitmap to the display content of the object to be rendered;
and rendering a user interface according to the display content of the object to be rendered.
Besides, the method for view level optimization can be implemented in other ways besides the above implementation ways, such as:
triggering user interface rendering for the object to be rendered based on the main thread;
obtaining the attribute of the view contained in each level of the view hierarchical structure of the object to be rendered;
finding an associated view having a hierarchical association with the view in the view hierarchy;
judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view;
switching from the main thread to a sub-thread, and drawing a bitmap corresponding to the object to be rendered on the sub-thread according to the view hierarchical structure obtained by rasterization;
calling back the main thread, and applying the drawn bitmap to the display content of the object to be rendered;
and rendering a user interface according to the display content of the object to be rendered.
The embodiment of the device for view level optimization provided by the application is as follows:
in the above embodiments, a method for view level optimization is provided, and correspondingly, an apparatus for view level optimization is also provided in the present application, which is described below with reference to the accompanying drawings.
Referring to fig. 5, a schematic diagram of an embodiment of an apparatus for view level optimization provided in the present application is shown.
Since the apparatus embodiments are substantially similar to the method embodiments, they are described in a relatively simple manner, and reference may be made to the corresponding description of the method embodiments provided above for relevant portions. The device embodiments described below are merely illustrative.
The application provides a view level optimization device, comprising:
a viewattribute acquiring unit 501, configured to acquire attributes of views included in each level of a view hierarchy;
an associatedview searching unit 502, configured to search the view hierarchy for an associated view having a hierarchical association relationship with the view;
arasterization determining unit 503, configured to determine, according to the associated view and the attribute of the view, whether the view and the associated view meet a constraint condition for rasterization, and if yes, run arasterization unit 504;
therasterizing unit 504 is configured to rasterize the view and the associated view.
Optionally, the view hierarchy includes: a view hierarchy tree;
the level association relation between the view and the associated view means that the associated view is an ancestor view of the view in the view level tree, and the associated view is at the level nearest to the level of the view.
Optionally, the attributes of the view include: a rasterized attribute and a non-rasterized attribute;
accordingly, the views in the view hierarchy tree include: a rasterized root view, a rasterized sub-view and a non-rasterized view;
wherein, the rasterization root view is provided with a state identifier, the state identifier includes: a first state identification that allows rasterization with the rasterized sub-view, and a second state identification that does not allow rasterization with the rasterized sub-view.
Optionally, the constraint condition for rasterizing the view and the associated view includes at least one of the following:
the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier.
Optionally, the associatedview searching unit 502 includes:
an ancestor view lookup subunit, configured to lookup an ancestor view of the view in the view hierarchy tree;
an associated view judging subunit, configured to judge whether an associated view of the view exists in the searched ancestor view, and if yes, operate therasterization judging unit 503; if not, the judging subunit is operated;
the judging subunit is configured to judge whether the attribute of the view is a rasterization attribute, and if the attribute of the view is the rasterization attribute, use the view as a rasterization root view, and set the state identifier of the view as the first state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterized root view, and the attribute of the view is a rasterized attribute;
correspondingly, therasterization determining unit 503 includes:
the first rasterization attribute judging subunit is used for judging whether the attribute of the view is the rasterization attribute, and if so, the first rasterization root view judging subunit is operated; if not, setting the associated view as a parent view of the view; judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier;
the first rasterization root view determining subunit is configured to determine whether the associated view is a rasterization root view, and if so, run therasterization unit 504; and if not, setting the associated view as the parent view of the view.
Optionally, if the constraint condition includes: the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, therasterization determining unit 503 includes:
the second rasterization attribute judging subunit is used for judging whether the attribute of the view is the rasterization attribute, and if the attribute is the rasterization attribute, operating the second rasterization root view judging subunit; if the view is not the rasterization attribute, setting the associated view as a parent view of the view; judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier;
the second rasterization root view judging subunit is used for judging whether the associated view is the rasterization root view, and if the associated view is the rasterization root view, the running state identifies the first judging subunit; if the view is not the rasterization root view, setting the associated view as a parent view of the view;
the state identifier first judging subunit is configured to judge whether the state identifier of the associated view is a first state identifier; if the status flag is the first status flag, therasterizing unit 504 is operated; and if the associated view is not the first state identifier, setting the associated view as a parent view of the view.
Optionally, if the constraint condition includes: the associated view is a rasterization root view, the attribute of the view is a rasterization attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, therasterization determining unit 503 includes:
the third rasterization attribute judgment subunit is used for judging whether the attribute of the view is the rasterization attribute, and if the attribute is the rasterization attribute, the running state marks the second judgment subunit; if the view is not the rasterization attribute, setting the associated view as a parent view of the view; judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier;
the second state identifier judging subunit is configured to judge whether the state identifier of the associated view is the first state identifier; if the status flag is the first status flag, therasterizing unit 504 is operated; and if the associated view is not the first state identifier, setting the associated view as a parent view of the view.
Optionally, therasterizing unit 504 is specifically configured to hide the view, and draw the display characteristic of the view on the bitmap where the associated view is located; or combining the view and the associated view and drawing the combined result on a bitmap.
Optionally, for the views included in the view level tree, traversing the views included in the view level tree in a depth traversal manner from a root view in the view level tree; and, every time a view is traversed, the associatedview searching unit 502 and therasterization judging unit 503 are run for the traversed view.
Optionally, the view-level optimizing apparatus includes:
and the traversal judging unit is used for judging whether the views contained in the view level tree are traversed or not, and if not, traversing the views which are not traversed in the views contained in the view level tree.
The embodiment of the electronic equipment provided by the application is as follows:
in the foregoing embodiment, a method for view level optimization is provided, and in addition, an electronic device for implementing the method for view level optimization is provided, which is described below with reference to the accompanying drawings.
Referring to fig. 6, a schematic diagram of an electronic device provided in the present embodiment is shown.
The embodiments of the electronic device provided in the present application are described more simply, and for related parts, reference may be made to the corresponding description of the embodiment of the view-level optimization method provided above. The embodiments described below are merely illustrative.
The application provides an electronic device, including:
amemory 601 and aprocessor 602;
thememory 601 is configured to store computer-executable instructions, and theprocessor 602 is configured to execute the following computer-executable instructions:
acquiring attributes of views contained in each level of a view hierarchy;
finding an associated view having a hierarchical association with the view in the view hierarchy;
and judging whether the view and the associated view meet the constraint condition for rasterization or not according to the associated view and the attribute of the view, and if so, rasterizing the view and the associated view.
Optionally, the view hierarchy includes: a view hierarchy tree;
the level association relation between the view and the associated view means that the associated view is an ancestor view of the view in the view level tree, and the associated view is at the level nearest to the level of the view.
Optionally, the attributes of the view include: a rasterized attribute and a non-rasterized attribute;
accordingly, the views in the view hierarchy tree include: a rasterized root view, a rasterized sub-view and a non-rasterized view;
wherein, the rasterization root view is provided with a state identifier, the state identifier includes: a first state identification that allows rasterization with the rasterized sub-view, and a second state identification that does not allow rasterization with the rasterized sub-view.
Optionally, the constraint condition for rasterizing the view and the associated view includes at least one of the following:
the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier.
Optionally, the finding of the associated view having a hierarchical association relationship with the view in the view hierarchical structure is implemented in the following manner:
looking up an ancestor view of the view in the view hierarchy tree;
judging whether the searched ancestor view has an associated view of the view, if so, executing the operation of judging whether the view and the associated view meet a constraint condition instruction for rasterization according to the associated view and the attributes of the view;
if not, judging whether the attribute of the view is a rasterization attribute, if so, taking the view as a rasterization root view, and setting the state identifier of the view as the first state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterized root view, and the attribute of the view is a rasterized attribute;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, if so, judging whether the associated view is a rasterization root view, and if so, executing a rasterization instruction for the view and the associated view; if the view is not the rasterization root view, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterized root view or a non-rasterized view, the attribute of the view is a rasterized attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, if so, judging whether the associated view is a rasterization root view, and if so, judging whether the state identifier of the associated view is a first state identifier; if the view and the associated view are in the first state identification, executing a rasterization instruction of the view and the associated view; if the view is not the first state identifier, setting the associated view as a parent view of the view; if the view is not the rasterization root view, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, if the constraint condition includes: the associated view is a rasterization root view, the attribute of the view is a rasterization attribute, and the state identifier of the associated view is a first state identifier;
correspondingly, the judgment of whether the view and the associated view meet the constraint condition for rasterization is realized by adopting the following mode:
judging whether the attribute of the view is a rasterization attribute, and if the attribute of the view is the rasterization attribute, judging whether the state identifier of the associated view is a first state identifier; if the view and the associated view are in the first state identification, executing a rasterization instruction of the view and the associated view; if the view is not the first state identifier, setting the associated view as a parent view of the view;
if the view is not the rasterization attribute, setting the associated view as a parent view of the view; and judging whether the associated view is a rasterization root view or not, and if the associated view is the rasterization root view, marking the state identifier of the associated view as the second state identifier.
Optionally, the rasterizing of the view and the associated view is implemented by the following method:
hiding the view, and drawing the display characteristics of the view on the bitmap where the associated view is located; or combining the view and the associated view and drawing the combined result on a bitmap.
Optionally, for the views included in the view level tree, traversing the views included in the view level tree in a depth traversal manner from a root view in the view level tree; and each time one view is traversed, executing the associated view instruction which is used for searching the view hierarchy and has the hierarchy association relation with the view aiming at the traversed view, and judging whether the view and the associated view meet the constraint condition instruction for rasterization or not according to the associated view and the attribute of the view.
Optionally, theprocessor 602 is further configured to execute the following computer-executable instructions:
and judging whether the views contained in the view level tree are traversed or not, if not, traversing the views which are not traversed in the views contained in the view level tree.
Although the present application has been described with reference to the preferred embodiments, it is not intended to limit the present application, and those skilled in the art can make variations and modifications without departing from the spirit and scope of the present application, therefore, the scope of the present application should be determined by the claims that follow.
In a typical configuration, a computing device includes one or more processors, input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory computer readable media (transient media), such as modulated data signals and carrier waves.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.