# DisplayItemList [DisplayItemList](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=50;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) is a container of paint operations represented as [PaintOp](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.h;l=107;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) such as ClipRectOp, DrawColorOp ... Let's see what it does. ## How to use DisplayItemList It starts painting from [StartPaint](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=68;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). Then [push](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=80;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) the operations to the list. After pushing all of the operations, end painting with [EndPaintOfPairedBegin](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.h;l=108;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). ```cpp= context_->list_->StartPaint(); context_->list_->push<cc::SaveOp>(); context_->list_->push<cc::ClipRectOp>(gfx::RectToSkRect(clip_rect), SkClipOp::kIntersect, antialias); context_->list_->EndPaintOfPairedBegin(); ``` Actually StartPaint implementation is empty for production build, so it's just used as a marker. (Only implemented meaningfully on debug build) ## PaintOpBuffer [PaintOpBuffer](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op_buffer.h;l=101;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) is a buffer to carry PaintOp elements. It's stored as [`data_`](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op_buffer.h;l=362;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). To run registered operations, [PaintOpBuffer::Playback](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op_buffer.cc;l=186;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) is called. Playback calls each operation's Raster [here](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op_buffer.cc;l=239-254;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). [PaintOp::Raster](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.cc;l=1661;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) calls raster functions corresponds to the operation type registered as [`type`](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.h;l=109;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). Each types of operation is implemented like [ClipRectOp](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.h;l=342;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). Raster implementaiton of ClipRectOp is [ClipRectOp::Raster](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/paint_op.cc;l=1069;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) below: ```cpp= void ClipRectOp::Raster(const ClipRectOp* op, SkCanvas* canvas, const PlaybackParams& params) { canvas->clipRect(op->rect, op->op, op->antialias); } ``` Other looks relatively the same, so what PaintOp does is basically a bypass to gfx::Canvas which goes to cc. [DisplayItemList::Raster](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.cc;l=81;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) gets the clip bounds via [GetCanvasClipBounds](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.cc;l=29;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6) and start rasterization. Raster starts operation from `offset` in the buffer, and [Playback](https://source.chromium.org/chromium/chromium/src/+/main:cc/paint/display_item_list.cc;l=91;drc=88d87ae50728261cfdbf77ae493a8d506eaf42e6). Operation types are ```cpp= #define TYPES(M) \ M(AnnotateOp) \ M(ClipPathOp) \ M(ClipRectOp) \ M(ClipRRectOp) \ M(ConcatOp) \ M(CustomDataOp) \ M(DrawColorOp) \ M(DrawDRRectOp) \ M(DrawImageOp) \ M(DrawImageRectOp) \ M(DrawIRectOp) \ M(DrawLineOp) \ M(DrawOvalOp) \ M(DrawPathOp) \ M(DrawRecordOp) \ M(DrawRectOp) \ M(DrawRRectOp) \ M(DrawSkottieOp) \ M(DrawSlugOp) \ M(DrawTextBlobOp) \ M(NoopOp) \ M(RestoreOp) \ M(RotateOp) \ M(SaveOp) \ M(SaveLayerOp) \ M(SaveLayerAlphaOp) \ M(ScaleOp) \ M(SetMatrixOp) \ M(SetNodeIdOp) \ M(TranslateOp) ```