Bug 1474806 - Use more std::unordered_map in layers r=nical

This commit is contained in:
sotaro 2018-07-12 12:12:50 +09:00
parent 3b0f9e6a60
commit ac2deac432
5 changed files with 31 additions and 28 deletions

View File

@ -135,7 +135,7 @@ void
CompositorBridgeChild::Destroy()
{
// This must not be called from the destructor!
mTexturesWaitingRecycled.Clear();
mTexturesWaitingRecycled.clear();
// Destroying the layer manager may cause all sorts of things to happen, so
// let's make sure there is still a reference to keep this alive whatever
@ -898,25 +898,26 @@ CompositorBridgeChild::HoldUntilCompositableRefReleasedIfNecessary(TextureClient
}
aClient->SetLastFwdTransactionId(GetFwdTransactionId());
mTexturesWaitingRecycled.Put(aClient->GetSerial(), aClient);
mTexturesWaitingRecycled.emplace(aClient->GetSerial(), aClient);
}
void
CompositorBridgeChild::NotifyNotUsed(uint64_t aTextureId, uint64_t aFwdTransactionId)
{
if (auto entry = mTexturesWaitingRecycled.Lookup(aTextureId)) {
if (aFwdTransactionId < entry.Data()->GetLastFwdTransactionId()) {
auto it = mTexturesWaitingRecycled.find(aTextureId);
if (it != mTexturesWaitingRecycled.end()) {
if (aFwdTransactionId < it->second->GetLastFwdTransactionId()) {
// Released on host side, but client already requested newer use texture.
return;
}
entry.Remove();
mTexturesWaitingRecycled.erase(it);
}
}
void
CompositorBridgeChild::CancelWaitForRecycle(uint64_t aTextureId)
{
mTexturesWaitingRecycled.Remove(aTextureId);
mTexturesWaitingRecycled.erase(aTextureId);
}
TextureClientPool*

View File

@ -17,13 +17,14 @@
#include "mozilla/layers/PaintThread.h" // for PaintThread
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsClassHashtable.h" // for nsClassHashtable
#include "nsRefPtrHashtable.h"
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsHashKeys.h" // for nsUint64HashKey
#include "nsISupportsImpl.h" // for NS_INLINE_DECL_REFCOUNTING
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
#include "nsWeakReference.h"
#include <unordered_map>
namespace mozilla {
namespace dom {
@ -389,7 +390,7 @@ private:
* Hold TextureClients refs until end of their usages on host side.
* It defer calling of TextureClient recycle callback.
*/
nsRefPtrHashtable<nsUint64HashKey, TextureClient> mTexturesWaitingRecycled;
std::unordered_map<uint64_t, RefPtr<TextureClient>> mTexturesWaitingRecycled;
MessageLoop* mMessageLoop;

View File

@ -158,18 +158,19 @@ ImageBridgeChild::HoldUntilCompositableRefReleasedIfNecessary(TextureClient* aCl
return;
}
aClient->SetLastFwdTransactionId(GetFwdTransactionId());
mTexturesWaitingRecycled.Put(aClient->GetSerial(), aClient);
mTexturesWaitingRecycled.emplace(aClient->GetSerial(), aClient);
}
void
ImageBridgeChild::NotifyNotUsed(uint64_t aTextureId, uint64_t aFwdTransactionId)
{
if (auto entry = mTexturesWaitingRecycled.Lookup(aTextureId)) {
if (aFwdTransactionId < entry.Data()->GetLastFwdTransactionId()) {
auto it = mTexturesWaitingRecycled.find(aTextureId);
if (it != mTexturesWaitingRecycled.end()) {
if (aFwdTransactionId < it->second->GetLastFwdTransactionId()) {
// Released on host side, but client already requested newer use texture.
return;
}
entry.Remove();
mTexturesWaitingRecycled.erase(it);
}
}
@ -177,7 +178,7 @@ void
ImageBridgeChild::CancelWaitForRecycle(uint64_t aTextureId)
{
MOZ_ASSERT(InImageBridgeChildThread());
mTexturesWaitingRecycled.Remove(aTextureId);
mTexturesWaitingRecycled.erase(aTextureId);
}
// Singleton
@ -235,7 +236,7 @@ ImageBridgeChild::ActorDestroy(ActorDestroyReason aWhy)
mDestroyed = true;
{
MutexAutoLock lock(mContainerMapLock);
mImageContainerListeners.Clear();
mImageContainerListeners.clear();
}
}
@ -287,7 +288,7 @@ ImageBridgeChild::~ImageBridgeChild()
void
ImageBridgeChild::MarkShutDown()
{
mTexturesWaitingRecycled.Clear();
mTexturesWaitingRecycled.clear();
mCanSend = false;
}
@ -310,8 +311,8 @@ ImageBridgeChild::Connect(CompositableClient* aCompositable,
// But offscreen canvas does not provide it.
if (aImageContainer) {
MutexAutoLock lock(mContainerMapLock);
MOZ_ASSERT(!mImageContainerListeners.Contains(id));
mImageContainerListeners.Put(id, aImageContainer->GetImageContainerListener());
MOZ_ASSERT(mImageContainerListeners.find(id) == mImageContainerListeners.end());
mImageContainerListeners.emplace(id, aImageContainer->GetImageContainerListener());
}
CompositableHandle handle(id);
@ -323,7 +324,7 @@ void
ImageBridgeChild::ForgetImageContainer(const CompositableHandle& aHandle)
{
MutexAutoLock lock(mContainerMapLock);
mImageContainerListeners.Remove(aHandle.Value());
mImageContainerListeners.erase(aHandle.Value());
}
Thread* ImageBridgeChild::GetThread() const
@ -724,9 +725,8 @@ ImageBridgeChild::UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier&
nsTArray<RefPtr<ImageContainerListener> > listeners;
{
MutexAutoLock lock(mContainerMapLock);
for (auto iter = mImageContainerListeners.Iter(); !iter.Done(); iter.Next()) {
RefPtr<ImageContainerListener>& listener = iter.Data();
listeners.AppendElement(listener);
for (const auto& entry : mImageContainerListeners) {
listeners.AppendElement(entry.second);
}
}
// Drop ImageContainer's ImageClient whithout holding mContainerMapLock to avoid deadlock.
@ -1004,8 +1004,9 @@ ImageBridgeChild::RecvDidComposite(InfallibleTArray<ImageCompositeNotification>&
RefPtr<ImageContainerListener> listener;
{
MutexAutoLock lock(mContainerMapLock);
if (auto entry = mImageContainerListeners.Lookup(n.compositable().Value())) {
listener = entry.Data();
auto it = mImageContainerListeners.find(n.compositable().Value());
if (it != mImageContainerListeners.end()) {
listener = it->second;
}
}
if (listener) {
@ -1117,7 +1118,7 @@ ImageBridgeChild::ReleaseCompositable(const CompositableHandle& aHandle)
{
MutexAutoLock lock(mContainerMapLock);
mImageContainerListeners.Remove(aHandle.Value());
mImageContainerListeners.erase(aHandle.Value());
}
}

View File

@ -9,6 +9,8 @@
#include <stddef.h> // for size_t
#include <stdint.h> // for uint32_t, uint64_t
#include <unordered_map>
#include "mozilla/Attributes.h" // for override
#include "mozilla/Atomics.h"
#include "mozilla/RefPtr.h" // for already_AddRefed
@ -21,7 +23,6 @@
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsIObserver.h"
#include "nsRegion.h" // for nsIntRegion
#include "nsRefPtrHashtable.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/ReentrantMonitor.h" // for ReentrantMonitor, etc
@ -395,13 +396,13 @@ private:
* Hold TextureClients refs until end of their usages on host side.
* It defer calling of TextureClient recycle callback.
*/
nsRefPtrHashtable<nsUint64HashKey, TextureClient> mTexturesWaitingRecycled;
std::unordered_map<uint64_t, RefPtr<TextureClient>> mTexturesWaitingRecycled;
/**
* Mapping from async compositable IDs to image containers.
*/
Mutex mContainerMapLock;
nsRefPtrHashtable<nsUint64HashKey, ImageContainerListener> mImageContainerListeners;
std::unordered_map<uint64_t, RefPtr<ImageContainerListener>> mImageContainerListeners;
#if defined(XP_WIN)
/**

View File

@ -12,7 +12,6 @@
#include "base/thread.h" // for Thread
#include "base/message_loop.h"
#include "nsISupportsImpl.h"
#include "nsRefPtrHashtable.h"
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
#include "mozilla/Mutex.h"
#include "mozilla/webrender/webrender_ffi.h"