Skip to content

Improved drawable management#2732

Merged
Andrei Salavei (ASalavei) merged 16 commits into
jb-mainfrom
andrei.salavei/surface-rendering
Feb 17, 2026
Merged

Improved drawable management#2732
Andrei Salavei (ASalavei) merged 16 commits into
jb-mainfrom
andrei.salavei/surface-rendering

Conversation

@ASalavei

@ASalavei Andrei Salavei (ASalavei) commented Jan 30, 2026

Copy link
Copy Markdown
  • Enable parallelRendering by default.
  • Implement the CMPMetalLayer class, which can manage a pool of self-allocated metal textures and use an IOSurface for presentation.
  • Add new implementation of the SurfaceMetalView and SurfaceRedrawer which are used when the parallelRendering flag is set to true.
  • Use old rendering approach with LegacyMetalView and LegacyRedrawer as a backup option when the the parallelRendering flag is set to false.
  • MetalView and MetalRedrawer where converted into the interfaces to hide implementation details of the corresponding classes.

Fixes https://youtrack.jetbrains.com/issue/CMP-9559/Fix-waiting-for-next-drawable-by-the-main-thread
Fixes https://youtrack.jetbrains.com/issue/CMP-7598/Skia-crash-on-iOS-GrResourceCachenotifyARefCntReachedZero

Release Notes

Migration Notes - iOS

  • parallelRendering flag now enabled by default.

Fixes - iOS

  • Fix crashes when parallelRendering is enabled.

@ASalavei Andrei Salavei (ASalavei) force-pushed the andrei.salavei/surface-rendering branch from 390e5ea to f85c4f6 Compare February 3, 2026 14:52
@ASalavei Andrei Salavei (ASalavei) marked this pull request as ready for review February 4, 2026 11:01

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few small comments, otherwise LGTM 👏🏻

Comment thread compose/ui/ui-uikit/src/iosMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalLayer.m Outdated
Comment thread compose/ui/ui-uikit/src/iosMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalLayer.m Outdated
Comment thread compose/ui/ui-uikit/src/iosMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalLayer.m Outdated
Comment thread compose/ui/ui-uikit/src/iosMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalLayer.m Outdated
Comment thread compose/ui/ui-uikit/src/iosMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPUIKitUtils.h Outdated
# Conflicts:
#	compose/ui/ui/src/iosMain/kotlin/androidx/compose/ui/window/MetalRedrawer.ios.kt

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new parallel rendering implementation for iOS using a custom CMPMetalLayer that manages a pool of IOSurface-backed Metal drawables. The implementation aims to fix crashes and improve performance when parallel rendering is enabled by giving explicit control over drawable lifecycle and presentation timing.

Changes:

  • Enables parallelRendering by default (changed from false to true)
  • Implements CMPMetalLayer and CMPDrawable in Objective-C to manage a pool of up to 3 Metal drawables with IOSurface backing
  • Adds SurfaceMetalView and SurfaceMetalRedrawer as the new default implementation when parallel rendering is enabled
  • Refactors existing implementations into LegacyMetalView and LegacyMetalRedrawer as fallback when parallel rendering is disabled
  • Converts MetalView and MetalRedrawer into sealed interfaces with factory functions to hide implementation details

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ComposeContainerConfiguration.ios.kt Changes parallelRendering default from false to true and updates documentation
MetalView.ios.kt Converts MetalView class to MetalViewHolder interface and factory function; renames existing implementation to LegacyMetalView
MetalRedrawer.ios.kt Converts MetalRedrawer class to sealed interface; renames existing implementation to LegacyMetalRedrawer; changes command buffer handler from addCompletedHandler to addScheduledHandler
SurfaceMetalView.ios.kt New implementation using CMPMetalLayer for parallel rendering
SurfaceMetalRedrawer.ios.kt New redrawer implementation with separate rendering queue and drawable pool management
CMPMetalLayer.h/.m New Objective-C class managing a pool of 3 IOSurface-backed Metal drawables with explicit lifecycle control
CMPDrawable.h/.m New Objective-C class representing an IOSurface-backed Metal drawable
CMPMetalLayerTests.swift Comprehensive test suite for CMPMetalLayer with 423 lines covering various scenarios
UIKitInteropTransaction.ios.kt Adds performTransaction() helper method to simplify action execution
ComposeContainerView.ios.kt Updates to use MetalViewHolder interface instead of concrete MetalView class
ComposeLayersViewController.ios.kt Updates to use MetalViewHolder interface
UIKitComposeSceneLayer.ios.kt Accesses view property through MetalViewHolder interface
MetalRedrawerTest.kt Updates test to use CMPMetalLayer and SurfaceMetalRedrawer
ComposeSceneMediatorTest.kt Updates test to use CMPMetalLayer and SurfaceMetalRedrawer
main.ios.kt Removes explicit parallelRendering = true configuration as it's now the default
CMPUIKitUtils.h Adds imports for new CMPDrawable and CMPMetalLayer headers
project.pbxproj Adds new source files and test files to Xcode project

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ASalavei Andrei Salavei (ASalavei) merged commit cbdff85 into jb-main Feb 17, 2026
22 checks passed
@ASalavei Andrei Salavei (ASalavei) deleted the andrei.salavei/surface-rendering branch February 17, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants