Architectural Invariant Design: Direct Skia Native Surface Render Pipeline for Variable Refresh Rate Displays
Direct Skia Native Surface Render Pipeline for Variable Refresh Rate Displays defines an industrial-grade behavioral standard for mobile engineering. Enforces direct unbuffered drawing through Skia native surfaces (SurfaceControl/ANativeWindow on Android and CAMetalLayer on iOS) in Kotlin Multiplatform Compose. Bypasses intermediate OS compositors and view hierarchy overlays to eliminate tearing, phase-shift jitter, and dropped frames on 120Hz+ ProMotion and Dynamic AMOLED displays. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
Hazard Analysis: What Breaks Without This Rule
The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:
| Failure Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Route-through-View Compositor Bridging and Unsynchronized Skia Flush Deadlocks | Critical | Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production. Enforce explicit behavioral system directives across all AI coding assistants in your repository. |
| Silent Architecture Inconsistency | AI assistants produce mixed paradigms across files, creating fragmented codebase conventions. | Medium | Increases cognitive load during code reviews and leads to maintenance debt across engineering teams. Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS bind Skia GrDirectContext flushes directly to native display clock tickers
Engineers MUST ALWAYS bind Skia GrDirectContext flushes directly to native display clock tickers: Choreographer.postFrameCallback on Android and CADisplayLink with preferredFrameRateRange (min=60, pref=120, max=120) on iOS.
Engineers MUST NOT invoke GrDirectContext.flushAndSubmit() synchronously inside the main UI dispatch thread
Engineers MUST NOT invoke GrDirectContext.flushAndSubmit() synchronously inside the main UI dispatch thread; canvas execution and command buffer submission MUST happen asynchronously or on dedicated render threads targeting the NativeSurface.
Engineers MUST configure Android surfaces via SurfaceHolder.Callback2 with SurfaceHolder.setFormat(PixelFormat.RGBA_8888) and explicitly set surfaceFrameRate using Surface.setFrameRate(120.0f, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT).
Engineers MUST configure Android surfaces via SurfaceHolder.Callback2 with SurfaceHolder.setFormat(PixelFormat.RGBA_8888) and explicitly set surfaceFrameRate using Surface.setFrameRate(120.0f, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT).
Engineers MUST configure iOS CAMetalLayer with framebufferOnly = true, allowsNextDrawableTimeout = false, and presentsWithTransaction = false to prevent GPU backpressure stall when locking frame pacing.
Engineers MUST configure iOS CAMetalLayer with framebufferOnly = true, allowsNextDrawableTimeout = false, and presentsWithTransaction = false to prevent GPU backpressure stall when locking frame pacing.
Components NEVER bridge Skia Bitmaps through platform UI widgets (e.g., android.widget.ImageView or iOS UIImage / UIImageView) within the render loop
Components NEVER bridge Skia Bitmaps through platform UI widgets (e.g., android.widget.ImageView or iOS UIImage / UIImageView) within the render loop; drawing MUST target SkSurface directly via Metal/Vulkan hardware handles.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Direct Skia Native Surface Render Pipeline for Variable Refresh Rate Displays critical for AI coding assistants?
Enforces direct unbuffered drawing through Skia native surfaces (SurfaceControl/ANativeWindow on Android and CAMetalLayer on iOS) in Kotlin Multiplatform Compose. Bypasses intermediate OS compositors and view hierarchy overlays to eliminate tearing, phase-shift jitter, and dropped frames on 120Hz+ ProMotion and Dynamic AMOLED displays. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.
Q:How does adopting this rule prevent AI hallucinations?
This rule explicitly declares what the AI must avoid (Route-through-View Compositor Bridging and Unsynchronized Skia Flush Deadlocks) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.
Q:Which AI coding environments are supported?
This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).
Q:Can I combine this rule with other technology stacks?
Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.