# Paint Helper Class
Painting is a complex operation. In chromium, there are many helper classes used here.
[View::Paint](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=1172;drc=abbfc06e9b070c9ea64af2b233624646cef00252) is responsible for painting stuff, so let's check the methods used inside here.
## PaintInfo
[PaintInfo](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/paint_info.h) is a class which manages the context for [View::Paint](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=1172;drc=abbfc06e9b070c9ea64af2b233624646cef00252).
PaintInfo is passed to View::Paint method itself, but there seems to be nothing special here. This class just stores a data to paint.
It stores
- paint_recording_scale_x_
- paint_recording_scale_y_
- paint_recording_bounds_
- offset_from_parent_
- context_
- root_context_
`paint_recording_bounds_` is relative to the root PaintInfo.
Some methods inside this such as GetSnappedRecordingBounds converts the position into the correct coordinates.
## ClipRecorder
[CliipRecorder](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/clip_recorder.h;l=25;drc=abbfc06e9b070c9ea64af2b233624646cef00252) class provides a scoped clip. It conveys the clip info to the children.
[ClipRect](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/clip_recorder.cc;l=30;drc=cf5c86ba22fcf6752ba8c5af6cde8bbc04e8e67f) specifies the `clip_rect` value and set it to [cc::DisplayItemList](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=50;drc=abbfc06e9b070c9ea64af2b233624646cef00252) as [ClipRectOp](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.h;l=342;drc=abbfc06e9b070c9ea64af2b233624646cef00252).
It will perform the clipping against all DisplayItems added to this list.
### [cc::DisplayItemList](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=50;drc=abbfc06e9b070c9ea64af2b233624646cef00252)
[cc::DisplayItemList](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=50;drc=abbfc06e9b070c9ea64af2b233624646cef00252) is a container of paint operations.
The operations are stored as [PaintOpBuffer](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=223;drc=abbfc06e9b070c9ea64af2b233624646cef00252)
## PaintRecorder
[PaintRecorder](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/paint_recorder.h;l=27;drc=abbfc06e9b070c9ea64af2b233624646cef00252) is used to hide the complexity behind setting up a recording into a DisplayItem.
~Recorder classes are a wrapper of DisplayItemList.
It records a refernce to [PaintContext](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/paint_context.h;l=22;drc=abbfc06e9b070c9ea64af2b233624646cef00252) which hols [DisplayItemList](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/paint_context.h;l=93;drc=abbfc06e9b070c9ea64af2b233624646cef00252).
## Paint methods in View
There are [four methods](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=2293-2316;drc=abbfc06e9b070c9ea64af2b233624646cef00252) implemented in view.
- PaintChildren
- OnPaint
- OnPaintBackground
- OnPintBorder
[Paint](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=1172;drc=abbfc06e9b070c9ea64af2b233624646cef00252) triggers [OnPaint](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=2298;drc=abbfc06e9b070c9ea64af2b233624646cef00252) after manipulating ClipRecorder, TranformRecorder and PaintRecorder. It implies that OnPaint is called after the content is painted.
Inside OnPaint, it calls [OnPaintBackground](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=2304;drc=abbfc06e9b070c9ea64af2b233624646cef00252) and [OnPaintBorder](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=2311;drc=abbfc06e9b070c9ea64af2b233624646cef00252).
Each of them interacts with [`background_`](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.h;l=2275;drc=abbfc06e9b070c9ea64af2b233624646cef00252) and [`border_`](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.h;l=2271;drc=abbfc06e9b070c9ea64af2b233624646cef00252) and call Paint for those views.
This painting is completed when all children views are done.