flutter_flutter/flow/layers/elevated_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

50 lines
1.8 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/elevated_container_layer.h"
namespace flutter {
namespace {
float ClampElevation(float elevation,
float parent_elevation,
float max_elevation) {
// TODO(mklim): Deal with bounds overflow more elegantly. We'd like to be
// able to have developers specify the behavior here to alternatives besides
// clamping, like normalization on some arbitrary curve.
float clamped_elevation = elevation;
if (max_elevation > -1 && (parent_elevation + elevation) > max_elevation) {
// Clamp the local z coordinate at our max bound. Take into account the
// parent z position here to fix clamping in cases where the child is
// overflowing because of its parents.
clamped_elevation = max_elevation - parent_elevation;
}
return clamped_elevation;
}
} // namespace
ElevatedContainerLayer::ElevatedContainerLayer(float elevation)
: elevation_(elevation), clamped_elevation_(elevation) {}
void ElevatedContainerLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "ElevatedContainerLayer::Preroll");
// Track total elevation as we walk the tree, in order to deal with bounds
// overflow in z.
parent_elevation_ = context->total_elevation;
clamped_elevation_ = ClampElevation(elevation_, parent_elevation_,
context->frame_physical_depth);
context->total_elevation += clamped_elevation_;
ContainerLayer::Preroll(context, matrix);
// Restore the elevation for our parent.
context->total_elevation = parent_elevation_;
}
} // namespace flutter