OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:html'; |
| 6 import 'dart:collection'; |
| 7 import 'dart:async'; |
| 8 |
| 9 abstract class RenderingTask { |
| 10 void render(); |
| 11 } |
| 12 |
| 13 abstract class RenderingBarrier { |
| 14 Future<num> get next; |
| 15 } |
| 16 |
| 17 class NextAnimationFrameBarrier implements RenderingBarrier { |
| 18 Future<num> get next => window.animationFrame; |
| 19 } |
| 20 |
| 21 class RenderingQueue { |
| 22 final RenderingBarrier _barrier; |
| 23 final Queue<RenderingTask> _queue = new Queue<RenderingTask>(); |
| 24 |
| 25 bool get isEmpty => _queue.isEmpty; |
| 26 bool get isNotEmpty => _queue.isNotEmpty; |
| 27 |
| 28 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); |
| 29 |
| 30 RenderingQueue.fromBarrier(this._barrier); |
| 31 |
| 32 void enqueue(RenderingTask r) { |
| 33 assert(r != null); |
| 34 if (isEmpty) _render(); |
| 35 _queue.addLast(r); |
| 36 } |
| 37 |
| 38 Future _render() async { |
| 39 await _barrier.next; |
| 40 while (_queue.isNotEmpty) { |
| 41 _queue.removeFirst().render(); |
| 42 } |
| 43 } |
| 44 } |
OLD | NEW |