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