• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DDGR_TEST_DTK_DTK_TEST_BASE_H
16 #define DDGR_TEST_DTK_DTK_TEST_BASE_H
17 
18 #include "recording/recording_canvas.h"
19 #include "ui/rs_root_node.h"
20 #include "ui/rs_surface_node.h"
21 #include "ui/rs_ui_director.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 using TestPlaybackCanvas = Drawing::Canvas;
26 
27 class TestBase {
28 public:
TestBase()29     TestBase() {};
30     virtual ~TestBase() = default;
31     void Recording();
32     void SetTestCount(int testCount);
33     void SetCanvas(Drawing::Canvas* canvas);
34     void SetSurface(Drawing::Surface* surface);
35 
36     void AddTestBrush(bool isAA = true);
37     void AddTestPen(bool isAA = true);
38     void AddTestPen(bool isAA, float width);
39     void AddTestPen(bool isAA, Drawing::Pen::CapStyle capStyle);
40     void AddTestPen(bool isAA, Drawing::Pen::JoinStyle joinStyle);
41     void AddTestPen(bool isAA, Drawing::Pen::CapStyle capStyle, Drawing::Pen::JoinStyle joinStyle);
42     void AddTestBrushAndPen(bool isAA = true);
43 
44     void ClearTestBrush();
45     void ClearTestPen();
46     void ClearTestBrushAndPen();
47 
48     void ClipPath(bool doAntiAlias);
49     void ClipRect(bool doAntiAlias);
50     void ClipRoundRectG2(bool doAntiAlias);
51     void ClipRoundRectG2capsule(bool doAntiAlias);
52     void ClipRoundRectnotG2(bool doAntiAlias);
53 
54     std::shared_ptr<Drawing::Image> GetEffectTestImage(const std::string& pathName);
55     std::shared_ptr<Drawing::Surface> GetNewColorSpaceSurface();
56     std::shared_ptr<Drawing::RuntimeEffect> GetTestRuntimeEffectForShader(const char* glsl);
57     std::shared_ptr<Drawing::RuntimeEffect> GetTestRuntimeEffectForBlender(const char* glsl);
58 
59 protected:
60     virtual void OnRecording() = 0;
61 
62     std::shared_ptr<Drawing::Image> OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap);
63     void Init(std::shared_ptr<RSUIDirector> rsUiDirector, int width, int height);
64     using MakeImageFunc = std::function<void(TestPlaybackCanvas* canvas, int w, int h)>;
65     std::shared_ptr<Drawing::Image> MakeImage(int w, int h, MakeImageFunc func);
66 
67     TestPlaybackCanvas* playbackCanvas_ = nullptr;
68     Drawing::Surface* mSurface = nullptr;
69     int testCount_ = 50;
70     int width_ = 1000;
71     int height_ = 1000;
72 
73     std::shared_ptr<RSNode> rootNode_ = nullptr;
74     std::shared_ptr<RSCanvasNode> canvasNode_ = nullptr;
75 
76 private:
77     std::unordered_map<std::string, std::shared_ptr<Drawing::Image>> effectTestImageMap_;
78     std::unordered_map<size_t, std::shared_ptr<Drawing::RuntimeEffect>> runtimeEffectMap_;
79     std::shared_ptr<Drawing::Surface> csSurface_;
80 };
81 } // namespace Rosen
82 } // namespace OHOS
83 #endif // DDGR_TEST_DTK_DTK_TEST_BASE_H