Bug 1451469 - Maintain a map from WrWindowId to APZSampler. r=botond

MozReview-Commit-ID: Bfkfs6FTOQ6

--HG--
extra : rebase_source : 0ca8d3b9452b9ece36eadf2bd2b1bb1c0783756d
This commit is contained in:
Kartikaya Gupta 2018-04-16 17:39:13 -04:00
parent 0eedeeda32
commit ee76c6b413
3 changed files with 50 additions and 0 deletions

View File

@ -7,7 +7,10 @@
#ifndef mozilla_layers_APZSampler_h
#define mozilla_layers_APZSampler_h
#include <unordered_map>
#include "mozilla/layers/AsyncCompositionManager.h" // for AsyncTransform
#include "mozilla/StaticMutex.h"
#include "nsTArray.h"
#include "Units.h"
@ -18,6 +21,7 @@ class TimeStamp;
namespace wr {
class TransactionBuilder;
struct WrTransformProperty;
struct WrWindowId;
} // namespace wr
namespace layers {
@ -37,6 +41,8 @@ class APZSampler {
public:
explicit APZSampler(const RefPtr<APZCTreeManager>& aApz);
void SetWebRenderWindowId(const wr::WindowId& aWindowId);
bool PushStateToWR(wr::TransactionBuilder& aTxn,
const TimeStamp& aSampleTime);
@ -84,8 +90,18 @@ public:
protected:
virtual ~APZSampler();
static already_AddRefed<APZSampler> GetSampler(const wr::WrWindowId& aWindowId);
private:
RefPtr<APZCTreeManager> mApz;
// Used to manage the mapping from a WR window id to APZSampler. These are only
// used if WebRender is enabled. Both sWindowIdMap and mWindowId should only
// be used while holding the sWindowIdLock.
static StaticMutex sWindowIdLock;
static std::unordered_map<uint64_t, APZSampler*> sWindowIdMap;
Maybe<wr::WrWindowId> mWindowId;
};
} // namespace layers

View File

@ -17,6 +17,10 @@
namespace mozilla {
namespace layers {
StaticMutex APZSampler::sWindowIdLock;
std::unordered_map<uint64_t, APZSampler*> APZSampler::sWindowIdMap;
APZSampler::APZSampler(const RefPtr<APZCTreeManager>& aApz)
: mApz(aApz)
{
@ -27,6 +31,20 @@ APZSampler::APZSampler(const RefPtr<APZCTreeManager>& aApz)
APZSampler::~APZSampler()
{
mApz->SetSampler(nullptr);
StaticMutexAutoLock lock(sWindowIdLock);
if (mWindowId) {
sWindowIdMap.erase(wr::AsUint64(*mWindowId));
}
}
void
APZSampler::SetWebRenderWindowId(const wr::WindowId& aWindowId)
{
StaticMutexAutoLock lock(sWindowIdLock);
MOZ_ASSERT(!mWindowId);
mWindowId = Some(aWindowId);
sWindowIdMap[wr::AsUint64(aWindowId)] = this;
}
bool
@ -158,5 +176,17 @@ APZSampler::IsSamplerThread() const
return CompositorThreadHolder::IsInCompositorThread();
}
/*static*/ already_AddRefed<APZSampler>
APZSampler::GetSampler(const wr::WrWindowId& aWindowId)
{
RefPtr<APZSampler> sampler;
StaticMutexAutoLock lock(sWindowIdLock);
auto it = sWindowIdMap.find(wr::AsUint64(aWindowId));
if (it != sWindowIdMap.end()) {
sampler = it->second;
}
return sampler.forget();
}
} // namespace layers
} // namespace mozilla

View File

@ -1779,6 +1779,10 @@ CompositorBridgeParent::AllocPWebRenderBridgeParent(const wr::PipelineId& aPipel
// that the callback from the updater thread can find the right APZUpdater.
mApzUpdater->SetWebRenderWindowId(windowId);
}
if (mApzSampler) {
// Same as for mApzUpdater, but for the sampler thread.
mApzSampler->SetWebRenderWindowId(windowId);
}
RefPtr<wr::WebRenderAPI> api = wr::WebRenderAPI::Create(this, Move(widget), windowId, aSize);
if (!api) {
mWrBridge = WebRenderBridgeParent::CreateDestroyed(aPipelineId);