Commit ec0bccfb authored by Adam Barth's avatar Adam Barth

Optimize circular clips slightly

This patch avoids creating weak references on every paint call by caching the
Path object between paints.
parent 8e11dcb5
...@@ -802,7 +802,8 @@ class RenderOpacity extends RenderProxyBox { ...@@ -802,7 +802,8 @@ class RenderOpacity extends RenderProxyBox {
if (_cachedPaint == null) { if (_cachedPaint == null) {
_cachedPaint = new Paint() _cachedPaint = new Paint()
..color = new Color.fromARGB(_alpha, 0, 0, 0) ..color = new Color.fromARGB(_alpha, 0, 0, 0)
..setTransferMode(sky.TransferMode.srcOver); ..setTransferMode(sky.TransferMode.srcOver)
..isAntiAlias = false;
} }
return _cachedPaint; return _cachedPaint;
} }
...@@ -857,7 +858,8 @@ class RenderColorFilter extends RenderProxyBox { ...@@ -857,7 +858,8 @@ class RenderColorFilter extends RenderProxyBox {
Paint get _paint { Paint get _paint {
if (_cachedPaint == null) { if (_cachedPaint == null) {
_cachedPaint = new Paint() _cachedPaint = new Paint()
..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode)); ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode))
..isAntiAlias = false;
} }
return _cachedPaint; return _cachedPaint;
} }
...@@ -911,10 +913,12 @@ class RenderClipRRect extends RenderProxyBox { ...@@ -911,10 +913,12 @@ class RenderClipRRect extends RenderProxyBox {
markNeedsPaint(); markNeedsPaint();
} }
final Paint _paint = new Paint()..isAntiAlias = false;
void paint(PaintingCanvas canvas, Offset offset) { void paint(PaintingCanvas canvas, Offset offset) {
if (child != null) { if (child != null) {
Rect rect = offset & size; Rect rect = offset & size;
canvas.saveLayer(rect, new Paint()); canvas.saveLayer(rect, _paint);
sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius); sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius);
canvas.clipRRect(rrect); canvas.clipRRect(rrect);
canvas.paintChild(child, offset.toPoint()); canvas.paintChild(child, offset.toPoint());
...@@ -926,13 +930,24 @@ class RenderClipRRect extends RenderProxyBox { ...@@ -926,13 +930,24 @@ class RenderClipRRect extends RenderProxyBox {
class RenderClipOval extends RenderProxyBox { class RenderClipOval extends RenderProxyBox {
RenderClipOval({ RenderBox child }) : super(child); RenderClipOval({ RenderBox child }) : super(child);
final Paint _paint = new Paint()..isAntiAlias = false;
Rect _cachedRect;
Path _cachedPath;
Path _getPath(Rect rect) {
if (rect != _cachedRect) {
_cachedRect = rect;
_cachedPath = new Path()..addOval(_cachedRect);
}
return _cachedPath;
}
void paint(PaintingCanvas canvas, Offset offset) { void paint(PaintingCanvas canvas, Offset offset) {
if (child != null) { if (child != null) {
Rect rect = offset & size; Rect rect = offset & size;
canvas.saveLayer(rect, new Paint()); canvas.saveLayer(rect, _paint);
Path path = new Path(); canvas.clipPath(_getPath(rect));
path.addOval(rect);
canvas.clipPath(path);
canvas.paintChild(child, offset.toPoint()); canvas.paintChild(child, offset.toPoint());
canvas.restore(); canvas.restore();
} }
......
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