PaintingCommandExecutorGPU.h 6.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <LibAccelGfx/Painter.h>
  9. #include <LibWeb/Painting/RecordingPainter.h>
  10. namespace Web::Painting {
  11. class PaintingCommandExecutorGPU : public PaintingCommandExecutor {
  12. public:
  13. CommandResult draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const&) override;
  14. 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;
  15. CommandResult fill_rect(Gfx::IntRect const& rect, Color const&) override;
  16. CommandResult draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) override;
  17. CommandResult draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const&, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) override;
  18. CommandResult set_clip_rect(Gfx::IntRect const& rect) override;
  19. CommandResult clear_clip_rect() override;
  20. CommandResult set_font(Gfx::Font const&) override;
  21. CommandResult push_stacking_context(float opacity, bool, Gfx::IntRect const& source_paintable_rect, Gfx::IntPoint post_transform_translation, CSS::ImageRendering image_rendering, StackingContextTransform transform, Optional<StackingContextMask> mask) override;
  22. CommandResult pop_stacking_context() override;
  23. CommandResult paint_linear_gradient(Gfx::IntRect const&, Web::Painting::LinearGradientData const&) override;
  24. CommandResult paint_outer_box_shadow(PaintOuterBoxShadowParams const&) override;
  25. CommandResult paint_inner_box_shadow(PaintOuterBoxShadowParams const&) override;
  26. CommandResult paint_text_shadow(int blur_radius, Gfx::IntRect const& shadow_bounding_rect, Gfx::IntRect const& text_rect, String const& text, Gfx::Font const&, Color const&, int fragment_baseline, Gfx::IntPoint const& draw_location) override;
  27. 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, Optional<Gfx::FloatPoint> const& aa_translation) override;
  28. CommandResult fill_path_using_color(Gfx::Path const&, Color const&, Gfx::Painter::WindingRule winding_rule, Optional<Gfx::FloatPoint> const& aa_translation) override;
  29. CommandResult fill_path_using_paint_style(Gfx::Path const&, Gfx::PaintStyle const& paint_style, Gfx::Painter::WindingRule winding_rule, float opacity, Optional<Gfx::FloatPoint> const& aa_translation) override;
  30. CommandResult stroke_path_using_color(Gfx::Path const&, Color const& color, float thickness, Optional<Gfx::FloatPoint> const& aa_translation) override;
  31. CommandResult stroke_path_using_paint_style(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, float thickness, float opacity, Optional<Gfx::FloatPoint> const& aa_translation) override;
  32. CommandResult draw_ellipse(Gfx::IntRect const& rect, Color const& color, int thickness) override;
  33. CommandResult fill_ellipse(Gfx::IntRect const& rect, Color const& color, Gfx::AntiAliasingPainter::BlendMode blend_mode) override;
  34. CommandResult draw_line(Color const&, Gfx::IntPoint const& from, Gfx::IntPoint const& to, int thickness, Gfx::Painter::LineStyle style, Color const& alternate_color) override;
  35. CommandResult draw_signed_distance_field(Gfx::IntRect const& rect, Color const&, Gfx::GrayscaleBitmap const& sdf, float smoothing) override;
  36. CommandResult paint_progressbar(Gfx::IntRect const& frame_rect, Gfx::IntRect const& progress_rect, Palette const& palette, int min, int max, int value, StringView const& text) override;
  37. CommandResult paint_frame(Gfx::IntRect const& rect, Palette const&, Gfx::FrameStyle) override;
  38. CommandResult apply_backdrop_filter(Gfx::IntRect const& backdrop_region, Web::CSS::ResolvedBackdropFilter const& backdrop_filter) override;
  39. CommandResult draw_rect(Gfx::IntRect const& rect, Color const&, bool rough) override;
  40. CommandResult paint_radial_gradient(Gfx::IntRect const& rect, Web::Painting::RadialGradientData const& radial_gradient_data, Gfx::IntPoint const& center, Gfx::IntSize const& size) override;
  41. CommandResult paint_conic_gradient(Gfx::IntRect const& rect, Web::Painting::ConicGradientData const& conic_gradient_data, Gfx::IntPoint const& position) override;
  42. CommandResult draw_triangle_wave(Gfx::IntPoint const& p1, Gfx::IntPoint const& p2, Color const&, int amplitude, int thickness) override;
  43. CommandResult sample_under_corners(BorderRadiusCornerClipper&) override;
  44. CommandResult blit_corner_clipping(BorderRadiusCornerClipper&) override;
  45. CommandResult paint_borders(DevicePixelRect const& border_rect, CornerRadii const& corner_radii, BordersDataDevicePixels const& borders_data) override;
  46. bool would_be_fully_clipped_by_painter(Gfx::IntRect) const override;
  47. virtual bool needs_prepare_glyphs_texture() const override { return true; }
  48. void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override;
  49. bool needs_update_immutable_bitmap_texture_cache() const override { return true; }
  50. void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) override;
  51. PaintingCommandExecutorGPU(Gfx::Bitmap& bitmap);
  52. ~PaintingCommandExecutorGPU() override;
  53. private:
  54. Gfx::Bitmap& m_target_bitmap;
  55. struct StackingContext {
  56. RefPtr<AccelGfx::Canvas> canvas;
  57. MaybeOwned<AccelGfx::Painter> painter;
  58. float opacity;
  59. Gfx::IntRect destination;
  60. Gfx::AffineTransform transform;
  61. int stacking_context_depth { 0 };
  62. };
  63. [[nodiscard]] AccelGfx::Painter const& painter() const { return *m_stacking_contexts.last().painter; }
  64. [[nodiscard]] AccelGfx::Painter& painter() { return *m_stacking_contexts.last().painter; }
  65. Vector<StackingContext> m_stacking_contexts;
  66. };
  67. }