• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_IDISPLAY_BUFFER_VDI_H
17 #define OHOS_HDI_DISPLAY_V1_0_IDISPLAY_BUFFER_VDI_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 
29 #define DISPLAY_BUFFER_VDI_LIBRARY "libdisplay_buffer_vdi_impl.z.so"
30 
31 class IDisplayBufferVdi {
32 public:
33     virtual ~IDisplayBufferVdi() = default;
34 
35     /**
36      * @brief Allocates memory based on the parameters passed by the GUI.
37      *
38      * @param info Indicates the description of the memory to allocate.
39      *
40      * @param handle Indicates the pointer to the buffer of the memory to allocate.
41      *
42      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
43      * otherwise.
44      * @since 1.0
45      * @version 1.0
46      */
47     virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const = 0;
48 
49     /**
50      * @brief Releases memory.
51      *
52      * @param handle Indicates the reference to the buffer of the memory to release.
53      *
54      * @since 1.0
55      * @version 1.0
56      */
57     virtual void FreeMem(const BufferHandle& handle) const = 0;
58 
59     /**
60      * @brief Maps memory to memory without cache in the process's address space.
61      *
62      * @param handle Indicates the reference to the buffer of the memory to map.
63      *
64      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
65      * @since 1.0
66      * @version 1.0
67      */
68     virtual void *Mmap(const BufferHandle& handle) const = 0;
69 
70     /**
71      * @brief Unmaps memory, that is, removes mappings from the process's address space.
72      *
73      * @param handle Indicates the reference to the buffer of the memory to unmap.
74      *
75      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
76      * otherwise.
77      * @since 1.0
78      * @version 1.0
79      */
80     virtual int32_t Unmap(const BufferHandle& handle) const = 0;
81 
82     /**
83      * @brief Flushes data from the cache to memory and invalidates the data in the cache.
84      *
85      * @param handle Indicates the reference to the buffer of the cache to flush.
86      *
87      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
88      * otherwise.
89      * @since 1.0
90      * @version 1.0
91      */
92     virtual int32_t FlushCache(const BufferHandle& handle) const = 0;
93 
94     /**
95      * @brief Invalidates the cache to update it from memory.
96      *
97      * @param handle Indicates the reference to the buffer of the cache, which will be invalidated.
98      *
99      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
100      * otherwise.
101      * @since 1.0
102      * @version 1.0
103      */
104     virtual int32_t InvalidateCache(const BufferHandle& handle) const = 0;
105 
106     /**
107      * @brief Checks whether the given VerifyAllocInfo array is allocatable.
108      *
109      * @param infos Indicates the VerifyAllocInfo array.
110      * @param supporteds Indicates whether the array is allocatable.
111      *
112      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
113      * otherwise.
114      * @since 1.0
115      * @version 1.0
116      */
117     virtual int32_t IsSupportedAlloc(
118         const std::vector<VerifyAllocInfo>& infos, std::vector<bool>& supporteds) const = 0;
119 };
120 
121 using CreateDisplayBufferVdiFunc = IDisplayBufferVdi* (*)();
122 using DestroyDisplayBufferVdiFunc = void (*)(IDisplayBufferVdi* vdi);
123 extern "C" IDisplayBufferVdi* CreateDisplayBufferVdi();
124 extern "C" void DestroyDisplayBufferVdi(IDisplayBufferVdi* vdi);
125 } // namespace V1_0
126 } // namespace Buffer
127 } // namespace Display
128 } // namespace HDI
129 } // namespace OHOS
130 
131 #endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAY_BUFFER_VDI_H
132