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#ifndef FLUTTER_FLOW_LAYERS_OPACITY_LAYER_H_
6#define FLUTTER_FLOW_LAYERS_OPACITY_LAYER_H_
7
8#include "flutter/flow/layers/container_layer.h"
9
10namespace flutter {
11
12// Don't add an OpacityLayer with no children to the layer tree. Painting an
13// OpacityLayer is very costly due to the saveLayer call. If there's no child,
14// having the OpacityLayer or not has the same effect. In debug_unopt build,
15// |Preroll| will assert if there are no children.
16class OpacityLayer : public MergedContainerLayer {
17 public:
18 // An offset is provided here because OpacityLayer.addToScene method in the
19 // Flutter framework can take an optional offset argument.
20 //
21 // By default, that offset is always zero, and all the offsets are handled by
22 // some parent TransformLayers. But we allow the offset to be non-zero for
23 // backward compatibility. If it's non-zero, the old behavior is to propage
24 // that offset to all the leaf layers (e.g., PictureLayer). That will make
25 // the retained rendering inefficient as a small offset change could propagate
26 // to many leaf layers. Therefore we try to capture that offset here to stop
27 // the propagation as repainting the OpacityLayer is expensive.
28 OpacityLayer(SkAlpha alpha, const SkPoint& offset);
29
30 void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
31
32 void Paint(PaintContext& context) const override;
33
34#if defined(LEGACY_FUCHSIA_EMBEDDER)
35 void UpdateScene(SceneUpdateContext& context) override;
36#endif
37
38 private:
39 SkAlpha alpha_;
40 SkPoint offset_;
41
42 FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
43};
44
45} // namespace flutter
46
47#endif // FLUTTER_FLOW_LAYERS_OPACITY_LAYER_H_
48