• 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_2/display_buffer_type.h"
22 
23 namespace OHOS {
24 namespace HDI {
25 namespace Display {
26 namespace Buffer {
27 namespace V1_0 {
28 
29 #ifdef BUFFER_VDI_DEFAULT_LIBRARY_ENABLE
30 #define DISPLAY_BUFFER_VDI_DEFAULT_LIBRARY "libdisplay_buffer_vdi_impl_default.z.so"
31 #endif // BUFFER_VDI_DEFAULT_LIBRARY_ENABLE
32 #define DISPLAY_BUFFER_VDI_LIBRARY "libdisplay_buffer_vdi_impl.z.so"
33 #define NOT_SUPPORT (-2)
34 
35 class IDisplayBufferVdi {
36 public:
37     virtual ~IDisplayBufferVdi() = default;
38 
39     /**
40      * @brief Allocates memory based on the parameters passed by the GUI.
41      *
42      * @param info Indicates the description of the memory to allocate.
43      *
44      * @param handle Indicates the pointer to the buffer of the memory to allocate.
45      *
46      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
47      * otherwise.
48      * @since 1.0
49      * @version 1.0
50      */
51     virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const = 0;
52 
53     /**
54      * @brief Releases memory.
55      *
56      * @param handle Indicates the reference to the buffer of the memory to release.
57      *
58      * @since 1.0
59      * @version 1.0
60      */
61     virtual void FreeMem(const BufferHandle& handle) const = 0;
62 
63     /**
64      * @brief Maps memory to memory without cache in the process's address space.
65      *
66      * @param handle Indicates the reference to the buffer of the memory to map.
67      *
68      * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
69      * @since 1.0
70      * @version 1.0
71      */
72     virtual void *Mmap(const BufferHandle& handle) const = 0;
73 
74     /**
75      * @brief Unmaps memory, that is, removes mappings from the process's address space.
76      *
77      * @param handle Indicates the reference to the buffer of the memory to unmap.
78      *
79      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
80      * otherwise.
81      * @since 1.0
82      * @version 1.0
83      */
84     virtual int32_t Unmap(const BufferHandle& handle) const = 0;
85 
86     /**
87      * @brief Flushes data from the cache to memory and invalidates the data in the cache.
88      *
89      * @param handle Indicates the reference to the buffer of the cache to flush.
90      *
91      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
92      * otherwise.
93      * @since 1.0
94      * @version 1.0
95      */
96     virtual int32_t FlushCache(const BufferHandle& handle) const = 0;
97 
98     /**
99      * @brief Invalidates the cache to update it from memory.
100      *
101      * @param handle Indicates the reference to the buffer of the cache, which will be invalidated.
102      *
103      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
104      * otherwise.
105      * @since 1.0
106      * @version 1.0
107      */
108     virtual int32_t InvalidateCache(const BufferHandle& handle) const = 0;
109 
110     /**
111      * @brief Checks whether the given VerifyAllocInfo array is allocatable.
112      *
113      * @param infos Indicates the VerifyAllocInfo array.
114      * @param supporteds Indicates whether the array is allocatable.
115      *
116      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
117      * otherwise.
118      * @since 1.0
119      * @version 1.0
120      */
121     virtual int32_t IsSupportedAlloc(
122         const std::vector<VerifyAllocInfo>& infos, std::vector<bool>& supporteds) const = 0;
123 
RegisterBuffer(const BufferHandle & handle)124     virtual int32_t RegisterBuffer(const BufferHandle& handle)
125     {
126         return 0;
127     }
128 
SetMetadata(const BufferHandle & handle,uint32_t key,const std::vector<uint8_t> & value)129     virtual int32_t SetMetadata(const BufferHandle& handle, uint32_t key, const std::vector<uint8_t>& value)
130     {
131         return 0;
132     }
133 
GetMetadata(const BufferHandle & handle,uint32_t key,std::vector<uint8_t> & value)134     virtual int32_t GetMetadata(const BufferHandle& handle, uint32_t key, std::vector<uint8_t>& value)
135     {
136         return 0;
137     }
138 
ListMetadataKeys(const BufferHandle & handle,std::vector<uint32_t> & keys)139     virtual int32_t ListMetadataKeys(const BufferHandle& handle, std::vector<uint32_t>& keys)
140     {
141         return 0;
142     }
143 
EraseMetadataKey(const BufferHandle & handle,uint32_t key)144     virtual int32_t EraseMetadataKey(const BufferHandle& handle, uint32_t key)
145     {
146         return 0;
147     }
148 
GetImageLayout(const BufferHandle & handle,V1_2::ImageLayout & layout)149     virtual int32_t GetImageLayout(const BufferHandle& handle, V1_2::ImageLayout& layout) const
150     {
151         return 0;
152     }
153 
IsSupportAllocPassthrough(const AllocInfo & info)154     virtual int32_t IsSupportAllocPassthrough(const AllocInfo& info) const
155     {
156         return NOT_SUPPORT;
157     }
158 
ReAllocMem(const OHOS::HDI::Display::Buffer::V1_0::AllocInfo & info,const BufferHandle & inHandle,BufferHandle * & outHandle)159     virtual int32_t ReAllocMem(const OHOS::HDI::Display::Buffer::V1_0::AllocInfo& info,
160         const BufferHandle& inHandle, BufferHandle*& outHandle) const
161     {
162         return NOT_SUPPORT;
163     }
164 };
165 
166 using CreateDisplayBufferVdiFunc = IDisplayBufferVdi* (*)();
167 using DestroyDisplayBufferVdiFunc = void (*)(IDisplayBufferVdi* vdi);
168 extern "C" IDisplayBufferVdi* CreateDisplayBufferVdi();
169 extern "C" void DestroyDisplayBufferVdi(IDisplayBufferVdi* vdi);
170 } // namespace V1_0
171 } // namespace Buffer
172 } // namespace Display
173 } // namespace HDI
174 } // namespace OHOS
175 
176 #endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAY_BUFFER_VDI_H
177