From 9b09e68e79467da70b1c72c1673c815c957f7d87 Mon Sep 17 00:00:00 2001 From: Nikita Lipsky Date: Thu, 18 May 2023 13:04:37 +0300 Subject: [PATCH] Add macOS native target to visual-effects-ny benchmark (#3180) * Add macOS native target to visual-effects-ny benchmark * handle width/height with expect/actuals --- .../src/androidMain/kotlin/MainActivity.kt | 1 - .../visual-effects-ny/shared/build.gradle.kts | 21 +++++++++++++++++++ .../src/androidMain/kotlin/main.android.kt | 5 +++++ .../shared/src/commonMain/kotlin/HappyNY.kt | 7 +++++-- .../src/desktopMain/kotlin/main.desktop.kt | 3 +++ .../shared/src/iosMain/kotlin/actuals.ios.kt | 4 ++++ .../src/macosMain/kotlin/actuals.macos.kt | 4 ++++ .../shared/src/macosMain/kotlin/main.macos.kt | 19 +++++++++++++++++ .../src/macosMain/kotlin/platform/NanoTime.kt | 3 +++ 9 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 benchmarks/ios/visual-effects-ny/shared/src/iosMain/kotlin/actuals.ios.kt create mode 100644 benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/actuals.macos.kt create mode 100644 benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/main.macos.kt create mode 100644 benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/platform/NanoTime.kt diff --git a/benchmarks/ios/visual-effects-ny/androidApp/src/androidMain/kotlin/MainActivity.kt b/benchmarks/ios/visual-effects-ny/androidApp/src/androidMain/kotlin/MainActivity.kt index 045ce66fb5..783122db5a 100644 --- a/benchmarks/ios/visual-effects-ny/androidApp/src/androidMain/kotlin/MainActivity.kt +++ b/benchmarks/ios/visual-effects-ny/androidApp/src/androidMain/kotlin/MainActivity.kt @@ -1,6 +1,5 @@ package org.jetbrains.compose.demo.visuals -import MainView import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity diff --git a/benchmarks/ios/visual-effects-ny/shared/build.gradle.kts b/benchmarks/ios/visual-effects-ny/shared/build.gradle.kts index de48622f63..48f2c79381 100644 --- a/benchmarks/ios/visual-effects-ny/shared/build.gradle.kts +++ b/benchmarks/ios/visual-effects-ny/shared/build.gradle.kts @@ -15,6 +15,21 @@ kotlin { ios() iosSimulatorArm64() + macosX64 { + binaries { + executable { + entryPoint = "main" + } + } + } + macosArm64 { + binaries { + executable { + entryPoint = "main" + } + } + } + cocoapods { summary = "Shared code for the sample" homepage = "https://github.com/JetBrains/compose-jb" @@ -54,6 +69,12 @@ kotlin { implementation(compose.desktop.common) } } + val macosMain by creating { + dependsOn(commonMain) + } + val macosArm64Main by getting { + dependsOn(macosMain) + } } } diff --git a/benchmarks/ios/visual-effects-ny/shared/src/androidMain/kotlin/main.android.kt b/benchmarks/ios/visual-effects-ny/shared/src/androidMain/kotlin/main.android.kt index ea20b28f05..41a4036628 100644 --- a/benchmarks/ios/visual-effects-ny/shared/src/androidMain/kotlin/main.android.kt +++ b/benchmarks/ios/visual-effects-ny/shared/src/androidMain/kotlin/main.android.kt @@ -1,5 +1,10 @@ +package org.jetbrains.compose.demo.visuals + import androidx.compose.runtime.Composable import org.jetbrains.compose.demo.visuals.NYContent +actual fun width(): Int = 400 +actual fun height(): Int = 800 + @Composable fun MainView() = NYContent() \ No newline at end of file diff --git a/benchmarks/ios/visual-effects-ny/shared/src/commonMain/kotlin/HappyNY.kt b/benchmarks/ios/visual-effects-ny/shared/src/commonMain/kotlin/HappyNY.kt index 72f8c41687..8871c6c106 100644 --- a/benchmarks/ios/visual-effects-ny/shared/src/commonMain/kotlin/HappyNY.kt +++ b/benchmarks/ios/visual-effects-ny/shared/src/commonMain/kotlin/HappyNY.kt @@ -17,8 +17,11 @@ import org.jetbrains.compose.demo.visuals.platform.nanoTime import kotlin.math.* import kotlin.random.Random -const val width = 400 -const val height = 800 +expect fun width(): Int +expect fun height(): Int + +val width = width() +val height = height() const val snowCount = 80 const val starCount = 60 const val rocketPartsCount = 30 diff --git a/benchmarks/ios/visual-effects-ny/shared/src/desktopMain/kotlin/main.desktop.kt b/benchmarks/ios/visual-effects-ny/shared/src/desktopMain/kotlin/main.desktop.kt index cc8baa8da6..c7e7a05a1f 100644 --- a/benchmarks/ios/visual-effects-ny/shared/src/desktopMain/kotlin/main.desktop.kt +++ b/benchmarks/ios/visual-effects-ny/shared/src/desktopMain/kotlin/main.desktop.kt @@ -5,6 +5,9 @@ import androidx.compose.runtime.remember import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* +actual fun width(): Int = 640 +actual fun height(): Int = 480 + @Composable fun NYWindow(onCloseRequest: () -> Unit) { val windowState = remember { WindowState(width = width.dp, height = height.dp) } diff --git a/benchmarks/ios/visual-effects-ny/shared/src/iosMain/kotlin/actuals.ios.kt b/benchmarks/ios/visual-effects-ny/shared/src/iosMain/kotlin/actuals.ios.kt new file mode 100644 index 0000000000..d7fb7142b6 --- /dev/null +++ b/benchmarks/ios/visual-effects-ny/shared/src/iosMain/kotlin/actuals.ios.kt @@ -0,0 +1,4 @@ +package org.jetbrains.compose.demo.visuals + +actual fun width(): Int = 400 +actual fun height(): Int = 800 \ No newline at end of file diff --git a/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/actuals.macos.kt b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/actuals.macos.kt new file mode 100644 index 0000000000..415f78bcf9 --- /dev/null +++ b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/actuals.macos.kt @@ -0,0 +1,4 @@ +package org.jetbrains.compose.demo.visuals + +actual fun width(): Int = 640 +actual fun height(): Int = 480 \ No newline at end of file diff --git a/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/main.macos.kt b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/main.macos.kt new file mode 100644 index 0000000000..600bf5d8a3 --- /dev/null +++ b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/main.macos.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +import androidx.compose.ui.window.Window +import androidx.compose.runtime.remember +import androidx.compose.ui.unit.dp +import org.jetbrains.compose.demo.visuals.NYContent +import platform.AppKit.NSApp +import platform.AppKit.NSApplication + +fun main() { + NSApplication.sharedApplication() + Window("Visual Effects") { + NYContent() + } + NSApp?.run() +} diff --git a/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/platform/NanoTime.kt b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/platform/NanoTime.kt new file mode 100644 index 0000000000..334c22b781 --- /dev/null +++ b/benchmarks/ios/visual-effects-ny/shared/src/macosMain/kotlin/platform/NanoTime.kt @@ -0,0 +1,3 @@ +package org.jetbrains.compose.demo.visuals.platform + +actual fun nanoTime(): Long = kotlin.system.getTimeNanos() \ No newline at end of file