Flutter Engine
clip_path_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/clip_path_layer.h"
6 #include "flutter/flow/paint_utils.h"
7 
8 #if defined(LEGACY_FUCHSIA_EMBEDDER)
9 #include "lib/ui/scenic/cpp/commands.h"
10 #endif
11 
12 namespace flutter {
13 
14 ClipPathLayer::ClipPathLayer(const SkPath& clip_path, Clip clip_behavior)
15  : clip_path_(clip_path), clip_behavior_(clip_behavior) {
16  FML_DCHECK(clip_behavior != Clip::none);
17 }
18 
19 void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
20  TRACE_EVENT0("flutter", "ClipPathLayer::Preroll");
21 
22  SkRect previous_cull_rect = context->cull_rect;
23  SkRect clip_path_bounds = clip_path_.getBounds();
24  children_inside_clip_ = context->cull_rect.intersect(clip_path_bounds);
25  if (children_inside_clip_) {
26  TRACE_EVENT_INSTANT0("flutter", "children inside clip rect");
27 
30  context->mutators_stack.PushClipPath(clip_path_);
31  SkRect child_paint_bounds = SkRect::MakeEmpty();
32  PrerollChildren(context, matrix, &child_paint_bounds);
33 
34  if (child_paint_bounds.intersect(clip_path_bounds)) {
35  set_paint_bounds(child_paint_bounds);
36  }
37  context->mutators_stack.Pop();
38  }
39  context->cull_rect = previous_cull_rect;
40 }
41 
42 #if defined(LEGACY_FUCHSIA_EMBEDDER)
43 
44 void ClipPathLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
45  TRACE_EVENT0("flutter", "ClipPathLayer::UpdateScene");
47 
48  // TODO(liyuqian): respect clip_behavior_
49  SceneUpdateContext::Clip clip(context, clip_path_.getBounds());
50  UpdateSceneChildren(context);
51 }
52 
53 #endif
54 
55 void ClipPathLayer::Paint(PaintContext& context) const {
56  TRACE_EVENT0("flutter", "ClipPathLayer::Paint");
58 
59  if (!children_inside_clip_) {
60  TRACE_EVENT_INSTANT0("flutter", "children not inside clip rect, skipping");
61  return;
62  }
63 
64  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
65  context.internal_nodes_canvas->clipPath(clip_path_,
66  clip_behavior_ != Clip::hardEdge);
67 
68  if (UsesSaveLayer()) {
69  context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
70  }
71  PaintChildren(context);
72  if (UsesSaveLayer()) {
73  context.internal_nodes_canvas->restore();
74  if (context.checkerboard_offscreen_layers) {
76  }
77  }
78 }
79 
80 } // namespace flutter
void Paint(PaintContext &context) const override
const bool checkerboard_offscreen_layers
Definition: layer.h:123
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
void PushClipPath(const SkPath &path)
#define FML_DCHECK(condition)
Definition: logging.h:86
#define TRACE_EVENT_INSTANT0(category_group, name)
Definition: trace_event.h:104
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
ClipPathLayer(const SkPath &clip_path, Clip clip_behavior=Clip::antiAlias)
bool UsesSaveLayer() const
bool needs_system_composite() const
Definition: layer.h:161
bool needs_painting() const
Definition: layer.h:174
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:43
const SkRect & paint_bounds() const
Definition: layer.h:166
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:170
Clip
Definition: layer.h:41
SkCanvas * internal_nodes_canvas
Definition: layer.h:115
MutatorsStack & mutators_stack
Definition: layer.h:47
void DrawCheckerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: paint_utils.cc:28
void PaintChildren(PaintContext &context) const