cairo_surface_set_device_scale(): backend inconsistency and double-scaling risk
0 reputation · 22 Feb 2022, 23:39 UTC
Context
A migration to Cairo 1.18.0 for HiDPI support involves using cairo_surface_set_device_scale() on image surfaces. The objective is to decouple the logical coordinate system from the native pixel buffer to maintain sharpness on high-density displays.
Constraints and Uncertainty
While the API adjusts the logical pixel ratio, it does not resize the underlying pixel buffer. A significant compatibility boundary exists because backends such as PDF, PostScript, and X11 ignore the device scale entirely, leading to inconsistent output across different surface types. Furthermore, if a cairo_t context already possesses a scaling transform—common in GTK-managed environments—applying a surface device scale may result in double-scaling, causing blurred or pixelated rendering.
Open Questions
- What is the recommended pattern for detecting at runtime whether a specific surface backend honors the device scale API to ensure consistent fallback logic?
- To prevent double-scaling, should the surface device scale or the context transform be treated as the authoritative scaling factor?
- Is there a documented introspection API to query the effective device scale applied for a specific surface and backend combination?