Flutter Engine
The Flutter Engine
shader_mask_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/shader_mask_layer.h"
6#include "flutter/flow/raster_cache_util.h"
7
8namespace flutter {
9
10ShaderMaskLayer::ShaderMaskLayer(std::shared_ptr<DlColorSource> color_source,
11 const SkRect& mask_rect,
12 DlBlendMode blend_mode)
14 RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer),
15 color_source_(std::move(color_source)),
16 mask_rect_(mask_rect),
17 blend_mode_(blend_mode) {}
18
19void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
20 DiffContext::AutoSubtreeRestore subtree(context);
21 auto* prev = static_cast<const ShaderMaskLayer*>(old_layer);
22 if (!context->IsSubtreeDirty()) {
24 if (color_source_ != prev->color_source_ ||
25 mask_rect_ != prev->mask_rect_ || blend_mode_ != prev->blend_mode_) {
26 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
27 }
28 }
29 if (context->has_raster_cache()) {
31 }
32 DiffChildren(context, prev);
33
34 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
35}
36
40#if !SLIMPELLER
42 context->state_stack.transform_3x3());
43#endif // !SLIMPELLER
45 // We always paint with a saveLayer (or a cached rendering),
46 // so we can always apply opacity in any of those cases.
48}
49
51 FML_DCHECK(needs_painting(context));
52
53 auto mutator = context.state_stack.save();
54
55#if !SLIMPELLER
56 if (context.raster_cache) {
57 mutator.integralTransform();
58
60 if (layer_raster_cache_item_->Draw(context,
61 context.state_stack.fill(paint))) {
62 return;
63 }
64 }
65#endif // !SLIMPELLER
66 auto shader_rect = SkRect::MakeWH(mask_rect_.width(), mask_rect_.height());
67
68 mutator.saveLayer(paint_bounds());
69
70 PaintChildren(context);
71
72 DlPaint dl_paint;
73 dl_paint.setBlendMode(blend_mode_);
74 if (color_source_) {
75 dl_paint.setColorSource(color_source_.get());
76 }
77 context.canvas->Translate(mask_rect_.left(), mask_rect_.top());
78 context.canvas->DrawRect(shader_rect, dl_paint);
79}
80
81} // namespace flutter
static float prev(float f)
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)
void WillPaintWithIntegralTransform()
Definition: diff_context.h:89
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
PaintRegion CurrentSubtreeRegion() const
bool has_raster_cache() const
Definition: diff_context.h:167
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
bool IsSubtreeDirty() const
Definition: diff_context.h:108
virtual void DrawRect(const SkRect &rect, const DlPaint &paint)=0
virtual void Translate(SkScalar tx, SkScalar ty)=0
DlPaint & setBlendMode(DlBlendMode mode)
Definition: dl_paint.h:86
DlPaint & setColorSource(std::shared_ptr< const DlColorSource > source)
Definition: dl_paint.h:131
SkMatrix transform_3x3() const
void fill(MutatorsStack *mutators)
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:210
static constexpr int kSaveLayerRenderFlags
Definition: layer.h:132
bool needs_painting(PaintContext &context) const
Definition: layer.h:232
void Diff(DiffContext *context, const Layer *old_layer) override
void Paint(PaintContext &context) const override
void Preroll(PrerollContext *context) override
ShaderMaskLayer(std::shared_ptr< DlColorSource > color_source, const SkRect &mask_rect, DlBlendMode blend_mode)
const Paint & paint
Definition: color_source.cc:38
#define FML_DCHECK(condition)
Definition: logging.h:103
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
constexpr float left() const
Definition: SkRect.h:734
constexpr float top() const
Definition: SkRect.h:741
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
DlCanvas * canvas
Definition: layer.h:102
LayerStateStack & state_stack
Definition: layer.h:101
LayerStateStack & state_stack
Definition: layer.h:59
int renderable_state_flags
Definition: layer.h:83