2014-11-19 02:17:17 +00:00
|
|
|
/* -*- 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"
|
2018-02-13 11:43:31 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-05-15 00:08:26 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
Bug 1691589 - Reduce reliance on GeckoProfiler.h when only labels (and maybe markers) are needed - r=necko-reviewers,geckoview-reviewers,sg,agi,florian
There are no code changes, only #include changes.
It was a fairly mechanical process: Search for all "AUTO_PROFILER_LABEL", and in each file, if only labels are used, convert "GeckoProfiler.h" into "ProfilerLabels.h" (or just add that last one where needed).
In some files, there were also some marker calls but no other profiler-related calls, in these cases "GeckoProfiler.h" was replaced with both "ProfilerLabels.h" and "ProfilerMarkers.h", which still helps in reducing the use of the all-encompassing "GeckoProfiler.h".
Differential Revision: https://phabricator.services.mozilla.com/D104588
2021-02-16 04:44:19 +00:00
|
|
|
#include "mozilla/ProfilerLabels.h"
|
2020-04-07 15:16:33 +00:00
|
|
|
#include "mozilla/SchedulerGroup.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/Services.h"
|
2019-07-26 01:10:23 +00:00
|
|
|
#include "mozilla/StaticPrefs_image.h"
|
2020-10-27 15:29:26 +00:00
|
|
|
#include "mozilla/TaskController.h"
|
2018-02-09 20:17:26 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIObserverService.h"
|
2015-05-15 00:08:26 +00:00
|
|
|
#include "nsThreadManager.h"
|
2015-01-18 09:27:16 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
#include "prsystem.h"
|
|
|
|
|
|
|
|
#include "Decoder.h"
|
2016-06-29 20:43:19 +00:00
|
|
|
#include "IDecodingTask.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
#include "RasterImage.h"
|
|
|
|
|
2019-04-22 22:30:41 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <objbase.h>
|
2021-04-27 07:41:16 +00:00
|
|
|
# include "mozilla/WindowsProcessMitigations.h"
|
2019-04-22 22:30:41 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-19 02:17:17 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
2015-05-15 00:08:26 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// DecodePool implementation.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-02-25 22:07:58 +00:00
|
|
|
/* static */
|
|
|
|
StaticRefPtr<DecodePool> DecodePool::sSingleton;
|
|
|
|
/* static */
|
|
|
|
uint32_t DecodePool::sNumCores = 0;
|
2015-05-15 00:08:26 +00:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(DecodePool, nsIObserver)
|
|
|
|
|
2019-02-25 22:07:58 +00:00
|
|
|
/* static */
|
|
|
|
void DecodePool::Initialize() {
|
2015-01-18 09:27:16 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-11-01 17:45:40 +00:00
|
|
|
sNumCores = max<int32_t>(PR_GetNumberOfProcessors(), 1);
|
2015-01-18 09:27:16 +00:00
|
|
|
DecodePool::Singleton();
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:07:58 +00:00
|
|
|
/* static */
|
|
|
|
DecodePool* DecodePool::Singleton() {
|
2014-11-19 02:17:17 +00:00
|
|
|
if (!sSingleton) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
sSingleton = new DecodePool();
|
|
|
|
ClearOnShutdown(&sSingleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sSingleton;
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:07:58 +00:00
|
|
|
/* static */
|
|
|
|
uint32_t DecodePool::NumberOfCores() { return sNumCores; }
|
2015-07-08 22:52:51 +00:00
|
|
|
|
2019-04-22 22:30:41 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
class IOThreadIniter final : public Runnable {
|
|
|
|
public:
|
|
|
|
explicit IOThreadIniter() : Runnable("image::IOThreadIniter") {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
CoInitialize(nullptr);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2019-04-22 22:30:40 +00:00
|
|
|
DecodePool::DecodePool() : mMutex("image::IOThread") {
|
2015-01-18 09:27:16 +00:00
|
|
|
// Initialize the I/O thread.
|
2019-04-22 22:30:41 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// On Windows we use the io thread to get icons from the system. Any thread
|
|
|
|
// that makes system calls needs to call CoInitialize. And these system calls
|
|
|
|
// (SHGetFileInfo) should only be called from one thread at a time, in case
|
2021-04-27 07:41:16 +00:00
|
|
|
// we ever create more than one io thread. If win32k is locked down, we can't
|
|
|
|
// call SHGetFileInfo anyway, so we don't need the initializer.
|
|
|
|
nsCOMPtr<nsIRunnable> initer =
|
|
|
|
IsWin32kLockedDown() ? nullptr : new IOThreadIniter();
|
2019-04-22 22:30:41 +00:00
|
|
|
nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread), initer);
|
|
|
|
#else
|
2015-01-18 09:27:16 +00:00
|
|
|
nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread));
|
2019-04-22 22:30:41 +00:00
|
|
|
#endif
|
2015-01-18 09:27:16 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOThread,
|
|
|
|
"Should successfully create image I/O thread");
|
|
|
|
|
2015-01-08 08:29:41 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
|
|
|
|
if (obsSvc) {
|
|
|
|
obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2020-10-27 15:29:26 +00:00
|
|
|
mShuttingDown = true;
|
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
nsCOMPtr<nsIThread> ioThread;
|
2014-11-19 02:17:17 +00:00
|
|
|
|
|
|
|
{
|
2015-01-18 09:27:16 +00:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
ioThread.swap(mIOThread);
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
if (ioThread) {
|
|
|
|
ioThread->Shutdown();
|
|
|
|
}
|
|
|
|
|
2014-11-19 02:17:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-27 15:29:26 +00:00
|
|
|
bool DecodePool::IsShuttingDown() const { return mShuttingDown; }
|
|
|
|
|
|
|
|
class DecodingTask final : public Task {
|
|
|
|
public:
|
|
|
|
explicit DecodingTask(RefPtr<IDecodingTask>&& aTask)
|
|
|
|
: Task(false, aTask->Priority() == TaskPriority::eLow
|
|
|
|
? EventQueuePriority::Normal
|
2021-10-08 19:29:37 +00:00
|
|
|
: EventQueuePriority::RenderBlocking),
|
2020-10-27 15:29:26 +00:00
|
|
|
mTask(aTask) {}
|
|
|
|
|
|
|
|
bool Run() override {
|
|
|
|
mTask->Run();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-31 13:41:45 +00:00
|
|
|
#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
|
|
|
|
bool GetName(nsACString& aName) override {
|
|
|
|
aName.AssignLiteral("ImageDecodingTask");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-10-27 15:29:26 +00:00
|
|
|
private:
|
|
|
|
RefPtr<IDecodingTask> mTask;
|
|
|
|
};
|
2018-03-27 14:57:01 +00:00
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
void DecodePool::AsyncRun(IDecodingTask* aTask) {
|
|
|
|
MOZ_ASSERT(aTask);
|
2020-10-27 15:29:26 +00:00
|
|
|
|
|
|
|
TaskController::Get()->AddTask(
|
|
|
|
MakeAndAddRef<DecodingTask>((RefPtr<IDecodingTask>(aTask))));
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
bool DecodePool::SyncRunIfPreferred(IDecodingTask* aTask,
|
|
|
|
const nsCString& aURI) {
|
2014-11-19 02:17:17 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-06-29 20:43:19 +00:00
|
|
|
MOZ_ASSERT(aTask);
|
2014-11-19 02:17:17 +00:00
|
|
|
|
2017-10-13 05:12:57 +00:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("DecodePool::SyncRunIfPreferred",
|
|
|
|
GRAPHICS, aURI);
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
if (aTask->ShouldPreferSyncRun()) {
|
|
|
|
aTask->Run();
|
2016-12-22 19:15:41 +00:00
|
|
|
return true;
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
AsyncRun(aTask);
|
2016-12-22 19:15:41 +00:00
|
|
|
return false;
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
void DecodePool::SyncRunIfPossible(IDecodingTask* aTask,
|
|
|
|
const nsCString& aURI) {
|
2015-01-15 23:11:36 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-06-29 20:43:19 +00:00
|
|
|
MOZ_ASSERT(aTask);
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
|
2017-10-13 05:12:57 +00:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("DecodePool::SyncRunIfPossible",
|
|
|
|
GRAPHICS, aURI);
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
aTask->Run();
|
2014-11-19 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
already_AddRefed<nsIEventTarget> DecodePool::GetIOEventTarget() {
|
|
|
|
MutexAutoLock threadPoolLock(mMutex);
|
2018-10-01 21:38:01 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> target = mIOThread;
|
2015-01-18 09:27:16 +00:00
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
2014-11-19 02:17:17 +00:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|