flutter_flutter/flow/layers/transform_layer.cc
David Worsham fcc4ab3230
[fuchsia] Wire up OpacityLayer to Scenic (#11322)
On Fuchsia, add a build flag for compositing OpacityLayers using the system
compositor vs Skia, which exposes a fastpath for opacity via Scenic.
This will only work under certain circumstances, in particular nested
OpacityLayers will not render correctly!

On Fuchsia, add a build flag for compositing PhysicalShapeLayers using
the system compositor vs Skia. Set to off by default, which restores
performant shadows on Fuchsia.

Remove the opacity exposed from ChildView, as that was added mistakenly.

Finally, we centralize the logic for switching between the
system-composited and in-process-composited paths inside of
ContainerLayer. We also centralize the logic for computing elevation
there. This allows the removal of many OS_FUCHSIA-specific code-paths.

Test: Ran workstation on Fuchsia; benchmarked before and after
Bug: 23711
Bug: 24163

* Fix broken tests
2019-09-25 12:48:42 -04:00

72 lines
2.4 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/transform_layer.h"
namespace flutter {
TransformLayer::TransformLayer(const SkMatrix& transform)
: transform_(transform) {
// Checks (in some degree) that SkMatrix transform_ is valid and initialized.
//
// If transform_ is uninitialized, this assert may look flaky as it doesn't
// fail all the time, and some rerun may make it pass. But don't ignore it and
// just rerun the test if this is triggered, since even a flaky failure here
// may signify a potentially big problem in the code.
//
// We have to write this flaky test because there is no reliable way to test
// whether a variable is initialized or not in C++.
FML_DCHECK(transform_.isFinite());
if (!transform_.isFinite()) {
FML_LOG(ERROR) << "TransformLayer is constructed with an invalid matrix.";
transform_.setIdentity();
}
}
TransformLayer::~TransformLayer() = default;
void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
SkMatrix child_matrix;
child_matrix.setConcat(matrix, transform_);
context->mutators_stack.PushTransform(transform_);
SkRect previous_cull_rect = context->cull_rect;
SkMatrix inverse_transform_;
// Perspective projections don't produce rectangles that are useful for
// culling for some reason.
if (!transform_.hasPerspective() && transform_.invert(&inverse_transform_)) {
inverse_transform_.mapRect(&context->cull_rect);
} else {
context->cull_rect = kGiantRect;
}
ContainerLayer::Preroll(context, child_matrix);
transform_.mapRect(paint_bounds());
context->cull_rect = previous_cull_rect;
context->mutators_stack.Pop();
}
void TransformLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "TransformLayer::Paint");
FML_DCHECK(needs_painting());
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->concat(transform_);
ContainerLayer::Paint(context);
}
void TransformLayer::UpdateScene(SceneUpdateContext& context) {
#if defined(OS_FUCHSIA)
FML_DCHECK(needs_system_composite());
SceneUpdateContext::Transform transform(context, transform_);
ContainerLayer::UpdateScene(context);
#endif // defined(OS_FUCHSIA)
}
} // namespace flutter