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 
7 namespace flutter {
8 
9 ShaderMaskLayer::ShaderMaskLayer(sk_sp<SkShader> shader,
10  const SkRect& mask_rect,
11  SkBlendMode blend_mode)
12  : shader_(shader), mask_rect_(mask_rect), blend_mode_(blend_mode) {}
13 
14 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
15 
16 void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
17  DiffContext::AutoSubtreeRestore subtree(context);
18  auto* prev = static_cast<const ShaderMaskLayer*>(old_layer);
19  if (!context->IsSubtreeDirty()) {
20  FML_DCHECK(prev);
21  if (shader_ != prev->shader_ || mask_rect_ != prev->mask_rect_ ||
22  blend_mode_ != prev->blend_mode_) {
23  context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
24  }
25  }
26 
27  DiffChildren(context, prev);
28 
29  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
30 }
31 
32 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
33 
34 void ShaderMaskLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
37  ContainerLayer::Preroll(context, matrix);
38 }
39 
40 void ShaderMaskLayer::Paint(PaintContext& context) const {
41  TRACE_EVENT0("flutter", "ShaderMaskLayer::Paint");
42  FML_DCHECK(needs_painting(context));
43 
45  Layer::AutoSaveLayer::Create(context, paint_bounds(), nullptr);
46  PaintChildren(context);
47 
48  SkPaint paint;
49  paint.setBlendMode(blend_mode_);
50  paint.setShader(shader_);
51  context.leaf_nodes_canvas->translate(mask_rect_.left(), mask_rect_.top());
52  context.leaf_nodes_canvas->drawRect(
53  SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint);
54 }
55 
56 } // namespace flutter
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
ShaderMaskLayer(sk_sp< SkShader > shader, const SkRect &mask_rect, SkBlendMode blend_mode)
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:44
const SkRect & paint_bounds() const
Definition: layer.h:227
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
SkCanvas * leaf_nodes_canvas
Definition: layer.h:145
void Paint(PaintContext &context) const override
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void PaintChildren(PaintContext &context) const
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint, SaveMode save_mode=SaveMode::kInternalNodesCanvas)
Definition: layer.cc:82