• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-2,5711,877

interfaces/12-May-2024-1,754478

test/12-May-2024-828548

.clang-formatD12-May-20246.6 KiB161160

BUILD.gnD12-May-20242 KiB6660

LICENSED12-May-20249.9 KiB177150

README.mdD12-May-20243.7 KiB7247

README_zh.mdD12-May-20243.1 KiB7247

bundle.jsonD12-May-2024857 3837

README.md

1# Surface<a name="EN-US_TOPIC_0000001078362030"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5-   [Compilation and Building](#section137768191623)
6-   [Description](#section1312121216216)
7    -   [Process Description](#section1551164914237)
8    -   [Usage](#section129654513264)
9
10-   [Repositories Involved](#section1371113476307)
11
12## Introduction<a name="section11660541593"></a>
13
14A surface is used to manage and transfer the shared memory of graphics and media. Specific use cases include graphics display and composition, and media playback and recording.
15
16A surface transfers data across processes through control structures such as Inter-Process Communication \(IPC\) handles \(with copies\), and transfers graphics and media data \(zero-copy\) through shared memory. The following figure shows the position where a surface works in the system architecture. The elements in green blocks are surface buffers.
17
18**Figure  1**  Position of a surface (known as Screen buffer in the following figure) in the system architecture<a name="fig584223343312"></a>
19![](figures/position-of-a-surface-in-the-system-architecture.png "position-of-a-surface-in-the-system-architecture")
20
21## Directory Structure<a name="section161941989596"></a>
22
23```
24/foundation/graphic/surface_lite
25├── frameworks       # Framework code
26├── interfaces       # APIs
27│   ├── innerkits    # APIs between modules
28│   └── kits         # External APIs
29└── test             # Test code
30    ├── fuzztest     # Fuzzing
31    └── unittest     # Unit testing
32```
33
34## Compilation and Building<a name="section137768191623"></a>
35
36```
37# Generate the libsurface.so file in the out directory of the product folder through GN compilation.
38hb build surface_lite
39```
40
41## Description<a name="section1312121216216"></a>
42
43### Process Description<a name="section1551164914237"></a>
44
45Take the interaction between Window Manager Service \(WMS\) and UI as an example. UI works as a producer, and WMS works as a consumer.
46
47The producer obtains a buffer from the free queue, draws the UI content into the buffer, and places the buffer in the dirty queue.
48
49The consumer obtains the buffer from the dirty queue, synthesizes graphics data, and places the buffer in the free queue again.
50
51**Figure  2**  Surface rotation process<a name="fig126141128261"></a>
52![](figures/surface-rotation-process.png "surface-rotation-process")
53
54>![](figures/icon-notice.gif) **NOTICE:**
55>1.  A shared memory is used for data transfer, and the process of creating a surface of the first time should be responsible for task of managing the shared memory. If the process is abnormal and is not recycled, severe memory leakage occurs. Therefore, pay special attention to the process.
56>2.  Surfaces are generally used for cross-process transfers of large memory blocks \(such as display data\) in graphics or media. Especially, when continuous physical memory is used, the transfer rate can be greatly improved. It is not recommended that surfaces be used in small-memory transfer scenarios. Otherwise, memory fragmentation may occur, which affects the performance in typical scenarios.
57
58### Usage<a name="section129654513264"></a>
59
60For details, see lite  [WMS](https://gitee.com/openharmony/window_window_manager_lite/blob/master/README.md).
61
62## Repositories Involved<a name="section1371113476307"></a>
63
64[Graphic subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/graphics.md)
65
66[window_window_manager_lite](https://gitee.com/openharmony/window_window_manager_lite/blob/master/README.md)
67
68**graphic_surface_lite**
69
70[arkui_ui_lite](https://gitee.com/openharmony/arkui_ui_lite/blob/master/README.md)
71
72[graphic_graphic_utils_lite](https://gitee.com/openharmony/graphic_graphic_utils_lite/blob/master/README.md)

README_zh.md

1# 图形SURFACE组件<a name="ZH-CN_TOPIC_0000001078362030"></a>
2
3-   [简介](#section11660541593)
4-   [目录](#section161941989596)
5-   [编译构建](#section137768191623)
6-   [说明](#section1312121216216)
7    -   [流程说明](#section1551164914237)
8    -   [使用说明](#section129654513264)
9
10-   [相关仓](#section1371113476307)
11
12## 简介<a name="section11660541593"></a>
13
14Surface组件用于管理和传递图形和媒体的共享内存。具体场景包括了图形的送显、合成,媒体的播放、录制等。
15
16Surface的跨进程传输使用IPC传输句柄等控制结构(有拷贝),使用共享内存传递图形/媒体数据(零拷贝)。
17
18**图 1**  surface(即图中的Screen Buffer)在系统架构中的位置<a name="fig584223343312"></a>
19![](figures/surface在系统架构中的位置(绿色部分为surface-buffer).png "surface在系统架构中的位置(绿色部分为surface-buffer)")
20
21## 目录<a name="section161941989596"></a>
22
23```
24/foundation/graphic/surface_lite
25├── frameworks       # 框架代码
26├── interfaces       # 接口
27│   ├── innerkits    # 模块间接口
28│   └── kits         # 对外接口
29└── test             # 测试代码
30    ├── fuzztest     # fuzz测试
31    └── unittest     # 单元测试
32```
33
34## 编译构建<a name="section137768191623"></a>
35
36```
37# 通过gn编译,在out目录下对应产品的文件夹中生成libsurface.so
38hb build surface_lite
39```
40
41## 说明<a name="section1312121216216"></a>
42
43### 流程说明<a name="section1551164914237"></a>
44
45以WMS组件和UI组件交互为例,UI为生产者,WMS为消费者。
46
47生产者:从Free队列中获取Buffer,将UI内容绘制到Buffer中,然后将Buffer放到Dirty队列;
48
49消费者:从Dirty队列中获取Buffer并进行合成,然后将Buffer重新放到Free队列中。
50
51**图 2**  Surface轮转流程<a name="fig126141128261"></a>
52![](figures/Surface轮转流程.png "Surface轮转流程")
53
54>![](figures/icon-notice.gif) **须知:**
55>1.  由于使用了共享内存,而共享内存的管理任务在首次创建Surface的进程中,因此需要对该进程格外关注,如果发生进程异常且没有回收处理会发生严重的内存泄漏;
56>2.  Surface一般用作图形/媒体中大块内存的跨进程传输(如显示数据),尤其在使用了连续物理内存的情况下,可以大幅提高传输速率。不建议用在小内存传输的场景,容易造成内存碎片化影响典型场景的性能。
57
58### 使用说明<a name="section129654513264"></a>
59
60可参考轻量图形[WMS组件](https://gitee.com/openharmony/window_window_manager_lite/blob/master/README_zh.md)61
62## 相关仓<a name="section1371113476307"></a>
63
64[图形子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%9B%BE%E5%BD%A2%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
65
66[window_window_manager_lite](https://gitee.com/openharmony/window_window_manager_lite/blob/master/README.md)
67
68**graphic_surface_lite**
69
70[arkui_ui_lite](https://gitee.com/openharmony/arkui_ui_lite/blob/master/README.md)
71
72[graphic_graphic_utils_lite](https://gitee.com/openharmony/graphic_graphic_utils_lite/blob/master/README.md)