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 #include "core/common/flutter/flutter_window.h" 17 18 #include <functional> 19 20 #include "flutter/runtime/window_manager.h" 21 22 #include "base/log/log.h" 23 #include "base/utils/utils.h" 24 #include "core/common/ace_view.h" 25 #include "core/pipeline/base/render_node.h" 26 27 namespace OHOS::Ace { 28 Create(AceView * view)29std::unique_ptr<PlatformWindow> PlatformWindow::Create(AceView* view) 30 { 31 CHECK_NULL_RETURN_NOLOG(view, nullptr); 32 return std::make_unique<Platform::FlutterWindow>(view->GetInstanceId()); 33 } 34 35 namespace Platform { 36 FlutterWindow(int32_t instanceId)37FlutterWindow::FlutterWindow(int32_t instanceId) : instanceId_(instanceId) {} 38 ~FlutterWindow()39FlutterWindow::~FlutterWindow() {} 40 Destroy()41void FlutterWindow::Destroy() 42 { 43 auto window = flutter::WindowManager::GetWindow(instanceId_); 44 if (window != nullptr) { 45 window->SetBeginFrameCallback(nullptr); 46 } 47 vsyncCallbacks_.clear(); 48 } 49 RequestFrame()50void FlutterWindow::RequestFrame() 51 { 52 auto window = flutter::WindowManager::GetWindow(instanceId_); 53 CHECK_NULL_VOID_NOLOG(window); 54 window->ScheduleFrame(); 55 if (!window->HasBeginFrameCallback()) { 56 window->SetBeginFrameCallback(std::bind(&FlutterWindow::OnVsyncCallback, this, std::placeholders::_1)); 57 } 58 } 59 RegisterVsyncCallback(AceVsyncCallback && callback)60void FlutterWindow::RegisterVsyncCallback(AceVsyncCallback&& callback) 61 { 62 vsyncCallbacks_.emplace_back(std::move(callback)); 63 } 64 SetRootRenderNode(const RefPtr<RenderNode> & root)65void FlutterWindow::SetRootRenderNode(const RefPtr<RenderNode>& root) {} 66 OnVsyncCallback(uint64_t timeStampNanos)67void FlutterWindow::OnVsyncCallback(uint64_t timeStampNanos) 68 { 69 for (const auto& vsyncCallback : vsyncCallbacks_) { 70 vsyncCallback(timeStampNanos, 0); 71 } 72 } 73 74 } // namespace Platform 75 } // namespace OHOS::Ace 76