flutter_flutter/flow/layers/clip_rect_layer.cc
liyuqian 4812a2af11
DCHECK that clip layer's behavior isn't none (#7659)
This will further guard that the framework won't forget to set the
clip behavior.

This has been tested with the flutter/flutter framework
`flutter test --local-engine=host_debug_unopt`
to ensure a successful engine roll.
2019-02-04 13:31:21 -08:00

63 lines
1.9 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/layers/clip_rect_layer.h"
namespace flow {
ClipRectLayer::ClipRectLayer(Clip clip_behavior)
: clip_behavior_(clip_behavior) {
FML_DCHECK(clip_behavior != Clip::none);
}
ClipRectLayer::~ClipRectLayer() = default;
void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
SkRect previous_cull_rect = context->cull_rect;
if (context->cull_rect.intersect(clip_rect_)) {
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);
}
}
context->cull_rect = previous_cull_rect;
}
#if defined(OS_FUCHSIA)
void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
FML_DCHECK(needs_system_composite());
scenic::Rectangle shape(context.session(), // session
clip_rect_.width(), // width
clip_rect_.height() // height
);
// TODO(liyuqian): respect clip_behavior_
SceneUpdateContext::Clip clip(context, shape, clip_rect_);
UpdateSceneChildren(context);
}
#endif // defined(OS_FUCHSIA)
void ClipRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
FML_DCHECK(needs_painting());
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->clipRect(paint_bounds(),
clip_behavior_ != Clip::hardEdge);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.internal_nodes_canvas->restore();
}
}
} // namespace flow