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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_UI_DISPLAY_SYNC_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_UI_DISPLAY_SYNC_MANAGER_H 18 19 #include <unordered_map> 20 #include <mutex> 21 22 #include "base/memory/ace_type.h" 23 #include "base/utils/utils.h" 24 #include "base/log/log.h" 25 #include "base/utils/base_id.h" 26 #include "base/log/ace_trace.h" 27 #include "base/utils/system_properties.h" 28 #include "ui_display_sync.h" 29 30 namespace OHOS::Ace { 31 using IdType = uint64_t; 32 using IdToDisplaySyncMap = std::unordered_map<IdType, WeakPtr<UIDisplaySync>>; 33 34 class ACE_FORCE_EXPORT UIDisplaySyncManager : public AceType { 35 DECLARE_ACE_TYPE(UIDisplaySyncManager, AceType) 36 public: 37 bool AddDisplaySync(const RefPtr<UIDisplaySync>& displaySync); 38 bool RemoveDisplaySync(const RefPtr<UIDisplaySync>& displaySync); 39 bool HasDisplaySync(const RefPtr<UIDisplaySync>& displaySync); 40 41 void DispatchFunc(uint64_t nanoTimestamp); 42 43 bool SetVsyncRate(int32_t vsyncRate); 44 int32_t GetVsyncRate() const; 45 bool SetVsyncPeriod(int64_t vsyncPeriod); 46 int64_t GetVsyncPeriod() const; 47 bool SetRefreshRateMode(int32_t refreshRateMode); 48 int32_t GetRefreshRateMode() const; 49 int32_t GetDisplaySyncRate() const; 50 IdToDisplaySyncMap GetUIDisplaySyncMap() const; 51 void CheckSkipEnableProperty(); 52 bool IsSupportSkip() const; 53 bool IsAutoRefreshRateMode() const; 54 bool IsNonAutoRefreshRateMode() const; 55 56 UIDisplaySyncManager(); 57 ~UIDisplaySyncManager() noexcept override; 58 59 private: 60 static const std::vector<int32_t> REFRESH_RATE_LIST; 61 static constexpr int32_t ERROR_DELTA = 3; 62 static constexpr float SECOND_IN_NANO = 1000000000.0f; 63 64 int32_t sourceVsyncRate_ = 0; 65 int64_t vsyncPeriod_ = 0; 66 int32_t refreshRateMode_ = 0; 67 RefPtr<FrameRateRange> displaySyncRange_ = AceType::MakeRefPtr<FrameRateRange>(); 68 69 IdToDisplaySyncMap uiDisplaySyncMap_; 70 std::once_flag isEnablePropertyFlag_; 71 bool supportSkipEnabled_ = true; 72 }; 73 } // namespace OHOS::Ace 74 75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_UI_DISPLAY_SYNC_MANAGER_H 76