• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HDI_IDISPLAY_GRALLOC_V1_0_H
17 #define HDI_IDISPLAY_GRALLOC_V1_0_H
18 
19 #include <vector>
20 #include "display_type.h"
21 #include "buffer_handle.h"
22 
23 namespace OHOS {
24 namespace HDI {
25 namespace Display {
26 namespace V1_0 {
27 using AllocatorDeathCallback = void (*)(void *);
28 class IDisplayGralloc {
29 public:
30     virtual ~IDisplayGralloc() = default;
31 
32     virtual int32_t RegAllocatorDeathCallback(AllocatorDeathCallback func, void* data) = 0;
33 
34     /**
35      * @brief Obtains all interfaces of IDisplayGralloc.
36      *
37      * @return Returns <b>IDisplayGralloc*</b> if the operation is successful; returns an null point otherwise.
38      * @since 1.0
39      * @version 1.0
40      */
41     static IDisplayGralloc* Get();
42 
43     /**
44      * @brief Allocates memory based on the parameters passed by the GUI.
45      *
46      * @param info Indicates the description of the memory to allocate.
47      *
48      * @param handle Indicates the pointer to the buffer of the memory to allocate.
49      *
50      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
51      * otherwise.
52      * @since 1.0
53      * @version 1.0
54      */
55     virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0;
56 
57     /**
58      * @brief Releases memory.
59      *
60      * @param handle Indicates the reference to the buffer of the memory to release.
61      *
62      * @since 1.0
63      * @version 1.0
64      */
65     virtual void FreeMem(const BufferHandle &handle) const = 0;
66 
67     /**
68      * @brief Maps memory to memory without cache in the process's address space.
69      *
70      * @param handle Indicates the reference to the buffer of the memory to map.
71      *
72      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
73      * @since 1.0
74      * @version 1.0
75      */
76     virtual void *Mmap(const BufferHandle &handle) const = 0;
77 
78     /**
79      * @brief Maps memory to memory with cache in the process's address space.
80      *
81      * @param handle Indicates the reference to the buffer of the memory to map.
82      *
83      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
84      * @since 1.0
85      * @version 1.0
86      */
87     virtual void *MmapCache(const BufferHandle &buffer) const = 0;
88 
89     /**
90      * @brief Unmaps memory, that is, removes mappings from the process's address space.
91      *
92      * @param handle Indicates the reference to the buffer of the memory to unmap.
93      *
94      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
95      * otherwise.
96      * @since 1.0
97      * @version 1.0
98      */
99     virtual int32_t Unmap(const BufferHandle &handle) const = 0;
100 
101     /**
102      * @brief Flushes data from the cache to memory and invalidates the data in the cache.
103      *
104      * @param handle Indicates the reference to the buffer of the cache to flush.
105      *
106      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
107      * otherwise.
108      * @since 1.0
109      * @version 1.0
110      */
111     virtual int32_t FlushCache(const BufferHandle &handle) const = 0;
112 
113     /**
114      * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache.
115      *
116      * @param handle Indicates the reference to the buffer of the cache to flush.
117      *
118      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
119      * otherwise.
120      * @since 1.0
121      * @version 1.0
122      */
123     virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0;
124 
125     /**
126      * @brief Invalidates the cache to update it from memory.
127      *
128      * @param handle Indicates the reference to the buffer of the cache, which will be invalidated.
129      *
130      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
131      * otherwise.
132      * @since 1.0
133      * @version 1.0
134      */
135     virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0;
136 
137     /**
138      * @brief Checks whether the given VerifyAllocInfo array is allocatable.
139      *
140      * @param infos Indicates the VerifyAllocInfo array.
141      * @param supporteds Indicates whether the array is allocatable.
142      *
143      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
144      * otherwise.
145      * @since 1.0
146      * @version 1.0
147      */
148     virtual int32_t IsSupportedAlloc(const std::vector<VerifyAllocInfo> &infos,
149                                      std::vector<bool> &supporteds) const = 0;
150 };
151 } // namespace V1_0
152 } // namespace Display
153 } // namespace HDI
154 } // namespace OHOS
155 
156 #endif // HDI_IDISPLAY_GRALLOC_V1_0_H
157