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
17
18namespace flutter {
19
20//------------------------------------------------------------------------------
21/// @brief Developer-facing API for rendering anything *within* the engine.
22///
23/// |DlCanvas| should be used to render anything in the framework classes (i.e.
24/// `lib/ui`), flow and flow layers, embedders, shell, and elsewhere.
25///
26/// The only state carried by implementations of this interface are the clip
27/// and transform which are saved and restored by the |save|, |saveLayer|, and
28/// |restore| calls.
29///
30/// @note The interface resembles closely the familiar |SkCanvas| interface
31/// used throughout the engine.
32class DlCanvas {
33 public:
34 virtual ~DlCanvas() = default;
35
36 virtual DlISize GetBaseLayerDimensions() const = 0;
37 virtual SkImageInfo GetImageInfo() const = 0;
38
39 virtual void Save() = 0;
40 virtual void SaveLayer(const std::optional<DlRect>& bounds,
41 const DlPaint* paint = nullptr,
42 const DlImageFilter* backdrop = nullptr,
43 std::optional<int64_t> backdrop_id = std::nullopt) = 0;
44 virtual void Restore() = 0;
45 virtual int GetSaveCount() const = 0;
46 virtual void RestoreToCount(int restore_count) = 0;
47
48 virtual void Translate(DlScalar tx, DlScalar ty) = 0;
49 virtual void Scale(DlScalar sx, DlScalar sy) = 0;
50 virtual void Rotate(DlScalar degrees) = 0;
51 virtual void Skew(DlScalar sx, DlScalar sy) = 0;
52
53 // clang-format off
54
55 // 2x3 2D affine subset of a 4x4 transform in row major order
56 virtual void Transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt,
57 DlScalar myx, DlScalar myy, DlScalar myt) = 0;
58 // full 4x4 transform in row major order
60 DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt,
61 DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt,
62 DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt,
63 DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) = 0;
64 // clang-format on
65 virtual void TransformReset() = 0;
66 virtual void Transform(const DlMatrix& matrix) = 0;
67 virtual void SetTransform(const DlMatrix& matrix) = 0;
68
69 virtual DlMatrix GetMatrix() const = 0;
70
71 virtual void ClipRect(const DlRect& rect,
73 bool is_aa = false) = 0;
74 virtual void ClipOval(const DlRect& bounds,
76 bool is_aa = false) = 0;
77 virtual void ClipRoundRect(const DlRoundRect& rrect,
79 bool is_aa = false) = 0;
82 bool is_aa = false) = 0;
83 virtual void ClipPath(const DlPath& path,
85 bool is_aa = false) = 0;
86
87 /// Conservative estimate of the bounds of all outstanding clip operations
88 /// measured in the coordinate space within which this DisplayList will
89 /// be rendered.
91 /// Conservative estimate of the bounds of all outstanding clip operations
92 /// transformed into the local coordinate space in which currently
93 /// recorded rendering operations are interpreted.
94 virtual DlRect GetLocalClipCoverage() const = 0;
95
96 /// Return true iff the supplied bounds are easily shown to be outside
97 /// of the current clip bounds. This method may conservatively return
98 /// false if it cannot make the determination.
99 virtual bool QuickReject(const DlRect& bounds) const = 0;
100
101 virtual void DrawPaint(const DlPaint& paint) = 0;
102 virtual void DrawColor(DlColor color,
103 DlBlendMode mode = DlBlendMode::kSrcOver) = 0;
104 void Clear(DlColor color) { DrawColor(color, DlBlendMode::kSrc); }
105 virtual void DrawLine(const DlPoint& p0,
106 const DlPoint& p1,
107 const DlPaint& paint) = 0;
108 virtual void DrawDashedLine(const DlPoint& p0,
109 const DlPoint& p1,
110 DlScalar on_length,
111 DlScalar off_length,
112 const DlPaint& paint) = 0;
113 virtual void DrawRect(const DlRect& rect, const DlPaint& paint) = 0;
114 virtual void DrawOval(const DlRect& bounds, const DlPaint& paint) = 0;
115 virtual void DrawCircle(const DlPoint& center,
116 DlScalar radius,
117 const DlPaint& paint) = 0;
118 virtual void DrawRoundRect(const DlRoundRect& rrect,
119 const DlPaint& paint) = 0;
120 virtual void DrawDiffRoundRect(const DlRoundRect& outer,
121 const DlRoundRect& inner,
122 const DlPaint& paint) = 0;
124 const DlPaint& paint) = 0;
125 virtual void DrawPath(const DlPath& path, const DlPaint& paint) = 0;
126 virtual void DrawArc(const DlRect& bounds,
127 DlScalar start,
128 DlScalar sweep,
129 bool useCenter,
130 const DlPaint& paint) = 0;
131 virtual void DrawPoints(DlPointMode mode,
132 uint32_t count,
133 const DlPoint pts[],
134 const DlPaint& paint) = 0;
135 virtual void DrawVertices(const std::shared_ptr<DlVertices>& vertices,
136 DlBlendMode mode,
137 const DlPaint& paint) = 0;
138 virtual void DrawImage(const sk_sp<DlImage>& image,
139 const DlPoint& point,
140 DlImageSampling sampling,
141 const DlPaint* paint = nullptr) = 0;
142 virtual void DrawImageRect(
143 const sk_sp<DlImage>& image,
144 const DlRect& src,
145 const DlRect& dst,
146 DlImageSampling sampling,
147 const DlPaint* paint = nullptr,
149 virtual void DrawImageRect(
150 const sk_sp<DlImage>& image,
151 const DlIRect& src,
152 const DlRect& dst,
153 DlImageSampling sampling,
154 const DlPaint* paint = nullptr,
156 auto float_src = DlRect::MakeLTRB(src.GetLeft(), src.GetTop(),
157 src.GetRight(), src.GetBottom());
158 DrawImageRect(image, float_src, dst, sampling, paint, constraint);
159 }
161 const sk_sp<DlImage>& image,
162 const DlRect& dst,
163 DlImageSampling sampling,
164 const DlPaint* paint = nullptr,
166 DrawImageRect(image, image->GetBounds(), dst, sampling, paint, constraint);
167 }
168 virtual void DrawImageNine(const sk_sp<DlImage>& image,
169 const DlIRect& center,
170 const DlRect& dst,
171 DlFilterMode filter,
172 const DlPaint* paint = nullptr) = 0;
173 virtual void DrawAtlas(const sk_sp<DlImage>& atlas,
174 const DlRSTransform xform[],
175 const DlRect tex[],
176 const DlColor colors[],
177 int count,
178 DlBlendMode mode,
179 DlImageSampling sampling,
180 const DlRect* cullRect,
181 const DlPaint* paint = nullptr) = 0;
182 virtual void DrawDisplayList(const sk_sp<DisplayList> display_list,
183 DlScalar opacity = SK_Scalar1) = 0;
184
185 virtual void DrawText(const std::shared_ptr<DlText>& text,
186 DlScalar x,
187 DlScalar y,
188 const DlPaint& paint) = 0;
189
190 /// @brief Draws the shadow of the given |path| rendered in the provided
191 /// |color| (which is only consulted for its opacity) as would be
192 /// produced by a directional light source uniformly shining in
193 /// the device space direction {0, -1, 1} against a backdrop
194 /// which is |elevation * dpr| device coordinates below the |path|
195 /// in the Z direction.
196 ///
197 /// Normally the renderer might consider omitting the rendering of any
198 /// of the shadow pixels that fall under the |path| itself, as an
199 /// optimization, unless the |transparent_occluder| flag is specified
200 /// which would indicate that the optimization isn't appropriate.
201 ///
202 /// Note that the |elevation| and |dpr| are unique in the API for being
203 /// considered in pure device coordinates while the |path| is interpreted
204 /// relative to the current local-to-device transform.
205 ///
206 /// @see |ComputeShadowBounds|
207 virtual void DrawShadow(const DlPath& path,
208 const DlColor color,
209 const DlScalar elevation,
210 bool transparent_occluder,
211 DlScalar dpr) = 0;
212
213 virtual void Flush() = 0;
214
215 static constexpr DlScalar kShadowLightHeight = 600;
216 static constexpr DlScalar kShadowLightRadius = 800;
217
218 /// @brief Compute the local coverage for a |DrawShadow| operation using
219 /// the given parameters (excluding the color and the transparent
220 /// occluder parameters which do not affect the bounds).
221 ///
222 /// Since the elevation is expressed in device coordinates relative to the
223 /// provided |dpr| value, the |ctm| of the final rendering coordinate
224 /// system that will be applied to the path must be provided so the two
225 /// sets of coordinates (path and light source) can be correlated.
226 ///
227 /// @see |DrawShadow|
229 float elevation,
230 DlScalar dpr,
231 const DlMatrix& ctm);
232};
233
235 public:
236 DlAutoCanvasRestore(DlCanvas* canvas, bool do_save) : canvas_(canvas) {
237 if (canvas) {
238 canvas_ = canvas;
239 restore_count_ = canvas->GetSaveCount();
240 if (do_save) {
241 canvas_->Save();
242 }
243 } else {
244 canvas_ = nullptr;
245 restore_count_ = 0;
246 }
247 }
248
250
251 void Restore() {
252 if (canvas_) {
253 canvas_->RestoreToCount(restore_count_);
254 canvas_ = nullptr;
255 }
256 }
257
258 private:
259 DlCanvas* canvas_;
260 int restore_count_;
261
263};
264
265} // namespace flutter
266
267#endif // FLUTTER_DISPLAY_LIST_DL_CANVAS_H_
DlAutoCanvasRestore(DlCanvas *canvas, bool do_save)
Definition dl_canvas.h:236
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual void Transform(const DlMatrix &matrix)=0
virtual void ClipRoundSuperellipse(const DlRoundSuperellipse &rse, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void DrawPaint(const DlPaint &paint)=0
virtual void DrawCircle(const DlPoint &center, DlScalar radius, const DlPaint &paint)=0
virtual void ClipRoundRect(const DlRoundRect &rrect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual DlRect GetDestinationClipCoverage() const =0
virtual void DrawRoundRect(const DlRoundRect &rrect, const DlPaint &paint)=0
virtual void TransformReset()=0
virtual void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1)=0
virtual DlRect GetLocalClipCoverage() const =0
virtual bool QuickReject(const DlRect &bounds) const =0
virtual DlISize GetBaseLayerDimensions() const =0
virtual void TransformFullPerspective(DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt)=0
virtual int GetSaveCount() const =0
virtual void DrawImageNine(const sk_sp< DlImage > &image, const DlIRect &center, const DlRect &dst, DlFilterMode filter, const DlPaint *paint=nullptr)=0
virtual void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt)=0
virtual void DrawLine(const DlPoint &p0, const DlPoint &p1, const DlPaint &paint)=0
virtual void DrawDiffRoundRect(const DlRoundRect &outer, const DlRoundRect &inner, const DlPaint &paint)=0
virtual void DrawRect(const DlRect &rect, const DlPaint &paint)=0
virtual void DrawVertices(const std::shared_ptr< DlVertices > &vertices, DlBlendMode mode, const DlPaint &paint)=0
virtual void ClipOval(const DlRect &bounds, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void Transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myt)=0
virtual void SetTransform(const DlMatrix &matrix)=0
static constexpr DlScalar kShadowLightHeight
Definition dl_canvas.h:215
virtual void DrawText(const std::shared_ptr< DlText > &text, DlScalar x, DlScalar y, const DlPaint &paint)=0
virtual void DrawImage(const sk_sp< DlImage > &image, const DlPoint &point, DlImageSampling sampling, const DlPaint *paint=nullptr)=0
virtual void DrawOval(const DlRect &bounds, const DlPaint &paint)=0
virtual void Translate(DlScalar tx, DlScalar ty)=0
virtual void DrawColor(DlColor color, DlBlendMode mode=DlBlendMode::kSrcOver)=0
virtual DlMatrix GetMatrix() const =0
virtual void Rotate(DlScalar degrees)=0
virtual void DrawDashedLine(const DlPoint &p0, const DlPoint &p1, DlScalar on_length, DlScalar off_length, const DlPaint &paint)=0
virtual SkImageInfo GetImageInfo() const =0
virtual void DrawPath(const DlPath &path, const DlPaint &paint)=0
void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast)
Definition dl_canvas.h:160
static constexpr DlScalar kShadowLightRadius
Definition dl_canvas.h:216
virtual void Restore()=0
virtual void RestoreToCount(int restore_count)=0
virtual ~DlCanvas()=default
virtual void DrawPoints(DlPointMode mode, uint32_t count, const DlPoint pts[], const DlPaint &paint)=0
virtual void ClipPath(const DlPath &path, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void DrawImageRect(const sk_sp< DlImage > &image, const DlIRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast)
Definition dl_canvas.h:149
virtual void DrawRoundSuperellipse(const DlRoundSuperellipse &rse, const DlPaint &paint)=0
void Clear(DlColor color)
Definition dl_canvas.h:104
virtual void DrawArc(const DlRect &bounds, DlScalar start, DlScalar sweep, bool useCenter, const DlPaint &paint)=0
virtual void DrawAtlas(const sk_sp< DlImage > &atlas, const DlRSTransform xform[], const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, const DlRect *cullRect, const DlPaint *paint=nullptr)=0
virtual void Skew(DlScalar sx, DlScalar sy)=0
virtual void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast)=0
virtual void Flush()=0
virtual void Scale(DlScalar sx, DlScalar sy)=0
static DlRect ComputeShadowBounds(const DlPath &path, float elevation, DlScalar dpr, const DlMatrix &ctm)
Compute the local coverage for a |DrawShadow| operation using the given parameters (excluding the col...
Definition dl_canvas.cc:125
virtual void DrawShadow(const DlPath &path, const DlColor color, const DlScalar elevation, bool transparent_occluder, DlScalar dpr)=0
Draws the shadow of the given |path| rendered in the provided |color| (which is only consulted for it...
virtual void Save()=0
int32_t x
FlutterVulkanImage * image
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
Definition macros.h:31
std::u16string text
double y
impeller::Scalar DlScalar
DlPointMode
Definition dl_types.h:15
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 switch_defs.h:52
DlSrcRectConstraint
Definition dl_types.h:21
BlendMode
Definition color.h:58
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr auto GetBottom() const
Definition rect.h:357
constexpr auto GetTop() const
Definition rect.h:353
constexpr auto GetLeft() const
Definition rect.h:351
constexpr auto GetRight() const
Definition rect.h:355
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129