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