1 /*
2  * Copyright (c) 2022-2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_CANVAS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_CANVAS_H
18 
19 #include "testing_bitmap.h"
20 #include "testing_brush.h"
21 #include "testing_color.h"
22 #include "testing_image.h"
23 #include "testing_matrix.h"
24 #include "testing_path.h"
25 #include "testing_pen.h"
26 #include "testing_point.h"
27 #include "testing_point3.h"
28 #include "testing_rect.h"
29 #include "testing_round_rect.h"
30 #include "testing_sampling_options.h"
31 #include "testing_save_layer_ops.h"
32 #include "testing_shadowflags.h"
33 
34 namespace OHOS::Ace::Testing {
35 enum class ClipOp {
36     DIFFERENCE,
37     INTERSECT,
38     UNION,
39     XOR,
40     REVERSE_DIFFERENCE,
41     REPLACE,
42 };
43 
44 enum class SrcRectConstraint {
45     STRICT_SRC_RECT_CONSTRAINT,
46     FAST_SRC_RECT_CONSTRAINT,
47 };
48 
49 class TestingCanvas {
50 public:
51     TestingCanvas() = default;
TestingCanvas(void * rawCanvas)52     explicit TestingCanvas(void* rawCanvas) {}
53     virtual ~TestingCanvas() = default;
54 
DrawLine(const TestingPoint & startPt,const TestingPoint & endPt)55     virtual void DrawLine(const TestingPoint& startPt, const TestingPoint& endPt) {}
DrawPath(const TestingPath & path)56     virtual void DrawPath(const TestingPath& path) {}
DrawArc(const TestingRect & oval,float startAngle,float sweepAngle)57     virtual void DrawArc(const TestingRect& oval, float startAngle, float sweepAngle) {}
DrawRect(const TestingRect & rect)58     virtual void DrawRect(const TestingRect& rect) {}
59     virtual void ClipRoundRect(const TestingRoundRect& roundRect, ClipOp op, bool antiAlias = false) {}
60     virtual void ClipRoundRect(const TestingRect& rect, std::vector<TestingPoint>& pts, bool antiAlias = false) {}
Rotate(float deg,float sx,float sy)61     virtual void Rotate(float deg, float sx, float sy) {}
Rotate(float deg)62     virtual void Rotate(float deg) {}
Translate(float tx,float ty)63     virtual void Translate(float tx, float ty) {}
DrawBitmap(const TestingBitmap & bitmap,const float px,const float py)64     virtual void DrawBitmap(const TestingBitmap& bitmap, const float px, const float py) {}
DrawImage(const TestingImage & image,const float px,const float py,const TestingSamplingOptions & sampling)65     virtual void DrawImage(
66         const TestingImage& image, const float px, const float py, const TestingSamplingOptions& sampling)
67     {}
DrawShadow(const TestingPath & path,const TestingPoint3 & planeParams,const TestingPoint3 & devLightPos,float lightRadius,TestingColor,TestingColor,TestingShadowFlags flag)68     virtual void DrawShadow(const TestingPath& path, const TestingPoint3& planeParams, const TestingPoint3& devLightPos,
69         float lightRadius, TestingColor /* ambientColor */, TestingColor /* spotColor */, TestingShadowFlags flag)
70     {}
DrawShadowStyle(const TestingPath & path,const TestingPoint3 & planeParams,const TestingPoint3 & devLightPos,float lightRadius,TestingColor,TestingColor,TestingShadowFlags flag,bool isLimitElevation)71     virtual void DrawShadowStyle(const TestingPath& path, const TestingPoint3& planeParams,
72         const TestingPoint3& devLightPos, float lightRadius, TestingColor /* ambientColor */,
73         TestingColor /* spotColor */, TestingShadowFlags flag, bool isLimitElevation)
74     {}
AttachPen(const TestingPen & pen)75     virtual TestingCanvas& AttachPen(const TestingPen& pen)
76     {
77         return *this;
78     }
79 
AttachBrush(const TestingBrush & brush)80     virtual TestingCanvas& AttachBrush(const TestingBrush& brush)
81     {
82         return *this;
83     }
84 
DetachPen()85     virtual TestingCanvas& DetachPen()
86     {
87         return *this;
88     }
89 
DetachBrush()90     virtual TestingCanvas& DetachBrush()
91     {
92         return *this;
93     }
94 
95     template<typename T>
GetImpl()96     const std::shared_ptr<T> GetImpl() const
97     {
98         return std::shared_ptr<T>();
99     }
100 
Save()101     virtual void Save() {}
Restore()102     virtual void Restore() {}
DrawCircle(const TestingPoint & center,float radius)103     virtual void DrawCircle(const TestingPoint& center, float radius) {}
DrawRoundRect(const TestingRoundRect & roundRect)104     virtual void DrawRoundRect(const TestingRoundRect& roundRect) {}
DrawBackground(const TestingBrush & brush)105     virtual void DrawBackground(const TestingBrush& brush) {}
106     virtual void ClipRect(const TestingRect& rect, ClipOp op = ClipOp::INTERSECT, bool doAntiAlias = false) {}
Scale(float sx,float sy)107     virtual void Scale(float sx, float sy) {}
108     virtual void ClipPath(const TestingPath& path, ClipOp op, bool doAntiAlias = false) {}
DrawOval(const TestingRect & oval)109     virtual void DrawOval(const TestingRect& oval) {}
DrawImageRect(const TestingImage & image,const TestingRect & dst,const TestingSamplingOptions & sampling)110     virtual void DrawImageRect(
111         const TestingImage& image, const TestingRect& dst, const TestingSamplingOptions& sampling)
112     {}
113     virtual void DrawImageRect(const TestingImage& image, const TestingRect& src, const TestingRect& dst,
114         const TestingSamplingOptions& sampling,
115         SrcRectConstraint constraint = SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT)
116     {}
SaveLayer(const TestingSaveLayerOps & saveLayerOps)117     virtual void SaveLayer(const TestingSaveLayerOps& saveLayerOps) {}
GetSaveCount()118     virtual uint32_t GetSaveCount() const
119     {
120         return 0;
121     }
122 
RestoreToCount(uint32_t count)123     virtual void RestoreToCount(uint32_t count) {}
ConcatMatrix(const TestingMatrix & matrix)124     virtual void ConcatMatrix(const TestingMatrix& matrix) {}
SetMatrix(const TestingMatrix & matrix)125     void SetMatrix(const TestingMatrix& matrix) {}
ResetMatrix()126     void ResetMatrix() {}
SetScale(float sx,float sy)127     void SetScale(float sx, float sy) {}
Bind(const TestingBitmap & bitmap)128     void Bind(const TestingBitmap& bitmap) {}
Clear(ColorQuad color)129     void Clear(ColorQuad color) {}
GetTotalMatrix()130     TestingMatrix GetTotalMatrix() const
131     {
132         return TestingMatrix();
133     }
134 };
135 } // namespace OHOS::Ace::Testing
136 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_CANVAS_H
137