|
| 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( |
| 10 | + SkColor color, |
| 11 | + float elevation) |
| 12 | + : ElevatedContainerLayer(elevation), color_(color) {} |
| 13 | + |
| 14 | +void FuchsiaSystemCompositedLayer::Preroll(PrerollContext* context, |
| 15 | + const SkMatrix& matrix) { |
| 16 | + TRACE_EVENT0("flutter", "FuchsiaSystemCompositedLayer::Preroll"); |
| 17 | +#if !defined(OS_FUCHSIA) |
| 18 | + FML_NOTIMPLEMENTED(); |
| 19 | +#endif // !defined(OS_FUCHSIA) |
| 20 | + |
| 21 | + ElevatedContainerLayer::Preroll(context, matrix); |
| 22 | + |
| 23 | + // System-composite this layer if its elevated. |
| 24 | + if (elevation() != 0.0f) { |
| 25 | + set_needs_system_composite(true); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +void FuchsiaSystemCompositedLayer::Paint(PaintContext& context) const { |
| 30 | + TRACE_EVENT0("flutter", "FuchsiaSystemCompositedLayer::Paint"); |
| 31 | +#if !defined(OS_FUCHSIA) |
| 32 | + FML_NOTIMPLEMENTED(); |
| 33 | +#endif // !defined(OS_FUCHSIA) |
| 34 | + |
| 35 | + // TODO: hole punch |
| 36 | + // If this is actually called, it's because flow is attempting to paint this |
| 37 | + // layer onto the frame behind it which gives us a chance to hole-punch |
| 38 | +} |
| 39 | + |
| 40 | +#if defined(OS_FUCHSIA) |
| 41 | + |
| 42 | +void FuchsiaSystemCompositedLayer::UpdateScene( |
| 43 | + SceneUpdateContext& context) { |
| 44 | + FML_DCHECK(needs_system_composite()); |
| 45 | + |
| 46 | + // Retained rendering: speedup by reusing a retained entity node if |
| 47 | + // possible. When an entity node is reused, no paint layer is added to the |
| 48 | + // frame so we won't call Paint. |
| 49 | + LayerRasterCacheKey key(unique_id(), context.Matrix()); |
| 50 | + if (context.HasRetainedNode(key)) { |
| 51 | + TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit"); |
| 52 | + const scenic::EntityNode& retained_node = context.GetRetainedNode(key); |
| 53 | + FML_DCHECK(context.top_entity()); |
| 54 | + FML_DCHECK(retained_node.session() == context.session()); |
| 55 | + context.top_entity()->embedder_node().AddChild(retained_node); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + TRACE_EVENT_INSTANT0("flutter", "retained cache miss, creating"); |
| 60 | + // If we can't find an existing retained surface, create one. |
| 61 | + SceneUpdateContext::Frame frame(context, rrect_, color_, elevation(), this); |
| 62 | + for (auto& layer : layers()) { |
| 63 | + if (layer->needs_painting()) { |
| 64 | + frame.AddPaintLayer(layer.get()); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + ContainerLayer::UpdateScene(context); |
| 69 | +} |
| 70 | + |
| 71 | +#endif // defined(OS_FUCHSIA) |
| 72 | + |
| 73 | +} // namespace flutter |
0 commit comments