Commit d1364643 authored by Ian Hickson's avatar Ian Hickson

applyPaintTransform() improvements

Previously, applyPaintTransform() had to know how it was positioned in
its parent, even though that's really the parent's responsibility.

Now, applyPaintTransform() is given a child and applies the transform
that it would give the child during paint.

This makes it possible for applyPaintTransform() to work across
coordinate system boundaries (e.g. box to sector, or view to box --
previously, view to box only worked because we explicitly skipped that
step -- since view doesn't actually apply a transform, it doesn't
really matter).
parent 7c8c8c1e
...@@ -298,17 +298,18 @@ abstract class InkFeature { ...@@ -298,17 +298,18 @@ abstract class InkFeature {
assert(referenceBox.attached); assert(referenceBox.attached);
assert(!_debugDisposed); assert(!_debugDisposed);
// find the chain of renderers from us to the feature's referenceBox // find the chain of renderers from us to the feature's referenceBox
List<RenderBox> descendants = <RenderBox>[]; List<RenderBox> descendants = <RenderBox>[referenceBox];
RenderBox node = referenceBox; RenderBox node = referenceBox;
while (node != renderer) { while (node != renderer) {
descendants.add(node);
node = node.parent; node = node.parent;
assert(node != null); assert(node != null);
descendants.add(node);
} }
// determine the transform that gets our coordinate system to be like theirs // determine the transform that gets our coordinate system to be like theirs
Matrix4 transform = new Matrix4.identity(); Matrix4 transform = new Matrix4.identity();
for (RenderBox descendant in descendants.reversed) assert(descendants.length >= 2);
descendant.applyPaintTransform(transform); for (int index = descendants.length - 1; index > 0; index -= 1)
descendants[index].applyPaintTransform(descendants[index - 1], transform);
paintFeature(canvas, transform); paintFeature(canvas, transform);
} }
......
...@@ -420,12 +420,12 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -420,12 +420,12 @@ class RenderBlockViewport extends RenderBlockBase {
context.pushClipRect(needsCompositing, offset, Point.origin & size, _paintContents); context.pushClipRect(needsCompositing, offset, Point.origin & size, _paintContents);
} }
void applyPaintTransform(Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
super.applyPaintTransform(transform);
if (isVertical) if (isVertical)
transform.translate(0.0, startOffset); transform.translate(0.0, startOffset);
else else
transform.translate(startOffset, 0.0); transform.translate(startOffset, 0.0);
super.applyPaintTransform(child, transform);
} }
bool hitTestChildren(HitTestResult result, { Point position }) { bool hitTestChildren(HitTestResult result, { Point position }) {
......
...@@ -609,24 +609,27 @@ abstract class RenderBox extends RenderObject { ...@@ -609,24 +609,27 @@ abstract class RenderBox extends RenderObject {
/// visually "on top" (i.e., paints later). /// visually "on top" (i.e., paints later).
bool hitTestChildren(HitTestResult result, { Point position }) => false; bool hitTestChildren(HitTestResult result, { Point position }) => false;
static Point _transformPoint(Matrix4 transform, Point point) {
Vector3 position3 = new Vector3(point.x, point.y, 0.0);
Vector3 transformed3 = transform.transform3(position3);
return new Point(transformed3.x, transformed3.y);
}
/// Multiply the transform from the parent's coordinate system to this box's /// Multiply the transform from the parent's coordinate system to this box's
/// coordinate system into the given transform /// coordinate system into the given transform.
/// ///
/// This function is used to convert coordinate systems between boxes. /// This function is used to convert coordinate systems between boxes.
/// Subclasses that apply transforms during painting should override this /// Subclasses that apply transforms during painting should override this
/// function to factor those transforms into the calculation. /// function to factor those transforms into the calculation.
void applyPaintTransform(Matrix4 transform) { ///
if (parentData is BoxParentData) { /// The RenderBox implementation takes care of adjusting the matrix for the
Point position = (parentData as BoxParentData).position; /// position of the given child.
void applyPaintTransform(RenderObject child, Matrix4 transform) {
assert(child.parent == this);
BoxParentData childParentData = child.parentData;
Point position = childParentData.position;
transform.translate(position.x, position.y); transform.translate(position.x, position.y);
} }
}
static Point _transformPoint(Matrix4 transform, Point point) {
Vector3 position3 = new Vector3(point.x, point.y, 0.0);
Vector3 transformed3 = transform.transform3(position3);
return new Point(transformed3.x, transformed3.y);
}
/// Convert the given point from the global coodinate system to the local /// Convert the given point from the global coodinate system to the local
/// coordinate system for this box /// coordinate system for this box
...@@ -634,24 +637,25 @@ abstract class RenderBox extends RenderObject { ...@@ -634,24 +637,25 @@ abstract class RenderBox extends RenderObject {
assert(attached); assert(attached);
Matrix4 transform = new Matrix4.identity(); Matrix4 transform = new Matrix4.identity();
RenderObject renderer = this; RenderObject renderer = this;
while (renderer != null) { while (renderer.parent is RenderObject) {
renderer.applyPaintTransform(transform); RenderObject rendererParent = renderer.parent;
renderer = renderer.parent; rendererParent.applyPaintTransform(renderer, transform);
renderer = rendererParent;
} }
/* double det = */ transform.invert(); /* double det = */ transform.invert();
// TODO(abarth): Check the determinant for degeneracy. // TODO(abarth): Check the determinant for degeneracy.
return _transformPoint(transform, point); return _transformPoint(transform, point);
} }
/// Convert the given point from the local coordiante system for this box to /// Convert the given point from the local coordinate system for this box to
/// the global coordinate sytem /// the global coordinate system.
Point localToGlobal(Point point) { Point localToGlobal(Point point) {
List<RenderObject> renderers = <RenderObject>[]; List<RenderObject> renderers = <RenderObject>[];
for (RenderObject renderer = this; renderer != null; renderer = renderer.parent) for (RenderObject renderer = this; renderer != null; renderer = renderer.parent)
renderers.add(renderer); renderers.add(renderer);
Matrix4 transform = new Matrix4.identity(); Matrix4 transform = new Matrix4.identity();
for (RenderObject renderer in renderers.reversed) for (int index = renderers.length - 1; index > 0; index -= 1)
renderer.applyPaintTransform(transform); renderers[index].applyPaintTransform(renderers[index - 1], transform);
return _transformPoint(transform, point); return _transformPoint(transform, point);
} }
......
...@@ -1036,12 +1036,14 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1036,12 +1036,14 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// be recorded on separate compositing layers. /// be recorded on separate compositing layers.
void paint(PaintingContext context, Offset offset) { } void paint(PaintingContext context, Offset offset) { }
/// If this render object applies a transform before painting, apply that /// Applies the transform that would be applied when painting the given child
/// transform to the given matrix /// to the given matrix.
/// ///
/// Used by coordinate conversion functions to translate coordinates local to /// Used by coordinate conversion functions to translate coordinates local to
/// one render object into coordinates local to another render object. /// one render object into coordinates local to another render object.
void applyPaintTransform(Matrix4 transform) { } void applyPaintTransform(RenderObject child, Matrix4 transform) {
assert(child.parent == this);
}
// EVENTS // EVENTS
......
...@@ -974,9 +974,9 @@ class RenderTransform extends RenderProxyBox { ...@@ -974,9 +974,9 @@ class RenderTransform extends RenderProxyBox {
} }
} }
void applyPaintTransform(Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
super.applyPaintTransform(transform);
transform.multiply(_effectiveTransform); transform.multiply(_effectiveTransform);
super.applyPaintTransform(child, transform);
} }
void debugDescribeSettings(List<String> settings) { void debugDescribeSettings(List<String> settings) {
......
...@@ -164,9 +164,9 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox ...@@ -164,9 +164,9 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox
} }
} }
void applyPaintTransform(Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
super.applyPaintTransform(transform);
transform.translate(-scrollOffset.dx, -scrollOffset.dy); transform.translate(-scrollOffset.dx, -scrollOffset.dy);
super.applyPaintTransform(child, transform);
} }
bool hitTestChildren(HitTestResult result, { Point position }) { bool hitTestChildren(HitTestResult result, { Point position }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment