RecordingPainter.cpp 24 KB

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