• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_utils_test.h"
17 
18 #include "define_multimodal.h"
19 #include "mmi_log.h"
20 #include "wm_common.h"
21 
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "WindowUtilsTest" };
26 constexpr int32_t IMAGE_WIDTH = 720;
27 constexpr int32_t IMAGE_HEIGHT = 1280;
28 constexpr uint32_t defaultWindowId = -1;
29 std::string windowName = "WindowUtilsTest";
30 } // namespace
31 
~WindowUtilsTest()32 WindowUtilsTest::~WindowUtilsTest()
33 {
34     ClearTestWindow();
35 }
36 
GetInstance()37 std::shared_ptr<WindowUtilsTest> WindowUtilsTest::GetInstance()
38 {
39     if (windowUtils_ == nullptr) {
40         windowUtils_ = std::make_shared<WindowUtilsTest>();
41     }
42     return windowUtils_;
43 }
44 
ClearTestWindow()45 void WindowUtilsTest::ClearTestWindow()
46 {
47     CALL_DEBUG_ENTER;
48     CHKPV(testWindow_);
49     testWindow_->Destroy();
50 }
51 
DrawTestWindow()52 bool WindowUtilsTest::DrawTestWindow()
53 {
54     CALL_DEBUG_ENTER;
55     testWindow_ = Rosen::Window::Find(windowName);
56     if (testWindow_ == nullptr) {
57         CreateSmoothWindow();
58     }
59 
60     CHKPF(testWindow_);
61     return testWindow_->Show() == Rosen::WMError::WM_OK;
62 }
63 
GetWindow()64 sptr<Rosen::Window>& WindowUtilsTest::GetWindow()
65 {
66     return testWindow_;
67 }
68 
GetWindowId()69 uint32_t WindowUtilsTest::GetWindowId()
70 {
71     CHKPR(testWindow_, defaultWindowId);
72     return testWindow_->GetWindowId();
73 }
74 
CreateSmoothWindow()75 void WindowUtilsTest::CreateSmoothWindow()
76 {
77     TestWindowInfo info = {
78         .name = windowName,
79         .rect = {
80             .posX_ = 0,
81             .posY_ = 0,
82             .width_ = IMAGE_WIDTH,
83             .height_ = IMAGE_HEIGHT,
84         },
85         .type = Rosen::WindowType::WINDOW_TYPE_SCREENSHOT,
86         .mode = Rosen::WindowMode::WINDOW_MODE_FULLSCREEN,
87         .needAvoid = false,
88         .parentLimit = false,
89         .parentId = Rosen::INVALID_WINDOW_ID,
90     };
91     testWindow_ = CreateWindow(info);
92 }
93 
CreateWindow(const TestWindowInfo & info)94 sptr<Rosen::Window> WindowUtilsTest::CreateWindow(const TestWindowInfo& info)
95 {
96     sptr<Rosen::WindowOption> option = new (std::nothrow) Rosen::WindowOption();
97     CHKPP(option);
98     option->SetWindowRect(info.rect);
99     option->SetWindowType(info.type);
100     option->SetWindowMode(info.mode);
101     option->SetFocusable(info.focusable_);
102     option->SetTurnScreenOn(true);
103     option->SetDisplayId(0);
104     option->SetRequestedOrientation(info.orientation_);
105     option->SetMainHandlerAvailable(false);
106     if (info.parentId != Rosen::INVALID_WINDOW_ID) {
107         option->SetParentId(info.parentId);
108     }
109     if (info.needAvoid) {
110         option->AddWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_NEED_AVOID);
111     } else {
112         option->RemoveWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_NEED_AVOID);
113     }
114     if (info.parentLimit) {
115         option->AddWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
116     } else {
117         option->RemoveWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
118     }
119     return Rosen::Window::Create(info.name, option);
120 }
121 } // namespace MMI
122 } // namespace OHOS