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

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

Issue 1190123003: Decouple Canvas from DisplayList and map Picture and PictureRecorder more directly to their Skia co… (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebased version of previous patch Created 5 years, 6 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 357 }
358 } 358 }
359 359
360 void hitTestChildren(HitTestResult result, { Point position }) { 360 void hitTestChildren(HitTestResult result, { Point position }) {
361 if (child != null) 361 if (child != null)
362 child.hitTest(result, position: position); 362 child.hitTest(result, position: position);
363 else 363 else
364 super.hitTestChildren(result, position: position); 364 super.hitTestChildren(result, position: position);
365 } 365 }
366 366
367 void paint(RenderObjectDisplayList canvas) { 367 void paint(RenderCanvas canvas) {
368 if (child != null) 368 if (child != null)
369 child.paint(canvas); 369 child.paint(canvas);
370 } 370 }
371 371
372 } 372 }
373 373
374 class RenderConstrainedBox extends RenderProxyBox { 374 class RenderConstrainedBox extends RenderProxyBox {
375 RenderConstrainedBox({ 375 RenderConstrainedBox({
376 RenderBox child, 376 RenderBox child,
377 BoxConstraints additionalConstraints 377 BoxConstraints additionalConstraints
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 double get opacity => _opacity; 478 double get opacity => _opacity;
479 void set opacity (double value) { 479 void set opacity (double value) {
480 assert(value != null); 480 assert(value != null);
481 assert(value >= 0.0 && value <= 1.0); 481 assert(value >= 0.0 && value <= 1.0);
482 if (_opacity == value) 482 if (_opacity == value)
483 return; 483 return;
484 _opacity = value; 484 _opacity = value;
485 markNeedsPaint(); 485 markNeedsPaint();
486 } 486 }
487 487
488 void paint(RenderObjectDisplayList canvas) { 488 void paint(RenderCanvas canvas) {
489 if (child != null) { 489 if (child != null) {
490 int a = (_opacity * 255).round(); 490 int a = (_opacity * 255).round();
491 491
492 if (a == 0) 492 if (a == 0)
493 return; 493 return;
494 494
495 if (a == 255) { 495 if (a == 255) {
496 child.paint(canvas); 496 child.paint(canvas);
497 return; 497 return;
498 } 498 }
(...skipping 26 matching lines...) Expand all
525 sky.TransferMode _transferMode; 525 sky.TransferMode _transferMode;
526 sky.TransferMode get transferMode => _transferMode; 526 sky.TransferMode get transferMode => _transferMode;
527 void set transferMode (sky.TransferMode value) { 527 void set transferMode (sky.TransferMode value) {
528 assert(value != null); 528 assert(value != null);
529 if (_transferMode == value) 529 if (_transferMode == value)
530 return; 530 return;
531 _transferMode = value; 531 _transferMode = value;
532 markNeedsPaint(); 532 markNeedsPaint();
533 } 533 }
534 534
535 void paint(RenderObjectDisplayList canvas) { 535 void paint(RenderCanvas canvas) {
536 if (child != null) { 536 if (child != null) {
537 Paint paint = new Paint() 537 Paint paint = new Paint()
538 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode)); 538 ..setColorFilter(new sky.ColorFilter.mode(_color, _transferMode));
539 canvas.saveLayer(null, paint); 539 canvas.saveLayer(null, paint);
540 child.paint(canvas); 540 child.paint(canvas);
541 canvas.restore(); 541 canvas.restore();
542 } 542 }
543 } 543 }
544 } 544 }
545 545
546 class RenderClipRect extends RenderProxyBox { 546 class RenderClipRect extends RenderProxyBox {
547 RenderClipRect({ RenderBox child }) : super(child); 547 RenderClipRect({ RenderBox child }) : super(child);
548 548
549 void paint(RenderObjectDisplayList canvas) { 549 void paint(RenderCanvas canvas) {
550 if (child != null) { 550 if (child != null) {
551 canvas.save(); 551 canvas.save();
552 canvas.clipRect(new Rect.fromSize(size)); 552 canvas.clipRect(new Rect.fromSize(size));
553 child.paint(canvas); 553 child.paint(canvas);
554 canvas.restore(); 554 canvas.restore();
555 } 555 }
556 } 556 }
557 } 557 }
558 558
559 class RenderClipOval extends RenderProxyBox { 559 class RenderClipOval extends RenderProxyBox {
560 RenderClipOval({ RenderBox child }) : super(child); 560 RenderClipOval({ RenderBox child }) : super(child);
561 561
562 void paint(RenderObjectDisplayList canvas) { 562 void paint(RenderCanvas canvas) {
563 if (child != null) { 563 if (child != null) {
564 Rect rect = new Rect.fromSize(size); 564 Rect rect = new Rect.fromSize(size);
565 canvas.saveLayer(rect, new Paint()); 565 canvas.saveLayer(rect, new Paint());
566 Path path = new Path(); 566 Path path = new Path();
567 path.addOval(rect); 567 path.addOval(rect);
568 canvas.clipPath(path); 568 canvas.clipPath(path);
569 child.paint(canvas); 569 child.paint(canvas);
570 canvas.restore(); 570 canvas.restore();
571 } 571 }
572 } 572 }
573 } 573 }
574 574
575 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> { 575 abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi n<RenderBox> {
576 576
577 // Abstract class for one-child-layout render boxes 577 // Abstract class for one-child-layout render boxes
578 578
579 RenderShiftedBox(RenderBox child) { 579 RenderShiftedBox(RenderBox child) {
580 this.child = child; 580 this.child = child;
581 } 581 }
582 582
583 void paint(RenderObjectDisplayList canvas) { 583 void paint(RenderCanvas canvas) {
584 if (child != null) 584 if (child != null)
585 canvas.paintChild(child, child.parentData.position); 585 canvas.paintChild(child, child.parentData.position);
586 } 586 }
587 587
588 void hitTestChildren(HitTestResult result, { Point position }) { 588 void hitTestChildren(HitTestResult result, { Point position }) {
589 if (child != null) { 589 if (child != null) {
590 assert(child.parentData is BoxParentData); 590 assert(child.parentData is BoxParentData);
591 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch ild.size); 591 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch ild.size);
592 if (childBounds.contains(position)) { 592 if (childBounds.contains(position)) {
593 child.hitTest(result, position: new Point(position.x - child.parentData. position.x, 593 child.hitTest(result, position: new Point(position.x - child.parentData. position.x,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 } 809 }
810 810
811 double getMaxIntrinsicHeight(BoxConstraints constraints) { 811 double getMaxIntrinsicHeight(BoxConstraints constraints) {
812 return _sizeForConstraints(constraints).height; 812 return _sizeForConstraints(constraints).height;
813 } 813 }
814 814
815 void performLayout() { 815 void performLayout() {
816 size = _sizeForConstraints(constraints); 816 size = _sizeForConstraints(constraints);
817 } 817 }
818 818
819 void paint(RenderObjectDisplayList canvas) { 819 void paint(RenderCanvas canvas) {
820 if (_image == null) return; 820 if (_image == null) return;
821 bool needsScale = size.width != _image.width || size.height != _image.height ; 821 bool needsScale = size.width != _image.width || size.height != _image.height ;
822 if (needsScale) { 822 if (needsScale) {
823 double widthScale = size.width / _image.width; 823 double widthScale = size.width / _image.width;
824 double heightScale = size.height / _image.height; 824 double heightScale = size.height / _image.height;
825 canvas.save(); 825 canvas.save();
826 canvas.scale(widthScale, heightScale); 826 canvas.scale(widthScale, heightScale);
827 } 827 }
828 Paint paint = new Paint(); 828 Paint paint = new Paint();
829 canvas.drawImage(_image, 0.0, 0.0, paint); 829 canvas.drawImage(_image, 0.0, 0.0, paint);
(...skipping 14 matching lines...) Expand all
844 BoxPainter _painter; 844 BoxPainter _painter;
845 BoxDecoration get decoration => _painter.decoration; 845 BoxDecoration get decoration => _painter.decoration;
846 void set decoration (BoxDecoration value) { 846 void set decoration (BoxDecoration value) {
847 assert(value != null); 847 assert(value != null);
848 if (value == _painter.decoration) 848 if (value == _painter.decoration)
849 return; 849 return;
850 _painter.decoration = value; 850 _painter.decoration = value;
851 markNeedsPaint(); 851 markNeedsPaint();
852 } 852 }
853 853
854 void paint(RenderObjectDisplayList canvas) { 854 void paint(RenderCanvas canvas) {
855 assert(size.width != null); 855 assert(size.width != null);
856 assert(size.height != null); 856 assert(size.height != null);
857 _painter.paint(canvas, new Rect.fromSize(size)); 857 _painter.paint(canvas, new Rect.fromSize(size));
858 super.paint(canvas); 858 super.paint(canvas);
859 } 859 }
860 860
861 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n'; 861 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n';
862 } 862 }
863 863
864 class RenderTransform extends RenderProxyBox { 864 class RenderTransform extends RenderProxyBox {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 Matrix4 inverse = new Matrix4.zero(); 914 Matrix4 inverse = new Matrix4.zero();
915 /* double det = */ inverse.copyInverse(_transform); 915 /* double det = */ inverse.copyInverse(_transform);
916 // TODO(abarth): Check the determinant for degeneracy. 916 // TODO(abarth): Check the determinant for degeneracy.
917 917
918 Vector3 position3 = new Vector3(position.x, position.y, 0.0); 918 Vector3 position3 = new Vector3(position.x, position.y, 0.0);
919 Vector3 transformed3 = inverse.transform3(position3); 919 Vector3 transformed3 = inverse.transform3(position3);
920 Point transformed = new Point(transformed3.x, transformed3.y); 920 Point transformed = new Point(transformed3.x, transformed3.y);
921 super.hitTestChildren(result, position: transformed); 921 super.hitTestChildren(result, position: transformed);
922 } 922 }
923 923
924 void paint(RenderObjectDisplayList canvas) { 924 void paint(RenderCanvas canvas) {
925 canvas.save(); 925 canvas.save();
926 canvas.concat(_transform.storage); 926 canvas.concat(_transform.storage);
927 super.paint(canvas); 927 super.paint(canvas);
928 canvas.restore(); 928 canvas.restore();
929 } 929 }
930 930
931 String debugDescribeSettings(String prefix) { 931 String debugDescribeSettings(String prefix) {
932 List<String> result = _transform.toString().split('\n').map((s) => '$prefix $s\n').toList(); 932 List<String> result = _transform.toString().split('\n').map((s) => '$prefix $s\n').toList();
933 result.removeLast(); 933 result.removeLast();
934 return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${ result.join()}'; 934 return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${ result.join()}';
(...skipping 15 matching lines...) Expand all
950 void performLayout() { 950 void performLayout() {
951 Size oldSize = size; 951 Size oldSize = size;
952 952
953 super.performLayout(); 953 super.performLayout();
954 954
955 if (oldSize != size) 955 if (oldSize != size)
956 callback(size); 956 callback(size);
957 } 957 }
958 } 958 }
959 959
960 typedef void CustomPaintCallback(sky.Canvas canvas, Size size); 960 typedef void CustomPaintCallback(RenderCanvas canvas, Size size);
961 961
962 class RenderCustomPaint extends RenderProxyBox { 962 class RenderCustomPaint extends RenderProxyBox {
963 963
964 RenderCustomPaint({ 964 RenderCustomPaint({
965 CustomPaintCallback callback, 965 CustomPaintCallback callback,
966 RenderBox child 966 RenderBox child
967 }) : super(child) { 967 }) : super(child) {
968 assert(callback != null); 968 assert(callback != null);
969 _callback = callback; 969 _callback = callback;
970 } 970 }
971 971
972 CustomPaintCallback _callback; 972 CustomPaintCallback _callback;
973 void set callback (CustomPaintCallback value) { 973 void set callback (CustomPaintCallback value) {
974 assert(value != null || !attached); 974 assert(value != null || !attached);
975 if (_callback == value) 975 if (_callback == value)
976 return; 976 return;
977 _callback = value; 977 _callback = value;
978 markNeedsPaint(); 978 markNeedsPaint();
979 } 979 }
980 980
981 void attach() { 981 void attach() {
982 assert(_callback != null); 982 assert(_callback != null);
983 super.attach(); 983 super.attach();
984 } 984 }
985 985
986 void paint(RenderObjectDisplayList canvas) { 986 void paint(RenderCanvas canvas) {
987 assert(_callback != null); 987 assert(_callback != null);
988 _callback(canvas, size); 988 _callback(canvas, size);
989 super.paint(canvas); 989 super.paint(canvas);
990 } 990 }
991 } 991 }
992 992
993 // RENDER VIEW LAYOUT MANAGER 993 // RENDER VIEW LAYOUT MANAGER
994 994
995 class ViewConstraints { 995 class ViewConstraints {
996 996
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 bool hitTest(HitTestResult result, { Point position }) { 1058 bool hitTest(HitTestResult result, { Point position }) {
1059 if (child != null) { 1059 if (child != null) {
1060 Rect childBounds = new Rect.fromSize(child.size); 1060 Rect childBounds = new Rect.fromSize(child.size);
1061 if (childBounds.contains(position)) 1061 if (childBounds.contains(position))
1062 child.hitTest(result, position: position); 1062 child.hitTest(result, position: position);
1063 } 1063 }
1064 result.add(new HitTestEntry(this)); 1064 result.add(new HitTestEntry(this));
1065 return true; 1065 return true;
1066 } 1066 }
1067 1067
1068 void paint(RenderObjectDisplayList canvas) { 1068 void paint(RenderCanvas canvas) {
1069 if (child != null) 1069 if (child != null)
1070 canvas.paintChild(child, Point.origin); 1070 canvas.paintChild(child, Point.origin);
1071 } 1071 }
1072 1072
1073 void paintFrame() { 1073 void paintFrame() {
1074 sky.tracing.begin('RenderView.paintFrame'); 1074 sky.tracing.begin('RenderView.paintFrame');
1075 RenderObject.debugDoingPaint = true; 1075 RenderObject.debugDoingPaint = true;
1076 try { 1076 try {
1077 RenderObjectDisplayList canvas = new RenderObjectDisplayList(sky.view.widt h, sky.view.height); 1077 sky.PictureRecorder recorder = new sky.PictureRecorder();
1078 RenderCanvas canvas = new RenderCanvas(recorder, width, height);
1078 paint(canvas); 1079 paint(canvas);
1079 sky.view.picture = canvas.endRecording(); 1080 sky.view.picture = recorder.endRecording();
1080 } finally { 1081 } finally {
1081 RenderObject.debugDoingPaint = false; 1082 RenderObject.debugDoingPaint = false;
1082 sky.tracing.end('RenderView.paintFrame'); 1083 sky.tracing.end('RenderView.paintFrame');
1083 } 1084 }
1084 } 1085 }
1085 1086
1086 } 1087 }
1087 1088
1088 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS 1089 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS
1089 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend erObjectMixin<ChildType, ParentDataType> { 1090 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend erObjectMixin<ChildType, ParentDataType> {
1090 1091
1091 void defaultHitTestChildren(HitTestResult result, { Point position }) { 1092 void defaultHitTestChildren(HitTestResult result, { Point position }) {
1092 // the x, y parameters have the top left of the node's box as the origin 1093 // the x, y parameters have the top left of the node's box as the origin
1093 ChildType child = lastChild; 1094 ChildType child = lastChild;
1094 while (child != null) { 1095 while (child != null) {
1095 assert(child.parentData is ParentDataType); 1096 assert(child.parentData is ParentDataType);
1096 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch ild.size); 1097 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch ild.size);
1097 if (childBounds.contains(position)) { 1098 if (childBounds.contains(position)) {
1098 if (child.hitTest(result, position: new Point(position.x - child.parentD ata.position.x, 1099 if (child.hitTest(result, position: new Point(position.x - child.parentD ata.position.x,
1099 position.y - child.par entData.position.y))) 1100 position.y - child.par entData.position.y)))
1100 break; 1101 break;
1101 } 1102 }
1102 child = child.parentData.previousSibling; 1103 child = child.parentData.previousSibling;
1103 } 1104 }
1104 } 1105 }
1105 1106
1106 void defaultPaint(RenderObjectDisplayList canvas) { 1107 void defaultPaint(RenderCanvas canvas) {
1107 RenderBox child = firstChild; 1108 RenderBox child = firstChild;
1108 while (child != null) { 1109 while (child != null) {
1109 assert(child.parentData is ParentDataType); 1110 assert(child.parentData is ParentDataType);
1110 canvas.paintChild(child, child.parentData.position); 1111 canvas.paintChild(child, child.parentData.position);
1111 child = child.parentData.nextSibling; 1112 child = child.parentData.nextSibling;
1112 } 1113 }
1113 } 1114 }
1114 } 1115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698