From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- image/IDecodingTask.cpp | 73 ++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) (limited to 'image/IDecodingTask.cpp') 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 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 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(¤t); - return current; -} - void IDecodingTask::NotifyProgress(NotNull aImage, NotNull 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 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 aImage, // We're forced to notify asynchronously. NotNull> image = aImage; - mEventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction( - "IDecodingTask::NotifyProgress", - [=]() -> void { - image->NotifyProgress(progress, invalidRect, - frameCount, decoderFlags, - surfaceFlags); - })), - NS_DISPATCH_NORMAL); + nsCOMPtr eventTarget = GetMainThreadSerialEventTarget(); + eventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction( + "IDecodingTask::NotifyProgress", + [=]() -> void { + image->NotifyProgress(progress, invalidRect, + frameCount, decoderFlags, + surfaceFlags); + })), + NS_DISPATCH_NORMAL); } void IDecodingTask::NotifyDecodeComplete(NotNull aImage, NotNull 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 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 aImage, // We're forced to notify asynchronously. NotNull> image = aImage; - mEventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction( - "IDecodingTask::NotifyDecodeComplete", - [=]() -> void { - image->NotifyDecodeComplete( - finalStatus, metadata, telemetry, progress, - invalidRect, frameCount, decoderFlags, - surfaceFlags); - })), - NS_DISPATCH_NORMAL); + nsCOMPtr eventTarget = GetMainThreadSerialEventTarget(); + eventTarget->Dispatch(CreateRenderBlockingRunnable(NS_NewRunnableFunction( + "IDecodingTask::NotifyDecodeComplete", + [=]() -> void { + image->NotifyDecodeComplete( + finalStatus, metadata, telemetry, progress, + invalidRect, frameCount, decoderFlags, + surfaceFlags); + })), + NS_DISPATCH_NORMAL); } /////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3