• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# OH_NativeBuffer
2
3
4## Overview
5
6The **OH_NativeBuffer** module provides the capabilities of **NativeBuffer**. Using the functions provided by this module, you can apply for, use, and release the shared memory, and query its attributes.
7
8\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
9
10**Since**
11
129
13
14
15## Summary
16
17
18### Files
19
20| Name| Description|
21| -------- | -------- |
22| [native_buffer.h](native__buffer_8h.md) | Declares the functions for obtaining and using **NativeBuffer**.<br>File to include: &lt;native_buffer/native_buffer.h&gt; |
23
24
25### Structs
26
27| Name| Description|
28| -------- | -------- |
29| [OH_NativeBuffer_Config](_o_h___native_buffer___config.md) | Defines the **OH_NativeBuffer** attribute configuration, which is used when you apply for a new **OH_NativeBuffer** instance or query the attributes of an existing instance.|
30
31
32### Types
33
34| Name| Description|
35| -------- | -------- |
36| [OH_NativeBuffer](#oh_nativebuffer) | Provides the declaration of an **OH_NativeBuffer** struct.|
37
38
39### Functions
40
41| Name| Description|
42| -------- | -------- |
43| [OH_NativeBuffer_Alloc](#oh_nativebuffer_alloc) (const [OH_NativeBuffer_Config](_o_h___native_buffer___config.md) \*config) | Creates an **OH_NativeBuffer** instance based on an **OH_NativeBuffer_Config** struct. A new **OH_NativeBuffer** instance is created each time this function is called.|
44| [OH_NativeBuffer_Reference](#oh_nativebuffer_reference) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer) | Increases the reference count of an **OH_NativeBuffer** instance by 1.|
45| [OH_NativeBuffer_Unreference](#oh_nativebuffer_unreference) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer) | Decreases the reference count of an **OH_NativeBuffer** instance by 1 and, when the reference count reaches 0, destroys the instance.|
46| [OH_NativeBuffer_GetConfig](#oh_nativebuffer_getconfig) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer, [OH_NativeBuffer_Config](_o_h___native_buffer___config.md) \*config) | Obtains the attributes of an **OH_NativeBuffer** instance.|
47| [OH_NativeBuffer_Map](#oh_nativebuffer_map) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer, void \*\*virAddr) | Maps the ION memory corresponding to an **OH_NativeBuffer** instance to the process address space.|
48| [OH_NativeBuffer_Unmap](#oh_nativebuffer_unmap) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer) | Unmaps the ION memory corresponding to an **OH_NativeBuffer** instance from the process address space.|
49| [OH_NativeBuffer_GetSeqNum](#oh_nativebuffer_getseqnum) ([OH_NativeBuffer](#oh_nativebuffer) \*buffer) | Obtains the sequence number of an **OH_NativeBuffer** instance.|
50
51
52## Type Description
53
54
55### OH_NativeBuffer
56
57
58```
59typedef struct OH_NativeBuffer OH_NativeBuffer
60```
61
62**Description**
63
64Provides the declaration of an **OH_NativeBuffer** struct.
65
66
67## Function Description
68
69
70### OH_NativeBuffer_Alloc()
71
72
73```
74OH_NativeBuffer* OH_NativeBuffer_Alloc (const OH_NativeBuffer_Config * config)
75```
76
77**Description**
78
79Creates an **OH_NativeBuffer** instance based on an **OH_NativeBuffer_Config** struct. A new **OH_NativeBuffer** instance is created each time this function is called.
80
81\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
82
83**Parameters**
84
85| Name| Description|
86| -------- | -------- |
87| config | Pointer to an **OH_NativeBuffer_Config** instance.|
88
89**Returns**
90
91Returns the pointer to the **OH_NativeBuffer** instance created if the operation is successful; returns **NULL** otherwise.
92
93
94### OH_NativeBuffer_GetConfig()
95
96
97```
98void OH_NativeBuffer_GetConfig (OH_NativeBuffer * buffer, OH_NativeBuffer_Config * config )
99```
100
101**Description**
102
103Obtains the attributes of an **OH_NativeBuffer** instance.
104
105\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
106
107**Parameters**
108
109| Name| Description|
110| -------- | -------- |
111| buffer | Pointer to an **OH_NativeBuffer** instance.|
112| config | Pointer to an **OH_NativeBuffer_Config** instance, which is used to receive the attributes of **OH_NativeBuffer**.|
113
114
115### OH_NativeBuffer_GetSeqNum()
116
117
118```
119uint32_t OH_NativeBuffer_GetSeqNum (OH_NativeBuffer * buffer)
120```
121
122**Description**
123
124Obtains the sequence number of an **OH_NativeBuffer** instance.
125
126\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
127
128**Parameters**
129
130| Name| Description|
131| -------- | -------- |
132| buffer | Pointer to an **OH_NativeBuffer** instance.|
133
134**Returns**
135
136Returns the unique sequence number of the **OH_NativeBuffer** instance.
137
138
139### OH_NativeBuffer_Map()
140
141
142```
143int32_t OH_NativeBuffer_Map (OH_NativeBuffer * buffer, void ** virAddr )
144```
145
146**Description**
147
148Maps the ION memory corresponding to an **OH_NativeBuffer** instance to the process address space.
149
150\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
151
152**Parameters**
153
154| Name| Description|
155| -------- | -------- |
156| buffer | Pointer to an **OH_NativeBuffer** instance.|
157| virAddr | Double pointer to the address of the virtual memory.|
158
159**Returns**
160
161Returns **0** if the operation is successful.
162
163
164### OH_NativeBuffer_Reference()
165
166
167```
168int32_t OH_NativeBuffer_Reference (OH_NativeBuffer * buffer)
169```
170
171**Description**
172
173Increases the reference count of an **OH_NativeBuffer** instance by 1.
174
175\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
176
177**Parameters**
178
179| Name| Description|
180| -------- | -------- |
181| buffer | Pointer to an **OH_NativeBuffer** instance.|
182
183**Returns**
184
185Returns **0** if the operation is successful.
186
187
188### OH_NativeBuffer_Unmap()
189
190
191```
192int32_t OH_NativeBuffer_Unmap (OH_NativeBuffer * buffer)
193```
194
195**Description**
196
197Unmaps the ION memory corresponding to an **OH_NativeBuffer** instance from the process address space.
198
199\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
200
201**Parameters**
202
203| Name| Description|
204| -------- | -------- |
205| buffer | Pointer to an **OH_NativeBuffer** instance.|
206
207**Returns**
208
209Returns **0** if the operation is successful.
210
211
212### OH_NativeBuffer_Unreference()
213
214
215```
216int32_t OH_NativeBuffer_Unreference (OH_NativeBuffer * buffer)
217```
218
219**Description**
220
221Decreases the reference count of an **OH_NativeBuffer** instance by 1 and, when the reference count reaches 0, destroys the instance.
222
223\@syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer
224
225**Parameters**
226
227| Name| Description|
228| -------- | -------- |
229| buffer | Pointer to an **OH_NativeBuffer** instance.|
230
231**Returns**
232
233Returns **0** if the operation is successful.
234