RecordingPainter.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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/Forward.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/SegmentedVector.h>
  10. #include <AK/Utf8View.h>
  11. #include <AK/Vector.h>
  12. #include <LibGfx/AntiAliasingPainter.h>
  13. #include <LibGfx/Color.h>
  14. #include <LibGfx/Forward.h>
  15. #include <LibGfx/Gradients.h>
  16. #include <LibGfx/GrayscaleBitmap.h>
  17. #include <LibGfx/ImmutableBitmap.h>
  18. #include <LibGfx/PaintStyle.h>
  19. #include <LibGfx/Painter.h>
  20. #include <LibGfx/Palette.h>
  21. #include <LibGfx/Point.h>
  22. #include <LibGfx/Rect.h>
  23. #include <LibGfx/Size.h>
  24. #include <LibGfx/StylePainter.h>
  25. #include <LibGfx/TextAlignment.h>
  26. #include <LibGfx/TextDirection.h>
  27. #include <LibGfx/TextElision.h>
  28. #include <LibGfx/TextLayout.h>
  29. #include <LibGfx/TextWrapping.h>
  30. #include <LibWeb/CSS/Enums.h>
  31. #include <LibWeb/Painting/BorderRadiiData.h>
  32. #include <LibWeb/Painting/BorderRadiusCornerClipper.h>
  33. #include <LibWeb/Painting/GradientData.h>
  34. #include <LibWeb/Painting/PaintOuterBoxShadowParams.h>
  35. namespace Web::Painting {
  36. enum class CommandResult {
  37. Continue,
  38. SkipStackingContext,
  39. };
  40. struct DrawGlyphRun {
  41. Vector<Gfx::DrawGlyphOrEmoji> glyph_run;
  42. Color color;
  43. Gfx::IntRect rect;
  44. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  45. void translate_by(Gfx::IntPoint const& offset);
  46. };
  47. struct DrawText {
  48. Gfx::IntRect rect;
  49. String raw_text;
  50. Gfx::TextAlignment alignment;
  51. Color color;
  52. Gfx::TextElision elision;
  53. Gfx::TextWrapping wrapping;
  54. Optional<NonnullRefPtr<Gfx::Font>> font {};
  55. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  56. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  57. };
  58. struct FillRect {
  59. Gfx::IntRect rect;
  60. Color color;
  61. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  62. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  63. };
  64. struct DrawScaledBitmap {
  65. Gfx::IntRect dst_rect;
  66. NonnullRefPtr<Gfx::Bitmap> bitmap;
  67. Gfx::IntRect src_rect;
  68. Gfx::Painter::ScalingMode scaling_mode;
  69. [[nodiscard]] Gfx::IntRect bounding_rect() const { return dst_rect; }
  70. void translate_by(Gfx::IntPoint const& offset) { dst_rect.translate_by(offset); }
  71. };
  72. struct DrawScaledImmutableBitmap {
  73. Gfx::IntRect dst_rect;
  74. NonnullRefPtr<Gfx::ImmutableBitmap> bitmap;
  75. Gfx::IntRect src_rect;
  76. Gfx::Painter::ScalingMode scaling_mode;
  77. [[nodiscard]] Gfx::IntRect bounding_rect() const { return dst_rect; }
  78. void translate_by(Gfx::IntPoint const& offset) { dst_rect.translate_by(offset); }
  79. };
  80. struct SetClipRect {
  81. Gfx::IntRect rect;
  82. };
  83. struct ClearClipRect { };
  84. struct StackingContextTransform {
  85. Gfx::FloatPoint origin;
  86. Gfx::FloatMatrix4x4 matrix;
  87. };
  88. struct StackingContextMask {
  89. NonnullRefPtr<Gfx::Bitmap> mask_bitmap;
  90. Gfx::Bitmap::MaskKind mask_kind;
  91. };
  92. struct PushStackingContext {
  93. float opacity;
  94. bool is_fixed_position;
  95. // The bounding box of the source paintable (pre-transform).
  96. Gfx::IntRect source_paintable_rect;
  97. // A translation to be applied after the stacking context has been transformed.
  98. Gfx::IntPoint post_transform_translation;
  99. CSS::ImageRendering image_rendering;
  100. StackingContextTransform transform;
  101. Optional<StackingContextMask> mask = {};
  102. void translate_by(Gfx::IntPoint const& offset)
  103. {
  104. source_paintable_rect.translate_by(offset);
  105. }
  106. };
  107. struct PopStackingContext { };
  108. struct PaintLinearGradient {
  109. Gfx::IntRect gradient_rect;
  110. LinearGradientData linear_gradient_data;
  111. [[nodiscard]] Gfx::IntRect bounding_rect() const { return gradient_rect; }
  112. void translate_by(Gfx::IntPoint const& offset)
  113. {
  114. gradient_rect.translate_by(offset);
  115. }
  116. };
  117. struct PaintOuterBoxShadow {
  118. PaintOuterBoxShadowParams outer_box_shadow_params;
  119. [[nodiscard]] Gfx::IntRect bounding_rect() const;
  120. void translate_by(Gfx::IntPoint const& offset);
  121. };
  122. struct PaintInnerBoxShadow {
  123. PaintOuterBoxShadowParams outer_box_shadow_params;
  124. void translate_by(Gfx::IntPoint const& offset);
  125. };
  126. struct PaintTextShadow {
  127. int blur_radius;
  128. Gfx::IntRect shadow_bounding_rect;
  129. Gfx::IntRect text_rect;
  130. Vector<Gfx::DrawGlyphOrEmoji> glyph_run;
  131. Color color;
  132. int fragment_baseline;
  133. Gfx::IntPoint draw_location;
  134. [[nodiscard]] Gfx::IntRect bounding_rect() const { return { draw_location, shadow_bounding_rect.size() }; }
  135. void translate_by(Gfx::IntPoint const& offset) { draw_location.translate_by(offset); }
  136. };
  137. struct FillRectWithRoundedCorners {
  138. Gfx::IntRect rect;
  139. Color color;
  140. Gfx::AntiAliasingPainter::CornerRadius top_left_radius;
  141. Gfx::AntiAliasingPainter::CornerRadius top_right_radius;
  142. Gfx::AntiAliasingPainter::CornerRadius bottom_left_radius;
  143. Gfx::AntiAliasingPainter::CornerRadius bottom_right_radius;
  144. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  145. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  146. };
  147. struct FillPathUsingColor {
  148. Gfx::IntRect path_bounding_rect;
  149. Gfx::Path path;
  150. Color color;
  151. Gfx::Painter::WindingRule winding_rule;
  152. Gfx::FloatPoint aa_translation;
  153. [[nodiscard]] Gfx::IntRect bounding_rect() const { return path_bounding_rect; }
  154. void translate_by(Gfx::IntPoint const& offset)
  155. {
  156. path_bounding_rect.translate_by(offset);
  157. aa_translation.translate_by(offset.to_type<float>());
  158. }
  159. };
  160. struct FillPathUsingPaintStyle {
  161. Gfx::IntRect path_bounding_rect;
  162. Gfx::Path path;
  163. NonnullRefPtr<Gfx::PaintStyle> paint_style;
  164. Gfx::Painter::WindingRule winding_rule;
  165. float opacity;
  166. Gfx::FloatPoint aa_translation;
  167. [[nodiscard]] Gfx::IntRect bounding_rect() const { return path_bounding_rect; }
  168. void translate_by(Gfx::IntPoint const& offset)
  169. {
  170. path_bounding_rect.translate_by(offset);
  171. aa_translation.translate_by(offset.to_type<float>());
  172. }
  173. };
  174. struct StrokePathUsingColor {
  175. Gfx::IntRect path_bounding_rect;
  176. Gfx::Path path;
  177. Color color;
  178. float thickness;
  179. Gfx::FloatPoint aa_translation;
  180. [[nodiscard]] Gfx::IntRect bounding_rect() const { return path_bounding_rect; }
  181. void translate_by(Gfx::IntPoint const& offset)
  182. {
  183. path_bounding_rect.translate_by(offset);
  184. aa_translation.translate_by(offset.to_type<float>());
  185. }
  186. };
  187. struct StrokePathUsingPaintStyle {
  188. Gfx::IntRect path_bounding_rect;
  189. Gfx::Path path;
  190. NonnullRefPtr<Gfx::PaintStyle> paint_style;
  191. float thickness;
  192. float opacity = 1.0f;
  193. Gfx::FloatPoint aa_translation;
  194. [[nodiscard]] Gfx::IntRect bounding_rect() const { return path_bounding_rect; }
  195. void translate_by(Gfx::IntPoint const& offset)
  196. {
  197. path_bounding_rect.translate_by(offset);
  198. aa_translation.translate_by(offset.to_type<float>());
  199. }
  200. };
  201. struct DrawEllipse {
  202. Gfx::IntRect rect;
  203. Color color;
  204. int thickness;
  205. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  206. void translate_by(Gfx::IntPoint const& offset)
  207. {
  208. rect.translate_by(offset);
  209. }
  210. };
  211. struct FillEllipse {
  212. Gfx::IntRect rect;
  213. Color color;
  214. Gfx::AntiAliasingPainter::BlendMode blend_mode;
  215. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  216. void translate_by(Gfx::IntPoint const& offset)
  217. {
  218. rect.translate_by(offset);
  219. }
  220. };
  221. struct DrawLine {
  222. Color color;
  223. Gfx::IntPoint from;
  224. Gfx::IntPoint to;
  225. int thickness;
  226. Gfx::Painter::LineStyle style;
  227. Color alternate_color;
  228. void translate_by(Gfx::IntPoint const& offset)
  229. {
  230. from.translate_by(offset);
  231. to.translate_by(offset);
  232. }
  233. };
  234. struct DrawSignedDistanceField {
  235. Gfx::IntRect rect;
  236. Color color;
  237. Gfx::GrayscaleBitmap sdf;
  238. float smoothing;
  239. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  240. void translate_by(Gfx::IntPoint const& offset)
  241. {
  242. rect.translate_by(offset);
  243. }
  244. };
  245. struct PaintFrame {
  246. Gfx::IntRect rect;
  247. Palette palette;
  248. Gfx::FrameStyle style;
  249. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  250. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  251. };
  252. struct ApplyBackdropFilter {
  253. Gfx::IntRect backdrop_region;
  254. BorderRadiiData border_radii_data;
  255. CSS::ResolvedBackdropFilter backdrop_filter;
  256. [[nodiscard]] Gfx::IntRect bounding_rect() const { return backdrop_region; }
  257. void translate_by(Gfx::IntPoint const& offset)
  258. {
  259. backdrop_region.translate_by(offset);
  260. }
  261. };
  262. struct DrawRect {
  263. Gfx::IntRect rect;
  264. Color color;
  265. bool rough;
  266. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  267. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  268. };
  269. struct PaintRadialGradient {
  270. Gfx::IntRect rect;
  271. RadialGradientData radial_gradient_data;
  272. Gfx::IntPoint center;
  273. Gfx::IntSize size;
  274. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  275. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  276. };
  277. struct PaintConicGradient {
  278. Gfx::IntRect rect;
  279. ConicGradientData conic_gradient_data;
  280. Gfx::IntPoint position;
  281. [[nodiscard]] Gfx::IntRect bounding_rect() const { return rect; }
  282. void translate_by(Gfx::IntPoint const& offset) { rect.translate_by(offset); }
  283. };
  284. struct DrawTriangleWave {
  285. Gfx::IntPoint p1;
  286. Gfx::IntPoint p2;
  287. Color color;
  288. int amplitude;
  289. int thickness;
  290. void translate_by(Gfx::IntPoint const& offset)
  291. {
  292. p1.translate_by(offset);
  293. p2.translate_by(offset);
  294. }
  295. };
  296. struct SampleUnderCorners {
  297. u32 id;
  298. CornerRadii corner_radii;
  299. Gfx::IntRect border_rect;
  300. CornerClip corner_clip;
  301. [[nodiscard]] Gfx::IntRect bounding_rect() const;
  302. void translate_by(Gfx::IntPoint const& offset)
  303. {
  304. border_rect.translate_by(offset);
  305. }
  306. };
  307. struct BlitCornerClipping {
  308. u32 id;
  309. Gfx::IntRect border_rect;
  310. [[nodiscard]] Gfx::IntRect bounding_rect() const;
  311. void translate_by(Gfx::IntPoint const& offset)
  312. {
  313. border_rect.translate_by(offset);
  314. }
  315. };
  316. struct PaintBorders {
  317. DevicePixelRect border_rect;
  318. CornerRadii corner_radii;
  319. BordersDataDevicePixels borders_data;
  320. [[nodiscard]] Gfx::IntRect bounding_rect() const { return border_rect.to_type<int>(); }
  321. void translate_by(Gfx::IntPoint const& offset)
  322. {
  323. border_rect.translate_by(offset.to_type<DevicePixels>());
  324. }
  325. };
  326. using PaintingCommand = Variant<
  327. DrawGlyphRun,
  328. DrawText,
  329. FillRect,
  330. DrawScaledBitmap,
  331. DrawScaledImmutableBitmap,
  332. SetClipRect,
  333. ClearClipRect,
  334. PushStackingContext,
  335. PopStackingContext,
  336. PaintLinearGradient,
  337. PaintRadialGradient,
  338. PaintConicGradient,
  339. PaintOuterBoxShadow,
  340. PaintInnerBoxShadow,
  341. PaintTextShadow,
  342. FillRectWithRoundedCorners,
  343. FillPathUsingColor,
  344. FillPathUsingPaintStyle,
  345. StrokePathUsingColor,
  346. StrokePathUsingPaintStyle,
  347. DrawEllipse,
  348. FillEllipse,
  349. DrawLine,
  350. DrawSignedDistanceField,
  351. PaintFrame,
  352. ApplyBackdropFilter,
  353. DrawRect,
  354. DrawTriangleWave,
  355. SampleUnderCorners,
  356. BlitCornerClipping,
  357. PaintBorders>;
  358. class PaintingCommandExecutor {
  359. public:
  360. virtual ~PaintingCommandExecutor() = default;
  361. virtual CommandResult draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const&) = 0;
  362. virtual CommandResult draw_text(Gfx::IntRect const&, String const&, Gfx::TextAlignment alignment, Color const&, Gfx::TextElision, Gfx::TextWrapping, Optional<NonnullRefPtr<Gfx::Font>> const&) = 0;
  363. virtual CommandResult fill_rect(Gfx::IntRect const&, Color const&) = 0;
  364. virtual CommandResult draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) = 0;
  365. virtual CommandResult draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const&, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode) = 0;
  366. virtual CommandResult set_clip_rect(Gfx::IntRect const& rect) = 0;
  367. virtual CommandResult clear_clip_rect() = 0;
  368. virtual 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) = 0;
  369. virtual CommandResult pop_stacking_context() = 0;
  370. virtual CommandResult paint_linear_gradient(Gfx::IntRect const&, LinearGradientData const&) = 0;
  371. virtual CommandResult paint_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const&, Gfx::IntPoint const& center, Gfx::IntSize const& size) = 0;
  372. virtual CommandResult paint_conic_gradient(Gfx::IntRect const& rect, ConicGradientData const&, Gfx::IntPoint const& position) = 0;
  373. virtual CommandResult paint_outer_box_shadow(PaintOuterBoxShadowParams const&) = 0;
  374. virtual CommandResult paint_inner_box_shadow(PaintOuterBoxShadowParams const&) = 0;
  375. virtual 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) = 0;
  376. virtual CommandResult fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color const& color, 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) = 0;
  377. virtual CommandResult fill_path_using_color(Gfx::Path const&, Color const& color, Gfx::Painter::WindingRule, Gfx::FloatPoint const& aa_translation) = 0;
  378. virtual 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) = 0;
  379. virtual CommandResult stroke_path_using_color(Gfx::Path const&, Color const& color, float thickness, Gfx::FloatPoint const& aa_translation) = 0;
  380. virtual CommandResult stroke_path_using_paint_style(Gfx::Path const&, Gfx::PaintStyle const& paint_style, float thickness, float opacity, Gfx::FloatPoint const& aa_translation) = 0;
  381. virtual CommandResult draw_ellipse(Gfx::IntRect const&, Color const&, int thickness) = 0;
  382. virtual CommandResult fill_ellipse(Gfx::IntRect const&, Color const&, Gfx::AntiAliasingPainter::BlendMode blend_mode) = 0;
  383. virtual CommandResult draw_line(Color const& color, Gfx::IntPoint const& from, Gfx::IntPoint const& to, int thickness, Gfx::Painter::LineStyle, Color const& alternate_color) = 0;
  384. virtual CommandResult draw_signed_distance_field(Gfx::IntRect const& rect, Color const&, Gfx::GrayscaleBitmap const&, float smoothing) = 0;
  385. virtual CommandResult paint_frame(Gfx::IntRect const& rect, Palette const&, Gfx::FrameStyle) = 0;
  386. virtual CommandResult apply_backdrop_filter(Gfx::IntRect const& backdrop_region, Web::CSS::ResolvedBackdropFilter const& backdrop_filter) = 0;
  387. virtual CommandResult draw_rect(Gfx::IntRect const& rect, Color const&, bool rough) = 0;
  388. virtual CommandResult draw_triangle_wave(Gfx::IntPoint const& p1, Gfx::IntPoint const& p2, Color const& color, int amplitude, int thickness) = 0;
  389. virtual CommandResult sample_under_corners(u32 id, CornerRadii const&, Gfx::IntRect const&, CornerClip) = 0;
  390. virtual CommandResult blit_corner_clipping(u32 id) = 0;
  391. virtual CommandResult paint_borders(DevicePixelRect const& border_rect, CornerRadii const& corner_radii, BordersDataDevicePixels const& borders_data) = 0;
  392. virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0;
  393. virtual bool needs_prepare_glyphs_texture() const { return false; }
  394. virtual void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs) = 0;
  395. virtual void prepare_to_execute() { }
  396. virtual bool needs_update_immutable_bitmap_texture_cache() const = 0;
  397. virtual void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) = 0;
  398. };
  399. class RecordingPainter {
  400. public:
  401. void fill_rect(Gfx::IntRect const& rect, Color color);
  402. struct FillPathUsingColorParams {
  403. Gfx::Path path;
  404. Gfx::Color color;
  405. Gfx::Painter::WindingRule winding_rule = Gfx::Painter::WindingRule::EvenOdd;
  406. Optional<Gfx::FloatPoint> translation = {};
  407. };
  408. void fill_path(FillPathUsingColorParams params);
  409. struct FillPathUsingPaintStyleParams {
  410. Gfx::Path path;
  411. NonnullRefPtr<Gfx::PaintStyle> paint_style;
  412. Gfx::Painter::WindingRule winding_rule = Gfx::Painter::WindingRule::EvenOdd;
  413. float opacity;
  414. Optional<Gfx::FloatPoint> translation = {};
  415. };
  416. void fill_path(FillPathUsingPaintStyleParams params);
  417. struct StrokePathUsingColorParams {
  418. Gfx::Path path;
  419. Gfx::Color color;
  420. float thickness;
  421. Optional<Gfx::FloatPoint> translation = {};
  422. };
  423. void stroke_path(StrokePathUsingColorParams params);
  424. struct StrokePathUsingPaintStyleParams {
  425. Gfx::Path path;
  426. NonnullRefPtr<Gfx::PaintStyle> paint_style;
  427. float thickness;
  428. float opacity;
  429. Optional<Gfx::FloatPoint> translation = {};
  430. };
  431. void stroke_path(StrokePathUsingPaintStyleParams params);
  432. void draw_ellipse(Gfx::IntRect const& a_rect, Color color, int thickness);
  433. void fill_ellipse(Gfx::IntRect const& a_rect, Color color, Gfx::AntiAliasingPainter::BlendMode blend_mode = Gfx::AntiAliasingPainter::BlendMode::Normal);
  434. void fill_rect_with_linear_gradient(Gfx::IntRect const& gradient_rect, LinearGradientData const& data);
  435. void fill_rect_with_conic_gradient(Gfx::IntRect const& rect, ConicGradientData const& data, Gfx::IntPoint const& position);
  436. void fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, Gfx::IntPoint center, Gfx::IntSize size);
  437. void draw_rect(Gfx::IntRect const& rect, Color color, bool rough = false);
  438. void draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode = Gfx::Painter::ScalingMode::NearestNeighbor);
  439. void draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode = Gfx::Painter::ScalingMode::NearestNeighbor);
  440. void draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness = 1, Gfx::Painter::LineStyle style = Gfx::Painter::LineStyle::Solid, Color alternate_color = Color::Transparent);
  441. void draw_text(Gfx::IntRect const&, String, Gfx::Font const&, Gfx::TextAlignment = Gfx::TextAlignment::TopLeft, Color = Color::Black, Gfx::TextElision = Gfx::TextElision::None, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap);
  442. void draw_signed_distance_field(Gfx::IntRect const& dst_rect, Color color, Gfx::GrayscaleBitmap const& sdf, float smoothing);
  443. // Streamlined text drawing routine that does no wrapping/elision/alignment.
  444. void draw_text_run(Gfx::IntPoint baseline_start, Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color color, Gfx::IntRect const& rect);
  445. void add_clip_rect(Gfx::IntRect const& rect);
  446. void translate(int dx, int dy);
  447. void translate(Gfx::IntPoint delta);
  448. void set_scroll_frame_id(i32 id)
  449. {
  450. state().scroll_frame_id = id;
  451. }
  452. void save();
  453. void restore();
  454. struct PushStackingContextParams {
  455. float opacity;
  456. bool is_fixed_position;
  457. Gfx::IntRect source_paintable_rect;
  458. CSS::ImageRendering image_rendering;
  459. StackingContextTransform transform;
  460. Optional<StackingContextMask> mask = {};
  461. };
  462. void push_stacking_context(PushStackingContextParams params);
  463. void pop_stacking_context();
  464. void sample_under_corners(u32 id, CornerRadii corner_radii, Gfx::IntRect border_rect, CornerClip corner_clip);
  465. void blit_corner_clipping(u32 id, Gfx::IntRect border_rect);
  466. void paint_frame(Gfx::IntRect rect, Palette palette, Gfx::FrameStyle style);
  467. void apply_backdrop_filter(Gfx::IntRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter);
  468. void paint_outer_box_shadow_params(PaintOuterBoxShadowParams params);
  469. void paint_inner_box_shadow_params(PaintOuterBoxShadowParams params);
  470. void paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color color, int fragment_baseline, Gfx::IntPoint draw_location);
  471. 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);
  472. void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius);
  473. void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
  474. void draw_triangle_wave(Gfx::IntPoint a_p1, Gfx::IntPoint a_p2, Color color, int amplitude, int thickness);
  475. void paint_borders(DevicePixelRect const& border_rect, CornerRadii const& corner_radii, BordersDataDevicePixels const& borders_data);
  476. void execute(PaintingCommandExecutor&);
  477. RecordingPainter()
  478. {
  479. m_state_stack.append(State());
  480. }
  481. void apply_scroll_offsets(Vector<Gfx::IntPoint> const& offsets_by_frame_id);
  482. private:
  483. struct State {
  484. Gfx::AffineTransform translation;
  485. Optional<Gfx::IntRect> clip_rect;
  486. Optional<i32> scroll_frame_id;
  487. };
  488. State& state() { return m_state_stack.last(); }
  489. State const& state() const { return m_state_stack.last(); }
  490. void push_command(PaintingCommand command)
  491. {
  492. m_painting_commands.append({ state().scroll_frame_id, move(command) });
  493. }
  494. struct PaintingCommandWithScrollFrame {
  495. Optional<i32> scroll_frame_id;
  496. PaintingCommand command;
  497. };
  498. AK::SegmentedVector<PaintingCommandWithScrollFrame, 512> m_painting_commands;
  499. Vector<State> m_state_stack;
  500. };
  501. class RecordingPainterStateSaver {
  502. public:
  503. explicit RecordingPainterStateSaver(RecordingPainter& painter)
  504. : m_painter(painter)
  505. {
  506. m_painter.save();
  507. }
  508. ~RecordingPainterStateSaver()
  509. {
  510. m_painter.restore();
  511. }
  512. private:
  513. RecordingPainter& m_painter;
  514. };
  515. }