• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 RECORDING_CANVAS_H
17 #define RECORDING_CANVAS_H
18 
19 #include "draw/canvas.h"
20 #include "recording/adaptive_image_helper.h"
21 #include "recording/draw_cmd_list.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace Drawing {
26 /*
27  * @brief  RecordingCanvas is an empty canvas, which does not act on any surface,
28  * and is used to record the sequence of draw calls for the canvas.
29  * Draw calls are kept in linear memory in DrawCmdList, Subsequent playback can be performed through DrawCmdList.
30  */
31 class RecordingCanvas : public Canvas {
32 public:
33     RecordingCanvas(int width, int height);
34     ~RecordingCanvas() override = default;
35 
36     std::shared_ptr<DrawCmdList> GetDrawCmdList() const;
37 
GetDrawingType()38     DrawingType GetDrawingType() const override
39     {
40         return DrawingType::RECORDING;
41     }
42 
43     void DrawPoint(const Point& point) override;
44     void DrawLine(const Point& startPt, const Point& endPt) override;
45     void DrawRect(const Rect& rect) override;
46     void DrawRoundRect(const RoundRect& roundRect) override;
47     void DrawNestedRoundRect(const RoundRect& outer, const RoundRect& inner) override;
48     void DrawArc(const Rect& oval, scalar startAngle, scalar sweepAngle) override;
49     void DrawPie(const Rect& oval, scalar startAngle, scalar sweepAngle) override;
50     void DrawOval(const Rect& oval) override;
51     void DrawCircle(const Point& centerPt, scalar radius) override;
52     void DrawPath(const Path& path) override;
53     void DrawBackground(const Brush& brush) override;
54     void DrawShadow(const Path& path, const Point3& planeParams, const Point3& devLightPos, scalar lightRadius,
55         Color ambientColor, Color spotColor, ShadowFlags flag) override;
56 
57     void DrawBitmap(const Bitmap& bitmap, const scalar px, const scalar py) override;
58     void DrawImage(const Image& image, const scalar px, const scalar py, const SamplingOptions& sampling) override;
59     void DrawImageRect(const Image& image, const Rect& src, const Rect& dst, const SamplingOptions& sampling,
60         SrcRectConstraint constraint = SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT) override;
61     void DrawImageRect(const Image& image, const Rect& dst, const SamplingOptions& sampling) override;
62     void DrawPicture(const Picture& picture) override;
63 
64     void ClipRect(const Rect& rect, ClipOp op, bool doAntiAlias) override;
65     void ClipRoundRect(const RoundRect& roundRect, ClipOp op, bool doAntiAlias) override;
66     void ClipPath(const Path& path, ClipOp op, bool doAntiAlias) override;
67 
68     void SetMatrix(const Matrix& matrix) override;
69     void ResetMatrix() override;
70     void ConcatMatrix(const Matrix& matrix) override;
71     void Translate(scalar dx, scalar dy) override;
72     void Scale(scalar sx, scalar sy) override;
73     void Rotate(scalar deg, scalar sx, scalar sy) override;
74     void Shear(scalar sx, scalar sy) override;
75 
76     void Flush() override;
77     void Clear(ColorQuad color) override;
78     void Save() override;
79     void SaveLayer(const SaveLayerOps& saveLayerOps) override;
80     void Restore() override;
81 
82     void ClipAdaptiveRoundRect(const std::vector<Point>& radius);
83     void DrawImage(const std::shared_ptr<Image>& image, const std::shared_ptr<Data>& data,
84         const AdaptiveImageInfo& rsImageInfo, const SamplingOptions& smapling);
85     void DrawPixelMap(const std::shared_ptr<Media::PixelMap>& pixelMap,
86         const AdaptiveImageInfo& rsImageInfo, const SamplingOptions& smapling);
87 
88     CoreCanvas& AttachPen(const Pen& pen) override;
89     CoreCanvas& AttachBrush(const Brush& brush) override;
90     CoreCanvas& DetachPen() override;
91     CoreCanvas& DetachBrush() override;
92 
93 private:
94     std::shared_ptr<DrawCmdList> cmdList_ = nullptr;
95     int saveCount_ = 0;
96 };
97 } // namespace Drawing
98 } // namespace Rosen
99 } // namespace OHOS
100 #endif
101