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 #include "ohos_adapter/bridge/ark_vsync_adapter_wrapper.h"
17
18 namespace OHOS::ArkWeb {
19
ArkVSyncAdapterWrapper(ArkWebRefPtr<ArkVSyncAdapter> ref)20 ArkVSyncAdapterWrapper::ArkVSyncAdapterWrapper(ArkWebRefPtr<ArkVSyncAdapter> ref) : ctocpp_(ref) {}
21
RequestVsync(void * data,OHOS::NWeb::NWebVSyncCb cb)22 OHOS::NWeb::VSyncErrorCode ArkVSyncAdapterWrapper::RequestVsync(void* data, OHOS::NWeb::NWebVSyncCb cb)
23 {
24 if (!ctocpp_) {
25 return OHOS::NWeb::VSyncErrorCode::ERROR;
26 }
27 uint32_t result = ctocpp_->RequestVsync(data, reinterpret_cast<void*>(cb));
28 return (OHOS::NWeb::VSyncErrorCode)result;
29 }
30
GetVSyncPeriod()31 int64_t ArkVSyncAdapterWrapper::GetVSyncPeriod()
32 {
33 if (!ctocpp_) {
34 return 0;
35 }
36 return ctocpp_->GetVSyncPeriod();
37 }
38
SetFrameRateLinkerEnable(bool enabled)39 void ArkVSyncAdapterWrapper::SetFrameRateLinkerEnable(bool enabled)
40 {
41 if (!ctocpp_) {
42 return;
43 }
44 return ctocpp_->SetFrameRateLinkerEnable(enabled);
45 }
46
SetFramePreferredRate(int32_t preferredRate)47 void ArkVSyncAdapterWrapper::SetFramePreferredRate(int32_t preferredRate)
48 {
49 if (!ctocpp_) {
50 return;
51 }
52 return ctocpp_->SetFramePreferredRate(preferredRate);
53 }
54
SetOnVsyncCallback(OnVsyncCallback callback)55 void ArkVSyncAdapterWrapper::SetOnVsyncCallback(OnVsyncCallback callback)
56 {
57 if (!ctocpp_) {
58 return;
59 }
60 return ctocpp_->SetOnVsyncCallback(callback);
61 }
62
SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback)63 void ArkVSyncAdapterWrapper::SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback)
64 {
65 if (!ctocpp_) {
66 return;
67 }
68 return ctocpp_->SetOnVsyncEndCallback(onVsyncEndCallback);
69 }
70
SetScene(const std::string & sceneName,uint32_t state)71 void ArkVSyncAdapterWrapper::SetScene(const std::string& sceneName, uint32_t state)
72 {
73 if (!ctocpp_) {
74 return;
75 }
76 ArkWebString ark_value = ArkWebStringClassToStruct(sceneName);
77 ctocpp_->SetScene(ark_value, state);
78 ArkWebStringStructRelease(ark_value);
79 }
80
SetDVSyncSwitch(bool dvsyncSwitch)81 void ArkVSyncAdapterWrapper::SetDVSyncSwitch(bool dvsyncSwitch)
82 {
83 if (!ctocpp_) {
84 return;
85 }
86 return ctocpp_->SetDVSyncSwitch(dvsyncSwitch);
87 }
88 } // namespace OHOS::ArkWeb
89