1 /*
2  * Copyright (c) 2024 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 #ifndef DRAWING_DEMO_H
16 #define DRAWING_DEMO_H
17 #include <chrono>
18 #include <iostream>
19 #include <string>
20 
21 #include "transaction/rs_transaction.h"
22 #include "ui/rs_root_node.h"
23 #include "ui/rs_surface_node.h"
24 #include "ui/rs_ui_director.h"
25 #include "utils/log.h"
26 #include "window.h"
27 
28 #include "test_case/test_base.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 #define ALL_TAST_CASE "ALL"
33 #define DEFAULT_DISPLAY_TIME 10
34 #define SLEEP_TIME 30000
35 #define MAX_TRY_NUMBER 3
36 #define INDEX_TEST_TYPE 1
37 #define INDEX_DRAWING_TYPE 2
38 #define INDEX_CASE_NAME 3
39 #define INDEX_FUNCTION_TIME 4
40 #define INDEX_COUNT 4
41 #define INDEX_PERFORMANCE_TIME 5
42 
43 class DrawingDemo {
44 public:
45     DrawingDemo(int argc, char* argv[]);
46     ~DrawingDemo();
47     int Test(TestDisplayCanvas* canvas);
48     enum {
49         FUNCTION_CPU = 0,
50         FUNCTION_GPU_UPSCREEN,
51         PERFORMANCE_CPU,
52         PERFORMANCE_GPU_UPSCREEN,
53     };
54 
55 protected:
56     int InitWindow();
57     int CreateWindow();
58     int GetFunctionalParam(std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map);
59     int TestFunction(int type);
60     int GetPerformanceParam(std::shared_ptr<TestBase>& testCase);
61     int TestPerformance(TestDisplayCanvas* canvasExt, int type);
62 
63     int argc_ = 0;
64     std::vector<std::string> argv_;
65     std::shared_ptr<RSNode> rootNode_ = nullptr;
66     std::shared_ptr<RSCanvasNode> canvasNode_ = nullptr;
67     sptr<OHOS::Rosen::Window> window_ = nullptr;
68     std::shared_ptr<RSUIDirector> rsUiDirector_ = nullptr;
69     Rect rect_;
70     std::string testType_;
71     std::string drawingType_;
72     std::string caseName_ = ALL_TAST_CASE;
73     int displayTime_ = DEFAULT_DISPLAY_TIME;
74     int testCount_ = DEFAULT_TEST_COUNT;
75 };
76 } // namespace Rosen
77 } // namespace OHOS
78 #endif // DRAWING_DEMO_H