RecordingPainter.cpp 22 KB

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