@@ -56,16 +56,16 @@ void Canvas::Create(Dart_Handle wrapper,
56
56
fml::RefPtr<Canvas> canvas = fml::MakeRefCounted<Canvas>(
57
57
recorder->BeginRecording (SkRect::MakeLTRB (left, top, right, bottom)));
58
58
recorder->set_canvas (canvas);
59
- canvas->display_list_recorder_ = recorder->display_list_recorder ();
60
59
canvas->AssociateWithDartWrapper (wrapper);
61
60
}
62
61
63
- Canvas::Canvas (SkCanvas* canvas) : canvas_(canvas) {}
62
+ Canvas::Canvas (sk_sp<DisplayListBuilder> builder)
63
+ : display_list_builder_(std::move(builder)) {}
64
64
65
65
Canvas::~Canvas () {}
66
66
67
67
void Canvas::save () {
68
- if (display_list_recorder_ ) {
68
+ if (display_list_builder_ ) {
69
69
builder ()->save ();
70
70
}
71
71
}
@@ -75,7 +75,7 @@ void Canvas::saveLayerWithoutBounds(Dart_Handle paint_objects,
75
75
Paint paint (paint_objects, paint_data);
76
76
77
77
FML_DCHECK (paint.isNotNull ());
78
- if (display_list_recorder_ ) {
78
+ if (display_list_builder_ ) {
79
79
bool restore_with_paint =
80
80
paint.sync_to (builder (), kSaveLayerWithPaintFlags );
81
81
FML_DCHECK (restore_with_paint);
@@ -94,7 +94,7 @@ void Canvas::saveLayer(double left,
94
94
95
95
FML_DCHECK (paint.isNotNull ());
96
96
SkRect bounds = SkRect::MakeLTRB (left, top, right, bottom);
97
- if (display_list_recorder_ ) {
97
+ if (display_list_builder_ ) {
98
98
bool restore_with_paint =
99
99
paint.sync_to (builder (), kSaveLayerWithPaintFlags );
100
100
FML_DCHECK (restore_with_paint);
@@ -104,53 +104,53 @@ void Canvas::saveLayer(double left,
104
104
}
105
105
106
106
void Canvas::restore () {
107
- if (display_list_recorder_ ) {
107
+ if (display_list_builder_ ) {
108
108
builder ()->restore ();
109
109
}
110
110
}
111
111
112
112
int Canvas::getSaveCount () {
113
- if (display_list_recorder_ ) {
113
+ if (display_list_builder_ ) {
114
114
return builder ()->getSaveCount ();
115
115
} else {
116
116
return 0 ;
117
117
}
118
118
}
119
119
120
120
void Canvas::restoreToCount (int count) {
121
- if (display_list_recorder_ && count < getSaveCount ()) {
121
+ if (display_list_builder_ && count < getSaveCount ()) {
122
122
builder ()->restoreToCount (count);
123
123
}
124
124
}
125
125
126
126
void Canvas::translate (double dx, double dy) {
127
- if (display_list_recorder_ ) {
127
+ if (display_list_builder_ ) {
128
128
builder ()->translate (dx, dy);
129
129
}
130
130
}
131
131
132
132
void Canvas::scale (double sx, double sy) {
133
- if (display_list_recorder_ ) {
133
+ if (display_list_builder_ ) {
134
134
builder ()->scale (sx, sy);
135
135
}
136
136
}
137
137
138
138
void Canvas::rotate (double radians) {
139
- if (display_list_recorder_ ) {
139
+ if (display_list_builder_ ) {
140
140
builder ()->rotate (radians * 180.0 / M_PI);
141
141
}
142
142
}
143
143
144
144
void Canvas::skew (double sx, double sy) {
145
- if (display_list_recorder_ ) {
145
+ if (display_list_builder_ ) {
146
146
builder ()->skew (sx, sy);
147
147
}
148
148
}
149
149
150
150
void Canvas::transform (const tonic::Float64List& matrix4) {
151
151
// The Float array stored by Dart Matrix4 is in column-major order
152
152
// Both DisplayList and SkM44 constructor take row-major matrix order
153
- if (display_list_recorder_ ) {
153
+ if (display_list_builder_ ) {
154
154
// clang-format off
155
155
builder ()->transformFullPerspective (
156
156
matrix4[ 0 ], matrix4[ 4 ], matrix4[ 8 ], matrix4[12 ],
@@ -162,10 +162,7 @@ void Canvas::transform(const tonic::Float64List& matrix4) {
162
162
}
163
163
164
164
void 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 ();
169
166
SkScalar m44_values[16 ];
170
167
// The Float array stored by Dart Matrix4 is in column-major order
171
168
sk_m44.getColMajor (m44_values);
@@ -181,14 +178,14 @@ void Canvas::clipRect(double left,
181
178
double bottom,
182
179
SkClipOp clipOp,
183
180
bool doAntiAlias) {
184
- if (display_list_recorder_ ) {
181
+ if (display_list_builder_ ) {
185
182
builder ()->clipRect (SkRect::MakeLTRB (left, top, right, bottom), clipOp,
186
183
doAntiAlias);
187
184
}
188
185
}
189
186
190
187
void Canvas::clipRRect (const RRect& rrect, bool doAntiAlias) {
191
- if (display_list_recorder_ ) {
188
+ if (display_list_builder_ ) {
192
189
builder ()->clipRRect (rrect.sk_rrect , SkClipOp::kIntersect , doAntiAlias);
193
190
}
194
191
}
@@ -199,13 +196,13 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
199
196
ToDart (" Canvas.clipPath called with non-genuine Path." ));
200
197
return ;
201
198
}
202
- if (display_list_recorder_ ) {
199
+ if (display_list_builder_ ) {
203
200
builder ()->clipPath (path->path (), SkClipOp::kIntersect , doAntiAlias);
204
201
}
205
202
}
206
203
207
204
void Canvas::getDestinationClipBounds (Dart_Handle rect_handle) {
208
- if (display_list_recorder_ ) {
205
+ if (display_list_builder_ ) {
209
206
auto rect = tonic::Float64List (rect_handle);
210
207
SkRect bounds = builder ()->getDestinationClipBounds ();
211
208
rect[0 ] = bounds.fLeft ;
@@ -216,9 +213,9 @@ void Canvas::getDestinationClipBounds(Dart_Handle rect_handle) {
216
213
}
217
214
218
215
void Canvas::getLocalClipBounds (Dart_Handle rect_handle) {
219
- if (display_list_recorder_ ) {
216
+ if (display_list_builder_ ) {
220
217
auto rect = tonic::Float64List (rect_handle);
221
- SkRect bounds = display_list_recorder_-> builder () ->getLocalClipBounds ();
218
+ SkRect bounds = display_list_builder_ ->getLocalClipBounds ();
222
219
rect[0 ] = bounds.fLeft ;
223
220
rect[1 ] = bounds.fTop ;
224
221
rect[2 ] = bounds.fRight ;
@@ -227,7 +224,7 @@ void Canvas::getLocalClipBounds(Dart_Handle rect_handle) {
227
224
}
228
225
229
226
void Canvas::drawColor (SkColor color, DlBlendMode blend_mode) {
230
- if (display_list_recorder_ ) {
227
+ if (display_list_builder_ ) {
231
228
builder ()->drawColor (color, blend_mode);
232
229
}
233
230
}
@@ -241,7 +238,7 @@ void Canvas::drawLine(double x1,
241
238
Paint paint (paint_objects, paint_data);
242
239
243
240
FML_DCHECK (paint.isNotNull ());
244
- if (display_list_recorder_ ) {
241
+ if (display_list_builder_ ) {
245
242
paint.sync_to (builder (), kDrawLineFlags );
246
243
builder ()->drawLine (SkPoint::Make (x1, y1 ), SkPoint::Make (x2, y2));
247
244
}
@@ -251,7 +248,7 @@ void Canvas::drawPaint(Dart_Handle paint_objects, Dart_Handle paint_data) {
251
248
Paint paint (paint_objects, paint_data);
252
249
253
250
FML_DCHECK (paint.isNotNull ());
254
- if (display_list_recorder_ ) {
251
+ if (display_list_builder_ ) {
255
252
paint.sync_to (builder (), kDrawPaintFlags );
256
253
std::shared_ptr<const DlImageFilter> filter = builder ()->getImageFilter ();
257
254
if (filter && !filter->asColorFilter ()) {
@@ -272,7 +269,7 @@ void Canvas::drawRect(double left,
272
269
Paint paint (paint_objects, paint_data);
273
270
274
271
FML_DCHECK (paint.isNotNull ());
275
- if (display_list_recorder_ ) {
272
+ if (display_list_builder_ ) {
276
273
paint.sync_to (builder (), kDrawRectFlags );
277
274
builder ()->drawRect (SkRect::MakeLTRB (left, top, right, bottom));
278
275
}
@@ -284,7 +281,7 @@ void Canvas::drawRRect(const RRect& rrect,
284
281
Paint paint (paint_objects, paint_data);
285
282
286
283
FML_DCHECK (paint.isNotNull ());
287
- if (display_list_recorder_ ) {
284
+ if (display_list_builder_ ) {
288
285
paint.sync_to (builder (), kDrawRRectFlags );
289
286
builder ()->drawRRect (rrect.sk_rrect );
290
287
}
@@ -297,7 +294,7 @@ void Canvas::drawDRRect(const RRect& outer,
297
294
Paint paint (paint_objects, paint_data);
298
295
299
296
FML_DCHECK (paint.isNotNull ());
300
- if (display_list_recorder_ ) {
297
+ if (display_list_builder_ ) {
301
298
paint.sync_to (builder (), kDrawDRRectFlags );
302
299
builder ()->drawDRRect (outer.sk_rrect , inner.sk_rrect );
303
300
}
@@ -312,7 +309,7 @@ void Canvas::drawOval(double left,
312
309
Paint paint (paint_objects, paint_data);
313
310
314
311
FML_DCHECK (paint.isNotNull ());
315
- if (display_list_recorder_ ) {
312
+ if (display_list_builder_ ) {
316
313
paint.sync_to (builder (), kDrawOvalFlags );
317
314
builder ()->drawOval (SkRect::MakeLTRB (left, top, right, bottom));
318
315
}
@@ -326,7 +323,7 @@ void Canvas::drawCircle(double x,
326
323
Paint paint (paint_objects, paint_data);
327
324
328
325
FML_DCHECK (paint.isNotNull ());
329
- if (display_list_recorder_ ) {
326
+ if (display_list_builder_ ) {
330
327
paint.sync_to (builder (), kDrawCircleFlags );
331
328
builder ()->drawCircle (SkPoint::Make (x, y), radius);
332
329
}
@@ -344,7 +341,7 @@ void Canvas::drawArc(double left,
344
341
Paint paint (paint_objects, paint_data);
345
342
346
343
FML_DCHECK (paint.isNotNull ());
347
- if (display_list_recorder_ ) {
344
+ if (display_list_builder_ ) {
348
345
paint.sync_to (builder (),
349
346
useCenter //
350
347
? kDrawArcWithCenterFlags
@@ -366,7 +363,7 @@ void Canvas::drawPath(const CanvasPath* path,
366
363
ToDart (" Canvas.drawPath called with non-genuine Path." ));
367
364
return ;
368
365
}
369
- if (display_list_recorder_ ) {
366
+ if (display_list_builder_ ) {
370
367
paint.sync_to (builder (), kDrawPathFlags );
371
368
builder ()->drawPath (path->path ());
372
369
}
@@ -395,7 +392,7 @@ Dart_Handle Canvas::drawImage(const CanvasImage* image,
395
392
}
396
393
397
394
auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
398
- if (display_list_recorder_ ) {
395
+ if (display_list_builder_ ) {
399
396
bool with_attributes = paint.sync_to (builder (), kDrawImageWithPaintFlags );
400
397
builder ()->drawImage (dl_image, SkPoint::Make (x, y), sampling,
401
398
with_attributes);
@@ -434,7 +431,7 @@ Dart_Handle Canvas::drawImageRect(const CanvasImage* image,
434
431
SkRect src = SkRect::MakeLTRB (src_left, src_top, src_right, src_bottom);
435
432
SkRect dst = SkRect::MakeLTRB (dst_left, dst_top, dst_right, dst_bottom);
436
433
auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
437
- if (display_list_recorder_ ) {
434
+ if (display_list_builder_ ) {
438
435
bool with_attributes =
439
436
paint.sync_to (builder (), kDrawImageRectWithPaintFlags );
440
437
builder ()->drawImageRect (dl_image, src, dst, sampling, with_attributes,
@@ -476,7 +473,7 @@ Dart_Handle Canvas::drawImageNine(const CanvasImage* image,
476
473
center.round (&icenter);
477
474
SkRect dst = SkRect::MakeLTRB (dst_left, dst_top, dst_right, dst_bottom);
478
475
auto filter = ImageFilter::FilterModeFromIndex (bitmapSamplingIndex);
479
- if (display_list_recorder_ ) {
476
+ if (display_list_builder_ ) {
480
477
bool with_attributes =
481
478
paint.sync_to (builder (), kDrawImageNineWithPaintFlags );
482
479
builder ()->drawImageNine (dl_image, icenter, dst, filter, with_attributes);
@@ -491,10 +488,8 @@ void Canvas::drawPicture(Picture* picture) {
491
488
return ;
492
489
}
493
490
if (picture->display_list ()) {
494
- if (display_list_recorder_ ) {
491
+ if (display_list_builder_ ) {
495
492
builder ()->drawDisplayList (picture->display_list ());
496
- } else if (canvas_) {
497
- picture->display_list ()->RenderTo (canvas_);
498
493
}
499
494
} else {
500
495
FML_DCHECK (false );
@@ -511,7 +506,7 @@ void Canvas::drawPoints(Dart_Handle paint_objects,
511
506
" SkPoint doesn't use floats." );
512
507
513
508
FML_DCHECK (paint.isNotNull ());
514
- if (display_list_recorder_ ) {
509
+ if (display_list_builder_ ) {
515
510
switch (point_mode) {
516
511
case SkCanvas::kPoints_PointMode :
517
512
paint.sync_to (builder (), kDrawPointsAsPointsFlags );
@@ -541,7 +536,7 @@ void Canvas::drawVertices(const Vertices* vertices,
541
536
return ;
542
537
}
543
538
FML_DCHECK (paint.isNotNull ());
544
- if (display_list_recorder_ ) {
539
+ if (display_list_builder_ ) {
545
540
paint.sync_to (builder (), kDrawVerticesFlags );
546
541
builder ()->drawVertices (vertices->vertices (), blend_mode);
547
542
}
@@ -578,7 +573,7 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects,
578
573
auto sampling = ImageFilter::SamplingFromIndex (filterQualityIndex);
579
574
580
575
FML_DCHECK (paint.isNotNull ());
581
- if (display_list_recorder_ ) {
576
+ if (display_list_builder_ ) {
582
577
tonic::Float32List transforms (transforms_handle);
583
578
tonic::Float32List rects (rects_handle);
584
579
tonic::Int32List colors (colors_handle);
@@ -610,7 +605,7 @@ void Canvas::drawShadow(const CanvasPath* path,
610
605
->get_window (0 )
611
606
->viewport_metrics ()
612
607
.device_pixel_ratio ;
613
- if (display_list_recorder_ ) {
608
+ if (display_list_builder_ ) {
614
609
// The DrawShadow mechanism results in non-public operations to be
615
610
// performed on the canvas involving an SkDrawShadowRec. Since we
616
611
// cannot include the header that defines that structure, we cannot
@@ -624,8 +619,7 @@ void Canvas::drawShadow(const CanvasPath* path,
624
619
}
625
620
626
621
void Canvas::Invalidate () {
627
- canvas_ = nullptr ;
628
- display_list_recorder_ = nullptr ;
622
+ display_list_builder_ = nullptr ;
629
623
if (dart_wrapper ()) {
630
624
ClearDartWrapper ();
631
625
}
0 commit comments