Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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/image/dl_image.h"
12
20
22
23namespace flutter {
24
25//------------------------------------------------------------------------------
26/// @brief Developer-facing API for rendering anything *within* the engine.
27///
28/// |DlCanvas| should be used to render anything in the framework classes (i.e.
29/// `lib/ui`), flow and flow layers, embedders, shell, and elsewhere.
30///
31/// The only state carried by implementations of this interface are the clip
32/// and transform which are saved and restored by the |save|, |saveLayer|, and
33/// |restore| calls.
34///
35/// @note The interface resembles closely the familiar |SkCanvas| interface
36/// used throughout the engine.
37class DlCanvas {
38 public:
39 enum class ClipOp {
42 };
43
44 enum class PointMode {
45 kPoints, //!< draw each point separately
46 kLines, //!< draw each separate pair of points as a line segment
47 kPolygon, //!< draw each pair of overlapping points as a line segment
48 };
49
50 enum class SrcRectConstraint {
51 kStrict,
52 kFast,
53 };
54
55 virtual ~DlCanvas() = default;
56
57 virtual SkISize GetBaseLayerSize() const = 0;
58 virtual SkImageInfo GetImageInfo() const = 0;
59
60 virtual void Save() = 0;
61 virtual void SaveLayer(const SkRect* bounds,
62 const DlPaint* paint = nullptr,
63 const DlImageFilter* backdrop = nullptr) = 0;
64 virtual void Restore() = 0;
65 virtual int GetSaveCount() const = 0;
66 virtual void RestoreToCount(int restore_count) = 0;
67
68 virtual void Translate(SkScalar tx, SkScalar ty) = 0;
69 virtual void Scale(SkScalar sx, SkScalar sy) = 0;
70 virtual void Rotate(SkScalar degrees) = 0;
71 virtual void Skew(SkScalar sx, SkScalar sy) = 0;
72
73 // clang-format off
74
75 // 2x3 2D affine subset of a 4x4 transform in row major order
76 virtual void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt,
77 SkScalar myx, SkScalar myy, SkScalar myt) = 0;
78 // full 4x4 transform in row major order
80 SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt,
81 SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt,
82 SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt,
83 SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) = 0;
84 // clang-format on
85 virtual void TransformReset() = 0;
86 virtual void Transform(const SkMatrix* matrix) = 0;
87 virtual void Transform(const SkM44* matrix44) = 0;
88 void Transform(const SkMatrix& matrix) { Transform(&matrix); }
89 void Transform(const SkM44& matrix44) { Transform(&matrix44); }
90 virtual void SetTransform(const SkMatrix* matrix) = 0;
91 virtual void SetTransform(const SkM44* matrix44) = 0;
92 virtual void SetTransform(const SkMatrix& matrix) { SetTransform(&matrix); }
93 virtual void SetTransform(const SkM44& matrix44) { SetTransform(&matrix44); }
94
95 /// Returns the 4x4 full perspective transform representing all transform
96 /// operations executed so far in this DisplayList within the enclosing
97 /// save stack.
99 /// Returns the 3x3 partial perspective transform representing all transform
100 /// operations executed so far in this DisplayList within the enclosing
101 /// save stack.
102 virtual SkMatrix GetTransform() const = 0;
103
104 virtual void ClipRect(const SkRect& rect,
105 ClipOp clip_op = ClipOp::kIntersect,
106 bool is_aa = false) = 0;
107 virtual void ClipRRect(const SkRRect& rrect,
108 ClipOp clip_op = ClipOp::kIntersect,
109 bool is_aa = false) = 0;
110 virtual void ClipPath(const SkPath& path,
111 ClipOp clip_op = ClipOp::kIntersect,
112 bool is_aa = false) = 0;
113
114 /// Conservative estimate of the bounds of all outstanding clip operations
115 /// measured in the coordinate space within which this DisplayList will
116 /// be rendered.
117 virtual SkRect GetDestinationClipBounds() const = 0;
118 /// Conservative estimate of the bounds of all outstanding clip operations
119 /// transformed into the local coordinate space in which currently
120 /// recorded rendering operations are interpreted.
121 virtual SkRect GetLocalClipBounds() const = 0;
122
123 /// Return true iff the supplied bounds are easily shown to be outside
124 /// of the current clip bounds. This method may conservatively return
125 /// false if it cannot make the determination.
126 virtual bool QuickReject(const SkRect& bounds) const = 0;
127
128 virtual void DrawPaint(const DlPaint& paint) = 0;
129 virtual void DrawColor(DlColor color,
132 virtual void DrawLine(const SkPoint& p0,
133 const SkPoint& p1,
134 const DlPaint& paint) = 0;
135 virtual void DrawRect(const SkRect& rect, const DlPaint& paint) = 0;
136 virtual void DrawOval(const SkRect& bounds, const DlPaint& paint) = 0;
137 virtual void DrawCircle(const SkPoint& center,
138 SkScalar radius,
139 const DlPaint& paint) = 0;
140 virtual void DrawRRect(const SkRRect& rrect, const DlPaint& paint) = 0;
141 virtual void DrawDRRect(const SkRRect& outer,
142 const SkRRect& inner,
143 const DlPaint& paint) = 0;
144 virtual void DrawPath(const SkPath& path, const DlPaint& paint) = 0;
145 virtual void DrawArc(const SkRect& bounds,
147 SkScalar sweep,
148 bool useCenter,
149 const DlPaint& paint) = 0;
151 uint32_t count,
152 const SkPoint pts[],
153 const DlPaint& paint) = 0;
154 virtual void DrawVertices(const DlVertices* vertices,
156 const DlPaint& paint) = 0;
157 void DrawVertices(const std::shared_ptr<const DlVertices>& vertices,
159 const DlPaint& paint) {
160 DrawVertices(vertices.get(), mode, paint);
161 }
162 virtual void DrawImage(const sk_sp<DlImage>& image,
163 const SkPoint point,
164 DlImageSampling sampling,
165 const DlPaint* paint = nullptr) = 0;
166 virtual void DrawImageRect(
167 const sk_sp<DlImage>& image,
168 const SkRect& src,
169 const SkRect& dst,
170 DlImageSampling sampling,
171 const DlPaint* paint = nullptr,
173 virtual void DrawImageRect(
174 const sk_sp<DlImage>& image,
175 const SkIRect& src,
176 const SkRect& dst,
177 DlImageSampling sampling,
178 const DlPaint* paint = nullptr,
180 DrawImageRect(image, SkRect::Make(src), dst, sampling, paint, constraint);
181 }
183 const SkRect& dst,
184 DlImageSampling sampling,
185 const DlPaint* paint = nullptr,
187 DrawImageRect(image, image->bounds(), dst, sampling, paint, constraint);
188 }
189 virtual void DrawImageNine(const sk_sp<DlImage>& image,
190 const SkIRect& center,
191 const SkRect& dst,
192 DlFilterMode filter,
193 const DlPaint* paint = nullptr) = 0;
194 virtual void DrawAtlas(const sk_sp<DlImage>& atlas,
195 const SkRSXform xform[],
196 const SkRect tex[],
197 const DlColor colors[],
198 int count,
200 DlImageSampling sampling,
201 const SkRect* cullRect,
202 const DlPaint* paint = nullptr) = 0;
203 virtual void DrawDisplayList(const sk_sp<DisplayList> display_list,
204 SkScalar opacity = SK_Scalar1) = 0;
205
206 virtual void DrawTextFrame(
207 const std::shared_ptr<impeller::TextFrame>& text_frame,
208 SkScalar x,
209 SkScalar y,
210 const DlPaint& paint) = 0;
211
212 virtual void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
213 SkScalar x,
214 SkScalar y,
215 const DlPaint& paint) = 0;
216 virtual void DrawShadow(const SkPath& path,
217 const DlColor color,
218 const SkScalar elevation,
219 bool transparent_occluder,
220 SkScalar dpr) = 0;
221
222 virtual void Flush() = 0;
223
224 static constexpr SkScalar kShadowLightHeight = 600;
225 static constexpr SkScalar kShadowLightRadius = 800;
226
228 float elevation,
229 SkScalar dpr,
230 const SkMatrix& ctm);
231};
232
234 public:
235 DlAutoCanvasRestore(DlCanvas* canvas, bool do_save) : canvas_(canvas) {
236 if (canvas) {
237 canvas_ = canvas;
238 restore_count_ = canvas->GetSaveCount();
239 if (do_save) {
240 canvas_->Save();
241 }
242 } else {
243 canvas_ = nullptr;
244 restore_count_ = 0;
245 }
246 }
247
249
250 void Restore() {
251 if (canvas_) {
252 canvas_->RestoreToCount(restore_count_);
253 canvas_ = nullptr;
254 }
255 }
256
257 private:
258 DlCanvas* canvas_;
259 int restore_count_;
260
262};
263
264} // namespace flutter
265
266#endif // FLUTTER_DISPLAY_LIST_DL_CANVAS_H_
int count
SkColor4f color
#define SK_Scalar1
Definition SkScalar.h:18
static SkScalar center(float pos0, float pos1)
SkIRect bounds() const
Definition SkImage.h:303
Definition SkM44.h:150
DlAutoCanvasRestore(DlCanvas *canvas, bool do_save)
Definition dl_canvas.h:235
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
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
@ kLines
draw each separate pair of points as a line segment
@ kPolygon
draw each pair of overlapping points as a line segment
@ kPoints
draw each point separately
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:182
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:93
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:225
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 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:173
void Transform(const SkM44 &matrix44)
Definition dl_canvas.h:89
static constexpr SkScalar kShadowLightHeight
Definition dl_canvas.h:224
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:131
virtual void Skew(SkScalar sx, SkScalar sy)=0
virtual void SetTransform(const SkMatrix &matrix)
Definition dl_canvas.h:92
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:88
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:157
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
sk_sp< SkImage > image
Definition examples.cpp:29
float SkScalar
Definition extension.cpp:12
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
Definition macros.h:31
double y
double x
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
static SkRect Make(const SkISize &size)
Definition SkRect.h:669