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 * As all the UI event handling is driven by the render tick, and to make sure the the event handling is 65 * in JS task, the HAL layer will transfer the TE event into the loop of JS task, when JS application go forground. 66 */ 67 typedef void (*RenderTEHandler)(); 68 typedef void (*VoidFuncHook)(); 69 70 /** 71 * The hook for screen on visible. 72 */ 73 typedef bool (*SetScreenOnVisibleHandler)(bool visible); 74 75 /** 76 * The wrapper data structure for get native memory pool info. 77 */ 78 struct TEHandlingHooks { 79 RenderTEHandler renderTEHandler; 80 VoidFuncHook renderEndHandler; 81 }; 82 83 enum TEDispatchingResult : uint8_t { 84 REFUSED = 0, // not on forground, will refuse TE, vsync should send it to other 85 ACCEPTED, // on forground, and TE event is received successfully 86 ACCEPT_FAILED, // on forground, but TE event can not be received, vsync should be retried to send to ACE again 87 }; 88 89 /** 90 * The wrapper data structure for get native memory pool info. 91 */ 92 struct ExtraPresetModulesHook { 93 VoidFuncHook loadingHandler; 94 VoidFuncHook unloadingHandler; 95 }; 96 97 /** 98 * The wrapper class for some product feature implementation, since some interfaces are provided by specific product. 99 */ 100 class ProductAdapter final { 101 public: 102 ProductAdapter(const ProductAdapter &) = delete; 103 ProductAdapter &operator=(const ProductAdapter &) = delete; 104 ProductAdapter(ProductAdapter &&) = delete; 105 ProductAdapter &operator=(ProductAdapter &&) = delete; 106 ProductAdapter() = delete; 107 ~ProductAdapter() = delete; 108 109 // initialization functions 110 static void InitTraceHandlers(EventPrintHandler eventHandler, ErrCodePrintHandler errCodeHandler); 111 static void InitAceTags(uint8_t *aceTags, uint8_t tagCount); 112 static void InitConsoleNativeHandler(JSLogOutputHandler handler); 113 static void InitNativeMemPoolHook(NativeMemInfoGetter getter); 114 static void InitExtraModulesGetter(ProductModulesGetter productModuleGetter, 115 PrivateModulesGetter privateModuleGetter); 116 static void InitDeviceInfo(const char *deviceType); 117 static void RegTerminatingHandler(TerminateAbilityHandler handler); 118 static void RegTEHandlers(const TEHandlingHooks &teHandlingHooks); 119 static TEDispatchingResult DispatchTEMessage(); 120 static void SetDefaultFontStyle(const char *defaultFontFamily, uint8_t defaultFontSize); 121 static void SetScreenSize(uint16_t width, uint16_t height); 122 static void RegSetScreenOnVisibleHandler(SetScreenOnVisibleHandler handler); 123 static void RegExtraPresetModulesHook(ExtraPresetModulesHook hook); 124 static void ConfigPrivateDataRootPath(const char *appDataRoot); 125 126 // wrapper functions, for ace internal calling 127 static void PrintEventTrace(uint8_t info2, uint8_t info3, uint8_t info4); 128 static void PrintErrCode(uint8_t info2, uint16_t rfu); 129 static void OutputJSConsoleLog(uint8_t level, const char *content); 130 static void GetNativeMemInfo(NativeMemInfo *memInfo); 131 static void SendTerminatingRequest(uint32_t token, bool forceStop); 132 static bool IsTEHandlersRegisted(); 133 static void ProcessOneTE(); 134 static void NotifyRenderEnd(); 135 static const char *GetDefaultFontFamilyName(); 136 static uint8_t GetDefaultFontSize(); 137 static void UpdateRenderTickAcceptable(bool acceptable); 138 static void GetScreenSize(uint16_t &width, uint16_t &height); 139 static const char *GetDeviceType(); 140 static bool SetScreenOnVisible(bool visible); 141 static void LoadExtraPresetModules(); 142 static void UnloadExtraPresetModules(); 143 static const char *GetPrivateDataRootPath(); 144 }; 145 } // namespace ACELite 146 } // namespace OHOS 147 #endif // OHOS_ACELITE_ACE_DFX_ADAPTER_H 148