Buffer allocation method, device, electronic device and storage medium

By serially allocating buffers in the rendering thread, the problem of rendering thread blocking when the application system load is high is solved, the buffer allocation efficiency and the response speed of the application system are improved, and the feeling of lag is reduced.

CN117687771BActive Publication Date: 2024-09-06HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310917073.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-24
Publication Date
2024-09-06
Estimated Expiration
2043-07-24

Smart Images

  • Figure CN117687771B
    Figure CN117687771B
Patent Text Reader

Abstract

The present application provides a buffer allocation method, device, electronic device and storage medium, which relates to the field of Internet application technology, including: when a buffer needs to be allocated for a window drawing task, obtaining the current system load; when the current system load exceeds a preset load threshold, serially calling the allocation buffer function of the buffer queue generator class in the rendering thread, and allocating a buffer for the window drawing task through the allocation buffer function. The embodiment of the present application improves the efficiency of buffer allocation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet application technology, and in particular to a buffer allocation method, device, electronic device and storage medium. Background Art

[0002] When a new application or program is started in the application system, a new window (Window) needs to be created for it. When the window is opaque, a task of allocating a memory buffer for the surface Surface corresponding to the window will be added to the layout process so that the application's rendering thread can use the buffer to complete the drawing of the window. In actual applications, the task of allocating a buffer for the Surface needs to establish a new thread outside the rendering thread, so that the task of allocating the buffer in the new thread is processed in parallel with the rendering thread to improve the execution efficiency of the rendering thread.

[0003] However, when the application system is overloaded, the new thread used to allocate buffers has a lower execution priority than the rendering thread in the application system. The new thread will be automatically delayed and unable to allocate buffers for Surface in time. The rendering thread that cannot get buffer allocation can only enter a dormant state and can only wake up after the buffer allocation is completed to perform subsequent drawing processing. The rendering thread will be blocked. The direct result of the rendering thread blocking is that the first frame after the new window appears takes longer to display, which gives users the feeling of slow response and lag of the application system. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a buffer allocation method, device, electronic device and storage medium to improve the quality of image selection. The specific technical solution is as follows:

[0005] In a first aspect, an embodiment of the present application provides a buffer allocation method, the method comprising:

[0006] When you need to allocate a buffer for a window drawing task, get the current system load;

[0007] When the current system load exceeds a preset load threshold, the buffer allocation function of the buffer queue generator class is serially called in the rendering thread, and a buffer is allocated for the window drawing task through the buffer allocation function.

[0008] In one embodiment of the present application, before obtaining the current system load, the method further includes:

[0009] Get the window creation task;

[0010] When the window corresponding to the window creation task is opaque, a window drawing task is created.

[0011] In one embodiment of the present application, when the window corresponding to the window creation task is opaque, creating a window drawing task includes:

[0012] Based on the window creation task, call the execution starting point function of the view root class;

[0013] Determining whether the window corresponding to the window creation task is transparent by the execution starting point function;

[0014] In the case where the window is opaque, calling a buffer allocation function of the hardware renderer class;

[0015] Calling the buffer allocation function of the rendering proxy class through the buffer allocation function of the hardware renderer class;

[0016] The window drawing task is created in the rendering thread through the buffer allocation function of the rendering proxy class.

[0017] In one embodiment of the present application, the serially calling the allocation buffer function of the buffer queue generator class in the rendering thread includes:

[0018] After the rendering thread calls the allocate buffer function of the buffer queue class, the render thread is used to call the allocate buffer function of the buffer queue generator class.

[0019] In one embodiment of the present application, before serially calling the buffer allocation function of the buffer queue generator class in the rendering thread and allocating a buffer for the window drawing task through the buffer allocation function, the method further includes:

[0020] Determining whether the current system load exceeds a preset load threshold by using the buffer allocation function of the buffer queue class;

[0021] The method further comprises:

[0022] When it is determined that the current system load does not exceed a preset load threshold, creating a buffer allocation thread executed in parallel with the rendering thread through an allocation buffer function of the buffer queue class;

[0023] The buffer allocation function of the buffer queue generator class is called in the allocation thread, and a buffer is allocated for the window drawing task through the buffer allocation function.

[0024] In one embodiment of the present application, after allocating a buffer for the window drawing task by the buffer allocation function, the method further includes:

[0025] The window drawing task is executed in the rendering thread based on the allocated buffer, and the window corresponding to the window creation task is drawn.

[0026] In a second aspect, an embodiment of the present application provides a buffer allocation device, the device comprising:

[0027] The system load acquisition module is used to obtain the current system load when a buffer needs to be allocated for a window drawing task;

[0028] The first buffer allocation module is used to serially call the buffer allocation function of the buffer queue generator class in the rendering thread when the current system load exceeds a preset load threshold, and allocate a buffer for the window drawing task through the buffer allocation function.

[0029] In one embodiment of the present application, the device further includes:

[0030] A first task creation module, used to obtain a window creation task;

[0031] The second task creation module is used to create a window drawing task when the window corresponding to the window creation task is opaque.

[0032] In one embodiment of the present application, the second task creation module is specifically used to:

[0033] Based on the window creation task, call the execution starting point function of the view root class;

[0034] Determining whether the window corresponding to the window creation task is transparent by the execution starting point function;

[0035] In the case where the window is opaque, calling a buffer allocation function of the hardware renderer class;

[0036] Calling the buffer allocation function of the rendering proxy class through the buffer allocation function of the hardware renderer class;

[0037] The window drawing task is created in the rendering thread through the buffer allocation function of the rendering proxy class.

[0038] In one embodiment of the present application, the first buffer allocation module is specifically used to:

[0039] After the rendering thread calls the allocate buffer function of the buffer queue class, the render thread is used to call the allocate buffer function of the buffer queue generator class.

[0040] In one embodiment of the present application, the device further includes:

[0041] A system load determination module, configured to determine whether the current system load exceeds a preset load threshold through the buffer allocation function of the buffer queue class;

[0042] The device also includes:

[0043] A thread creation module, configured to create a buffer allocation thread executed in parallel with the rendering thread through the buffer allocation function of the buffer queue class when it is determined that the current system load does not exceed a preset load threshold;

[0044] The second buffer allocation module is used to call the buffer allocation function of the buffer queue generator class in the allocation thread, and allocate a buffer for the window drawing task through the buffer allocation function.

[0045] In one embodiment of the present application, the device further includes:

[0046] The window drawing module is used to execute the window drawing task based on the allocated buffer in the rendering thread, and draw the window corresponding to the window creation task.

[0047] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0048] Memory, used to store computer programs;

[0049] The processor is used to implement any of the above-mentioned buffer allocation methods when executing a program stored in the memory.

[0050] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the buffer allocation method described above is implemented.

[0051] Beneficial effects of the embodiments of the present application:

[0052] The buffer allocation method provided in the embodiment of the present application obtains the current system load when a buffer needs to be allocated for a window drawing task. When the current system load exceeds a preset load threshold, the buffer allocation function of the buffer queue generator class is serially called in the rendering thread, and the buffer is allocated for the window drawing task through the buffer allocation function. Since the rendering thread has a higher execution priority and can be scheduled more timely, when the system load is high, compared with the solution of creating a new thread to allocate a buffer in the related art, the solution of the embodiment of the present application can complete the call of the buffer allocation function more timely, allocate a buffer for the window drawing task in time, improve the efficiency of buffer allocation, reduce the blocking probability of the rendering thread, and will not block the progress of window drawing in the rendering thread for a long time, but also save the time and memory overhead of creating a new thread, thereby improving the utilization rate of the application system. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0054] Figure 1-1 An example diagram of an application scenario of a buffer allocation method provided in an embodiment of the present application;

[0055] Figure 1-2 An example flow chart of a method for allocating a buffer zone in a related technology provided in an embodiment of the present application;

[0056] Figure 1-3 An example diagram of trace tracking of allocated buffers in a related technology provided in an embodiment of the present application;

[0057] Figure 2 A schematic diagram of a first structure of an electronic device provided in an embodiment of the present application;

[0058] Figure 3 A second structural diagram of an electronic device provided in an embodiment of the present application;

[0059] Figure 4 A software structure block diagram of an electronic device provided in an embodiment of the present application;

[0060] Figure 5 A schematic diagram of a flow chart of a first buffer allocation method provided in an embodiment of the present application;

[0061] Figure 6 A schematic diagram of a flow chart of a second buffer allocation method provided in an embodiment of the present application;

[0062] Figure 7 A possible implementation of step S202 provided in the embodiment of the present application;

[0063] Figure 8-1 An example diagram of an implementation process of a buffer allocation method provided in an embodiment of the present application;

[0064] Figure 8-2 An example diagram of implementation trace tracking of a buffer allocation method provided in an embodiment of the present application;

[0065] Fig. 9 A schematic diagram of the structure of a buffer allocation device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0066] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.

[0067] Because in the related art, when the load of the application system is too high, the task of allocating a buffer for the window drawing task in the new thread will be automatically delayed, causing the rendering thread where the window drawing task is located to be blocked. In order to solve this problem, the embodiments of the present application provide a buffer allocation method, device, electronic device and storage medium.

[0068] The buffer allocation method provided in the embodiment of the present application can be applied to any electronic device that has the ability to draw a window and allocate a buffer to a rendering thread for drawing a window. The electronic device can be an electronic device with display hardware and corresponding software support. For example, the electronic device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a household device, etc. The present application does not impose any restrictions on the specific type of the electronic device.

[0069] In a possible embodiment, in order to more clearly describe the electronic device provided by the embodiment of the present application, a possible application scenario of the electronic device provided by the embodiment of the present application is exemplarily described below. It can be understood that the following example is only a possible application scenario of the electronic device provided by the embodiment of the present application. In other possible embodiments, the electronic device provided by the embodiment of the present application can also be applied to other possible application scenarios, and the following example does not impose any limitation on this.

[0070] The buffer allocation method provided in the embodiment of the present application is applicable to application scenarios in which an application system of an electronic device opens a new window, for example, when a user selects a request for a browser application in the application system of the electronic device, and the browser application responds by popping up a browser homepage window, or when a user opens a new web page in the browser application, and the browser application pops up a new window corresponding to the new web page.

[0071] like Figure 1-1 As shown, Figure 1-1 An example diagram of an application scenario of a buffer allocation method provided by an embodiment of the present application is shown. When a user operates an electronic device, the application system of the electronic device needs to open a new window in response to the user's operation, that is, a new window needs to be drawn in the application system. At this time, a buffer is allocated for the drawing task of the new window so that the task of drawing the new window is implemented in the allocated buffer.

[0072] It should be understood that the above is an example of a scenario and does not limit the scenario of the present application.

[0073] like Figure 1-2As shown, an example diagram of a method flow for allocating a buffer in a related technology is provided. When the application system of the electronic device is an Android system (Android system, an operating system), when an application or activity is started, a new window (Window) is created for the started project, and a memory buffer is allocated for the surface corresponding to the new window in a new thread. Specifically, the application main thread calls the performTraversals() function of the ViewRootImpl class, calls the allocateBuffers() function of the HardwareRenderer class and the Android_view_ThreadedRenderer_allocateBuffers() function of the Android_graphics_HardwareRenderer class when the window is opaque, and calls the allocateBuffers() function of the RenderProxy class, posts the work of allocating the buffer to the work queue of the rendering thread RenerThread, calls the allocateBuffers() function of the CanvasContext class and the ANativeWindow_tryAllocateButters function of the AnativeWindow class in the rendering thread, and calls the allocateBuffers() function of the BBQSurface class, creates a new thread with the same name, and executes allocateBuffers() in the new thread, that is, calls the allocateBuffers() function of the BufferQueueProducer class in the newly created RenerThread thread.

[0074] like Figure 1-3 As shown, an example diagram of a trace of allocated buffers in a related technology is provided. The buffer allocation function is executed in a new thread created for allocating the buffer. When the system is under high load, the new thread where the allocated buffer is located cannot be scheduled, a large number of Runnable states appear, and the buffer allocation is incomplete (delayed). The rendering thread (RenerThread) cannot execute the window drawing task (blocking the DrawFrame process) because the corresponding buffer is not allocated. The rendering thread is blocked in the waitWhileAllocatingLocked() function (waiting function when allocating the lock) and enters the sleeping state.

[0075] In view of this, an embodiment of the present application provides a buffer allocation method to improve the efficiency of buffer allocation, reduce the probability of rendering thread blocking, reduce the time consumption of loading new windows, and improve the responsiveness of the application system.

[0076] The implementation of the embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0077] First, in a first aspect of an embodiment of the present application, an electronic device is provided, such as Figure 2 As shown, including:

[0078] Memory 201, used for storing computer programs;

[0079] The processor 202 is used to execute the program stored in the memory 201, and implements the following steps:

[0080] When you need to allocate a buffer for a window drawing task, get the current system load;

[0081] When the current system load exceeds a preset load threshold, the buffer allocation function of the buffer queue generator class is serially called in the rendering thread, and a buffer is allocated for the window drawing task through the buffer allocation function.

[0082] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 202, the communication interface, and the memory 201 communicate with each other via the communication bus.

[0083] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0084] The communication interface is used for communication between the above electronic device and other devices.

[0085] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0086] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0087] For ease of explanation, a mobile phone is used as an example of an electronic device.

[0088] like Figure 3 As shown, in some embodiments, the electronic device 300 may include a processor 301 and a communication module 302 .

[0089] The processor 301 and Figure 2 The processor 202 may be the same as the processor 201, and may include one or more processing units. For example, the processor 301 may include an application processor (AP), a modem processor, a graphics processor, an image signal processor (ISP), a controller, a memory, a video stream codec, a digital signal processor, a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or may be integrated in one or more processors 301.

[0090] The controller may be the nerve center and command center of the electronic device 300. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0091] The processor 301 may also be provided with a memory for storing instructions and data.

[0092] In some embodiments, the memory in the processor 301 is a cache memory. The memory can store instructions or data that the processor 301 has just used or cyclically used. If the processor 301 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 301, and thus improves the efficiency of the system.

[0093] In some embodiments, the processor 301 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0094] The communication module 302 may include an antenna 1, an antenna 2, a mobile communication module, and / or a wireless communication module.

[0095] like Figure 3 As shown, in some embodiments, the electronic device 300 may also include an external memory interface 305, an internal memory 304, a USB interface 306, a charging management module 307, a power management module 308, a battery 309, and a sensor module 303, etc.

[0096] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 300 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0097] The charging management module 307 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.

[0098] In some wired charging embodiments, the charging management module 307 may receive charging input from a wired charger through the USB interface 306 .

[0099] In some wireless charging embodiments, the charging management module 307 may receive wireless charging input via a wireless charging coil of the electronic device 300. While the charging management module 307 is charging the battery 309, it may also provide power to the electronic device 300 via the power management module 308.

[0100] The power management module 308 is used to connect the battery 309, the charging management module 307 and the processor 301. The power management module 308 receives input from the battery 309 and / or the charging management module 307, and supplies power to the processor 301, the internal memory 304, the external memory, and the communication module 302. The power management module 308 can also be used to monitor parameters such as battery capacity, battery cycle number, and battery health status (leakage, impedance).

[0101] In some other embodiments, the power management module 308 may also be disposed in the processor 301 .

[0102] In other embodiments, the power management module 308 and the charging management module 307 may also be disposed in the same device.

[0103] The external memory interface 305 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 300. The external memory card communicates with the processor 301 through the external memory interface 305 to implement a data storage function. For example, files such as music and video streams are stored in the external memory card.

[0104] The internal memory 304 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 301 executes various functional applications and data processing of the electronic device 300 by running the instructions stored in the internal memory 304. The internal memory 304 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 300 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 304 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0105] The sensor module 303 in the electronic device 300 may include image sensors, touch sensors, pressure sensors, gyroscope sensors, air pressure sensors, magnetic sensors, acceleration sensors, distance sensors, proximity light sensors, ambient light sensors, fingerprint sensors, temperature sensors, bone conduction sensors and other components to realize the sensing and / or acquisition functions of different signals.

[0106] Optionally, the electronic device 300 may further include peripheral devices, such as a mouse, buttons, indicator lights, a keyboard, a speaker, a microphone, etc.

[0107] The buttons include a power button, a volume button, etc. The buttons may be mechanical buttons or touch buttons. The electronic device 300 may receive button inputs and generate key signal inputs related to user settings and function control of the electronic device 300.

[0108] The indicator may be a light indicator, which may be used to indicate the charging status and the change in the power level, and may also be used to indicate messages, missed calls, and notifications, etc.

[0109] It can be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 300 .

[0110] In other embodiments, the electronic device 300 may include more or fewer components than shown, or combine some components, or separate some components, or arrange the components differently. The components shown may be implemented in hardware, software, or a combination of software and hardware.

[0111] In electronic devices, the software system can be divided into several layers, such as Figure 4 As shown, Figure 4 A software structure block diagram of an electronic device provided in an embodiment of the present application. The system architecture of the electronic device includes a kernel part, a framework layer part and an application layer part; the kernel part includes a driver layer and a real-time operating system, and the driver layer includes a GPU (graphics processor), a display driver (specifically an LCD driver in the figure), a TP driver (touch screen driver), buttons, etc.; the real-time operating system includes interrupt management, task scheduling, MEM (memory management), etc.; the framework layer includes: basic system capabilities, underlying software services, hardware service capabilities, etc.; the application layer includes: weather applications, video applications, input method applications, call applications, etc. Most applications need to create windows during use, and the process of creating windows requires the allocation of hardware resources through the framework layer and the kernel layer, such as the allocation of buffers, etc.

[0112] In order to solve the technical problem of low buffer allocation efficiency, the second aspect of the embodiment of the present application is as follows: Figure 5 As shown, Figure 5 A schematic flow chart of a first buffer allocation method provided in an embodiment of the present application includes:

[0113] Step S101, when a buffer needs to be allocated for a window drawing task, the current system load is obtained.

[0114] A window drawing task is a task created when a new window needs to be created and used to draw the new window. The execution of the window drawing task needs to be implemented based on the memory buffer allocated for it. For example, in the Android system, when a new window (Window) is created, a memory buffer needs to be allocated for the Surface corresponding to the Window to realize the drawing and creation of the Window.

[0115] When a buffer needs to be allocated for a window drawing task, the current system load is obtained. The current system load represents the current workload of the application system. A processing method that is more suitable for subsequent buffer allocation is selected based on the current system load.

[0116] Step S102, when the current system load exceeds a preset load threshold, serially calling the allocate buffer function of the buffer queue generator class in the rendering thread, and allocating a buffer for the window drawing task through the allocate buffer function.

[0117] When the current system load exceeds the preset load threshold, it means that the current system workload is too high. For the rendering thread and the new thread used to allocate the buffer, the current system can only schedule the rendering thread according to the priority, and the new thread cannot be scheduled temporarily. Therefore, the work of allocating the buffer is put into the rendering thread, and the buffer allocation function of the buffer queue generator is called serially (the allocateBuffers() function of the execution class BufferQueueProducer is used to allocate the memory buffer for the window drawing task.

[0118] The preset load threshold is a preset critical value of the system load. When the threshold is exceeded, it means that the current system load is too high and the new thread for allocating the buffer and the rendering thread for drawing the window cannot be executed in parallel.

[0119] In one embodiment of the present application, after allocating a buffer for the window drawing task by the buffer allocation function, the method further includes:

[0120] The window drawing task is executed in the rendering thread based on the allocated buffer, and the window corresponding to the window creation task is drawn.

[0121] The window drawing task has always existed in the rendering thread. As mentioned above, when the system load is too high and the buffer cannot be allocated, the rendering thread cannot execute the window drawing task due to the lack of a corresponding buffer, and the rendering thread will enter a dormant state. In an embodiment of the present application, when the current system load is too high, the execution priority of the rendering thread is used to put the work of allocating the buffer into the rendering thread before the window drawing task, and the buffer allocation function of the buffer queue generator class is serially called in the rendering thread to allocate the buffer for the window drawing task. After the buffer is allocated, the window drawing task is also executed in the rendering thread based on the allocated buffer to draw the required window.

[0122] The buffer allocation method provided in the embodiment of the present application utilizes the execution priority of the rendering thread to serially call the buffer allocation function of the buffer queue generator class when the current system load is high, allocates a buffer for the window drawing task, avoids the rendering thread from entering a dormant state, and enables the window drawing task to obtain the required buffer in a timely manner. Based on this, the required window is drawn in a timely manner, reducing the time spent on loading a new window, thereby improving the responsiveness of the application system.

[0123] The buffer allocation method provided in the embodiment of the present application obtains the current system load when a buffer needs to be allocated for a window drawing task. When the current system load exceeds a preset load threshold, the buffer allocation function of the buffer queue generator class is serially called in the rendering thread, and the buffer is allocated for the window drawing task through the buffer allocation function. Since the rendering thread has a higher execution priority and can be scheduled more timely, when the system load is high, compared with the solution of creating a new thread to allocate a buffer in the related art, the solution of the embodiment of the present application can complete the call of the buffer allocation function more timely, allocate a buffer for the window drawing task in time, improve the efficiency of buffer allocation, reduce the blocking probability of the rendering thread, and will not block the progress of window drawing in the rendering thread for a long time, but also save the time and memory overhead of creating a new thread, thereby improving the utilization rate of the application system.

[0124] In one embodiment of the present application, Figure 6 As shown, a flow chart of a second buffer allocation method is provided, which includes, before the above step S101 of obtaining the current system load, the following steps:

[0125] Step S201, obtaining a window creation task.

[0126] Step S202: When the window corresponding to the window creation task is opaque, create a window drawing task.

[0127] A window creation task is an execution task established when the application system starts an application or activity and needs to open a corresponding new window. For example, when the application system starts a new application, it needs to open the window corresponding to the application. At this time, the window creation task is to create a new window corresponding to the application. For example, when an input method application is started in the application system to make the input method keyboard pop up, it is necessary to open the new window where the input method keyboard is located, and a window creation task corresponding to the window where the input method keyboard is located is established; when an application running in the application system starts a new activity, it is necessary to open a new window corresponding to the activity. At this time, the window creation task is to create a window corresponding to the application. For example, when a browser application running in the application system starts a new web page, it is necessary to open a new window corresponding to the web page, and a window creation task corresponding to the window where the new web page is located is established.

[0128] In one example, when the new window is a transparent window, it means that there is no need to draw a completely new window, and it is only necessary to display the specific content of the new window in the current window. For example, when a browser application running in the application system starts a new web page, the window of the new web page is transparent. It can be understood that the window layout of the new web page is consistent with the window where the web page opened by the current browser application is located. There is no need to draw a new window for it, and the new web page can be displayed in the current window.

[0129] When the new window is opaque, it means that it needs to be drawn. For example, when starting an input method application in the application system to make the input method keyboard pop up, the new window where the input method keyboard is located needs to be drawn. In this case, a window drawing task for the new window is created. Specifically, the window drawing task is created in the rendering thread.

[0130] The buffer allocation method provided in the embodiment of the present application creates a window drawing task in the rendering process when the window corresponding to the window creation task is opaque, so that the rendering thread draws the required new window, thereby realizing timely creation of windows in the application system.

[0131] In one embodiment of the present application, Figure 7 As shown, the above step S202 creates a window drawing task when the window corresponding to the window creation task is opaque, including:

[0132] Step S301, based on the window creation task, calling the execution starting point function of the view viewing root class;

[0133] Step S302, determining whether the window corresponding to the window creation task is transparent by executing a starting point function;

[0134] Step S303, when the window is opaque, calling the allocation buffer function of the hardware renderer class;

[0135] Step S304, calling the allocate buffer function of the rendering proxy class through the allocate buffer function of the hardware renderer class;

[0136] Step S305: creating the window drawing task in the rendering thread through the allocation buffer function of the rendering proxy class.

[0137] The window creation task is located in the main thread of the application system. When there is a window creation task, the execution starting point function of the view root class (performTraversals() function of class ViewRootImpl) is first called in the main thread of the application. In this function, it is determined whether the newly created window is transparent. When the window is opaque, the buffer allocation function of the hardware renderer class (allocateBuffers() function of class HardwareRenderer) is called to allocate a buffer for the Surface corresponding to the window. The buffer allocation function of the hardware renderer class is called to the buffer allocation function of the rendering proxy class (allocateBuffers() function of class RenderProxy), and the corresponding window drawing task is created (Posted to the RenerThread work queue) in the work queue of the rendering thread (RenerThread).

[0138] The buffer allocation method provided in the embodiment of the present application executes the window creation task in the main thread of the application, executes the early process of the window creation task in the main thread of the application, and only executes the window drawing task in the rendering thread, thereby improving the efficiency of window creation.

[0139] In one embodiment of the present application, the serially calling the allocation buffer function of the buffer queue generator class in the rendering thread includes:

[0140] After the rendering thread calls the allocate buffer function of the buffer queue class, the render thread is used to call the allocate buffer function of the buffer queue generator class.

[0141] In one embodiment of the present application, before serially calling the buffer allocation function of the buffer queue generator class in the rendering thread and allocating a buffer for the window drawing task through the buffer allocation function, the method further includes:

[0142] Determining whether the current system load exceeds a preset load threshold by using the buffer allocation function of the buffer queue class;

[0143] The method further comprises:

[0144] Step 1: when it is determined that the current system load does not exceed a preset load threshold, create a buffer allocation thread executed in parallel with the rendering thread through the buffer allocation function of the buffer queue class;

[0145] Step 2: calling the buffer allocation function of the buffer queue generator class in the allocation thread, and allocating a buffer for the window drawing task through the buffer allocation function.

[0146] The buffer allocation function of the buffer queue class (allocateBuffers() function of the BufferQueueProducer (BBQSurface) class) is the upper function of the buffer allocation function of the buffer queue generator class.

[0147] The main thread of the application calls the execution start function of the view root class all the way to the allocation buffer function of the rendering proxy class, and then creates a window drawing task in the rendering thread. After the window drawing task is created, the allocation buffer function of the buffer queue class is called in the rendering thread, at which time it is determined whether the current system load exceeds the preset load threshold.

[0148] If it exceeds, the buffer allocation function of the buffer queue class directly calls the buffer allocation function of the buffer queue generator class in the rendering thread in series. After allocating the buffer for the window drawing task, the rendering thread continues to execute the window drawing task in series based on the buffer.

[0149] If it does not exceed, it means that the current system load still has room to execute two threads in parallel, then the buffer allocation function of the buffer queue class creates a buffer allocation thread that is executed in parallel with the rendering thread, and calls the buffer allocation function of the buffer queue generator class in the buffer thread to allocate a buffer for the window drawing task. The rendering thread executes the window drawing task based on the buffer in parallel and draws the corresponding window.

[0150] It should be emphasized that the above-mentioned calling of the execution starting point function of the view root class, the process of determining whether the window corresponding to the window creation task is transparent, the calling of the allocation buffer function of the hardware renderer class, the calling of the allocation buffer function of the rendering proxy class, and the creation of the window drawing task in the rendering thread are all executed in the main thread of the application system. The calling of the allocation buffer function of the buffer queue class and the determination of whether the current system load exceeds the preset load threshold are all executed in the rendering thread.

[0151] If the current system load exceeds the preset load threshold, the call of the buffer allocation function of the buffer queue generator class is executed in the rendering thread. If the current system load does not exceed the preset load threshold, the call of the buffer allocation function of the buffer queue generator class is executed in the newly created thread, namely the buffer allocation thread.

[0152] In one example, the buffer allocation thread and the rendering thread are actually named the same, both RenerThread.

[0153] The buffer allocation method provided in the embodiment of the present application serially executes buffer allocation and buffer-based window drawing in the rendering thread when the current system load is too high, and utilizes the time period in which the rendering thread in the related technology enters a dormant state due to the inability to allocate a buffer to execute buffer allocation, thereby improving the efficiency of buffer allocation, and then improving the execution efficiency of window drawing tasks and window creation tasks, reducing the blocking of the rendering thread as much as possible, and improving the fluency of the application main thread and even the system; when the current system load is low, the buffer allocation thread and the rendering thread are executed in parallel, and the overall execution efficiency of the window drawing tasks and window creation tasks is improved as much as possible, thereby improving the fluency of the application main thread and even the system, and improving the utilization rate of the application system.

[0154] like Figure 8-1 As shown, an embodiment of the present application provides an example diagram of the implementation process of a buffer allocation method. Figure 8-2 An example diagram of a trace tracking implementation of a buffer allocation method provided in an embodiment of the present application, through Figure 8-1 The buffer allocation method shown enables the rendering thread to execute smoothly. It can be seen that the buffer allocation method provided by the embodiment of the present application avoids the rendering thread from entering a dormant state, but instead utilizes the time when the rendering thread enters a dormant state in the related art to serially execute the buffer allocation, thereby improving the efficiency of the buffer allocation.

[0155] Second, as Fig. 9 As shown, an embodiment of the present application provides a schematic diagram of the structure of a buffer allocation device, the device comprising:

[0156] The system load acquisition module 401 is used to acquire the current system load when a buffer needs to be allocated for a window drawing task;

[0157] The first buffer allocation module 402 is used to serially call the buffer allocation function of the buffer queue generator class in the rendering thread when the current system load exceeds a preset load threshold, and allocate a buffer for the window drawing task through the buffer allocation function.

[0158] The buffer allocation device provided in the embodiment of the present application obtains the current system load when it is necessary to allocate a buffer for a window drawing task. When the current system load exceeds the preset load threshold, the buffer allocation function of the buffer queue generator class is serially called in the rendering thread, and the buffer is allocated for the window drawing task through the buffer allocation function. Since the rendering thread has a higher execution priority and can be scheduled more timely, when the system load is high, compared with the solution of creating a new thread to allocate a buffer in the related art, the solution of the embodiment of the present application can complete the call of the buffer allocation function more timely, allocate a buffer for the window drawing task in time, improve the efficiency of buffer allocation, reduce the blocking probability of the rendering thread, and will not block the progress of window drawing in the rendering thread for a long time, and also save the time and memory overhead of creating a new thread.

[0159] In one embodiment of the present application, the device further includes:

[0160] A first task creation module, used to obtain a window creation task;

[0161] The second task creation module is used to create a window drawing task when the window corresponding to the window creation task is opaque.

[0162] The buffer allocation device provided in the embodiment of the present application creates a window drawing task in the rendering process when the window corresponding to the window creation task is opaque, so that the rendering thread draws the required new window, thereby realizing timely creation of windows in the application system.

[0163] In one embodiment of the present application, the second task creation module is specifically used to:

[0164] Based on the window creation task, call the execution starting point function of the view root class;

[0165] Determining whether the window corresponding to the window creation task is transparent by the execution starting point function;

[0166] In the case where the window is opaque, calling a buffer allocation function of the hardware renderer class;

[0167] Calling the buffer allocation function of the rendering proxy class through the buffer allocation function of the hardware renderer class;

[0168] The window drawing task is created in the rendering thread through the buffer allocation function of the rendering proxy class.

[0169] The buffer allocation device provided in the embodiment of the present application executes the window creation task in the main thread of the application, executes the early process of the window creation task in the main thread of the application, and only executes the window drawing task in the rendering thread, thereby improving the efficiency of window creation.

[0170] In one embodiment of the present application, the first buffer allocation module 402 is specifically configured to:

[0171] After the rendering thread calls the allocate buffer function of the buffer queue class, the render thread is used to call the allocate buffer function of the buffer queue generator class.

[0172] In one embodiment of the present application, the device further includes:

[0173] A system load determination module, configured to determine whether the current system load exceeds a preset load threshold through the buffer allocation function of the buffer queue class;

[0174] The device also includes:

[0175] A thread creation module, configured to create a buffer allocation thread executed in parallel with the rendering thread through the buffer allocation function of the buffer queue class when it is determined that the current system load does not exceed a preset load threshold;

[0176] The second buffer allocation module is used to call the buffer allocation function of the buffer queue generator class in the allocation thread, and allocate a buffer for the window drawing task through the buffer allocation function.

[0177] The buffer allocation device provided in the embodiment of the present application serially executes buffer allocation and buffer-based window drawing in the rendering thread when the current system load is too high, and utilizes the time period in which the rendering thread in the related technology enters a dormant state due to the inability to allocate a buffer to execute buffer allocation, thereby improving the efficiency of buffer allocation, and then improving the execution efficiency of window drawing tasks and window creation tasks, reducing the blocking of the rendering thread as much as possible, and improving the fluency of the application main thread and even the system; when the current system load is low, the buffer allocation thread and the rendering thread are executed in parallel, further improving the overall execution efficiency of the window drawing tasks and window creation tasks as much as possible, thereby improving the fluency of the application main thread and even the system.

[0178] In one embodiment of the present application, the device further includes:

[0179] The window drawing module is used to execute the window drawing task based on the allocated buffer in the rendering thread, and draw the window corresponding to the window creation task.

[0180] The buffer allocation device provided in the embodiment of the present application utilizes the execution priority of the rendering thread to serially call the buffer allocation function of the buffer queue generator class when the current system load is high, allocates a buffer for the window drawing task, avoids the rendering thread from entering a dormant state, and enables the window drawing task to obtain the required buffer in a timely manner. Based on this, the required window is drawn in a timely manner, reducing the time consumed in loading a new window, thereby improving the responsiveness of the application system.

[0181] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above buffer allocation methods are implemented.

[0182] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any buffer allocation method in the above embodiments.

[0183] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0184] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0185] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and electronic device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0186] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A buffer allocation method, characterized in that: The method comprises: Get the window creation task; Create a task based on the window and call the execution starting point function of the view root class; Determining whether the window corresponding to the window creation task is transparent by executing the starting point function; In the case where the window is opaque, calling the allocation buffer function of the hardware renderer class; Calling the allocation buffer function of the rendering proxy class through the allocation buffer function of the hardware renderer class; Creating a window drawing task in the rendering thread through the buffer allocation function of the rendering proxy class; When you need to allocate a buffer for a window drawing task, get the current system load; When the current system load exceeds a preset load threshold, the allocate buffer function of the buffer queue builder class is serially called in the rendering thread, and a buffer is allocated for the window drawing task through the allocate buffer function of the buffer queue builder class.

2. The method according to claim 1, characterized in that The buffer allocation function of the buffer queue generator class is serially called in the rendering thread, including: After the rendering thread calls the allocate buffer function of the buffer queue class, the rendering thread is used to call the allocate buffer function of the buffer queue generator class.

3. The method according to claim 1, characterized in that Before serially calling the buffer allocation function of the buffer queue builder class in the rendering thread and allocating a buffer for the window drawing task through the buffer allocation function of the buffer queue builder class, the method further includes: Determine whether the current system load exceeds a preset load threshold by using the buffer allocation function of the buffer queue class; The method further comprises: When it is determined that the current system load does not exceed a preset load threshold, creating a buffer allocation thread executed in parallel with the rendering thread through the allocate buffer function of the buffer queue class; The buffer allocation function of the buffer queue builder class is called in the allocation thread, and a buffer is allocated for the window drawing task through the buffer allocation function of the buffer queue builder class.

4. The method according to any one of claims 1 to 3, characterized in that After allocating a buffer for the window drawing task through the buffer allocation function of the buffer queue builder class, the method further includes: The window drawing task is executed in the rendering thread based on the allocated buffer, and the window corresponding to the window creation task is drawn.

5. A buffer allocation device, characterized in that: The device comprises: A first task creation module is used to obtain a window creation task; A second task creation module is configured to call an execution start point function of a view view root class based on the window creation task; determine whether the window corresponding to the window creation task is transparent through the execution start point function; if the window is not transparent, call an allocate buffer function of a hardware renderer class; call an allocate buffer function of a rendering proxy class through the allocate buffer function of the hardware renderer class; and create a window drawing task in a rendering thread through the allocate buffer function of the rendering proxy class; The system load acquisition module is used to obtain the current system load when a buffer needs to be allocated for a window drawing task; The first buffer allocation module is used to serially call the buffer allocation function of the buffer queue builder class in the rendering thread when the current system load exceeds a preset load threshold, and allocate a buffer for the window drawing task through the buffer allocation function of the buffer queue builder class.

6. An electronic device, characterized in that: include: one or more processors and memory; The memory is coupled to the one or more processors, and the memory is used to store computer program code, where the computer program code includes computer instructions. The one or more processors call the computer instructions to enable the electronic device to execute the method according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that The method comprises a computer program, which, when running on an electronic device, causes the electronic device to perform the method according to any one of claims 1 to 4.