OLD | NEW |
1 | 1 |
| 2 import 'dart:sky' as sky; |
| 3 |
| 4 import 'package:sky/framework/rendering/box.dart'; |
2 import 'package:sky/framework/rendering/object.dart'; | 5 import 'package:sky/framework/rendering/object.dart'; |
3 import 'package:sky/framework/rendering/box.dart'; | |
4 import 'dart:sky' as sky; | |
5 | 6 |
6 typedef void Logger (String s); | 7 typedef void Logger (String s); |
7 | 8 |
8 class TestDisplayList extends RenderObjectDisplayList { | 9 class TestDisplayList extends RenderObjectDisplayList { |
9 TestDisplayList(double width, double height, this.logger, { this.indent: '' })
: | 10 TestDisplayList(double width, double height, this.logger, { this.indent: '' })
: |
10 this.width = width, | 11 this.width = width, |
11 this.height = height, | 12 this.height = height, |
12 super(width, height) { | 13 super(width, height) { |
13 log("TestDisplayList() constructor: $width x $height"); | 14 log("TestDisplayList() constructor: $width x $height"); |
14 } | 15 } |
15 | 16 |
16 final String indent; | 17 final String indent; |
17 final double width; | 18 final double width; |
18 final double height; | 19 final double height; |
19 | 20 |
20 Logger logger; | 21 Logger logger; |
21 void log(String s) { | 22 void log(String s) { |
22 logger("${indent} ${s}"); | 23 logger("${indent} ${s}"); |
23 } | 24 } |
24 | 25 |
25 String explainPaint(sky.Paint paint) { | 26 String explainPaint(Paint paint) { |
| 27 assert(paint.toString() == "Instance of 'Paint'"); // if this assertion fail
s, remove all calls to explainPaint with just inlining $paint |
26 return "Paint(${paint.color})"; | 28 return "Paint(${paint.color})"; |
27 } | 29 } |
28 | 30 |
29 void save() { | 31 void save() { |
30 log("save"); | 32 log("save"); |
31 } | 33 } |
32 | 34 |
33 void saveLayer(sky.Rect bounds, sky.Paint paint) { | 35 void saveLayer(Rect bounds, Paint paint) { |
34 log("saveLayer(${bounds.top}:${bounds.left}:${bounds.bottom}:${bounds.right}
, ${explainPaint(paint)})"); | 36 log("saveLayer($bounds, ${explainPaint(paint)})"); |
35 } | 37 } |
36 | 38 |
37 void restore() { | 39 void restore() { |
38 log("restore"); | 40 log("restore"); |
39 } | 41 } |
40 | 42 |
41 void translate(double dx, double dy) { | 43 void translate(double dx, double dy) { |
42 log("translate($dx, $dy)"); | 44 log("translate($dx, $dy)"); |
43 } | 45 } |
44 | 46 |
45 void scale(double sx, double sy) { | 47 void scale(double sx, double sy) { |
46 log("scale($sx, $sy)"); | 48 log("scale($sx, $sy)"); |
47 } | 49 } |
48 | 50 |
49 void rotate(double radians) { | 51 void rotate(double radians) { |
50 log("rotate($radians)"); | 52 log("rotate($radians)"); |
51 } | 53 } |
52 | 54 |
53 void skew(double sx, double sy) { | 55 void skew(double sx, double sy) { |
54 log("skew($sx, $sy)"); | 56 log("skew($sx, $sy)"); |
55 } | 57 } |
56 | 58 |
57 void concat(List<double> matrix9) { | 59 void concat(List<double> matrix9) { |
58 log("concat($matrix9)"); | 60 log("concat($matrix9)"); |
59 } | 61 } |
60 | 62 |
61 void clipRect(sky.Rect rect) { | 63 void clipRect(Rect rect) { |
62 log("clipRect(${rect.top}:${rect.left}:${rect.bottom}:${rect.right})"); | 64 log("clipRect($rect)"); |
| 65 } |
| 66 |
| 67 void clipRRect(sky.RRect rrect) { |
| 68 log("clipRRect()"); |
| 69 } |
| 70 |
| 71 void clipPath(Path path) { |
| 72 log("clipPath($path)"); |
| 73 } |
| 74 |
| 75 void drawLine(double x0, double y0, double x1, double y1, Paint paint) { |
| 76 log("drawLine($x0, $y0, $x1, $y1, ${explainPaint(paint)})"); |
63 } | 77 } |
64 | 78 |
65 void drawPicture(sky.Picture picture) { | 79 void drawPicture(sky.Picture picture) { |
66 log("drawPicture()"); | 80 log("drawPicture($picture)"); |
67 } | 81 } |
68 | 82 |
69 void drawPaint(sky.Paint paint) { | 83 void drawPaint(Paint paint) { |
70 log("drawPaint(${explainPaint(paint)})"); | 84 log("drawPaint(${explainPaint(paint)})"); |
71 } | 85 } |
72 | 86 |
73 void drawRect(sky.Rect rect, sky.Paint paint) { | 87 void drawRect(Rect rect, Paint paint) { |
74 log("drawRect(${rect.top}:${rect.left}:${rect.bottom}:${rect.right}, ${expla
inPaint(paint)})"); | 88 log("drawRect($rect, ${explainPaint(paint)})"); |
75 } | 89 } |
76 | 90 |
77 void drawOval(sky.Rect rect, sky.Paint paint) { | 91 void drawRRect(sky.RRect rrect, Paint paint) { |
78 log("drawOval(${rect.top}:${rect.left}:${rect.bottom}:${rect.right}, ${expla
inPaint(paint)})"); | 92 log("drawRRect($rrect, ${explainPaint(paint)})"); |
79 } | 93 } |
80 | 94 |
81 void drawCircle(double x, double y, double radius, sky.Paint paint) { | 95 void drawOval(Rect rect, Paint paint) { |
| 96 log("drawOval($rect, ${explainPaint(paint)})"); |
| 97 } |
| 98 |
| 99 void drawCircle(double x, double y, double radius, Paint paint) { |
82 log("drawCircle($x, $y, $radius, ${explainPaint(paint)})"); | 100 log("drawCircle($x, $y, $radius, ${explainPaint(paint)})"); |
83 } | 101 } |
84 | 102 |
85 void drawPath(sky.Path path, sky.Paint paint) { | 103 void drawPath(Path path, Paint paint) { |
86 log("drawPath(Path, ${explainPaint(paint)})"); | 104 log("drawPath($path, ${explainPaint(paint)})"); |
87 } | 105 } |
88 | 106 |
89 void paintChild(RenderObject child, sky.Point position) { | 107 void drawImage(sky.Image image, double x, double y, Paint paint) { |
90 log("paintChild at ${position.x},${position.y}"); | 108 log("drawImage($image, $x, $y, ${explainPaint(paint)})"); |
| 109 } |
| 110 |
| 111 void paintChild(RenderObject child, Point position) { |
| 112 log("paintChild ${child.runtimeType} at $position"); |
91 child.paint(new TestDisplayList(width, height, logger, indent: "$indent |")
); | 113 child.paint(new TestDisplayList(width, height, logger, indent: "$indent |")
); |
92 } | 114 } |
93 } | 115 } |
94 | 116 |
95 class TestView extends RenderView { | 117 class TestRenderView extends RenderView { |
96 | 118 |
97 TestView({ | 119 TestRenderView([ RenderBox child = null ]) : super(child: child) { |
98 RenderBox child, | 120 print("TestRenderView enabled"); |
99 Duration timeForRotation | 121 attach(); |
100 }) : super(child: child, timeForRotation: timeForRotation) { | 122 rootConstraints = new ViewConstraints(width: 800.0, height: 600.0); // arbit
rary figures |
101 print("TestView enabled"); | 123 scheduleInitialLayout(); |
| 124 checkFrame(); |
102 } | 125 } |
103 | 126 |
104 int frame = 0; | 127 int frame = 0; |
105 | 128 |
106 String lastPaint = ''; | 129 String lastPaint = ''; |
107 void log(String s) { | 130 void log(String s) { |
108 lastPaint += "\n$s"; | 131 lastPaint += "\n$s"; |
109 } | 132 } |
110 | 133 |
111 void paintFrame() { | 134 void paintFrame() { |
112 RenderObject.debugDoingPaint = true; | 135 RenderObject.debugDoingPaint = true; |
113 frame += 1; | 136 frame += 1; |
| 137 lastPaint = ''; |
114 log("PAINT FOR FRAME #${frame} ---------------------------------------------
-"); | 138 log("PAINT FOR FRAME #${frame} ---------------------------------------------
-"); |
115 var canvas = new TestDisplayList(sky.view.width, sky.view.height, log, inden
t: "${frame} |"); | 139 var canvas = new TestDisplayList(rootConstraints.width, rootConstraints.heig
ht, log, indent: "${frame} |"); |
116 paint(canvas); | 140 paint(canvas); |
117 log("-----------------------------------------------------------------------
-"); | 141 log("-----------------------------------------------------------------------
-"); |
118 RenderObject.debugDoingPaint = false; | 142 RenderObject.debugDoingPaint = false; |
119 } | 143 } |
120 | 144 |
121 } | 145 void checkFrame() { |
122 | |
123 class TestApp { | |
124 | |
125 TestApp(RenderBox root) { | |
126 _renderView = new TestView(child: root); | |
127 _renderView.attach(); | |
128 _renderView.rootConstraints = new ViewConstraints(width: sky.view.width, hei
ght: sky.view.height); | |
129 _renderView.scheduleInitialLayout(); | |
130 RenderObject.flushLayout(); | 146 RenderObject.flushLayout(); |
131 _renderView.paintFrame(); | 147 paintFrame(); |
132 print(_renderView.lastPaint); // TODO(ianh): figure out how to make this fit
the unit testing framework better | 148 print(lastPaint); // TODO(ianh): figure out how to make this fit the unit te
sting framework better |
133 } | |
134 | |
135 RenderView _renderView; | |
136 | |
137 RenderBox get root => _renderView.child; | |
138 void set root(RenderBox value) { | |
139 _renderView.child = value; | |
140 } | |
141 void _beginFrame(double timeStamp) { | |
142 RenderObject.flushLayout(); | |
143 _renderView.paintFrame(); | |
144 print(_renderView.lastPaint); // TODO(ianh): figure out how to make this fit
the unit testing framework better | |
145 } | 149 } |
146 | 150 |
147 } | 151 } |
OLD | NEW |