flutter_flutter/flow/layers/clip_path_layer.cc

57 lines
1.7 KiB
C++

// 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.
#include "flutter/flow/layers/clip_path_layer.h"
#if defined(OS_FUCHSIA)
#include "apps/mozart/lib/scene/session_helpers.h" // nogncheck
#endif // defined(OS_FUCHSIA)
namespace flow {
ClipPathLayer::ClipPathLayer() = default;
ClipPathLayer::~ClipPathLayer() = default;
void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
SkRect child_paint_bounds = SkRect::MakeEmpty();
PrerollChildren(context, matrix, &child_paint_bounds);
if (child_paint_bounds.intersect(clip_path_.getBounds())) {
set_paint_bounds(child_paint_bounds);
}
}
#if defined(OS_FUCHSIA)
void ClipPathLayer::UpdateScene(SceneUpdateContext& context) {
FTL_DCHECK(needs_system_composite());
// TODO(MZ-140): Must be able to specify paths as shapes to nodes.
// Treating the shape as a rectangle for now.
auto bounds = clip_path_.getBounds();
mozart::client::Rectangle shape(context.session(), // session
bounds.width(), // width
bounds.height() // height
);
SceneUpdateContext::Clip clip(context, shape, bounds);
UpdateSceneChildren(context);
}
#endif // defined(OS_FUCHSIA)
void ClipPathLayer::Paint(PaintContext& context) {
TRACE_EVENT0("flutter", "ClipPathLayer::Paint");
FTL_DCHECK(needs_painting());
Layer::AutoSaveLayer save(context, paint_bounds(), nullptr);
context.canvas.clipPath(clip_path_, true);
PaintChildren(context);
}
} // namespace flow