1 /*
2  * Copyright (c) 2022 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 DISPLAY_ADAPTER_H
17 #define DISPLAY_ADAPTER_H
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 #include "display_adapter_interface.h"
22 #include "display_module_loader.h"
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace DISPLAY {
27 using AdapterInitFunc = int32_t (*)(DisplayAdapterFuncs **funcs);
28 using AdapterDeInitFunc = int32_t (*)(DisplayAdapterFuncs *funcs);
29 
30 class DisplayAdapter {
31 public:
32     static std::unique_ptr<DisplayAdapter> &GetInstance();
33     virtual ~DisplayAdapter();
34 
35     int32_t Init();
36     int32_t OpenDevice(const std::string &pathName, int32_t flags, mode_t mode);
37     int32_t CloseDevice(int32_t devFd);
38     int32_t Ioctl(int32_t devFd, uint32_t cmd, void *args);
39     int32_t FbGetDmaBuffer(int32_t devFd);
40     int32_t FbFresh(int32_t devFd, DisplayFrameInfo &frame);
41 
42 private:
43     static constexpr const char *LIB_NAME_ADAPTER = "libdisplay_adapter_impl.z.so";
44     static constexpr const char *INIT_FUNCTION_NAME = "DisplayAdapaterInitialize";
45     static constexpr const char *DEINIT_FUNCTION_NAME = "DisplayAdapaterUninitialize";
46 
47     std::unique_ptr<DisplayModuleLoader> loader_;
48     DisplayAdapterFuncs *funcs_ = nullptr;
49     AdapterInitFunc initFunc_ = nullptr;
50     AdapterDeInitFunc deInitFunc_ = nullptr;
51 };
52 } // namespace DISPLAY
53 } // namespace HDI
54 } // namespace OHOS
55 #endif // DISPLAY_ADAPTER_INTERFACE_H