Add support for new Scenic clip planes. (#7804)

Uses SetClipPlanesCmd in addition to the old clipping approach.
Flutter will use both clipping methods during a transition period
(Scenic will select internally which one to use).
This commit is contained in:
Josh Gargus 2019-02-12 18:33:14 -08:00 committed by GitHub
parent 309b90ca58
commit 347d690b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -32,7 +32,7 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) {
FML_DCHECK(needs_system_composite());
// TODO(MZ-137): Need to be able to express the radii as vectors.
// TODO(SCN-137): Need to be able to express the radii as vectors.
scenic::RoundedRectangle shape(
context.session(), // session
clip_rrect_.width(), // width

View File

@ -40,6 +40,45 @@ void SceneUpdateContext::RemoveExportNode(ExportNode* export_node) {
export_nodes_.erase(export_node);
}
// Helper function to generate clip planes for a scenic::EntityNode.
static void SetEntityNodeClipPlanes(scenic::EntityNode* entity_node,
const SkRect& bounds) {
const float top = bounds.top();
const float bottom = bounds.bottom();
const float left = bounds.left();
const float right = bounds.right();
// We will generate 4 oriented planes, one for each edge of the bounding rect.
std::vector<fuchsia::ui::gfx::Plane3> clip_planes;
clip_planes.resize(4);
// Top plane.
clip_planes[0].dist = top;
clip_planes[0].dir.x = 0.f;
clip_planes[0].dir.y = 1.f;
clip_planes[0].dir.z = 0.f;
// Bottom plane.
clip_planes[1].dist = -bottom;
clip_planes[1].dir.x = 0.f;
clip_planes[1].dir.y = -1.f;
clip_planes[1].dir.z = 0.f;
// Left plane.
clip_planes[2].dist = left;
clip_planes[2].dir.x = 1.f;
clip_planes[2].dir.y = 0.f;
clip_planes[2].dir.z = 0.f;
// Right plane.
clip_planes[3].dist = -right;
clip_planes[3].dir.x = -1.f;
clip_planes[3].dir.y = 0.f;
clip_planes[3].dir.z = 0.f;
entity_node->SetClipPlanes(std::move(clip_planes));
}
void SceneUpdateContext::CreateFrame(
std::unique_ptr<scenic::EntityNode> entity_node,
const SkRRect& rrect,
@ -48,6 +87,8 @@ void SceneUpdateContext::CreateFrame(
std::vector<Layer*> paint_layers,
Layer* layer) {
// Frames always clip their children.
SetEntityNodeClipPlanes(entity_node.get(), rrect.getBounds());
// TODO(SCN-1274): AddPart() and SetClip() will be deleted.
entity_node->SetClip(0u, true /* clip to self */);
// We don't need a shape if the frame is zero size.
@ -72,6 +113,7 @@ void SceneUpdateContext::CreateFrame(
shape_node.SetTranslation(shape_bounds.width() * 0.5f + shape_bounds.left(),
shape_bounds.height() * 0.5f + shape_bounds.top(),
0.f);
// TODO(SCN-1274): AddPart() and SetClip() will be deleted.
entity_node->AddPart(shape_node);
// Check whether the painted layers will be visible.
@ -244,8 +286,11 @@ SceneUpdateContext::Clip::Clip(SceneUpdateContext& context,
shape_bounds.height() * 0.5f + shape_bounds.top(),
0.f);
// TODO(SCN-1274): AddPart() and SetClip() will be deleted.
entity_node().AddPart(shape_node);
entity_node().SetClip(0u, true /* clip to self */);
SetEntityNodeClipPlanes(&entity_node(), shape_bounds);
}
SceneUpdateContext::Clip::~Clip() = default;