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_TEST_BASE_H
16 #define DRAWING_DEMO_TEST_BASE_H
17 #include "pixel_map.h"
18 #include "recording/recording_canvas.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 #define DEFAULT_WIDTH 720
23 #define DEFAULT_HEIGHT 720
24 #define DEFAULT_BACKGROUND_COLOR 0xFFFFFFFF
25 #define DEFAULT_TEST_COUNT 1
26 
27 using TestDisplayCanvas = Drawing::RecordingCanvas;
28 
29 class TestBase {
30 public:
TestBase()31     TestBase(){};
32     virtual ~TestBase() = default;
33     void SetCanvas(TestDisplayCanvas* canvas);
34     void SetFileName(std::string fileName);
35     void SetTestCount(uint32_t count);
36     void TestFunctionCpu();
37     void TestPerformanceCpu();
38     void TestFunctionGpuUpScreen();
39     void TestPerformanceGpuUpScreen();
OnTestFunction(Drawing::Canvas * canvas)40     virtual void OnTestFunction(Drawing::Canvas* canvas) {};
OnTestPerformance(Drawing::Canvas * canvas)41     virtual void OnTestPerformance(Drawing::Canvas* canvas) {};
OnTestFunctionCpu(Drawing::Canvas * canvas)42     virtual void OnTestFunctionCpu(Drawing::Canvas* canvas)
43     {
44         return OnTestFunction(canvas);
45     };
OnTestPerformanceCpu(Drawing::Canvas * canvas)46     virtual void OnTestPerformanceCpu(Drawing::Canvas* canvas)
47     {
48         return OnTestPerformance(canvas);
49     };
OnTestFunctionGpuUpScreen(Drawing::Canvas * canvas)50     virtual void OnTestFunctionGpuUpScreen(Drawing::Canvas* canvas)
51     {
52         return OnTestFunction(canvas);
53     };
OnTestPerformanceGpuUpScreen(Drawing::Canvas * canvas)54     virtual void OnTestPerformanceGpuUpScreen(Drawing::Canvas* canvas)
55     {
56         return OnTestPerformance(canvas);
57     };
58 
59 protected:
60     int CreateBitmapCanvas();
61     int DiasplayToScreen();
62     void LogStart();
63     void LogEnd();
64 
65     TestDisplayCanvas* playbackCanvas_ = nullptr;
66 
67     int width_ = DEFAULT_WIDTH;
68     int height_ = DEFAULT_HEIGHT;
69     uint32_t background_ = DEFAULT_BACKGROUND_COLOR;
70     std::string fileName_ = "default";
71     uint32_t testCount_ = DEFAULT_TEST_COUNT;
72 
73     Drawing::Bitmap bitmap_;
74     std::shared_ptr<OHOS::Media::PixelMap> pixelMap_;
75     std::shared_ptr<Drawing::Canvas> bitmapCanvas_;
76     std::chrono::high_resolution_clock::time_point timeStart_;
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 #endif // DRAWING_DEMO_TEST_BASE_H