1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_VSYNC_STATION_H 17e0dac50fSopenharmony_ci#define OHOS_VSYNC_STATION_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <memory> 20e0dac50fSopenharmony_ci#include <unordered_set> 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_ci#include <event_handler.h> 23e0dac50fSopenharmony_ci#include <ui/rs_display_node.h> 24e0dac50fSopenharmony_ci#include <vsync_receiver.h> 25e0dac50fSopenharmony_ci 26e0dac50fSopenharmony_ci#include "wm_common.h" 27e0dac50fSopenharmony_ci 28e0dac50fSopenharmony_cinamespace OHOS { 29e0dac50fSopenharmony_cinamespace Rosen { 30e0dac50fSopenharmony_ciclass RSFrameRateLinker; 31e0dac50fSopenharmony_ci 32e0dac50fSopenharmony_ciclass VsyncStation : public std::enable_shared_from_this<VsyncStation> { 33e0dac50fSopenharmony_cipublic: 34e0dac50fSopenharmony_ci explicit VsyncStation(NodeId nodeId, 35e0dac50fSopenharmony_ci const std::shared_ptr<AppExecFwk::EventHandler>& vsyncHandler = nullptr); 36e0dac50fSopenharmony_ci ~VsyncStation(); 37e0dac50fSopenharmony_ci 38e0dac50fSopenharmony_ci bool IsVsyncReceiverCreated(); 39e0dac50fSopenharmony_ci void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback); 40e0dac50fSopenharmony_ci int64_t GetVSyncPeriod(); 41e0dac50fSopenharmony_ci void RemoveCallback(); 42e0dac50fSopenharmony_ci void Destroy(); 43e0dac50fSopenharmony_ci 44e0dac50fSopenharmony_ci FrameRateLinkerId GetFrameRateLinkerId(); 45e0dac50fSopenharmony_ci void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0); 46e0dac50fSopenharmony_ci void SetFrameRateLinkerEnable(bool enabled); 47e0dac50fSopenharmony_ci void SetDisplaySoloistFrameRateLinkerEnable(bool enabled); 48e0dac50fSopenharmony_ci void SetUiDvsyncSwitch(bool dvsyncSwitch); 49e0dac50fSopenharmony_ci 50e0dac50fSopenharmony_ciprivate: 51e0dac50fSopenharmony_ci std::shared_ptr<VSyncReceiver> GetOrCreateVsyncReceiver(); 52e0dac50fSopenharmony_ci std::shared_ptr<VSyncReceiver> GetOrCreateVsyncReceiverLocked(); 53e0dac50fSopenharmony_ci std::shared_ptr<RSFrameRateLinker> GetFrameRateLinker(); 54e0dac50fSopenharmony_ci void VsyncCallbackInner(int64_t nanoTimestamp, int64_t frameCount); 55e0dac50fSopenharmony_ci void OnVsyncTimeOut(); 56e0dac50fSopenharmony_ci 57e0dac50fSopenharmony_ci NodeId nodeId_ = 0; 58e0dac50fSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> vsyncHandler_ = nullptr; 59e0dac50fSopenharmony_ci std::string vsyncTimeoutTaskName_; 60e0dac50fSopenharmony_ci 61e0dac50fSopenharmony_ci std::mutex mutex_; 62e0dac50fSopenharmony_ci bool isFirstVsyncRequest_ = true; 63e0dac50fSopenharmony_ci bool isFirstVsyncBack_ = true; 64e0dac50fSopenharmony_ci bool destroyed_ = false; 65e0dac50fSopenharmony_ci bool hasRequestedVsync_ = false; 66e0dac50fSopenharmony_ci std::shared_ptr<VSyncReceiver> receiver_ = nullptr; 67e0dac50fSopenharmony_ci std::shared_ptr<RSFrameRateLinker> frameRateLinker_ = nullptr; 68e0dac50fSopenharmony_ci using Callbacks = std::unordered_set<std::shared_ptr<VsyncCallback>>; 69e0dac50fSopenharmony_ci Callbacks vsyncCallbacks_; 70e0dac50fSopenharmony_ci // Above guarded by mutex_ 71e0dac50fSopenharmony_ci}; 72e0dac50fSopenharmony_ci} // namespace Rosen 73e0dac50fSopenharmony_ci} // namespace OHOS 74e0dac50fSopenharmony_ci#endif // OHOS_VSYNC_STATION_H