Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
41 context->state_stack.transform_3x3());
42
44 // We always paint with a saveLayer (or a cached rendering),
45 // so we can always apply opacity in any of those cases.
47}
48
50 FML_DCHECK(needs_painting(context));
51
52 auto mutator = context.state_stack.save();
53
54 if (context.raster_cache) {
55 mutator.integralTransform();
56
58 if (layer_raster_cache_item_->Draw(context,
59 context.state_stack.fill(paint))) {
60 return;
61 }
62 }
63 auto shader_rect = SkRect::MakeWH(mask_rect_.width(), mask_rect_.height());
64
65 mutator.saveLayer(paint_bounds());
66
67 PaintChildren(context);
68
69 DlPaint dl_paint;
70 dl_paint.setBlendMode(blend_mode_);
71 if (color_source_) {
72 dl_paint.setColorSource(color_source_.get());
73 }
74 context.canvas->Translate(mask_rect_.left(), mask_rect_.top());
75 context.canvas->DrawRect(shader_rect, dl_paint);
76}
77
78} // 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()
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
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:87
DlPaint & setColorSource(std::shared_ptr< const DlColorSource > source)
Definition dl_paint.h:132
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:209
static constexpr int kSaveLayerRenderFlags
Definition layer.h:131
bool needs_painting(PaintContext &context) const
Definition layer.h:231
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
#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:101
LayerStateStack & state_stack
Definition layer.h:100
const RasterCache * raster_cache
Definition layer.h:114
LayerStateStack & state_stack
Definition layer.h:58