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 void ChangeGeneratorRate(const uint32_t controllerRate, 37 const std::vector<std::pair<FrameRateLinkerId, uint32_t>>& appData, 38 uint64_t targetTime = 0, 39 bool isNeedUpdateAppOffset = false); 40 uint32_t GetCurrentRate() const; 41 int64_t GetCurrentOffset() const; 42 private: 43 sptr<VSyncController> rsController_; 44 sptr<VSyncController> appController_; 45 sptr<VSyncGenerator> vsyncGenerator_; 46 uint32_t currentRate_ = 0; 47 int32_t currentOffset_ = 0; 48 }; 49 } // namespace Rosen 50 } // namespace OHOS 51 #endif // HGM_VSYNC_GENERATOR_CONTROLLER_H