Flutter Engine
The Flutter Engine
dl_canvas.h
Go to the documentation of this file.
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_DL_CANVAS_H_
6#define FLUTTER_DISPLAY_LIST_DL_CANVAS_H_
7
8#include "flutter/display_list/dl_blend_mode.h"
9#include "flutter/display_list/dl_paint.h"
10#include "flutter/display_list/dl_vertices.h"
11#include "flutter/display_list/geometry/dl_geometry_types.h"
12#include "flutter/display_list/image/dl_image.h"
13
21
23
24namespace flutter {
25
26//------------------------------------------------------------------------------
27/// @brief Developer-facing API for rendering anything *within* the engine.
28///
29/// |DlCanvas| should be used to render anything in the framework classes (i.e.
30/// `lib/ui`), flow and flow layers, embedders, shell, and elsewhere.
31///
32/// The only state carried by implementations of this interface are the clip
33/// and transform which are saved and restored by the |save|, |saveLayer|, and
34/// |restore| calls.
35///
36/// @note The interface resembles closely the familiar |SkCanvas| interface
37/// used throughout the engine.
38class DlCanvas {
39 public:
40 enum class ClipOp {
43 };
44
45 enum class PointMode {
46 kPoints, //!< draw each point separately
47 kLines, //!< draw each separate pair of points as a line segment
48 kPolygon, //!< draw each pair of overlapping points as a line segment
49 };
50
51 enum class SrcRectConstraint {
52 kStrict,
53 kFast,
54 };
55
56 virtual ~DlCanvas() = default;
57
58 virtual SkISize GetBaseLayerSize() const = 0;
59 virtual SkImageInfo GetImageInfo() const = 0;
60
61 virtual void Save() = 0;
62 virtual void SaveLayer(const SkRect* bounds,
63 const DlPaint* paint = nullptr,
64 const DlImageFilter* backdrop = nullptr) = 0;
65 virtual void Restore() = 0;
66 virtual int GetSaveCount() const = 0;
67 virtual void RestoreToCount(int restore_count) = 0;
68
69 virtual void Translate(SkScalar tx, SkScalar ty) = 0;
70 virtual void Scale(SkScalar sx, SkScalar sy) = 0;
71 virtual void Rotate(SkScalar degrees) = 0;
72 virtual void Skew(SkScalar sx, SkScalar sy) = 0;
73
74 // clang-format off
75
76 // 2x3 2D affine subset of a 4x4 transform in row major order
77 virtual void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt,
78 SkScalar myx, SkScalar myy, SkScalar myt) = 0;
79 // full 4x4 transform in row major order
81 SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt,
82 SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt,
83 SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt,
84 SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) = 0;
85 // clang-format on
86 virtual void TransformReset() = 0;
87 virtual void Transform(const SkMatrix* matrix) = 0;
88 virtual void Transform(const SkM44* matrix44) = 0;
90 void Transform(const SkM44& matrix44) { Transform(&matrix44); }
91 virtual void SetTransform(const SkMatrix* matrix) = 0;
92 virtual void SetTransform(const SkM44* matrix44) = 0;
93 virtual void SetTransform(const SkMatrix& matrix) { SetTransform(&matrix); }
94 virtual void SetTransform(const SkM44& matrix44) { SetTransform(&matrix44); }
95
96 /// Returns the 4x4 full perspective transform representing all transform
97 /// operations executed so far in this DisplayList within the enclosing
98 /// save stack.
100 /// Returns the 3x3 partial perspective transform representing all transform
101 /// operations executed so far in this DisplayList within the enclosing
102 /// save stack.
103 virtual SkMatrix GetTransform() const = 0;
104
105 virtual void ClipRect(const SkRect& rect,
106 ClipOp clip_op = ClipOp::kIntersect,
107 bool is_aa = false) = 0;
108 virtual void ClipRRect(const SkRRect& rrect,
109 ClipOp clip_op = ClipOp::kIntersect,
110 bool is_aa = false) = 0;
111 virtual void ClipPath(const SkPath& path,
112 ClipOp clip_op = ClipOp::kIntersect,
113 bool is_aa = false) = 0;
114
115 /// Conservative estimate of the bounds of all outstanding clip operations
116 /// measured in the coordinate space within which this DisplayList will
117 /// be rendered.
118 virtual SkRect GetDestinationClipBounds() const = 0;
119 /// Conservative estimate of the bounds of all outstanding clip operations
120 /// transformed into the local coordinate space in which currently
121 /// recorded rendering operations are interpreted.
122 virtual SkRect GetLocalClipBounds() const = 0;
123
124 /// Return true iff the supplied bounds are easily shown to be outside
125 /// of the current clip bounds. This method may conservatively return
126 /// false if it cannot make the determination.
127 virtual bool QuickReject(const SkRect& bounds) const = 0;
128
129 virtual void DrawPaint(const DlPaint& paint) = 0;
130 virtual void DrawColor(DlColor color,
133 virtual void DrawLine(const SkPoint& p0,
134 const SkPoint& p1,
135 const DlPaint& paint) = 0;
136 virtual void DrawDashedLine(const DlPoint& p0,
137 const DlPoint& p1,
138 DlScalar on_length,
139 DlScalar off_length,
140 const DlPaint& paint) = 0;
141 virtual void DrawRect(const SkRect& rect, const DlPaint& paint) = 0;
142 virtual void DrawOval(const SkRect& bounds, const DlPaint& paint) = 0;
143 virtual void DrawCircle(const SkPoint& center,
144 SkScalar radius,
145 const DlPaint& paint) = 0;
146 virtual void DrawRRect(const SkRRect& rrect, const DlPaint& paint) = 0;
147 virtual void DrawDRRect(const SkRRect& outer,
148 const SkRRect& inner,
149 const DlPaint& paint) = 0;
150 virtual void DrawPath(const SkPath& path, const DlPaint& paint) = 0;
151 virtual void DrawArc(const SkRect& bounds,
152 SkScalar start,
153 SkScalar sweep,
154 bool useCenter,
155 const DlPaint& paint) = 0;
157 uint32_t count,
158 const SkPoint pts[],
159 const DlPaint& paint) = 0;
160 virtual void DrawVertices(const DlVertices* vertices,
162 const DlPaint& paint) = 0;
163 void DrawVertices(const std::shared_ptr<const DlVertices>& vertices,
165 const DlPaint& paint) {
166 DrawVertices(vertices.get(), mode, paint);
167 }
168 virtual void DrawImage(const sk_sp<DlImage>& image,
169 const SkPoint point,
171 const DlPaint* paint = nullptr) = 0;
172 virtual void DrawImageRect(
173 const sk_sp<DlImage>& image,
174 const SkRect& src,
175 const SkRect& dst,
177 const DlPaint* paint = nullptr,
179 virtual void DrawImageRect(
180 const sk_sp<DlImage>& image,
181 const SkIRect& src,
182 const SkRect& dst,
184 const DlPaint* paint = nullptr,
187 }
189 const SkRect& dst,
191 const DlPaint* paint = nullptr,
193 DrawImageRect(image, image->bounds(), dst, sampling, paint, constraint);
194 }
195 virtual void DrawImageNine(const sk_sp<DlImage>& image,
196 const SkIRect& center,
197 const SkRect& dst,
198 DlFilterMode filter,
199 const DlPaint* paint = nullptr) = 0;
200 virtual void DrawAtlas(const sk_sp<DlImage>& atlas,
201 const SkRSXform xform[],
202 const SkRect tex[],
203 const DlColor colors[],
204 int count,
207 const SkRect* cullRect,
208 const DlPaint* paint = nullptr) = 0;
209 virtual void DrawDisplayList(const sk_sp<DisplayList> display_list,
210 SkScalar opacity = SK_Scalar1) = 0;
211
212 virtual void DrawTextFrame(
213 const std::shared_ptr<impeller::TextFrame>& text_frame,
214 SkScalar x,
215 SkScalar y,
216 const DlPaint& paint) = 0;
217
218 virtual void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
219 SkScalar x,
220 SkScalar y,
221 const DlPaint& paint) = 0;
222 virtual void DrawShadow(const SkPath& path,
223 const DlColor color,
224 const SkScalar elevation,
225 bool transparent_occluder,
226 SkScalar dpr) = 0;
227
228 virtual void Flush() = 0;
229
230 static constexpr SkScalar kShadowLightHeight = 600;
231 static constexpr SkScalar kShadowLightRadius = 800;
232
234 float elevation,
235 SkScalar dpr,
236 const SkMatrix& ctm);
237};
238
240 public:
241 DlAutoCanvasRestore(DlCanvas* canvas, bool do_save) : canvas_(canvas) {
242 if (canvas) {
243 canvas_ = canvas;
244 restore_count_ = canvas->GetSaveCount();
245 if (do_save) {
246 canvas_->Save();
247 }
248 } else {
249 canvas_ = nullptr;
250 restore_count_ = 0;
251 }
252 }
253
255
256 void Restore() {
257 if (canvas_) {
258 canvas_->RestoreToCount(restore_count_);
259 canvas_ = nullptr;
260 }
261 }
262
263 private:
264 DlCanvas* canvas_;
265 int restore_count_;
266
267 FML_DISALLOW_COPY_ASSIGN_AND_MOVE(DlAutoCanvasRestore);
268};
269
270} // namespace flutter
271
272#endif // FLUTTER_DISPLAY_LIST_DL_CANVAS_H_
int count
Definition: FontMgrTest.cpp:50
#define SK_Scalar1
Definition: SkScalar.h:18
SkIRect bounds() const
Definition: SkImage.h:303
Definition: SkM44.h:150
Definition: SkPath.h:59
DlAutoCanvasRestore(DlCanvas *canvas, bool do_save)
Definition: dl_canvas.h:241
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
virtual void DrawPaint(const DlPaint &paint)=0
virtual void Rotate(SkScalar degrees)=0
virtual void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myt)=0
virtual void TransformReset()=0
virtual void DrawRect(const SkRect &rect, const DlPaint &paint)=0
virtual void Transform(const SkMatrix *matrix)=0
virtual void DrawTextFrame(const std::shared_ptr< impeller::TextFrame > &text_frame, SkScalar x, SkScalar y, const DlPaint &paint)=0
virtual void DrawDRRect(const SkRRect &outer, const SkRRect &inner, const DlPaint &paint)=0
virtual void DrawAtlas(const sk_sp< DlImage > &atlas, const SkRSXform xform[], const SkRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, const SkRect *cullRect, const DlPaint *paint=nullptr)=0
virtual void Scale(SkScalar sx, SkScalar sy)=0
virtual void DrawCircle(const SkPoint &center, SkScalar radius, const DlPaint &paint)=0
virtual int GetSaveCount() const =0
virtual void ClipRect(const SkRect &rect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)
Definition: dl_canvas.h:188
virtual void DrawPoints(PointMode mode, uint32_t count, const SkPoint pts[], const DlPaint &paint)=0
virtual SkM44 GetTransformFullPerspective() const =0
virtual void SetTransform(const SkM44 &matrix44)
Definition: dl_canvas.h:94
virtual void SetTransform(const SkMatrix *matrix)=0
virtual SkRect GetDestinationClipBounds() const =0
virtual void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr)=0
static constexpr SkScalar kShadowLightRadius
Definition: dl_canvas.h:231
virtual SkRect GetLocalClipBounds() const =0
virtual void DrawRRect(const SkRRect &rrect, const DlPaint &paint)=0
virtual bool QuickReject(const SkRect &bounds) const =0
virtual void DrawColor(DlColor color, DlBlendMode mode=DlBlendMode::kSrcOver)=0
virtual void DrawDashedLine(const DlPoint &p0, const DlPoint &p1, DlScalar on_length, DlScalar off_length, const DlPaint &paint)=0
virtual void Transform(const SkM44 *matrix44)=0
virtual SkImageInfo GetImageInfo() const =0
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkIRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)
Definition: dl_canvas.h:179
void Transform(const SkM44 &matrix44)
Definition: dl_canvas.h:90
static constexpr SkScalar kShadowLightHeight
Definition: dl_canvas.h:230
virtual void DrawTextBlob(const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const DlPaint &paint)=0
virtual void DrawOval(const SkRect &bounds, const DlPaint &paint)=0
virtual void DrawVertices(const DlVertices *vertices, DlBlendMode mode, const DlPaint &paint)=0
virtual SkISize GetBaseLayerSize() const =0
virtual void Restore()=0
virtual void TransformFullPerspective(SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt)=0
virtual void RestoreToCount(int restore_count)=0
virtual void Translate(SkScalar tx, SkScalar ty)=0
virtual ~DlCanvas()=default
virtual void SetTransform(const SkM44 *matrix44)=0
static SkRect ComputeShadowBounds(const SkPath &path, float elevation, SkScalar dpr, const SkMatrix &ctm)
Definition: dl_canvas.cc:12
virtual void DrawArc(const SkRect &bounds, SkScalar start, SkScalar sweep, bool useCenter, const DlPaint &paint)=0
void Clear(DlColor color)
Definition: dl_canvas.h:132
virtual void Skew(SkScalar sx, SkScalar sy)=0
virtual void SetTransform(const SkMatrix &matrix)
Definition: dl_canvas.h:93
virtual void DrawLine(const SkPoint &p0, const SkPoint &p1, const DlPaint &paint)=0
virtual void DrawDisplayList(const sk_sp< DisplayList > display_list, SkScalar opacity=SK_Scalar1)=0
void Transform(const SkMatrix &matrix)
Definition: dl_canvas.h:89
virtual void DrawShadow(const SkPath &path, const DlColor color, const SkScalar elevation, bool transparent_occluder, SkScalar dpr)=0
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)=0
virtual SkMatrix GetTransform() const =0
virtual void DrawImage(const sk_sp< DlImage > &image, const SkPoint point, DlImageSampling sampling, const DlPaint *paint=nullptr)=0
void DrawVertices(const std::shared_ptr< const DlVertices > &vertices, DlBlendMode mode, const DlPaint &paint)
Definition: dl_canvas.h:163
virtual void ClipPath(const SkPath &path, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
virtual void Flush()=0
virtual void DrawImageNine(const sk_sp< DlImage > &image, const SkIRect &center, const SkRect &dst, DlFilterMode filter, const DlPaint *paint=nullptr)=0
virtual void ClipRRect(const SkRRect &rrect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
virtual void Save()=0
virtual void DrawPath(const SkPath &path, const DlPaint &paint)=0
Holds all of the data (both required and optional) for a DisplayList drawVertices call.
Definition: dl_vertices.h:71
const Paint & paint
Definition: color_source.cc:38
DlColor color
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< const SkImageFilter > backdrop
Definition: SkRecords.h:191
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions sampling
Definition: SkRecords.h:337
impeller::Scalar DlScalar
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
@ kSrcOver
r = s + (1-sa)*d
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
dst
Definition: cp.py:12
Definition: SkRect.h:32
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669