Skip to content

Commit d352c46

Browse files
gmtakalenikaliaksandr
authored andcommitted
LibWeb: Pass sizes instead of rects to to_gfx_scaling_mode()
Position is irrelevant when determining the right scaling mode. No functional changes.
1 parent 3f6cbeb commit d352c46

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ struct TextDecorationThickness {
453453
};
454454

455455
// FIXME: Find a better place for this helper.
456-
inline Gfx::ScalingMode to_gfx_scaling_mode(ImageRendering css_value, Gfx::IntRect source, Gfx::IntRect target)
456+
inline Gfx::ScalingMode to_gfx_scaling_mode(ImageRendering css_value, Gfx::IntSize source, Gfx::IntSize target)
457457
{
458-
if (source.size() == target.size())
458+
if (source == target)
459459
return Gfx::ScalingMode::None;
460460

461461
switch (css_value) {

Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void ImageStyleValue::paint(DisplayListRecordingContext& context, DevicePixelRec
156156
if (!image_data)
157157
return;
158158

159-
auto rect = image_data->frame_rect(m_current_frame_index).value_or(dest_rect.to_type<int>());
160-
auto scaling_mode = to_gfx_scaling_mode(image_rendering, rect, dest_rect.to_type<int>());
161159
auto dest_int_rect = dest_rect.to_type<int>();
160+
auto rect = image_data->frame_rect(m_current_frame_index).value_or(dest_int_rect);
161+
auto scaling_mode = to_gfx_scaling_mode(image_rendering, rect.size(), dest_int_rect.size());
162162
image_data->paint(context, m_current_frame_index, dest_int_rect, dest_int_rect, scaling_mode);
163163
}
164164

Libraries/LibWeb/Painting/BackgroundPainting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void paint_background(DisplayListRecordingContext& context, PaintableBox const&
322322
dest_rect.set_height(1);
323323

324324
auto const* bitmap = static_cast<CSS::ImageStyleValue const&>(image).current_frame_bitmap(dest_rect);
325-
auto scaling_mode = to_gfx_scaling_mode(image_rendering, bitmap->rect(), dest_rect.to_type<int>());
325+
auto scaling_mode = to_gfx_scaling_mode(image_rendering, bitmap->size(), dest_rect.size().to_type<int>());
326326
context.display_list_recorder().draw_repeated_immutable_bitmap(dest_rect.to_type<int>(), clip_rect.to_type<int>(), *bitmap, scaling_mode, repeat_x, repeat_y);
327327
} else {
328328
for_each_image_device_rect([&](auto const& image_device_rect) {

Libraries/LibWeb/Painting/CanvasPaintable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ void CanvasPaintable::paint(DisplayListRecordingContext& context, PaintPhase pha
3636
if (auto surface = canvas_element.surface()) {
3737
// FIXME: Remove this const_cast.
3838
const_cast<HTML::HTMLCanvasElement&>(canvas_element).present();
39-
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), surface->rect(), canvas_rect.to_type<int>());
40-
context.display_list_recorder().draw_painting_surface(canvas_rect.to_type<int>(), *surface, surface->rect(), scaling_mode);
39+
auto canvas_int_rect = canvas_rect.to_type<int>();
40+
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), surface->size(), canvas_int_rect.size());
41+
context.display_list_recorder().draw_painting_surface(canvas_int_rect, *surface, surface->rect(), scaling_mode);
4142
}
4243
}
4344
}

Libraries/LibWeb/Painting/ImagePaintable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void ImagePaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
7777
ScopedCornerRadiusClip corner_clip { context, image_rect_device_pixels, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
7878
auto image_int_rect_device_pixels = image_rect_device_pixels.to_type<int>();
7979
auto bitmap_rect = decoded_image_data->frame_rect(m_image_provider.current_frame_index()).value_or(image_int_rect_device_pixels);
80-
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), bitmap_rect, image_int_rect_device_pixels);
80+
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), bitmap_rect.size(), image_int_rect_device_pixels.size());
8181
auto bitmap_aspect_ratio = (float)bitmap_rect.height() / bitmap_rect.width();
8282
auto image_aspect_ratio = (float)image_rect.height() / (float)image_rect.width();
8383

Libraries/LibWeb/Painting/VideoPaintable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ void VideoPaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
127127
}();
128128

129129
auto paint_frame = [&](auto const& frame) {
130-
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), frame->rect(), video_rect.to_type<int>());
131130
auto dst_rect = video_rect.to_type<int>();
131+
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), frame->rect().size(), dst_rect.size());
132132
context.display_list_recorder().draw_scaled_immutable_bitmap(dst_rect, dst_rect, Gfx::ImmutableBitmap::create(*frame), scaling_mode);
133133
};
134134

Libraries/LibWeb/SVG/SVGFilterElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Optional<Gfx::Filter> SVGFilterElement::gfx_filter(Layout::NodeWithStyle const&
272272
return IterationDecision::Continue;
273273

274274
auto dest_rect = Gfx::enclosing_int_rect(paintable_box->absolute_rect().to_type<float>());
275-
auto scaling_mode = CSS::to_gfx_scaling_mode(paintable_box->computed_values().image_rendering(), *src_rect, dest_rect);
275+
auto scaling_mode = CSS::to_gfx_scaling_mode(paintable_box->computed_values().image_rendering(), src_rect->size(), dest_rect.size());
276276
root_filter = Gfx::Filter::image(*bitmap, *src_rect, dest_rect, scaling_mode);
277277
update_result_map(*image_primitive);
278278
} else if (auto* merge_primitive = as_if<SVGFEMergeElement>(node)) {

0 commit comments

Comments
 (0)