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 if (isUniRender) {
43 return std::atoi((system::GetParameter("rosen.parallelcomposition.enabled", "0")).c_str()) != 0;
44 }
45 return _s_parallelCompositionLoaded &&
46 std::atoi((system::GetParameter("rosen.parallelcomposition.enabled", "0")).c_str()) != 0;
47 }
48
UpdateQosVsyncEnabled()49 bool RSInnovation::UpdateQosVsyncEnabled()
50 {
51 return _s_qosVsyncFuncLoaded &&
52 (std::atoi((system::GetParameter("rosen.qos_vsync.enabled", "0")).c_str()) != 0);
53 }
54
GetParallelCompositionFunc()55 void RSInnovation::GetParallelCompositionFunc()
56 {
57 if (innovationHandle) {
58 _s_createParallelSyncSignal = dlsym(innovationHandle, "CreateParallelSyncSignal");
59 _s_signalCountDown = dlsym(innovationHandle, "SignalCountDown");
60 _s_signalAwait = dlsym(innovationHandle, "SignalAwait");
61 _s_assignTask = dlsym(innovationHandle, "AssignTask");
62 _s_removeStoppedThreads = dlsym(innovationHandle, "RemoveStoppedThreads");
63 _s_checkForSerialForced = dlsym(innovationHandle, "CheckForSerialForced");
64 _s_parallelCompositionLoaded =
65 (_s_createParallelSyncSignal != nullptr) &&
66 (_s_signalCountDown != nullptr) &&
67 (_s_signalAwait != nullptr) &&
68 (_s_assignTask != nullptr) &&
69 (_s_removeStoppedThreads != nullptr) &&
70 (_s_checkForSerialForced != nullptr);
71 }
72 }
73
ResetParallelCompositionFunc()74 void RSInnovation::ResetParallelCompositionFunc()
75 {
76 if (_s_parallelCompositionLoaded) {
77 _s_parallelCompositionLoaded = false;
78 _s_createParallelSyncSignal = nullptr;
79 _s_signalCountDown = nullptr;
80 _s_signalAwait = nullptr;
81 _s_assignTask = nullptr;
82 _s_removeStoppedThreads = nullptr;
83 _s_checkForSerialForced = nullptr;
84 }
85 }
86
GetQosVSyncFunc()87 void RSInnovation::GetQosVSyncFunc()
88 {
89 if (innovationHandle) {
90 _s_createRSQosService = dlsym(innovationHandle, "CreateRSQosService");
91 _s_qosThreadStart = dlsym(innovationHandle, "QosThreadStart");
92 _s_qosThreadStop = dlsym(innovationHandle, "QosThreadStop");
93 _s_qosSetBoundaryRate = dlsym(innovationHandle, "QosSetBoundaryRate");
94 _s_qosOnRSVisibilityChangeCB = dlsym(innovationHandle, "QosOnRSVisibilityChangeCB");
95 _s_qosRegisteFuncCB = dlsym(innovationHandle, "QosRegisteFuncCB");
96 _s_qosOnRSResetPid = dlsym(innovationHandle, "QosOnRSResetPid");
97 _s_qosVsyncFuncLoaded = (_s_createRSQosService != nullptr) &&
98 (_s_qosThreadStart != nullptr) &&
99 (_s_qosThreadStop != nullptr) &&
100 (_s_qosSetBoundaryRate != nullptr) &&
101 (_s_qosOnRSVisibilityChangeCB != nullptr) &&
102 (_s_qosRegisteFuncCB != nullptr) &&
103 (_s_qosOnRSResetPid != nullptr);
104 }
105 }
106
ResetQosVsyncFunc()107 void RSInnovation::ResetQosVsyncFunc()
108 {
109 if (_s_qosVsyncFuncLoaded) {
110 _s_qosVsyncFuncLoaded = false;
111 _s_createRSQosService = nullptr;
112 _s_qosThreadStart = nullptr;
113 _s_qosThreadStop = nullptr;
114 _s_qosSetBoundaryRate = nullptr;
115 _s_qosOnRSVisibilityChangeCB = nullptr;
116 _s_qosRegisteFuncCB = nullptr;
117 _s_qosOnRSResetPid = nullptr;
118 }
119 }
120 } // namespace Rosen
121 } // namespace OHOS
122