Flutter Engine
clip_rrect_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_rrect_layer.h"
6 #include "flutter/flow/paint_utils.h"
7 
8 namespace flutter {
9 
10 ClipRRectLayer::ClipRRectLayer(const SkRRect& clip_rrect, Clip clip_behavior)
11  : clip_rrect_(clip_rrect), clip_behavior_(clip_behavior) {
12  FML_DCHECK(clip_behavior != Clip::none);
13 }
14 
15 void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
16  TRACE_EVENT0("flutter", "ClipRRectLayer::Preroll");
17 
18  SkRect previous_cull_rect = context->cull_rect;
19  SkRect clip_rrect_bounds = clip_rrect_.getBounds();
20  children_inside_clip_ = context->cull_rect.intersect(clip_rrect_bounds);
21  if (children_inside_clip_) {
22  TRACE_EVENT_INSTANT0("flutter", "children inside clip rect");
23 
26  context->mutators_stack.PushClipRRect(clip_rrect_);
27  SkRect child_paint_bounds = SkRect::MakeEmpty();
28  PrerollChildren(context, matrix, &child_paint_bounds);
29 
30  if (child_paint_bounds.intersect(clip_rrect_bounds)) {
31  set_paint_bounds(child_paint_bounds);
32  }
33  context->mutators_stack.Pop();
34  }
35  context->cull_rect = previous_cull_rect;
36 }
37 
38 #if defined(LEGACY_FUCHSIA_EMBEDDER)
39 
40 void ClipRRectLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
41  TRACE_EVENT0("flutter", "ClipRRectLayer::UpdateScene");
43 
44  // TODO(liyuqian): respect clip_behavior_
45  SceneUpdateContext::Clip clip(context, clip_rrect_.getBounds());
46  UpdateSceneChildren(context);
47 }
48 
49 #endif
50 
51 void ClipRRectLayer::Paint(PaintContext& context) const {
52  TRACE_EVENT0("flutter", "ClipRRectLayer::Paint");
54 
55  if (!children_inside_clip_) {
56  TRACE_EVENT_INSTANT0("flutter", "children not inside clip rect, skipping");
57  return;
58  }
59 
60  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
61  context.internal_nodes_canvas->clipRRect(clip_rrect_,
62  clip_behavior_ != Clip::hardEdge);
63 
64  if (UsesSaveLayer()) {
65  context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
66  }
67  PaintChildren(context);
68  if (UsesSaveLayer()) {
69  context.internal_nodes_canvas->restore();
70  if (context.checkerboard_offscreen_layers) {
72  }
73  }
74 }
75 
76 } // namespace flutter
const bool checkerboard_offscreen_layers
Definition: layer.h:123
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#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)
void Paint(PaintContext &context) const override
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
ClipRRectLayer(const SkRRect &clip_rrect, Clip clip_behavior)
void PushClipRRect(const SkRRect &rrect)
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