RecordingPainter.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Painting/RecordingPainter.h>
  7. #include <LibWeb/Painting/ShadowPainting.h>
  8. namespace Web::Painting {
  9. void DrawGlyphRun::translate_by(Gfx::IntPoint const& offset)
  10. {
  11. for (auto& glyph : glyph_run) {
  12. glyph.visit([&](auto& glyph) {
  13. glyph.translate_by(offset.to_type<float>());
  14. });
  15. }
  16. rect.translate_by(offset);
  17. }
  18. Gfx::IntRect PaintOuterBoxShadow::bounding_rect() const
  19. {
  20. return get_outer_box_shadow_bounding_rect(outer_box_shadow_params);
  21. }
  22. void PaintOuterBoxShadow::translate_by(Gfx::IntPoint const& offset)
  23. {
  24. outer_box_shadow_params.device_content_rect.translate_by(offset.to_type<DevicePixels>());
  25. }
  26. void PaintInnerBoxShadow::translate_by(Gfx::IntPoint const& offset)
  27. {
  28. outer_box_shadow_params.device_content_rect.translate_by(offset.to_type<DevicePixels>());
  29. }
  30. Gfx::IntRect SampleUnderCorners::bounding_rect() const
  31. {
  32. return border_rect;
  33. }
  34. Gfx::IntRect BlitCornerClipping::bounding_rect() const
  35. {
  36. return border_rect;
  37. }
  38. void RecordingPainter::sample_under_corners(u32 id, CornerRadii corner_radii, Gfx::IntRect border_rect, CornerClip corner_clip)
  39. {
  40. push_command(SampleUnderCorners {
  41. id,
  42. corner_radii,
  43. border_rect = state().translation.map(border_rect),
  44. corner_clip });
  45. }
  46. void RecordingPainter::blit_corner_clipping(u32 id, Gfx::IntRect border_rect)
  47. {
  48. push_command(BlitCornerClipping { id, border_rect = state().translation.map(border_rect) });
  49. }
  50. void RecordingPainter::fill_rect(Gfx::IntRect const& rect, Color color)
  51. {
  52. push_command(FillRect {
  53. .rect = state().translation.map(rect),
  54. .color = color,
  55. });
  56. }
  57. void RecordingPainter::fill_path(FillPathUsingColorParams params)
  58. {
  59. auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
  60. auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
  61. push_command(FillPathUsingColor {
  62. .path_bounding_rect = path_bounding_rect,
  63. .path = params.path,
  64. .color = params.color,
  65. .winding_rule = params.winding_rule,
  66. .aa_translation = aa_translation,
  67. });
  68. }
  69. void RecordingPainter::fill_path(FillPathUsingPaintStyleParams params)
  70. {
  71. auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
  72. auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
  73. push_command(FillPathUsingPaintStyle {
  74. .path_bounding_rect = path_bounding_rect,
  75. .path = params.path,
  76. .paint_style = params.paint_style,
  77. .winding_rule = params.winding_rule,
  78. .opacity = params.opacity,
  79. .aa_translation = aa_translation,
  80. });
  81. }
  82. void RecordingPainter::stroke_path(StrokePathUsingColorParams params)
  83. {
  84. auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
  85. auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
  86. push_command(StrokePathUsingColor {
  87. .path_bounding_rect = path_bounding_rect,
  88. .path = params.path,
  89. .color = params.color,
  90. .thickness = params.thickness,
  91. .aa_translation = aa_translation,
  92. });
  93. }
  94. void RecordingPainter::stroke_path(StrokePathUsingPaintStyleParams params)
  95. {
  96. auto aa_translation = state().translation.map(params.translation.value_or(Gfx::FloatPoint {}));
  97. auto path_bounding_rect = params.path.bounding_box().translated(aa_translation).to_type<int>();
  98. push_command(StrokePathUsingPaintStyle {
  99. .path_bounding_rect = path_bounding_rect,
  100. .path = params.path,
  101. .paint_style = params.paint_style,
  102. .thickness = params.thickness,
  103. .opacity = params.opacity,
  104. .aa_translation = aa_translation,
  105. });
  106. }
  107. void RecordingPainter::draw_ellipse(Gfx::IntRect const& a_rect, Color color, int thickness)
  108. {
  109. push_command(DrawEllipse {
  110. .rect = state().translation.map(a_rect),
  111. .color = color,
  112. .thickness = thickness,
  113. });
  114. }
  115. void RecordingPainter::fill_ellipse(Gfx::IntRect const& a_rect, Color color, Gfx::AntiAliasingPainter::BlendMode blend_mode)
  116. {
  117. push_command(FillEllipse {
  118. .rect = state().translation.map(a_rect),
  119. .color = color,
  120. .blend_mode = blend_mode,
  121. });
  122. }
  123. void RecordingPainter::fill_rect_with_linear_gradient(Gfx::IntRect const& gradient_rect, LinearGradientData const& data)
  124. {
  125. push_command(PaintLinearGradient {
  126. .gradient_rect = state().translation.map(gradient_rect),
  127. .linear_gradient_data = data,
  128. });
  129. }
  130. void RecordingPainter::fill_rect_with_conic_gradient(Gfx::IntRect const& rect, ConicGradientData const& data, Gfx::IntPoint const& position)
  131. {
  132. push_command(PaintConicGradient {
  133. .rect = state().translation.map(rect),
  134. .conic_gradient_data = data,
  135. .position = position });
  136. }
  137. void RecordingPainter::fill_rect_with_radial_gradient(Gfx::IntRect const& rect, RadialGradientData const& data, Gfx::IntPoint center, Gfx::IntSize size)
  138. {
  139. push_command(PaintRadialGradient {
  140. .rect = state().translation.map(rect),
  141. .radial_gradient_data = data,
  142. .center = center,
  143. .size = size });
  144. }
  145. void RecordingPainter::draw_rect(Gfx::IntRect const& rect, Color color, bool rough)
  146. {
  147. push_command(DrawRect {
  148. .rect = state().translation.map(rect),
  149. .color = color,
  150. .rough = rough });
  151. }
  152. void RecordingPainter::draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode)
  153. {
  154. push_command(DrawScaledBitmap {
  155. .dst_rect = state().translation.map(dst_rect),
  156. .bitmap = bitmap,
  157. .src_rect = src_rect,
  158. .scaling_mode = scaling_mode,
  159. });
  160. }
  161. void RecordingPainter::draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::Painter::ScalingMode scaling_mode)
  162. {
  163. push_command(DrawScaledImmutableBitmap {
  164. .dst_rect = state().translation.map(dst_rect),
  165. .bitmap = bitmap,
  166. .src_rect = src_rect,
  167. .scaling_mode = scaling_mode,
  168. });
  169. }
  170. void RecordingPainter::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness, Gfx::Painter::LineStyle style, Color alternate_color)
  171. {
  172. push_command(DrawLine {
  173. .color = color,
  174. .from = state().translation.map(from),
  175. .to = state().translation.map(to),
  176. .thickness = thickness,
  177. .style = style,
  178. .alternate_color = alternate_color,
  179. });
  180. }
  181. void RecordingPainter::draw_text(Gfx::IntRect const& rect, String raw_text, Gfx::TextAlignment alignment, Color color, Gfx::TextElision elision, Gfx::TextWrapping wrapping)
  182. {
  183. push_command(DrawText {
  184. .rect = state().translation.map(rect),
  185. .raw_text = move(raw_text),
  186. .alignment = alignment,
  187. .color = color,
  188. .elision = elision,
  189. .wrapping = wrapping,
  190. });
  191. }
  192. void RecordingPainter::draw_text(Gfx::IntRect const& rect, String raw_text, Gfx::Font const& font, Gfx::TextAlignment alignment, Color color, Gfx::TextElision elision, Gfx::TextWrapping wrapping)
  193. {
  194. push_command(DrawText {
  195. .rect = state().translation.map(rect),
  196. .raw_text = move(raw_text),
  197. .alignment = alignment,
  198. .color = color,
  199. .elision = elision,
  200. .wrapping = wrapping,
  201. .font = font,
  202. });
  203. }
  204. void RecordingPainter::draw_signed_distance_field(Gfx::IntRect const& dst_rect, Color color, Gfx::GrayscaleBitmap const& sdf, float smoothing)
  205. {
  206. push_command(DrawSignedDistanceField {
  207. .rect = state().translation.map(dst_rect),
  208. .color = color,
  209. .sdf = sdf,
  210. .smoothing = smoothing,
  211. });
  212. }
  213. void RecordingPainter::draw_text_run(Gfx::IntPoint baseline_start, Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color color, Gfx::IntRect const& rect)
  214. {
  215. auto transformed_baseline_start = state().translation.map(baseline_start).to_type<float>();
  216. Vector<Gfx::DrawGlyphOrEmoji> translated_glyph_run;
  217. translated_glyph_run.ensure_capacity(glyph_run.size());
  218. for (auto glyph : glyph_run) {
  219. glyph.visit([&](auto& glyph) { glyph.position.translate_by(transformed_baseline_start); });
  220. translated_glyph_run.append(glyph);
  221. }
  222. push_command(DrawGlyphRun {
  223. .glyph_run = move(translated_glyph_run),
  224. .color = color,
  225. .rect = state().translation.map(rect),
  226. });
  227. }
  228. void RecordingPainter::add_clip_rect(Gfx::IntRect const& rect)
  229. {
  230. auto prev_clip_rect = state().clip_rect;
  231. if (!state().clip_rect.has_value()) {
  232. state().clip_rect = state().translation.map(rect);
  233. } else {
  234. state().clip_rect->intersect(state().translation.map(rect));
  235. }
  236. if (prev_clip_rect != state().clip_rect)
  237. push_command(SetClipRect { .rect = *state().clip_rect });
  238. }
  239. void RecordingPainter::translate(int dx, int dy)
  240. {
  241. m_state_stack.last().translation.translate(dx, dy);
  242. }
  243. void RecordingPainter::translate(Gfx::IntPoint delta)
  244. {
  245. m_state_stack.last().translation.translate(delta.to_type<float>());
  246. }
  247. void RecordingPainter::set_font(Gfx::Font const& font)
  248. {
  249. push_command(SetFont { .font = font });
  250. }
  251. void RecordingPainter::save()
  252. {
  253. m_state_stack.append(m_state_stack.last());
  254. }
  255. void RecordingPainter::restore()
  256. {
  257. auto prev_clip_rect = state().clip_rect;
  258. VERIFY(m_state_stack.size() > 1);
  259. m_state_stack.take_last();
  260. if (state().clip_rect != prev_clip_rect) {
  261. if (state().clip_rect.has_value())
  262. push_command(SetClipRect { .rect = *state().clip_rect });
  263. else
  264. push_command(ClearClipRect {});
  265. }
  266. }
  267. void RecordingPainter::push_stacking_context(PushStackingContextParams params)
  268. {
  269. push_command(PushStackingContext {
  270. .opacity = params.opacity,
  271. .is_fixed_position = params.is_fixed_position,
  272. .source_paintable_rect = params.source_paintable_rect,
  273. // No translations apply to fixed-position stacking contexts.
  274. .post_transform_translation = params.is_fixed_position
  275. ? Gfx::IntPoint {}
  276. : state().translation.translation().to_rounded<int>(),
  277. .image_rendering = params.image_rendering,
  278. .transform = {
  279. .origin = params.transform.origin,
  280. .matrix = params.transform.matrix,
  281. },
  282. .mask = params.mask });
  283. m_state_stack.append(State());
  284. }
  285. void RecordingPainter::pop_stacking_context()
  286. {
  287. m_state_stack.take_last();
  288. push_command(PopStackingContext {});
  289. }
  290. void RecordingPainter::paint_frame(Gfx::IntRect rect, Palette palette, Gfx::FrameStyle style)
  291. {
  292. push_command(PaintFrame { state().translation.map(rect), palette, style });
  293. }
  294. void RecordingPainter::apply_backdrop_filter(Gfx::IntRect const& backdrop_region, BorderRadiiData const& border_radii_data, CSS::ResolvedBackdropFilter const& backdrop_filter)
  295. {
  296. push_command(ApplyBackdropFilter {
  297. .backdrop_region = state().translation.map(backdrop_region),
  298. .border_radii_data = border_radii_data,
  299. .backdrop_filter = backdrop_filter,
  300. });
  301. }
  302. void RecordingPainter::paint_outer_box_shadow_params(PaintOuterBoxShadowParams params)
  303. {
  304. params.device_content_rect = state().translation.map(params.device_content_rect.to_type<int>()).to_type<DevicePixels>();
  305. push_command(PaintOuterBoxShadow {
  306. .outer_box_shadow_params = params,
  307. });
  308. }
  309. void RecordingPainter::paint_inner_box_shadow_params(PaintOuterBoxShadowParams params)
  310. {
  311. push_command(PaintInnerBoxShadow {
  312. .outer_box_shadow_params = params,
  313. });
  314. }
  315. void RecordingPainter::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)
  316. {
  317. push_command(PaintTextShadow {
  318. .blur_radius = blur_radius,
  319. .shadow_bounding_rect = bounding_rect,
  320. .text_rect = text_rect,
  321. .glyph_run = Vector<Gfx::DrawGlyphOrEmoji> { glyph_run },
  322. .color = color,
  323. .fragment_baseline = fragment_baseline,
  324. .draw_location = state().translation.map(draw_location) });
  325. }
  326. void RecordingPainter::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)
  327. {
  328. if (!top_left_radius && !top_right_radius && !bottom_right_radius && !bottom_left_radius) {
  329. fill_rect(rect, color);
  330. return;
  331. }
  332. push_command(FillRectWithRoundedCorners {
  333. .rect = state().translation.map(rect),
  334. .color = color,
  335. .top_left_radius = top_left_radius,
  336. .top_right_radius = top_right_radius,
  337. .bottom_left_radius = bottom_left_radius,
  338. .bottom_right_radius = bottom_right_radius,
  339. });
  340. }
  341. void RecordingPainter::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius)
  342. {
  343. fill_rect_with_rounded_corners(a_rect, color, radius, radius, radius, radius);
  344. }
  345. void RecordingPainter::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)
  346. {
  347. fill_rect_with_rounded_corners(a_rect, color,
  348. { top_left_radius, top_left_radius },
  349. { top_right_radius, top_right_radius },
  350. { bottom_right_radius, bottom_right_radius },
  351. { bottom_left_radius, bottom_left_radius });
  352. }
  353. void RecordingPainter::draw_triangle_wave(Gfx::IntPoint a_p1, Gfx::IntPoint a_p2, Color color, int amplitude, int thickness = 1)
  354. {
  355. push_command(DrawTriangleWave {
  356. .p1 = state().translation.map(a_p1),
  357. .p2 = state().translation.map(a_p2),
  358. .color = color,
  359. .amplitude = amplitude,
  360. .thickness = thickness });
  361. }
  362. void RecordingPainter::paint_borders(DevicePixelRect const& border_rect, CornerRadii const& corner_radii, BordersDataDevicePixels const& borders_data)
  363. {
  364. if (borders_data.top.width == 0 && borders_data.right.width == 0 && borders_data.bottom.width == 0 && borders_data.left.width == 0)
  365. return;
  366. push_command(PaintBorders { border_rect, corner_radii, borders_data });
  367. }
  368. static Optional<Gfx::IntRect> command_bounding_rectangle(PaintingCommand const& command)
  369. {
  370. return command.visit(
  371. [&](auto const& command) -> Optional<Gfx::IntRect> {
  372. if constexpr (requires { command.bounding_rect(); })
  373. return command.bounding_rect();
  374. else
  375. return {};
  376. });
  377. }
  378. void RecordingPainter::apply_scroll_offsets(Vector<Gfx::IntPoint> const& offsets_by_frame_id)
  379. {
  380. for (auto& command_with_scroll_id : m_painting_commands) {
  381. if (command_with_scroll_id.scroll_frame_id.has_value()) {
  382. auto const& scroll_frame_id = command_with_scroll_id.scroll_frame_id.value();
  383. auto const& scroll_offset = offsets_by_frame_id[scroll_frame_id];
  384. command_with_scroll_id.command.visit(
  385. [&](auto& command) {
  386. if constexpr (requires { command.translate_by(scroll_offset); })
  387. command.translate_by(scroll_offset);
  388. });
  389. }
  390. }
  391. }
  392. void RecordingPainter::execute(PaintingCommandExecutor& executor)
  393. {
  394. if (executor.needs_prepare_glyphs_texture()) {
  395. HashMap<Gfx::Font const*, HashTable<u32>> unique_glyphs;
  396. for (auto& command_with_scroll_id : m_painting_commands) {
  397. auto& command = command_with_scroll_id.command;
  398. if (command.has<DrawGlyphRun>()) {
  399. for (auto const& glyph_or_emoji : command.get<DrawGlyphRun>().glyph_run) {
  400. if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
  401. auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>();
  402. unique_glyphs.ensure(glyph.font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
  403. }
  404. }
  405. }
  406. }
  407. executor.prepare_glyph_texture(unique_glyphs);
  408. }
  409. if (executor.needs_update_immutable_bitmap_texture_cache()) {
  410. HashMap<u32, Gfx::ImmutableBitmap const*> immutable_bitmaps;
  411. for (auto const& command_with_scroll_id : m_painting_commands) {
  412. auto& command = command_with_scroll_id.command;
  413. if (command.has<DrawScaledImmutableBitmap>()) {
  414. auto const& immutable_bitmap = command.get<DrawScaledImmutableBitmap>().bitmap;
  415. immutable_bitmaps.set(immutable_bitmap->id(), immutable_bitmap.ptr());
  416. }
  417. }
  418. executor.update_immutable_bitmap_texture_cache(immutable_bitmaps);
  419. }
  420. HashTable<u32> skipped_sample_corner_commands;
  421. size_t next_command_index = 0;
  422. while (next_command_index < m_painting_commands.size()) {
  423. auto& command_with_scroll_id = m_painting_commands[next_command_index++];
  424. auto& command = command_with_scroll_id.command;
  425. auto bounding_rect = command_bounding_rectangle(command);
  426. if (bounding_rect.has_value() && (bounding_rect->is_empty() || executor.would_be_fully_clipped_by_painter(*bounding_rect))) {
  427. if (command.has<SampleUnderCorners>()) {
  428. auto const& sample_under_corners = command.get<SampleUnderCorners>();
  429. skipped_sample_corner_commands.set(sample_under_corners.id);
  430. }
  431. continue;
  432. }
  433. auto result = command.visit(
  434. [&](DrawGlyphRun const& command) {
  435. return executor.draw_glyph_run(command.glyph_run, command.color);
  436. },
  437. [&](DrawText const& command) {
  438. return executor.draw_text(command.rect, command.raw_text, command.alignment, command.color, command.elision, command.wrapping, command.font);
  439. },
  440. [&](FillRect const& command) {
  441. return executor.fill_rect(command.rect, command.color);
  442. },
  443. [&](DrawScaledBitmap const& command) {
  444. return executor.draw_scaled_bitmap(command.dst_rect, command.bitmap, command.src_rect, command.scaling_mode);
  445. },
  446. [&](DrawScaledImmutableBitmap const& command) {
  447. return executor.draw_scaled_immutable_bitmap(command.dst_rect, command.bitmap, command.src_rect, command.scaling_mode);
  448. },
  449. [&](SetClipRect const& command) {
  450. return executor.set_clip_rect(command.rect);
  451. },
  452. [&](ClearClipRect const&) {
  453. return executor.clear_clip_rect();
  454. },
  455. [&](SetFont const& command) {
  456. return executor.set_font(command.font);
  457. },
  458. [&](PushStackingContext const& command) {
  459. return executor.push_stacking_context(command.opacity, command.is_fixed_position, command.source_paintable_rect, command.post_transform_translation, command.image_rendering, command.transform, command.mask);
  460. },
  461. [&](PopStackingContext const&) {
  462. return executor.pop_stacking_context();
  463. },
  464. [&](PaintLinearGradient const& command) {
  465. return executor.paint_linear_gradient(command.gradient_rect, command.linear_gradient_data);
  466. },
  467. [&](PaintRadialGradient const& command) {
  468. return executor.paint_radial_gradient(command.rect, command.radial_gradient_data, command.center, command.size);
  469. },
  470. [&](PaintConicGradient const& command) {
  471. return executor.paint_conic_gradient(command.rect, command.conic_gradient_data, command.position);
  472. },
  473. [&](PaintOuterBoxShadow const& command) {
  474. return executor.paint_outer_box_shadow(command.outer_box_shadow_params);
  475. },
  476. [&](PaintInnerBoxShadow const& command) {
  477. return executor.paint_inner_box_shadow(command.outer_box_shadow_params);
  478. },
  479. [&](PaintTextShadow const& command) {
  480. return executor.paint_text_shadow(command.blur_radius, command.shadow_bounding_rect, command.text_rect, command.glyph_run, command.color, command.fragment_baseline, command.draw_location);
  481. },
  482. [&](FillRectWithRoundedCorners const& command) {
  483. return executor.fill_rect_with_rounded_corners(command.rect, command.color, command.top_left_radius, command.top_right_radius, command.bottom_left_radius, command.bottom_right_radius);
  484. },
  485. [&](FillPathUsingColor const& command) {
  486. return executor.fill_path_using_color(command.path, command.color, command.winding_rule, command.aa_translation);
  487. },
  488. [&](FillPathUsingPaintStyle const& command) {
  489. return executor.fill_path_using_paint_style(command.path, command.paint_style, command.winding_rule, command.opacity, command.aa_translation);
  490. },
  491. [&](StrokePathUsingColor const& command) {
  492. return executor.stroke_path_using_color(command.path, command.color, command.thickness, command.aa_translation);
  493. },
  494. [&](StrokePathUsingPaintStyle const& command) {
  495. return executor.stroke_path_using_paint_style(command.path, command.paint_style, command.thickness, command.opacity, command.aa_translation);
  496. },
  497. [&](DrawEllipse const& command) {
  498. return executor.draw_ellipse(command.rect, command.color, command.thickness);
  499. },
  500. [&](FillEllipse const& command) {
  501. return executor.fill_ellipse(command.rect, command.color, command.blend_mode);
  502. },
  503. [&](DrawLine const& command) {
  504. return executor.draw_line(command.color, command.from, command.to, command.thickness, command.style, command.alternate_color);
  505. },
  506. [&](DrawSignedDistanceField const& command) {
  507. return executor.draw_signed_distance_field(command.rect, command.color, command.sdf, command.smoothing);
  508. },
  509. [&](PaintFrame const& command) {
  510. return executor.paint_frame(command.rect, command.palette, command.style);
  511. },
  512. [&](ApplyBackdropFilter const& command) {
  513. return executor.apply_backdrop_filter(command.backdrop_region, command.backdrop_filter);
  514. },
  515. [&](DrawRect const& command) {
  516. return executor.draw_rect(command.rect, command.color, command.rough);
  517. },
  518. [&](DrawTriangleWave const& command) {
  519. return executor.draw_triangle_wave(command.p1, command.p2, command.color, command.amplitude, command.thickness);
  520. },
  521. [&](SampleUnderCorners const& command) {
  522. return executor.sample_under_corners(command.id, command.corner_radii, command.border_rect, command.corner_clip);
  523. },
  524. [&](BlitCornerClipping const& command) {
  525. if (skipped_sample_corner_commands.contains(command.id)) {
  526. // FIXME: If a sampling command falls outside the viewport and is not executed, the associated blit
  527. // should also be skipped if it is within the viewport. In a properly generated list of
  528. // painting commands, sample and blit commands should have matching rectangles, preventing
  529. // this discrepancy.
  530. dbgln("Skipping blit_corner_clipping command because the sample_under_corners command was skipped.");
  531. return CommandResult::Continue;
  532. }
  533. return executor.blit_corner_clipping(command.id);
  534. },
  535. [&](PaintBorders const& command) {
  536. return executor.paint_borders(command.border_rect, command.corner_radii, command.borders_data);
  537. });
  538. if (result == CommandResult::SkipStackingContext) {
  539. auto stacking_context_nesting_level = 1;
  540. while (next_command_index < m_painting_commands.size()) {
  541. if (m_painting_commands[next_command_index].command.has<PushStackingContext>()) {
  542. stacking_context_nesting_level++;
  543. } else if (m_painting_commands[next_command_index].command.has<PopStackingContext>()) {
  544. stacking_context_nesting_level--;
  545. }
  546. next_command_index++;
  547. if (stacking_context_nesting_level == 0)
  548. break;
  549. }
  550. }
  551. }
  552. }
  553. }