|
| 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/fuchsia_system_composited_layer.h" |
| 6 | + |
| 7 | +namespace flutter { |
| 8 | + |
| 9 | +FuchsiaSystemCompositedLayer::FuchsiaSystemCompositedLayer(SkColor color, |
| 10 | + SkAlpha opacity, |
| 11 | + float elevation) |
| 12 | + : ElevatedContainerLayer(elevation), color_(color), opacity_(opacity) {} |
| 13 | + |
| 14 | +void FuchsiaSystemCompositedLayer::Preroll(PrerollContext* context, |
| 15 | + const SkMatrix& matrix) { |
| 16 | + TRACE_EVENT0("flutter", "FuchsiaSystemCompositedLayer::Preroll"); |
| 17 | + |
| 18 | + const float parent_is_opaque = context->is_opaque; |
| 19 | + context->mutators_stack.PushOpacity(opacity_); |
| 20 | + context->is_opaque = parent_is_opaque && (opacity_ == SK_AlphaOPAQUE); |
| 21 | + ElevatedContainerLayer::Preroll(context, matrix); |
| 22 | + context->is_opaque = parent_is_opaque; |
| 23 | + context->mutators_stack.Pop(); |
| 24 | +} |
| 25 | + |
| 26 | +void FuchsiaSystemCompositedLayer::UpdateScene(SceneUpdateContext& context) { |
| 27 | + FML_DCHECK(needs_system_composite()); |
| 28 | + |
| 29 | + // Retained rendering: speedup by reusing a retained entity node if |
| 30 | + // possible. When an entity node is reused, no paint layer is added to the |
| 31 | + // frame so we won't call Paint. |
| 32 | + LayerRasterCacheKey key(unique_id(), context.Matrix()); |
| 33 | + if (context.HasRetainedNode(key)) { |
| 34 | + TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit"); |
| 35 | + const scenic::EntityNode& retained_node = context.GetRetainedNode(key); |
| 36 | + FML_DCHECK(context.top_entity()); |
| 37 | + FML_DCHECK(retained_node.session() == context.session()); |
| 38 | + context.top_entity()->embedder_node().AddChild(retained_node); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + TRACE_EVENT_INSTANT0("flutter", "retained cache miss, creating"); |
| 43 | + // If we can't find an existing retained surface, create one. |
| 44 | + SceneUpdateContext::Frame frame(context, rrect_, color_, opacity_ / 255.0f, |
| 45 | + elevation(), this); |
| 46 | + for (auto& layer : layers()) { |
| 47 | + if (layer->needs_painting()) { |
| 48 | + frame.AddPaintLayer(layer.get()); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + ElevatedContainerLayer::UpdateScene(context); |
| 53 | +} |
| 54 | + |
| 55 | +} // namespace flutter |
0 commit comments