| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:html'; | 5 import 'dart:html'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 /// A generic rendering task that can be scheduled. | 9 /// A generic rendering task that can be scheduled. |
| 10 abstract class RenderingTask { | 10 abstract class RenderingTask { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 Future<num> get next => _stream.stream.first; | 31 Future<num> get next => _stream.stream.first; |
| 32 | 32 |
| 33 /// Trigger the next barrier with an optional numer of ms elapsed. | 33 /// Trigger the next barrier with an optional numer of ms elapsed. |
| 34 void triggerRenderingBarrier({num step: 20}) { | 34 void triggerRenderingBarrier({num step: 20}) { |
| 35 assert(step != null); | 35 assert(step != null); |
| 36 _stream.add(_ms += step); | 36 _stream.add(_ms += step); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 /// MOCK synchronization system for timed barrier triggering. | |
| 41 class TimedRenderingBarrier implements RenderingBarrier { | |
| 42 final StreamController<num> _stream = new StreamController<num>.broadcast(); | |
| 43 num _ms = 0; | |
| 44 | |
| 45 Future<num> get next => _stream.stream.first; | |
| 46 | |
| 47 TimedRenderingBarrier({num milliseconds: 1}) { | |
| 48 assert(milliseconds != null); | |
| 49 assert(milliseconds > 0); | |
| 50 new Timer.periodic(new Duration(milliseconds: milliseconds), (Timer t) { | |
| 51 _stream.add(_ms += milliseconds); | |
| 52 }); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 /// RenderingTask queuing and synchronization system. | 40 /// RenderingTask queuing and synchronization system. |
| 57 class RenderingQueue { | 41 class RenderingQueue { |
| 58 final RenderingBarrier _barrier; | 42 final RenderingBarrier _barrier; |
| 59 final Queue<RenderingTask> _queue = new Queue<RenderingTask>(); | 43 final Queue<RenderingTask> _queue = new Queue<RenderingTask>(); |
| 60 | 44 |
| 61 bool get isEmpty => _queue.isEmpty; | 45 bool get isEmpty => _queue.isEmpty; |
| 62 bool get isNotEmpty => _queue.isNotEmpty; | 46 bool get isNotEmpty => _queue.isNotEmpty; |
| 63 | 47 |
| 64 /// Creates a RenderingQueue with the default synchronization barrier. | 48 /// Creates a RenderingQueue with the default synchronization barrier. |
| 65 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); | 49 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 _queue.addLast(r); | 63 _queue.addLast(r); |
| 80 } | 64 } |
| 81 | 65 |
| 82 Future _render() async { | 66 Future _render() async { |
| 83 await _barrier.next; | 67 await _barrier.next; |
| 84 while (_queue.isNotEmpty) { | 68 while (_queue.isNotEmpty) { |
| 85 _queue.removeFirst().render(); | 69 _queue.removeFirst().render(); |
| 86 } | 70 } |
| 87 } | 71 } |
| 88 } | 72 } |
| OLD | NEW |