Skip to content

Fix iOS Metal foreground framebuffer reset - #5351

Merged
shai-almog merged 9 commits into
masterfrom
fix-ios-metal-retained-framebuffer
Jul 11, 2026
Merged

Fix iOS Metal foreground framebuffer reset#5351
shai-almog merged 9 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: 223 seconds

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 62ms / native 9ms = 6.8x speedup
SIMD float-mul (64K x300) java 69ms / native 2ms = 34.5x 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 177.000 ms
Base64 CN1 decode 128.000 ms
Base64 native encode 1025.000 ms
Base64 encode ratio (CN1/native) 0.173x (82.7% faster)
Base64 native decode 602.000 ms
Base64 decode ratio (CN1/native) 0.213x (78.7% faster)
Base64 SIMD encode 55.000 ms
Base64 encode ratio (SIMD/CN1) 0.311x (68.9% faster)
Base64 SIMD decode 49.000 ms
Base64 decode ratio (SIMD/CN1) 0.383x (61.7% faster)
Base64 encode ratio (SIMD/native) 0.054x (94.6% faster)
Base64 decode ratio (SIMD/native) 0.081x (91.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 7.000 ms
Image createMask (SIMD on) 1.000 ms
Image createMask ratio (SIMD on/off) 0.143x (85.7% faster)
Image applyMask (SIMD off) 143.000 ms
Image applyMask (SIMD on) 190.000 ms
Image applyMask ratio (SIMD on/off) 1.329x (32.9% slower)
Image modifyAlpha (SIMD off) 150.000 ms
Image modifyAlpha (SIMD on) 104.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.693x (30.7% faster)
Image modifyAlpha removeColor (SIMD off) 147.000 ms
Image modifyAlpha removeColor (SIMD on) 133.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.905x (9.5% 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: 365 seconds

Build and Run Timing

Metric Duration
Simulator Boot 98000 ms
Simulator Boot (Run) 1000 ms
App Install 17000 ms
App Launch 6000 ms
Test Execution 354000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 67ms / native 3ms = 22.3x speedup
SIMD float-mul (64K x300) java 130ms / native 3ms = 43.3x 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 160.000 ms
Base64 CN1 decode 187.000 ms
Base64 native encode 682.000 ms
Base64 encode ratio (CN1/native) 0.235x (76.5% faster)
Base64 native decode 514.000 ms
Base64 decode ratio (CN1/native) 0.364x (63.6% faster)
Base64 SIMD encode 75.000 ms
Base64 encode ratio (SIMD/CN1) 0.469x (53.1% faster)
Base64 SIMD decode 53.000 ms
Base64 decode ratio (SIMD/CN1) 0.283x (71.7% faster)
Base64 encode ratio (SIMD/native) 0.110x (89.0% faster)
Base64 decode ratio (SIMD/native) 0.103x (89.7% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 7.000 ms
Image createMask (SIMD on) 2.000 ms
Image createMask ratio (SIMD on/off) 0.286x (71.4% faster)
Image applyMask (SIMD off) 44.000 ms
Image applyMask (SIMD on) 74.000 ms
Image applyMask ratio (SIMD on/off) 1.682x (68.2% slower)
Image modifyAlpha (SIMD off) 55.000 ms
Image modifyAlpha (SIMD on) 45.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.818x (18.2% faster)
Image modifyAlpha removeColor (SIMD off) 67.000 ms
Image modifyAlpha removeColor (SIMD on) 58.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.866x (13.4% faster)

@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: 346 seconds

Build and Run Timing

Metric Duration
Simulator Boot 83000 ms
Simulator Boot (Run) 1000 ms
App Install 16000 ms
App Launch 3000 ms
Test Execution 447000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 346ms / native 6ms = 57.6x speedup
SIMD float-mul (64K x300) java 80ms / native 4ms = 20.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 280.000 ms
Base64 CN1 decode 183.000 ms
Base64 native encode 668.000 ms
Base64 encode ratio (CN1/native) 0.419x (58.1% faster)
Base64 native decode 353.000 ms
Base64 decode ratio (CN1/native) 0.518x (48.2% faster)
Base64 SIMD encode 66.000 ms
Base64 encode ratio (SIMD/CN1) 0.236x (76.4% faster)
Base64 SIMD decode 70.000 ms
Base64 decode ratio (SIMD/CN1) 0.383x (61.7% faster)
Base64 encode ratio (SIMD/native) 0.099x (90.1% faster)
Base64 decode ratio (SIMD/native) 0.198x (80.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 12.000 ms
Image createMask (SIMD on) 2.000 ms
Image createMask ratio (SIMD on/off) 0.167x (83.3% faster)
Image applyMask (SIMD off) 78.000 ms
Image applyMask (SIMD on) 275.000 ms
Image applyMask ratio (SIMD on/off) 3.526x (252.6% slower)
Image modifyAlpha (SIMD off) 177.000 ms
Image modifyAlpha (SIMD on) 170.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.960x (4.0% faster)
Image modifyAlpha removeColor (SIMD off) 287.000 ms
Image modifyAlpha removeColor (SIMD on) 309.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.077x (7.7% slower)

@shai-almog

shai-almog commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 144 screenshots: 144 matched.

Native Android coverage

  • 📊 Line coverage: 10.14% (10350/102057 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 8.96% (50762/566696), branch 4.51% (2328/51664), complexity 4.48% (2446/54585), method 6.79% (1922/28292), class 10.82% (435/4021)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • com.google.common.cache.com.google.common.cache.LocalCache$Segment – 0.00% (0/726 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 10.14% (10350/102057 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 8.96% (50762/566696), branch 4.51% (2328/51664), complexity 4.48% (2446/54585), method 6.79% (1922/28292), class 10.82% (435/4021)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • com.google.common.cache.com.google.common.cache.LocalCache$Segment – 0.00% (0/726 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend scalar fallback (no native SIMD)
SIMD int-add (64K x300) java 314ms / native 151ms = 2.0x speedup
SIMD float-mul (64K x300) java 205ms / native 139ms = 1.4x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 268.000 ms
Base64 CN1 decode 631.000 ms
Base64 native encode 764.000 ms
Base64 encode ratio (CN1/native) 0.351x (64.9% faster)
Base64 native decode 1213.000 ms
Base64 decode ratio (CN1/native) 0.520x (48.0% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog

shai-almog commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 135 screenshots: 135 matched.
✅ JavaScript-port screenshot tests passed.

@shai-almog

shai-almog commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 140 screenshots: 140 matched.
Native Windows port, REAL shipping pipeline: the hellocodenameone screenshot suite rendered by a binary CROSS-COMPILED on Linux (clang-cl + xwin, WebView2 linked) and RUN on a Windows x64 runner. Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 62ms / native 5ms = 12.4x speedup
SIMD float-mul (64K x300) java 63ms / native 4ms = 15.7x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 native bridge unavailable (CN1 + SIMD + image benchmarks only)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 192.000 ms
Base64 CN1 decode 130.000 ms
Base64 SIMD encode 101.000 ms
Base64 encode ratio (SIMD/CN1) 0.526x (47.4% faster)
Base64 SIMD decode 88.000 ms
Base64 decode ratio (SIMD/CN1) 0.677x (32.3% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 19.000 ms
Image createMask (SIMD on) 15.000 ms
Image createMask ratio (SIMD on/off) 0.789x (21.1% faster)
Image applyMask (SIMD off) 43.000 ms
Image applyMask (SIMD on) 37.000 ms
Image applyMask ratio (SIMD on/off) 0.860x (14.0% faster)
Image modifyAlpha (SIMD off) 42.000 ms
Image modifyAlpha (SIMD on) 40.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.952x (4.8% faster)
Image modifyAlpha removeColor (SIMD off) 55.000 ms
Image modifyAlpha removeColor (SIMD on) 29.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.527x (47.3% faster)

@shai-almog

shai-almog commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 141 screenshots: 141 matched.
Native Linux port (x64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub x64 runner. Baseline: scripts/linux/screenshots.

@shai-almog

shai-almog commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 141 screenshots: 141 matched.
Native Linux port (arm64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub arm64 runner. Baseline: scripts/linux/screenshots-arm.

@shai-almog
shai-almog merged commit 048820d into master Jul 11, 2026
41 checks passed
@shai-almog
shai-almog deleted the fix-ios-metal-retained-framebuffer branch July 11, 2026 11:42
shai-almog added a commit that referenced this pull request Jul 11, 2026
… shift + rounded dark MultiButton

GL (16), Metal (16), tv (5), watch (9) renders reviewed against the
mac goldens from the merged tree. The old GL/Metal goldens carried
pre-#5351 renders where the Metal/GL foreground erase dropped button
pills and text-field glass cells (ButtonTheme_dark golden showed bare
blue text and H=7mm vs the correct glass pills at H=5mm); the new
renders restore them. Remaining churn is the #5358 TextArea vertical
alignment shift plus the rounded dark MultiButton fix (74599f4),
now confirmed rounded on metal, tv and watch.

Deliberately NOT accepted: AnimateLayoutScreenshotTest-family goldens
(their committed renders lost the tile text in the final frames on all
ParparVM runtimes -- iOS GL/Metal/JS -- while JVM/ART runtimes keep it;
that regression is being tracked down separately and the goldens will
be refreshed when it is fixed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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