Bug 1431211 - clean up WR blob image renderer resources on API destruction. r=gankro
authorLee Salzman <lsalzman@mozilla.com>
Thu, 18 Jan 2018 06:28:09 -0500
changeset 454131 294d12c7062b0ea08faf2ee12ff1a017a8f9c8f8
parent 454130 ac78853b7fc9fa46249944f7ef1e086cba5a7154
child 454132 4f42c8b2e10caa1295c3bb5029e86e8261e0662d
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgankro
bugs1431211
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1431211 - clean up WR blob image renderer resources on API destruction. r=gankro MozReview-Commit-ID: E7XuM7vpEXd
gfx/webrender_bindings/Moz2DImageRenderer.cpp
gfx/webrender_bindings/WebRenderAPI.cpp
--- a/gfx/webrender_bindings/Moz2DImageRenderer.cpp
+++ b/gfx/webrender_bindings/Moz2DImageRenderer.cpp
@@ -50,16 +50,31 @@ struct FontTemplate {
   uint32_t mIndex;
   const VecU8 *mVec;
   RefPtr<UnscaledFont> mUnscaledFont;
 };
 
 StaticMutex sFontDataTableLock;
 std::unordered_map<FontKey, FontTemplate> sFontDataTable;
 
+void
+ClearBlobImageResources(WrIdNamespace aNamespace) {
+  StaticMutexAutoLock lock(sFontDataTableLock);
+  for (auto i = sFontDataTable.begin(); i != sFontDataTable.end();) {
+    if (i->first.mNamespace == aNamespace) {
+      if (i->second.mVec) {
+        wr_dec_ref_arc(i->second.mVec);
+      }
+      i = sFontDataTable.erase(i);
+    } else {
+      i++;
+    }
+  }
+}
+
 extern "C" {
 void
 AddFontData(WrFontKey aKey, const uint8_t *aData, size_t aSize, uint32_t aIndex, const ArcVecU8 *aVec) {
   StaticMutexAutoLock lock(sFontDataTableLock);
   auto i = sFontDataTable.find(aKey);
   if (i == sFontDataTable.end()) {
     FontTemplate font;
     font.mData = aData;
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -290,28 +290,34 @@ WebRenderAPI::Clone()
   return renderApi.forget();
 }
 
 wr::WrIdNamespace
 WebRenderAPI::GetNamespace() {
   return wr_api_get_namespace(mDocHandle);
 }
 
+extern void ClearBlobImageResources(WrIdNamespace aNamespace);
+
 WebRenderAPI::~WebRenderAPI()
 {
   if (!mRootApi) {
 
     RenderThread::Get()->SetDestroyed(GetId());
 
     layers::SynchronousTask task("Destroy WebRenderAPI");
     auto event = MakeUnique<RemoveRenderer>(&task);
     RunOnRenderThread(Move(event));
     task.Wait();
   }
 
+  // Clean up any resources the blob image renderer is holding onto that
+  // can no longer be used once this WR API instance goes away.
+  ClearBlobImageResources(GetNamespace());
+
   wr_api_delete(mDocHandle);
 }
 
 void
 WebRenderAPI::SendTransaction(TransactionBuilder& aTxn)
 {
   wr_api_send_transaction(mDocHandle, aTxn.Raw());
 }