Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 016b342

Browse files
author
Yuncong Zhang
committed
[1.5.4] Upgrade image stream.
1 parent ca222ee commit 016b342

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Runtime/painting/image_stream.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public virtual void addListener(ImageListener listener, ImageErrorListener onErr
187187
new UIWidgetsErrorDetails(
188188
exception: ex,
189189
library: "image resource service",
190-
context: "by a synchronously-called image error listener"
190+
context: "when reporting an error to an image listener"
191191
)
192192
);
193193
}
@@ -298,9 +298,6 @@ public MultiFrameImageStreamCompleter(
298298
this._scale = scale;
299299
this._informationCollector = informationCollector;
300300

301-
this._framesEmitted = 0;
302-
this._timer = null;
303-
304301
codec.Then((Action<Codec>) this._handleCodecReady, ex => {
305302
this.reportError(
306303
context: "resolving an image codec",
@@ -318,17 +315,22 @@ public MultiFrameImageStreamCompleter(
318315
FrameInfo _nextFrame;
319316
TimeSpan? _shownTimestamp;
320317
TimeSpan? _frameDuration;
321-
int _framesEmitted;
318+
int _framesEmitted = 0;
322319
Timer _timer;
323320

321+
bool _frameCallbackScheduled = false;
322+
324323
void _handleCodecReady(Codec codec) {
325324
this._codec = codec;
326325
D.assert(this._codec != null);
327326

328-
this._decodeNextFrameAndSchedule();
327+
if (this.hasListeners) {
328+
this._decodeNextFrameAndSchedule();
329+
}
329330
}
330331

331332
void _handleAppFrame(TimeSpan timestamp) {
333+
this._frameCallbackScheduled = false;
332334
if (!this.hasListeners) {
333335
return;
334336
}
@@ -349,8 +351,7 @@ void _handleAppFrame(TimeSpan timestamp) {
349351

350352
TimeSpan delay = this._frameDuration.Value - (timestamp - this._shownTimestamp.Value);
351353
delay = new TimeSpan((long) (delay.Ticks * SchedulerBinding.instance.timeDilation));
352-
this._timer = Window.instance.run(delay,
353-
() => { SchedulerBinding.instance.scheduleFrameCallback(this._handleAppFrame); });
354+
this._timer = Window.instance.run(delay, this._scheduleAppFrame);
354355
}
355356

356357
bool _isFirstFrame() {
@@ -371,6 +372,15 @@ void _decodeNextFrameAndSchedule() {
371372
return;
372373
}
373374

375+
this._scheduleAppFrame();
376+
}
377+
378+
void _scheduleAppFrame() {
379+
if (this._frameCallbackScheduled) {
380+
return;
381+
}
382+
383+
this._frameCallbackScheduled = true;
374384
SchedulerBinding.instance.scheduleFrameCallback(this._handleAppFrame);
375385
}
376386

0 commit comments

Comments
 (0)