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 <refbase.h> 21 #include <mutex> 22 #include "vsync_generator.h" 23 #include "graphic_common.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class VSyncController : public VSyncGenerator::Callback { 28 public: 29 class Callback { 30 public: 31 virtual void OnVSyncEvent(int64_t now, int64_t period) = 0; 32 virtual ~Callback() = default; 33 }; 34 35 VSyncController(const sptr<VSyncGenerator> &geng, int64_t offset); 36 ~VSyncController(); 37 38 // nocopyable 39 VSyncController(const VSyncController &) = delete; 40 VSyncController &operator=(const VSyncController &) = delete; 41 42 VsyncError SetEnable(bool enable, bool& isGeneratorEnable); 43 VsyncError SetCallback(Callback* cb); 44 VsyncError SetPhaseOffset(int64_t offset); 45 46 private: 47 48 void OnVSyncEvent(int64_t now, int64_t period); 49 wptr<VSyncGenerator> generator_; 50 std::mutex callbackMutex_; 51 Callback* callback_; 52 53 std::mutex offsetMutex_; 54 int64_t phaseOffset_; 55 bool enabled_; 56 }; 57 } // namespace Rosen 58 } // namespace OHOS 59 60 #endif 61