Commit d689362d authored by Adam Barth's avatar Adam Barth

Some paint functions were using canvas.save/restore around children

This pattern breaks when using compositing because we need to lift those
operations into the compositing tree. This patch removes all the ones I could
find and adds an assert to help prevent more from getting introduced.

Fixes #191
parent 4fb5bcd8
...@@ -401,18 +401,17 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -401,18 +401,17 @@ class RenderBlockViewport extends RenderBlockBase {
super.performLayout(); super.performLayout();
} }
void paint(PaintingContext context, Offset offset) { void _paintContents(PaintingContext context, Offset offset) {
context.canvas.save();
context.canvas.clipRect(offset & size);
if (isVertical) if (isVertical)
defaultPaint(context, offset.translate(0.0, startOffset)); defaultPaint(context, offset.translate(0.0, startOffset));
else else
defaultPaint(context, offset.translate(startOffset, 0.0)); defaultPaint(context, offset.translate(startOffset, 0.0));
overlayPainter?.paint(context, offset); overlayPainter?.paint(context, offset);
}
context.canvas.restore(); void paint(PaintingContext context, Offset offset) {
context.pushClipRect(needsCompositing, offset, Point.origin & size, _paintContents);
} }
void applyPaintTransform(Matrix4 transform) { void applyPaintTransform(Matrix4 transform) {
......
...@@ -27,9 +27,6 @@ bool debugPaintLayerBordersEnabled = false; ...@@ -27,9 +27,6 @@ bool debugPaintLayerBordersEnabled = false;
/// The color to use when painting Layer borders. /// The color to use when painting Layer borders.
ui.Color debugPaintLayerBordersColor = const ui.Color(0xFFFF9800); ui.Color debugPaintLayerBordersColor = const ui.Color(0xFFFF9800);
/// Causes RenderObjects to paint warnings when painting outside their bounds.
bool debugPaintBoundsEnabled = false;
/// Causes RenderBox objects to flash while they are being tapped /// Causes RenderBox objects to flash while they are being tapped
bool debugPaintPointersEnabled = false; bool debugPaintPointersEnabled = false;
......
...@@ -97,15 +97,7 @@ class RenderEditableParagraph extends RenderParagraph { ...@@ -97,15 +97,7 @@ class RenderEditableParagraph extends RenderParagraph {
} }
} }
void paint(PaintingContext context, Offset offset) { void _paintContents(PaintingContext context, Offset offset) {
layoutText(_getTextContraints(constraints));
final bool needsClipping = (_contentSize.width > size.width);
if (needsClipping) {
context.canvas.save();
context.canvas.clipRect(offset & size);
}
textPainter.paint(context.canvas, offset - _scrollOffset); textPainter.paint(context.canvas, offset - _scrollOffset);
if (_showCursor) { if (_showCursor) {
...@@ -117,9 +109,15 @@ class RenderEditableParagraph extends RenderParagraph { ...@@ -117,9 +109,15 @@ class RenderEditableParagraph extends RenderParagraph {
); );
context.canvas.drawRect(cursorRect, new Paint()..color = _cursorColor); context.canvas.drawRect(cursorRect, new Paint()..color = _cursorColor);
} }
}
if (needsClipping) void paint(PaintingContext context, Offset offset) {
context.canvas.restore(); layoutText(_getTextContraints(constraints));
final bool hasVisualOverflow = (_contentSize.width > size.width);
if (hasVisualOverflow)
context.pushClipRect(needsCompositing, offset, Point.origin & size, _paintContents);
else
_paintContents(context, offset);
} }
} }
...@@ -553,10 +553,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -553,10 +553,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
} }
// We have overflow. Clip it. // We have overflow. Clip it.
context.canvas.save(); context.pushClipRect(needsCompositing, offset, Point.origin & size, defaultPaint);
context.canvas.clipRect(offset & size);
defaultPaint(context, offset);
context.canvas.restore();
assert(() { assert(() {
// In debug mode, if you have overflow, we highlight where the // In debug mode, if you have overflow, we highlight where the
// overflow would be by painting that area red. Since that is // overflow would be by painting that area red. Since that is
......
...@@ -139,13 +139,9 @@ class RenderGrid extends RenderBox with ContainerRenderObjectMixin<RenderBox, Gr ...@@ -139,13 +139,9 @@ class RenderGrid extends RenderBox with ContainerRenderObjectMixin<RenderBox, Gr
} }
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_hasVisualOverflow) { if (_hasVisualOverflow)
context.canvas.save(); context.pushClipRect(needsCompositing, offset, Point.origin & size, defaultPaint);
context.canvas.clipRect(offset & size); else
defaultPaint(context, offset); defaultPaint(context, offset);
context.canvas.restore();
} else {
defaultPaint(context, offset);
}
} }
} }
...@@ -96,6 +96,7 @@ class PaintingContext { ...@@ -96,6 +96,7 @@ class PaintingContext {
void _compositeChild(RenderObject child, Offset offset) { void _compositeChild(RenderObject child, Offset offset) {
assert(!_isRecording); assert(!_isRecording);
assert(child.hasLayer); assert(child.hasLayer);
assert(_canvas == null || _canvas.getSaveCount() == 1);
// Create a layer for our child, and paint the child into it. // Create a layer for our child, and paint the child into it.
if (child.needsPaint) { if (child.needsPaint) {
...@@ -966,10 +967,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -966,10 +967,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
_debugDoingThisPaint = true; _debugDoingThisPaint = true;
debugLastActivePaint = _debugActivePaint; debugLastActivePaint = _debugActivePaint;
_debugActivePaint = this; _debugActivePaint = this;
if (debugPaintBoundsEnabled) {
context.canvas.save();
context.canvas.clipRect(paintBounds.shift(offset));
}
assert(!hasLayer || _layer != null); assert(!hasLayer || _layer != null);
return true; return true;
}); });
...@@ -983,8 +980,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -983,8 +980,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
} }
assert(() { assert(() {
debugPaint(context, offset); debugPaint(context, offset);
if (debugPaintBoundsEnabled)
context.canvas.restore();
_debugActivePaint = debugLastActivePaint; _debugActivePaint = debugLastActivePaint;
_debugDoingThisPaint = false; _debugDoingThisPaint = false;
return true; return true;
......
...@@ -383,10 +383,7 @@ abstract class RenderStackBase extends RenderBox ...@@ -383,10 +383,7 @@ abstract class RenderStackBase extends RenderBox
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_hasVisualOverflow) { if (_hasVisualOverflow) {
context.canvas.save(); context.pushClipRect(needsCompositing, offset, Point.origin & size, paintStack);
context.canvas.clipRect(offset & size);
paintStack(context, offset);
context.canvas.restore();
} else { } else {
paintStack(context, offset); paintStack(context, offset);
} }
......
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