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 #ifndef HGM_VSYNC_GENERATOR_CONTROLLER_H 17 #define HGM_VSYNC_GENERATOR_CONTROLLER_H 18 19 #include <unordered_map> 20 #include <vector> 21 22 #include "common/rs_common_def.h" 23 #include "vsync_controller.h" 24 #include "vsync_generator.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class HgmVSyncGeneratorController { 29 public: 30 HgmVSyncGeneratorController(sptr<VSyncController> rsController, 31 sptr<VSyncController> appController, sptr<VSyncGenerator> vsyncGenerator); 32 ~HgmVSyncGeneratorController(); 33 34 static int32_t GetAppOffset(const uint32_t controllerRate); 35 uint64_t CalcVSyncQuickTriggerTime(uint64_t lastVSyncTime, uint32_t lastRate); 36 int64_t ChangeGeneratorRate(const uint32_t controllerRate, 37 const std::vector<std::pair<FrameRateLinkerId, uint32_t>>& appData, 38 uint64_t targetTime = 0, 39 bool isNeedUpdateAppOffset = false); GetCurrentRate()40 uint32_t GetCurrentRate() const { return currentRate_; } GetCurrentOffset()41 int64_t GetCurrentOffset() const { return currentOffset_; } GetPulseNum()42 int32_t GetPulseNum() const { return pulseNum_; } 43 static bool CheckNeedUpdateAppOffsetRefreshRate(uint32_t refreshRate); 44 void ChangeAdaptiveStatus(bool isAdaptive); 45 private: 46 sptr<VSyncController> rsController_; 47 sptr<VSyncController> appController_; 48 sptr<VSyncGenerator> vsyncGenerator_; 49 uint32_t currentRate_ = 0; 50 int32_t currentOffset_ = 0; 51 int32_t pulseNum_ = -1; 52 }; 53 } // namespace Rosen 54 } // namespace OHOS 55 #endif // HGM_VSYNC_GENERATOR_CONTROLLER_H