Flutter Engine
clip_rect_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_rect_layer.h"
6 #include "flutter/flow/paint_utils.h"
7 
8 namespace flutter {
9 
10 ClipRectLayer::ClipRectLayer(const SkRect& clip_rect, Clip clip_behavior)
11  : clip_rect_(clip_rect), clip_behavior_(clip_behavior) {
12  FML_DCHECK(clip_behavior != Clip::none);
13 }
14 
15 void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
16  TRACE_EVENT0("flutter", "ClipRectLayer::Preroll");
17 
18  SkRect previous_cull_rect = context->cull_rect;
19  children_inside_clip_ = context->cull_rect.intersect(clip_rect_);
20  if (children_inside_clip_) {
21  TRACE_EVENT_INSTANT0("flutter", "children inside clip rect");
22 
25  context->mutators_stack.PushClipRect(clip_rect_);
26  SkRect child_paint_bounds = SkRect::MakeEmpty();
27  PrerollChildren(context, matrix, &child_paint_bounds);
28 
29  if (child_paint_bounds.intersect(clip_rect_)) {
30  set_paint_bounds(child_paint_bounds);
31  }
32  context->mutators_stack.Pop();
33  }
34  context->cull_rect = previous_cull_rect;
35 }
36 
37 #if defined(LEGACY_FUCHSIA_EMBEDDER)
38 
39 void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
40  TRACE_EVENT0("flutter", "ClipRectLayer::UpdateScene");
42 
43  // TODO(liyuqian): respect clip_behavior_
44  SceneUpdateContext::Clip clip(context, clip_rect_);
45  UpdateSceneChildren(context);
46 }
47 
48 #endif
49 
50 void ClipRectLayer::Paint(PaintContext& context) const {
51  TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
53 
54  if (!children_inside_clip_) {
55  TRACE_EVENT_INSTANT0("flutter", "children not inside clip rect, skipping");
56  return;
57  }
58 
59  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
60  context.internal_nodes_canvas->clipRect(clip_rect_,
61  clip_behavior_ != Clip::hardEdge);
62 
63  if (UsesSaveLayer()) {
64  context.internal_nodes_canvas->saveLayer(clip_rect_, nullptr);
65  }
66  PaintChildren(context);
67  if (UsesSaveLayer()) {
68  context.internal_nodes_canvas->restore();
69  if (context.checkerboard_offscreen_layers) {
70  DrawCheckerboard(context.internal_nodes_canvas, clip_rect_);
71  }
72  }
73 }
74 
75 } // 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 Paint(PaintContext &context) const override
ClipRectLayer(const SkRect &clip_rect, Clip clip_behavior)
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
bool needs_system_composite() const
Definition: layer.h:161
bool needs_painting() const
Definition: layer.h:174
void PushClipRect(const SkRect &rect)
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:43
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
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
bool UsesSaveLayer() const
void DrawCheckerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: paint_utils.cc:28
void PaintChildren(PaintContext &context) const