Flutter Engine
opacity_layer.h
Go to the documentation of this file.
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 
10 namespace 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.
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 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
31 
32  void Diff(DiffContext* context, const Layer* old_layer) override;
33 
34 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
35 
36  void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
37 
38  void Paint(PaintContext& context) const override;
39 
40  private:
41  SkAlpha alpha_;
42  SkPoint offset_;
43 
44  FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
45 };
46 
47 } // namespace flutter
48 
49 #endif // FLUTTER_FLOW_LAYERS_OPACITY_LAYER_H_
void Paint(PaintContext &context) const override
OpacityLayer(SkAlpha alpha, const SkPoint &offset)
void Preroll(PrerollContext *context, const SkMatrix &matrix) override