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 // Start of DVSync 33 virtual void OnDVSyncEvent(int64_t now, int64_t period, 34 uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) = 0; 35 // End of DVSync 36 virtual void OnVSyncEvent(int64_t now, int64_t period, 37 uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) = 0; 38 virtual ~Callback() = default; 39 /* std::pair<id, refresh rate> */ 40 virtual void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) = 0; 41 }; 42 43 VSyncController(const sptr<VSyncGenerator> &geng, int64_t offset); 44 ~VSyncController(); 45 46 // nocopyable 47 VSyncController(const VSyncController &) = delete; 48 VSyncController &operator=(const VSyncController &) = delete; 49 50 virtual VsyncError SetEnable(bool enable, bool& isGeneratorEnable); 51 VsyncError SetCallback(Callback* cb); 52 VsyncError SetPhaseOffset(int64_t offset); 53 54 private: 55 friend class DVSyncController; 56 void OnVSyncEvent(int64_t now, int64_t period, 57 uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate); 58 void OnPhaseOffsetChanged(int64_t phaseOffset); 59 /* std::pair<id, refresh rate> */ 60 void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates); 61 wptr<VSyncGenerator> generator_; 62 std::mutex callbackMutex_; 63 Callback* callback_; 64 65 std::mutex offsetMutex_; 66 int64_t phaseOffset_; 67 bool enabled_; 68 }; 69 } // namespace Rosen 70 } // namespace OHOS 71 72 #endif 73