1/* 2 * Copyright (c) 2020-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 "window/window.h" 17 18#include "window/window_impl.h" 19 20namespace OHOS { 21Window* Window::CreateWindow(const WindowConfig& config) 22{ 23 WindowImpl* window = new WindowImpl; 24 if (window != nullptr) { 25 if (!window->Create(config)) { 26 delete window; 27 return nullptr; 28 } 29 window->AddToDisplay(); 30 } 31 return window; 32} 33 34void Window::DestroyWindow(Window* window) 35{ 36 if (window != nullptr) { 37 WindowImpl* windowImpl = dynamic_cast<WindowImpl*>(window); 38 if (windowImpl != nullptr) { 39 windowImpl->RemoveFromDisplay(); 40 windowImpl->UnbindRootView(); 41 windowImpl->Destroy(); 42 delete windowImpl; 43 windowImpl = nullptr; 44 window = nullptr; 45 } 46 } 47} 48} 49