Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
10
11namespace flutter {
12
13// Don't add an OpacityLayer with no children to the layer tree. Painting an
14// OpacityLayer is very costly due to the saveLayer call. If there's no child,
15// having the OpacityLayer or not has the same effect. In debug_unopt build,
16// |Preroll| will assert if there are no children.
18 public:
19 // An offset is provided here because OpacityLayer.addToScene method in the
20 // Flutter framework can take an optional offset argument.
21 //
22 // By default, that offset is always zero, and all the offsets are handled by
23 // some parent TransformLayers. But we allow the offset to be non-zero for
24 // backward compatibility. If it's non-zero, the old behavior is to propage
25 // that offset to all the leaf layers (e.g., DisplayListLayer). That will make
26 // the retained rendering inefficient as a small offset change could propagate
27 // to many leaf layers. Therefore we try to capture that offset here to stop
28 // the propagation as repainting the OpacityLayer is expensive.
29 OpacityLayer(uint8_t alpha, const DlPoint& offset);
30
31 void Diff(DiffContext* context, const Layer* old_layer) override;
32
33 void Preroll(PrerollContext* context) override;
34
35 void Paint(PaintContext& context) const override;
36
37 // Returns whether the children are capable of inheriting an opacity value
38 // and modifying their rendering accordingly. This value is only guaranteed
39 // to be valid after the local |Preroll| method is called.
41 return children_can_accept_opacity_;
42 }
44 children_can_accept_opacity_ = value;
45 }
46
47 DlScalar opacity() const { return DlColor::toOpacity(alpha_); }
48
49 private:
50 uint8_t alpha_;
51 DlPoint offset_;
52 bool children_can_accept_opacity_ = false;
53
55};
56
57} // namespace flutter
58
59#endif // FLUTTER_FLOW_LAYERS_OPACITY_LAYER_H_
void Diff(DiffContext *context, const Layer *old_layer) override
bool children_can_accept_opacity() const
void Preroll(PrerollContext *context) override
void set_children_can_accept_opacity(bool value)
DlScalar opacity() const
int32_t value
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
impeller::Scalar DlScalar
static constexpr DlScalar toOpacity(uint8_t alpha)
Definition dl_color.h:65