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