Layer processing method and related device
By scanning and releasing layers in electronic devices regularly, the problems of lag and crash during layer switching are solved, and the device's running speed and user experience are improved.
Patent Information
- Application Number
- CN202410159955.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-02
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2044-02-02
AI Technical Summary
Electronic devices are prone to lag and application crashes during layer switching, affecting the user experience.
By scanning the number of layers and memory usage in electronic devices regularly, release layers in off-screen layer queues, including layers with a long creation time and a large memory usage, avoiding memory leakage and improving device operation stability.
It effectively reduces the lag and crash of electronic devices, and improves the running speed and user experience.
Smart Images

Figure CN119271321B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of terminals, and in particular, to a method for processing layers and related devices. Background Art
[0002] With the development of electronic device technology, electronic devices are more and more widely used, the demand for display effects is getting higher and higher, and the content displayed on the electronic device interface is also getting richer. In some implementations, the display interface of an electronic device is usually composed of multiple layers. When a user uses the electronic device, the user may need to perform operations such as switching or closing the currently displayed interface of the electronic device, or entering another interface on this interface.
[0003] Currently, when the user performs the above operations, the electronic device sometimes freezes, which affects the user experience. Summary of the Invention
[0004] Embodiments of this application provide a method for processing layers and related devices, which can release the memory space occupied by layers in an electronic device, is beneficial to improving the running speed of the electronic device, is beneficial to reducing the probability of the electronic device freezing, and is beneficial to enhancing the user experience.
[0005] In a first aspect, an embodiment of the present application provides a layer processing method. The method includes: at a first moment, in response to an operation of entering a first interface, the first interface is displayed. The first interface includes an image synthesized by M layers, and the M layers exist in a first queue, and the M layers are in a referenced state. Wherein, as of the first moment, the number of layers in the electronic device is N1, the memory space occupied by the N1 layers is L1, N1 is less than a first threshold, and the proportion of L1 in the target memory space of the electronic device is less than a second threshold; at a second moment, in response to an operation of switching from the first interface to a second interface, the second interface is displayed and the M layers are placed in a second queue. The second interface includes an image synthesized by P layers, and the P layers exist in the first queue, and both the P layers and the M layers are in a referenced state. Wherein, as of the second moment, the number of layers in the electronic device is N2, the memory space occupied by the N2 layers is L2, N2 is greater than or equal to the first threshold, and the N2 layers include the P layers and the M layers; based on N2 being greater than or equal to the first threshold, Q layers in the second queue are released, and the Q layers are all or part of the layers in the second queue; at a third moment, in response to an operation of switching from the second interface to a third interface, the third interface is displayed and the P layers are placed in the second queue. The third interface includes an image synthesized by S layers, and the S layers exist in the first queue, and both the S layers and the P layers are in a referenced state. Wherein, as of the third moment, the number of layers in the electronic device is N3, the memory space occupied by the N3 layers is L3, the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold, and the N3 layers include the S layers and the P layers; based on the proportion of L3 in the target memory of the electronic device being greater than or equal to the second threshold, K layers in the second queue are released, and the K layers are all or part of the layers in the second queue.
[0006] It should be understood that the first threshold is the threshold of the number of layers that can exist simultaneously in the electronic device. When the number of layers in the electronic device is less than the first threshold, it can be considered that the electronic device can normally create new layers; the second threshold is the threshold of the memory space occupied by the layers in the electronic device. When the memory space occupied by the layers in the electronic device is less than the second threshold, it can be considered that the electronic device runs smoothly and the probability of freezing or crashing is relatively low.
[0007] It should also be understood that the first queue may be a queue including the layer corresponding to the interface being displayed on the display screen, and the second queue may be an off-screen layer queue. It should be noted that both the first queue and the second queue may be queues that can be updated in real time, and the layers in the second queue at the second moment and the layers in the second queue at the third moment may be different.
[0008] In the embodiment of the present application, as of the first moment, the number of layers in the electronic device is N1, the memory space occupied by the N1 layers is L1, N1 is less than the first threshold, and the proportion of L1 in the target memory space of the electronic device is less than the second threshold. Therefore, at the first moment, the electronic device is in a normal operating state; as of the second moment, the number of layers in the electronic device is N2, the memory space occupied by the N2 layers is L2, N2 is greater than or equal to the first threshold. Therefore, at this time, Q layers in the second queue can be released; as of the third moment, the number of layers in the electronic device is N3, the memory space occupied by the N3 layers is L3, and the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold. Therefore, at this time, K layers in the second queue can be released. The method provided by the embodiment of the present application releases all or part of the layers in the second queue when the number of layers in the electronic device exceeds the first threshold, and / or the memory occupied by the layers in the electronic device exceeds the second threshold, so as to release the memory of the electronic device, which is beneficial to improving the operating speed of the electronic device, reducing the occurrence of lags and application crashes in the electronic device, and enhancing the user experience.
[0009] In the embodiment of the present application, the capital letters or combinations of capital letters and numbers such as M, P, N1, L1, N2, L2, N3, L3, Q, S, K, X, etc. all represent positive integers greater than or equal to 1, and will not be repeated hereinafter.
[0010] Combined with the first aspect, in some implementation manners of the first aspect, the Q layers satisfy at least one of the following conditions: the Q layers belong to the layers in the second queue whose creation time is in the first X percent; or, the proportion of the memory space occupied by each layer in the Q layers in the memory space occupied by all the layers in the second queue exceeds the third threshold.
[0011] In the embodiment of the present application, the layers in the second queue whose creation time is in the first X percent can be understood as the layers that have been off the screen for a long time but the reference count is still not zero. They have been created for a long time but have not been released yet, and the probability of their abnormal reference is relatively high. Therefore, in the embodiment of the present application, these layers can be selected for release; the layers in the second queue whose proportion of the memory space occupied in the memory space occupied by all the layers in the off-screen layer queue exceeds the third threshold can be understood as the layers that occupy more memory of the electronic device. In the embodiment of the present application, these layers can be selected for release, which can accelerate the memory release efficiency of the electronic device.
[0012] In combination with the first aspect, in certain implementations of the first aspect, each layer of the second queue carries the following layer information: the identifier of the layer, the creation time of the layer, and the memory space occupied by the layer; before releasing the Q layers in the second queue, the method includes: copying the layer information carried in the second queue and putting the layer information into a third queue; traversing the third queue to obtain the Q layers.
[0013] In the embodiments of the present application, the second queue is a queue that can be updated in real time. To avoid directly screening in the second queue and affecting the normal putting and releasing of the layers in the second queue, when it is determined that Q layers in the second queue need to be released, the layer information in the second queue can be copied and put into the third queue, and the Q layers can be obtained by traversing the third queue, which is beneficial to the stable operation of the electronic device.
[0014] In combination with the first aspect, in certain implementations of the first aspect, releasing the Q layers in the second queue includes: setting the reference count of each of the Q layers to a preset value, where the preset value is used to indicate that the Q layers are releasable.
[0015] Optionally, the preset value can be zero, but the present application does not limit this.
[0016] In the embodiments of the present application, by setting the reference count of each of the Q layers to the preset value, the release (or also referred to as clearing, destroying, destructing, etc.) program of the Q layers can be triggered. In this way, there is no need to reset the program code for clearing the layers, reducing the operation complexity of the electronic device.
[0017] In combination with the first aspect, in certain implementations of the first aspect, the electronic device includes a first application, a display composition system, a display driver, and a display screen. The first interface belongs to the first application. After responding to the operation of entering the first interface, the method further includes: the first application transmitting the parameters of the M layers to the display composition module, where the parameters of the M layers include the position parameters, content parameters, size parameters, transparency parameters, and layer level parameters of each of the M layers; the display composition system synthesizing the first interface based on the parameters of the M layers and transmitting the first interface to the display driver; displaying the first interface includes: the display driver transmitting the first interface to the display screen; the display screen displaying the first interface.
[0018] In combination with the first aspect, in some implementations of the first aspect, releasing Q layers in the second queue based on N2 being greater than or equal to the first threshold includes: the display composition system releasing Q layers in the second queue based on N2 being greater than or equal to the first threshold.
[0019] In combination with the first aspect, in some implementations of the first aspect, the second queue includes an offscreen layers queue.
[0020] In combination with the first aspect, in some implementations of the first aspect, the display composition system includes a display composition surfaceflinger module.
[0021] In the embodiments of the present application, surfaceflinger can be used to periodically scan the number of layers and the memory of the layers in the electronic device. On the basis of not affecting the existing layer creation and release processes, it is beneficial to avoid phenomena such as the electronic device freezing and crashing caused by abnormal layer destruction, which is beneficial to the smooth operation of the electronic device and beneficial to improving the user experience.
[0022] In a second aspect, an embodiment of the present application provides a layer processing device. The layer processing device can be an electronic device, or a chip or a chip system inside the electronic device. The layer processing device may include a display unit and a processing unit. When the layer processing device is an electronic device, the display unit may be a display screen. The display unit is used to perform the display step so that the electronic device implements a layer processing method described in the first aspect or any one of the possible implementations of the first aspect. When the layer processing device is an electronic device, the processing unit may be a processor. The layer processing device may further include a storage unit, and the storage unit may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit so that the electronic device implements a layer processing method described in the first aspect or any one of the possible implementations of the first aspect. When the layer processing device is a chip or a chip system inside the electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit so that the electronic device implements a layer processing method described in the first aspect or any one of the possible implementations of the first aspect. The storage unit may be a storage unit inside the chip (for example, registers, caches, etc.), or a storage unit outside the chip inside the electronic device (for example, read-only memory, random access memory, etc.).
[0023] In a third aspect, an embodiment of the present application provides an electronic device, including one or more processors and a memory. The memory is coupled to the one or more processors. The memory is used to store computer program code, and the computer program code includes computer instructions. The one or more processors call the computer instructions to cause the electronic device to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0024] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which includes a computer program or instructions. When the computer program or instructions run on a computer, the computer is caused to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0025] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes computer program code. When the computer program code runs on a computer, the computer is caused to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0026] In a sixth aspect, the present application provides a chip or a chip system. The chip or the chip system includes one or more processors and a communication interface. The communication interface and the one or more processors are interconnected by a line. The one or more processors are used to run a computer program or instructions to execute the method described in the first aspect or any possible implementation manner of the first aspect. Among them, the communication interface in the chip can be an input / output interface, a pin, a circuit, etc.
[0027] In a possible implementation, the chip or the chip system described above in the present application further includes at least one memory, and instructions are stored in the at least one memory. The memory can be a storage unit inside the chip, such as a register, a cache, etc., or a storage unit of the chip (such as a read-only memory, a random access memory, etc.).
[0028] It should be understood that the second to sixth aspects of the present application correspond to the technical solutions of the first aspect of the present application. The beneficial effects obtained by each aspect and the corresponding feasible implementation manners are similar and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 It is a schematic diagram of interface synthesis provided by an embodiment of the present application;
[0030] Figure 2 It is a schematic block diagram of the software architecture of an electronic device provided by an embodiment of the present application;
[0031] Figure 3 It is a schematic flowchart of layer creation and release provided by an embodiment of the present application;
[0032] Figure 4 Schematic flowchart of a layer processing method provided by an embodiment of the present application;
[0033] Figure 5 Schematic flowchart of another layer processing method provided by an embodiment of the present application;
[0034] Figure 6 Schematic block diagram of the hardware structure of an electronic device provided by an embodiment of the present application;
[0035] Figure 7 Schematic block diagram of a chip structure provided by an embodiment of the present application. Detailed implementation manners
[0036] For the convenience of clearly describing the technical solutions of the embodiments of the present application, the following briefly introduces some terms and technologies involved in the embodiments of the present application:
[0037] 1. Other terms
[0038] In the embodiments of the present application, terms such as "first" and "second" are used to distinguish the same items or similar items with basically the same functions and roles. For example, the first chip and the second chip are only used to distinguish different chips, and do not limit their sequence. Those skilled in the art can understand that the terms "first", "second", etc. do not limit the quantity and execution order, and the terms "first", "second", etc. do not necessarily limit differences.
[0039] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to represent examples, illustrations or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Exactly speaking, the use of words such as "exemplary" or "for example" is intended to present relevant concepts in a specific manner.
[0040] In the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B may be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one (item)" or its similar expression refers to any combination of these items, including any combination of single item(s) or plural item(s). For example, at least one (item) of a, b, or c may represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, and c may be single or multiple.
[0041] 2. Electronic device
[0042] The electronic device in the embodiments of the present application may include a handheld device with a display function, a vehicle-mounted device, etc. For example, some electronic devices are: mobile phone, tablet computer, handheld computer, laptop computer, mobile internet device (MID), wearable device, virtual reality (VR) device, augmented reality (AR) device, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical surgery, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, cellular phone, cordless phone, session initiation protocol (SIP) phone, wireless local loop (WLL) station, personal digital assistant (PDA), handheld device with wireless communication function, computing device or other processing devices connected to a wireless modem, vehicle-mounted device, wearable device, electronic device in a 5G network, or electronic device in a future evolved public land mobile network (PLMN), etc. The embodiments of the present application are not limited thereto.
[0043] By way of example and not limitation, in the embodiments of the present application, the electronic device may also be a wearable device. A wearable device, also known as a wearable intelligent device, is a general term for devices developed by applying wearable technology to the intelligent design of daily wear, such as glasses, gloves, watches, clothing, and shoes. A wearable device is a portable device that is either directly worn on the body or integrated into the user's clothing or accessories. A wearable device is not only a hardware device, but also realizes powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable intelligent devices include those with complete functions and large sizes that can achieve complete or partial functions without relying on a smartphone, such as smart watches or smart glasses, as well as those that only focus on a certain type of application function and need to cooperate with other devices such as smartphones, such as various smart bracelets and smart jewelry for physical sign monitoring.
[0044] In addition, in the embodiments of the present application, the electronic device may also be an electronic device in an Internet of Things (IoT) system. The IoT is an important part of the future development of information technology. Its main technical feature is to connect objects to the network through communication technology, so as to realize an intelligent network of human-machine interconnection and object-object interconnection.
[0045] The electronic device in the embodiments of the present application may also be referred to as: electronic device, user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile terminal, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication device, user agent, or user device, etc.
[0046] In the embodiments of the present application, the electronic device or each network device includes a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes hardware such as a central processing unit (CPU), a memory management unit (MMU), and a memory (also called main memory). The operating system can be any one or more computer operating systems that implement service processing through processes, such as the Linux operating system, the Unix operating system, the Android operating system, the iOS operating system, or the Windows operating system, etc. The application layer includes applications such as a browser, an address book, a word processing software, and an instant messaging software.
[0047] With the development of electronic device technology, electronic devices are more and more widely used, the demand for display effects is getting higher and higher, and the content displayed on the electronic device interface is also becoming richer. In some implementations, the display interface of an electronic device is usually composed of multiple layers, for example Figure 1 The display interface 105 of the electronic device shown can be composed of a status bar layer 101, a desktop icon layer 102, a wallpaper layer 103, and a navigation bar layer 104.
[0048] It should be understood that the layers created by the electronic device will occupy the memory of the electronic device. Usually, the layer should be released when it is no longer used. However, in some implementations, the layer may be abnormally referenced, making it difficult to release the layer. This will cause the layers created by the electronic device to accumulate, and the excessive memory occupied by the layers will cause the electronic device to malfunction, possibly resulting in lags, application crashes, etc., affecting the user experience.
[0049] In view of this, the present application provides a layer processing method and related device, which can scan the number and memory of the layers created by the electronic device. When the number of layers in the electronic device exceeds a first threshold, and / or when the memory occupied by the layers of the electronic device exceeds a second threshold, all or part of the layers in the off-screen queue are released to release the memory of the electronic device, which is beneficial to improving the running speed of the electronic device, reducing the occurrence of lags and application crashes of the electronic device, and enhancing the user experience.
[0050] To facilitate the understanding of the embodiments of the present application, the software architecture of the electronic device provided by the embodiments of the present application will be introduced first. The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture. In the embodiments of the present application, the Android system with a layered architecture is taken as an example to exemplarily illustrate the software architecture of the electronic device 100.
[0051] Figure 2 An exemplary software architecture block diagram of the electronic device 100 is shown.
[0052] The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom, namely the application layer, the application framework layer, the system library layer, the hardware abstraction layer, and the kernel layer.
[0053] The application layer may include a series of application packages. Such as Figure 2As shown, the application package may be the application package of the first application, and the first application may be any application such as a camera, a gallery, a calendar, a call, a map, a navigation, a WLAN, a Bluetooth, music, a video, a short message, etc. This application does not make specific limitations in this regard.
[0054] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions. For example, Figure 2 As shown, the application framework layer may include a window manager service (WMS), a view system API, a graphics system API, etc.
[0055] Among them, the window manager service can be used to manage window programs and manage the size, display order, etc. of windows; the view system can be used to build the display interface of an application, and the display interface can be composed of one or more layers;
[0056] The system library layer may include multiple functional modules. For example: a display composition system (SurfaceFlinger), etc. SurfaceFlinger can provide the fusion of 2D and 3D layers for multiple applications.
[0057] The hardware abstraction layer defines a set of unified interfaces for accessing the functions of hardware devices. These interfaces hide the specific implementation details, enabling the operating system and applications to interact with hardware devices in a standardized manner, reducing system complexity and development costs. In the embodiments of this application, the hardware abstraction layer may include a Gralloc interface and a Hardware Composer interface. Through the Gralloc interface, a buffer can be applied for and allocated for a layer, and through the Hardware Composer interface, the hardware composition of the layer can be implemented to accelerate the layer composition process.
[0058] The kernel layer is the layer between hardware and software. In the embodiments of this application, the kernel layer at least includes a memory driver and a display driver.
[0059] In addition, the electronic device may further include a hardware layer. In the embodiments of this application, the hardware layer may at least include a memory and a display screen.
[0060] Next, in combination with the Figure 2 software architecture shown, the layer creation and destruction processes of the electronic device will be described in detail.
[0061] Figure 3Exemplarily, a schematic flowchart of the layer creation method 300 is shown. The method 300 can be executed by an electronic device, and the software architecture of the electronic device can be as shown in Figure 2 as shown, but this application does not limit this.
[0062] As a possible scenario, the user is using a first application on the electronic device. In response to the user's first operation, the electronic device enters the interface 1 corresponding to the first application. The process of the electronic device displaying the interface 1 on the display screen in response to the first operation may include the following steps S301 to S314. It should be understood that the first operation is used to instruct the first application to enter the interface 1. The first application executes S301 in response to the first operation.
[0063] S301. The first application transmits a first instruction to the view system. The first instruction is used to instruct to enter the interface 1, and the first instruction includes the graphic information of the interface 1. Correspondingly, the view system receives the first instruction.
[0064] Optionally, the first application can be any system application in the electronic device, such as the system desktop, the negative first screen, etc., or any third-party application installed on the electronic device, such as a chat and dating application, a meeting application, etc. This application does not make specific limitations on the first application.
[0065] It should be understood that the graphic information of the interface 1 may include the information of one or more layers corresponding to the interface 1. This information may include, for example, the content attribute information, position information, size information, transparency information, layer level information (z-order), etc. of each layer that composes the interface 1. This application does not make any limitations on the specific content of the graphic information.
[0066] In a possible implementation manner, the first application transmits the first instruction to the view system through the window management service. It should be understood that the window management service can allocate a display window for the interface 1 corresponding to the first instruction and manage the window.
[0067] In a possible implementation manner, the first application can transmit the first instruction to the view system through the Java Native Interface (JNI).
[0068] S302. The view system creates a surface through SurfaceControl.
[0069] S303. The view system transmits a first message to SurfaceFlinger. The first message is used to notify SurfaceFlinger to create a layer. Correspondingly, SurfaceFlinger receives the first message.
[0070] S304. SurfaceFlinger creates a layer corresponding to this surface.
[0071] In a possible implementation, the view system includes a surface control interface. After receiving the above first instruction, the view system creates one or more surfaces corresponding to Interface 1. It can be understood that in the Android system, the layer in the Java layer of the application process can be called a surface, and the layer in the SurfaceFlinger process can be called a layer. The surface in the Java layer can be considered to have the same meaning as the layer in SurfaceFlinger, but this application does not make any limitations in this regard.
[0072] In some implementations, each surface of the application corresponds to a layer in SurfaceFlinger. The layer can be understood, for example, as the layer used by SurfaceFlinger to synthesize Interface 1. The number of layers is the same as the number of surfaces created by the above view system.
[0073] It should be understood that the layer created here needs to obtain the graphic information cache (GraphicBuffer) corresponding to this layer from the buffer queue of the graphics system. Therefore, it is necessary to apply for memory from the storage module of the electronic device, and SurfaceFlinger continues to execute S305.
[0074] S305. SurfaceFlinger transmits a memory allocation request to the gralloc (graphic allocation) interface. Correspondingly, gralloc receives the memory allocation request.
[0075] S306. Gralloc allocates memory for the GraphicBuffer corresponding to the layer and obtains the memory address corresponding to this GraphicBuffer.
[0076] In a possible implementation, gralloc interacts with the memory through the memory driver to apply for memory for this GraphicBuffer. Optionally, this memory is shared memory. It should be understood that shared memory can be called by multiple processes.
[0077] S307. Gralloc transmits the memory address corresponding to this GraphicBuffer to SurfaceFlinger, the graphics system, and the view system. Correspondingly, SurfaceFlinger, the graphics system, and the view system receive this memory address.
[0078] In a possible implementation, gralloc can transfer the memory address to the graphics system through SurfaceFlinger, and then the graphics system transfers the memory address to the view system; in another possible implementation, gralloc can transfer the memory address to SurfaceFlinger, the graphics system, or the view system respectively, and this application does not make specific limitations on this.
[0079] S308. The view system transfers graphic information to the graphics system. Correspondingly, the graphics system receives the graphic information.
[0080] S309. The graphics system maps the graphic information to a memory address and puts it into the buffer queue BufferQueue.
[0081] Optionally, the memory address may include one or more. The graphic information corresponding to each layer of interface 1 may share one memory address, or each layer of interface 1 may correspond to one memory address respectively. This application does not make specific limitations on this.
[0082] S310. The graphics system transfers a second message to SurfaceFlinger. The second message is used to notify SurfaceFlinger that there is an update in the buffer queue BufferQueue. Correspondingly, SurfaceFlinger receives the second message.
[0083] It should be understood that the surface belongs to the application process, and the layer belongs to the SurfaceFlinger process. If only one buffer is used, both processes may be using the buffer simultaneously, which may cause the screen display we see to be incorrect and there may be tearing. In some implementations, a buffer queue method is adopted. For example, using the buffer queue BufferQueue, the surface can be understood as the producer here, and SurfaceFlinger can be understood as the consumer here.
[0084] S311. SurfaceFlinger obtains the buffer corresponding to the graphic information from BufferQueue and updates the layer.
[0085] In a possible implementation, the buffer corresponding to the graphic information can be encapsulated with GraphicBuffer.
[0086] S312. SurfaceFlinger synthesizes interface 1 based on the layer.
[0087] It should be understood that the layer(s) used to synthesize the interface 1 can be one or more, and this application does not limit this.
[0088] S313. SurfaceFlinger transmits the interface 1 to the display driver. Correspondingly, the display driver receives the interface 1.
[0089] S314. The display driver transmits the interface 1 to the display screen. Correspondingly, the display screen receives the interface 1.
[0090] S315. The display screen displays the interface 1.
[0091] As a possible scenario, after the electronic device displays the interface 1, the user performs a second operation, and the second operation is used to close the interface 1. In response to the user's second operation, the electronic device executes the following S316 - S319.
[0092] S316. The first application transmits a second instruction to the view system, and the second instruction is used to instruct to release the layers included in the interface 1. Correspondingly, the view system receives the second instruction.
[0093] In a possible implementation manner, when the electronic device is operating normally, the electronic device may not actively release the layer, but may respond to the user operation to perform the release of the layer.
[0094] S317. The view system decrements the reference count of the surface control referenced by the interface 1 by 1.
[0095] In some implementations, the interface 1 may reference one or more surface controls, and one surface control corresponds to one layer, but this application does not limit this. In the embodiments of this application, the way for the interface 1 to reference the surface control may be to increase the reference count of the surface control. Correspondingly, when it is necessary to release the layer corresponding to the interface 1, the reference count of the surface control can be decremented by 1.
[0096] In some implementations, the reference of the interface 1 to the surface control and the reference of the surface control to the layer can be strong pointers (SP).
[0097] S318. The view system transmits a second message to SurfaceFlinger, and the second message is used to notify SurfaceFlinger to destroy the layer referenced by the interface 1.
[0098] S319. SurfaceFlinger decrements the reference count of the layer referenced by Interface 1 by 1.
[0099] In a possible implementation, SurfaceControl references a layer through the layer's identifier. For example, it can be a handle program. When the reference count of SurfaceControl is decremented by 1, it triggers the handle.clear program to execute the program for clearing the layer identifier (onHandleDestroyed) to clear the reference of SurfaceControl to the layer. In this way, the reference count of the layer can be decremented by 1. It should be understood that when the reference count of the layer is zero, the layer executes the self-destruction program (onLayerDestroyed).
[0100] The above Method 300 describes the process of layer creation and destruction in an electronic device. Next, a layer processing method provided by an embodiment of the present application will be described in detail.
[0101] Figure 4 Exemplarily, a schematic flowchart of a layer processing method 400 is shown. This method 400 can be executed by an electronic device, and the software architecture of the electronic device can be as shown in Figure 2 As shown. Further, this method 400 can be executed by SurfaceFlinger in the electronic device, but the present application does not limit this.
[0102] Optionally, Method 400 can be executed at any time during the execution of the above Method 300, or it can also be executed outside the execution process of Method 300. The present application does not specifically limit the execution timing of Method 400.
[0103] Method 400 includes the following steps:
[0104] S401. Periodically count the number of all layers existing in the electronic device and the memory (dmabuf) occupied by all layers.
[0105] It should be understood that SurfaceFlinger can record the number of layers and the memory occupied by each layer during the process of creating a layer. In a possible implementation, SurfaceFlinger reports the number of all layers existing in the electronic device through a first interface and reports the memory occupied by all layers existing in the electronic device through a second interface.
[0106] The "periodically count" described in the above S401 can be understood as counting once every preset time interval. The preset time interval can be 10 milliseconds or 10 seconds. The present application does not limit this.
[0107] Optionally, the first interface may be reportlayerInfo, and the second interface may be reportdmainfo, but the present application does not limit this.
[0108] S402. Determine whether the number of all layers existing in the electronic device exceeds a first threshold, and / or whether the memory occupied by all layers exceeds a second threshold; if so, execute S403, if not, return to execute S401.
[0109] It should be understood that there is a limit to the number of layers that can exist simultaneously in the electronic device. This limit may be, for example, 4096, which means that the electronic device only allows 4096 layers to exist simultaneously. After the number of layers reaches the limit, the electronic device will not be able to continue creating layers. Referring to the description in the above method 300, the inability of the electronic device to create layers means that the target interface cannot be further synthesized, which may cause the display screen seen by the user to freeze and the user cannot enter the target interface. Therefore, in the embodiments of the present application, the number of all layers existing in the electronic device is set as the first threshold, and the first threshold may be less than or equal to the limit on the number of layers that can exist simultaneously in the electronic device. When the number of all layers existing in the electronic device exceeds the first threshold, the electronic device executes S403.
[0110] It should also be understood that the memory size available for storing layers in the electronic device is also limited. Usually, the memory for storing layers may be the running memory, but the present application does not limit this. When the memory occupied by all layers existing in the electronic device exceeds the second threshold, it may squeeze the running space of other programs in the electronic device, making the electronic device unable to run smoothly. In severe cases, it may cause the system to restart and the user's unsaved files to be lost, bringing a poor user experience to the user. In the embodiments of the present application, when the memory occupied by all layers existing in the electronic device exceeds the second threshold, S403 is executed to release the memory space of the electronic device.
[0111] S403. Copy the information of all layers in the offscreenlayers queue to the staticlayers queue.
[0112] It should be understood that all off-screen layers will be put into the off-screen layer queue. When a layer is destructed successfully, i.e., released successfully, it can trigger SurfaceFlinger to clean up and remove the corresponding layer, completing the closed-loop of the entire destruction process. When there is an abnormal reference in SurfaceControl, the destruction path is interrupted, the layer object cannot be destructed, and resources leak. These undestroyed layers will all be added to the off-screen layer queue. The layers in the off-screen layer queue are not referenced by the interface being displayed on the display, but these layers may be reused later, or are being referenced by other programs, or are abnormally referenced. Therefore, the reference count of these layers is not zero, and they are still occupying the memory space of the electronic device.
[0113] In the embodiments of the present application, to avoid interfering with the operation of the off-screen layer queue by directly operating on it in the off-screen layer queue, the information of all layers in the off-screen layer queue is transferred to the static layer queue, which is beneficial to maintaining the running stability of the electronic device.
[0114] S404. Screen out the first layer that meets the first condition in the static layer queue, and obtain the identification information of the first layer; the first condition includes: the first layer belongs to the layer in the off-screen layer queue whose creation time is in the top X percent, or the first layer is the layer in the off-screen layer queue whose occupied memory space accounts for more than the third threshold in the total memory space occupied by all layers in the off-screen layer queue.
[0115] S405. Release the first layer based on the identification information of the first layer.
[0116] The layer in the off-screen layer queue whose creation time is in the top X percent can be understood as a layer that has been off-screen for a long time but whose reference count is still not zero. It has not been released after a long creation time, and the probability of its abnormal reference is relatively high. Therefore, in the embodiments of the present application, this part of the layers can be selected for release.
[0117] The layer in the off-screen layer queue whose occupied memory space accounts for more than the third threshold in the total memory space occupied by all layers in the off-screen layer queue can be understood as a layer that occupies more memory of the electronic device. In the embodiments of the present application, this part of the layers can be selected for release, which can accelerate the memory release efficiency of the electronic device.
[0118] Optionally, X can be ten or twenty. The first layer can be called the top layer. The number of the first layers can be one or more. The queue composed of the first layers can be called the abnormal layers queue. The present application does not make specific limitations on this.
[0119] In a possible implementation, the method for releasing the first layer based on the identification information of the first layer may be to set the reference count of the first layer to zero to trigger the self-destruction process of the first layer, or the so-called destruction process.
[0120] Embodiments of the present application can, without affecting the existing layer creation and destruction programs, regularly count the number of all layers present in the electronic device and the memory occupied by all layers, and screen out the first layer that meets the first condition when the number of all layers present in the electronic device exceeds the first threshold and / or the memory occupied by all layers exceeds the second threshold, and release the first layer based on the identification information of the first layer. The method provided by the embodiments of the present application helps to avoid the phenomenon that the memory of the electronic device is over-occupied due to abnormal layer destruction (also known as layer dmabuf memory leakage), helps to maintain the running stability of the electronic device, and improves the user experience.
[0121] Figure 5 It is a schematic flowchart of a layer processing method 500 provided by an embodiment of the present application. This method 500 can be executed by an electronic device or by any module in the electronic device, and the present application does not make specific limitations on this. The software structure of the electronic device can be as Figure 2 shown.
[0122] This method 500 includes the following steps:
[0123] S501. At the first moment, in response to the operation of entering the first interface, display the first interface. The first interface includes an image synthesized by M layers. The M layers exist in the first queue, and the M layers are in a referenced state; where, as of the first moment, the number of layers in the electronic device is N1, the memory space occupied by the N1 layers is L1, N1 is less than the first threshold, and the proportion of L1 in the target memory space of the electronic device is less than the second threshold.
[0124] S502. At the second moment, in response to the operation of switching from the first interface to the second interface, display the second interface and put the M layers into the second queue. The second interface includes an image synthesized by P layers. The P layers exist in the first queue, and both the P layers and the M layers are in a referenced state; where, as of the second moment, the number of layers in the electronic device is N2, the memory space occupied by the N2 layers is L2, N2 is greater than or equal to the first threshold, and the N2 layers include the P layers and the M layers.
[0125] S503. Based on N2 being greater than or equal to the first threshold, release Q layers in the second queue, and the Q layers are all or part of the layers in the second queue.
[0126] S504. At the third moment, in response to the operation of switching from the second interface to the third interface, display the third interface and put P layers into the second queue. The third interface includes an image synthesized by S layers, and the S layers exist in the first queue. Both the S layers and the P layers are in a referenced state. Among them, as of the third moment, the number of layers in the electronic device is N3, the memory space occupied by the N3 layers is L3, and the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold. The N3 layers include the S layers and the P layers.
[0127] S505. Based on the fact that the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold, release K layers in the second queue, where the K layers are all or part of the layers in the second queue.
[0128] In a possible implementation manner, the process of displaying the first interface in response to the operation of entering the first interface in S501 above, the process of displaying the second interface in response to the operation of switching from the first interface to the second interface in S502 above, and the process of displaying the third interface in response to the operation of switching from the second interface to the third interface in S504 above are similar to the process of the electronic device displaying interface 1 in response to the first operation described in S301 - S315 of the above method 300, and will not be elaborated here.
[0129] It should be understood that the first threshold is the threshold for the number of layers that can exist simultaneously in the electronic device. When the number of layers in the electronic device is less than the first threshold, it can be considered that the electronic device can normally create new layers. The second threshold is the threshold for the memory space occupied by the layers in the electronic device. When the memory space occupied by the layers in the electronic device is less than the second threshold, it can be considered that the electronic device runs smoothly and the probability of freezing or crashing is relatively low.
[0130] It should also be understood that the first queue can be a queue including the layers corresponding to the interface being displayed on the display screen, and the second queue can be an off - screen layer queue.
[0131] In the embodiment of the present application, at the first moment, the number of layers in the electronic device is N1, the memory space occupied by the N1 layers is L1, N1 is less than the first threshold, and the proportion of L1 in the target memory space of the electronic device is less than the second threshold. Therefore, at the first moment, the electronic device is in a normal operating state; at the second moment, the number of layers in the electronic device is N2, the memory space occupied by the N2 layers is L2, N2 is greater than or equal to the first threshold. Therefore, at this time, Q layers in the second queue can be released; at the third moment, the number of layers in the electronic device is N3, the memory space occupied by the N3 layers is L3, and the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold. Therefore, at this time, K layers in the second queue can be released. The method provided by the embodiment of the present application releases all or part of the layers in the second queue when the number of layers in the electronic device exceeds the first threshold and / or the memory occupied by the layers in the electronic device exceeds the second threshold, so as to release the memory of the electronic device, which is beneficial to improving the running speed of the electronic device, reducing the occurrence of the electronic device freezing and application crashing, and enhancing the user experience.
[0132] In a possible implementation manner, the above Q layers can be any layers in the second queue as of the second moment, which can save the computing power of the electronic device.
[0133] In another possible implementation manner, the above Q layers satisfy at least one of the following conditions: the Q layers belong to the layers in the second queue whose creation time is in the top X percent; or, the proportion of the memory space occupied by each of the Q layers in the memory space occupied by all the layers in the second queue exceeds the third threshold.
[0134] In some implementations, the second queue includes an offscreen layers queue. The layers in the second queue whose creation time is in the top X percent can be understood as the layers that have been offscreen for a long time but whose reference count is still not zero. They have not been released yet although the creation time is long, and the probability of their abnormal reference is relatively high. Therefore, in the embodiment of the present application, these layers can be selected for release; the layers in the second queue whose occupied memory space exceeds the third threshold in the memory space occupied by all the layers in the offscreen layers queue can be understood as the layers that occupy more memory of the electronic device. In the embodiment of the present application, these layers can be selected for release, which can accelerate the memory release efficiency of the electronic device.
[0135] It should be understood that the method of screening K layers from the second queue can be similar to the method of screening Q layers from the second queue, which will not be elaborated here. However, it should be noted that the second queue can be a queue that can be updated in real time, and the layers in the second queue at the second moment and the layers in the second queue at the third moment can be different.
[0136] As an alternative embodiment, each layer in the second queue carries the following layer information: the identifier of the layer, the creation time of the layer, and the memory space occupied by the layer. Before releasing the Q layers in the second queue, the method includes: copying the layer information carried in the second queue and putting the layer information into the third queue; traversing the third queue to obtain the Q layers.
[0137] It should be understood that the second queue is a queue that can be updated in real time. To avoid directly screening in the second queue from affecting the normal putting and releasing of the layers in the second queue, in the embodiments of the present application, when it is determined that Q layers in the second queue need to be released, the layer information in the second queue can be copied and put into the third queue, and the Q layers can be obtained by traversing the third queue, which is beneficial to the stable operation of the electronic device.
[0138] As an alternative embodiment, releasing the Q layers in the second queue includes: setting the reference count of each layer in the Q layers to a preset value, and the preset value is used to identify that the Q layers can be released.
[0139] Optionally, the preset value can be zero, but the present application does not limit this.
[0140] As an alternative embodiment, the electronic device includes a first application, a display composition system, a display driver, and a display screen. The first interface belongs to the first application. After responding to the operation of entering the first interface, the method further includes: the first application transmits the parameters of M layers to the display composition system, and the parameters of the M layers include the position parameters, content parameters, size parameters, transparency parameters, and layer level parameters of each layer in the M layers; the display composition module composes the first interface based on the parameters of the M layers and transmits the first interface to the display driver; displaying the first interface includes: the display driver transmits the first interface to the display screen; the display screen displays the first interface.
[0141] As an alternative embodiment, based on N2 being greater than or equal to the first threshold, releasing the Q layers in the second queue includes: the display composition system releases the Q layers in the second queue based on N2 being greater than or equal to the first threshold.
[0142] In a possible implementation manner, the display composition system includes a display composition surfaceflinger module. In the embodiments of the present application, surfaceflinger can be used to implement the timing scan of the number of layers and the memory of the layers in the electronic device. On the basis of not affecting the existing layer creation and release processes, it can effectively avoid phenomena such as the electronic device freezing and crashing caused by abnormal layer destruction, which is beneficial to the smooth operation of the electronic device and beneficial to improving the user experience.
[0143] It should be noted that the module names involved in the embodiments of this application can all be defined as other names, as long as the functions of each module can be realized, and no specific restrictions are imposed on the module names.
[0144] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. And the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or reject.
[0145] It should be understood that the step numbers in the embodiments of this application do not constitute a limitation on the execution order. The execution order of the steps in each embodiment should be determined according to its internal logic. Each embodiment described in this application can be implemented alone or independently, and this application does not make specific limitations in this regard.
[0146] The layer processing method of the embodiments of this application has been described above. Next, the device for executing the above method provided by the embodiments of this application will be described. Those skilled in the art can understand that the method and the device can be combined and referenced with each other. The relevant device provided by the embodiments of this application can execute the steps in the above method for sorting the list.
[0147] Figure 6 An exemplary structural diagram of an electronic device 600 that can execute the above method is shown.
[0148] The electronic device 600 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 jack 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0149] It can be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device 600. In other embodiments of the present application, the electronic device 600 may include more or fewer components than those illustrated, or combine certain components, or split certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0150] The electronic device 600 realizes the display function through the GPU, the display screen 194, the application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to execute mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
[0151] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel may adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 600 may include one or N display screens 194, where N is a positive integer greater than 1. In the embodiments of the present application, the display screen may be used to display the interfaces in the above embodiments.
[0152] The internal memory 121 may be used to store computer-executable program codes, and the executable program codes include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.). The data storage area may store data created during the use of the electronic device 600, such as the layer data involved in the embodiments of the present application. The processor 110 executes various functional applications and data processing of the electronic device 600 by running the instructions stored in the internal memory 121 and / or the instructions stored in the memory provided in the processor.
[0153] Figure 7Exemplarily shown is a schematic structural diagram of a chip provided by an embodiment. The chip 700 includes one or more than two (including two) processors 701, communication lines 702, a communication interface 703, and a memory 704.
[0154] In some embodiments, the memory 704 stores the following elements: executable modules or data structures, or subsets thereof, or extended sets thereof.
[0155] The methods described in the embodiments of the present application above can be applied to the processor 701 or implemented by the processor 701. The processor 701 may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above methods can be completed by the integrated logic circuit in the hardware of the processor 701 or instructions in software form. The above-mentioned processor 701 may be a general-purpose processor (e.g., a microprocessor or a conventional processor), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate, transistor logic devices, or discrete hardware components. The processor 701 can implement or execute the various processing-related methods, steps, and logic block diagrams disclosed in the embodiments of the present application.
[0156] The steps of the methods disclosed in combination with the embodiments of the present application can be directly implemented by the execution of a hardware decoding processor or completed by a combination of hardware and software modules in the decoding processor. Among them, the software module can be located in a mature storage medium in the art such as a random access memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable read-only memory (EEPROM). This storage medium is located in the memory 704, and the processor 701 reads the information in the memory 704 and combines its hardware to complete the steps of the above methods.
[0157] Communication can be carried out among the processor 701, the memory 704, and the communication interface 703 through the communication lines 702.
[0158] In the above embodiments, the instructions stored in the memory for the processor to execute can be implemented in the form of a computer program product. Among them, the computer program product can be pre-written in the memory or downloaded and installed in the memory in software form.
[0159] In an embodiment of the present application, the above chip 700 may also be a chip system, for example: a system on chip (SOC). The present application does not make any limitation thereto.
[0160] An embodiment of the present application provides a chip or a chip system. The chip or the chip system is applied to an electronic device. The chip or the chip system includes one or more processors, and the one or more processors are used to call computer instructions to cause the electronic device to execute the method in the above embodiment. The implementation principle and technical effect are similar to those of the above related embodiments, and will not be described herein again.
[0161] An embodiment of the present application provides an electronic device, which includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory stores computer program code, and the computer program code includes computer instructions; the one or more processors call the computer instructions to cause the electronic device to execute the method in the above embodiment.
[0162] An embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium includes computer instructions. When the computer instructions run on an electronic device, the electronic device is caused to execute the method in the above embodiment. The method described in the above embodiment may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the functions may be stored on or transmitted over a computer-readable medium as one or more instructions or codes. The computer-readable medium may include a computer storage medium and a communication medium, and may also include any medium that can transfer a computer program from one place to another. The storage medium may be any target medium accessible by a computer.
[0163] In one possible implementation, the computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM), or other optical disc storage, magnetic disk storage, or any other medium targeted to carry or store the program code required in the form of instructions or data structures and accessible by a computer. Moreover, any connection is properly termed a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of the medium. As used herein, disk and optical disc include optical disc, laser disc, optical disc, digital versatile disc (DVD), floppy disk, and Blu-ray disc, where disks typically reproduce data magnetically, while optical discs utilize lasers to optically reproduce data. Combinations of the above should also be included within the scope of computer-readable media.
[0164] An embodiment of the present application provides a computer program product. The computer program product includes computer program code that, when running on an electronic device, causes the electronic device to execute the method in the above embodiment.
[0165] Embodiments of the present application are described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, as well as the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to generate a machine such that the instructions executed by the processing unit of the computer or other programmable data processing device generate means for implementing the specified functions in one Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0166] The above specific implementation manners further elaborate on the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are only specific implementation manners of the present invention and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solution of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for processing a layer, characterized in that, Applied to an electronic device, the method includes: At a first moment, in response to an operation of entering a first interface, the first interface is displayed. The first interface includes an image synthesized by M layers, and the M layers exist in a first queue and are in a referenced state. Wherein, as of the first moment, the number of layers in the electronic device is N1, the memory space occupied by the N1 layers is L1, N1 is less than a first threshold, and the proportion of L1 in the target memory space of the electronic device is less than a second threshold; At a second moment, in response to an operation of switching from the first interface to a second interface, the second interface is displayed and the M layers are placed in a second queue. The second interface includes an image synthesized by P layers, and the P layers exist in the first queue. Both the P layers and the M layers are in a referenced state. Wherein, as of the second moment, the number of layers in the electronic device is N2, the memory space occupied by the N2 layers is L2, N2 is greater than or equal to the first threshold, and the N2 layers include the P layers and the M layers; Based on N2 being greater than or equal to the first threshold, Q layers in the second queue are released, and the Q layers are all or part of the layers in the second queue; At a third moment, in response to an operation of switching from the second interface to a third interface, the third interface is displayed and the P layers are placed in the second queue. The third interface includes an image synthesized by S layers, and the S layers exist in the first queue. Both the S layers and the P layers are in a referenced state. Wherein, as of the third moment, the number of layers in the electronic device is N3, the memory space occupied by the N3 layers is L3, the proportion of L3 in the target memory of the electronic device is greater than or equal to the second threshold, and the N3 layers include the S layers and the P layers; Based on the proportion of L3 in the target memory of the electronic device being greater than or equal to the second threshold, K layers in the second queue are released, and the K layers are all or part of the layers in the second queue.
2. The method according to claim 1, wherein The Q layers satisfy at least one of the following conditions: The Q layers belong to the layers in the second queue whose creation time is in the top X percent; or, The proportion of the memory space occupied by each layer in the Q layers in the memory space occupied by all layers in the second queue exceeds a third threshold.
3. The method according to claim 1 or 2, characterized in that, Each layer in the second queue carries the following layer information: the identifier of the layer, the creation time of the layer, and the memory space occupied by the layer; Before releasing the Q layers in the second queue, the method includes: Copying the layer information carried in the second queue and placing the layer information in a third queue; Traversing the third queue to obtain the Q layers.
4. The method according to any one of claims 1 to 3, characterized in that Releasing the Q layers in the second queue includes: Setting the reference count of each layer in the Q layers to a preset value, and the preset value is used to indicate that the Q layers can be released.
5. The method according to any one of claims 1 to 4, characterized in that The electronic device includes a first application, a display composition system, a display driver, and a display screen. The first interface belongs to the first application. After the operation of entering the first interface is responded to, the method further includes: The first application transmits the parameters of the M layers to the display composition system. The parameters of the M layers include the position parameters, content parameters, size parameters, transparency parameters, and layer level parameters of each layer in the M layers; The display composition system composes the first interface based on the parameters of the M layers and transmits the first interface to the display driver; Displaying the first interface includes: The display driver transmits the first interface to the display screen; The display screen displays the first interface.
6. The method according to claim 5, wherein Releasing the Q layers in the second queue based on the N2 being greater than or equal to the first threshold includes: The display composition system releases the Q layers in the second queue based on the N2 being greater than or equal to the first threshold.
7. The method according to claim 5 or 6, characterized in that, The display composition system includes a display composition surfaceflinger module.
8. The method according to any one of claims 1 to 7, characterized in that, The second queue includes an offscreen layers queue.
9. An electronic device, characterized in that, The electronic device includes: one or more processors and a memory; The memory is coupled to the one or more processors. The memory is used to store computer program code, and the computer program code includes computer instructions. The one or more processors call the computer instructions to cause the electronic device to execute the method according to any one of claims 1 to 8.
10. A chip system, characterized in that, The chip system is applied to an electronic device. The chip system includes one or more processors, and the one or more processors are used to call computer instructions to cause the electronic device to execute the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer instructions. When the computer instructions run on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that, The computer program product includes computer program code. When the computer program code runs on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Interface display method and device, terminal and storage medium
CN109992347A
Multi-level promotion caching
US8838882B1