tree: 461f4f20738bb318a16365dc76c2c1ad6553685a [path history] [tgz]
  1. compositing/
  2. ng/
  3. test_data/
  4. adjust_paint_offset_scope.cc
  5. adjust_paint_offset_scope.h
  6. applied_decoration_painter.cc
  7. applied_decoration_painter.h
  8. background_image_geometry.cc
  9. background_image_geometry.h
  10. block_flow_paint_invalidator.cc
  11. block_flow_paint_invalidator.h
  12. block_flow_painter.cc
  13. block_flow_painter.h
  14. block_paint_invalidator.cc
  15. block_paint_invalidator.h
  16. block_painter.cc
  17. block_painter.h
  18. block_painter_test.cc
  19. box_border_painter.cc
  20. box_border_painter.h
  21. box_clipper.cc
  22. box_clipper.h
  23. box_clipper_base.cc
  24. box_clipper_base.h
  25. box_decoration_data.cc
  26. box_decoration_data.h
  27. box_model_object_painter.cc
  28. box_model_object_painter.h
  29. box_paint_invalidator.cc
  30. box_paint_invalidator.h
  31. box_paint_invalidator_test.cc
  32. box_painter.cc
  33. box_painter.h
  34. box_painter_base.cc
  35. box_painter_base.h
  36. box_reflection_utils.cc
  37. box_reflection_utils.h
  38. BUILD.gn
  39. clip_path_clipper.cc
  40. clip_path_clipper.h
  41. clip_path_clipper_test.cc
  42. clip_rect.cc
  43. clip_rect.h
  44. clip_rect_test.cc
  45. clip_rects.h
  46. clip_rects_cache.h
  47. collapsed_border_painter.cc
  48. collapsed_border_painter.h
  49. css_mask_painter.cc
  50. css_mask_painter.h
  51. css_mask_painter_test.cc
  52. decoration_info.h
  53. DEPS
  54. details_marker_painter.cc
  55. details_marker_painter.h
  56. document_marker_painter.h
  57. ellipsis_box_painter.cc
  58. ellipsis_box_painter.h
  59. embedded_content_painter.cc
  60. embedded_content_painter.h
  61. embedded_object_paint_invalidator.cc
  62. embedded_object_paint_invalidator.h
  63. embedded_object_painter.cc
  64. embedded_object_painter.h
  65. fallback_theme.cc
  66. fallback_theme.h
  67. fieldset_painter.cc
  68. fieldset_painter.h
  69. file_upload_control_painter.cc
  70. file_upload_control_painter.h
  71. filter_effect_builder.cc
  72. filter_effect_builder.h
  73. filter_painter.cc
  74. filter_painter.h
  75. find_paint_offset_and_visual_rect_needing_update.h
  76. find_properties_needing_update.h
  77. first_meaningful_paint_detector.cc
  78. first_meaningful_paint_detector.h
  79. first_meaningful_paint_detector_test.cc
  80. float_clip_recorder.cc
  81. float_clip_recorder.h
  82. fragment_data.cc
  83. fragment_data.h
  84. fragment_data_test.cc
  85. frame_paint_timing.h
  86. frame_painter.cc
  87. frame_painter.h
  88. frame_set_painter.cc
  89. frame_set_painter.h
  90. grid_painter.cc
  91. grid_painter.h
  92. html_canvas_paint_invalidator.cc
  93. html_canvas_paint_invalidator.h
  94. html_canvas_painter.cc
  95. html_canvas_painter.h
  96. html_canvas_painter_test.cc
  97. image_painter.cc
  98. image_painter.h
  99. inline_flow_box_painter.cc
  100. inline_flow_box_painter.h
  101. inline_painter.cc
  102. inline_painter.h
  103. inline_text_box_painter.cc
  104. inline_text_box_painter.h
  105. layer_clip_recorder.cc
  106. layer_clip_recorder.h
  107. layout_object_counter.h
  108. line_box_list_painter.cc
  109. line_box_list_painter.h
  110. link_highlight_impl.cc
  111. link_highlight_impl.h
  112. link_highlight_impl_test.cc
  113. list_item_painter.cc
  114. list_item_painter.h
  115. list_marker_painter.cc
  116. list_marker_painter.h
  117. multi_column_set_painter.cc
  118. multi_column_set_painter.h
  119. nine_piece_image_grid.cc
  120. nine_piece_image_grid.h
  121. nine_piece_image_grid_test.cc
  122. nine_piece_image_painter.cc
  123. nine_piece_image_painter.h
  124. object_paint_invalidator.cc
  125. object_paint_invalidator.h
  126. object_paint_invalidator_test.cc
  127. object_paint_properties.h
  128. object_painter.cc
  129. object_painter.h
  130. object_painter_base.cc
  131. object_painter_base.h
  132. OWNERS
  133. paint_and_raster_invalidation_test.cc
  134. paint_and_raster_invalidation_test.h
  135. paint_controller_paint_test.cc
  136. paint_controller_paint_test.h
  137. paint_event.h
  138. paint_info.h
  139. paint_invalidation_capable_scrollable_area.cc
  140. paint_invalidation_capable_scrollable_area.h
  141. paint_invalidator.cc
  142. paint_invalidator.h
  143. paint_layer.cc
  144. paint_layer.h
  145. paint_layer_clipper.cc
  146. paint_layer_clipper.h
  147. paint_layer_clipper_test.cc
  148. paint_layer_fragment.h
  149. paint_layer_painter.cc
  150. paint_layer_painter.h
  151. paint_layer_painter_test.cc
  152. paint_layer_painting_info.h
  153. paint_layer_resource_info.cc
  154. paint_layer_resource_info.h
  155. paint_layer_scrollable_area.cc
  156. paint_layer_scrollable_area.h
  157. paint_layer_scrollable_area_test.cc
  158. paint_layer_stacking_node.cc
  159. paint_layer_stacking_node.h
  160. paint_layer_stacking_node_iterator.cc
  161. paint_layer_stacking_node_iterator.h
  162. paint_layer_test.cc
  163. paint_phase.cc
  164. paint_phase.h
  165. paint_property_tree_builder.cc
  166. paint_property_tree_builder.h
  167. paint_property_tree_builder_test.cc
  168. paint_property_tree_builder_test.h
  169. paint_property_tree_printer.cc
  170. paint_property_tree_printer.h
  171. paint_property_tree_printer_test.cc
  172. paint_property_tree_update_tests.cc
  173. paint_result.h
  174. paint_timing.cc
  175. paint_timing.h
  176. pre_paint_tree_walk.cc
  177. pre_paint_tree_walk.h
  178. pre_paint_tree_walk_test.cc
  179. README.md
  180. replaced_painter.cc
  181. replaced_painter.h
  182. root_inline_box_painter.cc
  183. root_inline_box_painter.h
  184. rounded_inner_rect_clipper.cc
  185. rounded_inner_rect_clipper.h
  186. scroll_recorder.cc
  187. scroll_recorder.h
  188. scrollable_area_painter.cc
  189. scrollable_area_painter.h
  190. scrollbar_manager.cc
  191. scrollbar_manager.h
  192. scrollbar_painter.cc
  193. scrollbar_painter.h
  194. selection_painting_utils.cc
  195. selection_painting_utils.h
  196. stub_chrome_client_for_spv2.h
  197. svg_container_painter.cc
  198. svg_container_painter.h
  199. svg_filter_painter.cc
  200. svg_filter_painter.h
  201. svg_foreign_object_painter.cc
  202. svg_foreign_object_painter.h
  203. svg_image_painter.cc
  204. svg_image_painter.h
  205. svg_inline_flow_box_painter.cc
  206. svg_inline_flow_box_painter.h
  207. svg_inline_text_box_painter.cc
  208. svg_inline_text_box_painter.h
  209. svg_mask_painter.cc
  210. svg_mask_painter.h
  211. svg_paint_context.cc
  212. svg_paint_context.h
  213. svg_root_inline_box_painter.cc
  214. svg_root_inline_box_painter.h
  215. svg_root_painter.cc
  216. svg_root_painter.h
  217. svg_shape_painter.cc
  218. svg_shape_painter.h
  219. svg_text_painter.cc
  220. svg_text_painter.h
  221. table_cell_paint_invalidator.cc
  222. table_cell_paint_invalidator.h
  223. table_cell_painter.cc
  224. table_cell_painter.h
  225. table_paint_invalidator.cc
  226. table_paint_invalidator.h
  227. table_painter.cc
  228. table_painter.h
  229. table_painter_test.cc
  230. table_row_painter.cc
  231. table_row_painter.h
  232. table_section_painter.cc
  233. table_section_painter.h
  234. text_paint_style.h
  235. text_painter.cc
  236. text_painter.h
  237. text_painter_base.cc
  238. text_painter_base.h
  239. text_painter_test.cc
  240. text_selection_repaint_test.cc
  241. theme_painter.cc
  242. theme_painter.h
  243. theme_painter_default.cc
  244. theme_painter_default.h
  245. theme_painter_mac.h
  246. theme_painter_mac.mm
  247. transform_3d_recorder.cc
  248. transform_3d_recorder.h
  249. transform_recorder.cc
  250. transform_recorder.h
  251. video_painter.cc
  252. video_painter.h
  253. video_painter_test.cc
  254. view_painter.cc
  255. view_painter.h
  256. view_painter_test.cc
third_party/blink/renderer/core/paint/README.md

Source/core/paint

This directory contains implementation of painters of layout objects. It covers the following document lifecycle phases:

  • Layerization (kInCompositingUpdate, kCompositingInputsClean and kCompositingClean)
  • PaintInvalidation (InPaintInvalidation and PaintInvalidationClean)
  • PrePaint (InPrePaint and PrePaintClean)
  • Paint (InPaint and PaintClean)

Glossaries

Stacked elements and stacking contexts

This chapter is basically a clarification of CSS 2.1 appendix E. Elaborate description of Stacking Contexts.

Note: we use ‘element’ instead of ‘object’ in this chapter to keep consistency with the spec. We use ‘object’ in other places in this document.

According to the documentation, we can have the following types of elements that are treated in different ways during painting:

  • Stacked objects: objects that are z-ordered in stacking contexts, including:

    • Stacking contexts: elements with non-auto z-indices or other properties that affect stacking e.g. transform, opacity, blend-mode.

    • Replaced normal-flow stacking elements: replaced elements that do not have non-auto z-index but are stacking contexts for elements below them. Right now the only example is SVG . The difference between these elements and regular stacking contexts is that they paint in the foreground phase of the painting algorithm (as opposed to the positioned descendants phase).

    • Elements that are not real stacking contexts but are treated as stacking contexts but don't manage other stacked elements. Their z-ordering are managed by real stacking contexts. They are positioned elements with z-index: auto (E.2.8 in the documentation).

      They must be managed by the enclosing stacking context as stacked elements because z-index:auto and z-index:0 are considered equal for stacking context sorting and they may interleave by DOM order.

      The difference of a stacked element of this type from a real stacking context is that it doesn't manage z-ordering of stacked descendants. These descendants are managed by the parent stacking context of this stacked element.

    “Stacked element” is not defined as a formal term in the documentation, but we found it convenient to use this term to refer to any elements participating z-index ordering in stacking contexts.

    A stacked element is represented by a PaintLayerStackingNode associated with a PaintLayer. It‘s painted as self-painting PaintLayers by PaintLayerPainter by executing all of the steps of the painting algorithm explained in the documentation for the element. When painting a stacked element of the second type, we don’t paint its stacked descendants which are managed by the parent stacking context.

  • Non-stacked pseudo stacking contexts: elements that are not stacked, but paint their descendants (excluding any stacked contents) as if they created stacking contexts. This includes

    • inline blocks, inline tables, inline-level replaced elements (E.2.7.2.1.4 in the documentation)
    • non-positioned floating elements (E.2.5 in the documentation)
    • flex items
    • grid items
    • custom scrollbar parts

    They are painted by ObjectPainter::paintAllPhasesAtomically() which executes all of the steps of the painting algorithm explained in the documentation, except ignores any descendants which are positioned or have non-auto z-index (which is achieved by skipping descendants with self-painting layers).

  • Other normal elements.

Other glossaries

  • Paint container: the parent of an object for painting, as defined by CSS2.1 spec for painting. For regular objects, this is the parent in the DOM. For stacked objects, it's the containing stacking context-inducing object.

  • Paint container chain: the chain of paint ancestors between an element and the root of the page.

  • Compositing container: an implementation detail of Blink, which uses PaintLayers to represent some layout objects. It is the ancestor along the paint ancestor chain which has a PaintLayer. Implemented in PaintLayer::compositingContainer(). Think of it as skipping intermediate normal objects and going directly to the containing stacked object.

  • Compositing container chain: same as paint chain, but for compositing container.

  • Paint invalidation container: the nearest object on the compositing container chain which is composited. Slimming paint V2 doesn't have this concept.

  • Visual rect: the bounding box of all pixels that will be painted by a display item client.

Overview

The primary responsibility of this module is to convert the outputs from layout (the LayoutObject tree) to the inputs of the compositor (the cc::Layer tree and associated display items).

At the time of writing, there are three operation modes that are switched by RuntimeEnabledFeatures.

SlimmingPaintV175 (a.k.a. SPv1.75)

This mode is for incrementally shipping completed features from SPv2. SPv1.75 reuses layerization from SPv1, but will cherrypick property-tree-based paint from SPv2. Meta display items are abandoned in favor of property tree. Each drawable GraphicsLayer's layer state will be computed by the property tree builder. During paint, each display item will be associated with a property tree state. At the end of paint, meta display items will be generated from the state differences between the chunk and the layer.

from layout
  |
  v
+------------------------------+
| LayoutObject/PaintLayer tree |-----------+
+------------------------------+           |
  |                                        |
  | PaintLayerCompositor::UpdateIfNeeded() |
  |   CompositingInputsUpdater::Update()   |
  |   CompositingLayerAssigner::Assign()   |
  |   GraphicsLayerUpdater::Update()       | PrePaintTreeWalk::Walk()
  |   GraphicsLayerTreeBuilder::Rebuild()  |   PaintPropertyTreeBuider::UpdatePropertiesForSelf()
  v                                        |
+--------------------+                   +------------------+
| GraphicsLayer tree |<------------------|  Property trees  |
+--------------------+                   +------------------+
  |   |                                    |              |
  |   |<-----------------------------------+              |
  |   | LocalFrameView::PaintTree()                       |
  |   |   LocalFrameView::PaintGraphicsLayerRecursively() |
  |   |     GraphicsLayer::Paint()                        |
  |   |       CompositedLayerMapping::PaintContents()     |
  |   |         PaintLayerPainter::PaintLayerContents()   |
  |   |           ObjectPainter::Paint()                  |
  |   v                                                   |
  | +---------------------------------+                   |
  | | DisplayItemList/PaintChunk list |                   |
  | +---------------------------------+                   |
  |   |                                                   |
  |   |<--------------------------------------------------+
  |   | PaintChunksToCcLayer::Convert()
  |   |
  |   | WebContentLayer shim
  v   v
+----------------+
| cc::Layer tree |
+----------------+
  |
  | to compositor
  v

SPv1 compositing algorithm

The SPv1 compositing system chooses which LayoutObjects paint into their own composited backing texture. This is called “having a compositing trigger”. These textures correspond to GraphicsLayers. There are also additional GraphicsLayers which represent property tree-related effects.

All elements which do not have a compositing trigger paint into the texture of the nearest LayoutObjectwith a compositing trigger on its compositing container chain (except for squashed layers; see below). For historical, practical and implementation detail reasons, only LayoutObjects with PaintLayers can have a compositing trigger. See crbug.com/370604 for a bug tracking this limitation, which is often referred to as the “fundamental compositing bug”.

The various compositing triggers are listed here. They fall in to several categories:

  1. Direct reasons due to CSS style (see CompositingReason::kComboAllDirectStyleDeterminedReasons)
  2. Direct reasons due to other conditions (see CompositingReason::kComboAllDirectNonStyleDeterminedReasons)
  3. Composited scrolling-dependent reasons (see CompositingReason::kComboAllCompositedScrollingDeterminedReasons)
  4. Composited descendant-dependent reasons (see CompositingReason::kComboCompositedDescendants)
  5. Overlap-dependent reasons (See CompositingReasons::kComboSquashableReasons)

The triggers have no effect unless PaintLayerCompositor::CanBeComposited returns true.

Category (1) always triggers compositing of a LayoutObject based on its own style. Category (2) triggers based on the LayoutObject's style, its DOM ancestors, and whether it is a certain kind of frame root. Category (3) triggers based on whether composited scrolling applies to the LayoutObject, or the LayoutObject moves relative to a composited scroller (position: fixed or position: sticky). Category (4) triggers if there are any stacking descendants of the LayoutObject that end up composited. Category 5 triggers if the LayoutObject paints after and overlaps (or may overlap) another composited layer.

Note that composited scrolling is special. Several ways it is special:

  • Composited descendants do not necessarily cause composited scrolling of an ancestor.
  • The presence of LCD text prevents composited scrolling in the absence of other overriding triggers.
  • Local frame roots always use composited scrolling if they have overflow.
  • Non-local frame roots use composited scrolling if they have overflow and any composited descendants.
  • Composited scrolling is indicated by a bit on PaintLayerScrollableArea, not a direct compositing reason. This bit is then transformed into a compositing reason from category (3) during the CompositingRequirementsUpdater

Note that overlap triggers have two special behaviors:

  • Any LayoutObject which may overlap a LayoutObject that uses composited scrolling or a transform animation, paints after it, and scrolls with respect to it, receives an overlap trigger. In some cases this trigger is too aggressive.
  • Inline CSS transform is treated as if it was a transform animation. (This is a heuristic to speed up the compositing step but leads to more composited layers.)

The sequence of work during the DocumentLifecycle to compute these triggers is as follows:

  • kInStyleRecalc: compute (1) and most of (4) by calling CompositingReasonFinder::PotentialCompositingReasonsFromStyle and caching the result on PaintLayer, accessible via PaintLayer::PotentialCompositingReasonsFromStyle. Dirty bits in StyleDifference determine whether this has to be re-computed on a particular lifecycle update.
  • kInCompositingUpdate: compute (2) CompositingInputsUpdater. Also set the composited scrolling bit on PaintLayerScrollableArea if applicable.
  • kCompositingInputsClean: compute (3), the rest of (4), and (5), in CompositingRequirementsUpdater

BlinkGenPropertyTrees

This mode is for incrementally shipping completed features from SPv2. It is based on SPv1.75 and starts sending a layer list and property trees directly to the compositor. BlinkGenPropertyTrees still uses the GraphicsLayers from SPv1.75 and plugs them in as foreign layers to the SPv2 compositor (PaintArtifactCompositor).

from layout
  |
  v
+------------------------------+
| LayoutObject/PaintLayer tree |-----------+
+------------------------------+           |
  |                                        |
  | PaintLayerCompositor::UpdateIfNeeded() |
  |   CompositingInputsUpdater::Update()   |
  |   CompositingLayerAssigner::Assign()   |
  |   GraphicsLayerUpdater::Update()       | PrePaintTreeWalk::Walk()
  |   GraphicsLayerTreeBuilder::Rebuild()  |   PaintPropertyTreeBuider::UpdatePropertiesForSelf()
  v                                        |
+--------------------+                   +------------------+
| GraphicsLayer tree |<------------------|  Property trees  |
+--------------------+                   +------------------+
      |                                    |              |
      |<-----------------------------------+              |
      | LocalFrameView::PaintTree()                       |
      |   LocalFrameView::PaintGraphicsLayerRecursively() |
      |     GraphicsLayer::Paint()                        |
      |       CompositedLayerMapping::PaintContents()     |
      |         PaintLayerPainter::PaintLayerContents()   |
      |           ObjectPainter::Paint()                  |
      v                                                   |
    +---------------------------------+                   |
    | DisplayItemList/PaintChunk list |                   |
    +---------------------------------+                   |
      |                                                   |
      |<--------------------------------------------------+
      | PaintChunksToCcLayer::Convert()                   |
      v                                                   |
+----------------+                                        |
| Foreign layers |                                        |
+----------------+                                        |
  |                                                       |
  |    LocalFrameView::PushPaintArtifactToCompositor()    |
  |         PaintArtifactCompositor::Update()             |
  +--------------------+       +--------------------------+
                       |       |
                       v       v
        +----------------+  +-----------------------+
        | cc::Layer list |  |   cc property trees   |
        +----------------+  +-----------------------+
                |              |
  +-------------+--------------+
  | to compositor
  v

SlimmingPaintV2 (a.k.a. SPv2)

This is a new mode under development. In this mode, layerization runs after pre-paint and paint, and meta display items are abandoned in favor of property trees.

The process starts with pre-paint to generate property trees. During paint, each generated display item will be associated with a property tree state. Adjacent display items having the same property tree state will be grouped as PaintChunk. The list of paint chunks then will be processed by PaintArtifactCompositor for layerization. Property nodes that will be composited are converted into cc property nodes, while non-composited property nodes are converted into meta display items by PaintChunksToCcLayer.

from layout
  |
  v
+------------------------------+
| LayoutObject/PaintLayer tree |
+------------------------------+
  |     |
  |     | PrePaintTreeWalk::Walk()
  |     |   PaintPropertyTreeBuider::UpdatePropertiesForSelf()
  |     v
  |   +--------------------------------+
  |<--|         Property trees         |
  |   +--------------------------------+
  |                                  |
  | LocalFrameView::PaintTree()      |
  |   FramePainter::Paint()          |
  |     PaintLayerPainter::Paint()   |
  |       ObjectPainter::Paint()     |
  v                                  |
+---------------------------------+  |
| DisplayItemList/PaintChunk list |  |
+---------------------------------+  |
  |                                  |
  |<---------------------------------+
  | LocalFrameView::PushPaintArtifactToCompositor()
  |   PaintArtifactCompositor::Update()
  |
  +---+---------------------------------+
  |   v                                 |
  | +----------------------+            |
  | | Chunk list for layer |            |
  | +----------------------+            |
  |   |                                 |
  |   | PaintChunksToCcLayer::Convert() |
  v   v                                 v
+----------------+ +-----------------------+
| cc::Layer list | |   cc property trees   |
+----------------+ +-----------------------+
  |                  |
  +------------------+
  | to compositor
  v

Comparison of the three modes

                                 | SPv175             | BlinkGenPropertyTrees | SPv2
---------------------------------+--------------------+-----------------------+-------
REF::BlinkGenPropertyTreesEnabled| false              | true                  | false
REF::SPv2Enabled                 | false              | false                 | true
Layerization                     | PLC/CLM            | PLC/CLM               | PAC
cc property tree builder         | on                 | off                   | off

PaintInvalidation (Deprecated by PrePaint)

Paint invalidation marks anything that need to be painted differently from the original cached painting.

Paint invalidation is a document cycle stage after compositing update and before paint. During the previous stages, objects are marked for needing paint invalidation checking if needed by style change, layout change, compositing change, etc. In paint invalidation stage, we traverse the layout tree in pre-order, crossing frame boundaries, for marked subtrees and objects and send the following information to GraphicsLayers and PaintControllers:

  • invalidated display item clients: must invalidate all display item clients that will generate different display items.

  • paint invalidation rects: must cover all areas that will generate different pixels. They are generated based on visual rects of invalidated display item clients.

PaintInvalidationState

PaintInvalidationState is an optimization used during the paint invalidation phase. Before the paint invalidation tree walk, a root PaintInvalidationState is created for the root LayoutView. During the tree walk, one PaintInvalidationState is created for each visited object based on the PaintInvalidationState passed from the parent object. It tracks the following information to provide O(1) complexity access to them if possible:

  • Paint invalidation container: Since as indicated by the definitions in Glossaries, the paint invalidation container for stacked objects can differ from normal objects, we have to track both separately. Here is an example:

    <div style="overflow: scroll">
        <div id=A style="position: absolute"></div>
        <div id=B></div>
    </div>
    

    If the scroller is composited (for high-DPI screens for example), it is the paint invalidation container for div B, but not A.

  • Paint offset and clip rect: if possible, PaintInvalidationState accumulates paint offsets and overflow clipping rects from the paint invalidation container to provide O(1) complexity to map a point or a rect in current object‘s local space to paint invalidation container’s space. Because locations of objects are determined by their containing blocks, and the containing block for absolute-position objects differs from non-absolute, we track paint offsets and overflow clipping rects for absolute-position objects separately.

In cases that accurate accumulation of paint offsets and clipping rects is impossible, we will fall back to slow-path using LayoutObject::localToAncestorPoint() or LayoutObject::mapToVisualRectInAncestorSpace(). This includes the following cases:

  • An object has transform related property, is multi-column or has flipped blocks writing-mode, causing we can't simply accumulate paint offset for mapping a local rect to paint invalidation container;

  • An object has has filter (including filter induced by reflection), which needs to expand visual rect for descendants, because currently we don't include and filter extents into visual overflow;

  • For a fixed-position object we calculate its offset using LayoutObject::localToAncestorPoint(), but map for its descendants in fast-path if no other things prevent us from doing this;

  • Because we track paint offset from the normal paint invalidation container only, if we are going to use m_paintInvalidationContainerForStackedContents and it's different from the normal paint invalidation container, we have to force slow-path because the accumulated paint offset is not usable;

  • We also stop to track paint offset and clipping rect for absolute-position objects when m_paintInvalidationContainerForStackedContents becomes different from m_paintInvalidationContainer.

Paint invalidation of texts

Texts are painted by InlineTextBoxPainter using InlineTextBox as display item client. Text backgrounds and masks are painted by InlineTextFlowPainter using InlineFlowBox as display item client. We should invalidate these display item clients when their painting will change.

LayoutInlines and LayoutTexts are marked for full paint invalidation if needed when new style is set on them. During paint invalidation, we invalidate the InlineFlowBoxs directly contained by the LayoutInline in LayoutInline::InvalidateDisplayItemClients() and InlineTextBoxs contained by the LayoutText in LayoutText::InvalidateDisplayItemClients(). We don't need to traverse into the subtree of InlineFlowBoxs in LayoutInline::InvalidateDisplayItemClients() because the descendant InlineFlowBoxs and InlineTextBoxs will be handled by their owning LayoutInlines and LayoutTexts, respectively, when changed style is propagated.

Specialty of ::first-line

::first-line pseudo style dynamically applies to all InlineBox's in the first line in the block having ::first-line style. The actual applied style is computed from the ::first-line style and other applicable styles.

If the first line contains any LayoutInline, we compute the style from the ::first-line style and the style of the LayoutInline and apply the computed style to the first line part of the LayoutInline. In Blink's style implementation, the combined first line style of LayoutInline is identified with FIRST_LINE_INHERITED pseudo ID.

The normal paint invalidation of texts doesn't work for first line because

  • ComputedStyle::VisualInvalidationDiff() can't detect first line style changes;
  • The normal paint invalidation is based on whole LayoutObject's, not aware of the first line.

We have a special path for first line style change: the style system informs the layout system when the computed first-line style changes through LayoutObject::FirstLineStyleDidChange(). When this happens, we invalidate all InlineBoxes in the first line.

PrePaint (Slimming paint invalidation/v2 only)

PrePaintTreeWalk

During InPrePaint document lifecycle state, this class is called to walk the whole layout tree, beginning from the root FrameView, across frame boundaries. We do the following during the tree walk:

Building paint property trees

PaintPropertyTreeBuilder

This class is responsible for building property trees (see the platform paint README file).

Each PaintLayer's LayoutObject has one or more FragmentData objects (see below for more on fragments). Every FragmentData has an ObjectPaintProperties object if any property nodes are induced by it. For example, if the object has a transform, its ObjectPaintProperties::Transform() field points at the TransformPaintPropertyNode representing that transform.

The NeedsPaintPropertyUpdate, SubtreeNeedsPaintPropertyUpdate and DescendantNeedsPaintPropertyUpdate dirty bits on LayoutObject control how much of the layout tree is traversed during each PrePaintTreeWalk.

Fragments

In the absence of multicolumn/pagination, there is a 1:1 correspondence between self-painting PaintLayers and FragmentData. If there is multicolumn/pagination, there may be more FragmentDatas.. If a PaintLayer has a property node, each of its fragments will have one. The parent of a fragment‘s property node is the property node that belongs to the ancestor PaintLayer which is part of the same column. For example, if there are 3 columns and both a parent and child PaintLayer have a transform, there will be 3 FragmentData objects for the parent, 3 for the child, each FragmentData will have its own TransformPaintPropertyNode, and the child’s ith fragment‘s transform will point to the ith parent’s transform.

Each FragmentData receives its own ClipPaintPropertyNode. They also store a unique PaintOffset, PaginationOffset and LocalBordreBoxProperties object.

See LayoutMultiColumnFlowThread.h for a much more detail about multicolumn/pagination.

Paint invalidation

PaintInvalidator

This class replaces [PaintInvalidationState] for SlimmingPaintInvalidation. The main difference is that in PaintInvalidator, visual rects and locations are computed by GeometryMapper(../../platform/graphics/paint/GeometryMapper.h), based on paint properties produced by PaintPropertyTreeBuilder.

TODO(wangxianzhu): Combine documentation of PaintInvalidation phase into here.

Paint

Paint result caching

PaintController holds the previous painting result as a cache of display items. If some painter would generate results same as those of the previous painting, we'll skip the painting and reuse the display items from cache.

Display item caching

When a painter would create a DrawingDisplayItem exactly the same as the display item created in the previous painting, we'll reuse the previous one instead of repainting it.

Subsequence caching

When possible, we create a scoped SubsequenceRecorder in PaintLayerPainter::PaintContents() to record all display items generated in the scope as a “subsequence”. Before painting a layer, if we are sure that the layer will generate exactly the same display items as the previous paint, we'll get the whole subsequence from the cache instead of repainting them.

There are many conditions affecting

  • whether we need to generate subsequence for a PaintLayer;
  • whether we can use cached subsequence for a PaintLayer. See ShouldCreateSubsequence() and shouldRepaintSubsequence() in PaintLayerPainter.cpp for the conditions.

Empty paint phase optimization

During painting, we walk the layout tree multiple times for multiple paint phases. Sometimes a layer contain nothing needing a certain paint phase and we can skip tree walk for such empty phases. Now we have optimized PaintPhaseDescendantBlockBackgroundsOnly, PaintPhaseDescendantOutlinesOnly and PaintPhaseFloat for empty paint phases.

During paint invalidation, we set the containing self-painting layer's NeedsPaintPhaseXXX flag if the object has something needing to be painted in the paint phase.

During painting, we check the flag before painting a paint phase and skip the tree walk if the flag is not set.

It‘s hard to clear a NeedsPaintPhaseXXX flag when a layer no longer needs the paint phase, so we never clear the flags. Instead, we use another set of flags (PreviousPaintPhaseXXXWasEmpty) to record if a painting of a phase actually produced nothing. We’ll skip the next painting of the phase if the flag is set, regardless of the corresponding NeedsPaintPhaseXXX flag. We will clear the PreviousPaintPhaseXXXWasEmpty flags when we paint with different clipping, scroll offset or interest rect from the previous paint.

We don‘t clear the PreviousPaintPhaseXXXWasEmpty flags when the layer is marked NeedsRepaint. Instead we clear the flag when the corresponding NeedsPaintPhaseXXX is set. This ensures that we won’t clear PreviousPaintPhaseXXXWasEmpty flags when unrelated things changed which won't

When layer structure changes, and we are not invalidate paint of the changed subtree, we need to manually update the NeedsPaintPhaseXXX flags. For example, if an object changes style and creates a self-painting-layer, we copy the flags from its containing self-painting layer to this layer, assuming that this layer needs all paint phases that its container self-painting layer needs.

We could update the NeedsPaintPhaseXXX flags in a separate tree walk, but that would regress performance of the first paint. For slimming paint v2, we can update the flags during the pre-painting tree walk to simplify the logics.

Hit test painting

Hit testing is done in paint-order. The |PaintTouchActionRects| flag enables a mode where hit test display items are emitted in the background phase of painting. Hit test display items are produced even if there is no painted content.

PaintNG

LayoutNG is a project that will change how Layout generates geometry/style information for painting. Instead of modifying LayoutObjects, LayoutNG will generate an NGFragment tree.

NGPaintFragments are:

  • immutable
  • all coordinates are physical. See layout_box_model_object.h.
  • instead of Location(), NGFragment has Offset(), a physical offset from parent fragment.

The goal is for PaintNG to eventually paint from NGFragment tree, and not see LayoutObjects at all. Until this goal is reached, LegacyPaint, and NGPaint will coexist.

When a particular LayoutObject subclass fully migrates to NG, its LayoutObject geometry information might no longer be updated(*), and its painter needs to be rewritten to paint NGFragments. For example, see how BlockPainter is being rewritten as NGBoxFragmentPainter.