Bug 1440361 - Reduce unnecessary IPC traffic from RemoveExpiredFontKeys which can produce empty resource updates. r?lsalzman
MozReview-Commit-ID: 8FQ63efoQxt
--- a/gfx/layers/wr/IpcResourceUpdateQueue.cpp
+++ b/gfx/layers/wr/IpcResourceUpdateQueue.cpp
@@ -131,16 +131,22 @@ ShmSegmentsWriter::Flush(nsTArray<RefCou
{
MOZ_ASSERT(aSmallAllocs.IsEmpty());
MOZ_ASSERT(aLargeAllocs.IsEmpty());
mSmallAllocs.SwapElements(aSmallAllocs);
mLargeAllocs.SwapElements(aLargeAllocs);
mCursor = 0;
}
+bool
+ShmSegmentsWriter::IsEmpty() const
+{
+ return mCursor == 0;
+}
+
void
ShmSegmentsWriter::Clear()
{
if (mShmAllocator) {
IpcResourceUpdateQueue::ReleaseShmems(mShmAllocator, mSmallAllocs);
IpcResourceUpdateQueue::ReleaseShmems(mShmAllocator, mLargeAllocs);
}
mCursor = 0;
@@ -374,16 +380,26 @@ IpcResourceUpdateQueue::Flush(nsTArray<l
nsTArray<layers::RefCountedShmem>& aSmallAllocs,
nsTArray<ipc::Shmem>& aLargeAllocs)
{
aUpdates.Clear();
mUpdates.SwapElements(aUpdates);
mWriter.Flush(aSmallAllocs, aLargeAllocs);
}
+bool
+IpcResourceUpdateQueue::IsEmpty() const
+{
+ if (mUpdates.Length() == 0) {
+ MOZ_ASSERT(mWriter.IsEmpty());
+ return true;
+ }
+ return false;
+}
+
void
IpcResourceUpdateQueue::Clear()
{
mWriter.Clear();
mUpdates.Clear();
}
//static
--- a/gfx/layers/wr/IpcResourceUpdateQueue.h
+++ b/gfx/layers/wr/IpcResourceUpdateQueue.h
@@ -30,16 +30,17 @@ public:
layers::OffsetRange WriteAsBytes(Range<T> aValues)
{
return Write(Range<uint8_t>((uint8_t*)aValues.begin().get(), aValues.length() * sizeof(T)));
}
void Flush(nsTArray<layers::RefCountedShmem>& aSmallAllocs, nsTArray<ipc::Shmem>& aLargeAllocs);
void Clear();
+ bool IsEmpty() const;
protected:
bool AllocChunk();
layers::OffsetRange AllocLargeChunk(size_t aSize);
nsTArray<layers::RefCountedShmem> mSmallAllocs;
nsTArray<ipc::Shmem> mLargeAllocs;
layers::WebRenderBridgeChild* mShmAllocator;
@@ -115,16 +116,18 @@ public:
void DeleteFontInstance(wr::FontInstanceKey aKey);
void Clear();
void Flush(nsTArray<layers::OpUpdateResource>& aUpdates,
nsTArray<layers::RefCountedShmem>& aSmallAllocs,
nsTArray<ipc::Shmem>& aLargeAllocs);
+ bool IsEmpty() const;
+
static void ReleaseShmems(ipc::IProtocol*, nsTArray<layers::RefCountedShmem>& aShmems);
static void ReleaseShmems(ipc::IProtocol*, nsTArray<ipc::Shmem>& aShmems);
protected:
ShmSegmentsWriter mWriter;
nsTArray<layers::OpUpdateResource> mUpdates;
};
} // namespace
--- a/gfx/layers/wr/WebRenderBridgeChild.cpp
+++ b/gfx/layers/wr/WebRenderBridgeChild.cpp
@@ -124,16 +124,20 @@ WebRenderBridgeChild::ClearReadLocks()
void
WebRenderBridgeChild::UpdateResources(wr::IpcResourceUpdateQueue& aResources)
{
if (!IPCOpen()) {
aResources.Clear();
return;
}
+ if (aResources.IsEmpty()) {
+ return;
+ }
+
nsTArray<OpUpdateResource> resourceUpdates;
nsTArray<RefCountedShmem> smallShmems;
nsTArray<ipc::Shmem> largeShmems;
aResources.Flush(resourceUpdates, smallShmems, largeShmems);
this->SendUpdateResources(resourceUpdates, Move(smallShmems), Move(largeShmems));
}