• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_LISTENED_CANVAS_H
17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_LISTENED_CANVAS_H
18 
19 #include "pipeline/rs_paint_filter_canvas.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 class RSCanvasListener;
24 
25 #ifndef USE_ROSEN_DRAWING
26 class RSB_EXPORT RSListenedCanvas : public RSPaintFilterCanvas {
27 public:
28     RSListenedCanvas(SkCanvas* canvas, float alpha = 1.0f);
29     RSListenedCanvas(SkSurface* skSurface, float alpha = 1.0f);
30 
31     void SetListener(const std::shared_ptr<RSCanvasListener> &listener);
32 
33     void onDrawPaint(const SkPaint& paint) override;
34     void onDrawRect(const SkRect& rect, const SkPaint& paint) override;
35     void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override;
36     void onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
37                       const SkPaint& paint) override;
38     void onDrawOval(const SkRect& rect, const SkPaint& paint) override;
39     void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
40                    const SkPaint& paint) override;
41     void onDrawPath(const SkPath& path, const SkPaint& paint) override;
42     void onDrawRegion(const SkRegion& region, const SkPaint& paint) override;
43     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
44                         const SkPaint& paint) override;
45     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
46                      const SkPoint texCoords[4], SkBlendMode mode,
47                      const SkPaint& paint) override;
48     void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
49                       const SkPaint& paint) override;
50     void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
51     void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rect) override;
52     void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override;
53     void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
54                        const SkPaint* paint) override;
55 #ifdef NEW_SKIA
56     void onDrawImageRect2(const SkImage* image, const SkRect& src, const SkRect& dst,
57             const SkSamplingOptions& samplingOptions, const SkPaint* paint, SrcRectConstraint constraint) override;
58 #else
59     void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
60             const SkPaint* paint, SrcRectConstraint constraint) override;
61 #endif
62 
63 private:
64     std::shared_ptr<RSCanvasListener> listener_ = nullptr;
65 };
66 
67 #else
68 class RSB_EXPORT RSListenedCanvas : public RSPaintFilterCanvas {
69 public:
70     RSListenedCanvas(Drawing::Canvas& canvas, float alpha = 1.0f);
71     RSListenedCanvas(Drawing::Surface& surface, float alpha = 1.0f);
72 
73     void SetListener(const std::shared_ptr<RSCanvasListener>& listener);
74     // shapes
75     void DrawPoint(const Drawing::Point& point) override;
76     void DrawLine(const Drawing::Point& startPt, const Drawing::Point& endPt) override;
77     void DrawRect(const Drawing::Rect& rect) override;
78     void DrawRoundRect(const Drawing::RoundRect& roundRect) override;
79     void DrawNestedRoundRect(const Drawing::RoundRect& outer, const Drawing::RoundRect& inner) override;
80     void DrawArc(const Drawing::Rect& oval, Drawing::scalar startAngle, Drawing::scalar sweepAngle) override;
81     void DrawPie(const Drawing::Rect& oval, Drawing::scalar startAngle, Drawing::scalar sweepAngle) override;
82     void DrawOval(const Drawing::Rect& oval) override;
83     void DrawCircle(const Drawing::Point& centerPt, Drawing::scalar radius) override;
84     void DrawPath(const Drawing::Path& path) override;
85     void DrawBackground(const Drawing::Brush& brush) override;
86     void DrawShadow(const Drawing::Path& path, const Drawing::Point3& planeParams,
87         const Drawing::Point3& devLightPos, Drawing::scalar lightRadius,
88         Drawing::Color ambientColor, Drawing::Color spotColor, Drawing::ShadowFlags flag) override;
89     void DrawRegion(const Drawing::Region& region) override;
90 
91     // image
92     void DrawBitmap(const Drawing::Bitmap& bitmap, const Drawing::scalar px, const Drawing::scalar py) override;
93     void DrawBitmap(OHOS::Media::PixelMap& pixelMap, const Drawing::scalar px, const Drawing::scalar py) override;
94     void DrawImage(const Drawing::Image& image,
95         const Drawing::scalar px, const Drawing::scalar py, const Drawing::SamplingOptions& sampling) override;
96     void DrawImageRect(const Drawing::Image& image,
97         const Drawing::Rect& src, const Drawing::Rect& dst, const Drawing::SamplingOptions& sampling,
98         Drawing::SrcRectConstraint constraint = Drawing::SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT) override;
99     void DrawImageRect(const Drawing::Image& image,
100         const Drawing::Rect& dst, const Drawing::SamplingOptions& sampling) override;
101     void DrawPicture(const Drawing::Picture& picture) override;
102 
103     void Clear(Drawing::ColorQuad color) override;
104     // paint
105     CoreCanvas& AttachPen(const Drawing::Pen& pen) override;
106     CoreCanvas& AttachBrush(const Drawing::Brush& brush) override;
107     CoreCanvas& DetachPen() override;
108     CoreCanvas& DetachBrush() override;
109 
110 private:
111     std::shared_ptr<RSCanvasListener> listener_ = nullptr;
112 };
113 #endif // USE_ROSEN_DRAWING
114 } // namespace Rosen
115 } // namespace OHOS
116 
117 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_OVERDRAW_RS_LISTENED_CANVAS_H
118