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

Side by Side Diff: sky/sdk/lib/rendering/box.dart

Issue 1216833003: Make rendering use PaintingNodes for increased efficiency. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix comments I missed 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
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:vector_math/vector_math.dart'; 8 import 'package:vector_math/vector_math.dart';
9 9
10 import '../base/debug.dart'; 10 import '../base/debug.dart';
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 assert(RenderObject.debugDoingLayout); 423 assert(RenderObject.debugDoingLayout);
424 assert((sizedByParent && debugDoingThisResize) || 424 assert((sizedByParent && debugDoingThisResize) ||
425 (!sizedByParent && debugDoingThisLayout)); 425 (!sizedByParent && debugDoingThisLayout));
426 if (value is _DebugSize) { 426 if (value is _DebugSize) {
427 assert(value._canBeUsedByParent); 427 assert(value._canBeUsedByParent);
428 assert(value._owner.parent == this); 428 assert(value._owner.parent == this);
429 } 429 }
430 _size = inDebugBuild ? new _DebugSize(value, this, debugCanParentUseSize) : value; 430 _size = inDebugBuild ? new _DebugSize(value, this, debugCanParentUseSize) : value;
431 } 431 }
432 432
433 Rect get paintBounds => Point.origin & size;
434
433 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n'; 435 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n';
434 } 436 }
435 437
436 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox > { 438 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox > {
437 439
438 // ProxyBox assumes the child will be at 0,0 and will have the same size 440 // ProxyBox assumes the child will be at 0,0 and will have the same size
439 441
440 RenderProxyBox([RenderBox child = null]) { 442 RenderProxyBox([RenderBox child = null]) {
441 this.child = child; 443 this.child = child;
442 } 444 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 484
483 void hitTestChildren(HitTestResult result, { Point position }) { 485 void hitTestChildren(HitTestResult result, { Point position }) {
484 if (child != null) 486 if (child != null)
485 child.hitTest(result, position: position); 487 child.hitTest(result, position: position);
486 else 488 else
487 super.hitTestChildren(result, position: position); 489 super.hitTestChildren(result, position: position);
488 } 490 }
489 491
490 void paint(PaintingCanvas canvas, Offset offset) { 492 void paint(PaintingCanvas canvas, Offset offset) {
491 if (child != null) 493 if (child != null)
492 child.paint(canvas, offset); 494 canvas.paintChild(child, offset.toPoint());
493 } 495 }
494 496
495 } 497 }
496 498
497 class RenderConstrainedBox extends RenderProxyBox { 499 class RenderConstrainedBox extends RenderProxyBox {
498 RenderConstrainedBox({ 500 RenderConstrainedBox({
499 RenderBox child, 501 RenderBox child,
500 BoxConstraints additionalConstraints 502 BoxConstraints additionalConstraints
501 }) : super(child), _additionalConstraints = additionalConstraints { 503 }) : super(child), _additionalConstraints = additionalConstraints {
502 assert(additionalConstraints != null); 504 assert(additionalConstraints != null);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 657 }
656 658
657 void paint(PaintingCanvas canvas, Offset offset) { 659 void paint(PaintingCanvas canvas, Offset offset) {
658 if (child != null) { 660 if (child != null) {
659 int a = (_opacity * 255).round(); 661 int a = (_opacity * 255).round();
660 662
661 if (a == 0) 663 if (a == 0)
662 return; 664 return;
663 665
664 if (a == 255) { 666 if (a == 255) {
665 child.paint(canvas, offset); 667 canvas.paintChild(child, offset.toPoint());
666 return; 668 return;
667 } 669 }
668 670
669 Paint paint = new Paint() 671 Paint paint = new Paint()
670 ..color = new Color.fromARGB(a, 0, 0, 0) 672 ..color = new Color.fromARGB(a, 0, 0, 0)
671 ..setTransferMode(sky.TransferMode.srcOver); 673 ..setTransferMode(sky.TransferMode.srcOver);
672 canvas.saveLayer(null, paint); 674 canvas.saveLayer(null, paint);
673 child.paint(canvas, offset); 675 canvas.paintChild(child, offset.toPoint());
674 canvas.restore(); 676 canvas.restore();
675 } 677 }
676 } 678 }
677 } 679 }
678 680
679 class RenderColorFilter extends RenderProxyBox { 681 class RenderColorFilter extends RenderProxyBox {
680 RenderColorFilter({ RenderBox child, Color color, sky.TransferMode transferMod e }) 682 RenderColorFilter({ RenderBox child, Color color, sky.TransferMode transferMod e })
681 : _color = color, _transferMode = transferMode, super(child) { 683 : _color = color, _transferMode = transferMode, super(child) {
682 } 684 }
683 685
(...skipping 15 matching lines...) Expand all
699 return; 701 return;
700 _transferMode = value; 702 _transferMode = value;
701 markNeedsPaint(); 703 markNeedsPaint();
702 } 704 }
703 705
704 void paint(PaintingCanvas canvas, Offset offset) { 706 void paint(PaintingCanvas canvas, Offset offset) {
705 if (child != null) { 707 if (child != null) {
706 Paint paint = new Paint() 708 Paint paint = new Paint()
707 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode)); 709 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
708 canvas.saveLayer(null, paint); 710 canvas.saveLayer(null, paint);
709 child.paint(canvas, offset); 711 canvas.paintChild(child, offset.toPoint());
710 canvas.restore(); 712 canvas.restore();
711 } 713 }
712 } 714 }
713 } 715 }
714 716
715 class RenderClipRect extends RenderProxyBox { 717 class RenderClipRect extends RenderProxyBox {
716 RenderClipRect({ RenderBox child }) : super(child); 718 RenderClipRect({ RenderBox child }) : super(child);
717 719
718 void paint(PaintingCanvas canvas, Offset offset) { 720 void paint(PaintingCanvas canvas, Offset offset) {
719 if (child != null) { 721 if (child != null) {
720 canvas.save(); 722 canvas.save();
721 canvas.clipRect(offset & size); 723 canvas.clipRect(offset & size);
722 child.paint(canvas, offset); 724 canvas.paintChild(child, offset.toPoint());
723 canvas.restore(); 725 canvas.restore();
724 } 726 }
725 } 727 }
726 } 728 }
727 729
728 class RenderClipRRect extends RenderProxyBox { 730 class RenderClipRRect extends RenderProxyBox {
729 RenderClipRRect({ RenderBox child, double xRadius, double yRadius }) 731 RenderClipRRect({ RenderBox child, double xRadius, double yRadius })
730 : _xRadius = xRadius, _yRadius = yRadius, super(child) { 732 : _xRadius = xRadius, _yRadius = yRadius, super(child) {
731 assert(_xRadius != null); 733 assert(_xRadius != null);
732 assert(_yRadius != null); 734 assert(_yRadius != null);
(...skipping 18 matching lines...) Expand all
751 _yRadius = value; 753 _yRadius = value;
752 markNeedsPaint(); 754 markNeedsPaint();
753 } 755 }
754 756
755 void paint(PaintingCanvas canvas, Offset offset) { 757 void paint(PaintingCanvas canvas, Offset offset) {
756 if (child != null) { 758 if (child != null) {
757 Rect rect = offset & size; 759 Rect rect = offset & size;
758 canvas.saveLayer(rect, new Paint()); 760 canvas.saveLayer(rect, new Paint());
759 sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius); 761 sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius);
760 canvas.clipRRect(rrect); 762 canvas.clipRRect(rrect);
761 child.paint(canvas, offset); 763 canvas.paintChild(child, offset.toPoint());
762 canvas.restore(); 764 canvas.restore();
763 } 765 }
764 } 766 }
765 } 767 }
766 768
767 class RenderClipOval extends RenderProxyBox { 769 class RenderClipOval extends RenderProxyBox {
768 RenderClipOval({ RenderBox child }) : super(child); 770 RenderClipOval({ RenderBox child }) : super(child);
769 771
770 void paint(PaintingCanvas canvas, Offset offset) { 772 void paint(PaintingCanvas canvas, Offset offset) {
771 if (child != null) { 773 if (child != null) {
772 Rect rect = offset & size; 774 Rect rect = offset & size;
773 canvas.saveLayer(rect, new Paint()); 775 canvas.saveLayer(rect, new Paint());
774 Path path = new Path(); 776 Path path = new Path();
775 path.addOval(rect); 777 path.addOval(rect);
776 canvas.clipPath(path); 778 canvas.clipPath(path);
777 child.paint(canvas, offset); 779 canvas.paintChild(child, offset.toPoint());
778 canvas.restore(); 780 canvas.restore();
779 } 781 }
780 } 782 }
781 } 783 }
782 784
783 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> { 785 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> {
784 786
785 // Abstract class for one-child-layout render boxes 787 // Abstract class for one-child-layout render boxes
786 788
787 RenderShiftedBox(RenderBox child) { 789 RenderShiftedBox(RenderBox child) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 assert(size.width != null); 1138 assert(size.width != null);
1137 assert(size.height != null); 1139 assert(size.height != null);
1138 _painter.paint(canvas, offset & size); 1140 _painter.paint(canvas, offset & size);
1139 super.paint(canvas, offset); 1141 super.paint(canvas, offset);
1140 } 1142 }
1141 1143
1142 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n'; 1144 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n';
1143 } 1145 }
1144 1146
1145 class RenderTransform extends RenderProxyBox { 1147 class RenderTransform extends RenderProxyBox {
1148 bool get createNewDisplayList => true;
1149
1146 RenderTransform({ 1150 RenderTransform({
1147 Matrix4 transform, 1151 Matrix4 transform,
1148 RenderBox child 1152 RenderBox child
1149 }) : super(child) { 1153 }) : super(child) {
1150 assert(transform != null); 1154 assert(transform != null);
1151 this.transform = transform; 1155 this.transform = transform;
1152 } 1156 }
1153 1157
1154 Matrix4 _transform; 1158 Matrix4 _transform;
1155 1159
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 class ViewConstraints { 1283 class ViewConstraints {
1280 const ViewConstraints({ 1284 const ViewConstraints({
1281 this.size: Size.zero, 1285 this.size: Size.zero,
1282 this.orientation 1286 this.orientation
1283 }); 1287 });
1284 final Size size; 1288 final Size size;
1285 final int orientation; 1289 final int orientation;
1286 } 1290 }
1287 1291
1288 class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> { 1292 class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> {
1293 bool get createNewDisplayList => true;
1289 1294
1290 RenderView({ 1295 RenderView({
1291 RenderBox child, 1296 RenderBox child,
1292 this.timeForRotation: const Duration(microseconds: 83333) 1297 this.timeForRotation: const Duration(microseconds: 83333)
1293 }) { 1298 }) {
1294 this.child = child; 1299 this.child = child;
1295 } 1300 }
1296 1301
1297 Size _size = Size.zero; 1302 Size _size = Size.zero;
1298 Size get size => _size; 1303 Size get size => _size;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 return true; 1350 return true;
1346 } 1351 }
1347 1352
1348 void paint(PaintingCanvas canvas, Offset offset) { 1353 void paint(PaintingCanvas canvas, Offset offset) {
1349 if (child != null) 1354 if (child != null)
1350 canvas.paintChild(child, offset.toPoint()); 1355 canvas.paintChild(child, offset.toPoint());
1351 } 1356 }
1352 1357
1353 void paintFrame() { 1358 void paintFrame() {
1354 sky.tracing.begin('RenderView.paintFrame'); 1359 sky.tracing.begin('RenderView.paintFrame');
1355 RenderObject.debugDoingPaint = true;
1356 try { 1360 try {
1357 sky.PictureRecorder recorder = new sky.PictureRecorder(); 1361 sky.PictureRecorder recorder = new sky.PictureRecorder();
1358 PaintingCanvas canvas = new PaintingCanvas(recorder, _size); 1362 PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds);
1359 paint(canvas, Offset.zero); 1363 canvas.drawPaintingNode(paintingNode, Point.origin);
1360 sky.view.picture = recorder.endRecording(); 1364 sky.view.picture = recorder.endRecording();
1361 } finally { 1365 } finally {
1362 RenderObject.debugDoingPaint = false;
1363 sky.tracing.end('RenderView.paintFrame'); 1366 sky.tracing.end('RenderView.paintFrame');
1364 } 1367 }
1365 } 1368 }
1366 1369
1370 Rect get paintBounds => Point.origin & size;
1367 } 1371 }
1368 1372
1369 // HELPER METHODS FOR RENDERBOX CONTAINERS 1373 // HELPER METHODS FOR RENDERBOX CONTAINERS
1370 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend erObjectMixin<ChildType, ParentDataType> { 1374 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend erObjectMixin<ChildType, ParentDataType> {
1371 1375
1372 // This class, by convention, doesn't override any members of the superclass. 1376 // This class, by convention, doesn't override any members of the superclass.
1373 // It only provides helper functions that subclasses can call. 1377 // It only provides helper functions that subclasses can call.
1374 1378
1375 double defaultComputeDistanceToFirstActualBaseline(TextBaseline baseline) { 1379 double defaultComputeDistanceToFirstActualBaseline(TextBaseline baseline) {
1376 assert(!needsLayout); 1380 assert(!needsLayout);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 1425
1422 void defaultPaint(PaintingCanvas canvas, Offset offset) { 1426 void defaultPaint(PaintingCanvas canvas, Offset offset) {
1423 RenderBox child = firstChild; 1427 RenderBox child = firstChild;
1424 while (child != null) { 1428 while (child != null) {
1425 assert(child.parentData is ParentDataType); 1429 assert(child.parentData is ParentDataType);
1426 canvas.paintChild(child, child.parentData.position + offset); 1430 canvas.paintChild(child, child.parentData.position + offset);
1427 child = child.parentData.nextSibling; 1431 child = child.parentData.nextSibling;
1428 } 1432 }
1429 } 1433 }
1430 } 1434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698