flutter_flutter/flow/layers/container_layer.cc
Kaushik Iska f2dbeb8aa7
Reland Wire up Opacity on Fuchsia (#14559)
This reverts commit 6ea69a0d4339dd153899bb6c299689f1dd43329d.

On top of the revert, it reverted a commit in the PR:
https://github.com/flutter/engine/pull/14024

This reverts commit ea67e5b0b930ebf552bc7dbd678a35ee6a129c39.
2019-12-18 16:05:38 -08:00

89 lines
2.6 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/layers/container_layer.h"
namespace flutter {
ContainerLayer::ContainerLayer() {}
void ContainerLayer::Add(std::shared_ptr<Layer> layer) {
layers_.emplace_back(std::move(layer));
}
void ContainerLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "ContainerLayer::Preroll");
SkRect child_paint_bounds = SkRect::MakeEmpty();
PrerollChildren(context, matrix, &child_paint_bounds);
set_paint_bounds(child_paint_bounds);
}
void ContainerLayer::Paint(PaintContext& context) const {
FML_DCHECK(needs_painting());
PaintChildren(context);
}
void ContainerLayer::PrerollChildren(PrerollContext* context,
const SkMatrix& child_matrix,
SkRect* child_paint_bounds) {
// Platform views have no children, so context->has_platform_view should
// always be false.
FML_DCHECK(!context->has_platform_view);
bool child_has_platform_view = false;
for (auto& layer : layers_) {
// Reset context->has_platform_view to false so that layers aren't treated
// as if they have a platform view based on one being previously found in a
// sibling tree.
context->has_platform_view = false;
layer->Preroll(context, child_matrix);
if (layer->needs_system_composite()) {
set_needs_system_composite(true);
}
child_paint_bounds->join(layer->paint_bounds());
child_has_platform_view =
child_has_platform_view || context->has_platform_view;
}
context->has_platform_view = child_has_platform_view;
}
void ContainerLayer::PaintChildren(PaintContext& context) const {
FML_DCHECK(needs_painting());
// Intentionally not tracing here as there should be no self-time
// and the trace event on this common function has a small overhead.
for (auto& layer : layers_) {
if (layer->needs_painting()) {
layer->Paint(context);
}
}
}
#if defined(OS_FUCHSIA)
void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
UpdateSceneChildren(context);
}
void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) {
FML_DCHECK(needs_system_composite());
// Paint all of the layers which need to be drawn into the container.
// These may be flattened down to a containing
for (auto& layer : layers_) {
if (layer->needs_system_composite()) {
layer->UpdateScene(context);
}
}
}
#endif // defined(OS_FUCHSIA)
} // namespace flutter