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

Side by Side Diff: runtime/observatory/lib/src/elements/helpers/rendering_queue.dart

Issue 2995923002: Restore "Speedup Observatory elements first time rendering" (Closed)
Patch Set: Created 3 years, 4 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 (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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); 49 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier());
50 50
51 /// Creates a RenderingQueue with a custom synchronization barrier. 51 /// Creates a RenderingQueue with a custom synchronization barrier.
52 RenderingQueue.fromBarrier(this._barrier) { 52 RenderingQueue.fromBarrier(this._barrier) {
53 assert(this._barrier != null); 53 assert(this._barrier != null);
54 } 54 }
55 55
56 /// Add a task to the queue. 56 /// Add a task to the queue.
57 /// If the current rendering phase is running it will be executed during this 57 /// If the current rendering phase is running it will be executed during this
58 /// rendering cycle, otherwise it will be queued for the next one. 58 /// rendering cycle, otherwise it will be queued for the next one.
59 void enqueue(RenderingTask r) { 59 void enqueue(RenderingTask r, {bool waitForBarrier: true}) {
60 assert(r != null); 60 assert(r != null);
61 final wasEmpty = _queue.isEmpty;
62 _queue.addLast(r);
61 // If no task are in the queue there is no rendering phase scheduled. 63 // If no task are in the queue there is no rendering phase scheduled.
62 if (isEmpty) _render(); 64 if (wasEmpty) {
63 _queue.addLast(r); 65 if (waitForBarrier) {
66 _render();
67 } else {
68 // We schedule the _renderLoop as a microtask to allow the
69 // scheduleRendering method to terminate, due to the fact that it is
70 // generally invoked from inside a HtmlElement.attached method
71 scheduleMicrotask(_renderLoop);
72 }
73 }
64 } 74 }
65 75
66 Future _render() async { 76 Future _render() async {
67 await _barrier.next; 77 await _barrier.next;
78 _renderLoop();
79 }
80
81 void _renderLoop() {
68 while (_queue.isNotEmpty) { 82 while (_queue.isNotEmpty) {
69 _queue.first.render(); 83 _queue.first.render();
70 _queue.removeFirst(); 84 _queue.removeFirst();
71 } 85 }
72 } 86 }
73 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698