@@ -29,29 +29,27 @@ class SkwasmCanvas implements SceneCanvas {
29
29
30
30
@override
31
31
void saveLayer (ui.Rect ? bounds, ui.Paint paint) {
32
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
32
+ paint as SkwasmPaint ;
33
33
if (bounds != null ) {
34
34
withStackScope ((StackScope s) {
35
- canvasSaveLayer (_handle, s.convertRectToNative (bounds), paintHandle , nullptr);
35
+ canvasSaveLayer (_handle, s.convertRectToNative (bounds), paint.handle , nullptr);
36
36
});
37
37
} else {
38
- canvasSaveLayer (_handle, nullptr, paintHandle , nullptr);
38
+ canvasSaveLayer (_handle, nullptr, paint.handle , nullptr);
39
39
}
40
- paintDispose (paintHandle);
41
40
}
42
41
43
42
@override
44
43
void saveLayerWithFilter (ui.Rect ? bounds, ui.Paint paint, ui.ImageFilter imageFilter) {
45
44
final SkwasmImageFilter nativeFilter = SkwasmImageFilter .fromUiFilter (imageFilter);
46
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
45
+ paint as SkwasmPaint ;
47
46
if (bounds != null ) {
48
47
withStackScope ((StackScope s) {
49
- canvasSaveLayer (_handle, s.convertRectToNative (bounds), paintHandle , nativeFilter.handle);
48
+ canvasSaveLayer (_handle, s.convertRectToNative (bounds), paint.handle , nativeFilter.handle);
50
49
});
51
50
} else {
52
- canvasSaveLayer (_handle, nullptr, paintHandle , nativeFilter.handle);
51
+ canvasSaveLayer (_handle, nullptr, paint.handle , nativeFilter.handle);
53
52
}
54
- paintDispose (paintHandle);
55
53
}
56
54
57
55
@override
@@ -113,158 +111,136 @@ class SkwasmCanvas implements SceneCanvas {
113
111
114
112
@override
115
113
void drawLine (ui.Offset p1, ui.Offset p2, ui.Paint paint) {
116
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
117
- canvasDrawLine (_handle, p1.dx, p1.dy, p2.dx, p2.dy, paintHandle);
118
- paintDispose (paintHandle);
114
+ paint as SkwasmPaint ;
115
+ canvasDrawLine (_handle, p1.dx, p1.dy, p2.dx, p2.dy, paint.handle);
119
116
}
120
117
121
118
@override
122
119
void drawPaint (ui.Paint paint) {
123
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
124
- canvasDrawPaint (_handle, paintHandle);
125
- paintDispose (paintHandle);
120
+ paint as SkwasmPaint ;
121
+ canvasDrawPaint (_handle, paint.handle);
126
122
}
127
123
128
124
@override
129
125
void drawRect (ui.Rect rect, ui.Paint paint) {
130
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
126
+ paint as SkwasmPaint ;
131
127
withStackScope ((StackScope s) {
132
128
canvasDrawRect (
133
129
_handle,
134
130
s.convertRectToNative (rect),
135
- paintHandle
131
+ paint.handle
136
132
);
137
133
});
138
- paintDispose (paintHandle);
139
134
}
140
135
141
136
@override
142
137
void drawRRect (ui.RRect rrect, ui.Paint paint) {
143
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
138
+ paint as SkwasmPaint ;
144
139
withStackScope ((StackScope s) {
145
140
canvasDrawRRect (
146
141
_handle,
147
142
s.convertRRectToNative (rrect),
148
- paintHandle
143
+ paint.handle
149
144
);
150
145
});
151
- paintDispose (paintHandle);
152
146
}
153
147
154
148
@override
155
149
void drawDRRect (ui.RRect outer, ui.RRect inner, ui.Paint paint) {
156
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
150
+ paint as SkwasmPaint ;
157
151
withStackScope ((StackScope s) {
158
152
canvasDrawDRRect (
159
153
_handle,
160
154
s.convertRRectToNative (outer),
161
155
s.convertRRectToNative (inner),
162
- paintHandle
156
+ paint.handle
163
157
);
164
158
});
165
- paintDispose (paintHandle);
166
159
}
167
160
168
161
@override
169
162
void drawOval (ui.Rect rect, ui.Paint paint) {
170
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
163
+ paint as SkwasmPaint ;
171
164
withStackScope ((StackScope s) {
172
- canvasDrawOval (_handle, s.convertRectToNative (rect), paintHandle );
165
+ canvasDrawOval (_handle, s.convertRectToNative (rect), paint.handle );
173
166
});
174
- paintDispose (paintHandle);
175
167
}
176
168
177
169
@override
178
170
void drawCircle (ui.Offset center, double radius, ui.Paint paint) {
179
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
180
- canvasDrawCircle (_handle, center.dx, center.dy, radius, paintHandle);
181
- paintDispose (paintHandle);
171
+ paint as SkwasmPaint ;
172
+ canvasDrawCircle (_handle, center.dx, center.dy, radius, paint.handle);
182
173
}
183
174
184
175
@override
185
176
void drawArc (ui.Rect rect, double startAngle, double sweepAngle,
186
177
bool useCenter, ui.Paint paint) {
187
- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
178
+ paint as SkwasmPaint ;
188
179
withStackScope ((StackScope s) {
189
180
canvasDrawArc (
190
181
_handle,
191
182
s.convertRectToNative (rect),
192
183
ui.toDegrees (startAngle),
193
184
ui.toDegrees (sweepAngle),
194
185
useCenter,
195
- paintHandle,
186
+ paint.handle
196
187
);
197
188
});
198
- paintDispose (paintHandle);
199
189
}
200
190
201
191
@override
202
192
void drawPath (ui.Path path, ui.Paint paint) {
193
+ paint as SkwasmPaint ;
203
194
path as SkwasmPath ;
204
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
205
- canvasDrawPath (_handle, path.handle, paintHandle);
206
- paintDispose (paintHandle);
195
+ canvasDrawPath (_handle, path.handle, paint.handle);
207
196
}
208
197
209
198
@override
210
- void drawImage (ui.Image image, ui.Offset offset, ui.Paint paint) {
211
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
199
+ void drawImage (ui.Image image, ui.Offset offset, ui.Paint paint) =>
212
200
canvasDrawImage (
213
201
_handle,
214
202
(image as SkwasmImage ).handle,
215
203
offset.dx,
216
204
offset.dy,
217
- paintHandle ,
205
+ (paint as SkwasmPaint ).handle ,
218
206
paint.filterQuality.index,
219
207
);
220
- paintDispose (paintHandle);
221
- }
222
208
223
209
@override
224
210
void drawImageRect (
225
211
ui.Image image,
226
212
ui.Rect src,
227
213
ui.Rect dst,
228
- ui.Paint paint,
229
- ) {
230
- withStackScope ((StackScope scope) {
231
- final Pointer <Float > sourceRect = scope.convertRectToNative (src);
232
- final Pointer <Float > destRect = scope.convertRectToNative (dst);
233
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
234
- canvasDrawImageRect (
235
- _handle,
236
- (image as SkwasmImage ).handle,
237
- sourceRect,
238
- destRect,
239
- paintHandle,
240
- paint.filterQuality.index,
241
- );
242
- paintDispose (paintHandle);
243
- });
244
- }
214
+ ui.Paint paint) => withStackScope ((StackScope scope) {
215
+ final Pointer <Float > sourceRect = scope.convertRectToNative (src);
216
+ final Pointer <Float > destRect = scope.convertRectToNative (dst);
217
+ canvasDrawImageRect (
218
+ _handle,
219
+ (image as SkwasmImage ).handle,
220
+ sourceRect,
221
+ destRect,
222
+ (paint as SkwasmPaint ).handle,
223
+ paint.filterQuality.index,
224
+ );
225
+ });
245
226
246
227
@override
247
228
void drawImageNine (
248
229
ui.Image image,
249
230
ui.Rect center,
250
231
ui.Rect dst,
251
- ui.Paint paint,
252
- ) {
253
- withStackScope ((StackScope scope) {
254
- final Pointer <Int32 > centerRect = scope.convertIRectToNative (center);
255
- final Pointer <Float > destRect = scope.convertRectToNative (dst);
256
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
257
- canvasDrawImageNine (
258
- _handle,
259
- (image as SkwasmImage ).handle,
260
- centerRect,
261
- destRect,
262
- paintHandle,
263
- paint.filterQuality.index,
264
- );
265
- paintDispose (paintHandle);
266
- });
267
- }
232
+ ui.Paint paint) => withStackScope ((StackScope scope) {
233
+ final Pointer <Int32 > centerRect = scope.convertIRectToNative (center);
234
+ final Pointer <Float > destRect = scope.convertRectToNative (dst);
235
+ canvasDrawImageNine (
236
+ _handle,
237
+ (image as SkwasmImage ).handle,
238
+ centerRect,
239
+ destRect,
240
+ (paint as SkwasmPaint ).handle,
241
+ paint.filterQuality.index,
242
+ );
243
+ });
268
244
269
245
@override
270
246
void drawPicture (ui.Picture picture) {
@@ -288,15 +264,13 @@ class SkwasmCanvas implements SceneCanvas {
288
264
ui.Paint paint
289
265
) => withStackScope ((StackScope scope) {
290
266
final RawPointArray rawPoints = scope.convertPointArrayToNative (points);
291
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
292
267
canvasDrawPoints (
293
268
_handle,
294
269
pointMode.index,
295
270
rawPoints,
296
271
points.length,
297
- paintHandle ,
272
+ (paint as SkwasmPaint ).handle ,
298
273
);
299
- paintDispose (paintHandle);
300
274
});
301
275
302
276
@override
@@ -306,32 +280,26 @@ class SkwasmCanvas implements SceneCanvas {
306
280
ui.Paint paint
307
281
) => withStackScope ((StackScope scope) {
308
282
final RawPointArray rawPoints = scope.convertDoublesToNative (points);
309
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
310
283
canvasDrawPoints (
311
284
_handle,
312
285
pointMode.index,
313
286
rawPoints,
314
287
points.length ~ / 2 ,
315
- paintHandle ,
288
+ (paint as SkwasmPaint ).handle ,
316
289
);
317
- paintDispose (paintHandle);
318
290
});
319
291
320
292
@override
321
293
void drawVertices (
322
294
ui.Vertices vertices,
323
295
ui.BlendMode blendMode,
324
296
ui.Paint paint,
325
- ) {
326
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
327
- canvasDrawVertices (
328
- _handle,
329
- (vertices as SkwasmVertices ).handle,
330
- blendMode.index,
331
- paintHandle,
332
- );
333
- paintDispose (paintHandle);
334
- }
297
+ ) => canvasDrawVertices (
298
+ _handle,
299
+ (vertices as SkwasmVertices ).handle,
300
+ blendMode.index,
301
+ (paint as SkwasmPaint ).handle,
302
+ );
335
303
336
304
@override
337
305
void drawAtlas (
@@ -351,7 +319,6 @@ class SkwasmCanvas implements SceneCanvas {
351
319
final RawRect rawCullRect = cullRect != null
352
320
? scope.convertRectToNative (cullRect)
353
321
: nullptr;
354
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
355
322
canvasDrawAtlas (
356
323
_handle,
357
324
(atlas as SkwasmImage ).handle,
@@ -361,9 +328,8 @@ class SkwasmCanvas implements SceneCanvas {
361
328
transforms.length,
362
329
(blendMode ?? ui.BlendMode .src).index,
363
330
rawCullRect,
364
- paintHandle ,
331
+ (paint as SkwasmPaint ).handle ,
365
332
);
366
- paintDispose (paintHandle);
367
333
});
368
334
369
335
@override
@@ -384,7 +350,6 @@ class SkwasmCanvas implements SceneCanvas {
384
350
final RawRect rawCullRect = cullRect != null
385
351
? scope.convertRectToNative (cullRect)
386
352
: nullptr;
387
- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
388
353
canvasDrawAtlas (
389
354
_handle,
390
355
(atlas as SkwasmImage ).handle,
@@ -394,9 +359,8 @@ class SkwasmCanvas implements SceneCanvas {
394
359
rstTransforms.length ~ / 4 ,
395
360
(blendMode ?? ui.BlendMode .src).index,
396
361
rawCullRect,
397
- paintHandle ,
362
+ (paint as SkwasmPaint ).handle ,
398
363
);
399
- paintDispose (paintHandle);
400
364
});
401
365
402
366
@override
0 commit comments