CommandExecutorCPU.h 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/MaybeOwned.h>
  8. #include <LibWeb/Painting/RecordingPainter.h>
  9. namespace Web::Painting {
  10. class CommandExecutorCPU : public CommandExecutor {
  11. public:
  12. CommandResult draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const&) override;
  13. CommandResult draw_text(Gfx::IntRect const& rect, String const& raw_text, Gfx::TextAlignment alignment, Color const&, Gfx::TextElision, Gfx::TextWrapping, Optional<NonnullRefPtr<Gfx::Font>> const&) override;
  14. CommandResult fill_rect(Gfx::IntRect const& rect, Color const&) override;
  15. CommandResult draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) override;
  16. CommandResult draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const&, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) override;
  17. CommandResult set_clip_rect(Gfx::IntRect const& rect) override;
  18. CommandResult clear_clip_rect() override;
  19. CommandResult push_stacking_context(float opacity, bool is_fixed_position, Gfx::IntRect const& source_paintable_rect, Gfx::IntPoint post_transform_translation, CSS::ImageRendering image_rendering, StackingContextTransform transform, Optional<StackingContextMask> mask) override;
  20. CommandResult pop_stacking_context() override;
  21. CommandResult paint_linear_gradient(Gfx::IntRect const&, Web::Painting::LinearGradientData const&) override;
  22. CommandResult paint_outer_box_shadow(PaintOuterBoxShadowParams const&) override;
  23. CommandResult paint_inner_box_shadow(PaintOuterBoxShadowParams const&) override;
  24. CommandResult paint_text_shadow(int blur_radius, Gfx::IntRect const& shadow_bounding_rect, Gfx::IntRect const& text_rect, Span<Gfx::DrawGlyphOrEmoji const>, Color const&, int fragment_baseline, Gfx::IntPoint const& draw_location) override;
  25. CommandResult fill_rect_with_rounded_corners(Gfx::IntRect const&, Color const&, Gfx::AntiAliasingPainter::CornerRadius const& top_left_radius, Gfx::AntiAliasingPainter::CornerRadius const& top_right_radius, Gfx::AntiAliasingPainter::CornerRadius const& bottom_left_radius, Gfx::AntiAliasingPainter::CornerRadius const& bottom_right_radius) override;
  26. CommandResult fill_path_using_color(Gfx::Path const&, Color const&, Gfx::Painter::WindingRule winding_rule, Gfx::FloatPoint const& aa_translation) override;
  27. CommandResult fill_path_using_paint_style(Gfx::Path const&, Gfx::PaintStyle const& paint_style, Gfx::Painter::WindingRule winding_rule, float opacity, Gfx::FloatPoint const& aa_translation) override;
  28. CommandResult stroke_path_using_color(Gfx::Path const&, Color const& color, float thickness, Gfx::FloatPoint const& aa_translation) override;
  29. CommandResult stroke_path_using_paint_style(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, float thickness, float opacity, Gfx::FloatPoint const& aa_translation) override;
  30. CommandResult draw_ellipse(Gfx::IntRect const& rect, Color const& color, int thickness) override;
  31. CommandResult fill_ellipse(Gfx::IntRect const& rect, Color const& color, Gfx::AntiAliasingPainter::BlendMode blend_mode) override;
  32. CommandResult draw_line(Color const&, Gfx::IntPoint const& from, Gfx::IntPoint const& to, int thickness, Gfx::Painter::LineStyle style, Color const& alternate_color) override;
  33. CommandResult draw_signed_distance_field(Gfx::IntRect const& rect, Color const&, Gfx::GrayscaleBitmap const& sdf, float smoothing) override;
  34. CommandResult paint_frame(Gfx::IntRect const& rect, Palette const&, Gfx::FrameStyle) override;
  35. CommandResult apply_backdrop_filter(Gfx::IntRect const& backdrop_region, Web::CSS::ResolvedBackdropFilter const& backdrop_filter) override;
  36. CommandResult draw_rect(Gfx::IntRect const& rect, Color const&, bool rough) override;
  37. CommandResult paint_radial_gradient(Gfx::IntRect const& rect, Web::Painting::RadialGradientData const& radial_gradient_data, Gfx::IntPoint const& center, Gfx::IntSize const& size) override;
  38. CommandResult paint_conic_gradient(Gfx::IntRect const& rect, Web::Painting::ConicGradientData const& conic_gradient_data, Gfx::IntPoint const& position) override;
  39. CommandResult draw_triangle_wave(Gfx::IntPoint const& p1, Gfx::IntPoint const& p2, Color const&, int amplitude, int thickness) override;
  40. CommandResult sample_under_corners(u32 id, CornerRadii const&, Gfx::IntRect const&, CornerClip) override;
  41. CommandResult blit_corner_clipping(u32 id) override;
  42. CommandResult paint_borders(DevicePixelRect const& border_rect, CornerRadii const& corner_radii, BordersDataDevicePixels const& borders_data) override;
  43. bool would_be_fully_clipped_by_painter(Gfx::IntRect) const override;
  44. bool needs_prepare_glyphs_texture() const override { return false; }
  45. void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override {};
  46. bool needs_update_immutable_bitmap_texture_cache() const override { return false; }
  47. void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) override {};
  48. CommandExecutorCPU(Gfx::Bitmap& bitmap);
  49. private:
  50. Gfx::Bitmap& m_target_bitmap;
  51. Vector<RefPtr<BorderRadiusCornerClipper>> m_corner_clippers;
  52. struct StackingContext {
  53. MaybeOwned<Gfx::Painter> painter;
  54. float opacity;
  55. Gfx::IntRect destination;
  56. Gfx::Painter::ScalingMode scaling_mode;
  57. Optional<StackingContextMask> mask = {};
  58. };
  59. [[nodiscard]] Gfx::Painter const& painter() const { return *stacking_contexts.last().painter; }
  60. [[nodiscard]] Gfx::Painter& painter() { return *stacking_contexts.last().painter; }
  61. Vector<StackingContext> stacking_contexts;
  62. };
  63. }