summaryrefslogtreecommitdiffstats
path: root/image/IDecodingTask.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /image/IDecodingTask.cpp
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'image/IDecodingTask.cpp')
-rw-r--r--image/IDecodingTask.cpp73
1 files changed, 21 insertions, 52 deletions
diff --git a/image/IDecodingTask.cpp b/image/IDecodingTask.cpp
index 1816c9056b..670a651275 100644
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -23,41 +23,9 @@ namespace image {
// Helpers for sending notifications to the image associated with a decoder.
///////////////////////////////////////////////////////////////////////////////
-void IDecodingTask::EnsureHasEventTarget(NotNull<RasterImage*> aImage) {
- if (!mEventTarget) {
- // We determine the event target as late as possible, at the first dispatch
- // time, because the observers bound to an imgRequest will affect it.
- // We cache it rather than query for the event target each time because the
- // event target can change. We don't want to risk events being executed in
- // a different order than they are dispatched, which can happen if we
- // selected scheduler groups which have no ordering guarantees relative to
- // each other (e.g. it moves from scheduler group A for doc group DA to
- // scheduler group B for doc group DB due to changing observers -- if we
- // dispatched the first event on A, and the second on B, we don't know which
- // will execute first.)
- RefPtr<ProgressTracker> tracker = aImage->GetProgressTracker();
- if (tracker) {
- mEventTarget = tracker->GetEventTarget();
- } else {
- mEventTarget = GetMainThreadSerialEventTarget();
- }
- }
-}
-
-bool IDecodingTask::IsOnEventTarget() const {
- // This is essentially equivalent to NS_IsOnMainThread() because all of the
- // event targets are for the main thread (although perhaps with a different
- // label / scheduler group). The observers in ProgressTracker may have
- // different event targets from this, so this is just a best effort guess.
- bool current = false;
- mEventTarget->IsOnCurrentThread(&current);
- return current;
-}
-
void IDecodingTask::NotifyProgress(NotNull<RasterImage*> aImage,
NotNull<Decoder*> aDecoder) {
MOZ_ASSERT(aDecoder->HasProgress() && !aDecoder->IsMetadataDecode());
- EnsureHasEventTarget(aImage);
// Capture the decoder's state. If we need to notify asynchronously, it's
// important that we don't wait until the lambda actually runs to capture the
@@ -72,7 +40,7 @@ void IDecodingTask::NotifyProgress(NotNull<RasterImage*> aImage,
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
// Synchronously notify if we can.
- if (IsOnEventTarget() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
+ if (NS_IsMainThread() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
aImage->NotifyProgress(progress, invalidRect, frameCount, decoderFlags,
surfaceFlags);
return;
@@ -86,21 +54,21 @@ void IDecodingTask::NotifyProgress(NotNull<RasterImage*> aImage,
// We're forced to notify asynchronously.
NotNull<RefPtr<RasterImage>> image = aImage;
- mEventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction(
- "IDecodingTask::NotifyProgress",
- [=]() -> void {
- image->NotifyProgress(progress, invalidRect,
- frameCount, decoderFlags,
- surfaceFlags);
- })),
- NS_DISPATCH_NORMAL);
+ nsCOMPtr<nsIEventTarget> eventTarget = GetMainThreadSerialEventTarget();
+ eventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction(
+ "IDecodingTask::NotifyProgress",
+ [=]() -> void {
+ image->NotifyProgress(progress, invalidRect,
+ frameCount, decoderFlags,
+ surfaceFlags);
+ })),
+ NS_DISPATCH_NORMAL);
}
void IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
NotNull<Decoder*> aDecoder) {
MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
"Decode complete in the middle of a frame?");
- EnsureHasEventTarget(aImage);
// Capture the decoder's state.
DecoderFinalStatus finalStatus = aDecoder->FinalStatus();
@@ -113,7 +81,7 @@ void IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
// Synchronously notify if we can.
- if (IsOnEventTarget() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
+ if (NS_IsMainThread() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
aImage->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
invalidRect, frameCount, decoderFlags,
surfaceFlags);
@@ -128,15 +96,16 @@ void IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
// We're forced to notify asynchronously.
NotNull<RefPtr<RasterImage>> image = aImage;
- mEventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction(
- "IDecodingTask::NotifyDecodeComplete",
- [=]() -> void {
- image->NotifyDecodeComplete(
- finalStatus, metadata, telemetry, progress,
- invalidRect, frameCount, decoderFlags,
- surfaceFlags);
- })),
- NS_DISPATCH_NORMAL);
+ nsCOMPtr<nsIEventTarget> eventTarget = GetMainThreadSerialEventTarget();
+ eventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction(
+ "IDecodingTask::NotifyDecodeComplete",
+ [=]() -> void {
+ image->NotifyDecodeComplete(
+ finalStatus, metadata, telemetry, progress,
+ invalidRect, frameCount, decoderFlags,
+ surfaceFlags);
+ })),
+ NS_DISPATCH_NORMAL);
}
///////////////////////////////////////////////////////////////////////////////