Skip to content

Commit 014c569

Browse files
committed
More micro optimizations
1 parent 6cf65bc commit 014c569

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/InputDispatcher.skiko.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.ui.input.pointer.PointerType
2828
import androidx.compose.ui.node.RootForTest
2929
import androidx.compose.ui.platform.PlatformRootForTest
3030
import androidx.compose.ui.scene.ComposeScenePointer
31+
import androidx.compose.ui.util.fastForEach
3132

3233
@OptIn(InternalComposeUiApi::class)
3334
internal actual fun createInputDispatcher(
@@ -300,7 +301,7 @@ internal class SkikoInputDispatcher(
300301
override fun flush() {
301302
val copy = batchedEvents.toList()
302303
batchedEvents.clear()
303-
for (event in copy) {
304+
copy.fastForEach { event ->
304305
advanceClockTime(event.eventTime - currentClockTime)
305306
currentClockTime = event.eventTime
306307
event.action()

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/WindowComposeSceneLayer.desktop.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ import androidx.compose.ui.platform.PlatformWindowContext
2929
import androidx.compose.ui.scene.skia.SkiaLayerComponent
3030
import androidx.compose.ui.skiko.OverlayRenderDecorator
3131
import androidx.compose.ui.unit.Density
32+
import androidx.compose.ui.unit.IntRect
3233
import androidx.compose.ui.unit.LayoutDirection
3334
import androidx.compose.ui.unit.roundToIntRect
3435
import androidx.compose.ui.unit.toOffset
36+
import androidx.compose.ui.util.fastRoundToInt
3537
import androidx.compose.ui.window.density
3638
import androidx.compose.ui.window.getDialogScrimBlendMode
3739
import androidx.compose.ui.window.layoutDirectionFor
@@ -113,8 +115,12 @@ internal class WindowComposeSceneLayer(
113115
override var scrimColor: Color? = null
114116

115117
init {
116-
val boundsInPx = windowContainer.sizeInPx.toRect()
117-
drawBounds = boundsInPx.roundToIntRect()
118+
drawBounds = IntRect(
119+
0,
120+
0,
121+
windowContainer.sizeInPx.width.fastRoundToInt(),
122+
windowContainer.sizeInPx.height.fastRoundToInt()
123+
)
118124
mediator = ComposeSceneMediator(
119125
container = container,
120126
isWindowLevel = true,

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/node/RootNodeOwner.skiko.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ internal class RootNodeOwner(
358358
}
359359

360360
private fun isInBounds(localPosition: Offset): Boolean =
361-
size?.toIntRect()?.toRect()?.contains(localPosition) ?: true
361+
size?.toRect()?.contains(localPosition) ?: true
362362

363363
private fun calculateBoundsInWindow(): Rect? {
364-
val rect = size?.toIntRect()?.toRect() ?: return null
364+
val rect = size?.toRect() ?: return null
365365
val p0 = platformContext.convertLocalToWindowPosition(Offset(rect.left, rect.top))
366366
val p1 = platformContext.convertLocalToWindowPosition(Offset(rect.left, rect.bottom))
367367
val p3 = platformContext.convertLocalToWindowPosition(Offset(rect.right, rect.top))
@@ -732,7 +732,7 @@ internal class RootNodeOwner(
732732
override val semanticsOwner get() = owner.semanticsOwner
733733
override val visibleBounds: Rect
734734
get() {
735-
val windowRect = platformContext.windowInfo.containerSize.toIntRect().toRect()
735+
val windowRect = platformContext.windowInfo.containerSize.toRect()
736736
val ownerRect = calculateBoundsInWindow()
737737
return ownerRect?.intersect(windowRect) ?: windowRect
738738
}

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/LegacyRenderNodeLayer.skiko.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import androidx.compose.ui.unit.Density
4949
import androidx.compose.ui.unit.IntOffset
5050
import androidx.compose.ui.unit.IntSize
5151
import androidx.compose.ui.unit.dp
52+
import androidx.compose.ui.unit.toRect
5253
import androidx.compose.ui.unit.toSize
5354
import kotlin.math.abs
5455
import kotlin.math.max
@@ -245,7 +246,7 @@ internal class LegacyRenderNodeLayer(
245246

246247
if (picture == null) {
247248
val measureDrawBounds = !clip || shadowElevation > 0
248-
val bounds = size.toSize().toRect()
249+
val bounds = size.toRect()
249250
val pictureCanvas = pictureRecorder.beginRecording(
250251
left = if (measureDrawBounds) PICTURE_MIN_VALUE else bounds.left,
251252
top = if (measureDrawBounds) PICTURE_MIN_VALUE else bounds.top,

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/unit/Density.skiko.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,11 @@ internal inline fun Size.toDpSize(density: Density): DpSize = with(density) {
7979
internal inline fun DpSize.toSize(density: Density): Size = with(density) {
8080
toSize()
8181
}
82+
83+
/**
84+
* Converts a [IntSize] to a [Rect].
85+
*/
86+
@Stable
87+
internal inline fun IntSize.toRect(): Rect =
88+
Rect(0f, 0f, width.toFloat(), height.toFloat())
89+

0 commit comments

Comments
 (0)