getTransformTo method

Matrix4 getTransformTo(
  1. RenderObject? ancestor
)

Applies the paint transform up the tree to ancestor.

Returns a matrix that maps the local paint coordinate system to the coordinate system of ancestor.

If ancestor is null, this method returns a matrix that maps from the local paint coordinate system to the coordinate system of the PipelineOwner.rootNode.

For the render tree owned by the RendererBinding (i.e. for the main render tree displayed on the device) this means that this method maps to the global coordinate system in logical pixels. To get physical pixels, use applyPaintTransform from the RenderView to further transform the coordinate.

Implementation

Matrix4 getTransformTo(RenderObject? ancestor) {
  final bool ancestorSpecified = ancestor != null;
  assert(attached);
  if (ancestor == null) {
    final RenderObject? rootNode = owner!.rootNode;
    if (rootNode is RenderObject) {
      ancestor = rootNode;
    }
  }
  final List<RenderObject> renderers = <RenderObject>[];
  for (RenderObject renderer = this; renderer != ancestor; renderer = renderer.parent!) {
    renderers.add(renderer);
    assert(renderer.parent != null); // Failed to find ancestor in parent chain.
  }
  if (ancestorSpecified) {
    renderers.add(ancestor!);
  }
  final Matrix4 transform = Matrix4.identity();
  for (int index = renderers.length - 1; index > 0; index -= 1) {
    renderers[index].applyPaintTransform(renderers[index - 1], transform);
  }
  return transform;
}