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 RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_PARALLEL_RENDER_EXT_H 17 #define RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_PARALLEL_RENDER_EXT_H 18 #include <cstdint> 19 #include <dlfcn.h> 20 namespace OHOS { 21 namespace Rosen { 22 class RSParallelRenderExt { 23 public: ~RSParallelRenderExt()24 ~RSParallelRenderExt() 25 { 26 CloseParallelRenderExt(); 27 } 28 OpenParallelRenderExt()29 static bool OpenParallelRenderExt() 30 { 31 if (parallelRenderExtHandle_) { 32 return true; 33 } 34 parallelRenderExtHandle_ = dlopen("libparallel_render.z.so", RTLD_NOW); 35 if (parallelRenderExtHandle_ == nullptr) { 36 return false; 37 } 38 return GetParallelRenderEnable(); 39 } 40 CloseParallelRenderExt()41 static void CloseParallelRenderExt() 42 { 43 if (parallelRenderExtHandle_) { 44 dlclose(parallelRenderExtHandle_); 45 FreeFuncHandle(); 46 } 47 } 48 49 static inline void* parallelRenderExtHandle_ = nullptr; 50 static inline void* initParallelRenderLBFunc_ = nullptr; 51 static inline void* setSubRenderThreadNumFunc_ = nullptr; 52 static inline void* addRenderLoadFunc_ = nullptr; 53 static inline void* updateLoadCostFunc_ = nullptr; 54 static inline void* loadBalancingFunc_ = nullptr; 55 static inline void* clearRenderLoadFunc_ = nullptr; 56 static inline void* freeParallelRenderLBFunc_ = nullptr; 57 static inline void* setCoreLevelFunc_ = nullptr; 58 static inline void* updateNodeCostFunc_ = nullptr; 59 static inline void* getCostFactorFunc_ = nullptr; 60 61 private: 62 RSParallelRenderExt() = default; 63 GetParallelRenderEnable()64 static bool GetParallelRenderEnable() 65 { 66 return GetInitParallelRenderLoadBalancingFunc() && 67 GetSetSubRenderThreadNumFunc() && 68 GetAddRenderLoadFunc() && 69 GetUpdateLoadCostFunc() && 70 GetLoadBalancingFunc() && 71 GetClearRenderLoadFunc() && 72 GetFreeParallelRenderLoadBalancing() && 73 GetSetCoreLevelFunc() && 74 GetUpdateNodeCostFunc() && 75 GetGetCostFactorFunc(); 76 } 77 GetInitParallelRenderLoadBalancingFunc()78 static bool GetInitParallelRenderLoadBalancingFunc() 79 { 80 initParallelRenderLBFunc_ = dlsym(parallelRenderExtHandle_, "InitParallelRenderLoadBalancing"); 81 return initParallelRenderLBFunc_ != nullptr; 82 } 83 GetSetSubRenderThreadNumFunc()84 static bool GetSetSubRenderThreadNumFunc() 85 { 86 setSubRenderThreadNumFunc_ = dlsym(parallelRenderExtHandle_, "SetSubRenderThreadNum"); 87 return setSubRenderThreadNumFunc_ != nullptr; 88 } 89 GetAddRenderLoadFunc()90 static bool GetAddRenderLoadFunc() 91 { 92 addRenderLoadFunc_ = dlsym(parallelRenderExtHandle_, "AddRenderLoad"); 93 return addRenderLoadFunc_ != nullptr; 94 } 95 GetUpdateLoadCostFunc()96 static bool GetUpdateLoadCostFunc() 97 { 98 updateLoadCostFunc_ = dlsym(parallelRenderExtHandle_, "UpdateLoadCost"); 99 return updateLoadCostFunc_ != nullptr; 100 } 101 GetLoadBalancingFunc()102 static bool GetLoadBalancingFunc() 103 { 104 loadBalancingFunc_ = dlsym(parallelRenderExtHandle_, "LoadBalancing"); 105 return loadBalancingFunc_ != nullptr; 106 } 107 GetClearRenderLoadFunc()108 static bool GetClearRenderLoadFunc() 109 { 110 clearRenderLoadFunc_ = dlsym(parallelRenderExtHandle_, "ClearRenderLoad"); 111 return clearRenderLoadFunc_ != nullptr; 112 } 113 GetFreeParallelRenderLoadBalancing()114 static bool GetFreeParallelRenderLoadBalancing() 115 { 116 freeParallelRenderLBFunc_ = dlsym(parallelRenderExtHandle_, "FreeParallelRenderLoadBalancing"); 117 return freeParallelRenderLBFunc_ != nullptr; 118 } 119 GetSetCoreLevelFunc()120 static bool GetSetCoreLevelFunc() 121 { 122 setCoreLevelFunc_ = dlsym(parallelRenderExtHandle_, "SetCoreLevel"); 123 return setCoreLevelFunc_ != nullptr; 124 } 125 GetUpdateNodeCostFunc()126 static bool GetUpdateNodeCostFunc() 127 { 128 updateNodeCostFunc_ = dlsym(parallelRenderExtHandle_, "UpdateNodeCost"); 129 return updateNodeCostFunc_ != nullptr; 130 } 131 GetGetCostFactorFunc()132 static bool GetGetCostFactorFunc() 133 { 134 getCostFactorFunc_ = dlsym(parallelRenderExtHandle_, "GetCostFactor"); 135 return getCostFactorFunc_ != nullptr; 136 } 137 FreeFuncHandle()138 static void FreeFuncHandle() 139 { 140 parallelRenderExtHandle_ = nullptr; 141 initParallelRenderLBFunc_ = nullptr; 142 setSubRenderThreadNumFunc_ = nullptr; 143 addRenderLoadFunc_ = nullptr; 144 updateLoadCostFunc_ = nullptr; 145 loadBalancingFunc_ = nullptr; 146 clearRenderLoadFunc_ = nullptr; 147 freeParallelRenderLBFunc_ = nullptr; 148 setCoreLevelFunc_ = nullptr; 149 updateNodeCostFunc_ = nullptr; 150 getCostFactorFunc_ = nullptr; 151 } 152 }; 153 154 } // namespace Rosen 155 } // namespace OHOS 156 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_PARALLEL_RENDER_EXT_H