Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ internal actual class CacheDrawScopeDragShadowCallback {
onDrawWithContent {
val pictureRecorder = PictureRecorder()
val pictureCanvas = pictureRecorder
.beginRecording(Rect.makeWH(width, height))
.beginRecording(
0f,
0f,
width,
height
)
.asComposeCanvas()
draw(
density = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,43 +130,108 @@ internal class SkiaBackedPath(
forceMoveTo: Boolean
) {
internalPath.arcTo(
rect.toSkiaRect(),
rect.left,
rect.top,
rect.right,
rect.bottom,
startAngleDegrees,
sweepAngleDegrees,
forceMoveTo
)
}

override fun addRect(rect: Rect) {
internalPath.addRect(rect.toSkiaRect(), PathDirection.COUNTER_CLOCKWISE)
internalPath.addRect(
rect.left,
rect.top,
rect.right,
rect.bottom,
PathDirection.COUNTER_CLOCKWISE
)
}

override fun addRect(rect: Rect, direction: Path.Direction) {
internalPath.addRect(rect.toSkiaRect(), direction.toSkiaPathDirection())
internalPath.addRect(
rect.left,
rect.top,
rect.right,
rect.bottom,
direction.toSkiaPathDirection()
)
}

override fun addOval(oval: Rect) {
internalPath.addOval(oval.toSkiaRect(), PathDirection.COUNTER_CLOCKWISE)
internalPath.addOval(
oval.left,
oval.top,
oval.right,
oval.bottom,
PathDirection.COUNTER_CLOCKWISE
)
}

override fun addOval(oval: Rect, direction: Path.Direction) {
internalPath.addOval(oval.toSkiaRect(), direction.toSkiaPathDirection())
internalPath.addOval(
oval.left,
oval.top,
oval.right,
oval.bottom,
direction.toSkiaPathDirection()
)
}

override fun addRoundRect(roundRect: RoundRect) {
internalPath.addRRect(roundRect.toSkiaRRect(), PathDirection.COUNTER_CLOCKWISE)
internalPath.addRRect(
roundRect.left,
roundRect.top,
roundRect.right,
roundRect.bottom,
floatArrayOf(
roundRect.topLeftCornerRadius.x,
roundRect.topLeftCornerRadius.y,
roundRect.topRightCornerRadius.x,
roundRect.topRightCornerRadius.y,
roundRect.bottomRightCornerRadius.x,
roundRect.bottomRightCornerRadius.y,
roundRect.bottomLeftCornerRadius.x,
roundRect.bottomLeftCornerRadius.y
),
PathDirection.COUNTER_CLOCKWISE
)
}

override fun addRoundRect(roundRect: RoundRect, direction: Path.Direction) {
internalPath.addRRect(roundRect.toSkiaRRect(), direction.toSkiaPathDirection())
internalPath.addRRect(
roundRect.left,
roundRect.top,
roundRect.right,
roundRect.bottom,
floatArrayOf(
roundRect.topLeftCornerRadius.x,
roundRect.topLeftCornerRadius.y,
roundRect.topRightCornerRadius.x,
roundRect.topRightCornerRadius.y,
roundRect.bottomRightCornerRadius.x,
roundRect.bottomRightCornerRadius.y,
roundRect.bottomLeftCornerRadius.x,
roundRect.bottomLeftCornerRadius.y
),
direction.toSkiaPathDirection()
)
}

override fun addArcRad(oval: Rect, startAngleRadians: Float, sweepAngleRadians: Float) {
addArc(oval, degrees(startAngleRadians), degrees(sweepAngleRadians))
}

override fun addArc(oval: Rect, startAngleDegrees: Float, sweepAngleDegrees: Float) {
internalPath.addArc(oval.toSkiaRect(), startAngleDegrees, sweepAngleDegrees)
internalPath.addArc(
oval.left,
oval.top,
oval.right,
oval.bottom,
startAngleDegrees, sweepAngleDegrees
)
}

override fun addPath(path: Path, offset: Offset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import androidx.compose.ui.graphics.drawscope.draw
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.toSkia
import androidx.compose.ui.graphics.toSkiaRRect
import androidx.compose.ui.graphics.toSkiaRect
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
Expand Down Expand Up @@ -376,10 +374,31 @@ actual class GraphicsLayer internal constructor(
renderNode.setClipPath(null)
} else {
renderNode.clip = clip
val tmpOutline = outline
when (tmpOutline) {
is Outline.Rectangle -> renderNode.setClipRect(tmpOutline.rect.toSkiaRect(), antiAlias = true)
is Outline.Rounded -> renderNode.setClipRRect(tmpOutline.roundRect.toSkiaRRect(), antiAlias = true)
when (val tmpOutline = outline) {
is Outline.Rectangle -> renderNode.setClipRect(
tmpOutline.rect.left,
tmpOutline.rect.top,
tmpOutline.rect.right,
tmpOutline.rect.bottom,
antiAlias = true
)
is Outline.Rounded -> renderNode.setClipRRect(
tmpOutline.roundRect.left,
tmpOutline.roundRect.top,
tmpOutline.roundRect.right,
tmpOutline.roundRect.bottom,
floatArrayOf(
tmpOutline.roundRect.topLeftCornerRadius.x,
tmpOutline.roundRect.topLeftCornerRadius.y,
tmpOutline.roundRect.topRightCornerRadius.x,
tmpOutline.roundRect.topRightCornerRadius.y,
tmpOutline.roundRect.bottomRightCornerRadius.x,
tmpOutline.roundRect.bottomRightCornerRadius.y,
tmpOutline.roundRect.bottomLeftCornerRadius.x,
tmpOutline.roundRect.bottomLeftCornerRadius.y
),
antiAlias = true
)
is Outline.Generic -> renderNode.setClipPath(tmpOutline.path.asSkiaPath(), antiAlias = true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,14 @@ class SkiaGraphicsLayerTest {
}
}
surface.flushAndSubmit(true)
val area =
IRect.makeWH(
val imageBitmap = surface
.makeImageSnapshot(
0,
0,
if (entireScene) TEST_WIDTH * 2 else TEST_WIDTH,
if (entireScene) TEST_HEIGHT * 2 else TEST_HEIGHT
)
val imageBitmap = surface.makeImageSnapshot(area)!!.toComposeImageBitmap()
)!!
.toComposeImageBitmap()
verify?.invoke(imageBitmap.toPixelMap())
} finally {
surface.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ fun shadowTest(block: DrawScope.() -> Unit, verify: (PixelMap) -> Unit) {
block()
}
surface.flushAndSubmit(true)
val area =
IRect.makeWH(TEST_WIDTH, TEST_HEIGHT)
val imageBitmap = surface.makeImageSnapshot(area)!!.toComposeImageBitmap()
val imageBitmap = surface
.makeImageSnapshot(
0,
0,
TEST_WIDTH,
TEST_HEIGHT
)!!
.toComposeImageBitmap()
verify(imageBitmap.toPixelMap())
} finally {
surface.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,12 @@ open class SkikoComposeUiTest @InternalTestApi constructor(

fun captureToImage(semanticsNode: SemanticsNode): ImageBitmap {
val rect = semanticsNode.boundsInWindow
val iRect = IRect.makeLTRB(rect.left.toInt(), rect.top.toInt(), rect.right.toInt(), rect.bottom.toInt())
val image = surface.makeImageSnapshot(iRect)
val image = surface.makeImageSnapshot(
rect.left.toInt(),
rect.top.toInt(),
rect.right.toInt(),
rect.bottom.toInt()
)
return image!!.toComposeImageBitmap()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.node.RootForTest
import androidx.compose.ui.platform.PlatformRootForTest
import androidx.compose.ui.scene.ComposeScenePointer
import androidx.compose.ui.util.fastForEach

@OptIn(InternalComposeUiApi::class)
internal actual fun createInputDispatcher(
Expand Down Expand Up @@ -300,7 +301,7 @@ internal class SkikoInputDispatcher(
override fun flush() {
val copy = batchedEvents.toList()
batchedEvents.clear()
for (event in copy) {
copy.fastForEach { event ->
advanceClockTime(event.eventTime - currentClockTime)
currentClockTime = event.eventTime
event.action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal class SkiaParagraph(
)
val path = Path()
for (b in boxes) {
path.asSkiaPath().addRect(b.rect)
path.asSkiaPath().addRect(b.rect.left, b.rect.top, b.rect.right, b.rect.bottom)
}
return path
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ internal class ComposeContainer(
*/
fun layersAbove(layer: DesktopComposeSceneLayer) = sequence {
var isAbove = false
for (i in layers) {
layers.fastForEach { i ->
if (i == layer) {
isAbove = true
} else if (isAbove) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toOffset
import androidx.compose.ui.util.fastCoerceAtLeast
import androidx.compose.ui.util.fastRoundToInt
import androidx.compose.ui.viewinterop.SwingInteropContainer
import androidx.compose.ui.window.WindowExceptionHandler
import androidx.compose.ui.window.asDpOffset
Expand Down Expand Up @@ -97,7 +99,6 @@ import java.awt.im.InputMethodRequests
import javax.swing.JComponent
import javax.swing.SwingUtilities
import kotlin.coroutines.CoroutineContext
import kotlin.math.roundToInt
import org.jetbrains.skia.Canvas
import org.jetbrains.skiko.ClipRectangle
import org.jetbrains.skiko.ExperimentalSkikoApi
Expand Down Expand Up @@ -673,8 +674,8 @@ internal class ComposeSceneMediator(
val size = sceneBoundsInPx?.size ?: container.sizeInPx
scene.size = IntSize(
// container.sizeInPx can be negative
width = size.width.coerceAtLeast(0f).roundToInt(),
height = size.height.coerceAtLeast(0f).roundToInt()
width = size.width.fastCoerceAtLeast(0f).fastRoundToInt(),
height = size.height.fastCoerceAtLeast(0f).fastRoundToInt()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import androidx.compose.runtime.CompositionContext
import androidx.compose.ui.awt.toAwtColor
import androidx.compose.ui.awt.toAwtRectangle
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.toRect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.scene.skia.SkiaLayerComponent
import androidx.compose.ui.scene.skia.SwingSkiaLayerComponent
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.roundToIntRect
import androidx.compose.ui.unit.toOffset
import androidx.compose.ui.util.fastRoundToInt
import androidx.compose.ui.window.density
import androidx.compose.ui.window.sizeInPx
import java.awt.Dimension
Expand Down Expand Up @@ -97,8 +97,12 @@ internal class SwingComposeSceneLayer(
override var scrimColor: Color? = null

init {
val boundsInPx = windowContainer.sizeInPx.toRect()
drawBounds = boundsInPx.roundToIntRect()
drawBounds = IntRect(
0,
0,
windowContainer.sizeInPx.width.fastRoundToInt(),
windowContainer.sizeInPx.height.fastRoundToInt()
)
mediator = ComposeSceneMediator(
container = container,
isWindowLevel = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import javax.swing.JDialog
import org.jetbrains.skia.Canvas
import org.jetbrains.skia.Rect as SkRect
import org.jetbrains.skiko.DelicateSkikoApi
import org.jetbrains.skiko.SkiaLayerAnalytics
import org.jetbrains.skiko.transparentWindowBackgroundHack
Expand Down Expand Up @@ -195,7 +194,7 @@ internal class WindowComposeSceneLayer(
color = scrimColor
blendMode = getDialogScrimBlendMode(transparent)
}.asFrameworkPaint()
canvas.drawRect(SkRect.makeWH(width.toFloat(), height.toFloat()), paint)
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint)
}

private fun createSkiaLayerComponent(mediator: ComposeSceneMediator): SkiaLayerComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,10 @@ internal class MetalRedrawer(
// Perform timestep and record all draw commands into [Picture]
val picture = trace("MetalRedrawer:draw:pictureRecording") {
pictureRecorder.beginRecording(
Rect(
left = 0f,
top = 0f,
width.toFloat(),
height.toFloat()
)
).also { canvas ->
render(canvas, lastRenderTimestamp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ internal class RootNodeOwner(
}

private fun isInBounds(localPosition: Offset): Boolean =
size?.toIntRect()?.toRect()?.contains(localPosition) ?: true
size?.toRect()?.contains(localPosition) ?: true

private fun calculateBoundsInWindow(): Rect? {
val rect = size?.toIntRect()?.toRect() ?: return null
val rect = size?.toRect() ?: return null
val p0 = platformContext.convertLocalToWindowPosition(Offset(rect.left, rect.top))
val p1 = platformContext.convertLocalToWindowPosition(Offset(rect.left, rect.bottom))
val p3 = platformContext.convertLocalToWindowPosition(Offset(rect.right, rect.top))
Expand Down Expand Up @@ -732,7 +732,7 @@ internal class RootNodeOwner(
override val semanticsOwner get() = owner.semanticsOwner
override val visibleBounds: Rect
get() {
val windowRect = platformContext.windowInfo.containerSize.toIntRect().toRect()
val windowRect = platformContext.windowInfo.containerSize.toRect()
val ownerRect = calculateBoundsInWindow()
return ownerRect?.intersect(windowRect) ?: windowRect
}
Expand Down
Loading
Loading