• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef OHOS_ACELITE_ACE_DFX_ADAPTER_H
17 #define OHOS_ACELITE_ACE_DFX_ADAPTER_H
18 
19 #include <cstdint>
20 #include "jsi_types.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 /**
25  * This handler type is so specific for product, should be designed from OS dfx level.
26  */
27 typedef void (*EventPrintHandler)(uint8_t info1, uint8_t info2, uint8_t info3, uint8_t info4);
28 typedef void (*ErrCodePrintHandler)(uint8_t info1, uint8_t info2, uint8_t info3, uint16_t info4);
29 
30 /**
31  * The hook for outputing user's console log.
32  */
33 typedef void (*JSLogOutputHandler)(uint8_t level, const char *content);
34 
35 /**
36  * The wrapper data structure for get native memory pool info.
37  */
38 struct NativeMemInfo {
39     uint32_t totalSize; /* mem pool total size */
40     uint32_t freeSize;  /* total free size */
41 };
42 
43 /**
44  * Native memory pool info getter.
45  */
46 typedef void (*NativeMemInfoGetter)(NativeMemInfo *memInfo);
47 
48 /**
49  * Product modules hook.
50  */
51 typedef Module *(*ProductModulesGetter)(uint16_t &moduleCount);
52 
53 /**
54  * Private modules hook.
55  */
56 typedef PrivateModule *(*PrivateModulesGetter)(uint16_t &moduleCount);
57 
58 /**
59  * The hook for terminating ability.
60  */
61 typedef void (*TerminateAbilityHandler)(uint32_t token, bool forceStop);
62 
63 /**
64  * The hook for restore fail dump message.
65  */
66 typedef void (*RestoreSystemHandler)(const char *crashMessage);
67 
68 /**
69  * The hook for determining the capability of supporting PNG and JPG image formats.
70  */
71 typedef bool (*IsPNGSupportedHandler)(const char *imagePath, const char *bundleName);
72 
73 /**
74  * The hook for set component views parameters.
75  */
76 typedef void (*SetViewsParaHandler)(void *ComponentHandler);
77 
78 /**
79  * As all the UI event handling is driven by the render tick, and to make sure the the event handling is
80  * in JS task, the HAL layer will transfer the TE event into the loop of JS task, when JS application go foreground.
81  */
82 typedef void (*RenderTEHandler)();
83 typedef void (*VoidFuncHook)();
84 
85 /**
86  * The hook for screen on visible.
87  */
88 typedef bool (*SetScreenOnVisibleHandler)(bool visible);
89 
90 /**
91  * The wrapper data structure for get native memory pool info.
92  */
93 struct TEHandlingHooks {
94     RenderTEHandler renderTEHandler;
95     VoidFuncHook renderEndHandler;
96 };
97 
98 enum TEDispatchingResult : uint8_t {
99     REFUSED = 0, // not on foreground, will refuse TE, vsync should send it to other
100     ACCEPTED, // on foreground, and TE event is received successfully
101     ACCEPT_FAILED, // on foreground, but TE event can not be received, vsync should be retried to send to ACE again
102 };
103 
104 /**
105  * The wrapper data structure for get native memory pool info.
106  */
107 struct ExtraPresetModulesHook {
108     VoidFuncHook loadingHandler;
109     VoidFuncHook unloadingHandler;
110 };
111 
112 /**
113  * The wrapper class for some product feature implementation, since some interfaces are provided by specific product.
114  */
115 class ProductAdapter final {
116 public:
117     ProductAdapter(const ProductAdapter &) = delete;
118     ProductAdapter &operator=(const ProductAdapter &) = delete;
119     ProductAdapter(ProductAdapter &&) = delete;
120     ProductAdapter &operator=(ProductAdapter &&) = delete;
121     ProductAdapter() = delete;
122     ~ProductAdapter() = delete;
123 
124     // initialization functions
125     static void InitTraceHandlers(EventPrintHandler eventHandler, ErrCodePrintHandler errCodeHandler);
126     static void InitAceTags(uint8_t *aceTags, uint8_t tagCount);
127     static void InitConsoleNativeHandler(JSLogOutputHandler handler);
128     static void InitNativeMemPoolHook(NativeMemInfoGetter getter);
129     static void InitExtraModulesGetter(ProductModulesGetter productModuleGetter,
130                                        PrivateModulesGetter privateModuleGetter);
131     static void InitDeviceInfo(const char *deviceType);
132     static void RegTerminatingHandler(TerminateAbilityHandler handler);
133     static void RegTEHandlers(const TEHandlingHooks &teHandlingHooks);
134     static TEDispatchingResult DispatchTEMessage();
135     static void SetDefaultFontStyle(const char *defaultFontFamily, uint8_t defaultFontSize);
136     static void SetScreenSize(uint16_t width, uint16_t height);
137     static void RegSetScreenOnVisibleHandler(SetScreenOnVisibleHandler handler);
138     static void RegExtraPresetModulesHook(ExtraPresetModulesHook hook);
139     static void ConfigPrivateDataRootPath(const char *appDataRoot);
140     static void RegRestoreSystemHandler(RestoreSystemHandler handler);
141     static void RegIsPNGSupportedHandler(IsPNGSupportedHandler handler);
142     static void RegSetViewsParaHandler(SetViewsParaHandler handler);
143 
144     // wrapper functions, for ace internal calling
145     static void PrintEventTrace(uint8_t info2, uint8_t info3, uint8_t info4);
146     static void PrintErrCode(uint8_t info2, uint16_t rfu);
147     static void OutputJSConsoleLog(uint8_t level, const char *content);
148     static void GetNativeMemInfo(NativeMemInfo *memInfo);
149     static void SendTerminatingRequest(uint32_t token, bool forceStop);
150     static bool IsTEHandlersRegisted();
151     static void ProcessOneTE();
152     static void NotifyRenderEnd();
153     static const char *GetDefaultFontFamilyName();
154     static uint8_t GetDefaultFontSize();
155     static void UpdateRenderTickAcceptable(bool acceptable);
156     static void GetScreenSize(uint16_t &width, uint16_t &height);
157     static const char *GetDeviceType();
158     static bool SetScreenOnVisible(bool visible);
159     static void LoadExtraPresetModules();
160     static void UnloadExtraPresetModules();
161     static const char *GetPrivateDataRootPath();
162     static void RestoreSystemWrapper(const char *crashMessage);
163     static bool IsPNGSupportedWrapper(const char *imagePath, const char *bundleName);
164     static void SetViewsParaWrapper(void *ComponentHandler);
165 };
166 } // namespace ACELite
167 } // namespace OHOS
168 #endif // OHOS_ACELITE_ACE_DFX_ADAPTER_H
169