gecko-dev/image
Kyle Huey 76e3009ab8 Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:

1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).

2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).

3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.

The solve this, this patch does the following:

1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 06:10:46 -07:00
..
build Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
decoders Bug 1191090 - Use the normal PNG decoder for PNG metadata decodes. r=tn 2015-08-10 15:34:27 -07:00
encoders Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
test Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
BMPFileHeaders.h Bug 1186112 - Get rid of the #define'd constants in BMPFileHeaders.h. r=tn 2015-07-22 15:49:49 -07:00
ClippedImage.cpp Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
ClippedImage.h Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
DecodePool.cpp Bug 1187386 (Part 6) - Merge Decoder::Finish() and RasterImage::OnDecodingComplete() into RasterImage::FinalizeDecoder(). r=tn 2015-07-31 07:29:15 -07:00
DecodePool.h Bug 1188696 - Hoist nsRefPtr.h into MFBT. r=froydnj 2015-07-29 10:44:59 -07:00
Decoder.cpp Bug 1181863 (Part 2) - Add ImageOps::DecodeToSurface() to allow image decoding without involving any main-thread-only objects. r=tn 2015-07-31 18:10:31 -07:00
Decoder.h Bug 1181863 (Part 2) - Add ImageOps::DecodeToSurface() to allow image decoding without involving any main-thread-only objects. r=tn 2015-07-31 18:10:31 -07:00
DecoderFactory.cpp Bug 1181863 (Part 2) - Add ImageOps::DecodeToSurface() to allow image decoding without involving any main-thread-only objects. r=tn 2015-07-31 18:10:31 -07:00
DecoderFactory.h Bug 1181863 (Part 2) - Add ImageOps::DecodeToSurface() to allow image decoding without involving any main-thread-only objects. r=tn 2015-07-31 18:10:31 -07:00
Downscaler.cpp Bug 1189593 - Only use SSE2 in image::Downscaler if we're running on an SSE2-capable machine. r=tn 2015-07-30 19:48:22 -07:00
Downscaler.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
DynamicImage.cpp Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
DynamicImage.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
FrameAnimator.cpp Bug 1188705 (part 3) - Simplify imgFrame::SizeOfExcludingThis(). r=seth. 2015-07-28 21:02:45 -07:00
FrameAnimator.h Bug 1139641 - Return more information from SurfaceCache::Lookup and SurfaceCache::LookupBestMatch. r=dholbert 2015-06-30 18:57:03 -07:00
FrozenImage.cpp Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
FrozenImage.h Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
ICOFileHeaders.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
Image.cpp Bug 1184996 (Part 1) - Create decoders with a DecoderFactory. r=tn 2015-07-22 22:39:48 -07:00
Image.h Bug 1188705 (part 3) - Simplify imgFrame::SizeOfExcludingThis(). r=seth. 2015-07-28 21:02:45 -07:00
ImageCacheKey.cpp Bug 1169680 - Don't merge image cache entries for blob URIs with different refs. r=tn 2015-06-05 01:52:06 -07:00
ImageCacheKey.h Bug 1154974 (Part 2) - Merge image cache entries for blobs URIs with the same underlying blob. r=baku 2015-05-20 18:49:53 -07:00
ImageFactory.cpp Bug 1187386 (Part 2) - Rework decoder code to avoid calling Decode::GetImage(). r=tn 2015-07-31 07:29:03 -07:00
ImageFactory.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
ImageLogging.h Bug 1165515 - Part 13-2: Replace usage of PRLogModuleLevel and PR_LOG_*. rs=froydnj 2015-06-03 15:25:57 -07:00
ImageMetadata.cpp Bug 1187386 (Part 5) - Merge Decoder::SetSizeOnImage() into ImageMetadata::SetOnImage(). r=tn 2015-07-31 07:29:12 -07:00
ImageMetadata.h Bug 1187386 (Part 5) - Merge Decoder::SetSizeOnImage() into ImageMetadata::SetOnImage(). r=tn 2015-07-31 07:29:12 -07:00
ImageOps.cpp Bug 1181863 (Part 3) - Add tests for DecodeToSurface(). r=tn 2015-07-31 18:10:34 -07:00
ImageOps.h Bug 1181863 (Part 3) - Add tests for DecodeToSurface(). r=tn 2015-07-31 18:10:34 -07:00
ImageRegion.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ImageURL.h Bug 1169680 - Don't merge image cache entries for blob URIs with different refs. r=tn 2015-06-05 01:52:06 -07:00
ImageWrapper.cpp Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
ImageWrapper.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
imgFrame.cpp Bug 1187386 (Part 4) - Make imgFrame::SetOptimizable() callable from off-main-thread. r=tn 2015-07-31 07:29:10 -07:00
imgFrame.h Bug 1187386 (Part 4) - Make imgFrame::SetOptimizable() callable from off-main-thread. r=tn 2015-07-31 07:29:10 -07:00
imgICache.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgIContainer.idl Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
imgIContainerDebug.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgIEncoder.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgILoader.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgINotificationObserver.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgIOnloadBlocker.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgIRequest.idl Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of ImageLib. r=tn 2015-07-06 17:11:14 -07:00
imgIScriptedNotificationObserver.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgITools.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
imgLoader.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
imgLoader.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
imgRequest.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
imgRequest.h Bug 1160703 (Part 3) - Associate an imgRequest with its ImageCacheKey. r=baku 2015-05-20 10:21:13 -07:00
imgRequestProxy.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
imgRequestProxy.h Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of ImageLib. r=tn 2015-07-06 17:11:14 -07:00
imgTools.cpp Bug 1181863 (Part 2) - Add ImageOps::DecodeToSurface() to allow image decoding without involving any main-thread-only objects. r=tn 2015-07-31 18:10:31 -07:00
imgTools.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
IProgressObserver.h Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of ImageLib. r=tn 2015-07-06 17:11:14 -07:00
LookupResult.h Bug 1176124 (Part 1) - Add a MatchType enum to LookupResult to let Lookup*() return more detailed information. r=dholbert 2015-07-19 18:39:40 -07:00
moz.build Bug 1181863 (Part 3) - Add tests for DecodeToSurface(). r=tn 2015-07-31 18:10:34 -07:00
MultipartImage.cpp Bug 108603 - Remove NS_IMPL_QUERY_INTERFACE_INHERITED0. r=mccr8, r=froydnj 2015-07-24 12:13:00 -04:00
MultipartImage.h Bug 1181324 - Eliminate the duplicate mRefCnt member in MultipartImage. r=seth 2015-07-07 14:10:00 +02:00
nsIIconURI.idl Bug 1038536 - Flatten image/public/ directory. r=seth 2015-05-06 10:57:19 -07:00
Orientation.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
OrientedImage.cpp Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
OrientedImage.h Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; r=ehsan 2015-06-17 10:00:52 -04:00
ProgressTracker.cpp Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of ImageLib. r=tn 2015-07-06 17:11:14 -07:00
ProgressTracker.h Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of ImageLib. r=tn 2015-07-06 17:11:14 -07:00
RasterImage.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
RasterImage.h Bug 1181863 (Part 1) - Add support for reading from nsIInputStreams directly to SourceBuffer. r=tn 2015-07-31 18:10:29 -07:00
ScriptedNotificationObserver.cpp Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
ScriptedNotificationObserver.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
ShutdownTracker.cpp Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
ShutdownTracker.h Bug 1038536 - Flatten image/src/ directory. r=seth 2015-05-14 20:52:05 -07:00
SourceBuffer.cpp Bug 1181863 (Part 1) - Add support for reading from nsIInputStreams directly to SourceBuffer. r=tn 2015-07-31 18:10:29 -07:00
SourceBuffer.h Bug 1181863 (Part 1) - Add support for reading from nsIInputStreams directly to SourceBuffer. r=tn 2015-07-31 18:10:29 -07:00
SurfaceCache.cpp Bug 1188569: Drop unneeded MOZ_WARN_UNUSED_RESULT from from LookupBestMatch in SurfaceCache.cpp. r=seth 2015-07-30 12:35:19 -07:00
SurfaceCache.h Bug 1188705 (part 3) - Simplify imgFrame::SizeOfExcludingThis(). r=seth. 2015-07-28 21:02:45 -07:00
SVGDocumentWrapper.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
SVGDocumentWrapper.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
VectorImage.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
VectorImage.h Bug 1175371 - Make VectorImage wait to deliver LOAD_COMPLETE until its size is available. r=dholbert 2015-06-18 14:48:41 -07:00