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