Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix measuring clipped graphics #1385

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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 @@ -19,6 +19,7 @@ package androidx.compose.ui.platform
import org.jetbrains.skia.Rect as SkRect
import androidx.compose.ui.geometry.MutableRect
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.RoundRect
import androidx.compose.ui.geometry.toRect
import androidx.compose.ui.graphics.Canvas
Expand All @@ -42,6 +43,7 @@ import androidx.compose.ui.graphics.asSkiaPath
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.toSkiaRRect
import androidx.compose.ui.graphics.toSkiaRect
import androidx.compose.ui.node.OwnedLayer
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
Expand Down Expand Up @@ -237,11 +239,13 @@ internal class RenderNodeLayer(

override fun drawLayer(canvas: Canvas) {
if (picture == null) {
val measureDrawBounds = !clip || shadowElevation > 0
val bounds = size.toSize().toRect()
val pictureCanvas = pictureRecorder.beginRecording(
bounds = PICTURE_BOUNDS,
bbh = bbhFactory
bounds = if (measureDrawBounds) PICTURE_BOUNDS else bounds.toSkiaRect(),
bbh = if (measureDrawBounds) bbhFactory else null
)
performDrawLayer(pictureCanvas.asComposeCanvas())
performDrawLayer(pictureCanvas.asComposeCanvas(), bounds)
picture = pictureRecorder.finishRecordingAsPicture()
}

Expand All @@ -260,7 +264,7 @@ internal class RenderNodeLayer(
matrix.timesAssign(inverseMatrix)
}

private fun performDrawLayer(canvas: Canvas) {
private fun performDrawLayer(canvas: Canvas, bounds: Rect) {
if (alpha > 0) {
if (shadowElevation > 0) {
drawShadow(canvas)
Expand All @@ -281,7 +285,6 @@ internal class RenderNodeLayer(
currentRenderEffect != null ||
compositingStrategy == CompositingStrategy.Offscreen
if (requiresLayer) {
val bounds = size.toSize().toRect()
canvas.saveLayer(
bounds,
Paint().apply {
Expand Down
Loading