Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
color_filter_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/color_filter_layer.h"
6
7#include "flutter/display_list/dl_paint.h"
8#include "flutter/display_list/utils/dl_comparable.h"
9#include "flutter/flow/raster_cache_item.h"
10#include "flutter/flow/raster_cache_util.h"
11
12namespace flutter {
13
14ColorFilterLayer::ColorFilterLayer(std::shared_ptr<const DlColorFilter> filter)
16 RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer,
17 true),
18 filter_(std::move(filter)) {}
19
20void ColorFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
21 DiffContext::AutoSubtreeRestore subtree(context);
22 auto* prev = static_cast<const ColorFilterLayer*>(old_layer);
23 if (!context->IsSubtreeDirty()) {
25 if (NotEquals(filter_, prev->filter_)) {
26 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
27 }
28 }
29
30 if (context->has_raster_cache()) {
32 }
33
34 DiffChildren(context, prev);
35
36 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
37}
38
43 context->state_stack.transform_3x3());
44
46
47 // Our saveLayer would apply any outstanding opacity or any outstanding
48 // image filter before it applies our color filter, but that is in the
49 // wrong order compared to how these attributes were applied to the tree
50 // (they would have come from one of our ancestors). So we cannot apply
51 // those attributes with our saveLayer normally.
52 // However, some color filters can commute themselves with an opacity
53 // modulation so in that case we can apply the opacity on behalf of our
54 // ancestors - otherwise we can apply no attributes.
55 if (filter_) {
56 context->renderable_state_flags =
57 filter_->can_commute_with_opacity()
59 : 0;
60 }
61 // else - we can apply whatever our children can apply.
62}
63
65 FML_DCHECK(needs_painting(context));
66
67 auto mutator = context.state_stack.save();
68
69 if (context.raster_cache) {
70 // Always apply the integral transform in the presence of a raster cache
71 // whether or not we will draw from the cache
72 mutator.integralTransform();
73
74 // Try drawing the layer cache item from the cache before applying the
75 // color filter if it was cached with the filter applied.
76 if (!layer_raster_cache_item_->IsCacheChildren()) {
78 if (layer_raster_cache_item_->Draw(context,
79 context.state_stack.fill(paint))) {
80 return;
81 }
82 }
83 }
84
85 // Now apply the color filter and then try rendering children either from
86 // cache or directly.
87 mutator.applyColorFilter(paint_bounds(), filter_);
88
89 if (context.raster_cache && layer_raster_cache_item_->IsCacheChildren()) {
91 if (layer_raster_cache_item_->Draw(context,
92 context.state_stack.fill(paint))) {
93 return;
94 }
95 }
96
97 PaintChildren(context);
98}
99
100} // namespace flutter
static float prev(float f)
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Preroll(PrerollContext *context) override
ColorFilterLayer(std::shared_ptr< const DlColorFilter > filter)
void Paint(PaintContext &context) const override
void Diff(DiffContext *context, const Layer *old_layer) override
void Preroll(PrerollContext *context) override
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 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
const Paint & paint
#define FML_DCHECK(condition)
Definition logging.h:103
bool NotEquals(const T *a, const T *b)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
Definition ref_ptr.h:256
LayerStateStack & state_stack
Definition layer.h:100
const RasterCache * raster_cache
Definition layer.h:114
LayerStateStack & state_stack
Definition layer.h:58