Skip to content

Commit

Permalink
Merge branch 'JetBrains:master' into fix/master/issue-4953/fix-jswasm…
Browse files Browse the repository at this point in the history
…-build-fail
  • Loading branch information
issamux authored Jun 14, 2024
2 parents 75455a6 + a1b88db commit 01b2dc7
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 603 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ abstract class Dependencies {
}

override fun saveImage(picture: PictureData.Camera, image: PlatformStorableImage) {
pictures.add(0, picture)
imageStorage.saveImage(picture, image)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package example.imageviewer

import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toAwtImage
import androidx.compose.ui.graphics.toComposeImageBitmap
Expand All @@ -13,37 +12,36 @@ private const val maxStorableImageSizePx = 2000
private const val storableThumbnailSizePx = 200

class DesktopImageStorage(
private val pictures: SnapshotStateList<PictureData>,
private val ioScope: CoroutineScope
) : ImageStorage {
private val largeImages = mutableMapOf<PictureData.Camera, ImageBitmap>()
private val thumbnails = mutableMapOf<PictureData.Camera, ImageBitmap>()
private val largeImages = mutableMapOf<String, ImageBitmap>()
private val thumbnails = mutableMapOf<String, ImageBitmap>()

override fun saveImage(picture: PictureData.Camera, image: PlatformStorableImage) {
if (image.imageBitmap.width == 0 || image.imageBitmap.height == 0) {
return
}
ioScope.launch {
largeImages[picture] = image.imageBitmap.fitInto(maxStorableImageSizePx)
thumbnails[picture] = image.imageBitmap.fitInto(storableThumbnailSizePx)
pictures.add(0, picture)
largeImages[picture.id] = image.imageBitmap.fitInto(maxStorableImageSizePx)
thumbnails[picture.id] = image.imageBitmap.fitInto(storableThumbnailSizePx)
}
}

override fun delete(picture: PictureData.Camera) {
// For now, on Desktop pictures saving in memory. We don't need additional delete logic.
largeImages.remove(picture.id)
thumbnails.remove(picture.id)
}

override fun rewrite(picture: PictureData.Camera) {
// For now, on Desktop pictures saving in memory. We don't need additional rewrite logic.
}

override suspend fun getThumbnail(picture: PictureData.Camera): ImageBitmap {
return thumbnails[picture]!!
return thumbnails[picture.id]!!
}

override suspend fun getImage(picture: PictureData.Camera): ImageBitmap {
return largeImages[picture]!!
return largeImages[picture.id]!!
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private fun getDependencies(
toastState.value = ToastState.Shown(text)
}
}
override val imageStorage: DesktopImageStorage = DesktopImageStorage(pictures, ioScope)
override val imageStorage: DesktopImageStorage = DesktopImageStorage(ioScope)
override val sharePicture: SharePicture = object : SharePicture {
override fun share(context: PlatformContext, picture: PictureData) {
// On Desktop share feature not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import platform.CoreGraphics.CGRectMake
Expand All @@ -36,7 +35,7 @@ private const val storableThumbnailSizePx = 180
private const val jpegCompressionQuality = 60

class IosImageStorage(
private val pictures: SnapshotStateList<PictureData>,
pictures: SnapshotStateList<PictureData>,
private val ioScope: CoroutineScope
) : ImageStorage {

Expand Down Expand Up @@ -77,7 +76,6 @@ class IosImageStorage(
picture.jpgFile.writeJpeg(fitInto(maxStorableImageSizePx))
picture.thumbnailJpgFile.writeJpeg(fitInto(storableThumbnailSizePx))
}
pictures.add(0, picture)
picture.jsonFile.writeText(picture.toJson())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import org.jetbrains.compose.internal.KOTLIN_JVM_PLUGIN_ID
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.Version
import org.jetbrains.compose.internal.ideaIsInSyncProvider
import org.jetbrains.compose.internal.mppExtOrNull
import org.jetbrains.compose.internal.service.ConfigurationProblemReporterService
import org.jetbrains.compose.internal.webExt
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
Expand All @@ -26,7 +24,6 @@ import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

internal fun Project.configureComposeCompilerPlugin() {
//only one of them can be applied to the project
Expand Down Expand Up @@ -84,33 +81,9 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
}

applicableForPlatformTypes = composeExt.platformTypes

collectUnsupportedCompilerPluginUsages(target)
}
}

private fun collectUnsupportedCompilerPluginUsages(project: Project) {
fun Project.hasNonJvmTargets(): Boolean {
val nonJvmTargets = setOf(KotlinPlatformType.native, KotlinPlatformType.js, KotlinPlatformType.wasm)
return mppExtOrNull?.targets?.any {
it.platformType in nonJvmTargets
} ?: false
}

fun SubpluginArtifact.isNonJBComposeCompiler(): Boolean {
return !groupId.startsWith("org.jetbrains.compose.compiler")
}

ConfigurationProblemReporterService.registerUnsupportedPluginProvider(
project,
project.provider {
composeCompilerArtifactProvider.compilerArtifact.takeIf {
project.hasNonJvmTargets() && it.isNonJBComposeCompiler()
}
}
)
}

override fun getCompilerPluginId(): String =
"androidx.compose.compiler.plugins.kotlin"

Expand Down Expand Up @@ -153,14 +126,3 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
private fun options(vararg options: Pair<String, String>): List<SubpluginOption> =
options.map { SubpluginOption(it.first, it.second) }
}

private const val COMPOSE_COMPILER_COMPATIBILITY_LINK =
"https://github.com/JetBrains/compose-jb/blob/master/VERSIONING.md#using-compose-multiplatform-compiler"

internal fun createWarningAboutNonCompatibleCompiler(currentCompilerPluginGroupId: String): String {
return """
WARNING: Usage of the Custom Compose Compiler plugin ('$currentCompilerPluginGroupId')
with non-JVM targets (Kotlin/Native, Kotlin/JS, Kotlin/WASM) is not supported.
For more information, please visit: $COMPOSE_COMPILER_COMPATIBILITY_LINK
""".trimMargin()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import org.jetbrains.compose.desktop.preview.internal.initializePreview
import org.jetbrains.compose.experimental.dsl.ExperimentalExtension
import org.jetbrains.compose.experimental.internal.*
import org.jetbrains.compose.internal.*
import org.jetbrains.compose.internal.service.ConfigurationProblemReporterService
import org.jetbrains.compose.internal.service.GradlePropertySnapshotService
import org.jetbrains.compose.internal.utils.currentTarget
import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.compose.resources.configureComposeResources
Expand All @@ -35,15 +33,8 @@ import org.jetbrains.kotlin.gradle.plugin.*

internal val composeVersion get() = ComposeBuildConfig.composeVersion

private fun initBuildServices(project: Project) {
ConfigurationProblemReporterService.init(project)
GradlePropertySnapshotService.init(project)
}

abstract class ComposePlugin : Plugin<Project> {
override fun apply(project: Project) {
initBuildServices(project)

val composeExtension = project.extensions.create("compose", ComposeExtension::class.java, project)
val desktopExtension = composeExtension.extensions.create("desktop", DesktopExtension::class.java)
val androidExtension = composeExtension.extensions.create("android", AndroidExtension::class.java)
Expand All @@ -60,7 +51,6 @@ abstract class ComposePlugin : Plugin<Project> {
composeExtension.extensions.create("web", WebExtension::class.java)

project.configureComposeCompilerPlugin()
project.configureNativeCompilerCaching()

project.configureComposeResources(resourcesExtension)

Expand Down

This file was deleted.

Loading

0 comments on commit 01b2dc7

Please sign in to comment.