Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiber] Schedule animation regardless of deferred work #8187

Merged
merged 2 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,12 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalScheduling-test.js
* flushes scheduled deferred work fitting within deadline for many roots
* schedules more deferred work if it runs out of time
* schedules more deferred work if it runs out of time with many roots
* FIXME: flushes late animation work in a deferred callback if it wins
* FIXME: flushes late animation work in a deferred callback if it wins with many roots
* FIXME: ignores late animation work in an animation callback if it wins
* FIXME: ignores late animation work in an animation callback if it wins with many roots
* FIXME: ignores all work in a deferred callback if it wins
* FIXME: ignores all work in a deferred callback if it wins with many roots
* flushes late animation work in a deferred callback if it wins
* flushes late animation work in a deferred callback if it wins with many roots
* flushes late animation work in an animation callback if it wins
* flushes late animation work in an animation callback if it wins with many roots
* flushes all work in a deferred callback if it wins
* flushes all work in a deferred callback if it wins with many roots
* flushes root with late deferred work in an animation callback if it wins
* flushes all roots with animation work in an animation callback if it wins
* splits deferred work on multiple roots
Expand All @@ -828,7 +828,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalScheduling-test.js
* performs animated work in deferred callback if it has time
* performs animated work and deferred work in deferred callback if it has time
* performs deferred and animated work work in deferred callback if it has time
* FIXME: schedules animated work as if it was deferred in deferred callback if it runs out of time
* schedules animated work in deferred callback if it runs out of time
* schedules animated work and deferred work in deferred callback if it runs out of time
* schedules deferred work and animated work in deferred callback if it runs out of time

Expand Down
77 changes: 49 additions & 28 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
let nextScheduledRoot : ?FiberRoot = null;
let lastScheduledRoot : ?FiberRoot = null;

// Keep track of which host environment callbacks are scheduled
let isAnimationCallbackScheduled : boolean = false;
let isDeferredCallbackScheduled : boolean = false;

function findNextUnitOfWork() {
// Clear out roots with no more work on them.
while (nextScheduledRoot && nextScheduledRoot.current.pendingWorkPriority === NoWork) {
Expand Down Expand Up @@ -379,13 +383,17 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
nextUnitOfWork = findNextUnitOfWork();
}
} else {
scheduleDeferredCallback(performDeferredWork);
if (!isDeferredCallbackScheduled) {
isDeferredCallbackScheduled = true;
scheduleDeferredCallback(performDeferredWork);
}
return;
}
}
}

function performDeferredWork(deadline) {
isDeferredCallbackScheduled = false;
performAndHandleErrors(LowPriority, deadline);
}

Expand All @@ -403,20 +411,21 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
root.current.pendingWorkPriority = priority;
}

if (root.isScheduled) {
// If we're already scheduled, we can bail out.
return;
if (!root.isScheduled) {
root.isScheduled = true;
if (lastScheduledRoot) {
// Schedule ourselves to the end.
lastScheduledRoot.nextScheduledRoot = root;
lastScheduledRoot = root;
} else {
// We're the only work scheduled.
nextScheduledRoot = root;
lastScheduledRoot = root;
}
}
root.isScheduled = true;
if (lastScheduledRoot) {
// Schedule ourselves to the end.
lastScheduledRoot.nextScheduledRoot = root;
lastScheduledRoot = root;
} else {
// We're the only work scheduled.
nextScheduledRoot = root;
lastScheduledRoot = root;

if (!isDeferredCallbackScheduled) {
isDeferredCallbackScheduled = true;
scheduleDeferredCallback(performDeferredWork);
}
}
Expand All @@ -434,11 +443,15 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}
}
if (nextUnitOfWork && nextPriorityLevel > AnimationPriority) {
scheduleDeferredCallback(performDeferredWork);
if (!isDeferredCallbackScheduled) {
isDeferredCallbackScheduled = true;
scheduleDeferredCallback(performDeferredWork);
}
}
}

function performAnimationWork() {
isAnimationCallbackScheduled = false;
performAndHandleErrors(AnimationPriority);
}

Expand All @@ -449,19 +462,21 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
root.current.pendingWorkPriority = priorityLevel;
}

if (root.isScheduled) {
// If we're already scheduled, we can bail out.
return;
if (!root.isScheduled) {
root.isScheduled = true;
if (lastScheduledRoot) {
// Schedule ourselves to the end.
lastScheduledRoot.nextScheduledRoot = root;
lastScheduledRoot = root;
} else {
// We're the only work scheduled.
nextScheduledRoot = root;
lastScheduledRoot = root;
}
}
root.isScheduled = true;
if (lastScheduledRoot) {
// Schedule ourselves to the end.
lastScheduledRoot.nextScheduledRoot = root;
lastScheduledRoot = root;
} else {
// We're the only work scheduled.
nextScheduledRoot = root;
lastScheduledRoot = root;

if (!isAnimationCallbackScheduled) {
isAnimationCallbackScheduled = true;
scheduleAnimationCallback(performAnimationWork);
}
}
Expand Down Expand Up @@ -505,10 +520,16 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}
if (nextUnitOfWork) {
if (nextPriorityLevel > AnimationPriority) {
scheduleDeferredCallback(performDeferredWork);
if (!isDeferredCallbackScheduled) {
isDeferredCallbackScheduled = true;
scheduleDeferredCallback(performDeferredWork);
}
return;
}
scheduleAnimationCallback(performAnimationWork);
if (!isAnimationCallbackScheduled) {
isAnimationCallbackScheduled = true;
scheduleAnimationCallback(performAnimationWork);
}
}
}

Expand Down
Loading