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)