• 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_GRAPHIC_ENGINE_H
17 #define UPDATER_UI_GRAPHIC_ENGINE_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <thread>
22 #include "engines/gfx/soft_engine.h"
23 #include "macros_updater.h"
24 #include "surface_dev.h"
25 
26 namespace Updater {
27 class GraphicEngine : public OHOS::SoftEngine {
28     DISALLOW_COPY_MOVE(GraphicEngine);
29 public:
30     static constexpr uint32_t THREAD_USLEEP_TIME = 10000;
31     GraphicEngine() = default;
32     virtual ~GraphicEngine() = default;
33     static GraphicEngine &GetInstance();
34     void Init(uint32_t bkgColor, uint8_t mode, const char *fontPath);
35     void Flush(const OHOS::Rect& flushRect) override;
36     OHOS::BufferInfo *GetFBBufferInfo() override;
37     uint16_t GetScreenWidth() override;
38     uint16_t GetScreenHeight() override;
39     void StopEngine(void);
40     void SetSleepTime(uint32_t sleepTime);
41     void HandleScreenPowerDown(bool blank);
42 private:
43     void FlushThreadLoop() const;
44     void InitFontEngine(const char *fontPath) const;
45     void InitImageDecodeAbility() const;
46     void InitFlushThread();
47     std::thread flushLoop_;
48     std::unique_ptr<OHOS::BufferInfo> buffInfo_ = nullptr;
49     std::unique_ptr<uint8_t[]> virAddr_ = nullptr;
50     std::unique_ptr<SurfaceDev> sfDev_ = nullptr;
51     uint32_t bkgColor_ = 0;
52     uint16_t height_ = 0;
53     uint16_t width_ = 0;
54     uint8_t colorMode_ = 0;
55     bool flushStop_ = true;
56     uint32_t sleepTime_ = THREAD_USLEEP_TIME;
57     std::mutex mtx_ {};
58 };
59 
60 #ifdef __cplusplus
61 #if __cplusplus
62 extern "C" {
63 #endif
64 #endif /* __cplusplus */
65 void InitFlushBatteryStatusExt(void);
66 void PostInitSurfDev(std::unique_ptr<SurfaceDev> &surfDev, GrSurface &surface);
67 #ifdef __cplusplus
68 #if __cplusplus
69 }
70 #endif
71 #endif /* __cplusplus */
72 } // namespace Updater
73 #endif
74