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 GetOcclusionCullingFunc();
28 GetQosVSyncFunc();
29 }
30
CloseInnovationSo()31 void RSInnovation::CloseInnovationSo()
32 {
33 if (innovationHandle) {
34 ResetParallelCompositionFunc();
35 ResetOcclusionCullingFunc();
36 ResetQosVsyncFunc();
37 dlclose(innovationHandle);
38 }
39 }
40
41 // parallel composition
GetParallelCompositionEnabled()42 bool RSInnovation::GetParallelCompositionEnabled()
43 {
44 return _s_parallelCompositionLoaded &&
45 std::atoi((system::GetParameter("rosen.parallelcomposition.enabled", "0")).c_str()) != 0;
46 }
47
48 // occlusion culling
UpdateOcclusionCullingSoEnabled()49 void RSInnovation::UpdateOcclusionCullingSoEnabled()
50 {
51 _s_occlusionCullingSoEnabled =
52 std::atoi((system::GetParameter("rosen.occlusion.so.enabled", "0")).c_str()) != 0;
53 }
54
UpdateQosVsyncEnabled()55 bool RSInnovation::UpdateQosVsyncEnabled()
56 {
57 return _s_qosVsyncFuncLoaded &&
58 (std::atoi((system::GetParameter("rosen.qos_vsync.enabled", "0")).c_str()) != 0);
59 }
60
GetParallelCompositionFunc()61 void RSInnovation::GetParallelCompositionFunc()
62 {
63 if (innovationHandle) {
64 _s_createParallelSyncSignal = dlsym(innovationHandle, "CreateParallelSyncSignal");
65 _s_signalCountDown = dlsym(innovationHandle, "SignalCountDown");
66 _s_signalAwait = dlsym(innovationHandle, "SignalAwait");
67 _s_assignTask = dlsym(innovationHandle, "AssignTask");
68 _s_removeStoppedThreads = dlsym(innovationHandle, "RemoveStoppedThreads");
69 _s_checkForSerialForced = dlsym(innovationHandle, "CheckForSerialForced");
70 _s_parallelCompositionLoaded =
71 (_s_createParallelSyncSignal != nullptr) &&
72 (_s_signalCountDown != nullptr) &&
73 (_s_signalAwait != nullptr) &&
74 (_s_assignTask != nullptr) &&
75 (_s_removeStoppedThreads != nullptr) &&
76 (_s_checkForSerialForced != nullptr);
77 }
78 }
79
ResetParallelCompositionFunc()80 void RSInnovation::ResetParallelCompositionFunc()
81 {
82 if (_s_parallelCompositionLoaded) {
83 _s_parallelCompositionLoaded = false;
84 _s_createParallelSyncSignal = nullptr;
85 _s_signalCountDown = nullptr;
86 _s_signalAwait = nullptr;
87 _s_assignTask = nullptr;
88 _s_removeStoppedThreads = nullptr;
89 _s_checkForSerialForced = nullptr;
90 }
91 }
92
GetOcclusionCullingFunc()93 void RSInnovation::GetOcclusionCullingFunc()
94 {
95 if (innovationHandle) {
96 _s_regionOpFromSo = dlsym(innovationHandle, "RegionOpFromSO");
97 _s_occlusionCullingFuncLoaded = (_s_regionOpFromSo != nullptr);
98 }
99 }
100
ResetOcclusionCullingFunc()101 void RSInnovation::ResetOcclusionCullingFunc()
102 {
103 if (_s_occlusionCullingFuncLoaded) {
104 _s_regionOpFromSo = nullptr;
105 }
106 }
107
GetQosVSyncFunc()108 void RSInnovation::GetQosVSyncFunc()
109 {
110 if (innovationHandle) {
111 _s_createRSQosService = dlsym(innovationHandle, "CreateRSQosService");
112 _s_qosThreadStart = dlsym(innovationHandle, "QosThreadStart");
113 _s_qosThreadStop = dlsym(innovationHandle, "QosThreadStop");
114 _s_qosSetBoundaryRate = dlsym(innovationHandle, "QosSetBoundaryRate");
115 _s_qosOnRSVisibilityChangeCB = dlsym(innovationHandle, "QosOnRSVisibilityChangeCB");
116 _s_qosRegisteFuncCB = dlsym(innovationHandle, "QosRegisteFuncCB");
117 _s_qosOnRSResetPid = dlsym(innovationHandle, "QosOnRSResetPid");
118 _s_qosVsyncFuncLoaded = (_s_createRSQosService != nullptr) &&
119 (_s_qosThreadStart != nullptr) &&
120 (_s_qosThreadStop != nullptr) &&
121 (_s_qosSetBoundaryRate != nullptr) &&
122 (_s_qosOnRSVisibilityChangeCB != nullptr) &&
123 (_s_qosRegisteFuncCB != nullptr) &&
124 (_s_qosOnRSResetPid != nullptr);
125 }
126 }
127
ResetQosVsyncFunc()128 void RSInnovation::ResetQosVsyncFunc()
129 {
130 if (_s_qosVsyncFuncLoaded) {
131 _s_qosVsyncFuncLoaded = false;
132 _s_createRSQosService = nullptr;
133 _s_qosThreadStart = nullptr;
134 _s_qosThreadStop = nullptr;
135 _s_qosSetBoundaryRate = nullptr;
136 _s_qosOnRSVisibilityChangeCB = nullptr;
137 _s_qosRegisteFuncCB = nullptr;
138 _s_qosOnRSResetPid = nullptr;
139 }
140 }
141 } // namespace Rosen
142 } // namespace OHOS
143