Bug 1347963 - part 7 - make ImageContainer use RecursiveMutex; r=kats

Making ImageContainer slightly faster with RecursiveMutex is a good thing.
We need to fix up some cargo-culting of includes along the way, though.
This commit is contained in:
Nathan Froyd 2017-07-04 13:47:42 -04:00
Родитель 12b117c200
Коммит e1013bf46d
4 изменённых файлов: 32 добавлений и 30 удалений

Просмотреть файл

@ -129,7 +129,7 @@ ImageContainerListener::ClearImageContainer()
already_AddRefed<ImageClient>
ImageContainer::GetImageClient()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock mon(mRecursiveMutex);
EnsureImageClient();
RefPtr<ImageClient> imageClient = mImageClient;
return imageClient.forget();
@ -163,7 +163,7 @@ ImageContainer::EnsureImageClient()
}
ImageContainer::ImageContainer(Mode flag)
: mReentrantMonitor("ImageContainer.mReentrantMonitor"),
: mRecursiveMutex("ImageContainer.mRecursiveMutex"),
mGenerationCounter(++sGenerationCounter),
mPaintCount(0),
mDroppedImageCount(0),
@ -178,7 +178,7 @@ ImageContainer::ImageContainer(Mode flag)
}
ImageContainer::ImageContainer(const CompositableHandle& aHandle)
: mReentrantMonitor("ImageContainer.mReentrantMonitor"),
: mRecursiveMutex("ImageContainer.mRecursiveMutex"),
mGenerationCounter(++sGenerationCounter),
mPaintCount(0),
mDroppedImageCount(0),
@ -206,7 +206,7 @@ ImageContainer::~ImageContainer()
RefPtr<PlanarYCbCrImage>
ImageContainer::CreatePlanarYCbCrImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
EnsureImageClient();
if (mImageClient && mImageClient->AsImageClientSingle()) {
return new SharedPlanarYCbCrImage(mImageClient);
@ -217,7 +217,7 @@ ImageContainer::CreatePlanarYCbCrImage()
RefPtr<SharedRGBImage>
ImageContainer::CreateSharedRGBImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
EnsureImageClient();
if (!mImageClient || !mImageClient->AsImageClientSingle()) {
return nullptr;
@ -228,7 +228,7 @@ ImageContainer::CreateSharedRGBImage()
void
ImageContainer::SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
mGenerationCounter = ++sGenerationCounter;
@ -298,7 +298,7 @@ ImageContainer::SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages)
void
ImageContainer::ClearImagesFromImageBridge()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
SetCurrentImageInternal(nsTArray<NonOwningImage>());
}
@ -306,7 +306,7 @@ void
ImageContainer::SetCurrentImages(const nsTArray<NonOwningImage>& aImages)
{
MOZ_ASSERT(!aImages.IsEmpty());
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
if (mIsAsync) {
if (RefPtr<ImageBridgeChild> imageBridge = ImageBridgeChild::GetSingleton()) {
imageBridge->UpdateImageClient(this);
@ -327,14 +327,14 @@ ImageContainer::ClearAllImages()
return;
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
SetCurrentImageInternal(nsTArray<NonOwningImage>());
}
void
ImageContainer::ClearCachedResources()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
if (mImageClient && mImageClient->AsImageClientSingle()) {
if (!mImageClient->HasTextureClientRecycler()) {
return;
@ -378,7 +378,7 @@ CompositableHandle ImageContainer::GetAsyncContainerHandle()
bool
ImageContainer::HasCurrentImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
return !mCurrentImages.IsEmpty();
}
@ -387,7 +387,7 @@ void
ImageContainer::GetCurrentImages(nsTArray<OwningImage>* aImages,
uint32_t* aGenerationCounter)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
*aImages = mCurrentImages;
if (aGenerationCounter) {
@ -398,7 +398,7 @@ ImageContainer::GetCurrentImages(nsTArray<OwningImage>* aImages,
gfx::IntSize
ImageContainer::GetCurrentSize()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
if (mCurrentImages.IsEmpty()) {
return gfx::IntSize(0, 0);
@ -410,7 +410,7 @@ ImageContainer::GetCurrentSize()
void
ImageContainer::NotifyComposite(const ImageCompositeNotification& aNotification)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
// An image composition notification is sent the first time a particular
// image is composited by an ImageHost. Thus, every time we receive such

Просмотреть файл

@ -12,7 +12,7 @@
#include "ImageTypes.h" // for ImageFormat, etc
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
#include "mozilla/Mutex.h" // for Mutex
#include "mozilla/ReentrantMonitor.h" // for ReentrantMonitorAutoEnter, etc
#include "mozilla/RecursiveMutex.h" // for RecursiveMutex, etc
#include "mozilla/TimeStamp.h" // for TimeStamp
#include "mozilla/gfx/Point.h" // For IntSize
#include "mozilla/layers/LayersTypes.h" // for LayersBackend, etc
@ -420,7 +420,7 @@ public:
/**
* Set aImages as the list of timestamped to display. The Images must have
* been created by this ImageContainer.
* Can be called on any thread. This method takes mReentrantMonitor
* Can be called on any thread. This method takes mRecursiveMutex
* when accessing thread-shared state.
* aImages must be non-empty. The first timestamp in the list may be
* null but the others must not be, and the timestamps must increase.
@ -437,7 +437,7 @@ public:
* Note that this must not be called if ENABLE_ASYNC has not been set.
*
* The implementation calls CurrentImageChanged() while holding
* mReentrantMonitor.
* mRecursiveMutex.
*
* If this ImageContainer has an ImageClient for async video:
* Schedule a task to send the image to the compositor using the
@ -469,7 +469,7 @@ public:
* been created by this ImageContainer.
* Must be called on the main thread, within a layers transaction.
*
* This method takes mReentrantMonitor
* This method takes mRecursiveMutex
* when accessing thread-shared state.
* aImage can be null. While it's null, nothing will be painted.
*
@ -500,7 +500,7 @@ public:
/**
* Returns if the container currently has an image.
* Can be called on any thread. This method takes mReentrantMonitor
* Can be called on any thread. This method takes mRecursiveMutex
* when accessing thread-shared state.
*/
bool HasCurrentImage();
@ -528,7 +528,7 @@ public:
/**
* Returns the size of the image in pixels.
* Can be called on any thread. This method takes mReentrantMonitor when accessing
* Can be called on any thread. This method takes mRecursiveMutex when accessing
* thread-shared state.
*/
gfx::IntSize GetCurrentSize();
@ -537,7 +537,7 @@ public:
* Sets a size that the image is expected to be rendered at.
* This is a hint for image backends to optimize scaling.
* Default implementation in this class is to ignore the hint.
* Can be called on any thread. This method takes mReentrantMonitor
* Can be called on any thread. This method takes mRecursiveMutex
* when accessing thread-shared state.
*/
void SetScaleHint(const gfx::IntSize& aScaleHint)
@ -545,7 +545,7 @@ public:
void SetImageFactory(ImageFactory *aFactory)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
mImageFactory = aFactory ? aFactory : new ImageFactory();
}
@ -569,7 +569,7 @@ public:
*/
TimeDuration GetPaintDelay()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
return mPaintDelay;
}
@ -578,7 +578,7 @@ public:
* and painted at least once. Can be called from any thread.
*/
uint32_t GetPaintCount() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
return mPaintCount;
}
@ -592,7 +592,7 @@ public:
*/
uint32_t GetDroppedImageCount()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
RecursiveMutexAutoLock lock(mRecursiveMutex);
return mDroppedImageCount;
}
@ -616,7 +616,7 @@ public:
static ProducerID AllocateProducerID();
private:
typedef mozilla::ReentrantMonitor ReentrantMonitor;
typedef mozilla::RecursiveMutex RecursiveMutex;
// Private destructor, to discourage deletion outside of Release():
~ImageContainer();
@ -631,9 +631,9 @@ private:
void EnsureImageClient();
// ReentrantMonitor to protect thread safe access to the "current
// RecursiveMutex to protect thread safe access to the "current
// image", and any other state which is shared between threads.
ReentrantMonitor mReentrantMonitor;
RecursiveMutex mRecursiveMutex;
#ifdef XP_WIN
RefPtr<D3D11YCbCrRecycleAllocator> mD3D11YCbCrRecycleAllocator;
@ -649,10 +649,10 @@ private:
// threadsafe.
uint32_t mPaintCount;
// See GetPaintDelay. Accessed only with mReentrantMonitor held.
// See GetPaintDelay. Accessed only with mRecursiveMutex held.
TimeDuration mPaintDelay;
// See GetDroppedImageCount. Accessed only with mReentrantMonitor held.
// See GetDroppedImageCount. Accessed only with mRecursiveMutex held.
uint32_t mDroppedImageCount;
// This is the image factory used by this container, layer managers using

Просмотреть файл

@ -7,6 +7,7 @@
#define AUDIO_SESSION_H_
#include "mozilla/Attributes.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/TimeStamp.h"
#include "nsTArray.h"

Просмотреть файл

@ -7,6 +7,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/SharedThreadPool.h"
#include "nsAutoPtr.h"
#include "nsITimer.h"