Fix RecordDrawRectRenderDecorator closing#2864
Conversation
| }.also { | ||
| drawBoundsRecorder?.close() | ||
| drawBoundsRecorder = it |
There was a problem hiding this comment.
This looks strange. We're returning an object but continue owning it, and its lifecycle is the same as the DesktopComposeSceneLayer, unless someone asks for a new one.
Maybe something like this instead?
protected var targetRenderDelegate: SkikoRenderDelegate? = null
protected val drawBoundsRecorder = RecordDrawRectRenderDecorator(
decorated = { canvas, width, height, nanoTime ->
targetRenderDelegate?.onRender(canvas, width, height, nanoTime)
}
) { canvasBoundsInPx ->
val currentCanvasOffset = drawBounds.topLeft
val drawBoundsInWindow = canvasBoundsInPx.roundToIntRect().translate(currentCanvasOffset)
maxDrawInflate = maxInflate(boundsInWindow, drawBoundsInWindow, maxDrawInflate)
drawBounds = IntRect(
left = boundsInWindow.left - maxDrawInflate.left,
top = boundsInWindow.top - maxDrawInflate.top,
right = boundsInWindow.right + maxDrawInflate.right,
bottom = boundsInWindow.bottom + maxDrawInflate.bottom
)
onDrawBoundsChanged()
}
There was a problem hiding this comment.
This assumes that the function is called only once and we're having single targetRenderDelegate. This is kinda true for now, but seems more dangerous than "closing during close".
I'll think about different ways...
There was a problem hiding this comment.
Made it more generic, ptal
There was a problem hiding this comment.
This assumes that the function is called only once and we're having single targetRenderDelegate. This is kinda true for now, but seems more dangerous than "closing during close".
I think it's better for the code to reflect the current state rather than some future possible state.
With the latest changes it creates the illusion that recordDrawBounds can be called multiple times to wrap different, concurrently "alive" SkikoRenderDelegates , but this is not actually the case, as it will cause race conditions (the decorator writes to "global" state).
CMP-6590 Memory leak:
RecordDrawRectRenderDecoratoris not closedRelease Notes
Fixes - Desktop
compose.layers.typesetting