1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_
6#define FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_
7
8#include "flutter/display_list/dl_canvas.h"
9#include "flutter/display_list/skia/dl_sk_types.h"
10
11namespace flutter {
12
13// An adapter to receive DlCanvas calls and dispatch them into
14// an SkCanvas.
15class DlSkCanvasAdapter final : public virtual DlCanvas {
16 public:
17 DlSkCanvasAdapter() : delegate_(nullptr) {}
18 explicit DlSkCanvasAdapter(SkCanvas* canvas) : delegate_(canvas) {}
19 ~DlSkCanvasAdapter() override = default;
20
21 void set_canvas(SkCanvas* canvas);
22 SkCanvas* canvas() { return delegate_; }
23
24 SkISize GetBaseLayerSize() const override;
25 SkImageInfo GetImageInfo() const override;
26
27 void Save() override;
28 void SaveLayer(const SkRect* bounds,
29 const DlPaint* paint = nullptr,
30 const DlImageFilter* backdrop = nullptr) override;
31 void Restore() override;
32 int GetSaveCount() const override;
33 void RestoreToCount(int restore_count) override;
34
35 void Translate(SkScalar tx, SkScalar ty) override;
36 void Scale(SkScalar sx, SkScalar sy) override;
37 void Rotate(SkScalar degrees) override;
38 void Skew(SkScalar sx, SkScalar sy) override;
39
40 // clang-format off
41
42 // 2x3 2D affine subset of a 4x4 transform in row major order
43 void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt,
44 SkScalar myx, SkScalar myy, SkScalar myt) override;
45 // full 4x4 transform in row major order
46 void TransformFullPerspective(
47 SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt,
48 SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt,
49 SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt,
50 SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override;
51 // clang-format on
52 void TransformReset() override;
53 void Transform(const SkMatrix* matrix) override;
54 void Transform(const SkM44* matrix44) override;
55 void SetTransform(const SkMatrix* matrix) override;
56 void SetTransform(const SkM44* matrix44) override;
57 using DlCanvas::SetTransform;
58 using DlCanvas::Transform;
59
60 /// Returns the 4x4 full perspective transform representing all transform
61 /// operations executed so far in this DisplayList within the enclosing
62 /// save stack.
63 SkM44 GetTransformFullPerspective() const override;
64 /// Returns the 3x3 partial perspective transform representing all transform
65 /// operations executed so far in this DisplayList within the enclosing
66 /// save stack.
67 SkMatrix GetTransform() const override;
68
69 void ClipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override;
70 void ClipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override;
71 void ClipPath(const SkPath& path, ClipOp clip_op, bool is_aa) override;
72
73 /// Conservative estimate of the bounds of all outstanding clip operations
74 /// measured in the coordinate space within which this DisplayList will
75 /// be rendered.
76 SkRect GetDestinationClipBounds() const override;
77 /// Conservative estimate of the bounds of all outstanding clip operations
78 /// transformed into the local coordinate space in which currently
79 /// recorded rendering operations are interpreted.
80 SkRect GetLocalClipBounds() const override;
81
82 /// Return true iff the supplied bounds are easily shown to be outside
83 /// of the current clip bounds. This method may conservatively return
84 /// false if it cannot make the determination.
85 bool QuickReject(const SkRect& bounds) const override;
86
87 void DrawPaint(const DlPaint& paint) override;
88 void DrawColor(DlColor color, DlBlendMode mode) override;
89 void DrawLine(const SkPoint& p0,
90 const SkPoint& p1,
91 const DlPaint& paint) override;
92 void DrawRect(const SkRect& rect, const DlPaint& paint) override;
93 void DrawOval(const SkRect& bounds, const DlPaint& paint) override;
94 void DrawCircle(const SkPoint& center,
95 SkScalar radius,
96 const DlPaint& paint) override;
97 void DrawRRect(const SkRRect& rrect, const DlPaint& paint) override;
98 void DrawDRRect(const SkRRect& outer,
99 const SkRRect& inner,
100 const DlPaint& paint) override;
101 void DrawPath(const SkPath& path, const DlPaint& paint) override;
102 void DrawArc(const SkRect& bounds,
103 SkScalar start,
104 SkScalar sweep,
105 bool useCenter,
106 const DlPaint& paint) override;
107 void DrawPoints(PointMode mode,
108 uint32_t count,
109 const SkPoint pts[],
110 const DlPaint& paint) override;
111 void DrawVertices(const DlVertices* vertices,
112 DlBlendMode mode,
113 const DlPaint& paint) override;
114 void DrawImage(const sk_sp<DlImage>& image,
115 const SkPoint point,
116 DlImageSampling sampling,
117 const DlPaint* paint = nullptr) override;
118 void DrawImageRect(
119 const sk_sp<DlImage>& image,
120 const SkRect& src,
121 const SkRect& dst,
122 DlImageSampling sampling,
123 const DlPaint* paint = nullptr,
124 SrcRectConstraint constraint = SrcRectConstraint::kFast) override;
125 void DrawImageNine(const sk_sp<DlImage>& image,
126 const SkIRect& center,
127 const SkRect& dst,
128 DlFilterMode filter,
129 const DlPaint* paint = nullptr) override;
130 void DrawAtlas(const sk_sp<DlImage>& atlas,
131 const SkRSXform xform[],
132 const SkRect tex[],
133 const DlColor colors[],
134 int count,
135 DlBlendMode mode,
136 DlImageSampling sampling,
137 const SkRect* cullRect,
138 const DlPaint* paint = nullptr) override;
139 void DrawDisplayList(const sk_sp<DisplayList> display_list,
140 SkScalar opacity = SK_Scalar1) override;
141 void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
142 SkScalar x,
143 SkScalar y,
144 const DlPaint& paint) override;
145 void DrawShadow(const SkPath& path,
146 const DlColor color,
147 const SkScalar elevation,
148 bool transparent_occluder,
149 SkScalar dpr) override;
150
151 void Flush() override;
152
153 private:
154 SkCanvas* delegate_;
155};
156
157} // namespace flutter
158
159#endif // FLUTTER_DISPLAY_LIST_SKIA_DL_SK_CANVAS_H_
160

source code of flutter_engine/flutter/display_list/skia/dl_sk_canvas.h