A frame data writing and reading method based on shared memory

By creating shared memory region groups in the game and using active buffer numbers and frame count information, the memory bandwidth consumption and latency issues of cross-process frame data transmission are resolved, achieving stable and efficient frame data transmission and multi-instance concurrency.

CN123137964APending Publication Date: 2026-11-20GUANGZHOU BOGUAN TELECOMM TECH LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611367825.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-03
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

During game operation, cross-process frame data transmission suffers from high memory bandwidth consumption and unstable transmission latency due to system scheduling issues.

Method used

A shared memory-based frame data writing and reading method is adopted. By creating a named shared memory region group, including a metadata area, a first frame data area, and a second frame data area, physical isolation between writing and reading is achieved using active buffer numbers and frame count information, reducing system calls and dependence on the response speed of the reading end.

Benefits of technology

It improves the stability of cross-process frame transmission, reduces write operation being blocked by read and read operation being written, optimizes polling overhead, and supports multi-instance concurrent operation without interference.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137964A_ABST
    Figure CN123137964A_ABST
Patent Text Reader

Abstract

The disclosure provides a shared memory-based frame data writing and reading method, and relates to the technical field of rendering. The method comprises the following steps: in response to a creation request of a browser instance, creating a named shared memory area group corresponding to the browser instance; in response to current frame pixel data generated by off-screen rendering, reading an active buffer number stored in the meta information area, determining a non-active one of the first frame data area or the second frame data area as a writing target according to the active buffer number; writing the current frame pixel data into the frame data area corresponding to the writing target; after the writing is completed, updating the active buffer number stored in the meta information area, so that the writing target becomes a new active buffer; and updating frame count information stored in the meta information area, wherein the frame count information is used for the reading end to determine whether a new frame arrives.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of rendering technology, and more specifically, to a method for writing and reading frame data based on shared memory. Background Technology

[0002] With the rapid development of internet technology and the continuous improvement of terminal device performance, video games have become an indispensable form of entertainment in people's daily lives. Players' demands for game graphics quality, smooth interaction, and fast content updates are constantly increasing, driving the continuous evolution of game development technology.

[0003] During game operation, in addition to rendering native 3D scenes, developers often need to embed dynamic web content into the game interface to improve operational flexibility and user experience. These scenarios typically involve frame data transmission between the writing end and the game rendering process.

[0004] Related technologies suffer from problems such as high memory bandwidth consumption and unstable transmission latency due to system scheduling issues during cross-process frame transmission. Summary of the Invention

[0005] The purpose of this disclosure is to address the shortcomings of the prior art by providing a shared memory-based method for writing and reading frame data, thereby improving the stability of cross-process frame transmission.

[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this disclosure are as follows: In a first aspect, one embodiment of this disclosure provides a frame data writing method based on shared memory, applied at the writing end, the method comprising: In response to a browser instance creation request, a named shared memory region group corresponding to the browser instance is created; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, the first frame data area and the second frame data area being used for reading by the reading end; In response to the current frame pixel data generated by off-screen rendering, the active buffer number stored in the metadata area is read, and the inactive buffer in the first frame data area or the second frame data area is determined as the writing target based on the active buffer number. Write the current frame pixel data into the frame data area corresponding to the writing target; After the write operation is completed, the active buffer number stored in the metadata area is updated to make the write target a new active buffer. The frame count information stored in the metadata area is updated. The frame count information is used by the reading end to determine whether a new frame has arrived.

[0007] Secondly, one embodiment of this disclosure provides a frame data reading method based on shared memory, applied at a reading end, the method comprising: Obtain the identification information of the browser instance, and map the browser instance to a named shared memory region group corresponding to the browser instance through the cross-process memory sharing mechanism provided by the operating system based on the identification information; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are written by the writing end; Obtain the frame count information stored in the metadata area, and determine whether a new frame has arrived based on the frame count information; When a new frame is detected to have arrived, the reading target is determined in the first frame data area or the second frame data area according to the currently stored active buffer number in the metadata area. Pixel data is obtained from the frame data area corresponding to the target being read, and the pixel data is uploaded to the texture object of the graphics processor.

[0008] Thirdly, another embodiment of this disclosure provides a frame data writing apparatus based on shared memory, the apparatus comprising: a creation module, a first reading module, a writing module, and an update module, wherein: The creation module is used to create a named shared memory region group corresponding to the browser instance in response to the browser instance creation request; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are used for reading by the reading end; The first reading module is used to read the active buffer number stored in the metadata area in response to the current frame pixel data generated by off-screen rendering, and determine the inactive buffer in the first frame data area or the second frame data area as the writing target based on the active buffer number. The writing module is used to write the current frame pixel data into the frame data area corresponding to the writing target; The update module is used to update the active buffer number stored in the metadata area after the write is completed, so that the write target becomes the new active buffer; and to update the frame count information stored in the metadata area, the frame count information being used by the reading end to determine whether a new frame has arrived.

[0009] Fourthly, another embodiment of this disclosure provides a frame data reading device based on shared memory, the device comprising: an acquisition module, a determination module, a second reading module, and an upload module, wherein: The acquisition module is used to acquire the identification information of the browser instance, and based on the identification information, map the named shared memory region group corresponding to the browser instance through the cross-process memory sharing mechanism provided by the operating system; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are written by the writing end; The determination module is used to obtain the frame count information stored in the metadata area and determine whether a new frame has arrived based on the frame count information. The second reading module is used to determine the reading target in the first frame data area or the second frame data area according to the currently stored active buffer number in the metadata area when it is determined that a new frame has arrived. The upload module is used to obtain pixel data from the frame data area corresponding to the reading target and upload the pixel data to the texture object of the graphics processor.

[0010] Fifthly, another embodiment of this disclosure provides a computer device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor communicates with the memory via the bus, and the processor executes the machine-readable instructions to perform the steps of the method as described in either the first or second aspect above.

[0011] In a sixth aspect, another embodiment of this disclosure provides a storage medium storing a computer program, which, when executed by a processor, performs the steps of the method as described in either the first or second aspect above.

[0012] The beneficial effects of this disclosure are as follows: By creating a named shared memory region group in response to the browser instance creation request, a dedicated cross-process transmission channel is pre-established for subsequent frame writing, eliminating the need for repeated system calls for each frame write. Furthermore, each browser instance has an independent shared memory region group, ensuring data isolation and non-interference among multiple instances running simultaneously. Secondly, by determining inactive buffers as writing targets by reading the active buffer number in the metadata area, the write operation and the read operation on the reading end always operate on different shared memory regions, achieving physical isolation between write and read operations. This prevents write operations from being blocked by reads and read operations from being delayed by writes. Moreover, by updating the active buffer number in the metadata area only once after pixel data writing is complete, the switching process is independent of the reader's response speed or current load, and the write cycle is unaffected by the read-side state. Finally, by updating the frame count information in the metadata area, the reading end can quickly make a judgment without accessing a large block of frame data area when there are no new frames, thus optimizing the polling overhead. Furthermore, the frame count information exists independently of the active buffer number. Even if the reading end performs new writes and switches after reading the frame count information and before actually accessing the frame data area, the reading end can still perceive the existence of intermediate frames by comparing the frame count information, providing a basis for judgment for subsequent frame processing logic. Attached Figure Description

[0013] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this disclosure and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0014] Figure 1 A flowchart illustrating a shared memory-based frame data writing method according to an embodiment of this disclosure is shown. Figure 2 A flowchart illustrating a shared memory-based frame data writing method according to another embodiment of this disclosure is shown. Figure 3 A flowchart illustrating a shared memory-based frame data reading method according to an embodiment of this disclosure is shown. Figure 4 A flowchart illustrating a shared memory-based frame data reading method according to another embodiment of this disclosure is shown. Figure 5 A schematic diagram of the process for obtaining frame count information in one embodiment of this disclosure is shown; Figure 6 A flowchart illustrating a shared memory-based frame data read / write method according to an embodiment of this disclosure is shown. Figure 7 A flowchart illustrating a shared memory-based frame data read / write method according to another embodiment of this disclosure is shown. Figure 8 A schematic diagram of a shared memory-based frame data writing device provided in an embodiment of this disclosure is shown. Figure 9 A schematic diagram of the structure of a frame data reading device based on shared memory provided in an embodiment of this disclosure is shown; Figure 10 A schematic diagram of the structure of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation

[0015] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this disclosure are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this disclosure. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this disclosure illustrate operations implemented according to some embodiments of this disclosure. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this disclosure, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.

[0016] Furthermore, the described embodiments are merely some, not all, of the embodiments of this disclosure. The components of the embodiments of this disclosure typically described and illustrated in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the drawings is not intended to limit the scope of the claimed disclosure, but merely to illustrate selected embodiments of the disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0017] It should be noted that the term "comprising" will be used in the embodiments of this disclosure to indicate the presence of the features subsequently declared, but does not exclude the addition of other features.

[0018] The shared memory-based frame data writing method disclosed herein is mainly applied to scenarios where H5 pages are rendered by a web rendering engine (such as Electron), and each frame of the rendered image is transmitted in real time to a game engine (such as NeoX) process to display dynamic web page content in the form of textures in the game scene.

[0019] Specifically, the methods disclosed herein are applicable to embedding H5 e-commerce pages in massively multiplayer online games, allowing players to browse and purchase goods without leaving the game; or embedding activity pages (such as sign-in, lottery, season pass) within the game to achieve dynamic updates and rapid launch of operational content; displaying real-time data panels (such as leaderboards, battle statistics, and trading information) developed using Web technologies in the game, utilizing the rich layout and animation capabilities of HTML5 to present complex data visualizations; or embedding H5 promotional videos or interactive onboarding pages in the game login interface or lobby to rapidly iterate content using the Web front-end ecosystem.

[0020] Furthermore, the method provided in this disclosure can also be extended to various hybrid architecture scenarios in desktop applications that require embedding web content into native 3D rendering scenes, such as real-time data dashboard overlay in digital twin systems, web control panel embedding in industrial simulation software, and browser content projection in virtual reality / augmented reality applications, especially high-performance interactive scenarios that are sensitive to frame transmission latency and require that the game or main rendering loop not be blocked.

[0021] Figure 1 The diagram illustrates a flowchart of a shared memory-based frame data writing method according to an embodiment of this disclosure. Figure 2 This illustration shows a flowchart of a shared memory-based frame data writing method according to another embodiment of this disclosure, applied to the writing end, such as... Figure 1 As shown, the method includes steps 111-115, wherein: Step 111: The writer responds to the browser instance creation request and creates a named shared memory region group corresponding to the browser instance.

[0022] The writer is the producer of frame data. The writer can be a native addon in the Electron main process; or it can be a dedicated rendering process built on the Chromium Content API, a headless browser container, or any Web rendering engine module with off-screen rendering capabilities.

[0023] A named shared memory region group is a collection of shared memory regions created through the operating system kernel naming mechanism, accessible by name to multiple processes. In embodiments of this disclosure, the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, wherein the first frame data area and the second frame data area are used for reading by the reading end.

[0024] The reader is the consumer of frame data. In some embodiments, the reader can be a reading module in the game engine rendering thread; or it can be a dedicated reading thread independent of the game's main loop, a driver layer adapter module integrated into the game engine rendering pipeline, an independent rendering service process outside the game process, or any software module capable of reading data from shared memory and uploading textures to the graphics processing unit (GPU).

[0025] Among them, the metadata area (xy2_browser_share_<browser_tag> This is a shared memory area used to store control information, such as the active buffer number `current_render_target`, the effective pixel size of each buffer, frame count information `browser_render_count`, and the browser instance liveness flag `is_valid`. The metadata area is stored independently of the frame data area, preventing it from being evicted from the buffer during large-block pixel data copying and ensuring low latency access to control information.

[0026] First frame data area xy2_render_target_1_<browser_tag> Second frame data area xy2_render_target_2_<browser_tag> These are two independent, fixed-capacity shared memory areas, each used to store a complete frame of BGRA pixel data. One buffer in the first and second frame data areas is held by the reader (reader), which is either currently reading or ready to read. The other buffer is held by the writer (writer), which is either currently writing or has completed writing. Coordination between the two is achieved through atomic switching of the active buffer number `current_render_target` field. Physically isolated from each other, this eliminates the possibility of data contention at the hardware level, thus avoiding read-write conflicts.

[0027] As an example, the first frame data area is used to store the complete blue... green red Transparency (Blue) Green Red The first frame contains Alpha (BGRA) pixel data, with a capacity equal to the maximum resolution (e.g., 1920×1080×4 bytes); the second frame data area is used to store the complete BGRA pixel data.

[0028] A browser instance is an independent webpage rendering unit created on the writing end based on a request from the reading end, such as the BrowserWindow object in the Electron framework. Each browser instance has a unique identifier, browser_id, used to distinguish different HyperText Markup Language 5 (H5) pages opened simultaneously on the reading end, such as e-commerce pages, event pages, and login pages. The way each browser instance has its own independently named shared memory region group allows multiple H5 pages to be rendered simultaneously in the game, completely isolated from each other at the data level, without interference, thus supporting multi-instance concurrency.

[0029] In some embodiments, execution can be performed after the writer receives an open_browser request sent by the reader via a Thrift Remote Procedure Call (RPC). When the reader requests to open an H5 page, it includes parameters such as the page URL and the desired rendering resolution in the request. While creating the browser window object (BrowserWindow), the writer calls the create_browser_share interface of the native addon to execute step 111 above.

[0030] In the embodiments of this disclosure, a globally unique name string can be generated based on the identification information of the browser instance; and a metadata area, a first frame data area, and a second frame data area can be created based on the name string.

[0031] As an example, the writer can generate a globally unique name string (browser_tag) according to a predetermined rule based on the browser instance's identifier information (browser_id). Then, it concatenates the suffixes of each region, such as _share for the metadata region, and _target_1 and _target_2 for the frame data region, forming three complete shared memory names. This naming rule is pre-agreed upon by the writer and reader. Upon receiving the identifier information, the reader can map it to the same set of shared memory according to the same naming rule.

[0032] The metadata area, the first frame data area, and the second frame data area are three independent shared memory kernel objects. Each is created through a separate `CreateFileMapping` call, has its own kernel handle, and performs its own `MapViewOfFile` mapping of the file view to the process address space. This ensures that if an exception occurs in one of the frame data areas, normal reading and writing of the metadata area will not be affected. Furthermore, mapping and release operations can be performed separately, offering greater flexibility.

[0033] Step 112: In response to the current frame pixel data generated by off-screen rendering, the writing end reads the active buffer number stored in the metadata area and determines the inactive buffer in the first frame data area or the second frame data area as the writing target based on the active buffer number.

[0034] Off-screen rendering is a technique where the Chromium rendering engine draws the page in an invisible offscreen buffer. The output of off-screen rendering is a buffer of pixel data in memory, which is passed to the upper-layer application via Electron's onPaint callback. Off-screen rendering does not rely on a graphics processing unit (GPU) backend and outputs BGRA format pixel data accessible to the central processing unit (CPU).

[0035] The current frame pixel data is a complete pixel matrix generated by the Chromium off-screen rendering engine after drawing a single frame of the page. It is typically stored in BGRA four-channel format, with each pixel occupying 4 bytes. The current frame pixel data is provided to the writing end by the onPaint callback in the form of a pointer and size parameters (width, height).

[0036] The active buffer number is an integer value stored in the metadata area, taking the value 1 or 2. It indicates which frame data area is currently active, i.e., the area that the reader should currently read. The active buffer number is updated by the writer through an atomic operation after each frame is written. The reader determines which buffer to read data from by reading the active buffer number.

[0037] The inactive buffer is the portion of the first and second data frames that is not pointed to by the currently active buffer number. In the embodiments of this disclosure, if the active number is 1, the second data frame is inactive; if the active number is 2, the first data frame is inactive. The write end always writes to the inactive buffer, ensuring that the write target and the read target are always two different physical memory regions, thereby avoiding read-write conflicts. When the write end determines the write target, it only needs to rely on the active number in the metadata area, without querying the current state of the read end or waiting for the read end to complete the read, realizing the complete asynchronous nature of the write operation and ensuring that the write thread will not be blocked.

[0038] In some embodiments, if the read result is not within the valid set {1,2}, for example due to extreme race conditions or abnormal overwriting of shared memory, the writer processes it according to the default value 1, that is, the second frame data area is used as the write target. The above defensive handling method ensures that even in extreme abnormal situations, the write operation will not write to an illegal memory address and cause the process to crash.

[0039] In some embodiments, when a browser instance is created, the active buffer number (current_render_target) in the metadata area can be initialized to a default value, such as 1, meaning that the first frame data area is the active buffer by default. Of course, it can also be initialized to 2, and this disclosure does not impose any restrictions.

[0040] Step 113: The writing end writes the current frame pixel data into the frame data area corresponding to the writing target.

[0041] Writing is the process of copying pixel data from the Chromium off-screen rendering buffer to the target shared memory region via a memory copy (memcpy) operation. It is a memory-to-memory copy that occurs in user space, and subsequent data resides in the shared memory. When the reading end reads data, there is no need to perform another CPU-side copy, thereby reducing CPU memory bandwidth consumption.

[0042] If write_target = 1, it corresponds to the first frame data area; if write_target = 2, it corresponds to the second frame data area. The frame data area has already been mapped to the virtual address space of the writing end by mapping the file mapping view to the process address space (MapViewOfFile) during the creation stage. Therefore, it is only necessary to obtain the starting address pointer of this mapping to perform writing, thereby avoiding the overhead of performing system calls for each frame.

[0043] In some embodiments, after performing step 113, the writing end also writes the effective width and effective height of the current frame pixel data into the size information field corresponding to the writing target in the metadata area.

[0044] If the write target is the first frame data area, the effective width and effective height of the current frame pixel data are written to the render_1_width and render_1_height fields; if the write target is the second frame data area, the effective width and effective height of the current frame pixel data are written to the render_2_width and render_2_height fields. This ensures that when the write target is switched to a new active buffer, the reader can obtain the correct effective size of the current frame pixel data from the metadata area when reading the buffer, avoiding parsing errors caused by inconsistencies between the effective size of the pixel data and the fixed capacity of the buffer.

[0045] In some embodiments, after completing the pixel data writing and before switching the active buffer number, the writing end also writes the effective width and effective height of the current frame pixel data into the size information field corresponding to the writing target in the metadata area, so as to ensure that when the active buffer number is switched and the reading end reads the corresponding size information field according to the switched active buffer number, the size information read is consistent with the actual effective size of the pixel data.

[0046] In the embodiments of this disclosure, in order to ensure that the write does not access the shared memory out of bounds, before the current frame pixel data is written to the frame data area corresponding to the write target, capacity adaptation is required to determine whether the size of the current frame pixel data exceeds the capacity limit of the frame data area corresponding to the write target; if it exceeds, the size of the current frame pixel data is reduced until the size of the reduced current true pixel data does not exceed the capacity limit of the frame data area corresponding to the write target.

[0047] Step 114: After writing is completed, the writing end updates the active buffer number stored in the metadata area, making the writing target the new active buffer.

[0048] An update refers to modifying the value of the active buffer number field in the metadata area using atomic operations. Atomic operations ensure that the modification of the active buffer number field is indivisible, and the reading end will not read an illegal value that is in a half-updated state when reading this field at any time.

[0049] As an example, the active buffer number in the current metadata area is 1, meaning that data area 1 of the first frame is active. The writer writes the data of the Nth frame to the inactive area, i.e., the second frame data area, and after updating the size field, performs a switch operation to update the active buffer number to 2. At this point, the state of the metadata area is: active buffer number = 2, and the second frame data area stores the valid pixel data of the Nth frame. The reader reads the active buffer number = 2 in the next frame rendering loop, reads the data from the second frame data area, and uploads it to the GPU.

[0050] Step 115: The writing end updates the frame count information stored in the metadata area. The frame count information is used by the reading end to determine whether a new frame has arrived.

[0051] The frame count (browser_render_count) is a monotonically increasing integer value stored in the metadata area, incrementing by 1 each time a frame is written and switched to an active state. The reading end determines whether a new frame has arrived by comparing the current value of the frame count with the previous value in the local cache. If the comparison results are inconsistent, it means that a new frame has been written since the last read; if the comparison results are consistent, it means that no new frame has arrived.

[0052] The frame counter is monotonically increasing, and its value range can be set large enough to ensure it doesn't overflow throughout the browser instance's lifecycle. The reader determines the presence of a new frame by comparing the current frame count with the locally cached frame count, without needing to consider the specific frame count value. For example, when the browser is first opened, the reader's local cache value is 0, and the initial value of the frame counter in the metadata area is also 0. Therefore, the reader will not attempt to read invalid data before the first frame is rendered.

[0053] In some embodiments, when a browser instance is created, the active buffer number in the metadata area is initialized to 1, meaning the first frame data area is the active buffer by default. At this time, no valid frame data has been written to the first frame data area 1. Therefore, when the reader first reads, the initial value (0) of the frame counter is consistent with the local cache value (0), and the reader will skip texture updates. Only after the writer writes the first frame and increments the frame counter to 1 will the reader actually read and upload the texture. The above method ensures that the reader will not read uninitialized invalid data.

[0054] In some embodiments, after the writer updates the frame count information stored in the metadata area, it also needs to send a frame update notification message to the reader to trigger the reader to perform a frame reading operation.

[0055] In other words, after the writer performs an atomic increment operation to update the frame count information stored in the metadata area, it also sends a client event to the reader via a Thrift remote procedure call. Draw a notification message (browser_id) to proactively inform the reader that a new frame has arrived, thereby triggering the reader to perform a frame reading operation.

[0056] It should be understood that the above-mentioned active notification path is optional. The reading end can also use a pure polling method to read the frame count information to detect the arrival of new frames. The two methods can be used one at a time or coexist at the same time. This disclosure does not impose any restrictions here.

[0057] In some embodiments, a polling method is used if the game rendering thread is not allowed to block and wait, or an active notification method is enabled if the user needs to reduce the latency between the arrival of a new frame and the reading of a frame.

[0058] The shared memory-based frame data writing method disclosed herein creates a named shared memory region group in response to the browser instance creation request, pre-establishing a dedicated cross-process transmission channel for subsequent frame writing, eliminating the need for repeated system calls for each frame write. Furthermore, each browser instance has an independent shared memory region group, ensuring data isolation and non-interference among multiple instances running simultaneously. Secondly, by reading the active buffer number in the metadata area to determine inactive buffers as writing targets, the write operation and the read operation on the reading end always operate on different shared memory regions, achieving physical isolation between write and read operations. This prevents write operations from being blocked by read operations and read operations from being delayed by write operations. Moreover, by updating the active buffer number in the metadata area only once after pixel data writing is complete, the switching process is independent of the reader's response speed or current load, and the write cycle is unaffected by the reader's state. Finally, by updating the frame count information in the metadata area, the reading end can quickly make a judgment without accessing a large block of frame data area when there are no new frames, thus optimizing the polling overhead. Furthermore, the frame count information exists independently of the active buffer number. Even if the reading end performs new writes and switches after reading the frame count information and before actually accessing the frame data area, the reading end can still perceive the existence of intermediate frames by comparing the frame count information, providing a basis for judgment for subsequent frame processing logic.

[0059] Figure 3 The diagram illustrates a flowchart of a shared memory-based frame data reading method according to an embodiment of this disclosure. Figure 4 This illustration shows a flowchart of a shared memory-based frame data reading method according to another embodiment of this disclosure, applied to the reading end, i.e., the reader. Figure 3 and Figure 4 As shown, the method includes steps 121-124, wherein: Step 121: Obtain the identification information of the browser instance, and map the named shared memory region group corresponding to the browser instance based on the identification information through the cross-process memory sharing mechanism provided by the operating system.

[0060] The browser instance is identified by a unique identifier (such as browser_id) generated by the writer when creating the browser instance. This identifier distinguishes different H5 pages opened simultaneously on the reader. After browser creation is complete on the writer, the browser instance identifier is passed to the reader via an initial communication channel (such as the return value of a Thrift RPC). Based on the browser instance identifier, the reader maps it to the same shared memory region according to the naming rules agreed upon with the writer.

[0061] The cross-process memory sharing mechanism provided by the operating system is the named shared memory feature provided by the Windows operating system. It involves creating a file mapping object (CreateFileMapping), opening the file mapping object (OpenFileMapping), and mapping the file mapping view to the process address space (MapViewOfFile). This cross-process memory sharing mechanism allows different processes to access the same physical memory page using a unified naming convention.

[0062] Mapping is the process by which the reading end associates a shared memory object in the kernel with its own process's virtual address space by calling operating system APIs. Once mapping is complete, the reading end can directly access the contents of the shared memory using the returned memory address pointer. In this disclosure, the writing end is responsible for creation, and the reading end is responsible for mapping.

[0063] The named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are written by the writing end.

[0064] The reader obtains the browser instance from the writer's return value (browser_id) after sending an open browser (open_browser) request via Thrift RPC. The reader then generates the name string required for the mapping according to the naming rules agreed upon with the writer.

[0065] As an example, when the reading end executes step 121, it first generates three shared memory name strings based on the browser instance's identification information. For each name, it sequentially calls the `OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name)` function to open an existing shared memory kernel object. It then calls `MapViewOfFile` to map the file mapping view to the process address space, mapping each shared memory object to the reading end's virtual address space, obtaining their respective starting address pointers. Finally, it interprets the starting address of the metadata area as a pointer to a browser shared information (BrowserShareInfo*) structure for subsequent field-based access control information. Finally, it saves the starting addresses of the two frame data areas as unsigned char* pointers for later use when reading pixel data.

[0066] To illustrate parallel mapping across multiple browser instances, consider a scenario where three H5 pages—an online store, an event page, and a customer service page—are open simultaneously on the reading end. The reading end maintains a list of browser instances, each storing its own set of mapped pointers (metadata area pointer, frame data area 1 pointer, and frame data area 2 pointer). The reading end iterates through this list each frame, performing a read operation on each instance. Each of the three instances has its own independent shared memory region group; they are isolated from each other and do not interfere with each other. An exception in one instance will not affect the frame transmission of other instances. This method of each browser instance corresponding to a set of independent named shared memory regions allows the reading end to map multiple sets of regions simultaneously and read them separately in each frame, thus supporting concurrent rendering of multiple H5 pages.

[0067] Step 122: Obtain the frame count information stored in the metadata area, and determine whether a new frame has arrived based on the frame count information.

[0068] In some embodiments, frame count information can be obtained in the following ways: First, the reader actively polls, where the game rendering thread performs a read operation once per frame rendering cycle, reading the current value of the active buffer number in the metadata area and comparing it with the last count (last_count) in the local cache. Second, the writer actively notifies, where the writer sends a client event to the reader via Thrift RPC after completing the frame count update. The client will receive a painting notification; upon receiving the notification, the reader will read the frame count information to confirm the new frame; or, a hybrid mode, in which the writer actively notifies and the reader actively polls in a coordinated manner.

[0069] Figure 5 A schematic diagram of the process for obtaining frame count information in one embodiment of this disclosure is shown, as follows: Figure 5 As shown, step 122, obtaining the frame count information stored in the metadata area, includes steps 1221-1223, wherein: Step 1221: In each frame rendering loop, read the frame count information stored in the metadata area and compare the current value of the frame count information with the previous value in the local cache.

[0070] In some embodiments, the reader can maintain a local variable (last_render_count) to cache the frame count value read last time. Each time this step is executed, the current value of the frame count information in the metadata area is read and compared with the count value of the last count.

[0071] Step 1222: When the current value is inconsistent with the previous value, it is determined that a new frame has arrived, and the reading target is determined in the first frame data area or the second frame data area according to the active buffer number currently stored in the metadata area.

[0072] If the current frame count is equal to the previous count (browser_render_count == last_render_count), it means the writer has not written any new frames since the last read, and therefore no new frames have arrived. If the current frame count is not equal to the previous count (browser_render_count != last_render_count), it means the writer has written one or more frames, and therefore a new frame has arrived. This determination method is simple and efficient, requiring only one memory read and one integer comparison.

[0073] As an example, in a scenario where the reader actively polls, the reader can run at 60fps. In the early stages of each frame rendering cycle (e.g., before the scene begins rendering), it reads the current value of the frame count information in the metadata area. If the currently read value is 15, and the previous count in the reader's local cache is also 15, they are consistent. Therefore, it's determined that no new frame has arrived, and the texture update is skipped, continuing with other rendering tasks for the current frame. This continues until the writer completes writing the next frame and increments the frame count to 16. If, in a subsequent frame's polling, the reader reads 16, which is inconsistent with the local cached value of 15, it's determined that a new frame has arrived, and proceeds to steps 123 to perform the actual frame data reading and texture update.

[0074] As an example, in a scenario where the writer actively notifies the reader, the reader registers a Thrift callback handler function for the current browser instance during initialization to receive client events. Drawing notification. After the writer completes writing a frame and increments the frame count from 50 to 51, it sends a client event to the reader via Thrift RPC. A notification (browser identifier) ​​is drawn. Upon receiving this notification, the message processing thread on the reading end sets a flag for the game rendering thread (indicating a new frame is pending reading). The game rendering thread checks this flag at the beginning of the main loop of the next frame. The current value of the frame count is 51, which differs from the previous count of 50, indicating a new frame has arrived. Compared to the reading end's active polling method, the writing end's active notification method has lower latency.

[0075] As an example, in a hybrid scenario, the reader simultaneously employs both reader-side active polling and writer-side active notification mechanisms. The game rendering thread performs polling every frame as a fundamental guarantee, while the Thrift message processing thread sets a flag upon receiving an active notification. In one operation, due to high system load, the Thrift notification message was delayed in the transmission queue by approximately 5ms before reaching the reader. By the time the message arrived and the reader was preparing to respond, the game rendering thread's next frame cycle had already begun, its polling operation had read the new frame count value, and triggered a texture update. Upon receiving the notification, the reader checked the flag and found that the frame count had already been processed, so it ignored the notification. This hybrid mode design ensures that even if the active notification is delayed due to system load, the polling mechanism can still guarantee that new frames are processed in a timely manner, enhancing system stability.

[0076] In embodiments of this disclosure, when the current value is consistent with the previous value, it is determined that no new frame has arrived and the texture update of the current frame is skipped.

[0077] In some embodiments, in order to reduce the overhead of polling, when the current value of the frame count information is consistent with the previous value in the local cache for multiple consecutive determinations and the number of consecutive consistent determinations exceeds a predetermined threshold, the polling method is switched from per-frame polling to low-frequency polling at predetermined time intervals; if the current value of the frame count information is detected to be inconsistent with the previous value in the local cache during the low-frequency polling period, the polling method is switched back to per-frame polling.

[0078] Step 123: When a new frame is detected, the reading target is determined in the first frame data area or the second frame data area based on the currently stored active buffer number in the metadata area.

[0079] As an example, after the reader detects the arrival of a new frame, it reads the active buffer number field in the metadata area, which currently has a value of 2. Based on this, the reader determines that the reading target is the second frame data area and directs subsequent pixel data reading and texture upload operations to the mapping address of the second frame data area.

[0080] The way the active buffer number directly points to the frame data area where the latest frame is located means that the determination of the reading target only requires a single memory read operation, without the need for searching or traversing, resulting in extremely low determination latency.

[0081] Step 124: Obtain pixel data from the frame data area corresponding to the target and upload the pixel data to the texture object of the graphics processor.

[0082] A texture object is a resource object in a graphics processing unit (GPU) used to store two-dimensional image data (such as textures, UI elements, rendering targets, etc.). In this disclosure, the texture object is the final presentation carrier of the H5 page in the game scene. The texture object is mapped onto a 3D model surface in the game scene, such as a display board, UI panel, or screen on a character, and is sampled and displayed by the GPU when rendering each frame.

[0083] In some embodiments, the reading end may not perform any data copying operation, but directly pass the frame data area mapping address (frame_ptr) and effective size (width / height) as parameters to the control interface. Browser The texture update (ccui_browser_texture_update) interface. This interface performs direct memory access (DMA) transfer directly at the graphics driver layer using this address as the source address, uploading pixel data from system memory to GPU memory. The entire transfer process does not involve any movement or copying of pixel data on the CPU side; it only handles initiating the transfer command and receiving the completion interrupt. Therefore, this direct address passing method is a hardware-level direct memory access and does not consume CPU computing resources.

[0084] In other embodiments, the reading end can first copy the pixel data from shared memory to an intermediate buffer, such as a pixel buffer object (PBO), and then upload it from the intermediate buffer to the GPU. This method allows data preparation and GPU transfer to overlap in time, i.e., asynchronous upload.

[0085] In the embodiments of this disclosure, in addition to obtaining pixel data from the frame data area, the reading end also needs to obtain the effective width and effective height of the latest frame. The reading end reads the size field corresponding to the reading target from the metadata area. If the reading target is the first frame data area, then render_1_width / render_1_height is read; if it is the second frame data area, then render_2_width / render_2_height is read.

[0086] Continue as Figure 5As shown, after step 124, the method further includes step 1223.

[0087] Step 1223: Update the local cache with the current value.

[0088] After obtaining pixel data from the frame data area corresponding to the target and uploading the pixel data to the texture object of the graphics processor, the reading end updates the local cache based on the current value of the read frame count information. That is, it updates the count value variable of the previous count maintained locally on the reading end side, so that when the next frame determines whether a new frame has arrived based on the frame count information, the current value of the newly read frame count information is compared with the updated local cache value to determine whether a new frame has arrived.

[0089] In some embodiments, the metadata area also stores a valid flag indicating whether the browser instance is alive. In order to prevent the reading end from continuing to access the invalid shared memory area and causing access violations or reading invalid data, it is also necessary to check the valid flag corresponding to the browser instance before obtaining pixel data; if the valid flag indicates invalidity, the current read operation is terminated and the mapped shared memory area is released.

[0090] The metadata area also stores a valid flag (is_valid) indicating whether the browser instance is alive. If the browser instance has been destroyed on the writing side, the valid flag is set to 0. Before performing a read operation, the reading end first checks the valid flag. If the valid flag indicates an invalid state, that is, the valid flag bit is 0, it means that the browser instance on the writing side has been destroyed. The reading end immediately stops polling and reading operations on the browser instance and releases the mapped shared memory area to avoid the reading end continuing to access the invalid shared memory area, which would result in an access violation or read invalid data. If the reading end finds that the valid flag is valid, that is, the valid flag bit is 1, the reading end continues to perform subsequent read operations.

[0091] In some embodiments, the mapping address of the frame data area corresponding to the reading target in the local process address space can be passed to the texture update interface of the graphics driver layer, so that the graphics driver layer performs memory access transfer based on the mapping address and uploads the pixel data to the texture object of the graphics processor.

[0092] The reading end directly passes the mapping address (frame_ptr) of the frame data area corresponding to the target in the local process address space, as well as the effective width and effective height of the frame, to the engine texture update interface. The engine driver layer (OpenGL / DirectX / Vulkan) uses this mapping address as the source of pixel data within the texture update interface, performs direct memory access (DMA) transfer, and uploads the pixel data to the texture object of the graphics processor. This eliminates the need to copy the pixel data from shared memory to an intermediate buffer on the CPU side before uploading, thus achieving a zero-copy transfer path from shared memory to GPU texture, reducing CPU memory bandwidth consumption and transmission latency.

[0093] Figure 6 A flowchart illustrating a shared memory-based frame data read / write method according to an embodiment of this disclosure is shown, as follows: Figure 6 As shown, during the data production phase, the Chromium renderer process performs off-screen rendering. After completing the drawing of an H5 page frame, it triggers the Electron drawing event callback. The callback parameters carry the pixel data buffer pointer (frame_data) of the current frame, as well as its effective width (w) and effective height (h).

[0094] During the data transfer phase, the drawing event callback passes the frame data to the web page connection script file (we_connect.js) in the Electron main process. This scripting language layer (JavaScript) calls the native_render_frame function of the native addon through the native application programming interface (N-API) to pass the frame data and its size information to the C++ layer for processing.

[0095] Continue as Figure 6 As shown, during the data writing phase, the native extension component first reads the metadata area (xy2_browser_share_) in the native rendering frame function. <tag>The active buffer number in the memory is used to determine the current active buffer number, and the inactive buffer is calculated as the write target. Then, a memory copy operation is performed to write the frame pixel data to the corresponding frame data area (the first frame data area xy2_render_target_1_). <tag>Or the second frame data area xy2_render_target_2_ <tag>Then, an atomic update of the active buffer number is performed to make the write target the new active buffer, and the current value of the frame count information is atomically incremented.

[0096] During the data perception and reading phase, the reading-side rendering thread polls the current value of the frame count information in the metadata area during each frame rendering loop, comparing it with the local cache value to determine if a new frame has arrived. When a new frame is detected, the active buffer number is read to obtain the current active buffer number, and the mapping address of the corresponding frame data area is directly obtained.

[0097] Continue as Figure 6 As shown, the control interface is called from the reading end during the GPU screen display stage. Browser The texture update interface passes the pixel data mapping address in shared memory to the graphics driver layer, which then uploads the pixel data to the graphics processor (GPU) texture object via DMA transfer, completing the final rendering of the H5 page in the game scene.

[0098] During the above execution process, the frame pixel data in the entire path is copied only once on the CPU side when the native extension component performs a memory copy; all other steps are zero-copy operations.

[0099] Figure 7 A flowchart illustrating a shared memory-based frame data read / write method according to another embodiment of this disclosure is shown, as follows: Figure 7 As shown, a complete embodiment is provided as an example to illustrate the reading and writing of frame data.

[0100] like Figure 7 As shown, this example uses the game process as the reading end and the web rendering process as the writing end. The initial state of the browser shared information (BrowserShareInfo) in the metadata area is: active buffer number is 1, i.e., current_render_target=1, and the current value of the frame count information is 0. The game process's local cache has a last count value of 0, i.e., last_count=0.

[0101] The game process polls the current value of the frame count information every frame. If the value read is 0, which is consistent with the local cache value of 0, it is determined that no new frame has arrived, and the old frame is returned or the texture update is skipped.

[0102] After receiving the current frame pixel data in the onPaint callback, the Web rendering process reads the current value of the active buffer number in the metadata area, which is currently 1; calculates the write target = 3 – current value = 3 - 1 = 2, determining the write target to be the second frame data area; performs a memory copy to write the frame pixel data to the second frame data area; performs an atomic write operation to update the current value of the active buffer number to 2; performs an atomic increment operation to increment the current value of the frame count information from 0 to 1; completes the write, and switches the active buffer number from 1 to 2.

[0103] The game process polls the current value of the frame count information. The value read is 1, which is inconsistent with the local cache value of 0. It is determined that a new frame has arrived. Then, the current value of the active buffer number is read, which is 2. The target of reading is determined to be the second frame data area. The latest frame pixel data is read from the second frame data area and uploaded to the GPU texture. The local cache is updated with the current value of 1.

[0104] After receiving the next frame's pixel data, the Web rendering process reads the current value of the active buffer number in the metadata area, which is 2. It calculates the write target = 3 – current value = 3 - 2 = 1, determining the write target to be the first frame data area. It performs a memory copy to write the frame pixel data to the first frame data area. It performs an atomic write operation to update the current value of the active buffer number to 1. It performs an atomic increment operation to increment the current value of the frame count information from 1 to 2. After completing the write, it switches the active buffer number from 2 to 1.

[0105] Throughout the entire write and read process, the Web rendering process always writes to the inactive buffer, while the game process always reads from the active buffer. Since the two processes always operate on different buffers, data consistency can be guaranteed without the need for mutex locks, and atomic switching ensures the visibility of buffer state changes.

[0106] Based on the same inventive concept, this disclosure also provides a shared memory-based frame data writing device corresponding to the shared memory-based frame data writing method. Since the principle of the device in this disclosure for solving the problem is similar to the shared memory-based frame data writing method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0107] Figure 8 This illustration shows a schematic diagram of a shared memory-based frame data writing apparatus according to an embodiment of the present disclosure. Figure 8 As shown, the device includes: a creation module 210, a first reading module 220, a writing module 230, and an update module 240, wherein: The creation module 210 is used to create a named shared memory region group corresponding to the browser instance in response to the browser instance creation request; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are used for reading by the reading end; The first reading module 220 is used to read the active buffer number stored in the metadata area in response to the current frame pixel data generated by off-screen rendering, and determine the inactive buffer in the first frame data area or the second frame data area as the writing target based on the active buffer number. The writing module 230 is used to write the current frame pixel data into the frame data area corresponding to the writing target; The update module 240 is used to update the active buffer number stored in the metadata area after the write is completed, so that the write target becomes the new active buffer; and to update the frame count information stored in the metadata area. The frame count information is used by the reading end to determine whether a new frame has arrived.

[0108] In some embodiments, the creation module 210 is specifically used to generate a globally unique name string based on the identification information of the browser instance; and to create a metadata area, a first frame data area, and a second frame data area based on the name string.

[0109] In some embodiments, the first reading module 220 is specifically used to send a frame update notification message to the reading end to trigger the reading end to perform a frame reading operation.

[0110] In some embodiments, the writing module 230 is specifically used to write the effective width and effective height of the current frame pixel data into the size information field in the metadata area corresponding to the writing target.

[0111] In some embodiments, the writing module 230 is specifically used to determine whether the size of the current frame pixel data exceeds the capacity limit of the frame data area corresponding to the writing target; if it does, the size of the current frame pixel data is reduced until the size of the reduced current true pixel data does not exceed the capacity limit of the frame data area corresponding to the writing target.

[0112] Based on the same inventive concept, this disclosure also provides a shared memory-based frame data reading device corresponding to the shared memory-based frame data reading method. Since the principle of the device in this disclosure for solving the problem is similar to the shared memory-based frame data reading method described above, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0113] Figure 9 This illustration shows a schematic diagram of a shared memory-based frame data reading device according to an embodiment of the present disclosure. Figure 9 As shown, the device includes: an acquisition module 310, a determination module 320, a second reading module 330, and an upload module 340, wherein: The acquisition module 310 is used to acquire the identification information of the browser instance, and based on the identification information, it maps the named shared memory region group corresponding to the browser instance through the cross-process memory sharing mechanism provided by the operating system; the named shared memory region group includes at least: a meta-information area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are written by the writing end; The determination module 320 is used to obtain the frame count information stored in the metadata area and determine whether a new frame has arrived based on the frame count information; The second reading module 330 is used to determine the reading target in the first frame data area or the second frame data area according to the currently stored active buffer number in the metadata area when it is determined that a new frame has arrived. The upload module 340 is used to obtain pixel data from the frame data area corresponding to the reading target and upload the pixel data to the texture object of the graphics processor.

[0114] In some embodiments, the acquisition module 310 is specifically used to read the frame count information stored in the metadata area in each frame rendering loop, and compare the current value of the frame count information with the previous value of the local cache; when the current value is inconsistent with the previous value, it is determined that a new frame has arrived, and the reading target is determined in the first frame data area or the second frame data area according to the active buffer number currently stored in the metadata area. Upload module 340 is specifically used to update the local cache with the current value.

[0115] In some embodiments, the determination module 320 is specifically used to determine that no new frame has arrived and skip the texture update of the current frame when the current value is consistent with the previous value.

[0116] In some embodiments, the determination module 320 is specifically configured to switch the polling mode from per-frame polling to low-frequency polling at a predetermined time interval when the current value of the frame count information is consistent with the previous value in the local cache for multiple consecutive determinations and the number of consecutive consistency exceeds a predetermined threshold; and to switch the polling mode to per-frame polling if the current value of the frame count information is detected to be inconsistent with the previous value in the local cache during the low-frequency polling period.

[0117] In some embodiments, the upload module 340 is specifically used to pass the mapping address of the frame data area corresponding to the reading target in the local process address space to the texture update interface of the graphics driver layer, so that the graphics driver layer performs memory access transmission based on the mapping address and uploads the pixel data to the texture object of the graphics processor.

[0118] In some embodiments, the determination module 320 is specifically used to check the valid flag corresponding to the browser instance; if the valid flag indicates invalidity, the current read operation is terminated and the mapped shared memory region is released.

[0119] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.

[0120] This disclosure also provides a computer device. Figure 10 A schematic diagram of the structure of a computer device according to an embodiment of this disclosure is shown, such as... Figure 10 As shown, the system includes a processor 61 and a memory 62, and optionally, a bus 63. The memory 62 stores machine-readable instructions executable by the processor 61. When the computer device is running, the processor 61 communicates with the memory 62 via the bus 63. When the machine-readable instructions are executed by the processor 61, the aforementioned... Figures 1-7 The steps of any method.

[0121] This disclosure also provides a computer-readable storage medium storing a computer program, which is executed by a processor. Figures 1-7 The steps of the method.

[0122] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or modules may be electrical, mechanical, or other forms.

[0123] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.

[0124] The above are merely specific embodiments of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure.< / tag> < / tag> < / tag>

Claims

1. A method for writing frame data based on shared memory, applied at the writing end, characterized in that, The method includes: In response to a browser instance creation request, a named shared memory region group corresponding to the browser instance is created; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, the first frame data area and the second frame data area being used for reading by the reading end; In response to the current frame pixel data generated by off-screen rendering, the active buffer number stored in the metadata area is read, and the inactive buffer in the first frame data area or the second frame data area is determined as the writing target based on the active buffer number. Write the current frame pixel data into the frame data area corresponding to the writing target; After the write operation is completed, the active buffer number stored in the metadata area is updated to make the write target a new active buffer. The frame count information stored in the metadata area is updated. The frame count information is used by the reading end to determine whether a new frame has arrived.

2. The method according to claim 1, characterized in that, The creation of a named shared memory region group corresponding to the browser instance includes: Generate a globally unique name string based on the browser instance's identification information; The metadata area, the first frame data area, and the second frame data area are created based on the name string.

3. The method according to claim 1, characterized in that, After updating the frame count information stored in the metadata area, the method further includes: A frame update notification message is sent to the reading end to trigger the reading end to perform a frame reading operation.

4. The method according to claim 1, characterized in that, After writing the current frame pixel data into the frame data area corresponding to the writing target, the method further includes: Write the effective width and effective height of the current frame pixel data into the size information field corresponding to the writing target in the metadata area.

5. The method according to claim 4, characterized in that, Before writing the current frame pixel data into the frame data area corresponding to the writing target, the method further includes: Determine whether the size of the current frame pixel data exceeds the capacity limit of the frame data area corresponding to the write target; If the size exceeds the limit, the size of the current frame pixel data is reduced until the size of the reduced current frame pixel data does not exceed the capacity limit of the frame data area corresponding to the writing target.

6. A method for reading frame data based on shared memory, applied at the reading end, characterized in that, The method includes: Obtain the identification information of the browser instance, and map the browser instance to a named shared memory region group corresponding to the browser instance through the cross-process memory sharing mechanism provided by the operating system based on the identification information; the named shared memory region group includes at least: a metadata area for storing control information, a first frame data area and a second frame data area for storing pixel data, and the first frame data area and the second frame data area are written by the writing end; Obtain the frame count information stored in the metadata area, and determine whether a new frame has arrived based on the frame count information; When a new frame is detected to have arrived, the reading target is determined in the first frame data area or the second frame data area according to the currently stored active buffer number in the metadata area. Pixel data is obtained from the frame data area corresponding to the target being read, and the pixel data is uploaded to the texture object of the graphics processor.

7. The method according to claim 6, characterized in that, The step of obtaining the frame count information stored in the metadata area includes: In each frame rendering loop, the frame count information stored in the metadata area is read, and the current value of the frame count information is compared with the previous value in the local cache. When the current value is inconsistent with the previous value, it is determined that a new frame has arrived, and the reading target is determined in the first frame data area or the second frame data area according to the active buffer number currently stored in the metadata area; After obtaining pixel data from the frame data area corresponding to the reading target and uploading the pixel data to the texture object of the graphics processor, the method further includes: Update the local cache with the current value.

8. The method according to claim 7, characterized in that, The method further includes: When the current value is consistent with the previous value, it is determined that no new frame has arrived and the texture update of this frame is skipped.

9. The method according to claim 8, characterized in that, The method further includes: When the current value of the frame count information is consistent with the previous value in the local cache for multiple consecutive determinations and the number of consecutive consistent determinations exceeds a predetermined threshold, the polling method is switched from polling per frame to low-frequency polling at predetermined time intervals. If, during low-frequency polling, the current value of the frame count information is found to be inconsistent with the previous value in the local cache, the polling mode is switched to per-frame polling.

10. The method according to claim 6, characterized in that, The step of uploading the pixel data to the texture object of the graphics processor includes: The mapping address of the frame data area corresponding to the reading target in the local process address space is passed to the texture update interface of the graphics driver layer, so that the graphics driver layer performs memory access transmission based on the mapping address and uploads the pixel data to the texture object of the graphics processor.

11. The method according to claim 6, characterized in that, The metadata area also stores a valid flag indicating whether the browser instance is alive; before obtaining pixel data from the frame data area corresponding to the target, the method further includes: Check the valid flags corresponding to the browser instance; If the valid flag indicates invalidity, the current read operation is terminated and the mapped shared memory region is released.