A character rendering method and an electronic device
Patent Information
- Application Number
- CN202410870575.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2044-06-28
AI Technical Summary
在需要大量渲染文字的场景,比如,需要显示文字动画特效(简称文字动效)的场景下,会产生大量的内存资源占用,随之也容易触发内存清理,导致卡顿
[0033]第三方面,本申请实施例提供的一种计算机存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行上述第一方面及其可能的实施例中的方法。
Smart Images

Figure CN121304892B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal device technology, and in particular to a text rendering method and an electronic device. Background Technology
[0002] With the development of terminal technology, the display elements in the human-computer interaction interface of electronic devices (such as mobile phones, tablets, etc.) are becoming increasingly diverse, increasing the diversity of human-computer interaction. Of course, text remains the most common display element.
[0003] Electronic devices consume memory resources during text rendering. In scenarios requiring the rendering of large amounts of text, such as those displaying text animation effects, significant memory usage can occur, potentially triggering memory cleanup and causing lag. Summary of the Invention
[0004] In view of this, this application provides a text rendering method and electronic device for reducing the memory resources occupied and the frequency of triggering memory cleanup in the scene of text rendering, thereby avoiding lag.
[0005] To achieve the above objectives, this application adopts the following technical solution:
[0006] Firstly, the text rendering method provided in this application is applied to an electronic device. In scenarios where the electronic device needs to display text animation effects for target text, first text drawing information can be detected. This first text drawing information indicates the target text to be rendered and drawn on a first image frame for a first display effect, such as target text with a display size of a first size. The electronic device can calculate and render the first glyph data corresponding to the first text drawing information. It is understood that the first glyph data is the actual data of the target text that can participate in rendering the first display effect, which can improve the rendering efficiency of the target text for the first display effect. The display effect of text rendered according to different glyph data is different, while the display effect of text rendered according to the same glyph data is the same. Furthermore, the display effect can include multiple aspects such as font type, display posture, and display size.
[0007] The electronic device then stores the first glyph data in the target storage area. In this way, the electronic device can read the first glyph data from the target storage area and render and draw the target text on the first image frame according to the first glyph data.
[0008] After the target text is drawn on the first image frame, the electronic device may also detect second text drawing information. This second text drawing information indicates that the target text with a second display effect should be rendered and drawn on the second image frame; for example, the target text with a second display size. If the difference between the first and second display effects is not significant—for example, if their similarity meets a preset condition—there is no need to calculate or render the glyph data corresponding to the second text drawing information, nor is it necessary to occupy memory resources to store the glyph data corresponding to the second text drawing information. Instead, the target text is rendered and drawn on the second image frame by reusing the first glyph data.
[0009] In the above embodiments, when the display effects of the target text to be drawn are relatively similar, by reusing glyph data, the efficiency of text rendering is ensured while reducing the generation of new glyph data, avoiding excessive memory consumption, and effectively reducing the frequency of triggering memory cleanup, thus avoiding problems such as stuttering.
[0010] In some embodiments, after the target text is drawn on the first image frame, the electronic device may also detect third text drawing information. This third text drawing information indicates that the target text should be rendered and drawn with a third display effect on the third image frame. For example, target text with a third display size.
[0011] When the difference between the third display effect and the first display effect can be distinguished, for example, when the similarity between the two does not meet a preset condition, the electronic device does not reuse the first glyph data. Instead, it recalculates and renders the second glyph data corresponding to the third text drawing information and stores it in the target storage area. It is understood that the second glyph data is the data of the target text that actually participates in rendering the third display effect, which can improve the rendering efficiency of the target text in the third display effect. The electronic device obtains the second glyph data from the target storage area and renders and draws the target text on the third image frame according to the second glyph data.
[0012] Understandably, the target text rendered according to the first glyph data will have a different display effect than the target text rendered according to the third glyph data. In the above embodiment, if there is a distinguishable difference between the third display effect and the first display effect, the third glyph data is calculated and rendered, and then the target text is drawn on the third image frame according to the third rendering data. This ensures that the display effect of the target text in multiple image frames is basically consistent with the display effect required by the text animation. Of course, the overall memory resource usage can also be relatively reduced.
[0013] In one implementation, after detecting the first text drawing information, the electronic device can generate a first text descriptor based on the first text drawing information. The first text descriptor inherits most of the text attribute information used to describe the display effect of the target text from the first text drawing information. However, the third scaling factor in the first text descriptor differs from the first scaling factor in the first text drawing information. In this implementation, the third scaling factor is data obtained after truncating the first scaling factor. For example, the first scaling factor includes N significant digits, where N is a positive integer greater than 1, and the third scaling factor includes NM significant digits, where M is a positive integer less than N and greater than 0; the significant digits of the third scaling factor are the same as the first NM significant digits of the first scaling factor. Afterwards, the electronic device can calculate and render the first glyph data corresponding to the first text drawing information according to the first text descriptor.
[0014] After detecting the second text drawing information, the electronic device can generate a second text descriptor based on the second text drawing information. Similarly, the second text descriptor inherits most of the text attribute information used to describe the display effect of the target text from the second text drawing information. However, the fourth scaling factor in the second text descriptor is different from the second scaling factor in the second text drawing information. In this implementation, the fourth scaling factor is data obtained after truncating the second scaling factor. For example, the second scaling factor includes N significant digits, where N is a positive integer greater than 1, and the fourth scaling factor includes NM significant digits, where M is a positive integer less than N and greater than 0. The significant digits of the fourth scaling factor are the same as the first NM significant digits of the second scaling factor. When the fourth scaling factor is the same as the third scaling factor, the electronic device can obtain the first glyph data corresponding to the first text descriptor from the target storage area and draw the target text on the second image frame according to the first glyph data.
[0015] In the above embodiments, the text descriptors of the glyph data stored in the target storage area are precisely truncated. This makes it easier to match glyph data in the target storage area using precisely truncated text descriptors, reducing the need to trigger the generation of new glyph data, reducing memory resource consumption, and improving the reuse rate of glyph data in the target storage area.
[0016] In some embodiments, when an electronic device stores first glyph data, it may store a corresponding first character descriptor of the first glyph data.
[0017] Understandably, the first text descriptor is the key used to locate the first glyph data in the target storage area. In the above embodiment, the scaling factor in the first text descriptor has been truncated for precision, making the first glyph data easier to match. This improves the utilization rate of the first glyph data after it is stored.
[0018] As another implementation, after detecting the first text drawing information, the electronic device can generate a third text descriptor based on the first text drawing information. The third text descriptor inherits all the text attribute information from the first text drawing information used to describe the display effect of the target text. For example, the third text descriptor includes a fifth scaling factor, which is the same as the first scaling factor. Then, the electronic device can calculate and render the first glyph data corresponding to the first text drawing information according to the third text descriptor.
[0019] After detecting the second text drawing information, the electronic device can generate a fourth text descriptor based on the second text drawing information. The fourth text descriptor inherits all the text attribute information from the second text drawing information used to describe the display effect of the target text. For example, the fourth text descriptor includes a sixth scaling factor, which is the same as the second scaling factor. If the difference between the sixth scaling factor and the fifth scaling factor is less than a preset threshold, the target text is drawn on the second image frame according to the first glyph data.
[0020] In the above embodiments, the probability of matching the glyph data already stored in the target storage area can also be increased, the process of triggering the generation of new glyph data can be reduced, the occupation of memory resources can be reduced, and the reuse rate of glyph data in the target storage area can be improved.
[0021] In some embodiments, when an electronic device stores first glyph data, it may store a corresponding third character descriptor of the first glyph data.
[0022] Understandably, the third character descriptor is a key used to locate the first character data in the target storage area. In the above embodiment, the efficiency of locating the first character data can be improved.
[0023] In some embodiments, the electronic device generates a first text descriptor based on the first text drawing information. After determining that there is no text descriptor identical to the first text descriptor in the target storage area, it calculates and renders the first glyph data corresponding to the first text drawing information according to the first text descriptor.
[0024] In other embodiments, the electronic device generates a third text descriptor based on the first text drawing information. After determining that there is no text descriptor similar to the third text descriptor in the target storage area, it calculates and renders the first glyph data corresponding to the first text drawing information according to the third text descriptor. Here, "similar text descriptors" refers to text descriptors whose scaling factor difference is less than a preset threshold.
[0025] In some embodiments, both the first and second text drawing information carry multiple text attribute information, which are used to describe the display effect of the target text on the image frame. These multiple text attribute information include a scaling factor describing the display size, and may also include font type, font size, horizontal scaling factor (before font application), horizontal slant factor (before font application), scaling factor after font application, slant factor after font application, font outline width, etc. In the above embodiments, the first and second text drawing information are identical except for the scaling factor.
[0026] In the above embodiments, when implementing the enlarged text animation effect for the target text, the generation of glyph data can be effectively reduced, and the occupation of memory resources can be reduced.
[0027] In some embodiments, the similarity between the first display effect and the second display effect can be a numerical value evaluated based on multiple text attribute information carried in the first and second text drawing information. The preset conditions are evaluation criteria set for the degree of similarity of the display effects.
[0028] Similarly, the similarity between the first and third display effects can be a numerical value evaluated based on multiple text attribute information carried in the first and third text drawing information.
[0029] In some embodiments, after detecting third text rendering information, the electronic device can generate a fifth text descriptor based on the third text rendering information. Similarly, the fifth text descriptor inherits most of the text attribute information used to describe the display effect of the target text from the third text rendering information. However, the eighth scaling factor in the fifth text descriptor differs from the seventh scaling factor in the third text rendering information. In this implementation, the eighth scaling factor is data obtained after truncating the seventh scaling factor. For example, the seventh scaling factor includes N significant digits, where N is a positive integer greater than 1, and the eighth scaling factor includes NM significant digits, where M is a positive integer less than N and greater than 0. The significant digits of the eighth scaling factor are the same as the first NM significant digits of the seventh scaling factor.
[0030] In this embodiment, the eighth scaling factor is different from the third scaling factor. The electronic device needs to generate second glyph data that matches the fifth text descriptor and draw the target text on the third image frame according to the second glyph data.
[0031] In some embodiments, the electronic device includes a target application and a rendering thread. During the display of the target application's interface, a target operation from the user is received. This target operation triggers the display of text animation effects for the target text. The target application sends the first text drawing information to the rendering thread, triggering the rendering thread to render and draw the target text of a first size on a first image frame. Then, the target application can also send the second text drawing information to the rendering thread, triggering the rendering thread to render and draw the target text of a second size on a second image frame. Alternatively, the target application can send the third text drawing information to the rendering thread, triggering the rendering thread to render and draw the target text of a second size on a third image frame. Thus, when the electronic device sequentially displays the graphical interfaces corresponding to the first, second, and third image frames, text animation effects for the target text can be presented on the displayed graphical interfaces.
[0032] In a second aspect, an electronic device is provided in the embodiments of this application. The electronic device includes one or more processors and a memory. The memory is coupled to the processor and is used to store computer program code, which includes computer instructions. When one or more processors execute the computer instructions, the one or more processors are used to perform the methods described in the first aspect and its possible embodiments.
[0033] Thirdly, embodiments of this application provide a computer storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the methods described in the first aspect and its possible embodiments.
[0034] Fourthly, this application provides a computer program product that, when run on the aforementioned electronic device, causes the electronic device to perform the methods described in the first aspect and its possible embodiments.
[0035] Understandably, the electronic devices, computer storage media, and computer program products provided in the above aspects are all applied to the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here. Attached Figure Description
[0036] Figure 1 An example diagram of an application scenario provided in this application embodiment;
[0037] Figure 2An example diagram illustrating the principle of memory resource usage when drawing text of different display sizes;
[0038] Figure 3 An example diagram of the software structure of an electronic device provided in an embodiment of this application;
[0039] Figure 4 A flowchart illustrating the steps of a text rendering method provided in this application embodiment;
[0040] Figure 5 To execute Figure 4 When the method shown is found, an example image of the target text is rendered and drawn.
[0041] Figure 6 To execute Figure 4 When the method shown does not find matching glyph data, an example image of the target text is rendered and drawn.
[0042] Figure 7 A flowchart illustrating the steps of a first implementation method for a text rendering method provided in this application embodiment;
[0043] Figure 8 To execute Figure 7 The method shown illustrates the principle of drawing text on rendering frame 1.
[0044] Figure 9 To execute Figure 7 The method shown illustrates the principle of drawing text on rendering frame 2.
[0045] Figure 10 To execute Figure 7 The method shown illustrates the principle of drawing text on rendering frame 3.
[0046] Figure 11 A flowchart illustrating the steps of a second implementation method for a text rendering method provided in this application embodiment;
[0047] Figure 12 This is an example diagram illustrating the effect of text animation using a text rendering method provided in this application embodiment;
[0048] Figure 13 Example images showing the comparison of text animation effects achieved using relevant text rendering techniques;
[0049] Figure 14 This is an example diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0050] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. In the description of this application, unless otherwise stated, "at least one" refers to one or more, and "more than one" refers to two or more. Furthermore, to facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first," "second," etc., are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and that "first," "second," etc., do not necessarily imply differences.
[0051] When rendering text, an electronic device first needs to calculate the glyph data corresponding to that text. This glyph data represents the display effect of the corresponding text. For example, this glyph data is calculated based on information such as the display size (or display dimensions), font type, display orientation, and outline width of the text. For instance, the glyph data may include the relative positional relationships between the pixels corresponding to each stroke of the text. After calculating the glyph data, the electronic device can cache it in a pre-selected cache area. Then, when the electronic device actually renders the text, it reads the glyph data from the cache area and, based on the glyph data, draws the text on the layer used to present the text (such as a text rendering layer).
[0052] Understandably, even the same character will have different glyph data depending on the display size, font type, display posture, or outline width. After an electronic device renders a large number of characters with different display sizes, font types, display postures, or outline widths, a large amount of glyph data will be generated, which will in turn consume a lot of memory resources.
[0053] Text animation effects are frequent occurrences when users interact with electronic devices. When electronic devices display text animation effects, they render a large number of texts with different display sizes, font types, display postures, and / or outline widths. Consequently, a large amount of glyph data is generated, consuming significant memory resources.
[0054] like Figure 1As shown, the electronic device displays a desktop interface 101, and application icons of applications are displayed in the desktop interface 101, for example, the application icon 102 of a browser application. In addition, in the desktop interface 101, an application name 103 of the browser application is further displayed corresponding to the application icon 102, that is, the text "Browser". Before the electronic device receives a user's click on the application icon 102, the display size of the application name 103 displayed corresponding to the application icon 102 is size 1, and the application name 103 of size 1 is also referred to as application name 103-1. After the electronic device receives the user's click on the application icon 102, the display sizes of the application icon 102 and the corresponding application name 103 increase. For example, the application name 103 is enlarged from size 1 to size 2, and the application name 103 of size 2 is also referred to as application name 103-2. By enlarging the application icon 102 and the application name 103, the user is prompted that the currently selected application is the browser application. In addition, between the electronic device displaying the application name 103-1 and displaying the application name 103-2, an enlarging text animation effect can be connected, so that the above enlarging process is more visually coherent.
[0055] After that, the electronic device displays the application window 104 of the browser application on the desktop interface 101. The above application window 104 may also include text. The display size of the application window 104 gradually increases until the application window 104 is displayed in full screen. During the process in which the display size of the application window 104 increases, the display size of the text in the application window 104 also increases, and the electronic device may connect the process of the text in the application window 104 becoming larger by displaying an enlarging text animation effect.
[0056] In subsequent embodiments, taking the display of the enlarged text special effect of the character "Liu" as an example, details are introduced that a large amount of glyph data is generated and a large amount of memory resources are occupied when displaying the text animation effect.
[0057] As Figure 2 shown, the electronic device includes a rendering thread. The above rendering thread may invoke the rendering capability of the electronic device to calculate and render various types of text, graphics, and the like. The process in which the electronic device implements displaying the character "Liu" using the enlarging text animation effect on the desktop interface is as follows:
[0058] (1) The rendering thread continuously renders a plurality of rendering frames, where a rendering frame includes a plurality of layers, for example, including a layer for drawing the character "Liu", which may also be referred to as a text rendering layer. It can be understood that the above rendering frames may be synthesized into a desktop interface on which the character "Liu" is displayed. The display size of the character "Liu" drawn on the text rendering layer in each rendering frame is different. For example, the character "Liu" drawn on the text rendering layer of the i-th rendering frame corresponding to the text animation effect has a larger display size than the character "Liu" drawn on the text rendering layer in the (i+1)-th rendering frame, where i is a positive integer greater than zero.
[0059] Wherein, before drawing the character "浏" on the text rendering layer, the rendering thread generates relevant information describing the character "浏" to be drawn, which is referred to as a text descriptor, for example.
[0060] Exemplarily, the text descriptor includes: a font ID (representing the font type), a font size, a scaling coefficient, a horizontal scaling factor of the font (before applying the font), a horizontal shearing factor of the font (before applying the font), a scaling coefficient after applying the font, a shearing coefficient after applying the font, a font outline width, and the like. The aforementioned scaling coefficient and font size can represent the display size of the text drawn on the text rendering layer. Generally, a character is of the single-precision floating point type float, which has a precision of 6-7 significant digits. Taking a precision of 6 significant digits as an example, in the case where the font size is the same, the display sizes represented by the scenario where the scaling coefficient in the text descriptor is 0.959991 and the scenario where the scaling coefficient in the text descriptor is 0.959992 are different.
[0061] As Figure 2 shown, when the rendering thread renders the first rendering frame corresponding to the text animation effect, it may generate text descriptor 1 for describing the character "浏" that needs to be drawn in the text rendering layer of the first rendering frame. Wherein, the scaling coefficient in text descriptor 1 is 0.959991. Then, the rendering thread may generate corresponding glyph data 1 based on text descriptor 1. Next, the text descriptor 1 and the glyph data 1 are correspondingly stored into the cache area. After that, the rendering thread acquires the glyph data 1 from the cache area, and draws the character "浏" with a display size of dimension a in the text rendering layer 201 based on the glyph data 1. Wherein, the text rendering layer 201 is a layer in the first rendering frame.
[0062] When the rendering thread renders the second rendering frame corresponding to the text animation effect, it may generate text descriptor 2 for describing the character "浏" that needs to be drawn in the text rendering layer of the second rendering frame. Wherein, the scaling coefficient in text descriptor 2 is 0.959996. There is a difference between text descriptor 1 and text descriptor 2. The glyph data 2 generated based on text descriptor 2 is also different from glyph data 1. Then, the rendering thread may correspondingly store text descriptor 2 and glyph data 2 into the cache area. After that, the rendering thread acquires the glyph data 2 from the cache area, and draws the character "浏" with a display size of dimension b in the text rendering layer 202 based on the glyph data 2. Wherein, the text rendering layer 202 is a layer in the second rendering frame. The dimension b is slightly larger than the dimension a.
[0063] When the rendering thread renders the third rendering frame corresponding to the text animation, it may generate the text descriptor 3 for the character "浏" that needs to be drawn in the text rendering layer of the third rendering frame, where the scaling coefficient in the text descriptor 3 is 0.960001. The text descriptor 3 differs from the text descriptor 2. The glyph data 3 generated based on the text descriptor 3 is also different from the glyph data 2. Then, the rendering thread may correspondingly store the text descriptor 3 and the glyph data 3 into the cache area. After that, the rendering thread obtains the glyph data 3 from the cache area, and draws the character "浏" with a display size of dimension c in the text rendering layer 203 based on the glyph data 3, where the text rendering layer 203 is a layer in the third rendering frame. The dimension c is slightly larger than the dimension b.
[0064] By analogy, all rendering frames corresponding to the text animation are rendered, and the scaling coefficient in the text descriptor corresponding to each rendering frame is different. For example, the scaling coefficient in the text descriptor gradually increases with a step of 0.000005, so that the display size of the character "浏" actually drawn in the text rendering layer of different rendering frames will also gradually increase.
[0065] (2) The graphics synthesizer in the electronic device may synthesize corresponding desktop interface frames frame by frame based on the rendering frames, and transmit them to the display screen of the electronic device frame by frame. For example, based on the first rendering frame, a synthesized desktop interface frame includes the character "浏" with a display size of dimension a. Based on the second rendering frame, a synthesized desktop interface frame includes the character "浏" with a display size of dimension b. Based on the third rendering frame, a synthesized desktop interface frame includes the character "浏" with a display size of dimension c, and so on.
[0066] (3) The display screen displays the desktop interface frames from the graphics synthesizer frame by frame. For example, the characters "浏" with sizes of dimension a, dimension b, dimension c... are sequentially displayed on the desktop interface, presenting the zoom-in text animation of "浏".
[0067] In Figure 2 the illustrated example, if the generated text descriptors differ only in the scaling coefficient, for example, only the scaling coefficient differs by 0.000005 between the text descriptor 1 and the text descriptor 2, the display size corresponding to the text descriptor 1 is also different from the display size corresponding to the text descriptor 2. Although it is difficult for the naked eye to distinguish between dimension a and dimension b, the glyph data 1 of the text descriptor 1 and the glyph data 2 of the text descriptor 2 are different data, and the glyph data 1 and the glyph data 2 respectively occupy one storage space in the cache area.
[0068] In this way, during the display of text animation effects on electronic devices, the text descriptor corresponding to each rendering frame of the text animation effect is different. During the rendering of each rendering frame, corresponding glyph data is generated and occupies a storage space in the cache area. Even if the visual difference between the text to be drawn in the text rendering layer of two adjacent rendering frames is small, different glyph data will be generated, and each will occupy a storage area in the cache area.
[0069] The above only illustrates a scenario of displaying a single enlarged text animation. In actual applications, electronic devices can display multiple text animations simultaneously. Furthermore, text animations are not limited to changes in display size; they can also include changes in font type, display posture, or / or outline width. In other words, the amount of character data generated and the memory resources occupied when an electronic device actually displays text animations are considerable.
[0070] To address the aforementioned issues, this application provides a text rendering method applicable to electronic devices including displays (such as touchscreens). This method improves the reuse rate of cached glyph data, reduces the memory resources required for text rendering, lowers the frequency of memory cleanup, and prevents stuttering.
[0071] For example, the electronic device in this application embodiment may be a mobile phone, tablet computer, smartwatch, desktop, laptop, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, as well as cellular phone, personal digital assistant (PDA), augmented reality (AR) / virtual reality (VR) device, etc., including a display screen. This application embodiment does not impose any special restrictions on the specific form of the electronic device.
[0072] Figure 3 This is a software structure block diagram of an electronic device provided in an embodiment of this application. A layered architecture divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the electronic device may include an application layer (referred to as the application layer), an application framework layer, system libraries, and Android... TM Runtime (Android Runtime), services, kernel layer, etc.
[0073] For example, the application layer described above may include a series of applications.
[0074] For example, the application layer mentioned above may include system-level applications such as desktop managers (launchers). The application layer may also include third-party applications such as browsers; this embodiment of the application does not specifically limit this.
[0075] Launcher is an application that provides desktop services to users. It is mainly used to display application icons of various applications, receive user operations on application icons, respond to user operations on application icons, run the corresponding applications, and display a multitasking interface.
[0076] In addition, Figure 3 In addition to the applications shown, the application layer may also include Figure 3 The application not shown in the embodiments of this application is not specifically limited in this respect.
[0077] As another example, the application framework layer described above can provide application programming interfaces (APIs) and programming frameworks to applications within the application layer. The application framework layer includes some predefined functions.
[0078] like Figure 3 As shown, a rendering thread runs in the application framework layer, and this embodiment of the application does not impose any restrictions on it. Applications in the application layer can call the rendering thread to render and draw specified graphics or text.
[0079] For example, the aforementioned system library provides basic capabilities such as rendering, communication, data management, and application runtime criticality. The system library may include multiple functional modules, such as the Java Native Interface (JNI) and the Graphical User Interface (GUI).
[0080] The GUI is a standalone software module used to assist other software modules in communicating with the surface flinger (SF) of the service layer.
[0081] JNI, as mentioned above, is a programming framework that allows Java programs in the Java Virtual Machine to call native applications / libraries, and can also be called by other programs.
[0082] Of course, besides Figure 3 In addition to the GUI and JNI shown, the system library may also include Figure 3modules not shown in, for example, a 3D graphics processing library (e.g., OpenGL ES), SQLite, WebKit, a 2D vector graphics processing function library (Skia), etc.
[0083] As another example, the Android runtime includes core libraries and a virtual machine. The Android runtime is responsible for scheduling and management of the Android system.
[0084] The core libraries include two parts: one part is the functional functions that need to be called by the Java language, and the other part is the core libraries of Android.
[0085] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0086] As still another example, the above service layer may provide basic services of the Native layer, such as graphics, Video, Audio, etc. The above service layer may include SF. The SF is a special service for processing graphics data, for example, synthesizing a corresponding graphical interface based on a rendered frame rendered by a rendering thread.
[0087] As still another example, the kernel layer is located below the native layer, and is a layer between hardware and software. The kernel layer may include Figure 3 the display driver shown in. The SF may send the synthesized graphical interface to the display driver, and control the display screen to display the graphical interface through the display driver.
[0088] In addition, the kernel layer may further include Figure 3 a camera driver, an audio driver, various types of sensor drivers and the like not shown in, which is not limited in any way by the embodiments of the present application.
[0089] All the text rendering methods provided in the embodiments of the present application may be implemented in a device having the above software structure. In the following, taking an application program instructing to display a target text as an example, the implementation details of the above text rendering method are introduced. As Figure 4 shown in, the above method may include:
[0090] In S101, the application program may send target text rendering information to a rendering thread, to instruct to render a target text.
[0091] For example, the target text rendering information may instruct the rendering thread to render the target text in a target rendered frame, for example, when the target text is the character "浏", the target text rendering information may instruct the rendering thread to render the character "浏" on the target rendered frame.
[0092] Understandably, a rendering frame includes multiple layers, including a text rendering layer for drawing text and other layers for drawing other interface elements. The target rendering frame also includes a target text rendering layer for rendering target text, and other layers for rendering other interface elements. Accordingly, in addition to sending target text drawing information to the rendering thread to instruct the rendering thread to draw the target text on the target text rendering layer of the target rendering frame, the application can also send other types of drawing information to the rendering thread to instruct the rendering thread to draw other types of interface elements on other layers of the target rendering frame. This embodiment of the application does not specifically limit this.
[0093] In addition, the aforementioned target text rendering information carries the text attribute information of the target text. This text attribute information can describe the application's requirements for the display effect of the target text. For example, the text attribute information may include, but is not limited to, the target text's font type, font size, scaling factor, slant factor, font outline width, etc. For instance, the font type can describe the application's font requirements for the target text; the font size and scaling factor can describe the application's requirements for the display size of the target text; the slant factor can describe the application's requirements for the display posture of the target text; and the font outline width can describe the application's requirements for the display width of the target text, etc.
[0094] S102, the rendering thread records the target text drawing information.
[0095] In some embodiments, after receiving the target text drawing information, the rendering thread can record all the text attribute information carried in the target text drawing information.
[0096] S103, the rendering thread sends a recording completion notification to the application.
[0097] The aforementioned completion notification indicates that the rendering thread has received the target text rendering information. This allows the application to continue sending text rendering information to the rendering thread, instructing it to render other target text. If the rendering thread receives other text rendering information before completing the rendering of the target frame, it will render the next frame based on that other text rendering information after completing the rendering of the target frame.
[0098] S104, the rendering thread generates a target text descriptor based on the recorded target text drawing information.
[0099] In some embodiments, when the rendering thread receives a vertical synchronization signal instructing the rendering of the target rendering frame, it can generate a target text descriptor for the target text based on the recorded target text rendering information.
[0100] Herein, the target text descriptor may be composed of each piece of text attribute information of the target text.
[0101] In some embodiments, each piece of text attribute information in the target text descriptor is completely identical to each piece of text attribute information in the target text rendering information.
[0102] In other embodiments, there is a difference between the scaling factor of the target text in the target text descriptor and the scaling factor of the target text in the target text rendering information. For example, the number of significant digits of the scaling factor is different. The significant digits of the scaling factor of the target text in the target text rendering information are 6 digits (for example, the scaling factor corresponding to the target text in the target text rendering information is 0.959991). The significant digits of the scaling factor of the target text in the target text descriptor are 2 digits (for example, the scaling factor of the target text in the target text descriptor is 0.95).
[0103] In S105, the rendering thread determines whether there is target glyph data matching the target text descriptor in the cache area.
[0104] As described in the foregoing embodiments, the glyph data is data generated based on the text descriptor. After the glyph data is generated, the rendering thread may correspondingly store the text descriptor and the glyph data into the cache area. In the cache area, the text descriptor may be regarded as a lookup tag for the glyph data.
[0105] In some embodiments, the rendering thread may use the target text descriptor generated in S104 to look up in the cache area whether there is an identical or similar text descriptor. Herein, the identical text descriptor refers to the same text (for example, the target text), and all recorded text attribute information is completely identical. The above-mentioned similar text descriptor refers to the same text (for example, the target text), all text attribute information except the scaling factor is completely identical, and of course, the difference between the scaling factors does not exceed a preset threshold.
[0106] Optionally, if a text descriptor that is identical or similar to the target text descriptor is stored in the cache area, it is determined that there is target glyph data matching the target text descriptor in the cache area. As Figure 5 in the scenario shown, the target text is the Chinese character "浏", and after the rendering thread determines that there is target glyph data matching the target text descriptor in the cache area, S106 is executed.
[0107] Optionally, if there is no text descriptor that is identical or similar to the target text descriptor in the cache area, it is determined that there is no glyph data matching the target text descriptor in the cache area. As Figure 6In the scenario shown, after the rendering thread determines that there is no glyph data matching the target text descriptor in the cache area, S107 to S109 are executed.
[0108] In S106, the rendering thread draws the target text on the target text drawing layer of the target rendering frame based on the target glyph data.
[0109] As shown in Figure 5 the scenario shown, the target text is the Chinese character "浏", and the rendering thread finds the matching glyph data, that is, the target glyph data, according to the target text descriptor of "浏". The rendering thread may read the target glyph data corresponding to the character "浏" from the cache area, and on the target text drawing layer of the target rendering frame (that is, Figure 5 the text drawing layer 501 in), draw the character "浏".
[0110] In S107, the rendering thread generates corresponding target glyph data based on the target text descriptor.
[0111] In S108, the rendering thread correspondingly stores the target text descriptor and the target glyph data into the cache area.
[0112] In S109, the rendering thread reads the target glyph data from the cache area, and draws the target text on the target text drawing layer of the target rendering frame based on the target glyph data.
[0113] As shown in Figure 6 the scenario shown, the target text is the character "浏", and no glyph data matching the target text descriptor is stored in the cache area. The rendering thread needs to first generate the corresponding target glyph data based on the target text descriptor of the character "浏". Then, the target text descriptor and the target glyph data of the character "浏" are correspondingly stored into the cache area. After that, the rendering thread reads the target glyph data from the cache area, and on the target text drawing layer of the target rendering frame (that is, Figure 6 the text drawing layer 601 in), draw the character "浏".
[0114] In S110, the rendering thread sends the target rendering frame to SF.
[0115] In some embodiments, after completing the rendering and drawing of all layers in the target rendering frame, the rendering thread may send the target rendering frame to the SF.
[0116] In S111, the SF synthesizes the target graphical interface corresponding to the target rendering frame.
[0117] Wherein, the target graphical interface includes the target text indicated to be displayed by the application program.
[0118] S112, SF indicates that the display screen shows the target graphical interface.
[0119] In the above embodiments, when searching for target glyph data in the cache area, not only glyph data with the same text description can be used as target glyph data matching the target text descriptor, but also glyph data with similar text descriptions can be used as target glyph data matching the target text descriptor. This increases the probability of executing S106 after S105, reduces the probability of executing S107-S108, avoids storing too much glyph data in the cache area, improves the reuse rate of glyph data already stored in the cache area, and reduces the occupation of the cache area. Especially in scenarios implementing text enlargement animations for target text, this avoids a large amount of memory resources being occupied in a short time and also reduces the frequency of triggering memory cleanup.
[0120] The following is combined with Figure 1 The scenario illustrated demonstrates several implementation methods of the method provided in the embodiments of this application. Figure 1 In the scenario shown, the electronic device responds to the user's click on the application icon 102 by using a text enlargement animation, and the display size of the application name 103 changes from size 1 to size 2. Figure 1 In the scenario shown, the desktop manager (the application responsible for managing the desktop) instructs the rendering thread to draw application names 103 of different sizes across multiple consecutive rendering frames. During the display of the desktop interface, the desktop manager is the target application. The user's action of clicking the application icon 102 can be called a target action, which triggers text animations for the application name (i.e., the target text). Specifically, in the consecutive rendering frames, the desktop manager instructs the application name 103 of size 1 to be drawn on the first rendering frame, and the application name 103 of size 2 to be drawn on the last rendering frame. The application name 103 larger than size 1 and smaller than size 2 is drawn on the (i+1)th rendering frame, where i can be a positive integer greater than 0. For example, the application name 103 of size 3 is drawn on the second rendering frame, where size 3 is slightly larger than size 1 and smaller than size 2. The desktop manager instructs the display size of the application name 103 drawn in the previous rendering frame to be smaller than the application name 103 drawn in the next rendering frame. In this way, when the electronic device sequentially displays the graphical interface (e.g., desktop interface) corresponding to multiple consecutive rendering frames, it can present an animation effect of the application name 103 gradually increasing in size from size 1 to size 2 on the desktop interface.
[0121] In subsequent embodiments, the first rendered frame is referred to as rendered frame 1, the second rendered frame as rendered frame 2, the third rendered frame as rendered frame 3, and so on. The desktop manager may instruct to draw the application name 103 with size 2 on rendered frame 1, draw the application name 103 with size 3 on rendered frame 2, and draw the application name with size 4 on rendered frame 3. Size 1 is smaller than size 3, and size 3 is smaller than size 4. In addition, the application name 103 includes a plurality of characters, for example, "浏", "览" and "器", and the drawing process of each character is the same. In subsequent embodiments, the description is mainly made by taking that the desktop manager may instruct to draw the character "浏" on the rendered frame as an example. In the application name 103 with size 2, the font size of the character "浏" is A, and the scaling factor is 0.959991. In the application name 103 with size 3, the font size of the character "浏" is A, and the scaling factor is 0.959996. In the application name 103 with size 4, the font size of the character "浏" is A, and the scaling factor is 0.960001.
[0122] The first implementation manner: before the desktop manager instructs to draw the target character "浏" on rendered frame 1, the cache area does not contain glyph data related to the character "浏". As Figure 7 shown above, the above method may include:
[0123] S201: After the desktop manager receives a user's operation of clicking the application icon 102, the desktop manager sends text drawing information 1 to the rendering thread, and the scaling factor carried in the text drawing information 1 is 0.959991.
[0124] The text drawing information 1 (which may be referred to as first text drawing information) may instruct the rendering thread to draw the target character with a first size (e.g., the character "浏") in rendered frame 1 (the first image frame). Various types of text attribute information carried in the text drawing information 1 may describe the requirement of the desktop manager for the display effect of the target character (e.g., the character "浏") in the graphical interface corresponding to rendered frame 1. Exemplarily, the text drawing information 1 includes a scaling factor, which is 0.959991 and has six significant digits. The scaling factor in the text drawing information 1 may also be referred to as a first scaling factor, the number of significant digits of which is N bits, where N is a positive integer greater than 1. The first scaling factor may describe that the display size of the target character in the first image frame needs to be the first size.
[0125] S202: The rendering thread records the text drawing information 1.
[0126] S203: The rendering thread sends a recording completion notification 1 to the desktop manager.
[0127] The completion notification 1 indicates that the rendering thread has received the text drawing information 1. After the desktop manager receives the completion notification 1, the desktop manager executes the conditions in S209. Of course, there is no necessary order between S209 and S204 to S208.
[0128] S204, the rendering thread generates text descriptor 1 based on text drawing information 1. The scaling factor in text descriptor 1 is 0.95.
[0129] In some embodiments, the rendering thread performs precision truncation based on the scaling factor (i.e., 0.959991) in the text drawing information 1 to obtain the scaling factor in the text descriptor 1. The text descriptor 1 can be referred to as the first text descriptor, and the scaling factor in the text descriptor 1 can be referred to as the third scaling factor. For example, the above precision truncation process can change the number of significant digits from N bits (e.g., 6 bits) to NM bits (e.g., 2 bits), where M is a positive integer less than N and greater than 0. For example, the first two significant digits can be retained, and the last four significant digits can be discarded. Thus, after performing precision truncation on 0.959991, the scaling factor in the text descriptor 1 is obtained as 0.95.
[0130] In addition, apart from the scaling factor, the text attribute information in text descriptor 1 is the same as the text attribute information in text drawing information 1.
[0131] S205, the rendering thread determines that the cache area does not contain glyph data that matches text descriptor 1.
[0132] exist Figure 1 In the scenario shown, before receiving the text drawing information 1, the cache area (which can also be called the target storage area) does not contain the relevant glyph data. Consequently, the rendering thread cannot find the glyph data that matches the text descriptor 1.
[0133] S206, the rendering thread generates glyph data 1 based on text descriptor 1.
[0134] Among them, glyph data 1, also known as the first glyph data, is the data used to draw the target text, and can also be called the font cache, which can improve the efficiency of rendering the target text. Different glyph data will result in different display effects of the target text. The same glyph data will result in the same display effect of the target text.
[0135] S207, the rendering thread stores the text descriptor 1 and glyph data 1 into the cache area.
[0136] In S208, the rendering thread reads glyph data 1 from the cache area, and based on the glyph data 1, draws the text indicated by text descriptor 1 on the text drawing layer 1 of rendering frame 1.
[0137] As shown in Figure 8 , after the desktop manager sends text drawing information 1 (with a scaling factor of 0.959991) that instructs to draw the character "Liu" to the rendering thread, the rendering thread generates text descriptor 1 (with a scaling factor of 0.95) for the "Liu" character to be drawn. At this point, there is no text descriptor 1 in the cache area. The rendering thread can generate corresponding glyph data 1 based on the text descriptor 1, and store the text descriptor 1 and the glyph data 1 in the cache area in association with each other. After that, the rendering thread acquires the glyph data 1 from the cache area, and draws the character "Liu" on the text rendering layer 801 (that is, the text rendering layer 1 of rendering frame 1) based on the glyph data 1.
[0138] In addition, after the rendering thread finishes rendering and drawing rendering frame 1, it may further send rendering frame 1 to the SF, so that the SF synthesizes the corresponding graphical interface and transmits it to the display screen for display. For specific details, reference may be made to S110 to S112, which will not be elaborated here for the moment.
[0139] In S209, the desktop manager sends text drawing information 2 to the rendering thread. The scaling factor in the text drawing information 2 is 0.959996, and other text attribute information in the text drawing information 2 is the same as that in the text drawing information 1.
[0140] The text drawing information 2 (which may also be referred to as the second text drawing information) may instruct the rendering thread to draw the target text (for example, the character "Liu") of a second size in rendering frame 2 (for example, referred to as the second image frame). Various types of text attribute information carried in the text drawing information 2 may describe the requirements of the desktop manager for the display effect of the target text (for example, the character "Liu") in the graphical interface corresponding to rendering frame 2. In Figure 1 the scenario shown, except for the scaling factor, other text attribute information in the text drawing information 2 is the same as that in the text drawing information 1. The scaling factor in the text drawing information 2 may also be referred to as a second scaling factor, which has N significant digits. The second scaling factor may describe that the display size of the target text in the second image frame needs to be the second size. In some embodiments, the difference between the first size and the second size is small, which is difficult for a user to distinguish visually. For example, the difference between the first size and the second size is less than a preset value, and the preset value is an empirical value, for example, may be a value mined from a large amount of visual sensitivity evaluation data of users on the difference in text display size.
[0141] In S210, the rendering thread records the text drawing information 2.
[0142] S211, The rendering thread sends a recording completion notification 2 to the desktop manager.
[0143] The completion notification 2 indicates that the rendering thread has received the text drawing information 2. After the desktop manager receives the completion notification 2, the desktop manager executes the conditions in S215.
[0144] Additionally, if the rendering thread receives text drawing information 2 before rendering frame 1 has finished rendering, the rendering thread can record text drawing information 2 and temporarily suspend execution of S212. After rendering frame 1 has finished rendering, the rendering thread will then execute S212.
[0145] S212, the rendering thread generates text descriptor 2 based on text drawing information 2, wherein the scaling factor in the generated text descriptor 2 is also 0.95.
[0146] In some embodiments, the rendering thread performs precision truncation based on the scaling factor in the text drawing information 2 (i.e., the second scaling factor 0.959996) to obtain the scaling factor in the text descriptor 2. Furthermore, text descriptor 2 can also be referred to as the second text descriptor, and the scaling factor in text descriptor 2 can also be referred to as the fourth scaling factor. For example, the above precision truncation process can be to change the number of significant digits from N bits (e.g., 6 bits) to NM bits (e.g., 2 bits), where M is a positive integer less than N and greater than 0. For example, after performing precision truncation on the second scaling factor (0.959996), the fourth scaling factor is also 0.95.
[0147] S213, the rendering thread determines that text descriptor 2 matches the glyph data 1 in the cache area that corresponds to text descriptor 1.
[0148] Understandably, except for the scaling factor, the text attribute information in text descriptor 2 is the same as that in text drawing information 2. The text attribute information in text drawing information 2 is the same as that in text drawing information 1, except for the scaling factor. Furthermore, the scaling factor in text descriptor 2 is also the same as that in text descriptor 1. Thus, the generated text descriptor 2 is completely identical to text descriptor 1. When the rendering thread compares text descriptor 2 with the text descriptors already stored in the cache area, it can determine that text descriptor 2 is the same as text descriptor 1, and it can also match the glyph data 1 corresponding to text descriptor 1.
[0149] S214, the rendering thread, based on glyph data 1, draws the text indicated by text descriptor 2 on the text drawing layer 2 of rendering frame 2.
[0150] like Figure 9As shown, after the desktop manager sends text drawing information 2 (with a scaling factor of 0.959996) instructing to draw the Chinese character "浏" to the rendering thread, the rendering thread generates text descriptor 2 (with a scaling factor of 0.95) for the Chinese character "浏" to be drawn. At this time, text descriptor 2 is identical to the stored text descriptor 1 in the cache area, and it can be determined that the glyph data 1 corresponding to text descriptor 1 matches text descriptor 2. The rendering thread retrieves glyph data 1 from the cache area, and draws the Chinese character "浏" on the text rendering layer 901 (that is, the text rendering layer 2 of rendering frame 2) based on glyph data 1.
[0151] It can be understood that although the display size of the text finally drawn on the text rendering layer 2 is different from the display size of the text that the desktop manager instructs to draw on the text rendering layer 2, such difference is hardly distinguishable by the user. Meanwhile, in the above process, by reusing the glyph data already stored in the cache area, creating new glyph data in the cache area is avoided, and unnecessary occupation of memory resources is reduced.
[0152] S215, the desktop manager sends text drawing information 3 to the rendering thread. The scaling factor in the text drawing information 3 is 0.960001, and other text attribute information in the text drawing information 3 is the same as that in the text drawing information 1.
[0153] The text drawing information 3 (which may be referred to as third text drawing information) may instruct the rendering thread to draw a target text of a third size (for example, the Chinese character "浏") in the rendering frame 3 (which may be referred to as a third image frame), and various types of text attribute information carried in the text drawing information 3 may describe the requirements of the desktop manager for the display effect of the target text (for example, the Chinese character "浏") in the graphical interface corresponding to the rendering frame 3. In Figure 1 the scenario shown, except for the scaling factor, other text attribute information in the text drawing information 3 is also the same as that in the text drawing information 1. The scaling factor in the third text drawing information may also be referred to as a seventh scaling factor. The seventh scaling factor includes N significant digits, where N is a positive integer greater than 1, for example, the seventh scaling factor is 0.960001.
[0154] In some embodiments, the user can visually distinguish the difference between the first size and the third size. For example, the difference between the first size and the second size is not less than a preset value.
[0155] S216, the rendering thread records the text drawing information 3.
[0156] S217, the rendering thread sends a recording completion notification 3 to the desktop manager.
[0157] The recording completion notification 3 is configured to indicate that the rendering thread has received the text drawing information 3.
[0158] In S218, the rendering thread generates text descriptor 3 according to the text drawing information 3, wherein the scaling factor in the generated text descriptor 3 is also 0.96.
[0159] In some embodiments, the rendering thread performs precision truncation processing based on the scaling factor (i.e., 0.960001) in the text drawing information 3 to obtain the scaling factor in the text descriptor 3. The aforementioned text descriptor 3 may also be referred to as a fifth text descriptor, and the scaling factor carried in the text descriptor 3 may also be referred to as an eighth scaling factor. The eighth scaling factor is data obtained by performing precision truncation processing on the seventh scaling factor. For example, the seventh scaling factor is 0.960001, and after the precision truncation processing, the eighth scaling factor is obtained as 0.96.
[0160] In S219, the rendering thread determines that the cache area does not contain glyph data matching the text descriptor 3.
[0161] In Figure 1 the scenario shown, that is, the scenario where an enlarged text special effect needs to be displayed for the character "浏", when the rendering thread generates the text descriptor 3, the only glyph data related to the character "浏" in the cache area is glyph data 1, and the text descriptor 1 of the glyph data 1 is different from the text descriptor 3. The rendering thread may determine that the glyph data 1 does not match the text descriptor 3, and in the case that no other glyph data matching the text descriptor 3 is contained in the cache area, execute S220.
[0162] In S220, the rendering thread generates glyph data 3 based on the text descriptor 3.
[0163] For the details of generating glyph data based on a text descriptor, reference may be made to the foregoing embodiments and related technologies, and no further details are described herein. The glyph data 3 may also be referred to as second glyph data, which is data participating in drawing the target text, and may also be referred to as a font cache, which can improve the efficiency of rendering and drawing the target text. The second glyph data is different from the first glyph data, and the display effect of the target text drawn according to the second glyph data is different from the display effect of the target text drawn according to the first glyph data.
[0164] In S221, the rendering thread correspondingly stores the text descriptor 3 and the glyph data 3 into the cache area.
[0165] In S222, the rendering thread reads the glyph data 3 from the cache area, and draws the text indicated by the text descriptor 3 on the text drawing layer 3 of the rendering frame 3 based on the glyph data 3.
[0166] As Figure 10As shown, after the desktop manager sends text drawing information 3 (with a scaling factor of 0.960001) instructing to draw the character "Liu" to the rendering thread, the rendering thread generates a text descriptor 3 (with a scaling factor of 0.96) for the character "Liu" to be drawn. At this time, the text descriptor 3 is different from the text descriptor 1 already stored in the cache area, and it can be determined that the cache area does not contain glyph data matching the text descriptor 3. The rendering thread needs to calculate the glyph data 3 corresponding to the text descriptor 3, and store the text descriptor 3 and the glyph data 3 in the cache area in association with each other. After that, the rendering thread acquires the glyph data 3 from the cache area, and draws the character "Liu" on the text rendering layer 1001 (that is, the text rendering layer 3 of the rendering frame 3) based on the glyph data 3.
[0167] In this way, while ensuring that the target text drawn in consecutive rendering frames shows an increasing trend, the reuse rate of the stored glyph data can be improved, and the occupation of memory resources can be reduced.
[0168] Second implementation manner: Before the desktop manager instructs to draw the target text "Liu" on the rendering frame 1, the cache area does not contain glyph data related to the character "Liu". As shown in Figure 11 , the above method may include:
[0169] S301: After the desktop manager receives a user's operation of clicking the application icon 102, the desktop manager sends text drawing information 1 to the rendering thread, and the scaling factor carried in the text drawing information 1 is 0.959991.
[0170] S302: The rendering thread records the text drawing information 1.
[0171] S303: The rendering thread sends a recording completion notification 1 to the desktop manager.
[0172] In some embodiments, the above S301 to S303 may refer to S201 to S203 in the foregoing embodiments, and details are not described herein again.
[0173] S304: The rendering thread generates the text descriptor 1 according to the text drawing information 1. The scaling factor in the text descriptor 1 is 0.959991.
[0174] In some embodiments, the text attribute information in the text descriptor 1 is completely the same as the text attribute information in the text drawing information 1. The text descriptor 1 generated in S304 may also be referred to as a third text descriptor, and the carried scaling factor (for example, 0.959991) may also be referred to as a fifth scaling factor.
[0175] S305: The rendering thread determines that the cache area does not contain glyph data matching the text descriptor 1.
[0176] S306, the rendering thread generates glyph data 1 based on text descriptor 1.
[0177] S307, the rendering thread stores the text descriptor 1 and glyph data 1 into the cache area.
[0178] S308, the rendering thread reads glyph data 1 from the cache area, and, based on glyph data 1, draws the text indicated by text descriptor 1 on the text drawing layer 1 of rendering frame 1.
[0179] In some embodiments, S305 to S308 may refer to S205 to S208 in the foregoing embodiments, and will not be repeated here.
[0180] S309, the desktop manager sends text drawing information 2 to the rendering thread. In text drawing information 2, the scaling factor is 0.959996, and other text attribute information is the same as in text drawing information 1.
[0181] S310, the rendering thread records text drawing information 2.
[0182] S311, The rendering thread sends a recording completion notification 2 to the desktop manager.
[0183] S312, the rendering thread generates text descriptor 2 based on text drawing information 2, wherein the scaling factor in the generated text descriptor 2 is also 0.959996.
[0184] In some embodiments, the text attribute information in text descriptor 2 is exactly the same as the text attribute information in text drawing information 2. The text descriptor 2 generated in S312 can also be called the fourth text descriptor, and the scaling factor it carries (e.g., 0.959996) can also be called the sixth scaling factor.
[0185] S313, when the difference between the scaling factor of text descriptor 2 and text descriptor 1 is less than a preset threshold, it is determined that text descriptor 2 matches glyph data 1.
[0186] In some embodiments, the preset threshold can be a pre-configured empirical value, for example, the preset threshold mentioned above can be 0.000006. For the same text, when the font size is the same, the difference between the scaling factors is less than the preset threshold, and the actual display size difference is not significant.
[0187] exist Figure 1 In the example, the difference between the scaling factor of text descriptor 2 and text descriptor 1 is less than the preset threshold. Under the condition that other text attribute information is the same, it indicates that the glyph data 1 of text descriptor 1 can be reused to draw the text indicated by text descriptor 2. That is, it can be determined that text descriptor 2 matches glyph data 1.
[0188] S314, the rendering thread, based on glyph data 1, draws the text indicated by text descriptor 2 on the text drawing layer 2 of rendering frame 2.
[0189] S315, the desktop manager sends text drawing information 3 to the rendering thread. In text drawing information 3, the scaling factor is 0.960001, and other text attribute information is the same as that in text drawing information 1.
[0190] S316, the rendering thread records text drawing information 3.
[0191] S317, the rendering thread sends a recording completion notification 3 to the desktop manager.
[0192] In some embodiments, the implementation details of S315 to S317 can be found in S215 to S217, and will not be repeated here.
[0193] S318, the rendering thread generates a text descriptor 3 based on the text drawing information 3, wherein the scaling factor in the generated text descriptor 3 is also 0.960001.
[0194] In some embodiments, the text attribute information in text descriptor 3 is exactly the same as the text attribute information in text drawing information 3.
[0195] S319, when the difference between the scaling factor of text descriptor 3 and text descriptor 1 is not less than a preset threshold, it is determined that glyph data 1 and text descriptor 3 do not match.
[0196] exist Figure 1 In the scenario shown, the only glyph data related to the character "browse" in the cache area is glyph data 1. The difference between the scaling factor of text descriptor 3 and text descriptor 1 is not less than a preset threshold, indicating that the glyph data of text descriptor 1 cannot be reused to draw the text indicated by text descriptor 3. In other words, glyph data 1 and text descriptor 3 do not match. If the cache area also does not contain other glyph data matching text descriptor 3, then S320 is executed.
[0197] S320, the rendering thread generates glyph data 3 based on text descriptor 3.
[0198] S321, the rendering thread stores the text descriptor 3 and the glyph data 3 into the cache area.
[0199] S322, the rendering thread reads glyph data 3 from the cache area, and, based on the glyph data 3, draws the text indicated by the text descriptor 3 on the text drawing layer 3 of the rendering frame 3.
[0200] In some embodiments, the implementation details of S320 to S322 can be found in S220 to S222, which will not be repeated here.
[0201] In summary, when the desktop manager instructs the drawing of target text with different display effects on different rendering frames, if the differences in the display effects of the target text to be drawn are small, that is, if the similarity between the two meets the preset conditions, the same glyph data can be reused to draw the target text on different rendering frames. If the differences in the display effects of the target text to be drawn are distinguishable, that is, if the similarity between the two does not meet the preset conditions, different glyph data is used to draw the target text on different rendering frames to ensure that the display effect does not deviate from the expectation.
[0202] exist Figure 7 and Figure 11 The method described primarily uses the difference in display effect as a single dimension, meaning the difference in display effect is only exemplified by the difference in display size. In the method described above, the scaling factor for both text descriptors is the same (see reference). Figure 7 (Method) or similar (refer to) Figure 11 When using the method described above, it can be determined that the difference between the display effects indicated by the two text descriptors meets preset conditions. When the scaling factors of the two text descriptors are different (see reference...), Figure 7 The methods are not similar (see reference). Figure 11 When using the method, it can be determined that the difference between the display effects indicated by the two text descriptors does not meet the preset conditions.
[0203] In possible embodiments, the differences in display effects may also include differences in multiple dimensions, such as differences in display posture and display width. After generating text descriptor 1, the electronic device can use an artificial intelligence model to evaluate the quantization parameter 1 representing the display effect, combining the various text attribute information in text descriptor 1. After generating the glyph data 1 of text descriptor 1, the quantization parameter 1 and the glyph data 1 are stored in a cache area. After generating text descriptor 2, an artificial intelligence model can be used to evaluate the quantization parameter 2 representing the display effect, combining the various text attribute information in text descriptor 2. When the difference between quantization parameter 2 and quantization parameter 1 is less than a set value, it is determined that the difference between the display effects meets the preset conditions. After generating text descriptor 3, an artificial intelligence model can be used to evaluate the quantization parameter 3 representing the display effect, combining the various text attribute information in text descriptor 3. When the difference between quantization parameter 3 and quantization parameter 1 is not less than a set value, it is determined that the difference between the display effects does not meet the preset conditions. The above-mentioned set values are empirical values, and this application embodiment does not specifically limit them.
[0204] In the related art, before the desktop manager instructs to draw the target character "浏" on rendering frame 1, the cache area does not contain glyph data related to the character "浏". Most of the steps for drawing the character "浏" are the same as Figure 11 the steps shown in the drawings, with the difference that: in the related art, S313 and S314 are not executed. Since text descriptor 2 and text descriptor 1 are different, the glyph data 1 of text descriptor 1 is not reused to draw the text indicated by text descriptor 2. Correspondingly, the rendering thread may generate glyph data 2 based on text descriptor 2, store text descriptor 2 and glyph data 2 in the cache area in association with each other, then read glyph data 2 from the cache area, and draw the text indicated by text descriptor 2 on the text drawing layer 2 of rendering frame 2 based on glyph data 2.
[0205] In the related art, S319 is also not executed, and after it is determined that text descriptor 3 is different from both text descriptor 1 and text descriptor 2 stored in the cache area, S320 is executed.
[0206] In summary, when the first implementation manner and the second implementation manner are adopted, after N frames of graphical interfaces containing text showing an increasing trend are continuously displayed, the amount of glyph data stored in the cache area is less than N.
[0207] As shown Figure 12 in the drawings, the display screen of the electronic device sequentially displays 6 frames of graphical interfaces containing the target character (i.e., the character "浏"), wherein the displayed first frame of graphical interface contains target text 1201, the displayed second frame of graphical interface contains target text 1202, the displayed third frame of graphical interface contains target text 1203, the displayed fourth frame of graphical interface contains target text 1204, the displayed fifth frame of graphical interface contains target text 1205, and the displayed sixth frame of graphical interface contains target text 1206. As shown Figure 12 in the drawings, target text 1201 and target text 1202 are texts drawn by reusing glyph data 1, and the two have the same display size. Target text 1203 and target text 1204 are texts drawn by reusing glyph data 3, and the two have the same display size. Target text 1205 and target text 1206 are texts drawn by reusing glyph data 5, and the two have the same display size. Certainly, the display size of target text 1206 is larger than that of target text 1204, and the display size of target text 1204 is larger than that of target text 1202. Therefore, on the whole, the target text (i.e., the character "浏") in the graphical interface displayed on the display screen shows an increasing trend, which also belongs to the text animation effect of zooming in. In addition, there are 3 pieces of glyph data for the target text stored in the cache area, which occupies less memory resources.
[0208] In the related art, after N frames of graphical interfaces containing text showing an increasing trend are displayed consecutively, the amount of glyph data stored in the cache area is equal to N. As Figure 13 shown, after the display screen of the electronic device sequentially displays 6 frames of graphical interfaces containing the target text (i.e., the character "浏"), there are 6 pieces of glyph data for the character "浏" stored in the cache area. In contrast, under the condition of achieving the same text enlargement animation effect, the method provided by the embodiments of the present application occupies less memory resources, reduces the frequency of triggering memory cleanup, and avoids stuttering.
[0209] Some embodiments of the present application further provide an electronic device, which may include a memory and one or more processors. The memory is coupled to the processor. The memory is configured to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device may perform the respective functions or steps performed by the electronic device in the foregoing method embodiments.
[0210] As Figure 14 shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone interface 170D, a sensor module 180, keys 190, a motor 191, an indicator 192, a camera 193, a display screen 194, a subscriber identification module (SIM) card interface 195, and the like.
[0211] The above-mentioned sensor module 180 may include sensors such as a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, and a bone conduction sensor.
[0212] It can be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than those shown in the figure, or combine certain components, or split certain components, or arrange different components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0213] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0214] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0215] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0216] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0217] It is understood that the interface connection relationships between the modules illustrated in this embodiment are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0218] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0219] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a touch layer and a display panel. The touch layer is used to sense user interaction with display screen 194. The display panel can be a liquid crystal display (LCD), organic light-emitting diode (OLED), active-matrix organic light-emitting diode (AMOLED), flexible light-emitting diode (FLED), minimized, microLED, micro-OLED, quantum dot light-emitting diode (QLED), etc. Electronic device 100 can realize shooting functions through ISP, camera 193, video codec, GPU, display screen 194, and application processor.
[0220] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element (image sensor). The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.
[0221] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor, such as a camera sensor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include N cameras 193, where N is a positive integer greater than 1.
[0222] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.
[0223] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0224] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0225] This application also provides a computer-readable storage medium including computer instructions that, when executed on the electronic device, cause the electronic device to perform the various functions or steps described in the method embodiments.
[0226] This application also provides a computer program product that, when run on an electronic device, causes the electronic device to perform the various functions or steps described in the above method embodiments.
[0227] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0228] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0229] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0230] Furthermore, the functional units in the various embodiments of this application 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.
[0231] 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 readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0232] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A text rendering method, characterized in that, The method includes: Generate a first text descriptor corresponding to the first text drawing information; wherein, the first text drawing information indicates the target text to be rendered and drawn with a first display effect on the first image frame, and the first text drawing information includes a first scaling factor indicating a first size; the text descriptor includes one or more text attribute information for the target text; Generate the first glyph data corresponding to the first character descriptor; In response to the first text drawing information, the first glyph data is stored in the target storage area; the first glyph data is the data of the target text used to render the first display effect; According to the first character shape data, the target character is rendered and drawn on the first image frame; Second text drawing information is detected, wherein the second text drawing information indicates that the target text to be rendered and drawn with a second display effect on the second image frame; the second text drawing information includes a second scaling factor indicating a second size, and both the first scaling factor and the second scaling factor include N significant digits, where N is a positive integer greater than 1; the first text descriptor includes a third scaling factor; the third scaling factor includes NM significant digits, where M is a positive integer less than N and greater than 0; the significant digits of the third scaling factor are the same as the first NM significant digits of the first scaling factor; Generate a second text descriptor corresponding to the second text drawing information; the second text descriptor includes a fourth scaling factor, the fourth scaling factor including NM significant digits; the significant digits of the fourth scaling factor are the same as the first NM significant digits of the second scaling factor. When the similarity between the second display effect and the first display effect meets a preset condition, in response to the second text drawing information, the first glyph data is obtained from the target storage area; wherein, obtaining the first glyph data from the target storage area includes: when the fourth scaling factor is the same as the third scaling factor, obtaining the first glyph data corresponding to the first text descriptor from the target storage area; The target text is rendered and drawn on the second image frame according to the first character shape data.
2. The method according to claim 1, characterized in that, The method further includes: Third text drawing information is detected, wherein the third text drawing information indicates that the target text with a third display effect is rendered and drawn on the third image frame; If the similarity between the third display effect and the first display effect does not meet a preset condition, in response to the third text drawing information, the second glyph data is stored in the target storage area; the second glyph data is the data of the target text used to render the third display effect; The target text is rendered and drawn on the third image frame according to the second glyph data.
3. The method according to claim 1 or 2, characterized in that, The first text drawing information includes a first scaling factor indicating a first size, and the second text drawing information includes a second scaling factor indicating a second size; Before storing the first glyph data in the target storage area, the method further includes: Generate a third text descriptor corresponding to the first text drawing information; the third text descriptor includes a fifth scaling factor, which is the same as the first scaling factor. Generate the first glyph data corresponding to the third character descriptor; Before retrieving the first glyph data from the target storage area in response to the second character drawing information, the method further includes: Generate a fourth text descriptor corresponding to the second text drawing information; the fourth text descriptor includes a sixth scaling factor, which is the same as the second scaling factor. The step of obtaining the first glyph data from the target storage area includes: when the difference between the sixth scaling factor and the fifth scaling factor is less than a preset threshold, obtaining the first glyph data corresponding to the third character descriptor from the target storage area.
4. The method according to claim 1, characterized in that, The step of storing the first glyph data in the target storage area includes: storing the first character descriptor and the first glyph data correspondingly in the target storage area.
5. The method according to claim 4, characterized in that, Before generating the first glyph data corresponding to the first character descriptor, the method further includes: It is determined that there is no text descriptor in the target storage area that is identical to the first text descriptor.
6. The method according to claim 1, characterized in that, The step of generating the first text descriptor corresponding to the first text drawing information includes: truncating the effective numbers of the first scaling factor to obtain the third scaling factor; The step of generating a second text descriptor corresponding to the second text drawing information includes: truncating the significant digits of the second scaling factor to obtain the fourth scaling factor.
7. The method according to claim 1, characterized in that, Both the first text drawing information and the second text drawing information carry multiple text attribute information. The multiple text attribute information is used to describe the display effect of the target text on the image frame. The multiple text attribute information includes a scaling factor used to describe the display size. Except for the scaling factor, the other text attribute information is the same between the first text drawing information and the second text drawing information.
8. The method according to claim 2, characterized in that, The first text drawing information includes a first scaling factor indicating a first size, and the third text drawing information includes a seventh scaling factor indicating a third size. The first scaling factor and the seventh scaling factor include N significant digits, where N is a positive integer greater than 1. Before storing the first glyph data in the target storage area, the method further includes: Generate a first text descriptor corresponding to the first text drawing information; the first text descriptor includes a third scaling factor; the third scaling factor includes NM significant digits, where M is a positive integer less than N and greater than 0; the significant digits of the third scaling factor are the same as the first NM significant digits of the first scaling factor; Generate the first glyph data corresponding to the first text descriptor; Before storing the second glyph data in the target storage area, the method further includes: Generate a fifth text descriptor corresponding to the third text drawing information; the fifth text descriptor includes an eighth scaling factor, the eighth scaling factor includes NM significant digits; the significant digits of the eighth scaling factor are the same as the first NM significant digits of the seventh scaling factor. It is determined that the eighth scaling factor is different from the third scaling factor; Generate the second glyph data corresponding to the fifth character descriptor.
9. The method according to claim 1, characterized in that, The method is applied to an electronic device, which includes a target application and a rendering thread, and the method further includes: During the display of the application interface of the target application, a target operation from the user is received; the target operation is used to trigger the display of text animation effects for the target text. The target application sends the first text drawing information to the rendering thread, triggering the rendering thread to render and draw the target text with the first display effect on the first image frame.
10. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory being used to store computer instructions, which, when executed by the processor, cause the electronic device to perform the method as described in any one of claims 1-9.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a computer program or instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1-9.
12. A computer program product, characterized in that, The computer program product includes a computer program or instructions that, when run on a computer, cause the computer to perform the method as described in any one of claims 1-9.
Citation Information
Patent Citations
Object display method and device, electronic equipment and storage medium
CN112445318A