Skip to content

Smartwatch form-factor support (Apple Watch + Wear OS)#5251

Closed
shai-almog wants to merge 2 commits into
masterfrom
feat-watch-support
Closed

Smartwatch form-factor support (Apple Watch + Wear OS)#5251
shai-almog wants to merge 2 commits into
masterfrom
feat-watch-support

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

What

Adds the foundation for building Apple Watch (watchOS) and Wear OS apps, and proves the new APIs + entry-point model end-to-end in the hellocodenameone screenshot suite.

Form-factor API (core + ports)

  • Display.isWatch() / Display.getFormFactor() + CN facades + FORM_FACTOR_* constants, mirroring the isTablet()/isDesktop() pattern. Default false in CodenameOneImplementation; overridden in iOS (native isRunningOnWatch), Android (FEATURE_WATCH), and JavaSE (skin watch=true). New "watch" resource-override layer per port.

watchOS rendering port (iOS native sources)

watchOS has no UIKit view hierarchy, no OpenGL ES, and no Metal — so the iOS port's GL/Metal render path can't run. All additive under #if TARGET_OS_WATCH, leaving the iOS slice byte-for-byte unchanged:

  • CN1CGGraphics — Core Graphics rasterizer backend.
  • CN1WatchRenderingViewCGBitmapContext surface conforming to CN1RenderingView.
  • CN1WatchHost — timer-driven frame pump + Digital Crown / tap input bridge.
  • FillRect/DrawRect/ClearRect/DrawLine wired to the CG backend; remaining ops + rollout tracked in WATCHOS_PORT.md. Validated on the watchOS 26.2 simulator (Xcode 26.3).

Build pipeline — separate watchMain entry + seamless double app

  • codename1.watchMain in codenameone_settings.properties declares a distinct watch lifecycle (used for both Apple Watch and Wear). It may equal the phone main, but a distinct entry point lets the watch slice tree-shake from its own root.
  • WatchNativeBuilder (modeled on MacNativeBuilder) auto-enables when watchMain is set and adds a watchOS app target (arm64_32, WKApplication, companion-embed or standalone) to the iOS Xcode project — so the double app is produced as part of the regular iPhone build.
  • watchNative.* build hints registered; JavaSE ships generated Apple Watch simulator skins.

Proven in hellocodenameone

  • AbstractGraphicsScreenshotTest renders 4 separate full-screen captures on a watch (via CN.isWatch()) instead of a cramped 2×2 grid. Verified in the JavaSE simulator with the Apple Watch skin (396×484).
  • HelloCodenameOneWatch watchMain lifecycle + codename1.watchMain setting.
  • Cn1ssDeviceRunner gains an optional -Dcn1ss.filter subset selector.

Watch screenshots

See the inline comments below — fill-arc and draw-arc each rendered as 4 separate watch-shaped screenshots (one per AA/image variant) instead of one 2×2 grid tile.

Answering the original questions

  • Universal or separate build? Neither is one universal binary. Apple Watch = a distinct watch target that rides inside the same .ipa (companion) or ships standalone; Wear OS = a separate APK. One submission can carry phone + watch, but always two binaries.
  • isWatch() + skins? Yes — shipped, and the form-factor-aware test proves them.
  • How to construct such an app? Declare codename1.watchMain; the build emits the watch target automatically; per-component UI adapts via CN.isWatch()/getFormFactor().

🤖 Generated with Claude Code

shai-almog and others added 2 commits June 17, 2026 04:44
Adds the foundation for building Apple Watch / Wear OS apps and proves the
model end-to-end in the hellocodenameone screenshot suite.

Form-factor API (core + ports):
- Display.isWatch()/getFormFactor() + CN facades + FORM_FACTOR_* constants,
  following the isTablet()/isDesktop() pattern. Defaults false in
  CodenameOneImplementation; overridden in iOS (native isRunningOnWatch),
  Android (FEATURE_WATCH), and JavaSE (skin watch=true). New "watch" resource
  override layer in each port's getPlatformOverrides().

watchOS rendering port (iOS native sources, all additive under
#if TARGET_OS_WATCH so the iOS slice is byte-for-byte unchanged):
- CN1CGGraphics: Core Graphics rasterizer backend (no GL/Metal on watchOS).
- CN1WatchRenderingView: CGBitmapContext surface conforming to CN1RenderingView.
- CN1WatchHost: timer-driven frame pump + crown/tap input bridge.
- FillRect/DrawRect/ClearRect/DrawLine wired to the CG backend (rollout in
  WATCHOS_PORT.md). Validated on the watchOS simulator (Xcode 26.3).

Build pipeline (separate watch entry point + seamless double app):
- codename1.watchMain in codenameone_settings.properties declares a distinct
  watch lifecycle (Apple Watch + Wear); a distinct entry enables more
  aggressive tree-shaking. Flows via CN1BuildMojo as the watchMain build arg.
- WatchNativeBuilder (modeled on MacNativeBuilder) auto-enables when watchMain
  is set and adds a watchOS app target (arm64_32, WKApplication, companion
  embed or standalone) to the iOS Xcode project via the xcodeproj gem.
- watchNative.* build hints registered in BuildHintSchemaDefaults.
- JavaSE ships generated Apple Watch simulator skins (round, safe areas).

hellocodenameone (proves the APIs + model):
- AbstractGraphicsScreenshotTest renders 4 separate full-screen captures on a
  watch (via CN.isWatch()) instead of a cramped 2x2 grid; BaseTest gains a
  chained-capture helper. Verified in the JavaSE simulator with the Apple
  Watch skin (396x484): graphics-{draw,fill}-arc-{direct,image}-aa-{off,on}.
- HelloCodenameOneWatch watchMain lifecycle + codename1.watchMain setting.
- Cn1ssDeviceRunner gains an optional -Dcn1ss.filter subset selector.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Apple Watch 45mm (396x484) captures from the JavaSE simulator showing
AbstractGraphicsScreenshotTest emitting 4 separate full-screen screenshots per
test on the watch form factor instead of a 2x2 grid. Demonstration artifacts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shai-almog

Copy link
Copy Markdown
Collaborator Author

Watch form factor — graphics-fill-arc → 4 separate tests

On phone/tablet/desktop this test is one screenshot: a 2×2 grid comparing direct vs mutable-image painting × AA off/on.

Phone (2×2 grid, 320×480):

On Apple Watch (CN.isWatch()==true, 396×484) the same test detects the form factor and emits four separate full-screen captures — each variant readable on the small round screen instead of crammed into a quadrant:

direct, AA off direct, AA on mutable-image, AA off mutable-image, AA on

Rendered live in the JavaSE simulator with the generated Apple Watch 45mm skin.

@shai-almog

Copy link
Copy Markdown
Collaborator Author

Watch form factor — graphics-draw-arc → 4 separate tests

Phone (2×2 grid, 320×480):

Apple Watch (396×484) — four separate full-screen captures:

direct, AA off direct, AA on mutable-image, AA off mutable-image, AA on

The split is driven entirely by CN.isWatch() in AbstractGraphicsScreenshotTest.runTest(); no per-test changes were needed, which is the point — a single screenshot test adapts to the form factor. The watch app itself is reached through the distinct codename1.watchMain lifecycle (HelloCodenameOneWatch), so the same project services phone and watch from two entry points.

@shai-almog

shai-almog commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 11 screenshots: 11 matched.
✅ JavaSE simulator integration screenshots matched stored baselines.

@shai-almog

Copy link
Copy Markdown
Collaborator Author

Closing in favor of doing this properly. The right deliverable is a native watchOS-simulator screenshot job in CI (modeled on build-ios-metal/gl): build the watch slice, run the cn1ss suite on the watchOS simulator, compare to goldens, and post a <!-- CN1SS_IOS_WATCH_COMMENT --> status section. That requires finishing the watchOS rendering rollout first (the per-op Core Graphics backend + bootstrap so the suite actually renders on-device), which this PR did not do. Re-doing on a fresh branch.

@shai-almog shai-almog closed this Jun 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog

shai-almog commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 128 screenshots: 128 matched.

Native Android coverage

  • 📊 Line coverage: 14.26% (8685/60918 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.54% (42741/370532), branch 5.11% (1780/34863), complexity 6.09% (2035/33408), method 10.54% (1645/15613), class 17.16% (378/2203)
    • 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)
      • 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)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 14.26% (8685/60918 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 11.54% (42741/370532), branch 5.11% (1780/34863), complexity 6.09% (2035/33408), method 10.54% (1645/15613), class 17.16% (378/2203)
    • 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)
      • 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)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend scalar fallback (no native SIMD)
SIMD int-add (64K x300) java 215ms / native 154ms = 1.3x speedup
SIMD float-mul (64K x300) java 165ms / native 110ms = 1.5x 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 243.000 ms
Base64 CN1 decode 447.000 ms
Base64 native encode 892.000 ms
Base64 encode ratio (CN1/native) 0.272x (72.8% faster)
Base64 native decode 1385.000 ms
Base64 decode ratio (CN1/native) 0.323x (67.7% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog

shai-almog commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 127 screenshots: 127 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 Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 127 screenshots: 127 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 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 125 screenshots: 125 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 71ms / native 4ms = 17.7x speedup
SIMD float-mul (64K x300) java 71ms / native 5ms = 14.2x 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 276.000 ms
Base64 CN1 decode 170.000 ms
Base64 SIMD encode 133.000 ms
Base64 encode ratio (SIMD/CN1) 0.482x (51.8% faster)
Base64 SIMD decode 131.000 ms
Base64 decode ratio (SIMD/CN1) 0.771x (22.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 36.000 ms
Image createMask (SIMD on) 15.000 ms
Image createMask ratio (SIMD on/off) 0.417x (58.3% faster)
Image applyMask (SIMD off) 54.000 ms
Image applyMask (SIMD on) 29.000 ms
Image applyMask ratio (SIMD on/off) 0.537x (46.3% faster)
Image modifyAlpha (SIMD off) 55.000 ms
Image modifyAlpha (SIMD on) 21.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.382x (61.8% faster)
Image modifyAlpha removeColor (SIMD off) 62.000 ms
Image modifyAlpha removeColor (SIMD on) 24.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.387x (61.3% faster)

@shai-almog

shai-almog commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

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

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.

1 participant