1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci/**
17094332d3Sopenharmony_ci * @addtogroup Display
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Defines driver functions of the display module.
21094332d3Sopenharmony_ci *
22094332d3Sopenharmony_ci * This module provides driver functions for the graphics subsystem, including graphics layer management,
23094332d3Sopenharmony_ci * device control, graphics hardware acceleration, display memory management, and callbacks.
24094332d3Sopenharmony_ci * @since 1.0
25094332d3Sopenharmony_ci * @version 2.0
26094332d3Sopenharmony_ci */
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_ci
29094332d3Sopenharmony_ci/**
30094332d3Sopenharmony_ci * @file display_gralloc.h
31094332d3Sopenharmony_ci *
32094332d3Sopenharmony_ci * @brief Declares the driver functions for memory.
33094332d3Sopenharmony_ci *
34094332d3Sopenharmony_ci * @since 1.0
35094332d3Sopenharmony_ci * @version 2.0
36094332d3Sopenharmony_ci */
37094332d3Sopenharmony_ci
38094332d3Sopenharmony_ci#ifndef DISPLAY_GRALLOC_H
39094332d3Sopenharmony_ci#define DISPLAY_GRALLOC_H
40094332d3Sopenharmony_ci#include "display_type.h"
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_ci#ifdef __cplusplus
43094332d3Sopenharmony_ciextern "C" {
44094332d3Sopenharmony_ci#endif
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_ci/**
47094332d3Sopenharmony_ci * @brief Defines pointers to the memory driver functions.
48094332d3Sopenharmony_ci */
49094332d3Sopenharmony_citypedef struct {
50094332d3Sopenharmony_ci    /**
51094332d3Sopenharmony_ci     * @brief Allocates memory based on the parameters passed by the GUI.
52094332d3Sopenharmony_ci     *
53094332d3Sopenharmony_ci     * @param info Indicates the pointer to the description info of the memory to allocate.
54094332d3Sopenharmony_ci     * @param handle Indicates the double pointer to the buffer of the memory to allocate.
55094332d3Sopenharmony_ci     *
56094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
57094332d3Sopenharmony_ci     * otherwise.
58094332d3Sopenharmony_ci     * @since 1.0
59094332d3Sopenharmony_ci     * @version 1.0
60094332d3Sopenharmony_ci     */
61094332d3Sopenharmony_ci    int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle);
62094332d3Sopenharmony_ci
63094332d3Sopenharmony_ci    /**
64094332d3Sopenharmony_ci     * @brief Releases memory.
65094332d3Sopenharmony_ci     *
66094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the memory to release.
67094332d3Sopenharmony_ci     *
68094332d3Sopenharmony_ci     * @since 1.0
69094332d3Sopenharmony_ci     * @version 1.0
70094332d3Sopenharmony_ci     */
71094332d3Sopenharmony_ci    void (*FreeMem)(BufferHandle *handle);
72094332d3Sopenharmony_ci
73094332d3Sopenharmony_ci    /**
74094332d3Sopenharmony_ci     * @brief Maps memory to memory without cache in the process's address space.
75094332d3Sopenharmony_ci     *
76094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the memory to map.
77094332d3Sopenharmony_ci     *
78094332d3Sopenharmony_ci     * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
79094332d3Sopenharmony_ci     * @since 1.0
80094332d3Sopenharmony_ci     * @version 1.0
81094332d3Sopenharmony_ci     */
82094332d3Sopenharmony_ci    void *(*Mmap)(BufferHandle *handle);
83094332d3Sopenharmony_ci
84094332d3Sopenharmony_ci    /**
85094332d3Sopenharmony_ci     * @brief Maps memory to memory with cache in the process's address space.
86094332d3Sopenharmony_ci     *
87094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the memory to map.
88094332d3Sopenharmony_ci     *
89094332d3Sopenharmony_ci     * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
90094332d3Sopenharmony_ci     * @since 1.0
91094332d3Sopenharmony_ci     * @version 1.0
92094332d3Sopenharmony_ci     */
93094332d3Sopenharmony_ci    void *(*MmapCache)(BufferHandle *handle);
94094332d3Sopenharmony_ci
95094332d3Sopenharmony_ci    /**
96094332d3Sopenharmony_ci     * @brief Unmaps memory, that is, removes any mappings from the process's address space.
97094332d3Sopenharmony_ci     *
98094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the memory to unmap.
99094332d3Sopenharmony_ci     *
100094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
101094332d3Sopenharmony_ci     * otherwise.
102094332d3Sopenharmony_ci     * @since 1.0
103094332d3Sopenharmony_ci     * @version 1.0
104094332d3Sopenharmony_ci     */
105094332d3Sopenharmony_ci    int32_t (*Unmap)(BufferHandle *handle);
106094332d3Sopenharmony_ci
107094332d3Sopenharmony_ci    /**
108094332d3Sopenharmony_ci     * @brief Flushes data from the cache to memory and invalidates the data in the cache.
109094332d3Sopenharmony_ci     *
110094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the cache to flush.
111094332d3Sopenharmony_ci     *
112094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
113094332d3Sopenharmony_ci     * otherwise.
114094332d3Sopenharmony_ci     * @since 1.0
115094332d3Sopenharmony_ci     * @version 1.0
116094332d3Sopenharmony_ci     */
117094332d3Sopenharmony_ci    int32_t (*FlushCache)(BufferHandle *handle);
118094332d3Sopenharmony_ci
119094332d3Sopenharmony_ci    /**
120094332d3Sopenharmony_ci     * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache.
121094332d3Sopenharmony_ci     *
122094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the cache to flush.
123094332d3Sopenharmony_ci     *
124094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
125094332d3Sopenharmony_ci     * otherwise.
126094332d3Sopenharmony_ci     * @since 1.0
127094332d3Sopenharmony_ci     * @version 1.0
128094332d3Sopenharmony_ci     */
129094332d3Sopenharmony_ci    int32_t (*FlushMCache)(BufferHandle *handle);
130094332d3Sopenharmony_ci
131094332d3Sopenharmony_ci    /**
132094332d3Sopenharmony_ci     * @brief Invalidates the cache to update it from memory.
133094332d3Sopenharmony_ci     *
134094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the cache, which will been invalidated.
135094332d3Sopenharmony_ci     *
136094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
137094332d3Sopenharmony_ci     * otherwise.
138094332d3Sopenharmony_ci     * @since 1.0
139094332d3Sopenharmony_ci     * @version 1.0
140094332d3Sopenharmony_ci     */
141094332d3Sopenharmony_ci    int32_t (*InvalidateCache)(BufferHandle* handle);
142094332d3Sopenharmony_ci
143094332d3Sopenharmony_ci    /**
144094332d3Sopenharmony_ci     * @brief Checks whether the given VerifyAllocInfo array is allocatable.
145094332d3Sopenharmony_ci     *
146094332d3Sopenharmony_ci     * @param num Indicates the size of infos array.
147094332d3Sopenharmony_ci     * @param infos Indicates the pointer to the VerifyAllocInfo array.
148094332d3Sopenharmony_ci     * @param supporteds Indicates the pointer to the array that can be allocated.
149094332d3Sopenharmony_ci     *
150094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
151094332d3Sopenharmony_ci     * otherwise.
152094332d3Sopenharmony_ci     * @since 1.0
153094332d3Sopenharmony_ci     * @version 1.0
154094332d3Sopenharmony_ci     */
155094332d3Sopenharmony_ci    int32_t (*IsSupportedAlloc)(uint32_t num, const VerifyAllocInfo *infos, bool *supporteds);
156094332d3Sopenharmony_ci
157094332d3Sopenharmony_ci    /**
158094332d3Sopenharmony_ci     * @brief Maps memory for YUV.
159094332d3Sopenharmony_ci     *
160094332d3Sopenharmony_ci     * @param handle Indicates the pointer to the buffer of the memory to map.
161094332d3Sopenharmony_ci     * @param info Indicates the pointer to the YUVDescInfo of the memory to map.
162094332d3Sopenharmony_ci     *
163094332d3Sopenharmony_ci     * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise.
164094332d3Sopenharmony_ci     * @since 3.2
165094332d3Sopenharmony_ci     * @version 1.0
166094332d3Sopenharmony_ci     */
167094332d3Sopenharmony_ci    void *(*MmapYUV)(BufferHandle *handle, YUVDescInfo *info);
168094332d3Sopenharmony_ci} GrallocFuncs;
169094332d3Sopenharmony_ci
170094332d3Sopenharmony_ci/**
171094332d3Sopenharmony_ci * @brief Initializes the memory module to obtain the pointer to functions for memory operations.
172094332d3Sopenharmony_ci *
173094332d3Sopenharmony_ci * @param funcs Indicates the double pointer to functions for memory operations. Memory is allocated automatically when
174094332d3Sopenharmony_ci * you initiate the memory module initialization, so you can simply use the pointer to gain access to the functions.
175094332d3Sopenharmony_ci *
176094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
177094332d3Sopenharmony_ci * otherwise.
178094332d3Sopenharmony_ci * @since 1.0
179094332d3Sopenharmony_ci * @version 1.0
180094332d3Sopenharmony_ci */
181094332d3Sopenharmony_ciint32_t GrallocInitialize(GrallocFuncs **funcs);
182094332d3Sopenharmony_ci
183094332d3Sopenharmony_ci/**
184094332d3Sopenharmony_ci * @brief Deinitializes the memory module to release the memory allocated to the pointer to functions for memory
185094332d3Sopenharmony_ci * operations.
186094332d3Sopenharmony_ci *
187094332d3Sopenharmony_ci * @param funcs Indicates the pointer to functions for memory operations.
188094332d3Sopenharmony_ci *
189094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
190094332d3Sopenharmony_ci * otherwise.
191094332d3Sopenharmony_ci * @since 1.0
192094332d3Sopenharmony_ci * @version 1.0
193094332d3Sopenharmony_ci */
194094332d3Sopenharmony_ciint32_t GrallocUninitialize(GrallocFuncs *funcs);
195094332d3Sopenharmony_ci
196094332d3Sopenharmony_ci#ifdef __cplusplus
197094332d3Sopenharmony_ci}
198094332d3Sopenharmony_ci#endif
199094332d3Sopenharmony_ci#endif
200094332d3Sopenharmony_ci/** @} */
201