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 <iostream>
17 #include <surface.h>
18 
19 #include "common/rs_common_def.h"
20 #include "platform/common/rs_log.h"
21 #include "ui/rs_node.h"
22 #include "ui/rs_display_node.h"
23 #include "ui/rs_surface_node.h"
24 #include "transaction/rs_transaction.h"
25 
26 using namespace OHOS;
27 using namespace OHOS::Rosen;
28 using namespace std;
29 
30 class RSDemoDisplayNode : public RSDisplayNode {
31 public:
RSDemoDisplayNode()32     RSDemoDisplayNode() : RSDisplayNode(RSDisplayNodeConfig()) {}
33 
CreateForDemo(NodeId id)34     static shared_ptr<RSDemoDisplayNode> CreateForDemo(NodeId id)
35     {
36         shared_ptr<RSDemoDisplayNode> node = make_shared<RSDemoDisplayNode>();
37         node->SetDemoId(node->GetId());
38         node->SetId(id);
39         return node;
40     }
41 
RecoveryNode()42     void RecoveryNode()
43     {
44         SetId(demoId_);
45     }
46 
47 private:
SetDemoId(NodeId id)48     void SetDemoId(NodeId id)
49     {
50         demoId_ = id;
51     }
52 
53     NodeId demoId_ = 0;
54 };
55 
56 class RSDemoSurfaceNode : public RSSurfaceNode {
57 public:
RSDemoSurfaceNode()58     RSDemoSurfaceNode() : RSSurfaceNode(RSSurfaceNodeConfig(), true) {}
59 
CreateForDemo(NodeId id)60     static shared_ptr<RSDemoSurfaceNode> CreateForDemo(NodeId id)
61     {
62         shared_ptr<RSDemoSurfaceNode> node = make_shared<RSDemoSurfaceNode>();
63         node->SetDemoId(node->GetId());
64         node->SetId(id);
65         return node;
66     }
67 
RecoveryNode()68     void RecoveryNode()
69     {
70         SetId(demoId_);
71     }
72 
73 private:
SetDemoId(NodeId id)74     void SetDemoId(NodeId id)
75     {
76         demoId_ = id;
77     }
78 
79     NodeId demoId_ = 0;
80 };
81 
main()82 int main()
83 {
84     while (true) {
85         int testType = -1;
86         uint64_t nodeId = 0;
87         int param = -1;
88         cout << " ---------------------loop start------------------------" << endl;
89         cout << "Input test type, 1: displayNode, 0: surfaceNode: ";
90         cin >> testType;
91         cout << "Input node id: ";
92         cin >> nodeId;
93         cout << "Input param: 1: is security, 0: not security: ";
94         cin >> param;
95         cout << " " << endl;
96 
97         if (testType == 0) {
98             shared_ptr<RSDemoSurfaceNode> node = RSDemoSurfaceNode::CreateForDemo(nodeId);
99             node->SetSecurityLayer(param == 1 ? true : false);
100             node->RecoveryNode();
101         } else if (testType == 1) {
102             shared_ptr<RSDemoDisplayNode> node = RSDemoDisplayNode::CreateForDemo(nodeId);
103             node->SetSecurityDisplay(param == 1 ? true : false);
104             node->RecoveryNode();
105         }
106         RSTransaction::FlushImplicitTransaction();
107     }
108     return 0;
109 }
110