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 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
16 
17 void ClipRRectLayer::Diff(DiffContext* context, const Layer* old_layer) {
18  DiffContext::AutoSubtreeRestore subtree(context);
19  auto* prev = static_cast<const ClipRRectLayer*>(old_layer);
20  if (!context->IsSubtreeDirty()) {
21  FML_DCHECK(prev);
22  if (clip_behavior_ != prev->clip_behavior_ ||
23  clip_rrect_ != prev->clip_rrect_) {
24  context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
25  }
26  }
27  if (context->PushCullRect(clip_rrect_.getBounds())) {
28  DiffChildren(context, prev);
29  }
30  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
31 }
32 
33 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
34 
35 void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
36  TRACE_EVENT0("flutter", "ClipRRectLayer::Preroll");
37 
38  SkRect previous_cull_rect = context->cull_rect;
39  SkRect clip_rrect_bounds = clip_rrect_.getBounds();
40  if (!context->cull_rect.intersect(clip_rrect_bounds)) {
41  context->cull_rect.setEmpty();
42  }
45  context->mutators_stack.PushClipRRect(clip_rrect_);
46 
47  SkRect child_paint_bounds = SkRect::MakeEmpty();
48  PrerollChildren(context, matrix, &child_paint_bounds);
49  if (child_paint_bounds.intersect(clip_rrect_bounds)) {
50  set_paint_bounds(child_paint_bounds);
51  }
52 
53  context->mutators_stack.Pop();
54  context->cull_rect = previous_cull_rect;
55 }
56 
57 void ClipRRectLayer::Paint(PaintContext& context) const {
58  TRACE_EVENT0("flutter", "ClipRRectLayer::Paint");
59  FML_DCHECK(needs_painting(context));
60 
61  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
62  context.internal_nodes_canvas->clipRRect(clip_rrect_,
63  clip_behavior_ != Clip::hardEdge);
64 
65  if (UsesSaveLayer()) {
66  context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
67  }
68  PaintChildren(context);
69  if (UsesSaveLayer()) {
70  context.internal_nodes_canvas->restore();
71  if (context.checkerboard_offscreen_layers) {
73  }
74  }
75 }
76 
77 } // namespace flutter
const bool checkerboard_offscreen_layers
Definition: layer.h:152
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
void Paint(PaintContext &context) const override
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
ClipRRectLayer(const SkRRect &clip_rrect, Clip clip_behavior)
void PushClipRRect(const SkRRect &rrect)
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:240
Clip
Definition: layer.h:40
SkCanvas * internal_nodes_canvas
Definition: layer.h:144
MutatorsStack & mutators_stack
Definition: layer.h:46
void DrawCheckerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: paint_utils.cc:29
void PaintChildren(PaintContext &context) const