Skip to content

Fix iOS Metal foreground framebuffer reset#5351

Open
shai-almog wants to merge 3 commits into
masterfrom
fix-ios-metal-retained-framebuffer
Open

Fix iOS Metal foreground framebuffer reset#5351
shai-almog wants to merge 3 commits into
masterfrom
fix-ios-metal-retained-framebuffer

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5349.

The iOS Metal renderer keeps a persistent private screenTexture because Codename One may flush only dirty regions between frames. After iOS suspension, that private retained texture can be discarded or stale while the app resumes with partial dirty-region paints, leaving missing component pieces until touch or scroll forces a larger repaint.

This PR marks the Metal retained framebuffer invalid on foreground, requests a full repaint, and clears the persistent screen texture only when the next drain has screen-targeted full-frame work. The hooks are optional on the shared rendering-view protocol so OpenGL and watch renderers are unaffected.

Validation

  • git diff --check
  • XCODE_APP=/Applications/Xcode.app ./scripts/build-ios-app.sh -q -DskipTests
  • XCODE_APP=/Applications/Xcode.app ./scripts/run-ios-native-tests.sh /Users/shai/dev/cn3/CodenameOne/scripts/hellocodenameone/ios/target/hellocodenameone-ios-1.0-SNAPSHOT-ios-source/HelloCodenameOne.xcworkspace HelloCodenameOne

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

@shai-almog

shai-almog commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 139 screenshots: 139 matched.
✅ Native Apple TV (tvOS, Metal) screenshot tests passed.

@shai-almog

shai-almog commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 142 screenshots: 142 matched.
✅ Native Mac screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 176 seconds

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 56ms / native 9ms = 6.2x speedup
SIMD float-mul (64K x300) java 51ms / native 3ms = 17.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 262.000 ms
Base64 CN1 decode 189.000 ms
Base64 native encode 658.000 ms
Base64 encode ratio (CN1/native) 0.398x (60.2% faster)
Base64 native decode 365.000 ms
Base64 decode ratio (CN1/native) 0.518x (48.2% faster)
Base64 SIMD encode 52.000 ms
Base64 encode ratio (SIMD/CN1) 0.198x (80.2% faster)
Base64 SIMD decode 45.000 ms
Base64 decode ratio (SIMD/CN1) 0.238x (76.2% faster)
Base64 encode ratio (SIMD/native) 0.079x (92.1% faster)
Base64 decode ratio (SIMD/native) 0.123x (87.7% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 19.000 ms
Image createMask (SIMD on) 3.000 ms
Image createMask ratio (SIMD on/off) 0.158x (84.2% faster)
Image applyMask (SIMD off) 76.000 ms
Image applyMask (SIMD on) 78.000 ms
Image applyMask ratio (SIMD on/off) 1.026x (2.6% slower)
Image modifyAlpha (SIMD off) 71.000 ms
Image modifyAlpha (SIMD on) 48.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.676x (32.4% faster)
Image modifyAlpha removeColor (SIMD off) 60.000 ms
Image modifyAlpha removeColor (SIMD on) 37.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.617x (38.3% faster)

@shai-almog

shai-almog commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 216 screenshots: 216 matched.
✅ Native Apple Watch (watchOS, Core Graphics) screenshot tests passed.

@shai-almog

shai-almog commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 143 screenshots: 143 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 339 seconds

Build and Run Timing

Metric Duration
Simulator Boot 81000 ms
Simulator Boot (Run) 1000 ms
App Install 19000 ms
App Launch 2000 ms
Test Execution 523000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 57ms / native 3ms = 19.0x speedup
SIMD float-mul (64K x300) java 57ms / native 3ms = 19.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 296.000 ms
Base64 CN1 decode 250.000 ms
Base64 native encode 1087.000 ms
Base64 encode ratio (CN1/native) 0.272x (72.8% faster)
Base64 native decode 895.000 ms
Base64 decode ratio (CN1/native) 0.279x (72.1% faster)
Base64 SIMD encode 56.000 ms
Base64 encode ratio (SIMD/CN1) 0.189x (81.1% faster)
Base64 SIMD decode 49.000 ms
Base64 decode ratio (SIMD/CN1) 0.196x (80.4% faster)
Base64 encode ratio (SIMD/native) 0.052x (94.8% faster)
Base64 decode ratio (SIMD/native) 0.055x (94.5% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 21.000 ms
Image createMask (SIMD on) 84.000 ms
Image createMask ratio (SIMD on/off) 4.000x (300.0% slower)
Image applyMask (SIMD off) 234.000 ms
Image applyMask (SIMD on) 256.000 ms
Image applyMask ratio (SIMD on/off) 1.094x (9.4% slower)
Image modifyAlpha (SIMD off) 118.000 ms
Image modifyAlpha (SIMD on) 83.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.703x (29.7% faster)
Image modifyAlpha removeColor (SIMD off) 217.000 ms
Image modifyAlpha removeColor (SIMD on) 275.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.267x (26.7% slower)

@shai-almog

shai-almog commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 137 screenshots: 137 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 510 seconds

Build and Run Timing

Metric Duration
Simulator Boot 105000 ms
Simulator Boot (Run) 2000 ms
App Install 25000 ms
App Launch 9000 ms
Test Execution 658000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 84ms / native 3ms = 28.0x speedup
SIMD float-mul (64K x300) java 105ms / native 4ms = 26.2x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 297.000 ms
Base64 CN1 decode 215.000 ms
Base64 native encode 1147.000 ms
Base64 encode ratio (CN1/native) 0.259x (74.1% faster)
Base64 native decode 1063.000 ms
Base64 decode ratio (CN1/native) 0.202x (79.8% faster)
Base64 SIMD encode 57.000 ms
Base64 encode ratio (SIMD/CN1) 0.192x (80.8% faster)
Base64 SIMD decode 49.000 ms
Base64 decode ratio (SIMD/CN1) 0.228x (77.2% faster)
Base64 encode ratio (SIMD/native) 0.050x (95.0% faster)
Base64 decode ratio (SIMD/native) 0.046x (95.4% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 54.000 ms
Image createMask (SIMD on) 3.000 ms
Image createMask ratio (SIMD on/off) 0.056x (94.4% faster)
Image applyMask (SIMD off) 246.000 ms
Image applyMask (SIMD on) 328.000 ms
Image applyMask ratio (SIMD on/off) 1.333x (33.3% slower)
Image modifyAlpha (SIMD off) 221.000 ms
Image modifyAlpha (SIMD on) 225.000 ms
Image modifyAlpha ratio (SIMD on/off) 1.018x (1.8% slower)
Image modifyAlpha removeColor (SIMD off) 121.000 ms
Image modifyAlpha removeColor (SIMD on) 176.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.455x (45.5% slower)

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.

Still seeing some rare Metal issues such as FAB or switches with violet background or a component not being fully drawn until touching the UI

1 participant