From 9823c7996e02131cf767eb392be3aa09403dd7ac Mon Sep 17 00:00:00 2001 From: rainboy93 Date: Thu, 3 Sep 2026 09:15:21 +0700 Subject: [PATCH] fix(android): correct cover-fill scaling in SinkSurface vertices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FillMode::PreserveAspectRatioAndFill computed scaled_width from view_width_ / inset_framebuffer_height and scaled_height from view_height_ / inset_framebuffer_width — each axis divided by the other axis's extent, which is not a scale factor. On a portrait preview the content rendered pillarboxed (e.g. ~608px inside a 1080px view) instead of filling and cropping. Compute a single uniform cover factor and apply it on both axes. --- src/sink/sink_surface.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sink/sink_surface.cc b/src/sink/sink_surface.cc index 36b07c24..2560f141 100644 --- a/src/sink/sink_surface.cc +++ b/src/sink/sink_surface.cc @@ -382,9 +382,17 @@ void SinkSurface::UpdateDisplayVertices() { scaled_width = inset_framebuffer_width / view_width_; scaled_height = inset_framebuffer_height / view_height_; } else if (fill_mode_ == FillMode::PreserveAspectRatioAndFill) { - // Preserve aspect ratio and scale to fill, may crop - scaled_width = view_width_ / inset_framebuffer_height; - scaled_height = view_height_ / inset_framebuffer_width; + // Preserve aspect ratio and scale to fill, may crop. + // + // The inscribed fit above touches the view on one axis and falls short on + // the other; cover-fill scales it up uniformly until it spans both, letting + // the long axis overflow (i.e. crop). Dividing by view_* converts back to + // the normalised device coordinates the vertices below are expressed in. + float cover_w = view_width_ / inset_framebuffer_width; + float cover_h = view_height_ / inset_framebuffer_height; + float cover = cover_w > cover_h ? cover_w : cover_h; + scaled_width = inset_framebuffer_width * cover / view_width_; + scaled_height = inset_framebuffer_height * cover / view_height_; } // In Stretch mode, scaled_width and scaled_height remain 1.0