RecordingPainter.cpp 23 KB

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