tweener: make timeline loop indefinitely
Tweener uses a clutter timeline to manage all active animations running at a given moment. The timeline is mopped up when no animations are going any more. Clutter requires timelines to have a finite duration, but since animations can happen at any moment, no fixed duration can accomodate the shell's needs. To combat this problem, the tweener code picks a relatively long duration: 1000 seconds. No string of animations should take that long, so, in theory, that should be good enough. Unfortunately, this tactic fails, in practice, when the user suspends their machine, or VT switches. An animation can take much longer than 1000 seconds (~16 minutes) to complete in those cases. When the user resumes, or VT switches back the timeline completes immediately (since it's already late) and tweener never notices that the timeline stops ticking. This commit changes the tweener timeline to automatically loop back to 0 after completing, so that despite its fixed duration property, it effectively never stops. Since the timeline loops, its concept of elapsed time no longer increases monotonically, so we now ignore it and track time ourselves with GLib.get_monotonic_time(). This partially reverts commit 35764fa09e4341e79732409c4e74c226d19f780f. https://bugzilla.gnome.org/show_bug.cgi?id=653833
This commit is contained in:
parent
05863227a6
commit
207abe9a2c
@ -1,6 +1,7 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const GLib = imports.gi.GLib;
|
||||
const Lang = imports.lang;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Shell = imports.gi.Shell;
|
||||
@ -209,9 +210,14 @@ const ClutterFrameTicker = new Lang.Class({
|
||||
|
||||
_init : function() {
|
||||
// We don't have a finite duration; tweener will tell us to stop
|
||||
// when we need to stop, so use 1000 seconds as "infinity"
|
||||
// when we need to stop, so use 1000 seconds as "infinity", and
|
||||
// set the timeline to loop. Doing this means we have to track
|
||||
// time ourselves, since clutter timeline's time will cycle
|
||||
// instead of strictly increase.
|
||||
this._timeline = new Clutter.Timeline({ duration: 1000*1000 });
|
||||
this._timeline.set_loop(true);
|
||||
this._startTime = -1;
|
||||
this._currentTime = -1;
|
||||
|
||||
this._timeline.connect('new-frame', Lang.bind(this,
|
||||
function(timeline, frame) {
|
||||
@ -234,17 +240,18 @@ const ClutterFrameTicker = new Lang.Class({
|
||||
// That looks bad, so we always start at the first frame of the
|
||||
// animation then only do frame dropping from there.
|
||||
if (this._startTime < 0)
|
||||
this._startTime = this._timeline.get_elapsed_time();
|
||||
this._startTime = GLib.get_monotonic_time() / 1000.0;
|
||||
|
||||
// currentTime is in milliseconds
|
||||
let perf_log = Shell.PerfLog.get_default();
|
||||
this._currentTime = GLib.get_monotonic_time() / 1000.0 - this._startTime;
|
||||
perf_log.event("tweener.framePrepareStart");
|
||||
this.emit('prepare-frame');
|
||||
perf_log.event("tweener.framePrepareDone");
|
||||
},
|
||||
|
||||
getTime : function() {
|
||||
return this._timeline.get_elapsed_time();
|
||||
return this._currentTime;
|
||||
},
|
||||
|
||||
start : function() {
|
||||
@ -257,6 +264,7 @@ const ClutterFrameTicker = new Lang.Class({
|
||||
stop : function() {
|
||||
this._timeline.stop();
|
||||
this._startTime = -1;
|
||||
this._currentTime = -1;
|
||||
global.end_work();
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user