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)20ArkVSyncAdapterWrapper::ArkVSyncAdapterWrapper(ArkWebRefPtr<ArkVSyncAdapter> ref) : ctocpp_(ref) {} 21 RequestVsync(void * data,OHOS::NWeb::NWebVSyncCb cb)22OHOS::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()31int64_t ArkVSyncAdapterWrapper::GetVSyncPeriod() 32 { 33 if (!ctocpp_) { 34 return 0; 35 } 36 return ctocpp_->GetVSyncPeriod(); 37 } 38 SetFrameRateLinkerEnable(bool enabled)39void ArkVSyncAdapterWrapper::SetFrameRateLinkerEnable(bool enabled) 40 { 41 if (!ctocpp_) { 42 return; 43 } 44 return ctocpp_->SetFrameRateLinkerEnable(enabled); 45 } 46 SetFramePreferredRate(int32_t preferredRate)47void ArkVSyncAdapterWrapper::SetFramePreferredRate(int32_t preferredRate) 48 { 49 if (!ctocpp_) { 50 return; 51 } 52 return ctocpp_->SetFramePreferredRate(preferredRate); 53 } 54 SetOnVsyncCallback(OnVsyncCallback callback)55void ArkVSyncAdapterWrapper::SetOnVsyncCallback(OnVsyncCallback callback) 56 { 57 if (!ctocpp_) { 58 return; 59 } 60 return ctocpp_->SetOnVsyncCallback(callback); 61 } 62 SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback)63void ArkVSyncAdapterWrapper::SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback) 64 { 65 if (!ctocpp_) { 66 return; 67 } 68 return ctocpp_->SetOnVsyncEndCallback(onVsyncEndCallback); 69 } 70 71 } // namespace OHOS::ArkWeb 72