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 | void ShaderMaskLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { |
15 | #if defined(LEGACY_FUCHSIA_EMBEDDER) |
16 | CheckForChildLayerBelow(context); |
17 | #endif |
18 | |
19 | Layer::AutoPrerollSaveLayerState save = |
20 | Layer::AutoPrerollSaveLayerState::Create(context); |
21 | ContainerLayer::Preroll(context, matrix); |
22 | } |
23 | |
24 | void ShaderMaskLayer::Paint(PaintContext& context) const { |
25 | TRACE_EVENT0("flutter" , "ShaderMaskLayer::Paint" ); |
26 | FML_DCHECK(needs_painting()); |
27 | |
28 | Layer::AutoSaveLayer save = |
29 | Layer::AutoSaveLayer::Create(context, paint_bounds(), nullptr); |
30 | PaintChildren(context); |
31 | |
32 | SkPaint paint; |
33 | paint.setBlendMode(blend_mode_); |
34 | paint.setShader(shader_); |
35 | context.leaf_nodes_canvas->translate(mask_rect_.left(), mask_rect_.top()); |
36 | context.leaf_nodes_canvas->drawRect( |
37 | SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint); |
38 | } |
39 | |
40 | } // namespace flutter |
41 | |