-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
62 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 32 additions & 47 deletions
79
library/src/desktopMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.desktop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 9 additions & 43 deletions
52
library/src/iosMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,17 @@ | ||
package ir.mahozad.multiplatform.comshot | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.InternalComposeUiApi | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asComposeCanvas | ||
import androidx.compose.ui.graphics.toComposeImageBitmap | ||
import androidx.compose.ui.scene.ComposeScene | ||
import androidx.compose.ui.scene.MultiLayerComposeScene | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.toIntRect | ||
import org.jetbrains.skia.Surface | ||
|
||
private val surface = Surface.makeRasterN32Premul(800, 600) | ||
@OptIn(InternalComposeUiApi::class) | ||
private lateinit var scene: ComposeScene | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
private fun render(timeMillis: Long) { | ||
scene.render( | ||
surface.canvas.asComposeCanvas(), | ||
timeMillis * NanoSecondsPerMilliSecond | ||
) | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
private fun createUi() = MultiLayerComposeScene( | ||
layoutDirection = LayoutDirection.Ltr, | ||
invalidate = { render(0) }, | ||
// density = Density(1f), | ||
// coroutineContext = Dispatchers.Unconfined, | ||
// composeSceneContext = TestComposeSceneContext(), | ||
).also { | ||
it.boundsInWindow = IntSize(600, 400).toIntRect() | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
actual fun initializeeeeeee() { | ||
scene = createUi() | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
actual fun setContenttt(content: @Composable () -> Unit) { | ||
scene.setContent(content) | ||
} | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.runSkikoComposeUiTest | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
actual fun captureToImageeee(content: @Composable () -> Unit): ImageBitmap { | ||
// waitForIdle() | ||
return surface.makeImageSnapshot().toComposeImageBitmap() | ||
var image: ImageBitmap? = null | ||
runSkikoComposeUiTest { | ||
setContent(content) | ||
image = captureToImage() | ||
} | ||
return image!! | ||
} |
52 changes: 9 additions & 43 deletions
52
library/src/jsMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 9 additions & 43 deletions
52
library/src/wasmJsMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.wasm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,17 @@ | ||
package ir.mahozad.multiplatform.comshot | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.InternalComposeUiApi | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asComposeCanvas | ||
import androidx.compose.ui.graphics.toComposeImageBitmap | ||
import androidx.compose.ui.scene.ComposeScene | ||
import androidx.compose.ui.scene.MultiLayerComposeScene | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.toIntRect | ||
import org.jetbrains.skia.Surface | ||
|
||
private val surface = Surface.makeRasterN32Premul(800, 600) | ||
@OptIn(InternalComposeUiApi::class) | ||
private lateinit var scene: ComposeScene | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
private fun render(timeMillis: Long) { | ||
scene.render( | ||
surface.canvas.asComposeCanvas(), | ||
timeMillis * NanoSecondsPerMilliSecond | ||
) | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
private fun createUi() = MultiLayerComposeScene( | ||
layoutDirection = LayoutDirection.Ltr, | ||
invalidate = { render(0) }, | ||
// density = Density(1f), | ||
// coroutineContext = Dispatchers.Unconfined, | ||
// composeSceneContext = TestComposeSceneContext(), | ||
).also { | ||
it.boundsInWindow = IntSize(600, 400).toIntRect() | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
actual fun initializeeeeeee() { | ||
scene = createUi() | ||
} | ||
|
||
@OptIn(InternalComposeUiApi::class) | ||
actual fun setContenttt(content: @Composable () -> Unit) { | ||
scene.setContent(content) | ||
} | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.runSkikoComposeUiTest | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
actual fun captureToImageeee(content: @Composable () -> Unit): ImageBitmap { | ||
// waitForIdle() | ||
return surface.makeImageSnapshot().toComposeImageBitmap() | ||
var image: ImageBitmap? = null | ||
runSkikoComposeUiTest { | ||
setContent(content) | ||
image = captureToImage() | ||
} | ||
return image!! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters