Commit c80603cf authored by Adam Barth's avatar Adam Barth

Add PaintingContext which has-a sky.Canvas instead of is-a sky.Canvas

We'll need this for compositing because we need to switch out the sky.Canvas
when we switch compositing layers.
parent 7295563d
......@@ -321,7 +321,8 @@ class SpriteBox extends RenderBox {
_rootNode._invalidateToBoxTransformMatrix();
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas;
canvas.save();
// Move to correct coordinate space before drawing
......
......@@ -129,7 +129,7 @@ abstract class RenderDecoratedSector extends RenderSector {
}
// offset must point to the center of the circle
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
assert(deltaRadius != null);
assert(deltaTheta != null);
assert(parentData is SectorParentData);
......@@ -138,6 +138,7 @@ abstract class RenderDecoratedSector extends RenderSector {
return;
if (_decoration.backgroundColor != null) {
final PaintingCanvas canvas = context.canvas;
Paint paint = new Paint()..color = _decoration.backgroundColor;
Path path = new Path();
double outerRadius = (parentData.radius + deltaRadius);
......@@ -266,13 +267,13 @@ class RenderSectorRing extends RenderSectorWithChildren {
// offset must point to the center of our circle
// each sector then knows how to paint itself at its location
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
// TODO(ianh): avoid code duplication
super.paint(canvas, offset);
super.paint(context, offset);
RenderSector child = firstChild;
while (child != null) {
assert(child.parentData is SectorChildListParentData);
canvas.paintChild(child, offset.toPoint());
context.paintChild(child, offset.toPoint());
child = child.parentData.nextSibling;
}
}
......@@ -371,13 +372,13 @@ class RenderSectorSlice extends RenderSectorWithChildren {
// offset must point to the center of our circle
// each sector then knows how to paint itself at its location
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
// TODO(ianh): avoid code duplication
super.paint(canvas, offset);
super.paint(context, offset);
RenderSector child = firstChild;
while (child != null) {
assert(child.parentData is SectorChildListParentData);
canvas.paintChild(child, offset.toPoint());
context.paintChild(child, offset.toPoint());
child = child.parentData.nextSibling;
}
}
......@@ -464,12 +465,12 @@ class RenderBoxToRenderSectorAdapter extends RenderBox {
}
}
void paint(PaintingCanvas canvas, Offset offset) {
super.paint(canvas, offset);
void paint(PaintingContext context, Offset offset) {
super.paint(context, offset);
if (child != null) {
Rect bounds = offset & size;
// we move the offset to the center of the circle for the RenderSectors
canvas.paintChild(child, bounds.center);
context.paintChild(child, bounds.center);
}
}
......
......@@ -33,8 +33,8 @@ class Dot {
radius = 5 + (95 * event.pressure);
}
void paint(PaintingCanvas canvas, Offset offset) {
canvas.drawCircle(position + offset, radius, _paint);
void paint(PaintingContext context, Offset offset) {
context.canvas.drawCircle(position + offset, radius, _paint);
}
}
......@@ -70,7 +70,8 @@ class RenderTouchDemo extends RenderBox {
size = constraints.biggest;
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas;
Paint white = new Paint()
..color = const Color(0xFFFFFFFF);
canvas.drawRect(offset & size, white);
......
......@@ -216,8 +216,8 @@ class RenderAutoLayout extends RenderBox
defaultHitTestChildren(result, position: position);
}
void paint(PaintingCanvas canvas, Offset offset) {
defaultPaint(canvas, offset);
void paint(PaintingContext context, Offset offset) {
defaultPaint(context, offset);
}
List<al.Constraint> _constructImplicitConstraints() {
......
......@@ -156,8 +156,8 @@ class RenderBlock extends RenderBlockBase {
assert(!size.isInfinite);
}
void paint(PaintingCanvas canvas, Offset offset) {
defaultPaint(canvas, offset);
void paint(PaintingContext context, Offset offset) {
defaultPaint(context, offset);
}
void hitTestChildren(HitTestResult result, { Point position }) {
......@@ -242,11 +242,11 @@ class RenderBlockViewport extends RenderBlockBase {
super.performLayout();
}
void paint(PaintingCanvas canvas, Offset offset) {
canvas.save();
canvas.clipRect(offset & size);
defaultPaint(canvas, offset.translate(0.0, startOffset));
canvas.restore();
void paint(PaintingContext context, Offset offset) {
context.canvas.save();
context.canvas.clipRect(offset & size);
defaultPaint(context, offset.translate(0.0, startOffset));
context.canvas.restore();
}
void applyPaintTransform(Matrix4 transform) {
......
This diff is collapsed.
......@@ -449,19 +449,19 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
defaultHitTestChildren(result, position: position);
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
if (_overflow > 0) {
canvas.save();
canvas.clipRect(offset & size);
defaultPaint(canvas, offset);
canvas.restore();
context.canvas.save();
context.canvas.clipRect(offset & size);
defaultPaint(context, offset);
context.canvas.restore();
} else {
defaultPaint(canvas, offset);
defaultPaint(context, offset);
}
}
void debugPaintSize(PaintingCanvas canvas, Offset offset) {
super.debugPaintSize(canvas, offset);
void debugPaintSize(PaintingContext context, Offset offset) {
super.debugPaintSize(context, offset);
if (_overflow <= 0)
return;
......@@ -479,6 +479,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
new Size(size.width, _overflow);
break;
}
canvas.drawRect(overflowRect, paint);
context.canvas.drawRect(overflowRect, paint);
}
}
......@@ -29,15 +29,21 @@ class ParentData {
class PaintingCanvas extends sky.Canvas {
PaintingCanvas(sky.PictureRecorder recorder, Rect bounds) : super(recorder, bounds);
}
class PaintingContext {
final PaintingCanvas canvas;
PaintingContext(this.canvas);
List<RenderObject> _descendentsWithPaintingCanvases = new List<RenderObject>(); // used by RenderObject._updatePaintingCanvas() to find out which RenderObjects to ask to paint
void paintChild(RenderObject child, Point point) {
if (child.createNewDisplayList) {
assert(!_descendentsWithPaintingCanvases.contains(child));
_descendentsWithPaintingCanvases.add(child);
drawPaintingNode(child._paintingNode, point);
canvas.drawPaintingNode(child._paintingNode, point);
} else {
child._paintOnCanvas(this, point.toOffset());
child._paintWithContext(this, point.toOffset());
}
}
}
......@@ -362,10 +368,11 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
assert(!_needsLayout);
assert(createNewDisplayList);
sky.PictureRecorder recorder = new sky.PictureRecorder();
PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds);
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
PaintingContext context = new PaintingContext(canvas);
_needsPaint = false;
try {
_paintOnCanvas(canvas, Offset.zero);
_paintWithContext(context, Offset.zero);
} catch (e) {
print('Exception raised during _updatePaintingCanvas:\n${e}\nContext:\n${this}');
if (inDebugBuild)
......@@ -375,8 +382,8 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
assert(!_needsLayout); // check that the paint() method didn't mark us dirty again
assert(!_needsPaint); // check that the paint() method didn't mark us dirty again
_paintingNode.setBackingDrawable(recorder.endRecordingAsDrawable());
if (canvas._descendentsWithPaintingCanvases != null) {
for (RenderObject node in canvas._descendentsWithPaintingCanvases) {
if (context._descendentsWithPaintingCanvases != null) {
for (RenderObject node in context._descendentsWithPaintingCanvases) {
assert(node.attached == attached);
if (node._needsPaint)
node._updatePaintingCanvas();
......@@ -384,7 +391,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
}
}
void _paintOnCanvas(PaintingCanvas canvas, Offset offset) {
void _paintWithContext(PaintingContext context, Offset offset) {
_needsPaint = false;
assert(!_debugDoingThisPaint);
RenderObject debugLastActivePaint;
......@@ -392,17 +399,17 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
_debugDoingThisPaint = true;
debugLastActivePaint = _debugActivePaint;
_debugActivePaint = this;
debugPaint(canvas, offset);
debugPaint(context, offset);
if (debugPaintBoundsEnabled) {
canvas.save();
canvas.clipRect(paintBounds.shift(offset));
context.canvas.save();
context.canvas.clipRect(paintBounds.shift(offset));
}
return true;
});
paint(canvas, offset);
paint(context, offset);
assert(() {
if (debugPaintBoundsEnabled)
canvas.restore();
context.canvas.restore();
_debugActivePaint = debugLastActivePaint;
_debugDoingThisPaint = false;
return true;
......@@ -412,8 +419,8 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
bool get createNewDisplayList => false;
Rect get paintBounds;
void debugPaint(PaintingCanvas canvas, Offset offset) { }
void paint(PaintingCanvas canvas, Offset offset) { }
void debugPaint(PaintingContext context, Offset offset) { }
void paint(PaintingContext context, Offset offset) { }
void applyPaintTransform(Matrix4 transform) { }
......
......@@ -181,7 +181,7 @@ class RenderParagraph extends RenderBox {
_applyFloatingPointHack(root.height)));
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
// Ideally we could compute the min/max intrinsic width/height with a
// non-destructive operation. However, currently, computing these values
// will destroy state inside the layout root. If that happens, we need to
......@@ -192,9 +192,9 @@ class RenderParagraph extends RenderBox {
// TODO(ianh): Make LayoutRoot support a paint offset so we don't
// need to translate for each span of text.
_layout(constraints);
canvas.translate(offset.dx, offset.dy);
_layoutRoot.paint(canvas);
canvas.translate(-offset.dx, -offset.dy);
context.canvas.translate(offset.dx, offset.dy);
_layoutRoot.paint(context.canvas);
context.canvas.translate(-offset.dx, -offset.dy);
}
// we should probably expose a way to do precise (inter-glpyh) hit testing
......
......@@ -201,14 +201,14 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
defaultHitTestChildren(result, position: position);
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
if (_hasVisualOverflow) {
canvas.save();
canvas.clipRect(offset & size);
defaultPaint(canvas, offset);
canvas.restore();
context.canvas.save();
context.canvas.clipRect(offset & size);
defaultPaint(context, offset);
context.canvas.restore();
} else {
defaultPaint(canvas, offset);
defaultPaint(context, offset);
}
}
}
......@@ -101,7 +101,8 @@ class _RenderCheckbox extends RenderToggleable {
markNeedsPaint();
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas;
// Choose a color between grey and the theme color
sky.Paint paint = new sky.Paint()
..strokeWidth = 2.0
......
......@@ -113,8 +113,9 @@ class RenderInkWell extends RenderProxyBox {
markNeedsPaint();
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
if (!_splashes.isEmpty) {
final PaintingCanvas canvas = context.canvas;
canvas.save();
canvas.translate(offset.dx, offset.dy);
canvas.clipRect(Point.origin & size);
......@@ -122,7 +123,7 @@ class RenderInkWell extends RenderProxyBox {
splash.paint(canvas);
canvas.restore();
}
super.paint(canvas, offset);
super.paint(context, offset);
}
}
......
......@@ -141,12 +141,12 @@ class RenderScaffold extends RenderBox {
}
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
for (ScaffoldSlots slot in ScaffoldSlots.values) {
RenderBox box = _slots[slot];
if (box != null) {
assert(box.parentData is BoxParentData);
canvas.paintChild(box, box.parentData.position + offset);
context.paintChild(box, box.parentData.position + offset);
}
}
}
......
......@@ -117,7 +117,8 @@ class _RenderSwitch extends RenderToggleable {
_radialReaction = null;
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas;
sky.Color thumbColor = _kThumbOffColor;
sky.Color trackColor = _kTrackOffColor;
if (value) {
......
......@@ -246,21 +246,21 @@ class RenderTabBar extends RenderBox with
canvas.drawRect(rect, new Paint()..color = indicatorColor);
}
void paint(PaintingCanvas canvas, Offset offset) {
void paint(PaintingContext context, Offset offset) {
if (backgroundColor != null) {
double width = layoutWidths != null
? layoutWidths.reduce((sum, width) => sum + width)
: size.width;
Rect rect = offset & new Size(width, size.height);
canvas.drawRect(rect, new Paint()..color = backgroundColor);
context.canvas.drawRect(rect, new Paint()..color = backgroundColor);
}
int index = 0;
RenderBox child = firstChild;
while (child != null) {
assert(child.parentData is TabBarParentData);
canvas.paintChild(child, child.parentData.position + offset);
context.paintChild(child, child.parentData.position + offset);
if (index++ == selectedIndex)
_paintIndicator(canvas, child, offset);
_paintIndicator(context.canvas, child, offset);
child = child.parentData.nextSibling;
}
}
......
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