• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <iostream>
17 #include <surface.h>
18 
19 #include "wm/window.h"
20 
21 #include "include/core/SkCanvas.h"
22 #include "include/core/SkImageInfo.h"
23 #include "transaction/rs_transaction.h"
24 #include "ui/rs_root_node.h"
25 #include "ui/rs_display_node.h"
26 #include "ui/rs_surface_node.h"
27 #include "ui/rs_surface_extractor.h"
28 #include "ui/rs_ui_director.h"
29 
30 using namespace OHOS;
31 using namespace OHOS::Rosen;
32 using namespace std;
33 
34 std::shared_ptr<RSNode> rootNode;
35 std::vector<std::shared_ptr<RSCanvasNode>> nodes;
36 
Init(std::shared_ptr<RSUIDirector> rsUiDirector,int width,int height)37 void Init(std::shared_ptr<RSUIDirector> rsUiDirector, int width, int height)
38 {
39     std::cout << "rs app demo Init Rosen Backend!" << std::endl;
40 
41     rootNode = RSRootNode::Create();
42     rootNode->SetBounds(0, 0, width, height);
43     rootNode->SetFrame(0, 0, width, height);
44     rootNode->SetBackgroundColor(SK_ColorRED);
45 
46     rsUiDirector->SetRoot(rootNode->GetId());
47 }
48 
main()49 int main()
50 {
51     std::cout << "rs app demo start!" << std::endl;
52     sptr<WindowOption> option = new WindowOption();
53     option->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
54     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
55     option->SetWindowRect({0, 0, 2560, 112});
56     auto window = Window::Create("app_demo", option);
57 
58     window->Show();
59     auto rect = window->GetRect();
60     while (rect.width_ == 0 && rect.height_ == 0) {
61         std::cout << "rs app demo create window failed: " << rect.width_ << " " << rect.height_ << std::endl;
62         window->Hide();
63         window->Destroy();
64         window = Window::Create("app_demo", option);
65         window->Show();
66         rect = window->GetRect();
67     }
68     std::cout << "rs app demo create window " << rect.width_ << " " << rect.height_ << std::endl;
69     auto surfaceNode = window->GetSurfaceNode();
70 
71     auto rsUiDirector = RSUIDirector::Create();
72     rsUiDirector->Init();
73     RSTransaction::FlushImplicitTransaction();
74     sleep(1);
75 
76     std::cout << "rs app demo stage 1 " << std::endl;
77     rsUiDirector->SetRSSurfaceNode(surfaceNode);
78     Init(rsUiDirector, rect.width_, rect.height_);
79     rsUiDirector->SendMessages();
80     sleep(1);
81 
82     std::cout << "rs app demo stage 2 " << std::endl;
83     int resizeH = 1600;
84     window->Resize(2560, resizeH);
85     rootNode->SetBounds(0, 0, 2560, resizeH);
86     rootNode->SetBackgroundColor(SK_ColorYELLOW);
87     rsUiDirector->SendMessages();
88     sleep(4);
89 
90     std::cout << "rs app demo stage 3 " << std::endl;
91     rootNode->SetBackgroundColor(SK_ColorBLUE);
92     rsUiDirector->SendMessages();
93     sleep(1);
94 
95     std::cout << "rs app demo stage 3 " << std::endl;
96     rootNode->SetBackgroundColor(SK_ColorYELLOW);
97     rsUiDirector->SendMessages();
98     sleep(1);
99 
100     std::cout << "rs app demo stage 3 " << std::endl;
101     rootNode->SetBackgroundColor(SK_ColorBLUE);
102     rsUiDirector->SendMessages();
103     sleep(1);
104 
105     std::cout << "rs app demo start dump test --> " << std::endl;
106     rootNode->SetRotation(20.f);
107     rootNode->SetAlpha(0.5f);
108     rootNode->SetForegroundColor(SK_ColorRED);
109     rsUiDirector->SendMessages();
110     sleep(1);
111 
112     std::string dumpInfo = rootNode->GetStagingProperties().Dump();
113     std::cout << "dumpInfo: " << dumpInfo.c_str() << std::endl;
114     sleep(1);
115 
116     std::cout << "rs app demo end!" << std::endl;
117     window->Hide();
118     window->Destroy();
119     return 0;
120 }
121