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 FBDEV_DRIVER_H
17#define FBDEV_DRIVER_H
18
19#include "display_drv.h"
20#include "nocopyable.h"
21#include <cstdint>
22#include <linux/fb.h>
23#include <string>
24
25namespace OHOS {
26namespace PowerMgr {
27struct FbBufferObject {
28    uint32_t width {};
29    uint32_t height {};
30    uint32_t size {};
31    void* vaddr {};
32};
33
34class FbdevDriver : public DisplayDrv {
35    DISALLOW_COPY_AND_MOVE(FbdevDriver);
36    using FbBlankHook = std::function<void(int, bool)>;
37
38public:
39    FbdevDriver() = default;
40    ~FbdevDriver() override;
41    bool Init() override;
42    void Flip(const uint8_t* buf) override;
43    void GetDisplayInfo(DisplayInfo& dsInfo) override;
44    void Blank(bool blank) override;
45    void Exit() override;
46    static void SetDevPath(const std::string& devPath);
47    static void RegisterBlankHook(FbBlankHook blankHook);
48
49private:
50    void ReleaseFb(const struct FbBufferObject* fbo);
51    struct FbBufferObject buff_ {};
52    struct fb_fix_screeninfo finfo_ {};
53    struct fb_var_screeninfo vinfo_ {};
54    bool FbPowerContrl(int fd, bool powerOn);
55    static inline std::string devPath_ = FB_DEV_PATH;
56    static inline FbBlankHook blankHook_ {};
57};
58} // namespace PowerMgr
59} // namespace OHOS
60#endif
61