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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import 'dart:sky' as sky; 6 import 'dart:sky' as sky;
7 7
8 import 'package:sky/base/debug.dart'; 8 import 'package:sky/base/debug.dart';
9 import 'package:sky/painting/box_painter.dart'; 9 import 'package:sky/painting/box_painter.dart';
10 import 'package:sky/rendering/object.dart'; 10 import 'package:sky/rendering/object.dart';
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 649 }
650 650
651 double _opacity; 651 double _opacity;
652 double get opacity => _opacity; 652 double get opacity => _opacity;
653 void set opacity (double value) { 653 void set opacity (double value) {
654 assert(value != null); 654 assert(value != null);
655 assert(value >= 0.0 && value <= 1.0); 655 assert(value >= 0.0 && value <= 1.0);
656 if (_opacity == value) 656 if (_opacity == value)
657 return; 657 return;
658 _opacity = value; 658 _opacity = value;
659 _cachedPaint = null;
659 markNeedsPaint(); 660 markNeedsPaint();
660 } 661 }
661 662
663 int get _alpha => (_opacity * 255).round();
664
665 Paint _cachedPaint;
666 Paint get _paint {
667 if (_cachedPaint == null) {
668 _cachedPaint = new Paint()
669 ..color = new Color.fromARGB(_alpha, 0, 0, 0)
670 ..setTransferMode(sky.TransferMode.srcOver);
671 }
672 return _cachedPaint;
673 }
674
662 void paint(PaintingCanvas canvas, Offset offset) { 675 void paint(PaintingCanvas canvas, Offset offset) {
663 if (child != null) { 676 if (child != null) {
664 int a = (_opacity * 255).round(); 677 int a = _alpha;
665 678
666 if (a == 0) 679 if (a == 0)
667 return; 680 return;
668 681
669 if (a == 255) { 682 if (a == 255) {
670 canvas.paintChild(child, offset.toPoint()); 683 canvas.paintChild(child, offset.toPoint());
671 return; 684 return;
672 } 685 }
673 686
674 Paint paint = new Paint() 687 canvas.saveLayer(null, _paint);
675 ..color = new Color.fromARGB(a, 0, 0, 0)
676 ..setTransferMode(sky.TransferMode.srcOver);
677 canvas.saveLayer(null, paint);
678 canvas.paintChild(child, offset.toPoint()); 688 canvas.paintChild(child, offset.toPoint());
679 canvas.restore(); 689 canvas.restore();
680 } 690 }
681 } 691 }
682 } 692 }
683 693
684 class RenderColorFilter extends RenderProxyBox { 694 class RenderColorFilter extends RenderProxyBox {
685 RenderColorFilter({ RenderBox child, Color color, sky.TransferMode transferMod e }) 695 RenderColorFilter({ RenderBox child, Color color, sky.TransferMode transferMod e })
686 : _color = color, _transferMode = transferMode, super(child) { 696 : _color = color, _transferMode = transferMode, super(child) {
687 } 697 }
688 698
689 Color _color; 699 Color _color;
690 Color get color => _color; 700 Color get color => _color;
691 void set color (Color value) { 701 void set color (Color value) {
692 assert(value != null); 702 assert(value != null);
693 if (_color == value) 703 if (_color == value)
694 return; 704 return;
695 _color = value; 705 _color = value;
706 _cachedPaint = null;
696 markNeedsPaint(); 707 markNeedsPaint();
697 } 708 }
698 709
699 sky.TransferMode _transferMode; 710 sky.TransferMode _transferMode;
700 sky.TransferMode get transferMode => _transferMode; 711 sky.TransferMode get transferMode => _transferMode;
701 void set transferMode (sky.TransferMode value) { 712 void set transferMode (sky.TransferMode value) {
702 assert(value != null); 713 assert(value != null);
703 if (_transferMode == value) 714 if (_transferMode == value)
704 return; 715 return;
705 _transferMode = value; 716 _transferMode = value;
717 _cachedPaint = null;
706 markNeedsPaint(); 718 markNeedsPaint();
707 } 719 }
708 720
721 Paint _cachedPaint;
722 Paint get _paint {
723 if (_cachedPaint == null) {
724 _cachedPaint = new Paint()
725 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
726 }
727 return _cachedPaint;
728 }
729
709 void paint(PaintingCanvas canvas, Offset offset) { 730 void paint(PaintingCanvas canvas, Offset offset) {
710 if (child != null) { 731 if (child != null) {
711 Paint paint = new Paint() 732 canvas.saveLayer(offset & size, _paint);
712 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
713 canvas.saveLayer(null, paint);
714 canvas.paintChild(child, offset.toPoint()); 733 canvas.paintChild(child, offset.toPoint());
715 canvas.restore(); 734 canvas.restore();
716 } 735 }
717 } 736 }
718 } 737 }
719 738
720 class RenderClipRect extends RenderProxyBox { 739 class RenderClipRect extends RenderProxyBox {
721 RenderClipRect({ RenderBox child }) : super(child); 740 RenderClipRect({ RenderBox child }) : super(child);
722 741
723 void paint(PaintingCanvas canvas, Offset offset) { 742 void paint(PaintingCanvas canvas, Offset offset) {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 return; 1259 return;
1241 bool needsScale = size.width != _image.width || size.height != _image.height ; 1260 bool needsScale = size.width != _image.width || size.height != _image.height ;
1242 if (needsScale) { 1261 if (needsScale) {
1243 double widthScale = size.width / _image.width; 1262 double widthScale = size.width / _image.width;
1244 double heightScale = size.height / _image.height; 1263 double heightScale = size.height / _image.height;
1245 canvas.save(); 1264 canvas.save();
1246 canvas.translate(offset.dx, offset.dy); 1265 canvas.translate(offset.dx, offset.dy);
1247 canvas.scale(widthScale, heightScale); 1266 canvas.scale(widthScale, heightScale);
1248 offset = Offset.zero; 1267 offset = Offset.zero;
1249 } 1268 }
1250 Paint paint = new Paint(); 1269 canvas.drawImage(_image, offset.toPoint(), new Paint());
1251 canvas.drawImage(_image, offset.toPoint(), paint);
1252 if (needsScale) 1270 if (needsScale)
1253 canvas.restore(); 1271 canvas.restore();
1254 } 1272 }
1255 1273
1256 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}dimensions: ${requestedSize}\n'; 1274 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}dimensions: ${requestedSize}\n';
1257 } 1275 }
1258 1276
1259 class RenderDecoratedBox extends RenderProxyBox { 1277 class RenderDecoratedBox extends RenderProxyBox {
1260 1278
1261 RenderDecoratedBox({ 1279 RenderDecoratedBox({
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 1584
1567 void defaultPaint(PaintingCanvas canvas, Offset offset) { 1585 void defaultPaint(PaintingCanvas canvas, Offset offset) {
1568 RenderBox child = firstChild; 1586 RenderBox child = firstChild;
1569 while (child != null) { 1587 while (child != null) {
1570 assert(child.parentData is ParentDataType); 1588 assert(child.parentData is ParentDataType);
1571 canvas.paintChild(child, child.parentData.position + offset); 1589 canvas.paintChild(child, child.parentData.position + offset);
1572 child = child.parentData.nextSibling; 1590 child = child.parentData.nextSibling;
1573 } 1591 }
1574 } 1592 }
1575 } 1593 }
OLDNEW
« 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