Skip to main content

sanitize_scale

Function sanitize_scale 

Source
pub fn sanitize_scale(raw: f32) -> f64
Expand description

Sanitize a raw density (e.g. a JNI jfloat) into a scale safe to divide or multiply by: finite and strictly positive, else the 1.0 fallback.

The platform-supplied density is untrusted input (the surface state machine assumes a well-behaved platform, but density arrives through a separate, unchecked scalar argument); a bogus value here must never propagate into a NaN/infinite or zero-divide layout or paint transform.

A shell’s per-frame driver must call this exactly once per frame and reuse the identical result for both layout (via logical_size) and the paint transform, so the two passes can never disagree on scale.