mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
f32bf3ebba
- Bug 1268976 - Assert that the micro-task queues are empty upon destruction of CycleCollectedJSRuntime; r=mccr8 (a459a4af91) - Bug 1191354 part 1 - Clean up nsHTMLEditRules::GetHighestInlineParent; r=ehsan (a2f401887c) - Bug 1191354 part 2 - Clean up nsHTMLEditRules::CheckInterlinePosition; r=ehsan (75d3829eec) - Bug 1191354 part 3 - Clean up nsHTMLEditRules::InsertMozBRIfNeeded; r=ehsan (bedbba7c14) - Bug 772796 - Handle newlines correctly when joining <div> and <pre>. r=roc (323eaf4fe9) - Bug 1258085 - Avoid empty whitespace nodes when editing (b77825fb31) - Bug 1156062 part 4 - Clean up ns*EditRules::WillInsert; r=ehsan (f351557776) - Bug 1156062 part 5 - Make CreateBR return regular pointer; r=ehsan (8720917dee) - Bug 1156062 part 6 - Clean up nsHTMLEditRules::WillInsertBreak; r=ehsan (d71bca568f) - Bug 1156062 part 7 - Clean up nsHTMLEditRules::StandardBreakImpl; r=ehsan (625db32c02) - Bug 1156062 part 8 - Clean up nsHTMLEditRules::JoinBlocks; r=ehsan (266b6c5150) - Bug 1156062 part 9 - Clean up nsHTMLEditRules::WillAlign; r=masayuki (a6e3227001) - Bug 1156062 part 10 - Clean up MarginPropertyAtomForIndent; r=masayuki (28612e062c) - Bug 1184665 - Remove a spammy editor warning (a2db555918) - Bug 1156062 part 11 - Clean up nsHTMLEditRules::Before/AfterEdit; r=masayuki (6be722082e) - Bug 1156062 part 12 - Clean up nsHTMLEditRules::GetAlignment; r=masayuki (350be10ee8) - Bug 1190172 part 1 - Clean up nsHTMLEditor::SplitStyleAbovePoint; r=ehsan (ce5e360af6) - Bug 1145395 - Introduce an overload of nsHTMLEditor::SelElementPosition that takes an Element; r=ehsan (7ca9dfd2f8) - Bug 1190172 part 2 - Clean up nsHTMLEditor::ClearStyle; r=ehsan (84334514ad) - Bug 1190172 part 3 - Remove old method variants; r=ehsan (e042bd64d5) - Bug 1190172 part 4 - Remove unused nsHTMLEditor::HasAttr; r=ehsan (a4f1563465) - Bug 1190172 part 5 - Clean up nsHTMLEditor::NodeIsProperty; r=ehsan (98afb84bd4) - Bug 1190172 part 6 - Clean up nsHTMLEditor::RelativeFontChangeOnTextNode; r=ehsan (0bf036d206) - Bug 1190172 part 7 - Clean up nsHTMLEditor::PromoteInlineRange; r=ehsan (0a21347500) - Bug 1190172 part 8 - Clean up nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor; r=ehsan (78cf619036) - Bug 1190172 part 9 - Clean up nsHTMLEditor::ReturnInHeader; r=ehsan (1d8d151ff1) - Bug 1190172 part 10 - Clean up nsHTMLEditor::ReturnInListItem; r=ehsan (0ce94d3cb1) - Bug 1190172 part 11 - Clean up nsHTMLEditRules::IsEmptyBlock; r=ehsan (a8dc5092f8) - Bug 1190172 part 12 - Clean up nsHTMLEditRules::ExpandSelectionForDeletion; r=ehsan (3d4a87a56d) - Bug 1191354 part 4 - Clean up nsHTMLEditRules::AlignBlock; r=ehsan (b39372d726) - Bug 1191354 part 5 - Clean up nsHTMLEditRules::IsEmptyInline; r=ehsan (0b8ab19fd1) - Bug 1191354 part 6 - Clean up IsBlockNode/IsInlineNode in nsHTMLEditRules.cpp; r=ehsan (8ba8047e12) - Bug 1191354 part 7 - Clean up nsHTMLEditRules::CheckForInvisibleBR; r=ehsan (0bc61269bd) - Bug 1191354 part 8 - Typedefs in headers for readability; r=ehsan (50b43dc3e9) - Bug 1191354 part 9 - Remove old nsHTMLEditRules::ConvertListType variant; r=ehsan (871f1b30a5) - Bug 1191354 part 10 - More features for OwningNonNull; r=froydnj (8e365d079a) - Bug 1191354 part 11 - Clean up nsHTMLEditRules::WillOutdent; r=ehsan (0c59a81c10) - Bug 1191354 part 12 - Clean up nsHTMLEditRules::OutdentPartOfBlock; r=ehsan (243d7ab42f) - Bug 1191354 part 13 - Clean up nsHTMLEditRules::SplitBlock; r=ehsan (c1141ab04d) - Bug 1191356 part 1 - Clean up nsHTMLEditRules::RemoveListStructure; r=ehsan (1d2ad5faa6) - Bug 1191356 part 2 - Clean up nsHTMLEditor::RemoveBlockContainer; r=ehsan (a9d140f511) - Bug 1191356 part 3 - Clean up nsHTMLEditRules::MoveBlock; r=ehsan (6bc14cd40c) - Bug 1191356 part 4 - Clean up nsHTMLEditRules::MoveNodeSmart, MoveContents; r=ehsan (00e6536e47) - Bug 1191356 part 5 - Clean up nsHTMLEditRules::RelativeChangeIndentationOfElementNode; r=ehsan (c3139c7d90) - Bug 1191356 part 6 - Clean up nsHTMLEditRules::WillMakeBasicBlock; r=ehsan (b3f73c2e12) - Bug 1191356 part 7 - Clean up nsHTMLEditor::GetSelectionContainer; r=ehsan (091e999587) - Bug 1191356 part 8 - Clean up nsHTMLEditRules::WillAbsolutePosition; r=ehsan (9982c65a99) - Bug 1208884 - Fix a few null check ordering bugs in nsHTMLEditRules::SplitParagraph; r=roc (d04eece297) - Bug 1209037 - Eliminate some unneeded null checks; r=jdm (b35d5308c5) - Bug 1191356 part 9 - Convert nsHTMLEditRules::mNewBlock to Element; r=ehsan (f374780e22) - Bug 1253734 - Add some more editor things to CC traversal. r=mccr8. (94a0c77bb1) - Bug 1193762 part 1 - Remove nsEditor::IsBlockNode(nsIDOMNode*); r=ehsan (5e107cbdbb) - Bug 1193762 part 2 - Remove nsHTMLEditor::IsVisBreak(nsIDOMNode*); r=ehsan (5e61c27d21) - Bug 1193762 part 3 - Remove nsEditor::IsDescendantOfEditorRoot(nsIDOMNode*); r=ehsan (022a37d442) - Bug 1193762 part 4 - Avoid nsCOMPtr in ternary operator; r=froydnj (e4bc35cbe0) - Bug 1193762 part 5 - Convert DecodePool::threads to nsTArray; r=froydnj (c61f063f4d) - Bug 1193762 part 6 - Return raw pointer, not nsCOMPtr; r=froydnj (a43c30f92e) - Bug 1193762 part 7 - Use .get() when assigning to variables; r=froydnj (a61ad819f0) - Bug 1193762 part 8 - Fix things that will break; r=froydnj (40a76db662) - Bug 1193762 part 9 - Delete nsCOMPtr<T>::operator T*()&&; r=froydnj (022c1f0dba) - Bug 1168223 - Fix a crash caused by unexpected flushes under nsIEditor::SetFlags. r=ehsan (cc49d468b8) - Bug 1158837 - Ensure the start and end nodes are non-null before using them. r=roc (7c28121aa7) - Bug 1269047 - Remove chained ENSURE calls from GetStartNodeAndOffset. r=ehsan (f36c1c67aa) - Bug 1248078 - Remove the dedicated scroll acknowledgement message. r=botond (500b8d7574) - Bug 1260806: Remove some more dead MessageLoop code. r=jld (1c223cafe8) - Bug 1266595: Replace Chromium Task with Runnable. r=froydnj (5c1c056c83) - Bug 1242343 - p1. ConstructSystem32Path from LoadLibrarySystem32 - r=jimm (b28fcbc0c4) - Bug 1242343 - p2. Blacklist msmpeg2vdec.dll 12.0.9200.16426 & .17037 - r=cpearce (9a71795ab0) - Bug 1253395 - Disable msmpeg2vdec.dll blackslisting - r=cpearce (e1d4dc47be) - Bug 1242456 - Create RAIIs to manage HGLOBAL and printer HANDLE in ShowNativePrintDialog and CreateGlobalDevModeAndInit. r=jimm, r=bobowen (a22cecaebd) - Bug 1262399 - remove Impl suffixes from nsSupports* implementations; r=mccr8 (6733db9394) - Bug 1268772 (part 1) - Remove nsCheapSet::Put()'s return value. r=erahm. (5f3f553e84) - Bug 1268772 (part 2) - Make infallible nsVariant methods return |void| instead of |nsresult|. r=erahm. (22ae74fdaf) - Bug 1268772 (part 3) - Remove NS_NewWindowsRegKey()'s return value. r=erahm. (dc32bd698e) - Bug 1268772 (part 4) - Use MOZ_MUST_USE with NS_NewISupportsArray(). r=erahm. (e51ecfdf9f) - Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. (4d8a5183eb) - Bug 1266027 part 1 - make the MediaDecoderReaderWrapper as a proxy of requesting media data; r=jwwang (fbaa79019d) - Bug 1195601 - Remove MediaDecoderStateMachine::mLogicallySeeking. r=kinetik. (5ab1ff1ca0) - Bug 1266027 part 2 - make MDSM and SeekTask to adopt new MediaDecoderReaderWrapper API; r=jwwang (1961e26e80) - add mac specific dupes (4e4ff4b123) - Bug 1269262 - Unbreak build without NO_EXPAND_LIBS in js/src/moz.build after bug 1239083. r=ted (46d2dec64a) - Bug 1253215 - Initialize RequestSyncService only if its pref is enabled, r=ehsan (aec1b2f889) - Bug 1269303 - Remove RequestSync API, r=fabrice (f774336e34)
505 lines
12 KiB
C++
505 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "DecodePool.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/Monitor.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsIThreadPool.h"
|
|
#include "nsThreadManager.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "nsXPCOMCIDInternal.h"
|
|
#include "prsystem.h"
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
#include "ipc/Nuwa.h"
|
|
#endif
|
|
|
|
#include "gfxPrefs.h"
|
|
|
|
#include "Decoder.h"
|
|
#include "RasterImage.h"
|
|
|
|
using std::max;
|
|
using std::min;
|
|
|
|
namespace mozilla {
|
|
namespace image {
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Helper runnables.
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class NotifyProgressWorker : public Runnable
|
|
{
|
|
public:
|
|
/**
|
|
* Called by the DecodePool when it's done some significant portion of
|
|
* decoding, so that progress can be recorded and notifications can be sent.
|
|
*/
|
|
static void Dispatch(RasterImage* aImage,
|
|
Progress aProgress,
|
|
const nsIntRect& aInvalidRect,
|
|
SurfaceFlags aSurfaceFlags)
|
|
{
|
|
MOZ_ASSERT(aImage);
|
|
|
|
nsCOMPtr<nsIRunnable> worker =
|
|
new NotifyProgressWorker(aImage, aProgress, aInvalidRect, aSurfaceFlags);
|
|
NS_DispatchToMainThread(worker);
|
|
}
|
|
|
|
NS_IMETHOD Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mImage->NotifyProgress(mProgress, mInvalidRect, mSurfaceFlags);
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
NotifyProgressWorker(RasterImage* aImage,
|
|
Progress aProgress,
|
|
const nsIntRect& aInvalidRect,
|
|
SurfaceFlags aSurfaceFlags)
|
|
: mImage(aImage)
|
|
, mProgress(aProgress)
|
|
, mInvalidRect(aInvalidRect)
|
|
, mSurfaceFlags(aSurfaceFlags)
|
|
{ }
|
|
|
|
RefPtr<RasterImage> mImage;
|
|
const Progress mProgress;
|
|
const nsIntRect mInvalidRect;
|
|
const SurfaceFlags mSurfaceFlags;
|
|
};
|
|
|
|
class NotifyDecodeCompleteWorker : public Runnable
|
|
{
|
|
public:
|
|
/**
|
|
* Called by the DecodePool when decoding is complete, so that final cleanup
|
|
* can be performed.
|
|
*/
|
|
static void Dispatch(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
|
|
nsCOMPtr<nsIRunnable> worker = new NotifyDecodeCompleteWorker(aDecoder);
|
|
NS_DispatchToMainThread(worker);
|
|
}
|
|
|
|
NS_IMETHOD Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mDecoder->GetImage()->FinalizeDecoder(mDecoder);
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
explicit NotifyDecodeCompleteWorker(Decoder* aDecoder)
|
|
: mDecoder(aDecoder)
|
|
{ }
|
|
|
|
RefPtr<Decoder> mDecoder;
|
|
};
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
class RegisterDecodeIOThreadWithNuwaRunnable : public Runnable
|
|
{
|
|
public:
|
|
NS_IMETHOD Run()
|
|
{
|
|
NuwaMarkCurrentThread(static_cast<void(*)(void*)>(nullptr), nullptr);
|
|
return NS_OK;
|
|
}
|
|
};
|
|
|
|
#endif // MOZ_NUWA_PROCESS
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// DecodePool implementation.
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
/* static */ StaticRefPtr<DecodePool> DecodePool::sSingleton;
|
|
/* static */ uint32_t DecodePool::sNumCores = 0;
|
|
|
|
NS_IMPL_ISUPPORTS(DecodePool, nsIObserver)
|
|
|
|
struct Work
|
|
{
|
|
enum class Type {
|
|
DECODE,
|
|
SHUTDOWN
|
|
} mType;
|
|
|
|
RefPtr<Decoder> mDecoder;
|
|
};
|
|
|
|
class DecodePoolImpl
|
|
{
|
|
public:
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(DecodePoolImpl)
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodePoolImpl)
|
|
|
|
DecodePoolImpl()
|
|
: mMonitor("DecodePoolImpl")
|
|
, mShuttingDown(false)
|
|
{ }
|
|
|
|
/// Initialize the current thread for use by the decode pool.
|
|
void InitCurrentThread()
|
|
{
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
mThreadNaming.SetThreadPoolName(NS_LITERAL_CSTRING("ImgDecoder"));
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
if (IsNuwaProcess()) {
|
|
NuwaMarkCurrentThread(static_cast<void(*)(void*)>(nullptr), nullptr);
|
|
}
|
|
#endif // MOZ_NUWA_PROCESS
|
|
}
|
|
|
|
/// Shut down the provided decode pool thread.
|
|
static void ShutdownThread(nsIThread* aThisThread)
|
|
{
|
|
// Threads have to be shut down from another thread, so we'll ask the
|
|
// main thread to do it for us.
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
NS_NewRunnableMethod(aThisThread, &nsIThread::Shutdown);
|
|
NS_DispatchToMainThread(runnable);
|
|
}
|
|
|
|
/**
|
|
* Requests shutdown. New work items will be dropped on the floor, and all
|
|
* decode pool threads will be shut down once existing work items have been
|
|
* processed.
|
|
*/
|
|
void RequestShutdown()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
mShuttingDown = true;
|
|
mMonitor.NotifyAll();
|
|
}
|
|
|
|
/// Pushes a new decode work item.
|
|
void PushWork(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
RefPtr<Decoder> decoder(aDecoder);
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
if (mShuttingDown) {
|
|
// Drop any new work on the floor if we're shutting down.
|
|
return;
|
|
}
|
|
|
|
if (aDecoder->IsMetadataDecode()) {
|
|
mMetadataDecodeQueue.AppendElement(Move(decoder));
|
|
} else {
|
|
mFullDecodeQueue.AppendElement(Move(decoder));
|
|
}
|
|
|
|
mMonitor.Notify();
|
|
}
|
|
|
|
/// Pops a new work item, blocking if necessary.
|
|
Work PopWork()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
do {
|
|
// Prioritize metadata decodes over full decodes.
|
|
if (!mMetadataDecodeQueue.IsEmpty()) {
|
|
return PopWorkFromQueue(mMetadataDecodeQueue);
|
|
}
|
|
|
|
if (!mFullDecodeQueue.IsEmpty()) {
|
|
return PopWorkFromQueue(mFullDecodeQueue);
|
|
}
|
|
|
|
if (mShuttingDown) {
|
|
Work work;
|
|
work.mType = Work::Type::SHUTDOWN;
|
|
return work;
|
|
}
|
|
|
|
// Nothing to do; block until some work is available.
|
|
mMonitor.Wait();
|
|
} while (true);
|
|
}
|
|
|
|
private:
|
|
~DecodePoolImpl() { }
|
|
|
|
Work PopWorkFromQueue(nsTArray<RefPtr<Decoder>>& aQueue)
|
|
{
|
|
Work work;
|
|
work.mType = Work::Type::DECODE;
|
|
work.mDecoder = aQueue.LastElement().forget();
|
|
aQueue.RemoveElementAt(aQueue.Length() - 1);
|
|
|
|
return work;
|
|
}
|
|
|
|
nsThreadPoolNaming mThreadNaming;
|
|
|
|
// mMonitor guards the queues and mShuttingDown.
|
|
Monitor mMonitor;
|
|
nsTArray<RefPtr<Decoder>> mMetadataDecodeQueue;
|
|
nsTArray<RefPtr<Decoder>> mFullDecodeQueue;
|
|
bool mShuttingDown;
|
|
};
|
|
|
|
class DecodePoolWorker : public Runnable
|
|
{
|
|
public:
|
|
explicit DecodePoolWorker(DecodePoolImpl* aImpl) : mImpl(aImpl) { }
|
|
|
|
NS_IMETHOD Run()
|
|
{
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
mImpl->InitCurrentThread();
|
|
|
|
nsCOMPtr<nsIThread> thisThread;
|
|
nsThreadManager::get()->GetCurrentThread(getter_AddRefs(thisThread));
|
|
|
|
do {
|
|
Work work = mImpl->PopWork();
|
|
switch (work.mType) {
|
|
case Work::Type::DECODE:
|
|
DecodePool::Singleton()->Decode(work.mDecoder);
|
|
break;
|
|
|
|
case Work::Type::SHUTDOWN:
|
|
DecodePoolImpl::ShutdownThread(thisThread);
|
|
return NS_OK;
|
|
|
|
default:
|
|
MOZ_ASSERT_UNREACHABLE("Unknown work type");
|
|
}
|
|
} while (true);
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Exiting thread without Work::Type::SHUTDOWN");
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
RefPtr<DecodePoolImpl> mImpl;
|
|
};
|
|
|
|
/* static */ void
|
|
DecodePool::Initialize()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
sNumCores = max<int32_t>(PR_GetNumberOfProcessors(), 1);
|
|
DecodePool::Singleton();
|
|
}
|
|
|
|
/* static */ DecodePool*
|
|
DecodePool::Singleton()
|
|
{
|
|
if (!sSingleton) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
sSingleton = new DecodePool();
|
|
ClearOnShutdown(&sSingleton);
|
|
}
|
|
|
|
return sSingleton;
|
|
}
|
|
|
|
/* static */ uint32_t
|
|
DecodePool::NumberOfCores()
|
|
{
|
|
return sNumCores;
|
|
}
|
|
|
|
DecodePool::DecodePool()
|
|
: mImpl(new DecodePoolImpl)
|
|
, mMutex("image::DecodePool")
|
|
{
|
|
// Determine the number of threads we want.
|
|
int32_t prefLimit = gfxPrefs::ImageMTDecodingLimit();
|
|
uint32_t limit;
|
|
if (prefLimit <= 0) {
|
|
int32_t numCores = NumberOfCores();
|
|
if (numCores <= 1) {
|
|
limit = 1;
|
|
} else if (numCores == 2) {
|
|
// On an otherwise mostly idle system, having two image decoding threads
|
|
// doubles decoding performance, so it's worth doing on dual-core devices,
|
|
// even if under load we can't actually get that level of parallelism.
|
|
limit = 2;
|
|
} else {
|
|
limit = numCores - 1;
|
|
}
|
|
} else {
|
|
limit = static_cast<uint32_t>(prefLimit);
|
|
}
|
|
if (limit > 32) {
|
|
limit = 32;
|
|
}
|
|
|
|
// Initialize the thread pool.
|
|
for (uint32_t i = 0 ; i < limit ; ++i) {
|
|
nsCOMPtr<nsIRunnable> worker = new DecodePoolWorker(mImpl);
|
|
nsCOMPtr<nsIThread> thread;
|
|
nsresult rv = NS_NewThread(getter_AddRefs(thread), worker);
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && thread,
|
|
"Should successfully create image decoding threads");
|
|
mThreads.AppendElement(Move(thread));
|
|
}
|
|
|
|
// Initialize the I/O thread.
|
|
nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread));
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOThread,
|
|
"Should successfully create image I/O thread");
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
nsCOMPtr<nsIRunnable> worker = new RegisterDecodeIOThreadWithNuwaRunnable();
|
|
rv = mIOThread->Dispatch(worker, NS_DISPATCH_NORMAL);
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv),
|
|
"Should register decode IO thread with Nuwa process");
|
|
#endif
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
|
|
if (obsSvc) {
|
|
obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
|
|
}
|
|
}
|
|
|
|
DecodePool::~DecodePool()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must shut down DecodePool on main thread!");
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DecodePool::Observe(nsISupports*, const char* aTopic, const char16_t*)
|
|
{
|
|
MOZ_ASSERT(strcmp(aTopic, "xpcom-shutdown-threads") == 0, "Unexpected topic");
|
|
|
|
nsTArray<nsCOMPtr<nsIThread>> threads;
|
|
nsCOMPtr<nsIThread> ioThread;
|
|
|
|
{
|
|
MutexAutoLock lock(mMutex);
|
|
threads.SwapElements(mThreads);
|
|
ioThread.swap(mIOThread);
|
|
}
|
|
|
|
mImpl->RequestShutdown();
|
|
|
|
for (uint32_t i = 0 ; i < threads.Length() ; ++i) {
|
|
threads[i]->Shutdown();
|
|
}
|
|
|
|
if (ioThread) {
|
|
ioThread->Shutdown();
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DecodePool::AsyncDecode(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
mImpl->PushWork(aDecoder);
|
|
}
|
|
|
|
void
|
|
DecodePool::SyncDecodeIfSmall(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aDecoder);
|
|
|
|
if (aDecoder->ShouldSyncDecode(gfxPrefs::ImageMemDecodeBytesAtATime())) {
|
|
Decode(aDecoder);
|
|
return;
|
|
}
|
|
|
|
AsyncDecode(aDecoder);
|
|
}
|
|
|
|
void
|
|
DecodePool::SyncDecodeIfPossible(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
Decode(aDecoder);
|
|
}
|
|
|
|
already_AddRefed<nsIEventTarget>
|
|
DecodePool::GetIOEventTarget()
|
|
{
|
|
MutexAutoLock threadPoolLock(mMutex);
|
|
nsCOMPtr<nsIEventTarget> target = do_QueryInterface(mIOThread);
|
|
return target.forget();
|
|
}
|
|
|
|
void
|
|
DecodePool::Decode(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
|
|
nsresult rv = aDecoder->Decode();
|
|
|
|
if (NS_SUCCEEDED(rv) && !aDecoder->GetDecodeDone()) {
|
|
// If this isn't a metadata decode, notify for the progress we've made so
|
|
// far. It's important that metadata decode results are delivered
|
|
// atomically, so for those decodes we wait until NotifyDecodeComplete.
|
|
if (aDecoder->HasProgress() && !aDecoder->IsMetadataDecode()) {
|
|
NotifyProgress(aDecoder);
|
|
}
|
|
// The decoder will ensure that a new worker gets enqueued to continue
|
|
// decoding when more data is available.
|
|
} else {
|
|
NotifyDecodeComplete(aDecoder);
|
|
}
|
|
}
|
|
|
|
void
|
|
DecodePool::NotifyProgress(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
|
|
if (!NS_IsMainThread() ||
|
|
(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
|
|
NotifyProgressWorker::Dispatch(aDecoder->GetImage(),
|
|
aDecoder->TakeProgress(),
|
|
aDecoder->TakeInvalidRect(),
|
|
aDecoder->GetSurfaceFlags());
|
|
return;
|
|
}
|
|
|
|
aDecoder->GetImage()->NotifyProgress(aDecoder->TakeProgress(),
|
|
aDecoder->TakeInvalidRect(),
|
|
aDecoder->GetSurfaceFlags());
|
|
}
|
|
|
|
void
|
|
DecodePool::NotifyDecodeComplete(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(aDecoder);
|
|
|
|
if (!NS_IsMainThread() ||
|
|
(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
|
|
NotifyDecodeCompleteWorker::Dispatch(aDecoder);
|
|
return;
|
|
}
|
|
|
|
aDecoder->GetImage()->FinalizeDecoder(aDecoder);
|
|
}
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|