clip_rect_layer.cc 1.3 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "flutter/flow/layers/clip_rect_layer.h"
6

A
Adam Barth 已提交
7
namespace flow {
8

9
ClipRectLayer::ClipRectLayer() = default;
10

11
ClipRectLayer::~ClipRectLayer() = default;
12

13
void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
14 15 16 17 18 19
  SkRect child_paint_bounds = SkRect::MakeEmpty();
  PrerollChildren(context, matrix, &child_paint_bounds);

  if (child_paint_bounds.intersect(clip_rect_)) {
    set_paint_bounds(child_paint_bounds);
  }
20 21
}

22 23
#if defined(OS_FUCHSIA)

24
void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
25
  FXL_DCHECK(needs_system_composite());
26

27
  scenic::Rectangle shape(context.session(),   // session
28 29 30
                              clip_rect_.width(),  //  width
                              clip_rect_.height()  //  height
  );
31 32 33

  SceneUpdateContext::Clip clip(context, shape, clip_rect_);
  UpdateSceneChildren(context);
34 35 36 37
}

#endif  // defined(OS_FUCHSIA)

38
void ClipRectLayer::Paint(PaintContext& context) const {
39
  TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
40
  FXL_DCHECK(needs_painting());
41

42 43 44
  SkAutoCanvasRestore save(&context.canvas, true);
  context.canvas.clipRect(paint_bounds());
  PaintChildren(context);
45 46
}

A
Adam Barth 已提交
47
}  // namespace flow