Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1327)

Unified Diff: sky/sdk/lib/rendering/box.dart

Issue 1235813004: Reduce the number of temporary Paint objects (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/rendering/box.dart
diff --git a/sky/sdk/lib/rendering/box.dart b/sky/sdk/lib/rendering/box.dart
index f002e11afdbf1c994793731072b4a24f94af4d7e..fca4f7f0398b1ff7e705975d0ffc1c6a9c9cb84d 100644
--- a/sky/sdk/lib/rendering/box.dart
+++ b/sky/sdk/lib/rendering/box.dart
@@ -656,12 +656,25 @@ class RenderOpacity extends RenderProxyBox {
if (_opacity == value)
return;
_opacity = value;
+ _cachedPaint = null;
markNeedsPaint();
}
+ int get _alpha => (_opacity * 255).round();
+
+ Paint _cachedPaint;
+ Paint get _paint {
+ if (_cachedPaint == null) {
+ _cachedPaint = new Paint()
+ ..color = new Color.fromARGB(_alpha, 0, 0, 0)
+ ..setTransferMode(sky.TransferMode.srcOver);
+ }
+ return _cachedPaint;
+ }
+
void paint(PaintingCanvas canvas, Offset offset) {
if (child != null) {
- int a = (_opacity * 255).round();
+ int a = _alpha;
if (a == 0)
return;
@@ -671,10 +684,7 @@ class RenderOpacity extends RenderProxyBox {
return;
}
- Paint paint = new Paint()
- ..color = new Color.fromARGB(a, 0, 0, 0)
- ..setTransferMode(sky.TransferMode.srcOver);
- canvas.saveLayer(null, paint);
+ canvas.saveLayer(null, _paint);
canvas.paintChild(child, offset.toPoint());
canvas.restore();
}
@@ -693,6 +703,7 @@ class RenderColorFilter extends RenderProxyBox {
if (_color == value)
return;
_color = value;
+ _cachedPaint = null;
markNeedsPaint();
}
@@ -703,14 +714,22 @@ class RenderColorFilter extends RenderProxyBox {
if (_transferMode == value)
return;
_transferMode = value;
+ _cachedPaint = null;
markNeedsPaint();
}
+ Paint _cachedPaint;
+ Paint get _paint {
+ if (_cachedPaint == null) {
+ _cachedPaint = new Paint()
+ ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
+ }
+ return _cachedPaint;
+ }
+
void paint(PaintingCanvas canvas, Offset offset) {
if (child != null) {
- Paint paint = new Paint()
- ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
- canvas.saveLayer(null, paint);
+ canvas.saveLayer(offset & size, _paint);
canvas.paintChild(child, offset.toPoint());
canvas.restore();
}
@@ -1247,8 +1266,7 @@ class RenderImage extends RenderBox {
canvas.scale(widthScale, heightScale);
offset = Offset.zero;
}
- Paint paint = new Paint();
- canvas.drawImage(_image, offset.toPoint(), paint);
+ canvas.drawImage(_image, offset.toPoint(), new Paint());
if (needsScale)
canvas.restore();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698