• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     using FbBrightnessHook = std::function<void(const std::string &devPath, bool blank)>;
38 public:
39     FbdevDriver() = default;
40     ~FbdevDriver() override;
41     bool Init() override;
42     void Flip(const uint8_t *buf) override;
43     void GetGrSurface(GrSurface &surface) override;
44     void Blank(bool blank) override;
45     void Exit(void) override;
46     static void SetDevPath(const std::string &devPath);
47     static void RegisterBlankHook(FbBlankHook blankHook);
48     static void RegisterBrightnessHook(FbBrightnessHook brightness);
49 private:
50     void FBLog() const;
51     void ReleaseFb(const struct FbBufferObject *fbo);
52     struct FbBufferObject buff_ {};
53     struct fb_fix_screeninfo finfo_ {};
54     struct fb_var_screeninfo vinfo_ {};
55     bool FbPowerContrl(int fd, bool powerOn);
56     static inline std::string devPath_ = FB_DEV_PATH;
57     static inline FbBlankHook blankHook_ {};
58     static inline FbBrightnessHook brightnessHook_ {};
59 };
60 } // namespace Updater
61 #endif
62