Commit 80ceb88
authored
Canvas Extension functions not to allocate intermediate objects (#1137)
Added some functions to Skia canvas to be able to avoid creating
intermediate objects (SkRect, SkRRect, etc) on some hot paths.
See [this
conversation](JetBrains/compose-multiplatform-core#2543 (comment))
for the context of the PR.
This is the first step to allow for Compose Ui SkiaBackedCanvas to avoid
unnecessary intermediate allocations:
1.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L189
2.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L141
3.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L128
4.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L189
5.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L211
among others.
**Next steps**
-> open pr in Compose Ui to use these more optimized functions
-> More optimizations on the Skiko side, Matrixes is a good example, CMP
and Skiko are processing Matrixes 2 times, toSkiaMatrix, which basically
is the same as a wrapper around FloatArray and then in the toInterop
method which copies the array (unavoidable). A good optimization would
be to just pass the Compose Matrix underlying `values` property which is
a FloatArray that toInterop accepts and so a lot of intermediate objects
and transformations could be avoided altogether1 parent 35e297b commit 80ceb88
1 file changed
+81
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
291 | 302 | | |
292 | 303 | | |
293 | 304 | | |
| |||
299 | 310 | | |
300 | 311 | | |
301 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
302 | 324 | | |
303 | 325 | | |
304 | 326 | | |
| |||
321 | 343 | | |
322 | 344 | | |
323 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
324 | 359 | | |
325 | 360 | | |
326 | 361 | | |
| |||
456 | 491 | | |
457 | 492 | | |
458 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
459 | 534 | | |
460 | 535 | | |
461 | 536 | | |
| |||
1015 | 1090 | | |
1016 | 1091 | | |
1017 | 1092 | | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1018 | 1099 | | |
1019 | 1100 | | |
1020 | 1101 | | |
| |||
0 commit comments