1 /* 2 * Copyright (c) 2024 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 #ifndef CJFFI_DISPLAY_SYNC_IMPL_H 16 #define CJFFI_DISPLAY_SYNC_IMPL_H 17 18 #include <mutex> 19 #include <string> 20 21 #include "core/components_ng/manager/display_sync/ui_display_sync.h" 22 #include "display_sync_common.h" 23 #include "ffi_remote_data.h" 24 #include "interfaces/native/native_animate.h" 25 26 namespace OHOS { 27 namespace DisplaySync { 28 29 class DisplaySync { 30 public: 31 DisplaySync() = delete; DisplaySync(const Ace::RefPtr<Ace::UIDisplaySync> & uiDisplaySync)32 explicit DisplaySync(const Ace::RefPtr<Ace::UIDisplaySync>& uiDisplaySync) 33 : uiDisplaySync_(uiDisplaySync) {} 34 ~DisplaySync()35 ~DisplaySync() 36 { 37 if (uiDisplaySync_) { 38 uiDisplaySync_->DelFromPipelineOnContainer(); 39 } 40 } 41 GetUIDisplaySync()42 Ace::RefPtr<Ace::UIDisplaySync> GetUIDisplaySync() const 43 { 44 return uiDisplaySync_; 45 } 46 47 void RegisterOnFrameCallback(void (*callback)(CIntervalInfo)); 48 void UnregisterOnFrameCallback(void (*callback)(CIntervalInfo)); 49 50 private: 51 Ace::RefPtr<Ace::UIDisplaySync> uiDisplaySync_; 52 std::mutex mutex_; 53 }; 54 55 class DisplaySyncImpl : public OHOS::FFI::FFIData { 56 public: 57 DisplaySyncImpl(); 58 ~DisplaySyncImpl() = default; 59 60 int32_t SetExpectedFrameRateRange(CFrameRateRange cRateRange); 61 int32_t On(char* type, void (*callback)(CIntervalInfo)); 62 int32_t Off(char* type, void (*callback)(CIntervalInfo)); 63 int32_t Start(); 64 int32_t Stop(); 65 66 private: 67 std::shared_ptr<OHOS::DisplaySync::DisplaySync> displaySync_; 68 }; 69 } 70 } // namespace OHOS::DisplaySync 71 72 #endif // DISPLAY_SYNC_IMPL_H 73