1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/flow/layers/container_layer.h"
6
7 namespace flutter {
8
ContainerLayer()9 ContainerLayer::ContainerLayer() {}
10
11 ContainerLayer::~ContainerLayer() = default;
12
Add(std::shared_ptr<Layer> layer)13 void ContainerLayer::Add(std::shared_ptr<Layer> layer) {
14 layer->set_parent(this);
15 layers_.push_back(std::move(layer));
16 }
17
Preroll(PrerollContext * context,const SkMatrix & matrix)18 void ContainerLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
19 TRACE_EVENT0("flutter", "ContainerLayer::Preroll");
20
21 SkRect child_paint_bounds = SkRect::MakeEmpty();
22 PrerollChildren(context, matrix, &child_paint_bounds);
23 set_paint_bounds(child_paint_bounds);
24 }
25
PrerollChildren(PrerollContext * context,const SkMatrix & child_matrix,SkRect * child_paint_bounds)26 void ContainerLayer::PrerollChildren(PrerollContext* context,
27 const SkMatrix& child_matrix,
28 SkRect* child_paint_bounds) {
29 for (auto& layer : layers_) {
30 layer->Preroll(context, child_matrix);
31
32 if (layer->needs_system_composite()) {
33 set_needs_system_composite(true);
34 }
35 child_paint_bounds->join(layer->paint_bounds());
36 }
37 }
38
PaintChildren(PaintContext & context) const39 void ContainerLayer::PaintChildren(PaintContext& context) const {
40 FML_DCHECK(needs_painting());
41
42 // Intentionally not tracing here as there should be no self-time
43 // and the trace event on this common function has a small overhead.
44 for (auto& layer : layers_) {
45 if (layer->needs_painting()) {
46 layer->Paint(context);
47 }
48 }
49 }
50
51 #if defined(OS_FUCHSIA)
52
UpdateScene(SceneUpdateContext & context)53 void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
54 UpdateSceneChildren(context);
55 }
56
UpdateSceneChildren(SceneUpdateContext & context)57 void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) {
58 FML_DCHECK(needs_system_composite());
59
60 // Paint all of the layers which need to be drawn into the container.
61 // These may be flattened down to a containing
62 for (auto& layer : layers_) {
63 if (layer->needs_system_composite()) {
64 layer->UpdateScene(context);
65 }
66 }
67 }
68
69 #endif // defined(OS_FUCHSIA)
70
71 } // namespace flutter
72