Index: runtime/observatory/lib/src/elements/helpers/rendering_queue.dart |
diff --git a/runtime/observatory/lib/src/elements/helpers/rendering_queue.dart b/runtime/observatory/lib/src/elements/helpers/rendering_queue.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..657cbff3df95078201aa5979a84188a1db684115 |
--- /dev/null |
+++ b/runtime/observatory/lib/src/elements/helpers/rendering_queue.dart |
@@ -0,0 +1,44 @@ |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'dart:html'; |
+import 'dart:collection'; |
+import 'dart:async'; |
+ |
+abstract class RenderingTask { |
+ void render(); |
+} |
+ |
+abstract class RenderingBarrier { |
+ Future<num> get next; |
+} |
+ |
+class NextAnimationFrameBarrier implements RenderingBarrier { |
+ Future<num> get next => window.animationFrame; |
+} |
+ |
+class RenderingQueue { |
+ final RenderingBarrier _barrier; |
+ final Queue<RenderingTask> _queue = new Queue<RenderingTask>(); |
+ |
+ bool get isEmpty => _queue.isEmpty; |
+ bool get isNotEmpty => _queue.isNotEmpty; |
+ |
+ RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); |
+ |
+ RenderingQueue.fromBarrier(this._barrier); |
+ |
+ void enqueue(RenderingTask r) { |
+ assert(r != null); |
+ if (isEmpty) _render(); |
+ _queue.addLast(r); |
+ } |
+ |
+ Future _render() async { |
+ await _barrier.next; |
+ while (_queue.isNotEmpty) { |
+ _queue.removeFirst().render(); |
+ } |
+ } |
+} |