This application relates to the field of image processing technologies, and in particular, to a display method and an apparatus.
An electronic device may have a plurality of applications (APPs) installed thereon, and control, during running of an APP, display of an image frame at a refresh rate corresponding to the APP. Some of the plurality of APPs have different refresh rates. When the electronic device switches the APP, the refresh rate is also synchronously switched. However, when the electronic device switches from a high refresh rate to a low refresh rate, a frame loss problem occurs. As a result, apparent lag occurs in the electronic device, and user experience is reduced.
This application provides a display method and an apparatus, and an objective is to resolve a frame loss problem caused by switching from a high refresh rate to a low refresh rate, to reduce lag in an electronic device, and improve user experience. To achieve the foregoing objective, this application provides the following technical solutions.
According to a first aspect, this application provides a display method, applied to an electronic device, where the method includes: determining that a refresh rate of the electronic device is switched from a first refresh rate to a second refresh rate, where the first refresh rate is greater than the second refresh rate; generating, in a case that the refresh rate is switched from the first refresh rate to the second refresh rate, a second image frame after the electronic device completes display of a first image frame; and displaying the second image frame.
Generally, when the electronic device generates one image frame, two conditions need to be met: One condition is that a level change of a first signal (that is, Vsync-sf) meets a preset condition, where the preset condition is that a level of the first signal changes from a low level to a high level (corresponding to a rising edge), or the level of the first signal changes from the high level to the low level (corresponding to a falling edge); and the other condition is that the electronic device completes display of a previous image frame. However, when the electronic device switches from the first refresh rate to the second refresh rate, time consumption of a second signal (that is, Vsync-hw) increases (that is, a periodicity increases). The second signal with the increased time consumption may cover at least one first signal, and under the covered first signal, the electronic device cannot determine whether display of the image frame is completed, making the electronic device unable to process another image frame, and resulting in an image frame loss. At an end position of the second signal, the electronic device may determine that display of the image frame is completed, but the electronic device still needs to wait for a rising edge or a falling edge of the first signal, which may also cause the electronic device to lose the image frame during waiting. However, according to the display method provided in this application, after it is determined that the refresh rate is switched from the first refresh rate to the second refresh rate, and after the electronic device completes display of the first image frame, the electronic device may immediately generate and display the second image frame. In this way, after determining that display of the image frame is completed, the electronic device may immediately generate and display another image frame without waiting for the rising edge or the falling edge of the first signal, to reduce the image frame loss, thereby reducing lag in the electronic device, and improving user experience.
Optionally, the method further includes: controlling, after the refresh rate is switched to the second refresh rate, a first signal to be aligned with a second signal, where the first signal indicates to generate an image frame, and the second signal indicates to display the image frame; generating a third image frame when the electronic device completes display of the second image frame and a level change of the first signal meets a preset condition, where the preset condition is that a level of the first signal changes from a low level to a high level, or the level of the first signal changes from the high level to the low level; and displaying the third image frame under action of the second signal. Alignment means that periodicities of the first signal and the second signal are the same, rising edges of the first signal and the second signal are aligned, and falling edges of the first signal and the second signal are also aligned. In other words, waveforms of the first signal and the second signal are the same, where signal amplitude may be the same or different.
Generally, in a process in which the refresh rate is switched to the second refresh rate, a periodicity of the second signal generated by the electronic device increases, making the first signal and the second signal that can be aligned before switching unable to remain aligned after the refresh rate is switched. In this case, the image frame may be generated once every other first signal, resulting in alternate occurrence of synthesizing one frame and losing one frame in the electronic device. The synthesizing one frame may be generating one image frame, to further display the image frame. However, according to the display method provided in this application, the electronic device can control the first signal to be aligned with the second signal after the refresh rate is switched. In this way, the electronic device can generate one image frame at each first signal, to avoid alternate occurrence of synthesizing one frame and losing one frame, and reduce the image frame loss, thereby reducing lag in the electronic device, and improving user experience.
Optionally, before the determining that a refresh rate of the electronic device is switched from a first refresh rate to a second refresh rate, the method further includes: generating, in a case that the refresh rate is the first refresh rate, an (i+n)th first signal based on an ith second signal, where an interval between the (i+n)th first signal and the ith second signal is a sum of periodicities of n first signals, and n is a natural number greater than 1; and the controlling, after the refresh rate is switched to the second refresh rate, a first signal to be aligned with a second signal includes: sampling, after the refresh rate is switched to the second refresh rate, a 1st second signal after the refresh rate is switched, and generating the first signal by using a sampling result of the 1st second signal, where an interval between the first signal and the 1st second signal is a sum of periodicities of (n−1) second signals. After the refresh rate is switched, the reason why the first signal is not aligned with the second signal is the second signal with the increased periodicity is used during generation of the first signal. Therefore, in this application, after determining that the refresh rate is switched, the electronic device adjusts a generation mechanism of the first signal after switching, and generates the first signal by using the 1st second signal after the refresh rate is switched, so that the first signal and the second signal can be aligned after the refresh rate is switched. The sampling result of the second signal may be stored in a result sequence, and during generation of the first signal, the sampling result of the second signal is read from the result sequence. The sampling result of the second signal may be a plurality of timestamps of the second signal, and the result sequence may be a timestamp sequence storing the plurality of timestamps of the second signal.
Optionally, the method further includes: discarding a special signal, where the special signal is the second signal generated in a process in which the refresh rate is switched from the first refresh rate to the second refresh rate, and the special signal is a previous signal of the 1st second signal, to reduce a data volume processed by the electronic device.
Optionally, the discarding a special signal includes: prohibiting sampling the special signal; or sampling the special signal, where a sampling result of the special signal is not stored in a result sequence.
Optionally, the second image frame is an image frame lost in the process in which the refresh rate is switched from the first refresh rate to the second refresh rate. In some examples, after determining that display of the first image frame is completed, the electronic device may immediately generate a first image frame in a plurality of lost image frames, to ensure continuity of images. In some examples, after determining that display of the first image frame is completed, the electronic device may immediately synthesize a last image frame in the plurality of lost image frames, to shorten a delay of the last image frame, and when an image frame displayed next time by the electronic device is a next image frame of the lost last image frame, the electronic device immediately generates and displays the lost last image frame, so that the image frame displayed next time and the lost last image frame are continuous, to ensure continuity.
Optionally, that the electronic device completes display of a first image frame includes: determining that the electronic device completes display of the first image frame after the electronic device invokes a kernel thread crtc_commit to release a fence resource.
Optionally, the determining that a refresh rate of the electronic device is switched from a first refresh rate to a second refresh rate includes: determining end time of the first signal and start time of the first signal when the refresh rate of the electronic device is the first refresh rate; determining a difference between the end time and the start time; and determining that the refresh rate of the electronic device is switched from the first refresh rate to the second refresh rate if the difference meets a preset switching condition. The preset switching condition may indicate that a periodicity of the first signal increases, for example, the preset switching condition may be a preset threshold or a preset value range, and the preset threshold and the preset value range are determined based on the refresh rate. For example, when the refresh rate is switched from 90 Hz to 60 Hz, the preset threshold may be a value less than 19.4 ms, and the preset value range may be (11.1, 19.4].
Optionally, an application framework layer of the electronic device includes a refresh rate processing unit and a data reading unit; a hardware abstraction layer of the electronic device includes a hardware composer; and a kernel layer of the electronic device includes a display driver, where the refresh rate processing unit is configured to determine that the refresh rate of the electronic device is switched from the first refresh rate to the second refresh rate; the data reading unit is configured to read, in a case that the refresh rate is switched from the first refresh rate to the second refresh rate, first image data after the electronic device completes display of the first image frame; the hardware composer is configured to synthesize the first image data, to generate the second image frame; and the display driver is configured to display the second image frame.
Optionally, the application framework layer of the electronic device further includes: a signal generation unit, where the signal generation unit is configured to control, after the refresh rate is switched to the second refresh rate, the first signal to be aligned with the second signal, where the first signal indicates to generate the image frame, and the second signal indicates to display the image frame; the data reading unit is further configured to read second image data when the electronic device completes display of the second image frame and the level change of the first signal meets the preset condition, where the preset condition is that the level of the first signal changes from the low level to the high level, or the level of the first signal changes from the high level to the low level; the hardware composer is further configured to synthesize the second image data, to generate the third image frame; and the display driver is further configured to display the third image frame under the action of the second signal.
According to a second aspect, this application provides an electronic device, where the electronic device includes: one or more processors; and one or more memories, where the memory stores one or more programs, and the one or more programs, when executed by the processor, enable the electronic device to perform the foregoing display method.
According to a third aspect, this application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, enables the processor to perform the foregoing display method.
In this application, based on implementations according to the foregoing aspects, further combinations may be performed, to provide more implementations.
The following clearly and describes the technical solutions in embodiments of this application with reference to the accompanying drawings in embodiments of this application. Terms used in the following embodiments are merely intended to describe objectives of particular embodiments, but are not intended to limit this application. As used in this specification and the claims of this application, a singular expression form, “one”, “a”, “the”, “foregoing”, “the”, or “this”, is intended to also include “one or more” expression form, unless clearly indicated to the contrary in the context. It should be further understood that, in embodiments of this application, “one or more” means one, two, or more than two; and “and/or” describes an association relationship between associated objects and indicates that three relationships may exist. For example, A and/or B may indicate the following cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. The character “/” generally indicates an “or” relationship between the associated objects.
Reference to “one embodiment”, “some embodiments”, or the like described in this specification means that a specific feature, structure, or characteristic described with reference to this embodiment is included in one or more embodiments of this application. Therefore, statements such as “in one embodiment”, “in some embodiments”, “in some other embodiments” that appear in different parts of this application do not necessarily refer to same embodiments, but mean “one or more but not all embodiments”, unless otherwise specifically emphasized in other manners. The terms “comprise”, “include”, “have”, and variants thereof all mean “include but are not limited to”, unless otherwise specifically emphasized in another manner.
“Plurality of” in embodiments of this application means greater than or equal to two. It should be noted that, in descriptions of embodiments of this application, terms such as “first” and “second” are merely for distinguishing descriptions, and cannot be understood as an indication or implication of relative importance, or an indication or implication of a sequence.
First, technical terms involved in this application are described as follows.
A vertical synchronization (Vsync) signal is divided into a hardware Vsync signal and a software Vsync signal. The hardware Vsync signal is abbreviated as Vsync-hw signal, which can be understood as a tearing effect (TE) signal. The software Vsync signal includes a Vsync-app signal and a Vsync-sf signal. For convenience of description, the Vsync-hw signal, the Vsync-app signal, and the Vsync-sf signal are abbreviated as Vsync-hw, Vsync-app, and Vsync-sf.
The Vsync-app and the Vsync-sf are generated based on the Vsync-hw. Specifically, DispSyncSource.cpp in SF (surfaceflinger) virtualizes the Vsync-hw into the Vsync-app and the Vsync-sf, where DispSyncSource.cpp samples the Vsync-hw, and inputs a sampling result into a software Vsync model; and DispSyncSource.cpp runs the software Vsync model, to output the Vsync-app and the Vsync-sf through the software Vsync model. The Vsync-hw may be generated by a display driver based on a refresh rate.
A process in which an electronic device performs rendering to displaying of an image frame by using the Vsync-app, the Vsync-sf, and the Vsync-hw is shown in
However, display of the image frame is not completely independent of a previous image frame. After display of the previous image frame is completed and crtc_commit releases the fence resource, SF may read image data of a next image frame under the action of the Vsync-sf, and then complete display of the next image frame through HWC and the display driver. In
Periodicities of the Vsync-app, the Vsync-sf, and the Vsync-hw may be determined based on a refresh rate corresponding to the APP. For example, if the refresh rate corresponding to the APP is 90 Hz, the periodicities of the Vsync-app, the Vsync-sf, and the Vsync-hw are 11.1 milliseconds (ms); and if the refresh rate corresponding to the APP is 60 Hz, the periodicities of the Vsync-app, the Vsync-sf, and the Vsync-hw are 16.6 ms. When the electronic device switches the APP, the refresh rate is also synchronously switched. However, when the electronic device switches from a high refresh rate to a low refresh rate, the periodicity of the Vsync-hw is too long, resulting in a frame loss problem in the APP switching process. In addition, after switching is completed, the Vsync-app, the Vsync-sf, and the Vsync-hw are not aligned, resulting in alternate occurrence of synthesizing one frame and losing one frame after the electronic device completes switching. As a result, apparent lag occurs in the electronic device, and user experience is reduced. The synthesizing one frame may be synthesizing image data of the image frame through SF. The losing one frame may be delaying performing SF synthesis, for example, performing SF synthesis at a rising edge or a falling edge of next Vsync-sf, to synthesize the image data of the image frame at the next Vsync-sf; or the losing one frame may be losing the image data of the image frame.
For example, the refresh rate of the electronic device is switched from 90 Hz to 60 Hz. The display driver in the electronic device may generate Vsync-hw, and when the refresh rate is switched, the display driver may simulate refresh rate switching, to adjust the Vsync-hw based on the switched refresh rate. As shown in
Trace (trace) of the frame loss problem is shown in
At the rising edge and the falling edge of Vsync-sf, if SF waits until crtc_commit releases the fence resource, SF may read the image data. If SF does not wait until crtc_commit releases the fence resource, SF cannot read the image data. After 19.4 ms, if SF waits until the fence resource once every other Vsync-sf, it indicates that SF may read the image data once every other Vsync-sf, resulting in alternate occurrence of synthesizing one frame and losing one frame. As shown in 3 in
For example, in a process of sliding to exit the APP in the electronic device, the refresh rate is switched from 90 Hz to 60 Hz. In the switching process, the electronic device first loses two image frames. After switching is completed, one frame is lost when one frame is refreshed, resulting in lag throughout the process, and reducing user experience.
After the refresh rate is switched, a schematic diagram of software/hardware Vsync is shown in
When the refresh rate is 90 Hz, the periodicities of the Vsync-app, the Vsync-sf, and the Vsync-hw are the same, and at least references of the Vsync-sf and the Vsync-hw in each periodicity are also the same, that is, the Vsync-sf and the Vsync-hw are aligned in each periodicity, where alignment may be that periodicities are the same, the rising edges of the Vsync-sf and the Vsync-hw are same, and the falling edges of the Vsync-sf and the Vsync-hw are the same. For the Vsync-app, the periodicity is the same as those of the Vsync-sf and the Vsync-hw, but a rising edge and a falling edge may be different from those of the Vsync-sf and the Vsync-hw. In
As shown in
In addition, because the Vsync-hw ends at (2) in the fourth periodicity, crtc_commit originally releasing the fence resource at (1) delays to release the fence resource at (2). Because (2) is not at the rising edge or the falling edge of the Vsync-sf, SF synthesis is delayed by one Vsync-sf, to be specific, as shown in
Under action of software/hardware Vsync shown in
It can be learned from
For this problem, this application provides a display method. In the display method, in response to switching from a high refresh rate to a low refresh rate, image data of an image frame is synthesized when an instruction that crtc_commit releases a fence resource is received but Vsync-sf is not received. In other words, when the high refresh rate is switched to the low refresh rate, although SF is not at a rising edge or a falling edge of the Vsync-sf, SF determines that crtc_commit releases the fence resource (that is, display of the image frame is completed). In this case, SF may immediately read the image data after crtc_commit releases the fence resource, to immediately perform SF synthesis, and the image data of the image frame is synthesized in advance relative to waiting to receive the Vsync-sf to read the image data, so that the image data of the image frame can be quickly synthesized when the high refresh rate is switched to the low refresh rate, thereby reducing a quantity of lost frames.
In some examples, in response to switching to a low refresh rate, Vsync-app, Vsync-sf, and Vsync-hw are synchronized, that is, after the low refresh rate is switched to, the Vsync-app, the Vsync-sf, and the Vsync-hw are aligned, to resolve alternate occurrence of synthesizing one frame and losing one frame because the Vsync-app, the Vsync-sf, and the Vsync-hw are not aligned after switching.
To be specific, generally, SF synthesis needs to meet two conditions: One condition is that SF is at the rising edge or the falling edge of the Vsync-sf, and the other condition is that SF determines that crtc_commit releases the fence resource. However, when the high refresh rate is switched to the low refresh rate, Vsync-hw with long time consumption occurs, and SF synthesis needs to meet only one condition, where the condition may be that SF determines that crtc_commit releases the fence resource. In this way, SF does not need to wait for a rising edge or a falling edge of next Vsync-sf, and SF synthesis at the next Vsync-sf is advanced, so that image data of one image frame can be synthesized in advance.
The image data synthesized in advance may be image data of any of lost two image frames. Although the two frames are lost under the Vsync-hw with the time consumption of 19.4 ms, the image data of any of the lost two image frames may be immediately synthesized after the Vsync-hw with the time consumption of 19.4 ms ends, which is equivalent to losing one frame, thereby reducing a quantity of lost frames. In some examples, image data of a first frame of the lost two image frames may be immediately synthesized after the Vsync-hw with the time consumption of 19.4 ms ends, to ensure continuity of images. In some examples, image data of a second frame of the lost two image frames may be immediately synthesized after the Vsync-hw with the time consumption of 19.4 ms ends, to shorten a synthesis delay of the second image frame.
The Vsync-hw with the time consumption of 19.4 ms may cause subsequent Vsync-app, Vsync-sf, and Vsync-hw to be not aligned, and that the Vsync-app, the Vsync-sf, and the Vsync-hw are not aligned may result in alternate occurrence of synthesizing one frame and losing one frame in the electronic device. For this problem, after the refresh rate is switched to the low refresh rate, the electronic device may align the Vsync-app, the Vsync-sf, and the Vsync-hw. After the Vsync-app, the Vsync-sf, and the Vsync-hw are aligned, SF may read image data from a buffer at the rising edge and the falling edge of the Vsync-sf respectively, and the image data is synthesized by HWC, to perform SF synthesis at the rising edge and the falling edge of the Vsync-sf respectively, so that the electronic device may perform, after the refresh rate is switched to 60 Hz, SF synthesis at the rising edge and the falling edge of the Vsync-sf based on 60 Hz, thereby avoiding an image frame loss.
The following describes with reference to the accompanying drawings. A schematic diagram of optimizing software/hardware Vsync after a refresh rate is switched is shown in
In the fifth periodicity, end time of the Vsync-app, the Vsync-sf, and the Vsync-hw is the same. In this case, in a sixth periodicity, start time of the Vsync-app, the Vsync-sf, and the Vsync-hw is the same; and in addition, because the periodicities of the Vsync-app, the Vsync-sf, and the Vsync-hw are the same, the Vsync-app, the Vsync-sf, and the Vsync-hw are aligned up and down in the sixth periodicity. As shown in
After software/hardware Vsync is optimized, a process of completing rendering to displaying of the image frame by using the Vsync-app, the Vsync-sf, and the Vsync-hw is shown in
The display method may be applied to an electronic device. In some embodiments, the electronic device may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a handheld computer, a netbook, a personal digital assistant (PDA), a wearable electronic device, a smart watch, or the like. A specific form of the electronic device is not limited in this application.
As shown in
The processor may include one or more processing units. For example, the processor may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, a neural-network processing unit (NPU), and/or the like. Different processing units may be independent devices, or may be integrated into one or more processors. The processor is a neural center and a command center of the electronic device. The controller may generate an operation control signal based on instruction operation code and a time sequence signal, to implement control of instruction fetching and instruction executing.
The display is configured to display images, videos, a series of graphical user interfaces (GUI), and the like.
The external memory interface may be configured to connect to an external storage card, for example, a micro SD card, to expand a storage capability of the electronic device. The external storage card communicates with the processor by using the external memory interface, to implement a data storage function, for example, to store files such as music and a video into the external memory card. The internal memory may be configured to store computer-executable program code, where the executable program code includes instructions. The processor runs the instructions stored in the internal memory, to implement various functional applications and data processing of the electronic device. For example, in this application, the processor executes the instructions stored in the internal memory, so that the electronic device performs the display method provided in this application.
It may be understood that, a structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In some other embodiments, the electronic device may include more or fewer components than those shown in the figure, or some components may be combined, or some components may be split, or a different component arrangement may be used. The illustrated components may be implemented by hardware, software, or a combination of software and hardware.
In addition, an operating system is running on the foregoing components, for example, an iOS operating system developed by Apple Inc., an Android open-source operating system developed by Google Inc., or a Windows operating system developed by Microsoft Corporation.
The operating system of the electronic device may use a layered architecture, an event-driven architecture, a micro core architecture, a micro service architecture, or a cloud architecture. In this embodiment of this application, an Android system with the layered architecture is used as an example to describe a software structure of the electronic device.
The application layer may include a series of application packages. The application packages may include APPs such as a camera, a gallery, a calendar, a call, a map, a navigation, WLAN, Bluetooth, music, a video, and an SMS message. The application framework layer provides an application programming interface (Application Programming Interface, API) and a programming framework for the applications at the application layer. The application framework layer includes some predefined functions. For example, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like. The application framework layer may further include SF, where SF includes DispSyncSource.cpp, SF.cpp, and VsyncReactor.cpp. DispSyncSource.cpp, SF.cpp, and VsyncReactor.cpp may be regarded as three units of SF, for example, DispSyncSource.cpp may be referred to as a signal generation unit, SF.cpp may be referred to as a data reading unit, and VsyncReactor.cpp may be referred to as a refresh rate processing unit. HAL may include HWC. The kernel layer is a layer between hardware and software. The kernel layer includes at least a display driver, a camera driver, an audio driver, and a sensor driver. HWC may be configured to synthesize image data, and in a process of synthesizing the image data, functions such as setCallback, registerCallback, and onComposerhalVsync may be invoked.
VsyncReactor.cpp may sample Vsync-hw, and DispSyncSource.cpp generates Vsync-app and Vsync-sf based on a sampling result. VsyncReactor.cpp may invoke addResyncSample to sample the Vsync-hw, to obtain a timestamp of the Vsync-hw, where the timestamp of the Vsync-hw is an example of the sampling result. The timestamp of the Vsync-hw may be stored in a timestamp sequence through addHwVsyncTimestamp. VsyncReactor.cpp may further invoke periodConfirmed for scene recognition. After switching from a high refresh rate to a low refresh rate is recognized and Vsync-hw with long time consumption occurs, VsyncReactor.cpp may send, after determining that crtc_commit releases a fence resource, an instruction to SF.cpp to indicate SF.cpp to perform SF synthesis with HWC, and VsyncReactor.cpp adjusts the timestamp sequence, to ensure that the Vsync-app, the Vsync-sf, and the Vsync-hw may be aligned after a refresh rate is switched.
An example in which the refresh rate of the electronic device is 90 Hz, and the refresh rate is switched from 90 Hz to 60 Hz is used to describe an interaction process among DispSyncSource.cpp, SF.cpp, VsyncReactor.app, and HWC. Diagrams of signaling are shown in
S101: VsyncReactor.cpp invokes addResyncSample to sample Vsync-hw (i), to obtain a timestamp of the Vsync-hw (i), where the timestamp of the Vsync-hw (i) is stored in a timestamp sequence. For example, VsyncReactor.cpp invokes addHwVsyncTimestamp to store the timestamp of the Vsync-hw (i) in the timestamp sequence.
S102: DispSyncSource.cpp generates Vsync-sf (i+2) based on the timestamp of the Vsync-hw (i). The Vsync-sf (i+2) is second Vsync-sf after Vsync-sf (i), and the Vsync-hw (i) and the Vsync-sf (i) correspond to a same periodicity. In this embodiment, the Vsync-hw (i) and Vsync-sf (i) are Vsync-hw and Vsync-sf in an ith periodicity. When generating the Vsync-sf (i+2), SF may further generate Vsync-app (i+2), and an APP generates image data under action of the Vsync-app (i+2). This is not described herein in detail. That the Vsync-sf (i+2) is generated based on the timestamp of the Vsync-hw (i) is merely an example, and this is not limited in this embodiment.
S103: SF.cpp reads the image data when SF.cpp determines that crtc_commit releases a fence resource and SF.cpp is at a rising edge or a falling edge of the Vsync-sf (i+2). That SF.cpp is at the rising edge of the Vsync-sf (i+2) indicates that a level of the Vsync-sf (i+2) changes from a low level to a high level, and that SF.cpp is at the falling edge of the Vsync-sf (i+2) indicates that the level of the Vsync-sf (i+2) changes from the high level to the low level.
S104: HWC synthesizes the image data, to complete SF synthesis through SF.cpp and HWC, and generate one image frame.
S105: HWC may send the synthesized image data to a display driver, and the display driver drives a screen to display the image frame.
S106: VsyncReactor.cpp invokes periodConfirmed to recognize that time consumption of Vsync-hw (i+1) is 19.4 ms, to determine that the refresh rate is switched; and VsyncReactor.cpp sends an instruction that indicates that the refresh rate is switched to SF.cpp, where the instruction may further carry the time consumption of the Vsync-hw (i+1) in addition to indicating that the refresh rate is switched. The Vsync-hw (i+1) is next Vsync-hw of the Vsync-hw (i).
Ideally, if the next Vsync-hw signal ends at current time, a difference between the current time and start time of the Vsync-hw is equal to a periodicity of the Vsync-hw. Therefore, periodConfirmed may recognize whether a preset scenario occurs depending on whether the difference exceeds a preset threshold, where the preset scenario is a scenario in which Vsync-hw with long time consumption occurs after the refresh rate is switched. When the refresh rate is switched from 90 Hz to 60 Hz, the preset threshold may be, but is not limited to, a value less than 19.4 ms, for example, may be a value between 11.1 and 19.4. Alternatively, periodConfirmed may recognize whether the preset scenario occurs depending on whether the difference is within a preset value range, where the preset value range may be from 11.1 to 19.4, and the preset value range may not include 11.1, but may include 19.4. In another refresh rate switching scenario, the preset threshold is not limited to being determined based on 19.4 ms. For the preset threshold, this is not limited in this embodiment.
S107: SF.cpp immediately reads, in response to the instruction, image data after determining that crtc_commit releases the fence resource.
S108: HWC synthesizes the image data, to generate one image frame.
S109: HWC may send the synthesized image data to the display driver, and the display driver drives the screen to display the image frame.
In other words, SF.cpp receives the instruction sent by VsyncReactor.cpp. If the instruction indicates that the refresh rate is switched and time consumption of the Vsync-hw (i) is 19.4 ms, SF.cpp does not need to wait for the rising edge and the falling edge of the Vsync-sf, and SF may read the image data after determining that crtc_commit releases the fence resource, so that SF reads the image data in advance, and HWC also synthesizes the image data in advance.
S110: VsyncReactor.cpp prohibits invoking addResyncSample to sample the Vsync-hw (i+1), so that a timestamp of the Vsync-hw (i+1) is not stored in the timestamp sequence.
S110′: VsyncReactor.cpp invokes addResyncSample to sample the Vsync-hw (i+1), but prohibits invoking addHwVsyncTimestamp to store the timestamp of the Vsync-hw (i+1) in the timestamp sequence, so that the timestamp of the timestamp of the Vsync-hw (i+1) is also not stored in the timestamp sequence.
S111: VsyncReactor.cpp invokes addResyncSample to sample Vsync-hw (i+2), to obtain a timestamp of the Vsync-hw (i+2), and invokes addHwVsyncTimestamp to store the timestamp of the Vsync-hw (i+2) in the timestamp sequence.
S112: DispSyncSource.cpp generates Vsync-sf (i+3) based on the timestamp of the Vsync-hw (i+2), where the generated Vsync-sf (i+3) is aligned with Vsync-hw (i+3).
S113: SF.cpp reads image data when SF.cpp determines that crtc_commit releases the fence resource, and SF.cpp is at a rising edge or a falling edge of the Vsync-sf (i+3).
S114: HWC synthesizes the image data, to complete SF synthesis through SF.cpp and HWC, and generate one image frame.
S115: HWC may send the synthesized image data to the display driver, and the display driver drives the screen to display the image frame.
The Vsync-sf (i+3) and the Vsync-hw (i+3) are aligned, to ensure that the Vsync-app, the Vsync-sf, and the Vsync-hw may be aligned after the refresh rate is switched. Under action of a rising edge or a falling edge of subsequent Vsync-sf, SF reads image data, and HWC synthesizes the image data, to complete SF synthesis through SF and HWC, and generate one image frame. In this way, starting from the Vsync-sf (i+3), the electronic device can normally generate an image frame, thereby avoiding synthesizing one frame and losing one frame.
For example, in
Because addHwVsyncTimestamp skips the timestamp of the Vsync-hw3 and generates the Vsync-sf5 by using the timestamp of the Vsync-hw4, the Vsync-hw4 is next Vsync-hw of the Vsync-hw3. In this case, generating the Vsync-sf5 by using the timestamp of the Vsync-hw4 means that generation of the Vsync-sf5 is delayed, and end time of the Vsync-sf4 is also delayed, making a periodicity of the Vsync-sf4 increase. For example, in
In addition, this application provides an electronic device, where the electronic device includes: one or more processors; and one or more memories, where the memory stores one or more programs, and the one or more programs, when executed by the processor, enable the electronic device to perform the foregoing display method.
This application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, enables the processor to perform the foregoing display method.
Number | Date | Country | Kind |
---|---|---|---|
202211230396.X | Sep 2022 | CN | national |
This application is a national stage of International Application No. PCT/CN2023/116602, filed on Sep. 1, 2023, which claims priority to Chinese Patent Application No. 202211230396.X, filed on Sep. 30, 2022, both of which are incorporated herein by reference in their entireties.
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/CN2023/116602 | 9/1/2023 | WO |