1 /* 2 * Copyright (c) 2023 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 CHARGER_GRAPHIC_ENGINE_H 17 #define CHARGER_GRAPHIC_ENGINE_H 18 19 #include "dev/graphic_dev.h" 20 #include "engines/gfx/soft_engine.h" 21 #include <memory> 22 #include <mutex> 23 #include <thread> 24 25 namespace OHOS { 26 namespace PowerMgr { 27 class ChargerGraphicEngine : public OHOS::SoftEngine { 28 static constexpr uint32_t THREAD_USLEEP_TIME = 10000; 29 DISALLOW_COPY_AND_MOVE(ChargerGraphicEngine); 30 31 public: 32 ChargerGraphicEngine() = default; 33 virtual ~ChargerGraphicEngine() = default; 34 static ChargerGraphicEngine& GetInstance(); 35 void Init(uint32_t bkgColor, uint8_t mode, const char* fontPath, const char* ttfName); 36 void Flush(const OHOS::Rect& flushRect) override; 37 OHOS::BufferInfo* GetFBBufferInfo() override; 38 uint16_t GetScreenWidth() override; 39 uint16_t GetScreenHeight() override; 40 41 static void UsSleep(int usec); 42 43 private: 44 void FlushThreadLoop(); 45 void InitFontEngine(const char* fontPath, const char* ttfName); 46 void InitImageDecodeAbility(); 47 void InitFlushThread(); 48 std::thread flushLoop_; 49 std::unique_ptr<OHOS::BufferInfo> buffInfo_ = nullptr; 50 std::unique_ptr<uint8_t[]> virAddr_ = nullptr; 51 std::unique_ptr<GraphicDev> sfDev_ = nullptr; 52 uint32_t bkgColor_ = 0; 53 uint16_t height_ = 0; 54 uint16_t width_ = 0; 55 uint8_t colorMode_ = 0; 56 bool flushStop_ = true; 57 std::mutex mtx_ {}; 58 }; 59 } // namespace PowerMgr 60 } // namespace OHOS 61 #endif 62