• 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 OHOS_HDI_DISPLAY_V1_0_IDISPLAYBUFFERHWI_H
17 #define OHOS_HDI_DISPLAY_V1_0_IDISPLAYBUFFERHWI_H
18 
19 #include <vector>
20 #include "buffer_handle.h"
21 #include "v1_0/display_buffer_type.h"
22 
23 namespace OHOS {
24 namespace HDI {
25 namespace Display {
26 namespace Buffer {
27 namespace V1_0 {
28 #define DISPLAY_BUFFER_HWI_LIBRARY_PATH "/vendor/lib/libdisplay_buffer_hwi_impl.z.so"
29 
30 class IDisplayBufferHwi {
31 public:
32     virtual ~IDisplayBufferHwi() = default;
33 
34     /**
35      * @brief Allocates memory based on the parameters passed by the GUI.
36      *
37      * @param info Indicates the description of the memory to allocate.
38      *
39      * @param handle Indicates the pointer to the buffer of the memory to allocate.
40      *
41      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
42      * otherwise.
43      * @since 1.0
44      * @version 1.0
45      */
46     virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0;
47 
48     /**
49      * @brief Releases memory.
50      *
51      * @param handle Indicates the reference to the buffer of the memory to release.
52      *
53      * @since 1.0
54      * @version 1.0
55      */
56     virtual void FreeMem(const BufferHandle &handle) const = 0;
57 
58     /**
59      * @brief Maps memory to memory without cache in the process's address space.
60      *
61      * @param handle Indicates the reference to the buffer of the memory to map.
62      *
63      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
64      * @since 1.0
65      * @version 1.0
66      */
67     virtual void *Mmap(const BufferHandle &handle) const = 0;
68 
69     /**
70      * @brief Maps memory to memory with cache in the process's address space.
71      *
72      * @param handle Indicates the reference to the buffer of the memory to map.
73      *
74      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
75      * @since 1.0
76      * @version 1.0
77      */
78     virtual void *MmapCache(const BufferHandle &buffer) const = 0;
79 
80     /**
81      * @brief Unmaps memory, that is, removes mappings from the process's address space.
82      *
83      * @param handle Indicates the reference to the buffer of the memory to unmap.
84      *
85      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
86      * otherwise.
87      * @since 1.0
88      * @version 1.0
89      */
90     virtual int32_t Unmap(const BufferHandle &handle) const = 0;
91 
92     /**
93      * @brief Flushes data from the cache to memory and invalidates the data in the cache.
94      *
95      * @param handle Indicates the reference to the buffer of the cache to flush.
96      *
97      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
98      * otherwise.
99      * @since 1.0
100      * @version 1.0
101      */
102     virtual int32_t FlushCache(const BufferHandle &handle) const = 0;
103 
104     /**
105      * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache.
106      *
107      * @param handle Indicates the reference to the buffer of the cache to flush.
108      *
109      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
110      * otherwise.
111      * @since 1.0
112      * @version 1.0
113      */
114     virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0;
115 
116     /**
117      * @brief Invalidates the cache to update it from memory.
118      *
119      * @param handle Indicates the reference to the buffer of the cache, which will be invalidated.
120      *
121      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
122      * otherwise.
123      * @since 1.0
124      * @version 1.0
125      */
126     virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0;
127 
128     /**
129      * @brief Checks whether the given VerifyAllocInfo array is allocatable.
130      *
131      * @param infos Indicates the VerifyAllocInfo array.
132      * @param supporteds Indicates whether the array is allocatable.
133      *
134      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
135      * otherwise.
136      * @since 1.0
137      * @version 1.0
138      */
139     virtual int32_t IsSupportedAlloc(
140         const std::vector<VerifyAllocInfo> &infos, std::vector<bool> &supporteds) const = 0;
141 };
142 
143 using IDisplayBufferHwi *Create_DisplayBufferHwiFunc_t();
144 using void Destroy_DisplayBufferHwiFunc_t(IDisplayBufferHwi *hwi);
145 extern "C" IDisplayBufferHwi *Create_DisplayBufferHwi();
146 extern "C" void Destroy_DisplayBufferHwi(IDisplayBufferHwi *hwi);
147 } // namespace V1_0
148 } // namespace Buffer
149 } // namespace Display
150 } // namespace HDI
151 } // namespace OHOS
152 
153 #endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAYBUFFERHWI_H
154