Method for performing drawing operation by application and electronic device
This application provides a method for performing a drawing operation by an application and an electronic device. The method for performing a drawing operation by an application includes: determining a background drawing frequency of an application program; and when the application program is switched to a background application, intercepting a drawing operation of the application program, so that the application program performs the drawing operation at the background drawing frequency.
1 . A method, comprising:
starting, by an electronic device, a first application program;
performing, by the electronic device, a drawing operation at a first frequency when the first application program is a foreground application, wherein the drawing operation is for drawing a view for the first application program; and
performing, by the electronic device, the drawing operation at a second frequency after the first application program is switched from the foreground application to a background application, wherein the second frequency is less than the first frequency, and
wherein the first application program receives a vertical synchronization signal at the first frequency.
2 . The method according to claim 1 , wherein the performing, by the electronic device, the drawing operation at the second frequency after the first application program is switched from the foreground application to the background application comprises:
after the first application program is switched from the foreground application to the background application, indicating, by the electronic device, a choreographer of the first application program to respond to only N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
3 . The method according to claim 1 , wherein the performing, by the electronic device, the drawing operation at the second frequency after the first application program is switched from the foreground application to the background application comprises:
after the first application program is switched from the foreground application to the background application, indicating, by the electronic device, a choreographer of the first application program to process only animation event tasks corresponding to N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
4 . The method according to claim 1 , wherein the performing, by the electronic device, the drawing operation at the second frequency after the first application program is switched from the foreground application to the background application comprises:
after the first application program is switched from the foreground application to the background application, deleting, by the electronic device, animation event tasks corresponding to K-N vertical synchronization signals in K vertical synchronization signals received by a choreographer of the first application program, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
5 . The method according to claim 2 , wherein a first ratio of N to K corresponds to a second ratio of the second frequency to the first frequency.
6 . The method according to claim 1 , wherein the method further comprises:
after the starting the first application program, determining, by the electronic device, the second frequency according to a drawing frequency limiting policy and the first application program.
7 . The method according to claim 1 , wherein the method further comprises:
after the starting the first application program, determining, by the electronic device based on at least one of an activity manager service or a cpuset parameter of a process of the first application program, that the first application program is the foreground application or the background application.
8 . A method, comprising:
starting, by an electronic device, a first application program;
displaying, by the electronic device, an interface of the first application program;
performing, by the electronic device, a drawing operation at a first frequency, wherein the drawing operation is for drawing a view for the first application program;
closing, by the electronic device, display of the interface of the first application program; and
performing, by the electronic device, the drawing operation at a second frequency, wherein the second frequency is less than the first frequency, and
wherein the first application program receives a vertical synchronization signal at the first frequency.
9 . The method according to claim 8 , wherein the performing, by the electronic device, the drawing operation at the second frequency comprises:
indicating, by the electronic device, a choreographer of the first application program to respond to only N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
10 . The method according to claim 8 , wherein the performing, by the electronic device, the drawing operation at the second frequency comprises:
indicating, by the electronic device, a choreographer of the first application program to process only animation event tasks corresponding to N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
11 . The method according to claim 8 , wherein the performing, by the electronic device, the drawing operation at the second frequency comprises:
deleting, by the electronic device, animation event tasks corresponding to K-N vertical synchronization signals in K vertical synchronization signals received by a choreographer of the first application program, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
12 . The method according to claim 9 , wherein a first ratio of N to K corresponds to a second ratio of the second frequency to the first frequency.
13 . An electronic device, comprising:
a memory configured to store program instructions;
one or more processors configured to execute the program instructions, to cause the electronic device to perform:
starting a first application program;
performing a drawing operation at a first frequency when the first application program is a foreground application, wherein the drawing operation is for drawing a view for the first application program; and
performing the drawing operation at a second frequency after the first application program is switched from the foreground application to a background application, wherein the second frequency is less than the first frequency, and
wherein
the first application program receives a vertical synchronization signal at the first frequency.
14 . The electronic device according to claim 13 , wherein the performing the drawing operation at the second frequency comprises:
after the first application program is switched from the foreground application to the background application, indicating a choreographer of the first application program to respond to only N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
15 . The electronic device according to claim 13 , wherein the performing the drawing operation at the second frequency comprises:
after the first application program is switched from the foreground application to the background application, indicating a choreographer of the first application program to process only animation event tasks corresponding to N vertical synchronization signals in K received vertical synchronization signals, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and wherein N is a positive integer less than K.
16 . The electronic device according to claim 13 , wherein the performing the drawing operation at the second frequency comprises:
after the first application program is switched from the foreground application to the background application, deleting animation event tasks corresponding to K-N vertical synchronization signals in K vertical synchronization signals received by a choreographer of the first application program, so that the electronic device performs the drawing operation at the second frequency, wherein K is a positive integer, and N is a positive integer less than K.
17 . The electronic device according to claim 14 , wherein a first ratio of N to K corresponds to a second ratio of the second frequency to the first frequency.
18 . The electronic device according to claim 13 , wherein the one or more processors are further configured to execute the program instructions, to cause the electronic device to perform:
after the starting the first application program, determining the second frequency according to a drawing frequency limiting policy and the first application program.
19 . The electronic device according to claim 13 , wherein the one or more processors are further configured to execute the program instructions, to cause the electronic device to perform:
after the starting the first application program, determining, based on at least one of an activity manager service or a cpuset parameter of a process of the first application program, that the first application program is the foreground application or the background application.