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/. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DecodePool manages the threads used for decoding raster images.
|
|
|
|
*/
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_DecodePool_h
|
|
|
|
#define mozilla_image_DecodePool_h
|
2014-11-19 02:17:17 +00:00
|
|
|
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2015-05-15 00:08:26 +00:00
|
|
|
#include "nsCOMArray.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsIObserver.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
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
|
|
|
#include "nsStringFwd.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
class nsIThread;
|
2014-11-19 02:17:17 +00:00
|
|
|
class nsIThreadPool;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
|
|
|
class Decoder;
|
2015-05-15 00:08:26 +00:00
|
|
|
class DecodePoolImpl;
|
2016-06-29 20:43:19 +00:00
|
|
|
class IDecodingTask;
|
2014-11-19 02:17:17 +00:00
|
|
|
|
|
|
|
/**
|
2015-01-15 23:11:36 +00:00
|
|
|
* DecodePool is a singleton class that manages decoding of raster images. It
|
|
|
|
* owns a pool of image decoding threads that are used for asynchronous
|
|
|
|
* decoding.
|
2014-11-19 02:17:17 +00:00
|
|
|
*
|
2015-01-15 23:11:36 +00:00
|
|
|
* DecodePool allows callers to run a decoder, handling management of the
|
|
|
|
* decoder's lifecycle and whether it executes on the main thread,
|
|
|
|
* off-main-thread in the image decoding thread pool, or on some combination of
|
|
|
|
* the two.
|
2014-11-19 02:17:17 +00:00
|
|
|
*/
|
2018-02-13 11:43:30 +00:00
|
|
|
class DecodePool final : public nsIObserver
|
2014-11-19 02:17:17 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
/// Initializes the singleton instance. Should be called from the main thread.
|
|
|
|
static void Initialize();
|
|
|
|
|
|
|
|
/// Returns the singleton instance.
|
2014-11-19 02:17:17 +00:00
|
|
|
static DecodePool* Singleton();
|
|
|
|
|
2015-07-08 22:52:51 +00:00
|
|
|
/// @return the number of processor cores we have available. This is not the
|
|
|
|
/// same as the number of decoding threads we're actually using.
|
|
|
|
static uint32_t NumberOfCores();
|
|
|
|
|
2018-03-27 14:57:01 +00:00
|
|
|
/// True if the DecodePool is being shutdown. This may only be called by
|
|
|
|
/// threads from the pool to check if they should keep working or not.
|
|
|
|
bool IsShuttingDown() const;
|
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
/// Ask the DecodePool to run @aTask asynchronously and return immediately.
|
|
|
|
void AsyncRun(IDecodingTask* aTask);
|
2014-11-19 02:17:17 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-29 20:43:19 +00:00
|
|
|
* Run @aTask synchronously if the task would prefer it. It's up to the task
|
|
|
|
* itself to make this decision; @see IDecodingTask::ShouldPreferSyncRun(). If
|
|
|
|
* @aTask doesn't prefer it, just run @aTask asynchronously and return
|
|
|
|
* immediately.
|
2016-12-22 19:15:41 +00:00
|
|
|
* @return true if the task was run sync, false otherwise.
|
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 SyncRunIfPreferred(IDecodingTask* aTask, const nsCString& aURI);
|
2014-11-19 02:17:17 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-29 20:43:19 +00:00
|
|
|
* Run @aTask synchronously. This does not guarantee that @aTask will complete
|
|
|
|
* synchronously. If, for example, @aTask doesn't yet have the data it needs to
|
|
|
|
* run synchronously, it may recover by scheduling an async task to finish up
|
|
|
|
* the work when the remaining data is available.
|
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 SyncRunIfPossible(IDecodingTask* aTask, const nsCString& aURI);
|
2014-11-19 02:17:17 +00:00
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
/**
|
|
|
|
* Returns an event target interface to the DecodePool's I/O thread. Callers
|
|
|
|
* who want to deliver data to workers on the DecodePool can use this event
|
|
|
|
* target.
|
|
|
|
*
|
|
|
|
* @return An nsIEventTarget interface to the thread pool's I/O thread.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIEventTarget> GetIOEventTarget();
|
|
|
|
|
2015-01-11 19:43:32 +00:00
|
|
|
private:
|
2015-05-15 00:08:26 +00:00
|
|
|
friend class DecodePoolWorker;
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2014-11-19 02:17:17 +00:00
|
|
|
DecodePool();
|
|
|
|
virtual ~DecodePool();
|
|
|
|
|
|
|
|
static StaticRefPtr<DecodePool> sSingleton;
|
2015-07-08 22:52:51 +00:00
|
|
|
static uint32_t sNumCores;
|
2014-11-19 02:17:17 +00:00
|
|
|
|
2016-06-29 20:43:19 +00:00
|
|
|
RefPtr<DecodePoolImpl> mImpl;
|
2015-05-15 00:08:26 +00:00
|
|
|
|
2018-02-13 11:43:30 +00:00
|
|
|
// mMutex protects mIOThread.
|
2016-05-01 18:29:22 +00:00
|
|
|
Mutex mMutex;
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
2014-11-19 02:17:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_DecodePool_h
|