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

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

Issue 1217933002: Rename RenderCanvas to PaintingCanvas to avoid confusion with other classes that inherit from Rende… (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 | « sky/sdk/lib/rendering/block.dart ('k') | sky/sdk/lib/rendering/flex.dart » ('j') | 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: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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 } 423 }
424 424
425 void hitTestChildren(HitTestResult result, { Point position }) { 425 void hitTestChildren(HitTestResult result, { Point position }) {
426 if (child != null) 426 if (child != null)
427 child.hitTest(result, position: position); 427 child.hitTest(result, position: position);
428 else 428 else
429 super.hitTestChildren(result, position: position); 429 super.hitTestChildren(result, position: position);
430 } 430 }
431 431
432 void paint(RenderCanvas canvas, Offset offset) { 432 void paint(PaintingCanvas canvas, Offset offset) {
433 if (child != null) 433 if (child != null)
434 child.paint(canvas, offset); 434 child.paint(canvas, offset);
435 } 435 }
436 436
437 } 437 }
438 438
439 class RenderConstrainedBox extends RenderProxyBox { 439 class RenderConstrainedBox extends RenderProxyBox {
440 RenderConstrainedBox({ 440 RenderConstrainedBox({
441 RenderBox child, 441 RenderBox child,
442 BoxConstraints additionalConstraints 442 BoxConstraints additionalConstraints
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 double get opacity => _opacity; 543 double get opacity => _opacity;
544 void set opacity (double value) { 544 void set opacity (double value) {
545 assert(value != null); 545 assert(value != null);
546 assert(value >= 0.0 && value <= 1.0); 546 assert(value >= 0.0 && value <= 1.0);
547 if (_opacity == value) 547 if (_opacity == value)
548 return; 548 return;
549 _opacity = value; 549 _opacity = value;
550 markNeedsPaint(); 550 markNeedsPaint();
551 } 551 }
552 552
553 void paint(RenderCanvas canvas, Offset offset) { 553 void paint(PaintingCanvas canvas, Offset offset) {
554 if (child != null) { 554 if (child != null) {
555 int a = (_opacity * 255).round(); 555 int a = (_opacity * 255).round();
556 556
557 if (a == 0) 557 if (a == 0)
558 return; 558 return;
559 559
560 if (a == 255) { 560 if (a == 255) {
561 child.paint(canvas, offset); 561 child.paint(canvas, offset);
562 return; 562 return;
563 } 563 }
(...skipping 26 matching lines...) Expand all
590 sky.TransferMode _transferMode; 590 sky.TransferMode _transferMode;
591 sky.TransferMode get transferMode => _transferMode; 591 sky.TransferMode get transferMode => _transferMode;
592 void set transferMode (sky.TransferMode value) { 592 void set transferMode (sky.TransferMode value) {
593 assert(value != null); 593 assert(value != null);
594 if (_transferMode == value) 594 if (_transferMode == value)
595 return; 595 return;
596 _transferMode = value; 596 _transferMode = value;
597 markNeedsPaint(); 597 markNeedsPaint();
598 } 598 }
599 599
600 void paint(RenderCanvas canvas, Offset offset) { 600 void paint(PaintingCanvas canvas, Offset offset) {
601 if (child != null) { 601 if (child != null) {
602 Paint paint = new Paint() 602 Paint paint = new Paint()
603 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode)); 603 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
604 canvas.saveLayer(null, paint); 604 canvas.saveLayer(null, paint);
605 child.paint(canvas, offset); 605 child.paint(canvas, offset);
606 canvas.restore(); 606 canvas.restore();
607 } 607 }
608 } 608 }
609 } 609 }
610 610
611 class RenderClipRect extends RenderProxyBox { 611 class RenderClipRect extends RenderProxyBox {
612 RenderClipRect({ RenderBox child }) : super(child); 612 RenderClipRect({ RenderBox child }) : super(child);
613 613
614 void paint(RenderCanvas canvas, Offset offset) { 614 void paint(PaintingCanvas canvas, Offset offset) {
615 if (child != null) { 615 if (child != null) {
616 canvas.save(); 616 canvas.save();
617 canvas.clipRect(offset & size); 617 canvas.clipRect(offset & size);
618 child.paint(canvas, offset); 618 child.paint(canvas, offset);
619 canvas.restore(); 619 canvas.restore();
620 } 620 }
621 } 621 }
622 } 622 }
623 623
624 class RenderClipRRect extends RenderProxyBox { 624 class RenderClipRRect extends RenderProxyBox {
(...skipping 16 matching lines...) Expand all
641 double _yRadius; 641 double _yRadius;
642 double get yRadius => _yRadius; 642 double get yRadius => _yRadius;
643 void set yRadius (double value) { 643 void set yRadius (double value) {
644 assert(value != null); 644 assert(value != null);
645 if (_yRadius == value) 645 if (_yRadius == value)
646 return; 646 return;
647 _yRadius = value; 647 _yRadius = value;
648 markNeedsPaint(); 648 markNeedsPaint();
649 } 649 }
650 650
651 void paint(RenderCanvas canvas, Offset offset) { 651 void paint(PaintingCanvas canvas, Offset offset) {
652 if (child != null) { 652 if (child != null) {
653 Rect rect = offset & size; 653 Rect rect = offset & size;
654 canvas.saveLayer(rect, new Paint()); 654 canvas.saveLayer(rect, new Paint());
655 sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius); 655 sky.RRect rrect = new sky.RRect()..setRectXY(rect, xRadius, yRadius);
656 canvas.clipRRect(rrect); 656 canvas.clipRRect(rrect);
657 child.paint(canvas, offset); 657 child.paint(canvas, offset);
658 canvas.restore(); 658 canvas.restore();
659 } 659 }
660 } 660 }
661 } 661 }
662 662
663 class RenderClipOval extends RenderProxyBox { 663 class RenderClipOval extends RenderProxyBox {
664 RenderClipOval({ RenderBox child }) : super(child); 664 RenderClipOval({ RenderBox child }) : super(child);
665 665
666 void paint(RenderCanvas canvas, Offset offset) { 666 void paint(PaintingCanvas canvas, Offset offset) {
667 if (child != null) { 667 if (child != null) {
668 Rect rect = offset & size; 668 Rect rect = offset & size;
669 canvas.saveLayer(rect, new Paint()); 669 canvas.saveLayer(rect, new Paint());
670 Path path = new Path(); 670 Path path = new Path();
671 path.addOval(rect); 671 path.addOval(rect);
672 canvas.clipPath(path); 672 canvas.clipPath(path);
673 child.paint(canvas, offset); 673 child.paint(canvas, offset);
674 canvas.restore(); 674 canvas.restore();
675 } 675 }
676 } 676 }
677 } 677 }
678 678
679 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> { 679 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> {
680 680
681 // Abstract class for one-child-layout render boxes 681 // Abstract class for one-child-layout render boxes
682 682
683 RenderShiftedBox(RenderBox child) { 683 RenderShiftedBox(RenderBox child) {
684 this.child = child; 684 this.child = child;
685 } 685 }
686 686
687 void paint(RenderCanvas canvas, Offset offset) { 687 void paint(PaintingCanvas canvas, Offset offset) {
688 if (child != null) 688 if (child != null)
689 canvas.paintChild(child, child.parentData.position + offset); 689 canvas.paintChild(child, child.parentData.position + offset);
690 } 690 }
691 691
692 double getDistanceToActualBaseline(TextBaseline baseline) { 692 double getDistanceToActualBaseline(TextBaseline baseline) {
693 double result; 693 double result;
694 if (child != null) { 694 if (child != null) {
695 assert(!needsLayout); 695 assert(!needsLayout);
696 result = child.getDistanceToActualBaseline(baseline); 696 result = child.getDistanceToActualBaseline(baseline);
697 assert(child.parentData is BoxParentData); 697 assert(child.parentData is BoxParentData);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 } 927 }
928 928
929 double getMaxIntrinsicHeight(BoxConstraints constraints) { 929 double getMaxIntrinsicHeight(BoxConstraints constraints) {
930 return _sizeForConstraints(constraints).height; 930 return _sizeForConstraints(constraints).height;
931 } 931 }
932 932
933 void performLayout() { 933 void performLayout() {
934 size = _sizeForConstraints(constraints); 934 size = _sizeForConstraints(constraints);
935 } 935 }
936 936
937 void paint(RenderCanvas canvas, Offset offset) { 937 void paint(PaintingCanvas canvas, Offset offset) {
938 if (_image == null) 938 if (_image == null)
939 return; 939 return;
940 bool needsScale = size.width != _image.width || size.height != _image.height ; 940 bool needsScale = size.width != _image.width || size.height != _image.height ;
941 if (needsScale) { 941 if (needsScale) {
942 double widthScale = size.width / _image.width; 942 double widthScale = size.width / _image.width;
943 double heightScale = size.height / _image.height; 943 double heightScale = size.height / _image.height;
944 canvas.save(); 944 canvas.save();
945 canvas.translate(offset.dx, offset.dy); 945 canvas.translate(offset.dx, offset.dy);
946 canvas.scale(widthScale, heightScale); 946 canvas.scale(widthScale, heightScale);
947 offset = Offset.zero; 947 offset = Offset.zero;
(...skipping 17 matching lines...) Expand all
965 BoxPainter _painter; 965 BoxPainter _painter;
966 BoxDecoration get decoration => _painter.decoration; 966 BoxDecoration get decoration => _painter.decoration;
967 void set decoration (BoxDecoration value) { 967 void set decoration (BoxDecoration value) {
968 assert(value != null); 968 assert(value != null);
969 if (value == _painter.decoration) 969 if (value == _painter.decoration)
970 return; 970 return;
971 _painter.decoration = value; 971 _painter.decoration = value;
972 markNeedsPaint(); 972 markNeedsPaint();
973 } 973 }
974 974
975 void paint(RenderCanvas canvas, Offset offset) { 975 void paint(PaintingCanvas canvas, Offset offset) {
976 assert(size.width != null); 976 assert(size.width != null);
977 assert(size.height != null); 977 assert(size.height != null);
978 _painter.paint(canvas, offset & size); 978 _painter.paint(canvas, offset & size);
979 super.paint(canvas, offset); 979 super.paint(canvas, offset);
980 } 980 }
981 981
982 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n'; 982 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n';
983 } 983 }
984 984
985 class RenderTransform extends RenderProxyBox { 985 class RenderTransform extends RenderProxyBox {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 Matrix4 inverse = new Matrix4.zero(); 1035 Matrix4 inverse = new Matrix4.zero();
1036 /* double det = */ inverse.copyInverse(_transform); 1036 /* double det = */ inverse.copyInverse(_transform);
1037 // TODO(abarth): Check the determinant for degeneracy. 1037 // TODO(abarth): Check the determinant for degeneracy.
1038 1038
1039 Vector3 position3 = new Vector3(position.x, position.y, 0.0); 1039 Vector3 position3 = new Vector3(position.x, position.y, 0.0);
1040 Vector3 transformed3 = inverse.transform3(position3); 1040 Vector3 transformed3 = inverse.transform3(position3);
1041 Point transformed = new Point(transformed3.x, transformed3.y); 1041 Point transformed = new Point(transformed3.x, transformed3.y);
1042 super.hitTestChildren(result, position: transformed); 1042 super.hitTestChildren(result, position: transformed);
1043 } 1043 }
1044 1044
1045 void paint(RenderCanvas canvas, Offset offset) { 1045 void paint(PaintingCanvas canvas, Offset offset) {
1046 canvas.save(); 1046 canvas.save();
1047 canvas.translate(offset.dx, offset.dy); 1047 canvas.translate(offset.dx, offset.dy);
1048 canvas.concat(_transform.storage); 1048 canvas.concat(_transform.storage);
1049 super.paint(canvas, Offset.zero); 1049 super.paint(canvas, Offset.zero);
1050 canvas.restore(); 1050 canvas.restore();
1051 } 1051 }
1052 1052
1053 String debugDescribeSettings(String prefix) { 1053 String debugDescribeSettings(String prefix) {
1054 List<String> result = _transform.toString().split('\n').map((s) => '$prefix $s\n').toList(); 1054 List<String> result = _transform.toString().split('\n').map((s) => '$prefix $s\n').toList();
1055 result.removeLast(); 1055 result.removeLast();
(...skipping 16 matching lines...) Expand all
1072 void performLayout() { 1072 void performLayout() {
1073 Size oldSize = size; 1073 Size oldSize = size;
1074 1074
1075 super.performLayout(); 1075 super.performLayout();
1076 1076
1077 if (oldSize != size) 1077 if (oldSize != size)
1078 callback(size); 1078 callback(size);
1079 } 1079 }
1080 } 1080 }
1081 1081
1082 typedef void CustomPaintCallback(RenderCanvas canvas, Size size); 1082 typedef void CustomPaintCallback(PaintingCanvas canvas, Size size);
1083 1083
1084 class RenderCustomPaint extends RenderProxyBox { 1084 class RenderCustomPaint extends RenderProxyBox {
1085 1085
1086 RenderCustomPaint({ 1086 RenderCustomPaint({
1087 CustomPaintCallback callback, 1087 CustomPaintCallback callback,
1088 RenderBox child 1088 RenderBox child
1089 }) : super(child) { 1089 }) : super(child) {
1090 assert(callback != null); 1090 assert(callback != null);
1091 _callback = callback; 1091 _callback = callback;
1092 } 1092 }
1093 1093
1094 CustomPaintCallback _callback; 1094 CustomPaintCallback _callback;
1095 void set callback (CustomPaintCallback value) { 1095 void set callback (CustomPaintCallback value) {
1096 assert(value != null || !attached); 1096 assert(value != null || !attached);
1097 if (_callback == value) 1097 if (_callback == value)
1098 return; 1098 return;
1099 _callback = value; 1099 _callback = value;
1100 markNeedsPaint(); 1100 markNeedsPaint();
1101 } 1101 }
1102 1102
1103 void attach() { 1103 void attach() {
1104 assert(_callback != null); 1104 assert(_callback != null);
1105 super.attach(); 1105 super.attach();
1106 } 1106 }
1107 1107
1108 void paint(RenderCanvas canvas, Offset offset) { 1108 void paint(PaintingCanvas canvas, Offset offset) {
1109 assert(_callback != null); 1109 assert(_callback != null);
1110 canvas.translate(offset.dx, offset.dy); 1110 canvas.translate(offset.dx, offset.dy);
1111 _callback(canvas, size); 1111 _callback(canvas, size);
1112 super.paint(canvas, Offset.zero); 1112 super.paint(canvas, Offset.zero);
1113 canvas.translate(-offset.dx, -offset.dy); 1113 canvas.translate(-offset.dx, -offset.dy);
1114 } 1114 }
1115 } 1115 }
1116 1116
1117 // RENDER VIEW LAYOUT MANAGER 1117 // RENDER VIEW LAYOUT MANAGER
1118 1118
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 bool hitTest(HitTestResult result, { Point position }) { 1174 bool hitTest(HitTestResult result, { Point position }) {
1175 if (child != null) { 1175 if (child != null) {
1176 Rect childBounds = Point.origin & child.size; 1176 Rect childBounds = Point.origin & child.size;
1177 if (childBounds.contains(position)) 1177 if (childBounds.contains(position))
1178 child.hitTest(result, position: position); 1178 child.hitTest(result, position: position);
1179 } 1179 }
1180 result.add(new HitTestEntry(this)); 1180 result.add(new HitTestEntry(this));
1181 return true; 1181 return true;
1182 } 1182 }
1183 1183
1184 void paint(RenderCanvas canvas, Offset offset) { 1184 void paint(PaintingCanvas canvas, Offset offset) {
1185 if (child != null) 1185 if (child != null)
1186 canvas.paintChild(child, offset.toPoint()); 1186 canvas.paintChild(child, offset.toPoint());
1187 } 1187 }
1188 1188
1189 void paintFrame() { 1189 void paintFrame() {
1190 sky.tracing.begin('RenderView.paintFrame'); 1190 sky.tracing.begin('RenderView.paintFrame');
1191 RenderObject.debugDoingPaint = true; 1191 RenderObject.debugDoingPaint = true;
1192 try { 1192 try {
1193 sky.PictureRecorder recorder = new sky.PictureRecorder(); 1193 sky.PictureRecorder recorder = new sky.PictureRecorder();
1194 RenderCanvas canvas = new RenderCanvas(recorder, _size); 1194 PaintingCanvas canvas = new PaintingCanvas(recorder, _size);
1195 paint(canvas, Offset.zero); 1195 paint(canvas, Offset.zero);
1196 sky.view.picture = recorder.endRecording(); 1196 sky.view.picture = recorder.endRecording();
1197 } finally { 1197 } finally {
1198 RenderObject.debugDoingPaint = false; 1198 RenderObject.debugDoingPaint = false;
1199 sky.tracing.end('RenderView.paintFrame'); 1199 sky.tracing.end('RenderView.paintFrame');
1200 } 1200 }
1201 } 1201 }
1202 1202
1203 } 1203 }
1204 1204
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 Rect childBounds = child.parentData.position & child.size; 1248 Rect childBounds = child.parentData.position & child.size;
1249 if (childBounds.contains(position)) { 1249 if (childBounds.contains(position)) {
1250 if (child.hitTest(result, position: new Point(position.x - child.parentD ata.position.x, 1250 if (child.hitTest(result, position: new Point(position.x - child.parentD ata.position.x,
1251 position.y - child.par entData.position.y))) 1251 position.y - child.par entData.position.y)))
1252 break; 1252 break;
1253 } 1253 }
1254 child = child.parentData.previousSibling; 1254 child = child.parentData.previousSibling;
1255 } 1255 }
1256 } 1256 }
1257 1257
1258 void defaultPaint(RenderCanvas canvas, Offset offset) { 1258 void defaultPaint(PaintingCanvas canvas, Offset offset) {
1259 RenderBox child = firstChild; 1259 RenderBox child = firstChild;
1260 while (child != null) { 1260 while (child != null) {
1261 assert(child.parentData is ParentDataType); 1261 assert(child.parentData is ParentDataType);
1262 canvas.paintChild(child, child.parentData.position + offset); 1262 canvas.paintChild(child, child.parentData.position + offset);
1263 child = child.parentData.nextSibling; 1263 child = child.parentData.nextSibling;
1264 } 1264 }
1265 } 1265 }
1266 } 1266 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/rendering/block.dart ('k') | sky/sdk/lib/rendering/flex.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698