• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
30 namespace OHOS {
31 namespace Rosen {
32 class DrawCmdList;
33 class OpItem;
34 class RSRecordingCanvas : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
35 public:
36     RSRecordingCanvas(int width, int height);
37     virtual ~RSRecordingCanvas();
38     std::shared_ptr<DrawCmdList> GetDrawCmdList() const;
39     void Clear() const;
40     void AddOp(std::unique_ptr<OpItem>&& opItem);
41 
42     sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) override;
43 
44     void willSave() override;
45     SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
46     void willRestore() override;
47 
48     void onFlush() override;
49 
50     void didConcat(const SkMatrix& matrix) override;
51     void didSetMatrix(const SkMatrix& matrix) override;
52     void didTranslate(SkScalar dx, SkScalar dy) override;
53 
54     void onClipRect(const SkRect& rect, SkClipOp clipOp, ClipEdgeStyle style) override;
55     void onClipRRect(const SkRRect& rect, SkClipOp clipOp, ClipEdgeStyle style) override;
56     void onClipPath(const SkPath& path, SkClipOp clipOp, ClipEdgeStyle style) override;
57     void onClipRegion(const SkRegion& region, SkClipOp clipop) override;
58 
59     void onDrawPaint(const SkPaint& paint) override;
60     void onDrawBehind(const SkPaint&) override;
61     void onDrawPath(const SkPath& path, const SkPaint& paint) override;
62     void onDrawRect(const SkRect& rect, const SkPaint& paint) override;
63     void onDrawRegion(const SkRegion& region, const SkPaint& paint) override;
64     void onDrawOval(const SkRect& oval, const SkPaint& paint) override;
65     void onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
66         bool useCenter, const SkPaint& paint) override;
67     void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override;
68     void onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) override;
69 
70     void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override;
71     void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) override;
72     void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
73 
74     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override;
75 
76     void onDrawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPaint* paint) override;
77     void onDrawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& lattice, const SkRect& dst,
78         const SkPaint* paint) override;
79     void onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center, const SkRect& dst, const SkPaint* paint) override;
80     void onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
81         const SkPaint* paint, SrcRectConstraint constraint) override;
82 
83     void onDrawImage(const SkImage* img, SkScalar x, SkScalar y, const SkPaint* paint) override;
84     void onDrawImageLattice(const SkImage* img, const SkCanvas::Lattice& lattice,
85         const SkRect& dst, const SkPaint* paint) override;
86     void onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst, const SkPaint* paint) override;
87     void onDrawImageRect(const SkImage* img, const SkRect* src, const SkRect& dst, const SkPaint* paint,
88         SrcRectConstraint constraint) override;
89 
90     void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode, const SkPaint&) override;
91     void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) override;
92     void onDrawVerticesObject(
93         const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode, const SkPaint&) override;
94     void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode,
95         const SkRect*, const SkPaint*) override;
96     void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
97 
98     void DrawAdaptiveRRect(float radius, const SkPaint& paint);
99     void ClipAdaptiveRRect(float radius);
100     void DrawImageWithParm(const sk_sp<SkImage>, int, int, float, const SkPaint& paint);
101 
102     void MultiplyAlpha(float alpha);
103     void SaveAlpha();
104     void RestoreAlpha();
105 
onDrawEdgeAAQuad(const SkRect &,const SkPoint[4],QuadAAFlags,SkColor,SkBlendMode)106     void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, SkColor,
107                           SkBlendMode) override {}
onDrawEdgeAAImageSet(const ImageSetEntry[],int,const SkPoint[],const SkMatrix[],const SkPaint *,SrcRectConstraint)108     void onDrawEdgeAAImageSet(const ImageSetEntry[], int, const SkPoint[],
109                               const SkMatrix[], const SkPaint*, SrcRectConstraint) override {}
110 
111 private:
112     std::shared_ptr<DrawCmdList> drawCmdList_ { nullptr };
113     int saveCount_ = 0;
114 };
115 } // namespace Rosen
116 } // namespace OHOS
117 
118 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H
119