@@ -56,16 +56,16 @@ void Canvas::Create(Dart_Handle wrapper,
5656 fml::RefPtr<Canvas> canvas = fml::MakeRefCounted<Canvas>(
5757 recorder->BeginRecording (SkRect::MakeLTRB (left, top, right, bottom)));
5858 recorder->set_canvas (canvas);
59- canvas->display_list_recorder_ = recorder->display_list_recorder ();
6059 canvas->AssociateWithDartWrapper (wrapper);
6160}
6261
63- Canvas::Canvas (SkCanvas* canvas) : canvas_(canvas) {}
62+ Canvas::Canvas (sk_sp<DisplayListBuilder> builder)
63+ : display_list_builder_(std::move(builder)) {}
6464
6565Canvas::~Canvas () {}
6666
6767void Canvas::save () {
68- if (display_list_recorder_ ) {
68+ if (display_list_builder_ ) {
6969 builder ()->save ();
7070 }
7171}
@@ -75,7 +75,7 @@ void Canvas::saveLayerWithoutBounds(Dart_Handle paint_objects,
7575 Paint paint (paint_objects, paint_data);
7676
7777 FML_DCHECK (paint.isNotNull ());
78- if (display_list_recorder_ ) {
78+ if (display_list_builder_ ) {
7979 bool restore_with_paint =
8080 paint.sync_to (builder (), kSaveLayerWithPaintFlags );
8181 FML_DCHECK (restore_with_paint);
@@ -94,7 +94,7 @@ void Canvas::saveLayer(double left,
9494
9595 FML_DCHECK (paint.isNotNull ());
9696 SkRect bounds = SkRect::MakeLTRB (left, top, right, bottom);
97- if (display_list_recorder_ ) {
97+ if (display_list_builder_ ) {
9898 bool restore_with_paint =
9999 paint.sync_to (builder (), kSaveLayerWithPaintFlags );
100100 FML_DCHECK (restore_with_paint);
@@ -104,53 +104,53 @@ void Canvas::saveLayer(double left,
104104}
105105
106106void Canvas::restore () {
107- if (display_list_recorder_ ) {
107+ if (display_list_builder_ ) {
108108 builder ()->restore ();
109109 }
110110}
111111
112112int Canvas::getSaveCount () {
113- if (display_list_recorder_ ) {
113+ if (display_list_builder_ ) {
114114 return builder ()->getSaveCount ();
115115 } else {
116116 return 0 ;
117117 }
118118}
119119
120120void Canvas::restoreToCount (int count) {
121- if (display_list_recorder_ && count < getSaveCount ()) {
121+ if (display_list_builder_ && count < getSaveCount ()) {
122122 builder ()->restoreToCount (count);
123123 }
124124}
125125
126126void Canvas::translate (double dx, double dy) {
127- if (display_list_recorder_ ) {
127+ if (display_list_builder_ ) {
128128 builder ()->translate (dx, dy);
129129 }
130130}
131131
132132void Canvas::scale (double sx, double sy) {
133- if (display_list_recorder_ ) {
133+ if (display_list_builder_ ) {
134134 builder ()->scale (sx, sy);
135135 }
136136}
137137
138138void Canvas::rotate (double radians) {
139- if (display_list_recorder_ ) {
139+ if (display_list_builder_ ) {
140140 builder ()->rotate (radians * 180.0 / M_PI);
141141 }
142142}
143143
144144void Canvas::skew (double sx, double sy) {
145- if (display_list_recorder_ ) {
145+ if (display_list_builder_ ) {
146146 builder ()->skew (sx, sy);
147147 }
148148}
149149
150150void Canvas::transform (const tonic::Float64List& matrix4) {
151151 // The Float array stored by Dart Matrix4 is in column-major order
152152 // Both DisplayList and SkM44 constructor take row-major matrix order
153- if (display_list_recorder_ ) {
153+ if (display_list_builder_ ) {
154154 // clang-format off
155155 builder ()->transformFullPerspective (
156156 matrix4[ 0 ], matrix4[ 4 ], matrix4[ 8 ], matrix4[12 ],
@@ -162,10 +162,7 @@ void Canvas::transform(const tonic::Float64List& matrix4) {
162162}
163163
164164void Canvas::getTransform (Dart_Handle matrix4_handle) {
165- SkM44 sk_m44 =
166- display_list_recorder_
167- ? display_list_recorder_->builder ()->getTransformFullPerspective ()
168- : canvas_->getLocalToDevice ();
165+ SkM44 sk_m44 = display_list_builder_->getTransformFullPerspective ();
169166 SkScalar m44_values[16 ];
170167 // The Float array stored by Dart Matrix4 is in column-major order
171168 sk_m44.getColMajor (m44_values);
@@ -181,14 +178,14 @@ void Canvas::clipRect(double left,
181178 double bottom,
182179 SkClipOp clipOp,
183180 bool doAntiAlias) {
184- if (display_list_recorder_ ) {
181+ if (display_list_builder_ ) {
185182 builder ()->clipRect (SkRect::MakeLTRB (left, top, right, bottom), clipOp,
186183 doAntiAlias);
187184 }
188185}
189186
190187void Canvas::clipRRect (const RRect& rrect, bool doAntiAlias) {
191- if (display_list_recorder_ ) {
188+ if (display_list_builder_ ) {
192189 builder ()->clipRRect (rrect.sk_rrect , SkClipOp::kIntersect , doAntiAlias);
193190 }
194191}
@@ -199,13 +196,13 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
199196 ToDart (" Canvas.clipPath called with non-genuine Path." ));
200197 return ;
201198 }
202- if (display_list_recorder_ ) {
199+ if (display_list_builder_ ) {
203200 builder ()->clipPath (path->path (), SkClipOp::kIntersect , doAntiAlias);
204201 }
205202}
206203
207204void Canvas::getDestinationClipBounds (Dart_Handle rect_handle) {
208- if (display_list_recorder_ ) {
205+ if (display_list_builder_ ) {
209206 auto rect = tonic::Float64List (rect_handle);
210207 SkRect bounds = builder ()->getDestinationClipBounds ();
211208 rect[0 ] = bounds.fLeft ;
@@ -216,9 +213,9 @@ void Canvas::getDestinationClipBounds(Dart_Handle rect_handle) {
216213}
217214
218215void Canvas::getLocalClipBounds (Dart_Handle rect_handle) {
219- if (display_list_recorder_ ) {
216+ if (display_list_builder_ ) {
220217 auto rect = tonic::Float64List (rect_handle);
221- SkRect bounds = display_list_recorder_-> builder () ->getLocalClipBounds ();
218+ SkRect bounds = display_list_builder_ ->getLocalClipBounds ();
222219 rect[0 ] = bounds.fLeft ;
223220 rect[1 ] = bounds.fTop ;
224221 rect[2 ] = bounds.fRight ;
@@ -227,7 +224,7 @@ void Canvas::getLocalClipBounds(Dart_Handle rect_handle) {
227224}
228225
229226void Canvas::drawColor (SkColor color, DlBlendMode blend_mode) {
230- if (display_list_recorder_ ) {
227+ if (display_list_builder_ ) {
231228 builder ()->drawColor (color, blend_mode);
232229 }
233230}
@@ -241,7 +238,7 @@ void Canvas::drawLine(double x1,
241238 Paint paint (paint_objects, paint_data);
242239
243240 FML_DCHECK (paint.isNotNull ());
244- if (display_list_recorder_ ) {
241+ if (display_list_builder_ ) {
245242 paint.sync_to (builder (), kDrawLineFlags );
246243 builder ()->drawLine (SkPoint::Make (x1, y1), SkPoint::Make (x2, y2));
247244 }
@@ -251,7 +248,7 @@ void Canvas::drawPaint(Dart_Handle paint_objects, Dart_Handle paint_data) {
251248 Paint paint (paint_objects, paint_data);
252249
253250 FML_DCHECK (paint.isNotNull ());
254- if (display_list_recorder_ ) {
251+ if (display_list_builder_ ) {
255252 paint.sync_to (builder (), kDrawPaintFlags );
256253 std::shared_ptr<const DlImageFilter> filter = builder ()->getImageFilter ();
257254 if (filter && !filter->asColorFilter ()) {
@@ -272,7 +269,7 @@ void Canvas::drawRect(double left,
272269 Paint paint (paint_objects, paint_data);
273270
274271 FML_DCHECK (paint.isNotNull ());
275- if (display_list_recorder_ ) {
272+ if (display_list_builder_ ) {
276273 paint.sync_to (builder (), kDrawRectFlags );
277274 builder ()->drawRect (SkRect::MakeLTRB (left, top, right, bottom));
278275 }
@@ -284,7 +281,7 @@ void Canvas::drawRRect(const RRect& rrect,
284281 Paint paint (paint_objects, paint_data);
285282
286283 FML_DCHECK (paint.isNotNull ());
287- if (display_list_recorder_ ) {
284+ if (display_list_builder_ ) {
288285 paint.sync_to (builder (), kDrawRRectFlags );
289286 builder ()->drawRRect (rrect.sk_rrect );
290287 }
@@ -297,7 +294,7 @@ void Canvas::drawDRRect(const RRect& outer,
297294 Paint paint (paint_objects, paint_data);
298295
299296 FML_DCHECK (paint.isNotNull ());
300- if (display_list_recorder_ ) {
297+ if (display_list_builder_ ) {
301298 paint.sync_to (builder (), kDrawDRRectFlags );
302299 builder ()->drawDRRect (outer.sk_rrect , inner.sk_rrect );
303300 }
@@ -312,7 +309,7 @@ void Canvas::drawOval(double left,
312309 Paint paint (paint_objects, paint_data);
313310
314311 FML_DCHECK (paint.isNotNull ());
315- if (display_list_recorder_ ) {
312+ if (display_list_builder_ ) {
316313 paint.sync_to (builder (), kDrawOvalFlags );
317314 builder ()->drawOval (SkRect::MakeLTRB (left, top, right, bottom));
318315 }
@@ -326,7 +323,7 @@ void Canvas::drawCircle(double x,
326323 Paint paint (paint_objects, paint_data);
327324
328325 FML_DCHECK (paint.isNotNull ());
329- if (display_list_recorder_ ) {
326+ if (display_list_builder_ ) {
330327 paint.sync_to (builder (), kDrawCircleFlags );
331328 builder ()->drawCircle (SkPoint::Make (x, y), radius);
332329 }
@@ -344,7 +341,7 @@ void Canvas::drawArc(double left,
344341 Paint paint (paint_objects, paint_data);
345342
346343 FML_DCHECK (paint.isNotNull ());
347- if (display_list_recorder_ ) {
344+ if (display_list_builder_ ) {
348345 paint.sync_to (builder (),
349346 useCenter //
350347 ? kDrawArcWithCenterFlags
@@ -366,7 +363,7 @@ void Canvas::drawPath(const CanvasPath* path,
366363 ToDart (" Canvas.drawPath called with non-genuine Path." ));
367364 return ;
368365 }
369- if (display_list_recorder_ ) {
366+ if (display_list_builder_ ) {
370367 paint.sync_to (builder (), kDrawPathFlags );
371368 builder ()->drawPath (path->path ());
372369 }
@@ -395,7 +392,7 @@ Dart_Handle Canvas::drawImage(const CanvasImage* image,
395392 }
396393
397394 auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
398- if (display_list_recorder_ ) {
395+ if (display_list_builder_ ) {
399396 bool with_attributes = paint.sync_to (builder (), kDrawImageWithPaintFlags );
400397 builder ()->drawImage (dl_image, SkPoint::Make (x, y), sampling,
401398 with_attributes);
@@ -434,7 +431,7 @@ Dart_Handle Canvas::drawImageRect(const CanvasImage* image,
434431 SkRect src = SkRect::MakeLTRB (src_left, src_top, src_right, src_bottom);
435432 SkRect dst = SkRect::MakeLTRB (dst_left, dst_top, dst_right, dst_bottom);
436433 auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
437- if (display_list_recorder_ ) {
434+ if (display_list_builder_ ) {
438435 bool with_attributes =
439436 paint.sync_to (builder (), kDrawImageRectWithPaintFlags );
440437 builder ()->drawImageRect (dl_image, src, dst, sampling, with_attributes,
@@ -476,7 +473,7 @@ Dart_Handle Canvas::drawImageNine(const CanvasImage* image,
476473 center.round (&icenter);
477474 SkRect dst = SkRect::MakeLTRB (dst_left, dst_top, dst_right, dst_bottom);
478475 auto filter = ImageFilter::FilterModeFromIndex (bitmapSamplingIndex);
479- if (display_list_recorder_ ) {
476+ if (display_list_builder_ ) {
480477 bool with_attributes =
481478 paint.sync_to (builder (), kDrawImageNineWithPaintFlags );
482479 builder ()->drawImageNine (dl_image, icenter, dst, filter, with_attributes);
@@ -491,10 +488,8 @@ void Canvas::drawPicture(Picture* picture) {
491488 return ;
492489 }
493490 if (picture->display_list ()) {
494- if (display_list_recorder_ ) {
491+ if (display_list_builder_ ) {
495492 builder ()->drawDisplayList (picture->display_list ());
496- } else if (canvas_) {
497- picture->display_list ()->RenderTo (canvas_);
498493 }
499494 } else {
500495 FML_DCHECK (false );
@@ -511,7 +506,7 @@ void Canvas::drawPoints(Dart_Handle paint_objects,
511506 " SkPoint doesn't use floats." );
512507
513508 FML_DCHECK (paint.isNotNull ());
514- if (display_list_recorder_ ) {
509+ if (display_list_builder_ ) {
515510 switch (point_mode) {
516511 case SkCanvas::kPoints_PointMode :
517512 paint.sync_to (builder (), kDrawPointsAsPointsFlags );
@@ -541,7 +536,7 @@ void Canvas::drawVertices(const Vertices* vertices,
541536 return ;
542537 }
543538 FML_DCHECK (paint.isNotNull ());
544- if (display_list_recorder_ ) {
539+ if (display_list_builder_ ) {
545540 paint.sync_to (builder (), kDrawVerticesFlags );
546541 builder ()->drawVertices (vertices->vertices (), blend_mode);
547542 }
@@ -578,7 +573,7 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects,
578573 auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
579574
580575 FML_DCHECK (paint.isNotNull ());
581- if (display_list_recorder_ ) {
576+ if (display_list_builder_ ) {
582577 tonic::Float32List transforms (transforms_handle);
583578 tonic::Float32List rects (rects_handle);
584579 tonic::Int32List colors (colors_handle);
@@ -610,7 +605,7 @@ void Canvas::drawShadow(const CanvasPath* path,
610605 ->get_window (0 )
611606 ->viewport_metrics ()
612607 .device_pixel_ratio ;
613- if (display_list_recorder_ ) {
608+ if (display_list_builder_ ) {
614609 // The DrawShadow mechanism results in non-public operations to be
615610 // performed on the canvas involving an SkDrawShadowRec. Since we
616611 // cannot include the header that defines that structure, we cannot
@@ -624,8 +619,7 @@ void Canvas::drawShadow(const CanvasPath* path,
624619}
625620
626621void Canvas::Invalidate () {
627- canvas_ = nullptr ;
628- display_list_recorder_ = nullptr ;
622+ display_list_builder_ = nullptr ;
629623 if (dart_wrapper ()) {
630624 ClearDartWrapper ();
631625 }
0 commit comments