diff --git a/flow/layers/clip_rrect_layer.cc b/flow/layers/clip_rrect_layer.cc index b4b968bb396..72092110cf7 100644 --- a/flow/layers/clip_rrect_layer.cc +++ b/flow/layers/clip_rrect_layer.cc @@ -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 diff --git a/flow/scene_update_context.cc b/flow/scene_update_context.cc index bebe2ef67fb..c02332d83fb 100644 --- a/flow/scene_update_context.cc +++ b/flow/scene_update_context.cc @@ -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 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 entity_node, const SkRRect& rrect, @@ -48,6 +87,8 @@ void SceneUpdateContext::CreateFrame( std::vector 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;