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