Flutter Engine
The 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
5#include "flutter/flow/layers/opacity_layer.h"
6
7#include "flutter/flow/layers/cacheable_layer.h"
8#include "flutter/flow/raster_cache_util.h"
10
11namespace flutter {
12
13// the opacity_layer couldn't cache itself, so the cache_threshold is the
14// max_int
16 : CacheableContainerLayer(std::numeric_limits<int>::max(), true),
17 alpha_(alpha),
18 offset_(offset) {}
19
20void OpacityLayer::Diff(DiffContext* context, const Layer* old_layer) {
21 DiffContext::AutoSubtreeRestore subtree(context);
22 auto* prev = static_cast<const OpacityLayer*>(old_layer);
23 if (!context->IsSubtreeDirty()) {
25 if (alpha_ != prev->alpha_ || offset_ != prev->offset_) {
26 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
27 }
28 }
29 context->PushTransform(SkMatrix::Translate(offset_.fX, offset_.fY));
30 if (context->has_raster_cache()) {
32 }
33 DiffChildren(context, prev);
34 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
35}
36
38 auto mutator = context->state_stack.save();
39 mutator.translate(offset_);
40 mutator.applyOpacity(SkRect(), DlColor::toOpacity(alpha_));
41
42 AutoCache auto_cache = AutoCache(layer_raster_cache_item_.get(), context,
43 context->state_stack.transform_3x3());
46
48 // We store the inheritance ability of our children for |Paint|
51 0);
52
53 // Now we let our parent layers know that we, too, can inherit opacity
54 // regardless of what our children are capable of
56
57 set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
58
60 // For opacity layer, we can use raster_cache children only when the
61 // children can't accept opacity so if the children_can_accept_opacity we
62 // should tell the AutoCache object don't do raster_cache.
63 auto_cache.ShouldNotBeCached();
64 }
65}
66
67void OpacityLayer::Paint(PaintContext& context) const {
68 FML_DCHECK(needs_painting(context));
69
70 auto mutator = context.state_stack.save();
71 mutator.translate(offset_.fX, offset_.fY);
72 if (context.raster_cache) {
73 mutator.integralTransform();
74 }
75
76 mutator.applyOpacity(child_paint_bounds(), opacity());
77
80 if (layer_raster_cache_item_->Draw(context,
81 context.state_stack.fill(paint))) {
82 return;
83 }
84 }
85
86 PaintChildren(context);
87}
88
89} // namespace flutter
static float prev(float f)
uint8_t SkAlpha
Definition SkColor.h:26
Type::kYUV Type::kRGBA() int(0.7 *637)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Preroll(PrerollContext *context) override
void PaintChildren(PaintContext &context) const override
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
const SkRect & child_paint_bounds() const
void PushTransform(const SkMatrix &transform)
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 translate(SkScalar tx, SkScalar ty)
void fill(MutatorsStack *mutators)
static constexpr int kCallerCanApplyOpacity
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition layer.cc:40
const SkRect & paint_bounds() const
Definition layer.h:209
bool needs_painting(PaintContext &context) const
Definition layer.h:231
void set_paint_bounds(const SkRect &paint_bounds)
Definition layer.h:222
void Diff(DiffContext *context, const Layer *old_layer) override
SkScalar opacity() const
bool children_can_accept_opacity() const
void Preroll(PrerollContext *context) override
void Paint(PaintContext &context) const override
void set_children_can_accept_opacity(bool value)
OpacityLayer(SkAlpha alpha, const SkPoint &offset)
const Paint & paint
#define FML_DCHECK(condition)
Definition logging.h:103
static float max(float r, float g, float b)
Definition hsl.cpp:49
Definition ref_ptr.h:256
Point offset
float fX
x-axis value
float fY
y-axis value
static constexpr SkScalar toOpacity(uint8_t alpha)
Definition dl_color.h:18
LayerStateStack & state_stack
Definition layer.h:100
const RasterCache * raster_cache
Definition layer.h:114
LayerStateStack & state_stack
Definition layer.h:58