Method for requesting vsync signal and electronic device
Abstract
This application provides a method for requesting a vSync signal and an electronic device, and relates to the field of image display technologies. When a plurality of image frames that are dynamically changing and consecutive need to be displayed, a possibility of freezing and unsmoothness can be reduced. At a first moment, a first application in the electronic device calls a setVsyncRate interface of a window system SF in the electronic device to send a first request to the SF. The first request is for requesting a vSync signal. The SF periodically distributes the vSync signal to the first application in response to the first request. At a second moment, the first application calls the setVsyncRate interface to send a second request to the SF.
Claims
exact text as granted — not AI-modified1 . A method for requesting a vSync signal, applied to an electronic device having a display function and having a first application installed thereon, wherein the method comprises:
at a first moment, calling, by the first application in the electronic device, a setVsyncRate interface of a window system SF in the electronic device to send a first request to the SF, wherein the first request is for requesting a vSync signal; periodically distributing, by the SF, the vSync signal to the first application in response to the first request; and at a second moment, calling, by the first application, the setVsyncRate interface to send a second request to the SF, wherein the second request is for requesting to cancel the vSync signal, and after receiving the second request, the SF ends the periodically distributing the vSync signal to the first application.
2 . The method according to claim 1 , wherein the method further comprises:
determining, by the first application, that a plurality of image frames that are consecutive need to be rendered, wherein the first moment comprises a moment when rendering of a first image is requested, and the first image is the first image frame among the plurality of image frames.
3 . The method according to claim 2 , wherein the first application records a first on/off state, and a second on/off state is recorded in a rendering module at a framework layer of the electronic device, wherein initial states of the first on/off state and the second on/off state are both off states; and
after the determining, by the first application, that a plurality of image frames that are consecutive need to be rendered, the method further comprises: updating, by the first application, the first on/off state to an on state; and the at a first moment, calling, by the first application in the electronic device, a setVsyncRate interface of a window system SF in the electronic device to send a first request to the SF comprises: at the first moment, sending, by the first application, a first message to the rendering module, wherein the first message is for requesting the vSync signal; and calling, by the rendering module, the setVsyncRate interface in response to the first message and in response to that the first on/off state is the on state and the second on/off state is the off state, to send the first request to the SF.
4 . The method according to claim 3 , wherein the first on/off state is the on state, the second on/off state is the off state, and the method further comprises:
updating, by the rendering module, the second on/off state to the on state.
5 . The method according to claim 4 , wherein the method further comprises:
at a third moment, sending, by the first application, a first message to the rendering module, wherein the first message is for requesting the vSync signal, the third moment is a moment when rendering of a second image is requested, and the second image is any other image among the plurality of image frames than the first image frame; and skipping requesting, by the rendering module, the vSync signal from the SF in response to the first message and in response to that the first on/off state is the on state and the second on/off state is the on state.
6 . The method according to claim 4 , wherein after the sending the first request to the SF, the method further comprises:
determining, by the first application, to end rendering of the plurality of image frames that are consecutive, wherein the second moment comprises a moment when rendering of a third image is requested, and the third image is the first image frame that needs to be rendered by the first application after the rendering of the plurality of image frames is completed.
7 . The method according to claim 6 , wherein after the determining, by the first application, to end rendering of the plurality of image frames that are consecutive, the method further comprises:
updating, by the first application, the first on/off state to the off state; and the at a second moment, calling, by the first application, the setVsyncRate interface to send a second request to the SF comprises: at the second moment, sending, by the first application, a first message to the rendering module, wherein the first message is for requesting the vSync signal; and calling, by the rendering module, the setVsyncRate interface in response to the first message and in response to that the first on/off state is the off state and the second on/off state is the on state, to send the second request to the SF.
8 . The method according to claim 7 , wherein the first on/off state is the off state, the second on/off state is the on state, and the method further comprises:
updating, by the rendering module, the second on/off state to the off state.
9 . The method according to claim 7 , wherein after the sending the second request to the SF, the method further comprises:
calling, by the first application, a requestNextVsync interface of the SF to send a third request to the SF, wherein the third request is for requesting the vSync signal; and distributing, by the SF, the vSync signal to the first application once in response to the third request.
10 . The method according to claim 4 , wherein the periodically distributing, by the SF, the vSync signal to the first application comprises:
periodically distributing, by the SF, the vSync signal to the rendering module.
11 . The method according to claim 10 , wherein the method further comprises:
sending, by the first application, the first message to the rendering module when the first application needs to render a fourth image, wherein the fourth image is any image frame that needs to be displayed by the first application, and the fourth image comprises the first image or the second image; and recording, by the rendering module, a first mark in response to the first message, and deleting the first mark after receiving the vSync signal from the SF, wherein the second moment comprises a moment when the rendering module receives the vSync signal from the SF when the rendering module comprises no first mark.
12 . The method according to claim 11 , wherein the method further comprises:
at the second moment, notifying, by the rendering module, the first application to update the first on/off state to the off state, and updating the second on/off state to the off state.
13 . The method according to claim 3 , wherein the method further comprises:
at a fourth moment, sending, by the first application, a first message to the rendering module, wherein the first message is for requesting the vSync signal; and calling, by the rendering module, the requestNextVsync interface in response to the first message and in response to that the first on/off state and the second on/off state are both the off states, and sending a fourth request to the SF, wherein the fourth request is for requesting the vSync signal.
14 . The method according to claim 1 , wherein the SF is located at a native layer of the electronic device, the first application is located at an application layer of the electronic device, and before the sending a first request to the SF, the method further comprises:
adding a first interface to the framework layer of the electronic device, and adding a second interface to a Java native interface layer of the electronic device, wherein the first interface and the second interface are interfaces of the setVsyncRate interface that are open to Java; and the calling, by the first application, the setVsyncRate interface comprises: calling, by the first application, the setVsyncRate interface through the first interface and the second interface in sequence.
15 . The method according to claim 1 , wherein the first request comprises a periodicity n, n≥1, and n is an integer; and
the periodically distributing, by the SF, the vSync signal to the first application in response to the first request comprises:
in response to the first request, distributing, by the SF, the vSync signal once to the first application after the SF receives the vSync signal every n times.
16 . An electronic device, wherein the electronic device comprises a memory and a processor, the memory is coupled to the processor, the memory stores computer program code, the computer program code comprises computer instructions, and when the computer instructions are executed by the processor, the electronic device is enabled to perform the method according to claim 1 .
17 . A computer-readable storage medium, comprising computer instructions, wherein when the computer instructions are run on an electronic device, the electronic device is enabled to perform the method according to claim 1 .
18 . (canceled)Join the waitlist — get patent alerts
Track US2026018147A1 — get alerts on status changes and closely related new filings.
We store only your email — no account needed. See our privacy policy.