@@ -29,29 +29,27 @@ class SkwasmCanvas implements SceneCanvas {
2929
3030 @override
3131 void saveLayer (ui.Rect ? bounds, ui.Paint paint) {
32- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
32+ paint as SkwasmPaint ;
3333 if (bounds != null ) {
3434 withStackScope ((StackScope s) {
35- canvasSaveLayer (_handle, s.convertRectToNative (bounds), paintHandle , nullptr);
35+ canvasSaveLayer (_handle, s.convertRectToNative (bounds), paint.handle , nullptr);
3636 });
3737 } else {
38- canvasSaveLayer (_handle, nullptr, paintHandle , nullptr);
38+ canvasSaveLayer (_handle, nullptr, paint.handle , nullptr);
3939 }
40- paintDispose (paintHandle);
4140 }
4241
4342 @override
4443 void saveLayerWithFilter (ui.Rect ? bounds, ui.Paint paint, ui.ImageFilter imageFilter) {
4544 final SkwasmImageFilter nativeFilter = SkwasmImageFilter .fromUiFilter (imageFilter);
46- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
45+ paint as SkwasmPaint ;
4746 if (bounds != null ) {
4847 withStackScope ((StackScope s) {
49- canvasSaveLayer (_handle, s.convertRectToNative (bounds), paintHandle , nativeFilter.handle);
48+ canvasSaveLayer (_handle, s.convertRectToNative (bounds), paint.handle , nativeFilter.handle);
5049 });
5150 } else {
52- canvasSaveLayer (_handle, nullptr, paintHandle , nativeFilter.handle);
51+ canvasSaveLayer (_handle, nullptr, paint.handle , nativeFilter.handle);
5352 }
54- paintDispose (paintHandle);
5553 }
5654
5755 @override
@@ -113,158 +111,136 @@ class SkwasmCanvas implements SceneCanvas {
113111
114112 @override
115113 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);
119116 }
120117
121118 @override
122119 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);
126122 }
127123
128124 @override
129125 void drawRect (ui.Rect rect, ui.Paint paint) {
130- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
126+ paint as SkwasmPaint ;
131127 withStackScope ((StackScope s) {
132128 canvasDrawRect (
133129 _handle,
134130 s.convertRectToNative (rect),
135- paintHandle
131+ paint.handle
136132 );
137133 });
138- paintDispose (paintHandle);
139134 }
140135
141136 @override
142137 void drawRRect (ui.RRect rrect, ui.Paint paint) {
143- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
138+ paint as SkwasmPaint ;
144139 withStackScope ((StackScope s) {
145140 canvasDrawRRect (
146141 _handle,
147142 s.convertRRectToNative (rrect),
148- paintHandle
143+ paint.handle
149144 );
150145 });
151- paintDispose (paintHandle);
152146 }
153147
154148 @override
155149 void drawDRRect (ui.RRect outer, ui.RRect inner, ui.Paint paint) {
156- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
150+ paint as SkwasmPaint ;
157151 withStackScope ((StackScope s) {
158152 canvasDrawDRRect (
159153 _handle,
160154 s.convertRRectToNative (outer),
161155 s.convertRRectToNative (inner),
162- paintHandle
156+ paint.handle
163157 );
164158 });
165- paintDispose (paintHandle);
166159 }
167160
168161 @override
169162 void drawOval (ui.Rect rect, ui.Paint paint) {
170- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
163+ paint as SkwasmPaint ;
171164 withStackScope ((StackScope s) {
172- canvasDrawOval (_handle, s.convertRectToNative (rect), paintHandle );
165+ canvasDrawOval (_handle, s.convertRectToNative (rect), paint.handle );
173166 });
174- paintDispose (paintHandle);
175167 }
176168
177169 @override
178170 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);
182173 }
183174
184175 @override
185176 void drawArc (ui.Rect rect, double startAngle, double sweepAngle,
186177 bool useCenter, ui.Paint paint) {
187- final paintHandle = ( paint as SkwasmPaint ). toRawPaint () ;
178+ paint as SkwasmPaint ;
188179 withStackScope ((StackScope s) {
189180 canvasDrawArc (
190181 _handle,
191182 s.convertRectToNative (rect),
192183 ui.toDegrees (startAngle),
193184 ui.toDegrees (sweepAngle),
194185 useCenter,
195- paintHandle,
186+ paint.handle
196187 );
197188 });
198- paintDispose (paintHandle);
199189 }
200190
201191 @override
202192 void drawPath (ui.Path path, ui.Paint paint) {
193+ paint as SkwasmPaint ;
203194 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);
207196 }
208197
209198 @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) =>
212200 canvasDrawImage (
213201 _handle,
214202 (image as SkwasmImage ).handle,
215203 offset.dx,
216204 offset.dy,
217- paintHandle ,
205+ (paint as SkwasmPaint ).handle ,
218206 paint.filterQuality.index,
219207 );
220- paintDispose (paintHandle);
221- }
222208
223209 @override
224210 void drawImageRect (
225211 ui.Image image,
226212 ui.Rect src,
227213 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+ });
245226
246227 @override
247228 void drawImageNine (
248229 ui.Image image,
249230 ui.Rect center,
250231 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+ });
268244
269245 @override
270246 void drawPicture (ui.Picture picture) {
@@ -288,15 +264,13 @@ class SkwasmCanvas implements SceneCanvas {
288264 ui.Paint paint
289265 ) => withStackScope ((StackScope scope) {
290266 final RawPointArray rawPoints = scope.convertPointArrayToNative (points);
291- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
292267 canvasDrawPoints (
293268 _handle,
294269 pointMode.index,
295270 rawPoints,
296271 points.length,
297- paintHandle ,
272+ (paint as SkwasmPaint ).handle ,
298273 );
299- paintDispose (paintHandle);
300274 });
301275
302276 @override
@@ -306,32 +280,26 @@ class SkwasmCanvas implements SceneCanvas {
306280 ui.Paint paint
307281 ) => withStackScope ((StackScope scope) {
308282 final RawPointArray rawPoints = scope.convertDoublesToNative (points);
309- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
310283 canvasDrawPoints (
311284 _handle,
312285 pointMode.index,
313286 rawPoints,
314287 points.length ~ / 2 ,
315- paintHandle ,
288+ (paint as SkwasmPaint ).handle ,
316289 );
317- paintDispose (paintHandle);
318290 });
319291
320292 @override
321293 void drawVertices (
322294 ui.Vertices vertices,
323295 ui.BlendMode blendMode,
324296 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+ );
335303
336304 @override
337305 void drawAtlas (
@@ -351,7 +319,6 @@ class SkwasmCanvas implements SceneCanvas {
351319 final RawRect rawCullRect = cullRect != null
352320 ? scope.convertRectToNative (cullRect)
353321 : nullptr;
354- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
355322 canvasDrawAtlas (
356323 _handle,
357324 (atlas as SkwasmImage ).handle,
@@ -361,9 +328,8 @@ class SkwasmCanvas implements SceneCanvas {
361328 transforms.length,
362329 (blendMode ?? ui.BlendMode .src).index,
363330 rawCullRect,
364- paintHandle ,
331+ (paint as SkwasmPaint ).handle ,
365332 );
366- paintDispose (paintHandle);
367333 });
368334
369335 @override
@@ -384,7 +350,6 @@ class SkwasmCanvas implements SceneCanvas {
384350 final RawRect rawCullRect = cullRect != null
385351 ? scope.convertRectToNative (cullRect)
386352 : nullptr;
387- final paintHandle = (paint as SkwasmPaint ).toRawPaint ();
388353 canvasDrawAtlas (
389354 _handle,
390355 (atlas as SkwasmImage ).handle,
@@ -394,9 +359,8 @@ class SkwasmCanvas implements SceneCanvas {
394359 rstTransforms.length ~ / 4 ,
395360 (blendMode ?? ui.BlendMode .src).index,
396361 rawCullRect,
397- paintHandle ,
362+ (paint as SkwasmPaint ).handle ,
398363 );
399- paintDispose (paintHandle);
400364 });
401365
402366 @override
0 commit comments