1 /*
2 * Copyright (c) 2025 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 <iostream>
17 #include <surface.h>
18
19 #include "foundation/window/window_manager/interfaces/innerkits/wm/window.h"
20
21 #include "image_source.h"
22 #include "pixel_map.h"
23 #include "transaction/rs_interfaces.h"
24 #include "transaction/rs_transaction.h"
25 #include "ui/rs_root_node.h"
26 #include "ui/rs_display_node.h"
27 #include "ui/rs_surface_node.h"
28 #include "ui/rs_surface_extractor.h"
29 #include "ui/rs_ui_director.h"
30
31 using namespace std;
32 using namespace OHOS;
33 using namespace OHOS::Rosen;
34
35 constexpr float MAX_ZORDER = 1e5f;
36 constexpr size_t BOUNDS_WIDTH = 800;
37 constexpr size_t BOUNDS_HEIGHT = 500;
main()38 int main()
39 {
40 auto& rsInterfaces = RSInterfaces::GetInstance();
41 auto screenId = rsInterfaces.GetDefaultScreenId();
42 if (screenId == INVALID_SCREEN_ID) {
43 std::cout << "GetDefaultScreenId failed" << std::endl;
44 screenId = 0;
45 }
46
47 auto rsUiDirector = RSUIDirector::Create();
48 if (rsUiDirector == nullptr) {
49 std::cout << "rsUiDirector is nullptr" << std::endl;
50 return EXIT_FAILURE;
51 }
52
53 std::cout << "Create RSSurfaceNode" << std::endl;
54 RSSurfaceNodeConfig config {
55 .SurfaceNodeName = "SurfaceLocalMagnificationTest",
56 .isSync = true,
57 };
58 RSSurfaceNodeType type = RSSurfaceNodeType::ABILITY_MAGNIFICATION_NODE;
59 auto rsUIContext = rsUiDirector->GetRSUIContext();
60 auto surfaceNode = RSSurfaceNode::Create(config, type, true, false, rsUIContext);
61 if (surfaceNode == nullptr) {
62 std::cout << "surfaceNode is nullptr" << std::endl;
63 return EXIT_FAILURE;
64 }
65 surfaceNode->AttachToDisplay(screenId);
66
67 std::cout << "Local Magnification Case1: base case" << std::endl;
68 surfaceNode->SetPositionZ(MAX_ZORDER);
69 surfaceNode->SetAbilityBGAlpha(254);
70 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
71 surfaceNode->SetRegionToBeMagnified({0, 0, 160, 100});
72 surfaceNode->SetFrame({0, 0, BOUNDS_WIDTH, BOUNDS_HEIGHT});
73 RSTransaction::FlushImplicitTransaction();
74 sleep(2);
75
76 std::cout << "Local Magnification Case2: move position" << std::endl;
77 surfaceNode->SetPositionZ(MAX_ZORDER);
78 surfaceNode->SetAbilityBGAlpha(254);
79 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
80 surfaceNode->SetRegionToBeMagnified({500, 500, 160, 100});
81 surfaceNode->SetFrame({500, 500, BOUNDS_WIDTH, BOUNDS_HEIGHT});
82 RSTransaction::FlushImplicitTransaction();
83 sleep(2);
84
85 std::cout << "Local Magnification Case3: change scale" << std::endl;
86 surfaceNode->SetPositionZ(MAX_ZORDER);
87 surfaceNode->SetAbilityBGAlpha(254);
88 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
89 surfaceNode->SetRegionToBeMagnified({500, 500, 400, 250});
90 surfaceNode->SetFrame({500, 500, BOUNDS_WIDTH, BOUNDS_HEIGHT});
91 RSTransaction::FlushImplicitTransaction();
92 sleep(2);
93
94 std::cout << "Local Magnification Case4: move position and change scale" << std::endl;
95 surfaceNode->SetPositionZ(MAX_ZORDER);
96 surfaceNode->SetAbilityBGAlpha(254);
97 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
98 surfaceNode->SetRegionToBeMagnified({500, 1000, 100, 62.5});
99 surfaceNode->SetFrame({500, 1000, BOUNDS_WIDTH, BOUNDS_HEIGHT});
100 RSTransaction::FlushImplicitTransaction();
101 sleep(2);
102
103 std::cout << "Local Magnification Case5: abnormal case1" << std::endl;
104 surfaceNode->SetPositionZ(MAX_ZORDER);
105 surfaceNode->SetAbilityBGAlpha(254);
106 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
107 surfaceNode->SetRegionToBeMagnified({500, 500, 0, 0});
108 surfaceNode->SetFrame({500, 500, BOUNDS_WIDTH, BOUNDS_HEIGHT});
109 RSTransaction::FlushImplicitTransaction();
110 sleep(2);
111
112 std::cout << "Local Magnification Case5: abnormal case2" << std::endl;
113 surfaceNode->SetPositionZ(MAX_ZORDER);
114 surfaceNode->SetAbilityBGAlpha(254);
115 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
116 surfaceNode->SetRegionToBeMagnified({ 1300, 500, 400, 250 });
117 surfaceNode->SetFrame({ 500, 500, BOUNDS_WIDTH, BOUNDS_HEIGHT });
118 RSTransaction::FlushImplicitTransaction();
119 sleep(2);
120
121 std::cout << "Local Magnification Case7: sliding window" << std::endl;
122 for (int i = 0; i < 15; i++) {
123 surfaceNode->SetPositionZ(MAX_ZORDER);
124 surfaceNode->SetAbilityBGAlpha(254);
125 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
126 surfaceNode->SetRegionToBeMagnified({ 30 * i, 60 * i, 400, 250 });
127 surfaceNode->SetFrame({ 30 * i, 60 * i, BOUNDS_WIDTH, BOUNDS_HEIGHT });
128 RSTransaction::FlushImplicitTransaction();
129 sleep(1);
130 }
131
132 std::cout << "Local Magnification Case8: dirty manager, click to the accessibility page" << std::endl;
133 surfaceNode->SetPositionZ(MAX_ZORDER);
134 surfaceNode->SetAbilityBGAlpha(254);
135 surfaceNode->SetFrameGravity(Gravity::RESIZE_ASPECT);
136 surfaceNode->SetRegionToBeMagnified({230, 1100, 400, 400});
137 surfaceNode->SetFrame({230, 1100, 800, 800});
138 RSTransaction::FlushImplicitTransaction();
139 sleep(50);
140
141 return EXIT_SUCCESS;
142 }