1 /*
2 * Copyright (c) 2020-2021 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 #include "monitor.h"
17
18 #include "common/graphic_startup.h"
19 #include "common/image_decode_ability.h"
20 #include "common/input_device_manager.h"
21 #include "draw/draw_utils.h"
22 #include "font/ui_font.h"
23 #include "font/ui_font_header.h"
24 #if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
25 #include "font/ui_font_vector.h"
26 #else
27 #include "common/ui_text_language.h"
28 #include "font/ui_font_bitmap.h"
29 #endif
30 #include "key_input.h"
31 #include "mouse_input.h"
32 #include "mousewheel_input.h"
33 #include "windows.h"
34
35 namespace OHOS {
36 bool Monitor::isRegister_ = false;
37
GetInstance()38 Monitor* Monitor::GetInstance()
39 {
40 static Monitor instance;
41 if (!isRegister_) {
42 BaseGfxEngine::InitGfxEngine(&instance);
43 isRegister_ = true;
44 }
45 return &instance;
46 }
47
InitHal()48 void Monitor::InitHal()
49 {
50 #if defined(USE_MOUSE) && USE_MOUSE
51 MouseInput* mouse = MouseInput::GetInstance();
52 InputDeviceManager::GetInstance()->Add(mouse);
53 #endif
54
55 #if defined(USE_MOUSEWHEEL) && defined(ENABLE_ROTATE_INPUT) && USE_MOUSEWHEEL && ENABLE_ROTATE_INPUT
56 MousewheelInput* mousewheel = MousewheelInput::GetInstance();
57 InputDeviceManager::GetInstance()->Add(mousewheel);
58 #endif
59
60 #if defined(USE_KEY) && USE_KEY
61 KeyInput* key = KeyInput::GetInstance();
62 InputDeviceManager::GetInstance()->Add(key);
63 #endif
64 }
65
GetFBBufferInfo()66 BufferInfo* Monitor::GetFBBufferInfo()
67 {
68 static BufferInfo* bufferInfo = nullptr;
69 if (bufferInfo == nullptr) {
70 bufferInfo = new BufferInfo;
71 bufferInfo->rect = {0, 0, HORIZONTAL_RESOLUTION - 1, VERTICAL_RESOLUTION - 1};
72 bufferInfo->mode = ARGB8888;
73 bufferInfo->color = 0x44;
74 bufferInfo->phyAddr = bufferInfo->virAddr = tftFb_;
75 // 3: Shift right 3 bits
76 bufferInfo->stride = HORIZONTAL_RESOLUTION * (DrawUtils::GetPxSizeByColorMode(bufferInfo->mode) >> 3);
77 bufferInfo->width = HORIZONTAL_RESOLUTION;
78 bufferInfo->height = VERTICAL_RESOLUTION;
79 }
80 return bufferInfo;
81 }
82
Flush(const Rect & rect)83 void Monitor::Flush(const Rect &rect)
84 {
85 UpdatePaint(tftFb_, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
86 }
87
88 // assuming below are the memory pool
89 static uint8_t g_fontMemBaseAddr[OHOS::MIN_FONT_PSRAM_LENGTH];
90 #if defined(ENABLE_ICU) && ENABLE_ICU
91 static uint8_t g_icuMemBaseAddr[OHOS::SHAPING_WORD_DICT_LENGTH];
92 #endif
93
InitFontEngine()94 void Monitor::InitFontEngine()
95 {
96 #if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
97 GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH,
98 VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME);
99 #else
100 BitmapFontInit();
101 std::string dPath(_pgmptr);
102 size_t len = dPath.size();
103 size_t pos = dPath.find_last_of('\\');
104 dPath.replace((pos + 1), (len - pos), "..\\..\\simulator\\font\\font.bin");
105 GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH,
106 dPath.c_str(), nullptr);
107 #endif
108
109 #if defined(ENABLE_ICU) && ENABLE_ICU
110 GraphicStartUp::InitLineBreakEngine(reinterpret_cast<uintptr_t>(g_icuMemBaseAddr), SHAPING_WORD_DICT_LENGTH,
111 VECTOR_FONT_DIR, DEFAULT_LINE_BREAK_RULE_FILENAME);
112 #endif
113 }
114
InitImageDecodeAbility()115 void Monitor::InitImageDecodeAbility()
116 {
117 uint32_t imageType = IMG_SUPPORT_BITMAP | OHOS::IMG_SUPPORT_JPEG | OHOS::IMG_SUPPORT_PNG;
118 ImageDecodeAbility::GetInstance().SetImageDecodeAbility(imageType);
119 }
120
GUILoopStart() const121 void Monitor::GUILoopStart() const
122 {
123 Sleep(GUI_REFR_PERIOD);
124 }
125
InitGUI()126 void Monitor::InitGUI()
127 {
128 for (uint32_t i = 0; i < HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION; i++) {
129 tftFb_[i] = defaultColor_;
130 }
131 UpdatePaint(tftFb_, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
132 }
133
GUILoopQuit() const134 void Monitor::GUILoopQuit() const {}
135 } // namespace OHOS
136