Flutter Engine
 
Loading...
Searching...
No Matches
opacity_layer.cc
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
6
9
10namespace flutter {
11
12// the opacity_layer couldn't cache itself, so the cache_threshold is the
13// max_int
14OpacityLayer::OpacityLayer(uint8_t alpha, const DlPoint& offset)
15 : CacheableContainerLayer(std::numeric_limits<int>::max(), true),
16 alpha_(alpha),
17 offset_(offset) {}
18
19void OpacityLayer::Diff(DiffContext* context, const Layer* old_layer) {
20 DiffContext::AutoSubtreeRestore subtree(context);
21 auto* prev = static_cast<const OpacityLayer*>(old_layer);
22 if (!context->IsSubtreeDirty()) {
23 FML_DCHECK(prev);
24 if (alpha_ != prev->alpha_ || offset_ != prev->offset_) {
25 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
26 }
27 }
29 if (context->has_raster_cache()) {
31 }
32 DiffChildren(context, prev);
33 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
34}
35
37 auto mutator = context->state_stack.save();
38 mutator.translate(offset_);
39 mutator.applyOpacity(DlRect(), opacity());
40
41#if !SLIMPELLER
42 AutoCache auto_cache = AutoCache(layer_raster_cache_item_.get(), context,
43 context->state_stack.matrix());
44#endif // !SLIMPELLER
45
48
50 // We store the inheritance ability of our children for |Paint|
53 0);
54
55 // Now we let our parent layers know that we, too, can inherit opacity
56 // regardless of what our children are capable of
58
59 set_paint_bounds(paint_bounds().Shift(offset_));
60
61#if !SLIMPELLER
63 // For opacity layer, we can use raster_cache children only when the
64 // children can't accept opacity so if the children_can_accept_opacity we
65 // should tell the AutoCache object don't do raster_cache.
66 auto_cache.ShouldNotBeCached();
67 }
68#endif // !SLIMPELLER
69}
70
71void OpacityLayer::Paint(PaintContext& context) const {
72 FML_DCHECK(needs_painting(context));
73
74 auto mutator = context.state_stack.save();
75 mutator.translate(offset_.x, offset_.y);
76
77#if !SLIMPELLER
78 if (context.raster_cache) {
79 mutator.integralTransform();
80 }
81#endif // !SLIMPELLER
82
83 mutator.applyOpacity(child_paint_bounds(), opacity());
84
85#if !SLIMPELLER
87 DlPaint paint;
88 if (layer_raster_cache_item_->Draw(context,
89 context.state_stack.fill(paint))) {
90 return;
91 }
92 }
93#endif // !SLIMPELLER
94
95 PaintChildren(context);
96}
97
98} // namespace flutter
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Preroll(PrerollContext *context) override
const DlRect & child_paint_bounds() const
void PaintChildren(PaintContext &context) const override
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
void WillPaintWithIntegralTransform()
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
PaintRegion CurrentSubtreeRegion() const
bool has_raster_cache() const
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
bool IsSubtreeDirty() const
void PushTransform(const DlMatrix &transform)
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition layer.cc:37
void set_paint_bounds(const DlRect &paint_bounds)
Definition layer.h:209
bool needs_painting(PaintContext &context) const
Definition layer.h:218
const DlRect & paint_bounds() const
Definition layer.h:196
void translate(DlScalar tx, DlScalar ty)
void fill(MutatorsStack *mutators)
const DlMatrix matrix() const
static constexpr int kCallerCanApplyOpacity
void Diff(DiffContext *context, const Layer *old_layer) override
bool children_can_accept_opacity() const
void Preroll(PrerollContext *context) override
OpacityLayer(uint8_t alpha, const DlPoint &offset)
void Paint(PaintContext &context) const override
void set_children_can_accept_opacity(bool value)
DlScalar opacity() const
#define FML_DCHECK(condition)
Definition logging.h:122
impeller::Rect DlRect
Definition ref_ptr.h:261
LayerStateStack & state_stack
Definition layer.h:91
LayerStateStack & state_stack
Definition layer.h:49
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95