浏览代码

LibWeb: Snap transformed stacking contexts to pixel grid

Make sure that we're painting them at an integer pixel position, to
avoid smearing.
Andreas Kling 3 年之前
父节点
当前提交
a6e1b9eed2
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      Userland/Libraries/LibWeb/Painting/StackingContext.cpp

+ 6 - 1
Userland/Libraries/LibWeb/Painting/StackingContext.cpp

@@ -295,7 +295,12 @@ void StackingContext::paint(PaintContext& context) const
 
         auto transformed_destination_rect = affine_transform.map(source_rect).translated(transform_origin);
         source_rect.translate_by(transform_origin);
-        context.painter().draw_scaled_bitmap(transformed_destination_rect.to_rounded<int>(), *bitmap, source_rect, opacity, Gfx::Painter::ScalingMode::BilinearBlend);
+
+        // NOTE: If the destination and source rects are the same size, we round the source rect to ensure that it's pixel-aligned.
+        if (transformed_destination_rect.size() == source_rect.size())
+            context.painter().draw_scaled_bitmap(transformed_destination_rect.to_rounded<int>(), *bitmap, source_rect.to_rounded<int>(), opacity);
+        else
+            context.painter().draw_scaled_bitmap(transformed_destination_rect.to_rounded<int>(), *bitmap, source_rect, opacity, Gfx::Painter::ScalingMode::BilinearBlend);
     } else {
         paint_internal(context);
     }