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