1 /* 2 * Copyright (c) 2021 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 17 #ifndef VSYNC_VSYNC_CONTROLLER_H 18 #define VSYNC_VSYNC_CONTROLLER_H 19 20 #include <cstdint> 21 #include <refbase.h> 22 #include <mutex> 23 #include "vsync_generator.h" 24 #include "graphic_common.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class VSyncController : public VSyncGenerator::Callback { 29 public: 30 class Callback { 31 public: 32 virtual void OnVSyncEvent(int64_t now, int64_t period, 33 uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) = 0; 34 virtual ~Callback() = default; 35 /* std::pair<id, refresh rate> */ 36 virtual void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) = 0; 37 }; 38 39 VSyncController(const sptr<VSyncGenerator> &geng, int64_t offset); 40 ~VSyncController(); 41 42 // nocopyable 43 VSyncController(const VSyncController &) = delete; 44 VSyncController &operator=(const VSyncController &) = delete; 45 46 VsyncError SetEnable(bool enable, bool& isGeneratorEnable); 47 VsyncError SetCallback(Callback* cb); 48 VsyncError SetPhaseOffset(int64_t offset); 49 50 private: 51 52 void OnVSyncEvent(int64_t now, int64_t period, 53 uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate); 54 void OnPhaseOffsetChanged(int64_t phaseOffset); 55 /* std::pair<id, refresh rate> */ 56 void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates); 57 wptr<VSyncGenerator> generator_; 58 std::mutex callbackMutex_; 59 Callback* callback_; 60 61 std::mutex offsetMutex_; 62 int64_t phaseOffset_; 63 bool enabled_; 64 }; 65 } // namespace Rosen 66 } // namespace OHOS 67 68 #endif 69