• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H
17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H
18 
19 #include "common/rs_macros.h"
20 #include "include/core/SkBitmap.h"
21 #include "include/core/SkCanvas.h"
22 #include "include/core/SkCanvasVirtualEnforcer.h"
23 #include "include/core/SkDrawable.h"
24 #include "include/core/SkPaint.h"
25 #include "include/core/SkPath.h"
26 #include "include/core/SkRect.h"
27 #include "include/utils/SkNoDrawCanvas.h"
28 #include "pipeline/rs_draw_cmd_list.h"
29 #include "property/rs_properties_def.h"
30 #include "render/rs_image.h"
31 
32 
33 namespace OHOS {
34 namespace Media {
35 class PixelMap;
36 }
37 namespace Rosen {
38 class DrawCmdList;
39 class OpItem;
40 class RSB_EXPORT RSRecordingCanvas : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
41 public:
42     RSRecordingCanvas(int width, int height);
43     virtual ~RSRecordingCanvas();
44     std::shared_ptr<DrawCmdList> GetDrawCmdList() const;
45     void Clear() const;
46     void AddOp(std::unique_ptr<OpItem>&& opItem);
47 
48     GrContext* getGrContext() override;
49     void SetGrContext(GrContext* grContext);
50 
51     sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) override;
52 
53     void willSave() override;
54     SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
55     void willRestore() override;
56 
57     void onFlush() override;
58 
59     void didConcat(const SkMatrix& matrix) override;
60     void didSetMatrix(const SkMatrix& matrix) override;
61     void didTranslate(SkScalar dx, SkScalar dy) override;
62 
63     void onClipRect(const SkRect& rect, SkClipOp clipOp, ClipEdgeStyle style) override;
64     void onClipRRect(const SkRRect& rect, SkClipOp clipOp, ClipEdgeStyle style) override;
65     void onClipPath(const SkPath& path, SkClipOp clipOp, ClipEdgeStyle style) override;
66     void onClipRegion(const SkRegion& region, SkClipOp clipop) override;
67 
68     void onDrawPaint(const SkPaint& paint) override;
69     void onDrawBehind(const SkPaint&) override;
70     void onDrawPath(const SkPath& path, const SkPaint& paint) override;
71     void onDrawRect(const SkRect& rect, const SkPaint& paint) override;
72     void onDrawRegion(const SkRegion& region, const SkPaint& paint) override;
73     void onDrawOval(const SkRect& oval, const SkPaint& paint) override;
74     void onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
75         bool useCenter, const SkPaint& paint) override;
76     void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override;
77     void onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) override;
78 
79     void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override;
80     void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) override;
81     void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
82 
83     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override;
84 
85     void onDrawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPaint* paint) override;
86     void onDrawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& lattice, const SkRect& dst,
87         const SkPaint* paint) override;
88     void onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center, const SkRect& dst, const SkPaint* paint) override;
89     void onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
90         const SkPaint* paint, SrcRectConstraint constraint) override;
91 
92     void onDrawImage(const SkImage* img, SkScalar x, SkScalar y, const SkPaint* paint) override;
93     void onDrawImageLattice(const SkImage* img, const SkCanvas::Lattice& lattice,
94         const SkRect& dst, const SkPaint* paint) override;
95     void onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst, const SkPaint* paint) override;
96     void onDrawImageRect(const SkImage* img, const SkRect* src, const SkRect& dst, const SkPaint* paint,
97         SrcRectConstraint constraint) override;
98 
99     void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode, const SkPaint&) override;
100     void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) override;
101     void onDrawVerticesObject(
102         const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode, const SkPaint&) override;
103     void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode,
104         const SkRect*, const SkPaint*) override;
105     void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
106 
107     void ClipOutsetRect(float dx, float dy);
108     void DrawAdaptiveRRect(float radius, const SkPaint& paint);
109     void DrawAdaptiveRRectScale(float radiusRatio, const SkPaint& paint);
110     void ClipAdaptiveRRect(const SkVector radius[]);
111     void DrawImageWithParm(const sk_sp<SkImage> image, const sk_sp<SkData> data,
112         const Rosen::RsImageInfo& rsImageInfo, const SkPaint& paint);
113     void DrawPixelMap(const std::shared_ptr<Media::PixelMap>& pixelmap, SkScalar x, SkScalar y,
114         const SkPaint* paint = nullptr);
115     void DrawPixelMapRect(const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst,
116         const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint);
117     void DrawPixelMapRect(const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& dst, const SkPaint* paint);
118     void DrawPixelMapWithParm(
119         const std::shared_ptr<Media::PixelMap>& pixelmap, const Rosen::RsImageInfo& rsImageInfo, const SkPaint& paint);
120 
121     void MultiplyAlpha(float alpha);
122     void SaveAlpha();
123     void RestoreAlpha();
124 
onDrawEdgeAAQuad(const SkRect &,const SkPoint[4],QuadAAFlags,SkColor,SkBlendMode)125     void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, SkColor,
126                           SkBlendMode) override {}
onDrawEdgeAAImageSet(const ImageSetEntry[],int,const SkPoint[],const SkMatrix[],const SkPaint *,SrcRectConstraint)127     void onDrawEdgeAAImageSet(const ImageSetEntry[], int, const SkPoint[],
128                               const SkMatrix[], const SkPaint*, SrcRectConstraint) override {}
129 
130 private:
131     void DrawImageLatticeAsBitmap(
132         const SkImage* image, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint* paint);
133 
134     std::shared_ptr<DrawCmdList> drawCmdList_ { nullptr };
135     int saveCount_ = 0;
136     GrContext* grContext_ = nullptr;
137 };
138 } // namespace Rosen
139 } // namespace OHOS
140 
141 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H
142