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 private:
42     void FlushThreadLoop() const;
43     void InitFontEngine(const char *fontPath) const;
44     void InitImageDecodeAbility() const;
45     void InitFlushThread();
46     std::thread flushLoop_;
47     std::unique_ptr<OHOS::BufferInfo> buffInfo_ = nullptr;
48     std::unique_ptr<uint8_t[]> virAddr_ = nullptr;
49     std::unique_ptr<SurfaceDev> sfDev_ = nullptr;
50     uint32_t bkgColor_ = 0;
51     uint16_t height_ = 0;
52     uint16_t width_ = 0;
53     uint8_t colorMode_ = 0;
54     bool flushStop_ = true;
55     uint32_t sleepTime_ = THREAD_USLEEP_TIME;
56     std::mutex mtx_ {};
57 };
58 
59 #ifdef __cplusplus
60 #if __cplusplus
61 extern "C" {
62 #endif
63 #endif /* __cplusplus */
64 void InitFlushBatteryStatusExt(void);
65 void PostInitSurfDev(std::unique_ptr<SurfaceDev> &surfDev, GrSurface &surface);
66 #ifdef __cplusplus
67 #if __cplusplus
68 }
69 #endif
70 #endif /* __cplusplus */
71 } // namespace Updater
72 #endif
73