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