From 94f322867a11c565e649a138486b5ec8d042f294 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 24 Oct 2023 14:56:21 +0200 Subject: [PATCH] LibWeb: Get rid of DevicePixels usage in RecordingPainter This change removes inconsistency in coordinate representation of painter commands by changing everything to use int. --- .../LibWeb/Painting/FilterPainting.cpp | 2 +- .../LibWeb/Painting/GradientPainting.cpp | 2 +- .../LibWeb/Painting/RecordingPainter.cpp | 36 +++++++++---------- .../LibWeb/Painting/RecordingPainter.h | 28 +++++++-------- .../LibWeb/Painting/ShadowPainting.cpp | 22 ++++++------ .../LibWeb/Painting/StackingContext.cpp | 6 ++-- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp index 13fb415d1b..ea8a342bbb 100644 --- a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp @@ -103,7 +103,7 @@ void apply_backdrop_filter(PaintContext& context, CSSPixelRect const& backdrop_r auto backdrop_region = context.rounded_device_rect(backdrop_rect); ScopedCornerRadiusClip corner_clipper { context, backdrop_region, border_radii_data }; - context.painter().apply_backdrop_filter(backdrop_region, border_radii_data, backdrop_filter); + context.painter().apply_backdrop_filter(backdrop_region.to_type(), border_radii_data, backdrop_filter); } } diff --git a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp index 06867a0730..5c4ec7afcb 100644 --- a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp @@ -157,7 +157,7 @@ void paint_conic_gradient(PaintContext& context, DevicePixelRect const& gradient void paint_radial_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, RadialGradientData const& data, DevicePixelPoint center, DevicePixelSize size) { - context.painter().fill_rect_with_radial_gradient(gradient_rect.to_type(), data, center, size); + context.painter().fill_rect_with_radial_gradient(gradient_rect.to_type(), data, center.to_type(), size.to_type()); } } diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp index e0f6b56cfc..ccc1983d83 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp @@ -225,7 +225,7 @@ CommandResult PushStackingContext::execute(CommandExecutionState& state) const Gfx::Painter stacking_context_painter(bitmap); - stacking_context_painter.translate(painter_location.to_type() + destination_clipped_fixup.to_type()); + stacking_context_painter.translate(painter_location + destination_clipped_fixup.to_type()); state.stacking_contexts.append(CommandExecutionState::StackingContext { .painter = stacking_context_painter, @@ -260,14 +260,14 @@ CommandResult PopStackingContext::execute(CommandExecutionState& state) const CommandResult PushStackingContextWithMask::execute(CommandExecutionState& state) const { - auto bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, paint_rect.size().to_type()); + auto bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, paint_rect.size()); if (bitmap_or_error.is_error()) return CommandResult::Continue; auto bitmap = bitmap_or_error.release_value(); Gfx::Painter stacking_context_painter(bitmap); - stacking_context_painter.translate(-paint_rect.location().to_type()); + stacking_context_painter.translate(-paint_rect.location()); state.stacking_contexts.append(CommandExecutionState::StackingContext { .painter = stacking_context_painter, @@ -284,7 +284,7 @@ CommandResult PopStackingContextWithMask::execute(CommandExecutionState& state) auto bitmap = stacking_context.painter.target(); if (mask_bitmap) bitmap->apply_mask(*mask_bitmap, mask_kind); - state.painter().blit(paint_rect.location().to_type(), *bitmap, bitmap->rect(), opacity); + state.painter().blit(paint_rect.location(), *bitmap, bitmap->rect(), opacity); return CommandResult::Continue; } @@ -336,11 +336,11 @@ CommandResult PaintInnerBoxShadow::execute(CommandExecutionState& state) const CommandResult PaintTextShadow::execute(CommandExecutionState& state) const { - if (state.would_be_fully_clipped_by_painter(text_rect.to_type())) + if (state.would_be_fully_clipped_by_painter(text_rect)) return CommandResult::Continue; // FIXME: Figure out the maximum bitmap size for all shadows and then allocate it once and reuse it? - auto maybe_shadow_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, bounding_rect.size().to_type()); + auto maybe_shadow_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, bounding_rect.size()); if (maybe_shadow_bitmap.is_error()) { dbgln("Unable to allocate temporary bitmap {} for text-shadow rendering: {}", bounding_rect.size(), maybe_shadow_bitmap.error()); return CommandResult::Continue; @@ -349,15 +349,15 @@ CommandResult PaintTextShadow::execute(CommandExecutionState& state) const Gfx::Painter shadow_painter { *shadow_bitmap }; // FIXME: "Spread" the shadow somehow. - DevicePixelPoint baseline_start(text_rect.x(), text_rect.y() + fragment_baseline); - shadow_painter.draw_text_run(baseline_start.to_type(), Utf8View(text), font, color); + Gfx::IntPoint baseline_start(text_rect.x(), text_rect.y() + fragment_baseline); + shadow_painter.draw_text_run(baseline_start, Utf8View(text), font, color); // Blur Gfx::StackBlurFilter filter(*shadow_bitmap); - filter.process_rgba(blur_radius.value(), color); + filter.process_rgba(blur_radius, color); auto& painter = state.painter(); - painter.blit(draw_location.to_type(), *shadow_bitmap, bounding_rect.to_type()); + painter.blit(draw_location, *shadow_bitmap, bounding_rect); return CommandResult::Continue; } @@ -588,13 +588,13 @@ void RecordingPainter::fill_rect_with_conic_gradient(Gfx::IntRect const& rect, C .position = position }); } -void RecordingPainter::fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, DevicePixelPoint center, DevicePixelSize size) +void RecordingPainter::fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, Gfx::IntPoint center, Gfx::IntSize size) { push_command(PaintRadialGradient { .rect = rect, .radial_gradient_data = data, - .center = center.to_type(), - .size = size.to_type() }); + .center = center, + .size = size }); } void RecordingPainter::draw_rect(Gfx::IntRect const& rect, Color color, bool rough) @@ -753,10 +753,10 @@ void RecordingPainter::paint_frame(Gfx::IntRect rect, Palette palette, Gfx::Fram push_command(PaintFrame { rect, palette, style }); } -void RecordingPainter::apply_backdrop_filter(DevicePixelRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter) +void RecordingPainter::apply_backdrop_filter(Gfx::IntRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter) { push_command(ApplyBackdropFilter { - .backdrop_region = backdrop_region.to_type(), + .backdrop_region = backdrop_region, .border_radii_data = border_radii_data, .backdrop_filter = backdrop_filter, }); @@ -776,7 +776,7 @@ void RecordingPainter::paint_inner_box_shadow_params(PaintOuterBoxShadowParams p }); } -void RecordingPainter::paint_text_shadow(DevicePixels blur_radius, DevicePixelRect bounding_rect, DevicePixelRect text_rect, Utf8View text, Gfx::Font const& font, Color color, DevicePixels fragment_baseline, DevicePixelPoint draw_location) +void RecordingPainter::paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Utf8View text, Gfx::Font const& font, Color color, int fragment_baseline, Gfx::IntPoint draw_location) { push_command(PaintTextShadow { .blur_radius = blur_radius, @@ -815,12 +815,12 @@ void RecordingPainter::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect { bottom_left_radius, bottom_left_radius }); } -void RecordingPainter::push_stacking_context_with_mask(DevicePixelRect paint_rect) +void RecordingPainter::push_stacking_context_with_mask(Gfx::IntRect paint_rect) { push_command(PushStackingContextWithMask { .paint_rect = paint_rect }); } -void RecordingPainter::pop_stacking_context_with_mask(RefPtr mask_bitmap, Gfx::Bitmap::MaskKind mask_kind, DevicePixelRect paint_rect, float opacity) +void RecordingPainter::pop_stacking_context_with_mask(RefPtr mask_bitmap, Gfx::Bitmap::MaskKind mask_kind, Gfx::IntRect paint_rect, float opacity) { push_command(PopStackingContextWithMask { .paint_rect = paint_rect, diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h index 3fe6304000..0d204e6c80 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h @@ -115,7 +115,7 @@ struct PushStackingContext { float opacity; Gfx::FloatRect source_rect; Gfx::FloatRect transformed_destination_rect; - DevicePixelPoint painter_location; + Gfx::IntPoint painter_location; [[nodiscard]] CommandResult execute(CommandExecutionState&) const; }; @@ -128,13 +128,13 @@ struct PopStackingContext { }; struct PushStackingContextWithMask { - DevicePixelRect paint_rect; + Gfx::IntRect paint_rect; [[nodiscard]] CommandResult execute(CommandExecutionState&) const; }; struct PopStackingContextWithMask { - DevicePixelRect paint_rect; + Gfx::IntRect paint_rect; RefPtr mask_bitmap; Gfx::Bitmap::MaskKind mask_kind; float opacity; @@ -162,14 +162,14 @@ struct PaintInnerBoxShadow { }; struct PaintTextShadow { - DevicePixels blur_radius; - DevicePixelRect bounding_rect; - DevicePixelRect text_rect; + int blur_radius; + Gfx::IntRect bounding_rect; + Gfx::IntRect text_rect; String text; NonnullRefPtr font; Color color; - DevicePixels fragment_baseline; - DevicePixelPoint draw_location; + int fragment_baseline; + Gfx::IntPoint draw_location; [[nodiscard]] CommandResult execute(CommandExecutionState&) const; }; @@ -421,7 +421,7 @@ public: void fill_rect_with_linear_gradient(Gfx::IntRect const& gradient_rect, LinearGradientData const& data); void fill_rect_with_conic_gradient(Gfx::IntRect const& rect, ConicGradientData const& data, Gfx::IntPoint const& position); - void fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, DevicePixelPoint center, DevicePixelSize size); + void fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, Gfx::IntPoint center, Gfx::IntSize size); void draw_rect(Gfx::IntRect const& rect, Color color, bool rough = false); @@ -454,7 +454,7 @@ public: float opacity; Gfx::FloatRect source_rect; Gfx::FloatRect transformed_destination_rect; - DevicePixelPoint painter_location; + Gfx::IntPoint painter_location; }; void push_stacking_context(PushStackingContextParams params); @@ -464,8 +464,8 @@ public: }; void pop_stacking_context(PopStackingContextParams params); - void push_stacking_context_with_mask(DevicePixelRect paint_rect); - void pop_stacking_context_with_mask(RefPtr mask_bitmap, Gfx::Bitmap::MaskKind mask_kind, DevicePixelRect paint_rect, float opacity); + void push_stacking_context_with_mask(Gfx::IntRect paint_rect); + void pop_stacking_context_with_mask(RefPtr mask_bitmap, Gfx::Bitmap::MaskKind mask_kind, Gfx::IntRect paint_rect, float opacity); void sample_under_corners(NonnullRefPtr corner_clipper); void blit_corner_clipping(NonnullRefPtr corner_clipper); @@ -473,11 +473,11 @@ public: void paint_progressbar(Gfx::IntRect frame_rect, Gfx::IntRect progress_rect, Palette palette, int min, int max, int value, StringView text); void paint_frame(Gfx::IntRect rect, Palette palette, Gfx::FrameStyle style); - void apply_backdrop_filter(DevicePixelRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter); + void apply_backdrop_filter(Gfx::IntRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter); void paint_outer_box_shadow_params(PaintOuterBoxShadowParams params); void paint_inner_box_shadow_params(PaintOuterBoxShadowParams params); - void paint_text_shadow(DevicePixels blur_radius, DevicePixelRect bounding_rect, DevicePixelRect text_rect, Utf8View text, Gfx::Font const& font, Color color, DevicePixels fragment_baseline, DevicePixelPoint draw_location); + void paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Utf8View text, Gfx::Font const& font, Color color, int fragment_baseline, Gfx::IntPoint draw_location); void fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, Gfx::AntiAliasingPainter::CornerRadius top_left_radius, Gfx::AntiAliasingPainter::CornerRadius top_right_radius, Gfx::AntiAliasingPainter::CornerRadius bottom_right_radius, Gfx::AntiAliasingPainter::CornerRadius bottom_left_radius); void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius); diff --git a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp index 2ebcf9fc94..3d11f8ded7 100644 --- a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp @@ -583,32 +583,32 @@ void paint_text_shadow(PaintContext& context, Layout::LineBoxFragment const& fra if (shadow_layers.is_empty() || fragment.text().is_empty()) return; - auto fragment_width = context.enclosing_device_pixels(fragment.width()); - auto fragment_height = context.enclosing_device_pixels(fragment.height()); - auto draw_rect = context.enclosing_device_rect(fragment.absolute_rect()); + auto fragment_width = context.enclosing_device_pixels(fragment.width()).value(); + auto fragment_height = context.enclosing_device_pixels(fragment.height()).value(); + auto draw_rect = context.enclosing_device_rect(fragment.absolute_rect()).to_type(); auto text = Utf8View(fragment.text()); auto& font = fragment.layout_node().scaled_font(context); - auto fragment_baseline = context.rounded_device_pixels(fragment.baseline()); + auto fragment_baseline = context.rounded_device_pixels(fragment.baseline()).value(); // Note: Box-shadow layers are ordered front-to-back, so we paint them in reverse for (auto& layer : shadow_layers.in_reverse()) { - DevicePixels offset_x = context.rounded_device_pixels(layer.offset_x); - DevicePixels offset_y = context.rounded_device_pixels(layer.offset_y); - DevicePixels blur_radius = context.rounded_device_pixels(layer.blur_radius); + int offset_x = context.rounded_device_pixels(layer.offset_x).value(); + int offset_y = context.rounded_device_pixels(layer.offset_y).value(); + int blur_radius = context.rounded_device_pixels(layer.blur_radius).value(); // Space around the painted text to allow it to blur. // FIXME: Include spread in this once we use that. - DevicePixels margin = blur_radius * 2; - DevicePixelRect text_rect { + int margin = blur_radius * 2; + Gfx::IntRect text_rect { margin, margin, fragment_width, fragment_height }; - DevicePixelRect bounding_rect { + Gfx::IntRect bounding_rect { 0, 0, text_rect.width() + margin + margin, text_rect.height() + margin + margin }; - DevicePixelPoint draw_location { + Gfx::IntPoint draw_location { draw_rect.x() + offset_x - margin, draw_rect.y() + offset_y - margin }; diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index a4d52545a7..166db4f1f6 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -300,12 +300,12 @@ void StackingContext::paint(PaintContext& context) const if (masking_area->is_empty()) return; auto paint_rect = context.enclosing_device_rect(*masking_area); - context.painter().push_stacking_context_with_mask(paint_rect); + context.painter().push_stacking_context_with_mask(paint_rect.to_type()); paint_internal(context); auto mask_bitmap = paintable_box().calculate_mask(context, *masking_area); auto mask_type = paintable_box().get_mask_type(); - context.painter().pop_stacking_context_with_mask(mask_bitmap, *mask_type, paint_rect, opacity); + context.painter().pop_stacking_context_with_mask(mask_bitmap, *mask_type, paint_rect.to_type(), opacity); return; } @@ -324,7 +324,7 @@ void StackingContext::paint(PaintContext& context) const .opacity = opacity, .source_rect = source_rect, .transformed_destination_rect = transformed_destination_rect, - .painter_location = context.rounded_device_point(-paintable_box().absolute_paint_rect().location()) + .painter_location = context.rounded_device_point(-paintable_box().absolute_paint_rect().location()).to_type() }; RecordingPainter::PopStackingContextParams pop_stacking_context_params {