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 #include "platform/common/rs_innovation.h"
17
18 #include <dlfcn.h>
19 #include <parameters.h>
20
21 namespace OHOS {
22 namespace Rosen {
OpenInnovationSo()23 void RSInnovation::OpenInnovationSo()
24 {
25 innovationHandle = dlopen("libgraphic_innovation.z.so", RTLD_NOW);
26 GetParallelCompositionFunc();
27 GetQosVSyncFunc();
28 }
29
CloseInnovationSo()30 void RSInnovation::CloseInnovationSo()
31 {
32 if (innovationHandle) {
33 ResetParallelCompositionFunc();
34 ResetQosVsyncFunc();
35 dlclose(innovationHandle);
36 }
37 }
38
39 // parallel composition
GetParallelCompositionEnabled(bool isUniRender)40 bool RSInnovation::GetParallelCompositionEnabled(bool isUniRender)
41 {
42 static bool parallelcompositionEnabled =
43 std::atoi((system::GetParameter("persist.rosen.parallelcomposition.enabled", "0")).c_str()) != 0;
44 if (isUniRender) {
45 return parallelcompositionEnabled;
46 }
47 return _s_parallelCompositionLoaded && parallelcompositionEnabled;
48 }
49
UpdateQosVsyncEnabled()50 bool RSInnovation::UpdateQosVsyncEnabled()
51 {
52 static bool qosVsyncEnabled = std::atoi((system::GetParameter(
53 "persist.rosen.qos_vsync.enabled", "0")).c_str()) != 0;
54 return _s_qosVsyncFuncLoaded && qosVsyncEnabled;
55 }
56
GetParallelCompositionFunc()57 void RSInnovation::GetParallelCompositionFunc()
58 {
59 if (innovationHandle) {
60 _s_createParallelSyncSignal = dlsym(innovationHandle, "CreateParallelSyncSignal");
61 _s_signalCountDown = dlsym(innovationHandle, "SignalCountDown");
62 _s_signalAwait = dlsym(innovationHandle, "SignalAwait");
63 _s_assignTask = dlsym(innovationHandle, "AssignTask");
64 _s_removeStoppedThreads = dlsym(innovationHandle, "RemoveStoppedThreads");
65 _s_checkForSerialForced = dlsym(innovationHandle, "CheckForSerialForced");
66 _s_parallelCompositionLoaded =
67 (_s_createParallelSyncSignal != nullptr) &&
68 (_s_signalCountDown != nullptr) &&
69 (_s_signalAwait != nullptr) &&
70 (_s_assignTask != nullptr) &&
71 (_s_removeStoppedThreads != nullptr) &&
72 (_s_checkForSerialForced != nullptr);
73 }
74 }
75
ResetParallelCompositionFunc()76 void RSInnovation::ResetParallelCompositionFunc()
77 {
78 if (_s_parallelCompositionLoaded) {
79 _s_parallelCompositionLoaded = false;
80 _s_createParallelSyncSignal = nullptr;
81 _s_signalCountDown = nullptr;
82 _s_signalAwait = nullptr;
83 _s_assignTask = nullptr;
84 _s_removeStoppedThreads = nullptr;
85 _s_checkForSerialForced = nullptr;
86 }
87 }
88
GetQosVSyncFunc()89 void RSInnovation::GetQosVSyncFunc()
90 {
91 if (innovationHandle) {
92 _s_createRSQosService = dlsym(innovationHandle, "CreateRSQosService");
93 _s_qosThreadStart = dlsym(innovationHandle, "QosThreadStart");
94 _s_qosThreadStop = dlsym(innovationHandle, "QosThreadStop");
95 _s_qosSetBoundaryRate = dlsym(innovationHandle, "QosSetBoundaryRate");
96 _s_qosOnRSVisibilityChangeCB = dlsym(innovationHandle, "QosOnRSVisibilityChangeCB");
97 _s_qosRegisteFuncCB = dlsym(innovationHandle, "QosRegisteFuncCB");
98 _s_qosOnRSResetPid = dlsym(innovationHandle, "QosOnRSResetPid");
99 _s_qosVsyncFuncLoaded = (_s_createRSQosService != nullptr) &&
100 (_s_qosThreadStart != nullptr) &&
101 (_s_qosThreadStop != nullptr) &&
102 (_s_qosSetBoundaryRate != nullptr) &&
103 (_s_qosOnRSVisibilityChangeCB != nullptr) &&
104 (_s_qosRegisteFuncCB != nullptr) &&
105 (_s_qosOnRSResetPid != nullptr);
106 }
107 }
108
ResetQosVsyncFunc()109 void RSInnovation::ResetQosVsyncFunc()
110 {
111 if (_s_qosVsyncFuncLoaded) {
112 _s_qosVsyncFuncLoaded = false;
113 _s_createRSQosService = nullptr;
114 _s_qosThreadStart = nullptr;
115 _s_qosThreadStop = nullptr;
116 _s_qosSetBoundaryRate = nullptr;
117 _s_qosOnRSVisibilityChangeCB = nullptr;
118 _s_qosRegisteFuncCB = nullptr;
119 _s_qosOnRSResetPid = nullptr;
120 }
121 }
122 } // namespace Rosen
123 } // namespace OHOS
124