From 8b53bb68c704fc689d6328dd1d6c1f1be5ed3b2c Mon Sep 17 00:00:00 2001 From: Kelsey Gilbert Date: Tue, 6 Feb 2024 19:34:26 +0000 Subject: [PATCH] Bug 1794893 - WebGLMemoryTracker ensured-registered in WebGLContext::ctor. r=gfx-reviewers,lsalzman Differential Revision: https://phabricator.services.mozilla.com/D200851 --- dom/canvas/WebGLContext.cpp | 1 + dom/canvas/WebGLMemoryTracker.cpp | 8 ++++++++ dom/canvas/WebGLMemoryTracker.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index 09555275abb0..cfc06fc82708 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -149,6 +149,7 @@ WebGLContext::WebGLContext(HostWebGLContext* host, host->mContext = this; } const FuncScope funcScope(*this, ""); + WebGLMemoryTracker::EnsureRegistered(); } WebGLContext::~WebGLContext() { DestroyResourcesAndContext(); } diff --git a/dom/canvas/WebGLMemoryTracker.cpp b/dom/canvas/WebGLMemoryTracker.cpp index 936d93cd3ec0..361d1be695b5 100644 --- a/dom/canvas/WebGLMemoryTracker.cpp +++ b/dom/canvas/WebGLMemoryTracker.cpp @@ -15,6 +15,14 @@ namespace mozilla { MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf) +void WebGLMemoryTracker::EnsureRegistered() { + static bool sIsRegistered = []() { + RegisterStrongMemoryReporter(new WebGLMemoryTracker); + return true; + }(); + (void)sIsRegistered; +} + NS_IMETHODIMP WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool) { diff --git a/dom/canvas/WebGLMemoryTracker.h b/dom/canvas/WebGLMemoryTracker.h index 4612595e63d5..2250448ac8be 100644 --- a/dom/canvas/WebGLMemoryTracker.h +++ b/dom/canvas/WebGLMemoryTracker.h @@ -15,6 +15,8 @@ class WebGLMemoryTracker : public nsIMemoryReporter { NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIMEMORYREPORTER + static void EnsureRegistered(); + private: virtual ~WebGLMemoryTracker() = default; }; -- 2.11.4.GIT